Put in MS-DOS 7 locking support
[profile/ivi/syslinux.git] / dos / crt0.S
1         .code16
2
3         .section ".init","ax"
4         .globl _start
5         .type _start,@function
6 _start:
7         # Clear the .bss
8         cld
9         xorl %eax,%eax
10         movw $__bss_start,%di
11         movw $_end+3,%cx
12         subw %di,%cx
13         shrw $2,%cx
14         rep ; stosl
15
16         # Compute argc and argv
17         movzbw 0x80,%cx
18         movl $0x81,%esi
19         movw $argv,%di
20
21         xorl %eax,%eax          # Dummy argv[0]
22         stosl
23
24 1:
25         # Skip any space or control character
26         jcxz 2f
27         lodsb
28         decw %cx
29         cmp $0x20,%al
30         ja 3f
31 5:
32         movb $0,-1(%si)
33         jmp 1b
34
35 3:
36         movl %esi,%eax
37         stosl
38 4:
39         # Skip this word
40         jcxz 2f
41         lodsb
42         decw %cx
43         cmp $0x20,%al
44         ja 4b
45         jmp 5b
46 2:
47         xorl %eax,%eax          # Final null argv entry
48         stosl   
49
50         # Initialize malloc
51         calll __init_memory_arena
52
53         # Now call main...
54         pushl $argv             # Push argv
55         pushl %eax              # Dummy argc (we dont look at it)
56         calll main
57         pushl %eax
58         calll exit
59         hlt
60         .size _start,.-_start
61
62         .globl exit
63         .type exit,@function
64 exit:
65         movb 4(%esp),%al
66         movb $0x4c,%ah          # Terminate program
67         int $0x21
68         .size exit,.-exit
69         
70         .section ".bss","aw"
71 argv:   .space 4*128