Skip to content

Commit b8e1348

Browse files
author
dtrg
committed
Ensured that _errno is always defined. Rejigged the pc86 boot code so it doesn't always waste 510 bytes of memory.
1 parent 413880c commit b8e1348

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

plat/linux386/boot.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ EXIT:
6060

6161
! Some magic data. All EM systems need these.
6262

63-
.define .trppc, .ignmask
63+
.define .trppc, .ignmask, _errno
6464
.comm .trppc, 4
6565
.comm .ignmask, 4
66+
.comm _errno, 4

plat/pc86/boot.s

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212

1313
.sect .text
1414

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+
1528
! Some definitions.
1629

1730
BOOT_SEGMENT = 0x07C0 ! Where we've been loaded
@@ -255,10 +268,9 @@ finished:
255268
256269
! Push standard parameters onto the stack and go.
257270
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
262274
call __m_a_i_n
263275
! fall through into the exit routine.
264276
@@ -291,25 +303,28 @@ loading_msg: .asciz '\n\rLoading...\n\r'
291303
halted_msg: .asciz '\n\rHalted.\n\r'
292304
running_msg: .asciz '\n\rRunning.\n\r'
293305
306+
! The argv and env arrays.
307+
308+
argv: .data2 exename, 0
309+
envp: .data2 0
310+
exename: .asciz 'pc86.img'
311+
294312
! ...and we need this to fool the PC into booting our boot sector.
295313
296-
.align 510
314+
.space PADDING
297315
.data2 0xAA55
298316

299-
300-
.define begtext,begdata,begbss
301-
.define ERANGE,ESET,EHEAP,ECASE,EILLINS,EIDIVZ,EODDZ
302-
.extern _end
303-
304317
! Define symbols at the beginning of our various segments, so that we can find
305318
! them. (Except .text, which has already been done.)
306319

320+
.define begtext, begdata, begbss
307321
.sect .data; begdata:
308322
.sect .rom; begrom:
309323
.sect .bss; begbss:
310324

311325
! Some magic data. All EM systems need these.
312326

313-
.define .trppc, .ignmask
327+
.define .trppc, .ignmask, _errno
314328
.comm .trppc, 4
315329
.comm .ignmask, 4
330+
.comm _errno, 4

plat/pc86/descr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ name led
5555
(.ocm:{TAIL}={PLATFORMDIR}/liboccam.a) \
5656
(.ocm.b.mod.c.p:{TAIL}={PLATFORMDIR}/libc.a) \
5757
{FLOATS?} \
58-
(.e:{TAIL}={PLATFORMDIR}/libsys.a \
59-
{PLATFORMDIR}/libem.a \
58+
(.e:{TAIL}={PLATFORMDIR}/libem.a \
59+
{PLATFORMDIR}/libsys.a \
6060
{PLATFORMDIR}/libend.a)
6161
linker
6262
end

0 commit comments

Comments
 (0)