- Timestamp:
- Aug 4, 2017, 2:03:44 PM (7 years ago)
- Location:
- trunk/hal/tsar_mips32/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/tsar_mips32/core/hal_context.c
r311 r317 23 23 24 24 #include <hal_types.h> 25 #include <hal_switch.h> 25 26 #include <memcpy.h> 26 27 #include <thread.h> … … 31 32 #include <core.h> 32 33 #include <cluster.h> 33 34 34 #include <hal_context.h> 35 35 … … 177 177 hal_cpu_context_t * ctx = (hal_cpu_context_t *)thread->cpu_context; 178 178 179 printk("\n*** cpu_context for thread %x in cluster %x / ctx = %x ***\n"179 printk("\n***** cpu_context for thread %x in cluster %x / ctx = %x\n" 180 180 " gp_28 = %X sp_29 = %X ra_31 = %X\n" 181 181 " c0_sr = %X c0_epc = %X c0_th = %X\n" … … 185 185 ctx->c0_sr , ctx->c0_epc , ctx->c0_th, 186 186 ctx->c2_ptpr , ctx->c2_mode ); 187 } 188 189 ///////////////////////////////////////////////////////////////////////////////////////// 190 // These registers are saved to CPU context defined by <ctx> argument. 187 188 } // end hal_context_display() 189 190 /* 191 //////////////////////////////////////////////////////////////////////////////////////// 192 // This static function makes the actual context switch. 193 //////////////////////////////////////////////////////////////////////////////////////// 194 static void hal_do_switch( hal_cpu_context_t * ctx_old, 195 hal_cpu_context_t * ctx_new ) 196 { 197 asm volatile( 198 ".set noat \n" 199 ".set noreorder \n" 200 "move $26, %0 \n" 201 202 "mfc0 $27, $14 \n" 203 "sw $27, 0*4($26) \n" 204 205 "sw $1, 1*4($26) \n" 206 "sw $2, 2*4($26) \n" 207 "sw $3, 3*4($26) \n" 208 "sw $4, 4*4($26) \n" 209 "sw $5, 5*4($26) \n" 210 "sw $6, 6*4($26) \n" 211 "sw $7, 7*4($26) \n" 212 213 "sw $8, 8*4($26) \n" 214 "sw $9, 9*4($26) \n" 215 "sw $10, 10*4($26) \n" 216 "sw $11, 11*4($26) \n" 217 "sw $12, 12*4($26) \n" 218 "sw $13, 13*4($26) \n" 219 "sw $14, 14*4($26) \n" 220 "sw $15, 15*4($26) \n" 221 222 "sw $16, 16*4($26) \n" 223 "sw $17, 17*4($26) \n" 224 "sw $18, 18*4($26) \n" 225 "sw $19, 19*4($26) \n" 226 "sw $20, 20*4($26) \n" 227 "sw $21, 21*4($26) \n" 228 "sw $22, 22*4($26) \n" 229 "sw $23, 23*4($26) \n" 230 231 "sw $24, 24*4($26) \n" 232 "sw $25, 25*4($26) \n" 233 234 "mfhi $27 \n" 235 "sw $27, 26*4($26) \n" 236 "mflo $27 \n" 237 "sw $27, 27*4($26) \n" 238 239 "sw $28, 28*4($26) \n" 240 "sw $29, 29*4($26) \n" 241 "sw $30, 30*4($26) \n" 242 "sw $31, 31*4($26) \n" 243 244 "mfc2 $27, $0 \n" 245 "sw $27, 32*4($26) \n" 246 "mfc2 $27, $1 \n" 247 "sw $27, 33*4($26) \n" 248 249 "mfc0 $27, $12 \n" 250 "sw $27, 34*4($26) \n" 251 "mfc0 $27, $4, 2 \n" 252 "sw $27, 35*4($26) \n" 253 254 "sync \n" 255 256 "move $26, %1 \n" 257 258 "lw $27, 0*4($26) \n" 259 "mtc0 $27, $14 \n" 260 261 "lw $1, 1*4($26) \n" 262 "lw $2, 2*4($26) \n" 263 "lw $3, 3*4($26) \n" 264 "lw $4, 4*4($26) \n" 265 "lw $5, 5*4($26) \n" 266 "lw $6, 6*4($26) \n" 267 "lw $7, 7*4($26) \n" 268 269 "lw $8, 8*4($26) \n" 270 "lw $9, 9*4($26) \n" 271 "lw $10, 10*4($26) \n" 272 "lw $11, 11*4($26) \n" 273 "lw $12, 12*4($26) \n" 274 "lw $13, 13*4($26) \n" 275 "lw $14, 14*4($26) \n" 276 "lw $15, 15*4($26) \n" 277 278 "lw $16, 16*4($26) \n" 279 "lw $17, 17*4($26) \n" 280 "lw $18, 18*4($26) \n" 281 "lw $19, 19*4($26) \n" 282 "lw $20, 20*4($26) \n" 283 "lw $21, 21*4($26) \n" 284 "lw $22, 22*4($26) \n" 285 "lw $23, 23*4($26) \n" 286 287 "lw $24, 24*4($26) \n" 288 "lw $25, 25*4($26) \n" 289 290 "lw $27, 26*4($26) \n" 291 "mthi $27 \n" 292 "lw $27, 27*4($26) \n" 293 "mtlo $27 \n" 294 295 "lw $28, 28*4($26) \n" 296 "lw $29, 29*4($26) \n" 297 "lw $30, 30*4($26) \n" 298 "lw $31, 31*4($26) \n" 299 300 "lw $27, 32*4($26) \n" 301 "mtc2 $27, $0 \n" 302 "lw $27, 33*4($26) \n" 303 "mtc2 $27, $1 \n" 304 305 "lw $27, 34*4($26) \n" 306 "mtc0 $27, $12 \n" 307 "lw $27, 35*4($26) \n" 308 "mtc0 $27, $4, 2 \n" 309 310 "jr $31 \n" 311 312 ".set reorder \n" 313 ".set at \n" 314 : : "r"(ctx_old) , "r"(ctx_new) : "$26" , "$27" , "memory" ); 315 316 } // hal_context_switch() 317 318 */ 319 320 ///////////////////////////////////////////////////////////////////////////////////////// 321 // These registers are saved/restored to/from CPU context defined by <ctx> argument. 191 322 // - GPR : all, but (zero, k0, k1), plus (hi, lo) 192 323 // - CP0 : c0_th , c0_sr 193 324 // - CP2 : c2_ptpr , C2_mode, C2_epc 194 325 ///////////////////////////////////////////////////////////////////////////////////////// 195 void hal_cpu_context_save( void * ctx ) 196 { 197 asm volatile( 198 ".set noat \n" 199 ".set noreorder \n" 200 "move $26, $4 \n" /* $26 <= &ctx */ 201 202 "mfc0 $27, $14 \n" 203 "sw $27, 0*4($26) \n" /* save c0_epc to slot 0 */ 204 205 "sw $1, 1*4($26) \n" 206 "sw $2, 2*4($26) \n" 207 "sw $3, 3*4($26) \n" 208 "sw $4, 4*4($26) \n" 209 "sw $5, 5*4($26) \n" 210 "sw $6, 6*4($26) \n" 211 "sw $7, 7*4($26) \n" 212 213 "sw $8, 8*4($26) \n" 214 "sw $9, 9*4($26) \n" 215 "sw $10, 10*4($26) \n" 216 "sw $11, 11*4($26) \n" 217 "sw $12, 12*4($26) \n" 218 "sw $13, 13*4($26) \n" 219 "sw $14, 14*4($26) \n" 220 "sw $15, 15*4($26) \n" 221 222 "sw $16, 16*4($26) \n" 223 "sw $17, 17*4($26) \n" 224 "sw $18, 18*4($26) \n" 225 "sw $19, 19*4($26) \n" 226 "sw $20, 20*4($26) \n" 227 "sw $21, 21*4($26) \n" 228 "sw $22, 22*4($26) \n" 229 "sw $23, 23*4($26) \n" 230 231 "sw $24, 24*4($26) \n" 232 "sw $25, 25*4($26) \n" 233 234 "mfhi $27 \n" 235 "sw $27, 26*4($26) \n" /* save hi to slot 26 */ 236 "mflo $27 \n" 237 "sw $27, 27*4($26) \n" /* save lo to slot 27 */ 238 239 "sw $28, 28*4($26) \n" 240 "sw $29, 29*4($26) \n" 241 "sw $30, 30*4($26) \n" 242 "sw $31, 31*4($26) \n" 243 244 "mfc2 $27, $0 \n" 245 "sw $27, 32*4($26) \n" /* save c2_ptpr to slot 32 */ 246 "mfc2 $27, $1 \n" 247 "sw $27, 33*4($26) \n" /* save c2_mode to slot 33 */ 248 249 "mfc0 $27, $12 \n" 250 "sw $27, 34*4($26) \n" /* save c0_sr to slot 34 */ 251 "mfc0 $27, $4, 2 \n" 252 "sw $27, 35*4($26) \n" /* save c0_th to slot 35 */ 253 254 "sync \n" 255 256 "move $4, $27 \n" 257 "jal hal_cpu_context_display \n" /* display context */ 258 "nop \n" 259 260 ".set reorder \n" 261 ".set at \n" 262 : : : "$26" , "$27" , "memory" ); 263 } 264 265 ///////////////////////////////////////////////////////////////////////////////////////// 266 // These registers are restored from cpu context defined by <ctx> argument: 267 // - GPR : all, but (zero, k0, k1), plus (hi, lo) 268 // - CP0 : c0_th , c0_sr 269 // - CP2 : c2_ptpr , C2_mode 270 ///////////////////////////////////////////////////////////////////////////////////////// 271 void hal_cpu_context_restore( void * ctx ) 272 { 273 asm volatile( 274 ".set noat \n" 275 ".set noreorder \n" 276 "move $26, $4 \n" /* $26 <= &ctx */ 277 278 "lw $4, 35*4($26) \n" 279 "jal hal_cpu_context_display \n" /* display context */ 280 "nop \n" 281 282 "lw $27, 0*4($26) \n" 283 "mtc0 $27, $14 \n" /* restore C0_epc from slot 0 */ 284 285 "lw $1, 1*4($26) \n" 286 "lw $2, 2*4($26) \n" 287 "lw $3, 3*4($26) \n" 288 "lw $4, 4*4($26) \n" 289 "lw $5, 5*4($26) \n" 290 "lw $6, 6*4($26) \n" 291 "lw $7, 7*4($26) \n" 292 293 "lw $8, 8*4($26) \n" 294 "lw $9, 9*4($26) \n" 295 "lw $10, 10*4($26) \n" 296 "lw $11, 11*4($26) \n" 297 "lw $12, 12*4($26) \n" 298 "lw $13, 13*4($26) \n" 299 "lw $14, 14*4($26) \n" 300 "lw $15, 15*4($26) \n" 301 302 "lw $16, 16*4($26) \n" 303 "lw $17, 17*4($26) \n" 304 "lw $18, 18*4($26) \n" 305 "lw $19, 19*4($26) \n" 306 "lw $20, 20*4($26) \n" 307 "lw $21, 21*4($26) \n" 308 "lw $22, 22*4($26) \n" 309 "lw $23, 23*4($26) \n" 310 311 "lw $24, 24*4($26) \n" 312 "lw $25, 25*4($26) \n" 313 314 "lw $27, 26*4($26) \n" 315 "mthi $27 \n" /* restore hi from slot 26 */ 316 "lw $27, 27*4($26) \n" 317 "mtlo $27 \n" /* restote lo from slot 27 */ 318 319 "lw $28, 28*4($26) \n" 320 "lw $29, 29*4($26) \n" 321 "lw $30, 30*4($26) \n" 322 "lw $31, 31*4($26) \n" 323 324 "lw $27, 32*4($26) \n" 325 "mtc2 $27, $0 \n" /* restore c2_ptpr from slot 32 */ 326 "lw $27, 33*4($26) \n" 327 "mtc2 $27, $1 \n" /* restore c2_mode from slot 33 */ 328 329 "lw $27, 34*4($26) \n" 330 "mtc0 $27, $12 \n" /* restore c0_sr from slot 34 */ 331 "lw $27, 35*4($26) \n" 332 "mtc0 $27, $4, 2 \n" /* restore co_th from slot 35 */ 333 334 ".set reorder \n" 335 ".set at \n" 336 : : : "$26" , "$27" ); 337 } 338 339 void hal_cpu_context_switch( thread_t * old , thread_t * new ) 340 { 341 // XXX XXX: TODO 342 hal_cpu_context_save( old->cpu_context ); 343 hal_cpu_context_restore( new->cpu_context ); 326 void hal_cpu_context_switch( thread_t * old, 327 thread_t * new ) 328 { 329 hal_cpu_context_t * ctx_old = old->cpu_context; 330 hal_cpu_context_t * ctx_new = new->cpu_context; 331 332 #if CONFIG_CONTEXT_DEBUG 333 hal_cpu_context_display( old ); 334 hal_cpu_context_display( new ); 335 #endif 336 337 hal_do_switch( ctx_old , ctx_new ); 344 338 } 345 339 … … 368 362 369 363 return 0; 364 370 365 } // end hal_cpu_context_copy() 371 366 … … 380 375 381 376 } // end hal_cpu_context_destroy() 377 378 379 380 382 381 383 382 /////////////////////////////////////////////////// -
trunk/hal/tsar_mips32/core/hal_exception.c
r296 r317 72 72 { 73 73 case XCODE_DBE: // can be non fatal 74 case XCODE_IBE: // ca n be non fatal74 case XCODE_IBE: // call generic excepton handler for a MMU exception 75 75 { 76 // call generic excepton handler for a MMU exception77 76 error = do_exception( this , true ); 78 77 } … … 80 79 81 80 case XCODE_CPU: // can be non fatal 81 // call generic excepton handler for a FPU exception 82 82 { 83 83 if( ((regs_tbl[UZ_CR] >> 28) & 0x3) == 1 ) // unavailable FPU 84 84 { 85 // call generic excepton handler for a FPU exception86 85 error = do_exception( this , false ); 87 86 } 88 87 else 89 88 { 90 printk("\n[ERROR] in thread %x / unsupported coprocessor type\n",91 this->trdid );92 89 error = EXCP_USER_ERROR; 93 90 } … … 96 93 97 94 case XCODE_OVR: // user fatal error 95 case XCODE_RI: // user fatal error 96 case XCODE_ADEL: // user fatal error 97 case XCODE_ADES: // kill process 98 98 { 99 printk("\n[ERROR] in thread %x / arithmetic overflow\n",100 this->trdid );101 99 error = EXCP_USER_ERROR; 102 100 } 103 101 break; 104 102 105 case XCODE_RI: // user fatal error106 {107 printk("\n[ERROR] in thread %x / Illegal Codop\n",108 this->trdid );109 error = EXCP_USER_ERROR;110 }111 break;112 113 case XCODE_ADEL: // user fatal error114 115 case XCODE_ADES:116 {117 printk("\n[ERROR] in thread %x / illegal address\n",118 this->trdid );119 error = EXCP_USER_ERROR;120 }121 break;122 123 103 default: 124 104 { 125 printk("\n[PANIC] in %s for thread %x / illegal XCODE value = %x\n", 126 __FUNCTION__ , this->trdid , excCode ); 127 error = EXCP_USER_ERROR; 105 error = EXCP_KERNEL_PANIC; 128 106 } 129 107 } 130 108 131 109 // analyse error code 132 if( error == EXCP_USER_ERROR ) // user error => kill the user process and return110 if( error == EXCP_USER_ERROR ) // user error => kill user process 133 111 { 134 112 hal_exception_dump( this , regs_tbl ); … … 150 128 151 129 if( this->type == THREAD_USER ) 152 printk("\n================= USER ERROR =======================================\n"); 130 printk("\n================= USER ERROR / cycle %d ====================\n", 131 hal_time_stamp() ); 153 132 else 154 printk("\n================= KERNEL PANIC =====================================\n"); 133 printk("\n================= KERNEL PANIC / cycle %d ==================\n", 134 hal_time_stamp() ); 155 135 156 136 printk(" thread type = %s / trdid = %x / pid %x / core[%x,%d]\n"
Note: See TracChangeset
for help on using the changeset viewer.