OSDN Git Service

lib-fs-resize: remove unused probe-related code
[android-x86/external-parted.git] / libparted / mbr.s
1 ;   libparted - a library for manipulating disk partitions
2 ;   Copyright (C) 1999-2000, 2007, 2009-2012 Free Software Foundation, Inc.
3 ;
4 ;   This program is free software; you can redistribute it and/or modify
5 ;   it under the terms of the GNU General Public License as published by
6 ;   the Free Software Foundation; either version 3 of the License, or
7 ;   (at your option) any later version.
8 ;
9 ;   This program is distributed in the hope that it will be useful,
10 ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ;   GNU General Public License for more details.
13 ;
14 ;   You should have received a copy of the GNU General Public License
15 ;   along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 ; NOTE: I build this with:
18 ;       $ as86 -b /dev/stdout mbr.s | hexdump -e '8/1 "0x%02x, " "\n"'
19 ;
20 ; The build isn't done automagically by make, because as86 may not be on many
21 ; machines (particularly non-x86).  Also, it seems rather difficult to get
22 ; as86 to build object files that can be linked, especially as it's 16 bit
23 ; code...
24
25 USE16
26
27 ; This code, plus the partition table is loaded into 0000:7C00 by the BIOS
28
29 .text
30
31 ; set top of stack to 1000:B000
32
33         cli
34
35         mov     ax, #0x1000
36         mov     ss, ax
37         mov     sp, #0xB000
38
39         mov     ax, #0x0000
40         mov     ds, ax
41         mov     es, ax
42
43         sti
44
45 ; Copy what the BIOS loaded (i.e. the MBR + head of partition table) from
46 ; 0000:7c00 to 0000:0600
47
48         mov     si, #0x7c00
49         mov     di, #0x0600
50         mov     cx, #0x200
51         rep
52         movsb
53
54 ; Jump to the copy of the MBR
55
56         jmp     0x0000:find_boot_partition + 0x0600
57
58 find_boot_partition:
59         mov     si, #0x07BE
60
61 check_next_bootable:
62         cmp     [si], al
63         jnz     found_bootable
64         add     si, #0x0010
65         cmp     si, #0x07FE
66         jnz     check_next_bootable
67         jmp     error
68
69 found_bootable:
70
71 ; Load in the boot sector at 0000:7c00
72
73         mov     ah, #2                  ; BIOS command (read)
74         mov     al, #1                  ; count
75         mov     bx, #0x7c00             ; destination pointer
76         mov     dl, #0x80               ; drive
77         mov     dh, byte ptr [si + 1]   ; head
78         mov     cx, word ptr [si + 2]   ; sector / cylinder
79         int     #0x13                   ; BIOS read interrupt
80
81         jmp     0x0000:0x7c00           ; hand control to boot sector
82
83 error:
84         jmp     error