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

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

AiR-BOOT v1.07 -- As released with eCS v2.1. [2011-05-06]
Signature-date: 2006-03-13. (incorrect)
Trunk contains buildable v1.07 version as distributed with eCS v2.1.
Directory 'tags' contains v1.06 & v1.07 reference versions
built for all languages. Note that language ID for 'Dutch' changed
from 'DT' to 'NL' in v1.07 and that the v1.06 reference version also
uses 'NL' for 'Dutch'.
Also note that helper programs like the installer and setaboot are
are only modified for the OS/2 versions in v1.07.
The signature-date for v1.07 incorrectly states the same
date as for v1.06. The signature-version is correct.
Removed other binaries. (cd-rom images, old releases, etc.)
The tags serve as reference versions:

  • v1.06: rebuilt from source. (tags/v1.06r)
  • v1.07: built as released with eCS v2.1. (tags/v1.07r)
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, image_size ; 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, image_size
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, image_size ; 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, image_size
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 image_size 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.