source: trunk/TOOLS/DOS/SETABOOT/SETABOOT.ASM@ 44

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

Reworked Build Environment [2012-02-15]

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!!

Changes

o Reworked build environment
o Start made with coding FIXCODE in C
o Moved MBR protection image
o New overlap macro
o Protect type 0x35 from edit (user popup)
o Protect type 0x35 from adding to menu (user popup)
o More...
! No LVM Label change yet

Note

o Changed license to GPL v3

See file COPYING in trunk.

File size: 22.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
19JUMPS
20
21Include ../../../INCLUDE/ASM.INC
22include ../../../INCLUDE/DOS/AIRBOOT.INC
23
24 .386p
25 model large, basic
26
27code_seg segment public use16
28 assume cs:code_seg, ds:nothing, es:nothing, ss:nothing
29 org 100h
30air_boot_setup: jmp SETABOOT_Start
31
32Introduction: db 'SETABOOT - AiR-BOOT Configuration Utility (DOS) - (c) 2004-2009 by M. Kiewitz',13,10
33 db 0
34
35
36TXT_SYNTAX_Show db 'Syntax:', 13, 10
37 db ' SETABOOT [/T:x or /T:NO][/B][/IBA:name]', 13, 10
38 db 'where the parameters are:', 13, 10
39 db ' T:x Sets timeout value to x seconds.', 13, 10
40 db ' T:NO Disables timeout.', 13, 10
41 db ' B Restarts the system.', 13, 10
42 db ' IBA:name Restarts the system and automatically boot from partition/volume', 13, 10
43 db ' specified as "name".', 13, 10
44 db 0
45
46TXT_ERROR_IO db 'Could not access harddrive', 13, 10, 0
47TXT_ERROR_NoBootManager db 'SETABOOT: AiR-BOOT is not installed.', 13, 10, 0
48TXT_ERROR_CodeDamaged db 'SETABOOT: AiR-BOOT Code damaged!', 13, 10, 0
49TXT_ERROR_ConfigDamaged db 'SETABOOT: AiR-BOOT Config damaged!', 13, 10, 0
50TXT_ERROR_BadParm db 'SETABOOT: Bad parameter', 13, 10, 0
51TXT_ERROR_PartNotFound db 'SETABOOT: Partition not found in IPT.', 13, 10, 0
52TXT_ERROR_AnyRequired db 'SETABOOT: AiR-BOOT required for this feature.', 13, 10, 0
53TXT_ERROR_094required db 'SETABOOT: AiR-BOOT v0.94 required for this feature.', 13, 10, 0
54TXT_ERROR_PwdProtected db 'SETABOOT: This feature needs password protection to be off.', 13, 10, 0
55TXT_ERROR_NotBootable db 'SETABOOT: Partition not set bootable.', 13, 10, 0
56TXT_ConfigUpdated db 'SETABOOT: Configuration updated!', 13, 10, 0
57TXT_NowRebooting db 'SETABOOT: Now rebooting system...', 13, 10, 0
58
59TXT_AiRBOOTdetected db 'SETABOOT: AiR-BOOT ', 0
60 db ' detected.', 13, 10, 0
61
62 Include ../../../INCLUDE/DOS/CONST.ASM
63
64AiRBOOTdetected db 0
65
66DoSetTimer db 0 ; /T:xx
67DoSetTimerValue db 0
68DoUnSetTimer db 0 ; /T:NO
69DoReboot db 0 ; /B
70DoDirectBoot db 0 ; /IBA:xx
71DoDirectBootPart db 0
72
73SETABOOT_Start: mov ax, cs
74 mov ds, ax
75 mov es, ax ; DS==ES==CS
76 ; Show Introduction message
77 mov si, offset Introduction
78 call MBR_Teletype
79
80 mov ax, cs
81 mov es, ax
82 mov bx, offset TrackZero
83 mov dx, 0080h ; First harddrive, Sector 1
84 mov cx, 0001h
85 mov ax, 023Bh ; Read 59 sectors
86 int 13h
87 jnc LoadTrackZero_NoError
88 mov si, offset TXT_ERROR_IO
89 call MBR_Teletype
90 jmp GoByeBye
91 LoadTrackZero_NoError:
92 ; Check Master-Boot-Record Signature
93 cmp wptr ds:[TrackZero+01FEh], 0AA55h
94 jne CmdLine_Analyse
95 mov si, offset MBR_AiRBOOTCodeSig
96 mov di, offset TrackZero+2
97 mov cx, MBR_AiRBOOTCodeSigLen
98 repe cmpsb
99 jne CmdLine_Analyse
100 ; We found AiR-BOOT signature, so check if code is intact...
101 movzx cx, bptr ds:[TrackZero+10h]
102 ; CX - Total-Code-Sectors-Used
103 ; Now start at Sector 2 (Code-Image)...
104 mov si, offset TrackZero+512
105 xor bx, bx
106 CheckCode_CheckSumLoop:
107 call MBR_GetCheckOfSector
108 loop CheckCode_CheckSumLoop
109 cmp bx, wptr ds:[TrackZero+11h]
110 jne AiRBOOTCodeCorrupt
111 ; We found AiR-BOOT code that is intact
112 mov ax, wptr ds:[TrackZero+0Dh]
113 mov InstalledVersion_Code, ax
114 ; Check, if Track-Zero also contains Config-Image
115 mov si, offset MBR_AiRBOOTConfigSig
116 mov di, offset TrackZero+6C00h
117 mov cx, MBR_AiRBOOTConfigSigLen
118 repe cmpsb
119 jne AiRBOOTConfigCorrupt
120 ; We found AiR-BOOT CONFIG signature, so check if config okay...
121 mov si, offset TrackZero+6C00h
122 mov dx, wptr ds:[si+20]
123 mov wptr ds:[si+20], 0
124 ; Save Config-Checksum in DX and kill it in [TrackZero]
125 xor bx, bx
126 mov cx, 5 ; Total of 5 sectors
127 CheckConfig_CheckSumLoop:
128 call MBR_GetCheckOfSector
129 loop CheckConfig_CheckSumLoop
130 cmp bx, dx
131 jne AiRBOOTConfigCorrupt
132 mov ax, wptr ds:[TrackZero+6C0Dh]
133 mov InstalledVersion_Config, ax
134 jmp AiRBOOTfound
135
136 AiRBOOTnotFound:
137 mov si, offset TXT_ERROR_NoBootManager
138 call MBR_Teletype
139 jmp GoByeBye
140 AiRBOOTCodeCorrupt:
141 mov si, offset TXT_ERROR_CodeDamaged
142 call MBR_Teletype
143 jmp GoByeBye
144 AiRBOOTConfigCorrupt:
145 mov si, offset TXT_ERROR_ConfigDamaged
146 call MBR_Teletype
147 jmp GoByeBye
148
149 ; We found 100% INTACT AiR-BOOT...
150 AiRBOOTfound:
151 mov AiRBOOTdetected, 1
152 mov si, offset TXT_AiRBOOTdetected
153 call MBR_Teletype
154 mov ax, InstalledVersion_Code
155 call MBR_TeletypeNumber
156 mov al, '.'
157 call MBR_TeletypeSingle
158 mov al, ah
159 call MBR_TeletypeNumber2
160 ; Now finish sentence ("detected")
161 call MBR_Teletype
162
163 CmdLine_Analyse:
164 ; We now analyse the commandline...
165 mov ah, 62h
166 int 21h ; GET CURRENT PSP (into BX)
167 push es
168 mov es, bx ; ES points now to PSP-Segment
169 movzx cx, es:[80h] ; CX - Length of Command-Line
170 or cx, cx
171 jz CmdLine_Done
172 mov di, 81h ; Start at that position
173 CmdLine_Loop:
174 cmp bptr es:[di], '/'
175 jne CmdLine_NextChar
176 ; Found a delimiter
177 inc di
178 dec cx
179 jz CmdLine_Done
180 mov al, bptr es:[di] ; AL - Char that follows '/'
181 cmp al, '?'
182 je CmdLine_ShowSyntax
183 and al, 0DFh ; Upcase AL
184 cmp al, 'T'
185 je CmdLine_SetTimeout
186 cmp al, 'B'
187 je CmdLine_Reboot
188 cmp al, 'I'
189 je CmdLine_RebootTo
190 CmdLine_NextChar:
191 inc di
192 loop CmdLine_Loop
193 jmp CmdLine_Done
194
195 CmdLine_ShowSyntax:
196 mov si, offset TXT_SYNTAX_Show
197 call MBR_Teletype
198 jmp GoByeBye
199
200 CmdLine_SetTimeout:
201 cmp AiRBOOTdetected, 1
202 je CmdLine_SetTimeoutGo
203 mov si, offset TXT_ERROR_AnyRequired
204 call MBR_Teletype
205 jmp GoByeBye
206 CmdLine_SetTimeoutGo:
207 inc di
208 dec cx
209 jz CmdLine_BadParm
210 cmp bptr es:[di], ':'
211 jne CmdLine_BadParm
212 inc di
213 dec cx
214 jz CmdLine_BadParm
215 ; Now get number or 'NO' for disabling timer
216 mov dl, bptr es:[di]
217 cmp dl, '0'
218 jb CmdLine_BadParm
219 cmp dl, '9'
220 jbe CmdLine_SetTimeoutNumber
221 cmp dl, 'N'
222 jne CmdLine_BadParm
223 ; We expect that 'N' to get followed by 'O' -> 'NO'
224 inc di
225 dec cx
226 jz CmdLine_BadParm
227 cmp bptr es:[di], 'O'
228 jne CmdLine_BadParm
229 ; We actually disable Timed-Boot
230 mov DoUnSetTimer, 1
231 jmp CmdLine_NextChar
232
233 ; We expect this to be a number (0-255)
234 CmdLine_SetTimeoutNumber:
235 mov DoSetTimer, 1
236 xor ax, ax
237 mov bx, 10
238 CmdLine_SetTimeoutNumberLoop:
239 ; we definitely got a number in DL
240 sub dl, '0' ; Make 0 out of '0'
241 mul bl ; AX = AL * 10
242 add al, dl
243 adc ah, 0 ; Add the number to AX
244 ; Now get next byte if available
245 inc di
246 dec cx ; No more left, so we are done!
247 jz CmdLine_SetTimeoutNumberDone
248 mov dl, bptr es:[di]
249 cmp dl, ' ' ; Followed by space? -> Done!
250 je CmdLine_SetTimeoutNumberDone
251 cmp dl, '0'
252 jb CmdLine_BadParm
253 cmp dl, '9'
254 ja CmdLine_BadParm
255 jmp CmdLine_SetTimeoutNumberLoop
256 CmdLine_SetTimeoutNumberDone:
257 cmp ax, 255
258 ja CmdLine_BadParm
259 mov DoSetTimerValue, al
260 or cx, cx ; Nothing left on commandline? -> Done
261 jz CmdLine_Done
262 jmp CmdLine_NextChar
263
264 CmdLine_Reboot:
265 mov DoReboot, 1
266 jmp CmdLine_NextChar
267
268 CmdLine_RebootTo:
269 cmp AiRBOOTdetected, 1
270 jne CmdLine_RebootToAiRBOOTrequired
271 mov ax, InstalledVersion_Code
272 xchg ah, al
273 cmp ax, 094h
274 jae CmdLine_RebootToVersionOkay
275 CmdLine_RebootToAiRBOOTrequired:
276 mov si, offset TXT_ERROR_094required
277 call MBR_Teletype
278 jmp GoByeBye
279 CmdLine_RebootToVersionOkay:
280 ; Check, if PasswordSystem:BYTE or PasswordedChngBoot:BYTE
281 ; is active. We don't allow automatic boot on passworded
282 ; systems.
283 cmp wptr ds:[TrackZero+6C00h+37], 0
284 je CmdLine_RebootToNoPassword
285 mov si, offset TXT_ERROR_PwdProtected
286 call MBR_Teletype
287 jmp GoByeBye
288 CmdLine_RebootToNoPassword:
289 mov DoDirectBoot, 1
290 mov DoReboot, 1
291 cmp cx, 5 ; We need at least 4 more chars
292 jb CmdLine_BadParm
293 mov ax, wptr es:[di+1]
294 and ax, 0DFDFh ; Upcase AX
295 cmp ax, 'AB'
296 jne CmdLine_BadParm
297 cmp bptr es:[di+3], ':'
298 jne CmdLine_BadParm
299 add di, 4
300 sub cx, 4
301 ; We now need to extract the partition/volume name and
302 ; compare it to IPT entries...
303 ; First we will check, if there is a '"' in front. If that's
304 ; the case, we look for an ending '"'. Otherwise till ' '/EOL
305 mov al, ' '
306 cmp bptr es:[di], '"'
307 jne CmdLine_RebootToExtractName
308 mov al, '"'
309 inc di
310 dec cx
311 jz CmdLine_BadParm
312 CmdLine_RebootToExtractName:
313 ; AL is ending character to look for (or EOL)
314 mov si, di ; Save start of name
315 push cx
316 CmdLine_RebootToExtractNameLoop:
317 cmp bptr es:[di], al
318 je CmdLine_RebootToExtractNameDone
319 inc di
320 dec cx
321 jnz CmdLine_RebootToExtractNameLoop
322 CmdLine_RebootToExtractNameDone:
323 pop cx
324 mov bx, di
325 sub bx, si ; SI (BX) -> Partition/Volume Name
326 or bx, bx
327 jz CmdLine_BadParm ; If Length==0 -> Bad parameter
328 cmp al, '"' ; Skip over '"', if not already at EOS
329 jne CmdLine_RebootToNoFixup
330 or cx, cx
331 jz CmdLine_RebootToNoFixup
332 inc di
333 dec cx
334 CmdLine_RebootToNoFixup:
335 cmp bx, 11
336 jbe CmdLine_RebootToLengthFine
337 mov bx, 11 ; Maximum 11 chars
338 CmdLine_RebootToLengthFine:
339 ; Now we compare that name to the names in our IPT
340 ; SI will keep pointing to partition/volume name to search for
341 ; DI will point to IPT-entry (PartitionName-Item)
342 ; BX contains length of name to search for
343 ; DL holds total IPT entries to go
344 ; DH holds current partition number (base 0)
345 push cx
346 push es
347 push di
348 mov ax, ds
349 mov es, ax ; ES == DS for now
350 movzx dx, bptr [TrackZero+6C00h+22] ; [Partition count]
351 or dl, dl
352 jz CmdLine_RebootToNotFound
353 mov di, offset TrackZero+6E00h ; Starting at sector 56
354 CmdLine_RebootToSearchLoop:
355 push si
356 push di
357 add di, 4 ; Seek to "PartitionName" item
358 mov cx, bx
359 rep cmpsb
360 pop di
361 pop si
362 je CmdLine_RebootToSearchDone
363 add di, 34 ; Length of IPT entry
364 inc dh ; Partition number +1
365 dec dl ; One partition less to look for
366 jnz CmdLine_RebootToSearchLoop
367 CmdLine_RebootToSearchDone:
368 mov bl, ds:[di+17] ; Get "Flags"
369 pop di
370 pop es
371 pop cx
372 or dl, dl ; If no partitions left -> not found
373 jz CmdLine_RebootToNotFound
374 test bl, 1b ; Check, if that's bootable
375 jz CmdLine_RebootToNotBootable
376 ; Remember partition number for later
377 mov DoDirectBootPart, dh
378 or cx, cx ; Nothing left on commandline? -> Done
379 jz CmdLine_Done
380 jmp CmdLine_NextChar
381 CmdLine_RebootToNotFound:
382 mov si, offset TXT_ERROR_PartNotFound
383 call MBR_Teletype
384 jmp GoByeBye
385 CmdLine_RebootToNotBootable:
386 mov si, offset TXT_ERROR_NotBootable
387 call MBR_Teletype
388 jmp GoByeBye
389
390 CmdLine_BadParm:
391 mov si, offset TXT_ERROR_BadParm
392 call MBR_Teletype
393 jmp GoByeBye
394
395 CmdLine_Done:
396 ; Set ES back again to DS
397 mov ax, ds
398 mov es, ax
399
400 mov dl, 1 ; DL shows if anything was changed
401
402 test DoSetTimer, 1
403 jz NoSetTimer
404 mov al, DoSetTimerValue
405 or al, al
406 jz SetTimerDisableBootmenu
407 ; Set Value [TimedBoot:BYTE] to 1 to enable Timed Boot
408 mov bptr ds:[TrackZero+6C00h+26], 1
409 ; Set Value [TimedSeconds:BYTE]
410 mov bptr ds:[TrackZero+6C00h+27], al
411 jmp DoneSetTimer
412 SetTimerDisableBootmenu:
413 ; Set Value [BootMenuActive:BYTE] to 0 to disable boot menu
414 mov bptr ds:[TrackZero+6C00h+34], 0
415 DoneSetTimer:
416 xor dl, dl
417 NoSetTimer:
418
419 test DoUnSetTimer, 1
420 jz NoUnSetTimer
421 ; Set Value [TimedBoot:BYTE] to 0 to disable Timed Boot
422 mov bptr ds:[TrackZero+6C00h+26], 0
423 xor dl, dl
424 NoUnSetTimer:
425
426 test DoDirectBoot, 1
427 jz NoDirectBoot
428 ; Set Value [AutomaticBoot:BYTE] to 1 to enable direct boot
429 mov bptr ds:[TrackZero+6C00h+170], 1
430 mov al, DoDirectBootPart
431 ; Set Value [AutomaticPartition:BYTE] to selection
432 mov bptr ds:[TrackZero+6C00h+171], al
433 xor dl, dl
434 NoDirectBoot:
435
436 or dl, dl
437 jnz NothingChanged
438 ; Save configuration here...
439 ; Update counter first...
440 add wptr ds:[TrackZero+6C00h+16], 1
441 adc wptr ds:[TrackZero+6C00h+18], 0
442 ; Now update checksum...
443 mov si, offset TrackZero+6C00h
444 ; Save Config-Checksum in DX and kill it in [TrackZero]
445 xor bx, bx
446 mov cx, 5 ; Total of 5 sectors
447 push si
448 SaveConfig_CheckSumLoop:
449 call MBR_GetCheckOfSector
450 loop SaveConfig_CheckSumLoop
451 pop si
452 mov wptr ds:[si+20], bx
453 mov ax, cs
454 mov es, ax ; Make sure that ES is right
455 mov bx, si
456 mov dx, 0080h ; First harddrive, Sector 55...
457 mov cx, 0037h
458 mov ax, 0305h ; Function 03, 5 sectors to write
459 int 13h
460 jnc ConfigUpdated
461 mov si, offset TXT_ERROR_IO
462 call MBR_Teletype
463 jmp GoByeBye
464 ConfigUpdated:
465 mov si, offset TXT_ConfigUpdated
466 call MBR_Teletype
467 NothingChanged:
468
469 test DoReboot, 1
470 jz NoReboot
471 mov si, offset TXT_NowRebooting
472 call MBR_Teletype
473 mov ax, 8600h
474 mov cx, 65
475 xor dx, dx
476 int 15h ; Wait a little bit...
477 db 0EAh ; Jump to eternity
478 dw 0FFF0h
479 dw 0F000h
480 NoReboot:
481
482GoByeBye: mov ax, 4C00h
483 int 21h ; Terminate us...
484 ; End-Of-Code
485
486; In: BX - Base Check, DS:SI - Pointer to 512-byte-area to be included
487; Out: BX - Base Check Result
488; Destroyed: SI will get updated (+512)
489MBR_GetCheckOfSector Proc Near Uses ax cx
490 mov cx, 256
491 MBR_GetCheckOfSector_Loop:
492 lodsw
493 xor ax, 0BABEh
494 xor bx, ax
495 loop MBR_GetCheckOfSector_Loop
496 or bx, bx
497 jnz MBR_GetCheckOfSector_NoFixUp
498 mov bx, 1 ; dont allow 0, cause 0 means "empty"
499 MBR_GetCheckOfSector_NoFixUp:
500 ret
501MBR_GetCheckOfSector EndP
502
503; In: SI - Pointer to begin of string (EOS is 0)
504; Destroyed: SI
505MBR_Teletype Proc Near Uses ax bx cx
506 mov ah, 0Eh
507 mov bx, 7
508 MBR_Teletype_Loop:
509 lodsb
510 or al, al
511 jz MBR_Teletype_End
512 int 10h
513 jmp MBR_Teletype_Loop
514 MBR_Teletype_End:
515 ret
516MBR_Teletype EndP
517
518; In: AL - Single char to type to screen
519; Destroyed: *nothing*
520MBR_TeletypeSingle Proc Near Uses ax bx
521 mov ah, 0Eh
522 mov bx, 7
523 int 10h
524 ret
525MBR_TeletypeSingle EndP
526
527; In: AL - BCD-number to type to screen
528; Destroyed: *nothing*
529MBR_TeletypeNumber Proc Near Uses ax bx
530 mov ah, al
531 and ah, 0Fh
532 shr al, 4
533 add ax, 3030h
534 cmp al, 30h
535 je MBR_TTN_SkipDigit
536 call MBR_TeletypeSingle
537 MBR_TTN_SkipDigit:
538 mov al, ah
539 call MBR_TeletypeSingle
540 ret
541MBR_TeletypeNumber EndP
542
543; In: AL - BCD-number to type to screen (full 2 digits everytime)
544; Destroyed: *nothing*
545MBR_TeletypeNumber2 Proc Near Uses ax bx
546 mov ah, al
547 and ah, 0Fh
548 shr al, 4
549 add ax, 3030h
550 call MBR_TeletypeSingle
551 mov al, ah
552 call MBR_TeletypeSingle
553 ret
554MBR_TeletypeNumber2 EndP
555
556InstalledVersion_Code dw ?
557InstalledVersion_Config dw ?
558TrackZero: db 30976 dup (?)
559
560code_seg ends
561 end air_boot_setup
Note: See TracBrowser for help on using the repository browser.