source: trunk/bootcode/regular/partmain.asm@ 96

Last change on this file since 96 was 96, checked in by Ben Rietbroek, 8 years ago

Removed Linux noise [v1.1.1-testing]

This stuff was already commented out and not applicable anymore.
It was used to directly boot Linux kernels from FAT some eons ago.
Linux is supported by chain-loading GRUB.

CAUTION:
This is a testbuild !
AirBoot uses the BIOS to access disks and a small coding error can trash
partition tables or other vital disk structures. You are advised to make
backups of TRACK0 and EBRs before using this testbuild. More info at:
https://rousseaux.github.io/netlabs.air-boot/pdf/AirBoot-v1.1.0-manual.pdf

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