diff options
author | Hesham Almatary <heshamelmatary@gmail.com> | 2017-10-27 15:18:40 +1100 |
---|---|---|
committer | Hesham Almatary <heshamelmatary@gmail.com> | 2017-11-01 10:10:27 +1100 |
commit | 11ff3a9e72ca261a6024b16c34c6fb35054fd53a (patch) | |
tree | ffddc78ce5f3ceff414fa7551f49c7ccb5510672 /cpukit/score/cpu/riscv/rtems | |
parent | testsuite: Add bspIo for a local printk. (diff) | |
download | rtems-11ff3a9e72ca261a6024b16c34c6fb35054fd53a.tar.bz2 |
cpukit: RISC-V - make riscv32 code work for riscv64 - v2
* Use #ifdefs for 32/64 bit code
* Use unsigned long which is 32-bit on riscv32 and 64-bit on riscv64 (register size)
* Move the code to a new shared riscv folder to be shared between riscv32 and riscv64
* Rename RTEMS_CPU extracted from command line to shared riscv target s/riscv*/riscv
Update #3109
Diffstat (limited to '')
-rw-r--r-- | cpukit/score/cpu/riscv/rtems/asm.h (renamed from cpukit/score/cpu/riscv32/rtems/asm.h) | 0 | ||||
-rw-r--r-- | cpukit/score/cpu/riscv/rtems/score/cpu.h (renamed from cpukit/score/cpu/riscv32/rtems/score/cpu.h) | 54 | ||||
-rw-r--r-- | cpukit/score/cpu/riscv/rtems/score/cpu_asm.h (renamed from cpukit/score/cpu/riscv32/rtems/score/cpu_asm.h) | 0 | ||||
-rw-r--r-- | cpukit/score/cpu/riscv/rtems/score/cpuatomic.h (renamed from cpukit/score/cpu/riscv32/rtems/score/cpuatomic.h) | 0 | ||||
-rw-r--r-- | cpukit/score/cpu/riscv/rtems/score/cpuimpl.h (renamed from cpukit/score/cpu/riscv32/rtems/score/cpuimpl.h) | 0 | ||||
-rw-r--r-- | cpukit/score/cpu/riscv/rtems/score/riscv-utility.h (renamed from cpukit/score/cpu/riscv32/rtems/score/riscv-utility.h) | 0 | ||||
-rw-r--r-- | cpukit/score/cpu/riscv/rtems/score/riscv.h (renamed from cpukit/score/cpu/riscv32/rtems/score/riscv.h) | 0 | ||||
-rw-r--r-- | cpukit/score/cpu/riscv/rtems/score/types.h (renamed from cpukit/score/cpu/riscv32/rtems/score/types.h) | 2 |
8 files changed, 38 insertions, 18 deletions
diff --git a/cpukit/score/cpu/riscv32/rtems/asm.h b/cpukit/score/cpu/riscv/rtems/asm.h index 34b6474515..34b6474515 100644 --- a/cpukit/score/cpu/riscv32/rtems/asm.h +++ b/cpukit/score/cpu/riscv/rtems/asm.h diff --git a/cpukit/score/cpu/riscv32/rtems/score/cpu.h b/cpukit/score/cpu/riscv/rtems/score/cpu.h index f77db55932..439b8c2fd4 100644 --- a/cpukit/score/cpu/riscv32/rtems/score/cpu.h +++ b/cpukit/score/cpu/riscv/rtems/score/cpu.h @@ -66,7 +66,7 @@ extern "C" { #define CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES FALSE #define CPU_BIG_ENDIAN FALSE #define CPU_LITTLE_ENDIAN TRUE -#define CPU_MODES_INTERRUPT_MASK 0x00000001 +#define CPU_MODES_INTERRUPT_MASK 0x0000000000000001 /* * Processor defined structures required for cpukit/score. @@ -75,13 +75,13 @@ extern "C" { #ifndef ASM typedef struct { - /* riscv32 has 32 32-bit general purpose registers (x0-x31). */ - uint32_t x[32]; + /* riscv has 32 xlen-bit (where xlen can be 32 or 64) general purpose registers (x0-x31)*/ + unsigned long x[32]; /* Special purpose registers */ - uint32_t mstatus; - uint32_t mcause; - uint32_t mepc; + unsigned long mstatus; + unsigned long mcause; + unsigned long mepc; #ifdef RTEMS_SMP /** * @brief On SMP configurations the thread context must contain a boolean @@ -138,7 +138,11 @@ typedef Context_Control CPU_Interrupt_frame; Context_Control_fp _CPU_Null_fp_context; #define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0 +#if __riscv_xlen == 32 #define CPU_STACK_MINIMUM_SIZE 4096 +#else +#define CPU_STACK_MINIMUM_SIZE 4096 * 2 +#endif #define CPU_ALIGNMENT 8 #define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE #define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT @@ -152,14 +156,14 @@ Context_Control_fp _CPU_Null_fp_context; * */ -static inline uint32_t riscv_interrupt_disable( void ) +static inline unsigned long riscv_interrupt_disable( void ) { - register uint32_t status = read_csr(mstatus); + register unsigned long status = read_csr(mstatus); clear_csr(mstatus, MSTATUS_MIE); return status; } -static inline void riscv_interrupt_enable(uint32_t level) +static inline void riscv_interrupt_enable(unsigned long level) { write_csr(mstatus, level); } @@ -176,14 +180,14 @@ static inline void riscv_interrupt_enable(uint32_t level) riscv_interrupt_disable(); \ } while(0) -RTEMS_INLINE_ROUTINE bool _CPU_ISR_Is_enabled( uint32_t level ) +RTEMS_INLINE_ROUTINE bool _CPU_ISR_Is_enabled( unsigned long level ) { return ( level & MSTATUS_MIE ) != 0; } -void _CPU_ISR_Set_level( uint32_t level ); +void _CPU_ISR_Set_level( unsigned long level ); -uint32_t _CPU_ISR_Get_level( void ); +unsigned long _CPU_ISR_Get_level( void ); /* end of ISR handler macros */ @@ -194,7 +198,7 @@ void _CPU_Context_Initialize( Context_Control *context, void *stack_area_begin, size_t stack_area_size, - uint32_t new_level, + unsigned long new_level, void (*entry_point)( void ), bool is_fp, void *tls_area @@ -262,15 +266,31 @@ typedef struct { } CPU_Per_CPU_control; #endif /* ASM */ +#if __riscv_xlen == 32 #define CPU_SIZEOF_POINTER 4 + +/* 32-bit load/store instructions */ +#define LREG lw +#define SREG sw + #define CPU_EXCEPTION_FRAME_SIZE 128 +#else /* xlen = 64 */ +#define CPU_SIZEOF_POINTER 8 + +/* 64-bit load/store instructions */ +#define LREG ld +#define SREG sd + +#define CPU_EXCEPTION_FRAME_SIZE 256 +#endif + #define CPU_PER_CPU_CONTROL_SIZE 0 #ifndef ASM typedef uint16_t Priority_bit_map_Word; typedef struct { - uint32_t x[32];; + unsigned long x[32];; } CPU_Exception_frame; /** @@ -321,7 +341,7 @@ void _CPU_ISR_install_raw_handler( */ void _CPU_ISR_install_vector( - uint32_t vector, + unsigned long vector, proc_ptr new_handler, proc_ptr *old_handler ); @@ -423,8 +443,8 @@ void _CPU_Context_restore_fp( * */ -static inline unsigned int CPU_swap_u32( - unsigned int value +static inline uint32_t CPU_swap_u32( + uint32_t value ) { uint32_t byte1, byte2, byte3, byte4, swapped; diff --git a/cpukit/score/cpu/riscv32/rtems/score/cpu_asm.h b/cpukit/score/cpu/riscv/rtems/score/cpu_asm.h index b5a56f3e22..b5a56f3e22 100644 --- a/cpukit/score/cpu/riscv32/rtems/score/cpu_asm.h +++ b/cpukit/score/cpu/riscv/rtems/score/cpu_asm.h diff --git a/cpukit/score/cpu/riscv32/rtems/score/cpuatomic.h b/cpukit/score/cpu/riscv/rtems/score/cpuatomic.h index 8ee9606b44..8ee9606b44 100644 --- a/cpukit/score/cpu/riscv32/rtems/score/cpuatomic.h +++ b/cpukit/score/cpu/riscv/rtems/score/cpuatomic.h diff --git a/cpukit/score/cpu/riscv32/rtems/score/cpuimpl.h b/cpukit/score/cpu/riscv/rtems/score/cpuimpl.h index 3904c84bf9..3904c84bf9 100644 --- a/cpukit/score/cpu/riscv32/rtems/score/cpuimpl.h +++ b/cpukit/score/cpu/riscv/rtems/score/cpuimpl.h diff --git a/cpukit/score/cpu/riscv32/rtems/score/riscv-utility.h b/cpukit/score/cpu/riscv/rtems/score/riscv-utility.h index dc4836bee2..dc4836bee2 100644 --- a/cpukit/score/cpu/riscv32/rtems/score/riscv-utility.h +++ b/cpukit/score/cpu/riscv/rtems/score/riscv-utility.h diff --git a/cpukit/score/cpu/riscv32/rtems/score/riscv.h b/cpukit/score/cpu/riscv/rtems/score/riscv.h index 6e7f1370c6..6e7f1370c6 100644 --- a/cpukit/score/cpu/riscv32/rtems/score/riscv.h +++ b/cpukit/score/cpu/riscv/rtems/score/riscv.h diff --git a/cpukit/score/cpu/riscv32/rtems/score/types.h b/cpukit/score/cpu/riscv/rtems/score/types.h index fe23b4ff76..d1440fb319 100644 --- a/cpukit/score/cpu/riscv32/rtems/score/types.h +++ b/cpukit/score/cpu/riscv/rtems/score/types.h @@ -1,7 +1,7 @@ /** * @file * - * @brief riscv32 Architecture Types API + * @brief RISC-V Architecture Types API */ /* |