cpuconfig.mk 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # NOTE: Define the generic function for Nuclei CPU configuration
  2. # Usage: $(eval $(call def_xlcpucfg,CFGNAME[,DEP1,DEP2,...]))
  3. # - Defines XLCFG_$(1) with a default empty value using ?= (preserves existing value if set)
  4. # - If XLCFG_$(1) is set to a non-empty value and that value >= 1, enables the feature and triggers dependencies
  5. # - Dependencies (DEP1, DEP2, etc.) will be set to 1 when main config is active
  6. # - Adds -DXLCFG_$(1)=$$(XLCFG_$(1)) to COMMON_FLAGS for C preprocessing
  7. #
  8. # Example 1: Simple configuration without dependencies
  9. # $(eval $(call def_xlcpucfg,CCM))
  10. # - Creates XLCFG_CCM ?= (empty by default)
  11. # - If XLCFG_CCM is set to 1 or higher, adds -DXLCFG_CCM=1 to COMMON_FLAGS
  12. #
  13. # Example 2: Configuration with dependencies
  14. # $(eval $(call def_xlcpucfg,SPMP,TEE,PMP))
  15. # - Creates XLCFG_SPMP ?= (empty by default)
  16. # - If XLCFG_SPMP is set to 1 or higher:
  17. # - Sets XLCFG_TEE := 1 and XLCFG_PMP := 1
  18. # - Adds -DXLCFG_SPMP=$(value_of_XLCFG_SPMP) to COMMON_FLAGS
  19. define def_xlcpucfg
  20. # Initialize the configuration variable with a default empty value (using ?= preserves existing values)
  21. XLCFG_$(1) ?=
  22. # Check if the configuration variable has been set to a non-empty value
  23. # Use $$ to defer evaluation to the eval phase
  24. ifneq (x$$(XLCFG_$(1)),x)
  25. # Use $$ for gte call so it checks the value during eval
  26. ifeq ($$(call gte,$$(XLCFG_$(1)),1),$$(true))
  27. # Use $$ for foreach so it only runs if ifeq is true
  28. # Note: wordlist uses single $ because we want to parse the arguments immediately
  29. # Enable all dependent features by setting them to 1
  30. # Process dependencies from argument 2 onwards (wordlist 2,9 gets args 2-9)
  31. $$(foreach dep,$(wordlist 2,9,$(1) $(2) $(3) $(4) $(5) $(6) $(7) $(8) $(9)),$$(if $$(dep),$$(eval XLCFG_$$(dep) := 1)))
  32. endif
  33. # Add the configuration as a preprocessor define to COMMON_FLAGS
  34. # Use $$ to reference the variable value at the time COMMON_FLAGS is used/evaluated
  35. COMMON_FLAGS += -DXLCFG_$(1)=$$(XLCFG_$(1))
  36. endif
  37. endef
  38. # NOTE: This cpuconfig.mk is only valid when cpufeature.mk is not generated by nuclei_gen
  39. # NOTE: These XLCFG_xxx make variables control CPU features and are internally used by Nuclei SDK
  40. # Setting these variables affects `cpufeature.h` header file when `cpufeature.h` is not generated
  41. # Configuration options with dependencies - when enabled, they automatically enable dependent features
  42. # NOTE: Dependent features (such as TEE, PMP, SMODE, etc.) that are triggered by these configurations
  43. # also need to be defined separately in the simple configurations section below.
  44. # Example: SPMP depends on TEE and PMP, so when XLCFG_SPMP is set to >= 1, it will automatically
  45. # set XLCFG_TEE and XLCFG_PMP to 1, which is why TEE and PMP must also be defined below.
  46. $(eval $(call def_xlcpucfg,SPMP,TEE,PMP))
  47. $(eval $(call def_xlcpucfg,SMPU,TEE,PMP))
  48. $(eval $(call def_xlcpucfg,PLIC,SMODE))
  49. $(eval $(call def_xlcpucfg,SSTC,SMODE))
  50. $(eval $(call def_xlcpucfg,TEE,SMODE))
  51. $(eval $(call def_xlcpucfg,VNICE,NICE))
  52. $(eval $(call def_xlcpucfg,SMEPMP,PMP))
  53. $(eval $(call def_xlcpucfg,PMP_GRAIN,PMP))
  54. $(eval $(call def_xlcpucfg,PMP_ENTRY_NUM,PMP))
  55. $(eval $(call def_xlcpucfg,PMP,UMODE))
  56. $(eval $(call def_xlcpucfg,PMA_CSR_NUM,PMA))
  57. $(eval $(call def_xlcpucfg,PMA_SEC_CSR_NUM,PMA))
  58. # Simple configurations (no dependencies)
  59. # These configurations do not trigger any dependent features when enabled
  60. $(eval $(call def_xlcpucfg,CCM))
  61. $(eval $(call def_xlcpucfg,ECLIC))
  62. $(eval $(call def_xlcpucfg,SYSTIMER))
  63. $(eval $(call def_xlcpucfg,SMODE))
  64. $(eval $(call def_xlcpucfg,UMODE))
  65. $(eval $(call def_xlcpucfg,EXCP))
  66. $(eval $(call def_xlcpucfg,CIDU))
  67. $(eval $(call def_xlcpucfg,HPM))
  68. $(eval $(call def_xlcpucfg,SMPCC))
  69. $(eval $(call def_xlcpucfg,ECC))
  70. $(eval $(call def_xlcpucfg,PMA))
  71. $(eval $(call def_xlcpucfg,PMA_MACRO))
  72. $(eval $(call def_xlcpucfg,STACK_CHECK))
  73. $(eval $(call def_xlcpucfg,IRQ_NUM))
  74. $(eval $(call def_xlcpucfg,NICE))
  75. $(eval $(call def_xlcpucfg,ICACHE))
  76. $(eval $(call def_xlcpucfg,DCACHE))
  77. $(eval $(call def_xlcpucfg,ILM))
  78. $(eval $(call def_xlcpucfg,DLM))
  79. $(eval $(call def_xlcpucfg,SRAM))
  80. $(eval $(call def_xlcpucfg,DDR))
  81. $(eval $(call def_xlcpucfg,MISALIGNED_ACCESS))
  82. $(eval $(call def_xlcpucfg,AMO))