[7150f00f] | 1 | /*-------------------------------------------------------------------------+ |
---|
| 2 | | start.s v1.1 - PC386 BSP - 1997/08/07 |
---|
| 3 | +--------------------------------------------------------------------------+ |
---|
| 4 | | This file contains the entry point for the application. |
---|
| 5 | | The name of this entry point is compiler dependent. |
---|
| 6 | | It jumps to the BSP which is responsible for performing all initialization. |
---|
| 7 | +--------------------------------------------------------------------------+ |
---|
| 8 | | (C) Copyright 1997 - |
---|
| 9 | | - NavIST Group - Real-Time Distributed Systems and Industrial Automation |
---|
| 10 | | |
---|
| 11 | | http://pandora.ist.utl.pt |
---|
| 12 | | |
---|
| 13 | | Instituto Superior Tecnico * Lisboa * PORTUGAL |
---|
| 14 | +--------------------------------------------------------------------------+ |
---|
[2efdd08] | 15 | | Modified the 20/05/1998 by valette@crf.canon.fr in order to give a working |
---|
| 16 | | example of eraly stage debugging via the DEBUG_EARLY_START define. |
---|
| 17 | +--------------------------------------------------------------------------+ |
---|
[7150f00f] | 18 | | Disclaimer: |
---|
| 19 | | |
---|
| 20 | | This file is provided "AS IS" without warranty of any kind, either |
---|
| 21 | | expressed or implied. |
---|
| 22 | +--------------------------------------------------------------------------+ |
---|
| 23 | | This code is based on an earlier generation RTEMS i386 start.s and the |
---|
| 24 | | following copyright applies: |
---|
| 25 | | |
---|
| 26 | | ************************************************************************** |
---|
[08311cc3] | 27 | | * COPYRIGHT (c) 1989-1999. |
---|
[6128a4a] | 28 | | * On-Line Applications Research Corporation (OAR). |
---|
[7150f00f] | 29 | | * |
---|
| 30 | | * The license and distribution terms for this file may be |
---|
| 31 | | * found in the file LICENSE in this distribution or at |
---|
[af2abc9e] | 32 | | * http://www.rtems.com/license/LICENSE. |
---|
[7150f00f] | 33 | | ************************************************************************** |
---|
| 34 | | |
---|
[6f9c75c3] | 35 | | $Id$ |
---|
[7150f00f] | 36 | +--------------------------------------------------------------------------*/ |
---|
| 37 | |
---|
[4050a7f] | 38 | /* |
---|
| 39 | * The most trivial start.s possible. It does not know anything |
---|
| 40 | * about system it is running on, so it will jump to appropriate |
---|
| 41 | * place in BSP specific place to do things it knows nothing about |
---|
| 42 | */ |
---|
[7150f00f] | 43 | |
---|
[cc1426bb] | 44 | #include <rtems/asm.h> |
---|
[23303c03] | 45 | #include <rtems/score/cpu.h> |
---|
[7150f00f] | 46 | |
---|
[96d56b3] | 47 | /*----------------------------------------------------------------------------+ |
---|
[6128a4a] | 48 | | Size of heap and stack: |
---|
[96d56b3] | 49 | +----------------------------------------------------------------------------*/ |
---|
| 50 | |
---|
[23303c03] | 51 | #ifndef CPU_STACK_ALIGNMENT |
---|
| 52 | #error "Missing header ? CPU_STACK_ALIGNMENT NOT DEFINED" |
---|
| 53 | #endif |
---|
| 54 | |
---|
[96d56b3] | 55 | .set STACK_SIZE, 0x1000 |
---|
| 56 | |
---|
[7150f00f] | 57 | /*----------------------------------------------------------------------------+ |
---|
| 58 | | CODE section |
---|
| 59 | +----------------------------------------------------------------------------*/ |
---|
| 60 | |
---|
| 61 | BEGIN_CODE |
---|
| 62 | |
---|
| 63 | PUBLIC (start) # GNU default entry point |
---|
| 64 | |
---|
[e2a2ec60] | 65 | EXTERN (boot_card) |
---|
[4050a7f] | 66 | EXTERN (_load_segments) |
---|
| 67 | EXTERN (_return_to_monitor) |
---|
[2efdd08] | 68 | EXTERN (_IBMPC_initVideo) |
---|
[4050a7f] | 69 | EXTERN (debugPollingGetChar) |
---|
[ab0df696] | 70 | EXTERN (checkCPUtypeSetCr0) |
---|
[b092ad60] | 71 | EXTERN (BSP_console_select) |
---|
[4a4201c] | 72 | EXTERN (printk) |
---|
| 73 | #ifdef __SSE__ |
---|
| 74 | EXTERN (x86_capability) |
---|
| 75 | #ifdef __SSE3__ |
---|
| 76 | EXTERN (x86_capability_x) |
---|
| 77 | #endif |
---|
| 78 | #endif |
---|
[6128a4a] | 79 | |
---|
[2efdd08] | 80 | /* |
---|
[4050a7f] | 81 | * In case this crashes on your machine and this is not due |
---|
[2efdd08] | 82 | * to video mode set by the loader, you may try to define |
---|
[4050a7f] | 83 | * the following variable: |
---|
[2efdd08] | 84 | */ |
---|
[5d18fb0] | 85 | /* #define DEBUG_EARLY_START */ |
---|
[7150f00f] | 86 | |
---|
[4050a7f] | 87 | SYM (start): |
---|
[bb6d368] | 88 | /* |
---|
| 89 | * When things are really, REALLY!, bad -- turn on the speaker and |
---|
[6128a4a] | 90 | * lock up. This shows whether or not we make it to a certain |
---|
[bb6d368] | 91 | * location. |
---|
| 92 | */ |
---|
| 93 | #if 0 |
---|
| 94 | inb $0x61, al |
---|
| 95 | orb $0x03, al |
---|
| 96 | outb al, $0x61 # enable the speaker |
---|
| 97 | speakl: jmp speakl # and SPIN!!! |
---|
| 98 | #endif |
---|
| 99 | |
---|
[7150f00f] | 100 | nop |
---|
| 101 | cli # DISABLE INTERRUPTS!!! |
---|
[2efdd08] | 102 | cld |
---|
[662c157] | 103 | |
---|
[1c5ebc5] | 104 | /* Save multiboot info if we detect a multiboot loader */ |
---|
| 105 | cmp $0x2badb002,eax |
---|
| 106 | jne 2f |
---|
[359e537] | 107 | |
---|
[1c5ebc5] | 108 | /* We have multiboot info; let's hope DS and ES are OK... */ |
---|
| 109 | movl ebx, SYM(_boot_multiboot_info_p) |
---|
| 110 | /* Check for memory size info and save */ |
---|
| 111 | movl ebx, esi |
---|
| 112 | movl (esi), eax |
---|
| 113 | movl eax, ebx |
---|
| 114 | movl $SYM(_boot_multiboot_info), edi |
---|
| 115 | /* save flags, always present */ |
---|
| 116 | movsd |
---|
| 117 | /* flag 1 is memory */ |
---|
| 118 | and $1, eax |
---|
| 119 | je 1f |
---|
| 120 | movl $2, ecx |
---|
| 121 | rep movsd |
---|
| 122 | /* flag 2 is the command line */ |
---|
| 123 | 1: movl ebx, eax |
---|
| 124 | and $4, eax |
---|
| 125 | je 3f |
---|
| 126 | movl (_boot_multiboot_info_p), eax |
---|
| 127 | movl 16(eax), esi |
---|
| 128 | movl $255, ecx |
---|
| 129 | 2: movzbl (esi), eax |
---|
| 130 | test al, al |
---|
| 131 | je 3f |
---|
| 132 | movb al, (edi) |
---|
| 133 | inc edi |
---|
| 134 | inc esi |
---|
| 135 | dec ecx |
---|
| 136 | je 3f |
---|
| 137 | jmp 2b |
---|
| 138 | 3: xor al, al |
---|
| 139 | movb al, (edi) |
---|
[ab0df696] | 140 | #ifdef DEBUG_EARLY_START |
---|
[2efdd08] | 141 | /* |
---|
| 142 | * Must get video attribute to have a working printk. |
---|
[6128a4a] | 143 | * Note that the following code assume we already have |
---|
[2efdd08] | 144 | * valid segments and a stack. It should be true for |
---|
| 145 | * any loader starting RTEMS in protected mode (or |
---|
| 146 | * at least I hope so : -)). |
---|
| 147 | */ |
---|
| 148 | call _IBMPC_initVideo |
---|
| 149 | /* |
---|
| 150 | * try printk and a getchar in polling mode ASAP |
---|
| 151 | */ |
---|
[4a4201c] | 152 | movl $welcome_msg, 0(esp) |
---|
[2efdd08] | 153 | call printk |
---|
| 154 | addl $4, esp |
---|
| 155 | |
---|
[2d7d605] | 156 | /* call debugPollingGetChar */ |
---|
[6128a4a] | 157 | |
---|
| 158 | #endif |
---|
[7150f00f] | 159 | |
---|
| 160 | /*----------------------------------------------------------------------------+ |
---|
| 161 | | Load the segment registers (this is done by the board's BSP) and perform any |
---|
[4050a7f] | 162 | | other board specific initialization procedures, this piece of code |
---|
[6128a4a] | 163 | | does not know anything about |
---|
[7150f00f] | 164 | | |
---|
| 165 | | NOTE: Upon return, gs will contain the segment descriptor for a segment which |
---|
| 166 | | maps directly to all of physical memory. |
---|
| 167 | +----------------------------------------------------------------------------*/ |
---|
| 168 | |
---|
| 169 | jmp SYM (_load_segments) # load board dependent segments |
---|
| 170 | |
---|
| 171 | /*----------------------------------------------------------------------------+ |
---|
| 172 | | Set up the stack |
---|
| 173 | +----------------------------------------------------------------------------*/ |
---|
| 174 | |
---|
| 175 | PUBLIC (_establish_stack) |
---|
| 176 | SYM (_establish_stack): |
---|
| 177 | |
---|
| 178 | movl $_end, eax # eax = end of bss/start of heap |
---|
[96d56b3] | 179 | addl $STACK_SIZE, eax # make room for stack |
---|
[23303c03] | 180 | subl $4, eax # reserve room for arg to 'boot_card' |
---|
| 181 | andl $ - CPU_STACK_ALIGNMENT, eax # align SP on CPU_STACK_ALIGNMENT boundary |
---|
[7150f00f] | 182 | movl eax, esp # set stack pointer |
---|
| 183 | movl eax, ebp # set base pointer |
---|
| 184 | |
---|
| 185 | /*----------------------------------------------------------------------------+ |
---|
| 186 | | Zero out the BSS segment |
---|
| 187 | +----------------------------------------------------------------------------*/ |
---|
| 188 | |
---|
| 189 | SYM (zero_bss): |
---|
| 190 | cld # make direction flag count up |
---|
| 191 | movl $ SYM (_end), ecx # find end of .bss |
---|
[3f432fbd] | 192 | movl $ SYM (__bss_start), edi # edi = beginning of .bss |
---|
[7150f00f] | 193 | subl edi, ecx # ecx = size of .bss in bytes |
---|
[f02ffca] | 194 | shrl ecx # size of .bss in longs |
---|
| 195 | shrl ecx |
---|
[7150f00f] | 196 | xorl eax, eax # value to clear out memory |
---|
| 197 | repne # while ecx != 0 |
---|
[14023b45] | 198 | stosl # clear a long in the bss |
---|
[d57c04e] | 199 | |
---|
| 200 | /*-------------------------------------------------------------------+ |
---|
| 201 | | Initialize the video because zero_bss has cleared initVideo parameters |
---|
| 202 | | if it was called earlier |
---|
| 203 | | So from now we can use printk |
---|
| 204 | +-------------------------------------------------------------------*/ |
---|
| 205 | call _IBMPC_initVideo |
---|
[6128a4a] | 206 | |
---|
[4050a7f] | 207 | /*---------------------------------------------------------------------+ |
---|
[ab0df696] | 208 | | Check CPU type. Enable Cache and init coprocessor if needed. |
---|
[4050a7f] | 209 | +---------------------------------------------------------------------*/ |
---|
[ab0df696] | 210 | call checkCPUtypeSetCr0 |
---|
[6128a4a] | 211 | |
---|
[7521e43] | 212 | #ifdef __SSE__ |
---|
| 213 | call SYM(enable_sse) |
---|
| 214 | #endif |
---|
| 215 | |
---|
| 216 | /*---------------------------------------------------------------------+ |
---|
| 217 | | Transfer control to User's Board Support Package |
---|
| 218 | | Note: at the top we reserved space for the argument |
---|
| 219 | | so that |
---|
| 220 | | initial_esp = ( TOS - 4 ) & ~(CPU_STACK_ALIGNMENT-1) |
---|
| 221 | | this ensures that |
---|
| 222 | | 1) esp is now aligned |
---|
| 223 | | 2) there is space for the cmdline pointer which we just |
---|
| 224 | | may store at *(esp) |
---|
| 225 | +---------------------------------------------------------------------*/ |
---|
| 226 | |
---|
| 227 | movl $SYM(_boot_multiboot_cmdline), (esp) |
---|
| 228 | call SYM (boot_card) |
---|
| 229 | |
---|
| 230 | cli # stops interrupts from being processed after hlt! |
---|
| 231 | hlt # shutdown |
---|
| 232 | |
---|
[4a4201c] | 233 | #ifdef __SSE__ |
---|
| 234 | /*--------------------------------------------------------------------+ |
---|
| 235 | | Enable SSE; we really only care about fxsave/fxrstor and leave |
---|
| 236 | | The only feature *we* (as an OS) use is fxsave/fxrstor. |
---|
| 237 | | But as a courtesy we make sure we don't execute on hardware |
---|
| 238 | | that doesn't support features possibly used by the compiler. |
---|
| 239 | +---------------------------------------------------------------------*/ |
---|
[7521e43] | 240 | PUBLIC (enable_sse) |
---|
| 241 | SYM(enable_sse): |
---|
[4a4201c] | 242 | movl SYM (x86_capability), eax |
---|
| 243 | testl $0x01000000, eax |
---|
| 244 | jne 1f |
---|
| 245 | movl $SYM (no_fxsave_msg), 0(esp) |
---|
| 246 | jmp SYM(_sse_panic) |
---|
| 247 | 1: |
---|
| 248 | testl $0x02000000, eax |
---|
| 249 | jne 1f |
---|
| 250 | movl $SYM (no_sse_msg), 0(esp) |
---|
| 251 | jmp SYM(_sse_panic) |
---|
[359e537] | 252 | 1: |
---|
[4a4201c] | 253 | #ifdef __SSE2__ |
---|
| 254 | testl $0x04000000, eax |
---|
| 255 | jne 1f |
---|
| 256 | movl $SYM (no_sse2_msg), 0(esp) |
---|
| 257 | jmp SYM(_sse_panic) |
---|
| 258 | 1: |
---|
| 259 | #endif |
---|
| 260 | #ifdef __SSE3__ |
---|
| 261 | movl SYM (x86_capability_x), eax |
---|
| 262 | testl $1, eax |
---|
| 263 | jne 1f |
---|
| 264 | movl $SYM (no_sse3_msg), 0(esp) |
---|
| 265 | jmp SYM(_sse_panic) |
---|
| 266 | 1: |
---|
| 267 | #endif |
---|
| 268 | mov cr4, eax # OK to enable now |
---|
| 269 | or $0x600, eax |
---|
| 270 | mov eax, cr4 |
---|
[7521e43] | 271 | ret |
---|
[4a4201c] | 272 | |
---|
| 273 | SYM(_sse_panic): |
---|
| 274 | call SYM(printk) |
---|
| 275 | 1: hlt |
---|
| 276 | jmp 1b |
---|
| 277 | #endif |
---|
| 278 | |
---|
[7150f00f] | 279 | END_CODE |
---|
| 280 | |
---|
| 281 | BEGIN_DATA |
---|
[662c157] | 282 | PUBLIC(_boot_multiboot_info_p) |
---|
| 283 | SYM(_boot_multiboot_info_p): |
---|
| 284 | .long 0 |
---|
| 285 | |
---|
| 286 | PUBLIC(_boot_multiboot_info) |
---|
[1c5ebc5] | 287 | PUBLIC(_boot_multiboot_flags) |
---|
| 288 | PUBLIC(_boot_multiboot_memory) |
---|
| 289 | PUBLIC(_boot_multiboot_cmdline) |
---|
[662c157] | 290 | SYM(_boot_multiboot_info): |
---|
[1c5ebc5] | 291 | SYM(_boot_multiboot_flags): |
---|
[662c157] | 292 | .long 0 /* flags */ |
---|
[1c5ebc5] | 293 | SYM(_boot_multiboot_memory): |
---|
[662c157] | 294 | .long 0 /* mem_lower */ |
---|
| 295 | .long 0 /* mem_upper */ |
---|
[1c5ebc5] | 296 | SYM(_boot_multiboot_cmdline): |
---|
| 297 | .rept 256 /* cmd line */ |
---|
| 298 | .byte 0 |
---|
| 299 | .endr |
---|
[359e537] | 300 | |
---|
[4050a7f] | 301 | PUBLIC(_stack_size) |
---|
| 302 | SYM(_stack_size): |
---|
| 303 | .long STACK_SIZE |
---|
[7150f00f] | 304 | |
---|
[2efdd08] | 305 | #ifdef DEBUG_EARLY_START |
---|
[4050a7f] | 306 | |
---|
[2efdd08] | 307 | PUBLIC (welcome_msg) |
---|
| 308 | SYM (welcome_msg) : |
---|
| 309 | .string "Ready to debug RTEMS ?\nEnter <CR>\n" |
---|
| 310 | |
---|
[4050a7f] | 311 | PUBLIC (hex_msg) |
---|
| 312 | SYM (hex_msg) : |
---|
| 313 | .string "0x%x\n" |
---|
[7150f00f] | 314 | |
---|
[4050a7f] | 315 | PUBLIC (made_it_msg) |
---|
| 316 | SYM (made_it_msg) : |
---|
| 317 | .string "made it to %d\n" |
---|
[7150f00f] | 318 | |
---|
[4050a7f] | 319 | #endif |
---|
[7150f00f] | 320 | |
---|
[4a4201c] | 321 | #ifdef __SSE__ |
---|
| 322 | SYM (no_fxsave_msg) : |
---|
| 323 | .string "PANIC: compiled for SSE but CPU seems to have no FXSAVE/FXRSTOR support (which I need)\n" |
---|
| 324 | SYM (no_sse_msg) : |
---|
| 325 | .string "PANIC: compiled for SSE but your CPU seems to have no SSE support\n" |
---|
| 326 | #ifdef __SSE2__ |
---|
| 327 | SYM (no_sse2_msg) : |
---|
| 328 | .string "PANIC: compiled for SSE2 but your CPU seems to have no SSE2 support\n" |
---|
| 329 | #endif |
---|
| 330 | #ifdef __SSE3__ |
---|
| 331 | SYM (no_sse3_msg) : |
---|
| 332 | .string "PANIC: compiled for SSE3 but your CPU seems to have no SSE3 support\n" |
---|
| 333 | #endif |
---|
| 334 | #endif |
---|
| 335 | |
---|
[4050a7f] | 336 | END_DATA |
---|
[7150f00f] | 337 | |
---|
[4050a7f] | 338 | END |
---|