From 71d6af78d8838448805fb44f509e87f826b17d17 Mon Sep 17 00:00:00 2001 From: fslongjin Date: Fri, 18 Mar 2022 19:18:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 3 +- kernel/Makefile | 12 +- kernel/common/printk.c | 8 +- kernel/common/printk.h | 2 +- .../keyboard/{keyboard.c => ps2_keyboard.c} | 67 +-- .../keyboard/{keyboard.h => ps2_keyboard.h} | 36 +- kernel/driver/mouse/mouse.c | 372 ----------------- kernel/driver/mouse/ps2_mouse.c | 384 ++++++++++++++++++ kernel/driver/mouse/{mouse.h => ps2_mouse.h} | 38 +- kernel/main.c | 24 +- kernel/mm/mm.h | 1 + run.sh | 2 +- 12 files changed, 484 insertions(+), 465 deletions(-) rename kernel/driver/keyboard/{keyboard.c => ps2_keyboard.c} (80%) rename kernel/driver/keyboard/{keyboard.h => ps2_keyboard.h} (80%) delete mode 100644 kernel/driver/mouse/mouse.c create mode 100644 kernel/driver/mouse/ps2_mouse.c rename kernel/driver/mouse/{mouse.h => ps2_mouse.h} (67%) diff --git a/.vscode/settings.json b/.vscode/settings.json index edb20976..005e4ca6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,7 +20,8 @@ "ptrace.h": "c", "mouse.h": "c", "keyboard.h": "c", - "apic.h": "c" + "apic.h": "c", + "ps2_keyboard.h": "c" }, "C_Cpp.errorSquiggles": "Enabled" } \ No newline at end of file diff --git a/kernel/Makefile b/kernel/Makefile index 986386fe..85f37a38 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -19,10 +19,10 @@ all: kernel objcopy -I elf64-x86-64 -S -R ".comment" -R ".eh_frame" -O elf64-x86-64 kernel ../bin/kernel/kernel.elf -kernel: head.o entry.o main.o printk.o trap.o mm.o slab.o irq.o pic.o process.o syscall.o multiboot2.o cpu.o acpi.o keyboard.o mouse.o +kernel: head.o entry.o main.o printk.o trap.o mm.o slab.o irq.o pic.o process.o syscall.o multiboot2.o cpu.o acpi.o ps2_keyboard.o ps2_mouse.o ld -b elf64-x86-64 -z muldefs -o kernel head.o exception/entry.o main.o common/printk.o exception/trap.o exception/irq.o mm/mm.o mm/slab.o process/process.o syscall/syscall.o driver/multiboot2/multiboot2.o \ common/cpu.o \ - driver/acpi/acpi.o driver/interrupt/pic.o driver/keyboard/keyboard.o driver/mouse/mouse.o \ + driver/acpi/acpi.o driver/interrupt/pic.o driver/keyboard/ps2_keyboard.o driver/mouse/ps2_mouse.o \ -T link.lds head.o: head.S @@ -85,11 +85,11 @@ multiboot2.o: driver/multiboot2/multiboot2.c acpi.o: driver/acpi/acpi.c gcc $(CFLAGS) -c driver/acpi/acpi.c -o driver/acpi/acpi.o -keyboard.o: driver/keyboard/keyboard.c - gcc $(CFLAGS) -c driver/keyboard/keyboard.c -o driver/keyboard/keyboard.o +ps2_keyboard.o: driver/keyboard/ps2_keyboard.c + gcc $(CFLAGS) -c driver/keyboard/ps2_keyboard.c -o driver/keyboard/ps2_keyboard.o -mouse.o: driver/mouse/mouse.c - gcc $(CFLAGS) -c driver/mouse/mouse.c -o driver/mouse/mouse.o +ps2_mouse.o: driver/mouse/ps2_mouse.c + gcc $(CFLAGS) -c driver/mouse/ps2_mouse.c -o driver/mouse/ps2_mouse.o clean: diff --git a/kernel/common/printk.c b/kernel/common/printk.c index c360f9d1..9a6be72a 100644 --- a/kernel/common/printk.c +++ b/kernel/common/printk.c @@ -112,9 +112,9 @@ void auto_newline() if (pos.y > pos.max_y) { pos.y = pos.max_y; - int lines_to_scroll = 2; - scroll(true, lines_to_scroll * pos.char_size_y, true); - pos.y -= (lines_to_scroll - 1); + int lines_to_scroll = 1; + scroll(true, lines_to_scroll * pos.char_size_y, false); + pos.y -= (lines_to_scroll-1); } } @@ -405,7 +405,7 @@ static int vsprintf(char *buf, const char *fmt, va_list args) return str - buf; } -static char *write_num(char *str, ll num, int base, int field_width, int precision, int flags) +static char *write_num(char *str, ul num, int base, int field_width, int precision, int flags) { /** * @brief 将数字按照指定的要求转换成对应的字符串 diff --git a/kernel/common/printk.h b/kernel/common/printk.h index ef9b25d8..2baaac85 100644 --- a/kernel/common/printk.h +++ b/kernel/common/printk.h @@ -88,7 +88,7 @@ static int vsprintf(char *buf, const char *fmt, va_list args); * @param precision 精度 * @param flags 标志位 */ -static char *write_num(char *str, ll num, int base, int field_width, int precision, int flags); +static char *write_num(char *str,ul num, int base, int field_width, int precision, int flags); static char *write_float_point_num(char *str, double num, int field_width, int precision, int flags); diff --git a/kernel/driver/keyboard/keyboard.c b/kernel/driver/keyboard/ps2_keyboard.c similarity index 80% rename from kernel/driver/keyboard/keyboard.c rename to kernel/driver/keyboard/ps2_keyboard.c index 4da17a37..4bb562f1 100644 --- a/kernel/driver/keyboard/keyboard.c +++ b/kernel/driver/keyboard/ps2_keyboard.c @@ -1,10 +1,10 @@ -#include "keyboard.h" +#include "ps2_keyboard.h" #include "../interrupt/apic/apic.h" #include "../../mm/mm.h" #include "../../mm/slab.h" #include "../../common/printk.h" -static struct keyboard_input_buffer *kb_buf_ptr = NULL; +static struct ps2_keyboard_input_buffer *kb_buf_ptr = NULL; // 功能键标志变量 static bool shift_l, shift_r, ctrl_l, ctrl_r, alt_l, alt_r; @@ -13,7 +13,7 @@ static bool kp_forward_slash, kp_en; struct apic_IO_APIC_RTE_entry entry; -hardware_intr_controller keyboard_intr_controller = +hardware_intr_controller ps2_keyboard_intr_controller = { .enable = apic_ioapic_enable, .disable = apic_ioapic_disable, @@ -30,19 +30,19 @@ hardware_intr_controller keyboard_intr_controller = * @param param 参数 * @param regs 寄存器信息 */ -void keyboard_handler(ul irq_num, ul param, struct pt_regs *regs) +void ps2_keyboard_handler(ul irq_num, ul param, struct pt_regs *regs) { // 读取键盘输入的信息 - unsigned char x = io_in8(PORT_KEYBOARD_DATA); + unsigned char x = io_in8(PORT_PS2_KEYBOARD_DATA); // printk_color(ORANGE, BLACK, "key_pressed:%02x\n", x); // 当头指针越过界时,恢复指向数组头部 - if (kb_buf_ptr->ptr_head == kb_buf_ptr->buffer + keyboard_buffer_size) + if (kb_buf_ptr->ptr_head == kb_buf_ptr->buffer + ps2_keyboard_buffer_size) kb_buf_ptr->ptr_head = kb_buf_ptr->buffer; - if (kb_buf_ptr->count >= keyboard_buffer_size) + if (kb_buf_ptr->count >= ps2_keyboard_buffer_size) { - kwarn("Keyboard input buffer is full."); + kwarn("ps2_keyboard input buffer is full."); return; } @@ -54,24 +54,26 @@ void keyboard_handler(ul irq_num, ul param, struct pt_regs *regs) * @brief 初始化键盘驱动程序的函数 * */ -void keyboard_init() +void ps2_keyboard_init() { + // 开启键盘中断,中断向量号为0x21,物理模式,投递至BSP处理器 + apic_ioapic_write_rte(0x12, 0x21); // ======= 初始化键盘循环队列缓冲区 =========== // 申请键盘循环队列缓冲区的内存 - kb_buf_ptr = (struct keyboard_input_buffer *)kmalloc(sizeof(struct keyboard_input_buffer), 0); + kb_buf_ptr = (struct ps2_keyboard_input_buffer *)kmalloc(sizeof(struct ps2_keyboard_input_buffer), 0); kb_buf_ptr->ptr_head = kb_buf_ptr->buffer; kb_buf_ptr->ptr_tail = kb_buf_ptr->buffer; kb_buf_ptr->count = 0; - memset(kb_buf_ptr->buffer, 0, keyboard_buffer_size); + memset(kb_buf_ptr->buffer, 0, ps2_keyboard_buffer_size); // ======== 初始化中断RTE entry ========== - entry.vector = KEYBOARD_INTR_VECTOR; // 设置中断向量号 - entry.deliver_mode = IO_APIC_FIXED; // 投递模式:混合 - entry.dest_mode = DEST_PHYSICAL; // 物理模式投递中断 + entry.vector = PS2_KEYBOARD_INTR_VECTOR; // 设置中断向量号 + entry.deliver_mode = IO_APIC_FIXED; // 投递模式:混合 + entry.dest_mode = DEST_PHYSICAL; // 物理模式投递中断 entry.deliver_status = IDLE; entry.trigger_mode = EDGE_TRIGGER; // 设置边沿触发 entry.polarity = POLARITY_HIGH; // 高电平触发 @@ -84,11 +86,11 @@ void keyboard_init() entry.destination.physical.phy_dest = 0; // 设置投递到BSP处理器 // ======== 初始化键盘控制器,写入配置值 ========= - wait_keyboard_write(); - io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_WRITE); - wait_keyboard_write(); - io_out8(PORT_KEYBOARD_DATA, KEYBOARD_PARAM_INIT); - wait_keyboard_write(); + wait_ps2_keyboard_write(); + io_out8(PORT_PS2_KEYBOARD_CONTROL, PS2_KEYBOARD_COMMAND_WRITE); + wait_ps2_keyboard_write(); + io_out8(PORT_PS2_KEYBOARD_DATA, PS2_KEYBOARD_PARAM_INIT); + wait_ps2_keyboard_write(); // 执行一百万次nop,等待键盘控制器把命令执行完毕 for (int i = 0; i < 1000; ++i) @@ -102,16 +104,17 @@ void keyboard_init() alt_r = false; // 注册中断处理程序 - irq_register(KEYBOARD_INTR_VECTOR, &entry, &keyboard_handler, (ul)kb_buf_ptr, &keyboard_intr_controller, "ps/2 keyboard"); + irq_register(PS2_KEYBOARD_INTR_VECTOR, &entry, &ps2_keyboard_handler, (ul)kb_buf_ptr, &ps2_keyboard_intr_controller, "ps/2 keyboard"); + kdebug("kb registered."); } /** * @brief 键盘驱动卸载函数 * */ -void keyboard_exit() +void ps2_keyboard_exit() { - irq_unregister(KEYBOARD_INTR_VECTOR); + irq_unregister(PS2_KEYBOARD_INTR_VECTOR); kfree((ul *)kb_buf_ptr); } @@ -119,11 +122,11 @@ void keyboard_exit() * @brief 解析键盘扫描码 * */ -void keyboard_analyze_keycode() +void ps2_keyboard_analyze_keycode() { bool flag_make = false; - int c = keyboard_get_scancode(); + int c = ps2_keyboard_get_scancode(); // 循环队列为空 if (c == -1) return; @@ -136,7 +139,7 @@ void keyboard_analyze_keycode() key = PAUSE_BREAK; // 清除缓冲区中剩下的扫描码 for (int i = 1; i < 6; ++i) - if (keyboard_get_scancode() != pause_break_scan_code[i]) + if (ps2_keyboard_get_scancode() != pause_break_scan_code[i]) { key = 0; break; @@ -145,20 +148,20 @@ void keyboard_analyze_keycode() else if (scancode == 0xE0) // 功能键, 有多个扫描码 { // 获取下一个扫描码 - scancode = keyboard_get_scancode(); + scancode = ps2_keyboard_get_scancode(); switch (scancode) { case 0x2a: // print screen 按键被按下 - if (keyboard_get_scancode() == 0xe0) - if (keyboard_get_scancode() == 0x37) + if (ps2_keyboard_get_scancode() == 0xe0) + if (ps2_keyboard_get_scancode() == 0x37) { key = PRINT_SCREEN; flag_make = true; } break; case 0xb7: // print screen 按键被松开 - if (keyboard_get_scancode() == 0xe0) - if (keyboard_get_scancode() == 0xaa) + if (ps2_keyboard_get_scancode() == 0xe0) + if (ps2_keyboard_get_scancode() == 0xaa) { key = PRINT_SCREEN; flag_make = false; @@ -353,13 +356,13 @@ void keyboard_analyze_keycode() * @brief 从缓冲队列中获取键盘扫描码 * */ -int keyboard_get_scancode() +int ps2_keyboard_get_scancode() { // 缓冲队列为空 if (kb_buf_ptr->count == 0) return -1; - if (kb_buf_ptr->ptr_tail == kb_buf_ptr->buffer + keyboard_buffer_size) + if (kb_buf_ptr->ptr_tail == kb_buf_ptr->buffer + ps2_keyboard_buffer_size) kb_buf_ptr->ptr_tail = kb_buf_ptr->buffer; int ret = (int)(*(kb_buf_ptr->ptr_tail)); diff --git a/kernel/driver/keyboard/keyboard.h b/kernel/driver/keyboard/ps2_keyboard.h similarity index 80% rename from kernel/driver/keyboard/keyboard.h rename to kernel/driver/keyboard/ps2_keyboard.h index 9084781a..2fa21d2c 100644 --- a/kernel/driver/keyboard/keyboard.h +++ b/kernel/driver/keyboard/ps2_keyboard.h @@ -2,39 +2,39 @@ #include "../../common/glib.h" -#define KEYBOARD_INTR_VECTOR 0x21 // 键盘的中断向量号 +#define PS2_KEYBOARD_INTR_VECTOR 0x21 // 键盘的中断向量号 // 定义键盘循环队列缓冲区大小为100bytes -#define keyboard_buffer_size 100 +#define ps2_keyboard_buffer_size 100 /** * @brief 键盘循环队列缓冲区结构体 * */ -struct keyboard_input_buffer +struct ps2_keyboard_input_buffer { unsigned char *ptr_head; unsigned char *ptr_tail; int count; - unsigned char buffer[keyboard_buffer_size]; + unsigned char buffer[ps2_keyboard_buffer_size]; }; -#define PORT_KEYBOARD_DATA 0x60 -#define PORT_KEYBOARD_STATUS 0x64 -#define PORT_KEYBOARD_CONTROL 0x64 +#define PORT_PS2_KEYBOARD_DATA 0x60 +#define PORT_PS2_KEYBOARD_STATUS 0x64 +#define PORT_PS2_KEYBOARD_CONTROL 0x64 -#define KEYBOARD_COMMAND_WRITE 0x60 // 向键盘发送配置命令 -#define KEYBOARD_COMMAND_READ 0x20 // 读取键盘的配置值 -#define KEYBOARD_PARAM_INIT 0x47 // 初始化键盘控制器的配置值 +#define PS2_KEYBOARD_COMMAND_WRITE 0x60 // 向键盘发送配置命令 +#define PS2_KEYBOARD_COMMAND_READ 0x20 // 读取键盘的配置值 +#define PS2_KEYBOARD_PARAM_INIT 0x47 // 初始化键盘控制器的配置值 // ========= 检测键盘控制器输入/输出缓冲区是否已满 -#define KEYBOARD_FLAG_OUTBUF_FULL 0x01 // 键盘的输出缓冲区已满标志位 -#define KEYBOARD_FLAG_INBUF_FULL 0x02 // 键盘的输入缓冲区已满标志位 +#define PS2_KEYBOARD_FLAG_OUTBUF_FULL 0x01 // 键盘的输出缓冲区已满标志位 +#define PS2_KEYBOARD_FLAG_INBUF_FULL 0x02 // 键盘的输入缓冲区已满标志位 // 等待向键盘控制器写入信息完成 -#define wait_keyboard_write() while (io_in8(PORT_KEYBOARD_STATUS) & KEYBOARD_FLAG_INBUF_FULL) +#define wait_ps2_keyboard_write() while (io_in8(PORT_PS2_KEYBOARD_STATUS) & PS2_KEYBOARD_FLAG_INBUF_FULL) // 等待从键盘控制器读取信息完成 -#define wait_keyboard_read() while (io_in8(PORT_KEYBOARD_STATUS) & KEYBOARD_FLAG_OUTBUF_FULL) +#define wait_ps2_keyboard_read() while (io_in8(PORT_PS2_KEYBOARD_STATUS) & PS2_KEYBOARD_FLAG_OUTBUF_FULL) // 128个按键, 每个按键包含普通按键和shift+普通按键两种状态 #define NUM_SCAN_CODES 0x80 @@ -199,23 +199,23 @@ uint keycode_map_normal[NUM_SCAN_CODES*MAP_COLS] = * @brief 初始化键盘驱动程序的函数 * */ -void keyboard_init(); +void ps2_keyboard_init(); /** * @brief 键盘驱动卸载函数 * */ -void keyboard_exit(); +void ps2_keyboard_exit(); /** * @brief 解析键盘扫描码 * */ -void keyboard_analyze_keycode(); +void ps2_keyboard_analyze_keycode(); /** * @brief 从缓冲队列中获取键盘扫描码 * @return 键盘扫描码 * 若缓冲队列为空则返回-1 */ -int keyboard_get_scancode(); \ No newline at end of file +int ps2_keyboard_get_scancode(); \ No newline at end of file diff --git a/kernel/driver/mouse/mouse.c b/kernel/driver/mouse/mouse.c deleted file mode 100644 index 5b8904b2..00000000 --- a/kernel/driver/mouse/mouse.c +++ /dev/null @@ -1,372 +0,0 @@ -#include "mouse.h" -#include "../interrupt/apic/apic.h" -#include "../../mm/mm.h" -#include "../../mm/slab.h" -#include "../../common/printk.h" -#include "../../common/kprint.h" - -static struct mouse_input_buffer *mouse_buf_ptr = NULL; -static int c = 0; -struct apic_IO_APIC_RTE_entry mouse_entry; -static unsigned char mouse_id = 0; -struct mouse_packet_3bytes pak; -static mouse_count = 0; -/** - * @brief 清空缓冲区 - * - */ -static void mouse_clear_buf() -{ - mouse_buf_ptr->ptr_head = mouse_buf_ptr->buffer; - mouse_buf_ptr->ptr_tail = mouse_buf_ptr->buffer; - mouse_buf_ptr->count = 0; - memset(mouse_buf_ptr->buffer, 0, mouse_buffer_size); -} - -/** - * @brief 从缓冲队列中获取鼠标数据字节 - * @return 鼠标数据包的字节 - * 若缓冲队列为空则返回-1024 - */ -static int mouse_get_scancode() -{ - // 缓冲队列为空 - if (mouse_buf_ptr->count == 0) - while (!mouse_buf_ptr->count) - nop(); - - if (mouse_buf_ptr->ptr_tail == mouse_buf_ptr->buffer + mouse_buffer_size) - mouse_buf_ptr->ptr_tail = mouse_buf_ptr->buffer; - - int ret = (int)((char)(*(mouse_buf_ptr->ptr_tail))); - --(mouse_buf_ptr->count); - ++(mouse_buf_ptr->ptr_tail); - // printk("count=%d", mouse_buf_ptr->count); - - return ret; -} - -/** - * @brief 鼠标中断处理函数(中断上半部) - * 将数据存入缓冲区 - * @param irq_num 中断向量号 - * @param param 参数 - * @param regs 寄存器信息 - */ -void mouse_handler(ul irq_num, ul param, struct pt_regs *regs) -{ - // 读取鼠标输入的信息 - unsigned char x = io_in8(PORT_KEYBOARD_DATA); - - // 当头指针越过界时,恢复指向数组头部 - if (mouse_buf_ptr->ptr_head == mouse_buf_ptr->buffer + mouse_buffer_size) - mouse_buf_ptr->ptr_head = mouse_buf_ptr->buffer; - - if (mouse_buf_ptr->count >= mouse_buffer_size) - { - kwarn("mouse input buffer is full."); - return; - } - - *mouse_buf_ptr->ptr_head = x; - ++(mouse_buf_ptr->count); - ++(mouse_buf_ptr->ptr_head); - printk("c=%d\tval = %d\n", ++c, x); -} - -hardware_intr_controller mouse_intr_controller = - { - .enable = apic_ioapic_enable, - .disable = apic_ioapic_disable, - .install = apic_ioapic_install, - .uninstall = apic_ioapic_uninstall, - .ack = apic_ioapic_edge_ack, - -}; - -/** - * @brief 从键盘控制器读取mouse id - * - * @return unsigned char 鼠标id - */ -static unsigned char mouse_get_mouse_ID() -{ - // 读取鼠标的ID - io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_SEND_TO_MOUSE); - wait_keyboard_write(); - io_out8(PORT_KEYBOARD_DATA, MOUSE_GET_ID); - wait_keyboard_write(); - mouse_id = io_in8(PORT_KEYBOARD_DATA); - for (int i = 0; i < 1000; i++) - for (int j = 0; j < 1000; j++) - nop(); - return mouse_id; -} - -/** - * @brief 设置鼠标采样率 - * - * @param hz 采样率 - */ -int mouse_set_sample_rate(unsigned int hz) -{ - switch (hz) - { - case 10: - case 20: - case 40: - case 60: - case 80: - case 100: - case 200: - wait_keyboard_write(); - io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_SEND_TO_MOUSE); - wait_keyboard_write(); - io_out8(PORT_KEYBOARD_DATA, MOUSE_SET_SAMPLING_RATE); - wait_keyboard_write(); - for (int i = 0; i < 1000; i++) - for (int j = 0; j < 1000; j++) - nop(); - io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_SEND_TO_MOUSE); - wait_keyboard_write(); - io_out8(PORT_KEYBOARD_DATA, hz); - for (int i = 0; i < 1000; i++) - for (int j = 0; j < 1000; j++) - nop(); - wait_keyboard_write(); - - break; - - default: - return EINVALID_ARGUMENT; - break; - } - return SUCCESS; -} -/** - * @brief 使鼠标支持滚轮 - * 该模式下,鼠标ID=3 - */ -static int mouse_enable_scroll_wheel() -{ - if (mouse_id == 3) - return SUCCESS; - - mouse_set_sample_rate(200); - mouse_set_sample_rate(100); - mouse_set_sample_rate(80); - if (mouse_get_mouse_ID() != 3) - { - kerror("Cannot set mouse ID to 3"); - return EFAIL; - } - // 清空缓冲区,防止解析时产生错误 - mouse_clear_buf(); - return SUCCESS; -} -/** - * @brief 使鼠标支持5键 - * 该模式下ID=4 - */ -static int mouse_enable_5keys() -{ - if (mouse_id == 4) - return SUCCESS; - // 根据规范,应当先启用ID=3 - mouse_enable_scroll_wheel(); - - mouse_set_sample_rate(200); - mouse_set_sample_rate(200); - mouse_set_sample_rate(80); - if (mouse_get_mouse_ID() != 4) - { - kerror("Cannot set mouse ID to 4"); - return EFAIL; - } - // 清空缓冲区,防止解析时产生错误 - mouse_clear_buf(); - - return SUCCESS; -} -/** - * @brief 初始化鼠标驱动程序 - * - */ -void mouse_init() -{ - // 初始化鼠标读入队列缓冲区 - mouse_buf_ptr = (struct mouse_input_buffer *)kmalloc(sizeof(struct mouse_input_buffer), 0); - mouse_buf_ptr->ptr_head = mouse_buf_ptr->buffer; - mouse_buf_ptr->ptr_tail = mouse_buf_ptr->buffer; - mouse_buf_ptr->count = 0; - memset(mouse_buf_ptr->buffer, 0, mouse_buffer_size); - - // ======== 初始化中断RTE entry ========== - - mouse_entry.vector = MOUSE_INTR_VECTOR; // 设置中断向量号 - mouse_entry.deliver_mode = IO_APIC_FIXED; // 投递模式:混合 - mouse_entry.dest_mode = DEST_PHYSICAL; // 物理模式投递中断 - mouse_entry.deliver_status = IDLE; - mouse_entry.trigger_mode = EDGE_TRIGGER; // 设置边沿触发 - mouse_entry.polarity = POLARITY_HIGH; // 高电平触发 - mouse_entry.remote_IRR = IRR_RESET; - mouse_entry.mask = MASKED; - mouse_entry.reserved = 0; - - mouse_entry.destination.physical.reserved1 = 0; - mouse_entry.destination.physical.reserved2 = 0; - mouse_entry.destination.physical.phy_dest = 0; // 设置投递到BSP处理器 - - // 注册中断处理程序 - irq_register(MOUSE_INTR_VECTOR, &mouse_entry, &mouse_handler, (ul)mouse_buf_ptr, &mouse_intr_controller, "ps/2 mouse"); - - wait_keyboard_write(); - io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_ENABLE_MOUSE_PORT); // 开启鼠标端口 - for (int i = 0; i < 1000; i++) - for (int j = 0; j < 1000; j++) - nop(); - wait_keyboard_write(); - - io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_SEND_TO_MOUSE); - wait_keyboard_write(); - io_out8(PORT_KEYBOARD_DATA, MOUSE_ENABLE); // 允许鼠标设备发送数据包 - - for (int i = 0; i < 1000; i++) - for (int j = 0; j < 1000; j++) - nop(); - wait_keyboard_write(); - io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_WRITE); - wait_keyboard_write(); - io_out8(PORT_KEYBOARD_DATA, KEYBOARD_PARAM_INIT); // 设置键盘控制器 - for (int i = 0; i < 1000; i++) - for (int j = 0; j < 1000; j++) - nop(); - wait_keyboard_write(); - // mouse_enable_5keys(); - //mouse_get_mouse_ID(); - //mouse_set_sample_rate(100); - mouse_clear_buf(); - kdebug("mouse ID:%d", mouse_id); - c = 0; -} - -/** - * @brief 卸载鼠标驱动程序 - * - */ -void mouse_exit() -{ - irq_unregister(MOUSE_INTR_VECTOR); - kfree((ul *)mouse_buf_ptr); -} - -/** - * @brief 获取鼠标数据包 - * - * @param packet 数据包的返回值 - * @return int 错误码 - */ -int mouse_get_packet(void *packet) -{ - // if (mouse_buf_ptr->count != 0) - // kdebug("at get packet: count=%d", mouse_buf_ptr->count); - int code = 0; - switch (mouse_id) - { - case 0: // 3bytes 数据包 - if (mouse_buf_ptr->count < 4) - return EFAIL; - do - { - code = mouse_get_scancode(); - ((struct mouse_packet_3bytes *)packet)->byte0 = (unsigned char)code; - } while (code == -1024); - - do - { - code = mouse_get_scancode(); - ((struct mouse_packet_3bytes *)packet)->movement_x = (char)code; - } while (code == -1024); - - do - { - code = mouse_get_scancode(); - ((struct mouse_packet_3bytes *)packet)->movement_y = (char)code; - } while (code == -1024); - - return SUCCESS; - break; - - case 3: // 4bytes数据包 - case 4: - if (mouse_buf_ptr->count < 5) - return EFAIL; - do - { - code = mouse_get_scancode(); - ((struct mouse_packet_4bytes *)packet)->byte0 = (unsigned char)code; - } while (code == -1024); - - do - { - code = mouse_get_scancode(); - ((struct mouse_packet_4bytes *)packet)->movement_x = (char)code; - } while (code == -1024); - - do - { - code = mouse_get_scancode(); - ((struct mouse_packet_4bytes *)packet)->movement_y = (char)code; - } while (code == -1024); - - do - { - code = mouse_get_scancode(); - ((struct mouse_packet_4bytes *)packet)->byte3 = (char)code; - } while (code == -1024); - - return SUCCESS; - break; - - default: // Should not reach here - kBUG("mouse_get_packet(): Invalid mouse_id!"); - return EFAIL; - break; - } - return SUCCESS; -} - -void analyze_mousecode() -{ - if(!mouse_buf_ptr->count) - return; - else printk_color(ORANGE, BLACK, "COUNT=%d\n", mouse_buf_ptr->count); - unsigned char x = mouse_get_scancode(); - - switch (mouse_count) - { - case 0: - mouse_count++; - break; - - case 1: - pak.byte0 = x; - mouse_count++; - break; - - case 2: - pak.movement_x = (char)x; - mouse_count++; - break; - - case 3: - pak.movement_y = (char)x; - mouse_count = 1; - - printk_color(RED, GREEN, "(M:%02x,X:%3d,Y:%3d)\tcount=%d\n", pak.byte0, pak.movement_x, pak.movement_y, mouse_buf_ptr->count); - break; - - default: - break; - } -} \ No newline at end of file diff --git a/kernel/driver/mouse/ps2_mouse.c b/kernel/driver/mouse/ps2_mouse.c new file mode 100644 index 00000000..f2746f8a --- /dev/null +++ b/kernel/driver/mouse/ps2_mouse.c @@ -0,0 +1,384 @@ +#include "ps2_mouse.h" +#include "../interrupt/apic/apic.h" +#include "../../mm/mm.h" +#include "../../mm/slab.h" +#include "../../common/printk.h" +#include "../../common/kprint.h" + +static struct ps2_mouse_input_buffer *ps2_mouse_buf_ptr = NULL; +static int c = 0; +struct apic_IO_APIC_RTE_entry ps2_mouse_entry; +static unsigned char ps2_mouse_id = 0; +struct ps2_mouse_packet_3bytes pak; +static int ps2_mouse_count = 0; +/** + * @brief 清空缓冲区 + * + */ +static void ps2_mouse_clear_buf() +{ + ps2_mouse_buf_ptr->ptr_head = ps2_mouse_buf_ptr->buffer; + ps2_mouse_buf_ptr->ptr_tail = ps2_mouse_buf_ptr->buffer; + ps2_mouse_buf_ptr->count = 0; + memset(ps2_mouse_buf_ptr->buffer, 0, ps2_mouse_buffer_size); +} + +/** + * @brief 从缓冲队列中获取鼠标数据字节 + * @return 鼠标数据包的字节 + * 若缓冲队列为空则返回-1024 + */ +static int ps2_mouse_get_scancode() +{ + // 缓冲队列为空 + if (ps2_mouse_buf_ptr->count == 0) + while (!ps2_mouse_buf_ptr->count) + nop(); + + if (ps2_mouse_buf_ptr->ptr_tail == ps2_mouse_buf_ptr->buffer + ps2_mouse_buffer_size) + ps2_mouse_buf_ptr->ptr_tail = ps2_mouse_buf_ptr->buffer; + + int ret = (int)((char)(*(ps2_mouse_buf_ptr->ptr_tail))); + --(ps2_mouse_buf_ptr->count); + ++(ps2_mouse_buf_ptr->ptr_tail); + // printk("count=%d", ps2_mouse_buf_ptr->count); + + return ret; +} + +/** + * @brief 鼠标中断处理函数(中断上半部) + * 将数据存入缓冲区 + * @param irq_num 中断向量号 + * @param param 参数 + * @param regs 寄存器信息 + */ +void ps2_mouse_handler(ul irq_num, ul param, struct pt_regs *regs) +{ + // 读取鼠标输入的信息 + unsigned char x = io_in8(PORT_KEYBOARD_DATA); + + // 当头指针越过界时,恢复指向数组头部 + if (ps2_mouse_buf_ptr->ptr_head == ps2_mouse_buf_ptr->buffer + ps2_mouse_buffer_size) + ps2_mouse_buf_ptr->ptr_head = ps2_mouse_buf_ptr->buffer; + + if (ps2_mouse_buf_ptr->count >= ps2_mouse_buffer_size) + { + kwarn("ps2_mouse input buffer is full."); + return; + } + + *ps2_mouse_buf_ptr->ptr_head = x; + ++(ps2_mouse_buf_ptr->count); + ++(ps2_mouse_buf_ptr->ptr_head); + printk("c=%d\tval = %d\n", ++c, x); +} + +hardware_intr_controller ps2_mouse_intr_controller = + { + .enable = apic_ioapic_enable, + .disable = apic_ioapic_disable, + .install = apic_ioapic_install, + .uninstall = apic_ioapic_uninstall, + .ack = apic_ioapic_edge_ack, + +}; + +/** + * @brief 从键盘控制器读取ps2_mouse id + * + * @return unsigned char 鼠标id + */ +static unsigned char ps2_mouse_get_mouse_ID() +{ + // 读取鼠标的ID + io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_SEND_TO_PS2_MOUSE); + wait_keyboard_write(); + io_out8(PORT_KEYBOARD_DATA, PS2_MOUSE_GET_ID); + wait_keyboard_write(); + ps2_mouse_id = io_in8(PORT_KEYBOARD_DATA); + wait_keyboard_write(); + io_in8(PORT_KEYBOARD_DATA); + for (int i = 0; i < 1000; i++) + for (int j = 0; j < 1000; j++) + nop(); + return ps2_mouse_id; +} + +/** + * @brief 设置鼠标采样率 + * + * @param hz 采样率 + */ +int ps2_mouse_set_sample_rate(unsigned int hz) +{ + switch (hz) + { + case 10: + case 20: + case 40: + case 60: + case 80: + case 100: + case 200: + wait_keyboard_write(); + io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_SEND_TO_PS2_MOUSE); + wait_keyboard_write(); + io_out8(PORT_KEYBOARD_DATA, PS2_MOUSE_SET_SAMPLING_RATE); + wait_keyboard_write(); + io_in8(PORT_KEYBOARD_DATA); + + for (int i = 0; i < 1000; i++) + for (int j = 0; j < 1000; j++) + nop(); + + io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_SEND_TO_PS2_MOUSE); + wait_keyboard_write(); + io_out8(PORT_KEYBOARD_DATA, hz); + for (int i = 0; i < 1000; i++) + for (int j = 0; j < 1000; j++) + nop(); + wait_keyboard_write(); + io_in8(PORT_KEYBOARD_DATA); + + break; + + default: + return EINVALID_ARGUMENT; + break; + } + return SUCCESS; +} +/** + * @brief 使鼠标支持滚轮 + * 该模式下,鼠标ID=3 + */ +static int ps2_mouse_enable_scroll_wheel() +{ + if (ps2_mouse_id == 3) + return SUCCESS; + + ps2_mouse_set_sample_rate(200); + ps2_mouse_set_sample_rate(100); + ps2_mouse_set_sample_rate(80); + if (ps2_mouse_get_mouse_ID() != 3) + { + kerror("Cannot set mouse ID to 3"); + return EFAIL; + } + // 清空缓冲区,防止解析时产生错误 + ps2_mouse_clear_buf(); + return SUCCESS; +} +/** + * @brief 使鼠标支持5键 + * 该模式下ID=4 + */ +static int ps2_mouse_enable_5keys() +{ + if (ps2_mouse_id == 4) + return SUCCESS; + // 根据规范,应当先启用ID=3 + ps2_mouse_enable_scroll_wheel(); + + ps2_mouse_set_sample_rate(200); + ps2_mouse_set_sample_rate(200); + ps2_mouse_set_sample_rate(80); + if (ps2_mouse_get_mouse_ID() != 4) + { + kerror("Cannot set ps2_mouse ID to 4"); + return EFAIL; + } + // 清空缓冲区,防止解析时产生错误 + ps2_mouse_clear_buf(); + + return SUCCESS; +} +/** + * @brief 初始化鼠标驱动程序 + * + */ +void ps2_mouse_init() +{ + // 初始化鼠标读入队列缓冲区 + ps2_mouse_buf_ptr = (struct ps2_mouse_input_buffer *)kmalloc(sizeof(struct ps2_mouse_input_buffer), 0); + ps2_mouse_buf_ptr->ptr_head = ps2_mouse_buf_ptr->buffer; + ps2_mouse_buf_ptr->ptr_tail = ps2_mouse_buf_ptr->buffer; + ps2_mouse_buf_ptr->count = 0; + memset(ps2_mouse_buf_ptr->buffer, 0, ps2_mouse_buffer_size); + + // ======== 初始化中断RTE entry ========== + + ps2_mouse_entry.vector = PS2_MOUSE_INTR_VECTOR; // 设置中断向量号 + ps2_mouse_entry.deliver_mode = IO_APIC_FIXED; // 投递模式:混合 + ps2_mouse_entry.dest_mode = DEST_PHYSICAL; // 物理模式投递中断 + ps2_mouse_entry.deliver_status = IDLE; + ps2_mouse_entry.trigger_mode = EDGE_TRIGGER; // 设置边沿触发 + ps2_mouse_entry.polarity = POLARITY_HIGH; // 高电平触发 + ps2_mouse_entry.remote_IRR = IRR_RESET; + ps2_mouse_entry.mask = MASKED; + ps2_mouse_entry.reserved = 0; + + ps2_mouse_entry.destination.physical.reserved1 = 0; + ps2_mouse_entry.destination.physical.reserved2 = 0; + ps2_mouse_entry.destination.physical.phy_dest = 0; // 设置投递到BSP处理器 + + // 注册中断处理程序 + irq_register(PS2_MOUSE_INTR_VECTOR, &ps2_mouse_entry, &ps2_mouse_handler, (ul)ps2_mouse_buf_ptr, &ps2_mouse_intr_controller, "ps/2 mouse"); + + wait_keyboard_write(); + io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_ENABLE_PS2_MOUSE_PORT); // 开启鼠标端口 + for (int i = 0; i < 1000; i++) + for (int j = 0; j < 1000; j++) + nop(); + wait_keyboard_write(); + io_in8(PORT_KEYBOARD_DATA); + + io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_SEND_TO_PS2_MOUSE); + wait_keyboard_write(); + io_out8(PORT_KEYBOARD_DATA, PS2_MOUSE_ENABLE); // 允许鼠标设备发送数据包 + wait_keyboard_write(); + io_in8(PORT_KEYBOARD_DATA); + + for (int i = 0; i < 1000; i++) + for (int j = 0; j < 1000; j++) + nop(); + wait_keyboard_write(); + io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_WRITE); + wait_keyboard_write(); + io_out8(PORT_KEYBOARD_DATA, KEYBOARD_PARAM_INIT); // 设置键盘控制器 + wait_keyboard_write(); + io_in8(PORT_KEYBOARD_DATA); + for (int i = 0; i < 1000; i++) + for (int j = 0; j < 1000; j++) + nop(); + wait_keyboard_write(); + //ps2_mouse_enable_5keys(); + ps2_mouse_get_mouse_ID(); + ps2_mouse_set_sample_rate(30); + ps2_mouse_clear_buf(); + kdebug("ps2_mouse ID:%d", ps2_mouse_id); + c = 0; + //ps2_mouse_count = 1; +} + +/** + * @brief 卸载鼠标驱动程序 + * + */ +void ps2_mouse_exit() +{ + irq_unregister(PS2_MOUSE_INTR_VECTOR); + kfree((ul *)ps2_mouse_buf_ptr); +} + +/** + * @brief 获取鼠标数据包 + * + * @param packet 数据包的返回值 + * @return int 错误码 + */ +int ps2_mouse_get_packet(void *packet) +{ + // if (ps2_mouse_buf_ptr->count != 0) + // kdebug("at get packet: count=%d", ps2_mouse_buf_ptr->count); + int code = 0; + switch (ps2_mouse_id) + { + case 0: // 3bytes 数据包 + if (ps2_mouse_buf_ptr->count < 4) + return EFAIL; + do + { + code = ps2_mouse_get_scancode(); + ((struct ps2_mouse_packet_3bytes *)packet)->byte0 = (unsigned char)code; + } while (code == -1024); + + do + { + code = ps2_mouse_get_scancode(); + ((struct ps2_mouse_packet_3bytes *)packet)->movement_x = (char)code; + } while (code == -1024); + + do + { + code = ps2_mouse_get_scancode(); + ((struct ps2_mouse_packet_3bytes *)packet)->movement_y = (char)code; + } while (code == -1024); + + return SUCCESS; + break; + + case 3: // 4bytes数据包 + case 4: + if (ps2_mouse_buf_ptr->count < 5) + return EFAIL; + do + { + code = ps2_mouse_get_scancode(); + ((struct ps2_mouse_packet_4bytes *)packet)->byte0 = (unsigned char)code; + } while (code == -1024); + + do + { + code = ps2_mouse_get_scancode(); + ((struct ps2_mouse_packet_4bytes *)packet)->movement_x = (char)code; + } while (code == -1024); + + do + { + code = ps2_mouse_get_scancode(); + ((struct ps2_mouse_packet_4bytes *)packet)->movement_y = (char)code; + } while (code == -1024); + + do + { + code = ps2_mouse_get_scancode(); + ((struct ps2_mouse_packet_4bytes *)packet)->byte3 = (char)code; + } while (code == -1024); + + return SUCCESS; + break; + + default: // Should not reach here + kBUG("ps2_mouse_get_packet(): Invalid ps2_mouse_id!"); + return EFAIL; + break; + } + return SUCCESS; +} + +void analyze_mousecode() +{ + if(!ps2_mouse_buf_ptr->count) + return; + else printk_color(ORANGE, BLACK, "COUNT=%d\n", ps2_mouse_buf_ptr->count); + unsigned char x = ps2_mouse_get_scancode(); + + switch (ps2_mouse_count) + { + case 0: + ps2_mouse_count++; + break; + + case 1: + pak.byte0 = x; + ps2_mouse_count++; + break; + + case 2: + pak.movement_x = (char)x; + ps2_mouse_count++; + break; + + case 3: + pak.movement_y = (char)x; + ps2_mouse_count = 1; + + printk_color(RED, GREEN, "(M:%02x,X:%3d,Y:%3d)\tcount=%d\n", pak.byte0, pak.movement_x, pak.movement_y, ps2_mouse_buf_ptr->count); + break; + + default: + break; + } +} \ No newline at end of file diff --git a/kernel/driver/mouse/mouse.h b/kernel/driver/mouse/ps2_mouse.h similarity index 67% rename from kernel/driver/mouse/mouse.h rename to kernel/driver/mouse/ps2_mouse.h index 1718eb89..2427dd0d 100644 --- a/kernel/driver/mouse/mouse.h +++ b/kernel/driver/mouse/ps2_mouse.h @@ -2,21 +2,21 @@ #include "../../common/glib.h" -#define MOUSE_INTR_VECTOR 0x2c // 鼠标的中断向量号 +#define PS2_MOUSE_INTR_VECTOR 0x2c // 鼠标的中断向量号 -#define KEYBOARD_COMMAND_SEND_TO_MOUSE 0xd4 // 键盘控制器向鼠标设备发送数据的命令 +#define KEYBOARD_COMMAND_SEND_TO_PS2_MOUSE 0xd4 // 键盘控制器向鼠标设备发送数据的命令 -#define MOUSE_GET_ID 0xf2 // 获取鼠标的ID -#define MOUSE_SET_SAMPLING_RATE 0xf3 // 设置鼠标的采样率 -#define MOUSE_ENABLE 0xf4 // 允许鼠标设备发送数据包 -#define MOUSE_DISABLE 0xf5 // 禁止鼠标设备发送数据包 -#define MOUSE_SET_DEFAULT_SAMPLING_RATE 0xf6 // 设置使用默认采样率100hz,分辨率4px/mm -#define MOUSE_RESEND_LAST_PACKET 0xfe // 重新发送上一条数据包 -#define MOUSE_RESET 0xff // 重启鼠标 +#define PS2_MOUSE_GET_ID 0xf2 // 获取鼠标的ID +#define PS2_MOUSE_SET_SAMPLING_RATE 0xf3 // 设置鼠标的采样率 +#define PS2_MOUSE_ENABLE 0xf4 // 允许鼠标设备发送数据包 +#define PS2_MOUSE_DISABLE 0xf5 // 禁止鼠标设备发送数据包 +#define PS2_MOUSE_SET_DEFAULT_SAMPLING_RATE 0xf6 // 设置使用默认采样率100hz,分辨率4px/mm +#define PS2_MOUSE_RESEND_LAST_PACKET 0xfe // 重新发送上一条数据包 +#define PS2_MOUSE_RESET 0xff // 重启鼠标 -#define KEYBOARD_COMMAND_ENABLE_MOUSE_PORT 0xa8 // 通过键盘控制器开启鼠标端口的命令 +#define KEYBOARD_COMMAND_ENABLE_PS2_MOUSE_PORT 0xa8 // 通过键盘控制器开启鼠标端口的命令 -#define mouse_buffer_size 120 +#define ps2_mouse_buffer_size 360 #define PORT_KEYBOARD_DATA 0x60 #define PORT_KEYBOARD_STATUS 0x64 @@ -42,7 +42,7 @@ // =========== 定义鼠标数据包 ============== // 其中,x、y方向的移动值用9位二进制补码表示(算上byte0中的符号位) // 目前只用到8位,(精度要求没那么高) -struct mouse_packet_3bytes +struct ps2_mouse_packet_3bytes { unsigned char byte0; // 第0字节 @@ -53,7 +53,7 @@ struct mouse_packet_3bytes }; // ID = 3 或 ID = 4时,采用4bytes数据包 -struct mouse_packet_4bytes +struct ps2_mouse_packet_4bytes { unsigned char byte0; // 第0字节 // [y溢出,x溢出,y符号位, x符号位, 1, 鼠标中键, 鼠标右键,鼠标左键] @@ -71,32 +71,32 @@ struct mouse_packet_4bytes * @brief 键盘循环队列缓冲区结构体 * */ -struct mouse_input_buffer +struct ps2_mouse_input_buffer { unsigned char *ptr_head; unsigned char *ptr_tail; int count; - unsigned char buffer[mouse_buffer_size]; + unsigned char buffer[ps2_mouse_buffer_size]; }; /** * @brief 初始化鼠标驱动程序 * */ -void mouse_init(); +void ps2_mouse_init(); /** * @brief 卸载鼠标驱动程序 * */ -void mouse_exit(); +void ps2_mouse_exit(); /** * @brief 设置鼠标采样率 * * @param hz 采样率 */ -int mouse_set_sample_rate(unsigned int hz); +int ps2_mouse_set_sample_rate(unsigned int hz); /** * @brief 获取鼠标数据包 @@ -104,5 +104,5 @@ int mouse_set_sample_rate(unsigned int hz); * @param packet 数据包的返回值 * @return int 错误码 */ -int mouse_get_packet(void *packet); +int ps2_mouse_get_packet(void *packet); void analyze_mousecode(); \ No newline at end of file diff --git a/kernel/main.c b/kernel/main.c index ee44f857..dcbbb5ec 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -15,8 +15,8 @@ #include "driver/multiboot2/multiboot2.h" #include "driver/acpi/acpi.h" -#include "driver/keyboard/keyboard.h" -#include "driver/mouse/mouse.h" +#include "driver/keyboard/ps2_keyboard.h" +#include "driver/mouse/ps2_mouse.h" unsigned int *FR_address = (unsigned int *)0xb8000; //帧缓存区的地址 @@ -162,8 +162,8 @@ void system_initialize() syscall_init(); cpu_init(); - keyboard_init(); - mouse_init(); + ps2_keyboard_init(); + ps2_mouse_init(); // test_slab(); // test_mm(); @@ -180,27 +180,29 @@ void Start_Kernel(void) // show_welcome(); // test_mm(); - /* + while (1) { - keyboard_analyze_keycode(); - struct mouse_packet_3bytes packet = {0}; - //struct mouse_packet_4bytes packet = {0}; + ps2_keyboard_analyze_keycode(); + struct ps2_mouse_packet_3bytes packet = {0}; + //struct ps2_mouse_packet_4bytes packet = {0}; int errcode = 0; - errcode = mouse_get_packet(&packet); + errcode = ps2_mouse_get_packet(&packet); if(errcode == 0) { printk_color(GREEN, BLACK, " (Mouse: byte0:%d, x:%3d, y:%3d)\n", packet.byte0, packet.movement_x, packet.movement_y); //printk_color(GREEN, BLACK, " (Mouse: byte0:%d, x:%3d, y:%3d, byte3:%3d)\n", packet.byte0, packet.movement_x, packet.movement_y, (unsigned char)packet.byte3); } } - */ + +/* while (1) { + keyboard_analyze_keycode(); analyze_mousecode(); } - +*/ while (1) ; } diff --git a/kernel/mm/mm.h b/kernel/mm/mm.h index 1eae7a59..4be0a17a 100644 --- a/kernel/mm/mm.h +++ b/kernel/mm/mm.h @@ -39,6 +39,7 @@ #define SPECIAL_MEMOEY_MAPPING_VIRT_ADDR_BASE 0xffff800000000000UL #define FRAME_BUFFER_MAPPING_OFFSET 0x3000000UL #define ACPI_RSDT_MAPPING_OFFSET 0x7000000UL +#define ACPI_XSDT_MAPPING_OFFSET 0x9000000UL #define IO_APIC_MAPPING_OFFSET 0xfec00000UL #define LOCAL_APIC_MAPPING_OFFSET 0xfee00000UL // ===== 内存区域属性 ===== diff --git a/run.sh b/run.sh index a193ecd0..1be7640f 100644 --- a/run.sh +++ b/run.sh @@ -93,7 +93,7 @@ if [ $flag_can_run -eq 1 ]; then bochs -q -f ${bochsrc} -rc ./tools/bochsinit else qemu-system-x86_64 -cdrom ${iso} -m 512M \ - -monitor telnet::2333,server,nowait -serial stdio -s + -monitor telnet::2333,server,nowait -serial stdio -s -cpu IvyBridge --enable-kvm fi else echo "不满足运行条件"