| 1 |
|
|---|
| 2 | ; Disclaimer:
|
|---|
| 3 | ;=============
|
|---|
| 4 | ; The sourcecode is released via www.netlabs.org CVS *ONLY*.
|
|---|
| 5 | ; You MUST NOT upload it to other servers nor republish it in any way.
|
|---|
| 6 | ; The sourcecode is still COPYRIGHTED and NOT YET RELEASED UNDER GPL.
|
|---|
| 7 | ; It's (c) Copyright 1998-2002 by Martin Kiewitz.
|
|---|
| 8 | ; You may recompile the source and do *PRIVATE* modifications, but please keep
|
|---|
| 9 | ; in mind that modifying this code needs at least *some* assembly skill. If
|
|---|
| 10 | ; you mess up your system, because you needed to hack your way through, don't
|
|---|
| 11 | ; blame me. Releasing a customized version of AiR-BOOT, selling it in any form
|
|---|
| 12 | ; or reusing parts of this source is *PROHIBITED*. Ask me, if you have some
|
|---|
| 13 | ; idea about new functionality *before* developing the code, otherwise I will
|
|---|
| 14 | ; definitely reject it. Also please accept, that I have some basic design
|
|---|
| 15 | ; rules on AiR-BOOT and I will maintain them at all costs, so this won't get
|
|---|
| 16 | ; another GRUB.
|
|---|
| 17 |
|
|---|
| 18 | ;---------------------------------------------------------------------------
|
|---|
| 19 | ; AiR-BOOT / PARTiTiON REGULAR ROUTINES
|
|---|
| 20 | ;---------------------------------------------------------------------------
|
|---|
| 21 |
|
|---|
| 22 | PART_FixUpDefaultPartitionValues Proc Near Uses dx si di
|
|---|
| 23 | ; Fix-Up Default and Last Partition - If lost, search for Bootable
|
|---|
| 24 | xor bl, bl
|
|---|
| 25 | mov dl, CFG_PartDefault
|
|---|
| 26 | call PART_FixUpPartitionNumber
|
|---|
| 27 | mov CFG_PartDefault, dl
|
|---|
| 28 | mov dl, CFG_PartLast
|
|---|
| 29 | call PART_FixUpPartitionNumber
|
|---|
| 30 | mov CFG_PartLast, dl
|
|---|
| 31 | mov dl, CFG_PartAutomatic
|
|---|
| 32 | call PART_FixUpPartitionNumber
|
|---|
| 33 | mov CFG_PartAutomatic, dl
|
|---|
| 34 |
|
|---|
| 35 | ; Fix-Up Linux Kernel Partition - If lost, search for FAT-16
|
|---|
| 36 | mov bl, 06h
|
|---|
| 37 | mov dl, CFG_LinuxKrnlPartition
|
|---|
| 38 | call PART_FixUpPartitionNumber
|
|---|
| 39 | mov CFG_LinuxKrnlPartition, dl
|
|---|
| 40 |
|
|---|
| 41 | ; Fix-Up Linux Root Partition - If lost, search for Linux partition (83h)
|
|---|
| 42 | mov bl, 83h
|
|---|
| 43 | mov dl, CFG_LinuxRootPartition
|
|---|
| 44 | call PART_FixUpPartitionNumber
|
|---|
| 45 | mov CFG_LinuxRootPartition, dl
|
|---|
| 46 | ret
|
|---|
| 47 | PART_FixUpDefaultPartitionValues EndP
|
|---|
| 48 |
|
|---|
| 49 | ; Our resync process for partition number is as specified:
|
|---|
| 50 | ;==========================================================
|
|---|
| 51 | ; - If 0FFh -> Partition Disabled, so don't do anything to it...
|
|---|
| 52 | ; - Try to use GetXref to get the new partition no via X-Ref Table
|
|---|
| 53 | ; - If failed, increase partition no, till overflow or hit on specific
|
|---|
| 54 | ; characteristic
|
|---|
| 55 | ; On overflow -> Resume search from partition no 0
|
|---|
| 56 | ;
|
|---|
| 57 | ; Characteristic is a partition id. If this id is 0, then a bootable partition
|
|---|
| 58 | ; is searched for.
|
|---|
| 59 |
|
|---|
| 60 | ; Fixes a partition number, adjusting it to the new IPT after redetect
|
|---|
| 61 | ; In: DL - Number of partition
|
|---|
| 62 | ; BL - Requested Partition ID
|
|---|
| 63 | ; Out: DL - New number of partition (guessed normally ;)
|
|---|
| 64 | PART_FixUpPartitionNumber Proc Near Uses ax cx
|
|---|
| 65 | cmp dl, 0FFh
|
|---|
| 66 | je PFUPN_PartitionDisabled
|
|---|
| 67 | call PARTSCAN_GetXref ; DL - PartitionNo prev IPT
|
|---|
| 68 | cmp dh, 0FFh ; DH -> Partition No in new IPT
|
|---|
| 69 | je PFUPN_PartitionGone
|
|---|
| 70 | PFUPN_PartitionDisabled:
|
|---|
| 71 | ret
|
|---|
| 72 |
|
|---|
| 73 | ; Partition is not referenced in New-IPT, so dig for requested partition
|
|---|
| 74 | PFUPN_PartitionGone:
|
|---|
| 75 | mov cl, CFG_Partitions
|
|---|
| 76 | or cl, cl
|
|---|
| 77 | jz PFUPN_NothingFound ; No partitions available -> so fail
|
|---|
| 78 | or bl, bl
|
|---|
| 79 | jz PFUPN_BootableSearchLoop
|
|---|
| 80 | ; Search for Partition ID "BL"
|
|---|
| 81 | PFUPN_PartIDsearchLoop:
|
|---|
| 82 | call PART_GetPartitionPointer ; Gets SI for partition DL
|
|---|
| 83 | cmp bptr ds:[si+LocIPT_SystemID], bl
|
|---|
| 84 | je PFUPN_Found
|
|---|
| 85 | dec cl
|
|---|
| 86 | jz PFUPN_NothingFound
|
|---|
| 87 | inc dl ; Increase
|
|---|
| 88 | cmp CFG_Partitions, dl
|
|---|
| 89 | ja PFUPN_PartIDsearchLoop
|
|---|
| 90 | xor dl, dl
|
|---|
| 91 | jmp PFUPN_PartIDsearchLoop
|
|---|
| 92 |
|
|---|
| 93 | ; Search for Partition ID "BL"
|
|---|
| 94 | PFUPN_BootableSearchLoop:
|
|---|
| 95 | call PART_GetPartitionPointer ; Gets SI for partition DL
|
|---|
| 96 | mov al, cs:[si+LocIPT_Flags]
|
|---|
| 97 | and al, Flags_BootAble
|
|---|
| 98 | jnz PFUPN_Found
|
|---|
| 99 | dec cl
|
|---|
| 100 | jz PFUPN_NothingFound
|
|---|
| 101 | inc dl ; Increase
|
|---|
| 102 | cmp CFG_Partitions, dl
|
|---|
| 103 | ja PFUPN_PartIDsearchLoop
|
|---|
| 104 | xor dl, dl
|
|---|
| 105 | jmp PFUPN_PartIDsearchLoop
|
|---|
| 106 |
|
|---|
| 107 | PFUPN_NothingFound:
|
|---|
| 108 | mov dl, 0FFh ; Now being Disabled
|
|---|
| 109 | PFUPN_Found:
|
|---|
| 110 | ret
|
|---|
| 111 | PART_FixUpPartitionNumber EndP
|
|---|
| 112 |
|
|---|
| 113 | ; ============================================================================
|
|---|
| 114 | ; In: CS:SI - IPT-Entry of partition
|
|---|
| 115 | ; ExecBaseSeg:Ptr - Actual Boot-Record of partition
|
|---|
| 116 | ; Out: *none* (BootRecordCRD updated)
|
|---|
| 117 | PART_UpdateBootRecordCRC Proc Near Uses bx
|
|---|
| 118 | push ds si
|
|---|
| 119 | push ExecBaseSeg
|
|---|
| 120 | pop ds
|
|---|
| 121 | mov si, offset ExecBasePtr
|
|---|
| 122 | mov bx, 4B4Dh ; Magic: 'MK'
|
|---|
| 123 | call MBR_GetCheckOfSector
|
|---|
| 124 | pop si ds
|
|---|
| 125 | mov cs:[si+LocIPT_BootRecordCRC], bx
|
|---|
| 126 | ret
|
|---|
| 127 | PART_UpdateBootRecordCRC EndP
|
|---|
| 128 |
|
|---|
| 129 | ; ============================================================================
|
|---|
| 130 | ; Partition-Pointer Functions
|
|---|
| 131 | ; ============================================================================
|
|---|
| 132 |
|
|---|
| 133 | ; Builds Pointer-Table straight (without filtering, w/o Floppy/CD-ROM/Kernels)
|
|---|
| 134 | PART_CalculateStraightPartPointers Proc Near
|
|---|
| 135 | mov ax, offset PartitionTable
|
|---|
| 136 | mov bx, offset PartitionPointers
|
|---|
| 137 | mov cx, LocIPT_MaxPartitions
|
|---|
| 138 | PCSPP_Loop:
|
|---|
| 139 | mov ds:[bx], ax
|
|---|
| 140 | add bx, 2
|
|---|
| 141 | add ax, LocIPT_LenOfIPT
|
|---|
| 142 | dec cx
|
|---|
| 143 | jnz PCSPP_Loop
|
|---|
| 144 | mov al, ds:[CFG_Partitions]
|
|---|
| 145 | mov ds:[PartitionPointerCount], al
|
|---|
| 146 | ret
|
|---|
| 147 | PART_CalculateStraightPartPointers EndP
|
|---|
| 148 |
|
|---|
| 149 | ; This here does PartitionPointers in order for displaying in BootMenu
|
|---|
| 150 | ; [this means filtering and including Floppy/CD-ROM/Kernels, if wanted]
|
|---|
| 151 | PART_CalculateMenuPartPointers Proc Near Uses si
|
|---|
| 152 | mov si, offset PartitionTable
|
|---|
| 153 | mov bx, offset PartitionPointers
|
|---|
| 154 | test CFG_IncludeFloppy, 1
|
|---|
| 155 | jz PCMPP_NoFloppyInclude
|
|---|
| 156 | mov ax, offset FloppyIPTentry
|
|---|
| 157 | mov ds:[bx], ax
|
|---|
| 158 | add bx, 2
|
|---|
| 159 | PCMPP_NoFloppyInclude:
|
|---|
| 160 |
|
|---|
| 161 | test CFG_ResumeBIOSbootSeq, 0FFh
|
|---|
| 162 | jz PCMPP_NoResumeBootSeqInclude
|
|---|
| 163 | mov ax, offset BIOScontIPTentry
|
|---|
| 164 | mov ds:[bx], ax
|
|---|
| 165 | add bx, 2
|
|---|
| 166 | PCMPP_NoResumeBootSeqInclude:
|
|---|
| 167 |
|
|---|
| 168 | ; Now include all Linux Kernels, if any available...
|
|---|
| 169 | movzx cx, LINUX_KernelNo
|
|---|
| 170 | or cx, cx
|
|---|
| 171 | jz PCMPP_NoLinuxKernels
|
|---|
| 172 | mov ax, offset LINUX_KernelEntries
|
|---|
| 173 | PCMPP_KernelLoop:
|
|---|
| 174 | mov ds:[bx], ax
|
|---|
| 175 | add bx, 2
|
|---|
| 176 | add ax, LocIPT_LenOfIPT
|
|---|
| 177 | dec cx
|
|---|
| 178 | jnz PCMPP_KernelLoop
|
|---|
| 179 | PCMPP_NoLinuxKernels:
|
|---|
| 180 |
|
|---|
| 181 | movzx cx, CFG_Partitions ; LocIPT_MaxPartitions
|
|---|
| 182 | or cx, cx
|
|---|
| 183 | jz PCMPP_NoPartitions
|
|---|
| 184 | PCMPP_Loop:
|
|---|
| 185 | mov al, ds:[si+LocIPT_Flags]
|
|---|
| 186 | and al, Flags_Bootable
|
|---|
| 187 | jz PCMPP_IsNotBootable
|
|---|
| 188 | mov ds:[bx], si
|
|---|
| 189 | add bx, 2
|
|---|
| 190 | PCMPP_IsNotBootable:
|
|---|
| 191 | add si, LocIPT_LenOfIPT
|
|---|
| 192 | dec cx
|
|---|
| 193 | jnz PCMPP_Loop
|
|---|
| 194 | PCMPP_NoPartitions:
|
|---|
| 195 | sub bx, offset PartitionPointers
|
|---|
| 196 | shr bx, 1
|
|---|
| 197 | mov ds:[PartitionPointerCount], bl
|
|---|
| 198 | ret
|
|---|
| 199 | PART_CalculateMenuPartPointers EndP
|
|---|
| 200 |
|
|---|
| 201 | ; Gets a pointer to the given partition
|
|---|
| 202 | ; In: DL - Number of partition
|
|---|
| 203 | ; Out: SI - Pointer to it (use CS)
|
|---|
| 204 | PART_GetPartitionPointer Proc Near Uses bx
|
|---|
| 205 | cmp dl, 0FEh
|
|---|
| 206 | je PGPP_IsBIOSbootSeq ; FEh -> Resume BIOS boot Sequence
|
|---|
| 207 | ja PGPP_IsFloppy ; FFh -> Floppy
|
|---|
| 208 | movzx bx, dl
|
|---|
| 209 | shl bx, 1
|
|---|
| 210 | mov si, wptr cs:[PartitionPointers+bx]
|
|---|
| 211 | ret
|
|---|
| 212 | PGPP_IsBIOSbootSeq:
|
|---|
| 213 | mov si, offset BIOScontIPTentry
|
|---|
| 214 | ret
|
|---|
| 215 | PGPP_IsFloppy:
|
|---|
| 216 | mov si, offset FloppyIPTentry ; PartitionTable-LocIPT_LenOfIPT
|
|---|
| 217 | ret
|
|---|
| 218 | PART_GetPartitionPointer EndP
|
|---|
| 219 |
|
|---|
| 220 | ; Gets the number of a partition pointer
|
|---|
| 221 | ; In: SI - Pointer to Partition
|
|---|
| 222 | ; Out: DL - Number of partition
|
|---|
| 223 | PART_GetPartitionNumber Proc Near Uses bx
|
|---|
| 224 | mov dl, ds:[PartitionPointerCount]
|
|---|
| 225 | mov bx, offset PartitionPointers
|
|---|
| 226 | PGPN_SearchLoop:
|
|---|
| 227 | cmp wptr ds:[bx], si
|
|---|
| 228 | je PGPN_Found
|
|---|
| 229 | add bx, 2
|
|---|
| 230 | dec dl
|
|---|
| 231 | jnz PGPN_SearchLoop
|
|---|
| 232 | mov dl, 0FFh
|
|---|
| 233 | ret
|
|---|
| 234 | PGPN_Found:
|
|---|
| 235 | sub dl, ds:[PartitionPointerCount]
|
|---|
| 236 | dec dl
|
|---|
| 237 | not dl
|
|---|
| 238 | ret
|
|---|
| 239 | PART_GetPartitionNumber EndP
|
|---|
| 240 |
|
|---|
| 241 | ; Following functions are only usable, when Partition-Pointer-View is filtered
|
|---|
| 242 | ; They will convert from and to unfiltered view (used in Boot-Menu)
|
|---|
| 243 | ; In: DL - Number of partition in filtered view
|
|---|
| 244 | ; Out: DL - Number of partition in straight view
|
|---|
| 245 | PART_ConvertToStraight Proc Near Uses
|
|---|
| 246 | movzx bx, dl
|
|---|
| 247 | shl bx, 1
|
|---|
| 248 | mov ax, wptr cs:[PartitionPointers+bx]
|
|---|
| 249 | cmp ax, offset FloppyIPTentry
|
|---|
| 250 | jb PCTS_IsBIOSbootSeq
|
|---|
| 251 | je PCTS_IsFloppy
|
|---|
| 252 | cmp ax, offset LINUX_KernelEntries
|
|---|
| 253 | jae PCTS_IsKernelEntry
|
|---|
| 254 | sub ax, offset PartitionTable
|
|---|
| 255 | mov bl, LocIPT_LenOfIPT
|
|---|
| 256 | div bl ; Divide with IPTlength
|
|---|
| 257 | mov dl, al
|
|---|
| 258 | ret
|
|---|
| 259 | PCTS_IsKernelEntry:
|
|---|
| 260 | mov dl, 0FDh
|
|---|
| 261 | ret
|
|---|
| 262 | PCTS_IsBIOSbootSeq:
|
|---|
| 263 | mov dl, 0FEh
|
|---|
| 264 | ret
|
|---|
| 265 | PCTS_IsFloppy:
|
|---|
| 266 | mov dl, 0FFh
|
|---|
| 267 | ret
|
|---|
| 268 | PART_ConvertToStraight EndP
|
|---|
| 269 |
|
|---|
| 270 | ; In: DL - Number of partition in straight view
|
|---|
| 271 | ; Out: DL - Number of partition in filtered view
|
|---|
| 272 | PART_ConvertFromStraight Proc Near Uses es di
|
|---|
| 273 | ; First we get Partition-Offset in AX
|
|---|
| 274 | movzx ax, dl
|
|---|
| 275 | mov bl, LocIPT_LenOfIPT
|
|---|
| 276 | mul bl
|
|---|
| 277 | add ax, offset PartitionTable
|
|---|
| 278 | ; Now search for this offset in our filtered Partition-Pointer-Table
|
|---|
| 279 | push cs
|
|---|
| 280 | pop es
|
|---|
| 281 | mov di, offset PartitionPointers
|
|---|
| 282 | mov cx, LocIPT_MaxPartitions
|
|---|
| 283 | xor dl, dl ; Reply on Not-Found = Partition==0
|
|---|
| 284 | repne scasw ; Compare-Loop
|
|---|
| 285 | jne PCFS_NotFound
|
|---|
| 286 | sub di, 2 ; One Back, so point to compared value
|
|---|
| 287 | mov dx, di
|
|---|
| 288 | sub dx, offset PartitionPointers
|
|---|
| 289 | shr dx, 1
|
|---|
| 290 | ; Adjust for IncludeFloppy/etc. is automatically done, due Pointer-LookUp
|
|---|
| 291 | PCFS_NotFound:
|
|---|
| 292 | ret
|
|---|
| 293 | PART_ConvertFromStraight EndP
|
|---|
| 294 |
|
|---|
| 295 | ; In: AX - Pointer to IPT Entry
|
|---|
| 296 | ; Out: SI - Pointer to corresponding Size-Element
|
|---|
| 297 | ; Destroyed: AX
|
|---|
| 298 | PART_GetSizeElementPointer Proc Near Uses bx
|
|---|
| 299 | cmp ax, offset LINUX_KernelEntries
|
|---|
| 300 | jae PGSEP_IsKernelEntry
|
|---|
| 301 | mov si, offset PartitionSizeTable
|
|---|
| 302 | sub ax, offset PartitionTable
|
|---|
| 303 | jmp PGSEP_Continue
|
|---|
| 304 | PGSEP_IsKernelEntry:
|
|---|
| 305 | mov si, offset LINUX_KernelSizeTable
|
|---|
| 306 | sub ax, offset LINUX_KernelEntries
|
|---|
| 307 | PGSEP_Continue:
|
|---|
| 308 | mov bl, LocIPT_LenOfIPT
|
|---|
| 309 | div bl ; Divide with IPTlength
|
|---|
| 310 | movzx bx, al
|
|---|
| 311 | shl ax, 1
|
|---|
| 312 | shl bx, 2
|
|---|
| 313 | add ax, bx ; My way of multiplying with 6
|
|---|
| 314 | add si, ax ; SI - Partition Size-Element
|
|---|
| 315 | ret
|
|---|
| 316 | PART_GetSizeElementPointer EndP
|
|---|
| 317 |
|
|---|
| 318 | ; In: BX:AX - Sector Size (1=512 Bytes, 2=1024 Bytes, etc.)
|
|---|
| 319 | ; ES:DI - Pointer to Size-Element (6 bytes)
|
|---|
| 320 | ; Out: None, Size-Element filled out
|
|---|
| 321 | ; Destroyed: AX, BX, DI
|
|---|
| 322 | PART_FillOutSizeElement Proc Near Uses cx dx
|
|---|
| 323 | add di, 3 ; ES:DI - Last Digit of Size Digits
|
|---|
| 324 | shr bx, 1
|
|---|
| 325 | rcr ax, 1 ; /2 -> Sector Size is now KByte Size
|
|---|
| 326 | xor cl, cl ; 0 - KByte, 1 - MByte, 2 - GByte
|
|---|
| 327 | PFOSE_MakeSmallerLoop:
|
|---|
| 328 | or bx, bx
|
|---|
| 329 | jnz PFOSE_MakeSmaller
|
|---|
| 330 | cmp ax, 9999
|
|---|
| 331 | jbe PFOSE_IsSmallEnough
|
|---|
| 332 | PFOSE_MakeSmaller:
|
|---|
| 333 | mov dx, bx
|
|---|
| 334 | and dx, 1023 ; My crazy way of dividing a 32-bit
|
|---|
| 335 | shr ax, 10 ; value through 1024 using 16-bit
|
|---|
| 336 | shr bx, 10 ; instructions...
|
|---|
| 337 | shl dx, 6
|
|---|
| 338 | or ax, dx
|
|---|
| 339 | inc cl ; Value got smaller...
|
|---|
| 340 | jmp PFOSE_MakeSmallerLoop
|
|---|
| 341 |
|
|---|
| 342 | PFOSE_IsSmallEnough:
|
|---|
| 343 | ; First write the type of this Size-Element (KB/MB/GB)
|
|---|
| 344 | mov bx, 'BK'
|
|---|
| 345 | cmp cl, 1
|
|---|
| 346 | jb PFOSE_WriteType
|
|---|
| 347 | je PFOSE_IsMBtype
|
|---|
| 348 | mov bx, 'BG'
|
|---|
| 349 | jmp PFOSE_WriteType
|
|---|
| 350 | PFOSE_IsMBtype:
|
|---|
| 351 | mov bx, 'BM'
|
|---|
| 352 | PFOSE_WriteType:
|
|---|
| 353 | mov wptr es:[di+1], bx
|
|---|
| 354 | mov bx, 10 ; Digits are 10-Based
|
|---|
| 355 | xor dx, dx
|
|---|
| 356 | PFOSE_DigitLoop:
|
|---|
| 357 | xor dx, dx
|
|---|
| 358 | div bx ; AX - Digit, DX - Remainder
|
|---|
| 359 | add dl, '0' ; Convert digit to ASCII digit
|
|---|
| 360 | mov es:[di], dl
|
|---|
| 361 | or ax, ax
|
|---|
| 362 | jz PFOSE_EndOfDigitLoop
|
|---|
| 363 | dec di ; Go to previous char
|
|---|
| 364 | jmp PFOSE_DigitLoop
|
|---|
| 365 |
|
|---|
| 366 | PFOSE_EndOfDigitLoop:
|
|---|
| 367 | ret
|
|---|
| 368 | PART_FillOutSizeElement EndP
|
|---|
| 369 |
|
|---|
| 370 | ; Starts Partition DL from Internal Partition Table.
|
|---|
| 371 | ; In: DL - Number of partition (filtered view)
|
|---|
| 372 | ; Out: No Return...
|
|---|
| 373 | ; Destroyed: None, due no return ;-)
|
|---|
| 374 | ; Logic: - Harddrive: loads partition Table
|
|---|
| 375 | ; sets partition active
|
|---|
| 376 | ; saves partition table
|
|---|
| 377 | ; hides partitions, if needed
|
|---|
| 378 | ; Linux-Support, if needed
|
|---|
| 379 | ; load boot sector
|
|---|
| 380 | ; VIBR checking, if wanted
|
|---|
| 381 | ; install MBR Protection, if wanted
|
|---|
| 382 | ; Special Boot Support, if needed (OS/2 Extended partitions)
|
|---|
| 383 | ; run boot sector...
|
|---|
| 384 | PART_StartPartition Proc Near Uses ax dx es di
|
|---|
| 385 | local BootPartNo:byte
|
|---|
| 386 | ; Get Partition-Pointer (SI) to Partition-To-Boot (DL)
|
|---|
| 387 | call PART_GetPartitionPointer
|
|---|
| 388 |
|
|---|
| 389 | call PART_ConvertToStraight ; ...we save straight view for later...
|
|---|
| 390 | mov BootPartNo, dl
|
|---|
| 391 |
|
|---|
| 392 | ; We need straight pointers from now on, so calculate the table...
|
|---|
| 393 | call PART_CalculateStraightPartPointers
|
|---|
| 394 |
|
|---|
| 395 | ; SI contains the pointer to the IPT to what partition to boot
|
|---|
| 396 | ; in this whole routine...it may never get messed up.
|
|---|
| 397 |
|
|---|
| 398 | push si
|
|---|
| 399 | mov dl, cs:[si+LocIPT_Drive]
|
|---|
| 400 | mov dh, cs:[si+LocIPT_SystemID]
|
|---|
| 401 | ; Copy Partition-Name to BootingNow area for display purposes
|
|---|
| 402 | add si, LocIPT_Name
|
|---|
| 403 | mov cx, 11
|
|---|
| 404 | call GetLenOfName
|
|---|
| 405 | mov di, offset TXT_BootingNowPartName
|
|---|
| 406 | jz PSP_NoName
|
|---|
| 407 | rep movsb
|
|---|
| 408 | PSP_NoName:
|
|---|
| 409 | xor al, al
|
|---|
| 410 | stosb ; Ending Zero
|
|---|
| 411 | mov si, offset TXT_BootingNow1
|
|---|
| 412 | call MBR_Teletype
|
|---|
| 413 | cmp dh, 0FDh
|
|---|
| 414 | je PSP_IsKernel
|
|---|
| 415 | or dl, dl
|
|---|
| 416 | jnz PSP_IsHarddisc
|
|---|
| 417 | ; When booting floppy/CD-ROM/etc., we got other text to be displayed...
|
|---|
| 418 | mov si, offset TXT_BootingNowPartName
|
|---|
| 419 | call MBR_Teletype
|
|---|
| 420 | jmp PSP_IsFloppyCDROMetc
|
|---|
| 421 |
|
|---|
| 422 | PSP_IsKernel:
|
|---|
| 423 | IFDEF ReleaseCode
|
|---|
| 424 | ; Save configuration on HDD boots (save CFG_LinuxLastKernel)
|
|---|
| 425 | call DriveIO_SaveConfiguration
|
|---|
| 426 | ENDIF
|
|---|
| 427 | call MBR_Teletype ; Prints out BootingNow2 including KernelName
|
|---|
| 428 | mov si, offset TXT_BootingNowKernel
|
|---|
| 429 | call MBR_Teletype
|
|---|
| 430 | jmp PSP_IsFloppyCDROMetc
|
|---|
| 431 |
|
|---|
| 432 | PSP_IsHarddisc:
|
|---|
| 433 | IFDEF ReleaseCode
|
|---|
| 434 | ; Save configuration on HDD boots (save CFG_PartLast)
|
|---|
| 435 | call DriveIO_SaveConfiguration
|
|---|
| 436 | ENDIF
|
|---|
| 437 | call MBR_Teletype ; Prints out BootingNow2 including PartitionName
|
|---|
| 438 | mov si, offset TXT_BootingNowPartition
|
|---|
| 439 | call MBR_Teletype
|
|---|
| 440 | pop si ; restores SI (IPT-pointer)
|
|---|
| 441 |
|
|---|
| 442 | mov ax, wptr cs:[si+LocIPT_AbsolutePartTable+0]
|
|---|
| 443 | mov bx, wptr cs:[si+LocIPT_AbsolutePartTable+2]
|
|---|
| 444 | mov cx, wptr cs:[si+LocIPT_LocationPartTable+1]
|
|---|
| 445 | mov dh, bptr cs:[si+LocIPT_LocationPartTable+0]
|
|---|
| 446 | mov dl, cs:[si+LocIPT_Drive]
|
|---|
| 447 | call DriveIO_LoadPartition ; Load Table...
|
|---|
| 448 | ; --------------------------------------------------- MODIFY PARTITION TABLE
|
|---|
| 449 | push ExecBaseSeg
|
|---|
| 450 | pop es
|
|---|
| 451 | mov di, ExecBasePtr
|
|---|
| 452 | add di, 446 ; DS:SI - Erster Partitionseintrag
|
|---|
| 453 |
|
|---|
| 454 | ; Remove all active-flags for safety reasons, primary partition table will
|
|---|
| 455 | ; have one partition set active by ScanPartition-routine.
|
|---|
| 456 | push di
|
|---|
| 457 | mov cl, 4
|
|---|
| 458 | PSP_RemoveActiveFlagLoop:
|
|---|
| 459 | and bptr es:[di+LocBRPT_Flags], 7Fh
|
|---|
| 460 | add di, LocBRPT_LenOfEntry
|
|---|
| 461 | dec cl
|
|---|
| 462 | jnz PSP_RemoveActiveFlagLoop
|
|---|
| 463 | pop di
|
|---|
| 464 |
|
|---|
| 465 | ; Put the partition-to-be-booted location into registers...
|
|---|
| 466 | mov ax, wptr cs:[si+LocIPT_AbsoluteBegin+0]
|
|---|
| 467 | mov bx, wptr cs:[si+LocIPT_AbsoluteBegin+2]
|
|---|
| 468 | sub ax, wptr cs:[si+LocIPT_AbsolutePartTable+0]
|
|---|
| 469 | sbb bx, wptr cs:[si+LocIPT_AbsolutePartTable+2]
|
|---|
| 470 | ; BX:AX - absolute position of partition relative to partition table
|
|---|
| 471 | ; ...and search for it...
|
|---|
| 472 | PSP_SearchLoop:
|
|---|
| 473 | cmp ax, wptr es:[di+LocBRPT_RelativeBegin]
|
|---|
| 474 | jne PSP_SearchMismatch
|
|---|
| 475 | cmp bx, wptr es:[di+LocBRPT_RelativeBegin+2]
|
|---|
| 476 | jne PSP_SearchMismatch
|
|---|
| 477 | jmp PSP_SearchMatch
|
|---|
| 478 | PSP_SearchMismatch:
|
|---|
| 479 | add di, LocBRPT_LenOfEntry ; 16 Bytes per Partition-Entry
|
|---|
| 480 | cmp di, 500+ExecBasePtr
|
|---|
| 481 | jb PSP_SearchLoop
|
|---|
| 482 | jmp MBR_HaltSystem
|
|---|
| 483 |
|
|---|
| 484 | ; -------------------------------------------------------------- ENTRY FOUND
|
|---|
| 485 | PSP_SearchMatch:
|
|---|
| 486 | or byte ptr es:[di+LocBRPT_Flags], 80h ; set ACTIVE partition
|
|---|
| 487 | IFDEF ReleaseCode
|
|---|
| 488 | call DriveIO_SavePartition ; Saves the Partition-Table
|
|---|
| 489 | ENDIF
|
|---|
| 490 |
|
|---|
| 491 | ; ---------------------------------------------------------- OS/2 / eCS I13X
|
|---|
| 492 | ; Now check if the partition to get booted is above 8 GB.
|
|---|
| 493 | ; If yes, set magic bytes 'I13X' at 3000:0 for boot-loader to recognize.
|
|---|
| 494 | ; This method is (c) by IBM <g>
|
|---|
| 495 | mov ax, wptr cs:[si+LocIPT_AbsoluteBegin+0]
|
|---|
| 496 | mov bx, wptr cs:[si+LocIPT_AbsoluteBegin+2]
|
|---|
| 497 | add ax, wptr es:[di+LocBRPT_AbsoluteLength+0] ; Add length to absolute
|
|---|
| 498 | adc bx, wptr es:[di+LocBRPT_AbsoluteLength+2] ; begin location
|
|---|
| 499 | ; BX:AX -> Absolute End-Position of Partition
|
|---|
| 500 |
|
|---|
| 501 | ; LBA-boundary at 16450560 (FB0400h)
|
|---|
| 502 | cmp bx, 00FBh
|
|---|
| 503 | jb PSP_NoI13X
|
|---|
| 504 | push es di
|
|---|
| 505 | mov ax, 3000h
|
|---|
| 506 | mov es, ax
|
|---|
| 507 | xor di, di
|
|---|
| 508 | mov wptr es:[di], '1I'
|
|---|
| 509 | mov wptr es:[di+2], 'X3'
|
|---|
| 510 | pop di es
|
|---|
| 511 | PSP_NoI13X:
|
|---|
| 512 |
|
|---|
| 513 | ; now check, if we need to hide any partition
|
|---|
| 514 | test byte ptr cs:[si+LocIPT_Flags], Flags_HideFeature
|
|---|
| 515 | jz PSP_NoHideFeature
|
|---|
| 516 | ; --------------------------------------------------------- PARTITION HIDING
|
|---|
| 517 | push si
|
|---|
| 518 | mov si, offset TXT_BootingHide
|
|---|
| 519 | call MBR_Teletype ; display "hide active"
|
|---|
| 520 | pop si
|
|---|
| 521 | ; First, find Hide-Config
|
|---|
| 522 | mov dl, BootPartNo ; EntryNumber is straight view
|
|---|
| 523 | mov ax, LocIPT_MaxPartitions
|
|---|
| 524 | mul dl
|
|---|
| 525 | mov di, offset HidePartitionTable
|
|---|
| 526 | add di, ax ; We got the pointer
|
|---|
| 527 | ; So process Hide-Config. Read out Byte-Entries, each points to a partition
|
|---|
| 528 | ; 0FFh is end-marker / maximum entries = CFG_Partitions
|
|---|
| 529 | mov cl, CFG_Partitions
|
|---|
| 530 | PSP_PartitionsHideLoop:
|
|---|
| 531 | mov dl, cs:[di]
|
|---|
| 532 | inc di
|
|---|
| 533 | cmp dl, 0FFh
|
|---|
| 534 | je PSP_EndOfHideProcess ; -> End of Hiding
|
|---|
| 535 | call PART_HidePartition ; Now hide that partition
|
|---|
| 536 | dec cl
|
|---|
| 537 | jnz PSP_PartitionsHideLoop
|
|---|
| 538 | PSP_EndOfHideProcess:
|
|---|
| 539 | ; --- HIDE COMPLETED ---
|
|---|
| 540 | ; So something got hidden and we have to remark a primary partition,
|
|---|
| 541 | ; if we are booting something non-primary from 1st hdd.
|
|---|
| 542 | cmp bptr ds:[si+LocIPT_Drive], 80h
|
|---|
| 543 | ja PSP_HideAdjustPrimaryMark ; When booting any hdd, but 1st
|
|---|
| 544 | mov ax, wptr ds:[si+LocIPT_AbsolutePartTable]
|
|---|
| 545 | mov bx, wptr ds:[si+LocIPT_AbsolutePartTable+2]
|
|---|
| 546 | or ax, ax
|
|---|
| 547 | jnz PSP_HideAdjustPrimaryMark ; or booting non-primary partition
|
|---|
| 548 | or bx, bx ; on 1st harddrive.
|
|---|
| 549 | jz PSP_NoHideAdjustPrimaryMark
|
|---|
| 550 | PSP_HideAdjustPrimaryMark:
|
|---|
| 551 | ; Load Primary Partition Table...
|
|---|
| 552 | xor ax, ax
|
|---|
| 553 | xor bx, bx
|
|---|
| 554 | mov cx, 0001h ; Cylinder 0, Sector 1
|
|---|
| 555 | mov dx, 0080h ; First HD, Head 0
|
|---|
| 556 | call DriveIO_LoadPartition ; Load Primary Partition Table
|
|---|
| 557 | call PART_MarkFirstGoodPrimary
|
|---|
| 558 | IFDEF ReleaseCode
|
|---|
| 559 | call DriveIO_SavePartition ; Saves the Partition-Table
|
|---|
| 560 | ENDIF
|
|---|
| 561 | PSP_NoHideAdjustPrimaryMark:
|
|---|
| 562 |
|
|---|
| 563 | PSP_NoHideFeature:
|
|---|
| 564 | push si
|
|---|
| 565 | ; ------------------------------------------------------- -"PLEASE WAIT..."-
|
|---|
| 566 | PSP_IsFloppyCDROMetc:
|
|---|
| 567 | mov si, offset TXT_BootingWait
|
|---|
| 568 | call MBR_Teletype ; display "please wait"
|
|---|
| 569 | pop si
|
|---|
| 570 |
|
|---|
| 571 | ; Process Partition Tables, if M$-Hack required (changes Ext Part Type)
|
|---|
| 572 | call MSHACK_ProcessPartTables
|
|---|
| 573 |
|
|---|
| 574 | test CFG_BootMenuActive, 0FFh
|
|---|
| 575 | jz PSP_NoMenuNoSound
|
|---|
| 576 |
|
|---|
| 577 | ; --------------------------------------------------------------- BOOT-SOUND
|
|---|
| 578 | call SOUND_ExecuteBoot
|
|---|
| 579 | PSP_NoMenuNoSound:
|
|---|
| 580 |
|
|---|
| 581 | ; -------------------------------------------------- SPECIAL BOOT PROCESSING
|
|---|
| 582 | ; Check here, if the Boot shall be done via resume to BIOS...
|
|---|
| 583 | mov al, bptr cs:[si+LocIPT_SystemID]
|
|---|
| 584 | cmp al, 0FEh ; Via BIOS ? (aka resume BIOS boot sequence)
|
|---|
| 585 | je PSP_ResumeBIOSbootSeq
|
|---|
| 586 | cmp al, 0FDh ; Kernel-Booting ?
|
|---|
| 587 | je PSP_KernelBooting
|
|---|
| 588 | jmp PSP_StartNormal
|
|---|
| 589 |
|
|---|
| 590 | PSP_ResumeBIOSbootSeq:
|
|---|
| 591 | int 18h ; Give control back to BIOS
|
|---|
| 592 | db 0EAh ; if return to here -> Reboot
|
|---|
| 593 | dw 0FFF0h
|
|---|
| 594 | dw 0F000h
|
|---|
| 595 |
|
|---|
| 596 | PSP_KernelBooting:
|
|---|
| 597 | call LINUX_LoadKernel ; DS:SI - Entry Pointer to Kernel
|
|---|
| 598 | db 0EAh ; if return to here -> Reboot
|
|---|
| 599 | dw 0FFF0h
|
|---|
| 600 | dw 0F000h
|
|---|
| 601 |
|
|---|
| 602 | ; ==================================================================
|
|---|
| 603 | ; FROM THIS POINT ON, ONLY *SI* REGISTER IS NEEDED TO BE PRESERVED
|
|---|
| 604 | ; ==================================================================
|
|---|
| 605 |
|
|---|
| 606 | PSP_StartNormal:
|
|---|
| 607 | mov ax, wptr cs:[si+LocIPT_AbsoluteBegin+0]
|
|---|
| 608 | mov bx, wptr cs:[si+LocIPT_AbsoluteBegin+2]
|
|---|
| 609 | mov cx, cs:[si+LocIPT_LocationBegin+1]
|
|---|
| 610 | mov dh, cs:[si+LocIPT_LocationBegin+0]
|
|---|
| 611 | mov dl, cs:[si+LocIPT_Drive]
|
|---|
| 612 | call DriveIO_LoadPartition ; Loads boot-sector...
|
|---|
| 613 |
|
|---|
| 614 | test CFG_DetectVIBR, 1
|
|---|
| 615 | jz PSP_NoVIBR
|
|---|
| 616 | test byte ptr cs:[si+LocIPT_Flags], Flags_VIBR_Detection
|
|---|
| 617 | jz PSP_NoVIBR
|
|---|
| 618 | ; ---------------------------------------------------------- CHECKS FOR VIBR
|
|---|
| 619 | push ds si
|
|---|
| 620 | push ExecBaseSeg
|
|---|
| 621 | pop ds
|
|---|
| 622 | mov si, offset ExecBasePtr
|
|---|
| 623 | mov bx, 4B4Dh ; Magic: 'MK'
|
|---|
| 624 | call MBR_GetCheckOfSector
|
|---|
| 625 | pop si ds
|
|---|
| 626 | cmp cs:[si+LocIPT_BootRecordCRC], bx
|
|---|
| 627 | je PSP_NoVIBR
|
|---|
| 628 | mov bx, cs:[si+LocIPT_BootRecordCRC]
|
|---|
| 629 | or bx, bx
|
|---|
| 630 | jz PSP_NoVIBR
|
|---|
| 631 | ; Oh Oh, got a virus :(
|
|---|
| 632 | mov si, offset TXT_VirusFoundMain
|
|---|
| 633 | call MBR_Teletype
|
|---|
| 634 | mov si, offset TXT_VirusFound2 ; VIBR-Virus
|
|---|
| 635 | call MBR_Teletype
|
|---|
| 636 | mov si, offset TXT_VirusFoundEnd
|
|---|
| 637 | call MBR_Teletype
|
|---|
| 638 | jmp MBR_HaltSystem
|
|---|
| 639 |
|
|---|
| 640 | PSP_NoVIBR:
|
|---|
| 641 | test CFG_ProtectMBR, 1
|
|---|
| 642 | jz PSP_NoMBRprotect
|
|---|
| 643 | ; -------------------------------------------------- INSTALLS MBR-PROTECTION
|
|---|
| 644 | push si ; We need SI later...
|
|---|
| 645 | ; First subtract 1024 bytes from Base-Memory...
|
|---|
| 646 | push ds
|
|---|
| 647 | mov ax, 40h
|
|---|
| 648 | mov ds, ax
|
|---|
| 649 | mov dx, word ptr ds:[13h]
|
|---|
| 650 | dec dx ; 1 == 1kbyte
|
|---|
| 651 | mov word ptr ds:[13h], dx
|
|---|
| 652 | pop ds
|
|---|
| 653 | shl dx, 6 ; trick, now DX is a segment
|
|---|
| 654 |
|
|---|
| 655 | ; Now copy in our code (to DX:0)...
|
|---|
| 656 |
|
|---|
| 657 | mov ax, cs
|
|---|
| 658 | mov ds, ax
|
|---|
| 659 | mov si, offset MBR_Protection ; DS:SI - Source Image
|
|---|
| 660 | mov es, dx
|
|---|
| 661 | xor di, di ; ES:DI - Destination
|
|---|
| 662 | mov cx, 512
|
|---|
| 663 | rep movsw ; Move 1024 bytes...
|
|---|
| 664 |
|
|---|
| 665 | ; Now fill in variables...
|
|---|
| 666 |
|
|---|
| 667 | xor ax, ax
|
|---|
| 668 | mov ds, ax
|
|---|
| 669 | mov si, 10h*4
|
|---|
| 670 | xor di, di ; INT 10h Vector to MBR Protection
|
|---|
| 671 | movsd
|
|---|
| 672 | mov si, 13h*4 ; INT 13h Vector to MBR Protection
|
|---|
| 673 | movsd
|
|---|
| 674 | mov al, CFG_IgnoreWriteToMBR ; Option to MBR Protection
|
|---|
| 675 | stosb
|
|---|
| 676 |
|
|---|
| 677 | ; Now switch INT 13h vector to MBR Protection
|
|---|
| 678 |
|
|---|
| 679 | sub si, 4
|
|---|
| 680 | mov ax, 9
|
|---|
| 681 | mov ds:[si], ax
|
|---|
| 682 | mov ds:[si+2], dx ; Vector hardcoded at DS:0009
|
|---|
| 683 | ; MBR-Protection now active :)
|
|---|
| 684 | pop si ; Restore SI
|
|---|
| 685 |
|
|---|
| 686 | ; ------------------------------------------------ SPECIAL PARTITION SUPPORT
|
|---|
| 687 | ; needed by OS/2 Warp / eComStation
|
|---|
| 688 | PSP_NoMBRprotect:
|
|---|
| 689 | cmp bptr cs:[si+LocIPT_SystemID], 08 ; I hate Microsuck NTFS check
|
|---|
| 690 | je PSP_NoSpecialSupport
|
|---|
| 691 |
|
|---|
| 692 | push ExecBaseSeg
|
|---|
| 693 | pop es
|
|---|
| 694 | mov di, ExecBasePtr ; ES:DI - Actual Boot-Record
|
|---|
| 695 | ; Special Support Detection
|
|---|
| 696 | mov ax, wptr es:[di+24]
|
|---|
| 697 | cmp ax, 003Fh ; Physical Layout-Sectors... Safety check
|
|---|
| 698 | ja PSP_NoSpecialSupport
|
|---|
| 699 | mov ax, wptr es:[di+26]
|
|---|
| 700 | cmp ax, 00FFh ; Physical Layout-Heads... Safety check
|
|---|
| 701 | ja PSP_NoSpecialSupport
|
|---|
| 702 | mov al, bptr es:[di+36]
|
|---|
| 703 | cmp al, 80h ; Drive Letter
|
|---|
| 704 | jne PSP_NoSpecialSupport
|
|---|
| 705 | ; Special Support needed
|
|---|
| 706 | mov al, bptr cs:[si+LocIPT_Drive]
|
|---|
| 707 | mov bptr es:[di+36], al ; Write Actual Drive-Letter
|
|---|
| 708 | mov ax, cs:[si+LocIPT_AbsoluteBegin]
|
|---|
| 709 | mov wptr es:[di+28], ax ; Fixing Hidden Sectors count
|
|---|
| 710 | mov ax, cs:[si+LocIPT_AbsoluteBegin+2]
|
|---|
| 711 | mov wptr es:[di+30], ax ; Done by OS/2 BootMan as well...
|
|---|
| 712 |
|
|---|
| 713 | ; ------------------------------------------------ LOGICAL PARTITION SUPPORT
|
|---|
| 714 | PSP_NoSpecialSupport:
|
|---|
| 715 | test byte ptr cs:[si+LocIPT_Flags], Flags_DriveLetter
|
|---|
| 716 | jz PSP_NoLogicalSupport
|
|---|
| 717 |
|
|---|
| 718 | movzx bx, BootPartNo ; EntryNumber is straight view
|
|---|
| 719 | mov al, bptr cs:[DriveLetters+bx]
|
|---|
| 720 | mov bptr es:[di+37], al ; Write Drive Letter (OS/2 only)
|
|---|
| 721 |
|
|---|
| 722 | ; ---------------------------------------------------- NOW START BOOT-RECORD
|
|---|
| 723 | PSP_NoLogicalSupport:
|
|---|
| 724 | xor ax, ax
|
|---|
| 725 | xor bx, bx
|
|---|
| 726 | xor cx, cx
|
|---|
| 727 | mov ds, ax
|
|---|
| 728 | mov es, ax ; DS == ES == 0
|
|---|
| 729 | xor dh, dh ; Drive supported by BIOS
|
|---|
| 730 | mov dl, cs:[si+LocIPT_Drive] ; Drive Physical No
|
|---|
| 731 | db 0EAh ; JUMP TO Entry Point...Bye Bye
|
|---|
| 732 | dw ExecBasePtr
|
|---|
| 733 | dw ExecBaseSeg
|
|---|
| 734 | PART_StartPartition EndP
|
|---|
| 735 |
|
|---|
| 736 | ; This routine is called to hide a partition
|
|---|
| 737 | ; In: DL - Partition to hide
|
|---|
| 738 | ; Destroyed: None
|
|---|
| 739 | PART_HidePartition Proc Near Uses ax bx cx dx si es di
|
|---|
| 740 | call PART_GetPartitionPointer ; Pointer to partition (DL) -> SI
|
|---|
| 741 |
|
|---|
| 742 | ; First load the partition table of that partition...
|
|---|
| 743 | mov ax, wptr cs:[si+LocIPT_AbsolutePartTable+0]
|
|---|
| 744 | mov bx, wptr cs:[si+LocIPT_AbsolutePartTable+2]
|
|---|
| 745 | mov cx, wptr cs:[si+LocIPT_LocationPartTable+1]
|
|---|
| 746 | mov dh, bptr cs:[si+LocIPT_LocationPartTable+0]
|
|---|
| 747 | mov dl, cs:[si+LocIPT_Drive]
|
|---|
| 748 | call DriveIO_LoadPartition
|
|---|
| 749 | ; Partition-Table now LOADED
|
|---|
| 750 | push ExecBaseSeg
|
|---|
| 751 | pop es
|
|---|
| 752 | mov di, ExecBasePtr
|
|---|
| 753 | add di, 446 ; DS:SI - 1st partitionentry...
|
|---|
| 754 |
|
|---|
| 755 | ; Put our partition's location into registers...
|
|---|
| 756 | mov ax, wptr cs:[si+LocIPT_AbsoluteBegin+0]
|
|---|
| 757 | mov bx, wptr cs:[si+LocIPT_AbsoluteBegin+2]
|
|---|
| 758 | sub ax, wptr cs:[si+LocIPT_AbsolutePartTable+0]
|
|---|
| 759 | sbb bx, wptr cs:[si+LocIPT_AbsolutePartTable+2]
|
|---|
| 760 | ; BX:AX - absolute position of partition relative to partition table
|
|---|
| 761 | ; ...and search for it...
|
|---|
| 762 | PHP_SearchLoop:
|
|---|
| 763 | cmp ax, wptr es:[di+LocBRPT_RelativeBegin]
|
|---|
| 764 | jne PHP_SearchMismatch
|
|---|
| 765 | cmp bx, wptr es:[di+LocBRPT_RelativeBegin+2]
|
|---|
| 766 | jne PHP_SearchMismatch
|
|---|
| 767 | jmp PHP_SearchMatch
|
|---|
| 768 | PHP_SearchMismatch:
|
|---|
| 769 | add di, LocBRPT_LenOfEntry ; 16 Bytes per partition entry
|
|---|
| 770 | cmp di, 500+ExecBasePtr
|
|---|
| 771 | jb PHP_SearchLoop
|
|---|
| 772 | jmp MBR_HaltSystem ; not found, something is wrong here
|
|---|
| 773 |
|
|---|
| 774 | ; Found entry...
|
|---|
| 775 | PHP_SearchMatch:
|
|---|
| 776 | mov al, bptr es:[di+LocBRPT_SystemID] ; Partition-ID into AL
|
|---|
| 777 | call PART_SearchFileSysHiddenID ; Put on =STEALTH=
|
|---|
| 778 | mov bptr es:[di+LocBRPT_SystemID], al
|
|---|
| 779 | IFDEF ReleaseCode
|
|---|
| 780 | call DriveIO_SavePartition ; Saves Partition-Table
|
|---|
| 781 | ENDIF
|
|---|
| 782 | ret
|
|---|
| 783 | PART_HidePartition EndP
|
|---|
| 784 |
|
|---|
| 785 | ; This here is for marking the first "good" non-hidden partition as being
|
|---|
| 786 | ; active. It requires the partition table at EXECBASE.
|
|---|
| 787 | ; Some BIOSes have problems with no primary marked active. Actually this is
|
|---|
| 788 | ; a buggy implementation, because the MBR-code should normally check,
|
|---|
| 789 | ; *not* the BIOS. This one *could* cause havoc to some systems, but I can't
|
|---|
| 790 | ; do anything else.
|
|---|
| 791 | ; =In this routine DS may not be equal CS=
|
|---|
| 792 | PART_MarkFirstGoodPrimary Proc Near Uses ax si es di
|
|---|
| 793 | push ExecBaseSeg
|
|---|
| 794 | pop es
|
|---|
| 795 | mov di, ExecBasePtr
|
|---|
| 796 | add di, 446 ; DS:SI - First Partition-Entry
|
|---|
| 797 | ; First action to do: Remove the active flag from every partition
|
|---|
| 798 | push di
|
|---|
| 799 | mov cl, 4
|
|---|
| 800 | PMPP_RemoveActiveFlagLoop:
|
|---|
| 801 | and bptr es:[di+LocBRPT_Flags], 7Fh
|
|---|
| 802 | add di, LocBRPT_LenOfEntry
|
|---|
| 803 | dec cl
|
|---|
| 804 | jnz PMPP_RemoveActiveFlagLoop
|
|---|
| 805 | pop di
|
|---|
| 806 | ; First Search, will hit on any PartitionID that is:
|
|---|
| 807 | ; a) not 0
|
|---|
| 808 | ; b) not hidden
|
|---|
| 809 | ; c) not extended partition (05h or 0Fh)
|
|---|
| 810 | PMPP_Search1Loop:
|
|---|
| 811 | mov al, bptr es:[di+LocBRPT_SystemID]
|
|---|
| 812 | or al, al
|
|---|
| 813 | jz PMPP_Search1NoHit
|
|---|
| 814 | cmp al, 05h
|
|---|
| 815 | je PMPP_Search1NoHit
|
|---|
| 816 | cmp al, 0Fh
|
|---|
| 817 | je PMPP_Search1NoHit
|
|---|
| 818 | mov bl, al ; BL == AL == PartitionID
|
|---|
| 819 | push si
|
|---|
| 820 | call PART_SearchFileSysName
|
|---|
| 821 | pop si ; AL == UnhiddenPartitionID
|
|---|
| 822 | cmp al, bl ; if ID is unhidden...
|
|---|
| 823 | je PMPP_SearchHit
|
|---|
| 824 | PMPP_Search1NoHit:
|
|---|
| 825 | add di, LocBRPT_LenOfEntry ; 16 Bytes per Partition-Entry
|
|---|
| 826 | cmp di, 500+ExecBasePtr
|
|---|
| 827 | jb PMPP_Search1Loop
|
|---|
| 828 |
|
|---|
| 829 | mov di, ExecBasePtr
|
|---|
| 830 | add di, 446 ; DS:SI - First Partition-Entry
|
|---|
| 831 | ; Second Search, hit on anything that is not an extended partition
|
|---|
| 832 | ; (05 or 0Fh)
|
|---|
| 833 | PMPP_Search2Loop:
|
|---|
| 834 | mov al, bptr es:[di+LocBRPT_SystemID]
|
|---|
| 835 | or al, al
|
|---|
| 836 | jz PMPP_Search2NoHit
|
|---|
| 837 | cmp al, 05h
|
|---|
| 838 | je PMPP_Search2NoHit
|
|---|
| 839 | cmp al, 0Fh
|
|---|
| 840 | jne PMPP_SearchHit
|
|---|
| 841 | PMPP_Search2NoHit:
|
|---|
| 842 | add di, LocBRPT_LenOfEntry ; 16 Bytes per Partition-Entry
|
|---|
| 843 | cmp di, 500+ExecBasePtr
|
|---|
| 844 | jb PMPP_Search2Loop
|
|---|
| 845 | jmp PMPP_SearchFailed
|
|---|
| 846 |
|
|---|
| 847 | PMPP_SearchHit:
|
|---|
| 848 | or bptr es:[di], 80h ; SET ACTIVE PARTITION
|
|---|
| 849 | PMPP_SearchFailed:
|
|---|
| 850 | ret
|
|---|
| 851 | PART_MarkFirstGoodPrimary EndP
|
|---|
| 852 |
|
|---|
| 853 | ; Searches the Name and Flags to a FileSysID (PartitionID)
|
|---|
| 854 | ; In: AL - FileSysID
|
|---|
| 855 | ; Out: AL - Unhidden File-System-ID, AH - Flags for this File-System
|
|---|
| 856 | ; SI - Pointer to Name (8char)
|
|---|
| 857 | ; Destroyed: *none*
|
|---|
| 858 | PART_SearchFileSysName Proc Near Uses ds bx dx
|
|---|
| 859 | movzx bx, al
|
|---|
| 860 | push cs
|
|---|
| 861 | pop ds
|
|---|
| 862 | mov si, offset FileSysIDs
|
|---|
| 863 | PSFSN_SearchLoop:
|
|---|
| 864 | lodsw ; AL - NormalID, AH-HiddenID
|
|---|
| 865 | mov dl, ds:[si] ; DL - File-System-Flags
|
|---|
| 866 | inc si
|
|---|
| 867 | cmp al, bl ; Check, if Unhidden-ID matches...
|
|---|
| 868 | je PSFSN_Match
|
|---|
| 869 | cmp ah, bl ; Check, if Hidden-ID matches...
|
|---|
| 870 | je PSFSN_Match
|
|---|
| 871 | mov al, bl ; So Unhidden-ID will be Original-ID
|
|---|
| 872 | cmp ah, 0 ; Unknown (last ID in table)
|
|---|
| 873 | je PSFSN_Match
|
|---|
| 874 | inc bh
|
|---|
| 875 | jmp PSFSN_SearchLoop
|
|---|
| 876 |
|
|---|
| 877 | PSFSN_Match:
|
|---|
| 878 | ; AL is already Unhidden-ID
|
|---|
| 879 | mov ah, dl
|
|---|
| 880 | ; AH is now the FileSystem-Flag
|
|---|
| 881 | movzx bx, bh
|
|---|
| 882 | shl bx, 3 ; Offsets * 8
|
|---|
| 883 | mov si, offset FileSysNames
|
|---|
| 884 | add si, bx
|
|---|
| 885 | ret
|
|---|
| 886 | PART_SearchFileSysName EndP
|
|---|
| 887 |
|
|---|
| 888 | ; Searches the Hidden ID corresponding to a FileSysID (PartitionID)
|
|---|
| 889 | ; In: AL - FileSysID
|
|---|
| 890 | ; Out: AL - Hidden File-System-ID
|
|---|
| 891 | PART_SearchFileSysHiddenID Proc Near Uses ds bx
|
|---|
| 892 | movzx bx, al
|
|---|
| 893 | push cs
|
|---|
| 894 | pop ds
|
|---|
| 895 | mov si, offset FileSysIDs
|
|---|
| 896 | PSFSHI_SearchLoop:
|
|---|
| 897 | lodsw ; AL - NormalID, AH-HiddenID
|
|---|
| 898 | inc si
|
|---|
| 899 | cmp al, bl ; Check, if Unhidden-ID matches...
|
|---|
| 900 | je PSFSHI_Match
|
|---|
| 901 | cmp ah, bl ; Check, if Hidden-ID matches...
|
|---|
| 902 | je PSFSHI_Match
|
|---|
| 903 | mov ah, bl ; So Unhidden-ID will get replied...
|
|---|
| 904 | cmp ah, 0 ; Unknown (last ID in table)
|
|---|
| 905 | je PSFSHI_Match
|
|---|
| 906 | inc bh
|
|---|
| 907 | jmp PSFSHI_SearchLoop
|
|---|
| 908 |
|
|---|
| 909 | PSFSHI_Match:
|
|---|
| 910 | mov al, ah ; AL = Hidden ID
|
|---|
| 911 | ret
|
|---|
| 912 | PART_SearchFileSysHiddenID EndP
|
|---|
| 913 |
|
|---|
| 914 | ; In: DS:SI - Partition-Name, CX - Maximum/Total Length
|
|---|
| 915 | ; Out: Carry-Flag set, if valid Partition-Name
|
|---|
| 916 | ; Destroyed: None
|
|---|
| 917 | PART_CheckForValidPartName Proc Near Uses ax cx dx si
|
|---|
| 918 | ; Our logic is as follows:
|
|---|
| 919 | ; If all chars are U -> Invalid (due reformated signature)
|
|---|
| 920 | ; If anything below 32, but 0 -> Invalid (due invalid chars)
|
|---|
| 921 | ; If anything above 165 -> Invalid (due invalid chars)
|
|---|
| 922 | ; If anything between 123-128 -> Invalid (due invalid chars)
|
|---|
| 923 | ; DX - holds count of 'U's
|
|---|
| 924 | push cx
|
|---|
| 925 | or cx, cx
|
|---|
| 926 | jz PCFVPN_InvalidName
|
|---|
| 927 | xor dx, dx
|
|---|
| 928 | PCFVPN_CheckLoop:
|
|---|
| 929 | lodsb
|
|---|
| 930 | cmp al, 0
|
|---|
| 931 | je PCFVPN_ValidChar
|
|---|
| 932 | cmp al, 32
|
|---|
| 933 | jb PCFVPN_InvalidName
|
|---|
| 934 | cmp al, 165
|
|---|
| 935 | ja PCFVPN_InvalidName
|
|---|
| 936 | cmp al, 123
|
|---|
| 937 | jb PCFVPN_ValidChar
|
|---|
| 938 | cmp al, 128
|
|---|
| 939 | jbe PCFVPN_InvalidName
|
|---|
| 940 | PCFVPN_ValidChar:
|
|---|
| 941 | cmp al, 'U'
|
|---|
| 942 | jne PCFVPN_NoMagic
|
|---|
| 943 | inc dx
|
|---|
| 944 | PCFVPN_NoMagic:
|
|---|
| 945 | dec cx
|
|---|
| 946 | jnz PCFVPN_CheckLoop
|
|---|
| 947 | pop cx
|
|---|
| 948 | cmp cx, dx
|
|---|
| 949 | clc
|
|---|
| 950 | je PCFVPN_WasMagic
|
|---|
| 951 | stc
|
|---|
| 952 | PCFVPN_WasMagic:
|
|---|
| 953 | ret
|
|---|
| 954 | PCFVPN_InvalidName:
|
|---|
| 955 | pop cx
|
|---|
| 956 | clc
|
|---|
| 957 | ret
|
|---|
| 958 | PART_CheckForValidPartName EndP
|
|---|