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

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

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