From f0b8e96b51b1a8b19365c9d010639c8d67a42506 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 19 Sep 2024 20:06:53 +0200 Subject: initial commit --- sys.asm | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 sys.asm (limited to 'sys.asm') diff --git a/sys.asm b/sys.asm new file mode 100644 index 0000000..b9ab190 --- /dev/null +++ b/sys.asm @@ -0,0 +1,68 @@ +STDIN equ 0 +STDOUT equ 1 +STDERR equ 2 + +O_RDONLY equ 0 +O_WRONLY equ 1 +O_RDWR equ 2 + +macro scall1 v_rax, v_rdi +{ + mov rax, v_rax + mov rdi, v_rdi + syscall +} + +macro scall2 v_rax, v_rdi, v_rsi +{ + mov rax, v_rax + mov rdi, v_rdi + mov rsi, v_rsi + syscall +} + +macro scall3 v_rax, v_rdi, v_rsi, v_rdx +{ + mov rax, v_rax + mov rdi, v_rdi + mov rsi, v_rsi + mov rdx, v_rdx + syscall +} + +macro ls_read fd, buf, count { scall3 0, fd, buf, count } + +macro ls_write fd, buf, count { scall3 1, fd, buf, count } + +macro ls_open filename, flags, mode { scall3 2, filename, flags, mode } + +macro ls_close fd { scall1 3, fd } + +;; kernel: arch/x86/include/uapi/asm/stat.h +;; struc stat +;; { +;; .st_dev rd 1 +;; .st_ino rd 1 +;; .st_mode rw 1 +;; .st_nlink rw 1 +;; .st_uid rw 1 +;; .st_gid rw 1 +;; .st_rdev rd 1 +;; .st_size rd 1 +;; .st_blksize rd 1 +;; .st_blocks rd 1 +;; +;; .st_atime rd 1 +;; .st_atime_nsec rd 1 +;; .st_mtime rd 1 +;; .st_mtime_nsec rd 1 +;; .st_ctime rd 1 +;; .st_ctime_nsec rd 1 +;; +;; .__unused4 rd 1 +;; .__unused5 rd 1 +;; } +macro ls_stat filename, statbuf { scall2 4, filename, statbuf } + +macro ls_exit status { scall1 60, status } + -- cgit v1.2.3