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
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) {}
// 《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);
// 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:
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;
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;
// 它们之间的关系是多对一的关系
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
//
};
+struct file_operations {
+ // open
+ // close
+ // read
+ // write
+ // lseek
+ // ioctl
+};
struct inode_operations {
//
};
struct dentry_operations {
//
+ // hash
+ // compare
};
// 每当将一个存储设备安装到现有文件系统中的某个节点时,内核就要为之建立一个vfsmount结构
extern superblock_t *root_sb;
-void register_filesystem(fs_type_t *fs);
+void vfs_register_filesystem(fs_type_t *fs);
+# 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
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 \
#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}"