Compare commits
No commits in common. "bd9a3d3b99a11e50c2f08716d2384a7a835ade36" and "6a51f8851b10f5e0fa5ff8584fac1336c49ea1ca" have entirely different histories.
bd9a3d3b99
...
6a51f8851b
@ -48,7 +48,7 @@ intptr_t read(int32_t fd, const void* buf, intptr_t size){
|
||||
// Input operands
|
||||
: "r"((int64_t)fd), "r" (buf), "r"(size)
|
||||
// Clobbered registers
|
||||
: "x0", "x1", "x2", "x8", "memory"
|
||||
: "x0", "x1", "x2", "x8"
|
||||
);
|
||||
return n_read;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ intptr_t read(int32_t fd, const void* buf, intptr_t size){
|
||||
"move %0, $v0\n"
|
||||
: "=r"(n_read)
|
||||
: "r"(fd), "r"(buf), "r"(size)
|
||||
: "a0", "a1", "a2", "v0", "memory" //TODO: temp registers clobbered by syscall should probably also be listed but this fn returns right away so it should be fine?
|
||||
: "a0", "a1", "a2", "v0" //TODO: temp registers clobbered by syscall should probably also be listed but this fn returns right away so it should be fine?
|
||||
);
|
||||
return n_read;
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ intptr_t write(int32_t fd, const void* buf, intptr_t size) {
|
||||
"movq %0, %%rax\n"
|
||||
: "=r"(n_written)
|
||||
: "a"(SYS_WRITE), "D"(fd), "S"(buf), "d"(size) // RDI, RSI, RDX are used in x86-64 for write args
|
||||
: "rcx", "r11"
|
||||
: "rcx", "r11", "memory"
|
||||
);
|
||||
return n_written;
|
||||
}
|
||||
@ -50,18 +50,4 @@ uint32_t fork() {
|
||||
);
|
||||
return (uint32_t)rtn;
|
||||
}
|
||||
|
||||
#define SYS_OPENAT 257
|
||||
int32_t openat(int32_t fd, const char* filename, uint32_t flags, uint32_t mode) {
|
||||
int32_t file;
|
||||
asm volatile (
|
||||
"mov %%r10, %5\n"
|
||||
"syscall\n"
|
||||
: "=a"(file)
|
||||
: "a"(SYS_OPENAT), "D"(fd), "S"(filename), "d"(flags), "r"((uint64_t)mode) // RDI, RSI, RDX are used in x86-64 for write args
|
||||
: "rcx", "r10", "r11"
|
||||
);
|
||||
return file;
|
||||
}
|
||||
|
||||
#endif /* ifdef __x86_64__ */
|
||||
|
||||
@ -32,15 +32,6 @@ int main() {
|
||||
intptr_t n_read = read(STDIO, input_buffer, INPUT_BUFFER_LEN);
|
||||
write(STDIO, input_buffer, n_read);
|
||||
|
||||
// Test the open syscall
|
||||
#if defined(__x86_64__)
|
||||
int32_t file = open("/proc/version", O_RDONLY);
|
||||
int i = read(file, input_buffer, INPUT_BUFFER_LEN);
|
||||
while(i > 0) {
|
||||
write(STDIO, input_buffer, i);
|
||||
i = read(file, input_buffer, INPUT_BUFFER_LEN);
|
||||
}
|
||||
#endif
|
||||
return 69;
|
||||
}
|
||||
|
||||
|
||||
10
sys.h
10
sys.h
@ -8,16 +8,6 @@ void exit(int8_t status);
|
||||
intptr_t write(int32_t fd, const void* buf, intptr_t size);
|
||||
intptr_t read(int32_t fd, const void* buf, intptr_t size);
|
||||
|
||||
#define O_RDONLY 00
|
||||
#define O_WRONLY 01
|
||||
#define O_RDWR 02
|
||||
#define AT_FDCWD -100
|
||||
int32_t openat(int32_t fd, const char* filename, uint32_t flags, uint32_t mode);
|
||||
#define open(...) openat(AT_FDCWD, __VA_ARGS__, 0)
|
||||
//inline int32_t openat(int32_t fd, const char* filename, uint32_t flags) {return openat(fd, filename, flags, 0);}
|
||||
//inline int32_t open(const char* filename, uint32_t flags, uint32_t mode) {return openat(AT_FDCWD, filename, flags, mode);}
|
||||
//inline int32_t open(const char* filename, uint32_t flags) {return openat(AT_FDCWD, filename, flags, 0);}
|
||||
|
||||
uint32_t fork();
|
||||
|
||||
// Provide memset for clang
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user