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 // ljmpl $PROTECTED_MODE_CS, $(1f | 0xf0000)
82 .word 0xea66, 1f, 0x000f, PROTECTED_MODE_CS
87 movl $PROTECTED_MODE_DS, %eax
99 // Call a 16bit function from 32bit mode.
100 // %eax = address of struct bregs
101 // Clobbers: all gp registers, flags, stack registers, cr0, idt/gdt
102 .globl __call16_from32
106 // Jump to 16bit mode
107 ljmp $REAL_MODE_CS, $1f
111 // restore data segment limits to 0xffff
112 movw $REAL_MODE_DS, %ax
119 // reset PE bit in CR0
124 // far jump to flush CPU queue after transition to real mode
128 // restore IDT to normal real-mode defaults
129 lidt %cs:rmode_IDT_info
131 // Clear segment registers
137 movw %ax, %ss // Assume stack is in segment 0
142 // Fall through to __call16
145 // Call a 16bit function from 16bit mode with a specified cpu register state
146 // %eax = address of struct bregs
147 // Clobbers: all gp registers, es
153 // Setup for iretw call
155 pushw $1f // return point
156 pushw 0x28(%eax) // flags
157 pushl 0x24(%eax) // CS:IP
159 // Load calling registers.
160 movl 0x04(%eax), %edi
161 movl 0x08(%eax), %esi
162 movl 0x0c(%eax), %ebp
163 movl 0x14(%eax), %ebx
164 movl 0x18(%eax), %edx
165 movl 0x1c(%eax), %ecx
166 movw 0x02(%eax), %es // XXX - should load %ds too
167 movl 0x20(%eax), %eax
170 iretw // XXX - just do a lcalll
172 // Store flags, eax, ecx
175 movl 0x06(%esp), %eax
176 movl %ecx, 0x1c(%eax) // Save %ecx
178 movl %ecx, 0x20(%eax) // Save %eax
180 movw %cx, 0x28(%eax) // Save flags
182 // Store remaining registers
184 movl %edi, 0x04(%eax)
185 movl %esi, 0x08(%eax)
186 movl %ebp, 0x0c(%eax)
187 movl %ebx, 0x14(%eax)
188 movl %edx, 0x18(%eax)
196 /****************************************************************
198 ****************************************************************/
200 // Protected mode IDT descriptor
202 // I just make the limit 0, so the machine will shutdown
203 // if an exception occurs during protected mode memory
206 // Set base to f0000 to correspond to beginning of BIOS,
207 // in case I actually define an IDT later
210 .word 0x0000 // limit 15:00
211 .long 0xf0000 // base 16:47
213 // Real mode IDT descriptor
215 // Set to typical real-mode values.
219 .word 0x03ff // limit 15:00
220 .long 0 // base 16:47
231 // 32 bit flat code segment (PROTECTED_MODE_CS)
232 .word 0xffff, 0, 0x9b00, 0x00cf
233 // 32 bit flat data segment (PROTECTED_MODE_DS)
234 .word 0xffff, 0, 0x9300, 0x00cf
235 // 16 bit code segment base=0xf0000 limit=0xffff (REAL_MODE_CS)
236 .word 0xffff, 0, 0x9b0f, 0x0000
237 // 16 bit data segment base=0x0 limit=0xffff (REAL_MODE_DS)
238 .word 0xffff, 0, 0x9300, 0x0000
241 /****************************************************************
242 * Interrupt entry points
243 ****************************************************************/
246 cli // In case something far-calls instead of using "int"
267 .macro IRQ_TRAMPOLINE num
268 .globl irq_trampoline_0x\num
269 irq_trampoline_0x\num :
309 // XXX - Fixed Disk Parameter Table
315 .include "out/cbt.proc.16.s"
319 // XXX - Baud Rate Generator Table
337 .include "out/floppy_dbt.proc.16.s"
354 .globl freespace2_start, freespace2_end
368 .include "out/font.proc.16.s"
378 // XXX - Initial Interrupt Vector Offsets Loaded by POST
381 // XXX - BIOS_COPYRIGHT_STRING
382 .ascii "(c) 2002 MandrakeSoft S.A. Written by Kevin Lawton & the Bochs team."
385 .globl dummy_iret_handler
392 .org 0xfff0 // Power-up Entry Point
393 ljmpw $0xf000, $post16
400 .byte CONFIG_MODEL_ID