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 ****************************************************************/
28 // Macro to reset the 16bit stack
33 movl $ CONFIG_STACK_OFFSET , %esp
39 // init the stack pointer
42 // Set entry point of rombios32 code - the actual address
43 // is altered later in the build process.
48 // Fall through to transition32 function below
51 /****************************************************************
53 ****************************************************************/
55 // Place CPU into 32bit mode from 16bit mode.
56 // Clobbers: %eax, flags, stack registers, cr0, idt/gdt
66 // Set segment descriptors
67 lidt %cs:pmode_IDT_info
68 lgdt %cs:rombios32_gdt_48
75 // start protected mode code
76 .word 0xea66, 1f, 0x000f, 0x0010 // ljmpl $0x10, $(1f | 0xf0000)
93 // Call a 16bit function from 32bit mode.
94 // 4(%esp) = address of struct bregs
95 // Clobbers: all gp registers, flags, stack registers, cr0, idt/gdt
96 .globl __call16_from32
100 // Jump to 16bit mode
105 // restore data segment limits to 0xffff
113 // reset PE bit in CR0
118 // far jump to flush CPU queue after transition to real mode
121 // restore IDT to normal real-mode defaults
122 lidt %cs:rmode_IDT_info
124 // Clear segment registers
130 movw %ax, %ss // Assume stack is in segment 0
135 // Fall through to __call16
138 // Call a 16bit function with a specified cpu register state
139 // %eax = address of struct bregs
140 // Clobbers: all gp registers, es
146 // Setup for iretw call
148 pushw $1f // return point
149 pushw 0x28(%eax) // flags
150 pushl 0x24(%eax) // CS:IP
152 // Load calling registers.
153 movl 0x04(%eax), %edi
154 movl 0x08(%eax), %esi
155 movl 0x0c(%eax), %ebp
156 movl 0x14(%eax), %ebx
157 movl 0x18(%eax), %edx
158 movl 0x1c(%eax), %ecx
159 movw 0x02(%eax), %es // XXX - should load %ds too
160 movl 0x20(%eax), %eax
163 iretw // XXX - just do a lcalll
165 // Store flags, eax, ecx
168 movl 0x06(%esp), %eax
169 movl %ecx, 0x1c(%eax) // Save %ecx
171 movl %ecx, 0x20(%eax) // Save %eax
173 movw %cx, 0x28(%eax) // Save flags
175 // Store remaining registers
177 movl %edi, 0x04(%eax)
178 movl %esi, 0x08(%eax)
179 movl %ebp, 0x0c(%eax)
180 movl %ebx, 0x14(%eax)
181 movl %edx, 0x18(%eax)
189 /****************************************************************
191 ****************************************************************/
193 // Protected mode IDT descriptor
195 // I just make the limit 0, so the machine will shutdown
196 // if an exception occurs during protected mode memory
199 // Set base to f0000 to correspond to beginning of BIOS,
200 // in case I actually define an IDT later
203 .word 0x0000 // limit 15:00
204 .word 0x0000 // base 15:00
205 .byte 0x0f // base 23:16
207 // Real mode IDT descriptor
209 // Set to typical real-mode values.
213 .word 0x03ff // limit 15:00
214 .word 0x0000 // base 15:00
215 .byte 0x00 // base 23:16
225 .word 0xffff, 0, 0x9b00, 0x00cf // 32 bit flat code segment (0x10)
226 .word 0xffff, 0, 0x9300, 0x00cf // 32 bit flat data segment (0x18)
227 .word 0xffff, 0, 0x9b0f, 0x0000 // 16 bit code segment base=0xf0000 limit=0xffff
228 .word 0xffff, 0, 0x9300, 0x0000 // 16 bit data segment base=0x0 limit=0xffff
230 // We need a copy of this string, but we are not actually a PnP BIOS,
231 // so make sure it is *not* aligned, so OSes will not see it if they
240 /****************************************************************
241 * Interrupt entry points
242 ****************************************************************/
245 cli // In case something far-calls insted of using "int"
266 .macro IRQ_TRAMPOLINE num
267 .globl irq_trampoline_0x\num
268 irq_trampoline_0x\num :
308 // XXX - Fixed Disk Parameter Table
314 .include "out/cbt.proc.16.s"
318 // XXX - Baud Rate Generator Table
336 // XXX - Diskette Controller Parameter Table
352 .globl freespace2_start, freespace2_end
366 .include "out/font.proc.16.s"
376 // XXX - Initial Interrupt Vector Offsets Loaded by POST
379 // XXX - BIOS_COPYRIGHT_STRING
380 .ascii "(c) 2002 MandrakeSoft S.A. Written by Kevin Lawton & the Bochs team."
383 .globl dummy_iret_handler
390 .org 0xfff0 // Power-up Entry Point
391 ljmpw $0xf000, $post16
398 // model byte 0xFC = AT