[160] | 1 | /********************************************************************************/ |
---|
[165] | 2 | /* File : reset.S */ |
---|
| 3 | /* Author : Alain Greiner & Mohamed karaoui */ |
---|
| 4 | /* Date : 03/06/2012 */ |
---|
[160] | 5 | /********************************************************************************/ |
---|
| 6 | /* This boot code is for a multi-cluster, multi-processor architecture, */ |
---|
[165] | 7 | /* running one or several multi-tasks software application(s) defined in */ |
---|
[160] | 8 | /* the mapping_info data-structure. */ |
---|
[189] | 9 | /* Procesor 0 uses the mapping_info data structure to statically initialize */ |
---|
| 10 | /* the kernel structures: */ |
---|
| 11 | /* - build page tables for all vspaces */ |
---|
| 12 | /* - initializes the vobjs not initialized by GCC */ |
---|
| 13 | /* - initialize the schedulers and task contexts for all processeurs */ |
---|
| 14 | /* - initialize the peripherals */ |
---|
[160] | 15 | /* Other processors are waiting until the mapping_info signature has been */ |
---|
[189] | 16 | /* modified by processor 0. */ |
---|
| 17 | /* */ |
---|
[165] | 18 | /* Implementation note: */ |
---|
[160] | 19 | /* The entry point is 0xbfc00000, but the actual boot code starts at address */ |
---|
| 20 | /* 0xbfc00500, and a minimal boot exception handler is implemented at address */ |
---|
| 21 | /* 0xbfc0380. */ |
---|
| 22 | /********************************************************************************/ |
---|
| 23 | |
---|
| 24 | #include <giet_config.h> |
---|
[165] | 25 | #include "../sys/mips32_registers.h" |
---|
[160] | 26 | |
---|
| 27 | #define EXCEP_ORG 0x380 |
---|
| 28 | #define START_ORG 0x500 |
---|
| 29 | |
---|
| 30 | #define OUT_MAPPING_SIGNATURE 0xBABEF00D |
---|
| 31 | |
---|
| 32 | .section .boot,"ax",@progbits |
---|
| 33 | .align 2 |
---|
| 34 | .set noreorder |
---|
| 35 | |
---|
| 36 | /********************************************************/ |
---|
| 37 | /* reset entry point */ |
---|
| 38 | /* (address 0xBFC00000 imposed by the hardware) */ |
---|
| 39 | /********************************************************/ |
---|
| 40 | boot_reset: |
---|
| 41 | j boot_start |
---|
| 42 | nop |
---|
| 43 | |
---|
| 44 | /*******************************************************/ |
---|
| 45 | /* handling exceptions in the boot phase */ |
---|
| 46 | /* (address 0xBFC00380 imposed by the hardware */ |
---|
| 47 | /*******************************************************/ |
---|
| 48 | .align 2 |
---|
| 49 | .org EXCEP_ORG |
---|
[189] | 50 | |
---|
[160] | 51 | boot_excep: |
---|
[189] | 52 | |
---|
| 53 | # get the lock protecting TTY0 |
---|
| 54 | la k0, boot_tty0_lock |
---|
| 55 | ll k1, 0(k0) |
---|
| 56 | bnez k1, boot_excep |
---|
| 57 | li k1, 1 |
---|
| 58 | sc k1, 0(k0) |
---|
| 59 | beqz k1, boot_excep |
---|
[160] | 60 | nop |
---|
[189] | 61 | |
---|
| 62 | # display error messages on TTY0 |
---|
| 63 | la a0, boot_error_string |
---|
| 64 | jal boot_puts |
---|
| 65 | nop |
---|
[160] | 66 | mfc0 a0, CP0_TIME |
---|
[207] | 67 | jal boot_putd |
---|
[160] | 68 | nop |
---|
[189] | 69 | la a0, boot_lf_string |
---|
| 70 | jal boot_puts |
---|
[160] | 71 | nop |
---|
| 72 | |
---|
[189] | 73 | la a0, boot_pid_string |
---|
| 74 | jal boot_puts |
---|
[165] | 75 | nop |
---|
| 76 | mfc0 k0, CP0_PROCID |
---|
| 77 | andi a0, k0, 0xFFF |
---|
[207] | 78 | jal boot_putd |
---|
[165] | 79 | nop |
---|
[189] | 80 | la a0, boot_lf_string |
---|
| 81 | jal boot_puts |
---|
[165] | 82 | nop |
---|
| 83 | |
---|
[189] | 84 | la a0, boot_epc_string |
---|
| 85 | jal boot_puts |
---|
[160] | 86 | nop |
---|
| 87 | mfc0 a0, CP0_EPC |
---|
[204] | 88 | jal boot_putx |
---|
[160] | 89 | nop |
---|
[189] | 90 | la a0, boot_lf_string |
---|
| 91 | jal boot_puts |
---|
[160] | 92 | nop |
---|
| 93 | |
---|
[189] | 94 | la a0, boot_cr_string |
---|
| 95 | jal boot_puts |
---|
[160] | 96 | nop |
---|
| 97 | mfc0 a0, CP0_CR |
---|
[204] | 98 | jal boot_putx |
---|
[160] | 99 | nop |
---|
[189] | 100 | la a0, boot_lf_string |
---|
| 101 | jal boot_puts |
---|
[160] | 102 | nop |
---|
| 103 | |
---|
[189] | 104 | la a0, boot_sr_string |
---|
| 105 | jal boot_puts |
---|
[160] | 106 | nop |
---|
| 107 | mfc0 a0, CP0_SR |
---|
[204] | 108 | jal boot_putx |
---|
[160] | 109 | nop |
---|
[189] | 110 | la a0, boot_lf_string |
---|
| 111 | jal boot_puts |
---|
[160] | 112 | nop |
---|
| 113 | |
---|
[189] | 114 | la a0, boot_bar_string |
---|
| 115 | jal boot_puts |
---|
[160] | 116 | nop |
---|
[199] | 117 | mfc0 a0, CP0_BVAR |
---|
[204] | 118 | jal boot_putx |
---|
[160] | 119 | nop |
---|
[189] | 120 | la a0, boot_lf_string |
---|
| 121 | jal boot_puts |
---|
[160] | 122 | nop |
---|
| 123 | |
---|
[189] | 124 | # release the lock |
---|
| 125 | la k0, boot_tty0_lock |
---|
| 126 | li k1, 0 |
---|
| 127 | sw k1, 0(k0) |
---|
| 128 | |
---|
| 129 | # exit |
---|
[160] | 130 | j boot_exit |
---|
| 131 | nop |
---|
| 132 | |
---|
| 133 | /*******************************************/ |
---|
| 134 | /* actual starting point for the boot code */ |
---|
| 135 | /*******************************************/ |
---|
| 136 | .align 2 |
---|
[165] | 137 | .org START_ORG |
---|
[160] | 138 | |
---|
| 139 | boot_start: |
---|
[189] | 140 | |
---|
[234] | 141 | # initialize the proc_time to zero |
---|
| 142 | mtc0 $0, CP0_TIME |
---|
| 143 | |
---|
[189] | 144 | # get the procid |
---|
[160] | 145 | mfc0 k0, CP0_PROCID |
---|
[189] | 146 | andi k0, k0, 0xFFF # no more than 4096 processors |
---|
[160] | 147 | |
---|
[189] | 148 | # Only processor 0 does init |
---|
| 149 | bne k0, zero, boot_wait_signature |
---|
[160] | 150 | nop |
---|
| 151 | |
---|
[189] | 152 | # Processor 0 get a temporary stack |
---|
[165] | 153 | la sp, seg_boot_stack_base |
---|
[189] | 154 | addiu sp, sp, 0x3000 # SP <= seg_boot_stack + 12K |
---|
[160] | 155 | |
---|
[189] | 156 | # Processor 0 initialises all kernel structures |
---|
| 157 | jal boot_init |
---|
[160] | 158 | nop |
---|
[165] | 159 | |
---|
[189] | 160 | # jump to kernel_init |
---|
[165] | 161 | j boot_to_kernel_init |
---|
[160] | 162 | nop |
---|
| 163 | |
---|
| 164 | boot_wait_signature: |
---|
[165] | 165 | |
---|
[189] | 166 | # all other processors are waiting signature change |
---|
| 167 | la k0, seg_mapping_base |
---|
| 168 | cache 0x11, 0(k0) # invalidate local cache copy |
---|
| 169 | lw k0, 0(k0) # k0 <= mapping_info[0] |
---|
| 170 | li k1, OUT_MAPPING_SIGNATURE |
---|
| 171 | bne k1, k0, boot_wait_signature |
---|
[160] | 172 | nop |
---|
| 173 | |
---|
[189] | 174 | # all other processors initialise SP register: temporary stack of 256 bytes |
---|
[165] | 175 | la sp, seg_boot_stack_base |
---|
| 176 | addiu sp, sp, 0x3100 |
---|
| 177 | mfc0 k0, CP0_PROCID |
---|
| 178 | andi k0, k0, 0xFFF |
---|
| 179 | sll k0, k0, 8 |
---|
[189] | 180 | addu sp, sp, k0 # SP <= seg_boot_stack_base + 12K + (pid+1)*256 |
---|
[160] | 181 | |
---|
[165] | 182 | boot_to_kernel_init: |
---|
[160] | 183 | |
---|
[238] | 184 | # all processors initialise the CP0 SCHED register |
---|
[240] | 185 | # SCHED contains the scheduler virtual base address |
---|
[189] | 186 | mfc0 k0, CP0_PROCID |
---|
| 187 | andi k0, k0, 0xFFF |
---|
| 188 | sll k0, k0, 2 # k0 <= 4*pid |
---|
[238] | 189 | la k1, boot_schedulers |
---|
| 190 | addu k1, k1, k0 # k1 <= &boot_schedulers[pid] |
---|
| 191 | lw k0, 0(k1) |
---|
| 192 | mtc0 k0, CP0_SCHED |
---|
[189] | 193 | |
---|
[238] | 194 | # all processors initialize the CP2 PTPR register |
---|
| 195 | # At this stage, all PTPR registers contain the physical base |
---|
| 196 | # address (13 bits right shifted) of the page table for vspace[0] |
---|
[189] | 197 | la k1, boot_ptabs_paddr |
---|
[238] | 198 | lw k0, 0(k1) # k0 <= paddr_lsb |
---|
| 199 | lw k1, 4(k1) # k1 <= paddr_msb |
---|
| 200 | srl k0, k0, 13 # k0 <= paddr_lsb shifted |
---|
| 201 | sll k1, k1, 19 # k1 <= paddr_msb shifted |
---|
| 202 | or k0, k0, k1 |
---|
| 203 | mtc2 k0, CP2_PTPR |
---|
[160] | 204 | |
---|
[238] | 205 | # all processors activate MMU (already done for processor 0) |
---|
[165] | 206 | li k1, 0xF |
---|
[189] | 207 | mtc2 k1, CP2_MODE |
---|
[160] | 208 | |
---|
[189] | 209 | # all processors jump to kernel_init |
---|
[165] | 210 | la k0, seg_kernel_init_base |
---|
[160] | 211 | j k0 |
---|
| 212 | nop |
---|
| 213 | |
---|
[189] | 214 | boot_error_string: .asciiz "\n[BOOT] Fatal Error at cycle " |
---|
[165] | 215 | boot_pid_string: .asciiz " PID = " |
---|
[160] | 216 | boot_sr_string: .asciiz " SR = " |
---|
| 217 | boot_cr_string: .asciiz " CR = " |
---|
| 218 | boot_epc_string: .asciiz " EPC = " |
---|
| 219 | boot_bar_string: .asciiz " BAR = " |
---|
| 220 | boot_lf_string: .asciiz "\n" |
---|
| 221 | |
---|
[189] | 222 | boot_tty0_lock: .word 0 |
---|
[160] | 223 | |
---|
[189] | 224 | .set reorder |
---|
[160] | 225 | |
---|
[189] | 226 | |
---|