Luna/apps/init.asm

95 lines
1.4 KiB
NASM
Raw Normal View History

2022-09-30 15:43:14 +00:00
section .text
global _start
_start:
2022-10-01 15:32:50 +00:00
call gettid
cmp rax, 0
jne .continue ; shenanigans: init is tid 0 (which is normally reserved for the idle task)
mov rdi, shenanigans_label
call print
jmp .end
.continue:
mov rdi, welcome_label
call print
call next_line
mov rdi, 1000
call sleep
mov rdi, version_label
call print
2022-10-01 15:32:50 +00:00
call get_version
mov rdi, uname
call print
call next_line
call next_line
mov rdi, 2000
call sleep
mov rdi, end_label
call print
2022-10-01 15:32:50 +00:00
.end:
call exit
2022-10-01 15:32:50 +00:00
gettid:
mov rax, 7
int 42h
ret
sleep:
mov rax, 2
int 42h
ret
strlen:
push rbx
push rcx
mov rbx, rdi
xor al, al
mov rcx, 0xffffffff
repne scasb
sub rdi, rbx
mov rax, rdi
pop rcx
pop rbx
dec rax
ret
print: ; string: rdi
push rdi
call strlen
mov rsi, rax
mov rax, 3
pop rdi
int 42h
ret
next_line:
mov rdi, newline
mov rsi, 1
mov rax, 3
int 42h
ret
exit:
2022-09-30 15:43:14 +00:00
mov rax, 0
int 42h
2022-10-01 15:32:50 +00:00
get_version:
mov rdi, uname
mov rsi, 40
mov rax, 6
int 42h
ret
section .rodata
version_label:
2022-10-01 15:32:50 +00:00
db "Your kernel version is ", 0
welcome_label:
db "Welcome to Luna!", 0xA, 0
end_label:
db "Press any key to restart.", 0xA, 0
2022-10-01 15:32:50 +00:00
shenanigans_label:
db "SHENANIGANS: init is tid 0 (reserved for the idle task)", 0xA, 0
newline:
2022-10-01 15:32:50 +00:00
db 0xA
section .bss
uname:
resb 40