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

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

Removed the ancient 'ReleaseCode' conditional [v1.1.1-testing]

This was used in pre v1.07 versions to create a DOS .COM executable
for debugging. It has never been used in v1.07+ versions and debugging
is now done using the serial port from native AirBoot. Time to get rid
of this unused stuff.

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: 79.9 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 1st hdd.
1321 cmp bptr [si+LocIPT_Drive], 80h
1322 ja PSP_HideAdjustPrimaryMark ; When booting any hdd, but 1st
1323 mov ax, wptr [si+LocIPT_AbsolutePartTable]
1324 mov bx, wptr [si+LocIPT_AbsolutePartTable+2]
1325 or ax, ax
1326 jnz PSP_HideAdjustPrimaryMark ; or booting non-primary partition
1327 or bx, bx ; on 1st harddrive.
1328 jz PSP_NoHideAdjustPrimaryMark
1329
1330 PSP_HideAdjustPrimaryMark:
1331 ; Load Primary Partition Table...
1332 xor ax, ax
1333 xor bx, bx
1334 mov cx, 0001h ; Cylinder 0, Sector 1
1335 mov dx, 0080h ; First HD, Head 0
1336 ; Load MBR
1337 call DriveIO_LoadPartition ; Load Primary Partition Table
1338 call PART_MarkFirstGoodPrimary
1339 call DriveIO_SavePartition ; Saves the Partition-Table
1340
1341
1342 PSP_NoHideAdjustPrimaryMark:
1343
1344
1345 PSP_NoHideFeature:
1346 ; Check, if we are supposed to ignore LVM altogether...
1347 test byte ptr [CFG_IgnoreLVM], 1
1348 jnz PSP_NoLVMReassignment
1349
1350 ; ---------------------------------------------------- LVM REASSIGNMENT
1351
1352 ; Driveletter must be set for this partition
1353 test byte ptr [si+LocIPT_Flags], Flags_DriveLetter
1354 jz PSP_NoLVMReassignment
1355 ;movzx bx, BootPartNo ; EntryNumber is straight view
1356 mov bl,[BootPartNo] ; EntryNumber is straight view
1357 mov bh,0
1358
1359 mov al, bptr [DriveLetters+bx]
1360 sub al, 3Dh ; Convert e.g. 80h -> 'C'
1361 cmp al, bptr [PartitionVolumeLetters+bx]
1362
1363
1364 ;~ je PSP_NoLVMReassignment ; If driveletters match -> no change
1365 ; Rousseau:
1366 ; But there can still be other partitions with the same drive-letter.
1367 ; For instance if the user did an advanced installation with multiple
1368 ; eComStation systems using the same boot-drive-letter.
1369 ; So, even if the drive-letter forced is the same as the
1370 ; partition-volume-letter, other partitions still need to be checked
1371 ; and possibly hidden. So we always do the drive-letter reassignment,
1372 ; which is enhanced to keep data-partitions (those -not- in the Menu)
1373 ; visible. So the 'je' instruction above is commented-out.
1374
1375
1376 ;
1377 ; Give partition SI letter AL
1378 ;
1379 call LVM_DoLetterReassignment
1380
1381
1382
1383
1384 PSP_NoLVMReassignment:
1385 push si
1386 ; -------------------------------------------------- -"PLEASE WAIT..."-
1387 PSP_IsFloppyCDROMetc:
1388 mov si, offset TXT_BootingWait
1389 call MBR_Teletype ; display "please wait" ; SI staat nog op stack; aanpassen !!!!
1390 pop si
1391
1392 ; Process Partition Tables, if M$-Hack required (changes Ext Part Type)
1393 call MSHACK_ProcessPartTables
1394
1395 test byte ptr [CFG_BootMenuActive], 0FFh
1396 jz PSP_NoMenuNoSound
1397
1398 ; ---------------------------------------------------------- BOOT-SOUND
1399 call SOUND_ExecuteBoot
1400
1401 PSP_NoMenuNoSound:
1402
1403 ; --------------------------------------------- SPECIAL BOOT PROCESSING
1404 ; Check here, if the Boot shall be done via resume to BIOS...
1405 mov al, byte ptr [si+LocIPT_SystemID]
1406 cmp al, 0FEh ; Via BIOS ? (aka resume BIOS boot sequence)
1407 je PSP_ResumeBIOSbootSeq
1408
1409; [Linux support removed since v1.02]
1410; cmp al, 0FDh ; Kernel-Booting ?
1411; je PSP_KernelBooting
1412
1413 jmp PSP_StartNormal
1414
1415 PSP_ResumeBIOSbootSeq:
1416 int 18h ; Give control back to BIOS
1417 db 0EAh ; if return to here -> Reboot
1418 dw 0FFF0h
1419 dw 0F000h
1420
1421; [Linux support removed since v1.02]
1422; PSP_KernelBooting:
1423; call LINUX_LoadKernel ; DS:SI - Entry Pointer to Kernel
1424; db 0EAh ; if return to here -> Reboot
1425; dw 0FFF0h
1426; dw 0F000h
1427
1428
1429
1430 ; =======================================================================
1431 ; FROM THIS POINT ON, ONLY DS and SI REGISTER IS NEEDED TO BE PRESERVED
1432 ; =======================================================================
1433
1434 PSP_StartNormal:
1435 mov ax, wptr [si+LocIPT_AbsoluteBegin+0]
1436 mov bx, wptr [si+LocIPT_AbsoluteBegin+2]
1437 mov cx, [si+LocIPT_LocationBegin+1]
1438 mov dh, [si+LocIPT_LocationBegin+0]
1439 mov dl, [si+LocIPT_Drive]
1440
1441 ; This loads the PBR of the partition.
1442 call DriveIO_LoadPartition ; Loads boot-sector... [PARTBOOTSEC]
1443
1444 ;
1445 ; The JFS PBR-code does not use the passed BPB in memory but uses the BPB
1446 ; on disk. This breaks the drive-letter feature on JFS.
1447 ; So we make a copy of the PBR in memory, and if the partition is JFS
1448 ; we later adjust the physical-disk and boot-drive-letter in this
1449 ; copy and write it back to disk.
1450 ; Then the JFS PBR-code will see the correct boot-drive-letter.
1451 ;
1452 pusha
1453 mov si,offset [PartitionSector]
1454 mov di,offset [PBRSector]
1455 mov cx,100h
1456 cld
1457 rep movsw
1458 popa
1459
1460
1461
1462 ; Check if the disk is a harddisk or a floppy.
1463 mov dl,[si+LocIPT_Drive]
1464 cmp dl, 80h
1465 jae is_harddisk
1466
1467 ;
1468 ; This is a dirty hack to fix booting from a floppy.
1469 ; With all the modifications made since v1.06 this feature was broken
1470 ; because Int13X is used implicitly now, and that does not work
1471 ; for diskette access.
1472 ; This jumps to the code that loads and starts the pbr-code.
1473 ; Note that it also skips virus checking !
1474 ; This will be fixed at a later date.
1475 jmp boot_from_floppy
1476
1477 ;
1478 ; The disk is a harddisk so we need to do various checks and fixes.
1479 ;
1480 is_harddisk:
1481
1482 test byte ptr [CFG_DetectVIBR], 1
1483 jz PSP_NoVIBR
1484 test byte ptr [si+LocIPT_Flags], Flags_VIBR_Detection
1485 jz PSP_NoVIBR
1486
1487
1488 ; ----------------------------------------------------- CHECKS FOR VIBR
1489 ; BOOKMARK: Check for virus in PBR
1490 push si
1491 mov si, offset PartitionSector
1492 mov bx, 4B4Dh ; Magic: 'MK'
1493 call MBR_GetCheckOfSector
1494 pop si
1495
1496 cmp [si+LocIPT_BootRecordCRC], bx
1497 je PSP_NoVIBR
1498 mov bx, [si+LocIPT_BootRecordCRC]
1499 or bx, bx
1500 jz PSP_NoVIBR
1501 ; Oh Oh, got a virus :(
1502 mov si, offset TXT_VirusFoundMain
1503 call MBR_Teletype
1504 mov si, offset TXT_VirusFound2 ; VIBR-Virus
1505 call MBR_Teletype
1506 mov si, offset TXT_VirusFoundEnd
1507 call MBR_Teletype
1508 jmp MBR_HaltSystem
1509
1510 PSP_NoVIBR:
1511 test byte ptr [CFG_ProtectMBR], 1
1512 jz PSP_NoMBRprotect
1513 ; --------------------------------------------- INSTALLS MBR-PROTECTION
1514 ; We need DS:SI later...
1515 push ds
1516 push si
1517
1518 ; First subtract 1024 bytes from Base-Memory...
1519 push ds
1520 mov ax, 40h
1521 mov ds, ax
1522 mov dx, word ptr ds:[13h]
1523 dec dx ; 1 == 1kbyte
1524 mov word ptr ds:[13h], dx
1525 pop ds
1526 shl dx, 6 ; trick, now DX is a segment
1527
1528 ; Now copy in our code (to DX:0)...
1529
1530 mov si, offset MBR_Protection ; DS:SI - Source Image
1531 mov es, dx
1532 xor di, di ; ES:DI - Destination
1533 ;~ mov cx, 512
1534 mov cx, 384
1535 rep movsw ; Move 768 bytes...
1536
1537 ; Now fill in variables...
1538
1539 xor ax, ax
1540 mov ds, ax
1541 mov si, 10h*4
1542 xor di, di ; INT 10h Vector to MBR Protection
1543 ;movsd
1544 movsw
1545 movsw
1546
1547 mov si, 13h*4 ; INT 13h Vector to MBR Protection
1548 ;movsd
1549 movsw
1550 movsw
1551
1552 mov al, CFG_IgnoreWriteToMBR ; Option to MBR Protection
1553 stosb
1554
1555 ; Now switch INT 13h vector to MBR Protection
1556
1557 sub si, 4
1558 mov ax, 9
1559 mov ds:[si], ax
1560 mov ds:[si+2], dx ; Vector hardcoded at DS:0009
1561 ; MBR-Protection now active :)
1562
1563 ; Restore DS:SI
1564 pop si
1565 pop ds
1566
1567
1568
1569 PSP_NoMBRprotect:
1570
1571 ; Display volume-name in bold
1572 ; Just before booting the selected partition
1573 ;pushf
1574 ;pusha
1575 ;push si
1576 ;add si, LocIPT_Name
1577 ;call MBR_TeletypeVolName
1578 ;xor si,si
1579 ;call MBR_TeletypeNL
1580 ;pop si
1581 ;popa
1582 ;popf
1583
1584
1585
1586
1587
1588 ; ------------------------------------------------ SPECIAL PARTITION SUPPORT
1589 ; needed by OS/2 Warp / eComStation
1590
1591
1592 ;cmp byte ptr [si+LocIPT_SystemID],08 ; I hate Microsuck NTFS check
1593 mov di, offset PartitionSector ; ES:DI - Actual Boot-Record
1594
1595 ; Special Support Detection
1596 ;mov ax, word ptr es:[di+18h]
1597 ;cmp ax, 003Fh ; Physical Layout-Sectors... Safety check
1598
1599
1600
1601 ;
1602 ; At this point, SI points to IPT and DI points to the PBR from disk.
1603 ; Depending on the type of BPB used, the physical disk field is at
1604 ; different locations: 24h for old-style (OS/2) BPB's and 40h for
1605 ; FAT32 BPB's.
1606 ; The OS/2 boot-drive-letter is located at 25h in an old-style BPB,
1607 ; while the corresponding field in a FAT32 BPB is located at 41h but
1608 ; used for different purposes.
1609 ; In case of HPFS, using old-style BPB's, the boot-drive-letter needs
1610 ; to be adjusted if it is zero.
1611 ; In that case we trace the LVM-info for that partition and use the
1612 ; drive-letter defined there.
1613 ; This fixes issues #3067 and #3119.
1614 ; Adjusting the physical disk is always done but at different locations
1615 ; depending on the BPB used.
1616 ; Also, the "hidden sectors" field is adjusted to contain the absolute
1617 ; offset from the start of the disk instead of the relative offset to
1618 ; the start of the partition.
1619 ; http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/bios-parameter-block.html
1620 ;
1621
1622
1623 ; Get index of phys-disk field in BX
1624 call PART_GetFieldIndex
1625 mov [PhysDiskBpbIndex],ax
1626 mov bx,ax
1627
1628 ; Locate cursor for output of debug-info
1629 ;~ pusha
1630 ;~ mov ch,7
1631 ;~ mov cl,0
1632 ;~ call VideoIO_Color
1633 ;~ mov ch,6
1634 ;~ mov cl,1
1635 ;~ call VideoIO_Locate
1636 ;~ popa
1637
1638
1639 ; Debug display physdisk, ptype and physdisk offset in BPB
1640 ;~ pusha
1641 ;~ mov ah,[si+LocIPT_Drive]
1642 ;~ mov al,[si+LocIPT_SystemID]
1643 ;~ call VideoIO_PrintHexWord
1644 ;~ mov ax,bx
1645 ;~ call VideoIO_PrintHexWord
1646 ;~ mov ax,[si+LocIPT_AbsolutePartTable+02]
1647 ;~ call VideoIO_PrintHexWord
1648 ;~ mov ax,[si+LocIPT_AbsolutePartTable+00]
1649 ;~ call VideoIO_PrintHexWord
1650 ;~ mov al,[ExtendedAbsPosSet]
1651 ;~ call VideoIO_PrintHexByte
1652 ;~ mov al,'-'
1653 ;~ call VideoIO_PrintSingleChar
1654 ;~ mov al,byte ptr [Menu_EntrySelected]
1655 ;~ call VideoIO_PrintHexByte
1656 ;~ mov al,byte ptr [CFG_PartAutomatic]
1657 ;~ call VideoIO_PrintHexByte
1658 ;~ mov al,byte ptr [Phase1Active]
1659 ;~ call VideoIO_PrintHexByte
1660 ;~ mov al,byte ptr [NewPartitions]
1661 ;~ call VideoIO_PrintHexByte
1662 ;~ mov al, byte ptr [OldPartitionCount]
1663 ;~ call VideoIO_PrintHexByte
1664 ;~ popa
1665
1666
1667 ;
1668 ; If the partition is IBM-BM we skip all the BPB adjustments.
1669 ; IBM-BM does no need them.
1670 ;
1671 cmp byte ptr [si+LocIPT_SystemID], 0ah
1672 jnz no_os2_bm
1673 jmp chainload_ibm_bm
1674
1675
1676 no_os2_bm:
1677
1678 ;
1679 ; Update the phys-disk field
1680 ; DI points to PartitionSector
1681 ; BX holds index to phys-disk field
1682 ;
1683 mov al,byte ptr [si+LocIPT_Drive] ; Moet dit niet later gebeuren ??? (NT/WIN LDR hangs)
1684 mov es:[di+bx],al
1685
1686
1687 ;
1688 ; Legacy systems do not put the correct values in the "hidden sectors"
1689 ; field. Also, this field will be incorrect if a partition is moved on
1690 ; disk by a disktool not accounting for this field.
1691 ; Linux does not have a BPB at all, and does not use this field.
1692 ; So we set the correct value here obtained by the partition scanner.
1693 ; This fixing is done by OS/2 BM as well, according to Martin.
1694 ;
1695
1696 ; BOOKMARK: Fix hidden sectors field
1697 mov ax,[si+LocIPT_AbsoluteBegin]
1698 mov es:[di+1ch], ax ; Low word of 32-bits "hidden sectors"
1699
1700 mov ax,[si+LocIPT_AbsoluteBegin+2]
1701 mov es:[di+1eh], ax ; High word of 32-bits "hidden sectors"
1702
1703 ;
1704 ; Check partitions to see if boot-drive-letter fixing is needed.
1705 ; FAT12/FAT16/HPFS/JFS will have the value at 25h fixed
1706 ; to the LVM-info drive-letter. (+3dh to convert to BIOS notation)
1707 ;
1708
1709
1710 ; Setup partition disk and LBA address
1711 mov dl,byte ptr [si+LocIPT_Drive]
1712 mov cx,[si+LocIPT_AbsoluteBegin+00h]
1713 mov bx,[si+LocIPT_AbsoluteBegin+02h]
1714
1715 ; AL is gonna be used to shift-in CY status.
1716 ; If the type of file-system is one of FAT12/FAT16/HPFS/JFS then
1717 ; AL will be <> 0 and the boot-drive-letter can be tested / fixed.
1718 mov al,0
1719
1720
1721 ;
1722 ; The PBR is already loaded, no need to load it again in the
1723 ; calls below.
1724 ;
1725 ; Better use the already done discovery to determine the system.
1726 ;
1727 ; FIXME: PBR Already loaded
1728
1729 ; When FAT12/FAT16/HPFS/JFS then boot-drive-letter can be tested
1730 ; or adjusted.
1731 call PART_IsJFS
1732 rcl al,1
1733 call PART_IsHPFS
1734 rcl al,1
1735 call PART_IsFAT
1736 rcl al,1
1737 mov ah,al
1738
1739 ; Store for later reference.
1740 mov [FSType],al
1741
1742
1743 ;
1744 ; When the phys-disk byte (80h) is put in this BPB in RAM,
1745 ; Windows will not find it's loader if Windows itself
1746 ; is installed in a logical partition but the loader is on FAT
1747 ; in a primary.
1748 ; This goes for all NT-based versions ?
1749 ;
1750
1751
1752 ;
1753 ; See if phys-disk / boot-drive-letter fix is needed
1754 ; depending on FS used.
1755 ; AL will be 0 for any file-system other than FAT12/FAT16/HPFS/JFS.
1756 ; In that case no fixing of boot-drive-letters is needed.
1757 ;
1758 test al,al
1759 jz bdl_ok
1760
1761
1762 ;
1763 ; We have a partition that potentially can have incorrect values
1764 ; for the boot-drive-letter or incorrect LVM drive-letters.
1765 ;
1766 ; The boot-drive-letter can be zero as the result of copying / moving
1767 ; partitions or restoring a HPFS system from archive.
1768 ; In that case the LVM drive-letter is used if present.
1769 ;
1770 ; Incorrect LVM drive-letters are the result of the drive-letter
1771 ; reassign function when two or more eComStation installations use the
1772 ; same boot-drive-letter.
1773 ; In that case the boot-drive-letter is assigned to the
1774 ; LVM drive-letter.
1775 ;
1776 ; If both are zero there is no way to obtain the correct
1777 ; boot-drive-letter value. The user needs to examine CONFIG.SYS and
1778 ; force that letter for the partition.
1779 ;
1780
1781
1782
1783
1784
1785 ;
1786 ; Get the drive-letter for the partition from the LVM-info.
1787 ; Returns CY=1 if AL contains drive-letter, CY=0 and AL=0 if
1788 ; no letter assigned (hidden) or no LVM info found.
1789 ;
1790 mov dl,byte ptr [si+LocIPT_Drive]
1791 mov cx,[si+LocIPT_AbsoluteBegin+00h]
1792 mov bx,[si+LocIPT_AbsoluteBegin+02h]
1793 call LVM_GetDriveLetter
1794
1795
1796 ; Save for later use.
1797 mov byte ptr [LVMdl], al
1798
1799 ; See if the drive-letter feature is active.
1800 ; If active, we force the drive-letter from the user.
1801 test byte ptr [si+LocIPT_Flags], Flags_DriveLetter
1802
1803 ; Nope, it's not so we don't force the boot-drive-letter.
1804 jz PSP_NoLogicalSupport
1805
1806 ; Partition index in BX
1807 mov bl,[BootPartNo] ; EntryNumber is straight view
1808 mov bh,0
1809
1810 ; Get the user specified boot-drive-letter.
1811 ; 80h notation.
1812 mov al, bptr [DriveLetters+bx]
1813
1814 ; Safety check for zero value.
1815 test al,al
1816 jz PSP_NoValidUserDriveLetter
1817
1818 ; Convert 80h notation to ASCII.
1819 sub al,3dh ; 80h - 3dh = 43h = 'C', etc.
1820
1821 PSP_NoValidUserDriveLetter:
1822 ; Here we misuse the LVM-dl storage to store the user forced
1823 ; or zero drive-letter.
1824 mov byte ptr [LVMdl], al
1825
1826
1827 PSP_NoLogicalSupport:
1828
1829 ; A possibly valid drive-letter has been obtained from either
1830 ; LVM-info or the drive-letter feature.
1831 ; It's in [LDMdl] local storage.
1832
1833
1834
1835 ;
1836 ; Get the boot-drive-letter from the BPB of the partition.
1837 ;
1838 mov bx, [PhysDiskBpbIndex]
1839 inc bx
1840 mov al,es:[di+bx] ; 80h=C:,81h=D:, etc.
1841 ; Store it for later use
1842 mov byte ptr [BPBdl], al
1843
1844
1845 ; See if both the LVM drive-letter and the BPB drive-letter are zero.
1846 ; If so, then we have a problem.
1847 ; No valid drive-letter can be obtained and the user has to examine
1848 ; CONFIG.SYS and set that letter in the drive-letter feature
1849 ; for the partition.
1850 mov ah,al
1851 mov al, byte ptr [LVMdl]
1852 or al,ah
1853 jz no_valid_boot_drive_letter_found
1854
1855
1856 ; See if both the LVM drive-letter and the BPB drive-letter are
1857 ; the same. In that case we should have a valid situation and no
1858 ; adjustments need to be made.
1859 cmp al,ah
1860 jz PSP_valid_boot_drive
1861
1862
1863 ;
1864 ; Ok, at least one of them is valid.
1865 ;
1866
1867 ; See if the BPB boot-drive-letter is valid
1868 ; This one is supposed not to change since OS/2 cannot be booted
1869 ; from another drive then it was installed on.
1870 test ah,ah
1871 jnz BPB_boot_drive_valid
1872
1873 ; Nope it's not.
1874 ; So we use the LVM drive-letter for the BPB boot-drive-letter.
1875 ; Convert to BIOS notation ('C'+3dh=80h, 'D'->81h, etc.)
1876 ; This is where the user can fix this issue by using the
1877 ; drive-letter feature.
1878 add al,3dh
1879 mov bx,[PhysDiskBpbIndex]
1880 ; Advance to field for drive-letter in BIOS notation (OS/2)
1881 inc bx
1882 ; Fix the boot-drive-letter field in the BPB
1883 mov es:[di+bx],al
1884
1885 jmp PSP_valid_boot_drive
1886
1887 ;
1888 ; OS/2 uses this field to indicate the boot-drive-letter for the system.
1889 ; It is in BIOS notation where 80h='C', 81h='D' ... 97h='Z'.
1890 ; This is the field that get's forced to a specific value when the
1891 ; drive-letter feature of AiR-BOOT is used.
1892 ; Also, this field is the culprit of AiR-BOOT v1.07 not handling it
1893 ; correctly when the system uses HPFS and this byte is zero.
1894 ; This mostly involved booting older OS/2 versions on HPFS.
1895 ; See issues #3067 and #3119 on http://bugs.ecomstation.nl
1896 ;
1897
1898
1899 ;
1900 ; Here we enter when the LVM drive-letter is zero or not the same
1901 ; as the BPB boot-drive-letter.
1902 ; This can be the case when booting a hidden partition, LVM-dl = zero,
1903 ; or the LVM-dl was reassigned because another system with the same
1904 ; drive-letter was booted previously.
1905 ; In any case, we set the LVM drive-letter to the BPB boot-drive-letter
1906 ; so the system can be booted.
1907 ; Driveletters on other partitions have already been reassigned by the
1908 ; reassignement-procedure earlier.
1909 ;
1910 BPB_boot_drive_valid:
1911
1912
1913
1914
1915 ;
1916 ; ALWAYS SET LVM to BPB
1917 ;
1918 ;~ mov dl,byte ptr [si+LocIPT_Drive]
1919 ;~ mov cx,[si+LocIPT_AbsoluteBegin+00h]
1920 ;~ mov bx,[si+LocIPT_AbsoluteBegin+02h]
1921 ;~ mov al,[BPBdl]
1922 ;~ sub al,3dh
1923 ;~ call LVM_SetDriveLetter ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1924
1925
1926 ;
1927 ; ALWAYS SET BPB to LVM
1928 ;
1929 mov dl,byte ptr [si+LocIPT_Drive]
1930 mov cx,[si+LocIPT_AbsoluteBegin+00h]
1931 mov bx,[si+LocIPT_AbsoluteBegin+02h]
1932 call LVM_GetDriveLetter ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1933 add al,3dh
1934 mov bx,[PhysDiskBpbIndex]
1935 inc bx
1936 mov es:[di+bx],al
1937
1938
1939 update_PBR:
1940
1941
1942
1943 ;
1944 ; Here both the boot-drive-letter and the LVM drive-letter are zero.
1945 ; So the only way to determine the drive-letter is to examine CONFIG.SYS.
1946 ; Then force that drive-letter in the drive-letter feature.
1947 no_valid_boot_drive_letter_found:
1948 ; HERE SHOULD COME AN ERROR POP-UP ABOUT NO BOOT-DRIVE OR NO LVM-INFO.
1949 ; WE CONTINUE BOOTING BUT OS/2 WILL MOST PROBABLY FAIL TO BOOT.
1950
1951 ; FIXME: Issue some kind of warning
1952
1953 ;mov ah,07h
1954 ;mov si,offset CheckID_MBR
1955 ;call VideoIO_Print
1956
1957 hang:
1958 ;jmp hang
1959
1960
1961
1962
1963 PSP_valid_boot_drive:
1964
1965
1966
1967
1968 ;
1969 ; Boot DriveLetter OK.
1970 ;
1971 bdl_ok:
1972
1973
1974IFDEF AUX_DEBUG
1975 pusha
1976 call AuxIO_TeletypeNL
1977 mov bx, [PhysDiskBpbIndex]
1978 inc bx
1979 mov al, [di+bx]
1980 call AuxIO_TeletypeHexByte
1981 mov bl,[BootPartNo]
1982 mov al, [DriveLetters+bx]
1983 call AuxIO_TeletypeHexByte
1984 mov al, [PartitionVolumeLetters+bx]
1985 add al, 3dh
1986 call AuxIO_TeletypeHexByte
1987 mov al, [LVMdl]
1988 add al, 3dh
1989 call AuxIO_TeletypeHexByte
1990 mov al, [si+LocIPT_SystemID]
1991 call AuxIO_TeletypeHexByte
1992 mov al,[FSType]
1993 call AuxIO_TeletypeHexByte
1994 popa
1995ENDIF
1996
1997 ;
1998 ; If the partition getting booted is a JFS partition then write-back
1999 ; the modified PBR to the disk.
2000 ; Note that it's not the in-memory PBR that get's written back, but
2001 ; a copy of the original where only the phys-disk and boot-drive-letter
2002 ; are adjusted.
2003 ;
2004 pusha
2005 mov al,[FSType]
2006 cmp al,04h ; JFS
2007 je write_back_pbr
2008 cmp al,02h ; HPFS
2009 je write_back_pbr
2010
2011 jmp no_jfs_pbr
2012
2013
2014 write_back_pbr:
2015
2016 ; Save IPT pointer
2017 push si
2018
2019 ; Copy the boot-drive and boot-drive-letter fields.
2020 mov si,offset [PartitionSector]
2021 mov di,offset [PBRSector]
2022 mov al,[si+24h]
2023 mov [di+24h],al
2024 mov al,[si+25h]
2025 mov [di+25h],al
2026
2027 ; Restore IPT pointer
2028 pop si
2029
2030
2031 ; BOOKMARK: Update the CRC of the Partition Boot Record.
2032 mov bx, offset [PBRSector]
2033 call PART_UpdateBootRecordCRC
2034 call DriveIO_SaveConfiguration
2035
2036
2037 ; Setup the registers for the partition location.
2038 mov ax, wptr [si+LocIPT_AbsoluteBegin+0]
2039 mov bx, wptr [si+LocIPT_AbsoluteBegin+2]
2040 mov cx, [si+LocIPT_LocationBegin+1]
2041 mov dh, [si+LocIPT_LocationBegin+0]
2042 mov dl, [si+LocIPT_Drive]
2043
2044
2045 ; BOOKMARK: Write the adjusted HPFS/JFS PBR to disk.
2046 mov si, offset [PBRSector]
2047 call DriveIO_SaveSector
2048
2049 no_jfs_pbr:
2050 popa
2051
2052
2053
2054 ; ----------------------------------------------- LOGICAL PARTITION SUPPORT
2055
2056
2057
2058 ; AiR-BOOT now works around it by using the LVM-info (DLAT) of
2059 ; the partiton if present.
2060 ; Note however that if the drive-letter feature is active,
2061 ; this will override AB's automatic fixing.
2062 ;
2063 ; Test if the drive-letter feature is active for this partition.
2064 ; If so, then the drive that the user defined will be placed at
2065 ; byte 25h (37d) of the in-ram PartitionSector (BPB).
2066 ; (BIOS 80h notation: 80h=C, 81h=D, etc.)
2067 ; This is a remedy for when the corresponding field (25h) in the BPB on
2068 ; disk is zero.
2069 ;
2070
2071
2072
2073 ;
2074 ; Control is transferred to this point if we are booting IBM-BM.
2075 ; IBM-BM does not need the BPB fixes.
2076 ; It does require a other special stuff, which is already taken care of.
2077 ;
2078 chainload_ibm_bm:
2079
2080 ;
2081 ; Control is transferred to this point if we are booting a floppy.
2082 ; Booting from floppy skips all the harddisk related stuff.
2083 ; This is a dirty hack to fix the boot from floppy feature.
2084 ;
2085 boot_from_floppy:
2086
2087
2088
2089
2090 ;
2091 ; Here we copy the prepared boot-record to 0000:7C00h
2092 ; to give it control later on.
2093 ;
2094 push es
2095 push si
2096 mov ax, StartBaseSeg
2097 mov es, ax
2098 mov cx, 256
2099 mov si, offset PartitionSector
2100 mov di, StartBasePtr
2101 cld
2102 rep movsw
2103 pop si
2104 pop es
2105
2106 ; --------------------------------------------------- NOW START BOOT-RECORD
2107
2108
2109
2110
2111 IFDEF AUX_DEBUG
2112 pusha
2113 call DEBUG_Dump2
2114 ;~ call DEBUG_DumpBSSSectors
2115 call DEBUG_DumpDriveLetters
2116 call DEBUG_DumpVolumeLetters
2117 call AuxIO_TeletypeNL
2118 popa
2119 ENDIF
2120
2121
2122
2123;
2124; ################################## BYE BYE ##################################
2125;
2126
2127 IFNDEF AUX_DEBUG
2128 ; Skip wait-for-key
2129 jmp StartPBR
2130 ENDIF
2131
2132 ;
2133 ; Wait for keypress
2134 ;
2135 xor ax, ax
2136 int 16h
2137
2138 ; Is escape-key ?
2139 cmp al, 1bh
2140
2141 ; Nope, Go activate PBR loader
2142 jne StartPBR
2143
2144 ;push ds
2145 ;pop es
2146
2147 ; Yep, restart AiR-BOOT so simulate load DX:BX with old BIOS SS:SP
2148 jmp AirbootRestart
2149
2150 ; Yep, Reenter bootmenu
2151 ;~ jmp MBR_Main_ReEnterBootMenuPre
2152
2153
2154
2155;
2156; Transfer control to the PBR
2157;
2158StartPBR:
2159
2160 ; Debug display index
2161 ;pusha
2162 ;mov al, cs:[si+LocIPT_Drive] ; Drive Physical No
2163 ;mov ah, cs:[si+LocIPT_SystemID] ; SystemID
2164 ;call VideoIO_PrintHexWord
2165 ;xor ax, ax
2166 ;int 16h
2167 ;popa
2168
2169 ;~ jmp skip_delay
2170
2171
2172 ;
2173 ; Show dot's to indicate something is happening...
2174 ;
2175 call VideoIO_ShowWaitDots
2176
2177 ;
2178 ; Enter here to skip delay.
2179 ;
2180 skip_delay:
2181
2182
2183
2184
2185 ;
2186 ; BYE BYE (prepare some registers? look at other MBR-code)
2187 ;
2188 xor ax, ax
2189 xor bx, bx
2190 xor cx, cx
2191 mov ds, ax
2192 mov es, ax
2193 xor dh, dh
2194 mov dl, cs:[si+LocIPT_Drive] ; Drive Physical No
2195
2196
2197 ; BOOKMARK: JUMP TO PBR CODE
2198 ; ###############################
2199 ; # JUMP TO THE PBR LOADER CODE #
2200 ; ###############################
2201 db 0EAh
2202 dw StartBasePtr
2203 dw StartBaseSeg
2204
2205
2206PART_StartPartition EndP
2207
2208
2209
2210
2211
2212
2213
2214
2215;
2216; ######################################
2217; # Is this a primary partition or not #
2218; ######################################
2219;
2220; In
2221; --
2222; DL = Physical Disk
2223; BX:CX = LBA sector
2224;
2225; Out
2226; ---
2227; AX = Index in PT if found, otherwise -1
2228; CY = Set if Primary, clear if not
2229;
2230PART_IsPrimaryPartition Proc Near Uses bx cx dx si di ds es
2231 ; Push LBA address of partition
2232 push bx
2233 push cx
2234
2235 ; Load LBA sector 0 from the disk specified in DL
2236 xor bx,bx
2237 xor cx,cx
2238 mov di,ds
2239 mov si,offset [TmpSector]
2240 call DriveIO_LoadSectorLBA
2241
2242 ; Restore partitions LBA address to DI:SI
2243 pop si
2244 pop di
2245
2246 ; Return with index -1 and CY clear if there was an
2247 ; error loading the sector.
2248 mov ax,-1
2249 cmc
2250 jnc PART_IsPrimaryPartition_exit
2251
2252 ; Compare the partition address with each entry in the P-table
2253 mov cx,4 ; Nr. of PT-entries
2254 mov dx,offset [TmpSector]
2255 add dx,01beh+08h ; Point DX to 1st partition address
2256
2257 next_pe:
2258 ; Compute pointer to PE
2259 mov bx,dx ; Point BX to 1st partition address
2260 mov ax,cx ; Get PE-index
2261 dec ax ; Index is zero based so adjust it
2262 shl ax,4 ; PE's are 16 bytes in size
2263 add bx,ax ; Make BX point to the PE
2264
2265 ; Compare LBA address
2266 push si
2267 push di
2268 xor si,[bx+00h] ; Will put 0 in SI if the same
2269 xor di,[bx+02h] ; Will put 0 in DI if the same
2270 or si,di ; Wil set ZF if both zero
2271 pop di
2272 pop si
2273 loopnz next_pe ; Try next entry if non-zero
2274
2275 ; Partition found or counter exhausted
2276 mov ax,-1
2277 clc
2278 ; Not found, so exit with NC and invalid index
2279 jnz PART_IsPrimaryPartition_exit
2280
2281 ; Partition is Primary, set CY and return index
2282 mov ax,cx
2283 stc
2284
2285 PART_IsPrimaryPartition_exit:
2286 ret
2287PART_IsPrimaryPartition Endp
2288
2289
2290
2291;
2292; #############################
2293; # Is this an HPFS partition #
2294; #############################
2295;
2296; In
2297; --
2298; SI = Pointer to IPT entry
2299;
2300; Out
2301; ---
2302; CY = Set if HPFS partition, clear if not
2303;
2304PART_IsHPFS Proc Near Uses ax
2305 mov al, [si+LocIPT_SystemID] ; Get SystemID
2306 cmp al, 07h ; Compare with AiR-BOOT ID for HPFS
2307 stc ; Assume HPFS
2308 je PART_IsHPFS_exit ; Yep
2309 clc ; Nope, clear CY
2310 PART_IsHPFS_exit:
2311 ret
2312PART_IsHPFS Endp
2313
2314
2315;
2316; ###########################
2317; # Is this a JFS partition #
2318; ###########################
2319;
2320; In
2321; --
2322; SI = Pointer to IPT entry
2323;
2324; Out
2325; ---
2326; CY = Set if JFS partition, clear if not
2327;
2328PART_IsJFS Proc Near Uses ax
2329 mov al, [si+LocIPT_SystemID] ; Get SystemID
2330 cmp al, 0fch ; Compare with AiR-BOOT ID for JFS
2331 stc ; Assume JFS
2332 je PART_IsJFS_exit ; Yep
2333 clc ; Nope, clear CY
2334 PART_IsJFS_exit:
2335 ret
2336PART_IsJFS Endp
2337
2338
2339
2340;
2341; #############################
2342; # Is this an NTFS partition #
2343; #############################
2344;
2345; In
2346; --
2347; SI = Pointer to IPT entry
2348;
2349; Out
2350; ---
2351; CY = Set if NTFS partition, clear if not
2352;
2353PART_IsNTFS Proc Near Uses ax
2354 mov al, [si+LocIPT_SystemID] ; Get SystemID
2355 cmp al, 08h ; Compare with AiR-BOOT ID for NTFS
2356 stc ; Assume NTFS
2357 je PART_IsNTFS_exit ; Yep
2358 clc ; Nope, clear CY
2359 PART_IsNTFS_exit:
2360 ret
2361PART_IsNTFS Endp
2362
2363
2364;
2365; ######################################
2366; # Is this a FAT12 or FAT16 partition #
2367; ######################################
2368;
2369; In
2370; --
2371; SI = Pointer to IPT entry
2372;
2373; Out
2374; ---
2375; CY = Set if FAT12 or FAT16 partition, clear if not
2376;
2377PART_IsFAT Proc Near Uses ax
2378 mov al, [si+LocIPT_SystemID] ; Get SystemID
2379 cmp al, 04h ; Is FAT12 ?
2380 stc
2381 je PART_IsFAT_exit ; Yep
2382 cmp al, 06h ; Is FAT16 CHS ?
2383 stc
2384 je PART_IsFAT_exit ; Yep
2385 cmp al, 0eh ; Is FAT16 LBA ?
2386 stc
2387 je PART_IsFAT_exit ; Yep
2388 clc ; Nope
2389 PART_IsFAT_exit:
2390 ret
2391PART_IsFAT Endp
2392
2393
2394;
2395; #############################
2396; # Is this a FAT32 partition #
2397; #############################
2398;
2399; In
2400; --
2401; SI = Pointer to IPT entry
2402;
2403; Out
2404; ---
2405; CY = Set if FAT32 partition, clear if not
2406;
2407PART_IsFAT32 Proc Near Uses ax
2408 mov al, [si+LocIPT_SystemID] ; Get SystemID
2409 cmp al, 0bh ; Is FAT32 CHS ?
2410 stc
2411 je PART_IsFAT32_exit ; Yep
2412 cmp al, 0ch ; Is FAT32 LBA ?
2413 stc
2414 je PART_IsFAT32_exit ; Yep
2415 clc ; Nope
2416 PART_IsFAT32_exit:
2417 ret
2418PART_IsFAT32 Endp
2419
2420
2421
2422;
2423; ##############################################################
2424; # Does this partition have the Windows BootManager installed #
2425; ##############################################################
2426;
2427; In
2428; --
2429; DL = Physical Disk
2430; BX:CX = LBA sector
2431;
2432; Out
2433; ---
2434; CY = Set if BOOTMGR found, clear if not
2435;
2436;PART_IsWinBMGR Proc Near Uses ax bx cx dx si di ds es
2437;
2438; ; Load specified LBA sector (BX:CX) from the disk in DL
2439; mov di,ds
2440; mov si,offset [TmpSector]
2441; call DriveIO_LoadSectorLBA
2442
2443; ; Point to location of 'BOOTMGR' signature.
2444; add si,169h
2445
2446; ; DL holds equality status
2447; xor dl,dl
2448; cld
2449
2450; ; Load letter into AL, xor with letter will result 0 if the same.
2451; ; Then or to DL.
2452; ; If at the end of the sequence DL is zero, the signature is present.
2453; lodsb
2454; xor al,'B'
2455; or dl,al
2456; lodsb
2457; xor al,'O'
2458; or dl,al
2459; lodsb
2460; xor al,'O'
2461; or dl,al
2462; lodsb
2463; xor al,'T'
2464; or dl,al
2465; lodsb
2466; xor al,'M'
2467; or dl,al
2468; lodsb
2469; xor al,'G'
2470; or dl,al
2471; lodsb
2472; xor al,'R'
2473; or dl,al
2474
2475; ; Assume not present
2476; clc
2477; jnz PART_IsWinBMGR_exit
2478
2479; ; BOOTMGR signature found
2480; stc
2481
2482; PART_IsWinBMGR_exit:
2483; ret
2484;PART_IsWinBMGR Endp
2485
2486
2487;
2488; ##########################################################
2489; # Get the offset of the phys-disk field in the PBR (BPB) #
2490; ##########################################################
2491;
2492; In
2493; --
2494; DS:SI = IPT
2495;
2496; Out
2497; ---
2498; AX = Index in PBR for phys-disk field
2499;
2500PART_GetFieldIndex Proc Near uses bx cx dx
2501 ; Check for FAT32 partition
2502 mov dl,bptr [si+LocIPT_Drive]
2503 mov cx,[si+LocIPT_AbsoluteBegin+00h]
2504 mov bx,[si+LocIPT_AbsoluteBegin+02h]
2505 call PART_IsFAT32
2506 mov ax,24h ; Offset in old-style BPB
2507 jnc PART_GetFieldIndex_exit
2508 mov ax,40h ; Offset in FAT32 BPB
2509 PART_GetFieldIndex_exit:
2510 ret
2511PART_GetFieldIndex EndP
Note: See TracBrowser for help on using the repository browser.