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

4.115
Last change on this file since 441b90e was 441b90e, checked in by Jennifer Averett <Jennifer.Averett@…>, on Feb 1, 2012 at 8:32:28 PM

Correct run-time selection of console port.

This was broken by conversion of console driver to libchip style.

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