1 // Rom layout and bios assembler to C interface.
3 // Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002 MandrakeSoft S.A.
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
9 /****************************************************************
10 * Include of 16bit C code
11 ****************************************************************/
14 .include "out/ccode.16.s"
16 #include "config.h" // CONFIG_*
17 #include "ioport.h" // PORT_A20
18 #include "bregs.h" // CR0_*
19 #include "cmos.h" // CMOS_RESET_CODE
20 #include "../out/asm-offsets.h" // BREGS_*
21 #include "entryfuncs.S" // ENTRY_*
24 /****************************************************************
26 ****************************************************************/
28 // Place CPU into 32bit mode from 16bit mode.
29 // Clobbers: flags, segment registers, cr0, idt/gdt
34 // Disable irqs (and clear direction flag)
39 movl $CMOS_RESET_CODE|NMI_DISABLE_BIT, %eax
40 outb %al, $PORT_CMOS_INDEX
41 inb $PORT_CMOS_DATA, %al
45 orb $A20_ENABLE_BIT, %al
48 // Set segment descriptors
49 lidtw %cs:pmode_IDT_info
50 lgdtw %cs:rombios32_gdt_48
52 // Enable protected mode
57 // start 32bit protected mode code
58 ljmpl $SEG32_MODE32_CS, $(BUILD_BIOS_ADDR + 1f)
63 movl $SEG32_MODE32_DS, %eax
73 // Call a 16bit function from 32bit mode.
74 // %eax = address of struct bregs
75 // Clobbers: %e[bcd]x, %e[ds]i, flags, segment registers, idt/gdt
76 DECLFUNC __call16_from32
77 .global __call16big_from32
81 // restore data segment limits to 0xffff
82 movl $SEG32_MODE16_DS, %eax
89 #if CONFIG_DISABLE_A20
92 andb $~A20_ENABLE_BIT, %al
97 ljmpw $SEG32_MODE16_CS, $1f
102 movl $SEG32_MODE16BIG_DS, %eax
109 ljmpl $SEG32_MODE16BIG_CS, $(BUILD_BIOS_ADDR + 1f)
113 // Disable protected mode
118 // far jump to flush CPU queue after transition to real mode
122 // restore IDT to normal real-mode defaults
123 lidtw %cs:rmode_IDT_info
125 // Clear segment registers
131 movw %ax, %ss // Assume stack is in segment 0
138 // Return via transition32
142 // Call a 16bit function from 16bit mode with a specified cpu register state
143 // %eax = address of struct bregs
144 // Clobbers: %e[bcd]x, %e[ds]i, flags
151 // Setup for iretw call
153 pushw $1f // return point
154 pushw BREGS_flags(%eax) // flags
155 pushl BREGS_ip(%eax) // CS:IP
157 // Load calling registers.
158 movl BREGS_edi(%eax), %edi
159 movl BREGS_esi(%eax), %esi
160 movl BREGS_ebx(%eax), %ebx
161 movl BREGS_edx(%eax), %edx
162 movl BREGS_ecx(%eax), %ecx
163 movw BREGS_es(%eax), %es
164 movw BREGS_ds(%eax), %ds
165 movl %ss:BREGS_eax(%eax), %eax
168 iretw // XXX - just do a lcalll
170 // Store flags, eax, ecx
173 movl 0x06(%esp), %eax
174 movl %ecx, %ss:BREGS_ecx(%eax)
175 movw %ds, %ss:BREGS_ds(%eax)
177 movw %cx, %ds // Restore %ds == %ss
179 movl %ecx, BREGS_eax(%eax)
181 movw %cx, BREGS_flags(%eax)
183 // Store remaining registers
184 movw %es, BREGS_es(%eax)
185 movl %edi, BREGS_edi(%eax)
186 movl %esi, BREGS_esi(%eax)
187 movl %ebx, BREGS_ebx(%eax)
188 movl %edx, BREGS_edx(%eax)
190 // Remove %eax, restore %ebp
197 .macro IRQ_TRAMPOLINE num
198 DECLFUNC irq_trampoline_0x\num
199 irq_trampoline_0x\num :
212 /****************************************************************
214 ****************************************************************/
220 andl $~(CR0_CD|CR0_NW), %eax
223 // Disable interrupts
227 // Check for restart indicator.
228 movl $CMOS_RESET_CODE|NMI_DISABLE_BIT, %eax
229 outb %al, $PORT_CMOS_INDEX
230 inb $PORT_CMOS_DATA, %al
234 // Normal entry point
235 ENTRY_INTO32 _code32__start
237 // Entry point when a post call looks like a resume.
239 // Save old shutdown status.
242 // Clear shutdown status register.
243 movl $CMOS_RESET_CODE|NMI_DISABLE_BIT, %eax
244 outb %al, $PORT_CMOS_INDEX
246 outb %al, $PORT_CMOS_DATA
248 // Use a stack in EBDA
251 movw BDA_ebda_seg, %ax
252 // XXX - should verify ebda_seg looks sane.
255 movl $EBDA_OFFSET_TOP_STACK, %esp
262 /****************************************************************
263 * Misc. entry points.
264 ****************************************************************/
267 DECLFUNC entry_pnp_real
268 .global entry_pnp_prot
273 pushl %esp // Backup %esp, then clear high bits
276 pushfl // Save registers clobbered by C code
282 movw %ss, %cx // Move %ss to %ds
284 lea 28(%esp), %eax // %eax points to start of u16 args
286 movw %ax, 12(%esp) // Modify %eax to return %ax
297 DECLFUNC apm16protected_entry
298 apm16protected_entry:
301 ENTRY_ARG handle_1553
302 addw $4, %sp // pop dummy
303 popfw // restore flags
307 DECLFUNC apm32protected_entry
308 apm32protected_entry:
310 pushw %cs // Setup for long jump to 16bit mode
316 ENTRY_ARG_ESP handle_1553
318 movw $2f,(%esp) // Setup for long jump back to 32bit mode
323 addl $4, %esp // pop call address
327 // 32bit elf entry point
332 lidtl (BUILD_BIOS_ADDR + pmode_IDT_info)
333 lgdtl (BUILD_BIOS_ADDR + rombios32_gdt_48)
334 movl $SEG32_MODE32_DS, %eax
340 movl $BUILD_STACK_ADDR, %esp
341 ljmpl $SEG32_MODE32_CS, $_code32__start
346 /****************************************************************
347 * Interrupt entry points
348 ****************************************************************/
350 DECL_IRQ_ENTRY_ARG 13
351 DECL_IRQ_ENTRY_ARG 12
352 DECL_IRQ_ENTRY_ARG 11
357 DECL_IRQ_ENTRY hwpic1
358 DECL_IRQ_ENTRY hwpic2
360 // int 18/19 are special - they reset stack and call into 32bit mode.
363 ENTRY_INTO32 _code32_handle_19
367 ENTRY_INTO32 _code32_handle_18
370 /****************************************************************
371 * Fixed position entry points
372 ****************************************************************/
374 // Specify a location in the fixed part of bios area.
376 .section .fixedaddr.\addr
387 .global entry_13_official
391 // 0xe401 - OldFDPT in disk.c
394 .global entry_19_official
398 // 0xe6f5 - BIOS_CONFIG_TABLE in misc.c
400 // 0xe729 - BaudTable in serial.c
417 // 0xefc7 - diskette_param_table in floppy.c
424 // XXX - INT 10 Functions 0-Fh Entry Point
430 // 0xf0a4 - VideoParams in misc.c
433 .global entry_12_official
438 .global entry_11_official
445 // 0xfa6e - vgafont8 in font.c
453 // 0xfef3 - InitVectors in misc.c
455 // 0xff00 - BiosCopyright in misc.c
458 .global entry_iret_official
465 ORG 0xfff0 // Power-up Entry Point
468 ljmpw $SEG_BIOS, $entry_post_official
470 // 0xfff5 - BiosDate in misc.c
472 // 0xfffe - BiosModelId in misc.c
474 // 0xffff - BiosChecksum in misc.c