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

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

Fixed non-functional TAB-key caused by disabling FX [v1.1.3-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.2-manual.pdf

File size: 17.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; DO PREPARING STUFF.
88;
89PRECRAP_Main Proc Near
90
91IFDEF AUX_DEBUG
92 IF 0
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 ;
103 ; Tasm needs .386 to handle 32-bit constants so we push the current
104 ; operating state and switch temporarily to handle
105 ; InitialFreeDriveletterMap.
106 ;
107 IFDEF TASM
108 pushstate
109 .386
110 ENDIF
111 ; Initialize the FreeDriveletterMap.
112 ; This is used by driveletter reassignment functions.
113 mov di, offset [FreeDriveletterMap]
114 mov ax, InitialFreeDriveletterMap AND 0ffffh
115 cld
116 stosw
117 mov ax, InitialFreeDriveletterMap SHR 16
118 stosw
119 ;
120 ; Restore Tasm operating state.
121 ;
122 IFDEF TASM
123 popstate
124 ENDIF
125
126
127 ; Use video page 0 for screen output
128 mov word ptr [VideoIO_Segment], VideoIO_Page0
129
130 ; Don't use blinking attribute
131 call VideoIO_NoBlinking
132
133 ; Get HardDriveCount
134 call DriveIO_GetHardDriveCount
135
136
137 ; Rousseau: added
138 call VideoIO_ClearScreen
139
140 ; Cursor to upper-left
141 mov byte ptr [TextPosX], 0
142 mov byte ptr [TextPosY], 0
143 call VideoIO_CursorSet
144
145 ;~ mov ax, VideoIO_Page1
146 ;~ call VideoIO_BackUpTo ; Copy BIOS POST to Second Page
147
148 ; Copyright
149 mov si, [offset Copyright]
150 call VideoIO_Print
151 inc [TextPosY]
152 mov [TextPosX], 0
153 call MBR_TeletypeSyncPos
154
155 ;call SOUND_Beep
156
157 ; Show build info
158 call VideoIO_PrintBuildInfo
159
160 ; Let user know we started scanning...
161IFDEF AUX_DEBUG
162 xor si, si
163 call MBR_TeletypeNL
164ENDIF
165 mov si, offset [scanning_txt]
166 call MBR_TeletypeBold
167
168; Show message if com-port debugging is active
169IFDEF AUX_DEBUG
170 ; Don't show message if com-port debugging is not active
171 mov dx, [BIOS_AuxParms]
172 test dl, dl
173 jz @F
174
175 ; Show initialization message
176 mov ah, [TextPosY]
177 mov [TextPosY], 2
178 mov si, offset AuxInitMsg
179 ;~ call MBR_Teletype
180 call VideoIO_Print
181
182 ; Sync output position
183 ;~ call VideoIO_SyncPos
184
185 ; Show port number
186 mov al, dl
187 call VideoIO_PrintByteDynamicNumber
188 mov [TextPosY], ah
189 @@:
190ENDIF
191
192 ; Calculate Cooper-Bar Tables
193 IFDEF FX_ENABLED
194 call FX_CalculateTables
195 ENDIF
196
197 ; Calculate LVM-CRC-Table
198 call LVM_InitCRCTable
199
200 ; Get HardDriveCount
201 call DriveIO_GetHardDriveCount
202
203 ; Calculate CHS/LBA Switch Table
204 call DriveIO_InitLBASwitchTable
205
206 ; Setup PartitionPointers-Table
207 call PART_CalculateStraightPartPointers
208
209 ; Setup Cyrillic Charset, if needed
210 IFDEF TXT_IncludeCyrillic
211 call CHARSET_IncludeCyrillic
212 ENDIF
213
214
215 ; This sets [CurIO_UseExtension] flag.
216 call DriveIO_CheckFor13extensions
217 mov al,[CurIO_UseExtension]
218 test al,al
219 jnz INT13X_Supported
220
221 ;
222 ; Show Message that BIOS INT13X is not supported
223 ; and Halt the System.
224 ;
225 mov cx, 0C04h
226 mov si, offset TXT_NoINT13XSupport
227 call SETUP_ShowErrorBox
228
229 ; Halt the system.
230 jmp HaltSystem
231
232
233 ;
234 ; INT13X Supported so continue.
235 ;
236 INT13X_Supported:
237
238
239 ;
240 ; Setup the size of the INT13X Disk Address Packet
241 ;
242 mov [INT13X_DAP], INT13X_DAP_Size
243
244 ;
245 ; Check valididy of the AiR-BOOT Configuration.
246 ;
247 call PRECRAP_CheckConfiguration
248
249
250 ; =======================================
251 ; Checks for MBR Virii :) I love that job
252 ; =======================================
253 test byte ptr [CFG_DetectStealth], 1
254 jz PCM_NoStealthDetection
255 call VIRUS_CheckForStealth
256 PCM_NoStealthDetection:
257 test byte ptr [CFG_DetectVirus], 1
258 jz PCM_NoVirusDetection
259 call VIRUS_CheckForVirus
260 PCM_NoVirusDetection:
261
262
263 ; ============================================
264 ; Delay for some time and get Strg/Alt State
265 ; ============================================
266
267; While the FX-module is excluded from newer versions, we want to retain
268; the option of enabling it.
269IFDEF FX_ENABLED
270 test byte ptr [CFG_CooperBars], 1
271 jnz PCM_ShortDelay
272ENDIF
273
274 mov al, 27 ; About 1.5 seconds
275 test byte ptr [CFG_FloppyBootGetName], 1
276 jz PCM_LongDelay
277 PCM_ShortDelay:
278
279 mov al, 13 ; shorten delay,if floppy gets accessed
280 PCM_LongDelay:
281
282 call TIMER_WaitTicCount
283
284 ; First check, if any normal key got pressed...
285 mov ah, 1
286 int 16h
287 jz PCM_NoNormalKeyPressed
288 ; User doesn't know what to do...or he is crazy <g> so display message
289 mov si, offset TXT_HowEnterSetup
290 call MBR_Teletype
291 mov al, 54 ; about 3 seconds, delay again
292
293 call TIMER_WaitTicCount
294
295 PCM_NoNormalKeyPressed:
296 ; Now get keyboard Strg/Alt State
297 mov ah, 02h
298 int 16h
299 mov [SETUP_KeysOnEntry], al
300
301 ; Copy device-name to the ContBIOSbootSeq-IPT entry
302 ; We may not do this before PRECRAP_CheckConfiguration, because otherwise
303 ; this check will fail.
304 call PART_UpdateResumeBIOSName
305 ret
306PRECRAP_Main EndP
307
308
309
310
311AFTERCRAP_Main Proc Near
312
313IFDEF AUX_DEBUG
314 IF 0
315 DBG_TEXT_OUT_AUX 'AFTERCRAP_Main:'
316 PUSHRF
317 ;~ call DEBUG_DumpRegisters
318 ;~ call AuxIO_DumpParagraph
319 ;~ call AuxIO_TeletypeNL
320 POPRF
321 ENDIF
322ENDIF
323
324 ; ===================================================
325 ; Now get volume label of FloppyDrive, if wanted...
326 ; ===================================================
327 test byte ptr [CFG_FloppyBootGetName], 1
328 jz ACM_NoFloppyGetName
329 call DriveIO_UpdateFloppyName
330 or ax, ax
331 jnz ACM_NoFloppyGetName
332 ; Try a second time, if it failed to detect the Floppy
333 call DriveIO_UpdateFloppyName
334 ACM_NoFloppyGetName:
335 ret
336AFTERCRAP_Main EndP
337
338
339; Checks Configuration CheckSum...Displays message, if failed.
340PRECRAP_CheckConfiguration Proc Near Uses ds si es di
341
342IFDEF AUX_DEBUG
343 IF 0
344 DBG_TEXT_OUT_AUX 'PRECRAP_CheckConfiguration:'
345 PUSHRF
346 ;~ call DEBUG_DumpRegisters
347 ;~ call AuxIO_DumpParagraph
348 ;~ call AuxIO_TeletypeNL
349 POPRF
350 ENDIF
351ENDIF
352
353 mov si, offset Configuration
354 xor bx, bx
355
356 ; Changed from 5 to calculated value (not here, see compat. issue below)
357 ; Fixes issue: #2987 -- "air-boot doesn't remember drive letter"
358 ; Size of the ab-configuration in 512 byte sectors
359 ; mov cx, (MBR_BackUpMBR - Configuration) / 200h
360
361 ; AB v1.07 stores a 5 sector configuration with a 5 sector checksum.
362 ; AB v1.0.8+ *should* stores a 7 sector configuration with a
363 ; 7 sector checksum.
364 ; Because 5 was hardcoded here, SET(A)BOOT v1.07 will see see an AB v1.0.8+
365 ; config as corrupted, while this is not the case.
366 ; So, for compatibility reasons, in v1.0.8+, the checksum stored is over
367 ; 5 sectors, to be compatible with v1.07.
368 ; This may change (be corrected) in future versions !
369 mov cx,5
370
371 mov dx, [CFG_CheckConfig] ; Get current CRC for configuration
372 mov [CFG_CheckConfig], bx ; Mark it as invalid
373 PCCC_Loop:
374 call MBR_GetCheckOfSector ; Calculate CRC
375 loop PCCC_Loop
376 cmp bx, dx ; Validate CRC
377
378 ;
379 ; The CRC is calculated and inserted in the loader image when
380 ; AiR-BOOT is installed. Ignoring the CRC enables manually
381 ; merging the loader without using the installer. This is used
382 ; for debugging in virtual machines, where it is easy to
383 ; merge the loader to the disk image of the VM.
384 ;
385IFNDEF CRC_IGNORE
386 jne PCCC_Failed ; Validation failed, halt AiR-BOOT
387ENDIF
388
389 mov CFG_CheckConfig, dx ; Restore the valid CRC
390 ret
391
392 ;
393 ; CRC validation for the configuration failed.
394 ; Inform the user of this and halt the system.
395 ;
396 PCCC_Failed:
397 mov si, offset TXT_ERROR_CheckConfig
398 call MBR_Teletype
399 mov si, offset TXT_ERROR_CheckFailed
400 call MBR_Teletype
401 jmp MBR_HaltSystem
402PRECRAP_CheckConfiguration EndP
403
404
405; Rousseau: added
406; In: SI - Pointer to begin of string (EOS is 0)
407; Destroyed: SI
408; Fixme: Uses double writes to use attribute with teletype-function.
409MBR_TeletypeBold Proc Near Uses ax bx cx
410 MBRT_LoopBold:
411 lodsb
412 or al, al
413 jz MBRT_EndBold
414 push ax
415 mov ah,09h
416 mov bx,15
417 mov cx,1
418 int 10h
419 pop ax
420 mov ah,0eh
421 mov bx,7 ; Does not do anything in text-modus
422 mov cx,1
423 int 10h
424 jmp MBRT_LoopBold
425 MBRT_EndBold:
426 ret
427MBR_TeletypeBold EndP
428
429
430; In: SI - Pointer to begin of string (EOS is 0)
431; Destroyed: SI
432; Fixme: Uses double writes to use attribute with teletype-function.
433MBR_TeletypeVolName Proc Near Uses ax bx cx
434 mov cx, 11
435 MBRT_LoopVolName:
436 mov dx,cx ; Backup counter
437 lodsb
438 or al, al
439 jz MBRT_EndVolName
440 push ax
441 mov ah,09h
442 mov bx,15
443 mov cx,1
444 int 10h ; DX is preserved
445 pop ax
446 mov ah,0eh
447 mov bx,7 ; Does not do anything in text-modus
448 mov cx,1
449 int 10h ; DX is preserved
450 mov cx,dx ; Restore counter
451 loop MBRT_LoopVolName
452 MBRT_EndVolName:
453 ret
454MBR_TeletypeVolName EndP
455
456; Rousseau: added
457; Move cursor to next line
458; Just do a new-line if SI==0
459MBR_TeletypeNL Proc Near Uses ax bx cx
460 test si,si
461 jz MBR_TeletypeNL_NL
462 call MBR_Teletype
463 MBR_TeletypeNL_NL:
464 push si
465 mov si, offset NL
466 call MBR_Teletype
467 pop si
468 ret
469MBR_TeletypeNL EndP
470
471; Sync teletype position to VideoIO
472MBR_TeletypeSyncPos Proc Near Uses ax bx cx dx
473 pushf
474 mov bh, 0
475 mov ah, 02h
476 mov dh,byte ptr [TextPosY]
477 mov dl,byte ptr [TextPosX]
478 int 10h
479 popf
480 ret
481MBR_TeletypeSyncPos EndP
482
483;------------------------------------------------------------------------------
484; Check if a memory block is all zeros
485;------------------------------------------------------------------------------
486; IN : BX pointer to memblock
487; : CX length to check, zero length is interpreted as block is zero
488; OUT : ZF=1 block if all zeros
489; NOTE : Segment used is DS, which should be the same as ES
490;------------------------------------------------------------------------------
491IsMemBlockZero Proc Near Uses ax di es
492 push ds ; Segment to use
493 pop es ; Pop in ES because ES is required for scasb
494 mov di, bx ; Pointer to memblock
495 xor al, al ; Compare to zero
496 cld ; Direction upwards
497 repe scasb ; Scan the block, will leave ZF=1 if all zeros
498 ret
499IsMemBlockZero EndP
500
501;------------------------------------------------------------------------------
502; Check if a loaded sector is all zeros
503;------------------------------------------------------------------------------
504; IN : SI pointer to sector buffer
505; OUT : ZF=1 block if all zeros
506; NOTE : Segment used is DS
507;------------------------------------------------------------------------------
508IsSectorBufferZero Proc Near Uses bx cx
509 mov bx, si ; Address of sector buffer
510 mov cx, sector_size ; Normal size of a sector (512 bytes)
511 call IsMemBlockZero ; Check the memory block
512 ret
513IsSectorBufferZero EndP
514
515;------------------------------------------------------------------------------
516; Fill a memory block with a specific value
517;------------------------------------------------------------------------------
518; IN : AL value to fill block with
519; : BX pointer to memblock
520; : CX length to fill, 0 fills nothing
521; OUT : ZF=1 if fill value was 0
522; NOTE : Segment used is DS
523;------------------------------------------------------------------------------
524FillMemBlock Proc Near Uses cx di es
525 push ds ; Segment to use
526 pop es ; Pop in ES because ES is required for scasb
527 mov di, bx ; Pointer to memblock
528 cld ; Direction upwards
529 rep stosb ; Fill the memory block with value in AL
530 test al, al ; Set ZR if fill value used is 0
531 ret
532FillMemBlock EndP
533
534;------------------------------------------------------------------------------
535; Fill a memory block with zeros
536;------------------------------------------------------------------------------
537; IN : BX pointer to memblock
538; : CX length to fill, 0 fills nothing
539; OUT : Nothing
540; NOTE : Segment used is DS
541;------------------------------------------------------------------------------
542ClearMemBlock Proc Near Uses ax
543 xor al, al ; Fill value
544 call FillMemBlock ; Fill the memory block
545 ret
546ClearMemBlock EndP
547
548;------------------------------------------------------------------------------
549; Clears a sector buffer
550;------------------------------------------------------------------------------
551; IN : SI pointer to sector buffer
552; OUT : Nothing
553; NOTE : Segment used is DS
554;------------------------------------------------------------------------------
555ClearSectorBuffer Proc Near Uses bx cx
556 mov bx, si ; Address of sector buffer
557 mov cx, sector_size ; Normal size of a sector (512 bytes)
558 call ClearMemBlock ; Clear the sector buffer
559 ret
560ClearSectorBuffer EndP
561
Note: See TracBrowser for help on using the repository browser.