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

4.104.114.84.95
Last change on this file since d13b247 was d13b247, checked in by Joel Sherrill <joel.sherrill@…>, on Jun 25, 1998 at 6:42:30 PM

Clean up from Aleksey Romanov (Quality Quorum <qqi@…>).
Here are his comments:

I removed all unnecessary stuff from start16.s - setting idt and
setting 16-bit stack using .code32 istructions.

  • Property mode set to 100644
File size: 5.7 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
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
82        lgdt    gdtptr - start16        # load Global Descriptor Table
83       
84        movl    %cr0, %eax
85        orl     $CR0_PE, %eax
86        movl    %eax, %cr0              # turn on protected mode
87       
88        ljmp    $PROT_CODE_SEG, $1f     # flush prefetch queue, and reload %cs
891:
90
91.code32
92
93        /*---------------------------------------------------------------------+
94        | load the other segment registers
95        +---------------------------------------------------------------------*/
96        movl    $PROT_DATA_SEG, %eax
97        movl    %ax, %ds
98        movl    %ax, %es
99        movl    %ax, %ss
100        movl    $start16 + STACKOFF, %esp       # set up stack pointer
101        addl    $start16 + STACKOFF, %ebp       # set up stack pointer
102
103        /*---------------------------------------------------------------------+
104        | we have to enable A20 in order to access memory above 1MByte
105        +---------------------------------------------------------------------*/
106        call    empty_8042
107        movb    $0xD1, %al              # command write
108        outb    %al, $0x64
109        call    empty_8042
110        movb    $0xDF, %al              # A20 on
111        outb    %al, $0x60
112        call    empty_8042
113
114        movl    %cs:HDRSTART + HDROFF, %eax     #
115        pushl   %eax                            # jump to start of 32 bit code
116        ret                                     #
117
118/*----------------------------------------------------------------------------+
119| delay
120+------------------------------------------------------------------------------
121| Delay is needed after doing I/O. We do it by writing to a non-existent port.
122+----------------------------------------------------------------------------*/
123        .globl _delay
124        .globl delay
125delay:
126_delay:
127        outb    %al, $0xED      # about 1uS delay
128        ret
129
130/*----------------------------------------------------------------------------+
131| empty_8042
132+------------------------------------------------------------------------------
133| This routine checks that the keyboard command queue is empty (after emptying
134| the output buffers).
135| No timeout is used - if this hangs there is something wrong with the machine,
136| and we probably couldn't proceed anyway.
137+----------------------------------------------------------------------------*/
138        .globl _empty_8042
139        .globl empty_8042
140empty_8042:
141_empty_8042:
142        call    delay
143        inb     $0x64, %al      # 8042 status port
144        testb   $0x01, %al      # output buffer?
145        jz      no_output
146        call    delay
147        in      $0x60, %al      # read it
148        jmp     empty_8042
149no_output:
150        test    $0x02, %al      # is input buffer full?
151        jnz     empty_8042      # yes - loop
152        ret
153       
154/*----------------------------------------------------------------------------+
155| DATA section
156+----------------------------------------------------------------------------*/
157
158/**************************
159* GLOBAL DESCRIPTOR TABLE *
160**************************/
161
162        .p2align 4
163gdtptr:
164        /* we use the NULL descriptor to store the GDT pointer - a trick quite
165           nifty due to: Robert Collins (rcollins@x86.org) */
166        .word   gdtlen - 1
167        .long   gdtptr
168        .word   0x0000
169
170        /* code segment */
171        .word   0xffff, 0
172        .byte   0, 0x9f, 0xcf, 0
173
174        /* data segment */
175        .word   0xffff, 0
176        .byte   0, 0x93, 0xcf, 0
177
178        .set    gdtlen, . - gdtptr      # length of GDT
179       
Note: See TracBrowser for help on using the repository browser.