syscalls: implement read syscall
This commit is contained in:
@@ -46,6 +46,22 @@ const char* flags_to_mode_str(int flags) {
|
||||
return mode;
|
||||
}
|
||||
|
||||
int sys_read(TrapFrame *tf)
|
||||
{
|
||||
if(tf->ebx < 3)
|
||||
{
|
||||
//TODO: implement stdin handling here
|
||||
}
|
||||
else
|
||||
{
|
||||
if(current->file_descriptors[tf->ebx] == NULL)
|
||||
{
|
||||
return -EBADF;
|
||||
}
|
||||
return fat_fread(current->file_descriptors[tf->ebx], (void*)tf->ecx, tf->edx);
|
||||
}
|
||||
}
|
||||
|
||||
int sys_write(TrapFrame *tf)
|
||||
{
|
||||
if(tf->ebx < 3)
|
||||
@@ -53,7 +69,9 @@ int sys_write(TrapFrame *tf)
|
||||
//stdin, stdout or stderr
|
||||
if(tf->ebx == STDOUT_FILENO)
|
||||
{
|
||||
debug_log("\n=================SYS_WRITE output to stdout=====================\n");
|
||||
print((char*)tf->ecx, tf->edx);
|
||||
debug_log("\n=================END OF THAT SHIT=====================\n");
|
||||
tf->ecx++;
|
||||
}
|
||||
}
|
||||
@@ -102,9 +120,12 @@ int sys_open(TrapFrame *tf)
|
||||
int sys_close(TrapFrame *tf)
|
||||
{
|
||||
int fd = tf->ebx;
|
||||
debug_log("SYS_CLOSE: fd = 0x%X", fd);
|
||||
if(current->file_descriptors[fd] != NULL)
|
||||
{
|
||||
debug_log("SYS_CLOSE: current->file_descriptors[fd] != NULL");
|
||||
int result = fat_fclose(current->file_descriptors[fd]);
|
||||
debug_log("SYS_CLOSE: fat_fclose result: 0x%X", result);
|
||||
free(current->file_descriptors[fd]);
|
||||
current->file_descriptors[fd] = NULL;
|
||||
return result;
|
||||
@@ -120,6 +141,12 @@ void handle_syscall(TrapFrame *tf)
|
||||
debug_log("ECX: %s ", tf->ecx);
|
||||
debug_log("EDX: %X\n", tf->edx);
|
||||
|
||||
if(tf->eax == 3)//read
|
||||
{
|
||||
int r = sys_read(tf);
|
||||
tf->eax = r;
|
||||
}
|
||||
|
||||
if(tf->eax == 4)//write
|
||||
{
|
||||
int r = sys_write(tf);
|
||||
|
||||
Reference in New Issue
Block a user