blob: c8b77935f70663d0236143464e586e43bb865652 [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// 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//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05006// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05007
Kevin O'Connord9a8b2d2008-11-16 09:17:02 -05008#include "config.h" // CONFIG_*
9#include "ioport.h" // PORT_A20
Kevin O'Connor3eac0092008-11-16 09:59:32 -050010#include "bregs.h" // CR0_*
Kevin O'Connor18e38b22008-12-10 20:40:13 -050011#include "cmos.h" // CMOS_RESET_CODE
Kevin O'Connor952974e2008-11-16 18:14:33 -050012#include "../out/asm-offsets.h" // BREGS_*
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050013
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050014
15/****************************************************************
16 * Include of 16bit C code
17 ****************************************************************/
18
Kevin O'Connor74534532008-05-12 18:28:58 -040019 .code16gcc
Kevin O'Connor9e821222008-12-06 18:56:19 -050020.include "out/ccode.16.s"
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050021
22
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050023/****************************************************************
Kevin O'Connor1d019512008-03-11 21:21:47 -040024 * Entry macros
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050025 ****************************************************************/
26
Kevin O'Connor1d019512008-03-11 21:21:47 -040027 // Call a C function - this does the minimal work necessary to
28 // call into C. It sets up %ds, backs up %es, and backs up
29 // those registers that are call clobbered by the C compiler.
30 .macro ENTRY cfunc
31 cld
Kevin O'Connor18f368e2008-03-31 21:56:04 -040032 pushl %eax // Save registers clobbered by C code
Kevin O'Connor1d019512008-03-11 21:21:47 -040033 pushl %ecx
34 pushl %edx
35 pushw %es
36 pushw %ds
Kevin O'Connor18f368e2008-03-31 21:56:04 -040037 movw %ss, %ax // Move %ss to %ds
Kevin O'Connor1d019512008-03-11 21:21:47 -040038 movw %ax, %ds
Kevin O'Connorb3c28be2008-06-08 13:34:43 -040039 pushl %esp // Backup %esp, then clear high bits
40 movzwl %sp, %esp
Kevin O'Connor1d019512008-03-11 21:21:47 -040041 calll \cfunc
Kevin O'Connorb3c28be2008-06-08 13:34:43 -040042 popl %esp // Restore %esp (including high bits)
Kevin O'Connor18f368e2008-03-31 21:56:04 -040043 popw %ds // Restore registers saved above
Kevin O'Connor1d019512008-03-11 21:21:47 -040044 popw %es
45 popl %edx
46 popl %ecx
47 popl %eax
48 .endm
49
50 // Call a C function with current register list as an
51 // argument. This backs up the registers and sets %eax
52 // to point to the backup. On return, the registers are
53 // restored from the structure.
54 .macro ENTRY_ARG cfunc
55 cld
Kevin O'Connor18f368e2008-03-31 21:56:04 -040056 pushl %eax // Save registers (matches struct bregs)
Kevin O'Connor1d019512008-03-11 21:21:47 -040057 pushl %ecx
58 pushl %edx
59 pushl %ebx
60 pushl %esi
61 pushl %edi
62 pushw %es
63 pushw %ds
Kevin O'Connor18f368e2008-03-31 21:56:04 -040064 movw %ss, %ax // Move %ss to %ds
Kevin O'Connor1d019512008-03-11 21:21:47 -040065 movw %ax, %ds
Kevin O'Connorb3c28be2008-06-08 13:34:43 -040066 movl %esp, %ebx // Backup %esp, then zero high bits
67 movzwl %sp, %esp
68 movl %esp, %eax // First arg is pointer to struct bregs
69 calll \cfunc
70 movl %ebx, %esp // Restore %esp (including high bits)
71 popw %ds // Restore registers (from struct bregs)
72 popw %es
73 popl %edi
74 popl %esi
75 popl %ebx
76 popl %edx
77 popl %ecx
78 popl %eax
79 .endm
80
81 // As above, but don't mangle %esp
82 .macro ENTRY_ARG_ESP cfunc
83 cld
84 pushl %eax // Save registers (matches struct bregs)
85 pushl %ecx
86 pushl %edx
87 pushl %ebx
88 pushl %esi
89 pushl %edi
90 pushw %es
91 pushw %ds
92 movw %ss, %ax // Move %ss to %ds
93 movw %ax, %ds
Kevin O'Connor18f368e2008-03-31 21:56:04 -040094 movl %esp, %eax // First arg is pointer to struct bregs
Kevin O'Connor1d019512008-03-11 21:21:47 -040095 calll \cfunc
Kevin O'Connor18f368e2008-03-31 21:56:04 -040096 popw %ds // Restore registers (from struct bregs)
Kevin O'Connor1d019512008-03-11 21:21:47 -040097 popw %es
98 popl %edi
99 popl %esi
100 popl %ebx
101 popl %edx
102 popl %ecx
103 popl %eax
104 .endm
105
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500106 // Macro to reset the 16bit stack
107 // Clobbers %ax
108 .macro RESET_STACK
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500109 xorw %ax, %ax
110 movw %ax, %ss
Kevin O'Connor276d4a92008-06-11 22:47:01 -0400111 movl $ BUILD_STACK_ADDR , %esp
Kevin O'Connor44eeaf12008-07-06 10:14:49 -0400112 cld
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500113 .endm
114
Kevin O'Connor74534532008-05-12 18:28:58 -0400115 // Specify a location in the fixed part of bios area.
116 .macro ORG addr
Kevin O'Connor202024a2009-01-17 10:41:28 -0500117 .section .fixedaddr.\addr
Kevin O'Connor74534532008-05-12 18:28:58 -0400118 .endm
119
Kevin O'Connor1d019512008-03-11 21:21:47 -0400120
121/****************************************************************
122 * POST handler
123 ****************************************************************/
124
Kevin O'Connor74534532008-05-12 18:28:58 -0400125 ORG 0xe05b
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500126post16:
Kevin O'Connor50cf4f12008-10-25 23:06:23 -0400127 // enable cache
128 movl %cr0, %eax
Kevin O'Connor3eac0092008-11-16 09:59:32 -0500129 andl $~(CR0_CD|CR0_NW), %eax
Kevin O'Connor50cf4f12008-10-25 23:06:23 -0400130 movl %eax, %cr0
131
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500132 // Check for restart indicator.
133 movl $CMOS_RESET_CODE, %eax
134 outb %al, $PORT_CMOS_INDEX
135 inb $PORT_CMOS_DATA, %al
136 cmpb $0x0, %al
137 jnz entry_resume
138
139 // Normal entry point
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500140 RESET_STACK
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500141
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400142 pushl $_code32__start
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500143
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500144 // Fall through to transition32 function below
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500145
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500146
147/****************************************************************
148 * Call trampolines
149 ****************************************************************/
150
151// Place CPU into 32bit mode from 16bit mode.
152// Clobbers: %eax, flags, stack registers, cr0, idt/gdt
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500153transition32:
154 // Disable irqs
155 cli
156
157 // enable a20
Kevin O'Connord9a8b2d2008-11-16 09:17:02 -0500158 inb $PORT_A20, %al
159 orb $A20_ENABLE_BIT, %al
160 outb %al, $PORT_A20
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500161
162 // Set segment descriptors
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500163 lidtw %cs:pmode_IDT_info
164 lgdtw %cs:rombios32_gdt_48
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500165
Kevin O'Connor3eac0092008-11-16 09:59:32 -0500166 // Enable protected mode
167 movl %cr0, %eax
168 orl $CR0_PE, %eax
169 movl %eax, %cr0
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500170
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500171 // start 32bit protected mode code
Kevin O'Connor14927082008-11-08 19:07:49 -0500172 ljmpl $SEG32_MODE32_CS, $(BUILD_BIOS_ADDR + 1f)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500173
174 .code32
1751:
176 // init data segments
Kevin O'Connor14927082008-11-08 19:07:49 -0500177 movl $SEG32_MODE32_DS, %eax
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500178 movw %ax, %ds
179 movw %ax, %es
180 movw %ax, %ss
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500181 movw %ax, %fs
182 movw %ax, %gs
183
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500184 retl
185
186// Call a 16bit function from 32bit mode.
Kevin O'Connorcb6735f2008-03-01 13:39:52 -0500187// %eax = address of struct bregs
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500188// Clobbers: all gp registers, flags, stack registers, cr0, idt/gdt
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500189 .global __call16_from32, __call16big_from32
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500190__call16_from32:
191 pushl %eax
192
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500193 // restore data segment limits to 0xffff
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500194 movl $SEG32_MODE16_DS, %eax
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500195 movw %ax, %ds
196 movw %ax, %es
197 movw %ax, %ss
198 movw %ax, %fs
199 movw %ax, %gs
200
Kevin O'Connor1a72e2e2008-11-11 22:03:55 -0500201 // disable a20
Kevin O'Connord9a8b2d2008-11-16 09:17:02 -0500202 inb $PORT_A20, %al
203 andb $~A20_ENABLE_BIT, %al
204 outb %al, $PORT_A20
Kevin O'Connor1a72e2e2008-11-11 22:03:55 -0500205
206 // Jump to 16bit mode
207 ljmpw $SEG32_MODE16_CS, $1f
208
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500209__call16big_from32:
210 pushl %eax
211
212 movl $SEG32_MODE16BIG_DS, %eax
213 movw %ax, %ds
214 movw %ax, %es
215 movw %ax, %ss
216 movw %ax, %fs
217 movw %ax, %gs
218
219 ljmpl $SEG32_MODE16BIG_CS, $(BUILD_BIOS_ADDR + 1f)
220
Kevin O'Connor1a72e2e2008-11-11 22:03:55 -0500221 .code16gcc
2221:
Kevin O'Connor3eac0092008-11-16 09:59:32 -0500223 // Disable protected mode
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500224 movl %cr0, %eax
Kevin O'Connor3eac0092008-11-16 09:59:32 -0500225 andl $~CR0_PE, %eax
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500226 movl %eax, %cr0
227
228 // far jump to flush CPU queue after transition to real mode
Kevin O'Connore3677b12008-07-04 15:29:23 -0400229 ljmpw $SEG_BIOS, $2f
Kevin O'Connor21e930b2008-03-01 09:49:37 -0500230
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -05002312:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500232 // restore IDT to normal real-mode defaults
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500233 lidtw %cs:rmode_IDT_info
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500234
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500235 // Clear segment registers
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500236 xorw %ax, %ax
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500237 movw %ax, %fs
238 movw %ax, %gs
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500239 movw %ax, %es
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500240 movw %ax, %ds
241 movw %ax, %ss // Assume stack is in segment 0
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500242
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500243 popl %eax
Kevin O'Connor18f368e2008-03-31 21:56:04 -0400244
245 // Set __call16 return address to be transition32
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500246 pushl $transition32
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500247
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500248 // Fall through to __call16
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500249
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500250
Kevin O'Connor21e930b2008-03-01 09:49:37 -0500251// Call a 16bit function from 16bit mode with a specified cpu register state
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500252// %eax = address of struct bregs
253// Clobbers: all gp registers, es
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400254 .global __call16
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500255__call16:
256 // Save eax
257 pushl %eax
258
259 // Setup for iretw call
Kevin O'Connore3677b12008-07-04 15:29:23 -0400260 pushw $SEG_BIOS
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500261 pushw $1f // return point
Kevin O'Connor952974e2008-11-16 18:14:33 -0500262 pushw BREGS_flags(%eax) // flags
263 pushl BREGS_ip(%eax) // CS:IP
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500264
265 // Load calling registers.
Kevin O'Connor952974e2008-11-16 18:14:33 -0500266 movl BREGS_edi(%eax), %edi
267 movl BREGS_esi(%eax), %esi
268 movl BREGS_ebx(%eax), %ebx
269 movl BREGS_edx(%eax), %edx
270 movl BREGS_ecx(%eax), %ecx
271 movw BREGS_es(%eax), %es
272 movw BREGS_ds(%eax), %ds
273 movl %ss:BREGS_eax(%eax), %eax
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500274
275 // Invoke call
276 iretw // XXX - just do a lcalll
2771:
278 // Store flags, eax, ecx
279 pushfw
280 pushl %eax
281 movl 0x06(%esp), %eax
Kevin O'Connor952974e2008-11-16 18:14:33 -0500282 movl %ecx, %ss:BREGS_ecx(%eax)
283 movw %ds, %ss:BREGS_ds(%eax)
Kevin O'Connorcbbb6672008-03-08 13:04:10 -0500284 movw %ss, %cx
Kevin O'Connor952974e2008-11-16 18:14:33 -0500285 movw %cx, %ds // Restore %ds == %ss
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500286 popl %ecx
Kevin O'Connor952974e2008-11-16 18:14:33 -0500287 movl %ecx, BREGS_eax(%eax)
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500288 popw %cx
Kevin O'Connor952974e2008-11-16 18:14:33 -0500289 movw %cx, BREGS_flags(%eax)
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500290
291 // Store remaining registers
Kevin O'Connor952974e2008-11-16 18:14:33 -0500292 movw %es, BREGS_es(%eax)
293 movl %edi, BREGS_edi(%eax)
294 movl %esi, BREGS_esi(%eax)
295 movl %ebx, BREGS_ebx(%eax)
296 movl %edx, BREGS_edx(%eax)
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500297
298 // Remove %eax
299 popl %eax
300
Kevin O'Connored128492008-03-11 11:14:59 -0400301 cld
302
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500303 retl
304
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500305// Entry point when a post call looks like a resume.
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500306// %eax = shutdown status from cmos
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500307entry_resume:
308 // Save old shutdown status.
309 movl %eax, %ebx
310
311 // Clear shutdown status register.
312 movl $CMOS_RESET_CODE, %eax
313 outb %al, $PORT_CMOS_INDEX
314 xorl %eax, %eax
315 outb %al, $PORT_CMOS_DATA
316
317 // Use a stack in EBDA
318 movw $SEG_BDA, %ax
319 movw %ax, %ds
Kevin O'Connorc5b50362008-12-18 21:56:41 -0500320 movw BDA_ebda_seg, %ax
321 movw %ax, %ss
322 movw %ax, %ds
Kevin O'Connor7f343092009-01-01 18:31:11 -0500323 movl $EBDA_OFFSET_TOP_STACK, %esp
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500324
325 // Call handler.
326 movl %ebx, %eax
327 cld
328 cli
329 jmp handle_resume
Kevin O'Connor18f368e2008-03-31 21:56:04 -0400330
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500331// PnP trampolines
332 .global entry_pnp_real, entry_pnp_prot
333entry_pnp_prot:
334 pushl %esp
335 jmp 1f
336entry_pnp_real:
337 pushl %esp // Backup %esp, then clear high bits
338 movzwl %sp, %esp
3391:
340 pushfl // Save registers clobbered by C code
341 pushl %eax
342 pushl %ecx
343 pushl %edx
344 pushw %es
345 pushw %ds
346 movw %ss, %cx // Move %ss to %ds
347 movw %cx, %ds
348 lea 28(%esp), %eax // %eax points to start of u16 args
349 calll handle_pnp
350 movw %ax, 12(%esp) // Modify %eax to return %ax
351 popw %ds
352 popw %es
353 popl %edx
354 popl %ecx
355 popl %eax
356 popfl
357 popl %esp
358 lretw
359
Kevin O'Connor18f368e2008-03-31 21:56:04 -0400360// APM trampolines
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400361 .global apm16protected_entry
Kevin O'Connor1d019512008-03-11 21:21:47 -0400362apm16protected_entry:
363 pushfw // save flags
364 pushl %eax // dummy
365 ENTRY_ARG handle_1553
Kevin O'Connorb3c28be2008-06-08 13:34:43 -0400366 addw $4, %sp // pop dummy
Kevin O'Connor1d019512008-03-11 21:21:47 -0400367 popfw // restore flags
368 lretw
369
370 .code32
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400371 .global apm32protected_entry
Kevin O'Connor1d019512008-03-11 21:21:47 -0400372apm32protected_entry:
Kevin O'Connor68296e82008-03-13 21:33:26 -0400373 pushfw
374 pushw %cs // Setup for long jump to 16bit mode
375 pushw $1f
Kevin O'Connor0fae9e12008-06-07 14:51:14 -0400376 addw $8, 2(%esp)
Kevin O'Connor68296e82008-03-13 21:33:26 -0400377 ljmpw *(%esp)
378 .code16gcc
3791:
Kevin O'Connorb3c28be2008-06-08 13:34:43 -0400380 ENTRY_ARG_ESP handle_1553
Kevin O'Connor68296e82008-03-13 21:33:26 -0400381
382 movw $2f,(%esp) // Setup for long jump back to 32bit mode
Kevin O'Connor0fae9e12008-06-07 14:51:14 -0400383 subw $8, 2(%esp)
Kevin O'Connor68296e82008-03-13 21:33:26 -0400384 ljmpw *(%esp)
385 .code32
3862:
Kevin O'Connor1d019512008-03-11 21:21:47 -0400387 addl $4, %esp // pop call address
388 popfw
389 lretl
Kevin O'Connoree4f9ff2008-07-05 21:19:10 -0400390
391// 32bit elf entry point
392 .global post32
393post32:
394 cli
395 cld
396 lidtl (BUILD_BIOS_ADDR + pmode_IDT_info)
397 lgdtl (BUILD_BIOS_ADDR + rombios32_gdt_48)
398 movl $BUILD_STACK_ADDR, %esp
Kevin O'Connor14927082008-11-08 19:07:49 -0500399 ljmpl $SEG32_MODE32_CS, $_code32__start
Kevin O'Connoree4f9ff2008-07-05 21:19:10 -0400400
Kevin O'Connor1d019512008-03-11 21:21:47 -0400401 .code16gcc
Kevin O'Connor1d019512008-03-11 21:21:47 -0400402
Kevin O'Connor484270d2008-08-17 10:50:57 -0400403// Shutdown a CPU. We want this in the 0xf000 section to ensure that
404// the code wont be overwritten with something else. (Should
405// something spurious wake up the CPU, we want to be sure that the hlt
406// insn will still be present and will shutdown the CPU.)
407 .global permanent_halt
408permanent_halt:
409 cli
4101: hlt
411 jmp 1b
412
Kevin O'Connorc5b50362008-12-18 21:56:41 -0500413 // IRQ trampolines
414 .macro IRQ_TRAMPOLINE num
415 .global irq_trampoline_0x\num
416 irq_trampoline_0x\num :
417 int $0x\num
418 lretw
419 .endm
420
Kevin O'Connorc5b50362008-12-18 21:56:41 -0500421 IRQ_TRAMPOLINE 10
422 IRQ_TRAMPOLINE 13
423 IRQ_TRAMPOLINE 15
424 IRQ_TRAMPOLINE 16
425 IRQ_TRAMPOLINE 18
426 IRQ_TRAMPOLINE 19
Kevin O'Connorc5b50362008-12-18 21:56:41 -0500427
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500428
429/****************************************************************
Kevin O'Connorc5b50362008-12-18 21:56:41 -0500430 * Interrupt entry points
431 ****************************************************************/
432
433 // Define an entry point for an interrupt (no args passed).
434 .macro IRQ_ENTRY num
435 .global entry_\num
436 entry_\num :
437 cli // In case something far-calls instead of using "int"
438 ENTRY handle_\num
439 iretw
440 .endm
441
442 // Define an entry point for an interrupt (can read/modify args).
443 .macro IRQ_ENTRY_ARG num
444 .global entry_\num
445 entry_\num :
446 cli // In case something far-calls instead of using "int"
447 ENTRY_ARG handle_\num
448 iretw
449 .endm
450
451 ORG 0xe2c3
452 IRQ_ENTRY nmi
453
454/****************************************************************
455 * GDT and IDT tables (between 0xe2c3 - 0xe3fe)
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500456 ****************************************************************/
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500457
458// Protected mode IDT descriptor
459//
460// I just make the limit 0, so the machine will shutdown
461// if an exception occurs during protected mode memory
462// transfers.
463//
464// Set base to f0000 to correspond to beginning of BIOS,
465// in case I actually define an IDT later
466// Set limit to 0
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500467 .type pmode_IDT_info, @object
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500468pmode_IDT_info:
469 .word 0x0000 // limit 15:00
Kevin O'Connorddd4bfd2008-02-28 20:00:20 -0500470 .long 0xf0000 // base 16:47
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500471
472// Real mode IDT descriptor
473//
474// Set to typical real-mode values.
475// base = 000000
476// limit = 03ff
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500477 .type rmode_IDT_info, @object
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500478rmode_IDT_info:
479 .word 0x03ff // limit 15:00
Kevin O'Connorddd4bfd2008-02-28 20:00:20 -0500480 .long 0 // base 16:47
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500481
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500482 .type rombios32_gdt_48, @object
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500483rombios32_gdt_48:
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500484 .word (rombios32_gdt_end - rombios32_gdt)
485 .long (BUILD_BIOS_ADDR + rombios32_gdt)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500486
Kevin O'Connor711ddc62009-01-17 15:17:34 -0500487 //.balign 8
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500488 .type rombios32_gdt, @object
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500489rombios32_gdt:
490 .word 0, 0, 0, 0
491 .word 0, 0, 0, 0
Kevin O'Connor14927082008-11-08 19:07:49 -0500492 // 32 bit flat code segment (SEG32_MODE32_CS)
Kevin O'Connorcb6735f2008-03-01 13:39:52 -0500493 .word 0xffff, 0, 0x9b00, 0x00cf
Kevin O'Connor14927082008-11-08 19:07:49 -0500494 // 32 bit flat data segment (SEG32_MODE32_DS)
Kevin O'Connorcb6735f2008-03-01 13:39:52 -0500495 .word 0xffff, 0, 0x9300, 0x00cf
Kevin O'Connor14927082008-11-08 19:07:49 -0500496 // 16 bit code segment base=0xf0000 limit=0xffff (SEG32_MODE16_CS)
Kevin O'Connorcb6735f2008-03-01 13:39:52 -0500497 .word 0xffff, 0, 0x9b0f, 0x0000
Kevin O'Connor14927082008-11-08 19:07:49 -0500498 // 16 bit data segment base=0x0 limit=0xffff (SEG32_MODE16_DS)
Kevin O'Connorcb6735f2008-03-01 13:39:52 -0500499 .word 0xffff, 0, 0x9300, 0x0000
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500500 // 16 bit code segment base=0 limit=0xffffffff (SEG32_MODE16BIG_CS)
501 .word 0xffff, 0, 0x9b00, 0x008f
502 // 16 bit data segment base=0 limit=0xffffffff (SEG32_MODE16BIG_DS)
503 .word 0xffff, 0, 0x9300, 0x008f
504rombios32_gdt_end:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500505
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500506
507/****************************************************************
Kevin O'Connorc5b50362008-12-18 21:56:41 -0500508 * Interrupt entry points (continued)
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500509 ****************************************************************/
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500510
Kevin O'Connor74534532008-05-12 18:28:58 -0400511 ORG 0xe3fe
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500512 .global entry_13_official
513entry_13_official:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500514 jmp entry_13
515
Kevin O'Connor74534532008-05-12 18:28:58 -0400516 ORG 0xe401
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500517 .type __fdpt, @object
518__fdpt:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500519 // XXX - Fixed Disk Parameter Table
Kevin O'Connor711ddc62009-01-17 15:17:34 -0500520 .space 16
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500521
Kevin O'Connor74534532008-05-12 18:28:58 -0400522 ORG 0xe6f2
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500523 .global entry_19_official
524entry_19_official:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500525 jmp entry_19
526
Kevin O'Connor74534532008-05-12 18:28:58 -0400527 ORG 0xe6f5
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500528.include "out/cbt.proc.16.s"
529 .text
530
Kevin O'Connor74534532008-05-12 18:28:58 -0400531 ORG 0xe729
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500532 .type __brgt, @object
533__brgt:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500534 // XXX - Baud Rate Generator Table
Kevin O'Connor711ddc62009-01-17 15:17:34 -0500535 .space 16
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500536
Kevin O'Connor74534532008-05-12 18:28:58 -0400537 ORG 0xe739
Kevin O'Connored128492008-03-11 11:14:59 -0400538 IRQ_ENTRY_ARG 14
539
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500540 ORG 0xe82e
541 IRQ_ENTRY_ARG 16
542
543 ORG 0xe987
544 IRQ_ENTRY 09
545
546 ORG 0xec59
547 IRQ_ENTRY_ARG 40
548
549 ORG 0xef57
550 IRQ_ENTRY 0e
551
552 ORG 0xefc7
553.include "out/floppy_dbt.proc.16.s"
554 .text
555
556 ORG 0xefd2
557 IRQ_ENTRY_ARG 17
558
559 ORG 0xf045
560__int10_0x0f:
561 // XXX - INT 10 Functions 0-Fh Entry Point
562 iretw
563
564 ORG 0xf065
565 IRQ_ENTRY_ARG 10
566
567 ORG 0xf0a4
568 .type __int1d, @object
569__int1d:
570 // XXX - INT 1D - SYSTEM DATA - VIDEO PARAMETER TABLES
571 .space 0x58
572
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500573 ORG 0xf841
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500574 .global entry_12_official
575entry_12_official:
576 jmp entry_12
577
578 ORG 0xf84d
579 .global entry_11_official
580entry_11_official:
581 jmp entry_11
582
583 ORG 0xf859
584 IRQ_ENTRY_ARG 15
585
586 // Fit other misc defs if the freespace between 0xf859-0xfa6e
587
588 IRQ_ENTRY_ARG 13
589 IRQ_ENTRY_ARG 12
590 IRQ_ENTRY_ARG 11
591 IRQ_ENTRY 76
592 IRQ_ENTRY 1c
593 IRQ_ENTRY 70
Kevin O'Connor18f368e2008-03-31 21:56:04 -0400594 IRQ_ENTRY 74
Kevin O'Connor1d019512008-03-11 21:21:47 -0400595 IRQ_ENTRY 75
Kevin O'Connorffdc9ee2008-12-20 13:10:00 -0500596 IRQ_ENTRY hwpic1
597 IRQ_ENTRY hwpic2
Kevin O'Connor1d019512008-03-11 21:21:47 -0400598
Kevin O'Connored128492008-03-11 11:14:59 -0400599 // int 18/19 are special - they reset the stack and do not return.
Kevin O'Connored128492008-03-11 11:14:59 -0400600entry_19:
601 RESET_STACK
Kevin O'Connor44eeaf12008-07-06 10:14:49 -0400602 pushl $_code32_handle_19
603 jmp transition32
Kevin O'Connored128492008-03-11 11:14:59 -0400604
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400605 .global entry_18
Kevin O'Connored128492008-03-11 11:14:59 -0400606entry_18:
607 RESET_STACK
Kevin O'Connor44eeaf12008-07-06 10:14:49 -0400608 pushl $_code32_handle_18
609 jmp transition32
Kevin O'Connored128492008-03-11 11:14:59 -0400610
Kevin O'Connor74534532008-05-12 18:28:58 -0400611 ORG 0xfa6e
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500612.include "out/font.proc.16.s"
613 .text
614
Kevin O'Connor74534532008-05-12 18:28:58 -0400615 ORG 0xfe6e
Kevin O'Connored128492008-03-11 11:14:59 -0400616 IRQ_ENTRY_ARG 1a
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500617
Kevin O'Connor74534532008-05-12 18:28:58 -0400618 ORG 0xfea5
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500619 IRQ_ENTRY 08
620
Kevin O'Connor74534532008-05-12 18:28:58 -0400621 ORG 0xfef3
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500622__initvector:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500623 // XXX - Initial Interrupt Vector Offsets Loaded by POST
Kevin O'Connor711ddc62009-01-17 15:17:34 -0500624 .space 13
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500625
Kevin O'Connor74534532008-05-12 18:28:58 -0400626 ORG 0xff00
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500627 .type __copyright, @object
628__copyright:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500629 // XXX - BIOS_COPYRIGHT_STRING
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500630 .asciz "(c) 2002 MandrakeSoft S.A. Written by Kevin Lawton & the Bochs team."
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500631
Kevin O'Connor74534532008-05-12 18:28:58 -0400632 ORG 0xff53
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400633 .global dummy_iret_handler
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500634dummy_iret_handler:
635 iretw
636
Kevin O'Connor74534532008-05-12 18:28:58 -0400637 ORG 0xff54
Kevin O'Connored128492008-03-11 11:14:59 -0400638 IRQ_ENTRY_ARG 05
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500639
Kevin O'Connor74534532008-05-12 18:28:58 -0400640 ORG 0xfff0 // Power-up Entry Point
Kevin O'Connor3f168b62008-11-29 13:22:29 -0500641 .global reset_vector
642reset_vector:
Kevin O'Connore3677b12008-07-04 15:29:23 -0400643 ljmpw $SEG_BIOS, $post16
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500644
Kevin O'Connor74534532008-05-12 18:28:58 -0400645 ORG 0xfff5
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500646 .type __biosdate, @object
647__biosdate:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500648 // BIOS build date
649 .ascii "06/23/99"
650
Kevin O'Connor74534532008-05-12 18:28:58 -0400651 ORG 0xfffe
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500652 .type __model_id, @object
653__model_id:
Kevin O'Connor44c631d2008-03-02 11:24:36 -0500654 .byte CONFIG_MODEL_ID
Kevin O'Connore3677b12008-07-04 15:29:23 -0400655
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400656 .global bios_checksum
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500657 .type bios_checksum, @object
Kevin O'Connore3677b12008-07-04 15:29:23 -0400658bios_checksum:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500659 .byte 0x00
660
661 .end