diff options
author | fxqnlr <[email protected]> | 2024-09-19 20:06:53 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-19 20:06:53 +0200 |
commit | f0b8e96b51b1a8b19365c9d010639c8d67a42506 (patch) | |
tree | 36a217aa03f7174ddfdbb34736f2288072bda4af | |
download | asmsite-f0b8e96b51b1a8b19365c9d010639c8d67a42506.tar asmsite-f0b8e96b51b1a8b19365c9d010639c8d67a42506.tar.gz asmsite-f0b8e96b51b1a8b19365c9d010639c8d67a42506.zip |
initial commit
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | index.html | 9 | ||||
-rw-r--r-- | main.asm | 59 | ||||
-rw-r--r-- | recources.md | 3 | ||||
-rw-r--r-- | sys.asm | 68 |
6 files changed, 147 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e36c9ec --- /dev/null +++ b/.gitignore | |||
@@ -0,0 +1,4 @@ | |||
1 | gf/ | ||
2 | fasm/ | ||
3 | main | ||
4 | *.c | ||
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e01d065 --- /dev/null +++ b/Makefile | |||
@@ -0,0 +1,4 @@ | |||
1 | make: | ||
2 | ./fasm/fasm main.asm | ||
3 | chmod +x main | ||
4 | ./main | ||
diff --git a/index.html b/index.html new file mode 100644 index 0000000..9175f0f --- /dev/null +++ b/index.html | |||
@@ -0,0 +1,9 @@ | |||
1 | <html> | ||
2 | <head> | ||
3 | <title>asmsite</title> | ||
4 | </head> | ||
5 | |||
6 | <body> | ||
7 | <h1>Hello World</h1> | ||
8 | </body> | ||
9 | </html> | ||
diff --git a/main.asm b/main.asm new file mode 100644 index 0000000..7644482 --- /dev/null +++ b/main.asm | |||
@@ -0,0 +1,59 @@ | |||
1 | include 'sys.asm' | ||
2 | |||
3 | format ELF64 executable | ||
4 | |||
5 | segment writable readable | ||
6 | struc db [data] | ||
7 | { | ||
8 | common | ||
9 | . db data | ||
10 | .size = $ - . | ||
11 | } | ||
12 | stat_msg db 'Get file stats', 10 | ||
13 | open_msg db 'Open file', 10 | ||
14 | read_msg db 'Read file', 10 | ||
15 | close_msg db 'Close file', 10 | ||
16 | msg_dn db ':', 10 | ||
17 | |||
18 | indexname db 'index.html' | ||
19 | ;; indexstat stat | ||
20 | indexlen rq 1 | ||
21 | |||
22 | indexfd dd 0 | ||
23 | indexbuf dd ? | ||
24 | indexbuf_len rq 1 | ||
25 | |||
26 | segment readable executable | ||
27 | |||
28 | entry _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 | |||
57 | error: | ||
58 | ls_close qword [indexfd] | ||
59 | ls_exit 1 | ||
diff --git a/recources.md b/recources.md new file mode 100644 index 0000000..d1199b6 --- /dev/null +++ b/recources.md | |||
@@ -0,0 +1,3 @@ | |||
1 | # Links | ||
2 | * [syscall table](https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/) | ||
3 | * [manual](https://flatassembler.net/docs.php?article=manual#1.2.6) | ||
@@ -0,0 +1,68 @@ | |||
1 | STDIN equ 0 | ||
2 | STDOUT equ 1 | ||
3 | STDERR equ 2 | ||
4 | |||
5 | O_RDONLY equ 0 | ||
6 | O_WRONLY equ 1 | ||
7 | O_RDWR equ 2 | ||
8 | |||
9 | macro scall1 v_rax, v_rdi | ||
10 | { | ||
11 | mov rax, v_rax | ||
12 | mov rdi, v_rdi | ||
13 | syscall | ||
14 | } | ||
15 | |||
16 | macro scall2 v_rax, v_rdi, v_rsi | ||
17 | { | ||
18 | mov rax, v_rax | ||
19 | mov rdi, v_rdi | ||
20 | mov rsi, v_rsi | ||
21 | syscall | ||
22 | } | ||
23 | |||
24 | macro scall3 v_rax, v_rdi, v_rsi, v_rdx | ||
25 | { | ||
26 | mov rax, v_rax | ||
27 | mov rdi, v_rdi | ||
28 | mov rsi, v_rsi | ||
29 | mov rdx, v_rdx | ||
30 | syscall | ||
31 | } | ||
32 | |||
33 | macro ls_read fd, buf, count { scall3 0, fd, buf, count } | ||
34 | |||
35 | macro ls_write fd, buf, count { scall3 1, fd, buf, count } | ||
36 | |||
37 | macro ls_open filename, flags, mode { scall3 2, filename, flags, mode } | ||
38 | |||
39 | macro ls_close fd { scall1 3, fd } | ||
40 | |||
41 | ;; kernel: arch/x86/include/uapi/asm/stat.h | ||
42 | ;; struc stat | ||
43 | ;; { | ||
44 | ;; .st_dev rd 1 | ||
45 | ;; .st_ino rd 1 | ||
46 | ;; .st_mode rw 1 | ||
47 | ;; .st_nlink rw 1 | ||
48 | ;; .st_uid rw 1 | ||
49 | ;; .st_gid rw 1 | ||
50 | ;; .st_rdev rd 1 | ||
51 | ;; .st_size rd 1 | ||
52 | ;; .st_blksize rd 1 | ||
53 | ;; .st_blocks rd 1 | ||
54 | ;; | ||
55 | ;; .st_atime rd 1 | ||
56 | ;; .st_atime_nsec rd 1 | ||
57 | ;; .st_mtime rd 1 | ||
58 | ;; .st_mtime_nsec rd 1 | ||
59 | ;; .st_ctime rd 1 | ||
60 | ;; .st_ctime_nsec rd 1 | ||
61 | ;; | ||
62 | ;; .__unused4 rd 1 | ||
63 | ;; .__unused5 rd 1 | ||
64 | ;; } | ||
65 | macro ls_stat filename, statbuf { scall2 4, filename, statbuf } | ||
66 | |||
67 | macro ls_exit status { scall1 60, status } | ||
68 | |||