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
16 /****************************************************************
17 * Include of 16bit C code
18 ****************************************************************/
21 .include "out/blob.16.s"
24 /****************************************************************
26 ****************************************************************/
28 // Call a C function - this does the minimal work necessary to
29 // call into C. It sets up %ds, backs up %es, and backs up
30 // those registers that are call clobbered by the C compiler.
33 pushl %eax // Save registers clobbered by C code
38 movw %ss, %ax // Move %ss to %ds
41 popw %ds // Restore registers saved above
48 // Call a C function with current register list as an
49 // argument. This backs up the registers and sets %eax
50 // to point to the backup. On return, the registers are
51 // restored from the structure.
52 .macro ENTRY_ARG cfunc
54 pushl %eax // Save registers (matches struct bregs)
62 movw %ss, %ax // Move %ss to %ds
64 movl %esp, %eax // First arg is pointer to struct bregs
66 popw %ds // Restore registers (from struct bregs)
76 // Macro to reset the 16bit stack
81 movl $ CONFIG_STACK_OFFSET , %esp
84 // Specify a location in the fixed part of bios area.
86 .section .text.fixed.addr
87 .org \addr - CONFIG_START_FIXED
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
195 // Set __call16 return address to be transition32
198 // Fall through to __call16
201 // Call a 16bit function from 16bit mode with a specified cpu register state
202 // %eax = address of struct bregs
203 // Clobbers: all gp registers, es
209 // Setup for iretw call
211 pushw $1f // return point
212 pushw 0x20(%eax) // flags
213 pushl 0x1c(%eax) // CS:IP
215 // Load calling registers.
216 movl 0x04(%eax), %edi
217 movl 0x08(%eax), %esi
218 movl 0x0c(%eax), %ebx
219 movl 0x10(%eax), %edx
220 movl 0x14(%eax), %ecx
221 movw 0x02(%eax), %es // XXX - should load %ds too
222 movl 0x18(%eax), %eax
225 iretw // XXX - just do a lcalll
227 // Store flags, eax, ecx
230 movl 0x06(%esp), %eax
231 movl %ecx, %ss:0x14(%eax) // Save %ecx
233 movw %cx, %ds // Restore %ds == %ss
235 movl %ecx, 0x18(%eax) // Save %eax
237 movw %cx, 0x20(%eax) // Save flags
239 // Store remaining registers
241 movl %edi, 0x04(%eax)
242 movl %esi, 0x08(%eax)
243 movl %ebx, 0x0c(%eax)
244 movl %edx, 0x10(%eax)
255 .globl apm16protected_entry
256 apm16protected_entry:
259 ENTRY_ARG handle_1553
260 addl $4, %esp // pop dummy
261 popfw // restore flags
265 .globl apm32protected_entry
266 apm32protected_entry:
268 pushw %cs // Setup for long jump to 16bit mode
274 ENTRY_ARG handle_1553
276 movw $2f,(%esp) // Setup for long jump back to 32bit mode
281 addl $4, %esp // pop call address
287 /****************************************************************
289 ****************************************************************/
291 // Protected mode IDT descriptor
293 // I just make the limit 0, so the machine will shutdown
294 // if an exception occurs during protected mode memory
297 // Set base to f0000 to correspond to beginning of BIOS,
298 // in case I actually define an IDT later
301 .word 0x0000 // limit 15:00
302 .long 0xf0000 // base 16:47
304 // Real mode IDT descriptor
306 // Set to typical real-mode values.
310 .word 0x03ff // limit 15:00
311 .long 0 // base 16:47
322 // 32 bit flat code segment (PROTECTED_MODE_CS)
323 .word 0xffff, 0, 0x9b00, 0x00cf
324 // 32 bit flat data segment (PROTECTED_MODE_DS)
325 .word 0xffff, 0, 0x9300, 0x00cf
326 // 16 bit code segment base=0xf0000 limit=0xffff (REAL_MODE_CS)
327 .word 0xffff, 0, 0x9b0f, 0x0000
328 // 16 bit data segment base=0x0 limit=0xffff (REAL_MODE_DS)
329 .word 0xffff, 0, 0x9300, 0x0000
332 /****************************************************************
333 * Interrupt entry points
334 ****************************************************************/
336 // Define an entry point for an interrupt (no args passed).
340 cli // In case something far-calls instead of using "int"
345 // Define an entry point for an interrupt (can read/modify args).
346 .macro IRQ_ENTRY_ARG num
349 cli // In case something far-calls instead of using "int"
350 ENTRY_ARG handle_\num
368 // XXX - Fixed Disk Parameter Table
374 .include "out/cbt.proc.16.s"
378 // XXX - Baud Rate Generator Table
386 // int 18/19 are special - they reset the stack and do not return.
398 .macro IRQ_TRAMPOLINE num
399 .globl irq_trampoline_0x\num
400 irq_trampoline_0x\num :
428 .include "out/floppy_dbt.proc.16.s"
445 .globl freespace2_start, freespace2_end
459 .include "out/font.proc.16.s"
469 // XXX - Initial Interrupt Vector Offsets Loaded by POST
472 // XXX - BIOS_COPYRIGHT_STRING
473 .ascii "(c) 2002 MandrakeSoft S.A. Written by Kevin Lawton & the Bochs team."
476 .globl dummy_iret_handler
483 ORG 0xfff0 // Power-up Entry Point
484 ljmpw $0xf000, $post16
491 .byte CONFIG_MODEL_ID