Skip to content

Commit 3e3c631

Browse files
authored
fix: 修复了ps2和tty初始化顺序的错误 (DragonOS-Community#497)
* 修复了ps2和tty初始化顺序的错误
1 parent 74ffde6 commit 3e3c631

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

kernel/src/arch/x86_64/init/main.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@
2323

2424
#include "driver/acpi/acpi.h"
2525
#include "driver/disk/ata.h"
26-
#include "driver/keyboard/ps2_keyboard.h"
27-
#include "driver/mouse/ps2_mouse.h"
2826
#include "driver/multiboot2/multiboot2.h"
2927
#include <time/timer.h>
3028

3129
#include <arch/x86_64/driver/apic/apic_timer.h>
32-
#include <virt/kvm/kvm.h>
3330
#include <debug/bug.h>
31+
#include <virt/kvm/kvm.h>
3432

3533
extern int rs_driver_init();
3634
extern void rs_softirq_init();
@@ -56,17 +54,15 @@ ul bsp_idt_size, bsp_gdt_size;
5654
struct gdtr gdtp;
5755
struct idtr idtp;
5856
ul _stack_start;
59-
void reload_gdt()
60-
{
57+
void reload_gdt() {
6158

6259
gdtp.size = bsp_gdt_size - 1;
6360
gdtp.gdt_vaddr = (ul)phys_2_virt((ul)&GDT_Table);
6461

6562
asm volatile("lgdt (%0) \n\t" ::"r"(&gdtp) : "memory");
6663
}
6764

68-
void reload_idt()
69-
{
65+
void reload_idt() {
7066

7167
idtp.size = bsp_idt_size - 1;
7268
idtp.idt_vaddr = (ul)phys_2_virt((ul)&IDT_Table);
@@ -77,8 +73,7 @@ void reload_idt()
7773
}
7874

7975
// 初始化系统各模块
80-
void system_initialize()
81-
{
76+
void system_initialize() {
8277
rs_init_before_mem_init();
8378

8479
_stack_start =
@@ -147,7 +142,6 @@ void system_initialize()
147142

148143
cpu_init();
149144

150-
ps2_keyboard_init();
151145
io_mfence();
152146

153147
rs_pci_init();
@@ -179,8 +173,7 @@ void system_initialize()
179173
}
180174

181175
// 操作系统内核从这里开始执行
182-
void Start_Kernel(void)
183-
{
176+
void Start_Kernel(void) {
184177

185178
// 获取multiboot2的信息
186179
uint64_t mb2_info, mb2_magic;
@@ -201,16 +194,12 @@ void Start_Kernel(void)
201194
io_mfence();
202195

203196
// idle
204-
while (1)
205-
{
197+
while (1) {
206198
// 如果调用的时候,启用了中断,则hlt。否则认为是bug
207-
if (get_rflags() & 0x200)
208-
{
199+
if (get_rflags() & 0x200) {
209200
// kdebug("hlt");
210201
hlt();
211-
}
212-
else
213-
{
202+
} else {
214203
BUG_ON(1);
215204
pause();
216205
}

kernel/src/driver/keyboard/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
1+
use crate::init::initcall::INITCALL_LATE;
2+
use core::ffi::c_void;
3+
use system_error::SystemError;
4+
use unified_init::macros::unified_init;
5+
16
pub mod ps2_keyboard;
27
// pub mod ps2_keyboard_inode;
8+
9+
extern "C" {
10+
fn ps2_keyboard_init() -> c_void;
11+
}
12+
13+
/// 初始化ps2键盘
14+
///
15+
/// todo: 将ps2键盘适配到设备驱动模型后,把初始化时机改为INITCALL_DEVICE
16+
///
17+
/// 当前是LATE的原因是键盘驱动的TypeOneFSM需要在tty设备初始化之后才能工作。
18+
#[unified_init(INITCALL_LATE)]
19+
fn rs_ps2_keyboard_init() -> Result<(), SystemError> {
20+
unsafe {
21+
ps2_keyboard_init();
22+
}
23+
return Ok(());
24+
}

kernel/src/driver/keyboard/ps2_keyboard.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,20 @@
1919

2020
// ========= 检测键盘控制器输入/输出缓冲区是否已满
2121
#define PS2_KEYBOARD_FLAG_OUTBUF_FULL 0x01 // 键盘的输出缓冲区已满标志位
22-
#define PS2_KEYBOARD_FLAG_INBUF_FULL 0x02 // 键盘的输入缓冲区已满标志位
22+
#define PS2_KEYBOARD_FLAG_INBUF_FULL 0x02 // 键盘的输入缓冲区已满标志位
2323

2424
// 等待向键盘控制器写入信息完成
2525
// todo: bugfix:在不包含ps2键盘控制器的机器上,这里会卡死
26-
#define wait_ps2_keyboard_write() while (io_in8(PORT_PS2_KEYBOARD_STATUS) & PS2_KEYBOARD_FLAG_INBUF_FULL)
26+
#define wait_ps2_keyboard_write() \
27+
while (io_in8(PORT_PS2_KEYBOARD_STATUS) & PS2_KEYBOARD_FLAG_INBUF_FULL)
2728
// #define wait_ps2_keyboard_write() (1)
2829
// 等待从键盘控制器读取信息完成
29-
#define wait_ps2_keyboard_read() while (io_in8(PORT_PS2_KEYBOARD_STATUS) & PS2_KEYBOARD_FLAG_OUTBUF_FULL)
30+
#define wait_ps2_keyboard_read() \
31+
while (io_in8(PORT_PS2_KEYBOARD_STATUS) & PS2_KEYBOARD_FLAG_OUTBUF_FULL)
3032
// #define wait_ps2_keyboard_read() (1)
3133

3234
extern struct vfs_file_operations_t ps2_keyboard_fops;
3335

34-
/**
35-
* @brief 初始化键盘驱动程序的函数
36-
*
37-
*/
38-
void ps2_keyboard_init();
39-
4036
/**
4137
* @brief 键盘驱动卸载函数
4238
*

0 commit comments

Comments
 (0)