2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1999,2000,2001,2002,2003,2005 Free Software Foundation, Inc.
5 * This program 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 2 of the License, or
8 * (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Note: These functions defined in this file may be called from C.
23 * Be careful of that you must not modify some registers. Quote
24 * from gcc-2.95.2/gcc/config/i386/i386.h:
26 1 for registers not available across function calls.
27 These must include the FIXED_REGISTERS and also any
28 registers that can be used without being saved.
29 The latter must include the registers where values are returned
30 and the register where structure-value addresses are passed.
31 Aside from that, you can include as many other registers as you like.
33 ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7,arg
34 { 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
38 * Note: GRUB is compiled with the options -mrtd and -mregparm=3.
39 * So the first three arguments are passed in %eax, %edx, and %ecx,
40 * respectively, and if a function has a fixed number of arguments
41 * and the number if greater than three, the function must return
42 * with "ret $N" where N is ((the number of arguments) - 3) * 4.
46 #include <grub/symbol.h>
47 #include <grub/boot.h>
48 #include <grub/machine/boot.h>
49 #include <grub/machine/memory.h>
50 #include <grub/machine/console.h>
51 #include <grub/machine/linux.h>
52 #include <grub/machine/kernel.h>
53 #include <grub/machine/multiboot.h>
55 #define ABS(x) ((x) - EXT_C(start) + GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200)
61 /* Tell GAS to generate 16-bit instructions so that this code works
69 * Guarantee that "main" is loaded at 0x0:0x8200.
71 ljmp $0, $ABS(codestart)
74 * Compatibility version number
76 * These MUST be at byte offset 6 and 7 of the executable
79 . = EXT_C(start) + 0x6
80 .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR
83 * This is a special data area 8 bytes from the beginning.
86 . = EXT_C(start) + 0x8
88 VARIABLE(grub_total_module_size)
90 VARIABLE(grub_kernel_image_size)
92 VARIABLE(grub_compressed_size)
94 VARIABLE(grub_install_dos_part)
96 VARIABLE(grub_install_bsd_part)
102 * Leave some breathing room for the prefix.
105 . = EXT_C(start) + 0x50
108 * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself).
109 * This uses the a.out kludge to load raw binary to the area starting at 1MB,
110 * and relocates itself after loaded.
118 .long -0x1BADB002 - (1 << 16)
120 .long multiboot_header - _start + 0x100000 + 0x200
128 .long multiboot_entry - _start + 0x100000 + 0x200
132 /* obtain the boot device */
135 /* relocate the code */
136 movl $(GRUB_KERNEL_MACHINE_RAW_SIZE + 0x200), %ecx
137 addl EXT_C(grub_compressed_size) - _start + 0x100000 + 0x200, %ecx
139 movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %edi
143 /* jump to the real address */
144 movl $multiboot_trampoline, %eax
147 multiboot_trampoline:
148 /* fill the boot information */
155 movl %ebx, EXT_C(grub_install_dos_part)
160 movl %ebx, EXT_C(grub_install_bsd_part)
163 /* enter the usual booting */
167 /* the real mode code continues... */
169 cli /* we're not safe here! */
171 /* set up %ds, %ss, and %es */
177 /* set up the real mode/BIOS stack */
178 movl $GRUB_MEMORY_MACHINE_REAL_STACK, %ebp
181 sti /* we're safe again */
183 /* save boot drive reference */
184 ADDR32 movb %dl, EXT_C(grub_boot_drive)
186 /* reset disk system (%ah = 0) */
189 /* transition to protected mode */
190 DATA32 call real_to_prot
192 /* The ".code32" directive takes GAS out of 16-bit mode. */
196 call EXT_C(grub_gate_a20)
198 /* decompress the compressed part and put the result at 1MB */
200 movl $(START_SYMBOL + GRUB_KERNEL_MACHINE_RAW_SIZE), %edi
203 pushl EXT_C(grub_compressed_size)
205 call lzo1x_decompress
208 /* copy back the decompressed part */
214 /* copy modules before cleaning out the bss */
215 movl EXT_C(grub_total_module_size), %ecx
216 movl EXT_C(grub_kernel_image_size), %esi
218 addl $START_SYMBOL, %esi
220 movl $END_SYMBOL, %edi
227 /* clean out the bss */
228 movl $BSS_START_SYMBOL, %edi
230 /* compute the bss length */
231 movl $END_SYMBOL, %ecx
241 * Call the start of main body of C code.
243 call EXT_C(grub_main)
247 * This is the area for all of the special variables.
250 .p2align 2 /* force 4-byte alignment */
253 .long GRUB_MEMORY_MACHINE_PROT_STACK
255 VARIABLE(grub_boot_drive)
258 VARIABLE(grub_start_addr)
261 VARIABLE(grub_end_addr)
264 VARIABLE(grub_apm_bios_info)
265 .word 0 /* version */
268 .word 0 /* cseg_16 */
269 .word 0 /* dseg_16 */
270 .word 0 /* cseg_len */
271 .word 0 /* cseg_16_len */
272 .word 0 /* dseg_16_len */
275 * This is the Global Descriptor Table
277 * An entry, a "Segment Descriptor", looks like this:
280 * ------------------------------------------------------------
281 * | | |B| |A| | | |1|0|E|W|A| |
282 * | BASE 31..24 |G|/|L|V| LIMIT |P|DPL| TYPE | BASE 23:16 | 4
283 * | | |D| |L| 19..16| | |1|1|C|R|A| |
284 * ------------------------------------------------------------
286 * | BASE 15..0 | LIMIT 15..0 | 0
288 * ------------------------------------------------------------
290 * Note the ordering of the data items is reversed from the above
294 .p2align 2 /* force 4-byte alignment */
299 /* -- code segment --
300 * base = 0x00000000, limit = 0xFFFFF (4 KiB Granularity), present
301 * type = 32bit code execute/read, DPL = 0
304 .byte 0, 0x9A, 0xCF, 0
306 /* -- data segment --
307 * base = 0x00000000, limit 0xFFFFF (4 KiB Granularity), present
308 * type = 32 bit data read/write, DPL = 0
311 .byte 0, 0x92, 0xCF, 0
313 /* -- 16 bit real mode CS --
314 * base = 0x00000000, limit 0x0FFFF (1 B Granularity), present
315 * type = 16 bit code execute/read only/conforming, DPL = 0
320 /* -- 16 bit real mode DS --
321 * base = 0x00000000, limit 0x0FFFF (1 B Granularity), present
322 * type = 16 bit data read/write, DPL = 0
328 /* this is the GDT descriptor */
330 .word 0x27 /* limit */
335 * These next two routines, "real_to_prot" and "prot_to_real" are structured
336 * in a very specific way. Be very careful when changing them.
338 * NOTE: Use of either one messes up %eax and %ebp.
345 /* load the GDT register */
346 DATA32 ADDR32 lgdt gdtdesc
348 /* turn on protected mode */
350 orl $GRUB_MEMORY_MACHINE_CR0_PE_ON, %eax
353 /* jump to relocation, flush prefetch queue, and reload %cs */
354 DATA32 ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $protcseg
358 /* reload other segment registers */
359 movw $GRUB_MEMORY_MACHINE_PROT_MODE_DSEG, %ax
366 /* put the return address in a known safe location */
368 movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK
370 /* get protected mode stack */
375 /* get return address onto the right stack */
376 movl GRUB_MEMORY_MACHINE_REAL_STACK, %eax
382 /* return on the old (or initialized) stack! */
387 /* just in case, set GDT */
390 /* save the protected mode stack */
394 /* get the return address */
396 movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK
398 /* set up new stack */
399 movl $GRUB_MEMORY_MACHINE_REAL_STACK, %eax
403 /* set up segment limits */
404 movw $GRUB_MEMORY_MACHINE_PSEUDO_REAL_DSEG, %ax
411 /* this might be an extra step */
412 /* jump to a 16 bit segment */
413 ljmp $GRUB_MEMORY_MACHINE_PSEUDO_REAL_CSEG, $tmpcseg
418 /* clear the PE bit of CR0 */
420 andl $(~GRUB_MEMORY_MACHINE_CR0_PE_ON), %eax
423 /* flush prefetch queue, reload %cs */
424 DATA32 ljmp $0, $realcseg
427 /* we are in real mode now
428 * set up the real mode segment registers : DS, SS, ES
439 /* restore interrupts */
442 /* return on new stack! */
449 * grub_gate_a20(int on)
451 * Gate address-line 20 for high memory.
453 * This routine is probably overconservative in what it does, but so what?
455 * It also eats any keystrokes in the keyboard buffer. :-(
458 FUNCTION(grub_gate_a20)
461 gate_a20_test_current_state:
462 /* first of all, test if already in a good state */
463 call gate_a20_check_state
465 jnz gate_a20_try_bios
469 /* second, try a BIOS call */
480 DATA32 call real_to_prot
484 call gate_a20_check_state
486 jnz gate_a20_try_keyboard_controller
489 gate_a20_flush_keyboard_buffer:
492 jnz gate_a20_flush_keyboard_buffer
502 gate_a20_try_keyboard_controller:
503 /* third, try the keyboard controller */
504 call gate_a20_flush_keyboard_buffer
518 call gate_a20_flush_keyboard_buffer
520 /* output a dummy command (USB keyboard hack) */
523 call gate_a20_flush_keyboard_buffer
525 call gate_a20_check_state
527 jnz gate_a20_try_system_control_port_a
530 gate_a20_try_system_control_port_a:
531 /* fourth, try the system control port A */
539 /* When turning off Gate A20, do not check the state strictly,
540 because a failure is not fatal usually, and Gate A20 is always
541 on some modern machines. */
544 call gate_a20_check_state
546 /* everything failed, so restart from the beginning */
547 jnz gate_a20_try_bios
550 gate_a20_check_state:
551 /* iterate the checking for a while */
564 /* compare the byte at 0x8000 with that at 0x108000 */
565 movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %ebx
567 /* save the original byte in CL */
569 /* store the value at 0x108000 in AL */
572 /* try to set one less value at 0x8000 */
580 /* obtain the value at 0x108000 in CH */
584 /* this result is 1 if A20 is on or 0 if it is off */
587 /* restore the original */
598 * This call is special... it never returns... in fact it should simply
599 * hang at this point!
606 * This next part is sort of evil. It takes advantage of the
607 * byte ordering on the x86 to work in either 16-bit or 32-bit
608 * mode, so think about it before changing it.
611 FUNCTION(grub_hard_stop)
613 jmp EXT_C(grub_hard_stop)
619 * Stop the floppy drive from spinning, so that other software is
620 * jumped to with a known state.
622 FUNCTION(grub_stop_floppy)
631 * Reboot the system. At the moment, rely on BIOS.
633 FUNCTION(grub_reboot)
639 ljmp $0xFFFF, $0x0000
643 * grub_halt(int no_apm)
645 * Halt the system, using APM if possible. If NO_APM is true, don't use
646 * APM even if it is available.
660 jc EXT_C(grub_hard_stop)
661 /* don't check %bx for buggy BIOSes... */
663 /* disconnect APM first */
672 jc EXT_C(grub_hard_stop)
674 /* set APM protocol level - 1.1 or bust. (this covers APM 1.2 also) */
679 jc EXT_C(grub_hard_stop)
681 /* set the power state to off */
687 /* shouldn't reach here */
688 jmp EXT_C(grub_hard_stop)
693 * void grub_chainloader_real_boot (int drive, void *part_addr)
695 * This starts another boot loader.
698 FUNCTION(grub_chainloader_real_boot)
702 call EXT_C(grub_dl_unload_all)
704 /* set up to pass boot drive */
707 /* ESI must point to a partition table entry */
710 /* Turn off Gate A20 */
712 call EXT_C(grub_gate_a20)
716 ljmp $0, $GRUB_MEMORY_MACHINE_BOOT_LOADER_ADDR
721 * void grub_linux_boot_zimage (void)
723 VARIABLE(grub_linux_prot_size)
725 VARIABLE(grub_linux_tmp_addr)
727 VARIABLE(grub_linux_real_addr)
730 FUNCTION(grub_linux_boot_zimage)
731 /* copy the kernel */
732 movl EXT_C(grub_linux_prot_size), %ecx
735 movl $GRUB_LINUX_BZIMAGE_ADDR, %esi
736 movl $GRUB_LINUX_ZIMAGE_ADDR, %edi
741 FUNCTION(grub_linux_boot_bzimage)
742 call EXT_C(grub_dl_unload_all)
744 movl EXT_C(grub_linux_real_addr), %ebx
746 /* copy the real mode code */
747 movl EXT_C(grub_linux_tmp_addr), %esi
749 movl $GRUB_LINUX_SETUP_MOVE_SIZE, %ecx
754 /* change %ebx to the segment address */
758 movw %ax, linux_setup_seg
760 /* XXX new stack pointer in safe area for calling functions */
762 call EXT_C(grub_stop_floppy)
764 /* final setup for linux boot */
770 movw $GRUB_LINUX_SETUP_STACK, %sp
786 * This starts the multiboot kernel.
789 FUNCTION(grub_multiboot_real_boot)
790 /* Push the entry address on the stack. */
792 /* Move the address of the multiboot information structure to ebx. */
795 /* Unload all modules and stop the floppy driver. */
796 call EXT_C(grub_dl_unload_all)
797 call EXT_C(grub_stop_floppy)
799 /* Interrupts should be disabled. */
802 /* Move the magic value into eax and jump to the kernel. */
803 movl $GRUB_MB_MAGIC2,%eax
809 * int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap)
811 * Call IBM/MS INT13 Extensions (int 13 %ah=AH) for DRIVE. DAP
812 * is passed for disk address packet. If an error occurs, return
813 * non-zero, otherwise zero.
816 FUNCTION(grub_biosdisk_rw_int13_extensions)
820 /* compute the address of disk_address_packet */
823 shrl $4, %ecx /* save the segment to cx */
827 /* enter real mode */
833 int $0x13 /* do the operation */
834 movb %ah, %dl /* save return value */
835 /* clear the data segment */
838 /* back to protected mode */
839 DATA32 call real_to_prot
842 movb %dl, %al /* return value in %eax */
850 * int grub_biosdisk_rw_standard (int ah, int drive, int coff, int hoff,
851 * int soff, int nsec, int segment)
853 * Call standard and old INT13 (int 13 %ah=AH) for DRIVE. Read/write
854 * NSEC sectors from COFF/HOFF/SOFF into SEGMENT. If an error occurs,
855 * return non-zero, otherwise zero.
858 FUNCTION(grub_biosdisk_rw_standard)
866 /* set up CHS information */
868 /* set %ch to low eight bits of cylinder */
870 /* set bits 6-7 of %cl to high two bits of cylinder */
872 /* set bits 0-5 of %cl to sector */
874 /* set %dh to head */
878 /* set %al to NSEC */
880 /* save %ax in %di */
882 /* save SEGMENT in %bx */
885 /* enter real mode */
891 movw $3, %si /* attempt at least three times */
895 int $0x13 /* do the operation */
896 jnc 2f /* check if successful */
898 movb %ah, %bl /* save return value */
899 /* if fail, reset the disk system */
909 /* back to protected mode */
910 DATA32 call real_to_prot
913 movb %bl, %al /* return value in %eax */
924 * int grub_biosdisk_check_int13_extensions (int drive)
926 * Check if LBA is supported for DRIVE. If it is supported, then return
927 * the major version of extensions, otherwise zero.
930 FUNCTION(grub_biosdisk_check_int13_extensions)
936 /* enter real mode */
942 int $0x13 /* do the operation */
944 /* check the result */
949 movb %ah, %bl /* save the major version into %bl */
951 /* check if AH=0x42 is supported */
958 /* back to protected mode */
959 DATA32 call real_to_prot
962 movb %bl, %al /* return value in %eax */
971 * int grub_biosdisk_get_diskinfo_int13_extensions (int drive, void *drp)
973 * Return the geometry of DRIVE in a drive parameters, DRP. If an error
974 * occurs, then return non-zero, otherwise zero.
977 FUNCTION(grub_biosdisk_get_diskinfo_int13_extensions)
982 /* compute the address of drive parameters */
986 movw %dx, %bx /* save the segment into %bx */
989 /* enter real mode */
995 int $0x13 /* do the operation */
996 movb %ah, %bl /* save return value in %bl */
997 /* clear the data segment */
1000 /* back to protected mode */
1001 DATA32 call real_to_prot
1004 movb %bl, %al /* return value in %eax */
1014 * int grub_biosdisk_get_diskinfo_standard (int drive,
1015 * unsigned long *cylinders,
1016 * unsigned long *heads,
1017 * unsigned long *sectors)
1019 * Return the geometry of DRIVE in CYLINDERS, HEADS and SECTORS. If an
1020 * error occurs, then return non-zero, otherwise zero.
1023 FUNCTION(grub_biosdisk_get_diskinfo_standard)
1028 /* push CYLINDERS */
1032 /* SECTORS is on the stack */
1036 /* enter real mode */
1041 int $0x13 /* do the operation */
1042 /* check if successful */
1045 /* bogus BIOSes may not return an error number */
1046 testb $0x3f, %cl /* 0 sectors means no disk */
1047 jnz 1f /* if non-zero, then succeed */
1048 /* XXX 0x60 is one of the unused error numbers */
1051 movb %ah, %bl /* save return value in %bl */
1052 /* back to protected mode */
1053 DATA32 call real_to_prot
1059 incl %eax /* the number of heads is counted from zero */
1066 shrb $6, %ah /* the number of cylinders is counted from zero */
1071 movl 0x10(%esp), %edi
1077 movb %bl, %al /* return value in %eax */
1087 * int grub_biosdisk_get_num_floppies (void)
1089 FUNCTION(grub_biosdisk_get_num_floppies)
1096 /* reset the disk system first */
1101 /* call GET DISK TYPE */
1107 /* check if this drive exists */
1115 DATA32 call real_to_prot
1125 * grub_get_memsize(i) : return the memory size in KB. i == 0 for conventional
1126 * memory, i == 1 for extended memory
1127 * BIOS call "INT 12H" to get conventional memory size
1128 * BIOS call "INT 15H, AH=88H" to get extended memory size
1129 * Both have the return value in AX.
1133 FUNCTION(grub_get_memsize)
1138 call prot_to_real /* enter real mode */
1154 DATA32 call real_to_prot
1165 * grub_get_eisa_mmap() : return packed EISA memory map, lower 16 bits is
1166 * memory between 1M and 16M in 1K parts, upper 16 bits is
1167 * memory above 16M in 64K parts. If error, return zero.
1168 * BIOS call "INT 15H, AH=E801H" to get EISA memory map,
1169 * AX = memory between 1M and 16M in 1K parts.
1170 * BX = memory above 16M in 64K parts.
1174 FUNCTION(grub_get_eisa_mmap)
1178 call prot_to_real /* enter real mode */
1187 DATA32 call real_to_prot
1202 * grub_get_mmap_entry(addr, cont) : address and old continuation value (zero to
1203 * start), for the Query System Address Map BIOS call.
1205 * Sets the first 4-byte int value of "addr" to the size returned by
1206 * the call. If the call fails, sets it to zero.
1208 * Returns: new (non-zero) continuation value, 0 if done.
1211 FUNCTION(grub_get_mmap_entry)
1220 /* place address (+4) in ES:DI */
1227 /* set continuation value */
1230 /* set default maximum buffer size */
1233 /* set EDX to 'SMAP' */
1234 movl $0x534d4150, %edx
1236 call prot_to_real /* enter real mode */
1245 cmpl $0x534d4150, %eax
1260 DATA32 call real_to_prot
1263 /* write length of buffer (zero if error) into ADDR */
1267 /* set return value to continuation */
1278 * void grub_console_real_putchar (int c)
1280 * Put the character C on the console. Because GRUB wants to write a
1281 * character with an attribute, this implementation is a bit tricky.
1282 * If C is a control character (CR, LF, BEL, BS), use INT 10, AH = 0Eh
1283 * (TELETYPE OUTPUT). Otherwise, save the original position, put a space,
1284 * save the current position, restore the original position, write the
1285 * character and the attribute, and restore the current position.
1287 * The reason why this is so complicated is that there is no easy way to
1288 * get the height of the screen, and the TELETYPE OUPUT BIOS call doesn't
1289 * support setting a background attribute.
1291 FUNCTION(grub_console_real_putchar)
1294 movb EXT_C(grub_console_cur_color), %bl
1301 /* use teletype output if control character */
1311 /* save the character and the attribute on the stack */
1315 /* get the current position */
1319 /* check the column with the width */
1323 /* print CR and LF, if next write will exceed the width */
1329 /* get the current position */
1334 /* restore the character and the attribute */
1338 /* write the character with the attribute */
1343 /* move the cursor forward */
1354 3: DATA32 call real_to_prot
1362 * int grub_console_getkey (void)
1363 * BIOS call "INT 16H Function 00H" to read character from keyboard
1364 * Call with %ah = 0x0
1365 * Return: %ah = keyboard scan code
1366 * %al = ASCII character
1369 /* this table is used in translate_keycode below */
1371 .word GRUB_CONSOLE_KEY_LEFT, 2
1372 .word GRUB_CONSOLE_KEY_RIGHT, 6
1373 .word GRUB_CONSOLE_KEY_UP, 16
1374 .word GRUB_CONSOLE_KEY_DOWN, 14
1375 .word GRUB_CONSOLE_KEY_HOME, 1
1376 .word GRUB_CONSOLE_KEY_END, 5
1377 .word GRUB_CONSOLE_KEY_DC, 4
1378 .word GRUB_CONSOLE_KEY_BACKSPACE, 8
1379 .word GRUB_CONSOLE_KEY_PPAGE, 7
1380 .word GRUB_CONSOLE_KEY_NPAGE, 3
1384 * translate_keycode translates the key code %dx to an ascii code.
1392 movw $ABS(translation_table), %si
1395 /* check if this is the end */
1398 /* load the ascii code into %ax */
1401 /* check if this matches the key code */
1404 /* translate %dx, if successful */
1413 FUNCTION(grub_console_getkey)
1421 movw %ax, %dx /* real_to_prot uses %eax */
1422 call translate_keycode
1424 DATA32 call real_to_prot
1434 * int grub_console_checkkey (void)
1435 * if there is a character pending, return it; otherwise return -1
1436 * BIOS call "INT 16H Function 01H" to check whether a character is pending
1437 * Call with %ah = 0x1
1439 * If key waiting to be input:
1440 * %ah = keyboard scan code
1441 * %al = ASCII character
1446 FUNCTION(grub_console_checkkey)
1450 call prot_to_real /* enter real mode */
1465 DATA32 call real_to_prot
1475 * grub_uint16_t grub_console_getxy (void)
1476 * BIOS call "INT 10H Function 03h" to get cursor position
1477 * Call with %ah = 0x03
1479 * Returns %ch = starting scan line
1480 * %cl = ending scan line
1481 * %dh = row (0 is top)
1482 * %dl = column (0 is left)
1486 FUNCTION(grub_console_getxy)
1488 pushl %ebx /* save EBX */
1493 xorb %bh, %bh /* set page to 0 */
1495 int $0x10 /* get cursor position */
1497 DATA32 call real_to_prot
1509 * void grub_console_gotoxy(grub_uint8_t x, grub_uint8_t y)
1510 * BIOS call "INT 10H Function 02h" to set cursor position
1511 * Call with %ah = 0x02
1513 * %dh = row (0 is top)
1514 * %dl = column (0 is left)
1518 FUNCTION(grub_console_gotoxy)
1520 pushl %ebx /* save EBX */
1522 movb %dl, %dh /* %dh = y */
1523 movb %al, %dl /* %dl = x */
1528 xorb %bh, %bh /* set page to 0 */
1530 int $0x10 /* set cursor position */
1532 DATA32 call real_to_prot
1541 * void grub_console_cls (void)
1542 * BIOS call "INT 10H Function 09h" to write character and attribute
1543 * Call with %ah = 0x09
1545 * %bh = (page number)
1547 * %cx = (number of times)
1550 FUNCTION(grub_console_cls)
1552 pushl %ebx /* save EBX */
1557 /* move the cursor to the beginning */
1563 /* write spaces to the entire screen */
1566 movw $(80 * 25), %cx
1569 /* move back the cursor */
1573 DATA32 call real_to_prot
1582 * void grub_console_setcursor (int on)
1583 * BIOS call "INT 10H Function 01h" to set cursor type
1584 * Call with %ah = 0x01
1585 * %ch = cursor starting scanline
1586 * %cl = cursor ending scanline
1589 console_cursor_state:
1591 console_cursor_shape:
1594 FUNCTION(grub_console_setcursor)
1601 /* check if the standard cursor shape has already been saved */
1602 movw console_cursor_shape, %ax
1613 DATA32 call real_to_prot
1616 movw %cx, console_cursor_shape
1618 /* set %cx to the designated cursor shape */
1623 movw console_cursor_shape, %cx
1631 DATA32 call real_to_prot
1640 * if a seconds value can be read, read it and return it (BCD),
1641 * otherwise return 0xFF
1642 * BIOS call "INT 1AH Function 02H" to check whether a character is pending
1643 * Call with %ah = 0x2
1645 * If RT Clock can give correct values
1647 * %cl = minutes (BCD)
1648 * %dh = seconds (BCD)
1649 * %dl = daylight savings time (00h std, 01h daylight)
1650 * Carry flag = clear
1653 * (this indicates that the clock is updating, or
1654 * that it isn't running)
1656 FUNCTION(grub_getrtsecs)
1659 call prot_to_real /* enter real mode */
1670 DATA32 call real_to_prot
1681 * return the real time in ticks, of which there are about
1684 FUNCTION(grub_get_rtc)
1687 call prot_to_real /* enter real mode */
1690 /* %ax is already zero */
1693 DATA32 call real_to_prot
1705 * unsigned char grub_vga_set_mode (unsigned char mode)
1707 FUNCTION(grub_vga_set_mode)
1714 /* get current mode */
1720 /* set the new mode */
1725 DATA32 call real_to_prot
1735 * unsigned char *grub_vga_get_font (void)
1737 FUNCTION(grub_vga_get_font)
1748 DATA32 call real_to_prot
1761 * grub_vbe_bios_status_t grub_vbe_get_controller_info (struct grub_vbe_info_block *controller_info)
1763 * Register allocations for parameters:
1764 * %eax *controller_info
1766 FUNCTION(grub_vbe_bios_get_controller_info)
1771 movw %ax, %di /* Store *controller_info to %edx:%di. */
1774 mov %eax, %edx /* prot_to_real destroys %eax. */
1781 movw %dx, %es /* *controller_info is now on %es:%di. */
1785 movw %ax, %dx /* real_to_prot destroys %eax. */
1789 DATA32 call real_to_prot
1793 andl $0x0FFFF, %eax /* Return value in %eax. */
1801 * grub_vbe_status_t grub_vbe_bios_get_mode_info (grub_uint32_t mode,
1802 * struct grub_vbe_mode_info_block *mode_info)
1804 * Register allocations for parameters:
1808 FUNCTION(grub_vbe_bios_get_mode_info)
1812 movl %eax, %ecx /* Store mode number to %ecx. */
1814 movw %dx, %di /* Store *mode_info to %edx:%di. */
1823 movw %dx, %es /* *mode_info is now on %es:%di. */
1827 movw %ax, %dx /* real_to_prot destroys %eax. */
1831 DATA32 call real_to_prot
1835 andl $0x0FFFF, %eax /* Return value in %eax. */
1842 * grub_vbe_status_t grub_vbe_bios_set_mode (grub_uint32_t mode,
1843 * struct grub_vbe_crtc_info_block *crtc_info)
1845 * Register allocations for parameters:
1849 FUNCTION(grub_vbe_bios_set_mode)
1854 movl %eax, %ebx /* Store mode in %ebx. */
1856 movw %dx, %di /* Store *crtc_info to %edx:%di. */
1865 movw %dx, %es /* *crtc_info is now on %es:%di. */
1870 movw %ax, %dx /* real_to_prot destroys %eax. */
1874 DATA32 call real_to_prot
1878 andl $0xFFFF, %eax /* Return value in %eax. */
1886 * grub_vbe_status_t grub_vbe_bios_get_mode (grub_uint32_t *mode)
1888 * Register allocations for parameters:
1891 FUNCTION(grub_vbe_bios_get_mode)
1896 pushl %eax /* Push *mode to stack. */
1904 movw %ax, %dx /* real_to_prot destroys %eax. */
1906 DATA32 call real_to_prot
1909 popl %edi /* Pops *mode from stack to %edi. */
1914 andl $0xFFFF, %eax /* Return value in %eax. */
1923 * grub_vbe_status_t grub_vbe_bios_set_memory_window (grub_uint32_t window,
1924 * grub_uint32_t position);
1926 * Register allocations for parameters:
1930 FUNCTION(grub_vbe_bios_set_memory_window)
1940 andw $0x00ff, %bx /* BL = window, BH = 0, Set memory window. */
1943 movw %ax, %dx /* real_to_prot destroys %eax. */
1945 DATA32 call real_to_prot
1949 andl $0xFFFF, %eax /* Return value in %eax. */
1956 * grub_vbe_status_t grub_vbe_bios_get_memory_window (grub_uint32_t window,
1957 * grub_uint32_t *position);
1959 * Register allocations for parameters:
1963 FUNCTION(grub_vbe_bios_get_memory_window)
1967 pushl %edx /* Push *position to stack. */
1969 movl %eax, %ebx /* Store window in %ebx. */
1975 andw $0x00ff, %bx /* BL = window. */
1976 orw $0x0100, %bx /* BH = 1, Get memory window. */
1979 movw %ax, %bx /* real_to_prot destroys %eax. */
1981 DATA32 call real_to_prot
1984 popl %edi /* pops *position from stack to %edi. */
1986 movl %edx, (%edi) /* Return position to caller. */
1989 andl $0xFFFF, %eax /* Return value in %eax. */
1997 * grub_vbe_status_t grub_vbe_bios_set_scanline_length (grub_uint32_t length)
1999 * Register allocations for parameters:
2002 FUNCTION(grub_vbe_bios_set_scanline_length)
2007 movl %eax, %ecx /* Store length in %ecx. */
2013 movw $0x0002, %bx /* BL = 2, Set Scan Line in Bytes. */
2016 movw %ax, %dx /* real_to_prot destroys %eax. */
2018 DATA32 call real_to_prot
2022 andl $0xFFFF, %eax /* Return value in %eax. */
2030 * grub_vbe_status_t grub_vbe_bios_get_scanline_length (grub_uint32_t *length)
2032 * Register allocations for parameters:
2035 FUNCTION(grub_vbe_bios_get_scanline_length)
2039 pushl %edx /* Push *length to stack. */
2045 movw $0x0001, %bx /* BL = 1, Get Scan Line Length (in bytes). */
2048 movw %ax, %dx /* real_to_prot destroys %eax. */
2050 DATA32 call real_to_prot
2053 popl %edi /* Pops *length from stack to %edi. */
2055 movl %ebx, (%edi) /* Return length to caller. */
2058 andl $0xFFFF, %eax /* Return value in %eax. */
2066 * grub_vbe_status_t grub_vbe_bios_set_display_start (grub_uint32_t x,
2069 * Register allocations for parameters:
2073 FUNCTION(grub_vbe_bios_set_display_start)
2077 movl %eax, %ecx /* Store x in %ecx. */
2083 movw $0x0080, %bx /* BL = 80h, Set Display Start
2084 during Vertical Retrace. */
2087 movw %ax, %dx /* real_to_prot destroys %eax. */
2089 DATA32 call real_to_prot
2093 andl $0xFFFF, %eax /* Return value in %eax. */
2100 * grub_vbe_status_t grub_vbe_bios_get_display_start (grub_uint32_t *x,
2103 * Register allocations for parameters:
2107 FUNCTION(grub_vbe_bios_get_display_start)
2111 pushl %eax /* Push *x to stack. */
2112 pushl %edx /* Push *y to stack. */
2118 movw $0x0001, %bx /* BL = 1, Get Display Start. */
2121 movw %ax, %bx /* real_to_prot destroys %eax. */
2123 DATA32 call real_to_prot
2126 popl %edi /* Pops *y from stack to %edi. */
2128 movl %edx, (%edi) /* Return y-position to caller. */
2130 popl %edi /* Pops *x from stack to %edi. */
2132 movl %ecx, (%edi) /* Return x-position to caller. */
2135 andl $0xFFFF, %eax /* Return value in %eax. */
2143 * grub_vbe_status_t grub_vbe_bios_set_palette_data (grub_uint32_t color_count,
2144 * grub_uint32_t start_index,
2145 * struct grub_vbe_palette_data *palette_data)
2147 * Register allocations for parameters:
2150 * %ecx *palette_data
2152 FUNCTION(grub_vbe_bios_set_palette_data)
2157 movl %eax, %ebx /* Store color_count in %ebx. */
2159 movw %cx, %di /* Store *palette_data to %ecx:%di. */
2168 movw %cx, %es /* *palette_data is now on %es:%di. */
2169 movw %bx, %cx /* color_count is now on %cx. */
2172 xorw %bx, %bx /* BL = 0, Set Palette Data. */
2175 movw %ax, %dx /* real_to_prot destroys %eax. */
2179 DATA32 call real_to_prot
2183 andl $0xFFFF, %eax /* Return value in %eax. */