summaryrefslogtreecommitdiff
path: root/sys.asm
blob: b9ab19090f86009f54985e5b2e6e1b575af0f280 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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 }