From: acevest Date: Tue, 26 Sep 2023 12:53:19 +0000 (+0800) Subject: 修复编译问题;添加调试指令 X-Git-Url: http://zhaoyanbai.com/repos/Bv9ARM.ch07.html?a=commitdiff_plain;h=69256c2a3978b7698e006ac2b8ac5103cf73d362;p=kernel.git 修复编译问题;添加调试指令 --- diff --git a/Makefile b/Makefile index ba1ce6a..be70137 100644 --- 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 diff --git a/drivers/block.c b/drivers/block.c index ed538dd..2fa1450 100644 --- a/drivers/block.c +++ b/drivers/block.c @@ -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) {} diff --git a/drivers/ide.c b/drivers/ide.c index aa0f61e..1ea6430 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -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); diff --git a/drivers/pci.c b/drivers/pci.c index 21718d1..5f65f09 100644 --- a/drivers/pci.c +++ b/drivers/pci.c @@ -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: diff --git a/fs/vfs.c b/fs/vfs.c index c7b7578..d1ab375 100644 --- 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; diff --git a/fs/vfs.h b/fs/vfs.h index 1684dac..af9dee5 100644 --- 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); diff --git a/gdbscript b/gdbscript index 7c763a7..238cb70 100644 --- 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 efff4d2..ac37fed 100755 --- 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}"