aboutsummaryrefslogtreecommitdiffstats
path: root/dos/crt0.S
blob: 530059ca69aec921d20718ec35b705b3a12144da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
	.code16

	.section ".init","ax"
	.globl _start
	.type _start,@function
_start:
	# Clear the .bss
	cld
	xorl %eax,%eax
	movw $__bss_start,%di
	movw $_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

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	

	# Initialize malloc
	calll __init_memory_arena

	# Now call main...
	pushl $argv		# Push argv
	pushl %eax		# Dummy argc (we dont look at it)
	calll main
	pushl %eax
	calll exit
	hlt
	.size _start,.-_start

	.globl exit
	.type exit,@function
exit:
	movb 4(%esp),%al
	movb $0x4c,%ah		# Terminate program
	int $0x21
	.size exit,.-exit
	
	.section ".bss","aw"
argv:	.space 4*128