| 1 | /********************************************************************************/ |
|---|
| 2 | /* File : reset.S */ |
|---|
| 3 | /* Author : Alain Greiner & mohamed karaoui */ |
|---|
| 4 | /* Date : 26/04/2012 */ |
|---|
| 5 | /********************************************************************************/ |
|---|
| 6 | /* This file contain a function wich is called by init.s*/ |
|---|
| 7 | /* after initialising the peripherals and the shedulers.*/ |
|---|
| 8 | /* this _task_init function write the (procid+1) at the */ |
|---|
| 9 | /* first word of the mapping_base_info, to "wakeup" the */ |
|---|
| 10 | /* the processors wich id correspond to (procid+1) */ |
|---|
| 11 | /* ...TODO */ |
|---|
| 12 | /********************************************************************************/ |
|---|
| 13 | |
|---|
| 14 | #include <giet_config.h> |
|---|
| 15 | #include <mips32_registers.h> |
|---|
| 16 | |
|---|
| 17 | .section .kinitentry,"ax",@progbits |
|---|
| 18 | .align 2 |
|---|
| 19 | .set noreorder |
|---|
| 20 | |
|---|
| 21 | /* get the procid */ |
|---|
| 22 | mfc0 k0, CP0_PROCID |
|---|
| 23 | andi k0, k0, 0x3FF /* no more than 1024 processors... */ |
|---|
| 24 | |
|---|
| 25 | /* All processors jump to _task_init excepte the processor 0 */ |
|---|
| 26 | bne k0, zero, _task_init |
|---|
| 27 | nop |
|---|
| 28 | |
|---|
| 29 | /* plat-form initialisation */ |
|---|
| 30 | jal _init |
|---|
| 31 | nop |
|---|
| 32 | |
|---|
| 33 | _task_init: |
|---|
| 34 | |
|---|
| 35 | /* get the scheduler address */ |
|---|
| 36 | li k0, 256 |
|---|
| 37 | li k1, GIET_NB_TASKS_MAX |
|---|
| 38 | mul s2, k1, k0 /* s2 <= sizeof(context_array) */ |
|---|
| 39 | addiu k0, s2, 8 /* k0 <= sizeof(scheduler_t) */ |
|---|
| 40 | mul k0, k0, s0 /* k0 <= proc_id*sizeof(scheduler_t) */ |
|---|
| 41 | la k1, _scheduler |
|---|
| 42 | addu s1, k1, k0 /* s1 <= &_scheduler[proc_id] */ |
|---|
| 43 | |
|---|
| 44 | /* test number of tasks */ |
|---|
| 45 | addu k1, s1, s2 /* k1 <= &tasks */ |
|---|
| 46 | lw k1, 0(k1) /* k1 <= tasks */ |
|---|
| 47 | beq k1, zero, _task_exit |
|---|
| 48 | nop |
|---|
| 49 | |
|---|
| 50 | /* load SP */ |
|---|
| 51 | li k1, CTX_SP_ID |
|---|
| 52 | sll k1, k1, 2 |
|---|
| 53 | addu k1, s1, k1 |
|---|
| 54 | lw k1, 0(k1) |
|---|
| 55 | move sp, k1 /* sp <= ctx[SP] */ |
|---|
| 56 | |
|---|
| 57 | /* load SR */ |
|---|
| 58 | li k1, CTX_SR_ID |
|---|
| 59 | sll k1, k1, 2 |
|---|
| 60 | addu k1, s1, k1 |
|---|
| 61 | lw k1, 0(k1) |
|---|
| 62 | mtc0 k1, CP0_SR /* sr <= ctx[SR] */ |
|---|
| 63 | |
|---|
| 64 | /* load PTPR, MMU already activeted */ |
|---|
| 65 | li k1, CTX_PTPR_ID |
|---|
| 66 | sll k1, k1, 2 |
|---|
| 67 | addu k1, s1, k1 |
|---|
| 68 | lw k1, 0(k1) |
|---|
| 69 | mtc2 k1, CP2_PTPR /* ptpr <= ctx[PTPR] */ |
|---|
| 70 | |
|---|
| 71 | /* load EPC */ |
|---|
| 72 | li k1, CTX_EPC_ID |
|---|
| 73 | sll k1, k1, 2 |
|---|
| 74 | addu k1, s1, k1 |
|---|
| 75 | lw k1, 0(k1) |
|---|
| 76 | mtc0 k1, CP0_EPC /* epc <= ctx[EPC] */ |
|---|
| 77 | |
|---|
| 78 | /* jump to user's code in user mode */ |
|---|
| 79 | eret #jr ra |
|---|
| 80 | nop |
|---|
| 81 | |
|---|
| 82 | _task_exit: |
|---|
| 83 | j _task_exit |
|---|
| 84 | |
|---|
| 85 | .set reorder |
|---|
| 86 | |
|---|