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

Last change on this file since 65 was 57, checked in by Ben Rietbroek, 10 years ago

All source-files lowercased [v1.1.1-testing]

Some standard files like 'COPYING', 'LICENSE', etc. have not been
converted to lower case because they are usually distributed uppercased.

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