source: rtems/c/src/lib/libbsp/i386/pc386/start/start.s @ 2efdd08

4.104.114.84.95
Last change on this file since 2efdd08 was 2efdd08, checked in by Joel Sherrill <joel.sherrill@…>, on 05/20/98 at 17:06:57

Patch from Ralf Corseipus to fix latent configure problems suddenly triggered:

The breakdown:

  • CC_FOR_TARGET and CXX_FOR_TARGET were not correctly re-read from autoconf's configuration cache (config.cache)
  • If <target>-[gcc|g++] was not found while running configure, the config macros tried to use other (wrong) compilers (e.g. cc).

Changes:

  • New RTEMS_PROG_CC macro (aclocal/prog-cc.m4).
  • New RTEMS_PROG_CXX macro (aclocal/prog-cxx.m4)
  • Moved a shell script fragment from configure.in to a new m4-autoconf macro (New file: aclocal/tool-prefix.m4)
  • Minor changes to configure.in

I tested it with linux/posix (native gcc/primary libc) and
sh-rtems/gensh1 on a linux host and didn't notice any bugs
related to the problems mentioned above. There seem to be
more bugs with the posix bsp, but I consider them minor as
the build run completed successfully. It is just too late
for me to attempt to fix them now.

  • Property mode set to 100644
File size: 10.6 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|
16| Modified the 20/05/1998  by valette@crf.canon.fr in order to give a working
17| example of eraly stage debugging via the DEBUG_EARLY_START define.
18|
19+--------------------------------------------------------------------------+
20| Disclaimer:
21|
22| This file is provided "AS IS" without warranty of any kind, either
23| expressed or implied.
24+--------------------------------------------------------------------------+
25| This code is based on an earlier generation RTEMS i386 start.s and the
26| following copyright applies:
27|
28| **************************************************************************
29| *  COPYRIGHT (c) 1989-1998.
30| *  On-Line Applications Research Corporation (OAR).
31| *  Copyright assigned to U.S. Government, 1994.
32| *
33| *  The license and distribution terms for this file may be
34| *  found in the file LICENSE in this distribution or at
35| *  http://www.OARcorp.com/rtems/license.html.
36| **************************************************************************
37|
38|  $Id$
39+--------------------------------------------------------------------------*/
40
41
42#include "asm.h"
43
44/*----------------------------------------------------------------------------+
45| A Descriptor table register has the following format:
46+----------------------------------------------------------------------------*/
47
48.set DTR_LIMIT, 0               # offset of two byte limit
49.set DTR_BASE,  2               # offset of four byte base address
50.set DTR_SIZE,  6               # size of DTR register
51
52/*----------------------------------------------------------------------------+
53| Size of heap and stack:       
54+----------------------------------------------------------------------------*/
55
56.set HEAP_SIZE,  0x2000
57.set STACK_SIZE, 0x1000
58
59/*----------------------------------------------------------------------------+
60| CODE section
61+----------------------------------------------------------------------------*/
62
63BEGIN_CODE
64
65        PUBLIC (start)          # GNU default entry point
66
67        EXTERN (boot_card)
68        EXTERN (load_segments)
69        EXTERN (exit)
70        EXTERN (_IBMPC_initVideo)
71        EXTERN (debugPoolingGetChar)
72
73/*
74 * In case it crash on your machine and this is not due
75 * to video mode set by the loader, you may try to define
76 * the follwoing variable
77#define DEBUG_EARLY_START
78 */
79       
80SYM (start):
81
82        nop
83        cli                     # DISABLE INTERRUPTS!!!
84#ifdef DEBUG_EARLY_START
85        cld
86        /*
87         * Must get video attribute to have a working printk.
88         * Note that the following code assume we already have
89         * valid segments and a stack. It should be true for
90         * any loader starting RTEMS in protected mode (or
91         * at least I hope so : -)).
92         */
93        call _IBMPC_initVideo
94        /*
95         * try printk and a getchar in polling mode ASAP
96         */
97        pushl   $welcome_msg
98        call    printk
99        addl    $4, esp
100
101        call    debugPoolingGetChar
102#endif 
103
104/*----------------------------------------------------------------------------+
105| Load the segment registers (this is done by the board's BSP) and perform any
106| other board specific initialization procedures.
107|
108| NOTE: Upon return, gs will contain the segment descriptor for a segment which
109|       maps directly to all of physical memory.
110+----------------------------------------------------------------------------*/
111
112        jmp     SYM (_load_segments)    # load board dependent segments
113
114/*----------------------------------------------------------------------------+
115| Set up the stack
116+----------------------------------------------------------------------------*/
117
118        PUBLIC (_establish_stack)
119SYM (_establish_stack):
120
121        movl    $_end, eax              # eax = end of bss/start of heap
122        addl    $HEAP_SIZE, eax         # eax = end of heap
123        movl    eax, stack_start        # Save for brk() routine
124        addl    $STACK_SIZE, eax        # make room for stack
125        andl    $0xffffffc0, eax        # align it on 16 byte boundary
126        movl    eax, esp                # set stack pointer
127        movl    eax, ebp                # set base pointer
128
129/*----------------------------------------------------------------------------+
130| Zero out the BSS segment
131+----------------------------------------------------------------------------*/
132
133SYM (zero_bss):
134        cld                             # make direction flag count up
135        movl    $ SYM (_end), ecx       # find end of .bss
136        movl    $ SYM (_bss_start), edi # edi = beginning of .bss
137        subl    edi, ecx                # ecx = size of .bss in bytes
138        shrl    ecx                     # size of .bss in longs
139        shrl    ecx
140        xorl    eax, eax                # value to clear out memory
141        repne                           # while ecx != 0
142        stosl                           #   clear a long in the bss
143
144        /*---------------------------------------------------------------------+
145        | Copy the Global Descriptor Table to our space
146        +---------------------------------------------------------------------*/
147
148        sgdt    SYM (_Original_GDTR)    # save original GDT
149        movzwl  SYM (_Original_GDTR)+DTR_LIMIT, ecx     # size of GDT in bytes;
150                                        # limit is 8192 entries * 8 bytes per
151
152        /*---------------------------------------------------------------------+
153        | make ds:esi point to the original GDT
154        +---------------------------------------------------------------------*/
155
156        movl    SYM (_Original_GDTR)+DTR_BASE, esi
157        push    ds                      # save ds
158        movw    gs, ax
159        movw    ax, ds
160
161        /*---------------------------------------------------------------------+
162        | make es:edi point to the new (our copy) GDT
163        +---------------------------------------------------------------------*/
164
165        movl    $ SYM (_Global_descriptor_table), edi
166
167        rep
168        movsb                           # copy the GDT (ds:esi -> es:edi)
169
170        pop     ds                      # restore ds
171
172        /*---------------------------------------------------------------------+
173        | Build and load new contents of GDTR
174        +---------------------------------------------------------------------*/
175
176        movw    SYM (_Original_GDTR)+DTR_LIMIT, ecx     # set new limit
177        movw    cx, SYM (_New_GDTR)+DTR_LIMIT
178
179        push    $ SYM (_Global_descriptor_table)
180        push    es
181        call    SYM (i386_Logical_to_physical)
182        addl    $6, esp
183        movl    eax, SYM (_New_GDTR)+DTR_BASE   # set new base
184
185        cmpb    $0, SYM (_Do_Load_GDT)  # Should the new GDT be loaded?
186        je      SYM (no_gdt_load)       # NO, then branch
187        lgdt    SYM (_New_GDTR)         # load the new GDT
188
189SYM (no_gdt_load):
190
191        /*---------------------------------------------------------------------+
192        | Copy the Interrupt Descriptor Table to our space
193        +---------------------------------------------------------------------*/
194
195        sidt    SYM (_Original_IDTR)    # save original IDT
196        movzwl  SYM (_Original_IDTR)+DTR_LIMIT, ecx     # size of IDT in bytes;
197                                        #limit is 256 entries * 8 bytes per
198
199        /*---------------------------------------------------------------------+
200        | make ds:esi point to the original IDT
201        +---------------------------------------------------------------------*/
202
203        movl    SYM (_Original_IDTR)+DTR_BASE, esi
204
205        push    ds                      # save ds
206        movw    gs, ax
207        movw    ax, ds
208
209        /*---------------------------------------------------------------------+
210        | make es:edi point to the new (our copy) IDT
211        +---------------------------------------------------------------------*/
212
213        movl    $ SYM (Interrupt_descriptor_table), edi
214
215        rep
216        movsb                           # copy the IDT (ds:esi -> es:edi)
217        pop     ds                      # restore ds
218
219        /*---------------------------------------------------------------------+
220        | Build and load new contents of IDTR
221        +---------------------------------------------------------------------*/
222
223        movw    SYM (_Original_IDTR+DTR_LIMIT), ecx     # set new limit
224        movw    cx, SYM (_New_IDTR)+DTR_LIMIT
225
226        push    $ SYM (Interrupt_descriptor_table)
227        push    es
228        call    SYM (i386_Logical_to_physical)
229        addl    $6, esp
230        movl    eax, SYM (_New_IDTR)+DTR_BASE           # set new base
231
232        cmpb    $0, SYM (_Do_Load_IDT)  # Should the new IDT be loaded?
233        je      SYM (no_idt_load)       # NO, then branch
234        lidt    SYM (_New_IDTR)         # load the new IDT
235
236SYM (no_idt_load):
237
238        /*---------------------------------------------------------------------+
239        | Initialize the i387.
240        |
241        | Using the NO WAIT form of the instruction insures that if it is not
242        | present the board will not lock up or get an exception.
243        +---------------------------------------------------------------------*/
244
245        fninit                          # MUST USE NO-WAIT FORM
246
247        /*---------------------------------------------------------------------+
248        | Transfer control to User's Board Support Package
249        +---------------------------------------------------------------------*/
250
251        pushl   $0                      # environp
252        pushl   $0                      # argv
253        pushl   $0                      # argc
254        call    SYM (boot_card)
255        addl    $12, esp
256
257        /*---------------------------------------------------------------------+
258        | Clean up
259        +---------------------------------------------------------------------*/
260
261        EXTERN (return_to_monitor)
262
263        PUBLIC (Bsp_cleanup)
264
265SYM (Bsp_cleanup):
266
267        cmpb    $0, SYM (_Do_Load_IDT)  # Was the new IDT loaded?
268        je      SYM (no_idt_restore)    # NO, then branch
269        lidt    SYM (_Original_IDTR)    # restore the new IDT
270
271SYM (no_idt_restore):
272
273        cmpb    $0, SYM (_Do_Load_GDT)  # Was the new GDT loaded?
274        je      SYM (no_gdt_restore)    # NO, then branch
275        lgdt    SYM (_Original_GDTR)    # restore the new GDT
276
277SYM (no_gdt_restore):
278
279        jmp     SYM (_return_to_monitor)
280
281END_CODE
282
283/*----------------------------------------------------------------------------+
284| DATA section
285+----------------------------------------------------------------------------*/
286
287BEGIN_DATA
288
289        EXTERN (Do_Load_IDT)    # defined in the BSP
290        EXTERN (Do_Load_GDT)    # defined in the BSP
291
292        .align  2
293        PUBLIC (start_frame)
294SYM (start_frame):
295        .long   0
296
297        PUBLIC (stack_start)
298SYM (stack_start):
299        .long   0
300
301#ifdef DEBUG_EARLY_START
302       
303        PUBLIC (welcome_msg)
304SYM (welcome_msg) :
305        .string "Ready to debug RTEMS ?\nEnter <CR>\n"
306
307#endif
308               
309END_DATA
310
311/*----------------------------------------------------------------------------+
312| BSS section
313+----------------------------------------------------------------------------*/
314
315BEGIN_BSS
316
317        PUBLIC (_heap_size)
318SYM (_heap_size):
319        .long   HEAP_SIZE
320
321        PUBLIC (_stack_size)
322SYM (_stack_size):
323        .long   STACK_SIZE
324
325        PUBLIC (Interrupt_descriptor_table)
326SYM (Interrupt_descriptor_table):
327        .space (256 * 8)        # reserve space for all 256 interrupts
328
329        PUBLIC (_Original_IDTR)
330SYM (_Original_IDTR):
331        .space DTR_SIZE
332
333        PUBLIC (_New_IDTR)
334SYM (_New_IDTR):
335        .space DTR_SIZE
336
337        PUBLIC (_Global_descriptor_table)
338SYM (_Global_descriptor_table):
339        .space (3 * 8)  # the PC386 bsp only needs 3 segment descriptors:
340                        #   NULL, CODE and DATA
341        PUBLIC (_Original_GDTR)
342SYM (_Original_GDTR):
343        .space DTR_SIZE
344
345        PUBLIC (_New_GDTR)
346SYM (_New_GDTR):
347        .space DTR_SIZE
348
349        PUBLIC (_Physical_base_of_ds)
350SYM (_Physical_base_of_ds):
351        .space 4
352
353        PUBLIC (_Physical_base_of_cs)
354SYM (_Physical_base_of_cs):
355        .space 4
356
357END_BSS
358
359END
Note: See TracBrowser for help on using the repository browser.