aboutsummaryrefslogtreecommitdiff
path: root/include/uskel.s
blob: bca33c9f15d631c2a5379b2057b2c4f86886a57e (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
72
73

# uskel runtime and start; include this at the top.

.section .init
.global _start
_start:
	jmp _uskel_start

.include "include/macros.s"

# this has globals
.section .bss
_unix_rsp:
	# back-up of program entry rsp (aka the actual stack given by the
	# actual OS; we might like to use it at some point, maybe)
	cell 0
_write_region_start:
	# begin of the active memory area
	cell 0
_write_region_end:
	# end of the active memory area (%rsp kinda starts here and goes down
	# towars the start)
	cell 0
_gc_last_size:
	# how much data we evacuated last time
	cell 0
_gc_min_alloc:
	# minimum possible allocation
	cell 0x100000 # tunable constant
_gc_min_expect_ratio:
	# 256th's of the minimal amount of memory increment compared to the
	# last time. New minimal amount is compared as:
	# (ratio * last size) >> 8
	cell 0x200 # tunable constant
_gc_region_start:
	# in GC, this region is being evacuated and will eventually disappear
	cell 0
_gc_region_end:
	# end of the disappear region
	cell 0
_gc_backup_thunk:
	# backup of %rsi so that we can use the register for other nonsense
	cell 0
_gc_backup_cont:
	# backup of %rbp for same reason
	cell 0

.section .text

.include "include/gc.s"

_uskel_start:
	# we use the stack pointer for easy writing to the heap;
	# back it up to memory state just if we ever needed it again.
	mov %rsp, _unix_rsp

	# allocate the initial chunk of memory
	mov $_uskel_start_main, %rsi
	jmp _uskel_alloc

	_uskel_start_main:
	# push a thunk for main
	pushq $0
	pushq $main

	mov $0, %rsi # set continuation to exit
	enter %rsp # run the program
	# Q: are there gonna be functions that have both the argument AND the cont?
	# 
	# A: No, stuff is either entered as return-continuation (takes res,
	# cont has to be saved) or as forward call (takes cont)
	#
	# (A needs validation)