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