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

linld/iso2exe: remove non slitaz dos boot
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Aug 10 18:47:30 2019 +0200 (2019-08-10)
parents ab8e834bbcfe
children ec56ab0f8e5b
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 movw $patch,%si
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
106 ////////////////////////////// EXE/PE header //////////////////////////////////
108 .org 0x01A0
109 readsectorX: // read isolinux boot sector
110 movb $0xA5, %cl // patched by installer
111 readsector1:
112 andb $0x83, %dl // disk and floppy disk
113 movw %cx, (%bx)
114 incw %cx
115 movw $0x201, %ax
116 int $0x13
117 setreg:
118 movw %bx, %si
119 movw $moved, %di
120 movw $0x0100, %cx
121 movb $nobsmsg, %al
122 ret
123 .org 0x01B8
125 ////////////////////////// partition boot code ////////////////////////////////
126 // assume DS=SS BX=7C00 CH=01 DL=<drive> SI=7DBE
128 .org 0x7C00
129 jmp bootpartition
130 .org 0x7C03
131 .org 0x7DBE
132 table = moved+0x1BE
133 patch:
134 .byte 0,0,0 // head of original bs
135 partcode:
136 popw %si
137 xchgw %si,%di
138 call movepartition
139 pushw %cx
140 pushw %cx
141 decw %di
142 decw %di
143 movb $4,%cl
144 movw $16,%ax
145 next:
146 subw %ax,%di
147 cmpb %ch,(%di) // boot flag ?
148 loope next
149 pushw 10(%di)
150 pushw 8(%di)
151 pushw %cs
152 pushw %bx
153 movb $1,%cl
154 pushw %cx
155 pushw %ax
156 movw %sp,%si // assume %ds = %ss
157 pushw %bx
158 cmpw $63,2(%di) // empty or isolinux partition ?
159 jbe default
160 movb $0x42,%ah
161 int $0x13
162 default:
163 ret
164 .org 0x7DF0
165 bootpartition:
166 pushw %ds
167 popw %es
168 pushw %si
169 movw %bx,%di
170 movsw
171 movsb
172 movw $table-0x142,%di
173 pushw %di
174 movepartition:
175 movb $66,%cl // 0142 and 0042
176 rep
177 movsb
178 ret
179 .org 0x7E00
180 .org 0x7F40
181 ////////////////////////////// DOS EXE code ///////////////////////////////////
183 exestart:
184 movw 129, %ax
185 cmpb $0x2F, %al
186 je ishelp
187 cmpw $0x2F20, %ax
188 ishelp:
189 movw $0x3000+EXESTR(help), %ax
190 cwd // clear dx
191 pushw %dx // dos exit()
192 je abort
193 int $0x21 // get DOS version
194 addb $-3, %al
195 movb $EXESTR(noDOS3), %al
196 movw $0x100, %di
197 jc tst386
198 abort:
199 goputs:
200 mov $EXEADRS(puts), %si
201 jmp *%si
203 tst386:
204 pushw %sp
205 popw %ax
206 xorw %sp, %ax // clear C
207 movb $EXESTR(vm86modemsg), %al
208 jnz is86 // 86/186 not a 286+
209 .arch i486
210 is386:
211 smsww %bx // not privileged
212 andb $1, %bl // clear C
213 jne isvm86
214 movl %cr0, %ebx // privileged
215 incl %ebx
216 .arch i8086
217 movb $EXESTR(rmPaging), %al
218 js abort
219 is86:
220 incw %ax
221 //movb $EXESTR(realmodemsg), %al
222 isvm86:
223 call goputs
224 //----------
225 pushw %di
226 //------------- insert argv[0] in cmdline -----------------------
227 xchgw %ax,%dx // %ax = 0
228 movw %ax,%di
229 movw 0x2C(%di),%es
230 movw %sp,%cx // big enough
231 scalp:
232 repne
233 scasb
234 scasb
235 jne scalp
236 incw %di
237 movw %di,%bx
238 incw %di
239 pushw %di // %es:%di = programme pathname
240 repne
241 scasb
242 subw %di,%bx
243 negw %bx
244 movw $128,%si
245 addw %bx,(%si)
246 lodsb
247 xchgw %ax,%cx
248 incw %cx
249 pushw %si
250 p2lp:
251 lodsb
252 movb %al,-2(%bx,%si)
253 loop p2lp
254 popw %si
255 popw %bx
256 movb $0x20,%al
257 p1lp:
258 movb %al,(%si)
259 incw %si
260 movb %es:(%bx),%al
261 incw %bx
262 cmpw %bx,%di
263 ja p1lp
264 //----------
265 popw %di
266 pushw %cs
267 popw %es
268 //----------
269 movw comstart-end_header(%di), %si // .com address
270 pushw %di
271 movb $0x7C/2, %ch // 31K-31.5K, > com length
272 movb $0x80, %bh
273 movw $0xA5F3, (%bx) // rep movsw
274 movb $0xC3, 2(%bx) // ret
275 jmp *%bx
277 vm86modemsg:
278 // --------------- Must be in 7F40 7FFF range ------------------------
279 .ascii "v" // v86 mode
280 .ascii "86" // 86 mode
281 .byte EXESTR(mode)
282 rmPaging:
283 .ascii "X" // Xreal mode
284 realmodemsg:
285 .ascii "real" // real mode
286 // --------------- Must be in 7FC0 7FFF range ------------------------
287 mode:
288 .ascii " mode"
289 .byte EXESTR(eol)
290 noDOS3:
291 .ascii "DOS3?" // DOS3?
292 .byte EXESTR(eol)
293 help:
294 .ascii "SliTaz iso boot" // SliTaz iso boot
295 eol:
296 .ascii "\r\n"
297 .byte 1 // puts will return
299 .space 16,0 // ISO md5
300 .org 0x8000
301 ////////////////////////// ISO9660 header /////////////////////////////////////