Version 0.1.1
[seabios.git] / src / romlayout.S
1 // Rom layout and bios assembler to C interface.
2 //
3 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002  MandrakeSoft S.A.
5 //
6 // This file may be distributed under the terms of the GNU GPLv3 license.
7
8 #include "config.h"
9
10         .code16gcc
11         .text
12         .globl bios16c_start, bios16c_end
13 bios16c_start:
14 .include "out/blob.proc.16.s"
15         .text
16 bios16c_end:
17
18
19         .org 0xe05b
20         .globl _start
21 _start:
22         .globl post16
23 post16:
24
25         // Set entry point of rombios32 code - the actual instruction
26         // is altered later in the build process.
27         .globl set_entry32
28 set_entry32:
29         mov $0xf0000000, %ebx
30
31         // init the stack pointer
32         movl $ CONFIG_STACK32_OFFSET , %esp
33
34 transition32:
35         // Disable irqs
36         cli
37
38         // enable a20
39         inb $0x92, %al
40         orb $0x02, %al
41         outb %al, $0x92
42
43         // Set segment descriptors
44         lidt %cs:pmode_IDT_info
45         lgdt %cs:rombios32_gdt_48
46
47         // set PE bit in CR0
48         movl  %cr0, %eax
49         orb   $0x01, %al
50         movl  %eax, %cr0
51
52         // start protected mode code
53         .word 0xea66, 1f, 0x000f, 0x0010 // ljmpl $0x10, $(1f | 0xf0000)
54
55         .code32
56 1:
57         // init data segments
58         movl $0x18, %eax
59         movw %ax, %ds
60         movw %ax, %es
61         movw %ax, %ss
62         xorl %eax, %eax
63         movw %ax, %fs
64         movw %ax, %gs
65
66         cld
67
68         jmp *%ebx
69
70         .code16gcc
71
72 // We need a copy of this string, but we are not actually a PnP BIOS,
73 // so make sure it is *not* aligned, so OSes will not see it if they
74 // scan.
75         .align 2
76         .byte 0
77 pnp_string:
78         .ascii "$PnP"
79
80 // Return from 32bit code to 16bit code - must pass in destination
81 // code segment,offset (%ebx) and the return stack position (%esp).
82
83         .globl call16
84 call16:
85         // restore data segment limits to 0xffff
86         movw $0x28, %ax
87         movw %ax, %ds
88         movw %ax, %es
89         movw %ax, %ss
90         movw %ax, %fs
91         movw %ax, %gs
92
93         // reset PE bit in CR0
94         movl %cr0, %eax
95         andb $0xfe, %al
96         movl %eax, %cr0
97
98         // far jump to flush CPU queue after transition to real mode
99         ljmpw $0xf000, $1f
100 1:
101         // restore IDT to normal real-mode defaults
102         lidt %cs:rmode_IDT_info
103
104         // Setup segment registers
105         xorw %ax, %ax
106         movw %ax, %ds
107         movw %ax, %fs
108         movw %ax, %gs
109         movw $0xf000, %ax
110         movw %ax, %es
111         lea pnp_string, %di
112         movw $ CONFIG_STACK16_SEGMENT , %ax
113         movw %ax, %ss
114         movl %esp, %eax
115         movl $ CONFIG_STACK16_OFFSET , %esp
116
117         // Save info
118         pushl %eax
119         pushl %ebx
120         movl %esp, %ebp
121
122         lcallw %ss:*(%bp)
123
124         // Restore stack and jump back to 32bit mode.
125         popl %eax
126         popl %esp
127
128         // Set resume point of rombios32 code - the actual instruction
129         // is altered later in the build process.
130         .globl set_resume32
131 set_resume32:
132         mov $0xf0000000, %ebx
133
134         jmp transition32
135
136
137 // Protected mode IDT descriptor
138 //
139 // I just make the limit 0, so the machine will shutdown
140 // if an exception occurs during protected mode memory
141 // transfers.
142 //
143 // Set base to f0000 to correspond to beginning of BIOS,
144 // in case I actually define an IDT later
145 // Set limit to 0
146 pmode_IDT_info:
147         .word 0x0000  // limit 15:00
148         .word 0x0000  // base  15:00
149         .byte 0x0f    // base  23:16
150
151 // Real mode IDT descriptor
152 //
153 // Set to typical real-mode values.
154 // base  = 000000
155 // limit =   03ff
156 rmode_IDT_info:
157         .word 0x03ff  // limit 15:00
158         .word 0x0000  // base  15:00
159         .byte 0x00    // base  23:16
160
161 rombios32_gdt_48:
162         .word 0x30
163         .word rombios32_gdt
164         .word 0x000f
165
166 rombios32_gdt:
167         .word 0, 0, 0, 0
168         .word 0, 0, 0, 0
169         .word 0xffff, 0, 0x9b00, 0x00cf // 32 bit flat code segment (0x10)
170         .word 0xffff, 0, 0x9300, 0x00cf // 32 bit flat data segment (0x18)
171         .word 0xffff, 0, 0x9b0f, 0x0000 // 16 bit code segment base=0xf0000 limit=0xffff
172         .word 0xffff, 0, 0x9300, 0x0000 // 16 bit data segment base=0x0 limit=0xffff
173
174
175         .macro ENTRY cfunc
176         pushal
177         pushw %es
178         pushw %ds
179         movw %ss, %ax
180         movw %ax, %ds
181         mov %esp, %eax
182         call \cfunc
183         popw %ds
184         popw %es
185         popal
186         .endm
187
188         .macro IRQ_ENTRY num
189         .globl entry_\num
190         entry_\num :
191         ENTRY handle_\num
192         iretw
193         .endm
194
195
196         .org 0xe2c3
197         IRQ_ENTRY nmi
198
199         IRQ_ENTRY 13
200         IRQ_ENTRY 19
201         IRQ_ENTRY 12
202         IRQ_ENTRY 11
203         IRQ_ENTRY 76
204         IRQ_ENTRY 18
205         IRQ_ENTRY 1c
206         IRQ_ENTRY 70
207         IRQ_ENTRY 74
208         IRQ_ENTRY 75
209
210         .org 0xe3fe
211         jmp entry_13
212
213         .org 0xe401
214         // XXX - Fixed Disk Parameter Table
215
216         .org 0xe6f2
217         jmp entry_19
218
219         .org 0xe6f5
220 .include "out/cbt.proc.16.s"
221         .text
222
223         .org 0xe729
224         // XXX - Baud Rate Generator Table
225
226         .org 0xe739
227         IRQ_ENTRY 14
228
229         .org 0xe82e
230         IRQ_ENTRY 16
231
232         .org 0xe987
233         IRQ_ENTRY 09
234
235         .org 0xec59
236         IRQ_ENTRY 40
237
238         .org 0xef57
239         IRQ_ENTRY 0e
240
241         .org 0xefc7
242         // XXX - Diskette Controller Parameter Table
243
244         .org 0xefd2
245         IRQ_ENTRY 17
246
247         .org 0xf045
248         // XXX int 10
249         iretw
250
251         .org 0xf065
252         IRQ_ENTRY 10
253
254         .org 0xf0a4
255         // XXX int 1D
256         iretw
257
258         .org 0xf841
259         jmp entry_12
260
261         .org 0xf84d
262         jmp entry_11
263
264         .org 0xf859
265         IRQ_ENTRY 15
266
267         .org 0xfa6e
268 .include "out/font.proc.16.s"
269         .text
270
271         .org 0xfe6e
272         IRQ_ENTRY 1a
273
274         .org 0xfea5
275         IRQ_ENTRY 08
276
277         .org 0xfef3
278         // XXX - Initial Interrupt Vector Offsets Loaded by POST
279
280         .org 0xff00
281         // XXX - BIOS_COPYRIGHT_STRING
282         .ascii "(c) 2002 MandrakeSoft S.A. Written by Kevin Lawton & the Bochs team."
283
284         .org 0xff53
285         .globl dummy_iret_handler
286 dummy_iret_handler:
287         iretw
288
289         .org 0xff54
290         IRQ_ENTRY 05
291
292         .org 0xfff0 // Power-up Entry Point
293         ljmpw $0xf000, $post16
294
295         .org 0xfff5
296         // BIOS build date
297         .ascii "06/23/99"
298
299         .org 0xfffe
300         // model byte 0xFC = AT
301         .byte 0xfc
302         .byte 0x00
303
304         .end