Просмотр исходного кода

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

fslongjin 3 лет назад
Родитель
Сommit
2bb63e8e87
4 измененных файлов с 49 добавлено и 21 удалено
  1. 3 1
      .vscode/settings.json
  2. 1 1
      kernel/common/printk.c
  3. 9 2
      kernel/driver/acpi/acpi.c
  4. 36 17
      kernel/driver/mouse/mouse.c

+ 3 - 1
.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"
 }

+ 1 - 1
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;

+ 9 - 2
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

+ 36 - 17
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;