Changeset 238 for soft/giet_vm/sys/kernel_init.c
- Timestamp:
- May 29, 2013, 1:24:09 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/sys/kernel_init.c
r228 r238 33 33 34 34 /////////////////////////////////////////////////////////////////////////////////// 35 // array of pointers on the page tables ( both virtual and physical addresses)35 // array of pointers on the page tables (virtual addresses) 36 36 /////////////////////////////////////////////////////////////////////////////////// 37 37 38 38 __attribute__((section (".kdata"))) 39 unsigned int _ptabs_paddr[GIET_NB_VSPACE_MAX]; 39 unsigned int _ptabs[GIET_NB_VSPACE_MAX]; // virtual addresses 40 41 __attribute__((section (".kdata"))) 42 unsigned int _ptprs[GIET_NB_VSPACE_MAX]; // physical addresses >> 13 43 44 /////////////////////////////////////////////////////////////////////////////////// 45 // array of pointers on the schedulers (physical addresses) 46 /////////////////////////////////////////////////////////////////////////////////// 40 47 41 48 __attribute__((section (".kdata"))) 42 unsigned int _ptabs_vaddr[GIET_NB_VSPACE_MAX];43 44 /////////////////////////////////////////////////////////////////////////////////// 45 // array of pointers on the schedulers (physical addresses)49 static_scheduler_t* _schedulers[NB_CLUSTERS * NB_PROCS_MAX]; 50 51 /////////////////////////////////////////////////////////////////////////////////// 52 // staks for the "idle" tasks (256 bytes for each processor) 46 53 /////////////////////////////////////////////////////////////////////////////////// 47 54 48 55 __attribute__((section (".kdata"))) 49 static_scheduler_t * _schedulers_paddr[NB_CLUSTERS * NB_PROCS_MAX]; 50 51 /////////////////////////////////////////////////////////////////////////////////// 52 // staks for the "idle" tasks (256 bytes for each processor) 53 /////////////////////////////////////////////////////////////////////////////////// 54 55 __attribute__((section (".kdata"))) 56 unsigned int _idle_stack[NB_CLUSTERS*NB_PROCS_MAX * 64]; 57 58 void _sys_exit() { 56 unsigned int _idle_stack[NB_CLUSTERS * NB_PROCS_MAX * 64]; 57 58 //////////////// 59 void _sys_exit() 60 { 59 61 while (1); 60 62 } … … 63 65 ////////////////////////////////////////////////////////////////////////////////// 64 66 // This function is the entry point for the last step of the boot sequence. 67 // that is done in parallel by all processors, with MMU activated. 65 68 ////////////////////////////////////////////////////////////////////////////////// 66 __attribute__((section (".kinit"))) void _kernel_init() { 67 // compute cluster and local processor index 68 unsigned int global_pid = _procid(); 69 unsigned int cluster_id = global_pid / NB_PROCS_MAX; 70 unsigned int proc_id = global_pid % NB_PROCS_MAX; 71 72 // Step 0 : Compute number of tasks allocated to proc 73 74 unsigned int tasks = _get_tasks_number(); 75 76 #if GIET_DEBUG_INIT 77 _get_lock(&_tty_put_lock); 78 _puts("\n[GIET DEBUG] step 0 for processor "); 79 _putd(global_pid); 80 _puts(" : tasks = "); 81 _putd(tasks); 82 _puts("\n"); 83 _release_lock(&_tty_put_lock); 84 #endif 85 86 // step 1 : Initialise scheduler physical addresses array 87 // get scheduler physical address (from CP0 register) 88 89 static_scheduler_t * psched = (static_scheduler_t *) _get_sched(); 90 _schedulers_paddr[global_pid] = psched; 91 92 #if GIET_DEBUG_INIT 93 _get_lock(&_tty_put_lock); 94 _puts("\n[GIET DEBUG] step 1 for processor "); 95 _putd(global_pid); 96 _puts(" / scheduler pbase = "); 97 _putx((unsigned int) psched); 98 _puts("\n"); 99 _release_lock(&_tty_put_lock); 100 #endif 101 102 // step 2 : initialise page table addresse arrays 69 __attribute__((section (".kinit"))) void _kernel_init() 70 { 71 // Step 1 : get processor index, 72 // get scheduler address 73 // initialise _schedulers[] array 74 75 unsigned int global_pid = _procid(); 76 unsigned int cluster_id = global_pid / NB_PROCS_MAX; 77 unsigned int proc_id = global_pid % NB_PROCS_MAX; 78 static_scheduler_t* psched = _get_sched(); 79 unsigned int tasks = psched->tasks; 80 81 _schedulers[global_pid] = psched; 82 83 #if GIET_DEBUG_INIT 84 _get_lock(&_tty_put_lock); 85 _puts("\n[GIET DEBUG] step 1 for processor "); 86 _putd(global_pid); 87 _puts(" : tasks = "); 88 _putd(tasks); 89 _puts(" / scheduler vbase = "); 90 _putx((unsigned int) psched); 91 _puts("\n"); 92 _release_lock(&_tty_put_lock); 93 #endif 94 95 // step 2 : initialise ptabs[] & ptprs[] arrays 103 96 // each processor scans all tasks contexts in its 104 97 // private scheduler and get VSID, PTAB and PTPR values … … 106 99 unsigned int ltid; 107 100 108 for (ltid = 0; ltid < tasks; ltid++) { 109 unsigned int vspace_id = _get_context_slot(ltid , CTX_VSID_ID); 110 unsigned int ptab_vaddr = _get_context_slot(ltid , CTX_PTAB_ID); 111 unsigned int ptab_paddr = _get_context_slot(ltid , CTX_PTPR_ID) << 13; 112 113 _ptabs_vaddr[vspace_id] = ptab_vaddr; 114 _ptabs_paddr[vspace_id] = ptab_paddr; 115 116 #if GIET_DEBUG_INIT 117 _get_lock(&_tty_put_lock); 118 _puts("\n[GIET DEBUG] step 2 for processor "); 119 _putd(global_pid); 120 _puts(" / vspace "); 121 _putd(vspace_id); 122 _puts("\n- ptab vbase = "); 123 _putx(ptab_vaddr); 124 _puts("\n- ptab pbase = "); 125 _putx(ptab_paddr); 126 _puts("\n"); 127 _release_lock(&_tty_put_lock); 101 for (ltid = 0; ltid < tasks; ltid++) 102 { 103 unsigned int vsid = _get_task_slot(ltid , CTX_VSID_ID); 104 unsigned int ptab = _get_task_slot(ltid , CTX_PTAB_ID); 105 unsigned int ptpr = _get_task_slot(ltid , CTX_PTPR_ID); 106 107 _ptabs[vsid] = ptab; 108 _ptprs[vsid] = ptpr; 109 110 #if GIET_DEBUG_INIT 111 _get_lock(&_tty_put_lock); 112 _puts("\n[GIET DEBUG] step 2 for processor "); 113 _putd(global_pid); 114 _puts(" / vspace "); 115 _putd(vsid); 116 _puts("\n- ptab = "); 117 _putx(ptab); 118 _puts("\n- ptpr = "); 119 _putx(ptpr); 120 _puts("\n"); 121 _release_lock(&_tty_put_lock); 128 122 #endif 129 123 130 124 } 131 132 unsigned int isr_switch_channel = 0xFFFFFFFF;133 125 134 126 // step 3 : compute and set ICU masks … … 136 128 // software interrupts are not supported yet 137 129 138 unsigned int irq_id; 130 unsigned int isr_switch_channel = 0xFFFFFFFF; 131 unsigned int irq_id; // IN_IRQ index 139 132 unsigned int hwi_mask = 0; 140 133 unsigned int pti_mask = 0; 141 134 142 for (irq_id = 0; irq_id < 32; irq_id++) { 143 unsigned int entry = _get_interrupt_vector_entry(irq_id); 144 unsigned int isr = entry & 0x000000FF; 145 146 if ((isr == ISR_DMA) || (isr == ISR_IOC) || (isr == ISR_TTY)) { 135 for (irq_id = 0; irq_id < 32; irq_id++) 136 { 137 unsigned int entry = psched->interrupt_vector[irq_id]; 138 unsigned int isr = entry & 0x000000FF; 139 140 if ((isr == ISR_DMA) || (isr == ISR_IOC) || (isr == ISR_TTY)) 141 { 147 142 hwi_mask = hwi_mask | 0x1 << irq_id; 148 143 } 149 else if ((isr == ISR_SWITCH)) { 144 else if ((isr == ISR_SWITCH)) 145 { 150 146 pti_mask = pti_mask | 0x1 << irq_id; 151 147 isr_switch_channel = irq_id; 152 148 } 153 else if ((isr == ISR_TIMER)) { 149 else if ((isr == ISR_TIMER)) 150 { 154 151 pti_mask = pti_mask | 0x1 << irq_id; 155 152 } 156 153 } 154 155 #if GIET_DEBUG_INIT 156 _get_lock(&_tty_put_lock); 157 _puts("\n[GIET DEBUG] step 3 for processor "); 158 _putd(global_pid); 159 _puts("\n - ICU HWI_MASK = "); 160 _putx(hwi_mask); 161 _puts("\n - ICU PTI_MASK = "); 162 _putx(pti_mask); 163 _puts("\n"); 164 _release_lock(&_tty_put_lock); 165 #endif 166 157 167 _icu_set_mask(cluster_id, proc_id, hwi_mask, 0); // set HWI_MASK 158 168 _icu_set_mask(cluster_id, proc_id, pti_mask, 1); // set PTI_MASK 159 169 160 #if GIET_DEBUG_INIT161 _get_lock(&_tty_put_lock);162 _puts("\n[GIET DEBUG] step 3 for processor ");163 _putd(global_pid);164 _puts("\n - ICU HWI_MASK = ");165 _putx(hwi_mask);166 _puts("\n - ICU PTI_MASK = ");167 _putx(pti_mask);168 _puts("\n");169 _release_lock(&_tty_put_lock);170 #endif171 172 170 // step 4 : start TICK timer if more than one task 173 if (tasks > 1) { 174 if (isr_switch_channel == 0xFFFFFFFF) { 171 if (tasks > 1) 172 { 173 if (isr_switch_channel == 0xFFFFFFFF) 174 { 175 175 _get_lock(&_tty_put_lock); 176 176 _puts("\n[GIET ERROR] ISR_SWITCH not found on proc "); … … 181 181 } 182 182 183 if (_timer_start( cluster_id, isr_switch_channel, GIET_TICK_VALUE)) { 183 if (_timer_start( cluster_id, isr_switch_channel, GIET_TICK_VALUE)) 184 { 184 185 _get_lock(&_tty_put_lock); 185 186 _puts("\n[GIET ERROR] ISR_SWITCH init error for proc "); … … 191 192 192 193 #if GIET_DEBUG_INIT 193 194 195 196 197 194 _get_lock(&_tty_put_lock); 195 _puts("\n[GIET DEBUG] Step 4 for processor "); 196 _putd(global_pid); 197 _puts(" / context switch activated\n"); 198 _release_lock(&_tty_put_lock); 198 199 #endif 199 200 … … 206 207 // the stack size is 256 bytes 207 208 208 _set_context_slot( IDLE_TASK_INDEX, CTX_RUN_ID, 1); 209 _set_context_slot( IDLE_TASK_INDEX, CTX_SR_ID, 0xFF03); 210 _set_context_slot( IDLE_TASK_INDEX, CTX_SP_ID, (unsigned int) _idle_stack + ((global_pid + 1) << 8)); 211 _set_context_slot( IDLE_TASK_INDEX, CTX_RA_ID, (unsigned int) &_ctx_eret); 212 _set_context_slot( IDLE_TASK_INDEX, CTX_EPC_ID, (unsigned int) &_ctx_idle); 213 _set_context_slot( IDLE_TASK_INDEX, CTX_LTID_ID, IDLE_TASK_INDEX); 214 _set_context_slot( IDLE_TASK_INDEX, CTX_PTPR_ID, _ptabs_paddr[0] >> 13); 215 216 #if GIET_DEBUG_INIT 217 _get_lock(&_tty_put_lock); 218 _puts("\n[GIET DEBUG] Step 5 for processor "); 219 _putd(global_pid); 220 _puts(" / idle task context set\n"); 221 _release_lock(&_tty_put_lock); 209 unsigned int stack = (unsigned int)_idle_stack + ((global_pid + 1)<<8); 210 211 _set_task_slot( IDLE_TASK_INDEX, CTX_RUN_ID, 1); 212 _set_task_slot( IDLE_TASK_INDEX, CTX_SR_ID, 0xFF03); 213 _set_task_slot( IDLE_TASK_INDEX, CTX_SP_ID, stack); 214 _set_task_slot( IDLE_TASK_INDEX, CTX_RA_ID, (unsigned int) &_ctx_eret); 215 _set_task_slot( IDLE_TASK_INDEX, CTX_EPC_ID, (unsigned int) &_ctx_idle); 216 _set_task_slot( IDLE_TASK_INDEX, CTX_LTID_ID, IDLE_TASK_INDEX); 217 _set_task_slot( IDLE_TASK_INDEX, CTX_PTPR_ID, _ptprs[0]); 218 219 #if GIET_DEBUG_INIT 220 _get_lock(&_tty_put_lock); 221 _puts("\n[GIET DEBUG] Step 5 for processor "); 222 _putd(global_pid); 223 _puts(" / idle task context set\n"); 224 _release_lock(&_tty_put_lock); 222 225 #endif 223 226 … … 226 229 // and starts the "idle" task if there is no task allocated. 227 230 228 unsigned int task_id; 229 230 if (tasks == 0) { 231 task_id = IDLE_TASK_INDEX; 231 ltid = 0; 232 233 if (tasks == 0) 234 { 235 ltid = IDLE_TASK_INDEX; 232 236 233 237 _get_lock(&_tty_put_lock); … … 237 241 _release_lock (&_tty_put_lock); 238 242 } 239 else { 240 task_id = 0; 241 } 242 243 unsigned int sp_value = _get_context_slot(task_id, CTX_SP_ID); 244 unsigned int sr_value = _get_context_slot(task_id, CTX_SR_ID); 245 unsigned int ptpr_value = _get_context_slot(task_id, CTX_PTPR_ID); 246 unsigned int epc_value = _get_context_slot(task_id, CTX_EPC_ID); 247 248 #if GIET_DEBUG_INIT 249 _get_lock(&_tty_put_lock); 250 _puts("\n[GIET DEBUG] step 6 for processor "); 251 _putd(global_pid); 252 _puts(" / registers initialised \n"); 253 _puts("- sp = "); 254 _putx(sp_value); 255 _puts("\n"); 256 _puts("- sr = "); 257 _putx(sr_value); 258 _puts("\n"); 259 _puts("- ptpr = "); 260 _putx(ptpr_value << 13); 261 _puts("\n"); 262 _puts("- epc = "); 263 _putx(epc_value); 264 _puts("\n"); 265 _release_lock(&_tty_put_lock); 266 #endif 243 244 unsigned int sp_value = _get_task_slot(ltid, CTX_SP_ID); 245 unsigned int sr_value = _get_task_slot(ltid, CTX_SR_ID); 246 unsigned int ptpr_value = _get_task_slot(ltid, CTX_PTPR_ID); 247 unsigned int epc_value = _get_task_slot(ltid, CTX_EPC_ID); 248 249 _set_task_slot( ltid, CTX_LTID_ID, ltid); 250 251 #if GIET_DEBUG_INIT 252 _get_lock(&_tty_put_lock); 253 _puts("\n[GIET DEBUG] step 6 for processor "); 254 _putd(global_pid); 255 _puts(" / registers initialised \n"); 256 _puts("- sp = "); 257 _putx(sp_value); 258 _puts("\n"); 259 _puts("- sr = "); 260 _putx(sr_value); 261 _puts("\n"); 262 _puts("- ptpr = "); 263 _putx(ptpr_value); 264 _puts("\n"); 265 _puts("- epc = "); 266 _putx(epc_value); 267 _puts("\n"); 268 _release_lock(&_tty_put_lock); 269 #endif 270 271 _get_lock(&_tty_put_lock); 272 _puts("\n[GIET] Processor "); 273 _putd( global_pid ); 274 _puts(" starting user code at cycle "); 275 _putd( _proctime() ); 276 _puts("\n"); 277 _release_lock(&_tty_put_lock); 267 278 268 279 // set registers and jump to user code
Note: See TracChangeset
for help on using the changeset viewer.