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

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

Moved the INT13X DAP to the BSS [v1.1.1-testing]

No need to have this in the image, eating up precious code-space.
The byte holding the packet size is now initialized from PRERAP.

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