Changeset 279 for trunk/hal/tsar_mips32/core
- Timestamp:
- Jul 27, 2017, 12:23:29 AM (7 years ago)
- Location:
- trunk/hal/tsar_mips32/core
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/tsar_mips32/core/hal_drivers.c
r266 r279 75 75 /* update the PIC chdev extension */ 76 76 pic->ext.pic.enable_timer = &soclib_pic_enable_timer; 77 pic->ext.pic.enable_ipi = &soclib_pic_enable_ipi; 77 78 pic->ext.pic.enable_irq = &soclib_pic_enable_irq; 78 79 pic->ext.pic.disable_irq = &soclib_pic_disable_irq; -
trunk/hal/tsar_mips32/core/hal_interrupt.c
r238 r279 23 23 24 24 #include <hal_types.h> 25 #include <hal_special.h> 25 26 #include <kernel_config.h> 26 27 #include <thread.h> 28 #include <printk.h> 27 29 #include <do_interrupt.h> 28 30 #include <hal_interrupt.h> 29 #include <mips32_uzone.h>30 31 #include <soclib_pic.h> 31 32 … … 34 35 reg_t * regs_tbl ) 35 36 { 37 irq_dmsg("\n[INFO] %s : enter at cycle %d\n", __FUNCTION__ , hal_time_stamp() ); 38 36 39 // update user time 37 40 thread_user_time_update( this ); … … 45 48 // update kernel time 46 49 thread_kernel_time_update( this ); 50 51 irq_dmsg("\n[INFO] %s : exit at cycle %d\n", __FUNCTION__ , hal_time_stamp() ); 47 52 } -
trunk/hal/tsar_mips32/core/hal_irqmask.c
r62 r279 28 28 inline void hal_disable_irq( uint32_t * old ) 29 29 { 30 register u nsigned int sr;30 register uint32_t sr; 31 31 32 32 __asm__ volatile 33 33 (".set noat \n" 34 ".set noreorder \n" 35 "mfc0 $1, $12 \n" 36 "nop \n" 37 ".set reorder \n" 34 "mfc0 $1, $12 \n" 38 35 "or %0, $0, $1 \n" 39 36 "srl $1, $1, 1 \n" 40 37 "sll $1, $1, 1 \n" 41 38 "mtc0 $1, $12 \n" 42 43 : "=&r" (sr) );39 ".set at \n" 40 : "=&r" (sr) ); 44 41 45 42 if( old ) *old = sr; … … 49 46 inline void hal_enable_irq( uint32_t * old ) 50 47 { 51 register u nsigned int sr;48 register uint32_t sr; 52 49 53 50 __asm__ volatile 54 51 (".set noat \n" 55 ".set noreorder \n"56 52 "mfc0 $1, $12 \n" 57 "nop \n"58 53 "or %0, $0, $1 \n" 59 "ori $1, $1, 0x 1\n"54 "ori $1, $1, 0xFF01 \n" 60 55 "mtc0 $1, $12 \n" 61 "nop \n" 62 ".set reorder \n" 63 ".set at \n" 64 : "=&r" (sr)); 56 ".set at \n" 57 : "=&r" (sr) ); 65 58 66 59 if( old ) *old = sr; … … 71 64 { 72 65 __asm__ volatile 73 (".set noat \n" 74 ".set noreorder \n" 75 "mfc0 $1, $12 \n" 76 "ori $2, $0, 0xFF \n" 77 "and $2, $2, %0 \n" 78 "or $1, $1, $2 \n" 79 "mtc0 $1, $12 \n" 80 ".set reorder \n" 81 ".set at \n" 82 : : "r" (old) : "$2"); 66 ( "mtc0 %0, $12" : : "r" (old) ); 83 67 } 84 68 69 -
trunk/hal/tsar_mips32/core/hal_kentry.S
r121 r279 1 1 /* 2 * hal_kentry.S - exception/interrupt/syscall kernel entry point for MIPS322 * hal_kentry.S - Interrupt / Exception / Syscall kernel entry point for MIPS32 3 3 * 4 4 * AUthors Ghassan Almaless (2007,2008,2009,2010,2011,2012) … … 30 30 # or syscall for the TSAR_MIPS32 architecture. 31 31 # 32 # - If the core is in user mode: 33 # . we desactivate the MMU. 34 # . we save the context in the uzone of the calling thread descriptor. 35 # . we increment the cores_in_kernel variable. 36 # . we call the relevant exception/interrupt/syscall handler 32 # When we enter the kernel, we test the ststus register: 33 # - If the core is in user mode, we desactivate the MMU, and we save 34 # the core context in the uzone of the calling thread descriptor. 35 # - If the core is already in kernel mode (in case of interrupt), 36 # we save the context in the kernel stack. 37 # - In both cases, we increment the cores_in_kernel variable, 38 # and we call the relevant exception/interrupt/syscall handler 37 39 # 38 # - If the core is already in kernel mode: 39 # . we save the context in the kernel stack 40 # . we call the relevant exception/interrupt/syscall handler 41 # 42 # - In both cases, when the handler returns: 43 # . we restore the context 44 # . we reactivate the MMU ??? TODO 40 # When we exit the kernel after handler execution: 41 # - we restore the core context from the uzone 45 42 #--------------------------------------------------------------------------------- 46 43 47 .section .kentry,"ax",@progbits 48 .extern cpu_do_interrupt 49 .extern cpu_do_exception 50 .extern cpu_do_syscall 51 .extern cpu_kentry 52 .extern cpu_kexit 44 .section .kgiet, "ax", @progbits 45 46 .extern hal_do_interrupt 47 .extern hal_do_exception 48 .extern hal_do_syscall 49 .extern cluster_core_kernel_enter 50 .extern cluster_core_kernel_exit 51 53 52 .org 0x180 54 .ent ke ntry55 .global ke ntry56 .global kentry_load 53 .ent kernel_enter 54 .global kernel_enter 55 57 56 .set noat 58 57 .set noreorder … … 67 66 68 67 #--------------------------------------------------------------------------------- 69 # Kernel Entry point 68 # Kernel Entry point for Interrupt / Exception / Syscall 70 69 #--------------------------------------------------------------------------------- 71 70 72 ke ntry:71 kernel_enter: 73 72 mfc0 $26, $12 # read SR to test user/kernel mode 74 73 andi $26, $26, 0x10 # User Mode bitmask … … 101 100 #--------------------------------------------------------------------------------------- 102 101 # this code is executed when the core is in kernel mode: 103 # - we use an uzone allocated in kernel stack.102 # - we use an uzone dynamically allocated in kernel stack. 104 103 # - we set the MMU off, set the MMU data_paddr extension to local_cxy, 105 104 # and save the CP2_MODE and CP2_DEXT to uzone. … … 141 140 142 141 #-------------------------------------------------------------------------------------- 143 # this code is executed in both modes, with the two following assumptions: 144 # - $27 contains the pointer on uzone to save the cpu registers 142 # This code is executed in both modes, and saves the core context, 143 # with the two following assumptions: 144 # - $27 contains the pointer on uzone to save the core registers 145 145 # - $29 contains the kernel stack pointer 146 146 … … 186 186 sw $17, (UZ_CR*4)($27) # Save CR 187 187 188 srl $3, $18, 5 # put SR in kernel mode, IRQ disabled, clear exl 188 # put SR in kernel mode, IRQ disabled, clear exl 189 srl $3, $18, 5 189 190 sll $3, $3, 5 190 191 mtc0 $3, $12 # Set new SR 191 192 192 andi $1, $17, 0x3F # $1 <= XCODE (from CR)193 194 193 # signal that core enters kernel 195 jal cluster_core_kernel_enter 194 la $1, cluster_core_kernel_enter 195 jal $1 196 196 nop 197 197 198 198 #--------------------------------------------------------------------------------------- 199 # Depending on XCODE (in $1) , call the apropriate handler. The three called 200 # functions take the same two arguments: thread pointer and uzone pointer. 199 # This code call the relevant Interrupt / Exception / Syscall handler, 200 # depending on XCODE in CP0_CR, with the two following assumptions: 201 # - $27 contains the pointer on uzone containing to save the core registers 202 # - $29 contains the kernel stack pointer 203 # The three handlers take the same two arguments: thread pointer and uzone pointer. 204 # The uzone pointer is saved in $19 to be used by kernel_exit. 205 206 mfc0 $17, $13 # $1 <= CR 207 andi $1, $1, 0x3F # $1 <= XCODE 201 208 202 209 mfc0 $4, $4, 2 # $4 <= thread pointer (first arg) 203 210 or $5, $0, $27 # $5 <= uzone pointer (second arg) 204 or $19, $0, $27 # $19 <= &uzone (for ke ntry_exit)211 or $19, $0, $27 # $19 <= &uzone (for kernel_exit) 205 212 206 213 ori $8, $0, 0x20 # $8 <= cause syscall … … 215 222 addiu $29, $29, -8 # hal_do_exception has 2 args 216 223 addiu $29, $29, 8 217 j ke ntry_exit # jump to kentry_exit224 j kernel_exit # jump to kernel_exit 218 225 nop 219 226 … … 223 230 addiu $29, $29, -8 # hal_do_syscall has 2 args 224 231 addiu $29, $29, 8 225 j ke ntry_exit # jump to kentry_exit226 or $19, $0, $2232 j kernel_exit # jump to kernel_exit 233 nop 227 234 228 235 cause_int: … … 233 240 234 241 # ----------------------------------------------------------------------------------- 235 # Kentry exit 242 # Kernel exit 243 # The pointer on uzone is supposed to be stored in $19 236 244 # ----------------------------------------------------------------------------------- 237 ke ntry_exit:245 kernel_exit: 238 246 239 247 # signal that core exit kernel 240 jal cluster_core_kernel_exit 248 la $1, cluster_core_kernel_exit 249 jalr $1 250 nop 241 251 242 252 # restore context from uzone … … 286 296 lw $31, (UZ_RA*4)($27) 287 297 288 289 298 lw $26, (UZ_DEXT*4)($27) 290 299 mtc2 $26, $24 # restore CP2_DEXT from uzone 291 300 292 #TODO: optimize 293 lw $26, (UZ_MODE*4)($27) # get saved CP2_MODE from uzone 294 andi $26, $26, 0xc # keep only the TLBs controling bits 295 beq $26, $0, out_mmu_3 # both MSB are 0 (the first two LSB are always set) 296 andi $26, $26, 0x8 297 beq $26, $0, out_mmu_7 # first MSB is 0 (bit 2 is set) 298 299 # Possible value for MMU_MODE 300 # In kernel mode : 0x7/0x3 301 # In user mode : 0xF 302 303 # DP_EXT can either be local or remote 304 # Once these register set we can no longuer 305 # access global data 306 307 out_mmu_F: 308 ori $26, $0, 0xF 309 mtc2 $26, $1 # CP2_MODE <= 0xF 310 j out_kentry 311 nop 312 313 out_mmu_7: 314 ori $26, $0, 0x7 315 mtc2 $26, $1 # CP2_MODE <= 0x7 316 j out_kentry 317 nop 318 319 out_mmu_3: 320 ori $26, $0, 0x3 321 mtc2 $26, $1 # CP2_MODE <= 0x3 322 323 out_kentry: 301 lw $26, (UZ_MODE*4)($27) 302 mtc2 $26, $1 # restore CP2_MODE from uzone 303 324 304 nop 325 305 eret 326 306 327 .end ke ntry307 .end kernel_enter 328 308 .set reorder 329 309 .set at 330 310 331 .ent kentry_load332 kentry_load:333 # theses nops are required to load the eret instruction334 # while we are in virtual mode (processor pipeline) ?335 mtc2 $26, $1 # set MMU MODE336 nop337 nop338 eret339 .end kentry_load340 341 311 #------------------------------------------------------------------------------- 342 312 -
trunk/hal/tsar_mips32/core/hal_kentry.h
r121 r279 24 24 #define _HAL_KENTRY_H_ 25 25 26 /***************************************************************************************27 * This file ... TODO28 **************************************************************************************/29 30 #define KSP 031 #define AT 132 #define V0 233 #define V1 334 #define A0 435 #define A1 536 #define A2 637 #define A3 738 #define T0 839 #define T1 940 #define T2 1041 #define T3 1142 #define T4 1243 #define T5 1344 #define T6 1445 #define T7 1546 #define T8 1647 #define T9 1748 #define S0 1849 #define S1 1950 #define S2 2051 #define S3 2152 #define S4 2253 #define S5 2354 #define S6 2455 #define S7 2556 #define S8 2657 #define GP 2758 #define RA 2859 #define EPC 2960 #define CR 3061 #define SP 3162 #define SR 3263 #define LO 3364 #define HI 3465 #define TLS_K1 3566 #define DP_EXT 36 // DATA PADDR EXTENSION67 #define MMU_MD 37 // MMU MODE68 #define REGS_NR 3869 26 70 27 #define CPU_IN_KERNEL 1 -
trunk/hal/tsar_mips32/core/hal_ppm.c
r107 r279 39 39 // - the 64 bits XPTR value is identical to the 64 bits PADDR value. 40 40 // The pages_tbl[] is mapped in first free page after kernel code. 41 // There is no other reserved zones than the zone occupied by the kernel code.42 41 ////////////////////////////////////////////////////////////////////////////////////////// 43 44 42 45 43 /////////////////////////////////////////// … … 52 50 uint32_t pages_tbl_offset = info->pages_offset; 53 51 uint32_t rsvd_nr = info->rsvd_nr; 54 55 // check no reserved zones other than kernel code for TSAR56 assert( (rsvd_nr == 0 ) , __FUNCTION__ , "NO reserved zones for TSAR\n" );57 52 58 53 // get pointer on local Physical Page Manager -
trunk/hal/tsar_mips32/core/hal_remote.c
r204 r279 34 34 uint32_t cxy = (uint32_t)GET_CXY( xp ); 35 35 36 hal_disable_irq( &save_sr ); 37 38 asm volatile( 39 ".set noreorder \n" 40 "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ 41 "mtc2 %2, $24 \n" /* PADDR_EXT <= cxy */ 42 "sb %0, 0(%1) \n" /* *paddr <= value */ 43 "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ 36 /* TODO improve all hal remote functions to include SR handling in assembly code */ 37 /* as it is done below for hal_remote_sb */ 38 39 asm volatile( 40 ".set noreorder \n" 41 "mfc0 $14, $12 \n" /* $14 <= CP0_SR */ 42 "srl $13, $14, 1 \n" 43 "sll $13, $13, 1 \n" /* $13 <= SR masked */ 44 "mtc0 $13, $12 \n" /* IRQ disabled */ 45 46 47 "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ 48 "mtc2 %2, $24 \n" /* PADDR_EXT <= cxy */ 49 "sb %0, 0(%1) \n" /* *paddr <= value */ 50 "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ 51 52 "mtc0 $14, $12 \n" /* SR restored */ 53 44 54 "sync \n" 45 55 ".set reorder \n" 46 : : "r" (data), "r" (ptr), "r" (cxy) : "$15" ); 47 48 hal_restore_irq( save_sr ); 49 56 : : "r" (data), "r" (ptr), "r" (cxy) : "$13", "$14", "$15" ); 50 57 } 51 58 -
trunk/hal/tsar_mips32/core/hal_special.c
r124 r279 32 32 struct thread_s; 33 33 34 ///////////////////////////////// 35 void hal_set_ebase( reg_t base ) 36 { 37 asm volatile ("mtc0 %0, $15, 1" : : "r" (base)); 38 } 34 39 35 40 ////////////////////////// … … 48 53 cycle_t count; 49 54 50 asm volatile ("mfc0 %0, $9 55 asm volatile ("mfc0 %0, $9" : "=&r" (count)); 51 56 52 57 return count; 58 } 59 60 ///////////////////////// 61 inline reg_t hal_get_sr() 62 { 63 register uint32_t sr; 64 65 asm volatile ("mfc0 %0, $12" : "=&r" (sr)); 66 67 return sr; 53 68 } 54 69 … … 90 105 void * thread_ptr; 91 106 92 asm volatile 93 ( "mfc0 %0, $4, 2 \n" 94 : "=&r" (thread_ptr) ); 107 asm volatile ("mfc0 %0, $4, 2" : "=&r" (thread_ptr)); 95 108 96 109 return thread_ptr; … … 100 113 void hal_set_current_thread( struct thread_s * thread ) 101 114 { 102 asm volatile 103 ( "mtc0 %0, $4, 2 \n" 104 : : "r" (thread) ); 115 asm volatile ("mtc0 %0, $4, 2" : : "r" (thread)); 105 116 } 106 117 … … 135 146 register uint32_t sp; 136 147 137 asm volatile 138 ( "or %0, $0, $29 \n" 139 : "=&r" (sp) ); 148 asm volatile ("or %0, $0, $29" : "=&r" (sp)); 140 149 141 150 return sp;
Note: See TracChangeset
for help on using the changeset viewer.