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

4.104.114.84.95
Last change on this file since ea57368 was 3c7916f, checked in by Joel Sherrill <joel.sherrill@…>, on 06/03/98 at 19:00:57

Update from Pedro Romano <pmcnr@…> with an attempt
to fix start16.s. It does not work locally.

  • Property mode set to 100644
File size: 6.4 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| A Descriptor table register has the following format:
38+----------------------------------------------------------------------------*/
39
40.set DTR_LIMIT, 0               # offset of two byte limit
41.set DTR_BASE,  2               # offset of four byte base address
42.set DTR_SIZE,  6               # size of DTR register
43
44/*----------------------------------------------------------------------------+
45| CODE section
46+----------------------------------------------------------------------------*/
47
48.text
49
50        .globl _start16         # entry point
51        .globl start16
52start16:
53_start16:
54
55.code16
56
57        cli                     # DISABLE INTERRUPTS!!!
58
59        movw    %cs, %ax        #
60        movw    %ax, %ds        # set the rest of real mode registers
61        movw    %ax, %es        #
62        movw    %ax, %ss        #
63
64.code32
65
66        movl    $STACKOFF, %esp # set stack pointer
67        movl    $STACKOFF, %ebp #
68
69.code16
70
71#if defined(RTEMS_VIDEO_80x50)
72       
73        /*---------------------------------------------------------------------+
74        | Switch VGA video to 80 lines x 50 columns mode. Has to be done before
75        | turning protected mode on since it uses BIOS int 10h (video) services.
76        +---------------------------------------------------------------------*/
77
78        movw    $0x0003, %ax    # forced set
79        int     $0x10
80        movw    $0x1112, %ax    # use 8x8 font
81        xorb    %bl, %bl
82        int     $0x10
83        movw    $0x1201, %ax    # turn off cursor emulation
84        movb    $0x34, %bl
85        int     $0x10
86        movb    $0x01, %ah      # define cursor (scan lines 0 to 7)
87        movw    $0x0007, %cx
88        int     $0x10
89
90#endif /* RTEMS_VIDEO_80x50 */
91
92        /*---------------------------------------------------------------------+
93        | Bare PC machines boot in real mode! We have to turn protected mode on.
94        +---------------------------------------------------------------------*/
95
96        lgdt    gdtptr - start16        # load Global Descriptor Table
97        lidt    idtptr - start16        # load Interrupt Descriptor Table
98       
99        movl    %cr0, %eax
100        orl     $CR0_PE, %eax
101        movl    %eax, %cr0              # turn on protected mode
102       
103        ljmp    $PROT_CODE_SEG, $1f     # flush prefetch queue, and reload %cs
1041:
105
106.code32
107
108        /*---------------------------------------------------------------------+
109        | load the other segment registers
110        +---------------------------------------------------------------------*/
111        movl    $PROT_DATA_SEG, %eax
112        movl    %ax, %ds
113        movl    %ax, %es
114        movl    %ax, %ss
115        addl    $start16, %esp          # fix up stack pointer
116        addl    $start16, %ebp          # fix up stack pointer
117
118        /*---------------------------------------------------------------------+
119        | we have to enable A20 in order to access memory above 1MByte
120        +---------------------------------------------------------------------*/
121        call    empty_8042
122        movb    $0xD1, %al              # command write
123        outb    %al, $0x64
124        call    empty_8042
125        movb    $0xDF, %al              # A20 on
126        outb    %al, $0x60
127        call    empty_8042
128
129        movl    %cs:HDRSTART + HDROFF, %eax     #
130        pushl   %eax                            # jump to start of 32 bit code
131        ret                                     #
132
133/*----------------------------------------------------------------------------+
134| delay
135+------------------------------------------------------------------------------
136| Delay is needed after doing I/O. We do it by writing to a non-existent port.
137+----------------------------------------------------------------------------*/
138        .globl _delay
139        .globl delay
140delay:
141_delay:
142        outb    %al, $0xED      # about 1uS delay
143        ret
144
145/*----------------------------------------------------------------------------+
146| empty_8042
147+------------------------------------------------------------------------------
148| This routine checks that the keyboard command queue is empty (after emptying
149| the output buffers).
150| No timeout is used - if this hangs there is something wrong with the machine,
151| and we probably couldn't proceed anyway.
152+----------------------------------------------------------------------------*/
153        .globl _empty_8042
154        .globl empty_8042
155empty_8042:
156_empty_8042:
157        call    delay
158        inb     $0x64, %al      # 8042 status port
159        testb   $0x01, %al      # output buffer?
160        jz      no_output
161        call    delay
162        in      $0x60, %al      # read it
163        jmp     empty_8042
164no_output:
165        test    $0x02, %al      # is input buffer full?
166        jnz     empty_8042      # yes - loop
167        ret
168       
169/*----------------------------------------------------------------------------+
170| DATA section
171+----------------------------------------------------------------------------*/
172
173/**************************
174* GLOBAL DESCRIPTOR TABLE *
175**************************/
176
177        .align  4
178gdtptr:
179        /* we use the NULL descriptor to store the GDT pointer - a trick quite
180           nifty due to: Robert Collins (rcollins@x86.org) */
181        .word   gdtlen - 1
182        .long   gdtptr
183        .word   0x0000
184
185        /* code segment */
186        .word   0xffff, 0
187        .byte   0, 0x9f, 0xcf, 0
188
189        /* data segment */
190        .word   0xffff, 0
191        .byte   0, 0x93, 0xcf, 0
192
193        .set    gdtlen, . - gdtptr      # length of GDT
194       
195/*************************************
196* INTERRUPT DESCRIPTOR TABLE POINTER *
197*************************************/
198
199        .align  4
200idtptr:
201        .word   0x07ff  # limit at maximum (allows all 256 interrupts)
202        .word   0, 0    # base at 0
Note: See TracBrowser for help on using the repository browser.