From f0b8e96b51b1a8b19365c9d010639c8d67a42506 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 19 Sep 2024 20:06:53 +0200 Subject: initial commit --- main.asm | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 main.asm (limited to 'main.asm') diff --git a/main.asm b/main.asm new file mode 100644 index 0000000..7644482 --- /dev/null +++ b/main.asm @@ -0,0 +1,59 @@ +include 'sys.asm' + +format ELF64 executable + +segment writable readable +struc db [data] +{ + common + . db data + .size = $ - . +} +stat_msg db 'Get file stats', 10 +open_msg db 'Open file', 10 +read_msg db 'Read file', 10 +close_msg db 'Close file', 10 +msg_dn db ':', 10 + +indexname db 'index.html' +;; indexstat stat +indexlen rq 1 + +indexfd dd 0 +indexbuf dd ? +indexbuf_len rq 1 + +segment readable executable + +entry _main +_main: + ls_write STDOUT, open_msg, open_msg.size + ls_open indexname, O_RDONLY, 0 + mov qword [indexfd], rax + cmp [indexfd], 0 + jl error + + ls_write STDOUT, read_msg, read_msg.size + ls_read qword [indexfd], indexbuf, indexbuf_len + cmp qword rax, 0 + jl error + mov [indexlen], rax + + ls_write STDOUT, close_msg, close_msg.size + ls_close qword [indexfd] + cmp qword rax, 0 + jl error + + ls_write STDOUT, indexname, indexname.size + ls_write STDOUT, msg_dn, msg_dn.size + ls_write STDOUT, indexbuf, [indexlen] + cmp qword rax, 0 + jl error + + + + ls_exit 0 + +error: + ls_close qword [indexfd] + ls_exit 1 -- cgit v1.2.3