2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
21 * Note: These functions defined in this file may be called from C.
22 * Be careful of that you must not modify some registers. Quote
23 * from gcc-2.95.2/gcc/config/i386/i386.h:
25 1 for registers not available across function calls.
26 These must include the FIXED_REGISTERS and also any
27 registers that can be used without being saved.
28 The latter must include the registers where values are returned
29 and the register where structure-value addresses are passed.
30 Aside from that, you can include as many other registers as you like.
32 ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7,arg
33 { 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
37 * Note: GRUB is compiled with the options -mrtd and -mregparm=3.
38 * So the first three arguments are passed in %eax, %edx, and %ecx,
39 * respectively, and if a function has a fixed number of arguments
40 * and the number if greater than three, the function must return
41 * with "ret $N" where N is ((the number of arguments) - 3) * 4.
45 #include <grub/symbol.h>
46 #include <grub/boot.h>
47 #include <grub/machine/boot.h>
48 #include <grub/machine/memory.h>
49 #include <grub/machine/console.h>
50 #include <grub/cpu/linux.h>
51 #include <grub/machine/kernel.h>
52 #include <grub/term.h>
53 #include <multiboot.h>
54 #include <multiboot2.h>
56 #define ABS(x) ((x) - EXT_C(start) + GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200)
62 /* Tell GAS to generate 16-bit instructions so that this code works
70 * Guarantee that "main" is loaded at 0x0:0x8200.
72 ljmp $0, $ABS(codestart)
75 * Compatibility version number
77 * These MUST be at byte offset 6 and 7 of the executable
80 . = EXT_C(start) + 0x6
81 .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR
84 * This is a special data area 8 bytes from the beginning.
87 . = EXT_C(start) + 0x8
89 VARIABLE(grub_total_module_size)
91 VARIABLE(grub_kernel_image_size)
93 VARIABLE(grub_compressed_size)
95 VARIABLE(grub_install_dos_part)
97 VARIABLE(grub_install_bsd_part)
99 VARIABLE(grub_memdisk_image_size)
101 VARIABLE(grub_prefix)
102 /* to be filled by grub-mkimage */
105 * Leave some breathing room for the prefix.
108 . = EXT_C(start) + 0x50
111 * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself).
112 * This uses the a.out kludge to load raw binary to the area starting at 1MB,
113 * and relocates itself after loaded.
121 .long -0x1BADB002 - (1 << 16)
123 .long multiboot_header - _start + 0x100000 + 0x200
131 .long multiboot_entry - _start + 0x100000 + 0x200
135 /* obtain the boot device */
138 /* relocate the code */
139 movl $(GRUB_KERNEL_MACHINE_RAW_SIZE + 0x200), %ecx
140 addl EXT_C(grub_compressed_size) - _start + 0x100000 + 0x200, %ecx
142 movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %edi
146 /* jump to the real address */
147 movl $multiboot_trampoline, %eax
150 multiboot_trampoline:
151 /* fill the boot information */
158 movl %ebx, EXT_C(grub_install_dos_part)
163 movl %ebx, EXT_C(grub_install_bsd_part)
167 /* enter the usual booting */
171 /* the real mode code continues... */
173 cli /* we're not safe here! */
175 /* set up %ds, %ss, and %es */
181 /* set up the real mode/BIOS stack */
182 movl $GRUB_MEMORY_MACHINE_REAL_STACK, %ebp
185 sti /* we're safe again */
187 /* save boot and root drive references */
188 ADDR32 movb %dl, EXT_C(grub_boot_drive)
189 ADDR32 movb %dh, EXT_C(grub_root_drive)
191 /* reset disk system (%ah = 0) */
194 /* transition to protected mode */
195 DATA32 call real_to_prot
197 /* The ".code32" directive takes GAS out of 16-bit mode. */
201 call EXT_C(grub_gate_a20)
203 /* decompress the compressed part and put the result at 1MB */
204 movl $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %esi
205 movl $(START_SYMBOL + GRUB_KERNEL_MACHINE_RAW_SIZE), %edi
208 pushl EXT_C(grub_compressed_size)
210 call lzo1x_decompress
213 /* copy back the decompressed part */
219 /* copy modules before cleaning out the bss */
220 movl EXT_C(grub_total_module_size), %ecx
221 movl EXT_C(grub_kernel_image_size), %esi
223 addl $START_SYMBOL, %esi
225 movl $END_SYMBOL, %edi
232 /* clean out the bss */
233 movl $BSS_START_SYMBOL, %edi
235 /* compute the bss length */
236 movl $END_SYMBOL, %ecx
246 * Call the start of main body of C code.
248 call EXT_C(grub_main)
250 #include "../realmode.S"
253 * This is the area for all of the special variables.
256 .p2align 2 /* force 4-byte alignment */
258 VARIABLE(grub_boot_drive)
261 VARIABLE(grub_root_drive)
264 VARIABLE(grub_start_addr)
267 VARIABLE(grub_end_addr)
270 VARIABLE(grub_apm_bios_info)
271 .word 0 /* version */
274 .word 0 /* cseg_16 */
275 .word 0 /* dseg_16 */
276 .word 0 /* cseg_len */
277 .word 0 /* cseg_16_len */
278 .word 0 /* dseg_16_len */
280 .p2align 2 /* force 4-byte alignment */
283 * These next two routines, "real_to_prot" and "prot_to_real" are structured
284 * in a very specific way. Be very careful when changing them.
286 * NOTE: Use of either one messes up %eax and %ebp.
293 /* load the GDT register */
294 DATA32 ADDR32 lgdt %cs:gdtdesc
296 /* turn on protected mode */
298 orl $GRUB_MEMORY_MACHINE_CR0_PE_ON, %eax
301 /* jump to relocation, flush prefetch queue, and reload %cs */
302 DATA32 ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $protcseg
306 /* reload other segment registers */
307 movw $GRUB_MEMORY_MACHINE_PROT_MODE_DSEG, %ax
314 /* put the return address in a known safe location */
316 movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK
318 /* get protected mode stack */
323 /* get return address onto the right stack */
324 movl GRUB_MEMORY_MACHINE_REAL_STACK, %eax
330 /* return on the old (or initialized) stack! */
334 * grub_gate_a20(int on)
336 * Gate address-line 20 for high memory.
338 * This routine is probably overconservative in what it does, but so what?
340 * It also eats any keystrokes in the keyboard buffer. :-(
343 FUNCTION(grub_gate_a20)
346 gate_a20_test_current_state:
347 /* first of all, test if already in a good state */
348 call gate_a20_check_state
350 jnz gate_a20_try_bios
354 /* second, try a BIOS call */
365 DATA32 call real_to_prot
369 call gate_a20_check_state
371 jnz gate_a20_try_keyboard_controller
374 gate_a20_flush_keyboard_buffer:
377 jnz gate_a20_flush_keyboard_buffer
387 gate_a20_try_keyboard_controller:
388 /* third, try the keyboard controller */
389 call gate_a20_flush_keyboard_buffer
403 call gate_a20_flush_keyboard_buffer
405 /* output a dummy command (USB keyboard hack) */
408 call gate_a20_flush_keyboard_buffer
410 call gate_a20_check_state
412 jnz gate_a20_try_system_control_port_a
415 gate_a20_try_system_control_port_a:
416 /* fourth, try the system control port A */
424 /* When turning off Gate A20, do not check the state strictly,
425 because a failure is not fatal usually, and Gate A20 is always
426 on some modern machines. */
429 call gate_a20_check_state
431 /* everything failed, so restart from the beginning */
432 jnz gate_a20_try_bios
435 gate_a20_check_state:
436 /* iterate the checking for a while */
449 /* compare the byte at 0x8000 with that at 0x108000 */
450 movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %ebx
452 /* save the original byte in CL */
454 /* store the value at 0x108000 in AL */
457 /* try to set one less value at 0x8000 */
465 /* obtain the value at 0x108000 in CH */
469 /* this result is 1 if A20 is on or 0 if it is off */
472 /* restore the original */
482 * The code beyond this point is compressed. Assert that the uncompressed
483 * code fits GRUB_KERNEL_MACHINE_RAW_SIZE.
485 . = EXT_C(start) + GRUB_KERNEL_MACHINE_RAW_SIZE
488 * This call is special... it never returns... in fact it should simply
489 * hang at this point!
496 * This next part is sort of evil. It takes advantage of the
497 * byte ordering on the x86 to work in either 16-bit or 32-bit
498 * mode, so think about it before changing it.
501 FUNCTION(grub_hard_stop)
503 jmp EXT_C(grub_hard_stop)
509 * Stop the floppy drive from spinning, so that other software is
510 * jumped to with a known state.
512 FUNCTION(grub_stop_floppy)
526 /* Tell the BIOS a boot failure. If this does not work, reboot. */
534 * Reboot the system. At the moment, rely on BIOS.
536 FUNCTION(grub_reboot)
543 ljmp $0xFFFF, $0x0000
547 * grub_halt(int no_apm)
549 * Halt the system, using APM if possible. If NO_APM is true, don't use
550 * APM even if it is available.
564 jc EXT_C(grub_hard_stop)
565 /* don't check %bx for buggy BIOSes... */
567 /* disconnect APM first */
576 jc EXT_C(grub_hard_stop)
578 /* set APM protocol level - 1.1 or bust. (this covers APM 1.2 also) */
583 jc EXT_C(grub_hard_stop)
585 /* set the power state to off */
591 /* shouldn't reach here */
592 jmp EXT_C(grub_hard_stop)
597 * void grub_chainloader_real_boot (int drive, void *part_addr)
599 * This starts another boot loader.
602 FUNCTION(grub_chainloader_real_boot)
606 call EXT_C(grub_dl_unload_all)
608 /* Turn off Gate A20 */
610 call EXT_C(grub_gate_a20)
612 /* set up to pass boot drive */
615 /* ESI must point to a partition table entry */
620 ljmp $0, $GRUB_MEMORY_MACHINE_BOOT_LOADER_ADDR
623 #include "../loader.S"
626 * int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap)
628 * Call IBM/MS INT13 Extensions (int 13 %ah=AH) for DRIVE. DAP
629 * is passed for disk address packet. If an error occurs, return
630 * non-zero, otherwise zero.
633 FUNCTION(grub_biosdisk_rw_int13_extensions)
637 /* compute the address of disk_address_packet */
640 shrl $4, %ecx /* save the segment to cx */
644 /* enter real mode */
650 int $0x13 /* do the operation */
651 movb %ah, %dl /* save return value */
652 /* back to protected mode */
653 DATA32 call real_to_prot
656 movb %dl, %al /* return value in %eax */
664 * int grub_biosdisk_rw_standard (int ah, int drive, int coff, int hoff,
665 * int soff, int nsec, int segment)
667 * Call standard and old INT13 (int 13 %ah=AH) for DRIVE. Read/write
668 * NSEC sectors from COFF/HOFF/SOFF into SEGMENT. If an error occurs,
669 * return non-zero, otherwise zero.
672 FUNCTION(grub_biosdisk_rw_standard)
680 /* set up CHS information */
682 /* set %ch to low eight bits of cylinder */
684 /* set bits 6-7 of %cl to high two bits of cylinder */
686 /* set bits 0-5 of %cl to sector */
688 /* set %dh to head */
692 /* set %al to NSEC */
694 /* save %ax in %di */
696 /* save SEGMENT in %bx */
699 /* enter real mode */
705 movw $3, %si /* attempt at least three times */
709 int $0x13 /* do the operation */
710 jnc 2f /* check if successful */
712 movb %ah, %bl /* save return value */
713 /* if fail, reset the disk system */
723 /* back to protected mode */
724 DATA32 call real_to_prot
727 movb %bl, %al /* return value in %eax */
738 * int grub_biosdisk_check_int13_extensions (int drive)
740 * Check if LBA is supported for DRIVE. If it is supported, then return
741 * the major version of extensions, otherwise zero.
744 FUNCTION(grub_biosdisk_check_int13_extensions)
750 /* enter real mode */
756 int $0x13 /* do the operation */
758 /* check the result */
763 movb %ah, %bl /* save the major version into %bl */
765 /* check if AH=0x42 is supported */
772 /* back to protected mode */
773 DATA32 call real_to_prot
776 movb %bl, %al /* return value in %eax */
785 * int grub_biosdisk_get_cdinfo_int13_extensions (int drive, void *cdrp)
787 * Return the cdrom information of DRIVE in CDRP. If an error occurs,
788 * then return non-zero, otherwise zero.
791 FUNCTION(grub_biosdisk_get_cdinfo_int13_extensions)
796 * int grub_biosdisk_get_diskinfo_int13_extensions (int drive, void *drp)
798 * Return the geometry of DRIVE in a drive parameters, DRP. If an error
799 * occurs, then return non-zero, otherwise zero.
802 FUNCTION(grub_biosdisk_get_diskinfo_int13_extensions)
809 /* compute the address of drive parameters */
813 movw %dx, %bx /* save the segment into %bx */
816 /* enter real mode */
822 int $0x13 /* do the operation */
823 movb %ah, %bl /* save return value in %bl */
824 /* back to protected mode */
825 DATA32 call real_to_prot
828 movb %bl, %al /* return value in %eax */
838 * int grub_biosdisk_get_diskinfo_standard (int drive,
839 * unsigned long *cylinders,
840 * unsigned long *heads,
841 * unsigned long *sectors)
843 * Return the geometry of DRIVE in CYLINDERS, HEADS and SECTORS. If an
844 * error occurs, then return non-zero, otherwise zero.
847 FUNCTION(grub_biosdisk_get_diskinfo_standard)
856 /* SECTORS is on the stack */
860 /* enter real mode */
865 int $0x13 /* do the operation */
866 /* check if successful */
869 /* bogus BIOSes may not return an error number */
870 testb $0x3f, %cl /* 0 sectors means no disk */
871 jnz 1f /* if non-zero, then succeed */
872 /* XXX 0x60 is one of the unused error numbers */
875 movb %ah, %bl /* save return value in %bl */
876 /* back to protected mode */
877 DATA32 call real_to_prot
883 incl %eax /* the number of heads is counted from zero */
890 shrb $6, %ah /* the number of cylinders is counted from zero */
895 movl 0x10(%esp), %edi
901 movb %bl, %al /* return value in %eax */
911 * int grub_biosdisk_get_num_floppies (void)
913 FUNCTION(grub_biosdisk_get_num_floppies)
920 /* reset the disk system first */
925 /* call GET DISK TYPE */
931 /* check if this drive exists */
939 DATA32 call real_to_prot
949 * grub_get_memsize(i) : return the memory size in KB. i == 0 for conventional
950 * memory, i == 1 for extended memory
951 * BIOS call "INT 12H" to get conventional memory size
952 * BIOS call "INT 15H, AH=88H" to get extended memory size
953 * Both have the return value in AX.
957 FUNCTION(grub_get_memsize)
962 call prot_to_real /* enter real mode */
978 DATA32 call real_to_prot
989 * grub_get_eisa_mmap() : return packed EISA memory map, lower 16 bits is
990 * memory between 1M and 16M in 1K parts, upper 16 bits is
991 * memory above 16M in 64K parts. If error, return zero.
992 * BIOS call "INT 15H, AH=E801H" to get EISA memory map,
993 * AX = memory between 1M and 16M in 1K parts.
994 * BX = memory above 16M in 64K parts.
998 FUNCTION(grub_get_eisa_mmap)
1002 call prot_to_real /* enter real mode */
1011 DATA32 call real_to_prot
1026 * grub_get_mmap_entry(addr, cont) : address and old continuation value (zero to
1027 * start), for the Query System Address Map BIOS call.
1029 * Sets the first 4-byte int value of "addr" to the size returned by
1030 * the call. If the call fails, sets it to zero.
1032 * Returns: new (non-zero) continuation value, 0 if done.
1035 FUNCTION(grub_get_mmap_entry)
1044 /* place address (+4) in ES:DI */
1051 /* set continuation value */
1054 /* set default maximum buffer size */
1057 /* set EDX to 'SMAP' */
1058 movl $0x534d4150, %edx
1060 call prot_to_real /* enter real mode */
1069 cmpl $0x534d4150, %eax
1084 DATA32 call real_to_prot
1087 /* write length of buffer (zero if error) into ADDR */
1091 /* set return value to continuation */
1102 * void grub_console_real_putchar (int c)
1104 * Put the character C on the console. Because GRUB wants to write a
1105 * character with an attribute, this implementation is a bit tricky.
1106 * If C is a control character (CR, LF, BEL, BS), use INT 10, AH = 0Eh
1107 * (TELETYPE OUTPUT). Otherwise, save the original position, put a space,
1108 * save the current position, restore the original position, write the
1109 * character and the attribute, and restore the current position.
1111 * The reason why this is so complicated is that there is no easy way to
1112 * get the height of the screen, and the TELETYPE OUTPUT BIOS call doesn't
1113 * support setting a background attribute.
1115 FUNCTION(grub_console_real_putchar)
1118 movb EXT_C(grub_console_cur_color), %bl
1125 /* use teletype output if control character */
1135 /* save the character and the attribute on the stack */
1139 /* get the current position */
1143 /* check the column with the width */
1147 /* print CR and LF, if next write will exceed the width */
1153 /* get the current position */
1158 /* restore the character and the attribute */
1162 /* write the character with the attribute */
1167 /* move the cursor forward */
1178 3: DATA32 call real_to_prot
1186 * int grub_console_getkey (void)
1187 * BIOS call "INT 16H Function 00H" to read character from keyboard
1188 * Call with %ah = 0x0
1189 * Return: %ah = keyboard scan code
1190 * %al = ASCII character
1193 /* this table is used in translate_keycode below */
1195 .word GRUB_CONSOLE_KEY_LEFT, GRUB_TERM_LEFT
1196 .word GRUB_CONSOLE_KEY_RIGHT, GRUB_TERM_RIGHT
1197 .word GRUB_CONSOLE_KEY_UP, GRUB_TERM_UP
1198 .word GRUB_CONSOLE_KEY_DOWN, GRUB_TERM_DOWN
1199 .word GRUB_CONSOLE_KEY_HOME, GRUB_TERM_HOME
1200 .word GRUB_CONSOLE_KEY_END, GRUB_TERM_END
1201 .word GRUB_CONSOLE_KEY_DC, GRUB_TERM_DC
1202 .word GRUB_CONSOLE_KEY_BACKSPACE, GRUB_TERM_BACKSPACE
1203 .word GRUB_CONSOLE_KEY_PPAGE, GRUB_TERM_PPAGE
1204 .word GRUB_CONSOLE_KEY_NPAGE, GRUB_TERM_NPAGE
1208 * translate_keycode translates the key code %dx to an ascii code.
1216 movw $ABS(translation_table), %si
1219 /* check if this is the end */
1222 /* load the ascii code into %ax */
1225 /* check if this matches the key code */
1228 /* translate %dx, if successful */
1237 FUNCTION(grub_console_getkey)
1245 movw %ax, %dx /* real_to_prot uses %eax */
1246 call translate_keycode
1248 DATA32 call real_to_prot
1258 * int grub_console_checkkey (void)
1259 * if there is a character pending, return it; otherwise return -1
1260 * BIOS call "INT 16H Function 01H" to check whether a character is pending
1261 * Call with %ah = 0x1
1263 * If key waiting to be input:
1264 * %ah = keyboard scan code
1265 * %al = ASCII character
1270 FUNCTION(grub_console_checkkey)
1274 call prot_to_real /* enter real mode */
1289 DATA32 call real_to_prot
1299 * grub_uint16_t grub_console_getxy (void)
1300 * BIOS call "INT 10H Function 03h" to get cursor position
1301 * Call with %ah = 0x03
1303 * Returns %ch = starting scan line
1304 * %cl = ending scan line
1305 * %dh = row (0 is top)
1306 * %dl = column (0 is left)
1310 FUNCTION(grub_console_getxy)
1312 pushl %ebx /* save EBX */
1317 xorb %bh, %bh /* set page to 0 */
1319 int $0x10 /* get cursor position */
1321 DATA32 call real_to_prot
1333 * void grub_console_gotoxy(grub_uint8_t x, grub_uint8_t y)
1334 * BIOS call "INT 10H Function 02h" to set cursor position
1335 * Call with %ah = 0x02
1337 * %dh = row (0 is top)
1338 * %dl = column (0 is left)
1342 FUNCTION(grub_console_gotoxy)
1344 pushl %ebx /* save EBX */
1346 movb %dl, %dh /* %dh = y */
1347 movb %al, %dl /* %dl = x */
1352 xorb %bh, %bh /* set page to 0 */
1354 int $0x10 /* set cursor position */
1356 DATA32 call real_to_prot
1365 * void grub_console_cls (void)
1366 * BIOS call "INT 10H Function 09h" to write character and attribute
1367 * Call with %ah = 0x09
1369 * %bh = (page number)
1371 * %cx = (number of times)
1374 FUNCTION(grub_console_cls)
1376 pushl %ebx /* save EBX */
1381 /* move the cursor to the beginning */
1387 /* write spaces to the entire screen */
1390 movw $(80 * 25), %cx
1393 /* move back the cursor */
1397 DATA32 call real_to_prot
1406 * void grub_console_setcursor (int on)
1407 * BIOS call "INT 10H Function 01h" to set cursor type
1408 * Call with %ah = 0x01
1409 * %ch = cursor starting scanline
1410 * %cl = cursor ending scanline
1413 console_cursor_state:
1415 console_cursor_shape:
1418 FUNCTION(grub_console_setcursor)
1425 /* check if the standard cursor shape has already been saved */
1426 movw console_cursor_shape, %ax
1437 DATA32 call real_to_prot
1440 movw %cx, console_cursor_shape
1442 /* set %cx to the designated cursor shape */
1447 movw console_cursor_shape, %cx
1455 DATA32 call real_to_prot
1464 * if a seconds value can be read, read it and return it (BCD),
1465 * otherwise return 0xFF
1466 * BIOS call "INT 1AH Function 02H" to check whether a character is pending
1467 * Call with %ah = 0x2
1469 * If RT Clock can give correct values
1471 * %cl = minutes (BCD)
1472 * %dh = seconds (BCD)
1473 * %dl = daylight savings time (00h std, 01h daylight)
1474 * Carry flag = clear
1477 * (this indicates that the clock is updating, or
1478 * that it isn't running)
1480 FUNCTION(grub_getrtsecs)
1483 call prot_to_real /* enter real mode */
1494 DATA32 call real_to_prot
1505 * return the real time in ticks, of which there are about
1508 FUNCTION(grub_get_rtc)
1511 call prot_to_real /* enter real mode */
1514 /* %ax is already zero */
1517 DATA32 call real_to_prot
1529 * unsigned char grub_vga_set_mode (unsigned char mode)
1531 FUNCTION(grub_vga_set_mode)
1538 /* get current mode */
1544 /* set the new mode */
1549 DATA32 call real_to_prot
1559 * unsigned char *grub_vga_get_font (void)
1561 FUNCTION(grub_vga_get_font)
1572 DATA32 call real_to_prot
1585 * grub_vbe_bios_status_t grub_vbe_get_controller_info (struct grub_vbe_info_block *controller_info)
1587 * Register allocations for parameters:
1588 * %eax *controller_info
1590 FUNCTION(grub_vbe_bios_get_controller_info)
1595 movw %ax, %di /* Store *controller_info to %edx:%di. */
1598 mov %eax, %edx /* prot_to_real destroys %eax. */
1605 movw %dx, %es /* *controller_info is now on %es:%di. */
1609 movw %ax, %dx /* real_to_prot destroys %eax. */
1613 DATA32 call real_to_prot
1617 andl $0x0FFFF, %eax /* Return value in %eax. */
1625 * grub_vbe_status_t grub_vbe_bios_get_mode_info (grub_uint32_t mode,
1626 * struct grub_vbe_mode_info_block *mode_info)
1628 * Register allocations for parameters:
1632 FUNCTION(grub_vbe_bios_get_mode_info)
1636 movl %eax, %ecx /* Store mode number to %ecx. */
1638 movw %dx, %di /* Store *mode_info to %edx:%di. */
1647 movw %dx, %es /* *mode_info is now on %es:%di. */
1651 movw %ax, %dx /* real_to_prot destroys %eax. */
1655 DATA32 call real_to_prot
1659 andl $0x0FFFF, %eax /* Return value in %eax. */
1666 * grub_vbe_status_t grub_vbe_bios_set_mode (grub_uint32_t mode,
1667 * struct grub_vbe_crtc_info_block *crtc_info)
1669 * Register allocations for parameters:
1673 FUNCTION(grub_vbe_bios_set_mode)
1678 movl %eax, %ebx /* Store mode in %ebx. */
1680 movw %dx, %di /* Store *crtc_info to %edx:%di. */
1689 movw %dx, %es /* *crtc_info is now on %es:%di. */
1694 movw %ax, %dx /* real_to_prot destroys %eax. */
1698 DATA32 call real_to_prot
1702 andl $0xFFFF, %eax /* Return value in %eax. */
1710 * grub_vbe_status_t grub_vbe_bios_get_mode (grub_uint32_t *mode)
1712 * Register allocations for parameters:
1715 FUNCTION(grub_vbe_bios_get_mode)
1720 pushl %eax /* Push *mode to stack. */
1728 movw %ax, %dx /* real_to_prot destroys %eax. */
1730 DATA32 call real_to_prot
1733 popl %edi /* Pops *mode from stack to %edi. */
1738 andl $0xFFFF, %eax /* Return value in %eax. */
1747 * grub_vbe_status_t grub_vbe_bios_set_memory_window (grub_uint32_t window,
1748 * grub_uint32_t position);
1750 * Register allocations for parameters:
1754 FUNCTION(grub_vbe_bios_set_memory_window)
1764 andw $0x00ff, %bx /* BL = window, BH = 0, Set memory window. */
1767 movw %ax, %dx /* real_to_prot destroys %eax. */
1769 DATA32 call real_to_prot
1773 andl $0xFFFF, %eax /* Return value in %eax. */
1780 * grub_vbe_status_t grub_vbe_bios_get_memory_window (grub_uint32_t window,
1781 * grub_uint32_t *position);
1783 * Register allocations for parameters:
1787 FUNCTION(grub_vbe_bios_get_memory_window)
1791 pushl %edx /* Push *position to stack. */
1793 movl %eax, %ebx /* Store window in %ebx. */
1799 andw $0x00ff, %bx /* BL = window. */
1800 orw $0x0100, %bx /* BH = 1, Get memory window. */
1803 movw %ax, %bx /* real_to_prot destroys %eax. */
1805 DATA32 call real_to_prot
1808 popl %edi /* pops *position from stack to %edi. */
1810 movl %edx, (%edi) /* Return position to caller. */
1813 andl $0xFFFF, %eax /* Return value in %eax. */
1821 * grub_vbe_status_t grub_vbe_bios_set_scanline_length (grub_uint32_t length)
1823 * Register allocations for parameters:
1826 FUNCTION(grub_vbe_bios_set_scanline_length)
1831 movl %eax, %ecx /* Store length in %ecx. */
1837 movw $0x0002, %bx /* BL = 2, Set Scan Line in Bytes. */
1840 movw %ax, %dx /* real_to_prot destroys %eax. */
1842 DATA32 call real_to_prot
1846 andl $0xFFFF, %eax /* Return value in %eax. */
1854 * grub_vbe_status_t grub_vbe_bios_get_scanline_length (grub_uint32_t *length)
1856 * Register allocations for parameters:
1859 FUNCTION(grub_vbe_bios_get_scanline_length)
1863 pushl %edx /* Push *length to stack. */
1869 movw $0x0001, %bx /* BL = 1, Get Scan Line Length (in bytes). */
1872 movw %ax, %dx /* real_to_prot destroys %eax. */
1874 DATA32 call real_to_prot
1877 popl %edi /* Pops *length from stack to %edi. */
1879 movl %ebx, (%edi) /* Return length to caller. */
1882 andl $0xFFFF, %eax /* Return value in %eax. */
1890 * grub_vbe_status_t grub_vbe_bios_set_display_start (grub_uint32_t x,
1893 * Register allocations for parameters:
1897 FUNCTION(grub_vbe_bios_set_display_start)
1901 movl %eax, %ecx /* Store x in %ecx. */
1907 movw $0x0080, %bx /* BL = 80h, Set Display Start
1908 during Vertical Retrace. */
1911 movw %ax, %dx /* real_to_prot destroys %eax. */
1913 DATA32 call real_to_prot
1917 andl $0xFFFF, %eax /* Return value in %eax. */
1924 * grub_vbe_status_t grub_vbe_bios_get_display_start (grub_uint32_t *x,
1927 * Register allocations for parameters:
1931 FUNCTION(grub_vbe_bios_get_display_start)
1935 pushl %eax /* Push *x to stack. */
1936 pushl %edx /* Push *y to stack. */
1942 movw $0x0001, %bx /* BL = 1, Get Display Start. */
1945 movw %ax, %bx /* real_to_prot destroys %eax. */
1947 DATA32 call real_to_prot
1950 popl %edi /* Pops *y from stack to %edi. */
1952 movl %edx, (%edi) /* Return y-position to caller. */
1954 popl %edi /* Pops *x from stack to %edi. */
1956 movl %ecx, (%edi) /* Return x-position to caller. */
1959 andl $0xFFFF, %eax /* Return value in %eax. */
1967 * grub_vbe_status_t grub_vbe_bios_set_palette_data (grub_uint32_t color_count,
1968 * grub_uint32_t start_index,
1969 * struct grub_vbe_palette_data *palette_data)
1971 * Register allocations for parameters:
1974 * %ecx *palette_data
1976 FUNCTION(grub_vbe_bios_set_palette_data)
1981 movl %eax, %ebx /* Store color_count in %ebx. */
1983 movw %cx, %di /* Store *palette_data to %ecx:%di. */
1992 movw %cx, %es /* *palette_data is now on %es:%di. */
1993 movw %bx, %cx /* color_count is now on %cx. */
1996 xorw %bx, %bx /* BL = 0, Set Palette Data. */
1999 movw %ax, %dx /* real_to_prot destroys %eax. */
2003 DATA32 call real_to_prot
2007 andl $0xFFFF, %eax /* Return value in %eax. */