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

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

Added more debug hooks [v1.1.1-testing]

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.5 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
418IFDEF AUX_DEBUG
419 IF 1
420 mov dl, [BIOS_BootDisk]
421 ;~ mov dl, 81h
422 call DriveIO_LocateMasterLVMSector
423 call DEBUG_DumpRegisters
424 mov si, offset [TmpSector]
425 call AuxIO_DumpSector
426 ENDIF
427ENDIF
428
429 ; =======================================
430 ; Checks for MBR Virii :) I love that job
431 ; =======================================
432 test byte ptr [CFG_DetectStealth], 1
433 jz PCM_NoStealthDetection
434 call VIRUS_CheckForStealth
435 PCM_NoStealthDetection:
436 test byte ptr [CFG_DetectVirus], 1
437 jz PCM_NoVirusDetection
438 call VIRUS_CheckForVirus
439 PCM_NoVirusDetection:
440
441
442 ; ============================================
443 ; Delay for some time and get Strg/Alt State
444 ; ============================================
445 test byte ptr [CFG_CooperBars], 1
446 jnz PCM_ShortDelay
447 mov al, 27 ; About 1.5 seconds
448 test byte ptr [CFG_FloppyBootGetName], 1
449 jz PCM_LongDelay
450 PCM_ShortDelay:
451
452 mov al, 13 ; shorten delay,if floppy gets accessed
453 PCM_LongDelay:
454
455 call TIMER_WaitTicCount
456
457 ; First check, if any normal key got pressed...
458 mov ah, 1
459 int 16h
460 jz PCM_NoNormalKeyPressed
461 ; User doesn't know what to do...or he is crazy <g> so display message
462 mov si, offset TXT_HowEnterSetup
463 call MBR_Teletype
464 mov al, 54 ; about 3 seconds, delay again
465
466 call TIMER_WaitTicCount
467
468 PCM_NoNormalKeyPressed:
469 ; Now get keyboard Strg/Alt State
470 mov ah, 02h
471 int 16h
472 mov [SETUP_KeysOnEntry], al
473
474 ; Copy device-name to the ContBIOSbootSeq-IPT entry
475 ; We may not do this before PRECRAP_CheckConfiguration, because otherwise
476 ; this check will fail.
477 call PART_UpdateResumeBIOSName
478 ret
479PRECRAP_Main EndP
480
481
482
483
484AFTERCRAP_Main Proc Near
485
486IFDEF AUX_DEBUG
487 IF 0
488 pushf
489 pusha
490 push si
491 mov si, offset $+5
492 jmp @F
493 db 10,'AFTERCRAP_Main:',10,0
494 @@:
495 call AuxIO_Print
496 pop si
497 ;~ call DEBUG_DumpRegisters
498 ;~ call AuxIO_DumpParagraph
499 ;~ call AuxIO_TeletypeNL
500 popa
501 popf
502 ENDIF
503ENDIF
504
505 ; ===================================================
506 ; Now get volume label of FloppyDrive, if wanted...
507 ; ===================================================
508 test byte ptr [CFG_FloppyBootGetName], 1
509 jz ACM_NoFloppyGetName
510 call DriveIO_UpdateFloppyName
511 or ax, ax
512 jnz ACM_NoFloppyGetName
513 ; Try a second time, if it failed to detect the Floppy
514 call DriveIO_UpdateFloppyName
515 ACM_NoFloppyGetName:
516 ret
517AFTERCRAP_Main EndP
518
519
520; Checks Configuration CheckSum...Displays message, if failed.
521PRECRAP_CheckConfiguration Proc Near Uses ds si es di
522
523IFDEF AUX_DEBUG
524 IF 0
525 pushf
526 pusha
527 push si
528 mov si, offset $+5
529 jmp @F
530 db 10,'PRECRAP_CheckConfiguration:',10,0
531 @@:
532 call AuxIO_Print
533 pop si
534 ;~ call DEBUG_DumpRegisters
535 ;~ call AuxIO_DumpParagraph
536 ;~ call AuxIO_TeletypeNL
537 popa
538 popf
539 ENDIF
540ENDIF
541
542 mov si, offset Configuration
543 xor bx, bx
544
545 ; Changed from 5 to calculated value (not here, see compat. issue below)
546 ; Fixes issue: #2987 -- "air-boot doesn't remember drive letter"
547 ; Size of the ab-configuration in 512 byte sectors
548 ; mov cx, (MBR_BackUpMBR - Configuration) / 200h
549
550 ; AB v1.07 stores a 5 sector configuration with a 5 sector checksum.
551 ; AB v1.0.8+ *should* stores a 7 sector configuration with a
552 ; 7 sector checksum.
553 ; Because 5 was hardcoded here, SET(A)BOOT v1.07 will see see an AB v1.0.8+
554 ; config as corrupted, while this is not the case.
555 ; So, for compatibility reasons, in v1.0.8+, the checksum stored is over
556 ; 5 sectors, to be compatible with v1.07.
557 ; This may change (be corrected) in future versions !
558 mov cx,5
559
560 mov dx, [CFG_CheckConfig]
561 mov [CFG_CheckConfig], bx
562 PCCC_Loop:
563 call MBR_GetCheckOfSector
564 loop PCCC_Loop
565 cmp bx, dx
566 jne PCCC_Failed
567 mov CFG_CheckConfig, dx
568 ret
569 PCCC_Failed:
570 mov si, offset TXT_ERROR_CheckConfig
571 call MBR_Teletype
572 mov si, offset TXT_ERROR_CheckFailed
573 call MBR_Teletype
574 jmp MBR_HaltSystem
575PRECRAP_CheckConfiguration EndP
576
577
578; Rousseau: added
579; In: SI - Pointer to begin of string (EOS is 0)
580; Destroyed: SI
581; Fixme: Uses double writes to use attribute with teletype-function.
582MBR_TeletypeBold Proc Near Uses ax bx cx
583 MBRT_LoopBold:
584 lodsb
585 or al, al
586 jz MBRT_EndBold
587 push ax
588 mov ah,09h
589 mov bx,15
590 mov cx,1
591 int 10h
592 pop ax
593 mov ah,0eh
594 mov bx,7 ; Does not do anything in text-modus
595 mov cx,1
596 int 10h
597 jmp MBRT_LoopBold
598 MBRT_EndBold:
599 ret
600MBR_TeletypeBold EndP
601
602
603; In: SI - Pointer to begin of string (EOS is 0)
604; Destroyed: SI
605; Fixme: Uses double writes to use attribute with teletype-function.
606MBR_TeletypeVolName Proc Near Uses ax bx cx
607 mov cx, 11
608 MBRT_LoopVolName:
609 mov dx,cx ; Backup counter
610 lodsb
611 or al, al
612 jz MBRT_EndVolName
613 push ax
614 mov ah,09h
615 mov bx,15
616 mov cx,1
617 int 10h ; DX is preserved
618 pop ax
619 mov ah,0eh
620 mov bx,7 ; Does not do anything in text-modus
621 mov cx,1
622 int 10h ; DX is preserved
623 mov cx,dx ; Restore counter
624 loop MBRT_LoopVolName
625 MBRT_EndVolName:
626 ret
627MBR_TeletypeVolName EndP
628
629; Rousseau: added
630; Move cursor to next line
631; Just do a new-line if SI==0
632MBR_TeletypeNL Proc Near Uses ax bx cx
633 test si,si
634 jz MBR_TeletypeNL_NL
635 call MBR_Teletype
636 MBR_TeletypeNL_NL:
637 push si
638 mov si, offset NL
639 call MBR_Teletype
640 pop si
641 ret
642MBR_TeletypeNL EndP
643
644; Sync teletype position to VideoIO
645MBR_TeletypeSyncPos Proc Near Uses ax bx cx dx
646 pushf
647 mov bh, 0
648 mov ah, 02h
649 mov dh,byte ptr [TextPosY]
650 mov dl,byte ptr [TextPosX]
651 int 10h
652 popf
653 ret
654MBR_TeletypeSyncPos EndP
655
656; Check if a memory block is all zeros
657; IN : BX pointer to memblock
658; CX length to check, zero length is interpreted as block is zero
659; OUT : ZF=1 block if all zeros
660; NOTE: Segment used is DS, which should be the same as ES
661IsMemBlockZero Proc Near Uses ax di
662 push es ; Save ES just to be sure
663 push ds ; Segment to use
664 pop es ; Pop in ES because ES is required for scasb
665 mov di, bx ; Pointer to memblock
666 xor al, al ; Compare to zero
667 repe scasb ; Scan the block, will leave ZF=1 if all zeros
668 mov bx, di ; Update pointer (points past last byte compared)
669 pop es ; Restore ES
670 ret
671IsMemBlockZero EndP
672
673; Check if a loaded sector is all zeros
674; IN : BX pointer to memblock
675; OUT : ZF=1 block if all zeros
676; NOTE: Segment used is DS, which should be the same as ES
677IsSectorZero Proc Near Uses cx
678 mov cx, sector_size ; Normal size of a sector (512 bytes)
679 call IsMemBlockZero ; Check the memory block
680 ret
681IsSectorZero EndP
Note: See TracBrowser for help on using the repository browser.