source: trunk/BOOTCODE/REGULAR/PARTMAIN.ASM@ 43

Last change on this file since 43 was 43, checked in by Ben Rietbroek, 12 years ago

BSS Corruption Problem located (auxdebug on) [2012-02-21]

WARNING!!

All commits upto and including the commit of [2012-05-13] contain
a severe bug!! Building from these sources and then disabling
the 'force LBA' feature while also using the drive-letter feature or
editing the label can DESTROY THE MBR on ALL ATTACHED DISKS!!
DO NOT DISABLE 'FORCE LBA USAGE' WHEN BUILT FROM THE THESE COMMITS!!

Problem

o Function with Xrefs goes out-of-bounds because hideparttable is too small

Has only 30 entries and should be 45.
Lost partition checker initializes out-of-bounds.

Info

o About the hideparttable

For each partition it can be specified which other partitions need to
be hidden when that partition is booted. This is useful for legacy DOS
but also braindead Windows that presents HPFS/JFS partitions as
unformatted and tries to persuade the user to format them.
With v1.07 the numer of partitions that can be handled was expanded from
30 to 45, but the size of the hideparttable was overseen.

o The need to compress the hideparttable

The old size was 30x30=900 bytes while the required size is 45x45=2045 bytes.
This amount of space is not available in the image.
Since 6 bits are enough to identify the partition number to be hidden,
the solution is to devide the table into bitfields. This will result
in a table of (45*45*6)/8=1519 bytes, which can be fitted.

Changes

Revamped the sources quite a bit and moved the history to a separate
file. (AIR-BOOT.HIS)

New

o FIXCODE script for Linux

Just until the C version is ready...

File size: 66.4 KB
Line 
1; AiR-BOOT (c) Copyright 1998-2008 M. Kiewitz
2;
3; This file is part of AiR-BOOT
4;
5; AiR-BOOT is free software: you can redistribute it and/or modify it under
6; the terms of the GNU General Public License as published by the Free
7; Software Foundation, either version 3 of the License, or (at your option)
8; any later version.
9;
10; AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY
11; WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS
12; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13; details.
14;
15; You should have received a copy of the GNU General Public License along with
16; AiR-BOOT. If not, see <http://www.gnu.org/licenses/>.
17;
18;---------------------------------------------------------------------------
19; AiR-BOOT / PARTiTiON REGULAR ROUTINES
20;---------------------------------------------------------------------------
21
22IFDEF ModuleNames
23DB 'PARTMAIN',0
24ENDIF
25
26PART_FixUpDefaultPartitionValues Proc Near Uses dx si di
27 ; Fix-Up Default and Last Partition - If lost, search for Bootable
28 xor bl, bl
29 mov dl, CFG_PartDefault
30 call PART_FixUpSelectionNumber
31 mov CFG_PartDefault, dl
32 mov dl, CFG_PartLast
33 call PART_FixUpSelectionNumber
34 mov CFG_PartLast, dl
35 mov dl, CFG_PartAutomatic
36 call PART_FixUpSelectionNumber
37 mov CFG_PartAutomatic, dl
38
39; [Linux support removed since v1.02]
40; ; Fix-Up Linux Kernel Partition - If lost, search for FAT-16
41; mov bl, 06h
42; mov dl, CFG_LinuxKrnlPartition
43; call PART_FixUpPartitionNumber
44; mov CFG_LinuxKrnlPartition, dl
45;
46; ; Fix-Up Linux Root Partition - If lost, search for Linux partition (83h)
47; mov bl, 83h
48; mov dl, CFG_LinuxRootPartition
49; call PART_FixUpPartitionNumber
50; mov CFG_LinuxRootPartition, dl
51 ret
52PART_FixUpDefaultPartitionValues EndP
53
54; Our resync process for partition number is as specified:
55;==========================================================
56; - If 0FFh -> Partition Disabled, so don't do anything to it...
57; - Try to use GetXref to get the new partition no via X-Ref Table
58; - If failed, increase partition no, till overflow or hit on specific
59; characteristic
60; On overflow -> Resume search from partition no 0
61;
62; Characteristic is a partition id. If this id is 0, then a bootable partition
63; is searched for.
64
65; Fixes a partition number, adjusting it to the new IPT after redetect
66; In: DL - Number of partition
67; BL - Requested Partition ID
68; Out: DL - New number of partition (guessed normally ;)
69PART_FixUpSelectionNumber Proc Near Uses ax cx
70 cmp dl, 080h
71 je PFUPN_SelectionDisabled
72 ja PFUPN_SpecialSelection
73 call PARTSCAN_GetXref ; DL - PartitionNo prev IPT
74 cmp dh, 0FFh ; DH -> Partition No in new IPT
75 je PFUPN_SelectionGone
76 mov dl, dh
77 PFUPN_SelectionDisabled:
78 ret
79
80 PFUPN_SpecialSelection:
81 cmp dl, 0FEh ; Resume-BIOS?
82 ja PFUPN_SpecialSelectionFloppy
83 cmp CFG_ResumeBIOSbootSeq, 0
84 je PFUPN_SelectionGone
85 jmp PFUPN_Found
86 PFUPN_SpecialSelectionFloppy:
87 cmp CFG_IncludeFloppy, 0
88 je PFUPN_SelectionGone
89 jmp PFUPN_Found
90
91 ; Partition is not referenced in New-IPT or Resume-BIOS/Floppy selected, but
92 ; actual media is disabled...so dig for requested partition
93 PFUPN_SelectionGone:
94 mov cl, CFG_Partitions
95 or cl, cl
96 jz PFUPN_NothingFound ; No partitions available -> so fail
97 or bl, bl
98 jz PFUPN_BootableSearchLoop
99 ; Search for Partition ID "BL"
100 PFUPN_PartIDsearchLoop:
101 call PART_GetPartitionPointer ; Gets SI for partition DL
102 cmp bptr ds:[si+LocIPT_SystemID], bl
103 je PFUPN_Found
104 dec cl
105 jz PFUPN_NothingFound
106 inc dl ; Increase
107 cmp CFG_Partitions, dl
108 ja PFUPN_PartIDsearchLoop
109 xor dl, dl
110 jmp PFUPN_PartIDsearchLoop
111
112 ; Search for Partition ID "BL"
113 PFUPN_BootableSearchLoop:
114 call PART_GetPartitionPointer ; Gets SI for partition DL
115 mov al, ds:[si+LocIPT_Flags]
116 and al, Flags_Bootable
117 jnz PFUPN_Found
118 dec cl
119 jz PFUPN_NothingFound
120 inc dl ; Increase
121 cmp CFG_Partitions, dl
122 ja PFUPN_PartIDsearchLoop
123 xor dl, dl
124 jmp PFUPN_PartIDsearchLoop
125
126 PFUPN_NothingFound:
127 mov dl, 080h ; Now being Disabled
128 PFUPN_Found:
129 ret
130PART_FixUpSelectionNumber EndP
131
132; ============================================================================
133; In: DS:SI - IPT-Entry of partition
134; DS:PartitionSector - Actual Boot-Record of partition
135; Out: *none* (BootRecordCRD updated)
136PART_UpdateBootRecordCRC Proc Near Uses bx
137 mov si, offset PartitionSector
138 mov bx, 4B4Dh ; Magic: 'MK'
139 call MBR_GetCheckOfSector
140 mov [si+LocIPT_BootRecordCRC], bx
141 ret
142PART_UpdateBootRecordCRC EndP
143
144; Copies the device-name to the Resume-BIOS IPT entry
145PART_UpdateResumeBIOSName Proc Near Uses ax bx cx si di
146 ;movzx bx, CFG_ResumeBIOSbootSeq
147 mov bl,CFG_ResumeBIOSbootSeq
148 mov bh,0
149
150 dec bx
151 shl bx, 1
152 mov si, wptr [ContinueBIOSbootTable+bx]
153 mov di, offset BIOScontIPTentry+LocIPT_Name
154 push di
155 mov cx, 11
156 mov al, ' '
157 rep stosb
158 pop di
159 PURBN_BootDeviceCopyLoop:
160 lodsb
161 or al, al
162 jz PURBN_NoResumeBootSeq
163 stosb
164 jmp PURBN_BootDeviceCopyLoop
165 PURBN_NoResumeBootSeq:
166 ret
167PART_UpdateResumeBIOSName EndP
168
169; ============================================================================
170; Partition-Pointer Functions
171; ============================================================================
172
173; Builds Pointer-Table straight (without filtering, w/o Floppy/CD-ROM/Kernels)
174PART_CalculateStraightPartPointers Proc Near
175 mov ax, offset PartitionTable
176 mov bx, offset PartitionPointers
177 mov cx, LocIPT_MaxPartitions
178 PCSPP_Loop:
179 mov ds:[bx], ax
180 add bx, 2
181 add ax, LocIPT_LenOfIPT
182 dec cx
183 jnz PCSPP_Loop
184 mov al, ds:[CFG_Partitions]
185 mov ds:[PartitionPointerCount], al
186 ret
187PART_CalculateStraightPartPointers EndP
188
189; This here does PartitionPointers in order for displaying in BootMenu
190; [this means filtering and including Floppy/CD-ROM/Kernels, if wanted]
191PART_CalculateMenuPartPointers Proc Near Uses si
192 mov si, offset PartitionTable
193 mov bx, offset PartitionPointers
194 test CFG_IncludeFloppy, 1
195 jz PCMPP_NoFloppyInclude
196 mov ax, offset FloppyIPTentry
197 mov ds:[bx], ax
198 add bx, 2
199 PCMPP_NoFloppyInclude:
200
201 test CFG_ResumeBIOSbootSeq, 0FFh
202 jz PCMPP_NoResumeBootSeqInclude
203 mov ax, offset BIOScontIPTentry
204 mov ds:[bx], ax
205 add bx, 2
206 PCMPP_NoResumeBootSeqInclude:
207
208; [Linux support removed since v1.02]
209; ; Now include all Linux Kernels, if any available...
210; movzx cx, LINUX_KernelNo
211; or cx, cx
212; jz PCMPP_NoLinuxKernels
213; mov ax, offset LINUX_KernelEntries
214; PCMPP_KernelLoop:
215; mov ds:[bx], ax
216; add bx, 2
217; add ax, LocIPT_LenOfIPT
218; dec cx
219; jnz PCMPP_KernelLoop
220; PCMPP_NoLinuxKernels:
221
222 ;movzx cx, CFG_Partitions ; LocIPT_MaxPartitions
223 mov cl,CFG_Partitions ; LocIPT_MaxPartitions
224 mov ch,0
225
226 or cx, cx
227 jz PCMPP_NoPartitions
228 PCMPP_Loop:
229 mov al, ds:[si+LocIPT_Flags]
230 and al, Flags_Bootable
231 jz PCMPP_IsNotBootable
232 mov ds:[bx], si
233 add bx, 2
234 PCMPP_IsNotBootable:
235 add si, LocIPT_LenOfIPT
236 dec cx
237 jnz PCMPP_Loop
238 PCMPP_NoPartitions:
239 sub bx, offset PartitionPointers
240 shr bx, 1
241 mov ds:[PartitionPointerCount], bl
242 ret
243PART_CalculateMenuPartPointers EndP
244
245; Gets a pointer to the given partition
246; In: DL - Number of partition
247; Out: SI - Pointer to it
248PART_GetPartitionPointer Proc Near Uses bx
249 cmp dl, 0FEh
250 je PGPP_IsBIOSbootSeq ; FEh -> Resume BIOS boot Sequence
251 ja PGPP_IsFloppy ; FFh -> Floppy
252 ;movzx bx, dl
253 mov bl,dl
254 mov bh,0
255
256 shl bx, 1
257 mov si, wptr [PartitionPointers+bx]
258 ret
259 PGPP_IsBIOSbootSeq:
260 mov si, offset BIOScontIPTentry
261 ret
262 PGPP_IsFloppy:
263 mov si, offset FloppyIPTentry ; PartitionTable-LocIPT_LenOfIPT
264 ret
265PART_GetPartitionPointer EndP
266
267; Gets the number of a partition pointer
268; In: SI - Pointer to Partition
269; Out: DL - Number of partition
270PART_GetPartitionNumber Proc Near Uses bx
271 mov dl, ds:[PartitionPointerCount]
272 mov bx, offset PartitionPointers
273 PGPN_SearchLoop:
274 cmp wptr ds:[bx], si
275 je PGPN_Found
276 add bx, 2
277 dec dl
278 jnz PGPN_SearchLoop
279 mov dl, 0FFh
280 ret
281 PGPN_Found:
282 sub dl, ds:[PartitionPointerCount]
283 dec dl
284 not dl
285 ret
286PART_GetPartitionNumber EndP
287
288; Following functions are only usable, when Partition-Pointer-View is filtered
289; They will convert from and to unfiltered view (used in Boot-Menu)
290; In: DL - Number of partition in filtered view
291; Out: DL - Number of partition in straight view
292PART_ConvertToStraight Proc Near
293 ;movzx bx, dl
294 mov bl,dl ; partition number to bl
295 mov bh,0 ; zero extend to word
296
297 shl bx, 1 ; convert to word index
298 mov ax, wptr cs:[PartitionPointers+bx] ; get the partition pointer
299 cmp ax, offset FloppyIPTentry
300 jb PCTS_IsBIOSbootSeq
301 je PCTS_IsFloppy
302; [Linux support removed since v1.02]
303; cmp ax, offset LINUX_KernelEntries
304; jae PCTS_IsKernelEntry
305 sub ax, offset PartitionTable
306 mov bl, LocIPT_LenOfIPT
307 div bl ; Divide with IPTlength
308 mov dl, al
309 ret
310; [Linux support removed since v1.02]
311; PCTS_IsKernelEntry:
312; mov dl, 0FDh
313; ret
314 PCTS_IsBIOSbootSeq:
315 mov dl, 0FEh
316 ret
317 PCTS_IsFloppy:
318 mov dl, 0FFh
319 ret
320PART_ConvertToStraight EndP
321
322; In: DL - Number of partition in straight view
323; Out: DL - Number of partition in filtered view
324PART_ConvertFromStraight Proc Near Uses es di
325 cmp dl, 0FEh
326 jb PCFS_IsPartition
327 mov ax, offset BIOScontIPTentry
328 je PCFS_DoSearch
329 mov ax, offset FloppyIPTentry
330 jmp PCFS_DoSearch
331 PCFS_IsPartition:
332 ; First we get Partition-Offset in AX
333 ;movzx ax, dl
334 mov al,dl
335 mov ah,0
336
337 mov bl, LocIPT_LenOfIPT
338 mul bl
339 add ax, offset PartitionTable
340 PCFS_DoSearch:
341 ; Now search for this offset in our filtered Partition-Pointer-Table
342 push cs
343 pop es
344 mov di, offset PartitionPointers
345 mov cx, LocIPT_MaxPartitions
346 xor dl, dl ; Reply on Not-Found = Partition==0
347 repne scasw ; Compare-Loop
348 jne PCFS_NotFound
349 sub di, 2 ; One Back, so point to compared value
350 mov dx, di
351 sub dx, offset PartitionPointers
352 shr dx, 1
353 ; Adjust for IncludeFloppy/etc. is automatically done, due Pointer-LookUp
354 PCFS_NotFound:
355 ret
356PART_ConvertFromStraight EndP
357
358; In: AX - Pointer to IPT Entry
359; Out: SI - Pointer to corresponding Size-Element
360; Destroyed: AX
361PART_GetSizeElementPointer Proc Near Uses bx
362; [Linux support removed since v1.02]
363; cmp ax, offset LINUX_KernelEntries
364; jae PGSEP_IsKernelEntry
365 mov si, offset PartitionSizeTable
366 sub ax, offset PartitionTable
367; jmp PGSEP_Continue
368; [Linux support removed since v1.02]
369; PGSEP_IsKernelEntry:
370; mov si, offset LINUX_KernelSizeTable
371; sub ax, offset LINUX_KernelEntries
372; PGSEP_Continue:
373 mov bl, LocIPT_LenOfIPT
374 div bl ; Divide with IPTlength
375 ;movzx bx, al
376 mov bl,al
377 mov bh,0
378
379 shl ax, 1
380 shl bx, 2
381 add ax, bx ; My way of multiplying with 6
382 add si, ax ; SI - Partition Size-Element
383 ret
384PART_GetSizeElementPointer EndP
385
386; In: BX:AX - Sector Size (1=512 Bytes, 2=1024 Bytes, etc.)
387; ES:DI - Pointer to Size-Element (6 bytes)
388; Out: None, Size-Element filled out
389; Destroyed: AX, BX, DI
390PART_FillOutSizeElement Proc Near Uses cx dx
391 add di, 3 ; ES:DI - Last Digit of Size Digits
392 shr bx, 1
393 rcr ax, 1 ; /2 -> Sector Size is now KByte Size
394 xor cl, cl ; 0 - KByte, 1 - MByte, 2 - GByte
395 PFOSE_MakeSmallerLoop:
396 or bx, bx
397 jnz PFOSE_MakeSmaller
398 cmp ax, 9999
399 jbe PFOSE_IsSmallEnough
400 PFOSE_MakeSmaller:
401 mov dx, bx
402 and dx, 1023 ; My crazy way of dividing a 32-bit
403 shr ax, 10 ; value through 1024 using 16-bit
404 shr bx, 10 ; instructions...
405 shl dx, 6
406 or ax, dx
407 inc cl ; Value got smaller...
408 jmp PFOSE_MakeSmallerLoop
409
410 PFOSE_IsSmallEnough:
411 ; First write the type of this Size-Element (KB/MB/GB)
412 mov bx, 'BK'
413 cmp cl, 1
414 jb PFOSE_WriteType
415 je PFOSE_IsMBtype
416 mov bx, 'BG'
417 jmp PFOSE_WriteType
418 PFOSE_IsMBtype:
419 mov bx, 'BM'
420 PFOSE_WriteType:
421 mov wptr es:[di+1], bx
422 mov bx, 10 ; Digits are 10-Based
423 xor dx, dx
424 PFOSE_DigitLoop:
425 xor dx, dx
426 div bx ; AX - Digit, DX - Remainder
427 add dl, '0' ; Convert digit to ASCII digit
428 mov es:[di], dl
429 or ax, ax
430 jz PFOSE_EndOfDigitLoop
431 dec di ; Go to previous char
432 jmp PFOSE_DigitLoop
433
434 PFOSE_EndOfDigitLoop:
435 ret
436PART_FillOutSizeElement EndP
437
438
439
440
441
442
443
444
445
446
447
448; This routine is called to hide a partition
449; In: DL - Partition to hide
450; Destroyed: None
451PART_HidePartition Proc Near Uses ax bx cx dx si di
452 call PART_GetPartitionPointer ; Pointer to partition (DL) -> SI
453
454 ; First load the partition table of that partition...
455 mov ax, wptr [si+LocIPT_AbsolutePartTable+0]
456 mov bx, wptr [si+LocIPT_AbsolutePartTable+2]
457 mov cx, wptr [si+LocIPT_LocationPartTable+1]
458 mov dh, bptr [si+LocIPT_LocationPartTable+0]
459 mov dl, [si+LocIPT_Drive]
460 call DriveIO_LoadPartition
461 ; Partition-Table now LOADED
462 mov di, offset PartitionSector+446 ; ES:DI - 1st partitionentry...
463
464 ; Put our partition's location into registers...
465 mov ax, wptr [si+LocIPT_AbsoluteBegin+0]
466 mov bx, wptr [si+LocIPT_AbsoluteBegin+2]
467 sub ax, wptr [si+LocIPT_AbsolutePartTable+0]
468 sbb bx, wptr [si+LocIPT_AbsolutePartTable+2]
469 ; BX:AX - absolute position of partition relative to partition table
470 ; ...and search for it...
471 PHP_SearchLoop:
472 cmp ax, wptr es:[di+LocBRPT_RelativeBegin]
473 jne PHP_SearchMismatch
474 cmp bx, wptr es:[di+LocBRPT_RelativeBegin+2]
475 jne PHP_SearchMismatch
476 jmp PHP_SearchMatch
477 PHP_SearchMismatch:
478 add di, LocBRPT_LenOfEntry ; 16 Bytes per partition entry
479 cmp di, 500+offset PartitionSector
480 jb PHP_SearchLoop
481 jmp MBR_HaltSystem ; not found, something is wrong here
482
483 ; Found entry...
484 PHP_SearchMatch:
485 mov al, bptr es:[di+LocBRPT_SystemID] ; Partition-ID into AL
486 call PART_SearchFileSysHiddenID ; Put on =STEALTH=
487 mov bptr es:[di+LocBRPT_SystemID], al
488 IFDEF ReleaseCode
489 call DriveIO_SavePartition ; Saves Partition-Table
490 ENDIF
491 ret
492PART_HidePartition EndP
493
494; This here is for marking the first "good" non-hidden partition as being
495; active. It requires the partition table at EXECBASE.
496; Some BIOSes have problems with no primary marked active. Actually this is
497; a buggy implementation, because the MBR-code should normally check,
498; *not* the BIOS. This one *could* cause havoc to some systems, but I can't
499; do anything else.
500PART_MarkFirstGoodPrimary Proc Near Uses ax si di
501 mov di, offset PartitionSector+446 ; DS:SI - 1st partitionentry
502 ; First action to do: Remove the active flag from every partition
503 push di
504 mov cl, 4
505 PMPP_RemoveActiveFlagLoop:
506 and bptr es:[di+LocBRPT_Flags], 7Fh
507 add di, LocBRPT_LenOfEntry
508 dec cl
509 jnz PMPP_RemoveActiveFlagLoop
510 pop di
511 ; First Search, will hit on any PartitionID that is:
512 ; a) not 0
513 ; b) not hidden
514 ; c) not extended partition (05h or 0Fh)
515 PMPP_Search1Loop:
516 mov al, bptr es:[di+LocBRPT_SystemID]
517 or al, al
518 jz PMPP_Search1NoHit
519 cmp al, 05h
520 je PMPP_Search1NoHit
521 cmp al, 0Fh
522 je PMPP_Search1NoHit
523 mov bl, al ; BL == AL == PartitionID
524 push si
525 call PART_SearchFileSysName
526 pop si ; AL == UnhiddenPartitionID
527 cmp al, bl ; if ID is unhidden...
528 je PMPP_SearchHit
529 PMPP_Search1NoHit:
530 add di, LocBRPT_LenOfEntry ; 16 Bytes per Partition-Entry
531 cmp di, 500+offset PartitionSector
532 jb PMPP_Search1Loop
533
534 mov di, offset PartitionSector+446 ; DS:SI - 1st Partition-Entry
535 ; Second Search, hit on anything that is not an extended partition
536 ; (05 or 0Fh)
537 PMPP_Search2Loop:
538 mov al, bptr es:[di+LocBRPT_SystemID]
539 or al, al
540 jz PMPP_Search2NoHit
541 cmp al, 05h
542 je PMPP_Search2NoHit
543 cmp al, 0Fh
544 jne PMPP_SearchHit
545 PMPP_Search2NoHit:
546 add di, LocBRPT_LenOfEntry ; 16 Bytes per Partition-Entry
547 cmp di, 500+offset PartitionSector
548 jb PMPP_Search2Loop
549 jmp PMPP_SearchFailed
550
551 PMPP_SearchHit:
552 or bptr es:[di], 80h ; SET ACTIVE PARTITION
553 PMPP_SearchFailed:
554 ret
555PART_MarkFirstGoodPrimary EndP
556
557; Searches the Name and Flags to a FileSysID (PartitionID)
558; In: AL - FileSysID
559; Out: AL - Unhidden File-System-ID, AH - Flags for this File-System
560; SI - Pointer to Name (8char)
561; Destroyed: *none*
562PART_SearchFileSysName Proc Near Uses bx dx
563 ;movzx bx, al
564 mov bl,al
565 mov bh,0
566
567 mov si, offset FileSysIDs
568 PSFSN_SearchLoop:
569 lodsw ; AL - NormalID, AH-HiddenID
570 mov dl, ds:[si] ; DL - File-System-Flags
571 inc si
572 cmp al, bl ; Check, if Unhidden-ID matches...
573 je PSFSN_Match
574 cmp ah, bl ; Check, if Hidden-ID matches...
575 je PSFSN_Match
576 mov al, bl ; So Unhidden-ID will be Original-ID
577 cmp ah, 0 ; Unknown (last ID in table)
578 je PSFSN_Match
579 inc bh
580 jmp PSFSN_SearchLoop
581
582 PSFSN_Match:
583 ; AL is already Unhidden-ID
584 mov ah, dl
585 ; AH is now the FileSystem-Flag
586 ;movzx bx, bh
587 mov bl,bh
588 mov bh,0
589
590 shl bx, 3 ; Offsets * 8
591 mov si, offset FileSysNames
592 add si, bx
593 ret
594PART_SearchFileSysName EndP
595
596; Searches the Hidden ID corresponding to a FileSysID (PartitionID)
597; In: AL - FileSysID
598; Out: AL - Hidden File-System-ID
599PART_SearchFileSysHiddenID Proc Near Uses bx
600 ;movzx bx, al
601 mov bl,al
602 mov bh,0
603
604 mov si, offset FileSysIDs
605 PSFSHI_SearchLoop:
606 lodsw ; AL - NormalID, AH-HiddenID
607 inc si
608 cmp al, bl ; Check, if Unhidden-ID matches...
609 je PSFSHI_Match
610 cmp ah, bl ; Check, if Hidden-ID matches...
611 je PSFSHI_Match
612 mov ah, bl ; So Unhidden-ID will get replied...
613 cmp ah, 0 ; Unknown (last ID in table)
614 je PSFSHI_Match
615 inc bh
616 jmp PSFSHI_SearchLoop
617
618 PSFSHI_Match:
619 mov al, ah ; AL = Hidden ID
620 ret
621PART_SearchFileSysHiddenID EndP
622
623; In: DS:SI - Partition-Name, CX - Maximum/Total Length
624; Out: Carry-Flag set, if valid Partition-Name
625; Destroyed: None
626PART_CheckForValidPartName Proc Near Uses ax cx dx si
627 ; Our logic is as follows:
628 ; If all chars are U -> Invalid (due reformated signature)
629 ; If anything below 32, but 0 -> Invalid (due invalid chars)
630 ; If anything above 165 -> Invalid (due invalid chars)
631 ; If anything between 123-128 -> Invalid (due invalid chars)
632 ; DX - holds count of 'U's
633 push cx
634 or cx, cx
635 jz PCFVPN_InvalidName
636 xor dx, dx
637 PCFVPN_CheckLoop:
638 lodsb
639 cmp al, 0
640 je PCFVPN_ValidChar
641 cmp al, 32
642 jb PCFVPN_InvalidName
643 cmp al, 165
644 ja PCFVPN_InvalidName
645 cmp al, 123
646 jb PCFVPN_ValidChar
647 cmp al, 128
648 jbe PCFVPN_InvalidName
649 PCFVPN_ValidChar:
650 cmp al, 'U'
651 jne PCFVPN_NoMagic
652 inc dx
653 PCFVPN_NoMagic:
654 dec cx
655 jnz PCFVPN_CheckLoop
656 pop cx
657 cmp cx, dx
658 clc
659 je PCFVPN_WasMagic
660 stc
661 PCFVPN_WasMagic:
662 ret
663 PCFVPN_InvalidName:
664 pop cx
665 clc
666 ret
667PART_CheckForValidPartName EndP
668
669
670; Rousseau: added
671; Compare a volume-label in the IPT to the install-volume
672; SI holds pointer to entry in IPT
673; CY set if this entry is also the install-volume
674PART_IsInstallVolume Proc Near Uses ax cx dx si di
675 cld ; Advance upwards with lodsb
676 mov di, offset eCS_InstallVolume ; Address of install-volume label (max. 11 chars)
677
678 mov cx, 11 ; Maximum length of label
679 xor dl, dl ; Not found yet
680
681 ; Compare next character
682 PART_IsInstallVolumeNext:
683 lodsb ; Load byte from SI (IPT-entry)
684 ;cmp al,' ' ; If space then use zero
685 ;jne PART_IsInstallVolume_skip1
686 ;xor al,al
687 PART_IsInstallVolume_skip1:
688 xchg ah,al ; Save char to AH
689 xchg si,di ; Exchange pointers
690 lodsb ; Load byte from SI (install-volume label)
691 ;cmp al,' ' ; If space then use zero
692 ;jne PART_IsInstallVolume_skip2
693 ;xor al,al
694 PART_IsInstallVolume_skip2:
695 xchg si,di ; Reexchange pointers
696; call AuxIO_Teletype
697 call CONV_ToUpper
698; call AuxIO_Teletype
699 xchg al,ah
700; call AuxIO_Teletype
701 call CONV_ToUpper
702; call AuxIO_Teletype
703; call AuxIO_TeletypeNL
704
705 ; Are both of them zero ?
706 ; Then the names could be the same, but cx must not equal 11
707 ; because that would indicate a null-string.
708 mov dh,al
709 or dh,ah
710 jz PART_IsInstallVolumeFound
711
712 cmp ah,al ; Are the the same ?
713 jnz PART_IsInstallVolumeNotFound ; Nope, compare ended
714 loop PART_IsInstallVolumeNext ; Yep, Compare next character
715
716 PART_IsInstallVolumeFound:
717 ; If CX is still 11 this was a zero string
718 ; and thus not a valid volume-name.
719 ; This should not occur as this function is only called when the first
720 ; byte is non-zero.
721 cmp cx,11
722 je PART_IsInstallVolumeNotFound
723 ; Found !
724 mov dl,1 ; Found
725 jmp PART_IsInstallVolumeEnd
726
727
728 PART_IsInstallVolumeNotFound:
729 mov dl,0
730 jmp PART_IsInstallVolumeEnd
731
732
733 PART_IsInstallVolumeEnd:
734 ; Set the status in CY
735 mov al,dl
736 add al,'0'
737; call AuxIO_TeletypeHexByte
738; call AuxIO_TeletypeNL
739 rcr dl,1 ; Put found-flag in CY
740 ret
741PART_IsInstallVolume EndP
742
743
744
745
746
747
748; ###################
749; # START PARTITION #
750; ###################
751
752; Starts Partition DL from Internal Partition Table.
753; In: DL - Number of partition (filtered view)
754; Out: No Return...
755; Destroyed: None, due to no return ;-)
756; Logic: - Harddrive: loads partition Table
757; sets partition active
758; saves partition table
759; hides partitions, if needed
760; Linux-Support, if needed
761; load boot sector
762; VIBR checking, if wanted
763; install MBR Protection, if wanted
764; Special Boot Support, if needed (OS/2 Extended partitions)
765; Copy boot-sector to StartBase
766; run boot sector...
767PART_StartPartition Proc Near Uses ax dx es di
768 local BootPartNo:byte
769 local PhysDiskBpbIndex:word ; Index into BPB to field of phys-disk
770 local FSType:byte ; The FS used on the loaded BPB
771 ; Only used for FAT/HPFS/JFS
772
773 ; Get Partition-Pointer (SI) to Partition-To-Boot (DL)
774 call PART_GetPartitionPointer
775
776 call PART_ConvertToStraight ; ...we save straight view for later...
777 mov BootPartNo, dl
778 ; Straight - FFh -> Floppy boot
779 ; FEh -> BIOS continue (CD-ROM, ZIP, etc.)
780
781 ; We need straight pointers from now on, so calculate the table...
782 call PART_CalculateStraightPartPointers
783
784 ; SI contains the pointer to the IPT to what partition to boot
785 ; in this whole routine...it may never get messed up.
786
787 push si
788 mov dl, [si+LocIPT_Drive]
789 mov dh, [si+LocIPT_SystemID]
790 ; Copy Partition-Name to BootingNow area for display purposes
791 add si, LocIPT_Name
792
793
794;pusha
795;call MBR_Teletype
796;mov si,offset TXT_BootingNowPartName
797;call MBR_Teletype
798;popa
799
800 mov cx, 11
801 call GetLenOfName
802 mov di, offset TXT_BootingNowPartName
803 jz PSP_NoName
804 rep movsb ; Copy label-name to boot
805 PSP_NoName:
806 xor al, al
807 stosb ; Ending Zero
808 mov si, offset TXT_BootingNow1 ; "Booting the system using "
809 call MBR_Teletype
810; [Linux support removed since v1.02]
811; cmp dh, 0FDh
812; je PSP_IsKernel
813
814;pusha
815;call MBR_Teletype
816;mov si,offset TXT_BootingNowPartName
817;call MBR_Teletype
818;popa
819
820
821 or dl, dl
822 jnz PSP_IsHarddisc
823 ; When booting floppy/CD-ROM/etc., we got other text to be displayed...
824 mov si, offset TXT_BootingNowPartName
825 call MBR_TeletypeVolName
826 jmp PSP_IsFloppyCDROMetc
827
828; [Linux support removed since v1.02]
829; PSP_IsKernel:
830; IFDEF ReleaseCode
831; ; Save configuration on HDD boots (save CFG_LinuxLastKernel)
832; call DriveIO_SaveConfiguration
833; ENDIF
834; call MBR_Teletype ; Prints out BootingNow2 including KernelName
835; mov si, offset TXT_BootingNowKernel
836; call MBR_Teletype
837; jmp PSP_IsFloppyCDROMetc
838
839 PSP_IsHarddisc:
840 IFDEF ReleaseCode
841 ; Save configuration on HDD boots (save CFG_PartLast)
842 call DriveIO_SaveConfiguration ; Rousseau: SAVE CONFIGURATION !
843 ENDIF
844 ;call MBR_Teletype ; Prints out BootingNow2 including PartitionName
845 mov si, offset TXT_BootingNowPartName
846 call MBR_TeletypeVolName
847 mov si, offset TXT_BootingNowPartition
848 call MBR_Teletype
849 pop si ; restores SI (IPT-pointer)
850
851 mov ax, wptr [si+LocIPT_AbsolutePartTable+0]
852 mov bx, wptr [si+LocIPT_AbsolutePartTable+2]
853 mov cx, wptr [si+LocIPT_LocationPartTable+1]
854 mov dh, bptr [si+LocIPT_LocationPartTable+0]
855 mov dl, [si+LocIPT_Drive]
856
857
858
859 ; This loads the MBR in case of PRI or the EBR in case of LOG partitions.
860 call DriveIO_LoadPartition ; Load Table... [LOAD]
861
862
863
864 ; --------------------------------------------------- MODIFY PARTITION TABLE
865 push cs
866 pop es
867 mov di, offset PartitionSector+446 ; ES:DI - First Partitionentry
868
869 ; Remove all active-flags for safety reasons, primary partition table will
870 ; have one partition set active by ScanPartition-routine.
871 push di
872 mov cl, 4
873 PSP_RemoveActiveFlagLoop:
874 and bptr es:[di+LocBRPT_Flags], 7Fh
875 add di, LocBRPT_LenOfEntry
876 dec cl
877 jnz PSP_RemoveActiveFlagLoop
878 pop di
879
880 ; Put the partition-to-be-booted location into registers...
881 mov ax, wptr [si+LocIPT_AbsoluteBegin+0]
882 mov bx, wptr [si+LocIPT_AbsoluteBegin+2]
883 sub ax, wptr [si+LocIPT_AbsolutePartTable+0]
884 sbb bx, wptr [si+LocIPT_AbsolutePartTable+2]
885 ; BX:AX - absolute position of partition relative to partition table
886 ; ...and search for it...
887 PSP_SearchLoop:
888 cmp ax, wptr es:[di+LocBRPT_RelativeBegin]
889 jne PSP_SearchMismatch
890 cmp bx, wptr es:[di+LocBRPT_RelativeBegin+2]
891 jne PSP_SearchMismatch
892 jmp PSP_SearchMatch
893 PSP_SearchMismatch:
894 add di, LocBRPT_LenOfEntry ; 16 Bytes per Partition-Entry
895 cmp di, 500+offset PartitionSector
896 jb PSP_SearchLoop
897 jmp MBR_HaltSystem
898
899 ; -------------------------------------------------------------- ENTRY FOUND
900 PSP_SearchMatch:
901 or byte ptr es:[di+LocBRPT_Flags], 80h ; set ACTIVE partition
902 IFDEF ReleaseCode
903 call DriveIO_SavePartition ; Saves the Partition-Table [SAVE]
904 ENDIF
905
906
907
908 ; ---------------------------------------------------------- OS/2 / eCS I13X
909 ; Now check if the partition to get booted is above 8 GB.
910 ; If yes, set magic bytes 'I13X' at 3000:0 for boot-loader to recognize.
911 ; This method is (c) by IBM <g>
912 ; Rousseau: Booting IBM-BM also requires the LBA address of the IBM-BM
913 ; partitionafter the 'I13X' signature.
914 ; Also, FS needs to be set to 3000H.
915 ; This info was obtained by examining the LVM 2,x MBR-code.
916 mov ax, wptr [si+LocIPT_AbsoluteBegin+0]
917 mov bx, wptr [si+LocIPT_AbsoluteBegin+2]
918 add ax, wptr es:[di+LocBRPT_AbsoluteLength+0] ; Add length to absolute
919 adc bx, wptr es:[di+LocBRPT_AbsoluteLength+2] ; begin location
920 ; BX:AX -> Absolute End-Position of Partition
921
922 test CFG_ForceLBAUsage, 1
923 jnz PSP_ForceI13X
924 ; LBA-boundary at 16450560 (FB0400h) (16320x16x63)
925 cmp bx, 00FBh
926 jb PSP_NoI13X
927
928
929 PSP_ForceI13X:
930 push es
931 push di
932 push si
933
934 ; Setup ES and FS.
935 ; FS needs to keep this address.
936 mov ax, 3000h
937 mov es, ax
938 ; mov fs,ax
939 db 08eh
940 db 0e0h
941
942 ; Insert signature
943 xor di, di
944 mov wptr es:[di+00], '1I'
945 mov wptr es:[di+02], 'X3'
946
947 ;mov wptr es:[di], 0
948 ;mov wptr es:[di+2], 0
949
950 ; Insert LBA address.
951 mov ax, wptr [si+LocIPT_AbsoluteBegin+0]
952 mov wptr es:[di+04], ax
953 mov ax, wptr [si+LocIPT_AbsoluteBegin+2]
954 mov wptr es:[di+06], ax
955
956 pop si
957 pop di
958 pop es
959
960
961
962 PSP_NoI13X:
963
964 ; now check, if we need to hide any partition
965 test byte ptr [si+LocIPT_Flags], Flags_HideFeature
966 jz PSP_NoHideFeature
967 ; --------------------------------------------------------- PARTITION HIDING
968 push si
969 mov si, offset TXT_BootingHide
970 call MBR_Teletype ; display "hide active"
971 pop si
972 ; First, find Hide-Config
973 mov dl, BootPartNo ; EntryNumber is straight view
974 mov ax, LocIPT_MaxPartitions
975 mul dl
976 mov di, offset HidePartitionTable
977 add di, ax ; We got the pointer
978 ; So process Hide-Config. Read out Byte-Entries, each points to a partition
979 ; 0FFh is end-marker / maximum entries = CFG_Partitions
980 mov cl, CFG_Partitions
981 PSP_PartitionsHideLoop:
982 mov dl, es:[di]
983 inc di
984 cmp dl, 0FFh
985 je PSP_EndOfHideProcess ; -> End of Hiding
986 call PART_HidePartition ; Now hide that partition
987 dec cl
988 jnz PSP_PartitionsHideLoop
989 PSP_EndOfHideProcess:
990 ; --- HIDE COMPLETED ---
991 ; So something got hidden and we have to remark a primary partition,
992 ; if we are booting something non-primary from 1st hdd.
993 cmp bptr [si+LocIPT_Drive], 80h
994 ja PSP_HideAdjustPrimaryMark ; When booting any hdd, but 1st
995 mov ax, wptr [si+LocIPT_AbsolutePartTable]
996 mov bx, wptr [si+LocIPT_AbsolutePartTable+2]
997 or ax, ax
998 jnz PSP_HideAdjustPrimaryMark ; or booting non-primary partition
999 or bx, bx ; on 1st harddrive.
1000 jz PSP_NoHideAdjustPrimaryMark
1001 PSP_HideAdjustPrimaryMark:
1002 ; Load Primary Partition Table...
1003 xor ax, ax
1004 xor bx, bx
1005 mov cx, 0001h ; Cylinder 0, Sector 1
1006 mov dx, 0080h ; First HD, Head 0
1007 ; Load MBR
1008 call DriveIO_LoadPartition ; Load Primary Partition Table
1009 call PART_MarkFirstGoodPrimary
1010 IFDEF ReleaseCode
1011 ; Save MBR
1012 call DriveIO_SavePartition ; Saves the Partition-Table
1013 ENDIF
1014 PSP_NoHideAdjustPrimaryMark:
1015
1016 PSP_NoHideFeature:
1017 ; Check, if we are supposed to ignore LVM altogether...
1018 test [CFG_IgnoreLVM], 1
1019 jnz PSP_NoLVMReassignment
1020 ; --------------------------------------------------------- LVM REASSIGNMENT
1021 ; Driveletter must be set for this partition
1022 test byte ptr [si+LocIPT_Flags], Flags_DriveLetter
1023 jz PSP_NoLVMReassignment
1024 ;movzx bx, BootPartNo ; EntryNumber is straight view
1025 mov bl,BootPartNo ; EntryNumber is straight view
1026 mov bh,0
1027
1028 mov al, bptr [DriveLetters+bx]
1029 sub al, 3Dh ; Convert e.g. 80h -> 'C'
1030 cmp al, bptr [PartitionVolumeLetters+bx]
1031 je PSP_NoLVMReassignment ; If driveletters match -> no change
1032 call LVM_DoLetterReassignment ; Give partition SI letter AL
1033 PSP_NoLVMReassignment:
1034 push si
1035 ; ------------------------------------------------------- -"PLEASE WAIT..."-
1036 PSP_IsFloppyCDROMetc:
1037 mov si, offset TXT_BootingWait
1038 call MBR_Teletype ; display "please wait"
1039 pop si
1040
1041 ; Process Partition Tables, if M$-Hack required (changes Ext Part Type)
1042 call MSHACK_ProcessPartTables
1043
1044 test CFG_BootMenuActive, 0FFh
1045 jz PSP_NoMenuNoSound
1046
1047 ; --------------------------------------------------------------- BOOT-SOUND
1048 call SOUND_ExecuteBoot
1049 PSP_NoMenuNoSound:
1050
1051 ; -------------------------------------------------- SPECIAL BOOT PROCESSING
1052 ; Check here, if the Boot shall be done via resume to BIOS...
1053 mov al, bptr [si+LocIPT_SystemID]
1054 cmp al, 0FEh ; Via BIOS ? (aka resume BIOS boot sequence)
1055 je PSP_ResumeBIOSbootSeq
1056; [Linux support removed since v1.02]
1057; cmp al, 0FDh ; Kernel-Booting ?
1058; je PSP_KernelBooting
1059 jmp PSP_StartNormal
1060
1061 PSP_ResumeBIOSbootSeq:
1062 int 18h ; Give control back to BIOS
1063 db 0EAh ; if return to here -> Reboot
1064 dw 0FFF0h
1065 dw 0F000h
1066
1067; [Linux support removed since v1.02]
1068; PSP_KernelBooting:
1069; call LINUX_LoadKernel ; DS:SI - Entry Pointer to Kernel
1070; db 0EAh ; if return to here -> Reboot
1071; dw 0FFF0h
1072; dw 0F000h
1073
1074 ; =======================================================================
1075 ; FROM THIS POINT ON, ONLY DS and SI REGISTER IS NEEDED TO BE PRESERVED
1076 ; =======================================================================
1077
1078 PSP_StartNormal:
1079 mov ax, wptr [si+LocIPT_AbsoluteBegin+0]
1080 mov bx, wptr [si+LocIPT_AbsoluteBegin+2]
1081 mov cx, [si+LocIPT_LocationBegin+1]
1082 mov dh, [si+LocIPT_LocationBegin+0]
1083 mov dl, [si+LocIPT_Drive]
1084
1085 ; This loads the PBR of the partition.
1086 call DriveIO_LoadPartition ; Loads boot-sector... [PARTBOOTSEC]
1087
1088 ;
1089 ; The JFS PBR-code does not use the passed BPB in memory but uses the BPB
1090 ; on disk. This breaks the drive-letter feature on JFS.
1091 ; So we make a copy of the PBR in memory, and if the partition is JFS
1092 ; we later adjust the physical-disk and boot-drive-letter in this
1093 ; copy and write it back to disk.
1094 ; Then the JFS PBR-code will see the correct boot-drive-letter.
1095 ;
1096 pusha
1097 mov si,offset PartitionSector
1098 mov di,offset JfsPBR
1099 mov cx,100h
1100 cld
1101 rep movsw
1102 popa
1103
1104
1105
1106 ; Check if the disk is a harddisk or a floppy.
1107 mov dl,[si+LocIPT_Drive]
1108 cmp dl, 80h
1109 jae is_harddisk
1110
1111 ;
1112 ; This is a dirty hack to fix booting from a floppy.
1113 ; With all the modifications made since v1.06 this feature was broken
1114 ; because Int13X is used implicitly now, and that does not work
1115 ; for diskette access.
1116 ; This jumps to the code that loads and starts the pbr-code.
1117 ; Note that it also skips virus checking !
1118 ; This will be fixed at a later date.
1119 jmp boot_from_floppy
1120
1121
1122
1123
1124 ;
1125 ; The disk is a harddisk so we need to do various checks and fixes.
1126 ;
1127 is_harddisk:
1128
1129 test CFG_DetectVIBR, 1
1130 jz PSP_NoVIBR
1131 test byte ptr [si+LocIPT_Flags], Flags_VIBR_Detection
1132 jz PSP_NoVIBR
1133 ; ---------------------------------------------------------- CHECKS FOR VIBR
1134 push si
1135 mov si, offset PartitionSector
1136 mov bx, 4B4Dh ; Magic: 'MK'
1137 call MBR_GetCheckOfSector
1138 pop si
1139 cmp [si+LocIPT_BootRecordCRC], bx
1140 je PSP_NoVIBR
1141 mov bx, [si+LocIPT_BootRecordCRC]
1142 or bx, bx
1143 jz PSP_NoVIBR
1144 ; Oh Oh, got a virus :(
1145 mov si, offset TXT_VirusFoundMain
1146 call MBR_Teletype
1147 mov si, offset TXT_VirusFound2 ; VIBR-Virus
1148 call MBR_Teletype
1149 mov si, offset TXT_VirusFoundEnd
1150 call MBR_Teletype
1151 jmp MBR_HaltSystem
1152
1153 PSP_NoVIBR:
1154 test CFG_ProtectMBR, 1
1155 jz PSP_NoMBRprotect
1156 ; -------------------------------------------------- INSTALLS MBR-PROTECTION
1157 ; We need DS:SI later...
1158 push ds
1159 push si
1160 ; First subtract 1024 bytes from Base-Memory...
1161 push ds
1162 mov ax, 40h
1163 mov ds, ax
1164 mov dx, word ptr ds:[13h]
1165 dec dx ; 1 == 1kbyte
1166 mov word ptr ds:[13h], dx
1167 pop ds
1168 shl dx, 6 ; trick, now DX is a segment
1169
1170 ; Now copy in our code (to DX:0)...
1171
1172 mov si, offset MBR_Protection ; DS:SI - Source Image
1173 mov es, dx
1174 xor di, di ; ES:DI - Destination
1175 mov cx, 512
1176 rep movsw ; Move 1024 bytes...
1177
1178 ; Now fill in variables...
1179
1180 xor ax, ax
1181 mov ds, ax
1182 mov si, 10h*4
1183 xor di, di ; INT 10h Vector to MBR Protection
1184 ;movsd
1185 movsw
1186 movsw
1187
1188 mov si, 13h*4 ; INT 13h Vector to MBR Protection
1189 ;movsd
1190 movsw
1191 movsw
1192
1193 mov al, CFG_IgnoreWriteToMBR ; Option to MBR Protection
1194 stosb
1195
1196 ; Now switch INT 13h vector to MBR Protection
1197
1198 sub si, 4
1199 mov ax, 9
1200 mov ds:[si], ax
1201 mov ds:[si+2], dx ; Vector hardcoded at DS:0009
1202 ; MBR-Protection now active :)
1203 ; Restore DS:SI
1204 pop si
1205 pop ds
1206
1207
1208
1209
1210
1211
1212
1213 PSP_NoMBRprotect:
1214
1215 ; Display volume-name in bold
1216 ; Just before booting the selected partition
1217 ;pushf
1218 ;pusha
1219 ;push si
1220 ;add si, LocIPT_Name
1221 ;call MBR_TeletypeVolName
1222 ;xor si,si
1223 ;call MBR_TeletypeNL
1224 ;pop si
1225 ;popa
1226 ;popf
1227
1228
1229
1230
1231
1232 ; ------------------------------------------------ SPECIAL PARTITION SUPPORT
1233 ; needed by OS/2 Warp / eComStation
1234
1235
1236 ;cmp byte ptr [si+LocIPT_SystemID],08 ; I hate Microsuck NTFS check
1237 mov di, offset PartitionSector ; ES:DI - Actual Boot-Record
1238
1239 ; Special Support Detection
1240 ;mov ax, word ptr es:[di+18h]
1241 ;cmp ax, 003Fh ; Physical Layout-Sectors... Safety check
1242
1243
1244
1245 ;
1246 ; At this point, SI points to IPT and DI points to the PBR from disk.
1247 ; Depending on the type of BPB used, the physical disk field is at
1248 ; different locations: 24h for old-style (OS/2) BPB's and 40h for
1249 ; FAT32 BPB's.
1250 ; The OS/2 boot-drive-letter is located at 25h in an old-style BPB,
1251 ; while the corresponding field in a FAT32 BPB is located at 41h but
1252 ; used for different purposes.
1253 ; In case of HPFS, using old-style BPB's, the boot-drive-letter needs
1254 ; to be adjusted if it is zero.
1255 ; In that case we trace the LVM-info for that partition and use the
1256 ; drive-letter defined there.
1257 ; This fixes issues #3067 and #3119.
1258 ; Adjusting the physical disk is always done but at different locations
1259 ; depending on the BPB used.
1260 ; Also, the "hidden sectors" field is adjusted to contain the absolute
1261 ; offset from the start of the disk instead of the relative offset to
1262 ; the start of the partition.
1263 ; http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/bios-parameter-block.html
1264 ;
1265
1266
1267 ; Get index of phys-disk field in BX
1268 call PART_GetFieldIndex
1269 mov PhysDiskBpbIndex,ax
1270 mov bx,ax
1271
1272 ; Locate cursor for output of debug-info
1273 pusha
1274 mov ch,7
1275 mov cl,0
1276 call VideoIO_Color
1277 mov ch,6
1278 mov cl,1
1279 call VideoIO_Locate
1280 popa
1281
1282 ; Debug display physdisk, ptype and physdisk offset in BPB
1283 pusha
1284 mov ah,[si+LocIPT_Drive]
1285 mov al,[si+LocIPT_SystemID]
1286 call VideoIO_PrintHexWord
1287 mov ax,bx
1288 call VideoIO_PrintHexWord
1289 mov ax,[si+LocIPT_AbsolutePartTable+02]
1290 call VideoIO_PrintHexWord
1291 mov ax,[si+LocIPT_AbsolutePartTable+00]
1292 call VideoIO_PrintHexWord
1293 mov al,[ExtendedAbsPosSet]
1294 call VideoIO_PrintHexByte
1295 popa
1296
1297
1298 ;
1299 ; If the partition is IBM-BM we skip all the BPB adjustments.
1300 ; IBM-BM does no need them.
1301 ;
1302 cmp byte ptr [si+LocIPT_SystemID], 0ah
1303 jnz no_os2_bm
1304 jmp chainload_ibm_bm
1305
1306
1307 no_os2_bm:
1308
1309 ;
1310 ; Update the phys-disk field
1311 ; DI points to PartitionSector
1312 ; BX holds index to phys-disk field
1313 ;
1314 mov al,byte ptr [si+LocIPT_Drive]
1315 mov es:[di+bx],al
1316
1317
1318 ;
1319 ; Legacy systems do not put the correct values in the "hidden sectors"
1320 ; field. Also, this field will be incorrect if a partition is moved on
1321 ; disk by a disktool not accounting for this field.
1322 ; Linux does not have a BPB at all, and does not use this field.
1323 ; So we set the correct value here obtained by the partition scanner.
1324 ; This fixing is done by OS/2 BM as well, according to Martin.
1325 ;
1326
1327 ;
1328 ; Fix hidden sectors field
1329 ;
1330
1331 ; Low word of 32-bits "hidden sectors"
1332 mov ax,[si+LocIPT_AbsoluteBegin]
1333 mov es:[di+1ch], ax
1334 ; High word of 32-bits "hidden sectors"
1335 mov ax,[si+LocIPT_AbsoluteBegin+2]
1336 mov es:[di+1eh], ax
1337
1338
1339
1340
1341
1342 ;
1343 ; Check partitions to see if boot-drive-letter fixing is needed.
1344 ; FAT12/FAT16/HPFS/JFS will have the value at 25h fixed
1345 ; to the LVM-info drive-letter. (+3dh to convert to BIOS notation)
1346 ;
1347
1348
1349 ; Setup partition disk and LBA address
1350 mov dl,byte ptr [si+LocIPT_Drive]
1351 mov cx,[si+LocIPT_AbsoluteBegin+00h]
1352 mov bx,[si+LocIPT_AbsoluteBegin+02h]
1353
1354 ; AL is gonna be used to shift-in CY status.
1355 ; If the type of file-system is one of FAT12/FAT16/HPFS/JFS then
1356 ; AL will be <> 0 and the boot-drive-letter can be tested / fixed.
1357 mov al,0
1358
1359
1360 ; FIXME:
1361 ; The PBR is already loaded, no need to load it again in the
1362 ; calls below.
1363 ;
1364 ; Better use the already done discovery to determine the system.
1365 ;
1366
1367 ; When FAT12/FAT16/HPFS/JFS then boot-drive-letter can be tested
1368 ; or adjusted.
1369 call PART_IsJFS
1370 rcl al,1
1371 call PART_IsHPFS
1372 rcl al,1
1373 call PART_IsFAT
1374 rcl al,1
1375 mov ah,al
1376
1377 ; Store for later reference.
1378 mov [FSType],al
1379
1380
1381 ;
1382 ; When the phys-disk byte (80h) is put in this BPB in RAM,
1383 ; Windows will not find it's loader if Windows itself
1384 ; is installed in a logical partition but the loader is on FAT
1385 ; in a primary.
1386 ; This goes for all NT-based versions ?
1387 ;
1388
1389
1390 ;
1391 ; See if phys-disk / boot-drive-letter fix is needed
1392 ; depending on FS used.
1393 ; AL will be 0 for any file-system other than FAT12/FAT16/HPFS/JFS.
1394 ;
1395 test al,al
1396 jz bdl_ok
1397
1398
1399
1400 ; Check if the boot-drive-letter is non-zero.
1401 mov bx,PhysDiskBpbIndex
1402 inc bx
1403 mov al,es:[di+bx]
1404 test al,al
1405 ; Non-zero, so no fixing needed.
1406 ;jnz bdl_ok ;; Why not always fix ? (so, jnz disabled)
1407
1408
1409 ;
1410 ; Always fix boot-drive-letter on FAT12/FAT16/HPFS/JFS
1411 ;
1412
1413 ; Get the drive-letter for the partition from the LVM-info.
1414 mov dl,byte ptr [si+LocIPT_Drive]
1415 mov cx,[si+LocIPT_AbsoluteBegin+00h]
1416 mov bx,[si+LocIPT_AbsoluteBegin+02h]
1417 call LVM_GetDriveLetter
1418
1419 ; Save the status for later use
1420 pushf
1421
1422 ; See if the drive-letter feature is active.
1423 ; If active, we force the drive-letter from the user.
1424 test byte ptr [si+LocIPT_Flags], Flags_DriveLetter
1425
1426 ; Nope, it's not so we don't force the boot-drive-letter
1427 ; using field 25h.
1428 jz PSP_NoLogicalSupport
1429
1430 ; Partition index in BX
1431 mov bl,BootPartNo ; EntryNumber is straight view
1432 mov bh,0
1433
1434 ; Pointer to the user specified boot-drive
1435 ; Get it and convert to ASCII letter
1436 mov al, bptr [DriveLetters+bx]
1437 sub al,3dh ; Convert BIOS notation to ASCII drive-letter
1438
1439
1440
1441 PSP_NoLogicalSupport:
1442
1443 ; Drive letter is LVM obtained or user-forced.
1444 ; Save it in AH.
1445 mov ah,al
1446
1447
1448 ; Restore the status whether an LVM drive-letter could be obtained
1449 popf
1450
1451
1452 ;
1453 ; No valid LVM-info if no info found or drive-letter is zero.
1454 ;
1455 jnc no_valid_lvm_info
1456 test al,al
1457 jz no_valid_lvm_info
1458
1459
1460 ;
1461 ; We have found a valid drive-letter in the LVM-info.
1462 ;
1463
1464 ; Convert to BIOS notation ('C'+3dh=80h, 'D'->81h, etc.)
1465 add al,3dh
1466
1467
1468 ;
1469 ; OS/2 uses this field to indicate the boot-drive-letter for the system.
1470 ; It is in BIOS notation where 80h='C', 81h='D' ... 97h='Z'.
1471 ; This is the field that get's forced to a specific value when the
1472 ; drive-letter feature of AiR-BOOT is used.
1473 ; Also, this field is the culprit of AiR-BOOT v1.07 not handling it
1474 ; correctly when the system uses HPFS and this byte is zero.
1475 ; This mostly involved booting older eCS versions on HPFS.
1476 ; See issues #3067 and #3119 on http://bugs.ecomstation.nl
1477 ;
1478
1479
1480 ; Fix the boot-drive-letter field in the BPB
1481 mov bx,PhysDiskBpbIndex
1482 ; Advance to field for drive-letter in BIOS notation (OS/2 - eCS)
1483 inc bx
1484 mov es:[di+bx],al
1485
1486
1487 jmp bdl_ok
1488
1489
1490 no_valid_lvm_info:
1491 ; HERE SHOULD COME AN ERROR POP-UP ABOUT NO BOOT-DRIVE OR NO LVM-INFO.
1492 ; WE CONTINUE BOOTING BUT OS/2 - eCS WILL MOST PROBABLY FAIL TO BOOT.
1493
1494 ;mov ah,07h
1495 ;mov si,offset CheckID_MBR
1496 ;call VideoIO_Print
1497
1498 hang:
1499 ;jmp hang
1500
1501
1502 ;
1503 ; Boot DriveLetter OK.
1504 ;
1505 bdl_ok:
1506
1507
1508 ;
1509 ; If the partition getting booted is a JFS partition then write-back
1510 ; the modified PBR to the disk.
1511 ; Note that it's not the in-memory PBR that get's written back, but
1512 ; a copy of the original where only the phys-disk and boot-drive-letter
1513 ; are adjusted.
1514 ;
1515 pusha
1516 mov al,[FSType]
1517 cmp al,04h ; JFS
1518 jnz no_jfs_pbr
1519
1520 ; Save IPT pointer
1521 push si
1522
1523 ; Copy the boot-drive and boot-drive-letter fields.
1524 mov si,offset PartitionSector
1525 mov di,offset JfsPBR
1526 mov al,[si+24h]
1527 mov [di+24h],al
1528 mov al,[si+25h]
1529 mov [di+25h],al
1530
1531 ; Restore IPT pointer
1532 pop si
1533
1534 ; Setup the registers for the partition location.
1535 mov ax, wptr [si+LocIPT_AbsoluteBegin+0]
1536 mov bx, wptr [si+LocIPT_AbsoluteBegin+2]
1537 mov cx, [si+LocIPT_LocationBegin+1]
1538 mov dh, [si+LocIPT_LocationBegin+0]
1539 mov dl, [si+LocIPT_Drive]
1540
1541 ; Write the adjusted JFS PBR to disk.
1542 mov si, offset JfsPBR
1543 call DriveIO_SaveSector
1544
1545 no_jfs_pbr:
1546 popa
1547
1548
1549 ;xor ax,ax
1550 ;int 16h
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568 ; ----------------------------------------------- LOGICAL PARTITION SUPPORT
1569
1570
1571
1572 ; AiR-BOOT now works around it by using the LVM-info (DLAT) of
1573 ; the partiton if present.
1574 ; Note however that if the drive-letter feature is active,
1575 ; this will override AB's automatic fixing.
1576 ;
1577 ; Test if the drive-letter feature is active for this partition.
1578 ; If so, then the drive that the user defined will be placed at
1579 ; byte 25h (37d) of the in-ram PartitionSector (BPB).
1580 ; (BIOS 80h notation: 80h=C, 81h=D, etc.)
1581 ; This is a remedy for when the corresponding field (25h) in the BPB on
1582 ; disk is zero.
1583 ;
1584
1585
1586
1587 ;
1588 ; Control is transferred to this point if we are booting IBM-BM.
1589 ; IBM-BM does not need the BPB fixes.
1590 ; It does require a other special stuff, which is already taken care of.
1591 ;
1592 chainload_ibm_bm:
1593
1594 ;
1595 ; Control is transferred to this point if we are booting a floppy.
1596 ; Booting from floppy skips all the harddisk related stuff.
1597 ; This is a dirty hack to fix the boot from floppy feature.
1598 ;
1599 boot_from_floppy:
1600
1601 ;
1602 ; Here we copy the prepared partition boot-record to 0000:7C00h
1603 ; to give it control later on.
1604 ;
1605 push es
1606 push si
1607 mov ax, StartBaseSeg
1608 mov es, ax
1609 mov cx, 256
1610 mov si, offset PartitionSector
1611 mov di, StartBasePtr
1612 cld
1613 rep movsw
1614 pop si
1615 pop es
1616
1617 ; --------------------------------------------------- NOW START BOOT-RECORD
1618
1619
1620
1621
1622IFDEF AUX_DEBUG
1623 call DEBUG_Dump2
1624 call DEBUG_DumpBSSSectors
1625ENDIF
1626
1627
1628
1629;
1630; ################################## BYE BYE ##################################
1631;
1632
1633 ; Skip wait-for-key
1634 jmp start_pbr
1635
1636 ;
1637 ; Wait for keypress
1638 ;
1639 xor ax, ax
1640 int 16h
1641
1642 ; Is escape-key ?
1643 cmp al, 1bh
1644
1645 ; Nope, Go activate PBR loader
1646 jne start_pbr
1647
1648 ;xor ax,ax
1649 ;mov [CurPartition_Location+00],ax
1650 ;mov [CurPartition_Location+02],ax
1651 ;mov [CurPartition_Location+04],ax
1652 ;mov [CurPartition_Location+06],ax
1653
1654 ;pusha
1655 ;xor al,al
1656 ;mov di,si
1657 ;add di,LocIPT_Name
1658 ;mov cx,12
1659 ;cld
1660 ;rep stosb
1661 ;popa
1662
1663
1664 ;push ds
1665 ;pop es
1666
1667 ; Yep, Reenter bootmenu
1668 jmp MBR_Main_ReEnterBootMenuPre
1669
1670
1671
1672;
1673; Transfer control to the PBR
1674;
1675start_pbr:
1676
1677 ; Debug display index
1678 ;pusha
1679 ;mov al, cs:[si+LocIPT_Drive] ; Drive Physical No
1680 ;mov ah, cs:[si+LocIPT_SystemID] ; SystemID
1681 ;call VideoIO_PrintHexWord
1682 ;xor ax, ax
1683 ;int 16h
1684 ;popa
1685
1686 ;~ jmp skip_delay
1687
1688
1689 ;
1690 ; Show "wait dots"
1691 ;
1692 pusha
1693 ; Color white on black
1694 mov ch,7
1695 mov cl,0
1696 call VideoIO_Color
1697 ; Locate cursor for output of debug-info
1698 mov ch,8
1699 mov cl,1
1700 call VideoIO_Locate
1701
1702 ; Print dots with interval.
1703 mov cx,10
1704 print_next_dot:
1705 mov al,'.'
1706 call VideoIO_PrintSingleChar
1707 ; Value 30 is about 1.5 seconds
1708 mov al,1
1709 call TIMER_WaitTicCount
1710 loop print_next_dot
1711 popa
1712
1713 ;
1714 ; Enter here to skip delay.
1715 ;
1716 skip_delay:
1717
1718
1719
1720 ;
1721 ; BYE BYE
1722 ;
1723 xor ax, ax
1724 xor bx, bx
1725 xor cx, cx
1726 mov ds, ax
1727 mov es, ax
1728 xor dh, dh
1729 mov dl, cs:[si+LocIPT_Drive] ; Drive Physical No
1730
1731
1732
1733 ;
1734 ; JUMP TO PBR loader
1735 ;
1736 IFDEF ReleaseCode
1737 db 0EAh
1738 dw StartBasePtr
1739 dw StartBaseSeg
1740 ENDIF
1741
1742
1743PART_StartPartition EndP
1744
1745
1746;
1747; ######################################
1748; # Is this a primary partition or not #
1749; ######################################
1750;
1751; In
1752; --
1753; DL = Physical Disk
1754; BX:CX = LBA sector
1755;
1756; Out
1757; ---
1758; AX = Index in PT if found, otherwise -1
1759; CY = Set if Primary, clear if not
1760;
1761PART_IsPrimaryPartition Proc Near Uses bx cx dx si di ds es
1762 ; Push LBA address of partition
1763 push bx
1764 push cx
1765
1766 ; Load LBA sector 0 from the disk specified in DL
1767 xor bx,bx
1768 xor cx,cx
1769 mov di,ds
1770 mov si,offset [TmpSector]
1771 call DriveIO_LoadSectorLBA
1772
1773 ; Restore partitions LBA address to DI:SI
1774 pop si
1775 pop di
1776
1777 ; Return with index -1 and CY clear if there was an
1778 ; error loading the sector.
1779 mov ax,-1
1780 cmc
1781 jnc PART_IsPrimaryPartition_exit
1782
1783 ; Compare the partition address with each entry in the P-table
1784 mov cx,4 ; Nr. of PT-entries
1785 mov dx,offset [TmpSector]
1786 add dx,01beh+08h ; Point DX to 1st partition address
1787
1788 next_pe:
1789 ; Computer pointer to PE
1790 mov bx,dx ; Point BX to 1st partition address
1791 mov ax,cx ; Get PE-index
1792 dec ax ; Index is zero based so adjust it
1793 shl ax,4 ; PE's are 16 bytes in size
1794 add bx,ax ; Make BX point to the PE
1795
1796 ; Compare LBA address
1797 push si
1798 push di
1799 xor si,[bx+00h] ; Will put 0 in SI if the same
1800 xor di,[bx+02h] ; Will put 0 in DI if the same
1801 or si,di ; Wil set ZF if both zero
1802 pop di
1803 pop si
1804 loopnz next_pe ; Try next entry if non-zero
1805
1806 ; Partition found or counter exhausted
1807 mov ax,-1
1808 clc
1809 ; Not found, so exit with NC and invalid index
1810 jnz PART_IsPrimaryPartition_exit
1811
1812 ; Partition is Primary, set CY and return index
1813 mov ax,cx
1814 stc
1815
1816 PART_IsPrimaryPartition_exit:
1817 ret
1818PART_IsPrimaryPartition Endp
1819
1820
1821
1822;
1823; #############################
1824; # Is this an HPFS partition #
1825; #############################
1826;
1827; In
1828; --
1829; DL = Physical Disk
1830; BX:CX = LBA sector
1831;
1832; Out
1833; ---
1834; CY = Set if HPFS partition, clear if not
1835;
1836PART_IsHPFS Proc Near Uses ax bx cx dx si di ds es
1837
1838 ; Load specified LBA sector (BX:CX) from the disk in DL
1839 mov di,ds
1840 mov si,offset [TmpSector]
1841 call DriveIO_LoadSectorLBA
1842
1843 ; Point to location of 'HPFS ' identifier.
1844 add si,36h
1845
1846 ; DL holds equality status
1847 xor dl,dl
1848 cld
1849
1850 ; Load letter into AL, xor with letter will result 0 if the same.
1851 ; Then or to DL.
1852 ; If at the end of the sequence DL is zero, the signature is present.
1853 lodsb
1854 xor al,'H'
1855 or dl,al
1856 lodsb
1857 xor al,'P'
1858 or dl,al
1859 lodsb
1860 xor al,'F'
1861 or dl,al
1862 lodsb
1863 xor al,'S'
1864 or dl,al
1865 lodsb
1866 xor al,' '
1867 or dl,al
1868 lodsb
1869 xor al,' '
1870 or dl,al
1871 lodsb
1872 xor al,' '
1873 or dl,al
1874 lodsb
1875 xor al,' '
1876 or dl,al
1877
1878 ; Assume not present
1879 clc
1880 jnz PART_IsHPFS_exit
1881
1882 ; JFS signature found
1883 stc
1884
1885 PART_IsHPFS_exit:
1886 ret
1887PART_IsHPFS Endp
1888
1889
1890;
1891; ###########################
1892; # Is this a JFS partition #
1893; ###########################
1894;
1895; In
1896; --
1897; DL = Physical Disk
1898; BX:CX = LBA sector
1899;
1900; Out
1901; ---
1902; CY = Set if JFS partition, clear if not
1903;
1904PART_IsJFS Proc Near Uses ax bx cx dx si di ds es
1905
1906 ; Load specified LBA sector (BX:CX) from the disk in DL
1907 mov di,ds
1908 mov si,offset [TmpSector]
1909 call DriveIO_LoadSectorLBA
1910
1911 ; Point to location of 'JFS ' identifier.
1912 add si,36h
1913
1914 ; DL holds equality status
1915 xor dl,dl
1916 cld
1917
1918 ; Load letter into AL, xor with letter will result 0 if the same.
1919 ; Then or to DL.
1920 ; If at the end of the sequence DL is zero, the signature is present.
1921 lodsb
1922 xor al,'J'
1923 or dl,al
1924 lodsb
1925 xor al,'F'
1926 or dl,al
1927 lodsb
1928 xor al,'S'
1929 or dl,al
1930 lodsb
1931 xor al,' '
1932 or dl,al
1933 lodsb
1934 xor al,' '
1935 or dl,al
1936 lodsb
1937 xor al,' '
1938 or dl,al
1939 lodsb
1940 xor al,' '
1941 or dl,al
1942 lodsb
1943 xor al,' '
1944 or dl,al
1945
1946 ; Assume not present
1947 clc
1948 jnz PART_IsJFS_exit
1949
1950 ; JFS signature found
1951 stc
1952
1953 PART_IsJFS_exit:
1954 ret
1955PART_IsJFS Endp
1956
1957
1958
1959;
1960; ######################################
1961; # Is this a FAT12 or FAT16 partition #
1962; ######################################
1963;
1964; In
1965; --
1966; DL = Physical Disk
1967; BX:CX = LBA sector
1968;
1969; Out
1970; ---
1971; CY = Set if FAT12 or FAT16 partition, clear if not
1972;
1973; This can be a FAT12 or FAT16 partition.
1974; When OS/2 formats volume with FAT it does not use the FAT16 identifier,
1975; but uses the FAT identifier.
1976;
1977PART_IsFAT Proc Near Uses ax bx cx dx si di ds es
1978
1979 ; First see if this is a FAT32 partition.
1980 ; If it is, exit with NC indicating not FAT12 or FAT16.
1981 call PART_IsFAT32
1982 cmc
1983 jnc PART_IsFAT_exit
1984
1985 ; Load specified LBA sector (BX:CX) from the disk in DL
1986 mov di,ds
1987 mov si,offset [TmpSector]
1988 call DriveIO_LoadSectorLBA
1989
1990 ; Point to location of 'FAT ' identifier.
1991 add si,36h
1992
1993 ; DL holds equality status
1994 xor dl,dl
1995 cld
1996
1997 ; Load letter into AL, xor with letter will result 0 if the same.
1998 ; Then or to DL.
1999 ; If at the end of the sequence DL is zero, the signature is present.
2000 lodsb
2001 xor al,'F'
2002 or dl,al
2003 lodsb
2004 xor al,'A'
2005 or dl,al
2006 lodsb
2007 xor al,'T'
2008 or dl,al
2009 lodsb
2010
2011 ; Since OS/2 formats FAT volumes with an identifier of 'FAT ',
2012 ; and others with 'FAT16 ', we skip two bytes for comparison.
2013 ; The rest must be spaces however.
2014; xor al,' '
2015; or dl,al
2016 lodsb
2017; xor al,' '
2018; or dl,al
2019
2020 lodsb
2021 xor al,' '
2022 or dl,al
2023 lodsb
2024 xor al,' '
2025 or dl,al
2026 lodsb
2027 xor al,' '
2028 or dl,al
2029
2030 ; Assume not present
2031 clc
2032 jnz PART_IsFAT_exit
2033
2034 ; FAT signature found
2035 stc
2036
2037 PART_IsFAT_exit:
2038 ret
2039PART_IsFAT Endp
2040
2041
2042;
2043; #############################
2044; # Is this a FAT32 partition #
2045; #############################
2046;
2047; In
2048; --
2049; DL = Physical Disk
2050; BX:CX = LBA sector
2051;
2052; Out
2053; ---
2054; CY = Set if FAT32 partition, clear if not
2055;
2056PART_IsFAT32 Proc Near Uses ax bx cx dx si di ds es
2057
2058 ; Load specified LBA sector (BX:CX) from the disk in DL
2059 mov di,ds
2060 mov si,offset [TmpSector]
2061 call DriveIO_LoadSectorLBA
2062
2063 ; Point to location of 'FAT32 ' identifier.
2064 add si,52h
2065
2066 ; DL holds equality status
2067 xor dl,dl
2068 cld
2069
2070 ; Load letter into AL, xor with letter will result 0 if the same.
2071 ; Then or to DL.
2072 ; If at the end of the sequence DL is zero, the signature is present.
2073 lodsb
2074 xor al,'F'
2075 or dl,al
2076 lodsb
2077 xor al,'A'
2078 or dl,al
2079 lodsb
2080 xor al,'T'
2081 or dl,al
2082 lodsb
2083 xor al,'3'
2084 or dl,al
2085 lodsb
2086 xor al,'2'
2087 or dl,al
2088 lodsb
2089 xor al,' '
2090 or dl,al
2091 lodsb
2092 xor al,' '
2093 or dl,al
2094 lodsb
2095 xor al,' '
2096 or dl,al
2097
2098 ; Assume not present
2099 clc
2100 jnz PART_IsFAT32_exit
2101
2102 ; FAT32 signature found
2103 stc
2104
2105 PART_IsFAT32_exit:
2106 ret
2107PART_IsFAT32 Endp
2108
2109
2110
2111;
2112; ##############################################################
2113; # Does this partition have the Windows BootManager installed #
2114; ##############################################################
2115;
2116; In
2117; --
2118; DL = Physical Disk
2119; BX:CX = LBA sector
2120;
2121; Out
2122; ---
2123; CY = Set if BOOTMGR found, clear if not
2124;
2125;PART_IsWinBMGR Proc Near Uses ax bx cx dx si di ds es
2126;
2127; ; Load specified LBA sector (BX:CX) from the disk in DL
2128; mov di,ds
2129; mov si,offset [TmpSector]
2130; call DriveIO_LoadSectorLBA
2131
2132; ; Point to location of 'BOOTMGR' signature.
2133; add si,169h
2134
2135; ; DL holds equality status
2136; xor dl,dl
2137; cld
2138
2139; ; Load letter into AL, xor with letter will result 0 if the same.
2140; ; Then or to DL.
2141; ; If at the end of the sequence DL is zero, the signature is present.
2142; lodsb
2143; xor al,'B'
2144; or dl,al
2145; lodsb
2146; xor al,'O'
2147; or dl,al
2148; lodsb
2149; xor al,'O'
2150; or dl,al
2151; lodsb
2152; xor al,'T'
2153; or dl,al
2154; lodsb
2155; xor al,'M'
2156; or dl,al
2157; lodsb
2158; xor al,'G'
2159; or dl,al
2160; lodsb
2161; xor al,'R'
2162; or dl,al
2163
2164; ; Assume not present
2165; clc
2166; jnz PART_IsWinBMGR_exit
2167
2168; ; BOOTMGR signature found
2169; stc
2170
2171; PART_IsWinBMGR_exit:
2172; ret
2173;PART_IsWinBMGR Endp
2174
2175
2176;
2177; ##########################################################
2178; # Get the offset of the phys-disk field in the PBR (BPB) #
2179; ##########################################################
2180;
2181; In
2182; --
2183; DS:SI = IPT
2184;
2185; Out
2186; ---
2187; AX = Index in PBR for phys-disk field
2188;
2189PART_GetFieldIndex Proc Near uses bx cx dx
2190 ; Check for FAT32 partition
2191 mov dl,bptr [si+LocIPT_Drive]
2192 mov cx,[si+LocIPT_AbsoluteBegin+00h]
2193 mov bx,[si+LocIPT_AbsoluteBegin+02h]
2194 call PART_IsFAT32
2195 mov ax,24h ; Offset in old-style BPB
2196 jnc PART_GetFieldIndex_exit
2197 mov ax,40h ; Offset in FAT32 BPB
2198 PART_GetFieldIndex_exit:
2199 ret
2200PART_GetFieldIndex EndP
Note: See TracBrowser for help on using the repository browser.