Changeset 1b109cb in mainline
- Timestamp:
- 2006-03-20T13:39:56Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9d3e185
- Parents:
- 8d25b44
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
arch/mips32/include/cp0.h
r8d25b44 r1b109cb 59 59 #define cp0_unmask_int(it) cp0_status_write(cp0_status_read() | (1<<(cp0_status_im_shift+(it)))) 60 60 61 extern __u32 cp0_index_read(void); 62 extern void cp0_index_write(__u32 val); 61 #define GEN_READ_CP0(nm,reg) static inline __u32 cp0_ ##nm##_read(void) \ 62 { \ 63 __u32 retval; \ 64 asm("mfc0 %0, $" #reg : "=r"(retval)); \ 65 return retval; \ 66 } 63 67 64 extern __u32 cp0_random_read(void); 68 #define GEN_WRITE_CP0(nm,reg) static inline void cp0_ ##nm##_write(__u32 val) \ 69 { \ 70 asm("mtc0 %0, $" #reg : : "r"(val) ); \ 71 } 65 72 66 extern __u32 cp0_entry_lo0_read(void);67 extern void cp0_entry_lo0_write(__u32 val);73 GEN_READ_CP0(index, 0); 74 GEN_WRITE_CP0(index, 0); 68 75 69 extern __u32 cp0_entry_lo1_read(void); 70 extern void cp0_entry_lo1_write(__u32 val); 76 GEN_READ_CP0(random, 1); 71 77 72 extern __u32 cp0_context_read(void);73 extern void cp0_context_write(__u32 val);78 GEN_READ_CP0(entry_lo0, 2); 79 GEN_WRITE_CP0(entry_lo0, 2); 74 80 75 extern __u32 cp0_pagemask_read(void);76 extern void cp0_pagemask_write(__u32 val);81 GEN_READ_CP0(entry_lo1, 3); 82 GEN_WRITE_CP0(entry_lo1, 3); 77 83 78 extern __u32 cp0_wired_read(void);79 extern void cp0_wired_write(__u32 val);84 GEN_READ_CP0(context, 4); 85 GEN_WRITE_CP0(context, 4); 80 86 81 extern __u32 cp0_badvaddr_read(void); 87 GEN_READ_CP0(pagemask, 5); 88 GEN_WRITE_CP0(pagemask, 5); 82 89 83 extern __u32 cp0_count_read(void);84 extern void cp0_count_write(__u32 val);90 GEN_READ_CP0(wired, 6); 91 GEN_WRITE_CP0(wired, 6); 85 92 86 extern __u32 cp0_entry_hi_read(void); 87 extern void cp0_entry_hi_write(__u32 val); 93 GEN_READ_CP0(badvaddr, 8); 88 94 89 extern __u32 cp0_compare_read(void);90 extern void cp0_compare_write(__u32 val);95 GEN_READ_CP0(count, 9); 96 GEN_WRITE_CP0(count, 9); 91 97 92 extern __u32 cp0_status_read(void);93 extern void cp0_status_write(__u32 val);98 GEN_READ_CP0(entry_hi, 10); 99 GEN_WRITE_CP0(entry_hi, 10); 94 100 95 extern __u32 cp0_cause_read(void);96 extern void cp0_cause_write(__u32 val);101 GEN_READ_CP0(compare, 11); 102 GEN_WRITE_CP0(compare, 11); 97 103 98 extern __u32 cp0_epc_read(void);99 extern void cp0_epc_write(__u32 val);104 GEN_READ_CP0(status, 12); 105 GEN_WRITE_CP0(status, 12); 100 106 101 extern __u32 cp0_prid_read(void); 107 GEN_READ_CP0(cause, 13); 108 GEN_WRITE_CP0(cause, 13); 109 110 GEN_READ_CP0(epc, 14); 111 GEN_WRITE_CP0(epc, 14); 112 113 GEN_READ_CP0(prid, 15); 102 114 103 115 #endif -
arch/mips32/include/exception.h
r8d25b44 r1b109cb 99 99 extern void cache_error_entry(void); 100 100 extern void exception_init(void); 101 extern __native syscall_handler(__native a0, __native a1, __native a2, 102 __native a3, __native sysnum); 101 103 #endif -
arch/mips32/include/thread.h
r8d25b44 r1b109cb 32 32 #include <arch/exception.h> 33 33 34 #define ARCH_THREAD_DATA istate_t *istate34 #define ARCH_THREAD_DATA 35 35 36 36 #endif -
arch/mips32/src/asm.S
r8d25b44 r1b109cb 46 46 .set noreorder 47 47 .set nomacro 48 49 .global cp0_index_read50 .global cp0_index_write51 .global cp0_random_read52 .global cp0_entry_lo0_read53 .global cp0_entry_lo0_write54 .global cp0_entry_lo1_read55 .global cp0_entry_lo1_write56 .global cp0_context_read57 .global cp0_context_write58 .global cp0_pagemask_read59 .global cp0_pagemask_write60 .global cp0_wired_read61 .global cp0_wired_write62 .global cp0_badvaddr_read63 .global cp0_count_read64 .global cp0_count_write65 .global cp0_entry_hi_read66 .global cp0_entry_hi_write67 .global cp0_compare_read68 .global cp0_compare_write69 .global cp0_status_read70 .global cp0_status_write71 .global cp0_cause_read72 .global cp0_cause_write73 .global cp0_epc_read74 .global cp0_epc_write75 .global cp0_prid_read76 77 cp0_index_read: cp0_read $078 cp0_index_write: cp0_write $079 80 cp0_random_read: cp0_read $181 82 cp0_entry_lo0_read: cp0_read $283 cp0_entry_lo0_write: cp0_write $284 85 cp0_entry_lo1_read: cp0_read $386 cp0_entry_lo1_write: cp0_write $387 88 cp0_context_read: cp0_read $489 cp0_context_write: cp0_write $490 91 cp0_pagemask_read: cp0_read $592 cp0_pagemask_write: cp0_write $593 94 cp0_wired_read: cp0_read $695 cp0_wired_write: cp0_write $696 97 cp0_badvaddr_read: cp0_read $898 99 cp0_count_read: cp0_read $9100 cp0_count_write: cp0_write $9101 102 cp0_entry_hi_read: cp0_read $10103 cp0_entry_hi_write: cp0_write $10104 105 cp0_compare_read: cp0_read $11106 cp0_compare_write: cp0_write $11107 108 cp0_status_read: cp0_read $12109 cp0_status_write: cp0_write $12110 111 cp0_cause_read: cp0_read $13112 cp0_cause_write: cp0_write $13113 114 cp0_epc_read: cp0_read $14115 cp0_epc_write: cp0_write $14116 117 cp0_prid_read: cp0_read $15118 119 48 120 49 .global cpu_halt -
arch/mips32/src/exception.c
r8d25b44 r1b109cb 130 130 } 131 131 132 #include <debug.h> 132 __native syscall_handler(__native a0, __native a1, __native a2, 133 __native a3, __native sysnum) 134 { 135 if (sysnum < SYSCALL_END) 136 return syscall_table[sysnum](a0,a1,a2,a3); 137 panic("Undefined syscall %d", sysnum); 138 } 139 133 140 /** Handle syscall userspace call */ 134 141 static void syscall_exception(int n, istate_t *istate) 135 142 { 136 interrupts_enable(); 137 if (istate->t0 < SYSCALL_END) 138 istate->v0 = syscall_table[istate->t0](istate->a0, 139 istate->a1, 140 istate->a2, 141 istate->a3); 142 else 143 panic("Undefined syscall %d", istate->a3); 144 istate->epc += 4; 145 interrupts_disable(); 146 } 147 148 void exception(istate_t *istate) 149 { 150 int cause; 151 int excno; 152 153 ASSERT(CPU != NULL); 154 155 /* 156 * NOTE ON OPERATION ORDERING 157 * 158 * On entry, interrupts_disable() must be called before 159 * exception bit is cleared. 160 */ 161 162 interrupts_disable(); 163 cp0_status_write(cp0_status_read() & ~ (cp0_status_exl_exception_bit | 164 cp0_status_um_bit)); 165 166 /* Save istate so that the threads can access it */ 167 /* If THREAD->istate is set, this is nested exception, 168 * do not rewrite it 169 */ 170 if (THREAD && !THREAD->istate) 171 THREAD->istate = istate; 172 173 cause = cp0_cause_read(); 174 excno = cp0_cause_excno(cause); 175 /* Dispatch exception */ 176 exc_dispatch(excno, istate); 177 178 /* Set to NULL, so that we can still support nested 179 * exceptions 180 * TODO: We should probably set EXL bit before this command, 181 * nesting. On the other hand, if some exception occurs between 182 * here and ERET, it won't set anything on the istate anyway. 183 */ 184 if (THREAD) 185 THREAD->istate = NULL; 143 panic("Syscall is handled through shortcut"); 186 144 } 187 145 -
arch/mips32/src/fpu_context.c
r8d25b44 r1b109cb 37 37 #ifdef ARCH_HAS_FPU 38 38 cp0_status_write(cp0_status_read() & ~cp0_status_fpu_bit); 39 if (THREAD && THREAD->istate)40 THREAD->istate->status &= ~cp0_status_fpu_bit;41 39 #endif 42 40 } … … 46 44 #ifdef ARCH_HAS_FPU 47 45 cp0_status_write(cp0_status_read() | cp0_status_fpu_bit); 48 if (THREAD && THREAD->istate)49 THREAD->istate->status |= cp0_status_fpu_bit;50 46 #endif 51 47 } -
arch/mips32/src/start.S
r8d25b44 r1b109cb 44 44 .global userspace_asm 45 45 46 # Which status bits should are thread-local 47 #define REG_SAVE_MASK 0x1f # KSU(UM), EXL, ERL, IE 48 46 49 # Save registers to space defined by \r 47 # We will change $at on the way 48 .macro REGISTERS_STORE r 50 # We will change status: Disable ERL,EXL,UM,IE 51 # These changes will be automatically reversed in REGISTER_LOAD 52 .macro REGISTERS_STORE_AND_EXC_RESET r 49 53 sw $at,EOFFSET_AT(\r) 50 54 sw $v0,EOFFSET_V0(\r) … … 86 90 sw $sp,EOFFSET_SP(\r) 87 91 88 mfc0 $at, $status 89 sw $at,EOFFSET_STATUS(\r) 90 mfc0 $at, $epc 91 sw $at,EOFFSET_EPC(\r) 92 mfc0 $t0, $status 93 mfc0 $t1, $epc 94 95 and $t2, $t0, REG_SAVE_MASK # Save only KSU,EXL,ERL,IE 96 li $t3, ~(0x1f) 97 and $t0, $t0, $t3 # Clear KSU,EXL,ERL,IE 98 99 sw $t2,EOFFSET_STATUS(\r) 100 sw $t1,EOFFSET_EPC(\r) 101 mtc0 $t0, $status 92 102 .endm 93 103 94 104 .macro REGISTERS_LOAD r 105 # Update only UM,EXR,IE from status, the rest 106 # is controlled by OS and not bound to task 107 mfc0 $t0, $status 108 lw $t1,EOFFSET_STATUS(\r) 109 110 li $t2, ~REG_SAVE_MASK # Mask UM,EXL,ERL,IE 111 and $t0, $t0, $t2 112 113 or $t0, $t0, $t1 # Copy UM,EXL,ERL,IE from saved status 114 mtc0 $t0, $status 115 95 116 lw $v0,EOFFSET_V0(\r) 96 117 lw $v1,EOFFSET_V1(\r) … … 129 150 mthi $at 130 151 131 lw $at,EOFFSET_STATUS(\r)132 mtc0 $at, $status133 152 lw $at,EOFFSET_EPC(\r) 134 153 mtc0 $at, $epc … … 189 208 exception_handler: 190 209 KERNEL_STACK_TO_K0 210 211 mfc0 $k1, $cause 191 212 sub $k0, REGISTER_SPACE 192 REGISTERS_STORE $k0 193 add $sp, $k0, 0 194 195 add $a0, $sp, 0 196 jal exception /* exception(register_space) */ 197 nop 213 214 sra $k1, $k1, 0x2 # cp0_exc_cause() part 1 215 andi $k1, $k1, 0x1f # cp0_exc_cause() part 2 216 sub $k1, 8 # 8=SYSCALL 217 218 beqz $k1, uspace_shortcut 219 add $k1, 8 # Revert $k1 back to correct exc number 220 221 REGISTERS_STORE_AND_EXC_RESET $k0 222 move $sp, $k0 223 224 move $a1, $sp 225 jal exc_dispatch # exc_dispatch(excno, register_space) 226 move $a0, $k1 198 227 199 228 REGISTERS_LOAD $sp … … 201 230 eret 202 231 nop 232 233 # it seems that mips reserves some space on stack for varfuncs??? 234 #define SS_ARG4 16 235 #define SS_SP 20 236 #define SS_STATUS 24 237 #define SS_EPC 28 238 #define SS_RA 32 239 uspace_shortcut: 240 # We have a lot of space on the stack, with free use 241 sw $sp, SS_SP($k0) 242 move $sp, $k0 243 sw $ra, SS_RA($k0) 244 245 mfc0 $t1, $epc 246 mfc0 $t0, $status 247 sw $t1,SS_EPC($sp) # Save EPC 248 249 and $t2, $t0, REG_SAVE_MASK # Save only KSU,EXL,ERL,IE 250 li $t3, ~(0x1f) 251 and $t0, $t0, $t3 # Clear KSU,EXL,ERL 252 ori $t0, $t0, 0x1 # Set IE 253 254 sw $t2,SS_STATUS($sp) 255 mtc0 $t0, $status 256 257 jal syscall_handler 258 sw $v0, SS_ARG4($sp) # save v0 - arg4 to stack 259 260 # Restore RA 261 lw $ra, SS_RA($sp) 262 263 # restore epc+4 264 lw $t0,SS_EPC($sp) 265 addi $t0, $t0, 4 266 mtc0 $t0, $epc 267 268 # restore status 269 mfc0 $t0, $status 270 lw $t1,SS_STATUS($sp) 271 272 li $t2, ~REG_SAVE_MASK # Mask UM,EXL,ERL,IE 273 and $t0, $t0, $t2 274 or $t0, $t0, $t1 # Copy UM,EXL,ERL,IE from saved status 275 mtc0 $t0, $status 276 277 lw $sp,SS_SP($sp) # restore sp 278 279 eret 203 280 204 281 tlb_refill_handler: 205 282 KERNEL_STACK_TO_K0 206 283 sub $k0, REGISTER_SPACE 207 REGISTERS_STORE $k0284 REGISTERS_STORE_AND_EXC_RESET $k0 208 285 add $sp, $k0, 0 209 286 … … 215 292 216 293 eret 217 nop218 294 219 295 cache_error_handler: 220 296 KERNEL_STACK_TO_K0 221 297 sub $sp, REGISTER_SPACE 222 REGISTERS_STORE $sp298 REGISTERS_STORE_AND_EXC_RESET $sp 223 299 add $sp, $k0, 0 224 300 … … 229 305 230 306 eret 231 nop232 307 233 308 userspace_asm: … … 235 310 add $v0, $a1, 0 236 311 eret 237 nop 238 312 -
contrib/conf/gxemul.sh
r8d25b44 r1b109cb 2 2 # Uspace addresses outside of normal memory (kernel has std. 8 or 16MB) 3 3 # we place the pages at 24M 4 gxemul -E testmips -X 0x81800000:init kernel.bin4 gxemul $@ -E testmips -X 0x81800000:init kernel.bin -
kernel.config
r8d25b44 r1b109cb 75 75 76 76 # Save all interrupt registers 77 ! [CONFIG_DEBUG=y&(ARCH=amd64|ARCH=mips )] CONFIG_DEBUG_ALLREGS (y/n)77 ! [CONFIG_DEBUG=y&(ARCH=amd64|ARCH=mips32)] CONFIG_DEBUG_ALLREGS (y/n) 78 78 79 79 ## Run-time configuration directives
Note:
See TracChangeset
for help on using the changeset viewer.