From a3b5102a36a2eb1372a235764fcd7d92b1a71017 Mon Sep 17 00:00:00 2001 From: fslongjin Date: Mon, 25 Jul 2022 11:05:30 +0800 Subject: [PATCH] =?UTF-8?q?wrench:=20=E6=9B=B4=E6=96=B0Makefile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/Makefile | 101 +------------ kernel/arch/Makefile | 17 +++ kernel/arch/x86_64/Makefile | 7 + kernel/common/Makefile | 10 +- kernel/driver/Makefile | 2 +- kernel/driver/acpi/Makefile | 8 ++ kernel/driver/disk/Makefile | 10 ++ kernel/driver/keyboard/Makefile | 8 ++ kernel/driver/mouse/Makefile | 8 ++ kernel/driver/multiboot2/Makefile | 7 + kernel/driver/pci/Makefile | 11 ++ kernel/driver/pci/msi.c | 229 ++++++++++++++++++++++++++++++ kernel/driver/pci/msi.h | 32 +++++ kernel/driver/pci/pci.c | 224 ----------------------------- kernel/driver/pci/pci.h | 27 ---- kernel/driver/timers/Makefile | 10 ++ kernel/driver/uart/Makefile | 7 + kernel/driver/usb/xhci/xhci.h | 1 + kernel/exception/Makefile | 18 +++ kernel/mm/Makefile | 12 ++ kernel/sched/Makefile | 8 ++ kernel/smp/Makefile | 13 ++ kernel/syscall/Makefile | 8 ++ 23 files changed, 427 insertions(+), 351 deletions(-) create mode 100644 kernel/arch/Makefile create mode 100644 kernel/arch/x86_64/Makefile create mode 100644 kernel/driver/acpi/Makefile create mode 100644 kernel/driver/disk/Makefile create mode 100644 kernel/driver/keyboard/Makefile create mode 100644 kernel/driver/mouse/Makefile create mode 100644 kernel/driver/multiboot2/Makefile create mode 100644 kernel/driver/pci/Makefile create mode 100644 kernel/driver/pci/msi.c create mode 100644 kernel/driver/pci/msi.h create mode 100644 kernel/driver/timers/Makefile create mode 100644 kernel/driver/uart/Makefile create mode 100644 kernel/exception/Makefile create mode 100644 kernel/mm/Makefile create mode 100644 kernel/sched/Makefile create mode 100644 kernel/smp/Makefile create mode 100644 kernel/syscall/Makefile diff --git a/kernel/Makefile b/kernel/Makefile index e9276439..b218f7b6 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -12,27 +12,19 @@ LIB_FILES := $(foreach DIR,$(DIR_LIB),$(addprefix $(DIR)/,$(lib_patterns))) PIC := _INTR_APIC_ CFLAGS = $(GLOBAL_CFLAGS) -D $(PIC) -I $(shell pwd) -ASFLAGS := --64 +export ASFLAGS := --64 LD_LIST := head.o OBJ_LIST := head.o -kernel_subdirs := common driver process debug filesystem time +kernel_subdirs := common driver process debug filesystem time arch exception mm smp sched syscall head.o: head.S gcc -E head.S > head.s # 预处理 as $(ASFLAGS) -o head.o head.s -#gcc -mcmodel=large -fno-builtin -m64 -c head.S -o head.o - -entry.o: exception/entry.S - gcc -E exception/entry.S > exception/entry.s - as $(ASFLAGS) -o exception/entry.o exception/entry.s - - - main.o: main.c @@ -41,91 +33,6 @@ main.o: main.c gcc $(CFLAGS) -c main.c -o main.o -printk.o: common/printk.c - gcc $(CFLAGS) -c common/printk.c -o common/printk.o - -trap.o: exception/trap.c - gcc $(CFLAGS) -c exception/trap.c -o exception/trap.o - -irq.o: exception/irq.c - gcc $(CFLAGS) -c exception/irq.c -o exception/irq.o - - - -mm.o: mm/mm.c - gcc $(CFLAGS) -c mm/mm.c -o mm/mm.o - -slab.o: mm/slab.c - gcc $(CFLAGS) -c mm/slab.c -o mm/slab.o - - -sched.o: sched/sched.c - gcc $(CFLAGS) -c sched/sched.c -o sched/sched.o - -syscall.o: syscall/syscall.c - gcc $(CFLAGS) -c syscall/syscall.c -o syscall/syscall.o - -smp.o: smp/smp.c - gcc $(CFLAGS) -c smp/smp.c -o smp/smp.o - -apu_boot.o: smp/apu_boot.S - gcc -E smp/apu_boot.S > smp/apu_boot.s # 预处理 - as $(ASFLAGS) -o smp/apu_boot.o smp/apu_boot.s - -cpu.o: common/cpu.c - gcc $(CFLAGS) -c common/cpu.c -o common/cpu.o - -softirq.o: exception/softirq.c - gcc $(CFLAGS) -c exception/softirq.c -o exception/softirq.o - - -# IPI的代码 -ifeq ($(ARCH), __x86_64__) -OBJ_LIST += ipi.o -LD_LIST += arch/x86_64/x86_64_ipi.o -ipi.o: arch/x86_64/x86_64_ipi.c - gcc $(CFLAGS) -c arch/x86_64/x86_64_ipi.c -o arch/x86_64/x86_64_ipi.o - -endif - -# 驱动程序 - - -multiboot2.o: driver/multiboot2/multiboot2.c - gcc $(CFLAGS) -c driver/multiboot2/multiboot2.c -o driver/multiboot2/multiboot2.o - -acpi.o: driver/acpi/acpi.c - gcc $(CFLAGS) -c driver/acpi/acpi.c -o driver/acpi/acpi.o - -ps2_keyboard.o: driver/keyboard/ps2_keyboard.c - gcc $(CFLAGS) -c driver/keyboard/ps2_keyboard.c -o driver/keyboard/ps2_keyboard.o - -ps2_mouse.o: driver/mouse/ps2_mouse.c - gcc $(CFLAGS) -c driver/mouse/ps2_mouse.c -o driver/mouse/ps2_mouse.o - -ata.o: driver/disk/ata.c - gcc $(CFLAGS) -c driver/disk/ata.c -o driver/disk/ata.o - -pci.o: driver/pci/pci.c - gcc $(CFLAGS) -c driver/pci/pci.c -o driver/pci/pci.o - -ahci.o: driver/disk/ahci/ahci.c - gcc $(CFLAGS) -c driver/disk/ahci/ahci.c -o driver/disk/ahci/ahci.o - -rtc.o: driver/timers/rtc/rtc.c - gcc $(CFLAGS) -c driver/timers/rtc/rtc.c -o driver/timers/rtc/rtc.o - -HPET.o: driver/timers/HPET/HPET.c - gcc $(CFLAGS) -c driver/timers/HPET/HPET.c -o driver/timers/HPET/HPET.o - - -OBJ_LIST += uart.o -LD_LIST += driver/uart/uart.o -uart.o: driver/uart/uart.c - gcc $(CFLAGS) -c driver/uart/uart.c -o driver/uart/uart.o - - - all: kernel echo "Linking kernel..." ld -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") -T link.lds @@ -140,14 +47,14 @@ all: kernel # 重新链接 echo "Re-Linking kernel..." - ld -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ./debug/kallsyms.o -T link.lds + ld -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") -T link.lds echo "Generating kernel ELF file..." # 生成内核文件 objcopy -I elf64-x86-64 -O elf64-x86-64 -R ".comment" -R ".eh_frame" kernel ../bin/kernel/kernel.elf echo "Done." -kernel: head.o entry.o main.o printk.o trap.o mm.o slab.o irq.o sched.o syscall.o multiboot2.o cpu.o acpi.o ps2_keyboard.o ps2_mouse.o ata.o pci.o ahci.o smp.o apu_boot.o rtc.o HPET.o softirq.o $(OBJ_LIST) +kernel: head.o main.o $(OBJ_LIST) @list='$(kernel_subdirs)'; for subdir in $$list; do \ echo "make all in $$subdir";\ diff --git a/kernel/arch/Makefile b/kernel/arch/Makefile new file mode 100644 index 00000000..e2e8a164 --- /dev/null +++ b/kernel/arch/Makefile @@ -0,0 +1,17 @@ + +CFLAGS += -I . + +ifeq ($(ARCH), __x86_64__) +kernel_arch_subdirs:=x86_64 +endif + +all: + @list='$(kernel_arch_subdirs)'; for subdir in $$list; do \ + echo "make all in $$subdir";\ + cd $$subdir;\ + $(MAKE) all CFLAGS="$(CFLAGS)" PIC="$(PIC)";\ + cd ..;\ + done + +clean: + echo "Done." \ No newline at end of file diff --git a/kernel/arch/x86_64/Makefile b/kernel/arch/x86_64/Makefile new file mode 100644 index 00000000..fb2830f7 --- /dev/null +++ b/kernel/arch/x86_64/Makefile @@ -0,0 +1,7 @@ +CFLAGS += -I . + +all: x86_64_ipi.o + +x86_64_ipi.o: x86_64_ipi.c + gcc $(CFLAGS) -c x86_64_ipi.c -o x86_64_ipi.o + diff --git a/kernel/common/Makefile b/kernel/common/Makefile index c1740c59..038476a5 100644 --- a/kernel/common/Makefile +++ b/kernel/common/Makefile @@ -3,7 +3,7 @@ CFLAGS += -I . kernel_common_subdirs:=libELF math -all: glib.o +all: glib.o printk.o cpu.o @list='$(kernel_common_subdirs)'; for subdir in $$list; do \ echo "make all in $$subdir";\ cd $$subdir;\ @@ -12,4 +12,10 @@ all: glib.o done glib.o: glib.c - gcc $(CFLAGS) -c glib.c -o glib.o \ No newline at end of file + gcc $(CFLAGS) -c glib.c -o glib.o + +printk.o: printk.c + gcc $(CFLAGS) -c printk.c -o printk.o + +cpu.o: cpu.c + gcc $(CFLAGS) -c cpu.c -o cpu.o \ No newline at end of file diff --git a/kernel/driver/Makefile b/kernel/driver/Makefile index 06e53d61..1a9ede91 100644 --- a/kernel/driver/Makefile +++ b/kernel/driver/Makefile @@ -1,7 +1,7 @@ CFLAGS += -I . -kernel_driver_subdirs:=video interrupt usb +kernel_driver_subdirs:=video interrupt usb pci uart acpi disk keyboard mouse multiboot2 timers all: @list='$(kernel_driver_subdirs)'; for subdir in $$list; do \ diff --git a/kernel/driver/acpi/Makefile b/kernel/driver/acpi/Makefile new file mode 100644 index 00000000..8679a6fb --- /dev/null +++ b/kernel/driver/acpi/Makefile @@ -0,0 +1,8 @@ + +all: acpi.o + +CFLAGS += -I . + + +acpi.o: acpi.c + gcc $(CFLAGS) -c acpi.c -o acpi.o diff --git a/kernel/driver/disk/Makefile b/kernel/driver/disk/Makefile new file mode 100644 index 00000000..44a63927 --- /dev/null +++ b/kernel/driver/disk/Makefile @@ -0,0 +1,10 @@ + +all: ata.o ahci.o + +CFLAGS += -I . + +ata.o: ata.c + gcc $(CFLAGS) -c ata.c -o ata.o + +ahci.o: ahci/ahci.c + gcc $(CFLAGS) -c ahci/ahci.c -o ahci/ahci.o \ No newline at end of file diff --git a/kernel/driver/keyboard/Makefile b/kernel/driver/keyboard/Makefile new file mode 100644 index 00000000..245b69e9 --- /dev/null +++ b/kernel/driver/keyboard/Makefile @@ -0,0 +1,8 @@ + +all: ps2_keyboard.o + +CFLAGS += -I . + + +ps2_keyboard.o: ps2_keyboard.c + gcc $(CFLAGS) -c ps2_keyboard.c -o ps2_keyboard.o \ No newline at end of file diff --git a/kernel/driver/mouse/Makefile b/kernel/driver/mouse/Makefile new file mode 100644 index 00000000..93e1a00e --- /dev/null +++ b/kernel/driver/mouse/Makefile @@ -0,0 +1,8 @@ + +all: ps2_mouse.o + +CFLAGS += -I . + + +ps2_mouse.o: ps2_mouse.c + gcc $(CFLAGS) -c ps2_mouse.c -o ps2_mouse.o \ No newline at end of file diff --git a/kernel/driver/multiboot2/Makefile b/kernel/driver/multiboot2/Makefile new file mode 100644 index 00000000..ebe0652d --- /dev/null +++ b/kernel/driver/multiboot2/Makefile @@ -0,0 +1,7 @@ + +all: multiboot2.o + +CFLAGS += -I . + +multiboot2.o: multiboot2.c + gcc $(CFLAGS) -c multiboot2.c -o multiboot2.o \ No newline at end of file diff --git a/kernel/driver/pci/Makefile b/kernel/driver/pci/Makefile new file mode 100644 index 00000000..b96890c5 --- /dev/null +++ b/kernel/driver/pci/Makefile @@ -0,0 +1,11 @@ + +all: pci.o msi.o + +CFLAGS += -I . + + +pci.o: pci.c + gcc $(CFLAGS) -c pci.c -o pci.o + +msi.o: msi.c + gcc $(CFLAGS) -c msi.c -o msi.o diff --git a/kernel/driver/pci/msi.c b/kernel/driver/pci/msi.c new file mode 100644 index 00000000..aba4bde3 --- /dev/null +++ b/kernel/driver/pci/msi.c @@ -0,0 +1,229 @@ +#include "msi.h" +#include "pci.h" + +/** + * @brief 生成架构相关的msi的message address + * + */ +#define pci_get_arch_msi_message_address(processor) ((uint64_t)(0xfee00000UL | (processor << 12))) + +/** + * @brief 生成架构相关的message data + * + */ +#define pci_get_arch_msi_message_data(vector, processor, edge_trigger, assert) ((uint32_t)((vector & 0xff) | (edge_trigger == 1 ? 0 : (1 << 15)) | ((assert == 0) ? 0 : (1 << 14)))) + + +/** + * @brief 启用 Message Signaled Interrupts + * + * @param header 设备header + * @param vector 中断向量号 + * @param processor 要投递到的处理器 + * @param edge_trigger 是否边缘触发 + * @param assert 是否高电平触发 + * + * @return 返回码 + */ +int pci_enable_msi(void *header, uint8_t vector, uint32_t processor, uint8_t edge_trigger, uint8_t assert) +{ + struct pci_device_structure_header_t *ptr = (struct pci_device_structure_header_t *)header; + uint32_t cap_ptr; + uint32_t tmp; + uint16_t message_control; + uint64_t message_addr; + switch (ptr->HeaderType) + { + case 0x00: // general device + if (!(ptr->Status & 0x10)) + return E_NOT_SUPPORT_MSI; + + cap_ptr = ((struct pci_device_structure_general_device_t *)ptr)->Capabilities_Pointer; + + tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 + message_control = (tmp >> 16) & 0xffff; + + if (tmp & 0xff != 0x5) + return E_NOT_SUPPORT_MSI; + + // 写入message address + message_addr = pci_get_arch_msi_message_address(processor); // 获取message address + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0x4, (uint32_t)(message_addr & 0xffffffff)); + + if (message_control & (1 << 7)) // 64位 + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0x8, (uint32_t)((message_addr >> 32) & 0xffffffff)); + + // 写入message data + tmp = pci_get_arch_msi_message_data(vector, processor, edge_trigger, assert); + if (message_control & (1 << 7)) // 64位 + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0xc, tmp); + else + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0x8, tmp); + + // 使能msi + tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 + tmp |= (1 << 16); + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp); + + break; + + case 0x01: // pci to pci bridge + if (!(ptr->Status & 0x10)) + return E_NOT_SUPPORT_MSI; + cap_ptr = ((struct pci_device_structure_pci_to_pci_bridge_t *)ptr)->Capability_Pointer; + + tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 + + message_control = (tmp >> 16) & 0xffff; + + if (tmp & 0xff != 0x5) + return E_NOT_SUPPORT_MSI; + + // 写入message address + message_addr = pci_get_arch_msi_message_address(processor); // 获取message address + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0x4, (uint32_t)(message_addr & 0xffffffff)); + + if (message_control & (1 << 7)) // 64位 + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0x8, (uint32_t)((message_addr >> 32) & 0xffffffff)); + + // 写入message data + tmp = pci_get_arch_msi_message_data(vector, processor, edge_trigger, assert); + if (message_control & (1 << 7)) // 64位 + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0xc, tmp); + else + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0x8, tmp); + + // 使能msi + tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 + tmp |= (1 << 16); + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp); + + break; + case 0x02: // pci to card bus bridge + return E_NOT_SUPPORT_MSI; + break; + + default: // 不应该到达这里 + return E_WRONG_HEADER_TYPE; + break; + } + + return 0; +} + +/** + * @brief 在已配置好msi寄存器的设备上,使能msi + * + * @param header 设备头部 + * @return int 返回码 + */ +int pci_start_msi(void *header) +{ + struct pci_device_structure_header_t *ptr = (struct pci_device_structure_header_t *)header; + uint32_t cap_ptr; + uint32_t tmp; + + switch (ptr->HeaderType) + { + case 0x00: // general device + if (!(ptr->Status & 0x10)) + return E_NOT_SUPPORT_MSI; + cap_ptr = ((struct pci_device_structure_general_device_t *)ptr)->Capabilities_Pointer; + + tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 + + if (tmp & 0xff != 0x5) + return E_NOT_SUPPORT_MSI; + + // 使能msi + tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 + tmp |= (1 << 16); + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp); + + break; + + case 0x01: // pci to pci bridge + if (!(ptr->Status & 0x10)) + return E_NOT_SUPPORT_MSI; + cap_ptr = ((struct pci_device_structure_pci_to_pci_bridge_t *)ptr)->Capability_Pointer; + + tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 + + if (tmp & 0xff != 0x5) + return E_NOT_SUPPORT_MSI; + + //使能msi + tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 + tmp |= (1 << 16); + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp); + + break; + case 0x02: // pci to card bus bridge + return E_NOT_SUPPORT_MSI; + break; + + default: // 不应该到达这里 + return E_WRONG_HEADER_TYPE; + break; + } + + return 0; +} +/** + * @brief 禁用指定设备的msi + * + * @param header pci header + * @return int + */ +int pci_disable_msi(void *header) +{ + struct pci_device_structure_header_t *ptr = (struct pci_device_structure_header_t *)header; + uint32_t cap_ptr; + uint32_t tmp; + + switch (ptr->HeaderType) + { + case 0x00: // general device + if (!(ptr->Status & 0x10)) + return E_NOT_SUPPORT_MSI; + cap_ptr = ((struct pci_device_structure_general_device_t *)ptr)->Capabilities_Pointer; + + tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 + + if (tmp & 0xff != 0x5) + return E_NOT_SUPPORT_MSI; + + // 禁用msi + tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 + tmp &= (~(1 << 16)); + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp); + + break; + + case 0x01: // pci to pci bridge + if (!(ptr->Status & 0x10)) + return E_NOT_SUPPORT_MSI; + cap_ptr = ((struct pci_device_structure_pci_to_pci_bridge_t *)ptr)->Capability_Pointer; + + tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 + + if (tmp & 0xff != 0x5) + return E_NOT_SUPPORT_MSI; + + //禁用msi + tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 + tmp &= (~(1 << 16)); + pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp); + + break; + case 0x02: // pci to card bus bridge + return E_NOT_SUPPORT_MSI; + break; + + default: // 不应该到达这里 + return E_WRONG_HEADER_TYPE; + break; + } + + return 0; +} \ No newline at end of file diff --git a/kernel/driver/pci/msi.h b/kernel/driver/pci/msi.h new file mode 100644 index 00000000..4bef35e5 --- /dev/null +++ b/kernel/driver/pci/msi.h @@ -0,0 +1,32 @@ +#pragma once +#include + + +/** + * @brief 启用 Message Signaled Interrupts + * + * @param header 设备header + * @param vector 中断向量号 + * @param processor 要投递到的处理器 + * @param edge_trigger 是否边缘触发 + * @param assert 是否高电平触发 + * + * @return 返回码 + */ +int pci_enable_msi(void * header, uint8_t vector, uint32_t processor, uint8_t edge_trigger, uint8_t assert); + +/** + * @brief 禁用指定设备的msi + * + * @param header pci header + * @return int + */ +int pci_disable_msi(void *header); + +/** + * @brief 在已配置好msi寄存器的设备上,使能msi + * + * @param header 设备头部 + * @return int 返回码 + */ +int pci_start_msi(void *header); \ No newline at end of file diff --git a/kernel/driver/pci/pci.c b/kernel/driver/pci/pci.c index f8822723..c0dd3eda 100644 --- a/kernel/driver/pci/pci.c +++ b/kernel/driver/pci/pci.c @@ -26,17 +26,6 @@ static void pci_checkBus(uint8_t bus); } \ } while (0) -/** - * @brief 生成架构相关的msi的message address - * - */ -#define pci_get_arch_msi_message_address(processor) ((uint64_t)(0xfee00000UL | (processor << 12))) - -/** - * @brief 生成架构相关的message data - * - */ -#define pci_get_arch_msi_message_data(vector, processor, edge_trigger, assert) ((uint32_t)((vector & 0xff) | (edge_trigger == 1 ? 0 : (1 << 15)) | ((assert == 0) ? 0 : (1 << 14)))) /** * @brief 从pci配置空间读取信息 @@ -479,219 +468,6 @@ void pci_init() kinfo("PCI bus initialized.") } -/** - * @brief 启用 Message Signaled Interrupts - * - * @param header 设备header - * @param vector 中断向量号 - * @param processor 要投递到的处理器 - * @param edge_trigger 是否边缘触发 - * @param assert 是否高电平触发 - * - * @return 返回码 - */ -int pci_enable_msi(void *header, uint8_t vector, uint32_t processor, uint8_t edge_trigger, uint8_t assert) -{ - struct pci_device_structure_header_t *ptr = (struct pci_device_structure_header_t *)header; - uint32_t cap_ptr; - uint32_t tmp; - uint16_t message_control; - uint64_t message_addr; - switch (ptr->HeaderType) - { - case 0x00: // general device - if (!(ptr->Status & 0x10)) - return E_NOT_SUPPORT_MSI; - - cap_ptr = ((struct pci_device_structure_general_device_t *)ptr)->Capabilities_Pointer; - - tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 - message_control = (tmp >> 16) & 0xffff; - - if (tmp & 0xff != 0x5) - return E_NOT_SUPPORT_MSI; - - // 写入message address - message_addr = pci_get_arch_msi_message_address(processor); // 获取message address - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0x4, (uint32_t)(message_addr & 0xffffffff)); - - if (message_control & (1 << 7)) // 64位 - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0x8, (uint32_t)((message_addr >> 32) & 0xffffffff)); - - // 写入message data - tmp = pci_get_arch_msi_message_data(vector, processor, edge_trigger, assert); - if (message_control & (1 << 7)) // 64位 - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0xc, tmp); - else - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0x8, tmp); - - // 使能msi - tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 - tmp |= (1 << 16); - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp); - - break; - - case 0x01: // pci to pci bridge - if (!(ptr->Status & 0x10)) - return E_NOT_SUPPORT_MSI; - cap_ptr = ((struct pci_device_structure_pci_to_pci_bridge_t *)ptr)->Capability_Pointer; - - tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 - - message_control = (tmp >> 16) & 0xffff; - - if (tmp & 0xff != 0x5) - return E_NOT_SUPPORT_MSI; - - // 写入message address - message_addr = pci_get_arch_msi_message_address(processor); // 获取message address - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0x4, (uint32_t)(message_addr & 0xffffffff)); - - if (message_control & (1 << 7)) // 64位 - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0x8, (uint32_t)((message_addr >> 32) & 0xffffffff)); - - // 写入message data - tmp = pci_get_arch_msi_message_data(vector, processor, edge_trigger, assert); - if (message_control & (1 << 7)) // 64位 - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0xc, tmp); - else - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr + 0x8, tmp); - - // 使能msi - tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 - tmp |= (1 << 16); - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp); - - break; - case 0x02: // pci to card bus bridge - return E_NOT_SUPPORT_MSI; - break; - - default: // 不应该到达这里 - return E_WRONG_HEADER_TYPE; - break; - } - - return 0; -} - -/** - * @brief 在已配置好msi寄存器的设备上,使能msi - * - * @param header 设备头部 - * @return int 返回码 - */ -int pci_start_msi(void *header) -{ - struct pci_device_structure_header_t *ptr = (struct pci_device_structure_header_t *)header; - uint32_t cap_ptr; - uint32_t tmp; - - switch (ptr->HeaderType) - { - case 0x00: // general device - if (!(ptr->Status & 0x10)) - return E_NOT_SUPPORT_MSI; - cap_ptr = ((struct pci_device_structure_general_device_t *)ptr)->Capabilities_Pointer; - - tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 - - if (tmp & 0xff != 0x5) - return E_NOT_SUPPORT_MSI; - - // 使能msi - tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 - tmp |= (1 << 16); - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp); - - break; - - case 0x01: // pci to pci bridge - if (!(ptr->Status & 0x10)) - return E_NOT_SUPPORT_MSI; - cap_ptr = ((struct pci_device_structure_pci_to_pci_bridge_t *)ptr)->Capability_Pointer; - - tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 - - if (tmp & 0xff != 0x5) - return E_NOT_SUPPORT_MSI; - - //使能msi - tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 - tmp |= (1 << 16); - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp); - - break; - case 0x02: // pci to card bus bridge - return E_NOT_SUPPORT_MSI; - break; - - default: // 不应该到达这里 - return E_WRONG_HEADER_TYPE; - break; - } - - return 0; -} -/** - * @brief 禁用指定设备的msi - * - * @param header pci header - * @return int - */ -int pci_disable_msi(void *header) -{ - struct pci_device_structure_header_t *ptr = (struct pci_device_structure_header_t *)header; - uint32_t cap_ptr; - uint32_t tmp; - - switch (ptr->HeaderType) - { - case 0x00: // general device - if (!(ptr->Status & 0x10)) - return E_NOT_SUPPORT_MSI; - cap_ptr = ((struct pci_device_structure_general_device_t *)ptr)->Capabilities_Pointer; - - tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 - - if (tmp & 0xff != 0x5) - return E_NOT_SUPPORT_MSI; - - // 禁用msi - tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 - tmp &= (~(1 << 16)); - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp); - - break; - - case 0x01: // pci to pci bridge - if (!(ptr->Status & 0x10)) - return E_NOT_SUPPORT_MSI; - cap_ptr = ((struct pci_device_structure_pci_to_pci_bridge_t *)ptr)->Capability_Pointer; - - tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 - - if (tmp & 0xff != 0x5) - return E_NOT_SUPPORT_MSI; - - //禁用msi - tmp = pci_read_config(ptr->bus, ptr->device, ptr->func, cap_ptr); // 读取cap+0x0处的值 - tmp &= (~(1 << 16)); - pci_write_config(ptr->bus, ptr->device, ptr->func, cap_ptr, tmp); - - break; - case 0x02: // pci to card bus bridge - return E_NOT_SUPPORT_MSI; - break; - - default: // 不应该到达这里 - return E_WRONG_HEADER_TYPE; - break; - } - - return 0; -} /** * @brief 获取 device structure diff --git a/kernel/driver/pci/pci.h b/kernel/driver/pci/pci.h index eb5832bb..5bf417b2 100644 --- a/kernel/driver/pci/pci.h +++ b/kernel/driver/pci/pci.h @@ -205,34 +205,7 @@ void* pci_read_header(int *type, uchar bus, uchar slot, uchar func, bool add_to_ */ void pci_checkAllBuses(); -/** - * @brief 启用 Message Signaled Interrupts - * - * @param header 设备header - * @param vector 中断向量号 - * @param processor 要投递到的处理器 - * @param edge_trigger 是否边缘触发 - * @param assert 是否高电平触发 - * - * @return 返回码 - */ -int pci_enable_msi(void * header, uint8_t vector, uint32_t processor, uint8_t edge_trigger, uint8_t assert); -/** - * @brief 禁用指定设备的msi - * - * @param header pci header - * @return int - */ -int pci_disable_msi(void *header); - -/** - * @brief 在已配置好msi寄存器的设备上,使能msi - * - * @param header 设备头部 - * @return int 返回码 - */ -int pci_start_msi(void *header); /** * @brief 获取 device structure diff --git a/kernel/driver/timers/Makefile b/kernel/driver/timers/Makefile new file mode 100644 index 00000000..42ca1932 --- /dev/null +++ b/kernel/driver/timers/Makefile @@ -0,0 +1,10 @@ + +all: rtc.o HPET.o + +CFLAGS += -I . + +rtc.o: rtc/rtc.c + gcc $(CFLAGS) -c rtc/rtc.c -o rtc/rtc.o + +HPET.o: HPET/HPET.c + gcc $(CFLAGS) -c HPET/HPET.c -o HPET/HPET.o diff --git a/kernel/driver/uart/Makefile b/kernel/driver/uart/Makefile new file mode 100644 index 00000000..9f8ea0dd --- /dev/null +++ b/kernel/driver/uart/Makefile @@ -0,0 +1,7 @@ + +all: uart.o + +CFLAGS += -I . + +uart.o: uart.c + gcc $(CFLAGS) -c uart.c -o uart.o diff --git a/kernel/driver/usb/xhci/xhci.h b/kernel/driver/usb/xhci/xhci.h index 9e724423..2ac11c8e 100644 --- a/kernel/driver/usb/xhci/xhci.h +++ b/kernel/driver/usb/xhci/xhci.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #define XHCI_MAX_HOST_CONTROLLERS 4 // 本驱动程序最大支持4个xhci root hub controller #define XHCI_MAX_ROOT_HUB_PORTS 128 // 本驱动程序最大支持127个root hub 端口(第0个保留) diff --git a/kernel/exception/Makefile b/kernel/exception/Makefile new file mode 100644 index 00000000..033c0e70 --- /dev/null +++ b/kernel/exception/Makefile @@ -0,0 +1,18 @@ + +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 + +trap.o: trap.c + gcc $(CFLAGS) -c trap.c -o trap.o + +softirq.o: softirq.c + gcc $(CFLAGS) -c softirq.c -o softirq.o + +irq.o: irq.c + gcc $(CFLAGS) -c irq.c -o irq.o \ No newline at end of file diff --git a/kernel/mm/Makefile b/kernel/mm/Makefile new file mode 100644 index 00000000..d604d817 --- /dev/null +++ b/kernel/mm/Makefile @@ -0,0 +1,12 @@ + +CFLAGS += -I . + + +all:mm.o slab.o + +mm.o: mm.c + gcc $(CFLAGS) -c mm.c -o mm.o + +slab.o: slab.c + gcc $(CFLAGS) -c slab.c -o slab.o + diff --git a/kernel/sched/Makefile b/kernel/sched/Makefile new file mode 100644 index 00000000..54099cbc --- /dev/null +++ b/kernel/sched/Makefile @@ -0,0 +1,8 @@ + +CFLAGS += -I . + + +all: sched.o + +sched.o: sched.c + gcc $(CFLAGS) -c sched.c -o sched.o diff --git a/kernel/smp/Makefile b/kernel/smp/Makefile new file mode 100644 index 00000000..5379b54c --- /dev/null +++ b/kernel/smp/Makefile @@ -0,0 +1,13 @@ + +CFLAGS += -I . + + +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 + +smp.o: smp.c + gcc $(CFLAGS) -c smp.c -o smp.o \ No newline at end of file diff --git a/kernel/syscall/Makefile b/kernel/syscall/Makefile new file mode 100644 index 00000000..e82c325d --- /dev/null +++ b/kernel/syscall/Makefile @@ -0,0 +1,8 @@ + +CFLAGS += -I . + + +all: syscall.o + +syscall.o: syscall.c + gcc $(CFLAGS) -c syscall.c -o syscall.o