Skip to content

Commit e6dd68e

Browse files
ycsinkartben
authored andcommitted
arch: riscv: introduce CONFIG_RISCV_GP_PURPOSE choice
Introduce `CONFIG_RISCV_GP_PURPOSE` choice to make sure that only one of `CONFIG_RISCV_GP` or `CONFIG_RISCV_CURRENT_VIA_GP` can be enabled, instead of relying of dependencies. To do that, introduce a new `CONFIG_RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING` that can be selected by SoC when it implemented global pointer (GP) initialization for relative addressing in its linker. `CONFIG_RISCV_GP` will be the default choice when `CONFIG_RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING=y` Signed-off-by: Yong Cong Sin <[email protected]> Signed-off-by: Yong Cong Sin <[email protected]>
1 parent 033804e commit e6dd68e

File tree

37 files changed

+33
-56
lines changed

37 files changed

+33
-56
lines changed

arch/riscv/Kconfig

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ config FLOAT_HARD
1616
help
1717
This option enables the hard-float calling convention.
1818

19+
choice RISCV_GP_PURPOSE
20+
prompt "Purpose of the global pointer (GP) register"
21+
default RISCV_GP if RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
22+
1923
config RISCV_GP
2024
bool "RISC-V global pointer relative addressing"
21-
default n
25+
depends on RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
2226
help
2327
Use global pointer relative addressing for small globals declared
2428
anywhere in the executable. It can benefit performance and reduce
@@ -30,14 +34,15 @@ config RISCV_GP
3034

3135
config RISCV_CURRENT_VIA_GP
3236
bool "Store current thread into the global pointer (GP) register"
33-
depends on !RISCV_GP
3437
depends on MP_MAX_NUM_CPUS > 1
3538
select ARCH_HAS_CUSTOM_CURRENT_IMPL
3639
help
3740
Store the current thread's pointer into the global pointer (GP) register.
3841
When is enabled, calls to `arch_current_thread()` & `k_sched_current_thread_query()` will
3942
be reduced to a single register read.
4043

44+
endchoice # RISCV_GP_PURPOSE
45+
4146
config RISCV_ALWAYS_SWITCH_THROUGH_ECALL
4247
bool "Do not use mret outside a trap handler context"
4348
depends on MULTITHREADING
@@ -148,6 +153,12 @@ config RISCV_SOC_HAS_CUSTOM_SYS_IO
148153
the RISC-V SoC needs to do something different and more than reading and
149154
writing the registers.
150155

156+
config RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
157+
bool
158+
help
159+
Selected when SoC has implemented the initialization of global pointer (GP)
160+
at program start, or earlier than any instruction using GP relative addressing.
161+
151162
config RISCV_SOC_CONTEXT_SAVE
152163
bool "SOC-based context saving in IRQ handlers"
153164
select RISCV_SOC_OFFSETS

soc/andestech/ae350/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ config SOC_SERIES_ANDES_AE350
55
select RISCV
66
select RISCV_PRIVILEGED
77
select RISCV_HAS_PLIC
8+
select RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
89
imply XIP
910

1011
config SOC_ANDES_AE350

soc/andestech/ae350/Kconfig.defconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ config RISCV_GENERIC_TOOLCHAIN
2121
config RISCV_SOC_INTERRUPT_INIT
2222
default y
2323

24-
config RISCV_GP
25-
default y
26-
2724
config 2ND_LVL_ISR_TBL_OFFSET
2825
default 12
2926

soc/espressif/esp32c2/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
config SOC_SERIES_ESP32C2
55
select RISCV
6-
select RISCV_GP
6+
select RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
77
select DYNAMIC_INTERRUPTS
88
select CLOCK_CONTROL
99
select PINCTRL

soc/espressif/esp32c3/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
config SOC_SERIES_ESP32C3
55
select RISCV
6-
select RISCV_GP
6+
select RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
77
select DYNAMIC_INTERRUPTS
88
select CLOCK_CONTROL
99
select PINCTRL

soc/espressif/esp32c6/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
config SOC_SERIES_ESP32C6
55
select RISCV
6-
select RISCV_GP
6+
select RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
77
select DYNAMIC_INTERRUPTS
88
select CLOCK_CONTROL
99
select PINCTRL

soc/gd/gd32/gd32vf103/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ config SOC_SERIES_GD32VF103
1313
select RISCV_ISA_EXT_ZICSR
1414
select RISCV_ISA_EXT_ZIFENCEI
1515
select RISCV_HAS_CLIC
16+
select RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
1617
select ATOMIC_OPERATIONS_C
1718
select INCLUDE_RESET_VECTOR
1819
select GD32_HAS_AFIO_PINMUX

soc/gd/gd32/gd32vf103/Kconfig.defconfig.gd32vf103

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ config RISCV_MCAUSE_EXCEPTION_MASK
1717
config RISCV_SOC_INTERRUPT_INIT
1818
default y
1919

20-
config RISCV_GP
21-
default y
22-
2320
config NUM_IRQS
2421
default 87 if NUCLEI_ECLIC
2522
default 16 if !NUCLEI_ECLIC

soc/intel/intel_niosv/niosv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ config SOC_SERIES_NIOSV
1111
select RISCV_ISA_EXT_A
1212
select RISCV_ISA_EXT_ZICSR
1313
select RISCV_ISA_EXT_ZIFENCEI
14+
select RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
1415
imply XIP
1516

1617
config SOC_NIOSV_M

soc/intel/intel_niosv/niosv/Kconfig.defconfig.series

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC
1010
config NUM_IRQS # Platform interrupts IRQs index start from index 16
1111
default 32
1212

13-
config RISCV_GP
14-
default y
15-
1613
config RISCV_SOC_INTERRUPT_INIT
1714
default y
1815

0 commit comments

Comments
 (0)