Update TTY

This commit is contained in:
XIAOYI12 2024-08-31 23:46:21 +08:00
parent a6b044fe1c
commit 520c393187
5 changed files with 96 additions and 5 deletions

View File

@ -89,6 +89,21 @@ unsigned char shift_keyboard_map[128] =
0, /* All other keys are undefined */ 0, /* All other keys are undefined */
}; };
char keytable[0x54] = { // 按下Shift
0, 0x01, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\b', '\t', 'Q',
'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 10, 0, 'A', 'S', 'D', 'F',
'G', 'H', 'J', 'K', 'L', ':', '\"', '~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M',
'<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, '7', 'D', '8', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.'};
char keytable1[0x54] = { // 未按下Shift
0, 0x01, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', '\t', 'q',
'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 10, 0, 'a', 's', 'd', 'f',
'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm',
',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.'};
static void default_handle(uint32_t key,int release,char c){ static void default_handle(uint32_t key,int release,char c){
if(!release) { if(!release) {
if(key == 42) { if(key == 42) {
@ -146,8 +161,6 @@ int handle_keyboard_input(registers_t *reg){
io_cli(); io_cli();
info("PS/2 Keyboard: %c : %08x",c,key);
struct key_listener* h = head_listener; struct key_listener* h = head_listener;
while (1){ while (1){
h->func(key,release,c); h->func(key,release,c);
@ -224,3 +237,31 @@ void add_listener(struct key_listener* listener){
} }
} }
} }
int kernel_getch() {
uint8_t ch;
ch = input_char_inSM(); // 扫描码
if (ch == 0xe0) { // keytable之外的键↑,↓,←,→)
ch = input_char_inSM();
if (ch == 0x48) { // ↑
return -1;
} else if (ch == 0x50) { // ↓
return -2;
} else if (ch == 0x4b) { // ←
return -3;
} else if (ch == 0x4d) { // →
return -4;
}
}
// 返回扫描码keytable之内对应的ASCII码
if (keytable[ch] == 0x00) {
return 0;
} else if (shift == 0 && caps_lock == 0) {
return keytable1[ch];
} else if (shift == 1 || caps_lock == 1) {
return keytable[ch];
} else if (shift == 1 && caps_lock == 1) {
return keytable1[ch];
}
return -1;
}

View File

@ -3,6 +3,7 @@
#include "memory.h" #include "memory.h"
#include "vfs.h" #include "vfs.h"
#include "tty.h"
typedef struct { typedef struct {
int (*main)(int argc,char* * argv); int (*main)(int argc,char* * argv);
@ -41,8 +42,9 @@ struct task_struct {
int mem_size; // 内存利用率 int mem_size; // 内存利用率
char *name; // 进程名 char *name; // 进程名
void *stack; // 进程的内核栈地址 void *stack; // 进程的内核栈地址
header_t *head; // 进程堆 header_t *head; // 进程堆链表头
header_t *tail; header_t *tail;
tty_t *tty; // 输入输出设备管理器
vfs_t *vfs_now; // 文件路径焦点 vfs_t *vfs_now; // 文件路径焦点
bool isUser; // 是否是用户进程 bool isUser; // 是否是用户进程
uint32_t program_break; // 进程堆基址 uint32_t program_break; // 进程堆基址

20
src/include/tty.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef CRASHPOWEROS_TTY_H
#define CRASHPOWEROS_TTY_H
#include "common.h"
#include "fifo.h"
typedef struct tty{
uint32_t *frame_buffer; // 图形缓冲区映射
uint32_t width;
uint32_t height;
bool is_default_frame; // 是否为根缓冲区
struct FIFO8 *fifo; // 键盘输出缓冲区
}tty_t;
#include "task.h"
void init_default_tty(struct task_struct *task);
void free_tty(struct task_struct *task);
#endif

View File

@ -145,12 +145,13 @@ void task_kill(int pid) {
} }
argv->state = TASK_DEATH; argv->state = TASK_DEATH;
printf("Taskkill process PID:%d Name:%s\n", argv->pid, argv->name); printf("Taskkill process PID:%d Name:%s\n", argv->pid, argv->name);
kfree(argv); free_tty(*argv);
struct task_struct *head = running_proc_head; struct task_struct *head = running_proc_head;
struct task_struct *last = NULL; struct task_struct *last = NULL;
while (1) { while (1) {
if (head->pid == argv->pid) { if (head->pid == argv->pid) {
last->next = argv->next; last->next = argv->next;
kfree(argv);
io_sti(); io_sti();
return; return;
} }
@ -215,6 +216,8 @@ int32_t user_process(char *path, char *name){ // 用户进程创建
new_task->program_break_end = USER_HEAP_END; new_task->program_break_end = USER_HEAP_END;
new_task->name = name; new_task->name = name;
new_task->isUser = 1; new_task->isUser = 1;
new_task->tty = kmalloc(sizeof(tty_t));
init_default_tty(*new_task);
extern char root_disk; extern char root_disk;
vfs_change_disk(new_task,root_disk); vfs_change_disk(new_task,root_disk);
@ -233,7 +236,7 @@ int32_t user_process(char *path, char *name){ // 用户进程创建
alloc_frame(pg,0,1); alloc_frame(pg,0,1);
} }
char* buffer = USER_EXEC_FILE_START;//user_alloc(new_task,size); char* buffer = USER_EXEC_FILE_START;
memset(buffer,0,size); memset(buffer,0,size);
vfs_readfile(path,buffer); vfs_readfile(path,buffer);

25
src/kernel/tty.c Normal file
View File

@ -0,0 +1,25 @@
#include "../include/tty.h"
extern uint32_t *screen;
extern uint32_t width, height;
void init_default_tty(struct task_struct *task){
task->tty->fifo = kmalloc(sizeof(struct FIFO8));
char* buffer = kmalloc(256);
task->tty->frame_buffer = screen;
task->tty->width = width;
task->tty->height = height;
task->tty->is_default_frame = true;
fifo8_init(task->tty->fifo,256,buffer);
}
void free_tty(struct task_struct *task){
if(!task->tty->is_default_frame){
kfree(task->tty->frame_buffer);
}
kfree(task->tty->fifo->buf);
kfree(task->tty->fifo);
kfree(task->tty);
}