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

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

Updated debug hooks (debugging) [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: 18.6 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; =============================================================================
202
203 ; Start with disk at index 0
204 xor cx,cx
205
206 PRECRAP_Main_next_disk:
207
208 ; Get next disk and convert to BIOS disk-number
209 mov dl,cl
210 or dl,80h
211
212 ;
213 ; This also setup the size of the i13xbuf.
214 ;
215 call DriveIO_GatherDiskInfo ; Also used to fill the geo, should be separate function
216
217 mov bx,offset [HugeDisk]
218 add bx,cx
219 mov [bx], al
220
221
222 ; CHECKSUM CALCULATION DOES NOT WORK YET HERE
223 ; CRC TABLE NOT INITED YET
224 ; Returns NC if no valid LVM record found
225 call DriveIO_LoadMasterLVMSector
226
227 pushf
228
229 mov bx, offset [TrueSecs]
230 add bx,cx
231 add bx,cx
232 add bx,cx
233 add bx,cx
234 popf
235
236 ; bx now contains pointer to truesecs for this drive
237
238 jnc NoValidMasterLVM
239
240 ; ?? 3f bij disk 80h maar 0 bij disk 81h
241 mov si,offset [LVMSector]
242 mov ax,[si+LocLVM_Secs]
243
244 ;~ pusha
245 ;~ mov dx,ax
246 ;~ mov al,'%'
247 ;~ call VideoIO_PrintSingleChar
248 ;~ mov ax,dx
249 ;~ call VideoIO_PrintHexWord
250 ;~ mov al,'%'
251 ;~ call VideoIO_PrintSingleChar
252 ;~ popa
253
254 mov word ptr [bx],ax
255 jmp SkipUseBiosSecs
256
257
258 NoValidMasterLVM:
259 push bx ; push truesecs pointer
260 mov bx, offset [BIOS_Secs]
261 add bx,cx
262 add bx,cx
263 add bx,cx
264 add bx,cx
265
266 mov ax,[bx] ; get biossecs
267 pop bx
268 mov word ptr [bx],ax ; store bios secs in truesecs
269
270
271 SkipUseBiosSecs:
272 inc cx
273 cmp cl,[TotalHarddiscs]
274 jb PRECRAP_Main_next_disk
275
276; =============================================================================
277
278 IFDEF AUX_DEBUG
279 ; Write some debug-info to the com-port
280 call DEBUG_Dump1
281 ENDIF
282
283 ;~ jz NoValidMasterLVM
284;~
285 ;~ ; A valid Master LVM has been found.
286 ;~ ; We use the values in here to determine the number of sectors per track,
287 ;~ ; since this could be OS/2 extended geometry.
288;~
289 ;~ jmp Continue1
290 ;~
291 ;~ mov word ptr [LOG_Secs],63
292
293; mov al,[HugeDisk] ;; fout, moet nog index bij
294; call AuxIO_TeletypeHexByte
295; call AuxIO_TeletypeNL
296
297; mov ax,word ptr [TrueSecs] ;; fout, moet nog index bij
298; call AuxIO_TeletypeHexWord
299; call AuxIO_TeletypeNL
300
301
302
303 ; Huge Disk indicator
304 ;~ mov si, offset [HugeBootDisk]
305 ;~ call MBR_Teletype
306 ;~ mov al,[HugeDisk]
307 ;~ mov si, offset [No]
308 ;~ test al,al
309 ;~ jz MBR_HugeDriveIndicator
310 ;~ mov si, offset [Yes]
311
312 MBR_HugeDriveIndicator:
313 ;~ call MBR_Teletype
314 ;~ xor si,si
315 ;~ call MBR_TeletypeNL
316
317
318 ;
319 ; Phase 1 Indicator
320 ;
321 mov si, offset [Phase1]
322 call MBR_Teletype
323
324 mov si, offset OS2_InstallVolume
325 mov al, [si]
326 test al,al ; See if phase 1 is active
327 jnz MBR_Main_BootThrough
328 mov si, offset NotActive
329
330 MBR_Main_BootThrough:
331 call MBR_Teletype
332 xor si,si
333 call MBR_TeletypeNL
334
335; =============================================================================
336
337 ; Calculate Cooper-Bar Tables
338 IFDEF FX_ENABLED
339 call FX_CalculateTables
340 ENDIF
341
342 ; Calculate LVM-CRC-Table
343 call LVM_InitCRCTable
344
345 ; Get HardDriveCount
346 call DriveIO_GetHardDriveCount
347
348 ; Calculate CHS/LBA Switch Table
349 call DriveIO_InitLBASwitchTable
350
351 ; Setup PartitionPointers-Table
352 call PART_CalculateStraightPartPointers
353
354 ; Setup Cyrillic Charset, if needed
355 IFDEF TXT_IncludeCyrillic
356 call CHARSET_IncludeCyrillic
357 ENDIF
358
359
360 ; This sets [CurIO_UseExtension] flag.
361 call DriveIO_CheckFor13extensions
362 mov al,[CurIO_UseExtension]
363 test al,al
364 jnz INT13X_Supported
365
366 ;
367 ; Show Message that BIOS INT13X is not supported
368 ; and Halt the System.
369 ;
370 mov cx, 0C04h
371 mov si, offset TXT_NoINT13XSupport
372 call SETUP_ShowErrorBox
373
374 ; Halt the system.
375 jmp HaltSystem
376
377
378 ;
379 ; INT13X Supported so continue.
380 ;
381 INT13X_Supported:
382
383
384 ;
385 ; Setup the size of the INT13X Disk Address Packet
386 ;
387 mov [INT13X_DAP], INT13X_DAP_Size
388
389 ;
390 ; Check valididy of the AiR-BOOT Configuration.
391 ;
392 call PRECRAP_CheckConfiguration
393
394
395 ; =======================================
396 ; Checks for MBR Virii :) I love that job
397 ; =======================================
398 test byte ptr [CFG_DetectStealth], 1
399 jz PCM_NoStealthDetection
400 call VIRUS_CheckForStealth
401 PCM_NoStealthDetection:
402 test byte ptr [CFG_DetectVirus], 1
403 jz PCM_NoVirusDetection
404 call VIRUS_CheckForVirus
405 PCM_NoVirusDetection:
406
407
408 ; ============================================
409 ; Delay for some time and get Strg/Alt State
410 ; ============================================
411 test byte ptr [CFG_CooperBars], 1
412 jnz PCM_ShortDelay
413 mov al, 27 ; About 1.5 seconds
414 test byte ptr [CFG_FloppyBootGetName], 1
415 jz PCM_LongDelay
416 PCM_ShortDelay:
417
418 mov al, 13 ; shorten delay,if floppy gets accessed
419 PCM_LongDelay:
420
421 call TIMER_WaitTicCount
422
423 ; First check, if any normal key got pressed...
424 mov ah, 1
425 int 16h
426 jz PCM_NoNormalKeyPressed
427 ; User doesn't know what to do...or he is crazy <g> so display message
428 mov si, offset TXT_HowEnterSetup
429 call MBR_Teletype
430 mov al, 54 ; about 3 seconds, delay again
431
432 call TIMER_WaitTicCount
433
434 PCM_NoNormalKeyPressed:
435 ; Now get keyboard Strg/Alt State
436 mov ah, 02h
437 int 16h
438 mov [SETUP_KeysOnEntry], al
439
440 ; Copy device-name to the ContBIOSbootSeq-IPT entry
441 ; We may not do this before PRECRAP_CheckConfiguration, because otherwise
442 ; this check will fail.
443 call PART_UpdateResumeBIOSName
444 ret
445PRECRAP_Main EndP
446
447
448
449
450AFTERCRAP_Main Proc Near
451
452IFDEF AUX_DEBUG
453 IF 0
454 pushf
455 pusha
456 push si
457 mov si, offset $+5
458 jmp @F
459 db 10,'AFTERCRAP_Main:',10,0
460 @@:
461 call AuxIO_Print
462 pop si
463 ;~ call DEBUG_DumpRegisters
464 ;~ call AuxIO_DumpParagraph
465 ;~ call AuxIO_TeletypeNL
466 popa
467 popf
468 ENDIF
469ENDIF
470
471 ; ===================================================
472 ; Now get volume label of FloppyDrive, if wanted...
473 ; ===================================================
474 test byte ptr [CFG_FloppyBootGetName], 1
475 jz ACM_NoFloppyGetName
476 call DriveIO_UpdateFloppyName
477 or ax, ax
478 jnz ACM_NoFloppyGetName
479 ; Try a second time, if it failed to detect the Floppy
480 call DriveIO_UpdateFloppyName
481 ACM_NoFloppyGetName:
482 ret
483AFTERCRAP_Main EndP
484
485
486; Checks Configuration CheckSum...Displays message, if failed.
487PRECRAP_CheckConfiguration Proc Near Uses ds si es di
488
489IFDEF AUX_DEBUG
490 IF 0
491 pushf
492 pusha
493 push si
494 mov si, offset $+5
495 jmp @F
496 db 10,'PRECRAP_CheckConfiguration:',10,0
497 @@:
498 call AuxIO_Print
499 pop si
500 ;~ call DEBUG_DumpRegisters
501 ;~ call AuxIO_DumpParagraph
502 ;~ call AuxIO_TeletypeNL
503 popa
504 popf
505 ENDIF
506ENDIF
507
508 mov si, offset Configuration
509 xor bx, bx
510
511 ; Changed from 5 to calculated value (not here, see compat. issue below)
512 ; Fixes issue: #2987 -- "air-boot doesn't remember drive letter"
513 ; Size of the ab-configuration in 512 byte sectors
514 ; mov cx, (MBR_BackUpMBR - Configuration) / 200h
515
516 ; AB v1.07 stores a 5 sector configuration with a 5 sector checksum.
517 ; AB v1.0.8+ *should* stores a 7 sector configuration with a
518 ; 7 sector checksum.
519 ; Because 5 was hardcoded here, SET(A)BOOT v1.07 will see see an AB v1.0.8+
520 ; config as corrupted, while this is not the case.
521 ; So, for compatibility reasons, in v1.0.8+, the checksum stored is over
522 ; 5 sectors, to be compatible with v1.07.
523 ; This may change (be corrected) in future versions !
524 mov cx,5
525
526 mov dx, [CFG_CheckConfig]
527 mov [CFG_CheckConfig], bx
528 PCCC_Loop:
529 call MBR_GetCheckOfSector
530 loop PCCC_Loop
531 cmp bx, dx
532 jne PCCC_Failed
533 mov CFG_CheckConfig, dx
534 ret
535 PCCC_Failed:
536 mov si, offset TXT_ERROR_CheckConfig
537 call MBR_Teletype
538 mov si, offset TXT_ERROR_CheckFailed
539 call MBR_Teletype
540 jmp MBR_HaltSystem
541PRECRAP_CheckConfiguration EndP
542
543
544; Rousseau: added
545; In: SI - Pointer to begin of string (EOS is 0)
546; Destroyed: SI
547; Fixme: Uses double writes to use attribute with teletype-function.
548MBR_TeletypeBold Proc Near Uses ax bx cx
549 MBRT_LoopBold:
550 lodsb
551 or al, al
552 jz MBRT_EndBold
553 push ax
554 mov ah,09h
555 mov bx,15
556 mov cx,1
557 int 10h
558 pop ax
559 mov ah,0eh
560 mov bx,7 ; Does not do anything in text-modus
561 mov cx,1
562 int 10h
563 jmp MBRT_LoopBold
564 MBRT_EndBold:
565 ret
566MBR_TeletypeBold EndP
567
568
569; In: SI - Pointer to begin of string (EOS is 0)
570; Destroyed: SI
571; Fixme: Uses double writes to use attribute with teletype-function.
572MBR_TeletypeVolName Proc Near Uses ax bx cx
573 mov cx, 11
574 MBRT_LoopVolName:
575 mov dx,cx ; Backup counter
576 lodsb
577 or al, al
578 jz MBRT_EndVolName
579 push ax
580 mov ah,09h
581 mov bx,15
582 mov cx,1
583 int 10h ; DX is preserved
584 pop ax
585 mov ah,0eh
586 mov bx,7 ; Does not do anything in text-modus
587 mov cx,1
588 int 10h ; DX is preserved
589 mov cx,dx ; Restore counter
590 loop MBRT_LoopVolName
591 MBRT_EndVolName:
592 ret
593MBR_TeletypeVolName EndP
594
595; Rousseau: added
596; Move cursor to next line
597; Just do a new-line if SI==0
598MBR_TeletypeNL Proc Near Uses ax bx cx
599 test si,si
600 jz MBR_TeletypeNL_NL
601 call MBR_Teletype
602 MBR_TeletypeNL_NL:
603 push si
604 mov si, offset NL
605 call MBR_Teletype
606 pop si
607 ret
608MBR_TeletypeNL EndP
609
610; Sync teletype position to VideoIO
611MBR_TeletypeSyncPos Proc Near Uses ax bx cx dx
612 pushf
613 mov bh, 0
614 mov ah, 02h
615 mov dh,byte ptr [TextPosY]
616 mov dl,byte ptr [TextPosX]
617 int 10h
618 popf
619 ret
620MBR_TeletypeSyncPos EndP
621
622; Check if a memory block is all zeros
623; IN : BX pointer to memblock
624; CX length to check, zero length is interpreted as block is zero
625; OUT : ZF=1 block if all zeros
626; NOTE: Segment used is DS, which should be the same as ES
627IsMemBlockZero Proc Near Uses ax di
628 push es ; Save ES just to be sure
629 push ds ; Segment to use
630 pop es ; Pop in ES because ES is required for scasb
631 mov di, bx ; Pointer to memblock
632 xor al, al ; Compare to zero
633 repe scasb ; Scan the block, will leave ZF=1 if all zeros
634 mov bx, di ; Update pointer (points past last byte compared)
635 pop es ; Restore ES
636 ret
637IsMemBlockZero EndP
638
639; Check if a loaded sector is all zeros
640; IN : BX pointer to memblock
641; OUT : ZF=1 block if all zeros
642; NOTE: Segment used is DS, which should be the same as ES
643IsSectorZero Proc Near Uses cx
644 mov cx, sector_size ; Normal size of a sector (512 bytes)
645 call IsMemBlockZero ; Check the memory block
646 ret
647IsSectorZero EndP
Note: See TracBrowser for help on using the repository browser.