source: trunk/BOOTCODE/REGULAR/OTHER.ASM@ 44

Last change on this file since 44 was 43, checked in by Ben Rietbroek, 12 years ago

BSS Corruption Problem located (auxdebug on) [2012-02-21]

WARNING!!

All commits upto and including the commit of [2012-05-13] contain
a severe bug!! Building from these sources and then disabling
the 'force LBA' feature while also using the drive-letter feature or
editing the label can DESTROY THE MBR on ALL ATTACHED DISKS!!
DO NOT DISABLE 'FORCE LBA USAGE' WHEN BUILT FROM THE THESE COMMITS!!

Problem

o Function with Xrefs goes out-of-bounds because hideparttable is too small

Has only 30 entries and should be 45.
Lost partition checker initializes out-of-bounds.

Info

o About the hideparttable

For each partition it can be specified which other partitions need to
be hidden when that partition is booted. This is useful for legacy DOS
but also braindead Windows that presents HPFS/JFS partitions as
unformatted and tries to persuade the user to format them.
With v1.07 the numer of partitions that can be handled was expanded from
30 to 45, but the size of the hideparttable was overseen.

o The need to compress the hideparttable

The old size was 30x30=900 bytes while the required size is 45x45=2045 bytes.
This amount of space is not available in the image.
Since 6 bits are enough to identify the partition number to be hidden,
the solution is to devide the table into bitfields. This will result
in a table of (45*45*6)/8=1519 bytes, which can be fitted.

Changes

Revamped the sources quite a bit and moved the history to a separate
file. (AIR-BOOT.HIS)

New

o FIXCODE script for Linux

Just until the C version is ready...

File size: 14.5 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 ModuleNames
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
84PRECRAP_Main Proc Near
85 ; First initialize Variable-Area (everything with NUL)
86 ; We use the start instead of the variables because they could be 'orged'
87 ; to an offset. We want everything after the code to be nullified.
88 mov di, offset sobss
89 mov cx, offset EndOfVariables-offset BeginOfVariables
90 xor ax, ax
91 shr cx, 1
92 inc cx
93 rep stosw
94
95 mov VideoIO_Segment, VideoIO_Page0
96
97 ; Don't use blinking attribute
98 call VideoIO_NoBlinking
99
100 ; Get HardDriveCount
101 call DriveIO_GetHardDriveCount
102
103
104 ; Rousseau: added
105 call VideoIO_ClearScreen
106
107 ; Cursor to upper-left
108 mov TextPosX, 0
109 mov TextPosY, 0
110 call VideoIO_CursorSet
111
112 ;~ mov ax, VideoIO_Page1
113 ;~ call VideoIO_BackUpTo ; Copy BIOS POST to Second Page
114
115 ; Copyright
116 mov si, offset Copyright
117 call MBR_Teletype
118 xor si,si
119 call MBR_TeletypeNL
120
121
122 ;call SOUND_Beep
123
124 ; Build Date
125 mov si, offset BUILD_DATE
126 call MBR_TeletypeNL
127
128 IFDEF AUX_DEBUG
129 ; Initialize the com-port for debugging
130 call AuxIO_Init
131 ENDIF
132
133 xor si,si
134 call MBR_TeletypeNL
135
136 xor cx,cx
137 PRECRAP_Main_next_disk:
138
139 mov dl,cl
140 or dl,80h
141
142 ;
143 ; This also setup the size of the i13xbuf.
144 ;
145 call DriveIO_GatherDiskInfo ; Also used to fill the geo, should be separate function
146
147 mov bx,offset HugeDisk
148 add bx,cx
149 mov [bx], al
150
151 call DriveIO_LoadMasterLVMSector ; returns NC if no valid LVM record found
152
153 pushf
154
155 ;~ mov al,'#'
156 ;~ pushf
157 ;~ call VideoIO_PrintSingleChar
158 ;~ popf
159 ;~ mov al,0
160 ;~ rcl al,1
161 ;~ call VideoIO_PrintHexByte
162 ;~ mov al,'#'
163 ;~ call VideoIO_PrintSingleChar
164
165 mov bx, offset TrueSecs
166 add bx,cx
167 add bx,cx
168 add bx,cx
169 add bx,cx
170 popf
171
172 ; bx now contains pointer to truesecs for this drive
173
174 jnc NoValidMasterLVM
175
176 ; ?? 3f bij disk 80h maar 0 bij disk 81h
177 mov si,offset LVMSector
178 mov ax,[si+LocLVM_Secs]
179
180 ;~ pusha
181 ;~ mov dx,ax
182 ;~ mov al,'%'
183 ;~ call VideoIO_PrintSingleChar
184 ;~ mov ax,dx
185 ;~ call VideoIO_PrintHexWord
186 ;~ mov al,'%'
187 ;~ call VideoIO_PrintSingleChar
188 ;~ popa
189
190 mov word ptr [bx],ax
191 jmp SkipUseBiosSecs
192
193
194 NoValidMasterLVM:
195 push bx ; push truesecs pointer
196 mov bx, offset BIOS_Secs
197 add bx,cx
198 add bx,cx
199 add bx,cx
200 add bx,cx
201
202 mov ax,[bx] ; get biossecs
203 pop bx
204 mov word ptr [bx],ax ; store bios secs in truesecs
205
206
207 SkipUseBiosSecs:
208 inc cx
209 cmp cl,[TotalHarddiscs]
210 jb PRECRAP_Main_next_disk
211
212
213
214 IFDEF AUX_DEBUG
215 ; Write some debug-info to the com-port
216 call DEBUG_Dump1
217 ENDIF
218
219 ;~ jz NoValidMasterLVM
220;~
221 ;~ ; A valid Master LVM has been found.
222 ;~ ; We use the values in here to determine the number of sectors per track,
223 ;~ ; since this could be OS/2 extended geometry.
224;~
225 ;~ jmp Continue1
226 ;~
227 ;~ mov word ptr [LOG_Secs],63
228
229; mov al,[HugeDisk] ;; fout, moet nog index bij
230; call AuxIO_TeletypeHexByte
231; call AuxIO_TeletypeNL
232
233; mov ax,word ptr [TrueSecs] ;; fout, moet nog index bij
234; call AuxIO_TeletypeHexWord
235; call AuxIO_TeletypeNL
236
237
238
239 ; Huge Disk indicator
240 mov si, offset HugeBootDisk
241 call MBR_Teletype
242 mov al,[HugeDisk]
243 mov si, offset No
244 test al,al
245 jz MBR_HugeDriveIndicator
246 mov si, offset Yes
247
248 MBR_HugeDriveIndicator:
249 call MBR_Teletype
250 xor si,si
251 call MBR_TeletypeNL
252
253
254 ;
255 ; Phase 1 Indicator
256 ;
257 mov si, offset Phase1
258 call MBR_Teletype
259
260 mov si, offset eCS_InstallVolume
261 mov al, [si]
262 test al,al ; See if phase 1 is active
263 jnz MBR_Main_BootThrough
264 mov si, offset NotActive
265
266 MBR_Main_BootThrough:
267 call MBR_Teletype
268 xor si,si
269 call MBR_TeletypeNL
270
271
272 ; Calculate Cooper-Bar Tables
273 call FX_CalculateTables
274
275 ; Calculate LVM-CRC-Table
276 call LVM_InitCRCTable
277
278 ; Get HardDriveCount
279 call DriveIO_GetHardDriveCount
280
281 ; Calculate CHS/LBA Switch Table
282 call DriveIO_InitLBASwitchTable
283
284 ; Setup PartitionPointers-Table
285 call PART_CalculateStraightPartPointers
286
287 ; Setup Cyrillic Charset, if needed
288 IFDEF TXT_IncludeCyrillic
289 call CHARSET_IncludeCyrillic
290 ENDIF
291
292
293 ; This sets [CurIO_UseExtension] flag.
294 call PRECRAP_CheckFor13extensions
295
296 IFNDEF ReleaseCode
297 ret
298 ENDIF
299
300
301 call PRECRAP_CheckConfiguration
302
303
304 ; =======================================
305 ; Checks for MBR Virii :) I love that job
306 ; =======================================
307 test CFG_DetectStealth, 1
308 jz PCM_NoStealthDetection
309 call VIRUS_CheckForStealth
310 PCM_NoStealthDetection:
311 test CFG_DetectVirus, 1
312 jz PCM_NoVirusDetection
313 call VIRUS_CheckForVirus
314 PCM_NoVirusDetection:
315
316
317 ; ============================================
318 ; Delay for some time and get Strg/Alt State
319 ; ============================================
320 test CFG_CooperBars, 1
321 jnz PCM_ShortDelay
322 mov al, 27 ; About 1.5 seconds
323 test CFG_FloppyBootGetName, 1
324 jz PCM_LongDelay
325 PCM_ShortDelay:
326
327 mov al, 13 ; shorten delay,if floppy gets accessed
328 PCM_LongDelay:
329
330 call TIMER_WaitTicCount
331
332 ; First check, if any normal key got pressed...
333 mov ah, 1
334 int 16h
335 jz PCM_NoNormalKeyPressed
336 ; User doesn't know what to do...or he is crazy <g> so display message
337 mov si, offset TXT_HowEnterSetup
338 call MBR_Teletype
339 mov al, 54 ; about 3 seconds, delay again
340
341 call TIMER_WaitTicCount
342
343 PCM_NoNormalKeyPressed:
344 ; Now get keyboard Strg/Alt State
345 mov ah, 02h
346 int 16h
347 mov SETUP_KeysOnEntry, al
348
349 ; Copy device-name to the ContBIOSbootSeq-IPT entry
350 ; We may not do this before PRECRAP_CheckConfiguration, because otherwise
351 ; this check will fail.
352 call PART_UpdateResumeBIOSName
353 ret
354PRECRAP_Main EndP
355
356AFTERCRAP_Main Proc Near
357 ; ===================================================
358 ; Now get volume label of FloppyDrive, if wanted...
359 ; ===================================================
360 test CFG_FloppyBootGetName, 1
361 jz ACM_NoFloppyGetName
362 call DriveIO_UpdateFloppyName
363 or ax, ax
364 jnz ACM_NoFloppyGetName
365 ; Try a second time, if it failed to detect the Floppy
366 call DriveIO_UpdateFloppyName
367 ACM_NoFloppyGetName:
368 ret
369AFTERCRAP_Main EndP
370
371PRECRAP_CheckFor13extensions Proc Near
372 mov ah, 41h
373 mov bx, 55AAh
374 mov dl, 80h
375 int 13h
376 cmp bx, 0AA55h
377 je PCCF13E_Found
378 PCCF13E_NotFound:
379 ret
380 PCCF13E_Found:
381 and cx, 1
382 jz PCCF13E_NotFound
383 mov CurIO_UseExtension, 1
384 ret
385PRECRAP_CheckFor13extensions EndP
386
387
388; Checks Configuration CheckSum...Displays message, if failed.
389PRECRAP_CheckConfiguration Proc Near Uses ds si es di
390 mov si, offset Configuration
391 xor bx, bx
392
393 ; Changed from 5 to calculated value (not here, see compat. issue below)
394 ; Fixes issue: #2987 -- "air-boot doesn't remember drive letter"
395 ; Size of the ab-configuration in 512 byte sectors
396 ; mov cx, (MBR_BackUpMBR - Configuration) / 200h
397
398 ; AB v1.07 stores a 5 sector configuration with a 5 sector checksum.
399 ; AB v1.0.8 *should* stores a 7 sector configuration with a
400 ; 7 sector checksum.
401 ; Because 5 was hardcoded here, SET(A)BOOT v1.07 will see see an AB v1.0.8
402 ; config as corrupted, while this is not the case.
403 ; So, for compatibility reasons, in v1.0.8, the checksum stored is over
404 ; 5 sectors, to be compatible with v1.07.
405 ; This may change (be corrected) in future versions !
406 mov cx,5
407
408 mov dx, CFG_CheckConfig
409 mov CFG_CheckConfig, bx
410 PCCC_Loop:
411 call MBR_GetCheckOfSector
412 loop PCCC_Loop
413 cmp bx, dx
414 jne PCCC_Failed
415 mov CFG_CheckConfig, dx
416 ret
417 PCCC_Failed:
418 mov si, offset TXT_ERROR_CheckConfig
419 call MBR_Teletype
420 mov si, offset TXT_ERROR_CheckFailed
421 call MBR_Teletype
422 jmp MBR_HaltSystem
423PRECRAP_CheckConfiguration EndP
424
425
426; Rousseau: added
427; In: SI - Pointer to begin of string (EOS is 0)
428; Destroyed: SI
429; Fixme: Uses double writes to use attribute with teletype-function.
430MBR_TeletypeBold Proc Near Uses ax bx cx
431 MBRT_LoopBold:
432 lodsb
433 or al, al
434 jz MBRT_EndBold
435 push ax
436 mov ah,09h
437 mov bx,15
438 mov cx,1
439 int 10h
440 pop ax
441 mov ah,0eh
442 mov bx,7 ; Does not do anything in text-modus
443 mov cx,1
444 int 10h
445 jmp MBRT_LoopBold
446 MBRT_EndBold:
447 ret
448MBR_TeletypeBold EndP
449
450
451; In: SI - Pointer to begin of string (EOS is 0)
452; Destroyed: SI
453; Fixme: Uses double writes to use attribute with teletype-function.
454MBR_TeletypeVolName Proc Near Uses ax bx cx
455 mov cx, 11
456 MBRT_LoopVolName:
457 mov dx,cx ; Backup counter
458 lodsb
459 or al, al
460 jz MBRT_EndVolName
461 push ax
462 mov ah,09h
463 mov bx,15
464 mov cx,1
465 int 10h ; DX is preserved
466 pop ax
467 mov ah,0eh
468 mov bx,7 ; Does not do anything in text-modus
469 mov cx,1
470 int 10h ; DX is preserved
471 mov cx,dx ; Restore counter
472 loop MBRT_LoopVolName
473 MBRT_EndVolName:
474 ret
475MBR_TeletypeVolName EndP
476
477; Rousseau: added
478; Move cursor to next line
479; Just do a new-line if SI==0
480MBR_TeletypeNL Proc Near Uses ax bx cx
481 test si,si
482 jz MBR_TeletypeNL_NL
483 call MBR_Teletype
484 MBR_TeletypeNL_NL:
485 push si
486 mov si, offset NL
487 call MBR_Teletype
488 pop si
489 ret
490MBR_TeletypeNL EndP
491
492; Sync teletype position to VideoIO
493MBR_TeletypeSyncPos Proc Near Uses ax bx cx dx
494 pushf
495 mov bh, 0
496 mov ah, 02h
497 mov dh,[TextPosY]
498 mov dl,[TextPosX]
499 int 10h
500 popf
501 ret
502MBR_TeletypeSyncPos EndP
Note: See TracBrowser for help on using the repository browser.