Browse Source

Merge pull request #43 from liricliu/master

login 2 years ago
parent
commit
44d1648e37

+ 1 - 0
.gitignore

@@ -3,6 +3,7 @@
 DragonOS.iso
 .idea/
 kernel/kernel
+.DS_Store
 
 *.o
 *.s

+ 2 - 1
.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": ""

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

+ 1 - 1
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 "$@"

+ 8 - 0
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

+ 92 - 0
kernel/driver/tty/tty.c

@@ -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 - 0
kernel/driver/tty/tty.h

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

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

+ 1 - 0
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] = "",
 };
 /**

+ 1 - 0
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, // 结束标志
 };
 

+ 2 - 0
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();

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

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

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