]> Zhao Yanbai Git Server - kernel.git/commitdiff
修复编译问题;添加调试指令
authoracevest <zhaoyanbai@126.com>
Tue, 26 Sep 2023 12:53:19 +0000 (20:53 +0800)
committeracevest <zhaoyanbai@126.com>
Tue, 26 Sep 2023 12:53:19 +0000 (20:53 +0800)
Makefile
drivers/block.c
drivers/ide.c
drivers/pci.c
fs/vfs.c
fs/vfs.h
gdbscript
qemu.sh

index ba1ce6ae31829bceda45dfff014a3465f89776e3..be70137829358a92186b5b968ac2c35f596cad1b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,32 +1,37 @@
 OS := $(shell uname -s)
 CPU_ARCH := $(shell uname -p)
 
-CC                     = gcc
-LD                     = ld
 ifeq ($(OS), Darwin)
        # MacOS下安装i686-elf-*的方法: brew install i686-elf-binutils
        # Apple Silicon
        ifeq ($(CPU_ARCH), arm)
-               CC              = i686-elf-gcc
-               LD              = i686-elf-ld
+               CROSS_PREFIX = i686-elf-
        # Intel MacOS
        else ifeq ($(CPU_ARCH), i386)
-               CC              = i686-elf-gcc
-               LD              = i686-elf-ld
+               CROSS_PREFIX = i686-elf-
        endif
 else ifeq ($(OS), Linux)
        # Apple Silicon Docker Linux
        ifeq ($(CPU_ARCH), aarch64)
-               CC              = x86_64-linux-gnu-gcc
-               LD              = x86_64-linux-gnu-ld
+               CROSS_PREFIX = x86_64-linux-gnu-
        endif
 endif
 
 
+CC                     = $(CROSS_PREFIX)gcc
+LD                     = $(CROSS_PREFIX)ld
+
 CFLAGS         = -g -c -fno-builtin -m32 -DBUILDER='"$(shell whoami)"'
+# 指示编译器生成不依赖位置无关代码
+CFLAGS     += -fno-pic
+# 指示编译器在生成目标文件时不省略函数调用栈帧指针: frame pointer
+CFLAGS     += -fno-omit-frame-pointer
+# 禁用控制流保护: Control-Flow Enforcement Technology (CET)
+CFLAGS     += -fcf-protection=none
 CFLAGS     += -DNR_TTYS=3
 CFLAGS     += -DFIX_SYSENTER_ESP_MODE=1
-#CFLAGS     += -DENABLE_BOOT_WAIT=1
+CFLAGS     += -DENABLE_BOOT_WAIT=0
+
 SYSTEMMAP      = System.map
 KERNELBIN      = KERNEL.ELF
 LINKSCRIPT     = scripts/link.ld
index ed538dd9fcfcf9780cf8fcda1c6f25cc2d7b36df..2fa1450d5477ea5568c266062237e85c8df3ee3c 100644 (file)
@@ -17,7 +17,7 @@ blk_buffer_t *block_buffer_hash_table[BLOCK_BUFFER_HASH_TABLE_SIZE] = {
     0,
 };
 
-int hash(dev_t dev, uint32_t block) { return ((co ~dev) ^ block) % BLOCK_BUFFER_HASH_TABLE_SIZE; }
+int hash(dev_t dev, uint32_t block) { return ((~dev) ^ block) % BLOCK_BUFFER_HASH_TABLE_SIZE; }
 
 blk_buffer_t *get_hash_block_buffer(dev_t dev, uint32_t block, uint16_t size) {}
 
index aa0f61ee13365d6381a1e908b56c0eabb37c6123..1ea64300baae68c79a722800fa7975525df3e43a 100644 (file)
@@ -24,15 +24,23 @@ unsigned int IDE_CHL1_CTL_BASE = 0x376;
 // 《PCI IDE Controller Specification》
 // 《Programming Interface for Bus Master IDE Controller》
 void ide_pci_init(pci_device_t *pci) {
-    unsigned int v;
+#if 0
+    uint32_t v;
+    uint32_t cmd;
 
-    v = pci_read_config_word(pci_cmd(pci, PCI_COMMAND));
+    cmd = pci_cmd(pci, PCI_COMMAND);
+    v = pci_read_config_word(cmd);
     // printk(" ide pci command %04x\n", v);
 
-    v = pci_read_config_byte(pci_cmd(pci, PCI_PROGIF));
-    printd("ide pci program interface %02x\n", v);
+    cmd = pci_cmd(pci, PCI_PROGIF);
+    v = pci_read_config_byte(cmd);
 
-    unsigned int iobase = pci_read_config_long(pci_cmd(pci, PCI_BAR4));
+    printd("ide pci program interface %02x %02X\n", v);
+#endif
+    printd("PCI %03d:%02d.%d %02X #%02d %04X:%04X\n", pci->bus, pci->dev, pci->devfn, pci->progif, pci->intr_line,
+           pci->vendor, pci->classcode);
+
+    uint32_t iobase = pci_read_config_long(pci_cmd(pci, PCI_BAR4));
 
     for (int i = 0; i < NR_IDE_CONTROLLER; i++) {
         INIT_MUTEX(&ide_pci_controller[i].request_mutex);
index 21718d1d381711571815494dcfa955a66bea2b4b..5f65f095112b8bd726a5e6167113289d2fb0c442 100644 (file)
@@ -152,8 +152,8 @@ void dump_pci_dev() {
         // printk("vendor %04x device %04x class %04x:%02x bus %d intr %3d ", pci->vendor, pci->device, pci->classcode,
         //        pci->progif, pci->bus, pci->intr_line);
         // printk("%s\n", pci_get_info(pci->classcode, pci->progif));
-        printk("PCI %03d:%02d.%d #%02d %04X:%04X %s\n", pci->bus, pci->dev, pci->devfn, pci->intr_line, pci->vendor,
-               pci->classcode, pci_get_info(pci->classcode, pci->progif));
+        printk("PCI %03d:%02d.%d %02X #%02d %04X:%04X %s\n", pci->bus, pci->dev, pci->devfn, pci->progif,
+               pci->intr_line, pci->vendor, pci->classcode, pci_get_info(pci->classcode, pci->progif));
 #if 0
         switch (pci->hdr_type) {
         case PCI_HDRTYPE_NORMAL:
index c7b757866bb4faa2dd463018b94b4e768e48b502..d1ab375a0341752edc4bc06ad42a555ee36bdc18 100644 (file)
--- a/fs/vfs.c
+++ b/fs/vfs.c
@@ -27,7 +27,7 @@ dentry_t *root_entry = 0;
 
 fs_type_t file_systems = {"filesystems", 0, 0};
 
-void register_filesystem(fs_type_t *fs) {
+void vfs_register_filesystem(fs_type_t *fs) {
     int ret = 0;
 
     fs_type_t *add = &file_systems;
index 1684dacee8e183f3b179c9984a72a6f2d7b0b7dd..af9dee58de5404c5df9164dfcb7821e7831a5cfb 100644 (file)
--- a/fs/vfs.h
+++ b/fs/vfs.h
@@ -14,6 +14,7 @@
 typedef struct dentry dentry_t;
 
 typedef struct sb_operations sb_operations_t;
+typedef struct file_operations file_operations_t;
 typedef struct inode_operations inode_operations_t;
 typedef struct dentry_operations dentry_operations_t;
 
@@ -35,7 +36,13 @@ typedef struct superblock {
 // 它们之间的关系是多对一的关系
 typedef struct inode {
     superblock_t *i_sb;
+
     void *i_private;
+
+    // fops - file ops 的副本
+    file_operations_t *i_fops;
+
+    // ops - inode ops
     inode_operations_t *i_ops;
 
     // 缓存的pages
@@ -71,12 +78,22 @@ struct sb_operations {
     //
 };
 
+struct file_operations {
+    // open
+    // close
+    // read
+    // write
+    // lseek
+    // ioctl
+};
 struct inode_operations {
     //
 };
 
 struct dentry_operations {
     //
+    // hash
+    // compare
 };
 
 // 每当将一个存储设备安装到现有文件系统中的某个节点时,内核就要为之建立一个vfsmount结构
@@ -93,4 +110,4 @@ typedef struct fs_type {
 
 extern superblock_t *root_sb;
 
-void register_filesystem(fs_type_t *fs);
+void vfs_register_filesystem(fs_type_t *fs);
index 7c763a757b838824d00cdaba5bd8412ddf78f48f..238cb70ab375118716801bc77693252ec1f2d04a 100644 (file)
--- a/gdbscript
+++ b/gdbscript
@@ -1,5 +1,32 @@
+# kill qemu on gdb exit
+#define hook-quit
+#    kill
+#end
+
+#b *0x7c00
+
+# watch point
+#wa *0x7c00
+
 target remote localhost:1234
+
+
+set pagination off
+
 b init_system_info
+
+# finish 可以执行到当前函数返回处, 缩写 fin
+b setup_pci
+
 #b setup_kernel
 #b e820_init_bootmem_data
 c
+
+
+# set disassembly-flavor intel  Intel语法
+# set disassembly-flavor att    AT&T语法
+
+
+# set architecture i8086
+
+# info registers
diff --git a/qemu.sh b/qemu.sh
index efff4d2a2c8f5344d18a53817decb8968ecde7e7..ac37fed44c23ea2bbd6fd0daf0899d2901a390cc 100755 (executable)
--- a/qemu.sh
+++ b/qemu.sh
@@ -1,11 +1,12 @@
 qemu-system-i386 \
-    -device ich9-ahci,id=ahci \
     -boot d \
+    -serial mon:stdio \
     -drive file=HDa.IMG,format=raw,index=0,media=disk \
     -drive file=kernel.iso,index=1,media=cdrom \
     -drive file=HDb.IMG,format=raw,index=2,media=disk \
     -name kernel \
     -s -S \
+    -device ich9-ahci,id=ahci \
     &
 
 #    -device ich9-ahci,id=ahci \
@@ -14,6 +15,8 @@ qemu-system-i386 \
 #qemu-system-x86_64 -boot d -s -S -drive file=HD.IMG,format=raw,index=0,media=disk -drive file=kernel.iso,index=1,media=cdrom &
 #
 
+# i386-elf-gdb KERNEL.ELF -x gdbscript
+
 pid=$!
 echo "pid is ${pid}"