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

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

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