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

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

Removed all the disk stuff from 'PRECRAP' [v1.1.1-testing]

This stuff has always been in the wrong place because no scanning has
taken place yet. The stuff in 'PRECRAP' should be concerned with
initializing stuff only.

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: 17.7 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 ; Write MBR back to disk to sync MBR variables.
179 ; Otherwise subsequent MBR loads will differ from the RAM stored one,
180 ; which is used by MBR protection to validate parts of the MBR.
181 xor bx, bx
182 mov cx, 1
183 xor dh, dh
184 mov dl, [BIOS_BootDisk]
185 mov al, 1
186 mov ah, 03h
187 int 13h
188 ;!
189 ;! TODO: Check success
190 ;! Yes, we should check for errors here, coz it would mean AirBoot
191 ;! was loaded from a disk where the MBR cannot be written !
192 ;!
193
194
195IFDEF AUX_DEBUG
196 IF 1
197 call DEBUG_Dump1
198 ENDIF
199ENDIF
200
201
202 ;
203 ; Phase 1 Indicator
204 ;
205 mov si, offset [Phase1]
206 call MBR_Teletype
207
208 mov si, offset OS2_InstallVolume
209 mov al, [si]
210 test al,al ; See if phase 1 is active
211 jnz MBR_Main_BootThrough
212 mov si, offset NotActive
213
214 MBR_Main_BootThrough:
215 call MBR_Teletype
216 xor si,si
217 call MBR_TeletypeNL
218
219
220 ; Calculate Cooper-Bar Tables
221 IFDEF FX_ENABLED
222 call FX_CalculateTables
223 ENDIF
224
225 ; Calculate LVM-CRC-Table
226 call LVM_InitCRCTable
227
228 ; Get HardDriveCount
229 call DriveIO_GetHardDriveCount
230
231 ; Calculate CHS/LBA Switch Table
232 call DriveIO_InitLBASwitchTable
233
234 ; Setup PartitionPointers-Table
235 call PART_CalculateStraightPartPointers
236
237 ; Setup Cyrillic Charset, if needed
238 IFDEF TXT_IncludeCyrillic
239 call CHARSET_IncludeCyrillic
240 ENDIF
241
242
243 ; This sets [CurIO_UseExtension] flag.
244 call DriveIO_CheckFor13extensions
245 mov al,[CurIO_UseExtension]
246 test al,al
247 jnz INT13X_Supported
248
249 ;
250 ; Show Message that BIOS INT13X is not supported
251 ; and Halt the System.
252 ;
253 mov cx, 0C04h
254 mov si, offset TXT_NoINT13XSupport
255 call SETUP_ShowErrorBox
256
257 ; Halt the system.
258 jmp HaltSystem
259
260
261 ;
262 ; INT13X Supported so continue.
263 ;
264 INT13X_Supported:
265
266
267 ;
268 ; Setup the size of the INT13X Disk Address Packet
269 ;
270 mov [INT13X_DAP], INT13X_DAP_Size
271
272 ;
273 ; Check valididy of the AiR-BOOT Configuration.
274 ;
275 call PRECRAP_CheckConfiguration
276
277
278 ; =======================================
279 ; Checks for MBR Virii :) I love that job
280 ; =======================================
281 test byte ptr [CFG_DetectStealth], 1
282 jz PCM_NoStealthDetection
283 call VIRUS_CheckForStealth
284 PCM_NoStealthDetection:
285 test byte ptr [CFG_DetectVirus], 1
286 jz PCM_NoVirusDetection
287 call VIRUS_CheckForVirus
288 PCM_NoVirusDetection:
289
290
291 ; ============================================
292 ; Delay for some time and get Strg/Alt State
293 ; ============================================
294 test byte ptr [CFG_CooperBars], 1
295 jnz PCM_ShortDelay
296 mov al, 27 ; About 1.5 seconds
297 test byte ptr [CFG_FloppyBootGetName], 1
298 jz PCM_LongDelay
299 PCM_ShortDelay:
300
301 mov al, 13 ; shorten delay,if floppy gets accessed
302 PCM_LongDelay:
303
304 call TIMER_WaitTicCount
305
306 ; First check, if any normal key got pressed...
307 mov ah, 1
308 int 16h
309 jz PCM_NoNormalKeyPressed
310 ; User doesn't know what to do...or he is crazy <g> so display message
311 mov si, offset TXT_HowEnterSetup
312 call MBR_Teletype
313 mov al, 54 ; about 3 seconds, delay again
314
315 call TIMER_WaitTicCount
316
317 PCM_NoNormalKeyPressed:
318 ; Now get keyboard Strg/Alt State
319 mov ah, 02h
320 int 16h
321 mov [SETUP_KeysOnEntry], al
322
323 ; Copy device-name to the ContBIOSbootSeq-IPT entry
324 ; We may not do this before PRECRAP_CheckConfiguration, because otherwise
325 ; this check will fail.
326 call PART_UpdateResumeBIOSName
327 ret
328PRECRAP_Main EndP
329
330
331
332
333AFTERCRAP_Main Proc Near
334
335IFDEF AUX_DEBUG
336 IF 0
337 DBG_TEXT_OUT_AUX 'AFTERCRAP_Main:'
338 PUSHRF
339 ;~ call DEBUG_DumpRegisters
340 ;~ call AuxIO_DumpParagraph
341 ;~ call AuxIO_TeletypeNL
342 POPRF
343 ENDIF
344ENDIF
345
346 ; ===================================================
347 ; Now get volume label of FloppyDrive, if wanted...
348 ; ===================================================
349 test byte ptr [CFG_FloppyBootGetName], 1
350 jz ACM_NoFloppyGetName
351 call DriveIO_UpdateFloppyName
352 or ax, ax
353 jnz ACM_NoFloppyGetName
354 ; Try a second time, if it failed to detect the Floppy
355 call DriveIO_UpdateFloppyName
356 ACM_NoFloppyGetName:
357 ret
358AFTERCRAP_Main EndP
359
360
361; Checks Configuration CheckSum...Displays message, if failed.
362PRECRAP_CheckConfiguration Proc Near Uses ds si es di
363
364IFDEF AUX_DEBUG
365 IF 0
366 DBG_TEXT_OUT_AUX 'PRECRAP_CheckConfiguration:'
367 PUSHRF
368 ;~ call DEBUG_DumpRegisters
369 ;~ call AuxIO_DumpParagraph
370 ;~ call AuxIO_TeletypeNL
371 POPRF
372 ENDIF
373ENDIF
374
375 mov si, offset Configuration
376 xor bx, bx
377
378 ; Changed from 5 to calculated value (not here, see compat. issue below)
379 ; Fixes issue: #2987 -- "air-boot doesn't remember drive letter"
380 ; Size of the ab-configuration in 512 byte sectors
381 ; mov cx, (MBR_BackUpMBR - Configuration) / 200h
382
383 ; AB v1.07 stores a 5 sector configuration with a 5 sector checksum.
384 ; AB v1.0.8+ *should* stores a 7 sector configuration with a
385 ; 7 sector checksum.
386 ; Because 5 was hardcoded here, SET(A)BOOT v1.07 will see see an AB v1.0.8+
387 ; config as corrupted, while this is not the case.
388 ; So, for compatibility reasons, in v1.0.8+, the checksum stored is over
389 ; 5 sectors, to be compatible with v1.07.
390 ; This may change (be corrected) in future versions !
391 mov cx,5
392
393 mov dx, [CFG_CheckConfig]
394 mov [CFG_CheckConfig], bx
395 PCCC_Loop:
396 call MBR_GetCheckOfSector
397 loop PCCC_Loop
398 cmp bx, dx
399 jne PCCC_Failed
400 mov CFG_CheckConfig, dx
401 ret
402 PCCC_Failed:
403 mov si, offset TXT_ERROR_CheckConfig
404 call MBR_Teletype
405 mov si, offset TXT_ERROR_CheckFailed
406 call MBR_Teletype
407 jmp MBR_HaltSystem
408PRECRAP_CheckConfiguration EndP
409
410
411; Rousseau: added
412; In: SI - Pointer to begin of string (EOS is 0)
413; Destroyed: SI
414; Fixme: Uses double writes to use attribute with teletype-function.
415MBR_TeletypeBold Proc Near Uses ax bx cx
416 MBRT_LoopBold:
417 lodsb
418 or al, al
419 jz MBRT_EndBold
420 push ax
421 mov ah,09h
422 mov bx,15
423 mov cx,1
424 int 10h
425 pop ax
426 mov ah,0eh
427 mov bx,7 ; Does not do anything in text-modus
428 mov cx,1
429 int 10h
430 jmp MBRT_LoopBold
431 MBRT_EndBold:
432 ret
433MBR_TeletypeBold EndP
434
435
436; In: SI - Pointer to begin of string (EOS is 0)
437; Destroyed: SI
438; Fixme: Uses double writes to use attribute with teletype-function.
439MBR_TeletypeVolName Proc Near Uses ax bx cx
440 mov cx, 11
441 MBRT_LoopVolName:
442 mov dx,cx ; Backup counter
443 lodsb
444 or al, al
445 jz MBRT_EndVolName
446 push ax
447 mov ah,09h
448 mov bx,15
449 mov cx,1
450 int 10h ; DX is preserved
451 pop ax
452 mov ah,0eh
453 mov bx,7 ; Does not do anything in text-modus
454 mov cx,1
455 int 10h ; DX is preserved
456 mov cx,dx ; Restore counter
457 loop MBRT_LoopVolName
458 MBRT_EndVolName:
459 ret
460MBR_TeletypeVolName EndP
461
462; Rousseau: added
463; Move cursor to next line
464; Just do a new-line if SI==0
465MBR_TeletypeNL Proc Near Uses ax bx cx
466 test si,si
467 jz MBR_TeletypeNL_NL
468 call MBR_Teletype
469 MBR_TeletypeNL_NL:
470 push si
471 mov si, offset NL
472 call MBR_Teletype
473 pop si
474 ret
475MBR_TeletypeNL EndP
476
477; Sync teletype position to VideoIO
478MBR_TeletypeSyncPos Proc Near Uses ax bx cx dx
479 pushf
480 mov bh, 0
481 mov ah, 02h
482 mov dh,byte ptr [TextPosY]
483 mov dl,byte ptr [TextPosX]
484 int 10h
485 popf
486 ret
487MBR_TeletypeSyncPos EndP
488
489;------------------------------------------------------------------------------
490; Check if a memory block is all zeros
491;------------------------------------------------------------------------------
492; IN : BX pointer to memblock
493; : CX length to check, zero length is interpreted as block is zero
494; OUT : ZF=1 block if all zeros
495; NOTE : Segment used is DS, which should be the same as ES
496;------------------------------------------------------------------------------
497IsMemBlockZero Proc Near Uses ax di es
498 push ds ; Segment to use
499 pop es ; Pop in ES because ES is required for scasb
500 mov di, bx ; Pointer to memblock
501 xor al, al ; Compare to zero
502 cld ; Direction upwards
503 repe scasb ; Scan the block, will leave ZF=1 if all zeros
504 ret
505IsMemBlockZero EndP
506
507;------------------------------------------------------------------------------
508; Check if a loaded sector is all zeros
509;------------------------------------------------------------------------------
510; IN : SI pointer to sector buffer
511; OUT : ZF=1 block if all zeros
512; NOTE : Segment used is DS
513;------------------------------------------------------------------------------
514IsSectorBufferZero Proc Near Uses bx cx
515 mov bx, si ; Address of sector buffer
516 mov cx, sector_size ; Normal size of a sector (512 bytes)
517 call IsMemBlockZero ; Check the memory block
518 ret
519IsSectorBufferZero EndP
520
521;------------------------------------------------------------------------------
522; Fill a memory block with a specific value
523;------------------------------------------------------------------------------
524; IN : AL value to fill block with
525; : BX pointer to memblock
526; : CX length to fill, 0 fills nothing
527; OUT : ZF=1 if fill value was 0
528; NOTE : Segment used is DS
529;------------------------------------------------------------------------------
530FillMemBlock Proc Near Uses cx di es
531 push ds ; Segment to use
532 pop es ; Pop in ES because ES is required for scasb
533 mov di, bx ; Pointer to memblock
534 cld ; Direction upwards
535 rep stosb ; Fill the memory block with value in AL
536 test al, al ; Set ZR if fill value used is 0
537 ret
538FillMemBlock EndP
539
540;------------------------------------------------------------------------------
541; Fill a memory block with zeros
542;------------------------------------------------------------------------------
543; IN : BX pointer to memblock
544; : CX length to fill, 0 fills nothing
545; OUT : Nothing
546; NOTE : Segment used is DS
547;------------------------------------------------------------------------------
548ClearMemBlock Proc Near Uses ax
549 xor al, al ; Fill value
550 call FillMemBlock ; Fill the memory block
551 ret
552ClearMemBlock EndP
553
554;------------------------------------------------------------------------------
555; Clears a sector buffer
556;------------------------------------------------------------------------------
557; IN : SI pointer to sector buffer
558; OUT : Nothing
559; NOTE : Segment used is DS
560;------------------------------------------------------------------------------
561ClearSectorBuffer Proc Near Uses bx cx
562 mov bx, si ; Address of sector buffer
563 mov cx, sector_size ; Normal size of a sector (512 bytes)
564 call ClearMemBlock ; Clear the sector buffer
565 ret
566ClearSectorBuffer EndP
567
Note: See TracBrowser for help on using the repository browser.