source: trunk/bootcode/regular/other.asm@ 119

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

Now locating Master LVM-sectors when scanning disks [v1.1.1-testing]

Note that if LVM is set to be ignored in the SETUP, checking for a
signature will not be done and thus no Master LVM sectors will be found.

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

File size: 19.2 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 / OTHER ROUTINES
20;---------------------------------------------------------------------------
21
22IFDEF MODULE_NAMES
23DB 'OTHER',0
24ENDIF
25
26; In: DS:SI - Pointer to begin of string
27; CX - Len of string
28; Out: CX - Supposed real len of string
29; Zero Flag set if nul string
30; Destroyed: None
31GetLenOfName Proc Near Uses ax si
32 add si, cx
33 dec si
34 GLON_NameLoop:
35 mov al, ds:[si]
36 dec si
37 cmp al, 32
38 ja GLON_EndLoop
39 dec cx
40 jnz GLON_NameLoop
41 GLON_EndLoop:
42 or cx, cx
43 ret ; return supposed len
44GetLenOfName EndP
45
46; In: DS:SI - Pointer to NUL-terminated string
47; Out: CX - Length of string
48; Zero Flag set if nul string
49; Destroyed: None
50GetLenOfString Proc Near Uses ax si
51 xor cx, cx
52 GLOS_StringLoop:
53 lodsb
54 or al, al
55 jz GLOS_EndOfString
56 inc cx
57 jmp GLOS_StringLoop
58
59 GLOS_EndOfString:
60 or cx, cx
61 ret
62GetLenOfString EndP
63
64; In: DS:SI - Pointer to NUL-terminated strings
65; CL - Counter, how many strings to count
66; Out: CX - Length of strings
67; Destroyed: None
68GetLenOfStrings Proc Near Uses bx dx si
69 mov dh, cl
70 xor dl, dl
71 GLOSS_StringsLoop:
72 call GetLenOfString
73 add dl, cl
74 add si, cx
75 inc si
76 dec dh
77 jnz GLOSS_StringsLoop
78 ;movzx cx, dl
79 mov cl,dl
80 mov ch,0
81 ret
82GetLenOfStrings EndP
83
84
85
86
87;
88; DO PREPARING STUFF.
89;
90PRECRAP_Main Proc Near
91
92IFDEF AUX_DEBUG
93 IF 0
94 pushf
95 pusha
96 push si
97 mov si, offset $+5
98 jmp @F
99 db 10,'PRECRAP_Main:',10,0
100 @@:
101 call AuxIO_Print
102 pop si
103 ;~ call DEBUG_DumpRegisters
104 ;~ call AuxIO_DumpParagraph
105 ;~ call AuxIO_TeletypeNL
106 popa
107 popf
108 ENDIF
109ENDIF
110
111 ; First initialize Variable-Area (everything with NUL)
112 ; We use the start instead of the variables because they could be 'orged'
113 ; to an offset. We want everything after the code to be nullified.
114 mov di, offset sobss
115 mov cx, offset EndOfVariables - offset sobss
116 xor ax, ax
117 shr cx, 1
118 inc cx
119 rep stosw
120
121
122 ;
123 ; Tasm needs .386 to handle 32-bit constants so we push the current
124 ; operating state and switch temporarily to handle
125 ; InitialFreeDriveletterMap.
126 ;
127 IFDEF TASM
128 pushstate
129 .386
130 ENDIF
131 ; Initialize the FreeDriveletterMap.
132 ; This is used by driveletter reassignment functions.
133 mov di, offset [FreeDriveletterMap]
134 mov ax, InitialFreeDriveletterMap AND 0ffffh
135 cld
136 stosw
137 mov ax, InitialFreeDriveletterMap SHR 16
138 stosw
139 ;
140 ; Restore Tasm operating state.
141 ;
142 IFDEF TASM
143 popstate
144 ENDIF
145
146
147 ; Use video page 0 for screen output
148 mov word ptr [VideoIO_Segment], VideoIO_Page0
149
150 ; Don't use blinking attribute
151 call VideoIO_NoBlinking
152
153 ; Get HardDriveCount
154 call DriveIO_GetHardDriveCount
155
156
157 ; Rousseau: added
158 call VideoIO_ClearScreen
159
160 ; Cursor to upper-left
161 mov byte ptr [TextPosX], 0
162 mov byte ptr [TextPosY], 0
163 call VideoIO_CursorSet
164
165 ;~ mov ax, VideoIO_Page1
166 ;~ call VideoIO_BackUpTo ; Copy BIOS POST to Second Page
167
168 ; Copyright
169 mov si, [offset Copyright]
170 call MBR_Teletype
171 xor si,si
172 call MBR_TeletypeNL
173
174
175 ;call SOUND_Beep
176
177 ; Show build info
178 call VideoIO_PrintBuildInfo
179
180 IFDEF AUX_DEBUG
181 ; Initialize the com-port for debugging
182 call AuxIO_Init
183 ENDIF
184
185 xor si,si
186 call MBR_TeletypeNL
187
188 ;
189 ; Write MBR back to disk to sync MBR variables.
190 ; Otherwise subsequent MBR loads will differ from the RAM stored one,
191 ; which is used by MBR protection to validate parts of the MBR.
192 ;
193 xor bx, bx
194 mov cx, 1
195 xor dh, dh
196 mov dl, [BIOS_BootDisk]
197 mov al, 1
198 mov ah, 03h
199 int 13h
200 ;!
201 ;! TODO: Check success
202 ;! Yes, we should check for errors here, coz it would mean AirBoot
203 ;! was loaded from a disk where the MBR cannot be written !
204 ;!
205
206; =============================================================================
207
208 ; Start with disk at index 0
209 xor cx,cx
210
211 PRECRAP_Main_next_disk:
212
213 ; Get next disk and convert to BIOS disk-number
214 mov dl,cl
215 or dl,80h
216
217 ;
218 ; This also setup the size of the i13xbuf.
219 ;
220 call DriveIO_GatherDiskInfo ; Also used to fill the geo, should be separate function
221
222 mov bx,offset [HugeDisk]
223 add bx,cx
224 mov [bx], al
225
226
227 ; CHECKSUM CALCULATION DOES NOT WORK YET HERE
228 ; CRC TABLE NOT INITED YET
229 ; Returns NC if no valid LVM record found
230 call DriveIO_LoadMasterLVMSector
231
232 pushf
233
234 mov bx, offset [TrueSecs]
235 add bx,cx
236 add bx,cx
237 add bx,cx
238 add bx,cx
239
240IFDEF AUX_DEBUG
241 IF 0
242 pushf
243 pusha
244 mov al, '#'
245 call AuxIO_Teletype
246 mov ax, [bx]
247 call AuxIO_TeletypeHexWord
248 mov al, '#'
249 call AuxIO_Teletype
250 call AuxIO_TeletypeNL
251 popa
252 popf
253 ENDIF
254ENDIF
255
256 popf
257
258 ; bx now contains pointer to truesecs for this drive
259
260 jnc NoValidMasterLVM
261
262 ; ?? 3f bij disk 80h maar 0 bij disk 81h
263 mov si,offset [LVMSector]
264 mov ax,[si+LocLVM_Secs]
265
266 ;~ pusha
267 ;~ mov dx,ax
268 ;~ mov al,'%'
269 ;~ call VideoIO_PrintSingleChar
270 ;~ mov ax,dx
271 ;~ call VideoIO_PrintHexWord
272 ;~ mov al,'%'
273 ;~ call VideoIO_PrintSingleChar
274 ;~ popa
275
276 mov word ptr [bx],ax
277 jmp SkipUseBiosSecs
278
279
280 NoValidMasterLVM:
281 push bx ; push truesecs pointer
282 mov bx, offset [BIOS_Secs]
283 add bx,cx
284 add bx,cx
285 add bx,cx
286 add bx,cx
287
288 mov ax,[bx] ; get biossecs
289 pop bx
290 mov word ptr [bx],ax ; store bios secs in truesecs
291
292
293 SkipUseBiosSecs:
294 inc cx
295 cmp cl,[TotalHarddiscs]
296 jb PRECRAP_Main_next_disk
297
298; =============================================================================
299
300IFDEF AUX_DEBUG
301 IF 1
302 call DEBUG_Dump1
303 ENDIF
304ENDIF
305
306 ;~ jz NoValidMasterLVM
307;~
308 ;~ ; A valid Master LVM has been found.
309 ;~ ; We use the values in here to determine the number of sectors per track,
310 ;~ ; since this could be OS/2 extended geometry.
311;~
312 ;~ jmp Continue1
313 ;~
314 ;~ mov word ptr [LOG_Secs],63
315
316; mov al,[HugeDisk] ;; fout, moet nog index bij
317; call AuxIO_TeletypeHexByte
318; call AuxIO_TeletypeNL
319
320; mov ax,word ptr [TrueSecs] ;; fout, moet nog index bij
321; call AuxIO_TeletypeHexWord
322; call AuxIO_TeletypeNL
323
324;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
325
326 ; Huge Disk indicator
327 ;~ mov si, offset [HugeBootDisk]
328 ;~ call MBR_Teletype
329 ;~ mov al,[HugeDisk]
330 ;~ mov si, offset [No]
331 ;~ test al,al
332 ;~ jz MBR_HugeDriveIndicator
333 ;~ mov si, offset [Yes]
334
335 MBR_HugeDriveIndicator:
336 ;~ call MBR_Teletype
337 ;~ xor si,si
338 ;~ call MBR_TeletypeNL
339
340
341 ;
342 ; Phase 1 Indicator
343 ;
344 mov si, offset [Phase1]
345 call MBR_Teletype
346
347 mov si, offset OS2_InstallVolume
348 mov al, [si]
349 test al,al ; See if phase 1 is active
350 jnz MBR_Main_BootThrough
351 mov si, offset NotActive
352
353 MBR_Main_BootThrough:
354 call MBR_Teletype
355 xor si,si
356 call MBR_TeletypeNL
357
358; =============================================================================
359
360 ; Calculate Cooper-Bar Tables
361 IFDEF FX_ENABLED
362 call FX_CalculateTables
363 ENDIF
364
365 ; Calculate LVM-CRC-Table
366 call LVM_InitCRCTable
367
368 ; Get HardDriveCount
369 call DriveIO_GetHardDriveCount
370
371 ; Calculate CHS/LBA Switch Table
372 call DriveIO_InitLBASwitchTable
373
374 ; Setup PartitionPointers-Table
375 call PART_CalculateStraightPartPointers
376
377 ; Setup Cyrillic Charset, if needed
378 IFDEF TXT_IncludeCyrillic
379 call CHARSET_IncludeCyrillic
380 ENDIF
381
382
383 ; This sets [CurIO_UseExtension] flag.
384 call DriveIO_CheckFor13extensions
385 mov al,[CurIO_UseExtension]
386 test al,al
387 jnz INT13X_Supported
388
389 ;
390 ; Show Message that BIOS INT13X is not supported
391 ; and Halt the System.
392 ;
393 mov cx, 0C04h
394 mov si, offset TXT_NoINT13XSupport
395 call SETUP_ShowErrorBox
396
397 ; Halt the system.
398 jmp HaltSystem
399
400
401 ;
402 ; INT13X Supported so continue.
403 ;
404 INT13X_Supported:
405
406
407 ;
408 ; Setup the size of the INT13X Disk Address Packet
409 ;
410 mov [INT13X_DAP], INT13X_DAP_Size
411
412 ;
413 ; Check valididy of the AiR-BOOT Configuration.
414 ;
415 call PRECRAP_CheckConfiguration
416
417
418 ; =======================================
419 ; Checks for MBR Virii :) I love that job
420 ; =======================================
421 test byte ptr [CFG_DetectStealth], 1
422 jz PCM_NoStealthDetection
423 call VIRUS_CheckForStealth
424 PCM_NoStealthDetection:
425 test byte ptr [CFG_DetectVirus], 1
426 jz PCM_NoVirusDetection
427 call VIRUS_CheckForVirus
428 PCM_NoVirusDetection:
429
430
431 ; ============================================
432 ; Delay for some time and get Strg/Alt State
433 ; ============================================
434 test byte ptr [CFG_CooperBars], 1
435 jnz PCM_ShortDelay
436 mov al, 27 ; About 1.5 seconds
437 test byte ptr [CFG_FloppyBootGetName], 1
438 jz PCM_LongDelay
439 PCM_ShortDelay:
440
441 mov al, 13 ; shorten delay,if floppy gets accessed
442 PCM_LongDelay:
443
444 call TIMER_WaitTicCount
445
446 ; First check, if any normal key got pressed...
447 mov ah, 1
448 int 16h
449 jz PCM_NoNormalKeyPressed
450 ; User doesn't know what to do...or he is crazy <g> so display message
451 mov si, offset TXT_HowEnterSetup
452 call MBR_Teletype
453 mov al, 54 ; about 3 seconds, delay again
454
455 call TIMER_WaitTicCount
456
457 PCM_NoNormalKeyPressed:
458 ; Now get keyboard Strg/Alt State
459 mov ah, 02h
460 int 16h
461 mov [SETUP_KeysOnEntry], al
462
463 ; Copy device-name to the ContBIOSbootSeq-IPT entry
464 ; We may not do this before PRECRAP_CheckConfiguration, because otherwise
465 ; this check will fail.
466 call PART_UpdateResumeBIOSName
467 ret
468PRECRAP_Main EndP
469
470
471
472
473AFTERCRAP_Main Proc Near
474
475IFDEF AUX_DEBUG
476 IF 0
477 pushf
478 pusha
479 push si
480 mov si, offset $+5
481 jmp @F
482 db 10,'AFTERCRAP_Main:',10,0
483 @@:
484 call AuxIO_Print
485 pop si
486 ;~ call DEBUG_DumpRegisters
487 ;~ call AuxIO_DumpParagraph
488 ;~ call AuxIO_TeletypeNL
489 popa
490 popf
491 ENDIF
492ENDIF
493
494 ; ===================================================
495 ; Now get volume label of FloppyDrive, if wanted...
496 ; ===================================================
497 test byte ptr [CFG_FloppyBootGetName], 1
498 jz ACM_NoFloppyGetName
499 call DriveIO_UpdateFloppyName
500 or ax, ax
501 jnz ACM_NoFloppyGetName
502 ; Try a second time, if it failed to detect the Floppy
503 call DriveIO_UpdateFloppyName
504 ACM_NoFloppyGetName:
505 ret
506AFTERCRAP_Main EndP
507
508
509; Checks Configuration CheckSum...Displays message, if failed.
510PRECRAP_CheckConfiguration Proc Near Uses ds si es di
511
512IFDEF AUX_DEBUG
513 IF 0
514 pushf
515 pusha
516 push si
517 mov si, offset $+5
518 jmp @F
519 db 10,'PRECRAP_CheckConfiguration:',10,0
520 @@:
521 call AuxIO_Print
522 pop si
523 ;~ call DEBUG_DumpRegisters
524 ;~ call AuxIO_DumpParagraph
525 ;~ call AuxIO_TeletypeNL
526 popa
527 popf
528 ENDIF
529ENDIF
530
531 mov si, offset Configuration
532 xor bx, bx
533
534 ; Changed from 5 to calculated value (not here, see compat. issue below)
535 ; Fixes issue: #2987 -- "air-boot doesn't remember drive letter"
536 ; Size of the ab-configuration in 512 byte sectors
537 ; mov cx, (MBR_BackUpMBR - Configuration) / 200h
538
539 ; AB v1.07 stores a 5 sector configuration with a 5 sector checksum.
540 ; AB v1.0.8+ *should* stores a 7 sector configuration with a
541 ; 7 sector checksum.
542 ; Because 5 was hardcoded here, SET(A)BOOT v1.07 will see see an AB v1.0.8+
543 ; config as corrupted, while this is not the case.
544 ; So, for compatibility reasons, in v1.0.8+, the checksum stored is over
545 ; 5 sectors, to be compatible with v1.07.
546 ; This may change (be corrected) in future versions !
547 mov cx,5
548
549 mov dx, [CFG_CheckConfig]
550 mov [CFG_CheckConfig], bx
551 PCCC_Loop:
552 call MBR_GetCheckOfSector
553 loop PCCC_Loop
554 cmp bx, dx
555 jne PCCC_Failed
556 mov CFG_CheckConfig, dx
557 ret
558 PCCC_Failed:
559 mov si, offset TXT_ERROR_CheckConfig
560 call MBR_Teletype
561 mov si, offset TXT_ERROR_CheckFailed
562 call MBR_Teletype
563 jmp MBR_HaltSystem
564PRECRAP_CheckConfiguration EndP
565
566
567; Rousseau: added
568; In: SI - Pointer to begin of string (EOS is 0)
569; Destroyed: SI
570; Fixme: Uses double writes to use attribute with teletype-function.
571MBR_TeletypeBold Proc Near Uses ax bx cx
572 MBRT_LoopBold:
573 lodsb
574 or al, al
575 jz MBRT_EndBold
576 push ax
577 mov ah,09h
578 mov bx,15
579 mov cx,1
580 int 10h
581 pop ax
582 mov ah,0eh
583 mov bx,7 ; Does not do anything in text-modus
584 mov cx,1
585 int 10h
586 jmp MBRT_LoopBold
587 MBRT_EndBold:
588 ret
589MBR_TeletypeBold EndP
590
591
592; In: SI - Pointer to begin of string (EOS is 0)
593; Destroyed: SI
594; Fixme: Uses double writes to use attribute with teletype-function.
595MBR_TeletypeVolName Proc Near Uses ax bx cx
596 mov cx, 11
597 MBRT_LoopVolName:
598 mov dx,cx ; Backup counter
599 lodsb
600 or al, al
601 jz MBRT_EndVolName
602 push ax
603 mov ah,09h
604 mov bx,15
605 mov cx,1
606 int 10h ; DX is preserved
607 pop ax
608 mov ah,0eh
609 mov bx,7 ; Does not do anything in text-modus
610 mov cx,1
611 int 10h ; DX is preserved
612 mov cx,dx ; Restore counter
613 loop MBRT_LoopVolName
614 MBRT_EndVolName:
615 ret
616MBR_TeletypeVolName EndP
617
618; Rousseau: added
619; Move cursor to next line
620; Just do a new-line if SI==0
621MBR_TeletypeNL Proc Near Uses ax bx cx
622 test si,si
623 jz MBR_TeletypeNL_NL
624 call MBR_Teletype
625 MBR_TeletypeNL_NL:
626 push si
627 mov si, offset NL
628 call MBR_Teletype
629 pop si
630 ret
631MBR_TeletypeNL EndP
632
633; Sync teletype position to VideoIO
634MBR_TeletypeSyncPos Proc Near Uses ax bx cx dx
635 pushf
636 mov bh, 0
637 mov ah, 02h
638 mov dh,byte ptr [TextPosY]
639 mov dl,byte ptr [TextPosX]
640 int 10h
641 popf
642 ret
643MBR_TeletypeSyncPos EndP
644
645; Check if a memory block is all zeros
646; IN : BX pointer to memblock
647; CX length to check, zero length is interpreted as block is zero
648; OUT : ZF=1 block if all zeros
649; NOTE: Segment used is DS, which should be the same as ES
650IsMemBlockZero Proc Near Uses ax di
651 push es ; Save ES just to be sure
652 push ds ; Segment to use
653 pop es ; Pop in ES because ES is required for scasb
654 mov di, bx ; Pointer to memblock
655 xor al, al ; Compare to zero
656 repe scasb ; Scan the block, will leave ZF=1 if all zeros
657 mov bx, di ; Update pointer (points past last byte compared)
658 pop es ; Restore ES
659 ret
660IsMemBlockZero EndP
661
662; Check if a loaded sector is all zeros
663; IN : BX pointer to memblock
664; OUT : ZF=1 block if all zeros
665; NOTE: Segment used is DS, which should be the same as ES
666IsSectorZero Proc Near Uses cx
667 mov cx, sector_size ; Normal size of a sector (512 bytes)
668 call IsMemBlockZero ; Check the memory block
669 ret
670IsSectorZero EndP
Note: See TracBrowser for help on using the repository browser.