Add read support for mips
This commit is contained in:
parent
8a01908b1c
commit
6a51f8851b
16
arch/mips.c
16
arch/mips.c
@ -28,7 +28,21 @@ intptr_t write(int32_t fd, const void* buf, intptr_t size){
|
|||||||
);
|
);
|
||||||
return n_written;
|
return n_written;
|
||||||
}
|
}
|
||||||
//intptr_t read(int32_t fd, const void* buf, intptr_t size);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t fork(){
|
uint32_t fork(){
|
||||||
int rtn;
|
int rtn;
|
||||||
|
|||||||
@ -25,14 +25,12 @@ int main() {
|
|||||||
if(pid == 0) return 0;
|
if(pid == 0) return 0;
|
||||||
//TODO: wait on child to remove zombie process
|
//TODO: wait on child to remove zombie process
|
||||||
|
|
||||||
#if defined(__x86_64__) || defined(__aarch64__)
|
|
||||||
// Test the read syscall
|
// Test the read syscall
|
||||||
#define INPUT_BUFFER_LEN 4096
|
#define INPUT_BUFFER_LEN 4096
|
||||||
char input_buffer[INPUT_BUFFER_LEN] = {0};
|
char input_buffer[INPUT_BUFFER_LEN] = {0};
|
||||||
write(STDIO, "Enter some text:", 16);
|
write(STDIO, "Enter some text:", 16);
|
||||||
intptr_t n_read = read(STDIO, input_buffer, INPUT_BUFFER_LEN);
|
intptr_t n_read = read(STDIO, input_buffer, INPUT_BUFFER_LEN);
|
||||||
write(STDIO, input_buffer, n_read);
|
write(STDIO, input_buffer, n_read);
|
||||||
#endif
|
|
||||||
|
|
||||||
return 69;
|
return 69;
|
||||||
}
|
}
|
||||||
|
|||||||
2
sys.h
2
sys.h
@ -6,9 +6,7 @@ void exit(int8_t status);
|
|||||||
#define STDIO 1
|
#define STDIO 1
|
||||||
#define STDERR 2
|
#define STDERR 2
|
||||||
intptr_t write(int32_t fd, const void* buf, intptr_t size);
|
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);
|
intptr_t read(int32_t fd, const void* buf, intptr_t size);
|
||||||
#endif
|
|
||||||
|
|
||||||
uint32_t fork();
|
uint32_t fork();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user