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 // Macro to reset the 16bit stack
38 movl $ CONFIG_STACK_OFFSET , %esp
44 // init the stack pointer
47 // Set entry point of rombios32 code - the actual address
48 // is altered later in the build process.
53 // Fall through to transition32 function below
56 /****************************************************************
58 ****************************************************************/
60 // Place CPU into 32bit mode from 16bit mode.
61 // Clobbers: %eax, flags, stack registers, cr0, idt/gdt
71 // Set segment descriptors
72 lidt %cs:pmode_IDT_info
73 lgdt %cs:rombios32_gdt_48
80 // start protected mode code
81 .word 0xea66, 1f, 0x000f, PROTECTED_MODE_CS // ljmpl $PROTECTED_MODE_CS, $1f
86 movl $PROTECTED_MODE_DS, %eax
98 // Call a 16bit function from 32bit mode.
99 // 4(%esp) = address of struct bregs
100 // Clobbers: all gp registers, flags, stack registers, cr0, idt/gdt
101 .globl __call16_from32
105 // Jump to 16bit mode
110 // restore data segment limits to 0xffff
118 // reset PE bit in CR0
123 // far jump to flush CPU queue after transition to real mode
127 // restore IDT to normal real-mode defaults
128 lidt %cs:rmode_IDT_info
130 // Clear segment registers
136 movw %ax, %ss // Assume stack is in segment 0
141 // Fall through to __call16
144 // Call a 16bit function from 16bit mode with a specified cpu register state
145 // %eax = address of struct bregs
146 // Clobbers: all gp registers, es
152 // Setup for iretw call
154 pushw $1f // return point
155 pushw 0x28(%eax) // flags
156 pushl 0x24(%eax) // CS:IP
158 // Load calling registers.
159 movl 0x04(%eax), %edi
160 movl 0x08(%eax), %esi
161 movl 0x0c(%eax), %ebp
162 movl 0x14(%eax), %ebx
163 movl 0x18(%eax), %edx
164 movl 0x1c(%eax), %ecx
165 movw 0x02(%eax), %es // XXX - should load %ds too
166 movl 0x20(%eax), %eax
169 iretw // XXX - just do a lcalll
171 // Store flags, eax, ecx
174 movl 0x06(%esp), %eax
175 movl %ecx, 0x1c(%eax) // Save %ecx
177 movl %ecx, 0x20(%eax) // Save %eax
179 movw %cx, 0x28(%eax) // Save flags
181 // Store remaining registers
183 movl %edi, 0x04(%eax)
184 movl %esi, 0x08(%eax)
185 movl %ebp, 0x0c(%eax)
186 movl %ebx, 0x14(%eax)
187 movl %edx, 0x18(%eax)
195 /****************************************************************
197 ****************************************************************/
199 // Protected mode IDT descriptor
201 // I just make the limit 0, so the machine will shutdown
202 // if an exception occurs during protected mode memory
205 // Set base to f0000 to correspond to beginning of BIOS,
206 // in case I actually define an IDT later
209 .word 0x0000 // limit 15:00
210 .long 0xf0000 // base 16:47
212 // Real mode IDT descriptor
214 // Set to typical real-mode values.
218 .word 0x03ff // limit 15:00
219 .long 0 // base 16:47
229 .word 0xffff, 0, 0x9b00, 0x00cf // 32 bit flat code segment (PROTECTED_MODE_CS)
230 .word 0xffff, 0, 0x9300, 0x00cf // 32 bit flat data segment (PROTECTED_MODE_DS)
231 .word 0xffff, 0, 0x9b0f, 0x0000 // 16 bit code segment base=0xf0000 limit=0xffff
232 .word 0xffff, 0, 0x9300, 0x0000 // 16 bit data segment base=0x0 limit=0xffff
234 // We need a copy of this string, but we are not actually a PnP BIOS,
235 // so make sure it is *not* aligned, so OSes will not see it if they
244 /****************************************************************
245 * Interrupt entry points
246 ****************************************************************/
249 cli // In case something far-calls insted of using "int"
270 .macro IRQ_TRAMPOLINE num
271 .globl irq_trampoline_0x\num
272 irq_trampoline_0x\num :
312 // XXX - Fixed Disk Parameter Table
318 .include "out/cbt.proc.16.s"
322 // XXX - Baud Rate Generator Table
340 // XXX - Diskette Controller Parameter Table
356 .globl freespace2_start, freespace2_end
370 .include "out/font.proc.16.s"
380 // XXX - Initial Interrupt Vector Offsets Loaded by POST
383 // XXX - BIOS_COPYRIGHT_STRING
384 .ascii "(c) 2002 MandrakeSoft S.A. Written by Kevin Lawton & the Bochs team."
387 .globl dummy_iret_handler
394 .org 0xfff0 // Power-up Entry Point
395 ljmpw $0xf000, $post16
402 // model byte 0xFC = AT