Additional fixes for the proper argc/argv parsing
[profile/ivi/syslinux.git] / dos / crt0.S
1         .code16
2
3         .section ".init","ax"
4         .globl _start
5         .type _start,@function
6 _start:
7         # Align the stack and make sure the high half is zero
8         andl $0xfff8,%esp
9         
10         # Clear the .bss
11         cld
12         xorl %eax,%eax
13         movw $__bss_start,%di
14         movw $_end+3,%cx
15         subw %di,%cx
16         shrw $2,%cx
17         rep ; stosl
18
19         # Compute argc and argv
20         xorl %edx,%edx
21         movzbw 80,%bx
22         movb %dl,81(%bx)        # Zero-terminate string
23         movb $81,%dl
24         pushl %eax              # Make space for argv
25         movl %esp,%eax
26         calll __parse_argv
27         pushl %eax              # argc
28
29         # Initialize malloc
30         calll __init_memory_arena
31
32         # Now call main...
33         popl %eax               # argc
34         popl %edx               # argv
35         calll main
36
37         # Here %eax is the exit code, fall through into exit
38         
39         .size _start,.-_start
40
41         .globl exit
42         .type exit,@function
43 exit:
44         # Exit code already in %eax
45         movb $0x4c,%ah          # Terminate program
46         int $0x21
47 1:      hlt
48         jmp 1b
49         .size exit,.-exit