1 // Rom layout and bios assembler to C interface.
3 // Copyright (C) 2008 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 GPLv3 license.
10 #define PROTECTED_MODE_CS (2 << 3) // 0x10
11 #define PROTECTED_MODE_DS (3 << 3) // 0x18
12 #define REAL_MODE_CS (4 << 3) // 0x20
13 #define REAL_MODE_DS (5 << 3) // 0x28
18 /****************************************************************
19 * Include of 16bit C code
20 ****************************************************************/
22 .globl bios16c_start, bios16c_end
24 .include "out/blob.proc.16.s"
29 /****************************************************************
31 ****************************************************************/
33 // Call a C function - this does the minimal work necessary to
34 // call into C. It sets up %ds, backs up %es, and backs up
35 // those registers that are call clobbered by the C compiler.
53 // Call a C function with current register list as an
54 // argument. This backs up the registers and sets %eax
55 // to point to the backup. On return, the registers are
56 // restored from the structure.
57 .macro ENTRY_ARG cfunc
82 // Macro to reset the 16bit stack
87 movl $ CONFIG_STACK_OFFSET , %esp
91 /****************************************************************
93 ****************************************************************/
98 // init the stack pointer
101 // Set entry point of rombios32 code - the actual address
102 // is altered later in the build process.
109 // Fall through to transition32 function below
112 /****************************************************************
114 ****************************************************************/
116 // Place CPU into 32bit mode from 16bit mode.
117 // Clobbers: %eax, flags, stack registers, cr0, idt/gdt
127 // Set segment descriptors
128 lidt %cs:pmode_IDT_info
129 lgdt %cs:rombios32_gdt_48
136 // start protected mode code
137 // ljmpl $PROTECTED_MODE_CS, $(1f | 0xf0000)
138 .word 0xea66, 1f, 0x000f, PROTECTED_MODE_CS
142 // init data segments
143 movl $PROTECTED_MODE_DS, %eax
153 // Call a 16bit function from 32bit mode.
154 // %eax = address of struct bregs
155 // Clobbers: all gp registers, flags, stack registers, cr0, idt/gdt
156 .globl __call16_from32
160 // Jump to 16bit mode
161 ljmpw $REAL_MODE_CS, $1f
165 // restore data segment limits to 0xffff
166 movw $REAL_MODE_DS, %ax
173 // reset PE bit in CR0
178 // far jump to flush CPU queue after transition to real mode
182 // restore IDT to normal real-mode defaults
183 lidt %cs:rmode_IDT_info
185 // Clear segment registers
191 movw %ax, %ss // Assume stack is in segment 0
196 // Fall through to __call16
199 // Call a 16bit function from 16bit mode with a specified cpu register state
200 // %eax = address of struct bregs
201 // Clobbers: all gp registers, es
207 // Setup for iretw call
209 pushw $1f // return point
210 pushw 0x20(%eax) // flags
211 pushl 0x1c(%eax) // CS:IP
213 // Load calling registers.
214 movl 0x04(%eax), %edi
215 movl 0x08(%eax), %esi
216 movl 0x0c(%eax), %ebx
217 movl 0x10(%eax), %edx
218 movl 0x14(%eax), %ecx
219 movw 0x02(%eax), %es // XXX - should load %ds too
220 movl 0x18(%eax), %eax
223 iretw // XXX - just do a lcalll
225 // Store flags, eax, ecx
228 movl 0x06(%esp), %eax
229 movl %ecx, %ss:0x14(%eax) // Save %ecx
231 movw %cx, %ds // Restore %ds == %ss
233 movl %ecx, 0x18(%eax) // Save %eax
235 movw %cx, 0x20(%eax) // Save flags
237 // Store remaining registers
239 movl %edi, 0x04(%eax)
240 movl %esi, 0x08(%eax)
241 movl %ebx, 0x0c(%eax)
242 movl %edx, 0x10(%eax)
252 .globl apm16protected_entry
253 apm16protected_entry:
256 ENTRY_ARG handle_1553
257 addw $4, %sp // pop dummy
258 popfw // restore flags
262 .globl apm32protected_entry
263 apm32protected_entry:
265 pushw %cs // Setup for long jump to 16bit mode
271 ENTRY_ARG handle_1553
273 movw $2f,(%esp) // Setup for long jump back to 32bit mode
278 addl $4, %esp // pop call address
284 /****************************************************************
286 ****************************************************************/
288 // Protected mode IDT descriptor
290 // I just make the limit 0, so the machine will shutdown
291 // if an exception occurs during protected mode memory
294 // Set base to f0000 to correspond to beginning of BIOS,
295 // in case I actually define an IDT later
298 .word 0x0000 // limit 15:00
299 .long 0xf0000 // base 16:47
301 // Real mode IDT descriptor
303 // Set to typical real-mode values.
307 .word 0x03ff // limit 15:00
308 .long 0 // base 16:47
319 // 32 bit flat code segment (PROTECTED_MODE_CS)
320 .word 0xffff, 0, 0x9b00, 0x00cf
321 // 32 bit flat data segment (PROTECTED_MODE_DS)
322 .word 0xffff, 0, 0x9300, 0x00cf
323 // 16 bit code segment base=0xf0000 limit=0xffff (REAL_MODE_CS)
324 .word 0xffff, 0, 0x9b0f, 0x0000
325 // 16 bit data segment base=0x0 limit=0xffff (REAL_MODE_DS)
326 .word 0xffff, 0, 0x9300, 0x0000
329 /****************************************************************
330 * Interrupt entry points
331 ****************************************************************/
333 // Define an entry point for an interrupt (no args passed).
337 cli // In case something far-calls instead of using "int"
342 // Define an entry point for an interrupt (can read/modify args).
343 .macro IRQ_ENTRY_ARG num
346 cli // In case something far-calls instead of using "int"
347 ENTRY_ARG handle_\num
366 // XXX - Fixed Disk Parameter Table
372 .include "out/cbt.proc.16.s"
376 // XXX - Baud Rate Generator Table
383 // int 18/19 are special - they reset the stack and do not return.
395 .macro IRQ_TRAMPOLINE num
396 .globl irq_trampoline_0x\num
397 irq_trampoline_0x\num :
424 .include "out/floppy_dbt.proc.16.s"
441 .globl freespace2_start, freespace2_end
455 .include "out/font.proc.16.s"
465 // XXX - Initial Interrupt Vector Offsets Loaded by POST
468 // XXX - BIOS_COPYRIGHT_STRING
469 .ascii "(c) 2002 MandrakeSoft S.A. Written by Kevin Lawton & the Bochs team."
472 .globl dummy_iret_handler
479 .org 0xfff0 // Power-up Entry Point
480 ljmpw $0xf000, $post16
487 .byte CONFIG_MODEL_ID