.code16
- .section ".init","ax"
+#ifndef REGPARM
+# error "This file assumes -mregparm=3 -DREGPARM=3"
+#endif
+
+ .section ".text","ax"
.globl _start
.type _start,@function
_start:
+ # Align the stack and make sure the high half is zero
+ andl $0xfff8,%esp
+
+ # DS, ES points to the PSP at this point
+ pushw %es # Save PSP pointer
+ movw %cs,%ax
+ movw %ax,%ds
+ movw %ax,%es
+
# Clear the .bss
cld
xorl %eax,%eax
movw $__bss_start,%di
- movw $_end+3,%cx
+ movw $__bss_end+3,%cx
subw %di,%cx
shrw $2,%cx
rep ; stosl
- # Compute argc and argv
- movzbw 0x80,%cx
- movl $0x81,%esi
- movw $argv,%di
-
- xorl %eax,%eax # Dummy argv[0]
- stosl
-
-1:
- # Skip any space or control character
- jcxz 2f
- lodsb
- decw %cx
- cmp $0x20,%al
- ja 3f
-5:
- movb $0,-1(%si)
- jmp 1b
+ # Copy the command line into our own segment
+ popw %fs # FS -> PSP
+ movw $_cmdline,%di
+ movzbw %fs:0x80,%cx
+ movw $0x81,%si
+ fs ; rep ; movsb
+ # Already zero-terminated since we're writing into clean bss
-3:
- movl %esi,%eax
- stosl
-4:
- # Skip this word
- jcxz 2f
- lodsb
- decw %cx
- cmp $0x20,%al
- ja 4b
- jmp 5b
-2:
- xorl %eax,%eax # Final null argv entry
- stosl
+ # Compute argc and argv (assumes REGPARM)
+ movl $_cmdline,%edx
+ pushl %eax # Make space for argv
+ movl %esp,%eax
+ calll __parse_argv
+ pushl %eax # argc
# Initialize malloc
calll __init_memory_arena
- # Now call main...
- pushl $argv # Push argv
- pushl %eax # Dummy argc (we dont look at it)
+ # Now call main... (NOTE: gcc forces main to be regparm 0)
+ popl %eax # argc
+ popl %edx # argv
calll main
- pushl %eax
- calll exit
- hlt
+
+ # Here %eax is the exit code, fall through into exit
+
.size _start,.-_start
.globl exit
.type exit,@function
exit:
- movb 4(%esp),%al
+ # Exit code already in %eax
movb $0x4c,%ah # Terminate program
int $0x21
+1: hlt
+ jmp 1b
.size exit,.-exit
-
+
.section ".bss","aw"
-argv: .space 4*128
+ .balign 4
+_cmdline:
+ .space 128
+ .size _cmdline,.-_cmdline