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

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

Moved the clearing of BSS variables to an earlier stage [v1.1.1-testing]

When debugging, we want 'AuxIO' available before 'PRECRAP'.

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