diff options
| author | Mirek Kratochvil <exa.exa@gmail.com> | 2023-08-06 00:25:53 +0200 |
|---|---|---|
| committer | Mirek Kratochvil <exa.exa@gmail.com> | 2023-08-06 00:25:53 +0200 |
| commit | 74cad993376dc269e8389fbf150be9ecc36890c7 (patch) | |
| tree | 32a2dbb382836ee0f1853fe5e63036d044fea77d /include/uskel.s | |
| parent | 46d84e91ebe48ade19bd3f5e18360bf853b53968 (diff) | |
| download | uskel-74cad993376dc269e8389fbf150be9ecc36890c7.tar.gz uskel-74cad993376dc269e8389fbf150be9ecc36890c7.tar.bz2 | |
fibs work
Diffstat (limited to 'include/uskel.s')
| -rw-r--r-- | include/uskel.s | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/include/uskel.s b/include/uskel.s new file mode 100644 index 0000000..136b382 --- /dev/null +++ b/include/uskel.s @@ -0,0 +1,54 @@ + +# uskel runtime and start; include this at the top. + +.section .init +.global _start +_start: + jmp _uskel_start + +.include "include/macros.s" + +.section .bss +_memory_state: + cell 0 # bottom of allocation (grows down) + cell 0 # region start + cell 0 # region end + cell 0 # program entry rsp (aka the actual stack) + +.section .text + +_uskel_alloc_basic_mem: + mov $0x100000, %r15 # desired size + + mov $0x9, %rax # mmap + mov $0, %rdi # addr = NULL + mov %r15, %rsi # len = %rcx + mov $0x3, %rdx # prot = PROT_READ 0x1 | PROT_WRITE 0x2 + mov $0x22, %r10 # flags = MAP_PRIVATE 0x2 | MAP_ANONYMOUS 0x20 + mov $-1, %r8 # fd = -1 + mov $0, %r9 # off = 0 + syscall + mov $_memory_state, %rdi + mov %rax, 010(%rdi) + add %r15, %rax + mov %rax, (%rdi) + mov %rax, 020(%rdi) + retq + +_uskel_start: + call _uskel_alloc_basic_mem + # use the stack pointer for easy writing to the heap, + # but back it up to memory state + mov $_memory_state, %rdi + mov %rsp, 030(%rdi) + mov 0(%rdi), %rsp + + # 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) + # (needs validation) |
