fix memory bugs and clear up shits
This commit is contained in:
parent
1a5b096b94
commit
ae40a40fb1
4
Makefile
4
Makefile
@ -151,7 +151,9 @@ gdb: $(IMAGE)
|
|||||||
@qemu-system-i386 \
|
@qemu-system-i386 \
|
||||||
-boot order=a \
|
-boot order=a \
|
||||||
-drive file=$<,format=raw \
|
-drive file=$<,format=raw \
|
||||||
-s -S \
|
-serial stdio \
|
||||||
|
-s -S &
|
||||||
|
@x-terminal-emulator -e "make monitor"
|
||||||
|
|
||||||
gdb-no-graphic: $(IMAGE)
|
gdb-no-graphic: $(IMAGE)
|
||||||
@qemu-system-i386 \
|
@qemu-system-i386 \
|
||||||
|
|||||||
@ -36,7 +36,7 @@ extern irq_handler irq_table[];
|
|||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
|
|
||||||
extern TTY tty_table[];
|
// extern TTY tty_table[];
|
||||||
extern CONSOLE console_table[];
|
extern CONSOLE console_table[];
|
||||||
extern int current_console;
|
extern int current_console;
|
||||||
|
|
||||||
|
|||||||
@ -158,16 +158,6 @@ typedef struct mouse_inbuf{
|
|||||||
u8 buf[MOUSE_IN_BYTES];
|
u8 buf[MOUSE_IN_BYTES];
|
||||||
}MOUSE_INPUT;
|
}MOUSE_INPUT;
|
||||||
|
|
||||||
typedef struct MouseState
|
|
||||||
{
|
|
||||||
u8 mouse_lb;
|
|
||||||
u8 mouse_mb;
|
|
||||||
u8 mouse_rb;
|
|
||||||
signed char mouse_scroll;
|
|
||||||
int mouse_x;
|
|
||||||
int mouse_y;
|
|
||||||
} MouseState;
|
|
||||||
|
|
||||||
#endif /* _ORANGES_KEYBOARD_H_ */
|
#endif /* _ORANGES_KEYBOARD_H_ */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -47,9 +47,10 @@ void keyboard_read();
|
|||||||
//added by mingxuan 2019-5-19
|
//added by mingxuan 2019-5-19
|
||||||
void in_process(TTY* p_tty,u32 key);
|
void in_process(TTY* p_tty,u32 key);
|
||||||
void task_tty();
|
void task_tty();
|
||||||
void tty_write(TTY* tty, char* buf, int len);
|
void tty_write(NTTY* tty, char* buf, int len);
|
||||||
int tty_read(TTY* tty, char* buf, int len);
|
int tty_read(NTTY* tty, char* buf, int len);
|
||||||
void init_tty_main();
|
void init_tty_main();
|
||||||
|
NTTY* get_tty(const int nr_tty);
|
||||||
|
|
||||||
/* printf.c */
|
/* printf.c */
|
||||||
//added by mingxuan 2019-5-19
|
//added by mingxuan 2019-5-19
|
||||||
|
|||||||
@ -119,6 +119,5 @@ int ps2_tty_read(NTTY* tty, char* buf, int nr);
|
|||||||
|
|
||||||
// extern int cur_ntty;
|
// extern int cur_ntty;
|
||||||
extern NTTY* cur_ntty;
|
extern NTTY* cur_ntty;
|
||||||
extern NTTY* default_ntty;
|
|
||||||
// extern NTTY ntty_table[3];
|
// extern NTTY ntty_table[3];
|
||||||
#endif /* _ORANGES_TTY_H_ */
|
#endif /* _ORANGES_TTY_H_ */
|
||||||
@ -52,9 +52,9 @@ u32 sys_exec(char *path)
|
|||||||
// u32 fd = fake_open(path,"r"); //modified by xw, 18/5/30
|
// u32 fd = fake_open(path,"r"); //modified by xw, 18/5/30
|
||||||
|
|
||||||
/*************获取elf信息**************/
|
/*************获取elf信息**************/
|
||||||
Echo_Ehdr = sys_kmalloc(sizeof(Elf32_Ehdr));
|
Echo_Ehdr = (Elf32_Ehdr*)K_PHY2LIN(sys_kmalloc(sizeof(Elf32_Ehdr)));
|
||||||
read_Ehdr(fd, Echo_Ehdr, 0);
|
read_Ehdr(fd, Echo_Ehdr, 0);
|
||||||
Echo_Phdr = sys_kmalloc(sizeof(Elf32_Phdr) * Echo_Ehdr->e_phnum);
|
Echo_Phdr = (Elf32_Phdr*)K_PHY2LIN(sys_kmalloc(sizeof(Elf32_Phdr) * Echo_Ehdr->e_phnum));
|
||||||
for (int i = 0 ; i < Echo_Ehdr->e_phnum ; i++)
|
for (int i = 0 ; i < Echo_Ehdr->e_phnum ; i++)
|
||||||
read_Phdr(fd, Echo_Phdr + i, Echo_Ehdr->e_phoff + i * sizeof(Elf32_Phdr));
|
read_Phdr(fd, Echo_Phdr + i, Echo_Ehdr->e_phoff + i * sizeof(Elf32_Phdr));
|
||||||
|
|
||||||
@ -169,15 +169,15 @@ static u32 exec_load(u32 fd,const Elf32_Ehdr* Echo_Ehdr,const Elf32_Phdr Echo_Ph
|
|||||||
{//最后一个program
|
{//最后一个program
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( Echo_Phdr[ph_num].p_flags == 0x5) //101,R E
|
if( Echo_Phdr[ph_num].p_flags == 0x5) //101,R_E
|
||||||
{//.text
|
{//Code Segment
|
||||||
exec_elfcpy(fd,Echo_Phdr[ph_num],PG_P | PG_USU | PG_RWR);//进程代码段
|
exec_elfcpy(fd,Echo_Phdr[ph_num],PG_P | PG_USU | PG_RWR);//进程代码段
|
||||||
// kprintf("text lin base: 0x%08x\n", Echo_Phdr[ph_num].p_vaddr);
|
// kprintf("text lin base: 0x%08x\n", Echo_Phdr[ph_num].p_vaddr);
|
||||||
p_proc_current->task.memmap.text_lin_base = Echo_Phdr[ph_num].p_vaddr;
|
p_proc_current->task.memmap.text_lin_base = Echo_Phdr[ph_num].p_vaddr;
|
||||||
p_proc_current->task.memmap.text_lin_limit = Echo_Phdr[ph_num].p_vaddr + Echo_Phdr[ph_num].p_memsz;
|
p_proc_current->task.memmap.text_lin_limit = Echo_Phdr[ph_num].p_vaddr + Echo_Phdr[ph_num].p_memsz;
|
||||||
}
|
}
|
||||||
else if(Echo_Phdr[ph_num].p_flags == 0x4)//110,R
|
else if(Echo_Phdr[ph_num].p_flags == 0x4)//110,R__
|
||||||
{//.data
|
{// It is virtually ROData Segment, god knows what those senpai think about this
|
||||||
exec_elfcpy(fd,Echo_Phdr[ph_num],PG_P | PG_USU | PG_RWW);//进程数据段
|
exec_elfcpy(fd,Echo_Phdr[ph_num],PG_P | PG_USU | PG_RWW);//进程数据段
|
||||||
// kprintf("data lin base: 0x%08x\n", Echo_Phdr[ph_num].p_vaddr);
|
// kprintf("data lin base: 0x%08x\n", Echo_Phdr[ph_num].p_vaddr);
|
||||||
p_proc_current->task.memmap.data_lin_base = Echo_Phdr[ph_num].p_vaddr;
|
p_proc_current->task.memmap.data_lin_base = Echo_Phdr[ph_num].p_vaddr;
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
static int fork_mem_cpy(u32 ppid,u32 pid);
|
static int fork_mem_cpy(u32 ppid,u32 pid);
|
||||||
static int fork_pcb_cpy(PROCESS* p_child);
|
static int fork_pcb_cpy(PROCESS* p_child);
|
||||||
@ -56,9 +57,7 @@ int sys_fork()
|
|||||||
/****************用户进程数+1****************************/
|
/****************用户进程数+1****************************/
|
||||||
u_proc_sum += 1;
|
u_proc_sum += 1;
|
||||||
|
|
||||||
disp_color_str("[fork success:",0x72);
|
// kprintf("\x1b[32mfork success %s \x1b[0m\n", p_proc_current->task.p_name);
|
||||||
disp_color_str(p_proc_current->task.p_name,0x72);
|
|
||||||
disp_color_str("]",0x72);
|
|
||||||
|
|
||||||
//anything child need is prepared now, set its state to ready. added by xw, 17/12/11
|
//anything child need is prepared now, set its state to ready. added by xw, 17/12/11
|
||||||
p_child->task.stat = READY;
|
p_child->task.stat = READY;
|
||||||
|
|||||||
@ -1263,11 +1263,12 @@ static int do_rdwt(MESSAGE *fs_msg)
|
|||||||
|
|
||||||
if (fs_msg->type == DEV_READ)
|
if (fs_msg->type == DEV_READ)
|
||||||
{
|
{
|
||||||
fs_msg->CNT = tty_read(&tty_table[nr_tty], buf, len);
|
fs_msg->CNT = tty_read(get_tty(nr_tty), buf, len);
|
||||||
}
|
}
|
||||||
else if (fs_msg->type == DEV_WRITE)
|
else if (fs_msg->type == DEV_WRITE)
|
||||||
{
|
{
|
||||||
tty_write(&tty_table[nr_tty], buf, len);
|
// kprintf("pid %d, tty %d; ", p_proc_current->task.pid, nr_tty);
|
||||||
|
tty_write(get_tty(nr_tty), buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fs_msg->CNT;
|
return fs_msg->CNT;
|
||||||
|
|||||||
@ -9,11 +9,11 @@
|
|||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
// #include "keymap.h"
|
// #include "keymap.h"
|
||||||
#include "spinlock.h"
|
|
||||||
#include "x86.h"
|
#include "x86.h"
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "minix_keymap.h"
|
#include "minix_keymap.h"
|
||||||
|
#include "memman.h"
|
||||||
|
|
||||||
static KB_INPUT kb_in;
|
static KB_INPUT kb_in;
|
||||||
static MOUSE_INPUT mouse_in;
|
static MOUSE_INPUT mouse_in;
|
||||||
@ -29,16 +29,13 @@ static int ctrl_r; /* l ctrl state */
|
|||||||
static int caps_lock; /* Caps Lock */
|
static int caps_lock; /* Caps Lock */
|
||||||
static int num_lock; /* Num Lock */
|
static int num_lock; /* Num Lock */
|
||||||
static int scroll_lock; /* Scroll Lock */
|
static int scroll_lock; /* Scroll Lock */
|
||||||
static MouseState mouse_state;
|
|
||||||
|
|
||||||
static u8 get_byte_from_kb_buf();
|
|
||||||
static void set_leds();
|
static void set_leds();
|
||||||
static void set_mouse_leds();
|
static void set_mouse_leds();
|
||||||
static void kb_wait();
|
static void kb_wait();
|
||||||
static void ps2_push(NTTY *tty, u32 key);
|
static void ps2_push(NTTY *tty, u32 key);
|
||||||
static void kbd_process(unsigned char scode);
|
static void kbd_process(unsigned char scode);
|
||||||
|
|
||||||
// static void kb_ack();
|
|
||||||
/*
|
/*
|
||||||
* Helper Procedures for PS/2 Mouse Operation
|
* Helper Procedures for PS/2 Mouse Operation
|
||||||
* */
|
* */
|
||||||
@ -99,21 +96,8 @@ static u8 mouse_get_id()
|
|||||||
void kb_handler(int irq)
|
void kb_handler(int irq)
|
||||||
{
|
{
|
||||||
u8 scan_code = inb(PS2_PORT_DATA);
|
u8 scan_code = inb(PS2_PORT_DATA);
|
||||||
#ifdef DEBUGNEW
|
|
||||||
kbd_process(scan_code);
|
kbd_process(scan_code);
|
||||||
// kprintf("shit");
|
// kprintf("kb");
|
||||||
#else
|
|
||||||
if (kb_in.count < KB_IN_BYTES)
|
|
||||||
{
|
|
||||||
*(kb_in.p_head) = scan_code;
|
|
||||||
kb_in.p_head++;
|
|
||||||
if (kb_in.p_head == kb_in.buf + KB_IN_BYTES)
|
|
||||||
{
|
|
||||||
kb_in.p_head = kb_in.buf;
|
|
||||||
}
|
|
||||||
kb_in.count++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void mouse_handler(int irq)
|
void mouse_handler(int irq)
|
||||||
@ -218,251 +202,6 @@ void init_kb()
|
|||||||
init_mouse();
|
init_mouse();
|
||||||
set_mouse_leds();
|
set_mouse_leds();
|
||||||
}
|
}
|
||||||
#ifndef DEBUGNEW
|
|
||||||
static int column;
|
|
||||||
void keyboard_read(TTY *p_tty)
|
|
||||||
{
|
|
||||||
u8 scan_code;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1 : make
|
|
||||||
* 0 : break
|
|
||||||
*/
|
|
||||||
int make;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We use a integer to record a key press.
|
|
||||||
* For instance, if the key HOME is pressed, key will be evaluated to
|
|
||||||
* `HOME' defined in keyboard.h.
|
|
||||||
*/
|
|
||||||
u32 key = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This var points to a row in keymap[]. I don't use two-dimension
|
|
||||||
* array because I don't like it.
|
|
||||||
*/
|
|
||||||
u32 *keyrow;
|
|
||||||
|
|
||||||
while (kb_in.count > 0)
|
|
||||||
{
|
|
||||||
code_with_E0 = 0;
|
|
||||||
scan_code = get_byte_from_kb_buf();
|
|
||||||
|
|
||||||
/* parse the scan code below */
|
|
||||||
if (scan_code == 0xE1)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
u8 pausebreak_scan_code[] = {0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5};
|
|
||||||
int is_pausebreak = 1;
|
|
||||||
for (i = 1; i < 6; i++)
|
|
||||||
{
|
|
||||||
if (get_byte_from_kb_buf() != pausebreak_scan_code[i])
|
|
||||||
{
|
|
||||||
is_pausebreak = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (is_pausebreak)
|
|
||||||
{
|
|
||||||
key = PAUSEBREAK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (scan_code == 0xE0)
|
|
||||||
{
|
|
||||||
code_with_E0 = 1;
|
|
||||||
scan_code = get_byte_from_kb_buf();
|
|
||||||
|
|
||||||
/* PrintScreen is pressed */
|
|
||||||
if (scan_code == 0x2A)
|
|
||||||
{
|
|
||||||
code_with_E0 = 0;
|
|
||||||
if ((scan_code = get_byte_from_kb_buf()) == 0xE0)
|
|
||||||
{
|
|
||||||
code_with_E0 = 1;
|
|
||||||
if ((scan_code = get_byte_from_kb_buf()) == 0x37)
|
|
||||||
{
|
|
||||||
key = PRINTSCREEN;
|
|
||||||
make = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* PrintScreen is released */
|
|
||||||
else if (scan_code == 0xB7)
|
|
||||||
{
|
|
||||||
code_with_E0 = 0;
|
|
||||||
if ((scan_code = get_byte_from_kb_buf()) == 0xE0)
|
|
||||||
{
|
|
||||||
code_with_E0 = 1;
|
|
||||||
if ((scan_code = get_byte_from_kb_buf()) == 0xAA)
|
|
||||||
{
|
|
||||||
key = PRINTSCREEN;
|
|
||||||
make = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((key != PAUSEBREAK) && (key != PRINTSCREEN))
|
|
||||||
{
|
|
||||||
int caps;
|
|
||||||
|
|
||||||
/* make or break */
|
|
||||||
make = (scan_code & FLAG_BREAK ? 0 : 1);
|
|
||||||
|
|
||||||
keyrow = &keymap[(scan_code & 0x7F) * MAP_COLS];
|
|
||||||
|
|
||||||
column = 0;
|
|
||||||
|
|
||||||
caps = shift_l || shift_r;
|
|
||||||
if (caps_lock &&
|
|
||||||
keyrow[0] >= 'a' && keyrow[0] <= 'z')
|
|
||||||
caps = !caps;
|
|
||||||
|
|
||||||
if (caps)
|
|
||||||
column = 1;
|
|
||||||
|
|
||||||
if (code_with_E0)
|
|
||||||
column = 2;
|
|
||||||
|
|
||||||
key = keyrow[column];
|
|
||||||
|
|
||||||
switch (key)
|
|
||||||
{
|
|
||||||
case SHIFT_L:
|
|
||||||
shift_l = make;
|
|
||||||
break;
|
|
||||||
case SHIFT_R:
|
|
||||||
shift_r = make;
|
|
||||||
break;
|
|
||||||
case CTRL_L:
|
|
||||||
ctrl_l = make;
|
|
||||||
break;
|
|
||||||
case CTRL_R:
|
|
||||||
ctrl_r = make;
|
|
||||||
break;
|
|
||||||
case ALT_L:
|
|
||||||
alt_l = make;
|
|
||||||
break;
|
|
||||||
case ALT_R:
|
|
||||||
alt_l = make;
|
|
||||||
break;
|
|
||||||
case CAPS_LOCK:
|
|
||||||
if (make)
|
|
||||||
{
|
|
||||||
caps_lock = !caps_lock;
|
|
||||||
set_leds();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case NUM_LOCK:
|
|
||||||
if (make)
|
|
||||||
{
|
|
||||||
num_lock = !num_lock;
|
|
||||||
set_leds();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SCROLL_LOCK:
|
|
||||||
if (make)
|
|
||||||
{
|
|
||||||
scroll_lock = !scroll_lock;
|
|
||||||
set_leds();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (make)
|
|
||||||
{ /* Break Code is ignored */
|
|
||||||
int pad = 0;
|
|
||||||
|
|
||||||
/* deal with the numpad first */
|
|
||||||
if ((key >= PAD_SLASH) && (key <= PAD_9))
|
|
||||||
{
|
|
||||||
pad = 1;
|
|
||||||
switch (key)
|
|
||||||
{ /* '/', '*', '-', '+',
|
|
||||||
* and 'Enter' in num pad
|
|
||||||
*/
|
|
||||||
case PAD_SLASH:
|
|
||||||
key = '/';
|
|
||||||
break;
|
|
||||||
case PAD_STAR:
|
|
||||||
key = '*';
|
|
||||||
break;
|
|
||||||
case PAD_MINUS:
|
|
||||||
key = '-';
|
|
||||||
break;
|
|
||||||
case PAD_PLUS:
|
|
||||||
key = '+';
|
|
||||||
break;
|
|
||||||
case PAD_ENTER:
|
|
||||||
key = ENTER;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* the value of these keys
|
|
||||||
* depends on the Numlock
|
|
||||||
*/
|
|
||||||
if (num_lock)
|
|
||||||
{ /* '0' ~ '9' and '.' in num pad */
|
|
||||||
if (key >= PAD_0 && key <= PAD_9)
|
|
||||||
key = key - PAD_0 + '0';
|
|
||||||
else if (key == PAD_DOT)
|
|
||||||
key = '.';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch (key)
|
|
||||||
{
|
|
||||||
case PAD_HOME:
|
|
||||||
key = HOME;
|
|
||||||
break;
|
|
||||||
case PAD_END:
|
|
||||||
key = END;
|
|
||||||
break;
|
|
||||||
case PAD_PAGEUP:
|
|
||||||
key = PAGEUP;
|
|
||||||
break;
|
|
||||||
case PAD_PAGEDOWN:
|
|
||||||
key = PAGEDOWN;
|
|
||||||
break;
|
|
||||||
case PAD_INS:
|
|
||||||
key = INSERT;
|
|
||||||
break;
|
|
||||||
case PAD_UP:
|
|
||||||
key = UP;
|
|
||||||
break;
|
|
||||||
case PAD_DOWN:
|
|
||||||
key = DOWN;
|
|
||||||
break;
|
|
||||||
case PAD_LEFT:
|
|
||||||
key = LEFT;
|
|
||||||
break;
|
|
||||||
case PAD_RIGHT:
|
|
||||||
key = RIGHT;
|
|
||||||
break;
|
|
||||||
case PAD_DOT:
|
|
||||||
key = DELETE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
key |= shift_l ? FLAG_SHIFT_L : 0;
|
|
||||||
key |= shift_r ? FLAG_SHIFT_R : 0;
|
|
||||||
key |= ctrl_l ? FLAG_CTRL_L : 0;
|
|
||||||
key |= ctrl_r ? FLAG_CTRL_R : 0;
|
|
||||||
key |= alt_l ? FLAG_ALT_L : 0;
|
|
||||||
key |= alt_r ? FLAG_ALT_R : 0;
|
|
||||||
key |= pad ? FLAG_PAD : 0;
|
|
||||||
in_process(p_tty, key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static u16 map_key(int code)
|
static u16 map_key(int code)
|
||||||
{
|
{
|
||||||
@ -487,16 +226,11 @@ static u16 map_key(int code)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if (sticky_alt_mode && (lk & ALT_LOCK)) {
|
|
||||||
// column = 2;
|
|
||||||
// if (caps) column = 4;
|
|
||||||
// } else {
|
|
||||||
column = 0;
|
column = 0;
|
||||||
if (caps)
|
if (caps)
|
||||||
column = 1;
|
column = 1;
|
||||||
if (ctrl)
|
if (ctrl)
|
||||||
column = 5;
|
column = 5;
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
return keyrow[column] & ~(HASNUM | HASCAPS);
|
return keyrow[column] & ~(HASNUM | HASCAPS);
|
||||||
}
|
}
|
||||||
@ -564,16 +298,22 @@ static void kbd_process(unsigned char scode)
|
|||||||
alt_r = press;
|
alt_r = press;
|
||||||
break;
|
break;
|
||||||
case INPUT_KEY_NUM_LOCK:
|
case INPUT_KEY_NUM_LOCK:
|
||||||
if (press)
|
if (press){
|
||||||
num_lock = !num_lock;
|
num_lock = !num_lock;
|
||||||
|
set_leds();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case INPUT_KEY_CAPS_LOCK:
|
case INPUT_KEY_CAPS_LOCK:
|
||||||
if (press)
|
if (press){
|
||||||
caps_lock = !caps_lock;
|
caps_lock = !caps_lock;
|
||||||
|
set_leds();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case INPUT_KEY_SCROLL_LOCK:
|
case INPUT_KEY_SCROLL_LOCK:
|
||||||
if (press)
|
if (press){
|
||||||
scroll_lock = !scroll_lock;
|
scroll_lock = !scroll_lock;
|
||||||
|
set_leds();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -585,34 +325,6 @@ static void kbd_process(unsigned char scode)
|
|||||||
kbd_state = 0;
|
kbd_state = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* get_byte_from_kb_buf
|
|
||||||
*****************************************************************************/
|
|
||||||
/**
|
|
||||||
* Read a byte from the keyboard buffer.
|
|
||||||
*
|
|
||||||
* @return The byte read.
|
|
||||||
*****************************************************************************/
|
|
||||||
static u8 get_byte_from_kb_buf()
|
|
||||||
{
|
|
||||||
u8 scan_code;
|
|
||||||
|
|
||||||
while (kb_in.count <= 0)
|
|
||||||
{
|
|
||||||
} /* wait for a byte to arrive */
|
|
||||||
|
|
||||||
disable_int(); /* for synchronization */
|
|
||||||
scan_code = *(kb_in.p_tail);
|
|
||||||
kb_in.p_tail++;
|
|
||||||
if (kb_in.p_tail == kb_in.buf + KB_IN_BYTES)
|
|
||||||
{
|
|
||||||
kb_in.p_tail = kb_in.buf;
|
|
||||||
}
|
|
||||||
kb_in.count--;
|
|
||||||
enable_int(); /* for synchronization */
|
|
||||||
|
|
||||||
return scan_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* kb_wait
|
* kb_wait
|
||||||
@ -661,29 +373,34 @@ static void set_mouse_leds()
|
|||||||
outb(KB_DATA, KBC_MODE);
|
outb(KB_DATA, KBC_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct spinlock buflock;
|
|
||||||
|
|
||||||
#define LASTKEY(x) LAST(x, TTY_IN_BYTES)
|
#define LASTKEY(x) LAST(x, TTY_IN_BYTES)
|
||||||
#define NEXTKEY(x) NEXT(x, TTY_IN_BYTES)
|
#define NEXTKEY(x) NEXT(x, TTY_IN_BYTES)
|
||||||
|
|
||||||
static u8 keybuf[3][TTY_IN_BYTES];
|
// static u8 keybuf[3][TTY_IN_BYTES];
|
||||||
void ps2_tty_init(NTTY *tty)
|
void ps2_tty_init(NTTY *tty)
|
||||||
{
|
{
|
||||||
static int _cnt = 0;
|
static int _cnt = 0;
|
||||||
assert(tty->driver_type == 1);
|
assert(tty->driver_type == 1);
|
||||||
assert(tty->input_buf);
|
assert(tty->input_buf);
|
||||||
keyboard_buf *kbd = (keyboard_buf *)tty->input_buf;
|
keyboard_buf *kbd = (keyboard_buf *)tty->input_buf;
|
||||||
kbd->buf = (void *)keybuf[_cnt++];
|
// kbd->buf = (void *)keybuf[_cnt++];
|
||||||
|
kbd->buf = (void*)K_PHY2LIN(do_kmalloc(TTY_IN_BYTES));
|
||||||
|
// kprintf("kbd buf: %p\n", kbd->buf);
|
||||||
kbd->head = kbd->tail = kbd->readable = 0;
|
kbd->head = kbd->tail = kbd->readable = 0;
|
||||||
kbd->len = 0;
|
kbd->len = 0;
|
||||||
buflock.locked = 0;
|
}
|
||||||
|
|
||||||
|
static inline void printallbuf(u8* ibuf) {
|
||||||
|
for (int i = 0; i < TTY_IN_BYTES; ++ i) {
|
||||||
|
kprintf("%c", ibuf[i]);
|
||||||
|
}
|
||||||
|
kprintf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int ps2_tty_read(NTTY *tty, char *buf, int nr)
|
int ps2_tty_read(NTTY *tty, char *buf, int nr)
|
||||||
{
|
{
|
||||||
assert(tty->input_buf);
|
assert(tty->input_buf);
|
||||||
keyboard_buf *kbd = (keyboard_buf *)tty->input_buf;
|
keyboard_buf *kbd = (keyboard_buf *)tty->input_buf;
|
||||||
assert(kbd->buf);
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
@ -693,11 +410,12 @@ int ps2_tty_read(NTTY *tty, char *buf, int nr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assert(kbd->buf);
|
||||||
u8 *ibuf = kbd->buf;
|
u8 *ibuf = kbd->buf;
|
||||||
for (; i < nr && i < kbd->readable; ++i)
|
for (; i < nr && i < kbd->readable; ++i)
|
||||||
{
|
{
|
||||||
*(buf + i) = *(ibuf + kbd->head);
|
*buf ++ = ibuf[kbd->head];
|
||||||
// kprintf("read %p\n", ibuf+kbd->head);
|
// kprintf("[r]%p;", ibuf+kbd->head);
|
||||||
kbd->head = NEXTKEY(kbd->head);
|
kbd->head = NEXTKEY(kbd->head);
|
||||||
}
|
}
|
||||||
kbd->readable -= i;
|
kbd->readable -= i;
|
||||||
@ -721,6 +439,7 @@ static void ps2_push(NTTY *tty, u32 key)
|
|||||||
disable_int();
|
disable_int();
|
||||||
assert(tty->input_buf);
|
assert(tty->input_buf);
|
||||||
keyboard_buf *kbd = (keyboard_buf *)tty->input_buf;
|
keyboard_buf *kbd = (keyboard_buf *)tty->input_buf;
|
||||||
|
u8* buf = kbd->buf;
|
||||||
if (key & ISMOUSE)
|
if (key & ISMOUSE)
|
||||||
{
|
{
|
||||||
if (key & MOUSESCR)
|
if (key & MOUSESCR)
|
||||||
@ -749,25 +468,14 @@ static void ps2_push(NTTY *tty, u32 key)
|
|||||||
{
|
{
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case F1:
|
case F1: case F2: case F3: case F4: case F5: case F6:
|
||||||
case F2:
|
case F7: case F8: case F9: case F10: case F11: case F12:
|
||||||
case F3:
|
|
||||||
case F4:
|
|
||||||
case F5:
|
|
||||||
case F6:
|
|
||||||
case F7:
|
|
||||||
case F8:
|
|
||||||
case F9:
|
|
||||||
case F10:
|
|
||||||
case F11:
|
|
||||||
case F12:
|
|
||||||
// select_console((key & 0xff) - (F1 & 0xff)); // TODO
|
|
||||||
{
|
{
|
||||||
int conno = (key & 0xff) - (F1 & 0xff);
|
int conno = (key & 0xff) - (F1 & 0xff);
|
||||||
if (conno < NR_CONSOLES)
|
if (conno < NR_CONSOLES)
|
||||||
{
|
{
|
||||||
kprintf("select console %d\n", conno);
|
// kprintf("select console %d\n", conno);
|
||||||
vga_tty_select(default_ntty + conno);
|
vga_tty_select(get_tty(conno));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -783,7 +491,7 @@ static void ps2_push(NTTY *tty, u32 key)
|
|||||||
case '\r':
|
case '\r':
|
||||||
case '\n': // escape ENTER
|
case '\n': // escape ENTER
|
||||||
vga_tty_write(tty, '\n');
|
vga_tty_write(tty, '\n');
|
||||||
((u8 *)kbd->buf)[kbd->tail] = '\n';
|
buf[kbd->tail] = '\n';
|
||||||
kbd->len++;
|
kbd->len++;
|
||||||
kbd->tail = NEXTKEY(kbd->tail);
|
kbd->tail = NEXTKEY(kbd->tail);
|
||||||
kbd->readable = CYCLE_SUB(kbd->head, kbd->tail, TTY_IN_BYTES);
|
kbd->readable = CYCLE_SUB(kbd->head, kbd->tail, TTY_IN_BYTES);
|
||||||
@ -804,7 +512,8 @@ static void ps2_push(NTTY *tty, u32 key)
|
|||||||
if (kbd->len == TTY_IN_BYTES - 1)
|
if (kbd->len == TTY_IN_BYTES - 1)
|
||||||
return; // leave one space for ctrl ascii
|
return; // leave one space for ctrl ascii
|
||||||
vga_tty_write(tty, key);
|
vga_tty_write(tty, key);
|
||||||
((u8 *)kbd->buf)[kbd->tail] = key & 0xff;
|
buf[kbd->tail] = (u8)(key & 0xff);
|
||||||
|
// kprintf("%d %d %d", key & 0xff, kbd->tail, buf[kbd->tail]);
|
||||||
kbd->len++;
|
kbd->len++;
|
||||||
kbd->tail = NEXTKEY(kbd->tail);
|
kbd->tail = NEXTKEY(kbd->tail);
|
||||||
// kprintf("len=%d, h=%d, t=%d, rd=%d\n", kbd->len, kbd->head, kbd->tail, kbd->readable);
|
// kprintf("len=%d, h=%d, t=%d, rd=%d\n", kbd->len, kbd->head, kbd->tail, kbd->readable);
|
||||||
@ -814,5 +523,3 @@ static void ps2_push(NTTY *tty, u32 key)
|
|||||||
}
|
}
|
||||||
enable_int();
|
enable_int();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 1. 修改键盘驱动 2. 添加测试代码 3. 添加鼠标并调试滚动
|
|
||||||
@ -31,6 +31,8 @@ static int initialize_cpus(); // added by xw, 18/6/2
|
|||||||
*======================================================================*/
|
*======================================================================*/
|
||||||
int kernel_main()
|
int kernel_main()
|
||||||
{
|
{
|
||||||
|
clear_kernel_pagepte_low();
|
||||||
|
|
||||||
init_serial();
|
init_serial();
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
@ -114,7 +116,6 @@ int kernel_main()
|
|||||||
* note that disp_xx can't work after this function is invoked until processes runs.
|
* note that disp_xx can't work after this function is invoked until processes runs.
|
||||||
* add by visual 2016.5.13; moved by xw, 18/5/30
|
* add by visual 2016.5.13; moved by xw, 18/5/30
|
||||||
*/
|
*/
|
||||||
clear_kernel_pagepte_low();
|
|
||||||
|
|
||||||
p_proc_current = proc_table;
|
p_proc_current = proc_table;
|
||||||
kernel_initial = 0; // kernel initialization is done. added by xw, 18/5/31
|
kernel_initial = 0; // kernel initialization is done. added by xw, 18/5/31
|
||||||
|
|||||||
@ -27,7 +27,7 @@ void init() //初始化
|
|||||||
u32 memstart = MEMSTART; //4M 开始初始化
|
u32 memstart = MEMSTART; //4M 开始初始化
|
||||||
u32 i,j;
|
u32 i,j;
|
||||||
|
|
||||||
memcpy(MemInfo,(u32 *)FMIBuff,1024); //复制内存
|
memcpy(MemInfo,(u32 *)(K_PHY2LIN(FMIBuff)),1024); //复制内存
|
||||||
|
|
||||||
memman_init(memman); //初始化memman中frees,maxfrees,lostsize,losts
|
memman_init(memman); //初始化memman中frees,maxfrees,lostsize,losts
|
||||||
|
|
||||||
@ -329,77 +329,3 @@ u32 memman_total(struct MEMMAN *man)
|
|||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void memman_test()
|
|
||||||
{ //测试
|
|
||||||
u32 *p1 = 0;
|
|
||||||
u32 *p2 = 0;
|
|
||||||
u32 *p3 = 0;
|
|
||||||
u32 *p4 = 0;
|
|
||||||
u32 *p = 0;
|
|
||||||
|
|
||||||
p1 = (u32 *)do_malloc(4);
|
|
||||||
if(-1 != (u32)p1){ //打印p1,当前空闲内存信息,p1所指内存的内容
|
|
||||||
disp_str("START");
|
|
||||||
disp_int((u32)p1);
|
|
||||||
//disp_free();
|
|
||||||
*p1 = TEST;
|
|
||||||
disp_int(*p1);
|
|
||||||
disp_str("END");
|
|
||||||
}
|
|
||||||
|
|
||||||
p2 = (u32 *)do_kmalloc(4);
|
|
||||||
if(-1 != (u32)p2){
|
|
||||||
disp_str("START");
|
|
||||||
disp_int((u32)p2);
|
|
||||||
//disp_free();
|
|
||||||
*p2 = TEST;
|
|
||||||
disp_int(*p2);
|
|
||||||
disp_str("END");
|
|
||||||
}
|
|
||||||
|
|
||||||
do_free((u32)p1,4);
|
|
||||||
do_free((u32)p2,4);
|
|
||||||
|
|
||||||
p3 = (u32 *)do_malloc_4k();
|
|
||||||
if(-1 != (u32)p3){
|
|
||||||
disp_str("START");
|
|
||||||
disp_int((u32)p3);
|
|
||||||
//disp_free();
|
|
||||||
*p3 = TEST;
|
|
||||||
disp_int(*p3);
|
|
||||||
p = p3 + 2044;
|
|
||||||
*p = 0x22334455;
|
|
||||||
disp_int(*p);
|
|
||||||
p += 2048;
|
|
||||||
*p = 0x33445566;
|
|
||||||
disp_int(*p);
|
|
||||||
disp_str("END");
|
|
||||||
}
|
|
||||||
|
|
||||||
p4 = (u32 *)do_kmalloc_4k(4);
|
|
||||||
if(-1 != (u32)p4){
|
|
||||||
disp_str("START");
|
|
||||||
disp_int((u32)p4);
|
|
||||||
//disp_free();
|
|
||||||
*p4 = TEST;
|
|
||||||
disp_int(*p4);
|
|
||||||
p = p4 + 2044;
|
|
||||||
*p = 0x22334455;
|
|
||||||
disp_int(*p);
|
|
||||||
p += 2048;
|
|
||||||
*p = 0x33445566;
|
|
||||||
disp_int(*p);
|
|
||||||
disp_str("END");
|
|
||||||
}
|
|
||||||
|
|
||||||
do_free_4k((u32)p3);
|
|
||||||
do_free_4k((u32)p4);
|
|
||||||
|
|
||||||
disp_str("START");
|
|
||||||
disp_free();
|
|
||||||
disp_str("END");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,8 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "memman.h"
|
#include "memman.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "x86.h"
|
||||||
|
|
||||||
// to determine if a page fault is reparable. added by xw, 18/6/11
|
// to determine if a page fault is reparable. added by xw, 18/6/11
|
||||||
u32 cr2_save;
|
u32 cr2_save;
|
||||||
@ -81,18 +83,9 @@ void page_fault_handler(u32 vec_no, //异常编号,此时应该是14,代
|
|||||||
// if page fault happens in kernel, it's an error.
|
// if page fault happens in kernel, it's an error.
|
||||||
if (kernel_initial == 1)
|
if (kernel_initial == 1)
|
||||||
{
|
{
|
||||||
disp_str("\n");
|
kprintf("\n");
|
||||||
disp_color_str("Page Fault\n", 0x74);
|
kprintf("\033[91;47m Page Fault\n\033[0m");
|
||||||
disp_color_str("eip=", 0x74); //灰底红字
|
kprintf("\033[91meip=0x%08x, eflags=0x%x, CS=0x%x, ERR=0x%x, CR2=0x%08x\033[0m\n", eip, eflags, cs, err_code, cr2);
|
||||||
disp_int(eip);
|
|
||||||
disp_color_str("eflags=", 0x74);
|
|
||||||
disp_int(eflags);
|
|
||||||
disp_color_str("cs=", 0x74);
|
|
||||||
disp_int(cs);
|
|
||||||
disp_color_str("err_code=", 0x74);
|
|
||||||
disp_int(err_code);
|
|
||||||
disp_color_str("Cr2=", 0x74); //灰底红字
|
|
||||||
disp_int(cr2);
|
|
||||||
halt();
|
halt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,51 +94,27 @@ void page_fault_handler(u32 vec_no, //异常编号,此时应该是14,代
|
|||||||
//获取该线性地址对应的页表的物理地址
|
//获取该线性地址对应的页表的物理地址
|
||||||
pte_addr_phy_temp = get_pte_phy_addr(p_proc_current->task.pid, cr2);
|
pte_addr_phy_temp = get_pte_phy_addr(p_proc_current->task.pid, cr2);
|
||||||
|
|
||||||
if (cr2 == cr2_save)
|
kprintf("\n");
|
||||||
{
|
kprintf("\033[91;47m Page Fault\033[0m in %d\n", p_proc_current->task.pid);
|
||||||
cr2_count++;
|
kprintf("\033[91meip=0x%08x, eflags=0x%x, CS=0x%x, ERR=0x%x, CR2=0x%08x\033[0m\n", eip, eflags, cs, err_code, cr2);
|
||||||
if (cr2_count == 5)
|
kprintf("\033[91mCR3=0x%08x, PDE=%p, PTE=%p\033[0m\n",
|
||||||
{
|
p_proc_current->task.cr3,
|
||||||
disp_str("\n");
|
*((u32 *)K_PHY2LIN(pde_addr_phy_temp) + get_pde_index(cr2)),
|
||||||
disp_color_str("Page Fault\n", 0x74);
|
*((u32 *)K_PHY2LIN(pte_addr_phy_temp) + get_pte_index(cr2)));
|
||||||
disp_color_str("eip=", 0x74); //灰底红字
|
disable_int();
|
||||||
disp_int(eip);
|
halt();
|
||||||
disp_color_str("eflags=", 0x74);
|
|
||||||
disp_int(eflags);
|
|
||||||
disp_color_str("cs=", 0x74);
|
|
||||||
disp_int(cs);
|
|
||||||
disp_color_str("err_code=", 0x74);
|
|
||||||
disp_int(err_code);
|
|
||||||
disp_color_str("Cr2=", 0x74); //灰底红字
|
|
||||||
disp_int(cr2);
|
|
||||||
disp_color_str("Cr3=", 0x74);
|
|
||||||
disp_int(p_proc_current->task.cr3);
|
|
||||||
//获取页目录中填写的内容
|
|
||||||
disp_color_str("Pde=", 0x74);
|
|
||||||
disp_int(*((u32 *)K_PHY2LIN(pde_addr_phy_temp) + get_pde_index(cr2)));
|
|
||||||
//获取页表中填写的内容
|
|
||||||
disp_color_str("Pte=", 0x74);
|
|
||||||
disp_int(*((u32 *)K_PHY2LIN(pte_addr_phy_temp) + get_pte_index(cr2)));
|
|
||||||
halt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cr2_save = cr2;
|
|
||||||
cr2_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 == pte_exist(pde_addr_phy_temp, cr2))
|
if (0 == pte_exist(pde_addr_phy_temp, cr2))
|
||||||
{ //页表不存在
|
{ //页表不存在
|
||||||
// disp_color_str("[Pde Fault!]",0x74); //灰底红字
|
// kprintf("\033[91;47m[PDE FAULT]\033[0m in %d\n",p_proc_current->task.pid);
|
||||||
(*((u32 *)K_PHY2LIN(pde_addr_phy_temp) + get_pde_index(cr2))) |= PG_P;
|
(*((u32 *)K_PHY2LIN(pde_addr_phy_temp) + get_pde_index(cr2))) |= PG_P;
|
||||||
// disp_color_str("[Solved]",0x74);
|
// kprintf("\033[92;47m[Solved]\033[0m in %d\n",p_proc_current->task.pid);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ //只是缺少物理页
|
{ //只是缺少物理页
|
||||||
// disp_color_str("[Pte Fault!]",0x74); //灰底红字
|
// kprintf("\033[91;47m[PTE FAULT]\033[0m in %d\n",p_proc_current->task.pid);
|
||||||
(*((u32 *)K_PHY2LIN(pte_addr_phy_temp) + get_pte_index(cr2))) |= PG_P;
|
(*((u32 *)K_PHY2LIN(pte_addr_phy_temp) + get_pte_index(cr2))) |= PG_P;
|
||||||
// disp_color_str("[Solved]",0x74);
|
// kprintf("\033[92;47m[Solved]\033[0m in %d\n",p_proc_current->task.pid);
|
||||||
}
|
}
|
||||||
refresh_page_cache();
|
refresh_page_cache();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,7 +57,7 @@ _warn(const char *file, int line, const char *fmt,...)
|
|||||||
*======================================================================*/
|
*======================================================================*/
|
||||||
void cstart()
|
void cstart()
|
||||||
{
|
{
|
||||||
kprintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n-----\"cstart\" begins-----\n");
|
kprintf("-----\"cstart\" begins-----\n");
|
||||||
|
|
||||||
// 将 LOADER 中的 GDT 复制到新的 GDT 中
|
// 将 LOADER 中的 GDT 复制到新的 GDT 中
|
||||||
memcpy( &gdt, // New GDT
|
memcpy( &gdt, // New GDT
|
||||||
|
|||||||
225
kernel/tty.c
225
kernel/tty.c
@ -14,10 +14,9 @@
|
|||||||
|
|
||||||
|
|
||||||
int current_console; // 当前显示在屏幕上的console
|
int current_console; // 当前显示在屏幕上的console
|
||||||
void tty_write(TTY *tty, char *buf, int len);
|
void tty_write(NTTY *tty, char *buf, int len);
|
||||||
int tty_read(TTY *tty, char *buf, int len);
|
int tty_read(NTTY *tty, char *buf, int len);
|
||||||
|
|
||||||
static void init_tty(TTY *tty);
|
|
||||||
static void tty_mouse(TTY *tty);
|
static void tty_mouse(TTY *tty);
|
||||||
static void tty_dev_read(TTY *tty);
|
static void tty_dev_read(TTY *tty);
|
||||||
static void tty_dev_write(TTY *tty);
|
static void tty_dev_write(TTY *tty);
|
||||||
@ -26,18 +25,22 @@ static void put_key(TTY *tty, u32 key);
|
|||||||
#ifdef DEBUGNEW
|
#ifdef DEBUGNEW
|
||||||
|
|
||||||
NTTY* cur_ntty;
|
NTTY* cur_ntty;
|
||||||
NTTY* default_ntty;
|
NTTY* ntty_table[NR_CONSOLES];
|
||||||
NTTY ntty_table[NR_CONSOLES];
|
|
||||||
// int cur_ntty = 0;
|
// int cur_ntty = 0;
|
||||||
static keyboard_buf keyboardbuf[NR_CONSOLES];
|
static keyboard_buf keyboardbuf[NR_CONSOLES];
|
||||||
static vga_buf vgabuf[NR_CONSOLES];
|
static vga_buf vgabuf[NR_CONSOLES];
|
||||||
|
|
||||||
|
inline NTTY* get_tty(const int nr_tty) {
|
||||||
|
return ntty_table[nr_tty];
|
||||||
|
}
|
||||||
|
|
||||||
void init_tty_main()
|
void init_tty_main()
|
||||||
{
|
{
|
||||||
NTTY *tty;
|
NTTY *tty;
|
||||||
for (int i = 0; i < 3; ++i)
|
for (int i = 0; i < 3; ++i)
|
||||||
{
|
{
|
||||||
tty = &ntty_table[i];
|
// tty = &ntty_table[i];
|
||||||
|
tty = (NTTY*)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
||||||
tty->driver_type = 1; // vga
|
tty->driver_type = 1; // vga
|
||||||
// tty->input_buf = (void*)do_kmalloc(sizeof(keyboard_buf));
|
// tty->input_buf = (void*)do_kmalloc(sizeof(keyboard_buf));
|
||||||
// tty->output_buf = (void*)do_kmalloc(sizeof(vga_buf));
|
// tty->output_buf = (void*)do_kmalloc(sizeof(vga_buf));
|
||||||
@ -45,8 +48,10 @@ void init_tty_main()
|
|||||||
tty->output_buf = &vgabuf[i];
|
tty->output_buf = &vgabuf[i];
|
||||||
vga_tty_init(tty);
|
vga_tty_init(tty);
|
||||||
ps2_tty_init(tty);
|
ps2_tty_init(tty);
|
||||||
|
ntty_table[i] = tty;
|
||||||
|
// kprintf("tty: %p, outbuf: %p\n", tty, tty->output_buf);
|
||||||
}
|
}
|
||||||
cur_ntty = default_ntty = &ntty_table[0];
|
cur_ntty = ntty_table[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -115,185 +120,21 @@ void in_process(TTY *p_tty, u32 key)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TTY_FIRST (tty_table)
|
|
||||||
#define TTY_END (tty_table + NR_CONSOLES)
|
|
||||||
|
|
||||||
void task_tty()
|
void task_tty()
|
||||||
{
|
{
|
||||||
#ifdef DEBUGNEW
|
|
||||||
// NTTY* p_tty;
|
// NTTY* p_tty;
|
||||||
// for (p_tty = ntty_table; p_tty < ntty_table + 3; ++ p_tty) {
|
// for (p_tty = ntty_table; p_tty < ntty_table + 3; ++ p_tty) {
|
||||||
// init_ntty(p_tty);
|
// init_ntty(p_tty);
|
||||||
// }
|
// }
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
// sys_yield();
|
||||||
// vga_tty_flush(cur_ntty);
|
// vga_tty_flush(cur_ntty);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
TTY *p_tty;
|
|
||||||
for (p_tty = TTY_FIRST; p_tty < TTY_END; p_tty++)
|
|
||||||
{
|
|
||||||
init_tty(p_tty);
|
|
||||||
}
|
|
||||||
p_tty = tty_table;
|
|
||||||
|
|
||||||
select_console(0);
|
|
||||||
|
|
||||||
// 设置第一个tty光标位置,第一个tty需要特殊处理
|
|
||||||
disable_int();
|
|
||||||
outb(CRTC_ADDR_REG, CURSOR_H);
|
|
||||||
outb(CRTC_DATA_REG, ((disp_pos / 2) >> 8) & 0xFF);
|
|
||||||
outb(CRTC_ADDR_REG, CURSOR_L);
|
|
||||||
outb(CRTC_DATA_REG, (disp_pos / 2) & 0xFF);
|
|
||||||
enable_int();
|
|
||||||
|
|
||||||
// 轮询
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
for (p_tty = TTY_FIRST; p_tty < TTY_END; p_tty++)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
tty_mouse(p_tty); /* tty判断鼠标操作 */
|
|
||||||
tty_dev_read(p_tty); /* 从键盘输入缓冲区读到这个tty自己的缓冲区 */
|
|
||||||
tty_dev_write(p_tty); /* 把tty缓存区的数据写到这个tty占有的显存 */
|
|
||||||
|
|
||||||
} while (p_tty->ibuf_cnt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_tty(TTY *p_tty)
|
|
||||||
{
|
|
||||||
p_tty->ibuf_read_cnt = p_tty->ibuf_cnt = 0;
|
|
||||||
p_tty->status = TTY_STATE_DISPLAY;
|
|
||||||
p_tty->ibuf_read = p_tty->ibuf_head = p_tty->ibuf_tail = p_tty->ibuf;
|
|
||||||
int det = p_tty - tty_table;
|
|
||||||
p_tty->console = console_table + det;
|
|
||||||
|
|
||||||
p_tty->mouse_left_button = 0;
|
|
||||||
p_tty->mouse_mid_button = 0;
|
|
||||||
p_tty->mouse_X = 0;
|
|
||||||
p_tty->mouse_Y = 0;
|
|
||||||
init_screen(p_tty);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tty_mouse(TTY *tty)
|
|
||||||
{
|
|
||||||
if (is_current_console(tty->console))
|
|
||||||
{
|
|
||||||
int real_line = tty->console->orig / SCR_WIDTH;
|
|
||||||
if (tty->mouse_left_button)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (tty->mouse_Y > MOUSE_UPDOWN_BOUND)
|
|
||||||
{ // 按住鼠标左键向上滚动
|
|
||||||
if (tty->console->current_line < 43)
|
|
||||||
{
|
|
||||||
disable_int();
|
|
||||||
tty->console->current_line++;
|
|
||||||
outb(CRTC_ADDR_REG, START_ADDR_H);
|
|
||||||
outb(CRTC_DATA_REG, ((80 * (tty->console->current_line + real_line)) >> 8) & 0xFF);
|
|
||||||
outb(CRTC_ADDR_REG, START_ADDR_L);
|
|
||||||
outb(CRTC_DATA_REG, (80 * (tty->console->current_line + real_line)) & 0xFF);
|
|
||||||
enable_int();
|
|
||||||
tty->mouse_Y = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (tty->mouse_Y < -MOUSE_UPDOWN_BOUND)
|
|
||||||
{ // 按住鼠标左键向下滚动
|
|
||||||
if (tty->console->current_line > 0)
|
|
||||||
{
|
|
||||||
disable_int();
|
|
||||||
tty->console->current_line--;
|
|
||||||
outb(CRTC_ADDR_REG, START_ADDR_H);
|
|
||||||
outb(CRTC_DATA_REG, ((80 * (tty->console->current_line + real_line)) >> 8) & 0xFF);
|
|
||||||
outb(CRTC_ADDR_REG, START_ADDR_L);
|
|
||||||
outb(CRTC_DATA_REG, (80 * (tty->console->current_line + real_line)) & 0xFF);
|
|
||||||
enable_int();
|
|
||||||
tty->mouse_Y = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tty->mouse_mid_button)
|
|
||||||
{ // 点击中键复原
|
|
||||||
disable_int();
|
|
||||||
tty->console->current_line = 0;
|
|
||||||
outb(CRTC_ADDR_REG, START_ADDR_H);
|
|
||||||
outb(CRTC_DATA_REG, ((80 * (tty->console->current_line + real_line)) >> 8) & 0xFF);
|
|
||||||
outb(CRTC_ADDR_REG, START_ADDR_L);
|
|
||||||
outb(CRTC_DATA_REG, (80 * (tty->console->current_line + real_line)) & 0xFF);
|
|
||||||
enable_int();
|
|
||||||
tty->mouse_Y = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifndef DEBUGNEW
|
|
||||||
static void tty_dev_read(TTY *tty)
|
|
||||||
{
|
|
||||||
if (is_current_console(tty->console))
|
|
||||||
{
|
|
||||||
keyboard_read(tty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tty_dev_write(TTY *tty)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (tty->ibuf_cnt)
|
|
||||||
{
|
|
||||||
char ch = *(tty->ibuf_tail);
|
|
||||||
tty->ibuf_tail++;
|
|
||||||
if (tty->ibuf_tail == tty->ibuf + TTY_IN_BYTES)
|
|
||||||
{
|
|
||||||
tty->ibuf_tail = tty->ibuf;
|
|
||||||
}
|
|
||||||
tty->ibuf_cnt--;
|
|
||||||
|
|
||||||
if (ch == '\b')
|
|
||||||
{
|
|
||||||
if (tty->ibuf_read_cnt == 1)
|
|
||||||
{
|
|
||||||
tty->ibuf_read_cnt--;
|
|
||||||
tty->ibuf_head--;
|
|
||||||
tty->ibuf_tail--;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tty->ibuf_read_cnt -= 2;
|
|
||||||
if (tty->ibuf_head == tty->ibuf)
|
|
||||||
{
|
|
||||||
tty->ibuf_head = tty->ibuf_tail = &tty->ibuf[256 - 2];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tty->ibuf_head--;
|
|
||||||
tty->ibuf_tail--;
|
|
||||||
tty->ibuf_head--;
|
|
||||||
tty->ibuf_tail--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out_char(tty->console, ch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
static void put_key(TTY *tty, u32 key)
|
|
||||||
{
|
|
||||||
if (tty->ibuf_cnt < TTY_IN_BYTES)
|
|
||||||
{
|
|
||||||
*(tty->ibuf_head) = key;
|
|
||||||
tty->ibuf_head++;
|
|
||||||
if (tty->ibuf_head == tty->ibuf + TTY_IN_BYTES)
|
|
||||||
tty->ibuf_head = tty->ibuf;
|
|
||||||
tty->ibuf_cnt++;
|
|
||||||
tty->ibuf_read_cnt++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* tty_write
|
* tty_write
|
||||||
@ -301,18 +142,13 @@ static void put_key(TTY *tty, u32 key)
|
|||||||
|
|
||||||
* 当fd=STD_OUT时,write()系统调用转发到此函数
|
* 当fd=STD_OUT时,write()系统调用转发到此函数
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void tty_write(TTY *tty, char *buf, int len)
|
void tty_write(NTTY *tty, char *buf, int len)
|
||||||
{
|
{
|
||||||
#ifdef DEBUGNEW
|
|
||||||
while (--len >= 0)
|
while (--len >= 0)
|
||||||
{
|
{
|
||||||
vga_tty_write(cur_ntty, *buf++);
|
vga_tty_write(tty, *buf++);
|
||||||
}
|
}
|
||||||
vga_tty_flush(cur_ntty);
|
if (cur_ntty == tty) vga_tty_flush(tty);
|
||||||
#else
|
|
||||||
while (--len >= 0)
|
|
||||||
out_char(tty->console, *buf++);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -321,32 +157,7 @@ void tty_write(TTY *tty, char *buf, int len)
|
|||||||
|
|
||||||
* 当fd=STD_IN时,read()系统调用转发到此函数
|
* 当fd=STD_IN时,read()系统调用转发到此函数
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int tty_read(TTY *tty, char *buf, int len)
|
int tty_read(NTTY *tty, char *buf, int len)
|
||||||
{
|
{
|
||||||
#ifdef DEBUGNEW
|
return ps2_tty_read(tty, buf, len);
|
||||||
return ps2_tty_read(cur_ntty, buf, len);
|
|
||||||
#else
|
|
||||||
int i = 0;
|
|
||||||
if (!tty->ibuf_read_cnt)
|
|
||||||
{
|
|
||||||
tty->status |= TTY_STATE_WAIT_ENTER;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((tty->status & TTY_STATE_WAIT_ENTER))
|
|
||||||
;
|
|
||||||
|
|
||||||
while (tty->ibuf_read_cnt && i < len)
|
|
||||||
{
|
|
||||||
buf[i] = *tty->ibuf_read;
|
|
||||||
tty->ibuf_read++;
|
|
||||||
if (tty->ibuf_read == tty->ibuf + TTY_IN_BYTES)
|
|
||||||
{
|
|
||||||
tty->ibuf_read = tty->ibuf;
|
|
||||||
}
|
|
||||||
tty->ibuf_read_cnt--;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return i;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
@ -137,6 +137,7 @@ static void init_vfs_table()
|
|||||||
// tty0
|
// tty0
|
||||||
// device_table[0].dev_name="dev_tty0";
|
// device_table[0].dev_name="dev_tty0";
|
||||||
// device_table[0].op = &f_op_table[0];
|
// device_table[0].op = &f_op_table[0];
|
||||||
|
memset(vfs_table, 0, sizeof(vfs_table));
|
||||||
vfs_table[0].fs_name = "dev_tty0"; // modifed by mingxuan 2020-10-18
|
vfs_table[0].fs_name = "dev_tty0"; // modifed by mingxuan 2020-10-18
|
||||||
vfs_table[0].op = &f_op_table[0];
|
vfs_table[0].op = &f_op_table[0];
|
||||||
vfs_table[0].sb = &super_block[0]; // 每个tty都有一个superblock //added by mingxuan 2020-10-30
|
vfs_table[0].sb = &super_block[0]; // 每个tty都有一个superblock //added by mingxuan 2020-10-30
|
||||||
@ -208,7 +209,9 @@ static int get_index(char path[])
|
|||||||
for (i = 0; i < NR_FS; i++) // modified by mingxuan 2020-10-29
|
for (i = 0; i < NR_FS; i++) // modified by mingxuan 2020-10-29
|
||||||
{
|
{
|
||||||
// if(!strcmp(dev_name, device_table[i].dev_name))
|
// if(!strcmp(dev_name, device_table[i].dev_name))
|
||||||
|
if(vfs_table[i].fs_name == NULL) continue;
|
||||||
if (!strcmp(fs_name, vfs_table[i].fs_name)) // modified by mingxuan 2020-10-18
|
if (!strcmp(fs_name, vfs_table[i].fs_name)) // modified by mingxuan 2020-10-18
|
||||||
|
// f**k u mingxuan, you bloody retarded idiot piece of shit
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +306,7 @@ int do_vopen(const char *path, int flags)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
kprintf(" error!\n");
|
kprintf("open %s error!\n", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
|
|||||||
@ -6,9 +6,10 @@ USERLIB_OBJS := $(patsubst %.c, $(OBJDIR)/%.o, $(USERLIB_SRCS))
|
|||||||
USERLIB_OBJS := $(patsubst %.asm, $(OBJDIR)/%.o, $(USERLIB_OBJS))
|
USERLIB_OBJS := $(patsubst %.asm, $(OBJDIR)/%.o, $(USERLIB_OBJS))
|
||||||
|
|
||||||
# 这里给我整不会了,文件名只能长度为16位,否则会寄,原因还挺难找
|
# 这里给我整不会了,文件名只能长度为16位,否则会寄,原因还挺难找
|
||||||
USER_SRCS := user/ptTest.c \
|
USER_SRCS := user/shell_1.c \
|
||||||
user/shell_0.c \
|
user/shell_0.c \
|
||||||
user/test.c \
|
user/test.c \
|
||||||
|
user/test2.c \
|
||||||
|
|
||||||
USER_BINS := $(patsubst %.c, $(OBJDIR)/%.bin, $(USER_SRCS))
|
USER_BINS := $(patsubst %.c, $(OBJDIR)/%.bin, $(USER_SRCS))
|
||||||
USER_BASENAMES := $(patsubst $(OBJDIR)/user/%, %, $(USER_BINS))
|
USER_BASENAMES := $(patsubst $(OBJDIR)/user/%, %, $(USER_BINS))
|
||||||
|
|||||||
54
user/shell_1.c
Normal file
54
user/shell_1.c
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#include "type.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "protect.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "proc.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "proto.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
int main(int arg, char *argv[])
|
||||||
|
{
|
||||||
|
if (0 == fork()) {
|
||||||
|
int stdin = open("dev_tty0", O_RDWR);
|
||||||
|
int stdout = open("dev_tty0", O_RDWR);
|
||||||
|
int stderr = open("dev_tty0", O_RDWR);
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
int pid;
|
||||||
|
int times = 0;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
printf("\nminiOS:/ $ ");
|
||||||
|
if (gets(buf) && strlen(buf) != 0)
|
||||||
|
{
|
||||||
|
if (exec(buf) != 0)
|
||||||
|
{
|
||||||
|
printf("exec failed: file not found!\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int stdin = open("dev_tty1", O_RDWR);
|
||||||
|
int stdout = open("dev_tty1", O_RDWR);
|
||||||
|
int stderr = open("dev_tty1", O_RDWR);
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
int pid;
|
||||||
|
int times = 0;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
printf("\nminiOS:/ $ ");
|
||||||
|
if (gets(buf) && strlen(buf) != 0)
|
||||||
|
{
|
||||||
|
if (exec(buf) != 0)
|
||||||
|
{
|
||||||
|
printf("exec failed: file not found!\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
40
user/test2.c
Normal file
40
user/test2.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include "type.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "protect.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "proc.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "proto.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
int main(int arg, char *argv[])
|
||||||
|
{
|
||||||
|
int pid = fork();
|
||||||
|
volatile int i;
|
||||||
|
if (pid == 0) {
|
||||||
|
int stdin = open("dev_tty0", O_RDWR);
|
||||||
|
int stdout = open("dev_tty0", O_RDWR);
|
||||||
|
int stderr = open("dev_tty0", O_RDWR);
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
printf("\x1b[32;40mAAA ");
|
||||||
|
i=100000000;
|
||||||
|
while(--i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int stdin = open("dev_tty1", O_RDWR);
|
||||||
|
int stdout = open("dev_tty1", O_RDWR);
|
||||||
|
int stderr = open("dev_tty1", O_RDWR);
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
char* s = "\x1b[33;40mBBB ";
|
||||||
|
for (char* p = s; *p != 0; p++ ){
|
||||||
|
write(stdout, p, 1);
|
||||||
|
}
|
||||||
|
i=100000000;
|
||||||
|
while(--i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user