source: rtems/c/src/lib/libbsp/i386/pc386/start/start.S @ 4081032

4.115
Last change on this file since 4081032 was 4081032, checked in by Ben Gras <beng@…>, on 12/02/14 at 22:36:59

pc386 bsp fix for default mode

If USE_VBE_RM is 0, vesa_realmode_bootup_init() is not available so the
test should be #if instead of #ifdef.

  • Property mode set to 100644
File size: 9.7 KB
Line 
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-2012.
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.org/license/LICENSE.
33| **************************************************************************
34+--------------------------------------------------------------------------*/
35
36/*
37 * The most trivial start.s possible. It does not know anything
38 * about system it is running on, so it will jump to appropriate
39 * place in BSP specific place to do things it knows nothing about
40 */
41
42#include <rtems/asm.h>
43#include <rtems/score/cpu.h>
44#include <bspopts.h>
45
46/*----------------------------------------------------------------------------+
47| Size of heap and stack:
48+----------------------------------------------------------------------------*/
49
50#ifndef CPU_STACK_ALIGNMENT
51#error  "Missing header ? CPU_STACK_ALIGNMENT NOT DEFINED"
52#endif
53
54.set STACK_SIZE, 0x1000
55
56/*----------------------------------------------------------------------------+
57| CODE section
58+----------------------------------------------------------------------------*/
59
60BEGIN_CODE
61
62        PUBLIC (start)          # GNU default entry point
63
64        EXTERN (boot_card)
65#if USE_VBE_RM
66        EXTERN (vesa_realmode_bootup_init)
67#endif
68        EXTERN (_load_segments)
69        EXTERN (_return_to_monitor)
70        EXTERN (_IBMPC_initVideo)
71        EXTERN (debugPollingGetChar)
72        EXTERN (checkCPUtypeSetCr0)
73        EXTERN (printk)
74#ifdef __SSE__
75        EXTERN (x86_capability)
76#ifdef __SSE3__
77        EXTERN (x86_capability_x)
78#endif
79#endif
80
81/*
82 * In case this crashes on your machine and this is not due
83 * to video mode set by the loader, you may try to define
84 * the following variable:
85 */
86/* #define DEBUG_EARLY_START */
87
88SYM (start):
89        /*
90         *  When things are really, REALLY!, bad -- turn on the speaker and
91         *  lock up.  This shows whether or not we make it to a certain
92         *  location.
93         */
94#if 0
95        inb     $0x61, al
96        orb     $0x03, al
97        outb    al, $0x61       # enable the speaker
98speakl: jmp     speakl             # and SPIN!!!
99#endif
100
101        nop
102        cli                     # DISABLE INTERRUPTS!!!
103        cld
104
105        /* Save multiboot info if we detect a multiboot loader */
106        cmp     $0x2badb002,eax
107        jne     2f
108
109        /* We have multiboot info; let's hope DS and ES are OK... */
110        movl    ebx, SYM(_boot_multiboot_info_p)
111        /* Check for memory size info and save */
112        movl    ebx, esi
113        movl    (esi), eax
114        movl    eax, ebx
115        movl    $SYM(_boot_multiboot_info), edi
116        /* save flags, always present */
117        movsd
118        /* flag 1 is memory */
119        and     $1, eax
120        je      1f
121        movl    $2, ecx
122        rep movsd
123        /* flag 2 is the command line */
1241:      movl    ebx, eax
125        and     $4, eax
126        je      3f
127        movl    (_boot_multiboot_info_p), eax
128        movl    16(eax), esi
129        movl    $255, ecx
1302:      movzbl  (esi), eax
131        test    al, al
132        je      3f
133        movb    al, (edi)
134        inc     edi
135        inc     esi
136        dec     ecx
137        je      3f
138        jmp     2b
1393:      xor     al, al
140        movb    al, (edi)
141#ifdef DEBUG_EARLY_START
142        /*
143         * Must get video attribute to have a working printk.
144         * Note that the following code assume we already have
145         * valid segments and a stack. It should be true for
146         * any loader starting RTEMS in protected mode (or
147         * at least I hope so : -)).
148         */
149        call _IBMPC_initVideo
150        /*
151         * try printk and a getchar in polling mode ASAP
152         */
153        movl    $welcome_msg, 0(esp)
154        call    printk
155        addl    $4, esp
156
157        /* call debugPollingGetChar */
158
159#endif
160
161/*----------------------------------------------------------------------------+
162| Load the segment registers (this is done by the board's BSP) and perform any
163| other board specific initialization procedures, this piece of code
164| does not know anything about
165|
166| NOTE: Upon return, gs will contain the segment descriptor for a segment which
167|       maps directly to all of physical memory.
168+----------------------------------------------------------------------------*/
169
170        jmp     SYM (_load_segments)    # load board dependent segments
171
172/*----------------------------------------------------------------------------+
173| Set up the stack
174+----------------------------------------------------------------------------*/
175
176        PUBLIC (_establish_stack)
177SYM (_establish_stack):
178
179        movl    $_end, eax              # eax = end of bss/start of heap
180        addl    $STACK_SIZE, eax        # make room for stack
181        subl    $4,          eax    # reserve room for arg to 'boot_card'
182        andl    $ - CPU_STACK_ALIGNMENT, eax    # align SP on CPU_STACK_ALIGNMENT boundary
183        movl    eax, esp                # set stack pointer
184        movl    eax, ebp                # set base pointer
185
186/*----------------------------------------------------------------------------+
187| Zero out the BSS segment
188+----------------------------------------------------------------------------*/
189
190SYM (zero_bss):
191        cld                             # make direction flag count up
192        movl    $ SYM (_end), ecx       # find end of .bss
193        movl    $ SYM (__bss_start), edi # edi = beginning of .bss
194        subl    edi, ecx                # ecx = size of .bss in bytes
195        shrl    ecx                     # size of .bss in longs
196        shrl    ecx
197        xorl    eax, eax                # value to clear out memory
198        repne                           # while ecx != 0
199        stosl                           #   clear a long in the bss
200
201/*-------------------------------------------------------------------+
202| Initialize the video because zero_bss has cleared initVideo parameters
203| if it was called earlier
204| So from now we can use printk
205+-------------------------------------------------------------------*/
206        call _IBMPC_initVideo
207
208#if USE_VBE_RM
209        call    vesa_realmode_bootup_init
210#endif
211
212/*---------------------------------------------------------------------+
213| Check CPU type. Enable Cache and init coprocessor if needed.
214+---------------------------------------------------------------------*/
215        call checkCPUtypeSetCr0
216
217#ifdef __SSE__
218        call SYM(enable_sse)
219#endif
220
221/*---------------------------------------------------------------------+
222| Transfer control to User's Board Support Package
223| Note: at the top we reserved space for the argument
224|       so that
225|          initial_esp = ( TOS - 4 ) & ~(CPU_STACK_ALIGNMENT-1)
226|       this ensures that
227|       1) esp is now aligned
228|       2) there is space for the cmdline pointer which we just
229|          may store at *(esp)
230+---------------------------------------------------------------------*/
231
232        movl    $SYM(_boot_multiboot_cmdline), (esp)
233        call    SYM (boot_card)
234
235        cli     # stops interrupts from being processed after hlt!
236        hlt     # shutdown
237
238#ifdef __SSE__
239/*--------------------------------------------------------------------+
240 | Enable SSE; we really only care about fxsave/fxrstor and leave
241 | The only feature *we* (as an OS) use is fxsave/fxrstor.
242 | But as a courtesy we make sure we don't execute on hardware
243 | that doesn't support features possibly used by the compiler.
244+---------------------------------------------------------------------*/
245        PUBLIC (enable_sse)
246SYM(enable_sse):
247        movl    SYM (x86_capability), eax
248        testl   $0x01000000, eax
249        jne     1f
250        movl    $SYM (no_fxsave_msg), 0(esp)
251        jmp     SYM(_sse_panic)
2521:
253        testl   $0x02000000, eax
254        jne     1f
255        movl    $SYM (no_sse_msg), 0(esp)
256        jmp     SYM(_sse_panic)
2571:
258#ifdef __SSE2__
259        testl   $0x04000000, eax
260        jne     1f
261        movl    $SYM (no_sse2_msg), 0(esp)
262        jmp     SYM(_sse_panic)
2631:
264#endif
265#ifdef __SSE3__
266        movl    SYM (x86_capability_x), eax
267        testl   $1, eax
268        jne     1f
269        movl    $SYM (no_sse3_msg), 0(esp)
270        jmp     SYM(_sse_panic)
2711:
272#endif
273        mov     cr4, eax                # OK to enable now
274        or      $0x600, eax
275        mov     eax, cr4
276        ret
277
278SYM(_sse_panic):
279        call SYM(printk)
2801:      hlt
281        jmp 1b
282#endif
283
284END_CODE
285
286BEGIN_DATA
287        PUBLIC(_boot_multiboot_info_p)
288SYM(_boot_multiboot_info_p):
289        .long 0
290
291        PUBLIC(_boot_multiboot_info)
292        PUBLIC(_boot_multiboot_flags)
293        PUBLIC(_boot_multiboot_memory)
294        PUBLIC(_boot_multiboot_cmdline)
295SYM(_boot_multiboot_info):
296SYM(_boot_multiboot_flags):
297        .long 0 /* flags */
298SYM(_boot_multiboot_memory):
299        .long 0 /* mem_lower */
300        .long 0 /* mem_upper */
301SYM(_boot_multiboot_cmdline):
302        .rept 256 /* cmd line */
303        .byte 0
304        .endr
305
306        PUBLIC(_stack_size)
307SYM(_stack_size):
308        .long STACK_SIZE
309
310#ifdef DEBUG_EARLY_START
311
312        PUBLIC (welcome_msg)
313SYM (welcome_msg) :
314        .string "Ready to debug RTEMS ?\nEnter <CR>\n"
315
316        PUBLIC (hex_msg)
317SYM (hex_msg) :
318        .string "0x%x\n"
319
320        PUBLIC (made_it_msg)
321SYM (made_it_msg) :
322        .string "made it to %d\n"
323
324#endif
325
326#ifdef __SSE__
327SYM (no_fxsave_msg) :
328        .string "PANIC: compiled for SSE but CPU seems to have no FXSAVE/FXRSTOR support (which I need)\n"
329SYM (no_sse_msg) :
330        .string "PANIC: compiled for SSE but your CPU seems to have no SSE support\n"
331#ifdef __SSE2__
332SYM (no_sse2_msg) :
333        .string "PANIC: compiled for SSE2 but your CPU seems to have no SSE2 support\n"
334#endif
335#ifdef __SSE3__
336SYM (no_sse3_msg) :
337        .string "PANIC: compiled for SSE3 but your CPU seems to have no SSE3 support\n"
338#endif
339#endif
340
341END_DATA
342
343END
Note: See TracBrowser for help on using the repository browser.