Separated multiboot kernel loader and reactos kernel loader so that support for other...
[reactos.git] / freeldr / bootsect / win2k.asm
1 segment .text
2
3 bits 16
4
5 start:
6 jmp short main
7 nop
8
9 OEMName db 'FreeLDR!'
10 BytesPerSector dw 512
11 SectsPerCluster db 1
12 ReservedSectors dw 1
13 NumberOfFats db 2
14 MaxRootEntries dw 0 ;512 - Always zero for FAT32 volumes
15 TotalSectors dw 0 ;2880 - Always zero for FAT32 volumes
16 MediaDescriptor db 0f8h
17 SectorsPerFat dw 0 ;9 - Always zero for FAT32 volumes
18 SectorsPerTrack dw 18
19 NumberOfHeads dw 2
20 HiddenSectors dd 0
21 TotalSectorsBig dd 0
22 ; FAT32 Inserted Info
23 SectorsPerFatBig dd 0
24 ExtendedFlags dw 0
25 FSVersion dw 0
26 RootDirStartCluster dd 0
27 FSInfoSector dw 0
28 BackupBootSector dw 6
29 Reserved1 times 12 db 0
30 ; End FAT32 Inserted Info
31 BootDrive db 0
32 Reserved db 0
33 ExtendSig db 29h
34 SerialNumber dd 00000000h
35 VolumeLabel db 'FreeLoader!'
36 FileSystem db 'FAT12 '
37
38 main:
39 00007C5A 33C9 xor cx,cx
40 00007C5C 8ED1 mov ss,cx
41 00007C5E BCF47B mov sp,0x7bf4
42 00007C61 8EC1 mov es,cx
43 00007C63 8ED9 mov ds,cx
44 00007C65 BD007C mov bp,0x7c00
45 00007C68 884E02 mov [bp+0x2],cl
46 00007C6B 8A5640 mov dl,[bp+BootDrive]
47 00007C6E B408 mov ah,0x8
48 00007C70 CD13 int 0x13 ; Int 13, func 8 - Get Drive Parameters
49 00007C72 7305 jnc 0x7c79 ; If no error jmp
50
51 00007C74 B9FFFF mov cx,0xffff
52 00007C77 8AF1 mov dh,cl
53
54 00007C79 660FB6C6 movzx eax,dh
55 00007C7D 40 inc ax
56 00007C7E 660FB6D1 movzx edx,cl
57 00007C82 80E23F and dl,0x3f
58 00007C85 F7E2 mul dx
59 00007C87 86CD xchg cl,ch
60 00007C89 C0ED06 shr ch,0x6
61 00007C8C 41 inc cx
62 00007C8D 660FB7C9 movzx ecx,cx
63 00007C91 66F7E1 mul ecx
64 00007C94 668946F8 mov [bp-0x8],eax
65 00007C98 837E1600 cmp word [bp+TotalSectors],byte +0x0
66 00007C9C 7538 jnz print_ntldr_error_message
67
68 00007C9E 837E2A00 cmp word [bp+FSVersion],byte +0x0
69 00007CA2 7732 ja print_ntldr_error_message
70
71 00007CA4 668B461C mov eax,[bp+0x1c]
72 00007CA8 6683C00C add eax,byte +0xc
73 00007CAC BB0080 mov bx,0x8000
74 00007CAF B90100 mov cx,0x1
75 00007CB2 E82B00 call read_sectors
76 00007CB5 E94803 jmp 0x8000
77
78 print_disk_error_message:
79 00007CB8 A0FA7D mov al,[DISK_ERR_offset_from_0x7d00]
80 putchars:
81 00007CBB B47D mov ah,0x7d
82 00007CBD 8BF0 mov si,ax
83 get_another_char:
84 00007CBF AC lodsb
85 00007CC0 84C0 test al,al
86 00007CC2 7417 jz reboot
87 00007CC4 3CFF cmp al,0xff
88 00007CC6 7409 jz print_reboot_message
89 00007CC8 B40E mov ah,0xe
90 00007CCA BB0700 mov bx,0x7
91 00007CCD CD10 int 0x10
92 00007CCF EBEE jmp short get_another_char
93 print_reboot_message:
94 00007CD1 A0FB7D mov al,[RESTART_ERR_offset_from_0x7d00]
95 00007CD4 EBE5 jmp short putchars
96 print_ntldr_error_message:
97 00007CD6 A0F97D mov al,[NTLDR_ERR_offset_from_0x7d00]
98 00007CD9 EBE0 jmp short putchars
99 reboot:
100 00007CDB 98 cbw
101 00007CDC CD16 int 0x16
102 00007CDE CD19 int 0x19
103
104 read_sectors:
105 00007CE0 6660 pushad
106 00007CE2 663B46F8 cmp eax,[bp-0x8]
107 00007CE6 0F824A00 jc near 0x7d34
108 00007CEA 666A00 o32 push byte +0x0
109 00007CED 6650 push eax
110 00007CEF 06 push es
111 00007CF0 53 push bx
112 00007CF1 666810000100 push dword 0x10010
113 00007CF7 807E0200 cmp byte [bp+0x2],0x0
114 00007CFB 0F852000 jnz near 0x7d1f
115 00007CFF B441 mov ah,0x41
116 00007D01 BBAA55 mov bx,0x55aa
117 00007D04 8A5640 mov dl,[bp+BootDrive]
118 00007D07 CD13 int 0x13
119 00007D09 0F821C00 jc near 0x7d29
120 00007D0D 81FB55AA cmp bx,0xaa55
121 00007D11 0F851400 jnz near 0x7d29
122 00007D15 F6C101 test cl,0x1
123 00007D18 0F840D00 jz near 0x7d29
124 00007D1C FE4602 inc byte [bp+0x2]
125 00007D1F B442 mov ah,0x42
126 00007D21 8A5640 mov dl,[bp+BootDrive]
127 00007D24 8BF4 mov si,sp
128 00007D26 CD13 int 0x13
129 00007D28 B0F9 mov al,0xf9
130 00007D2A 6658 pop eax
131 00007D2C 6658 pop eax
132 00007D2E 6658 pop eax
133 00007D30 6658 pop eax
134 00007D32 EB2A jmp short 0x7d5e
135 00007D34 6633D2 xor edx,edx
136 00007D37 660FB74E18 movzx ecx,word [bp+SectorsPerTrack]
137 00007D3C 66F7F1 div ecx
138 00007D3F FEC2 inc dl
139 00007D41 8ACA mov cl,dl
140 00007D43 668BD0 mov edx,eax
141 00007D46 66C1EA10 shr edx,0x10
142 00007D4A F7761A div word [bp+NumberOfHeads]
143 00007D4D 86D6 xchg dl,dh
144 00007D4F 8A5640 mov dl,[bp+BootDrive]
145 00007D52 8AE8 mov ch,al
146 00007D54 C0E406 shl ah,0x6
147 00007D57 0ACC or cl,ah
148 00007D59 B80102 mov ax,0x201
149 00007D5C CD13 int 0x13
150 00007D5E 6661 popad
151 00007D60 0F8254FF jc near print_disk_error_message
152 00007D64 81C30002 add bx,0x200
153 00007D68 6640 inc eax
154 00007D6A 49 dec cx
155 00007D6B 0F8571FF jnz near read_sectors
156 00007D6F C3 ret
157
158 NTLDR db 'NTLDR '
159
160 filler times 49 db 0
161
162 NTLDR_ERR db 0dh,0ah,'NTLDR is missing',0ffh
163 DISK_ERR db 0dh,0ah,'Disk error',0ffh
164 RESTART_ERR db 0dh,0ah,'Press any key to restart',0dh,0ah
165
166 more_filler times 16 db 0
167
168 NTLDR_offset_from_0x7d00 db 0
169 NTLDR_ERR_offset_from_0x7d00 db 0ach
170 DISK_ERR_offset_from_0x7d00 db 0bfh
171 RESTART_ERR_offset_from_0x7d00 db 0cch
172
173 dw 0
174 dw 0aa55h