Jelajahi Sumber

[libcpu][c906] add clone support

jasonhu 4 tahun lalu
induk
melakukan
9a71c9e91a

+ 13 - 0
libcpu/risc-v/t-head/c906/cpuport.h

@@ -22,6 +22,19 @@
 // error here, not portable
 #endif
 
+/* 33 general register */
+#define CTX_GENERAL_REG_NR  33
+
+#ifdef ENABLE_FPU
+/* 32 fpu register */
+#define CTX_FPU_REG_NR  32
+#else
+#define CTX_FPU_REG_NR  0
+#endif
+
+/* all context registers */
+#define CTX_REG_NR  (CTX_GENERAL_REG_NR + CTX_FPU_REG_NR)
+
 #ifndef __ASSEMBLY__
 rt_inline void rt_hw_dsb()
 {

+ 4 - 4
libcpu/risc-v/t-head/c906/interrupt_gcc.S

@@ -71,9 +71,9 @@ __restore_sp_from_tcb_interrupt:
 __move_stack_context_interrupt:
     mv t1, sp//src
     mv sp, t0//switch stack
-    addi sp, sp, -33 * REGBYTES
+    addi sp, sp, -CTX_REG_NR * REGBYTES
     //copy context
-    li s0, 33//cnt
+    li s0, CTX_REG_NR//cnt
     mv t2, sp//dst
 
 copy_context_loop_interrupt:
@@ -121,9 +121,9 @@ __restore_sp_from_tcb:
 __move_stack_context:
     mv t1, sp//src
     mv sp, t0//switch stack
-    addi sp, sp, -33 * REGBYTES
+    addi sp, sp, -CTX_REG_NR * REGBYTES
     //copy context
-    li s0, 33//cnt
+    li s0, CTX_REG_NR//cnt
     mv t2, sp//dst
 
 copy_context_loop:

+ 1 - 1
libcpu/risc-v/t-head/c906/stack.h

@@ -49,7 +49,7 @@ struct rt_hw_stack_frame
     rt_ubase_t t6;         /* x31 - t6     - temporary register 6                */
     rt_ubase_t user_sp_exc_stack;    /* sscratch - user mode sp/exception stack  */
 #ifdef ENABLE_FPU
-    rt_ubase_t f[32];      /* f0~f31 */
+    rt_ubase_t f[CTX_FPU_REG_NR];      /* f0~f31 */
 #endif
 };
 

+ 3 - 4
libcpu/risc-v/t-head/c906/stackframe.h

@@ -54,7 +54,7 @@
 .macro SAVE_ALL
 #ifdef ENABLE_FPU
     /* save float registers */
-    addi sp, sp, -32 * REGBYTES
+    addi sp, sp, -CTX_FPU_REG_NR * REGBYTES
 
     li  t0, SSTATUS_FS
     csrs sstatus, t0
@@ -101,8 +101,7 @@
 #endif /* ENABLE_FPU */
 
     /* save general registers */
-    addi sp, sp, -33 * REGBYTES
-
+    addi sp, sp, -CTX_GENERAL_REG_NR * REGBYTES
     STORE x1,   1 * REGBYTES(sp)
 
     csrr  x1, sstatus
@@ -189,7 +188,7 @@
 #ifdef ENABLE_FPU
     /* restore float register  */
     mv t2, sp
-    addi t2, t2, 33 * REGBYTES   /* skip all normal reg */
+    addi t2, t2, CTX_GENERAL_REG_NR * REGBYTES   /* skip all normal reg */
 
     li  t0, SSTATUS_FS
     csrs sstatus, t0