Changeset 425 for trunk/hal/tsar_mips32/core
- Timestamp:
- Jan 29, 2018, 5:57:57 PM (7 years ago)
- Location:
- trunk/hal/tsar_mips32/core
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/tsar_mips32/core/hal_exception.c
r416 r425 284 284 default: // this is a kernel error => panic 285 285 { 286 printk("\n[PANIC] in %s for thread %x : kernel exception= %x / vaddr = %x\n",287 __FUNCTION__ ,this->trdid , excp_code , bad_vaddr );286 assert( false , __FUNCTION__ , "thread %x / excp_code = %x / vaddr = %x\n", 287 this->trdid , excp_code , bad_vaddr ); 288 288 289 289 return EXCP_KERNEL_PANIC; … … 297 297 ////////////////////////////////////////////////////////////////////////////////////////// 298 298 // @ this : pointer on faulty thread descriptor. 299 // @ uzone : pointer on register array.299 // @ uzone : pointer on register array. 300 300 // @ error : EXCP_USER_ERROR or EXCP_KERNEL_PANIC 301 301 ////////////////////////////////////////////////////////////////////////////////////////// … … 372 372 // get pointer on faulty thread uzone 373 373 this = CURRENT_THREAD; 374 uzone = (uint32_t *)CURRENT_THREAD->uzone ;374 uzone = (uint32_t *)CURRENT_THREAD->uzone_current; 375 375 376 376 // get 4 bits XCODE from CP0_CR register … … 424 424 hal_exception_dump( this , uzone , error ); 425 425 426 // FIXME : replace this loop by sys_kill() 427 while( 1 ) asm volatile ("nop"); 428 // sys_kill( this->process->pid , SIGKILL ); 426 sys_kill( this->process->pid , SIGKILL ); 429 427 } 430 428 else if( error == EXCP_KERNEL_PANIC ) // kernel error => kernel panic 431 429 { 432 430 hal_exception_dump( this , uzone , error ); 433 panic( "for thread %x in process %x on core [%x,%d]", 431 432 assert( false , __FUNCTION__ , "thread %x in process %x on core [%x,%d]", 434 433 this->trdid , this->process->pid , local_cxy , this->core->lid ); 435 434 } -
trunk/hal/tsar_mips32/core/hal_kentry.S
r418 r425 119 119 #------------------------------------------------------------------------------------ 120 120 # This code is executed when the core is already in kernel mode, 121 # after a syscall, to handle an interrupt .121 # after a syscall, to handle an interrupt, or to handle a non-fatal exception. 122 122 # - save current c2_mode in $26. 123 123 # - set MMU OFF. … … 286 286 287 287 #------------------------------------------------------------------------------------ 288 # This code calls the relevant Interrupt / Exception / Syscall handler, 289 # depending on XCODE in CP0_CR. 290 # In case of syscall or exception, it set the "uzone" pointer in thread descriptor, 291 # that is used by the hal_do_syscall() & hal_do_exception() functions. 292 # WARNING: This "uzone" pointer is NOT modified in case of interrupt, 293 # because syscalls can be interrupted, and we want preserve this pointer. 294 288 # This code handle the uzone pointers stack, and calls the relevant 289 # Interrupt / Exception / Syscall handler, depending on XCODE in CP0_CR. 290 # Both the hal_do_syscall() and the hal_do_exception() functions use 291 # the values saved in the "uzone", but a syscall can be interrupted 292 # by an interrupt, or by a non-fatal exception. Therefore, we need 293 # to handle a two-slots "stack of uzones", implemented in the kernel stack, 294 # using the two "current_uzone" and "previous_uzone" pointers in thread descriptor. 295 # - at kernel_entry, we copy the "current_uzone" pointer to the "previous_uzone" 296 # slot, and copy the "$29" stack pointer to the "current_uzone" slot. 297 # - at kernel_exit, we simply restore the "previous_uzone" value to the 298 # "current_uzone" slot. 299 # For a syscall, the hal_do_syscall() function increment the uzone[EPC] 300 # slot and set the return value in the uzone[V0] slot before returning. 301 302 # update "current_uzone" and "previous_uzone" pointers 303 mfc0 $4, $4, 2 # $4 <= pointer on thread desc 304 lw $5, 8($4) # $5 <= current uzone pointer trom thread 305 sw $29, 8($4) # current uzone pointer <= $29 306 sw $5, 12($4) # previous uzone pointer <= current 307 308 # analyse XCODE to call relevant handler 295 309 mfc0 $17, $13 # $17 <= CR 296 andi $17, $17, 0x3F# $17 <= XCODE310 andi $17, $17, 0x3F # $17 <= XCODE 297 311 ori $8, $0, 0x20 298 312 beq $8, $17, cause_sys # go to syscall handler … … 302 316 303 317 cause_excp: 304 mfc0 $4, $4, 2 # get pointer on thread desc 305 sw $29, 8($4) # update uzone pointer in thread desc 318 306 319 jal hal_do_exception # call exception handler 307 320 nop … … 310 323 311 324 cause_sys: 312 mfc0 $4, $4, 2 # get pointer on thread desc 313 sw $29, 8($4) # update uzone pointer in thread desc 325 314 326 jal hal_do_syscall # call syscall handler 315 327 nop … … 318 330 319 331 cause_int: 332 320 333 jal hal_do_interrupt # call interrupt handler 321 334 nop … … 330 343 331 344 kentry_exit: 345 346 # restore "current_uzone" pointer 347 mfc0 $4, $4, 2 # $4 <= pointer on thread desc 348 lw $5, 12($4) # $5 <= previous uzone pointer from thread 349 sw $5, 8($4) # current uzone pointer <= previous 332 350 333 351 #---------------------- -
trunk/hal/tsar_mips32/core/hal_special.c
r407 r425 206 206 void hal_core_sleep() 207 207 { 208 asm volatile ("wait");208 while( 1 ) asm volatile ("nop"); 209 209 } 210 210 -
trunk/hal/tsar_mips32/core/hal_syscall.c
r418 r425 29 29 #include <hal_kentry.h> 30 30 31 // @@@32 // __attribute__((section(".kdata"))) uint32_t * enter_uzone;33 // __attribute__((section(".kdata"))) uint32_t * exit_uzone;34 // @@@35 36 31 ///////////////////// 37 32 void hal_do_syscall() … … 51 46 // get pointer on enter_thread uzone 52 47 this = CURRENT_THREAD; 53 enter_uzone = (uint32_t *)this->uzone; 48 enter_uzone = (uint32_t *)this->uzone_current; 49 50 //printk("\n@@@ enter %s : thread = %x / enter_uzone = %x / EPC = %x\n", 51 //__FUNCTION__ , this , enter_uzone , enter_uzone[UZ_EPC] ); 54 52 55 53 // get syscall arguments from uzone … … 68 66 service_num ); 69 67 70 // get pointer on exit_thread uzone, 68 // get pointer on exit_thread uzone, because 71 69 // exit_thread can be different from enter_thread 72 70 this = CURRENT_THREAD; 73 exit_uzone = (uint32_t *)this->uzone ;71 exit_uzone = (uint32_t *)this->uzone_current; 74 72 75 // printk("\n@@@ %s exit : enter_uzone = %x / exit_uzone = %x\n",76 // __FUNCTION__ , enter_uzone , exit_uzone);73 //printk("\n@@@ exit %s : thread = %x / exit_uzone = %x / EPC = %x\n", 74 //__FUNCTION__ , this , exit_uzone , exit_uzone[UZ_EPC] ); 77 75 78 // set syscallreturn value to uzone76 // set return value to uzone 79 77 exit_uzone[UZ_V0] = retval; 80 78 -
trunk/hal/tsar_mips32/core/hal_user.c
r407 r425 30 30 int arg3 ) 31 31 { 32 register int reg_num_and_ret __asm__("v0") = service_num;33 register int reg_a0 __asm__("a0") = arg0;34 register int reg_a1 __asm__("a1") = arg1;35 register int reg_a2 __asm__("a2") = arg2;36 register int reg_a3 __asm__("a3") = arg3;32 register int num_and_ret __asm__("v0") = service_num; 33 register int a0 __asm__("a0") = arg0; 34 register int a1 __asm__("a1") = arg1; 35 register int a2 __asm__("a2") = arg2; 36 register int a3 __asm__("a3") = arg3; 37 37 38 __asm__volatile(38 asm volatile( 39 39 "syscall" 40 : "+r" (reg_num_and_ret), 41 "+r" (reg_a0), 42 "+r" (reg_a1), 43 "+r" (reg_a2), 44 "+r" (reg_a3) 45 : 40 : "+r" (num_and_ret) 41 : "r" (a0), 42 "r" (a1), 43 "r" (a2), 44 "r" (a3) 46 45 : "memory", 47 46 "at", … … 60 59 ); 61 60 62 return (volatile int) reg_num_and_ret;61 return (volatile int)num_and_ret; 63 62 } 64 63 -
trunk/hal/tsar_mips32/core/hal_uspace.c
r407 r425 29 29 #include <hal_irqmask.h> 30 30 31 #include <printk.h> 32 #include <thread.h> 33 31 34 /////////////////////////////////////////// 32 35 void hal_copy_from_uspace( void * k_dst, 33 36 void * u_src, 34 uint32_t size ) 37 uint32_t size ) 35 38 { 36 39 uint32_t save_sr; … … 136 139 { 137 140 uint32_t save_sr; 138 139 141 uint32_t src = (uint32_t)u_src; 140 142 uint32_t dst = (uint32_t)k_dst; … … 142 144 hal_disable_irq( &save_sr ); 143 145 144 // loop on characters while ( (character != NUL) and (count < size ) 146 // loop on characters while ( (character != NUL) and (count < size ) ) 145 147 asm volatile( 146 148 ".set noreorder \n" … … 148 150 "move $12, %1 \n" /* $12 <= u_src */ 149 151 "move $13, %2 \n" /* $13 <= k_dst */ 150 "mfc2 $15, $1 \n" /* $15 <= MMU_MODE*/151 "ori $14, $15, 0x 7\n" /* $14 <= mode DTLB on */152 "mfc2 $15, $1 \n" /* $15 <= mode DTLB and ITLB off */ 153 "ori $14, $15, 0x4 \n" /* $14 <= mode DTLB on */ 152 154 "1: \n" 153 155 "mtc2 $14, $1 \n" /* MMU_MODE <= DTLB ON */ 154 156 "lb $10, 0($12) \n" /* read char from user space */ 155 "mtc2 $15, $1 \n" /* restore MMU_MODE*/157 "mtc2 $15, $1 \n" /* restore DTLB and ITLB off */ 156 158 "sb $10, 0($13) \n" /* store char to kernel space */ 157 "beq $1 3, $0, 2f \n" /* exit if char = 0 */159 "beq $10, $0, 2f \n" /* exit if char = 0 */ 158 160 "addi $11, $11, -1 \n" /* decrement count */ 159 161 "addi $12, $12, 1 \n" /* increment u_src pointer */ … … 178 180 { 179 181 uint32_t save_sr; 180 181 182 uint32_t src = (uint32_t)k_src; 182 183 uint32_t dst = (uint32_t)u_dst; … … 190 191 "move $12, %1 \n" /* $12 <= k_src */ 191 192 "move $13, %2 \n" /* $13 <= u_dst */ 192 "mfc2 $15, $1 \n" /* $15 <= MMU_MODE*/193 "ori $14, $15, 0x 7\n" /* $14 <= mode DTLB on */193 "mfc2 $15, $1 \n" /* $15 <= mode DTLB and ITLB off */ 194 "ori $14, $15, 0x4 \n" /* $14 <= mode DTLB on */ 194 195 "1: \n" 195 196 "lb $10, 0($12) \n" /* read char from kernel space */ 196 197 "mtc2 $14, $1 \n" /* MMU_MODE <= DTLB ON */ 197 198 "sb $10, 0($13) \n" /* store char to user space */ 198 "mtc2 $15, $1 \n" /* restore MMU_MODE*/199 "beq $1 3, $0, 2f \n" /* exit if char == 0 */199 "mtc2 $15, $1 \n" /* restore DTLB and ITLB off */ 200 "beq $10, $0, 2f \n" /* exit if char == 0 */ 200 201 "addi $11, $11, -1 \n" /* decrement count */ 201 202 "addi $12, $12, 1 \n" /* increment k_src pointer */ … … 219 220 uint32_t save_sr; 220 221 uint32_t count = 0; 221 222 uint32_t str = (uint32_t)u_str; 222 uint32_t str = (uint32_t)u_str; 223 223 224 224 hal_disable_irq( &save_sr ); … … 226 226 asm volatile( 227 227 ".set noreorder \n" 228 "ori $13, %1, 0 \n" /* $13 <= str */ 229 "mfc2 $15, $1 \n" /* $15 <= MMU_MODE */ 230 "ori $14, $15, 0x7 \n" /* $14 <= mode DTLB on */ 231 "mtc2 $14, $1 \n" /* MMU_MODE <= DTLB ON */ 228 "move $13, %1 \n" /* $13 <= str */ 229 "mfc2 $15, $1 \n" /* $15 <= DTLB and ITLB off */ 230 "ori $14, $15, 0x4 \n" /* $14 <= mode DTLB on */ 232 231 "1: \n" 232 "mtc2 $14, $1 \n" /* set DTLB on */ 233 233 "lb $12, 0($13) \n" /* read char from user space */ 234 "mtc2 $15, $1 \n" /* set DTLB off */ 234 235 "addi $13, $13, 1 \n" /* increment address */ 235 236 "bne $12, $0, 1b \n" /* loop until NUL found */ 236 237 "addi %0, %0, 1 \n" /* increment count */ 237 "mtc2 $15, $1 \n" /* restore MMU_MODE */238 238 ".set reorder \n" 239 239 : "+r"(count)
Note: See TracChangeset
for help on using the changeset viewer.