blob: 8125277158d9da90926e9fef2330ac19fca69d2f [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// Rom layout and bios assembler to C interface.
2//
Kevin O'Connor36feea92012-02-11 10:49:45 -05003// Copyright (C) 2008-2012 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05004// 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'Connorf8e176c2009-05-06 23:33:32 -04008#include "config.h" // CONFIG_*
9#include "ioport.h" // PORT_A20
10#include "bregs.h" // CR0_*
11#include "cmos.h" // CMOS_RESET_CODE
Kevin O'Connor3dba4c22011-01-29 11:26:54 -050012#include "asm-offsets.h" // BREGS_*
Kevin O'Connorf8e176c2009-05-06 23:33:32 -040013#include "entryfuncs.S" // ENTRY_*
Kevin O'Connor74534532008-05-12 18:28:58 -040014
Kevin O'Connor1d019512008-03-11 21:21:47 -040015
16/****************************************************************
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050017 * Call trampolines
18 ****************************************************************/
19
20// Place CPU into 32bit mode from 16bit mode.
Kevin O'Connor4057f982010-11-25 08:52:50 -050021// %edx = return location (in 32bit mode)
Kevin O'Connorad901592009-12-13 11:25:25 -050022// Clobbers: ecx, flags, segment registers, cr0, idt/gdt
Kevin O'Connord67a7032009-01-17 19:37:26 -050023 DECLFUNC transition32
Kevin O'Connor36feea92012-02-11 10:49:45 -050024 .code16gcc
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050025transition32:
Kevin O'Connorad901592009-12-13 11:25:25 -050026 movl %eax, %ecx
Kevin O'Connor9caf7862009-02-27 20:14:05 -050027
Kevin O'Connorf094ba82009-04-13 19:30:27 -040028 // Disable irqs (and clear direction flag)
29 cli
30 cld
31
32 // Disable nmi
33 movl $CMOS_RESET_CODE|NMI_DISABLE_BIT, %eax
34 outb %al, $PORT_CMOS_INDEX
35 inb $PORT_CMOS_DATA, %al
36
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050037 // enable a20
Kevin O'Connord9a8b2d2008-11-16 09:17:02 -050038 inb $PORT_A20, %al
39 orb $A20_ENABLE_BIT, %al
40 outb %al, $PORT_A20
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050041
42 // Set segment descriptors
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -050043 lidtw %cs:pmode_IDT_info
44 lgdtw %cs:rombios32_gdt_48
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050045
Kevin O'Connor3eac0092008-11-16 09:59:32 -050046 // Enable protected mode
47 movl %cr0, %eax
48 orl $CR0_PE, %eax
49 movl %eax, %cr0
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050050
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -050051 // start 32bit protected mode code
Kevin O'Connor14927082008-11-08 19:07:49 -050052 ljmpl $SEG32_MODE32_CS, $(BUILD_BIOS_ADDR + 1f)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050053
54 .code32
551:
56 // init data segments
Kevin O'Connor14927082008-11-08 19:07:49 -050057 movl $SEG32_MODE32_DS, %eax
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050058 movw %ax, %ds
59 movw %ax, %es
60 movw %ax, %ss
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050061 movw %ax, %fs
62 movw %ax, %gs
63
Kevin O'Connorad901592009-12-13 11:25:25 -050064 movl %ecx, %eax
Kevin O'Connor4057f982010-11-25 08:52:50 -050065 jmpl *%edx
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050066
Kevin O'Connor752151b2009-12-10 21:16:07 -050067// Place CPU into 16bit mode from 32bit mode.
Kevin O'Connor4057f982010-11-25 08:52:50 -050068// %edx = return location (in 16bit mode)
Kevin O'Connorad901592009-12-13 11:25:25 -050069// Clobbers: ecx, flags, segment registers, cr0, idt/gdt
Kevin O'Connor752151b2009-12-10 21:16:07 -050070 DECLFUNC transition16
71 .global transition16big
72transition16:
Kevin O'Connorad901592009-12-13 11:25:25 -050073 movl %eax, %ecx
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050074
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050075 // restore data segment limits to 0xffff
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -050076 movl $SEG32_MODE16_DS, %eax
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050077 movw %ax, %ds
78 movw %ax, %es
79 movw %ax, %ss
80 movw %ax, %fs
81 movw %ax, %gs
82
Kevin O'Connorffb81a42009-04-13 19:44:55 -040083#if CONFIG_DISABLE_A20
Kevin O'Connor1a72e2e2008-11-11 22:03:55 -050084 // disable a20
Kevin O'Connord9a8b2d2008-11-16 09:17:02 -050085 inb $PORT_A20, %al
86 andb $~A20_ENABLE_BIT, %al
87 outb %al, $PORT_A20
Kevin O'Connorffb81a42009-04-13 19:44:55 -040088#endif
Kevin O'Connor1a72e2e2008-11-11 22:03:55 -050089
90 // Jump to 16bit mode
91 ljmpw $SEG32_MODE16_CS, $1f
92
Kevin O'Connor752151b2009-12-10 21:16:07 -050093transition16big:
Kevin O'Connorad901592009-12-13 11:25:25 -050094 movl %eax, %ecx
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -050095
96 movl $SEG32_MODE16BIG_DS, %eax
97 movw %ax, %ds
98 movw %ax, %es
99 movw %ax, %ss
100 movw %ax, %fs
101 movw %ax, %gs
102
Kevin O'Connor0f788892010-07-25 14:04:01 -0400103 ljmpw $SEG32_MODE16BIG_CS, $1f
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500104
Kevin O'Connor1a72e2e2008-11-11 22:03:55 -0500105 .code16gcc
1061:
Kevin O'Connor3eac0092008-11-16 09:59:32 -0500107 // Disable protected mode
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500108 movl %cr0, %eax
Kevin O'Connor3eac0092008-11-16 09:59:32 -0500109 andl $~CR0_PE, %eax
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500110 movl %eax, %cr0
111
112 // far jump to flush CPU queue after transition to real mode
Kevin O'Connore3677b12008-07-04 15:29:23 -0400113 ljmpw $SEG_BIOS, $2f
Kevin O'Connor21e930b2008-03-01 09:49:37 -0500114
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -05001152:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500116 // restore IDT to normal real-mode defaults
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500117 lidtw %cs:rmode_IDT_info
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500118
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500119 // Clear segment registers
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500120 xorw %ax, %ax
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500121 movw %ax, %fs
122 movw %ax, %gs
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500123 movw %ax, %es
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500124 movw %ax, %ds
125 movw %ax, %ss // Assume stack is in segment 0
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500126
Kevin O'Connorad901592009-12-13 11:25:25 -0500127 movl %ecx, %eax
Kevin O'Connor4057f982010-11-25 08:52:50 -0500128 jmpl *%edx
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500129
Kevin O'Connorc7ffbac2012-03-25 11:04:10 -0400130// Far call a 16bit function from 16bit mode with a specified cpu register state
Kevin O'Connorbeeabd62012-05-28 13:59:07 -0400131// %es:%eax = address of struct bregs
Kevin O'Connor9caf7862009-02-27 20:14:05 -0500132// Clobbers: %e[bcd]x, %e[ds]i, flags
Kevin O'Connorc7ffbac2012-03-25 11:04:10 -0400133 DECLFUNC __farcall16
134__farcall16:
Kevin O'Connor9caf7862009-02-27 20:14:05 -0500135 // Save %eax, %ebp
136 pushl %ebp
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500137 pushl %eax
Kevin O'Connorbeeabd62012-05-28 13:59:07 -0400138 pushl %es
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500139
140 // Setup for iretw call
Kevin O'Connor273e8ae2009-01-19 19:56:07 -0500141 pushw %cs
Kevin O'Connorbeeabd62012-05-28 13:59:07 -0400142 pushw $1f // return point
143 pushw %es:BREGS_flags(%eax) // flags
144 pushl %es:BREGS_code(%eax) // CS:IP
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500145
146 // Load calling registers.
Kevin O'Connorbeeabd62012-05-28 13:59:07 -0400147 movl %es:BREGS_edi(%eax), %edi
148 movl %es:BREGS_esi(%eax), %esi
149 movl %es:BREGS_ebp(%eax), %ebp
150 movl %es:BREGS_ebx(%eax), %ebx
151 movl %es:BREGS_edx(%eax), %edx
152 movl %es:BREGS_ecx(%eax), %ecx
153 movw %es:BREGS_ds(%eax), %ds
154 pushl %es:BREGS_eax(%eax)
155 movw %es:BREGS_es(%eax), %es
156 popl %eax
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500157
158 // Invoke call
Kevin O'Connorbeeabd62012-05-28 13:59:07 -0400159 iretw // XXX - just do a lcalll
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -05001601:
Kevin O'Connorbeeabd62012-05-28 13:59:07 -0400161 // Store flags, es, eax
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500162 pushfw
Kevin O'Connorbeeabd62012-05-28 13:59:07 -0400163 cli
164 cld
165 pushw %es
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500166 pushl %eax
Kevin O'Connorbeeabd62012-05-28 13:59:07 -0400167 movw 0x08(%esp), %es
168 movl 0x0c(%esp), %eax
169 popl %es:BREGS_eax(%eax)
170 popw %es:BREGS_es(%eax)
171 popw %es:BREGS_flags(%eax)
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500172
173 // Store remaining registers
Kevin O'Connorbeeabd62012-05-28 13:59:07 -0400174 movl %edi, %es:BREGS_edi(%eax)
175 movl %esi, %es:BREGS_esi(%eax)
176 movl %ebp, %es:BREGS_ebp(%eax)
177 movl %ebx, %es:BREGS_ebx(%eax)
178 movl %edx, %es:BREGS_edx(%eax)
179 movl %ecx, %es:BREGS_ecx(%eax)
180 movw %ds, %es:BREGS_ds(%eax)
181 movw %ss, %cx
182 movw %cx, %ds // Restore %ds == %ss
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500183
Kevin O'Connorbeeabd62012-05-28 13:59:07 -0400184 // Remove %es/%eax, restore %ebp
185 popl %eax
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500186 popl %eax
Kevin O'Connor9caf7862009-02-27 20:14:05 -0500187 popl %ebp
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500188
189 retl
190
Kevin O'Connor2f898d52012-05-28 10:56:20 -0400191// Call a 16bit SeaBIOS function from SeaBIOS 32bit C code.
192// %ebx = calling function
193// Clobbers: %ecx, %edx, flags, segment registers, idt/gdt
194 DECLFUNC __call16
195 .global __call16big
Kevin O'Connor752151b2009-12-10 21:16:07 -0500196 .code32
Kevin O'Connor2f898d52012-05-28 10:56:20 -0400197__call16:
Kevin O'Connor4057f982010-11-25 08:52:50 -0500198 movl $1f, %edx
Kevin O'Connor752151b2009-12-10 21:16:07 -0500199 jmp transition16
Kevin O'Connor2f898d52012-05-28 10:56:20 -0400200__call16big:
Kevin O'Connor4057f982010-11-25 08:52:50 -0500201 movl $1f, %edx
Kevin O'Connor752151b2009-12-10 21:16:07 -0500202 jmp transition16big
203
204 // Make call.
205 .code16gcc
Kevin O'Connor2f898d52012-05-28 10:56:20 -04002061: calll *%ebx
Kevin O'Connor752151b2009-12-10 21:16:07 -0500207 // Return via transition32
Kevin O'Connor4057f982010-11-25 08:52:50 -0500208 movl $(2f + BUILD_BIOS_ADDR), %edx
Kevin O'Connor752151b2009-12-10 21:16:07 -0500209 jmp transition32
Kevin O'Connor4057f982010-11-25 08:52:50 -0500210 .code32
2112: retl
Kevin O'Connor752151b2009-12-10 21:16:07 -0500212
Kevin O'Connor4057f982010-11-25 08:52:50 -0500213 .code16gcc
Kevin O'Connor79dde652009-04-13 19:26:43 -0400214// IRQ trampolines
215 .macro IRQ_TRAMPOLINE num
216 DECLFUNC irq_trampoline_0x\num
217 irq_trampoline_0x\num :
218 int $0x\num
219 lretw
220 .endm
221
Kevin O'Connorecdc6552012-05-28 14:25:15 -0400222 IRQ_TRAMPOLINE 02
Kevin O'Connor79dde652009-04-13 19:26:43 -0400223 IRQ_TRAMPOLINE 10
224 IRQ_TRAMPOLINE 13
225 IRQ_TRAMPOLINE 15
226 IRQ_TRAMPOLINE 16
227 IRQ_TRAMPOLINE 18
228 IRQ_TRAMPOLINE 19
Kevin O'Connorecdc6552012-05-28 14:25:15 -0400229 IRQ_TRAMPOLINE 1c
230 IRQ_TRAMPOLINE 4a
Kevin O'Connor79dde652009-04-13 19:26:43 -0400231
232
233/****************************************************************
Kevin O'Connor87b533b2011-07-10 22:35:07 -0400234 * Misc. entry points.
Kevin O'Connor79dde652009-04-13 19:26:43 -0400235 ****************************************************************/
236
Kevin O'Connor87b533b2011-07-10 22:35:07 -0400237// Resume (and reboot) entry point - called from entry_post
238 DECLFUNC entry_resume
239entry_resume:
Kevin O'Connor79dde652009-04-13 19:26:43 -0400240 // Disable interrupts
241 cli
242 cld
Kevin O'Connor46b82622012-05-13 12:10:30 -0400243 // Use the ExtraStack in low mem.
244 movl $_datalow_seg, %eax
Kevin O'Connor87b533b2011-07-10 22:35:07 -0400245 movw %ax, %ds
Kevin O'Connor79dde652009-04-13 19:26:43 -0400246 movw %ax, %ss
Kevin O'Connor46b82622012-05-13 12:10:30 -0400247 movl $ExtraStack + BUILD_EXTRA_STACK_SIZE, %esp
Kevin O'Connor79dde652009-04-13 19:26:43 -0400248 // Call handler.
Kevin O'Connor79dde652009-04-13 19:26:43 -0400249 jmp handle_resume
250
Kevin O'Connore54ee382009-07-26 19:33:13 -0400251// PMM entry point
252 DECLFUNC entry_pmm
253entry_pmm:
254 pushl %esp // Backup %esp, then clear high bits
255 movzwl %sp, %esp
256 pushfl // Save registers clobbered by C code
257 cli
258 cld
259 pushl %eax
260 pushl %ecx
261 pushl %edx
262 pushw %es
263 pushw %ds
264 movw %ss, %cx // Move %ss to %ds
265 movw %cx, %ds
Kevin O'Connor533b6282011-07-16 13:13:12 -0400266 movl $_cfunc32flat_handle_pmm, %eax // Setup: call32(handle_pmm, args, -1)
267 leal 28(%esp), %edx // %edx points to start of args
268 movl $-1, %ecx
269 calll call32
Kevin O'Connore54ee382009-07-26 19:33:13 -0400270 movw %ax, 12(%esp) // Modify %ax:%dx to return %eax
271 shrl $16, %eax
272 movw %ax, 4(%esp)
273 popw %ds // Restore saved registers
274 popw %es
275 popl %edx
276 popl %ecx
277 popl %eax
278 popfl
279 popl %esp
280 lretw
281
Kevin O'Connor79dde652009-04-13 19:26:43 -0400282// PnP entry points
Kevin O'Connord67a7032009-01-17 19:37:26 -0500283 DECLFUNC entry_pnp_real
284 .global entry_pnp_prot
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500285entry_pnp_prot:
286 pushl %esp
287 jmp 1f
288entry_pnp_real:
289 pushl %esp // Backup %esp, then clear high bits
290 movzwl %sp, %esp
2911:
292 pushfl // Save registers clobbered by C code
Kevin O'Connore54ee382009-07-26 19:33:13 -0400293 cli
294 cld
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500295 pushl %eax
296 pushl %ecx
297 pushl %edx
298 pushw %es
299 pushw %ds
300 movw %ss, %cx // Move %ss to %ds
301 movw %cx, %ds
Kevin O'Connor752151b2009-12-10 21:16:07 -0500302 leal 28(%esp), %eax // %eax points to start of u16 args
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500303 calll handle_pnp
304 movw %ax, 12(%esp) // Modify %eax to return %ax
305 popw %ds
306 popw %es
307 popl %edx
308 popl %ecx
309 popl %eax
310 popfl
311 popl %esp
312 lretw
313
Kevin O'Connor79dde652009-04-13 19:26:43 -0400314// APM entry points
Kevin O'Connor47c8e312011-07-10 22:57:32 -0400315 DECLFUNC entry_apm16
316entry_apm16:
Kevin O'Connor1d019512008-03-11 21:21:47 -0400317 pushfw // save flags
318 pushl %eax // dummy
Kevin O'Connord3e43672012-05-28 11:37:53 -0400319 ENTRY_ARG handle_apm
Kevin O'Connorb3c28be2008-06-08 13:34:43 -0400320 addw $4, %sp // pop dummy
Kevin O'Connor1d019512008-03-11 21:21:47 -0400321 popfw // restore flags
322 lretw
323
324 .code32
Kevin O'Connor47c8e312011-07-10 22:57:32 -0400325 DECLFUNC entry_apm32
326entry_apm32:
Kevin O'Connorc0031482010-01-01 13:03:17 -0500327 pushfl
328 pushl %gs
329 pushl %cs // Move second descriptor after %cs to %gs
330 addl $16, (%esp)
331 popl %gs
Kevin O'Connord3e43672012-05-28 11:37:53 -0400332 ENTRY_ARG_ESP _cfunc32seg_handle_apm
Kevin O'Connorc0031482010-01-01 13:03:17 -0500333 popl %gs
334 popfl
Kevin O'Connor1d019512008-03-11 21:21:47 -0400335 lretl
Kevin O'Connoree4f9ff2008-07-05 21:19:10 -0400336
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500337// PCI-BIOS 32bit entry point
Kevin O'Connor47c8e312011-07-10 22:57:32 -0400338 DECLFUNC entry_pcibios32
339entry_pcibios32:
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500340 pushfl
Kevin O'Connorc0031482010-01-01 13:03:17 -0500341 pushl %gs // Backup %gs and set %gs=%ds
342 pushl %ds
343 popl %gs
Kevin O'Connorf3fe3aa2010-12-05 12:38:33 -0500344 ENTRY_ARG_ESP _cfunc32seg_handle_pcibios32
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500345 popl %gs
346 popfl
347 lretl
348
349// BIOS32 support
Kevin O'Connor47c8e312011-07-10 22:57:32 -0400350 EXPORTFUNC entry_bios32
351entry_bios32:
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500352 pushfl
353#if CONFIG_PCIBIOS
354 // Check for PCI-BIOS request
355 cmpl $0x49435024, %eax // $PCI
356 jne 1f
357 movl $BUILD_BIOS_ADDR, %ebx
358 movl $BUILD_BIOS_SIZE, %ecx
Kevin O'Connor47c8e312011-07-10 22:57:32 -0400359 movl $entry_pcibios32, %edx
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500360 xorb %al, %al
361 jmp 2f
362#endif
363 // Unknown request
3641: movb $0x80, %al
365 // Return to caller
3662: popfl
367 lretl
368
Kevin O'Connoree4f9ff2008-07-05 21:19:10 -0400369// 32bit elf entry point
Kevin O'Connor47c8e312011-07-10 22:57:32 -0400370 EXPORTFUNC entry_elf
371entry_elf:
Kevin O'Connoree4f9ff2008-07-05 21:19:10 -0400372 cli
373 cld
374 lidtl (BUILD_BIOS_ADDR + pmode_IDT_info)
375 lgdtl (BUILD_BIOS_ADDR + rombios32_gdt_48)
Kevin O'Connore0504b02009-04-13 19:32:51 -0400376 movl $SEG32_MODE32_DS, %eax
377 movw %ax, %ds
378 movw %ax, %es
379 movw %ax, %fs
380 movw %ax, %gs
381 movw %ax, %ss
Kevin O'Connoree4f9ff2008-07-05 21:19:10 -0400382 movl $BUILD_STACK_ADDR, %esp
Kevin O'Connor87b533b2011-07-10 22:35:07 -0400383 ljmpl $SEG32_MODE32_CS, $_cfunc32flat_handle_post
Kevin O'Connoree4f9ff2008-07-05 21:19:10 -0400384
Kevin O'Connor1d019512008-03-11 21:21:47 -0400385 .code16gcc
Kevin O'Connor1d019512008-03-11 21:21:47 -0400386
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500387
388/****************************************************************
Kevin O'Connorc5b50362008-12-18 21:56:41 -0500389 * Interrupt entry points
390 ****************************************************************/
391
Kevin O'Connorecdc6552012-05-28 14:25:15 -0400392 // Main entry point for interrupts handled on extra stack
393 DECLFUNC irqentry_extrastack
394irqentry_extrastack:
395 cli
396 cld
Kevin O'Connor1297e5d2012-06-02 20:30:58 -0400397 pushw %ds // Set %ds:%eax to space on ExtraStack
Kevin O'Connorecdc6552012-05-28 14:25:15 -0400398 pushl %eax
399 movl $_datalow_seg, %eax
400 movl %eax, %ds
401 movl StackPos, %eax
Kevin O'Connor1297e5d2012-06-02 20:30:58 -0400402 subl $24, %eax
403 popl 0(%eax) // Backup %eax, %ds, %es, %ecx, %edx
404 popw 4(%eax)
405 movw %es, 6(%eax)
406 movl %ecx, 8(%eax)
Kevin O'Connorecdc6552012-05-28 14:25:15 -0400407 popl %ecx
Kevin O'Connor1297e5d2012-06-02 20:30:58 -0400408 movl %edx, 12(%eax)
409 movl %esp, 16(%eax)
410 movzwl %sp, %esp
411 movw %ss, 20(%eax)
Kevin O'Connorecdc6552012-05-28 14:25:15 -0400412
Kevin O'Connor1297e5d2012-06-02 20:30:58 -0400413 movw %ds, %dx // Setup %ss/%esp and call function
Kevin O'Connorecdc6552012-05-28 14:25:15 -0400414 movw %dx, %ss
415 movl %eax, %esp
416 calll *%ecx
417
Kevin O'Connor1297e5d2012-06-02 20:30:58 -0400418 movl %esp, %eax // Restore registers and return
419 movw 20(%eax), %ss
420 movl 16(%eax), %esp
421 movl 12(%eax), %edx
422 movl 8(%eax), %ecx
423 movw 6(%eax), %es
424 pushw 4(%eax)
425 pushl 0(%eax)
Kevin O'Connorecdc6552012-05-28 14:25:15 -0400426 popl %eax
427 popw %ds
Kevin O'Connor9f193b92009-05-16 23:31:27 -0400428 iretw
429
430 // Main entry point for interrupts with args
Kevin O'Connoreaec3c22009-05-30 03:40:22 -0400431 DECLFUNC irqentryarg
Kevin O'Connor9f193b92009-05-16 23:31:27 -0400432irqentryarg:
433 ENTRY_ARG_ST
434 iretw
435
Kevin O'Connorecdc6552012-05-28 14:25:15 -0400436 // Define an entry point for hardware interrupts.
Kevin O'Connor812478e2011-01-22 10:53:48 -0500437 .macro IRQ_ENTRY num
438 .global entry_\num
439 entry_\num :
440 pushl $ handle_\num
Kevin O'Connorecdc6552012-05-28 14:25:15 -0400441 jmp irqentry_extrastack
Kevin O'Connor812478e2011-01-22 10:53:48 -0500442 .endm
443
444 .macro DECL_IRQ_ENTRY num
445 DECLFUNC entry_\num
446 IRQ_ENTRY \num
447 .endm
448
449 // Define an entry point for an interrupt (can read/modify args).
450 .macro IRQ_ENTRY_ARG num
451 .global entry_\num
452 entry_\num :
453 pushl $ handle_\num
454 jmp irqentryarg
455 .endm
456
457 .macro DECL_IRQ_ENTRY_ARG num
458 DECLFUNC entry_\num
459 IRQ_ENTRY_ARG \num
460 .endm
461
462 // Various entry points (that don't require a fixed location).
Kevin O'Connord67a7032009-01-17 19:37:26 -0500463 DECL_IRQ_ENTRY_ARG 13
Kevin O'Connord67a7032009-01-17 19:37:26 -0500464 DECL_IRQ_ENTRY 76
Kevin O'Connord67a7032009-01-17 19:37:26 -0500465 DECL_IRQ_ENTRY 70
466 DECL_IRQ_ENTRY 74
467 DECL_IRQ_ENTRY 75
468 DECL_IRQ_ENTRY hwpic1
469 DECL_IRQ_ENTRY hwpic2
470
Kevin O'Connor4ebc0b72009-03-01 12:31:57 -0500471 // int 18/19 are special - they reset stack and call into 32bit mode.
Kevin O'Connord67a7032009-01-17 19:37:26 -0500472 DECLFUNC entry_19
473entry_19:
Kevin O'Connorf3fe3aa2010-12-05 12:38:33 -0500474 ENTRY_INTO32 _cfunc32flat_handle_19
Kevin O'Connord67a7032009-01-17 19:37:26 -0500475
476 DECLFUNC entry_18
477entry_18:
Kevin O'Connorf3fe3aa2010-12-05 12:38:33 -0500478 ENTRY_INTO32 _cfunc32flat_handle_18
Kevin O'Connord67a7032009-01-17 19:37:26 -0500479
480
481/****************************************************************
482 * Fixed position entry points
483 ****************************************************************/
484
485 // Specify a location in the fixed part of bios area.
486 .macro ORG addr
487 .section .fixedaddr.\addr
488 .endm
489
490 ORG 0xe05b
Kevin O'Connor87b533b2011-07-10 22:35:07 -0400491entry_post:
492 cmpl $0, %cs:HaveRunPost // Check for resume/reboot
493 jnz entry_resume
494 ENTRY_INTO32 _cfunc32flat_handle_post // Normal entry point
Kevin O'Connord67a7032009-01-17 19:37:26 -0500495
Kevin O'Connorc5b50362008-12-18 21:56:41 -0500496 ORG 0xe2c3
Kevin O'Connor75f49b32009-03-07 00:07:24 -0500497 IRQ_ENTRY 02
Kevin O'Connorc5b50362008-12-18 21:56:41 -0500498
Kevin O'Connor74534532008-05-12 18:28:58 -0400499 ORG 0xe3fe
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500500 .global entry_13_official
501entry_13_official:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500502 jmp entry_13
503
Kevin O'Connor30853762009-01-17 18:49:20 -0500504 // 0xe401 - OldFDPT in disk.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500505
Kevin O'Connor74534532008-05-12 18:28:58 -0400506 ORG 0xe6f2
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500507 .global entry_19_official
508entry_19_official:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500509 jmp entry_19
510
Kevin O'Connor30853762009-01-17 18:49:20 -0500511 // 0xe6f5 - BIOS_CONFIG_TABLE in misc.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500512
Kevin O'Connor30853762009-01-17 18:49:20 -0500513 // 0xe729 - BaudTable in serial.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500514
Kevin O'Connor74534532008-05-12 18:28:58 -0400515 ORG 0xe739
Kevin O'Connored128492008-03-11 11:14:59 -0400516 IRQ_ENTRY_ARG 14
517
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500518 ORG 0xe82e
519 IRQ_ENTRY_ARG 16
520
521 ORG 0xe987
522 IRQ_ENTRY 09
523
524 ORG 0xec59
525 IRQ_ENTRY_ARG 40
526
527 ORG 0xef57
528 IRQ_ENTRY 0e
529
Kevin O'Connor30853762009-01-17 18:49:20 -0500530 // 0xefc7 - diskette_param_table in floppy.c
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500531
532 ORG 0xefd2
533 IRQ_ENTRY_ARG 17
534
535 ORG 0xf045
Kevin O'Connord67a7032009-01-17 19:37:26 -0500536entry_10_0x0f:
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500537 // XXX - INT 10 Functions 0-Fh Entry Point
538 iretw
539
540 ORG 0xf065
541 IRQ_ENTRY_ARG 10
542
Kevin O'Connor30853762009-01-17 18:49:20 -0500543 // 0xf0a4 - VideoParams in misc.c
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500544
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500545 ORG 0xf841
Kevin O'Connor9f193b92009-05-16 23:31:27 -0400546 IRQ_ENTRY_ARG 12
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500547
548 ORG 0xf84d
Kevin O'Connor9f193b92009-05-16 23:31:27 -0400549 IRQ_ENTRY_ARG 11
Kevin O'Connorb4f0e892008-12-13 18:33:05 -0500550
551 ORG 0xf859
552 IRQ_ENTRY_ARG 15
553
Kevin O'Connor30853762009-01-17 18:49:20 -0500554 // 0xfa6e - vgafont8 in font.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500555
Kevin O'Connor74534532008-05-12 18:28:58 -0400556 ORG 0xfe6e
Kevin O'Connored128492008-03-11 11:14:59 -0400557 IRQ_ENTRY_ARG 1a
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500558
Kevin O'Connor74534532008-05-12 18:28:58 -0400559 ORG 0xfea5
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500560 IRQ_ENTRY 08
561
Kevin O'Connor30853762009-01-17 18:49:20 -0500562 // 0xfef3 - InitVectors in misc.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500563
Kevin O'Connor30853762009-01-17 18:49:20 -0500564 // 0xff00 - BiosCopyright in misc.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500565
Kevin O'Connor74534532008-05-12 18:28:58 -0400566 ORG 0xff53
Kevin O'Connord67a7032009-01-17 19:37:26 -0500567 .global entry_iret_official
568entry_iret_official:
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500569 iretw
570
Kevin O'Connor74534532008-05-12 18:28:58 -0400571 ORG 0xff54
Kevin O'Connored128492008-03-11 11:14:59 -0400572 IRQ_ENTRY_ARG 05
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500573
Kevin O'Connor74534532008-05-12 18:28:58 -0400574 ORG 0xfff0 // Power-up Entry Point
Kevin O'Connor3f168b62008-11-29 13:22:29 -0500575 .global reset_vector
576reset_vector:
Kevin O'Connor87b533b2011-07-10 22:35:07 -0400577 ljmpw $SEG_BIOS, $entry_post
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500578
Kevin O'Connor30853762009-01-17 18:49:20 -0500579 // 0xfff5 - BiosDate in misc.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500580
Kevin O'Connor30853762009-01-17 18:49:20 -0500581 // 0xfffe - BiosModelId in misc.c
Kevin O'Connore3677b12008-07-04 15:29:23 -0400582
Kevin O'Connor30853762009-01-17 18:49:20 -0500583 // 0xffff - BiosChecksum in misc.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500584
585 .end