|
12 | 12 |
|
13 | 13 | .sect .text |
14 | 14 |
|
| 15 | +! ****** WARNING! ****** |
| 16 | +! |
| 17 | +! The PC boot sector requires a magic number at the end to signify that the |
| 18 | +! disk is bootable. Unfortunately, the ACK assembler is a bit simple and we |
| 19 | +! can't tell it to put the 0xAA55 at a particular address without writing our |
| 20 | +! own custom binary generator. As a result, we need to manually insert just |
| 21 | +! the right amount of padding in order to make this work. |
| 22 | +! |
| 23 | +! If you ever need to change the boot code, this needs adjusting. I recommend |
| 24 | +! a hex editor. |
| 25 | + |
| 26 | +PADDING = 0xB9 |
| 27 | + |
15 | 28 | ! Some definitions. |
16 | 29 |
|
17 | 30 | BOOT_SEGMENT = 0x07C0 ! Where we've been loaded |
@@ -255,10 +268,9 @@ finished: |
255 | 268 | |
256 | 269 | ! Push standard parameters onto the stack and go. |
257 | 270 | |
258 | | - xor ax, ax |
259 | | - push ax ! argc |
260 | | - push ax ! argv |
261 | | - push ax ! envp |
| 271 | + push envp ! envp |
| 272 | + push argv ! argv |
| 273 | + push 1 ! argc |
262 | 274 | call __m_a_i_n |
263 | 275 | ! fall through into the exit routine. |
264 | 276 | |
@@ -291,25 +303,28 @@ loading_msg: .asciz '\n\rLoading...\n\r' |
291 | 303 | halted_msg: .asciz '\n\rHalted.\n\r' |
292 | 304 | running_msg: .asciz '\n\rRunning.\n\r' |
293 | 305 | |
| 306 | + ! The argv and env arrays. |
| 307 | + |
| 308 | +argv: .data2 exename, 0 |
| 309 | +envp: .data2 0 |
| 310 | +exename: .asciz 'pc86.img' |
| 311 | + |
294 | 312 | ! ...and we need this to fool the PC into booting our boot sector. |
295 | 313 | |
296 | | - .align 510 |
| 314 | + .space PADDING |
297 | 315 | .data2 0xAA55 |
298 | 316 |
|
299 | | - |
300 | | -.define begtext,begdata,begbss |
301 | | -.define ERANGE,ESET,EHEAP,ECASE,EILLINS,EIDIVZ,EODDZ |
302 | | -.extern _end |
303 | | - |
304 | 317 | ! Define symbols at the beginning of our various segments, so that we can find |
305 | 318 | ! them. (Except .text, which has already been done.) |
306 | 319 |
|
| 320 | +.define begtext, begdata, begbss |
307 | 321 | .sect .data; begdata: |
308 | 322 | .sect .rom; begrom: |
309 | 323 | .sect .bss; begbss: |
310 | 324 |
|
311 | 325 | ! Some magic data. All EM systems need these. |
312 | 326 |
|
313 | | -.define .trppc, .ignmask |
| 327 | +.define .trppc, .ignmask, _errno |
314 | 328 | .comm .trppc, 4 |
315 | 329 | .comm .ignmask, 4 |
| 330 | +.comm _errno, 4 |
0 commit comments