wok-next view syslinux/stuff/iso2exe/bootiso.S @ rev 21276

try to build gens-gs again
author Hans-G?nter Theisgen
date Sat Dec 07 15:51:18 2019 +0100 (2019-12-07)
parents 7a16da2c93b9
children
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
181 .org 0x7F83
182 ////////////////////////////// DOS EXE code ///////////////////////////////////
184 exestart:
185 cld
186 movw 129, %ax
187 cmpb $0x2F, %al
188 je ishelp
189 cmpw $0x2F20, %ax
190 ishelp:
191 movw $0x3000+EXESTR(help), %ax
192 cwd // clear dx
193 pushw %dx // dos exit()
194 je abort
195 int $0x21 // get DOS version
196 addb $-3, %al
197 movb $EXESTR(noDOS3), %al
198 movw $0x100, %di
199 jc tst386
200 abort:
201 goputs:
202 jmp puts
204 tst386:
205 pushw %sp
206 popw %ax
207 xorw %sp, %ax // clear C
208 movb $EXESTR(vm86modemsg), %al
209 jnz is86 // 86/186 not a 286+
210 .arch i486
211 is386:
212 smsww %bx // not privileged
213 andb $1, %bl // clear C
214 jne isvm86
215 movl %cr0, %ebx // privileged
216 incl %ebx
217 .arch i8086
218 movb $EXESTR(rmPaging), %al
219 js abort
220 is86:
221 incw %ax
222 //movb $EXESTR(realmodemsg), %al
223 isvm86:
224 call goputs
225 movw comstart-end_header(%di), %si // .com address
226 pushw %di
227 movb $0x7C/2, %ch // 31K-31.5K, > com length
228 rep
229 movsw
230 ret
232 vm86modemsg:
233 // --------------- Must be in 7F40 7FFF range ------------------------
234 .ascii "v" // v86 mode
235 .ascii "86" // 86 mode
236 .byte EXESTR(mode)
237 rmPaging:
238 .ascii "X" // Xreal mode
239 realmodemsg:
240 .ascii "real" // real mode
241 // --------------- Must be in 7FC0 7FFF range ------------------------
242 mode:
243 .ascii " m"
244 ode:
245 .ascii "ode"
246 .byte EXESTR(eol)
247 noDOS3:
248 .ascii "DOS3" // DOS3?
249 need:
250 .ascii "?"
251 .byte EXESTR(eol)
252 help:
253 .ascii "SliTaz iso boot." // SliTaz iso boot.
254 eol:
255 .ascii "\r\n"
256 .byte 1 // puts will return
258 .space 16,0 // ISO md5
259 .org 0x8000
260 ////////////////////////// ISO9660 header /////////////////////////////////////