鼠标驱动已知bug: 数据包大小不正确

This commit is contained in:
fslongjin 2022-03-17 22:38:23 +08:00
parent a75fa791e7
commit 2bb63e8e87
4 changed files with 49 additions and 21 deletions

View File

@ -18,7 +18,9 @@
"kprint.h": "c", "kprint.h": "c",
"8259a.h": "c", "8259a.h": "c",
"ptrace.h": "c", "ptrace.h": "c",
"mouse.h": "c" "mouse.h": "c",
"keyboard.h": "c",
"apic.h": "c"
}, },
"C_Cpp.errorSquiggles": "Enabled" "C_Cpp.errorSquiggles": "Enabled"
} }

View File

@ -342,7 +342,7 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
case 'X': case 'X':
// flags |= SPECIAL; // flags |= SPECIAL;
if (qualifier == 'l') 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 else
str = write_num(str, va_arg(args, int), 16, field_width, precision, flags); str = write_num(str, va_arg(args, int), 16, field_width, precision, flags);
break; break;

View File

@ -5,7 +5,7 @@
#include "../../mm/mm.h" #include "../../mm/mm.h"
// 获取RSDT entry的虚拟地址 // 获取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_t *rsdpv1;
static struct acpi_RSDP_2_t *rsdpv2; 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)))); 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) if (_fun(sdt_header, _data) == true)
return; return;
@ -58,7 +61,9 @@ bool acpi_get_MADT(const struct acpi_system_description_table_header_t *_iter_da
return false; return false;
//*(struct acpi_Multiple_APIC_Description_Table_t *)_data = *(struct acpi_Multiple_APIC_Description_Table_t *)_iter_data; //*(struct acpi_Multiple_APIC_Description_Table_t *)_data = *(struct acpi_Multiple_APIC_Description_Table_t *)_iter_data;
// 返回MADT的虚拟地址 // 返回MADT的虚拟地址
*(ul *)_data = (ul)_iter_data; *(ul *)_data = (ul)_iter_data;
printk_color(ORANGE, BLACK,"xxx=%#018lx\n", (ul)_iter_data);
return true; return true;
} }
@ -67,6 +72,7 @@ bool acpi_get_MADT(const struct acpi_system_description_table_header_t *_iter_da
* @brief acpi模块 * @brief acpi模块
* *
*/ */
// todo: 修复bug当物理机上提供了rsdpv2之后rsdpv1是不提供的物理地址为0因此需要手动判断rsdp的版本信息然后做对应的解析。
void acpi_init() void acpi_init()
{ {
kinfo("Initializing ACPI..."); 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 Length=%dbytes.\n", rsdt->header.Length);
printk_color(ORANGE, BLACK, "RSDT Entry num=%d\n", acpi_RSDT_Entry_num); 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的物理地址 // 映射所有的Entry的物理地址
acpi_RSDT_entry_phys_base = ((ul)(rsdt->Entry)) & PAGE_2M_MASK; acpi_RSDT_entry_phys_base = ((ul)(rsdt->Entry)) & PAGE_2M_MASK;
// 由于地址只是32bit的并且存在脏数据这里需要手动清除高32bit否则会触发#GP // 由于地址只是32bit的并且存在脏数据这里需要手动清除高32bit否则会触发#GP

View File

@ -7,7 +7,7 @@
static struct mouse_input_buffer *mouse_buf_ptr = NULL; static struct mouse_input_buffer *mouse_buf_ptr = NULL;
static int c = 0; 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; 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->ptr_head = x;
++(mouse_buf_ptr->count); ++(mouse_buf_ptr->count);
++(mouse_buf_ptr->ptr_head); ++(mouse_buf_ptr->ptr_head);
printk("c=%d\n", ++c); //printk("c=%d\tval = %d\n", ++c, x);
} }
hardware_intr_controller mouse_intr_controller = 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); io_out8(PORT_KEYBOARD_DATA, MOUSE_GET_ID);
wait_keyboard_write(); wait_keyboard_write();
mouse_id = io_in8(PORT_KEYBOARD_DATA); 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; return mouse_id;
} }
@ -120,10 +123,17 @@ int mouse_set_sample_rate(unsigned int hz)
wait_keyboard_write(); wait_keyboard_write();
io_out8(PORT_KEYBOARD_DATA, MOUSE_SET_SAMPLING_RATE); io_out8(PORT_KEYBOARD_DATA, MOUSE_SET_SAMPLING_RATE);
wait_keyboard_write(); 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); io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_SEND_TO_MOUSE);
wait_keyboard_write(); wait_keyboard_write();
io_out8(PORT_KEYBOARD_DATA, hz); io_out8(PORT_KEYBOARD_DATA, hz);
for (int i = 0; i < 1000; i++)
for (int j = 0; j < 1000; j++)
nop();
wait_keyboard_write(); wait_keyboard_write();
break; break;
default: default:
@ -192,37 +202,46 @@ void mouse_init()
// ======== 初始化中断RTE entry ========== // ======== 初始化中断RTE entry ==========
entry.vector = MOUSE_INTR_VECTOR; // 设置中断向量号 mouse_entry.vector = MOUSE_INTR_VECTOR; // 设置中断向量号
entry.deliver_mode = IO_APIC_FIXED; // 投递模式:混合 mouse_entry.deliver_mode = IO_APIC_FIXED; // 投递模式:混合
entry.dest_mode = DEST_PHYSICAL; // 物理模式投递中断 mouse_entry.dest_mode = DEST_PHYSICAL; // 物理模式投递中断
entry.deliver_status = IDLE; mouse_entry.deliver_status = IDLE;
entry.trigger_mode = EDGE_TRIGGER; // 设置边沿触发 mouse_entry.trigger_mode = EDGE_TRIGGER; // 设置边沿触发
entry.polarity = POLARITY_HIGH; // 高电平触发 mouse_entry.polarity = POLARITY_HIGH; // 高电平触发
entry.remote_IRR = IRR_RESET; mouse_entry.remote_IRR = IRR_RESET;
entry.mask = MASKED; mouse_entry.mask = MASKED;
entry.reserved = 0; mouse_entry.reserved = 0;
entry.destination.physical.reserved1 = 0; mouse_entry.destination.physical.reserved1 = 0;
entry.destination.physical.reserved2 = 0; mouse_entry.destination.physical.reserved2 = 0;
entry.destination.physical.phy_dest = 0; // 设置投递到BSP处理器 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(); wait_keyboard_write();
io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_ENABLE_MOUSE_PORT); // 开启鼠标端口 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(); wait_keyboard_write();
io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_SEND_TO_MOUSE); io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_SEND_TO_MOUSE);
wait_keyboard_write(); wait_keyboard_write();
io_out8(PORT_KEYBOARD_DATA, MOUSE_ENABLE); // 允许鼠标设备发送数据包 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); io_out8(PORT_KEYBOARD_CONTROL, KEYBOARD_COMMAND_WRITE);
wait_keyboard_write(); wait_keyboard_write();
io_out8(PORT_KEYBOARD_DATA, KEYBOARD_PARAM_INIT); // 设置键盘控制器 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(); wait_keyboard_write();
//mouse_enable_5keys(); mouse_enable_5keys();
mouse_get_mouse_ID(); mouse_get_mouse_ID();
kdebug("mouse ID:%d", mouse_id); kdebug("mouse ID:%d", mouse_id);
c = 0; c = 0;