1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
BITS 16
ORG 0x7C00
%define INODE_ADDRESS 0xF000
%define INODE_NBLOCKS 20
%define INODE_DBP0 24
; Save the boot drive id
mov [bootDriveID], dl
jmp start
print:
mov ah, 0x0E
xor bh, bh
.print_L:
lodsb
test al, al
jz .print_end
int 0x10
jmp .print_L
.print_end:
ret
bootDriveID: db 0
dapack:
dapack_size: db 0x10
dapack_null: db 0x00
dapack_blkcount: dw 0x0001
dapack_boffset: dw 0x8000
dapack_bsegment: dw 0x0000
dapack_start: dd 0x00000000
dapack_upper_lba_bits: dd 0x00000000
readsector:
mov dword [dapack_start], eax
mov ah, 0x42
mov dl, [bootDriveID]
xor bx, bx
mov ds, bx
mov si, dapack
int 0x13
ret
; 5K max
readwholefile:
mov bx, word [dapack_boffset]
push bx
mov bx, INODE_ADDRESS
mov word [dapack_boffset], bx
call readsector
pop bx
mov word [dapack_boffset], bx
mov edx, [INODE_ADDRESS+INODE_NBLOCKS]
xor ecx, ecx
.readwholefile_L:
lea bx, [INODE_ADDRESS + INODE_DBP0 + (ecx*4)]
mov eax, dword [bx]
push dx
call readsector
pop dx
add dword [dapack_boffset], 512
inc cx
cmp cx, dx
jl .readwholefile_L
ret
welcome db "Melvix", 0x0A, 0x0D, 0x00
nolba db "BIOS lacks support for lba addressing.", 0x00
signaturebad db "Bad disk signature.", 0x00
start:
mov ax, 0x0003
int 0x10
mov si, welcome
call print
mov ah, 0x41
mov bx, 0x55AA
int 0x13
jc lba_not_supported
cmp bx, 0xAA55
jnz lba_not_supported
mov eax, 1
call readsector
mov eax, [0x8000+0]
cmp eax, 0x34B59645
jnz signature_BAD
mov eax, [0x8000+4]
cmp eax, 0x1083B99F
jnz signature_BAD
mov eax, 2
call readwholefile
jmp 0x8000
lba_not_supported:
mov si, nolba
call print
jmp $
signature_BAD:
mov si, signaturebad
call print
jmp $
times 510-($-$$) db 0
dw 0xAA55
|