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

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

More hard-coded '80h' corrections [v1.1.1-testing]

Code in 'partmain.asm' around line 1350 needs some more attention.
Possibly the whole 'boot-flag' stuff is not needed with modern BIOSses.
Updating them is disabled for now, which should only affect very old
BIOSses that don't leave this checking to the MBR code.

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