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

linld: fix progname
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Mar 30 15:54:03 2017 +0200 (2017-03-30)
parents de17d022fe9c
children 7144509c7473
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 .word 0 // Checksum
24 .word EXEADRS(exestart) // Initial IP value
25 .word 0xFFF0 // Initial (relative) CS value
26 initramfssize:
27 .word 0 // File address of relocation table
28 fdcnt: // Overlay number
29 .byte 0 // Bootstrap floppy sector count
30 .ascii "slitaz"
32 /////////////////////// Master Boot Record code //////////////////////////////
34 moved = 0x8000
35 start0:
36 //pushw %dx // restore %sp
37 //incw %bp // restore %bp
38 xorw %bx, %bx
39 movw %bx, %ds
40 movb $0x7C, %bh
41 pushw %ds
42 popw %ss
43 movw %bx, %sp
44 pushw %bx // return address
45 pushw %di
46 pushw %es // save %es:%di
47 cld
48 sti
49 pushw %ds
50 popw %es
51 call setreg
52 rep
53 movsw
54 movw $0x80, %dx
55 ljmp $0, $moved+start2
56 .byte 0
57 // .org 60
58 // .long 0x0080 // PE header offset
59 .org 64
60 end_header:
61 comstart:
62 .word 0
64 .org 66
65 dxloop:
66 start2:
67 call readsector1 // look for the boot device
68 repe
69 cmpsw
70 je dxfound
71 movb $0, %cl // ch = 0
72 addb $0x7D, %dl // try every hard disk
73 jno dxloop
75 dxfound:
76 call readsectorX // read isolinux boot sector
77 cmpw (%bx), %cx
78 jnc puts // read fail or no isohydrid boot sector
79 movw $patch,%si
80 popw %es
81 popw %di // isolinux boot needs %es:%di and %dx
82 putsret:
83 ret
85 putstrlp:
86 movw $7, %bx
87 movb $0xE, %ah
88 int $0x10
89 error:
90 lodsb
91 cmp $1, %al
92 jg putstrlp
93 jz putsret
94 puts:
95 movb $0x80, %ah
96 xchgw %ax, %si
97 jnc error
98 halt:
99 hlt
100 jmp halt
101 nobsmsg:
102 .asciz "No isolinux."
104 .org 0x0080
105 ////////////////////////////// EXE/PE header //////////////////////////////////
107 .org 0x01A0
108 readsectorX: // read isolinux boot sector
109 movb $0xA5, %cl // patched by installer
110 readsector1:
111 andb $0x83, %dl // disk and floppy disk
112 movw %cx, (%bx)
113 incw %cx
114 movw $0x201, %ax
115 int $0x13
116 setreg:
117 movw %bx, %si
118 movw $moved, %di
119 movw $0x0100, %cx
120 movb $nobsmsg, %al
121 ret
122 .org 0x01B8
124 ////////////////////////// partition boot code ////////////////////////////////
125 // assume DS=SS BX=7C00 CH=01 DL=<drive> SI=7DBE
127 .org 0x7C00
128 jmp bootpartition
129 .org 0x7C03
130 .org 0x7DBE
131 table = moved+0x1BE
132 patch:
133 .byte 0,0,0 // head of original bs
134 partcode:
135 popw %si
136 xchgw %si,%di
137 call movepartition
138 pushw %cx
139 pushw %cx
140 decw %di
141 decw %di
142 movb $4,%cl
143 movw $16,%ax
144 next:
145 subw %ax,%di
146 cmpb %ch,(%di) // boot flag ?
147 loope next
148 pushw 10(%di)
149 pushw 8(%di)
150 pushw %cs
151 pushw %bx
152 movb $1,%cl
153 pushw %cx
154 pushw %ax
155 movw %sp,%si // assume %ds = %ss
156 pushw %bx
157 cmpw $63,2(%di) // empty or isolinux partition ?
158 jbe default
159 movb $0x42,%ah
160 int $0x13
161 default:
162 ret
163 .org 0x7DF0
164 bootpartition:
165 pushw %ds
166 popw %es
167 pushw %si
168 movw %bx,%di
169 movsw
170 movsb
171 movw $table-0x142,%di
172 pushw %di
173 movepartition:
174 movb $66,%cl // 0142 and 0042
175 rep
176 movsb
177 ret
178 .org 0x7E00
180 .org 0x7F83
181 ////////////////////////////// DOS EXE code ///////////////////////////////////
183 exestart:
184 cld
185 movw 129, %ax
186 cmpb $0x2F, %al
187 je ishelp
188 cmpw $0x2F20, %ax
189 ishelp:
190 movw $0x3000+EXESTR(help), %ax
191 cwd // clear dx
192 pushw %dx // dos exit()
193 je abort
194 int $0x21 // get DOS version
195 addb $-3, %al
196 movb $EXESTR(noDOS3), %al
197 movw $0x100, %di
198 jc tst386
199 abort:
200 goputs:
201 jmp puts
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 movw comstart-end_header(%di), %si // .com address
225 pushw %di
226 movb $0x7C/2, %ch // 31K-31.5K, > com length
227 rep
228 movsw
229 ret
231 vm86modemsg:
232 // --------------- Must be in 7F40 7FFF range ------------------------
233 .ascii "V" // V86 mode
234 .ascii "86" // 86 mode
235 .byte EXESTR(mode)
236 rmPaging:
237 .ascii "X" // Xreal mode
238 realmodemsg:
239 .ascii "real" // real mode
240 // --------------- Must be in 7FC0 7FFF range ------------------------
241 mode:
242 .ascii " m"
243 ode:
244 .ascii "ode"
245 .byte EXESTR(eol)
246 noDOS3:
247 .ascii "DOS3" // DOS3?
248 need:
249 .ascii "?"
250 .byte EXESTR(eol)
251 help:
252 .ascii "SliTaz iso boot." // SliTaz iso boot.
253 eol:
254 .ascii "\r\n"
255 .byte 1 // puts will return
257 .space 16,0 // ISO md5
258 .org 0x8000
259 ////////////////////////// ISO9660 header /////////////////////////////////////