source: rtems/c/src/lib/libbsp/i386/pc386/start/start16.s @ eb562f2

4.104.114.84.9
Last change on this file since eb562f2 was eb562f2, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 21, 1998 at 4:39:52 PM

Patch from Eric Valette <valette@…>:

Here is a patch that enables to catch exception
and get message before crashing RTEMS :)

It should be generic to any Intel port although enabled
only for pc386 BSP...

[Joel] I fixed the bug I introduced in irq_asm.s...

  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*-------------------------------------------------------------------------+
2| start16.s v1.0 - PC386 BSP - 1998/04/13
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 partly based on (from the Linux source tree):
21|   video.S - Copyright (C) 1995, 1996 Martin Mares <mj@k332.feld.cvut.cz>
22+--------------------------------------------------------------------------*/
23
24
25/*----------------------------------------------------------------------------+
26| Constants
27+----------------------------------------------------------------------------*/
28
29.set PROT_CODE_SEG, 0x08        # offset of code segment descriptor into GDT
30.set PROT_DATA_SEG, 0x10        # offset of code segment descriptor into GDT
31.set CR0_PE,        1           # protected mode flag on CR0 register
32.set HDRSTART,      HEADERADDR  # address of start of bin2boot header
33.set HDROFF,        0x24        # offset into bin2boot header of start32 addr
34.set STACKOFF,      0x200-0x10  # offset to load into %esp, from start of image
35
36/* #define NEW_GAS*/
37/*----------------------------------------------------------------------------+
38| CODE section
39+----------------------------------------------------------------------------*/
40
41.text
42
43        .globl _start16         # entry point
44        .globl start16
45start16:
46_start16:
47
48.code16
49
50        cli                     # DISABLE INTERRUPTS!!!
51
52        movw    %cs, %ax        #
53        movw    %ax, %ds        # set the rest of real mode registers
54        movw    %ax, %es        #
55        movw    %ax, %ss        #
56
57#if defined(RTEMS_VIDEO_80x50)
58       
59        /*---------------------------------------------------------------------+
60        | Switch VGA video to 80 lines x 50 columns mode. Has to be done before
61        | turning protected mode on since it uses BIOS int 10h (video) services.
62        +---------------------------------------------------------------------*/
63
64        movw    $0x0003, %ax    # forced set
65        int     $0x10
66        movw    $0x1112, %ax    # use 8x8 font
67        xorb    %bl, %bl
68        int     $0x10
69        movw    $0x1201, %ax    # turn off cursor emulation
70        movb    $0x34, %bl
71        int     $0x10
72        movb    $0x01, %ah      # define cursor (scan lines 0 to 7)
73        movw    $0x0007, %cx
74        int     $0x10
75
76#endif /* RTEMS_VIDEO_80x50 */
77
78        /*---------------------------------------------------------------------+
79        | Bare PC machines boot in real mode! We have to turn protected mode on.
80        +---------------------------------------------------------------------*/
81#ifdef NEW_GAS
82        data32
83        addr32
84#endif 
85        lgdt    gdtptr - start16        # load Global Descriptor Table
86        movl    %cr0, %eax
87        orl     $CR0_PE, %eax
88        movl    %eax, %cr0              # turn on protected mode
89       
90#ifdef NEW_GAS
91        ljmpl   $PROT_CODE_SEG, $1f     # flush prefetch queue, and reload %cs
92#else
93        ljmp    $PROT_CODE_SEG, $1f     # flush prefetch queue, and reload %cs
94#endif 
951:
96
97.code32
98
99        /*---------------------------------------------------------------------+
100        | load the other segment registers
101        +---------------------------------------------------------------------*/
102        movl    $PROT_DATA_SEG, %eax
103        movl    %ax, %ds
104        movl    %ax, %es
105        movl    %ax, %ss
106        movl    $start16 + STACKOFF, %esp       # set up stack pointer
107        addl    $start16 + STACKOFF, %ebp       # set up stack pointer
108
109        /*---------------------------------------------------------------------+
110        | we have to enable A20 in order to access memory above 1MByte
111        +---------------------------------------------------------------------*/
112        call    empty_8042
113        movb    $0xD1, %al              # command write
114        outb    %al, $0x64
115        call    empty_8042
116        movb    $0xDF, %al              # A20 on
117        outb    %al, $0x60
118        call    empty_8042
119
120        movl    %cs:HDRSTART + HDROFF, %eax     #
121        pushl   %eax                            # jump to start of 32 bit code
122        ret                                     #
123
124/*----------------------------------------------------------------------------+
125| delay
126+------------------------------------------------------------------------------
127| Delay is needed after doing I/O. We do it by writing to a non-existent port.
128+----------------------------------------------------------------------------*/
129        .globl _delay
130        .globl delay
131delay:
132_delay:
133        outb    %al, $0xED      # about 1uS delay
134        ret
135
136/*----------------------------------------------------------------------------+
137| empty_8042
138+------------------------------------------------------------------------------
139| This routine checks that the keyboard command queue is empty (after emptying
140| the output buffers).
141| No timeout is used - if this hangs there is something wrong with the machine,
142| and we probably couldn't proceed anyway.
143+----------------------------------------------------------------------------*/
144        .globl _empty_8042
145        .globl empty_8042
146empty_8042:
147_empty_8042:
148        call    delay
149        inb     $0x64, %al      # 8042 status port
150        testb   $0x01, %al      # output buffer?
151        jz      no_output
152        call    delay
153        in      $0x60, %al      # read it
154        jmp     empty_8042
155no_output:
156        test    $0x02, %al      # is input buffer full?
157        jnz     empty_8042      # yes - loop
158        ret
159       
160/*----------------------------------------------------------------------------+
161| DATA section
162+----------------------------------------------------------------------------*/
163
164/**************************
165* GLOBAL DESCRIPTOR TABLE *
166**************************/
167
168        .p2align 4
169gdtptr:
170        /* we use the NULL descriptor to store the GDT pointer - a trick quite
171           nifty due to: Robert Collins (rcollins@x86.org) */
172        .word   gdtlen - 1
173        .long   gdtptr
174        .word   0x0000
175
176        /* code segment */
177        .word   0xffff, 0
178        .byte   0, 0x9f, 0xcf, 0
179
180        /* data segment */
181        .word   0xffff, 0
182        .byte   0, 0x93, 0xcf, 0
183
184        .set    gdtlen, . - gdtptr      # length of GDT
185       
Note: See TracBrowser for help on using the repository browser.