implement prover stdin reading
This commit is contained in:
+43
-6
@@ -152,19 +152,55 @@ int sys_fork(TrapFrame *tf)
|
||||
return child->pid;
|
||||
}
|
||||
|
||||
#include "../../include/keyboard.h"
|
||||
int sys_read(TrapFrame *tf)
|
||||
{
|
||||
if(tf->ebx < 3)
|
||||
int fd = tf->ebx;
|
||||
char *user_buf = (char *)tf->ecx;
|
||||
size_t count = tf->edx;
|
||||
|
||||
if (fd == STDIN_FILENO) {
|
||||
scheduler_lock();
|
||||
while (!stdin_has_line) {//while enter has not been pressed
|
||||
current->state = Waiting;
|
||||
current->waiting_reason = STDIN;
|
||||
schedule();
|
||||
}
|
||||
scheduler_unlock();
|
||||
|
||||
//find the pos of the first \n
|
||||
int line_len = 0;
|
||||
while (line_len < stdin_pos && stdin_buffer[line_len] != '\n') line_len++;
|
||||
if (line_len < stdin_pos) line_len++;
|
||||
|
||||
//copy the input to the user buffer
|
||||
int to_copy = (line_len < count) ? line_len : count;
|
||||
memcpy(user_buf, stdin_buffer, to_copy);
|
||||
|
||||
memmove(stdin_buffer, stdin_buffer + to_copy, stdin_pos - to_copy);
|
||||
stdin_pos -= to_copy;
|
||||
|
||||
stdin_has_line = false;
|
||||
for (int i = 0; i < stdin_pos; i++) {
|
||||
if (stdin_buffer[i] == '\n') {
|
||||
stdin_has_line = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return to_copy;
|
||||
}
|
||||
else if(fd < 3)
|
||||
{
|
||||
//TODO: implement stdin handling here
|
||||
return -EBADF;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(current->file_descriptors[tf->ebx] == NULL)
|
||||
if(current->file_descriptors[fd] == NULL)
|
||||
{
|
||||
return -EBADF;
|
||||
}
|
||||
return vfs_read_file_length(current->file_descriptors[tf->ebx], (uint8_t*)tf->ecx, tf->edx);
|
||||
return vfs_read_file_length(current->file_descriptors[fd], (uint8_t*)user_buf, count);
|
||||
//return 0;//fat_fread(current->file_descriptors[tf->ebx], (void*)tf->ecx, tf->edx);
|
||||
}
|
||||
}
|
||||
@@ -497,7 +533,7 @@ uint32_t sys_getcwd(TrapFrame *tf)
|
||||
|
||||
//strcpy((char*)tf->ebx, current->cwd->fat->path);
|
||||
|
||||
return tf->ebx;
|
||||
return strlen(final_path);//tf->ebx;
|
||||
}
|
||||
|
||||
int sys_getpid(TrapFrame *tf)
|
||||
@@ -551,6 +587,7 @@ uint32_t sys_nanosleep(TrapFrame *tf)
|
||||
scheduler_lock();
|
||||
current->wake_up_time = timer_ticks + ms;
|
||||
current->state = Waiting;
|
||||
current->waiting_reason = TIMER;
|
||||
schedule();
|
||||
scheduler_unlock();
|
||||
|
||||
@@ -566,7 +603,7 @@ void handle_syscall(TrapFrame *tf)
|
||||
debug_log("EDX: %X\n", tf->edx);
|
||||
*/
|
||||
|
||||
debug_log("calling 0x%X\n", tf->eax);
|
||||
//debug_log("calling 0x%X\n", tf->eax);
|
||||
|
||||
switch(tf->eax)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user