2
* GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS
3
* Copyright (C) 2009 Bean (bean123ch@gmail.com)
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 3 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, see <http://www.gnu.org/licenses/>.
24
#define ABS(a) (a - start + CODE_START)
26
#define VARIABLE(a) . = start + OFS_ ## a ; a:
28
#define KEY_ESCAPE 0x11b
30
#define DATA_BUF_SEG 0x8000
31
#define CODE_START 0x2000
33
#define DOT_SIZE 1024 /* 512k */
35
#define orig_es -2(%bp)
36
#define orig_di -4(%bp)
37
#define text_color -6(%bp)
38
#define file_name -8(%bp)
39
#define gdt_table -56(%bp)
40
#define gdt_src_len -40(%bp)
41
#define gdt_src_low -38(%bp)
42
#define gdt_src_hi1 -36(%bp)
43
#define gdt_src_acc -35(%bp)
44
#define gdt_src_hi2 -33(%bp)
45
#define gdt_dst_len -32(%bp)
46
#define gdt_dst_low -30(%bp)
47
#define gdt_dst_hi1 -28(%bp)
48
#define gdt_dst_acc -27(%bp)
49
#define gdt_dst_hi2 -25(%bp)
50
#define block_size -58(%bp)
51
#define dot_max -60(%bp)
52
#define dot_cur -62(%bp)
59
#define DBG_PRINT(s) jmp 101f ; 100: .ascii s "\0" ; 101: pushaw ; movw $ABS(100b), %si ; call print_string; popaw
60
#define DUMP_VAR(v) pushw v ; call dump_hex
101
#if CODE_START == 0x2000
106
pushw $(CODE_START >> 4)
113
call safe_int13 /* 0, 0, 1 */
115
movw ABS(lba), %di /* sector 0 offset */
117
pushw $((CODE_START + 0x200) >> 4)
120
/* detect lba mode */
128
jne 1f /* No EBIOS */
139
call safe_int13 /* 0, 1, 1 */
145
xchg %ch, %dh /* 1, 0, 1 */
153
movw ABS(boot_base), %ax
155
movw ABS(boot_size), %si
157
ljmp $0, $ABS(start_2000)
160
movw (CODE_START + 0x200 + 0x1fe), %ax
164
movw (CODE_START + 0x200 + OFS_lba), %ax
170
cmpw $FB_MAGIC_WORD, %es: (OFS_fb_magic)
253
subb $('0'-'A'+10), %al
268
* %es:%bx - target address
269
* %bp,%ax - start sector
271
* %di - sector offset
273
* %si - remain sectors
283
/* cx = sector, ax = current count, si = total count */
301
movb ABS(max_sec), %al
318
/* ch = cylinder, cl = sector, dh = head, dl = drive */
319
/* ax = current count, si = total count */
330
movw %ax, %cx /* cx = cylinder */
335
popw %dx /* dl = drive */
336
movb %al, %dh /* dh = heads */
340
xchgb %cl, %ch /* cl = sector, ch = cylinder */
346
cmpb ABS(max_sec), %al
348
movb ABS(max_sec), %al
383
movb %al, ABS(max_sec)
414
. = start + 0x200 - 2
419
.word start_menu - start - 0x200
481
* %si: string pointer
489
* %si - string pointer
518
* src, dst - gdt table
519
* %ax - number of sectors
520
* block_size (512/510)
546
movw $ABS(err_int15), %si
550
addw $512, gdt_src_low
551
addw %cx, gdt_dst_low
598
* %ax - number of sectors
599
* block_size (512/510)
603
movw $ABS(start_menu), %si
604
movb $FBM_TYPE_FILE, %cl
609
movw $ABS(err_no_file), %si
637
cmpw ABS(pri_size + 2), %ax
640
cmpw ABS(pri_size), %ax
667
movw $ABS(loading_message), %si
678
* gdt_dst - target address
687
* gdt_dst - target address
689
* %ax - number of sectors
690
* block_size (512/510)
715
movw $ABS(dot_message), %si
729
call read_sectors_cont_2
740
call read_sectors_cont_1
744
popw %ax /* ax = boot_size */
748
addw $(CODE_START + 0x200 + 64), %ax
751
movw $COLOR_NORMAL, text_color
752
movw %si, dot_max /* si = 0 */
764
movw %ax, gdt_src_len
765
movw %ax, gdt_dst_len
767
movb %al, gdt_src_acc
768
movb %al, gdt_dst_acc
770
movw ABS(menu_ofs), %cx
773
popw %ax /* ax = boot_size */
777
addw $(CODE_START + 0x200), %cx
778
movw %cx, gdt_src_low
781
movw %cx, gdt_dst_low
782
movw $510, block_size
789
movb $(DATA_BUF_SEG >> 12), gdt_src_hi1
790
movw $ABS(menu_file), %si
791
movw %bp, gdt_dst_low
796
. = start + 0x400 - 2
825
* cf clear if menu found
835
movb $FBM_TYPE_MENU, %cl
860
* cf clear if menu found
879
/* cx,dx = current tick */
880
/* si,bx = next tick */
916
movb $FBM_TYPE_TIMEOUT, %cl
925
cmpw $KEY_ESCAPE, %ax
940
cmpb $FBM_TYPE_COLOR, %ah
945
cmpb $FBM_TYPE_TEXT, %ah
954
movb $COLOR_NORMAL, text_color
959
movb $FBM_TYPE_DEFAULT, %cl
966
movb $FBM_TYPE_MENU, %cl
977
movw $ABS(err_no_menu), %si
985
cmpb $FBS_TYPE_GRLDR, %al
995
cmpb $FBS_TYPE_SYSLINUX, %al
999
movw $0x7c00, gdt_dst_low
1002
movb ABS(max_sec), %al
1003
movb %al, (0x7dfc) /* MaxTransfer */
1008
cmpb $FBS_TYPE_LINUX, %al
1012
movw $DOT_SIZE, dot_max
1015
movb $9, gdt_dst_hi1
1020
movb %es: (0x1f1), %al
1024
addw block_size, %ax
1041
movb $0x10, gdt_dst_hi1
1043
xchgw %cx, gdt_dst_low /* assume load address 0x100000 */
1047
movw %ax, block_size
1049
movw %cx, gdt_src_low
1050
incb gdt_src_hi1 /* 8000 -> 9000 */
1055
decb gdt_src_hi1 /* 9000 -> 8000 */
1074
incb gdt_dst_hi2 /* initrd at 16m */
1078
incb %es: (0x218 + 3) /* ramdisk_image */
1080
movw %cx, %es: (0x21c) /* ramdisk_size */
1082
movw %cx, %es: (0x21c + 2) /* ramdisk_size */
1095
movw %bx, %es: (0x228) /* cmd_line_ptr */
1100
movb %al, %es: (%bx)
1105
movb $7, %es: (0x210) /* type of loader (GRUB) */
1106
movw $(0x9000 - 0x200), %es: (0x224) /* heap end */
1107
orb $0x80, %es: (0x211) /* loadflags */
1108
movb $9, %es: (0x228 + 2) /* cmd_line_ptr */
1122
. = start + 0x600 - 2
1126
movw $ABS(newline), %si
1132
movw %ax, gdt_dst_low
1133
movb %al, gdt_dst_hi1
1134
movb %al, gdt_dst_hi2
1146
cmpb $FBS_TYPE_MSDOS, %al
1150
movw $(DATA_BUF_SEG >> 5), %bx
1156
movw %ax, gdt_dst_low
1159
movb %al, gdt_dst_hi1
1168
movw $ABS(iosys_trampoline_start), %si
1169
movw $(iosys_trampoline_end - iosys_trampoline_start), %cx
1173
ljmp $DATA_BUF_SEG, $0x200
1176
movw $ABS(err_no_type), %si
1179
#define IOSYS_CM_MAGIC 0x4d43
1181
iosys_trampoline_start:
1201
cmpw $IOSYS_CM_MAGIC,(%si)
1208
call normalize_address
1239
addw %bx, %ax /* skip the source len field */
1242
call normalize_address
1256
cmpw $IOSYS_CM_MAGIC, %ax
1257
jnz iosys_expand_error
1259
movw %ax, %cs: (iosys_expand_func - iosys_trampoline_start + 0x200)
1260
movw %ds, %cs: (iosys_expand_func - iosys_trampoline_start + 0x200 + 2)
1266
call normalize_address
1275
movw %ax, %cx /* uncompressed block */
1280
lodsw /* dest length */
1281
movw %ax, %cx /* convert to sector */
1294
.byte 0x9a /* lcall */
1297
jc iosys_expand_error
1304
jmp iosys_expand_error
1322
iosys_trampoline_end:
1328
movw $(CODE_START + 0x1be), %si
1329
movw $(0x800 - 18), %di
1338
movb %dl, ABS(bootdrv)
1345
movw $DATA_BUF_SEG, %ax
1350
movw (CODE_START + 0x1c6), %ax
1351
movw (CODE_START + 0x1c8), %bp
1369
popw (0x1c) /* Hidden sectors */
1428
.ascii FB_MENU_FILE "\0"