diff --git a/.gitignore b/.gitignore index 13b1f785..03f6b7ab 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ DragonOS.iso .idea/ kernel/kernel +.DS_Store *.o *.s diff --git a/.vscode/settings.json b/.vscode/settings.json index 30a402e9..4ae0d181 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -138,7 +138,8 @@ "devfs.h": "c", "devfs-types.h": "c", "chardev.h": "c", - "rootfs.h": "c" + "rootfs.h": "c", + "tty.h": "c" }, "C_Cpp.errorSquiggles": "Enabled", "esbonio.sphinx.confDir": "" diff --git a/kernel/Makefile b/kernel/Makefile index 8bdb98d7..a9db8fc3 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -22,8 +22,8 @@ kernel_subdirs := common driver process debug filesystem time arch exception mm head.o: head.S - gcc -E head.S > head.s # 预处理 - as $(ASFLAGS) -o head.o head.s + gcc -E head.S > _head.s # 预处理 + as $(ASFLAGS) -o head.o _head.s main.o: main.c diff --git a/kernel/driver/Makefile b/kernel/driver/Makefile index 972f7cb0..bbd51c12 100644 --- a/kernel/driver/Makefile +++ b/kernel/driver/Makefile @@ -1,7 +1,7 @@ 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 "$@" diff --git a/kernel/driver/tty/Makefile b/kernel/driver/tty/Makefile new file mode 100644 index 00000000..e7a913c7 --- /dev/null +++ b/kernel/driver/tty/Makefile @@ -0,0 +1,8 @@ + +all: tty.o + +CFLAGS += -I . + + +tty.o: tty.c + gcc $(CFLAGS) -c tty.c -o tty.o \ No newline at end of file diff --git a/kernel/driver/tty/tty.c b/kernel/driver/tty/tty.c new file mode 100644 index 00000000..5e92c22c --- /dev/null +++ b/kernel/driver/tty/tty.c @@ -0,0 +1,92 @@ +#include +#include +#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."); +} \ No newline at end of file diff --git a/kernel/driver/tty/tty.h b/kernel/driver/tty/tty.h new file mode 100644 index 00000000..d35cb68f --- /dev/null +++ b/kernel/driver/tty/tty.h @@ -0,0 +1,3 @@ +#pragma once + +void tty_init(); \ No newline at end of file diff --git a/kernel/exception/Makefile b/kernel/exception/Makefile index 033c0e70..e3e0f72b 100644 --- a/kernel/exception/Makefile +++ b/kernel/exception/Makefile @@ -5,8 +5,8 @@ CFLAGS += -I . all: entry.o irq.o softirq.o trap.o entry.o: entry.S - gcc -E entry.S > entry.s - as $(ASFLAGS) -o entry.o entry.s + gcc -E entry.S > _entry.s + as $(ASFLAGS) -o entry.o _entry.s trap.o: trap.c gcc $(CFLAGS) -c trap.c -o trap.o diff --git a/kernel/filesystem/devfs/chardev.c b/kernel/filesystem/devfs/chardev.c index cdda059d..5dcd97d6 100644 --- a/kernel/filesystem/devfs/chardev.c +++ b/kernel/filesystem/devfs/chardev.c @@ -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_BLUETOOTH_MOUSE] = "bt.mse", [CHAR_DEV_STYPE_BLUETOOTH_KEYBOARD] = "bt.kb", + [CHAR_DEV_STYPE_TTY] = "vdev.tty", [CHAR_DEV_STYPE_END] = "", }; /** diff --git a/kernel/filesystem/devfs/devfs-types.h b/kernel/filesystem/devfs/devfs-types.h index 8efdb88c..4acf8aa7 100644 --- a/kernel/filesystem/devfs/devfs-types.h +++ b/kernel/filesystem/devfs/devfs-types.h @@ -29,6 +29,7 @@ enum CHAR_DEV_STYPE_USB_MOUSE, CHAR_DEV_STYPE_BLUETOOTH_MOUSE, CHAR_DEV_STYPE_BLUETOOTH_KEYBOARD, + CHAR_DEV_STYPE_TTY, CHAR_DEV_STYPE_END, // 结束标志 }; diff --git a/kernel/main.c b/kernel/main.c index 80cab1aa..9bc7ed19 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -26,6 +26,7 @@ #include "driver/multiboot2/multiboot2.h" #include "driver/acpi/acpi.h" #include "driver/keyboard/ps2_keyboard.h" +#include "driver/tty/tty.h" #include "driver/mouse/ps2_mouse.h" #include "driver/disk/ata.h" #include "driver/pci/pci.h" @@ -145,6 +146,7 @@ void system_initialize() devfs_init(); cpu_init(); ps2_keyboard_init(); + tty_init(); // ps2_mouse_init(); // ata_init(); pci_init(); diff --git a/kernel/process/Makefile b/kernel/process/Makefile index e7fb7ce7..ba4385e3 100644 --- a/kernel/process/Makefile +++ b/kernel/process/Makefile @@ -6,8 +6,8 @@ CFLAGS += -I . procs.o: proc.S - gcc -E proc.S > proc.s - as $(ASFLAGS) -o procs.o proc.s + gcc -E proc.S > _proc.s + as $(ASFLAGS) -o procs.o _proc.s process.o: process.c gcc $(CFLAGS) -c process.c -o process.o diff --git a/kernel/smp/Makefile b/kernel/smp/Makefile index 5379b54c..7f7ab081 100644 --- a/kernel/smp/Makefile +++ b/kernel/smp/Makefile @@ -6,8 +6,8 @@ all: apu_boot.o smp.o apu_boot.o: apu_boot.S - gcc -E apu_boot.S > apu_boot.s # 预处理 - as $(ASFLAGS) -o apu_boot.o apu_boot.s + gcc -E apu_boot.S > _apu_boot.s # 预处理 + as $(ASFLAGS) -o apu_boot.o _apu_boot.s smp.o: smp.c gcc $(CFLAGS) -c smp.c -o smp.o \ No newline at end of file diff --git a/run.sh b/run.sh index 92ecc581..da640b37 100755 --- a/run.sh +++ b/run.sh @@ -159,7 +159,7 @@ qemu_trace_usb=trace:usb_xhci_reset,trace:usb_xhci_run,trace:usb_xhci_stop,trace qemu_accel=kvm -if [ "${OS}" == "Darwin" ]; then +if [ $(uname) == Darwin ]; then qemu_accel=hvf fi