summaryrefslogtreecommitdiff
path: root/main.asm
diff options
context:
space:
mode:
Diffstat (limited to 'main.asm')
-rw-r--r--main.asm59
1 files changed, 59 insertions, 0 deletions
diff --git a/main.asm b/main.asm
new file mode 100644
index 0000000..7644482
--- /dev/null
+++ b/main.asm
@@ -0,0 +1,59 @@
1include 'sys.asm'
2
3format ELF64 executable
4
5segment writable readable
6struc db [data]
7{
8 common
9 . db data
10 .size = $ - .
11}
12stat_msg db 'Get file stats', 10
13open_msg db 'Open file', 10
14read_msg db 'Read file', 10
15close_msg db 'Close file', 10
16msg_dn db ':', 10
17
18indexname db 'index.html'
19;; indexstat stat
20indexlen rq 1
21
22indexfd dd 0
23indexbuf dd ?
24indexbuf_len rq 1
25
26segment readable executable
27
28entry _main
29_main:
30 ls_write STDOUT, open_msg, open_msg.size
31 ls_open indexname, O_RDONLY, 0
32 mov qword [indexfd], rax
33 cmp [indexfd], 0
34 jl error
35
36 ls_write STDOUT, read_msg, read_msg.size
37 ls_read qword [indexfd], indexbuf, indexbuf_len
38 cmp qword rax, 0
39 jl error
40 mov [indexlen], rax
41
42 ls_write STDOUT, close_msg, close_msg.size
43 ls_close qword [indexfd]
44 cmp qword rax, 0
45 jl error
46
47 ls_write STDOUT, indexname, indexname.size
48 ls_write STDOUT, msg_dn, msg_dn.size
49 ls_write STDOUT, indexbuf, [indexlen]
50 cmp qword rax, 0
51 jl error
52
53
54
55 ls_exit 0
56
57error:
58 ls_close qword [indexfd]
59 ls_exit 1