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)
100 /* to be filled by grub-mkimage */
103 * Leave some breathing room for the prefix.
106 . = EXT_C(start) + GRUB_KERNEL_MACHINE_DATA_END
109 * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself).
110 * This uses the a.out kludge to load raw binary to the area starting at 1MB,
111 * and relocates itself after loaded.
113 .p2align 2 /* force 4-byte alignment */
120 .long -0x1BADB002 - (1 << 16)
122 .long multiboot_header - _start + 0x100000 + 0x200
130 .long multiboot_entry - _start + 0x100000 + 0x200
134 /* obtain the boot device */
137 /* relocate the code */
138 movl $(GRUB_KERNEL_MACHINE_RAW_SIZE + 0x200), %ecx
139 addl EXT_C(grub_compressed_size) - _start + 0x100000 + 0x200, %ecx
141 movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %edi
145 /* jump to the real address */
146 movl $multiboot_trampoline, %eax
149 multiboot_trampoline:
150 /* fill the boot information */
157 movl %ebx, EXT_C(grub_install_dos_part)
162 movl %ebx, EXT_C(grub_install_bsd_part)
166 /* enter the usual booting */
170 /* the real mode code continues... */
172 cli /* we're not safe here! */
174 /* set up %ds, %ss, and %es */
180 /* set up the real mode/BIOS stack */
181 movl $GRUB_MEMORY_MACHINE_REAL_STACK, %ebp
184 sti /* we're safe again */
186 /* save boot and root drive references */
187 ADDR32 movb %dl, EXT_C(grub_boot_drive)
188 ADDR32 movb %dh, EXT_C(grub_root_drive)
190 /* reset disk system (%ah = 0) */
193 /* transition to protected mode */
194 DATA32 call real_to_prot
196 /* The ".code32" directive takes GAS out of 16-bit mode. */
200 call EXT_C(grub_gate_a20)
202 #if defined(ENABLE_LZO)
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
215 #elif defined(ENABLE_LZMA)
216 movl $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %edi
217 movl $(START_SYMBOL + GRUB_KERNEL_MACHINE_RAW_SIZE), %esi
220 movl EXT_C(grub_kernel_image_size), %ecx
221 addl EXT_C(grub_total_module_size), %ecx
222 subl $GRUB_KERNEL_MACHINE_RAW_SIZE, %ecx
224 leal (%edi, %ecx), %ebx
226 /* _LzmaDecodeA clears DF, so no need to run cld */
232 /* copy back the decompressed part (except the modules) */
233 subl EXT_C(grub_total_module_size), %ecx
238 /* copy modules before cleaning out the bss */
239 movl EXT_C(grub_total_module_size), %ecx
240 movl EXT_C(grub_kernel_image_size), %esi
242 addl $START_SYMBOL, %esi
244 movl $END_SYMBOL, %edi
252 /* clean out the bss */
253 movl $BSS_START_SYMBOL, %edi
255 /* compute the bss length */
256 movl $END_SYMBOL, %ecx
266 * Call the start of main body of C code.
268 call EXT_C(grub_main)
270 #include "../realmode.S"
273 * This is the area for all of the special variables.
276 .p2align 2 /* force 4-byte alignment */
278 VARIABLE(grub_boot_drive)
281 VARIABLE(grub_root_drive)
284 VARIABLE(grub_start_addr)
287 VARIABLE(grub_end_addr)
290 VARIABLE(grub_apm_bios_info)
291 .word 0 /* version */
294 .word 0 /* cseg_16 */
295 .word 0 /* dseg_16 */
296 .word 0 /* cseg_len */
297 .word 0 /* cseg_16_len */
298 .word 0 /* dseg_16_len */
300 .p2align 2 /* force 4-byte alignment */
303 * These next two routines, "real_to_prot" and "prot_to_real" are structured
304 * in a very specific way. Be very careful when changing them.
306 * NOTE: Use of either one messes up %eax and %ebp.
313 /* load the GDT register */
314 DATA32 ADDR32 lgdt %cs:gdtdesc
316 /* turn on protected mode */
318 orl $GRUB_MEMORY_MACHINE_CR0_PE_ON, %eax
321 /* jump to relocation, flush prefetch queue, and reload %cs */
322 DATA32 ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $protcseg
326 /* reload other segment registers */
327 movw $GRUB_MEMORY_MACHINE_PROT_MODE_DSEG, %ax
334 /* put the return address in a known safe location */
336 movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK
338 /* get protected mode stack */
343 /* get return address onto the right stack */
344 movl GRUB_MEMORY_MACHINE_REAL_STACK, %eax
350 /* return on the old (or initialized) stack! */
354 * grub_gate_a20(int on)
356 * Gate address-line 20 for high memory.
358 * This routine is probably overconservative in what it does, but so what?
360 * It also eats any keystrokes in the keyboard buffer. :-(
363 FUNCTION(grub_gate_a20)
366 gate_a20_test_current_state:
367 /* first of all, test if already in a good state */
368 call gate_a20_check_state
370 jnz gate_a20_try_bios
374 /* second, try a BIOS call */
385 DATA32 call real_to_prot
389 call gate_a20_check_state
391 jnz gate_a20_try_system_control_port_a
394 gate_a20_try_system_control_port_a:
396 * In macbook, the keyboard test would hang the machine, so we move
399 /* fourth, try the system control port A */
407 /* When turning off Gate A20, do not check the state strictly,
408 because a failure is not fatal usually, and Gate A20 is always
409 on some modern machines. */
412 call gate_a20_check_state
414 jnz gate_a20_try_keyboard_controller
417 gate_a20_flush_keyboard_buffer:
420 jnz gate_a20_flush_keyboard_buffer
430 gate_a20_try_keyboard_controller:
431 /* third, try the keyboard controller */
432 call gate_a20_flush_keyboard_buffer
446 call gate_a20_flush_keyboard_buffer
448 /* output a dummy command (USB keyboard hack) */
451 call gate_a20_flush_keyboard_buffer
453 call gate_a20_check_state
455 /* everything failed, so restart from the beginning */
456 jnz gate_a20_try_bios
459 gate_a20_check_state:
460 /* iterate the checking for a while */
473 /* compare the byte at 0x8000 with that at 0x108000 */
474 movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %ebx
476 /* save the original byte in CL */
478 /* store the value at 0x108000 in AL */
481 /* try to set one less value at 0x8000 */
489 /* obtain the value at 0x108000 in CH */
493 /* this result is 1 if A20 is on or 0 if it is off */
496 /* restore the original */
503 #if defined(ENABLE_LZO)
505 #elif defined(ENABLE_LZMA)
506 #include "lzma_decode.S"
510 * The code beyond this point is compressed. Assert that the uncompressed
511 * code fits GRUB_KERNEL_MACHINE_RAW_SIZE.
513 . = EXT_C(start) + GRUB_KERNEL_MACHINE_RAW_SIZE
516 * This call is special... it never returns... in fact it should simply
517 * hang at this point!
524 * This next part is sort of evil. It takes advantage of the
525 * byte ordering on the x86 to work in either 16-bit or 32-bit
526 * mode, so think about it before changing it.
529 FUNCTION(grub_hard_stop)
531 jmp EXT_C(grub_hard_stop)
537 * Stop the floppy drive from spinning, so that other software is
538 * jumped to with a known state.
540 FUNCTION(grub_stop_floppy)
554 /* Tell the BIOS a boot failure. If this does not work, reboot. */
562 * Reboot the system. At the moment, rely on BIOS.
564 FUNCTION(grub_reboot)
571 ljmp $0xFFFF, $0x0000
575 * grub_halt(int no_apm)
577 * Halt the system, using APM if possible. If NO_APM is true, don't use
578 * APM even if it is available.
592 jc EXT_C(grub_hard_stop)
593 /* don't check %bx for buggy BIOSes... */
595 /* disconnect APM first */
604 jc EXT_C(grub_hard_stop)
606 /* set APM protocol level - 1.1 or bust. (this covers APM 1.2 also) */
611 jc EXT_C(grub_hard_stop)
613 /* set the power state to off */
619 /* shouldn't reach here */
620 jmp EXT_C(grub_hard_stop)
625 * void grub_chainloader_real_boot (int drive, void *part_addr)
627 * This starts another boot loader.
630 FUNCTION(grub_chainloader_real_boot)
634 call EXT_C(grub_dl_unload_all)
636 /* Turn off Gate A20 */
638 call EXT_C(grub_gate_a20)
640 /* set up to pass boot drive */
643 /* ESI must point to a partition table entry */
648 ljmp $0, $GRUB_MEMORY_MACHINE_BOOT_LOADER_ADDR
651 #include "../loader.S"
654 * int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap)
656 * Call IBM/MS INT13 Extensions (int 13 %ah=AH) for DRIVE. DAP
657 * is passed for disk address packet. If an error occurs, return
658 * non-zero, otherwise zero.
661 FUNCTION(grub_biosdisk_rw_int13_extensions)
665 /* compute the address of disk_address_packet */
668 shrl $4, %ecx /* save the segment to cx */
672 /* enter real mode */
678 int $0x13 /* do the operation */
679 movb %ah, %dl /* save return value */
680 /* back to protected mode */
681 DATA32 call real_to_prot
684 movb %dl, %al /* return value in %eax */
692 * int grub_biosdisk_rw_standard (int ah, int drive, int coff, int hoff,
693 * int soff, int nsec, int segment)
695 * Call standard and old INT13 (int 13 %ah=AH) for DRIVE. Read/write
696 * NSEC sectors from COFF/HOFF/SOFF into SEGMENT. If an error occurs,
697 * return non-zero, otherwise zero.
700 FUNCTION(grub_biosdisk_rw_standard)
708 /* set up CHS information */
710 /* set %ch to low eight bits of cylinder */
712 /* set bits 6-7 of %cl to high two bits of cylinder */
714 /* set bits 0-5 of %cl to sector */
716 /* set %dh to head */
720 /* set %al to NSEC */
722 /* save %ax in %di */
724 /* save SEGMENT in %bx */
727 /* enter real mode */
733 movw $3, %si /* attempt at least three times */
737 int $0x13 /* do the operation */
738 jnc 2f /* check if successful */
740 movb %ah, %bl /* save return value */
741 /* if fail, reset the disk system */
751 /* back to protected mode */
752 DATA32 call real_to_prot
755 movb %bl, %al /* return value in %eax */
766 * int grub_biosdisk_check_int13_extensions (int drive)
768 * Check if LBA is supported for DRIVE. If it is supported, then return
769 * the major version of extensions, otherwise zero.
772 FUNCTION(grub_biosdisk_check_int13_extensions)
778 /* enter real mode */
784 int $0x13 /* do the operation */
786 /* check the result */
791 movb %ah, %bl /* save the major version into %bl */
793 /* check if AH=0x42 is supported */
800 /* back to protected mode */
801 DATA32 call real_to_prot
804 movb %bl, %al /* return value in %eax */
813 * int grub_biosdisk_get_cdinfo_int13_extensions (int drive, void *cdrp)
815 * Return the cdrom information of DRIVE in CDRP. If an error occurs,
816 * then return non-zero, otherwise zero.
819 FUNCTION(grub_biosdisk_get_cdinfo_int13_extensions)
824 * int grub_biosdisk_get_diskinfo_int13_extensions (int drive, void *drp)
826 * Return the geometry of DRIVE in a drive parameters, DRP. If an error
827 * occurs, then return non-zero, otherwise zero.
830 FUNCTION(grub_biosdisk_get_diskinfo_int13_extensions)
837 /* compute the address of drive parameters */
841 movw %dx, %bx /* save the segment into %bx */
844 /* enter real mode */
850 int $0x13 /* do the operation */
851 movb %ah, %bl /* save return value in %bl */
852 /* back to protected mode */
853 DATA32 call real_to_prot
856 movb %bl, %al /* return value in %eax */
866 * int grub_biosdisk_get_diskinfo_standard (int drive,
867 * unsigned long *cylinders,
868 * unsigned long *heads,
869 * unsigned long *sectors)
871 * Return the geometry of DRIVE in CYLINDERS, HEADS and SECTORS. If an
872 * error occurs, then return non-zero, otherwise zero.
875 FUNCTION(grub_biosdisk_get_diskinfo_standard)
884 /* SECTORS is on the stack */
888 /* enter real mode */
893 int $0x13 /* do the operation */
894 /* check if successful */
897 /* bogus BIOSes may not return an error number */
898 testb $0x3f, %cl /* 0 sectors means no disk */
899 jnz 1f /* if non-zero, then succeed */
900 /* XXX 0x60 is one of the unused error numbers */
903 movb %ah, %bl /* save return value in %bl */
904 /* back to protected mode */
905 DATA32 call real_to_prot
911 incl %eax /* the number of heads is counted from zero */
918 shrb $6, %ah /* the number of cylinders is counted from zero */
923 movl 0x10(%esp), %edi
929 movb %bl, %al /* return value in %eax */
939 * int grub_biosdisk_get_num_floppies (void)
941 FUNCTION(grub_biosdisk_get_num_floppies)
948 /* reset the disk system first */
953 /* call GET DISK TYPE */
959 /* check if this drive exists */
967 DATA32 call real_to_prot
977 * grub_get_memsize(i) : return the memory size in KB. i == 0 for conventional
978 * memory, i == 1 for extended memory
979 * BIOS call "INT 12H" to get conventional memory size
980 * BIOS call "INT 15H, AH=88H" to get extended memory size
981 * Both have the return value in AX.
985 FUNCTION(grub_get_memsize)
990 call prot_to_real /* enter real mode */
1006 DATA32 call real_to_prot
1017 * grub_get_eisa_mmap() : return packed EISA memory map, lower 16 bits is
1018 * memory between 1M and 16M in 1K parts, upper 16 bits is
1019 * memory above 16M in 64K parts. If error, return zero.
1020 * BIOS call "INT 15H, AH=E801H" to get EISA memory map,
1021 * AX = memory between 1M and 16M in 1K parts.
1022 * BX = memory above 16M in 64K parts.
1026 FUNCTION(grub_get_eisa_mmap)
1030 call prot_to_real /* enter real mode */
1039 DATA32 call real_to_prot
1054 * grub_get_mmap_entry(addr, cont) : address and old continuation value (zero to
1055 * start), for the Query System Address Map BIOS call.
1057 * Sets the first 4-byte int value of "addr" to the size returned by
1058 * the call. If the call fails, sets it to zero.
1060 * Returns: new (non-zero) continuation value, 0 if done.
1063 FUNCTION(grub_get_mmap_entry)
1072 /* place address (+4) in ES:DI */
1079 /* set continuation value */
1082 /* set default maximum buffer size */
1085 /* set EDX to 'SMAP' */
1086 movl $0x534d4150, %edx
1088 call prot_to_real /* enter real mode */
1097 cmpl $0x534d4150, %eax
1112 DATA32 call real_to_prot
1115 /* write length of buffer (zero if error) into ADDR */
1119 /* set return value to continuation */
1130 * void grub_console_real_putchar (int c)
1132 * Put the character C on the console. Because GRUB wants to write a
1133 * character with an attribute, this implementation is a bit tricky.
1134 * If C is a control character (CR, LF, BEL, BS), use INT 10, AH = 0Eh
1135 * (TELETYPE OUTPUT). Otherwise, save the original position, put a space,
1136 * save the current position, restore the original position, write the
1137 * character and the attribute, and restore the current position.
1139 * The reason why this is so complicated is that there is no easy way to
1140 * get the height of the screen, and the TELETYPE OUTPUT BIOS call doesn't
1141 * support setting a background attribute.
1143 FUNCTION(grub_console_real_putchar)
1146 movb EXT_C(grub_console_cur_color), %bl
1153 /* use teletype output if control character */
1163 /* save the character and the attribute on the stack */
1167 /* get the current position */
1171 /* check the column with the width */
1175 /* print CR and LF, if next write will exceed the width */
1181 /* get the current position */
1186 /* restore the character and the attribute */
1190 /* write the character with the attribute */
1195 /* move the cursor forward */
1206 3: DATA32 call real_to_prot
1214 * int grub_console_getkey (void)
1215 * BIOS call "INT 16H Function 00H" to read character from keyboard
1216 * Call with %ah = 0x0
1217 * Return: %ah = keyboard scan code
1218 * %al = ASCII character
1221 /* this table is used in translate_keycode below */
1223 .word GRUB_CONSOLE_KEY_LEFT, GRUB_TERM_LEFT
1224 .word GRUB_CONSOLE_KEY_RIGHT, GRUB_TERM_RIGHT
1225 .word GRUB_CONSOLE_KEY_UP, GRUB_TERM_UP
1226 .word GRUB_CONSOLE_KEY_DOWN, GRUB_TERM_DOWN
1227 .word GRUB_CONSOLE_KEY_HOME, GRUB_TERM_HOME
1228 .word GRUB_CONSOLE_KEY_END, GRUB_TERM_END
1229 .word GRUB_CONSOLE_KEY_DC, GRUB_TERM_DC
1230 .word GRUB_CONSOLE_KEY_BACKSPACE, GRUB_TERM_BACKSPACE
1231 .word GRUB_CONSOLE_KEY_PPAGE, GRUB_TERM_PPAGE
1232 .word GRUB_CONSOLE_KEY_NPAGE, GRUB_TERM_NPAGE
1236 * translate_keycode translates the key code %dx to an ascii code.
1244 movw $ABS(translation_table), %si
1247 /* check if this is the end */
1250 /* load the ascii code into %ax */
1253 /* check if this matches the key code */
1256 /* translate %dx, if successful */
1265 FUNCTION(grub_console_getkey)
1272 * Due to a bug in apple's bootcamp implementation, INT 16/AH = 0 would
1273 * cause the machine to hang at the second keystroke. However, we can
1274 * work around this problem by ensuring the presence of keystroke with
1275 * INT 16/AH = 1 before calling INT 16/AH = 0.
1290 movw %ax, %dx /* real_to_prot uses %eax */
1291 call translate_keycode
1293 DATA32 call real_to_prot
1303 * int grub_console_checkkey (void)
1304 * if there is a character pending, return it; otherwise return -1
1305 * BIOS call "INT 16H Function 01H" to check whether a character is pending
1306 * Call with %ah = 0x1
1308 * If key waiting to be input:
1309 * %ah = keyboard scan code
1310 * %al = ASCII character
1315 FUNCTION(grub_console_checkkey)
1319 call prot_to_real /* enter real mode */
1334 DATA32 call real_to_prot
1344 * grub_uint16_t grub_console_getxy (void)
1345 * BIOS call "INT 10H Function 03h" to get cursor position
1346 * Call with %ah = 0x03
1348 * Returns %ch = starting scan line
1349 * %cl = ending scan line
1350 * %dh = row (0 is top)
1351 * %dl = column (0 is left)
1355 FUNCTION(grub_console_getxy)
1357 pushl %ebx /* save EBX */
1362 xorb %bh, %bh /* set page to 0 */
1364 int $0x10 /* get cursor position */
1366 DATA32 call real_to_prot
1378 * void grub_console_gotoxy(grub_uint8_t x, grub_uint8_t y)
1379 * BIOS call "INT 10H Function 02h" to set cursor position
1380 * Call with %ah = 0x02
1382 * %dh = row (0 is top)
1383 * %dl = column (0 is left)
1387 FUNCTION(grub_console_gotoxy)
1389 pushl %ebx /* save EBX */
1391 movb %dl, %dh /* %dh = y */
1392 movb %al, %dl /* %dl = x */
1397 xorb %bh, %bh /* set page to 0 */
1399 int $0x10 /* set cursor position */
1401 DATA32 call real_to_prot
1410 * void grub_console_cls (void)
1411 * BIOS call "INT 10H Function 09h" to write character and attribute
1412 * Call with %ah = 0x09
1414 * %bh = (page number)
1416 * %cx = (number of times)
1419 FUNCTION(grub_console_cls)
1421 pushl %ebx /* save EBX */
1426 /* move the cursor to the beginning */
1432 /* write spaces to the entire screen */
1435 movw $(80 * 25), %cx
1438 /* move back the cursor */
1442 DATA32 call real_to_prot
1451 * void grub_console_setcursor (int on)
1452 * BIOS call "INT 10H Function 01h" to set cursor type
1453 * Call with %ah = 0x01
1454 * %ch = cursor starting scanline
1455 * %cl = cursor ending scanline
1458 console_cursor_state:
1460 console_cursor_shape:
1463 FUNCTION(grub_console_setcursor)
1470 /* check if the standard cursor shape has already been saved */
1471 movw console_cursor_shape, %ax
1482 DATA32 call real_to_prot
1485 movw %cx, console_cursor_shape
1487 /* set %cx to the designated cursor shape */
1492 movw console_cursor_shape, %cx
1500 DATA32 call real_to_prot
1509 * if a seconds value can be read, read it and return it (BCD),
1510 * otherwise return 0xFF
1511 * BIOS call "INT 1AH Function 02H" to check whether a character is pending
1512 * Call with %ah = 0x2
1514 * If RT Clock can give correct values
1516 * %cl = minutes (BCD)
1517 * %dh = seconds (BCD)
1518 * %dl = daylight savings time (00h std, 01h daylight)
1519 * Carry flag = clear
1522 * (this indicates that the clock is updating, or
1523 * that it isn't running)
1525 FUNCTION(grub_getrtsecs)
1528 call prot_to_real /* enter real mode */
1539 DATA32 call real_to_prot
1550 * return the real time in ticks, of which there are about
1553 FUNCTION(grub_get_rtc)
1556 call prot_to_real /* enter real mode */
1559 /* %ax is already zero */
1562 DATA32 call real_to_prot
1574 * unsigned char grub_vga_set_mode (unsigned char mode)
1576 FUNCTION(grub_vga_set_mode)
1583 /* get current mode */
1589 /* set the new mode */
1594 DATA32 call real_to_prot
1604 * unsigned char *grub_vga_get_font (void)
1606 FUNCTION(grub_vga_get_font)
1617 DATA32 call real_to_prot
1630 * grub_vbe_bios_status_t grub_vbe_get_controller_info (struct grub_vbe_info_block *controller_info)
1632 * Register allocations for parameters:
1633 * %eax *controller_info
1635 FUNCTION(grub_vbe_bios_get_controller_info)
1640 movw %ax, %di /* Store *controller_info to %edx:%di. */
1643 mov %eax, %edx /* prot_to_real destroys %eax. */
1650 movw %dx, %es /* *controller_info is now on %es:%di. */
1654 movw %ax, %dx /* real_to_prot destroys %eax. */
1658 DATA32 call real_to_prot
1662 andl $0x0FFFF, %eax /* Return value in %eax. */
1670 * grub_vbe_status_t grub_vbe_bios_get_mode_info (grub_uint32_t mode,
1671 * struct grub_vbe_mode_info_block *mode_info)
1673 * Register allocations for parameters:
1677 FUNCTION(grub_vbe_bios_get_mode_info)
1681 movl %eax, %ecx /* Store mode number to %ecx. */
1683 movw %dx, %di /* Store *mode_info to %edx:%di. */
1692 movw %dx, %es /* *mode_info is now on %es:%di. */
1696 movw %ax, %dx /* real_to_prot destroys %eax. */
1700 DATA32 call real_to_prot
1704 andl $0x0FFFF, %eax /* Return value in %eax. */
1711 * grub_vbe_status_t grub_vbe_bios_set_mode (grub_uint32_t mode,
1712 * struct grub_vbe_crtc_info_block *crtc_info)
1714 * Register allocations for parameters:
1718 FUNCTION(grub_vbe_bios_set_mode)
1723 movl %eax, %ebx /* Store mode in %ebx. */
1725 movw %dx, %di /* Store *crtc_info to %edx:%di. */
1734 movw %dx, %es /* *crtc_info is now on %es:%di. */
1739 movw %ax, %dx /* real_to_prot destroys %eax. */
1743 DATA32 call real_to_prot
1747 andl $0xFFFF, %eax /* Return value in %eax. */
1755 * grub_vbe_status_t grub_vbe_bios_get_mode (grub_uint32_t *mode)
1757 * Register allocations for parameters:
1760 FUNCTION(grub_vbe_bios_get_mode)
1765 pushl %eax /* Push *mode to stack. */
1773 movw %ax, %dx /* real_to_prot destroys %eax. */
1775 DATA32 call real_to_prot
1778 popl %edi /* Pops *mode from stack to %edi. */
1783 andl $0xFFFF, %eax /* Return value in %eax. */
1792 * grub_vbe_status_t grub_vbe_bios_set_memory_window (grub_uint32_t window,
1793 * grub_uint32_t position);
1795 * Register allocations for parameters:
1799 FUNCTION(grub_vbe_bios_set_memory_window)
1809 andw $0x00ff, %bx /* BL = window, BH = 0, Set memory window. */
1812 movw %ax, %dx /* real_to_prot destroys %eax. */
1814 DATA32 call real_to_prot
1818 andl $0xFFFF, %eax /* Return value in %eax. */
1825 * grub_vbe_status_t grub_vbe_bios_get_memory_window (grub_uint32_t window,
1826 * grub_uint32_t *position);
1828 * Register allocations for parameters:
1832 FUNCTION(grub_vbe_bios_get_memory_window)
1836 pushl %edx /* Push *position to stack. */
1838 movl %eax, %ebx /* Store window in %ebx. */
1844 andw $0x00ff, %bx /* BL = window. */
1845 orw $0x0100, %bx /* BH = 1, Get memory window. */
1848 movw %ax, %bx /* real_to_prot destroys %eax. */
1850 DATA32 call real_to_prot
1853 popl %edi /* pops *position from stack to %edi. */
1855 movl %edx, (%edi) /* Return position to caller. */
1858 andl $0xFFFF, %eax /* Return value in %eax. */
1866 * grub_vbe_status_t grub_vbe_bios_set_scanline_length (grub_uint32_t length)
1868 * Register allocations for parameters:
1871 FUNCTION(grub_vbe_bios_set_scanline_length)
1876 movl %eax, %ecx /* Store length in %ecx. */
1882 movw $0x0002, %bx /* BL = 2, Set Scan Line in Bytes. */
1885 movw %ax, %dx /* real_to_prot destroys %eax. */
1887 DATA32 call real_to_prot
1891 andl $0xFFFF, %eax /* Return value in %eax. */
1899 * grub_vbe_status_t grub_vbe_bios_get_scanline_length (grub_uint32_t *length)
1901 * Register allocations for parameters:
1904 FUNCTION(grub_vbe_bios_get_scanline_length)
1908 pushl %edx /* Push *length to stack. */
1914 movw $0x0001, %bx /* BL = 1, Get Scan Line Length (in bytes). */
1917 movw %ax, %dx /* real_to_prot destroys %eax. */
1919 DATA32 call real_to_prot
1922 popl %edi /* Pops *length from stack to %edi. */
1924 movl %ebx, (%edi) /* Return length to caller. */
1927 andl $0xFFFF, %eax /* Return value in %eax. */
1935 * grub_vbe_status_t grub_vbe_bios_set_display_start (grub_uint32_t x,
1938 * Register allocations for parameters:
1942 FUNCTION(grub_vbe_bios_set_display_start)
1946 movl %eax, %ecx /* Store x in %ecx. */
1952 movw $0x0080, %bx /* BL = 80h, Set Display Start
1953 during Vertical Retrace. */
1956 movw %ax, %dx /* real_to_prot destroys %eax. */
1958 DATA32 call real_to_prot
1962 andl $0xFFFF, %eax /* Return value in %eax. */
1969 * grub_vbe_status_t grub_vbe_bios_get_display_start (grub_uint32_t *x,
1972 * Register allocations for parameters:
1976 FUNCTION(grub_vbe_bios_get_display_start)
1980 pushl %eax /* Push *x to stack. */
1981 pushl %edx /* Push *y to stack. */
1987 movw $0x0001, %bx /* BL = 1, Get Display Start. */
1990 movw %ax, %bx /* real_to_prot destroys %eax. */
1992 DATA32 call real_to_prot
1995 popl %edi /* Pops *y from stack to %edi. */
1997 movl %edx, (%edi) /* Return y-position to caller. */
1999 popl %edi /* Pops *x from stack to %edi. */
2001 movl %ecx, (%edi) /* Return x-position to caller. */
2004 andl $0xFFFF, %eax /* Return value in %eax. */
2012 * grub_vbe_status_t grub_vbe_bios_set_palette_data (grub_uint32_t color_count,
2013 * grub_uint32_t start_index,
2014 * struct grub_vbe_palette_data *palette_data)
2016 * Register allocations for parameters:
2019 * %ecx *palette_data
2021 FUNCTION(grub_vbe_bios_set_palette_data)
2026 movl %eax, %ebx /* Store color_count in %ebx. */
2028 movw %cx, %di /* Store *palette_data to %ecx:%di. */
2037 movw %cx, %es /* *palette_data is now on %es:%di. */
2038 movw %bx, %cx /* color_count is now on %cx. */
2041 xorw %bx, %bx /* BL = 0, Set Palette Data. */
2044 movw %ax, %dx /* real_to_prot destroys %eax. */
2048 DATA32 call real_to_prot
2052 andl $0xFFFF, %eax /* Return value in %eax. */
2064 * struct grub_pxenv *grub_pxe_scan (void);
2066 FUNCTION(grub_pxe_scan)
2082 cmpl $0x4E455850, %es:(%bx) /* PXEN(V+) */
2084 cmpw $0x201, %es:6(%bx) /* API version */
2086 lesw %es:0x28(%bx), %bx /* !PXE structure */
2087 cmpl $0x45585021, %es:(%bx) /* !PXE */
2098 DATA32 call real_to_prot
2102 leal (%eax, %ecx, 4), %ecx
2103 leal (%ebx, %ecx, 4), %eax /* eax = ecx * 16 + ebx */
2108 movl 0x10(%eax), %ecx
2109 movl %ecx, pxe_rm_entry
2118 * int grub_pxe_call (int func, void* data);
2120 FUNCTION(grub_pxe_call)
2133 movl pxe_rm_entry, %ebx
2147 DATA32 call real_to_prot