forked from juserrrrr/SensorQueryInterface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileio.s
45 lines (39 loc) · 745 Bytes
/
fileio.s
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
@ Various macros to perform file I/O
@ The fd parameter needs to be a register.
@ Uses R0, R1, R7.
@ Return code is in R0.
.equ O_RDONLY, 0
.equ O_WRONLY, 1
.equ O_CREAT, 0100
.equ S_RDWR, 0666
.macro openFile fileName, flags
ldr r0, =\fileName
mov r1, #\flags
mov r2, #S_RDWR @ RW access rights
mov r7, #sys_open
svc 0
.endm
.macro readFile fd, buffer, length
mov r0, \fd @ file descriptor
ldr r1, =\buffer
mov r2, #\length
mov r7, #sys_read
svc 0
.endm
.macro writeFile fd, buffer, length
mov r0, \fd @ file descriptor
ldr r1, =\buffer
mov r2, \length
mov r7, #sys_write
svc 0
.endm
.macro flushClose fd
@fsync syscall
mov r0, \fd
mov r7, #sys_fsync
svc 0
@close syscall
mov r0, \fd
mov r7, #sys_close
svc 0
.endm