OSDN Git Service

tests: adjust cleanup_ handler to work with init.sh
[android-x86/external-parted.git] / libparted / mbr.s
1 ;   libparted - a library for manipulating disk partitions
2 ;   Copyright (C) 1999-2000, 2007, 2009-2010 Free Software Foundation,
3 ;   Inc.
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 ; NOTE: I build this with:
19 ;       $ as86 -b /dev/stdout mbr.s | hexdump -e '8/1 "0x%02x, " "\n"'
20 ;
21 ; The build isn't done automagically by make, because as86 may not be on many
22 ; machines (particularly non-x86).  Also, it seems rather difficult to get
23 ; as86 to build object files that can be linked, especially as it's 16 bit
24 ; code...
25
26 USE16
27
28 ; This code, plus the partition table is loaded into 0000:7C00 by the BIOS
29
30 .text
31
32 ; set top of stack to 1000:B000
33
34         cli
35
36         mov     ax, #0x1000
37         mov     ss, ax
38         mov     sp, #0xB000
39
40         mov     ax, #0x0000
41         mov     ds, ax
42         mov     es, ax
43
44         sti
45
46 ; Copy what the BIOS loaded (i.e. the MBR + head of partition table) from
47 ; 0000:7c00 to 0000:0600
48
49         mov     si, #0x7c00
50         mov     di, #0x0600
51         mov     cx, #0x200
52         rep
53         movsb
54
55 ; Jump to the copy of the MBR
56
57         jmp     0x0000:find_boot_partition + 0x0600
58
59 find_boot_partition:
60         mov     si, #0x07BE
61
62 check_next_bootable:
63         cmp     [si], al
64         jnz     found_bootable
65         add     si, #0x0010
66         cmp     si, #0x07FE
67         jnz     check_next_bootable
68         jmp     error
69
70 found_bootable:
71
72 ; Load in the boot sector at 0000:7c00
73
74         mov     ah, #2                  ; BIOS command (read)
75         mov     al, #1                  ; count
76         mov     bx, #0x7c00             ; destination pointer
77         mov     dl, #0x80               ; drive
78         mov     dh, byte ptr [si + 1]   ; head
79         mov     cx, word ptr [si + 2]   ; sector / cylinder
80         int     #0x13                   ; BIOS read interrupt
81
82         jmp     0x0000:0x7c00           ; hand control to boot sector
83
84 error:
85         jmp     error