Changeset 37 for trunk/TOOLS/INTERNAL/FIXCODE.ASM
- Timestamp:
- Apr 11, 2014, 8:39:07 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/TOOLS/INTERNAL/FIXCODE.ASM
r31 r37 21 21 ; b) it writes totally used sectors to byte at offset 10h in the image 22 22 23 JUMPS 24 25 Include ..\..\include\asm.inc 26 ; include ..\..\include\dos\airboot.inc 27 28 .386p 29 model large, basic 30 31 code_seg segment public use16 32 assume cs:code_seg, ds:code_seg, es:nothing, ss:nothing 23 ;JUMPS 24 25 Include ../../INCLUDE/ASM.INC 26 27 .286p 28 .model small, basic 29 30 fixcode group code_seg,bss_data 31 32 code_seg segment use16 public 'CODE' 33 ;assume cs:code_seg, ds:code_seg, es:nothing, ss:nothing 34 assume cs:fixcode, ds:fixcode, es:nothing, ss:nothing 33 35 org 100h 34 36 COM_StartUp: jmp COM_Init … … 63 65 ShowMessage EndP 64 66 65 ShowError Proc Near Uses67 ShowError Proc Near 66 68 mov ah, 09h 67 69 int 21h ; DOS: WRITE STRING DS:DX TO CONSOLE 68 EndProgram: 69 mov ax, 4C00h 70 int 21h ; DOS: TERMINATE PROGRAM 70 jmp EndProgram 71 ret 71 72 ShowError EndP 72 73 73 COM_Init: mov ax, cs 74 COM_Init: 75 ; Setup and Copyright. 76 mov ax, cs 74 77 mov ds, ax 75 78 mov es, ax ; CS==DS==ES … … 77 80 call ShowMessage 78 81 79 ; =========================================== Load air-boot.bin82 ; Open AIR-BOOT.COM 80 83 mov dx, offset COM_LoadCode 81 84 call ShowMessage … … 90 93 DoneOpenCode: mov bx, ax ; BX = Filehandle 91 94 95 ; Load AIR-BOOT.COM 92 96 mov ah, 3Fh 93 97 mov cx, image_size ; Image size … … 98 102 call ShowError 99 103 100 DoneReadCode: cmp ax, image_size 104 105 DoneReadCode: 106 ; See if at least 'image-size' is loaded. 107 cmp ax, image_size 101 108 je DoneReadCode2 102 109 InvalidCode: mov dx, offset COM_FailedInvalidCode 103 110 call ShowError 104 111 112 ; Try to read again which is expected to fail. 113 ; Otherwise image is too large. 105 114 DoneReadCode2: mov ah, 3Fh 106 115 mov cx, 1 … … 112 121 jmp InvalidCode 113 122 123 ; It's loaded now, close it. 114 124 DoneReadCode3: mov ah, 3Eh 115 125 int 21h ; DOS: CLOSE FILE … … 118 128 call ShowMessage 119 129 120 ; =================================== Load MBR-protection image130 ; Open MBR_PROT.COM 121 131 mov dx, offset COM_LoadMBR 122 132 call ShowMessage … … 131 141 DoneOpenMBR: mov bx, ax ; BX = Filehandle 132 142 143 ; Load MBR_PROT.COM 133 144 mov ah, 3Fh 134 145 mov cx, 1024 ; Image size … … 139 150 call ShowError 140 151 141 DoneReadMBR: cmp ax, 1024 152 DoneReadMBR: 153 ; See if at least 1kB is loaded. 154 cmp ax, 1024 142 155 je DoneReadMBR2 143 156 InvalidMBR: mov dx, offset COM_FailedInvalidMBR 144 157 call ShowError 145 158 159 ; Try to read again which is expected to fail. 160 ; Otherwise image is too large. 146 161 DoneReadMBR2: mov ah, 3Fh 147 162 mov cx, 1 … … 153 168 jmp InvalidMBR 154 169 170 ; It's loaded now, close file. 155 171 DoneReadMBR3: mov ah, 3Eh 156 172 int 21h ; DOS: CLOSE FILE … … 159 175 call ShowMessage 160 176 177 178 161 179 ; ========================== Merge MBR-Protection into Bootcode 162 180 mov dx, offset COM_MergeMBR … … 164 182 165 183 ; Search for signature in Bootcode 184 ; Note the search is with sector granularity. 185 ; This means the signature must be 512 bytes aligned. 166 186 mov si, offset BootCode 167 187 mov di, offset MBRProtectionSignature 168 188 mov cx, MBRProtectionSignatureLen 169 mov dx, 54 ; 54 sectors where signature may be (all sectors preceding config sector) 189 ; 54 sectors where signature may be. 190 ; (all sectors preceding config sector) 191 mov dx, 54 170 192 COM_SignatureLoop: 171 push cx si di 193 push cx 194 push si 195 push di 172 196 repe cmpsb 173 pop di si cx 197 pop di 198 pop si 199 pop cx 174 200 je COM_GotSignature 175 201 add si, 512 … … 197 223 mov cx, 256 198 224 mov dx, 53 199 COM_CodeEndLoop:push cx si di 225 COM_CodeEndLoop:push cx 226 push si 227 push di 200 228 COM_CodeEndLoop2: 201 229 cmp wptr ds:[si], 0 … … 205 233 jnz COM_CodeEndLoop2 206 234 COM_ExitCodeEndLoop: 207 pop di si cx 235 pop di 236 pop si 237 pop cx 208 238 jne COM_FoundCodeEnd 209 239 sub si, 512 … … 249 279 jmp EndProgram 250 280 281 282 EndProgram: 283 ; DOS: TERMINATE PROGRAM 284 mov ax, 4C00h 285 int 21h 286 287 288 289 COM_EndOfSegment: 290 291 code_seg ends 292 293 bss_data segment use16 public 'BSS' 251 294 ; Buffers for files 252 295 BootCode db image_size dup (?) 253 296 MBRProtection db 1024 dup (?) 254 255 COM_EndOfSegment: 256 257 code_seg ends 297 bss_data ends 298 258 299 end COM_StartUp
Note:
See TracChangeset
for help on using the changeset viewer.