Add support for fflush and close syscalls
This commit is contained in:
parent
f07d793e6c
commit
adfdaa27f7
@ -99,4 +99,32 @@ int32_t openat(int32_t fd, const char* filename, uint32_t flags, uint32_t mode)
|
||||
return (int32_t)rtn;
|
||||
}
|
||||
|
||||
int close(unsigned int fd){
|
||||
long int rtn;
|
||||
asm (
|
||||
"mov x0, %1\n"
|
||||
"mov x8, #57\n"
|
||||
"svc #0\n"
|
||||
"mov %0, x0\n"
|
||||
: "=r"(rtn)
|
||||
: "r" ((long)fd)
|
||||
: "x0", "x8"
|
||||
);
|
||||
return (int)rtn;
|
||||
}
|
||||
|
||||
int fsync(unsigned int fd){
|
||||
long int rtn;
|
||||
asm (
|
||||
"mov x0, %1\n"
|
||||
"mov x8, #82\n"
|
||||
"svc #0\n"
|
||||
"mov %0, x0\n"
|
||||
: "=r"(rtn)
|
||||
: "r" ((long)fd)
|
||||
: "x0", "x8"
|
||||
);
|
||||
return (int)rtn;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
28
arch/mips.c
28
arch/mips.c
@ -74,4 +74,32 @@ int32_t openat(int32_t fd, const char* filename, uint32_t flags, uint32_t mode)
|
||||
return file;
|
||||
}
|
||||
|
||||
int close(unsigned int fd){
|
||||
int rtn = 0;
|
||||
asm (
|
||||
"move $a0, %1\n"
|
||||
"li $v0, 4006\n"
|
||||
"syscall\n"
|
||||
"move %0, $v0\n"
|
||||
: "=r"(rtn)
|
||||
: "r" (fd)
|
||||
: "a0", "v0"
|
||||
);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
int fsync(unsigned int fd){
|
||||
int rtn = 0;
|
||||
asm (
|
||||
"move $a0, %1\n"
|
||||
"li $v0, 4118\n"
|
||||
"syscall\n"
|
||||
"move %0, $v0\n"
|
||||
: "=r"(rtn)
|
||||
: "r" (fd)
|
||||
: "a0", "v0"
|
||||
);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -64,4 +64,28 @@ int32_t openat(int32_t fd, const char* filename, uint32_t flags, uint32_t mode)
|
||||
return file;
|
||||
}
|
||||
|
||||
#define SYS_CLOSE 3
|
||||
int close(unsigned int fd) {
|
||||
int rtn;
|
||||
asm volatile(
|
||||
"syscall"
|
||||
: "=a"(rtn)
|
||||
: "a"(SYS_CLOSE), "D"(fd)
|
||||
: "rcx", "r11"
|
||||
);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
#define SYS_FSYNC 74
|
||||
int fsync(unsigned int fd) {
|
||||
int rtn;
|
||||
asm volatile(
|
||||
"syscall"
|
||||
: "=a"(rtn)
|
||||
: "a"(SYS_FSYNC), "D"(fd)
|
||||
: "rcx", "r11"
|
||||
);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
#endif /* ifdef __x86_64__ */
|
||||
|
||||
@ -35,6 +35,8 @@ int main() {
|
||||
write(STDOUT, input_buffer, n_read);
|
||||
if(fout > 0) {
|
||||
write(fout, input_buffer, n_read);
|
||||
fsync(fout);
|
||||
close(fout);
|
||||
}
|
||||
|
||||
// Test the open syscall
|
||||
|
||||
2
sys.h
2
sys.h
@ -32,6 +32,8 @@ intptr_t read(int32_t fd, const void* buf, intptr_t size);
|
||||
int32_t openat(int32_t fd, const char* filename, uint32_t flags, uint32_t mode);
|
||||
#define open(...) openat(AT_FDCWD, __VA_ARGS__, 0)
|
||||
#define openc(...) openat(AT_FDCWD, __VA_ARGS__)
|
||||
int close(unsigned int fd);
|
||||
int fsync(unsigned int fd);
|
||||
|
||||
uint32_t fork();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user