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

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

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