完成了tty设备在devfs中的注册

This commit is contained in:
liric 2022-09-15 23:09:15 +08:00
parent 518ce3818c
commit fcdd6f5fa9
8 changed files with 110 additions and 2 deletions

View File

@ -138,7 +138,8 @@
"devfs.h": "c", "devfs.h": "c",
"devfs-types.h": "c", "devfs-types.h": "c",
"chardev.h": "c", "chardev.h": "c",
"rootfs.h": "c" "rootfs.h": "c",
"tty.h": "c"
}, },
"C_Cpp.errorSquiggles": "Enabled", "C_Cpp.errorSquiggles": "Enabled",
"esbonio.sphinx.confDir": "" "esbonio.sphinx.confDir": ""

View File

@ -1,7 +1,7 @@
CFLAGS += -I . CFLAGS += -I .
kernel_driver_subdirs:=video interrupt usb pci uart acpi disk keyboard mouse multiboot2 timers kernel_driver_subdirs:=video interrupt usb pci uart acpi disk keyboard mouse multiboot2 timers tty
ECHO: ECHO:
@echo "$@" @echo "$@"

View File

@ -0,0 +1,8 @@
all: tty.o
CFLAGS += -I .
tty.o: tty.c
gcc $(CFLAGS) -c tty.c -o tty.o

92
kernel/driver/tty/tty.c Normal file
View File

@ -0,0 +1,92 @@
#include <filesystem/devfs/devfs.h>
#include <filesystem/VFS/VFS.h>
#include "tty.h"
static int tty_private_data;
/**
* @brief tty文件
*
* @param inode inode
* @param filp
* @return long
*/
long tty_open(struct vfs_index_node_t *inode, struct vfs_file_t *filp)
{
filp->private_data = &tty_private_data;
return 0;
}
/**
* @brief tty文件
*
* @param inode inode
* @param filp
* @return long
*/
long tty_close(struct vfs_index_node_t *inode, struct vfs_file_t *filp)
{
filp->private_data = NULL;
return 0;
}
/**
* @brief tty控制接口
*
* @param inode inode
* @param filp tty文件指针
* @param cmd
* @param arg
* @return long
*/
long tty_ioctl(struct vfs_index_node_t *inode, struct vfs_file_t *filp, uint64_t cmd, uint64_t arg)
{
switch (cmd)
{
default:
break;
}
return 0;
}
/**
* @brief tty文件的操作接口
*
* @param filp
* @param buf
* @param count
* @param position
* @return long
*/
long tty_read(struct vfs_file_t *filp, char *buf, int64_t count, long *position)
{
return 0;
}
/**
* @brief tty文件写入接口
*
* @param filp
* @param buf
* @param count
* @param position
* @return long
*/
long tty_write(struct vfs_file_t *filp, char *buf, int64_t count, long *position)
{
return 0;
}
struct vfs_file_operations_t tty_fops={
.open = tty_open,
.close = tty_close,
.ioctl = tty_ioctl,
.read = tty_read,
.write = tty_write,
};
void tty_init(){
//注册devfs
devfs_register_device(DEV_TYPE_CHAR, CHAR_DEV_STYPE_TTY, &tty_fops);
kinfo("tty driver registered.");
}

3
kernel/driver/tty/tty.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
void tty_init();

View File

@ -22,6 +22,7 @@ static char chardev_name_prefix[CHAR_DEV_STYPE_END + 1][32] = {
[CHAR_DEV_STYPE_USB_KEYBOARD] = "usb.kb", [CHAR_DEV_STYPE_USB_KEYBOARD] = "usb.kb",
[CHAR_DEV_STYPE_BLUETOOTH_MOUSE] = "bt.mse", [CHAR_DEV_STYPE_BLUETOOTH_MOUSE] = "bt.mse",
[CHAR_DEV_STYPE_BLUETOOTH_KEYBOARD] = "bt.kb", [CHAR_DEV_STYPE_BLUETOOTH_KEYBOARD] = "bt.kb",
[CHAR_DEV_STYPE_TTY] = "vdev.tty",
[CHAR_DEV_STYPE_END] = "", [CHAR_DEV_STYPE_END] = "",
}; };
/** /**

View File

@ -29,6 +29,7 @@ enum
CHAR_DEV_STYPE_USB_MOUSE, CHAR_DEV_STYPE_USB_MOUSE,
CHAR_DEV_STYPE_BLUETOOTH_MOUSE, CHAR_DEV_STYPE_BLUETOOTH_MOUSE,
CHAR_DEV_STYPE_BLUETOOTH_KEYBOARD, CHAR_DEV_STYPE_BLUETOOTH_KEYBOARD,
CHAR_DEV_STYPE_TTY,
CHAR_DEV_STYPE_END, // 结束标志 CHAR_DEV_STYPE_END, // 结束标志
}; };

View File

@ -26,6 +26,7 @@
#include "driver/multiboot2/multiboot2.h" #include "driver/multiboot2/multiboot2.h"
#include "driver/acpi/acpi.h" #include "driver/acpi/acpi.h"
#include "driver/keyboard/ps2_keyboard.h" #include "driver/keyboard/ps2_keyboard.h"
#include "driver/tty/tty.h"
#include "driver/mouse/ps2_mouse.h" #include "driver/mouse/ps2_mouse.h"
#include "driver/disk/ata.h" #include "driver/disk/ata.h"
#include "driver/pci/pci.h" #include "driver/pci/pci.h"
@ -145,6 +146,7 @@ void system_initialize()
devfs_init(); devfs_init();
cpu_init(); cpu_init();
ps2_keyboard_init(); ps2_keyboard_init();
tty_init();
// ps2_mouse_init(); // ps2_mouse_init();
// ata_init(); // ata_init();
pci_init(); pci_init();