summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-19 20:06:53 +0200
committerfxqnlr <[email protected]>2024-09-19 20:06:53 +0200
commitf0b8e96b51b1a8b19365c9d010639c8d67a42506 (patch)
tree36a217aa03f7174ddfdbb34736f2288072bda4af
downloadasmsite-f0b8e96b51b1a8b19365c9d010639c8d67a42506.tar
asmsite-f0b8e96b51b1a8b19365c9d010639c8d67a42506.tar.gz
asmsite-f0b8e96b51b1a8b19365c9d010639c8d67a42506.zip
initial commit
-rw-r--r--.gitignore4
-rw-r--r--Makefile4
-rw-r--r--index.html9
-rw-r--r--main.asm59
-rw-r--r--recources.md3
-rw-r--r--sys.asm68
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 @@
1gf/
2fasm/
3main
4*.c
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e01d065
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,4 @@
1make:
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 @@
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
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)
diff --git a/sys.asm b/sys.asm
new file mode 100644
index 0000000..b9ab190
--- /dev/null
+++ b/sys.asm
@@ -0,0 +1,68 @@
1STDIN equ 0
2STDOUT equ 1
3STDERR equ 2
4
5O_RDONLY equ 0
6O_WRONLY equ 1
7O_RDWR equ 2
8
9macro scall1 v_rax, v_rdi
10{
11 mov rax, v_rax
12 mov rdi, v_rdi
13 syscall
14}
15
16macro 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
24macro 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
33macro ls_read fd, buf, count { scall3 0, fd, buf, count }
34
35macro ls_write fd, buf, count { scall3 1, fd, buf, count }
36
37macro ls_open filename, flags, mode { scall3 2, filename, flags, mode }
38
39macro 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;; }
65macro ls_stat filename, statbuf { scall2 4, filename, statbuf }
66
67macro ls_exit status { scall1 60, status }
68