wok view syslinux/stuff/iso2exe/bootiso.S @ rev 17591

syslinux/isohybrib.exe: add --md5, --undo
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 10 08:53:27 2015 +0100 (2015-02-10)
parents 26654c1a7ca7
children 6a2e6eb35735
line source
1 .text
2 .code16
3 .org 0
5 CODESZ = 0x8000 // 16 sectors = 32Kb
6 #define EXEADRS(x) x+0xC0
7 #define EXELOC(x) x-0x40
8 #define EXESTR(x) x-0x7F40
10 .globl _start
11 _start:
12 decw %bp // Magic number: MZ
13 popw %dx
14 jmp start0 // Bytes on last page of file
15 .word (CODESZ+511)/512 // Pages in file
16 .word 0 // Relocations
17 .word (end_header-_start)/16 // Size of header in paragraphs
18 .word 4064-(CODESZ/16) // Minimum extra paragraphs needed
19 .word 4064-(CODESZ/16) // Maximum extra paragraphs needed
20 .word 0xFFF0 // Initial (relative) SS value
21 .word 0xFFFE // Initial SP value
22 .word 0 // Checksum
23 .word EXEADRS(exestart) // Initial IP value
24 .word 0xFFF0 // Initial (relative) CS value
25 initramfssize:
26 .word 0 // File address of relocation table
27 id:
28 .word 0 // Overlay number
29 fdcnt: // File address of relocation table
30 .byte 0 // Bootstrap floppy sector count
32 /////////////////////// Master Boot Record code //////////////////////////////
34 start0:
35 pushw %dx // restore %sp
36 incw %bp // restore %bp
37 xorw %bx, %bx
38 movw %bx, %ds
39 movb $0x7C, %bh
40 pushw %bx // return address
41 pushaw
42 movw %sp, %bp
43 pushw %es // save %es:%di
44 cld
45 sti
46 pushw %ds
47 popw %es
48 call setreg
49 rep
50 movsw
51 movw $0x80, %dx
52 ljmp $0, $0x0600+start2
54 .org 60
55 .long 0x0080 // PE header offset
56 end_header:
57 chksum:
58 .word 0
59 comstart:
60 .word 0
62 .org 68
63 readsectorX: // read isolinux boot sector
64 movb $0xA5, %cl // patched by installer
65 readsector1:
66 andb $0x83, %dl // disk and floppy disk
67 movw %cx, (%bx)
68 incw %cx
69 movw $0x201, %ax
70 int $0x13
71 setreg:
72 movw %bx, %si
73 movw $0x0600, %di
74 movw $0x0100, %cx
75 return:
76 ret
77 dxloop:
78 start2:
79 call readsector1 // look for the boot device
80 repe
81 cmpsw
82 je dxfound
83 movb $0, %cl // ch = 0
84 addb $0x7D, %dl // try every hard disk
85 jno dxloop
86 dxfound:
87 call readsectorX // read isolinux boot sector
88 movw %dx, 10(%bp)
89 call checkboot
90 .asciz "No isolinux bs"
92 .org 0x0080
93 ////////////////////////////// EXE/PE header //////////////////////////////////
95 .org 0x01A0
96 checkboot:
97 cmpw %cx, (%bx)
98 popw %si
99 jc error // read fail or no isohydrid boot sector
100 popw %es
101 popa
102 putsret:
103 ret
104 putstrlp:
105 movw $7, %bx
106 movb $0xE, %ah
107 int $0x10
108 error:
109 lodsb
110 cmp $1, %al
111 jg putstrlp
112 jz putsret
113 putstr:
114 movb $0x80, %ah
115 xchgw %ax, %si
116 jnc error
117 halt:
118 hlt
119 jmp halt
120 .org 0x01BE
122 .org 0x7F26
123 ////////////////////////////// DOS EXE code ///////////////////////////////////
125 exestart:
126 cld
127 movw $0x100, %si
128 movw -127(%si), %ax
129 cmpb $0x2F, %al
130 je ishelp
131 cmpw $0x2F20, %ax
132 ishelp:
133 movw $0x3000+EXESTR(help), %ax
134 cwd // clear dx
135 pushw %dx // dos exit()
136 je abort
137 pushw %si
138 int $0x21 // get DOS version
139 popw %di // %di = 0x100: .COM start address
140 addb $-3, %al
141 movb $EXESTR(noDOS3), %al
142 jnc abort
143 movw $(EXELOC(0x8000))/2, %cx
144 chklp:
145 lodsw
146 addw %ax, %dx // break C
147 loop chklp
148 chked:
149 movw $0x1000+EXESTR(chkerr), %ax
150 je tst386 // dx == 0 ?
151 abort:
152 puts:
153 clc
154 jmp putstr
156 tst386:
157 pushfw // save flags
158 // bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
159 // flags 0 NT IOPL OF DF IF TF SF ZF 0 AF 0 PF 1 CF
160 // movb $0x10, %ah
161 pushw %ax
162 popfw // < 286 : flags[12..15] are forced 1
163 pushfw // = 286 : flags[12..15] are forced 0
164 popw %bx // > 286 : only flags[15] is forced 0
165 popfw // restore flags (IOPL)
166 addb %ah, %bh // test F0 and 00 cases
167 cmpb %ah, %bh
168 movb $EXESTR(no386), %al
169 jbe is86 // C=8086/80186, Z=80286
170 is386:
171 smsww %ax // not privileged
172 andb $1, %al
173 movw $10, %si
174 jne tstvcpi
175 movl %cr0, %eax // privileged
176 incl %eax
177 movb $EXESTR(rmPaging), %al
178 js abort
179 movb $EXESTR(realmodemsg), %al
180 realmode:
181 is86:
182 call puts
183 movw comstart-end_header(%di), %si // .com address
184 pushw %di
185 movb $0x7C/2, %ch // 31K-31.5K, > com length
186 rep
187 movsw
188 ret
190 VersionVCPI:
191 xchgw %ax, %si // movb $EXESTR(vm86modemsg), %al
192 cmpb $0x40, %cl // EMM386 / VCPI 4.0 mini
193 jnc realmode // %si = 0
194 tstvcpi:
195 pushw %ds
196 movw %dx, %ds // %dx = 0
197 movw 0x67*4+2, %ds
198 lodsw
199 xorw $0x4D45, %ax // EM(MX) or EM(MQ)
200 lodsw
201 lodsw
202 popw %ds
203 jne NoVCPI
204 xorw $0x5858, %ax // XX(X0)
205 movw $EXEADRS(CmdVCPI), %si
206 ChkVCPI:
207 NoVCPI:
208 movb $EXESTR(ERRvcpi), %al
209 jne abort
210 lodsb
211 shlw $8, %ax
212 je VersionVCPI
213 int $0x67
214 testb %ah, %ah
215 xchgw %ax, %cx
216 jmp ChkVCPI
217 CmdVCPI:
218 .byte 0x40 // status
219 .byte 0xDE // vcpi present ?
220 .byte 0x46 // version
221 .byte 0
223 vm86modemsg:
224 // --------------- Must be in 7F40 7FFF range ------------------------
225 .ascii "vm86" // vm86 mode
226 .byte EXESTR(mode)
227 ERRvcpi:
228 .ascii "EMM" // EMM386 need
229 no386:
230 .ascii "386" // 386 need
231 .byte EXESTR(need)
232 chkerr:
233 .ascii "Bad c" // Bad code
234 .byte EXESTR(ode)
235 rmPaging:
236 .ascii "Un" // Unreal mode
237 realmodemsg:
238 .ascii "real" // real mode
239 // --------------- Must be in 7FC0 7FFF range ------------------------
240 mode:
241 .ascii " m"
242 ode:
243 .ascii "ode"
244 .byte EXESTR(eol)
245 noDOS3:
246 .ascii "DOS3" // DOS3 need
247 need:
248 .ascii " need"
249 .byte EXESTR(eol)
250 help:
251 .ascii "SliTaz iso boot" // SliTaz iso boot
252 eol:
253 .ascii "\r\n"
254 .byte 1 // putstr will return
256 .space 16,0 // ISO md5
257 .org 0x8000
258 ////////////////////////// ISO9660 header /////////////////////////////////////