wok view syslinux/stuff/iso2exe/bootiso.S @ rev 23863
syslinux/isoboot.s: accept user args
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Jun 19 15:46:21 2020 +0000 (2020-06-19) |
parents | ec56ab0f8e5b |
children | a2e843f5d9e4 |
line source
1 .text
2 .code16
3 .arch i8086
4 .org 0
6 CODESZ = 0x8000 // 16 sectors = 32Kb
7 #define EXEADRS(x) x+0xC0
8 #define EXELOC(x) x-0x40
9 #define EXESTR(x) x-0x7F40
11 .globl _start
12 _start:
13 decw %bp // Magic number: MZ
14 popw %dx
15 jmp start0 // Bytes on last page of file
16 .word (CODESZ+511)/512 // Pages in file
17 .word 0 // Relocations
18 .word (end_header-_start)/16 // Size of header in paragraphs
19 .word 4064-(CODESZ/16) // Minimum extra paragraphs needed
20 .word 4064-(CODESZ/16) // Maximum extra paragraphs needed
21 .word 0xFFF0 // Initial (relative) SS value
22 .word 0xFFFE // Initial SP value
23 magic:
24 .word 0 // Checksum
25 .word EXEADRS(exestart) // Initial IP value
26 .word 0xFFF0 // Initial (relative) CS value
27 initramfssize:
28 .word 0 // File address of relocation table
29 fdcnt: // Overlay number
30 .byte 0 // Bootstrap floppy sector count
31 .ascii "slitaz"
33 /////////////////////// Master Boot Record code //////////////////////////////
35 moved = 0x8000
36 start0:
37 //pushw %dx // restore %sp
38 //incw %bp // restore %bp
39 xorw %bx, %bx
40 movw %bx, %ds
41 movb $0x7C, %bh
42 pushw %ds
43 popw %ss
44 movw %bx, %sp
45 pushw %bx // return address
46 pushw %di
47 pushw %es // save %es:%di
48 cld
49 sti
50 pushw %ds
51 popw %es
52 call setreg
53 rep
54 movsw
55 movw $0x80, %dx
56 ljmp $0, $moved+start2
57 .byte 0
58 // .org 60
59 // .long 0x0080 // PE header offset
60 .org 64
61 end_header:
62 comstart:
63 .word 0
65 .org 66
66 dxloop:
67 start2:
68 call readsector1 // look for the boot device
69 repe
70 cmpsw
71 je dxfound
72 movb $0, %cl // ch = 0
73 addb $0x7D, %dl // try every hard disk
74 jno dxloop
76 dxfound:
77 call readsectorX // read isolinux boot sector
78 cmpw (%bx), %cx
79 jnc puts // read fail or no isohydrid boot sector
80 call bootpartition // assume DS=SS SI=BX=7C00 CX=0100 DL=<drive> DI=table+66
81 popw %es
82 popw %di // isolinux boot needs %es:%di and %dx
83 putsret:
84 ret
86 putstrlp:
87 movw $7, %bx
88 movb $0xE, %ah
89 int $0x10
90 error:
91 lodsb
92 cmp $1, %al
93 jg putstrlp
94 jz putsret
95 puts:
96 movb $0x80, %ah
97 xchgw %ax, %si
98 jnc error
99 halt:
100 hlt
101 jmp halt
102 nobsmsg:
103 .asciz "No isolinux."
105 .org 0x0080,0xEE
106 ////////////////////////////// EXE/PE header //////////////////////////////////
107 .org 0x0178,0xFF
108 ////////////////////////// partition boot code ////////////////////////////////
109 // assume DS=SS SI=BX=7C00 CX=0100 DL=<drive> DI=table+66
111 bootpartition:
112 movw $4,%cx
113 movw $16,%ax
114 next:
115 subw %ax,%di
116 cmpb %ch,-2(%di) // boot flag ?
117 loope next
118 cmpw $63,2-2(%di) // empty or isolinux partition ?
119 jbe default
120 .arch i486
121 pushl $0
122 pushl 8-2(%di)
123 pushw %cs
124 pushw %bx
125 pushw $1
126 pushw %ax
127 movw %sp,%si // assume %ds = %ss
128 movb $0x42,%ah
129 int $0x13
130 add $16,%sp
131 .arch i8086
132 default:
133 ret
135 .org 0x01A0,0xFF
136 readsectorX: // read isolinux boot sector
137 movb $0xA5, %cl // patched by installer
138 readsector1:
139 andb $0x83, %dl // disk and floppy disk
140 movw %cx, (%bx)
141 incw %cx
142 movw $0x201, %ax
143 int $0x13
144 setreg:
145 movw %bx, %si
146 movw $moved, %di
147 movw $0x0100, %cx
148 movb $nobsmsg, %al
149 ret
150 .org 0x01B8,0xEE // partition table
152 .org 0x0270,0xFF
154 ////////////////////////////// DOS EXE code ///////////////////////////////////
156 bootdir:
157 .asciz "/boot"
158 linld:
159 .asciz "linld.com"
160 cmdline:
161 .ascii "-f "
162 // .ascii "image=\boot\"
163 // .ascii "bzImage "
164 .ascii "initrd="
165 rootfs:
166 .ascii "rootfs"
167 dotgz:
168 .ascii ".gz,! "
169 // .ascii ".gz,rootfs4.gz,! "
170 args:
171 // .ascii " rw "
172 // .ascii " mode=menu"
173 .ascii " autologin rdinit=/init.exe magic="
174 magicstr:
175 .ascii "0 bootfrom="
176 // .ascii "65535 bootfrom="
177 filename:
178 exestart:
179 movb $0x30,%ah // get DOS version
180 int $0x21
181 cmpb $3,%al
182 jc goabort
184 cld
185 movw EXEADRS(comstart),%si
186 movw $0xF000,%di
187 movb $4,%ch // 2k min
188 rep
189 movsw // helper
190 movw $129,%si
191 leaw args-cmdline(%si),%di
192 movb -1(%si),%cl
193 pushw %si
194 rep
195 movsb // user args
196 xchgw %ax,%di
197 popw %di
198 movw $EXEADRS(cmdline),%si
199 movb $args-cmdline,%cl
200 rep
201 movsb // files
202 xchgw %ax,%di
203 movb $filename-args,%cl
204 rep
205 movsb // end
206 pushw %di // filename
208 #define ISOSTATE 0xF000
209 #define ISO_OPEN iso_open
210 #define ISO_READDIR *0xF004
211 #define ISO_READMENU iso_readmenu
212 #define RUN_LINLD run_linld
213 movw ISOSTATE,%bp
214 xorw %ax,%ax
215 movw %bp,%di
216 movb $64,%cl
217 rep
218 stosb // clear BSS
220 movw %ax,%di
221 movw 0x2C(%di),%es
222 decw %cx
223 scalp:
224 repne
225 scasb
226 scasb
227 jne scalp
228 scasw
229 movw %di,%si // %es:%di = programme pathname
231 pushw %es
232 pushw %ds
233 popw %es
234 popw %ds
235 popw %di // filename
236 pushw %di
237 movb $0x60,%ah // canonicalize filename
238 int $0x21
239 pushw %es
240 popw %ds
241 #define LONG_FILENAME
242 #ifdef LONG_FILENAME
243 popw %si
244 pushw %si
245 movw $0x716C,%ax
246 xorw %bx,%bx // R/O
247 xorw %cx,%cx // attributes
248 cwd // action = open
249 stc
250 int $0x21
251 jnc opened
252 #endif
253 popw %dx
254 pushw %dx
255 movw $0x3D00,%ax
256 // movb $0,%cl
257 int $0x21
258 goabort:
259 jc abort
260 opened:
261 movw %ax,4(%bp) // fd
263 call ISO_READMENU
264 movw 6(%bp),%ax // magic = filemod
265 popw %bx
266 leaw magicstr-filename(%bx),%di
267 movb $10,%bl
268 xorw %cx,%cx
269 lp1:
270 xorw %dx,%dx
271 divw %bx
272 pushw %dx
273 incw %cx
274 orw %ax,%ax
275 jnz lp1
276 lp2:
277 popw %ax
278 addb $'0',%al
279 stosb // store magic
280 loop lp2
282 movw $EXEADRS(bootdir),%ax
283 call ISO_OPEN
284 orw $-1,18(%bp) // curdirsize = -1
285 xorw %ax,%ax
286 found:
287 incb %ah
288 patchtest:
289 pushw %ax
290 call ISO_READDIR
291 pushw %ds
292 popw %es
293 incw %ax
294 popw %ax
295 movw $EXEADRS(rootfs),%si
296 je dopatch
297 movw %si,%di
298 movw 16(%bp),%si // filename
299 movw $9,%cx
300 rep
301 cmpsb
302 jcxz found
303 cmpb $3,%cl
304 ja patchtest
305 decw %si
306 cmpb (%si),%al
307 ja patchtest
308 lodsb
309 jmp patchtest
310 done:
311 movw $128,%ax
312 subw %ax,%si
313 xchgw %ax,%si
314 decw %ax
315 movb %al,(%si) // cmdline length
317 movw $EXEADRS(linld),%ax
318 call ISO_OPEN
319 jc abort
320 movw 12(%bp),%cx // filesize
321 movw $0x100,%dx
322 call RUN_LINLD
323 abort:
324 movw $EXEADRS(stopmsg),%dx
325 movb $9,%ah
326 int $0x21
327 int $0x20
328 dopatch:
329 pushw %si
330 cmpw $0x200,%ax
331 je initrddone
332 movw $EXEADRS(dotgz),%di
333 decb %ah
334 je modify
335 scasw
336 scasw // addw $4,%di
337 movsw
338 movsw
339 movsw
340 modify:
341 stosb
342 movw $129+dotgz-cmdline,%si
343 movsb
344 movsw
345 movsw
346 initrddone:
347 movw $129+rootfs-cmdline,%di
348 popw %si
349 movw $args-rootfs,%cx
350 rep
351 movsb
353 shrink0:
354 movw $129,%si
355 shrink:
356 movw %si,%di
357 lodsb
358 cmpb $0,%al
359 je done
360 cmpb $' ',%al
361 jne shrink
362 cmpb (%si),%al
363 jne shrink
364 pack:
365 lodsb
366 stosb
367 cmpb $0,%al
368 jne pack
369 jmp shrink0
371 .org 0x0400,0xEE
372 .org 0x0600,0xFF
373 .org 0x0750,0xBB
374 stopmsg:
375 .ascii "This program cannot be run in DOS mode.$"
376 .org 0x0778,0xEE
377 .org 0xF002-0xC0
378 iso_open:
379 .word 0
380 .word 0
381 iso_readmenu:
382 .word 0
383 run_linld:
385 .end