source: trunk/TOOLS/INTERNAL/FIXCODE.ASM@ 29

Last change on this file since 29 was 29, checked in by Ben Rietbroek, 14 years ago

AiR-BOOT v1.06 -- Complete sourceforge mirror. (r56) [2010-02-19]
Signature-date: 2006-03-13.
Also contains binairy releases from v1.01 to v1.06, cd-rom images, etc.
If you want the whole pre v1.07 shebang, checkout this revision's trunk.
The v1.06 reference version is in 'tags/v1.06r'.
Note that this reference version uses 'NL' for 'Dutch'.

File size: 9.3 KB
Line 
1; AiR-BOOT (c) Copyright 1998-2009 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; This program fixes air-boot.com image.
20; a) it includes MBR protection image from mbr-prot\mbr_prot.com
21; b) it writes totally used sectors to byte at offset 10h in the image
22
23JUMPS
24
25Include ..\..\include\asm.inc
26; include ..\..\include\dos\airboot.inc
27
28 .386p
29 model large, basic
30
31code_seg segment public use16
32 assume cs:code_seg, ds:code_seg, es:nothing, ss:nothing
33 org 100h
34COM_StartUp: jmp COM_Init
35
36COM_Copyright db 'AiR-BOOT Bootcode Image Fix', 13, 10
37 db ' - (c) Copyright 2009 by M. Kiewitz', 13, 10, '$'
38COM_LoadCode db ' - Loading bootcode from file...$'
39COM_CodeName db 'air-boot.com', 0
40COM_LoadMBR db ' - Loading MBR-protection from file...$'
41COM_MBRName db 'mbr-prot\mbr_prot.com', 0
42COM_MergeMBR db ' - Merging MBR-protection into bootcode...$'
43COM_CountCode db ' - Count code in bootcode-image...$'
44COM_WriteCode db ' - Saving bootcode to file...$'
45COM_Okay db 'ok', 13, 10, '$'
46COM_Failed db 'failed', 13, 10, '$'
47
48COM_FailedOpenCode db 'air-boot.com not found', 13, 10, '$'
49COM_FailedReadCode db 'Read air-boot.com failed', 13, 10, '$'
50COM_FailedInvalidCode db 'Invalid air-boot.com', 13, 10, '$'
51COM_FailedOpenMBR db 'mbr-prot\mbr_prot.com not found', 13, 10, '$'
52COM_FailedReadMBR db 'Read mbr-prot\mbr_prot.com failed', 13, 10, '$'
53COM_FailedInvalidMBR db 'Invalid mbr-prot\mbr_prot.com', 13, 10, '$'
54COM_FailedWriteCode db 'Write air-boot.com failed', 13, 10, '$'
55
56MBRProtectionSignature db 'AiR-BOOT MBR-Protection Image'
57MBRProtectionSignatureLen equ 29
58
59ShowMessage Proc Near Uses ax
60 mov ah, 09h
61 int 21h ; DOS: WRITE STRING DS:DX TO CONSOLE
62 ret
63ShowMessage EndP
64
65ShowError Proc Near Uses
66 mov ah, 09h
67 int 21h ; DOS: WRITE STRING DS:DX TO CONSOLE
68 EndProgram:
69 mov ax, 4C00h
70 int 21h ; DOS: TERMINATE PROGRAM
71ShowError EndP
72
73COM_Init: mov ax, cs
74 mov ds, ax
75 mov es, ax ; CS==DS==ES
76 mov dx, offset COM_Copyright
77 call ShowMessage
78
79 ; =========================================== Load air-boot.bin
80 mov dx, offset COM_LoadCode
81 call ShowMessage
82 mov ax, 3D00h
83 mov dx, offset COM_CodeName
84 xor cl, cl
85 int 21h ; DOS: OPEN EXISTING FILE
86 jnc DoneOpenCode
87 mov dx, offset COM_FailedOpenCode
88 call ShowError
89
90DoneOpenCode: mov bx, ax ; BX = Filehandle
91
92 mov ah, 3Fh
93 mov cx, 30720 ; Image size
94 mov dx, offset BootCode
95 int 21h ; DOS: READ FILE
96 jnc DoneReadCode
97 mov dx, offset COM_FailedReadCode
98 call ShowError
99
100DoneReadCode: cmp ax, 30720
101 je DoneReadCode2
102InvalidCode: mov dx, offset COM_FailedInvalidCode
103 call ShowError
104
105DoneReadCode2: mov ah, 3Fh
106 mov cx, 1
107 mov dx, offset BootCode
108 int 21h ; DOS: READ FILE
109 jc DoneReadCode3
110 or ax, ax
111 jz DoneReadCode3 ; EOF -> is now expected
112 jmp InvalidCode
113
114DoneReadCode3: mov ah, 3Eh
115 int 21h ; DOS: CLOSE FILE
116
117 mov dx, offset COM_Okay
118 call ShowMessage
119
120 ; =================================== Load MBR-protection image
121 mov dx, offset COM_LoadMBR
122 call ShowMessage
123 mov ax, 3D00h
124 mov dx, offset COM_MBRName
125 xor cl, cl
126 int 21h ; DOS: OPEN EXISTING FILE
127 jnc DoneOpenMBR
128 mov dx, offset COM_FailedOpenMBR
129 call ShowError
130
131DoneOpenMBR: mov bx, ax ; BX = Filehandle
132
133 mov ah, 3Fh
134 mov cx, 1024 ; Image size
135 mov dx, offset MBRProtection
136 int 21h ; DOS: READ FILE
137 jnc DoneReadMBR
138 mov dx, offset COM_FailedReadMBR
139 call ShowError
140
141DoneReadMBR: cmp ax, 1024
142 je DoneReadMBR2
143InvalidMBR: mov dx, offset COM_FailedInvalidMBR
144 call ShowError
145
146DoneReadMBR2: mov ah, 3Fh
147 mov cx, 1
148 mov dx, offset MBRProtection
149 int 21h ; DOS: READ FILE
150 jc DoneReadMBR3
151 or ax, ax
152 jz DoneReadMBR3 ; EOF -> is now expected
153 jmp InvalidMBR
154
155DoneReadMBR3: mov ah, 3Eh
156 int 21h ; DOS: CLOSE FILE
157
158 mov dx, offset COM_Okay
159 call ShowMessage
160
161 ; ========================== Merge MBR-Protection into Bootcode
162 mov dx, offset COM_MergeMBR
163 call ShowMessage
164
165 ; Search for signature in Bootcode
166 mov si, offset BootCode
167 mov di, offset MBRProtectionSignature
168 mov cx, MBRProtectionSignatureLen
169 mov dx, 54 ; 54 sectors where signature may be
170COM_SignatureLoop:
171 push cx si di
172 repe cmpsb
173 pop di si cx
174 je COM_GotSignature
175 add si, 512
176 dec dx
177 jnz COM_SignatureLoop
178 mov dx, offset COM_Failed
179 call ShowMessage
180 jmp EndProgram
181
182COM_GotSignature:
183 ; Now copy MBR-protection into bootcode
184 mov di, si
185 mov si, offset MBRProtection
186 mov cx, 512
187 rep movsw
188 mov dx, offset COM_Okay
189 call ShowMessage
190
191 ; ====================== Count code sectors and adjust bootcode
192 mov dx, offset COM_CountCode
193 call ShowMessage
194
195 mov si, offset BootCode
196 add si, 512*53
197 mov cx, 256
198 mov dx, 53
199COM_CodeEndLoop:push cx si di
200COM_CodeEndLoop2:
201 cmp wptr ds:[si], 0
202 jne COM_ExitCodeEndLoop
203 add si, 2
204 dec cx
205 jnz COM_CodeEndLoop2
206COM_ExitCodeEndLoop:
207 pop di si cx
208 jne COM_FoundCodeEnd
209 sub si, 512
210 dec dx
211 jnz COM_CodeEndLoop
212 mov dx, offset COM_Failed
213 call ShowError
214
215COM_FoundCodeEnd:
216 mov [BootCode+10h], dl
217 mov dx, offset COM_Okay
218 call ShowMessage
219
220 ; ================================ Save bootcode back into file
221 mov dx, offset COM_WriteCode
222 call ShowMessage
223 mov ax, 3D02h
224 mov dx, offset COM_CodeName
225 xor cl, cl
226 int 21h ; DOS: OPEN EXISTING FILE
227 jnc DoneOpenCode2
228 mov dx, offset COM_FailedOpenCode
229 call ShowError
230
231DoneOpenCode2: mov bx, ax ; BX = Filehandle
232
233 mov ah, 40h
234 mov cx, 30720 ; Image size
235 mov dx, offset BootCode
236 int 21h ; DOS: WRITE FILE
237 jnc DoneWriteCode
238FailedWriteCode:mov dx, offset COM_FailedWriteCode
239 call ShowError
240
241DoneWriteCode: cmp ax, 30720
242 jne FailedWriteCode
243
244 mov ah, 3Eh
245 int 21h ; DOS: CLOSE FILE
246
247 mov dx, offset COM_Okay
248 call ShowMessage
249 jmp EndProgram
250
251; Buffers for files
252BootCode db 30720 dup (?)
253MBRProtection db 1024 dup (?)
254
255COM_EndOfSegment:
256
257code_seg ends
258 end COM_StartUp
Note: See TracBrowser for help on using the repository browser.