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 | +--------------------------------------------------------------------------+ |
---|
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 | +--------------------------------------------------------------------------+ |
---|
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 | | ************************************************************************** |
---|
27 | | * COPYRIGHT (c) 1989-1999. |
---|
28 | | * On-Line Applications Research Corporation (OAR). |
---|
29 | | * |
---|
30 | | * The license and distribution terms for this file may be |
---|
31 | | * found in the file LICENSE in this distribution or at |
---|
32 | | * http://www.rtems.com/license/LICENSE. |
---|
33 | | ************************************************************************** |
---|
34 | | |
---|
35 | | $Id$ |
---|
36 | +--------------------------------------------------------------------------*/ |
---|
37 | |
---|
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 | */ |
---|
43 | |
---|
44 | #include <rtems/asm.h> |
---|
45 | |
---|
46 | /*----------------------------------------------------------------------------+ |
---|
47 | | Size of heap and stack: |
---|
48 | +----------------------------------------------------------------------------*/ |
---|
49 | |
---|
50 | .set STACK_SIZE, 0x1000 |
---|
51 | |
---|
52 | /*----------------------------------------------------------------------------+ |
---|
53 | | CODE section |
---|
54 | +----------------------------------------------------------------------------*/ |
---|
55 | |
---|
56 | BEGIN_CODE |
---|
57 | |
---|
58 | PUBLIC (start) # GNU default entry point |
---|
59 | |
---|
60 | EXTERN (boot_card) |
---|
61 | EXTERN (_load_segments) |
---|
62 | EXTERN (_return_to_monitor) |
---|
63 | EXTERN (_IBMPC_initVideo) |
---|
64 | EXTERN (debugPollingGetChar) |
---|
65 | EXTERN (checkCPUtypeSetCr0) |
---|
66 | |
---|
67 | /* |
---|
68 | * In case this crashes on your machine and this is not due |
---|
69 | * to video mode set by the loader, you may try to define |
---|
70 | * the following variable: |
---|
71 | */ |
---|
72 | /* #define DEBUG_EARLY_START */ |
---|
73 | |
---|
74 | SYM (start): |
---|
75 | /* |
---|
76 | * When things are really, REALLY!, bad -- turn on the speaker and |
---|
77 | * lock up. This shows whether or not we make it to a certain |
---|
78 | * location. |
---|
79 | */ |
---|
80 | #if 0 |
---|
81 | inb $0x61, al |
---|
82 | orb $0x03, al |
---|
83 | outb al, $0x61 # enable the speaker |
---|
84 | speakl: jmp speakl # and SPIN!!! |
---|
85 | #endif |
---|
86 | |
---|
87 | nop |
---|
88 | cli # DISABLE INTERRUPTS!!! |
---|
89 | cld |
---|
90 | |
---|
91 | /* Save multiboot info if we detect a multiboot loader */ |
---|
92 | cmp $0x2badb002,eax |
---|
93 | jne 2f |
---|
94 | |
---|
95 | /* We have multiboot info; let's hope DS and ES are OK... */ |
---|
96 | movl ebx, SYM(_boot_multiboot_info_p) |
---|
97 | /* Check for memory size info and save */ |
---|
98 | movl ebx, esi |
---|
99 | movl (esi), eax |
---|
100 | movl eax, ebx |
---|
101 | movl $SYM(_boot_multiboot_info), edi |
---|
102 | /* save flags, always present */ |
---|
103 | movsd |
---|
104 | /* flag 1 is memory */ |
---|
105 | and $1, eax |
---|
106 | je 1f |
---|
107 | movl $2, ecx |
---|
108 | rep movsd |
---|
109 | /* flag 2 is the command line */ |
---|
110 | 1: movl ebx, eax |
---|
111 | and $4, eax |
---|
112 | je 3f |
---|
113 | movl (_boot_multiboot_info_p), eax |
---|
114 | movl 16(eax), esi |
---|
115 | movl $255, ecx |
---|
116 | 2: movzbl (esi), eax |
---|
117 | test al, al |
---|
118 | je 3f |
---|
119 | movb al, (edi) |
---|
120 | inc edi |
---|
121 | inc esi |
---|
122 | dec ecx |
---|
123 | je 3f |
---|
124 | jmp 2b |
---|
125 | 3: xor al, al |
---|
126 | movb al, (edi) |
---|
127 | #ifdef DEBUG_EARLY_START |
---|
128 | /* |
---|
129 | * Must get video attribute to have a working printk. |
---|
130 | * Note that the following code assume we already have |
---|
131 | * valid segments and a stack. It should be true for |
---|
132 | * any loader starting RTEMS in protected mode (or |
---|
133 | * at least I hope so : -)). |
---|
134 | */ |
---|
135 | call _IBMPC_initVideo |
---|
136 | /* |
---|
137 | * try printk and a getchar in polling mode ASAP |
---|
138 | */ |
---|
139 | pushl $welcome_msg |
---|
140 | call printk |
---|
141 | addl $4, esp |
---|
142 | |
---|
143 | /* call debugPollingGetChar */ |
---|
144 | |
---|
145 | #endif |
---|
146 | |
---|
147 | /*----------------------------------------------------------------------------+ |
---|
148 | | Load the segment registers (this is done by the board's BSP) and perform any |
---|
149 | | other board specific initialization procedures, this piece of code |
---|
150 | | does not know anything about |
---|
151 | | |
---|
152 | | NOTE: Upon return, gs will contain the segment descriptor for a segment which |
---|
153 | | maps directly to all of physical memory. |
---|
154 | +----------------------------------------------------------------------------*/ |
---|
155 | |
---|
156 | jmp SYM (_load_segments) # load board dependent segments |
---|
157 | |
---|
158 | /*----------------------------------------------------------------------------+ |
---|
159 | | Set up the stack |
---|
160 | +----------------------------------------------------------------------------*/ |
---|
161 | |
---|
162 | PUBLIC (_establish_stack) |
---|
163 | SYM (_establish_stack): |
---|
164 | |
---|
165 | movl $_end, eax # eax = end of bss/start of heap |
---|
166 | addl $STACK_SIZE, eax # make room for stack |
---|
167 | andl $0xffffffc0, eax # align it on 16 byte boundary |
---|
168 | movl eax, esp # set stack pointer |
---|
169 | movl eax, ebp # set base pointer |
---|
170 | |
---|
171 | /*----------------------------------------------------------------------------+ |
---|
172 | | Zero out the BSS segment |
---|
173 | +----------------------------------------------------------------------------*/ |
---|
174 | |
---|
175 | SYM (zero_bss): |
---|
176 | cld # make direction flag count up |
---|
177 | movl $ SYM (_end), ecx # find end of .bss |
---|
178 | movl $ SYM (__bss_start), edi # edi = beginning of .bss |
---|
179 | subl edi, ecx # ecx = size of .bss in bytes |
---|
180 | shrl ecx # size of .bss in longs |
---|
181 | shrl ecx |
---|
182 | xorl eax, eax # value to clear out memory |
---|
183 | repne # while ecx != 0 |
---|
184 | stosl # clear a long in the bss |
---|
185 | |
---|
186 | /*-------------------------------------------------------------------+ |
---|
187 | | Initialize the video because zero_bss has cleared initVideo parameters |
---|
188 | | if it was called earlier |
---|
189 | | So from now we can use printk |
---|
190 | +-------------------------------------------------------------------*/ |
---|
191 | call _IBMPC_initVideo |
---|
192 | |
---|
193 | /*---------------------------------------------------------------------+ |
---|
194 | | Check CPU type. Enable Cache and init coprocessor if needed. |
---|
195 | +---------------------------------------------------------------------*/ |
---|
196 | call checkCPUtypeSetCr0 |
---|
197 | |
---|
198 | /*---------------------------------------------------------------------+ |
---|
199 | | Transfer control to User's Board Support Package |
---|
200 | +---------------------------------------------------------------------*/ |
---|
201 | |
---|
202 | movl $SYM(_boot_multiboot_cmdline), eax |
---|
203 | pushl eax # cmdline |
---|
204 | call SYM (boot_card) |
---|
205 | addl $4, esp |
---|
206 | |
---|
207 | /*---------------------------------------------------------------------+ |
---|
208 | | Clean up - we do not know anything about it, so we will |
---|
209 | | jump to BSP specific code to do cleanup |
---|
210 | +---------------------------------------------------------------------*/ |
---|
211 | |
---|
212 | jmp SYM (_return_to_monitor) |
---|
213 | |
---|
214 | END_CODE |
---|
215 | |
---|
216 | BEGIN_DATA |
---|
217 | PUBLIC(_boot_multiboot_info_p) |
---|
218 | SYM(_boot_multiboot_info_p): |
---|
219 | .long 0 |
---|
220 | |
---|
221 | PUBLIC(_boot_multiboot_info) |
---|
222 | PUBLIC(_boot_multiboot_flags) |
---|
223 | PUBLIC(_boot_multiboot_memory) |
---|
224 | PUBLIC(_boot_multiboot_cmdline) |
---|
225 | SYM(_boot_multiboot_info): |
---|
226 | SYM(_boot_multiboot_flags): |
---|
227 | .long 0 /* flags */ |
---|
228 | SYM(_boot_multiboot_memory): |
---|
229 | .long 0 /* mem_lower */ |
---|
230 | .long 0 /* mem_upper */ |
---|
231 | SYM(_boot_multiboot_cmdline): |
---|
232 | .rept 256 /* cmd line */ |
---|
233 | .byte 0 |
---|
234 | .endr |
---|
235 | |
---|
236 | PUBLIC(_stack_size) |
---|
237 | SYM(_stack_size): |
---|
238 | .long STACK_SIZE |
---|
239 | |
---|
240 | #ifdef DEBUG_EARLY_START |
---|
241 | |
---|
242 | PUBLIC (welcome_msg) |
---|
243 | SYM (welcome_msg) : |
---|
244 | .string "Ready to debug RTEMS ?\nEnter <CR>\n" |
---|
245 | |
---|
246 | PUBLIC (hex_msg) |
---|
247 | SYM (hex_msg) : |
---|
248 | .string "0x%x\n" |
---|
249 | |
---|
250 | PUBLIC (made_it_msg) |
---|
251 | SYM (made_it_msg) : |
---|
252 | .string "made it to %d\n" |
---|
253 | |
---|
254 | #endif |
---|
255 | |
---|
256 | END_DATA |
---|
257 | |
---|
258 | END |
---|