Compare commits

..

No commits in common. "6a51f8851b10f5e0fa5ff8584fac1336c49ea1ca" and "a8594606c332daa15ee408a208ad7d06ccddfdee" have entirely different histories.

3 changed files with 11 additions and 22 deletions

View File

@ -15,34 +15,19 @@ void exit(int8_t status){
intptr_t write(int32_t fd, const void* buf, intptr_t size){
intptr_t n_written = 0;
asm volatile (
"move $a0, %1\n"
"move $a1, %2\n"
"move $a2, %3\n"
asm (
"move $a0, %2\n"
"move $a1, %0\n"
"move $a2, %1\n"
"li $v0, 4004\n"
"syscall\n"
"move %0, $v0\n"
: "=r"(n_written)
: "r"(fd), "r"(buf), "r"(size)
: //TODO: n_written
: "r"(buf), "r"(size), "r"(fd)
: "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_written;
}
intptr_t read(int32_t fd, const void* buf, intptr_t size){
intptr_t n_read = 0;
asm volatile (
"move $a0, %1\n"
"move $a1, %2\n"
"move $a2, %3\n"
"li $v0, 4004\n"
"syscall\n"
"move %0, $v0\n"
: "=r"(n_read)
: "r"(fd), "r"(buf), "r"(size)
: "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;
}
//intptr_t read(int32_t fd, const void* buf, intptr_t size);
uint32_t fork(){
int rtn;

View File

@ -25,12 +25,14 @@ int main() {
if(pid == 0) return 0;
//TODO: wait on child to remove zombie process
#if defined(__x86_64__) || defined(__aarch64__)
// Test the read syscall
#define INPUT_BUFFER_LEN 4096
char input_buffer[INPUT_BUFFER_LEN] = {0};
write(STDIO, "Enter some text:", 16);
intptr_t n_read = read(STDIO, input_buffer, INPUT_BUFFER_LEN);
write(STDIO, input_buffer, n_read);
#endif
return 69;
}

2
sys.h
View File

@ -6,7 +6,9 @@ void exit(int8_t status);
#define STDIO 1
#define STDERR 2
intptr_t write(int32_t fd, const void* buf, intptr_t size);
#if defined(__x86_64__) || defined(__aarch64__)
intptr_t read(int32_t fd, const void* buf, intptr_t size);
#endif
uint32_t fork();