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

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

More hard-coded '80h' corrections [v1.1.1-testing]

Code in 'partmain.asm' around line 1350 needs some more attention.
Possibly the whole 'boot-flag' stuff is not needed with modern BIOSses.
Updating them is disabled for now, which should only affect very old
BIOSses that don't leave this checking to the MBR code.

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