source: rtems/c/src/lib/libbsp/i386/pc386/start/start.s @ 96d56b3

4.104.114.84.95
Last change on this file since 96d56b3 was 96d56b3, checked in by Joel Sherrill <joel.sherrill@…>, on 04/27/98 at 18:42:04

Update from Pedro Romano <pmcnr@…>.

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