-
Notifications
You must be signed in to change notification settings - Fork 1
/
syscalls.h
147 lines (129 loc) · 2.77 KB
/
syscalls.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
;;
;; MC404ABCD - 2008s2
;; Projeto 2
;; decompify - COM files disassembler for Linux.
;;
;; 071294 - Jorge Augusto Hongo
;; 072201 - Raphael Kubo da Costa
;;
;; Copyright (C) 2008 Jorge Augusto Hongo
;; Copyright (C) 2008 Raphael Kubo da Costa
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
%ifndef _SYSCALLS_H
%define _SYSCALLS_H
; Syscall numbers
%define SYS_EXIT 1
%define SYS_READ 3
%define SYS_WRITE 4
%define SYS_OPEN 5
%define SYS_CLOSE 6
%define SYS_LSEEK 19
; Interrupt
%define LINUX_CALL 0x80
; Default stream numbers
%define STDIN 0
%define STDOUT 1
; The following error codes were taken from <sysexits.h>
%define EX_OK 0
%define EX_USAGE 64
%define EX_DATAERR 65
; File access modes
%define O_RDONLY 0
%define O_WRONLY 1
%define O_RDWR 2
%define O_CREAT 100q
%define O_TRUNC 1000q
; Seek constants
%define SEEK_SET 0
%define SEEK_CUR 1
%define SEEK_END 2
; Modes
%define S_IRWXU 00700q
%define S_IRUSR 00400q
%define S_IWUSR 00200q
%define S_IXUSR 00100q
%define S_IRWXG 00070q
%define S_IRGRP 00040q
%define S_IWGRP 00020q
%define S_IXGRP 00010q
%define S_IRWXO 00007q
%define S_IROTH 00004q
%define S_IWOTH 00002q
%define S_IXOTH 00001q
%macro sys_close 1
push ebx
mov eax, SYS_CLOSE
mov ebx, %1
int LINUX_CALL
pop ebx
%endmacro
%macro sys_exit 0-1 0
mov eax, SYS_EXIT
mov ebx, %1
int LINUX_CALL
%endmacro
%macro sys_open 1-3 O_RDONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
push ebx
mov eax, SYS_OPEN
mov ebx, %1
mov ecx, %2
mov edx, %3
int LINUX_CALL
pop ebx
%endmacro
%macro sys_lseek 2-3 SEEK_SET
push ebx
push ecx
push edx
mov eax, SYS_LSEEK
mov ebx, %1
mov ecx, %2
mov edx, %3
int LINUX_CALL
pop edx
pop ecx
pop ebx
%endmacro
%macro sys_read 3
push ebx
push ecx
push edx
mov eax, SYS_READ
mov ebx, %1
mov ecx, %2
mov edx, %3
int LINUX_CALL
pop edx
pop ecx
pop ebx
%endmacro
%macro sys_write 3
push eax
push ebx
push ecx
push edx
mov eax, SYS_WRITE
mov ebx, %1
mov ecx, %2
mov edx, %3
int LINUX_CALL
pop edx
pop ecx
pop ebx
pop eax
%endmacro
%endif
; vim:syntax=nasm