source: rtems/c/src/lib/libbsp/i386/pc386/start/start16.S @ 119204d8

4.104.114.84.95
Last change on this file since 119204d8 was 119204d8, checked in by Joel Sherrill <joel.sherrill@…>, on 01/10/00 at 20:40:41

Removed warning by changing %eax -> %ax as source of move to segment
registers.

  • Property mode set to 100644
File size: 6.2 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 
95.code32
961:
97        /*---------------------------------------------------------------------+
98        | load the other segment registers
99        +---------------------------------------------------------------------*/
100        movl    $PROT_DATA_SEG, %eax
101        movw    %ax, %ds
102        movw    %ax, %es
103        movw    %ax, %ss
104        movl    $start16 + STACKOFF, %esp       # set up stack pointer
105        addl    $start16 + STACKOFF, %ebp       # set up stack pointer
106
107        /*---------------------------------------------------------------------+
108        | we have to enable A20 in order to access memory above 1MByte
109        +---------------------------------------------------------------------*/
110        call    empty_8042
111        movb    $0xD1, %al              # command write
112        outb    %al, $0x64
113        call    empty_8042
114        movb    $0xDF, %al              # A20 on
115        outb    %al, $0x60
116        call    empty_8042
117
118        call    delay
119        call    delay
120        call    delay
121
122        movl    %cs:HDRSTART + HDROFF, %eax     #
123        pushl   %eax                            # jump to start of 32 bit code
124        ret                                     #
125
126/*----------------------------------------------------------------------------+
127| delay
128+------------------------------------------------------------------------------
129| Delay is needed after doing I/O.
130|
131| The outb version is OK on most machines BUT the loop version ...
132|
133| will delay for 1us on 1Gz machine, it will take a little bit
134| longer on slower machines, however, it does not matter because we
135| are going to call this function only a few times
136
137+----------------------------------------------------------------------------*/
138        .p2align 4
139        .globl _delay
140        .globl delay
141delay:
142_delay:
143/*
144        outb    %al, $0x80      # about 1uS delay on most machines
145*/
146/*
147        movl    $0x200, %eax
148delay1:
149        dec     %eax
150        jnz     delay1
151*/
152        ret
153
154/*----------------------------------------------------------------------------+
155| empty_8042
156+------------------------------------------------------------------------------
157| This routine checks that the keyboard command queue is empty (after emptying
158| the output buffers).
159| No timeout is used - if this hangs there is something wrong with the machine,
160| and we probably couldn't proceed anyway.
161+----------------------------------------------------------------------------*/
162        .p2align 4
163        .globl _empty_8042
164        .globl empty_8042
165empty_8042:
166_empty_8042:
167        call    delay
168        inb     $0x64, %al      # 8042 status port
169        testb   $0x01, %al      # output buffer?
170        jz      no_output
171        call    delay
172        in      $0x60, %al      # read it
173        jmp     empty_8042
174no_output:
175        test    $0x02, %al      # is input buffer full?
176        jnz     empty_8042      # yes - loop
177        ret
178       
179/*----------------------------------------------------------------------------+
180| DATA section
181+----------------------------------------------------------------------------*/
182
183/**************************
184* GLOBAL DESCRIPTOR TABLE *
185**************************/
186
187        .p2align 4
188gdtptr:
189        /* we use the NULL descriptor to store the GDT pointer - a trick quite
190           nifty due to: Robert Collins (rcollins@x86.org) */
191        .word   gdtlen - 1
192        .long   gdtptr
193        .word   0x0000
194
195        /* code segment */
196        .word   0xffff, 0
197        .byte   0, 0x9f, 0xcf, 0
198
199        /* data segment */
200        .word   0xffff, 0
201        .byte   0, 0x93, 0xcf, 0
202
203        .set    gdtlen, . - gdtptr      # length of GDT
204       
Note: See TracBrowser for help on using the repository browser.