From 2bb63e8e873f3edee6df87f4d85f0fd4d5c5e9c3 Mon Sep 17 00:00:00 2001 From: fslongjin Date: Thu, 17 Mar 2022 22:38:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BC=A0=E6=A0=87=E9=A9=B1=E5=8A=A8=E5=B7=B2?= =?UTF-8?q?=E7=9F=A5bug:=20=E6=95=B0=E6=8D=AE=E5=8C=85=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 4 ++- kernel/common/printk.c | 2 +- kernel/driver/acpi/acpi.c | 11 ++++++-- kernel/driver/mouse/mouse.c | 53 +++++++++++++++++++++++++------------ 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a0cba5fd..edb20976 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,7 +18,9 @@ "kprint.h": "c", "8259a.h": "c", "ptrace.h": "c", - "mouse.h": "c" + "mouse.h": "c", + "keyboard.h": "c", + "apic.h": "c" }, "C_Cpp.errorSquiggles": "Enabled" } \ No newline at end of file diff --git a/kernel/common/printk.c b/kernel/common/printk.c index a187e1fb..c360f9d1 100644 --- a/kernel/common/printk.c +++ b/kernel/common/printk.c @@ -342,7 +342,7 @@ static int vsprintf(char *buf, const char *fmt, va_list args) case 'X': // flags |= SPECIAL; if (qualifier == 'l') - str = write_num(str, va_arg(args, ull), 16, field_width, precision, flags); + str = write_num(str, va_arg(args, ll), 16, field_width, precision, flags); else str = write_num(str, va_arg(args, int), 16, field_width, precision, flags); break; diff --git a/kernel/driver/acpi/acpi.c b/kernel/driver/acpi/acpi.c index 79dfeefe..3449a196 100644 --- a/kernel/driver/acpi/acpi.c +++ b/kernel/driver/acpi/acpi.c @@ -5,7 +5,7 @@ #include "../../mm/mm.h" // 获取RSDT entry的虚拟地址 -#define acpi_get_RSDT_entry_vaddr(phys_addr) (ACPI_DESCRIPTION_HEDERS_BASE + MASK_HIGH_32bit(phys_addr) - acpi_RSDT_entry_phys_base) +#define acpi_get_RSDT_entry_vaddr(phys_addr) (ACPI_DESCRIPTION_HEDERS_BASE + (phys_addr)-acpi_RSDT_entry_phys_base) static struct acpi_RSDP_t *rsdpv1; static struct acpi_RSDP_2_t *rsdpv2; @@ -35,6 +35,9 @@ void acpi_iter_SDT(bool (*_fun)(const struct acpi_system_description_table_heade { sdt_header = (struct acpi_system_description_table_header_t *)(acpi_get_RSDT_entry_vaddr((ul)(*(ent + i)))); + kwarn("vvv=%#018lx", (ul)(*(ent + i))); + kwarn("vaddr=%#018lx", (ul)acpi_get_RSDT_entry_vaddr((ul)(*(ent + i)))); + printk_color(ORANGE, BLACK,"kkl=%s\n", sdt_header->Signature); if (_fun(sdt_header, _data) == true) return; @@ -58,8 +61,10 @@ bool acpi_get_MADT(const struct acpi_system_description_table_header_t *_iter_da return false; //*(struct acpi_Multiple_APIC_Description_Table_t *)_data = *(struct acpi_Multiple_APIC_Description_Table_t *)_iter_data; // 返回MADT的虚拟地址 - *(ul*)_data = (ul)_iter_data; + *(ul *)_data = (ul)_iter_data; + printk_color(ORANGE, BLACK,"xxx=%#018lx\n", (ul)_iter_data); + return true; } @@ -67,6 +72,7 @@ bool acpi_get_MADT(const struct acpi_system_description_table_header_t *_iter_da * @brief 初始化acpi模块 * */ +// todo: 修复bug:当物理机上提供了rsdpv2之后,rsdpv1是不提供的(物理地址为0),因此需要手动判断rsdp的版本信息,然后做对应的解析。 void acpi_init() { kinfo("Initializing ACPI..."); @@ -103,6 +109,7 @@ void acpi_init() printk_color(ORANGE, BLACK, "RSDT Length=%dbytes.\n", rsdt->header.Length); printk_color(ORANGE, BLACK, "RSDT Entry num=%d\n", acpi_RSDT_Entry_num); + mm_map_phys_addr(ACPI_RSDT_VIRT_ADDR_BASE, rsdt_phys_base, rsdt->header.Length + PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD); // 映射所有的Entry的物理地址 acpi_RSDT_entry_phys_base = ((ul)(rsdt->Entry)) & PAGE_2M_MASK; // 由于地址只是32bit的,并且存在脏数据,这里需要手动清除高32bit,否则会触发#GP diff --git a/kernel/driver/mouse/mouse.c b/kernel/driver/mouse/mouse.c index 77abe92d..766f18df 100644 --- a/kernel/driver/mouse/mouse.c +++ b/kernel/driver/mouse/mouse.c @@ -7,7 +7,7 @@ static struct mouse_input_buffer *mouse_buf_ptr = NULL; static int c = 0; -struct apic_IO_APIC_RTE_entry entry; +struct apic_IO_APIC_RTE_entry mouse_entry; static unsigned char mouse_id = 0; /** @@ -70,7 +70,7 @@ void mouse_handler(ul irq_num, ul param, struct pt_regs *regs) *mouse_buf_ptr->ptr_head = x; ++(mouse_buf_ptr->count); ++(mouse_buf_ptr->ptr_head); - printk("c=%d\n", ++c); + //printk("c=%d\tval = %d\n", ++c, x); } hardware_intr_controller mouse_intr_controller = @@ -96,6 +96,9 @@ static unsigned char mouse_get_mouse_ID() 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; } @@ -120,10 +123,17 @@ int mouse_set_sample_rate(unsigned int hz) 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: @@ -192,37 +202,46 @@ void mouse_init() // ======== 初始化中断RTE entry ========== - entry.vector = MOUSE_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; // 高电平触发 - entry.remote_IRR = IRR_RESET; - entry.mask = MASKED; - entry.reserved = 0; + 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; - entry.destination.physical.reserved1 = 0; - entry.destination.physical.reserved2 = 0; - entry.destination.physical.phy_dest = 0; // 设置投递到BSP处理器 + 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, &entry, &mouse_handler, (ul)mouse_buf_ptr, &mouse_intr_controller, "ps/2 mouse"); + 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); // 允许鼠标设备发送数据包 - wait_keyboard_write(); + 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_enable_5keys(); mouse_get_mouse_ID(); kdebug("mouse ID:%d", mouse_id); c = 0;