implement prover stdin reading
This commit is contained in:
@@ -67,6 +67,7 @@ iso:
|
|||||||
cp grubshit/callee2 katauos/katau/callee2
|
cp grubshit/callee2 katauos/katau/callee2
|
||||||
|
|
||||||
cp grubshit/zsh katauos/katau/zsh
|
cp grubshit/zsh katauos/katau/zsh
|
||||||
|
cp grubshit/ksh katauos/katau/ksh
|
||||||
|
|
||||||
sudo umount tmp/
|
sudo umount tmp/
|
||||||
grub-mkrescue -o boot.iso katauos/
|
grub-mkrescue -o boot.iso katauos/
|
||||||
|
|||||||
@@ -3,7 +3,14 @@
|
|||||||
|
|
||||||
#include "../include/utils.h"
|
#include "../include/utils.h"
|
||||||
#include "../include/stdio.h"
|
#include "../include/stdio.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#define STDIN_BUFFER_SIZE 4096
|
||||||
|
extern char stdin_buffer[STDIN_BUFFER_SIZE];
|
||||||
|
extern int stdin_pos;
|
||||||
|
extern bool stdin_has_line;
|
||||||
|
|
||||||
void handle_keyboard();
|
void handle_keyboard();
|
||||||
|
void init_keyboard();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ typedef enum TaskState
|
|||||||
Terminated
|
Terminated
|
||||||
} TaskState;
|
} TaskState;
|
||||||
|
|
||||||
|
enum WaitingReason {
|
||||||
|
NONE,
|
||||||
|
TIMER,
|
||||||
|
STDIN,
|
||||||
|
};
|
||||||
|
|
||||||
typedef void (*EntryPoint)(void);
|
typedef void (*EntryPoint)(void);
|
||||||
|
|
||||||
// Структура контекста для переключения между процессами
|
// Структура контекста для переключения между процессами
|
||||||
@@ -71,6 +77,7 @@ typedef struct Process
|
|||||||
|
|
||||||
uint32_t kstack_top;
|
uint32_t kstack_top;
|
||||||
size_t wake_up_time;//wake up time in ticks of the processor, gets set by nanosleep syscall
|
size_t wake_up_time;//wake up time in ticks of the processor, gets set by nanosleep syscall
|
||||||
|
enum WaitingReason waiting_reason;
|
||||||
} Process;
|
} Process;
|
||||||
|
|
||||||
extern Process* current;
|
extern Process* current;
|
||||||
|
|||||||
+57
-30
@@ -1,5 +1,11 @@
|
|||||||
#include "../include/keyboard.h"
|
#include "../include/keyboard.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "../include/task.h"
|
||||||
|
#include "../include/string.h"
|
||||||
|
|
||||||
|
char stdin_buffer[STDIN_BUFFER_SIZE];
|
||||||
|
int stdin_pos = 0;
|
||||||
|
bool stdin_has_line = false;
|
||||||
|
|
||||||
unsigned char kbdus[128] =
|
unsigned char kbdus[128] =
|
||||||
{
|
{
|
||||||
@@ -87,39 +93,60 @@ bool caps_pressed;
|
|||||||
|
|
||||||
void keyboard_wait();
|
void keyboard_wait();
|
||||||
|
|
||||||
void handle_keyboard()
|
void handle_keyboard() {
|
||||||
{//3a
|
uint8_t scancode = inb(0x60);
|
||||||
uint8_t scancode = inb(0x60);
|
|
||||||
|
|
||||||
if(scancode & 0x80)//key released
|
if (scancode & 0x80) { // Released
|
||||||
{
|
scancode -= 0x80;
|
||||||
scancode = scancode-0x80;
|
if (scancode == 0x2A || scancode == 0x36) shift_pressed = false;
|
||||||
if(scancode == 0x2a || scancode == 0x36)
|
} else { // Pressed
|
||||||
shift_pressed = false;
|
if (scancode == 0x2A || scancode == 0x36) {
|
||||||
//printf("(%X)%c released ", scancode, kbdus[scancode-0x80]);
|
shift_pressed = true;
|
||||||
}
|
return;
|
||||||
else//key pressed
|
}
|
||||||
{
|
if (scancode == 0x3A) { // Caps
|
||||||
if(scancode == 0x2a || scancode == 0x36)
|
return;
|
||||||
{
|
}
|
||||||
shift_pressed = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(scancode == 0x3a)
|
char c;
|
||||||
{
|
if (shift_pressed || caps_pressed) c = kbdus2[scancode];
|
||||||
caps_pressed = !caps_pressed;
|
else c = kbdus[scancode];
|
||||||
outb(0x60, 0xed);//set LED command
|
|
||||||
keyboard_wait();
|
|
||||||
outb(0x60, caps_pressed << 2);//0 is scroll lock, 1 is numlock, 2 is caps lock
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(shift_pressed || caps_pressed)
|
if (c == '\b') { //Backspace
|
||||||
printf("%c", kbdus2[scancode]);
|
if (stdin_pos > 0) {
|
||||||
else
|
stdin_pos--;
|
||||||
printf("%c", kbdus[scancode]); //printf("(0x%X)%c", scancode, kbdus[scancode]);
|
printf("\b \b");
|
||||||
}
|
}
|
||||||
|
} else if (c == '\n') { // Enter
|
||||||
|
if (stdin_pos < STDIN_BUFFER_SIZE - 1) {
|
||||||
|
stdin_buffer[stdin_pos++] = '\n';
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
stdin_has_line = true;
|
||||||
|
|
||||||
|
// Wake-up: wake up all Waiting tasks on STDIN
|
||||||
|
scheduler_lock();
|
||||||
|
Process *p = queue;
|
||||||
|
while (p) {
|
||||||
|
if (p->state == Waiting && p->waiting_reason == STDIN) {
|
||||||
|
p->state = Ready;
|
||||||
|
p->waiting_reason = NONE;
|
||||||
|
}
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
scheduler_unlock();
|
||||||
|
} else if (c != 0 && stdin_pos < STDIN_BUFFER_SIZE - 1) {//if printable
|
||||||
|
stdin_buffer[stdin_pos++] = c;
|
||||||
|
printf("%c", c);//echo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_keyboard()
|
||||||
|
{
|
||||||
|
memset(stdin_buffer, 0, STDIN_BUFFER_SIZE);
|
||||||
|
stdin_pos = 0;
|
||||||
|
stdin_has_line = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void keyboard_wait()
|
void keyboard_wait()
|
||||||
|
|||||||
+4
-1
@@ -16,6 +16,7 @@
|
|||||||
#include "../include/atapi.h"
|
#include "../include/atapi.h"
|
||||||
#include "../include/vfs.h"
|
#include "../include/vfs.h"
|
||||||
#include "../include/apic.h"
|
#include "../include/apic.h"
|
||||||
|
#include "../include/keyboard.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@@ -131,10 +132,12 @@ void kmain(unsigned int magic, unsigned int info)
|
|||||||
|
|
||||||
mount_fs();
|
mount_fs();
|
||||||
|
|
||||||
|
init_keyboard();
|
||||||
|
|
||||||
l9660_dir dir;
|
l9660_dir dir;
|
||||||
l9660_file file;
|
l9660_file file;
|
||||||
|
|
||||||
follow_path("/katau/dash.", &file, &dir);
|
follow_path("/katau/ksh.", &file, &dir);
|
||||||
|
|
||||||
exec_from_file(&file, &dir);
|
exec_from_file(&file, &dir);
|
||||||
|
|
||||||
|
|||||||
+43
-6
@@ -152,19 +152,55 @@ int sys_fork(TrapFrame *tf)
|
|||||||
return child->pid;
|
return child->pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "../../include/keyboard.h"
|
||||||
int sys_read(TrapFrame *tf)
|
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
|
else
|
||||||
{
|
{
|
||||||
if(current->file_descriptors[tf->ebx] == NULL)
|
if(current->file_descriptors[fd] == NULL)
|
||||||
{
|
{
|
||||||
return -EBADF;
|
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);
|
//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);
|
//strcpy((char*)tf->ebx, current->cwd->fat->path);
|
||||||
|
|
||||||
return tf->ebx;
|
return strlen(final_path);//tf->ebx;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sys_getpid(TrapFrame *tf)
|
int sys_getpid(TrapFrame *tf)
|
||||||
@@ -551,6 +587,7 @@ uint32_t sys_nanosleep(TrapFrame *tf)
|
|||||||
scheduler_lock();
|
scheduler_lock();
|
||||||
current->wake_up_time = timer_ticks + ms;
|
current->wake_up_time = timer_ticks + ms;
|
||||||
current->state = Waiting;
|
current->state = Waiting;
|
||||||
|
current->waiting_reason = TIMER;
|
||||||
schedule();
|
schedule();
|
||||||
scheduler_unlock();
|
scheduler_unlock();
|
||||||
|
|
||||||
@@ -566,7 +603,7 @@ void handle_syscall(TrapFrame *tf)
|
|||||||
debug_log("EDX: %X\n", tf->edx);
|
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)
|
switch(tf->eax)
|
||||||
{
|
{
|
||||||
|
|||||||
+5
-2
@@ -106,8 +106,11 @@ void schedule() {
|
|||||||
// Step 1: Iterate through all processes to wake up any that are due.
|
// Step 1: Iterate through all processes to wake up any that are due.
|
||||||
Process* p = queue;
|
Process* p = queue;
|
||||||
while (p) {
|
while (p) {
|
||||||
if (p->state == Waiting && timer_ticks >= p->wake_up_time) {
|
if(p->state == Waiting){
|
||||||
p->state = Ready;
|
if (p->waiting_reason == TIMER && timer_ticks >= p->wake_up_time) {
|
||||||
|
p->state = Ready;
|
||||||
|
p->waiting_reason = NONE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user