2 * This file is part of the coreboot project.
4 * Copyright (C) 2009 coresystems GmbH
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 #define REALMODE_BASE 0x600
21 #define RELOCATED(x) (x - __realmode_code + REALMODE_BASE)
26 /* This is the intXX interrupt handler stub code. It gets copied
27 * to the IDT and to some fixed addresses in the F segment. Before
28 * the code can used, it gets patched up by the C function copying
29 * it: byte 3 (the $0 in movb $0, %al) is overwritten with the int#.
36 movb $0, %al /* This instruction gets modified */
37 ljmp $0, $__interrupt_handler_16bit
38 .globl __idt_handler_size
39 __idt_handler_size = ( . - __idt_handler)
42 /* In order to be independent of coreboot's position in RAM
43 * we relocate a part of the code to the low megabyte, so the
44 * CPU can use it in real-mode. This code lives at __realmode_code.
46 .globl __realmode_code
49 /* Realmode IDT pointer structure. */
51 __realmode_idt = RELOCATED(.)
52 .word 1023 /* 16-bit limit */
53 .long 0 /* 24-bit base */
56 /* Preserve old stack */
57 __stack = RELOCATED(.)
61 .globl __run_optionrom
62 __run_optionrom = RELOCATED(.)
63 /* save all registers to the stack */
66 /* Move the protected mode stack to a safe place */
69 /* Get devfn into %ecx */
71 /* This function is called with regparm=0 and we have
72 * to skip the 32 byte from pushal:
76 /* Activate the right segment descriptor real mode. */
77 ljmp $0x28, $RELOCATED(1f)
80 /* 16 bit code from here on... */
82 /* Load the segment registers w/ properly configured
83 * segment descriptors. They will retain these
84 * configurations (limits, writability, etc.) once
85 * protected mode is turned off.
94 /* Turn off protection */
99 /* Now really going into real mode */
100 ljmp $0, $RELOCATED(1f)
102 /* Setup a stack: Put the stack at the end of page zero.
103 * That way we can easily share it between real and
104 * protected, since the 16-bit ESP at segment 0 will
105 * work for any case. */
111 /* Load our 16 bit idt */
116 /* Set all segments to 0x0000, ds to 0x0040 */
122 mov %cx, %ax // restore ax
124 /* ************************************ */
125 // TODO this will not work for non-VGA option ROMs
126 /* run VGA BIOS at 0xc000:0003 */
127 lcall $0xc000, $0x0003
128 /* ************************************ */
130 /* If we got here, just about done.
131 * Need to get back to protected mode
137 /* Now that we are in protected mode
138 * jump to a 32 bit code segment.
140 data32 ljmp $0x10, $RELOCATED(1f)
150 /* restore proper idt */
158 #if defined(CONFIG_GEODE_VSA) && CONFIG_GEODE_VSA
159 #define VSA2_ENTRY_POINT 0x60020
162 __run_vsa = RELOCATED(.)
163 /* save all registers to the stack */
166 /* Move the protected mode stack to a safe place */
170 /* This function is called with regparm=0 and we have
171 * to skip the 32 byte from pushal:
176 /* Activate the right segment descriptor real mode. */
177 ljmp $0x28, $RELOCATED(1f)
180 /* 16 bit code from here on... */
182 /* Load the segment registers w/ properly configured
183 * segment descriptors. They will retain these
184 * configurations (limits, writability, etc.) once
185 * protected mode is turned off.
194 /* Turn off protection */
199 /* Now really going into real mode */
200 ljmp $0, $RELOCATED(1f)
202 /* Setup a stack: Put the stack at the end of page zero.
203 * That way we can easily share it between real and
204 * protected, since the 16-bit ESP at segment 0 will
205 * work for any case. */
211 /* Load our 16 bit idt */
216 /* Set all segments to 0x0000, ds to 0x0040 */
222 mov %cx, %ax // restore ax
224 /* ************************************ */
225 lcall $((VSA2_ENTRY_POINT & 0xffff0000) >> 4), $(VSA2_ENTRY_POINT & 0xffff)
226 /* ************************************ */
228 /* If we got here, just about done.
229 * Need to get back to protected mode
235 /* Now that we are in protected mode
236 * jump to a 32 bit code segment.
238 data32 ljmp $0x10, $RELOCATED(1f)
248 /* restore proper idt */
257 .globl __run_interrupt
258 __run_interrupt = RELOCATED(.)
260 /* paranoia -- does ecx get saved? not sure. This is
261 * the easiest safe thing to do. */
267 /* This configures CS properly for real mode. */
268 ljmp $0x28, $RELOCATED(1f)
270 .code16 /* 16 bit code from here on... */
276 /* Load the segment registers w/ properly configured segment
277 * descriptors. They will retain these configurations (limits,
278 * writability, etc.) once protected mode is turned off.
287 /* Turn off protected mode */
292 /* Now really going into real mode */
293 data32 ljmp $0, $RELOCATED(1f)
296 /* put the stack at the end of page zero.
297 * that way we can easily share it between real and protected,
298 * since the 16-bit ESP at segment 0 will work for any case.
306 /* Load 16-bit intXX IDT */
311 /* Set all segments to 0x0000 */
317 /* Call VGA BIOS int10 function 0x4f14 to enable main console
318 * Epia-M does not always autosence the main console so forcing
322 /* Ask VGA option rom to enable main console */
330 /* Ok, the job is done, now go back to protected mode coreboot */
335 /* Now that we are in protected mode jump to a 32-bit code segment. */
336 data32 ljmp $0x10, $RELOCATED(1f)
346 /* restore coreboot's 32-bit IDT */
354 /* This is the 16-bit interrupt entry point called by the IDT stub code.
355 * Before this code code is called, %eax is pushed to the stack, and the
356 * interrupt number is loaded into %al
359 __interrupt_handler_16bit = RELOCATED(.)
365 /* Clean up the interrupt number. We could have done this in the stub,
366 * but it would have cost 2 more bytes per stub entry.
369 pushl %eax /* ... and make it the first parameter */
371 /* Switch to protected mode */
376 /* ... and jump to a 32 bit code segment. */
377 data32 ljmp $0x10, $RELOCATED(1f)
389 /* Call the C interrupt handler */
390 movl $interrupt_handler, %eax
393 /* Now return to real mode ... */
394 ljmp $0x28, $RELOCATED(1f)
397 /* Load the segment registers with properly configured segment
398 * descriptors. They will retain these configurations (limits,
399 * writability, etc.) once protected mode is turned off.
408 /* Disable Protected Mode */
413 /* Now really going into real mode */
414 ljmp $0, $RELOCATED(1f)
416 /* Restore real-mode stack segment */
420 /* Restore 16-bit IDT */
425 /* Set up our segment registers to segment 0x0000 */
432 /* Restore all registers, including those
433 * manipulated by the C handler
443 .globl __realmode_code_size
444 __realmode_code_size = (. - __realmode_code)