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.
13 /****************************************************************
14 * Include of 16bit C code
15 ****************************************************************/
17 .globl bios16c_start, bios16c_end
19 .include "out/blob.proc.16.s"
24 /****************************************************************
26 ****************************************************************/
33 // init the stack pointer
36 movl $ CONFIG_STACK_OFFSET , %esp
38 // Set entry point of rombios32 code - the actual address
39 // is altered later in the build process.
44 // Fall through to transition32 function below
47 /****************************************************************
49 ****************************************************************/
51 // Place CPU into 32bit mode from 16bit mode.
52 // Clobbers: %eax, flags, stack registers, cr0, idt/gdt
62 // Set segment descriptors
63 lidt %cs:pmode_IDT_info
64 lgdt %cs:rombios32_gdt_48
71 // start protected mode code
72 .word 0xea66, 1f, 0x000f, 0x0010 // ljmpl $0x10, $(1f | 0xf0000)
89 // Call a 16bit function from 32bit mode.
90 // 4(%esp) = address of struct bregs
91 // Clobbers: all gp registers, flags, stack registers, cr0, idt/gdt
92 .globl __call16_from32
101 // restore data segment limits to 0xffff
109 // reset PE bit in CR0
114 // far jump to flush CPU queue after transition to real mode
117 // restore IDT to normal real-mode defaults
118 lidt %cs:rmode_IDT_info
120 // Clear segment registers
126 movw %ax, %ss // Assume stack is in segment 0
131 // Fall through to __call16
134 // Call a 16bit function with a specified cpu register state
135 // %eax = address of struct bregs
136 // Clobbers: all gp registers, es
142 // Setup for iretw call
144 pushw $1f // return point
145 pushw 0x28(%eax) // flags
146 pushl 0x24(%eax) // CS:IP
148 // Load calling registers.
149 movl 0x04(%eax), %edi
150 movl 0x08(%eax), %esi
151 movl 0x0c(%eax), %ebp
152 movl 0x14(%eax), %ebx
153 movl 0x18(%eax), %edx
154 movl 0x1c(%eax), %ecx
155 movw 0x02(%eax), %es // XXX - should load %ds too
156 movl 0x20(%eax), %eax
159 iretw // XXX - just do a lcalll
161 // Store flags, eax, ecx
164 movl 0x06(%esp), %eax
165 movl %ecx, 0x1c(%eax) // Save %ecx
167 movl %ecx, 0x20(%eax) // Save %eax
169 movw %cx, 0x28(%eax) // Save flags
171 // Store remaining registers
173 movl %edi, 0x04(%eax)
174 movl %esi, 0x08(%eax)
175 movl %ebp, 0x0c(%eax)
176 movl %ebx, 0x14(%eax)
177 movl %edx, 0x18(%eax)
185 /****************************************************************
187 ****************************************************************/
189 // Protected mode IDT descriptor
191 // I just make the limit 0, so the machine will shutdown
192 // if an exception occurs during protected mode memory
195 // Set base to f0000 to correspond to beginning of BIOS,
196 // in case I actually define an IDT later
199 .word 0x0000 // limit 15:00
200 .word 0x0000 // base 15:00
201 .byte 0x0f // base 23:16
203 // Real mode IDT descriptor
205 // Set to typical real-mode values.
209 .word 0x03ff // limit 15:00
210 .word 0x0000 // base 15:00
211 .byte 0x00 // base 23:16
221 .word 0xffff, 0, 0x9b00, 0x00cf // 32 bit flat code segment (0x10)
222 .word 0xffff, 0, 0x9300, 0x00cf // 32 bit flat data segment (0x18)
223 .word 0xffff, 0, 0x9b0f, 0x0000 // 16 bit code segment base=0xf0000 limit=0xffff
224 .word 0xffff, 0, 0x9300, 0x0000 // 16 bit data segment base=0x0 limit=0xffff
226 // We need a copy of this string, but we are not actually a PnP BIOS,
227 // so make sure it is *not* aligned, so OSes will not see it if they
236 /****************************************************************
237 * Interrupt entry points
238 ****************************************************************/
241 cli // In case something far-calls insted of using "int"
262 .macro IRQ_TRAMPOLINE num
263 .globl irq_trampoline_0x\num
264 irq_trampoline_0x\num :
283 // init the stack pointer
286 movl $ CONFIG_STACK_OFFSET , %esp
291 // init the stack pointer
294 movl $ CONFIG_STACK_OFFSET , %esp
310 // XXX - Fixed Disk Parameter Table
313 // XXX - should reset ss and sp
317 .include "out/cbt.proc.16.s"
321 // XXX - Baud Rate Generator Table
339 // XXX - Diskette Controller Parameter Table
355 .globl freespace2_start, freespace2_end
369 .include "out/font.proc.16.s"
379 // XXX - Initial Interrupt Vector Offsets Loaded by POST
382 // XXX - BIOS_COPYRIGHT_STRING
383 .ascii "(c) 2002 MandrakeSoft S.A. Written by Kevin Lawton & the Bochs team."
386 .globl dummy_iret_handler
393 .org 0xfff0 // Power-up Entry Point
394 ljmpw $0xf000, $post16
401 // model byte 0xFC = AT