~smartboyhw/wubi/bug-1080090-new

« back to all changes in this revision

Viewing changes to src/grubutil/fbinst/.svn/text-base/fbmbr.S.svn-base

  • Committer: Howard Chan
  • Date: 2012-11-20 10:16:05 UTC
  • Revision ID: smartboyhw@gmail.com-20121120101605-qfmjfsdynpzg9an9
Added images

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB Utilities --  Utilities for GRUB Legacy, GRUB2 and GRUB for DOS
3
 
 *  Copyright (C) 2009  Bean (bean123ch@gmail.com)
4
 
 *
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.
9
 
 *
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.
14
 
 *
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/>.
17
 
 */
18
 
 
19
 
        .text
20
 
 
21
 
#include "version.h"
22
 
#include "fbinst.h"
23
 
 
24
 
#define ABS(a)          (a - start + CODE_START)
25
 
 
26
 
#define VARIABLE(a)     . = start + OFS_ ## a ; a:
27
 
 
28
 
#define KEY_ESCAPE      0x11b
29
 
 
30
 
#define DATA_BUF_SEG    0x8000
31
 
#define CODE_START      0x2000
32
 
 
33
 
#define DOT_SIZE        1024            /* 512k  */
34
 
 
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)
53
 
 
54
 
//#define DEBUG
55
 
//#define DEBUG_INT13
56
 
 
57
 
#ifdef DEBUG
58
 
 
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
61
 
 
62
 
#else
63
 
 
64
 
#define DBG_PRINT(s)
65
 
#define DUMP_VAR(s)
66
 
 
67
 
#endif
68
 
 
69
 
        .code16
70
 
 
71
 
start:
72
 
        jmp     start_7c00
73
 
 
74
 
        . = start + 0x10
75
 
        .byte   2
76
 
 
77
 
        . = start + 0x18
78
 
        .word   0x3f
79
 
        .word   0xff
80
 
 
81
 
        . = start + 0x24
82
 
        .byte   0x80
83
 
 
84
 
#ifdef DEBUG
85
 
        . = start + 0x28
86
 
#else
87
 
        . = start + 0x60
88
 
#endif
89
 
 
90
 
start_7c00:
91
 
        xorw    %bx, %bx
92
 
        movw    %bx, %ds
93
 
        movw    %bx, %bp
94
 
 
95
 
        movw    %bx, %ss
96
 
        movw    $0x7c00, %sp
97
 
 
98
 
        pushw   %es
99
 
        pushw   %di
100
 
 
101
 
#if CODE_START == 0x2000
102
 
        movw    $0x200, %ax
103
 
        movw    %ax, %es
104
 
        incw    %ax
105
 
#else
106
 
        pushw   $(CODE_START >> 4)
107
 
        popw    %es
108
 
        movw    $0x201, %ax
109
 
#endif
110
 
 
111
 
        movw    $0x1, %cx
112
 
        xorb    %dh, %dh
113
 
        call    safe_int13              /* 0, 0, 1  */
114
 
        call    check_mbr
115
 
        movw    ABS(lba), %di           /* sector 0 offset  */
116
 
 
117
 
        pushw   $((CODE_START + 0x200) >> 4)
118
 
        popw    %es
119
 
 
120
 
        /* detect lba mode  */
121
 
        pushaw
122
 
 
123
 
        movb    $0x41, %ah
124
 
        movw    $0x55aa, %bx
125
 
        int     $0x13
126
 
        jc      1f                      /* No EBIOS */
127
 
        cmpw    $0xaa55, %bx
128
 
        jne     1f                      /* No EBIOS */
129
 
        testb   $1, %cl
130
 
        jz      1f                      /* No EBIOS */
131
 
        popaw
132
 
        decb    %dh
133
 
        jmp     2f
134
 
1:
135
 
 
136
 
        popaw
137
 
 
138
 
        incb    %dh
139
 
        call    safe_int13              /* 0, 1, 1  */
140
 
        pushw   %ax
141
 
        call    calc_lba
142
 
        movb    %al, ABS(spt)
143
 
        popw    %ax
144
 
 
145
 
        xchg    %ch, %dh                /* 1, 0, 1  */
146
 
        call    safe_int13
147
 
        call    calc_lba
148
 
        divb    ABS(spt)
149
 
        movb    %al, ABS(heads)
150
 
 
151
 
2:
152
 
 
153
 
        movw    ABS(boot_base), %ax
154
 
        incw    %ax
155
 
        movw    ABS(boot_size), %si
156
 
        call    read_sectors
157
 
        ljmp    $0, $ABS(start_2000)
158
 
 
159
 
calc_lba:
160
 
        movw    (CODE_START + 0x200 + 0x1fe), %ax
161
 
        cmpw    $0xaa55, %ax
162
 
        jnz     1f
163
 
        call    check_mbr
164
 
        movw    (CODE_START + 0x200 + OFS_lba), %ax
165
 
1:
166
 
        subw    %di, %ax
167
 
        ret
168
 
 
169
 
check_mbr:
170
 
        cmpw    $FB_MAGIC_WORD, %es: (OFS_fb_magic)
171
 
        jnz     1f
172
 
        ret
173
 
1:
174
 
        movb    $'m', %al
175
 
        jmp     early_fail
176
 
 
177
 
test_int13:
178
 
 
179
 
        pushaw
180
 
        stc
181
 
        int     $0x13
182
 
        sti
183
 
        popaw
184
 
 
185
 
#ifdef DEBUG_INT13
186
 
        pushfw
187
 
        pushaw
188
 
 
189
 
        pushaw
190
 
        pushfw
191
 
        pushw   %es
192
 
 
193
 
        shlw    $9, %ax
194
 
        addw    %ax, %bx
195
 
        movw    $5, %cx
196
 
 
197
 
1:
198
 
        decw    %bx
199
 
        decw    %bx
200
 
        pushw   %es: (%bx)
201
 
        loop    1b
202
 
 
203
 
        pushw   %es: (OFS_lba)
204
 
 
205
 
        movb    $16, %cl
206
 
1:
207
 
        call    dump_hex
208
 
        loop    1b
209
 
 
210
 
        popaw
211
 
        popfw
212
 
#endif
213
 
 
214
 
        ret
215
 
 
216
 
safe_int13:
217
 
        call    test_int13
218
 
        jc      err_int13
219
 
        ret
220
 
 
221
 
err_int13:
222
 
        movb    $'i', %al
223
 
 
224
 
early_fail:
225
 
        movb    $0xe, %ah
226
 
        xorw    %bx, %bx
227
 
        int     $0x10
228
 
 
229
 
halt:
230
 
        hlt
231
 
        jmp     halt
232
 
 
233
 
#ifdef DEBUG
234
 
 
235
 
/*
236
 
 * input:
237
 
 *   18(%bp) - word
238
 
 */
239
 
dump_hex:
240
 
        pushaw
241
 
        movw    %sp, %bp
242
 
 
243
 
        movb    $0xe, %ah
244
 
        xorw    %bx, %bx
245
 
        movw    $4, %cx
246
 
        movw    18(%bp), %dx
247
 
1:
248
 
        rol     $4, %dx
249
 
        movb    %dl, %al
250
 
        andb    $0xF, %al
251
 
        cmpb    $10, %al
252
 
        jb      2f
253
 
        subb    $('0'-'A'+10), %al
254
 
2:
255
 
        addb    $'0', %al
256
 
        int     $0x10
257
 
        loop    1b
258
 
        movb    $' ', %al
259
 
        int     $0x10
260
 
 
261
 
        popaw
262
 
        ret     $2
263
 
 
264
 
#endif
265
 
 
266
 
/*
267
 
 * input:
268
 
 *   %es:%bx - target address
269
 
 *   %bp,%ax - start sector
270
 
 *   %si - sector count
271
 
 *   %di - sector offset
272
 
 * output:
273
 
 *   %si - remain sectors
274
 
 */
275
 
read_sectors:
276
 
        subw    %di, %ax
277
 
        sbbw    $0, %bp
278
 
 
279
 
        cmpb    $0xff, %dh
280
 
        jnz     chs_mode
281
 
 
282
 
lba_mode:
283
 
        /* cx = sector,  ax = current count, si = total count  */
284
 
 
285
 
        movw    %ax, %cx
286
 
 
287
 
lba_mode_cont:
288
 
 
289
 
        pushw   %si
290
 
 
291
 
        xorw    %ax, %ax
292
 
        pushw   %ax
293
 
        pushw   %ax
294
 
 
295
 
        pushw   %bp
296
 
        pushw   %cx
297
 
 
298
 
        pushw   %es
299
 
        pushw   %bx
300
 
 
301
 
        movb    ABS(max_sec), %al
302
 
        cmpw    %si, %ax
303
 
        jbe     1f
304
 
        movw    %si, %ax
305
 
1:
306
 
        pushw   %ax
307
 
        pushw   $0x10
308
 
 
309
 
        movw    %sp, %si
310
 
        movb    $0x42, %ah
311
 
        call    read_int13
312
 
        addw    $16, %sp
313
 
 
314
 
        popw    %si
315
 
        ret
316
 
 
317
 
chs_mode:
318
 
        /* ch = cylinder, cl = sector, dh = head, dl = drive  */
319
 
        /* ax = current count, si = total count  */
320
 
 
321
 
        pushw   %dx
322
 
        movw    %bp, %dx
323
 
 
324
 
        movw    %ax, %cx
325
 
        movb    ABS(spt), %al
326
 
        mulb    ABS(heads)
327
 
        xchgw   %ax, %cx
328
 
        divw    %cx
329
 
 
330
 
        movw    %ax, %cx        /* cx = cylinder  */
331
 
 
332
 
        movw    %dx, %ax
333
 
        divb    ABS(spt)
334
 
 
335
 
        popw    %dx             /* dl = drive  */
336
 
        movb    %al, %dh        /* dh = heads  */
337
 
 
338
 
        shlb    $6, %ch
339
 
        orb     %ah, %ch
340
 
        xchgb   %cl, %ch        /* cl = sector, ch = cylinder  */
341
 
 
342
 
chs_mode_cont:
343
 
        movzbw  ABS(spt), %ax
344
 
        subb    %cl, %al
345
 
        andb    $0x3f, %al
346
 
        cmpb    ABS(max_sec), %al
347
 
        jbe     1f
348
 
        movb    ABS(max_sec), %al
349
 
1:
350
 
 
351
 
        cmpw    %si, %ax
352
 
        jbe     1f
353
 
        movw    %si, %ax
354
 
1:
355
 
 
356
 
        movb    $2, %ah
357
 
        incb    %cl
358
 
 
359
 
read_int13:
360
 
        call    test_int13
361
 
        jc      1f
362
 
        xorb    %ah, %ah
363
 
        ret
364
 
 
365
 
1:
366
 
        cmpb    $7, %al
367
 
        jbe     1f
368
 
        movb    $7, %al
369
 
        jmp     2f
370
 
 
371
 
1:
372
 
        cmpb    $1, %al
373
 
        jbe     err_int13
374
 
        movb    $1, %al
375
 
 
376
 
2:
377
 
 
378
 
        cmpb    $0xff, %dh
379
 
        jnz     2f
380
 
        movb    %al, 2(%si)
381
 
2:
382
 
 
383
 
        movb    %al, ABS(max_sec)
384
 
        pushaw
385
 
        xorw    %ax, %ax
386
 
        int     $0x13
387
 
        popaw
388
 
        jmp     read_int13
389
 
 
390
 
VARIABLE(max_sec)
391
 
        .byte   63
392
 
 
393
 
VARIABLE(lba)
394
 
        .byte   0
395
 
 
396
 
VARIABLE(bootdrv)
397
 
        .byte   0
398
 
 
399
 
VARIABLE(spt)
400
 
        .byte   63
401
 
 
402
 
VARIABLE(heads)
403
 
        .byte   255
404
 
 
405
 
VARIABLE(boot_base)
406
 
        .word   0
407
 
 
408
 
VARIABLE(boot_size)
409
 
        .word   0
410
 
 
411
 
VARIABLE(fb_magic)
412
 
        .ascii  FB_MAGIC
413
 
 
414
 
        . = start + 0x200 - 2
415
 
 
416
 
        .word   0xaa55
417
 
 
418
 
VARIABLE(menu_ofs)
419
 
        .word   start_menu - start - 0x200
420
 
 
421
 
VARIABLE(flags)
422
 
        .word   0
423
 
 
424
 
VARIABLE(ver_major)
425
 
        .byte   VER_MAJOR
426
 
 
427
 
VARIABLE(ver_minor)
428
 
        .byte   VER_MINOR
429
 
 
430
 
VARIABLE(pri_size)
431
 
        .long   0
432
 
 
433
 
VARIABLE(ext_size)
434
 
        .long   0
435
 
 
436
 
read_sectors_cont_1:
437
 
        pushw   %ax
438
 
 
439
 
        shlw    $5, %ax
440
 
        pushw   %bx
441
 
        movw    %es, %bx
442
 
        addw    %ax, %bx
443
 
        movw    %bx, %es
444
 
        popw    %bx
445
 
 
446
 
        popw    %ax
447
 
 
448
 
read_sectors_cont_2:
449
 
        subw    %ax, %si
450
 
        jnz     1f
451
 
        ret
452
 
 
453
 
1:
454
 
        cmpb    $0xff, %dh
455
 
        jnz     1f
456
 
        addw    %ax, %cx
457
 
        adcw    $0, %bp
458
 
        jmp     lba_mode_cont
459
 
 
460
 
1:
461
 
        decb    %cl
462
 
        addb    %cl, %al
463
 
        andb    $0x3f, %al
464
 
        andb    $0xc0, %cl
465
 
        cmpb    ABS(spt), %al
466
 
        jz      1f
467
 
        orb     %al, %cl
468
 
        jmp     chs_mode_cont
469
 
1:
470
 
        incb    %dh
471
 
        cmpb    ABS(heads), %dh
472
 
        jnz     chs_mode_cont
473
 
        xorb    %dh, %dh
474
 
        incb    %ch
475
 
        jnz     chs_mode_cont
476
 
        addb    $0x40, %cl
477
 
        jmp     chs_mode_cont
478
 
 
479
 
/*
480
 
 * input:
481
 
 *   %si: string pointer
482
 
 */
483
 
fail:
484
 
        call    print_string
485
 
        jmp     halt
486
 
 
487
 
/*
488
 
 * input:
489
 
 *   %si - string pointer
490
 
 */
491
 
print_string:
492
 
        cld
493
 
        pushaw
494
 
        movw    $1, %cx
495
 
        movw    text_color, %bx
496
 
 
497
 
1:
498
 
        lodsb   (%si), %al
499
 
        orb     %al, %al
500
 
        jz      1f
501
 
        cmpb    $10, %al
502
 
        jz      2f
503
 
        cmpb    $13, %al
504
 
        jz      2f
505
 
        movb    $0x9, %ah
506
 
        int     $0x10
507
 
2:
508
 
        movb    $0xe, %ah
509
 
        int     $0x10
510
 
        jmp     1b
511
 
 
512
 
1:
513
 
        popaw
514
 
        ret
515
 
 
516
 
/*
517
 
 * input:
518
 
 *   src, dst - gdt table
519
 
 *   %ax - number of sectors
520
 
 *   block_size (512/510)
521
 
 */
522
 
copy_sectors:
523
 
        pushw   %es
524
 
        pushw   %ds
525
 
 
526
 
        pushw   %ds
527
 
        popw    %es
528
 
        leaw    gdt_table, %si
529
 
        movw    block_size, %cx
530
 
        cmpb    $2, %ch
531
 
        jnz     1f
532
 
        shlw    $9, %ax
533
 
        movw    %ax, %cx
534
 
        movb    $1, %al
535
 
 
536
 
1:
537
 
        movb    $0x87, %ah
538
 
 
539
 
1:
540
 
        pushaw
541
 
        shrw    $1, %cx
542
 
        int     $0x15
543
 
        popaw
544
 
 
545
 
        jnc     2f
546
 
        movw    $ABS(err_int15), %si
547
 
        jmp     fail
548
 
 
549
 
2:
550
 
        addw    $512, gdt_src_low
551
 
        addw    %cx, gdt_dst_low
552
 
        jnc     2f
553
 
        incb    gdt_dst_hi1
554
 
        jnz     2f
555
 
        incb    gdt_dst_hi2
556
 
2:
557
 
        decb    %al
558
 
        jnz     1b
559
 
 
560
 
        popw    gdt_src_low
561
 
        popw    %es
562
 
        ret
563
 
 
564
 
/*
565
 
 * input:
566
 
 *   %cl - type
567
 
 * output:
568
 
 *   cf clear if found
569
 
 *   %si - current item
570
 
 */
571
 
 
572
 
find_first_item:
573
 
        movw    %bp, %si
574
 
        jmp     find_item_start
575
 
 
576
 
find_next_item:
577
 
        movb    -2(%si), %al
578
 
1:
579
 
        xorb    %ah, %ah
580
 
        addw    %ax, %si
581
 
 
582
 
find_item_start:
583
 
        cld
584
 
        lodsw
585
 
        cmpb    %ah, %cl
586
 
        jz      1f
587
 
        orb     %al, %al
588
 
        jnz     1b
589
 
        stc
590
 
1:
591
 
        ret
592
 
 
593
 
/*
594
 
 * input:
595
 
 *   %si - file name
596
 
 * output:
597
 
 *   %si - current item
598
 
 *   %ax - number of sectors
599
 
 *   block_size (512/510)
600
 
 */
601
 
find_file:
602
 
        movw    %si, file_name
603
 
        movw    $ABS(start_menu), %si
604
 
        movb    $FBM_TYPE_FILE, %cl
605
 
        call    find_item_start
606
 
 
607
 
1:
608
 
        jnc     2f
609
 
        movw    $ABS(err_no_file), %si
610
 
        jmp     fail
611
 
 
612
 
2:
613
 
 
614
 
        pushw   %si
615
 
        addw    $13, %si
616
 
        movw    file_name, %bx
617
 
 
618
 
2:
619
 
        lodsb
620
 
        cmpb    (%bx), %al
621
 
        jnz     2f
622
 
        incw    %bx
623
 
        orb     %al, %al
624
 
        jnz     2b
625
 
 
626
 
        movw    %bx, file_name
627
 
 
628
 
2:
629
 
        popw    %si
630
 
        jz      1f
631
 
        call    find_next_item
632
 
        jmp     1b
633
 
 
634
 
1:
635
 
 
636
 
        movw    2(%si), %ax
637
 
        cmpw    ABS(pri_size + 2), %ax
638
 
        jnz     1f
639
 
        movw    (%si), %ax
640
 
        cmpw    ABS(pri_size), %ax
641
 
1:
642
 
 
643
 
        movw    $512, %cx
644
 
        jae     1f
645
 
        decw    %cx
646
 
        decw    %cx
647
 
1:
648
 
 
649
 
        pushw   %dx
650
 
 
651
 
        movw    4(%si), %ax
652
 
        movw    6(%si), %dx
653
 
        divw    %cx
654
 
        orw     %dx, %dx
655
 
        jz      1f
656
 
        incw    %ax
657
 
1:
658
 
 
659
 
        popw    %dx
660
 
        movw    %cx, block_size
661
 
 
662
 
        movw    dot_max, %bx
663
 
        orw     %bx, %bx
664
 
        jz      1f
665
 
        movw    %bx, dot_cur
666
 
        movw    %si, %bx
667
 
        movw    $ABS(loading_message), %si
668
 
        call    print_string
669
 
        leaw    13(%bx), %si
670
 
        call    print_string
671
 
        movw    %bx, %si
672
 
 
673
 
1:
674
 
        ret
675
 
 
676
 
/*
677
 
 * input:
678
 
 *   gdt_dst - target address
679
 
 *   %si - name
680
 
 */
681
 
 
682
 
load_file:
683
 
        call    find_file
684
 
 
685
 
/*
686
 
 * input:
687
 
 *   gdt_dst - target address
688
 
 *   %si - current item
689
 
 *   %ax - number of sectors
690
 
 *   block_size (512/510)
691
 
 */
692
 
load_data:
693
 
        pushw   %bp
694
 
 
695
 
        xorw    %bx, %bx
696
 
        pushw   $DATA_BUF_SEG
697
 
        popw    %es
698
 
 
699
 
        pushw   %ax
700
 
        movw    (%si), %ax
701
 
        movw    2(%si), %bp
702
 
        popw    %si
703
 
 
704
 
        call    read_sectors
705
 
 
706
 
1:
707
 
        movw    %bp, %bx
708
 
        popw    %bp
709
 
 
710
 
        cmpw    $0, dot_max
711
 
        jz      2f
712
 
        subw    %ax, dot_cur
713
 
        jnc     2f
714
 
        pushw   %si
715
 
        movw    $ABS(dot_message), %si
716
 
        call    print_string
717
 
        movw    dot_max, %si
718
 
        addw    %si, dot_cur
719
 
        popw    %si
720
 
2:
721
 
 
722
 
        pushaw
723
 
        call    copy_sectors
724
 
        popaw
725
 
 
726
 
        pushw   %bp
727
 
        movw    %bx, %bp
728
 
        xorw    %bx, %bx
729
 
        call    read_sectors_cont_2
730
 
        orw     %si, %si
731
 
        jnz     1b
732
 
 
733
 
        popw    %bp
734
 
        ret
735
 
 
736
 
start_2000:
737
 
        pushw   %si
738
 
 
739
 
1:
740
 
        call    read_sectors_cont_1
741
 
        orw     %si, %si
742
 
        jnz     1b
743
 
 
744
 
        popw    %ax                             /* ax = boot_size  */
745
 
        pushw   %ax
746
 
 
747
 
        shlw    $9, %ax
748
 
        addw    $(CODE_START + 0x200 + 64), %ax
749
 
 
750
 
        movw    %ax, %bp
751
 
        movw    $COLOR_NORMAL, text_color
752
 
        movw    %si, dot_max                    /* si = 0  */
753
 
 
754
 
        xorw    %ax, %ax
755
 
        movw    %ax, %es
756
 
        movw    $24, %cx
757
 
        pushw   %di
758
 
        leaw    gdt_table, %di
759
 
        cld
760
 
        rep     stosw
761
 
        popw    %di
762
 
 
763
 
        decw    %ax
764
 
        movw    %ax, gdt_src_len
765
 
        movw    %ax, gdt_dst_len
766
 
        movb    $0x93, %al
767
 
        movb    %al, gdt_src_acc
768
 
        movb    %al, gdt_dst_acc
769
 
 
770
 
        movw    ABS(menu_ofs), %cx
771
 
        shrw    $9, %cx
772
 
        incw    %cx
773
 
        popw    %ax                             /*  ax = boot_size  */
774
 
        subw    %cx, %ax
775
 
        jz      1f
776
 
        shlw    $9, %cx
777
 
        addw    $(CODE_START + 0x200), %cx
778
 
        movw    %cx, gdt_src_low
779
 
        decw    %cx
780
 
        decw    %cx
781
 
        movw    %cx, gdt_dst_low
782
 
        movw    $510, block_size
783
 
        call    copy_sectors
784
 
1:
785
 
 
786
 
        popw    orig_di
787
 
        popw    orig_es
788
 
 
789
 
        movb    $(DATA_BUF_SEG >> 12), gdt_src_hi1
790
 
        movw    $ABS(menu_file), %si
791
 
        movw    %bp, gdt_dst_low
792
 
        call    load_file
793
 
 
794
 
        jmp     parse_menu
795
 
 
796
 
        . = start + 0x400 - 2
797
 
        .word   0
798
 
 
799
 
/*
800
 
 * output:
801
 
 *   %ax - keycode
802
 
 */
803
 
check_key:
804
 
        movb    $0x1, %ah
805
 
        pushw   %ax
806
 
        int     $0x16
807
 
        popw    %ax
808
 
        jnz     1f
809
 
 
810
 
        movb    $0x11, %ah
811
 
        pushw   %ax
812
 
        int     $0x16
813
 
        popw    %ax
814
 
        jnz     1f
815
 
        xorw    %ax, %ax
816
 
        ret
817
 
 
818
 
1:
819
 
        decb    %ah
820
 
        int     $0x16
821
 
        ret
822
 
 
823
 
/*
824
 
 * output:
825
 
 *   cf clear if menu found
826
 
 *   si - current item
827
 
 */
828
 
check_menu:
829
 
        call    check_key
830
 
        orw     %ax, %ax
831
 
        jz      2f
832
 
 
833
 
        pushaw
834
 
        movw    %ax, %bx
835
 
        movb    $FBM_TYPE_MENU, %cl
836
 
        call    find_first_item
837
 
 
838
 
1:
839
 
        jc      1f
840
 
        cmpw    (%si), %bx
841
 
        jz      3f
842
 
        call    find_next_item
843
 
        jmp     1b
844
 
1:
845
 
 
846
 
        popaw
847
 
 
848
 
2:
849
 
        stc
850
 
        ret
851
 
 
852
 
3:
853
 
        addw    $16, %sp
854
 
        ret
855
 
 
856
 
/*
857
 
 * input:
858
 
 *   %bl - timeout
859
 
 * output:
860
 
 *   cf clear if menu found
861
 
 *   si - current item
862
 
 */
863
 
check_timeout:
864
 
        pushw   %dx
865
 
 
866
 
        cmpb    $0xff, %bl
867
 
        jnz     2f
868
 
 
869
 
1:
870
 
        call    check_menu
871
 
        jnc     3f
872
 
        hlt
873
 
        jmp     1b
874
 
 
875
 
2:
876
 
        xorw    %ax, %ax
877
 
        int     $0x1a
878
 
 
879
 
        /* cx,dx = current tick  */
880
 
        /* si,bx = next tick  */
881
 
        movb    $18, %al
882
 
        mulb    %bl
883
 
        addw    %ax, %dx
884
 
        adcw    $0, %cx
885
 
        movw    %dx, %bx
886
 
        movw    %cx, %si
887
 
 
888
 
1:
889
 
        call    check_menu
890
 
        jnc     3f
891
 
 
892
 
        xorw    %ax, %ax
893
 
        int     $0x1a
894
 
 
895
 
        orb     %al, %al
896
 
        jz      2f
897
 
        subw    $0xb0, %bx
898
 
        sbbw    $0x18, %si
899
 
2:
900
 
        cmpw    %cx, %si
901
 
        jnz     2f
902
 
        cmpw    %dx, %bx
903
 
2:
904
 
        jb      3f
905
 
 
906
 
        hlt
907
 
        jmp     1b
908
 
 
909
 
3:
910
 
 
911
 
        popw    %dx
912
 
        ret
913
 
 
914
 
parse_menu:
915
 
        /* bl = timeout  */
916
 
        movb    $FBM_TYPE_TIMEOUT, %cl
917
 
        call    find_first_item
918
 
        movb    $0, %bl
919
 
        jc      1f
920
 
        movb    (%si), %bl
921
 
1:
922
 
 
923
 
        call    check_menu
924
 
        jnc     boot_item
925
 
        cmpw    $KEY_ESCAPE, %ax
926
 
        jnz     1f
927
 
        movb    $0xff, %bl
928
 
1:
929
 
 
930
 
        orb     %bl, %bl
931
 
        jz      no_timeout
932
 
 
933
 
        cld
934
 
        movw    %bp, %si
935
 
 
936
 
1:
937
 
        lodsw
938
 
        orb     %al, %al
939
 
        jz      3f
940
 
        cmpb    $FBM_TYPE_COLOR, %ah
941
 
        jnz     2f
942
 
        movb    (%si), %bh
943
 
        movb    %bh, text_color
944
 
2:
945
 
        cmpb    $FBM_TYPE_TEXT, %ah
946
 
        jnz     2f
947
 
        call    print_string
948
 
2:
949
 
        xorb    %ah, %ah
950
 
        addw    %ax, %si
951
 
        jmp     1b
952
 
 
953
 
3:
954
 
        movb    $COLOR_NORMAL, text_color
955
 
        call    check_timeout
956
 
        jnc     boot_item
957
 
 
958
 
no_timeout:
959
 
        movb    $FBM_TYPE_DEFAULT, %cl
960
 
        call    find_first_item
961
 
        movb    $0, %bl
962
 
        jc      1f
963
 
        movb    (%si), %bl
964
 
1:
965
 
 
966
 
        movb    $FBM_TYPE_MENU, %cl
967
 
        call    find_first_item
968
 
 
969
 
1:
970
 
        jc      1f
971
 
        subb    $1, %bl
972
 
        jc      boot_item
973
 
        call    find_next_item
974
 
        jmp     1b
975
 
 
976
 
1:
977
 
        movw    $ABS(err_no_menu), %si
978
 
        jmp     fail
979
 
 
980
 
boot_item:
981
 
        call    clear_dest
982
 
 
983
 
        movb    2(%si), %al
984
 
        addw    $3, %si
985
 
        cmpb    $FBS_TYPE_GRLDR, %al
986
 
        jnz     1f
987
 
 
988
 
boot_grldr:
989
 
        movb    $2, gdt_dst_hi1
990
 
        call    load_file
991
 
        call    setup_mbr
992
 
        ljmp    $0x2000, $0
993
 
 
994
 
1:
995
 
        cmpb    $FBS_TYPE_SYSLINUX, %al
996
 
        jnz     10f
997
 
 
998
 
boot_syslinux:
999
 
        movw    $0x7c00, gdt_dst_low
1000
 
        call    load_file
1001
 
        call    copy_bs
1002
 
        movb    ABS(max_sec), %al
1003
 
        movb    %al, (0x7dfc)           /* MaxTransfer  */
1004
 
        call    setup_mbr
1005
 
        ljmp    $0, $0x7c00
1006
 
 
1007
 
10:
1008
 
        cmpb    $FBS_TYPE_LINUX, %al
1009
 
        jnz     10f
1010
 
 
1011
 
boot_linux:
1012
 
        movw    $DOT_SIZE, dot_max
1013
 
        call    find_file
1014
 
        pushw   %ax
1015
 
        movb    $9, gdt_dst_hi1
1016
 
        movw    $1, %ax
1017
 
        call    load_data_inc
1018
 
        movw    $0x9000, %bx
1019
 
        movw    %bx, %es
1020
 
        movb    %es: (0x1f1), %al
1021
 
        incw    %ax
1022
 
        shlw    $9, %ax
1023
 
        movw    %ax, %cx
1024
 
        addw    block_size, %ax
1025
 
        decw    %ax
1026
 
        pushw   %dx
1027
 
        xorw    %dx, %dx
1028
 
        divw    block_size
1029
 
        popw    %dx
1030
 
 
1031
 
        pushw   %ax
1032
 
        decw    %ax
1033
 
        call    load_data_inc
1034
 
        incw    %ax
1035
 
 
1036
 
        pushw   %dx
1037
 
        mulw    block_size
1038
 
        popw    %dx
1039
 
        subw    %cx, %ax
1040
 
 
1041
 
        movb    $0x10, gdt_dst_hi1
1042
 
        movw    $0, %cx
1043
 
        xchgw   %cx, gdt_dst_low        /* assume load address 0x100000 */
1044
 
 
1045
 
        jz      1f
1046
 
        pushw   block_size
1047
 
        movw    %ax, block_size
1048
 
        subw    %ax, %cx
1049
 
        movw    %cx, gdt_src_low
1050
 
        incb    gdt_src_hi1             /* 8000 -> 9000  */
1051
 
        movw    $1, %ax
1052
 
        pushw   %si
1053
 
        call    copy_sectors
1054
 
        popw    %si
1055
 
        decb    gdt_src_hi1             /* 9000 -> 8000  */
1056
 
        popw    block_size
1057
 
1:
1058
 
 
1059
 
        popw    %cx
1060
 
        popw    %ax
1061
 
 
1062
 
        subw    %cx, %ax
1063
 
        jz      1f
1064
 
        call    load_data_inc
1065
 
1:
1066
 
 
1067
 
        call    print_newline
1068
 
 
1069
 
        movw    %bx, %es
1070
 
        movw    file_name, %si
1071
 
        cmpb    $0, (%si)
1072
 
        jz      1f
1073
 
        call    clear_dest
1074
 
        incb    gdt_dst_hi2                     /* initrd at 16m  */
1075
 
        pushw   %bx
1076
 
        call    find_file
1077
 
 
1078
 
        incb    %es: (0x218 + 3)                /* ramdisk_image  */
1079
 
        movw    4(%si), %cx
1080
 
        movw    %cx, %es: (0x21c)               /* ramdisk_size  */
1081
 
        movw    6(%si), %cx
1082
 
        movw    %cx, %es: (0x21c + 2)           /* ramdisk_size  */
1083
 
 
1084
 
        call    load_data
1085
 
        call    print_newline
1086
 
 
1087
 
        popw    %bx
1088
 
        movw    %bx, %es
1089
 
 
1090
 
        movw    file_name, %si
1091
 
        decw    %si
1092
 
1:
1093
 
        incw    %si
1094
 
 
1095
 
        movw    %bx, %es: (0x228)               /* cmd_line_ptr  */
1096
 
        cld
1097
 
 
1098
 
1:
1099
 
        lodsb
1100
 
        movb    %al, %es: (%bx)
1101
 
        incw    %bx
1102
 
        orb     %al, %al
1103
 
        jnz     1b
1104
 
 
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  */
1109
 
 
1110
 
        cli
1111
 
        movw    %es, %bx
1112
 
 
1113
 
        movw    %bx, %ss
1114
 
        movw    %bx, %sp
1115
 
 
1116
 
        movw    %bx, %ds
1117
 
        movw    %bx, %fs
1118
 
        movw    %bx, %gs
1119
 
 
1120
 
        ljmp    $0x9020, $0
1121
 
 
1122
 
        . = start + 0x600 - 2
1123
 
        .word   0
1124
 
 
1125
 
print_newline:
1126
 
        movw    $ABS(newline), %si
1127
 
        call    print_string
1128
 
        ret
1129
 
 
1130
 
clear_dest:
1131
 
        xorw    %ax, %ax
1132
 
        movw    %ax, gdt_dst_low
1133
 
        movb    %al, gdt_dst_hi1
1134
 
        movb    %al, gdt_dst_hi2
1135
 
        ret
1136
 
 
1137
 
load_data_inc:
1138
 
        pushaw
1139
 
        call    load_data
1140
 
        popaw
1141
 
        addw    %ax, (%si)
1142
 
        adcw    $0, 2(%si)
1143
 
        ret
1144
 
 
1145
 
10:
1146
 
        cmpb    $FBS_TYPE_MSDOS, %al
1147
 
        jnz     10f
1148
 
 
1149
 
        call    find_file
1150
 
        movw    $(DATA_BUF_SEG >> 5), %bx
1151
 
        subw    %ax, %bx
1152
 
        pushw   %ax
1153
 
        pushw   %ax
1154
 
        movw    %bx, %ax
1155
 
        shlw    $9, %ax
1156
 
        movw    %ax, gdt_dst_low
1157
 
        movw    %bx, %ax
1158
 
        shrw    $7, %ax
1159
 
        movb    %al, gdt_dst_hi1
1160
 
        popw    %ax
1161
 
        pushw   %bx
1162
 
        call    load_data
1163
 
        call    copy_bs
1164
 
 
1165
 
        popw    %bx
1166
 
        popw    %ax
1167
 
 
1168
 
        movw    $ABS(iosys_trampoline_start), %si
1169
 
        movw    $(iosys_trampoline_end - iosys_trampoline_start), %cx
1170
 
        movw    $0x200, %di
1171
 
        rep     movsb
1172
 
 
1173
 
        ljmp    $DATA_BUF_SEG, $0x200
1174
 
 
1175
 
10:
1176
 
        movw    $ABS(err_no_type), %si
1177
 
        jmp     fail
1178
 
 
1179
 
#define IOSYS_CM_MAGIC          0x4d43
1180
 
 
1181
 
iosys_trampoline_start:
1182
 
        movw    %es, %cx
1183
 
        movw    %cx, %ss
1184
 
        xorw    %sp, %sp
1185
 
 
1186
 
        addw    $4, %bx
1187
 
        subw    $4, %ax
1188
 
        shlw    $5, %bx
1189
 
 
1190
 
        movw    %bx, %ds
1191
 
        pushw   $0x70
1192
 
        popw    %es
1193
 
 
1194
 
        movw    %ax, %bx
1195
 
 
1196
 
        xorw    %si, %si
1197
 
        xorw    %di, %di
1198
 
 
1199
 
        pushw   %dx
1200
 
 
1201
 
        cmpw    $IOSYS_CM_MAGIC,(%si)
1202
 
        jz      iosys_expand
1203
 
 
1204
 
1:
1205
 
        movw    $256, %cx
1206
 
        rep     movsw
1207
 
 
1208
 
        call    normalize_address
1209
 
 
1210
 
        decw    %bx
1211
 
        jnz     1b
1212
 
 
1213
 
iosys_boot:
1214
 
        popw    %dx
1215
 
        xorw    %ax, %ax
1216
 
        xorw    %bx, %bx
1217
 
        xorw    %bp, %bp
1218
 
        xorw    %di, %di
1219
 
 
1220
 
        pushw   %cs
1221
 
        popw    %ds
1222
 
 
1223
 
        movb    $0xf8, %dh
1224
 
        ljmp    $0x70, $0
1225
 
 
1226
 
iosys_expand:
1227
 
        pushw   %ds
1228
 
        lodsw
1229
 
        pushw   %si
1230
 
 
1231
 
        xorb    %bh, %bh
1232
 
 
1233
 
1:
1234
 
        lodsb
1235
 
        movb    %al, %bl
1236
 
        lodsw
1237
 
        orw     %ax, %ax
1238
 
        jz      1f
1239
 
        addw    %bx, %ax                /* skip the source len field  */
1240
 
        addw    %bx, %ax
1241
 
        addw    %ax, %si
1242
 
        call    normalize_address
1243
 
        jmp     1b
1244
 
 
1245
 
1:
1246
 
 
1247
 
        orw     %si, %si
1248
 
        jz      1f
1249
 
        movw    %ds, %ax
1250
 
        incw    %ax
1251
 
        movw    %ax, %ds
1252
 
1:
1253
 
 
1254
 
        xorw    %si, %si
1255
 
        lodsw
1256
 
        cmpw    $IOSYS_CM_MAGIC, %ax
1257
 
        jnz     iosys_expand_error
1258
 
        lodsw
1259
 
        movw    %ax, %cs: (iosys_expand_func - iosys_trampoline_start + 0x200)
1260
 
        movw    %ds, %cs: (iosys_expand_func - iosys_trampoline_start + 0x200 + 2)
1261
 
 
1262
 
        popw    %si
1263
 
        popw    %ds
1264
 
 
1265
 
1:
1266
 
        call    normalize_address
1267
 
        lodsb
1268
 
        movb    %al, %bl
1269
 
        lodsw
1270
 
        orw     %ax, %ax
1271
 
        jz      iosys_boot
1272
 
        orb     %bl, %bl
1273
 
        jnz     2f
1274
 
 
1275
 
        movw    %ax, %cx                /* uncompressed block  */
1276
 
        rep     movsb
1277
 
        jmp     1b
1278
 
 
1279
 
2:
1280
 
        lodsw                           /* dest length  */
1281
 
        movw    %ax, %cx                /* convert to sector  */
1282
 
        shrw    $9, %ax
1283
 
        andw    $0x1ff, %cx
1284
 
        jz      2f
1285
 
        incw    %ax
1286
 
2:
1287
 
 
1288
 
        movw    %ax, %cx
1289
 
        lodsw                           /* 0x5344  */
1290
 
        lodsw
1291
 
        lodsw
1292
 
        xorw    %dx, %dx
1293
 
 
1294
 
        .byte   0x9a                    /* lcall  */
1295
 
iosys_expand_func:
1296
 
        .word   0, 0
1297
 
        jc      iosys_expand_error
1298
 
 
1299
 
        decw    %si
1300
 
        jmp     1b
1301
 
 
1302
 
iosys_expand_error:
1303
 
        hlt
1304
 
        jmp     iosys_expand_error
1305
 
 
1306
 
normalize_address:
1307
 
        movw    %si, %ax
1308
 
        andw    $0xf, %si
1309
 
        shrw    $4, %ax
1310
 
        movw    %ds, %cx
1311
 
        addw    %cx, %ax
1312
 
        movw    %ax, %ds
1313
 
 
1314
 
        movw    %di, %ax
1315
 
        andw    $0xf, %di
1316
 
        shrw    $4, %ax
1317
 
        movw    %es, %cx
1318
 
        addw    %cx, %ax
1319
 
        movw    %ax, %es
1320
 
        ret
1321
 
 
1322
 
iosys_trampoline_end:
1323
 
 
1324
 
setup_mbr:
1325
 
        pushw   %ds
1326
 
        popw    %es
1327
 
        movw    $8, %cx
1328
 
        movw    $(CODE_START + 0x1be), %si
1329
 
        movw    $(0x800 - 18), %di
1330
 
        pushw   %di
1331
 
        rep     movsw
1332
 
        popw    %si
1333
 
 
1334
 
        movw    orig_es, %es
1335
 
        movw    orig_di, %di
1336
 
 
1337
 
        xorb    %dh, %dh
1338
 
        movb    %dl, ABS(bootdrv)
1339
 
        ret
1340
 
 
1341
 
copy_bs:
1342
 
        pushaw
1343
 
 
1344
 
        xorw    %di, %di
1345
 
        movw    $DATA_BUF_SEG, %ax
1346
 
        movw    %ax, %es
1347
 
        xorw    %bx, %bx
1348
 
        movw    $1, %si
1349
 
 
1350
 
        movw    (CODE_START + 0x1c6), %ax
1351
 
        movw    (CODE_START + 0x1c8), %bp
1352
 
 
1353
 
        pushw   %bp
1354
 
        pushw   %ax
1355
 
 
1356
 
        call    read_sectors
1357
 
 
1358
 
        movb    (0x7c01), %cl
1359
 
        xorb    %ch, %ch
1360
 
 
1361
 
        movw    ABS(spt), %ax
1362
 
 
1363
 
        pushw   %ds
1364
 
        pushw   %es
1365
 
 
1366
 
        popw    %ds
1367
 
        popw    %es
1368
 
 
1369
 
        popw    (0x1c)          /* Hidden sectors  */
1370
 
        popw    (0x1e)
1371
 
 
1372
 
        movb    %al, (0x18)
1373
 
        movb    %ah, (0x1a)
1374
 
 
1375
 
        movw    $2, %si
1376
 
        movw    $0x7c02, %di
1377
 
 
1378
 
        cld
1379
 
        rep     movsb
1380
 
 
1381
 
        pushw   %ds
1382
 
        pushw   %es
1383
 
 
1384
 
        popw    %ds
1385
 
        popw    %es
1386
 
 
1387
 
        popaw
1388
 
        ret
1389
 
 
1390
 
#if 0
1391
 
 
1392
 
dump_reg:
1393
 
        pushw   %cx
1394
 
        pushaw
1395
 
        movw    $8, %cx
1396
 
1:
1397
 
        call    dump_hex
1398
 
        loop    1b
1399
 
        popw    %cx
1400
 
        ret
1401
 
 
1402
 
/*
1403
 
 * input:
1404
 
 *   22(%bp) - len
1405
 
 *   20(%bp) - seg
1406
 
 *   18(%bp) - ofs
1407
 
 */
1408
 
dump_mem:
1409
 
        pushaw
1410
 
        movw    %sp, %bp
1411
 
        pushw   %ds
1412
 
 
1413
 
        ldsw    18(%bp), %si
1414
 
1:
1415
 
        pushw   (%si)
1416
 
        addw    $2, %si
1417
 
        call    dump_hex
1418
 
        decw    22(%bp)
1419
 
        jnz     1b
1420
 
 
1421
 
        popw    %ds
1422
 
        popaw
1423
 
        ret     $6
1424
 
 
1425
 
#endif
1426
 
 
1427
 
menu_file:
1428
 
        .ascii  FB_MENU_FILE "\0"
1429
 
 
1430
 
err_int15:
1431
 
        .ascii  "int15\0"
1432
 
 
1433
 
err_no_file:
1434
 
        .ascii  "no file\0"
1435
 
 
1436
 
err_no_menu:
1437
 
        .ascii  "no menu\0"
1438
 
 
1439
 
err_no_type:
1440
 
        .ascii  "no type\0"
1441
 
 
1442
 
loading_message:
1443
 
        .ascii  "Loading \0"
1444
 
 
1445
 
dot_message:
1446
 
        .ascii  ".\0"
1447
 
 
1448
 
newline:
1449
 
        .ascii  "\r\n\0"
1450
 
 
1451
 
start_menu: