From 1b09896afcf562d199d4df8d671601bba2b1f081 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sun, 4 Feb 2024 14:19:54 -0500 Subject: [PATCH] refactor arch --- Makefile | 46 +++-- debugger.o | Bin 0 -> 22448 bytes include/fpu.h | 3 - include/sys/acpi.h | 177 +++++++++++++++++ include/sys/pci.h | 16 ++ include/{memory => sys}/physalloc.h | 2 +- include/{memory => sys}/virtalloc.h | 0 src/{arch/amd64 => }/acpi.c | 187 +----------------- src/arch/amd64/cpu/idt.c | 6 +- src/arch/amd64/fpu.c | 5 +- src/arch/amd64/fpu.h | 3 + src/arch/amd64/paging.c | 6 +- src/arch/amd64/panic.c | 4 +- src/arch/amd64/shim.c | 6 +- src/arch/x86_common/acpi.c | 13 ++ .../{amd64 => x86_common}/drivers/bochs.c | 3 +- src/arch/x86_common/drivers/pci.c | 57 ++++++ src/arch/{amd64 => x86_common}/drivers/pic.c | 4 +- .../{amd64 => x86_common}/drivers/serial.c | 3 +- .../{amd64 => x86_common/include}/bindings.h | 0 .../{amd64 => x86_common/include}/mboot.h | 0 .../drivers => x86_common/include}/pic.h | 0 src/arch/{amd64 => x86_common}/mboot.c | 3 +- src/{arch/amd64 => }/drivers/pci.c | 55 ++---- src/kmain.c | 2 - src/memory/physalloc.c | 4 +- src/memory/virtalloc.c | 2 +- 27 files changed, 343 insertions(+), 264 deletions(-) create mode 100644 debugger.o delete mode 100644 include/fpu.h create mode 100644 include/sys/acpi.h create mode 100644 include/sys/pci.h rename include/{memory => sys}/physalloc.h (89%) rename include/{memory => sys}/virtalloc.h (100%) rename src/{arch/amd64 => }/acpi.c (50%) create mode 100644 src/arch/amd64/fpu.h create mode 100644 src/arch/x86_common/acpi.c rename src/arch/{amd64 => x86_common}/drivers/bochs.c (98%) create mode 100644 src/arch/x86_common/drivers/pci.c rename src/arch/{amd64 => x86_common}/drivers/pic.c (98%) rename src/arch/{amd64 => x86_common}/drivers/serial.c (98%) rename src/arch/{amd64 => x86_common/include}/bindings.h (100%) rename src/arch/{amd64 => x86_common/include}/mboot.h (100%) rename src/arch/{amd64/drivers => x86_common/include}/pic.h (100%) rename src/arch/{amd64 => x86_common}/mboot.c (99%) rename src/{arch/amd64 => }/drivers/pci.c (73%) diff --git a/Makefile b/Makefile index ae2396e..0f034af 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,14 @@ -KERNEL=kernel.bin -ISO=os_image.iso +# +# Makefile Configuration +# -ARCH=amd64 CC=cc LD=ld AS=nasm +ARCH=amd64 +ARCH_COMMON=x86_common + +BUILD=build CFLAGS += -std=c2x -ffreestanding -lgcc -isystem include -pipe CFLAGS += -Wall -Wextra -pedantic @@ -13,24 +17,37 @@ CFLAGS += -DPAGE_SIZE=4096 LDFLAGS += -nmagic --no-warn-rwx-segments -nostdlib -H_SRC = $(shell find src include -type f -name "*.h") +# +# Makefile +# -C_SRC = $(shell find src -type f -name "*.c") +ARCH_COMMON += $(ARCH) + +KERNEL=kernel.bin +ISO=os_image.iso + +ARCH_DIRS = $(patsubst %,src/arch/%,$(ARCH_COMMON)) +ARCH_INCLUDES = $(shell find $(ARCH_DIRS) -type d -name "include") +CFLAGS_ARCH = $(patsubst %, -isystem %,$(ARCH_INCLUDES)) + +H_SRC = $(shell find src include -type f -name "*.h" -not -path "src/arch/*") +HA_SRC = $(shell find $(ARCH_DIRS) -type f -name "*.h") + +C_SRC = $(shell find src -type f -name "*.c" -not -path "src/arch/*") C_OBJ = $(patsubst %.c,build/%.o,$(C_SRC)) +CA_SRC = $(shell find $(ARCH_DIRS) -type f -name "*.c") +CA_OBJ = $(patsubst %.c,build/%.o,$(CA_SRC)) -A_SRC = $(shell find src -type f -name "*.S" -not -path "src/arch/*") -A_SRC += $(shell find src/arch/$(ARCH) -type f -name "*.S") +A_SRC = $(shell find $(ARCH_DIRS) -type f -name "*.S") A_OBJ = $(patsubst %.S,build/%.S.o,$(A_SRC)) .PHONY: all clean all: build/$(ISO) -build: build/$(ISO) - clean: @printf "\033[31m RM \033[0m%s\n" build - @rm -rf build/* + @rm -fr ./build $(A_OBJ): build/%.S.o : %.S @mkdir -p $(@D) @@ -42,10 +59,15 @@ $(C_OBJ): build/%.o : %.c @printf "\033[34m CC \033[0m%s\n" $< @$(CC) -c $(CFLAGS) -o $@ $< -build/$(KERNEL): arch/$(ARCH)/linker.ld $(A_OBJ) $(C_OBJ) $(H_SRC) +$(CA_OBJ): build/%.o : %.c + @mkdir -p $(@D) + @printf "\033[34m CC \033[0m%s\n" $< + @$(CC) -c $(CFLAGS) $(CFLAGS_ARCH) -o $@ $< + +build/$(KERNEL): arch/$(ARCH)/linker.ld $(A_OBJ) $(C_OBJ) $(CA_OBJ) $(H_SRC) $(HA_SRC) @mkdir -p $(@D) @printf "\033[32m LD \033[0m%s\n" $@ - @$(LD) $(LDFLAGS) -T arch/$(ARCH)/linker.ld -o build/$(KERNEL) $(A_OBJ) $(C_OBJ) + @$(LD) $(LDFLAGS) -T arch/$(ARCH)/linker.ld -o build/$(KERNEL) $(A_OBJ) $(C_OBJ) $(CA_OBJ) build/$(ISO): build/$(KERNEL) grub.cfg @mkdir -p $(@D) diff --git a/debugger.o b/debugger.o new file mode 100644 index 0000000000000000000000000000000000000000..9700bf8fc7b624712c14faa41d411c62a3712fa5 GIT binary patch literal 22448 zcmb`v2|QKLAOC-@B};PArnFoY;ZwLs$&#DxDq2V?l`Pkitt=re_6Vg#iTb3pXjekT zM~Ko+o6?34eFanG4~&THN?XSTDl(Za@3gvFw;u_zPj zcMMaC%ANN+Y)S`BsZo>?<-kvT&0A=b5;}wDV4c{*TVT&m{Lu^ryu=ElLBVXJjUi6f z2G0ZiZ45dB-=toa21#_fb&7>4-{4BnWPV~fU%f7-krk|PRg~h#Tw(DI9tRKeV2?GY zC?OHKYSu>q8uH1Bx0JVxw|v#Q|s&NW2?ti_rhIDJ-th#Xt?haj45~U5})y6n%L~P$skMD zHB)x%1Q1A~Yadt2-nszB2El`fyUvcA3t}<7EOxA>Bn*hKV?_sml&%mSY6;X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KGxJ}NfhusFCEWem;^W8p7l0HPW)$=5I)Yh$a&3c7=Yrqg+FugBBnAfmu^Tkl z{_xTfmyg@u1u$BI6F?lA7dlVRVhjw1j9Ln`e=Gk2TF|u7gG*RGyp+TFaru6L{jK~9 zgFynYB2<52?00?~j{t$c?tWTVY0= zA09t!Qd~Yh{{4Xct^R5-1F-AD-LEaqj{#iY|Caw7$`Aj|A8E||XF%fL>aRFQm}?$7 zVCW9ceViZHzZ5Vi!QXp;AZ=>!V@zP{QGQ|UcYcg-f`q^2&lxMsk%Kd$JuV;Te~R-n zbn`euFp9x(KD=)N={QVEeK}<8cbKW|1W9mSG3W0pjxZ1Ie_`zR@#8pr-w1s&^Jj5{ zib&z^*A^c?2JrdM-}=uBE)2kM`LO@sJ4~D(_ut>jhWR+ka7$68X#T_NG86D)=7)2d iF~tA@_q7x09d!^EKo}!RUrYThe>$rFFh&MOl=?rX4^ig; literal 0 HcmV?d00001 diff --git a/include/fpu.h b/include/fpu.h deleted file mode 100644 index 9f094c2..0000000 --- a/include/fpu.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -void enable_fpu(void); diff --git a/include/sys/acpi.h b/include/sys/acpi.h new file mode 100644 index 0000000..97eeab9 --- /dev/null +++ b/include/sys/acpi.h @@ -0,0 +1,177 @@ +#pragma once + +#include + +#ifndef ACPI_INTERNAL + #error "Do not include , only use " +#endif + +struct acpi_header { + uint32_t signature; + uint32_t length; + uint8_t revision; + uint8_t checksum; + uint8_t oem_id[6]; + uint8_t oem_table_id[8]; + uint32_t oem_revision; + uint32_t creator_id; + uint32_t creator_revision; +} __attribute__((packed)); + +// root system descriptor pointer +// ACPI 1.0 +struct rsdp { + uint8_t signature[8]; + uint8_t checksum; + uint8_t oemid[6]; + uint8_t revision; + uint32_t rsdt_addr; +} __attribute__((packed)); + +// eXtended system descriptor pointer +// ACPI 2.0 +struct xsdp { + char signature[8]; + uint8_t checksum; + char oemid[6]; + uint8_t revision; + uint32_t rsdt_addr; + uint32_t length; + uint64_t xsdt_addr; + uint8_t extendeid_checksum; + uint8_t reserved[3]; +} __attribute__((packed)); + +// root system descriptor table +// ACPI 1.0 +struct rsdt { + struct acpi_header h; + uint32_t sdt_pointers[]; +} __attribute__((packed)); + +// eXtended system descriptor table +// ACPI 2.0 +struct xsdt { + struct acpi_header h; + uint64_t sdt_pointers[]; +} __attribute__((packed)); + + +// generic address structure +struct gas { + uint8_t address_space; + uint8_t bit_width; + uint8_t bit_offset; + uint8_t access_size; + uint64_t address; +}; + +// differentiated system description table +struct dsdt { + struct acpi_header h; + char s5_addr[]; +} __attribute__((packed)); + +struct apic { + struct acpi_header h; + // todo +} __attribute__((packed)); + +struct hept { + struct acpi_header h; + // todo +} __attribute__((packed)); + +struct waet { + struct acpi_header h; + // todo +} __attribute__((packed)); + +// fixed acpi description table +struct fadt { + struct acpi_header h; + uint32_t firmware_ctrl; + uint32_t dsdt; + + // field used in ACPI 1.0; no longer in use, for compatibility only + uint8_t reserved; + + uint8_t preferred_power_management_profile; + uint16_t sci_interrupt; + uint32_t smi_command_port; + uint8_t acpi_enable; + uint8_t acpi_disable; + uint8_t s4bios_req; + uint8_t pstate_control; + uint32_t pm1_a_event_block; + uint32_t pm1_b_event_block; + uint32_t pm1_a_control_block; + uint32_t pm1_b_control_block; + uint32_t pm2_control_block; + uint32_t pm_timer_block; + uint32_t gpe0_block; + uint32_t gpe1_block; + uint8_t pm1_event_length; + uint8_t pm1_control_length; + uint8_t pm2_control_length; + uint8_t pm_timer_length; + uint8_t gpe0_length; + uint8_t gpe1_length; + uint8_t gpe1_base; + uint8_t cstate_control; + uint16_t worst_c2_latency; + uint16_t worst_c3_latency; + uint16_t flush_size; + uint16_t flush_stride; + uint8_t duty_offset; + uint8_t duty_width; + uint8_t day_alarm; + uint8_t month_alarm; + uint8_t century; + + // reserved in ACPI 1.0; used since ACPI 2.0+ + uint16_t boot_architecture_flags; + + uint8_t reserved_2; + uint32_t flags; + + // 12 byte structure; see below for details + struct gas reset_reg; + + uint8_t reset_value; + uint8_t reserved_3[3]; + + // 64bit pointers - Available on ACPI 2.0+ + uint64_t x_firmware_control; + uint64_t x_dsdt; + + struct gas x_pm1_a_event_block; + struct gas x_pm1_b_event_block; + struct gas x_pm1_a_control_block; + struct gas x_pm1_b_control_block; + struct gas x_pm2_control_block; + struct gas x_pm_timer_block; + struct gas x_gpe0_block; + struct gas x_gpe1_block; +} __attribute__((packed)); + +struct acpi_state { + union { + struct xsdt *xsdt; + struct rsdt *rsdt; + } sdt; + struct fadt *fadt; + struct dsdt *dsdt; + struct apic *apic; + struct hept *hept; + struct waet *waet; + uint8_t version; + + uint16_t SLP_TYPa; + uint16_t SLP_TYPb; + uint16_t SLP_EN; + uint16_t SCI_EN; +}; + +void acpi_sys_enable(struct acpi_state *state); +int acpi_sys_shutdown(struct acpi_state *state); diff --git a/include/sys/pci.h b/include/sys/pci.h new file mode 100644 index 0000000..1451434 --- /dev/null +++ b/include/sys/pci.h @@ -0,0 +1,16 @@ +#pragma once + +#ifndef PCI_INTERNAL + #error "do not include , only use " +#endif + +#include +#include + +uint32_t pci_sys_rcfg_d(struct pci_device dev, uint8_t offset); +uint16_t pci_sys_rcfg_w(struct pci_device dev, uint8_t offset); +uint8_t pci_sys_rcfg_b(struct pci_device dev, uint8_t offset); + +void pci_sys_wcfg_d(struct pci_device dev, uint8_t offset, uint32_t dword); +void pci_sys_wcfg_w(struct pci_device dev, uint8_t offset, uint16_t word); +void pci_sys_wcfg_b(struct pci_device dev, uint8_t offset, uint8_t byte); diff --git a/include/memory/physalloc.h b/include/sys/physalloc.h similarity index 89% rename from include/memory/physalloc.h rename to include/sys/physalloc.h index e95e418..6837972 100644 --- a/include/memory/physalloc.h +++ b/include/sys/physalloc.h @@ -1,7 +1,7 @@ #pragma once #ifndef MEMORY_INTERNAL - #error "Do not include headers from , only use " + #error "Do not include headers from , only use " #endif /** diff --git a/include/memory/virtalloc.h b/include/sys/virtalloc.h similarity index 100% rename from include/memory/virtalloc.h rename to include/sys/virtalloc.h diff --git a/src/arch/amd64/acpi.c b/src/acpi.c similarity index 50% rename from src/arch/amd64/acpi.c rename to src/acpi.c index a7f38b6..c6a0cce 100644 --- a/src/arch/amd64/acpi.c +++ b/src/acpi.c @@ -6,174 +6,8 @@ #include #include -#include "bindings.h" - -struct acpi_header { - uint32_t signature; - uint32_t length; - uint8_t revision; - uint8_t checksum; - uint8_t oem_id[6]; - uint8_t oem_table_id[8]; - uint32_t oem_revision; - uint32_t creator_id; - uint32_t creator_revision; -} __attribute__((packed)); - -// root system descriptor pointer -// ACPI 1.0 -struct rsdp { - uint8_t signature[8]; - uint8_t checksum; - uint8_t oemid[6]; - uint8_t revision; - uint32_t rsdt_addr; -} __attribute__((packed)); - -// eXtended system descriptor pointer -// ACPI 2.0 -struct xsdp { - char signature[8]; - uint8_t checksum; - char oemid[6]; - uint8_t revision; - uint32_t rsdt_addr; - uint32_t length; - uint64_t xsdt_addr; - uint8_t extendeid_checksum; - uint8_t reserved[3]; -} __attribute__((packed)); - -// root system descriptor table -// ACPI 1.0 -struct rsdt { - struct acpi_header h; - uint32_t sdt_pointers[]; -} __attribute__((packed)); - -// eXtended system descriptor table -// ACPI 2.0 -struct xsdt { - struct acpi_header h; - uint64_t sdt_pointers[]; -} __attribute__((packed)); - - -// generic address structure -struct gas { - uint8_t address_space; - uint8_t bit_width; - uint8_t bit_offset; - uint8_t access_size; - uint64_t address; -}; - -// differentiated system description table -struct dsdt { - struct acpi_header h; - char s5_addr[]; -} __attribute__((packed)); - -struct apic { - struct acpi_header h; - // todo -} __attribute__((packed)); - -struct hept { - struct acpi_header h; - // todo -} __attribute__((packed)); - -struct waet { - struct acpi_header h; - // todo -} __attribute__((packed)); - -// fixed acpi description table -struct fadt { - struct acpi_header h; - uint32_t firmware_ctrl; - uint32_t dsdt; - - // field used in ACPI 1.0; no longer in use, for compatibility only - uint8_t reserved; - - uint8_t preferred_power_management_profile; - uint16_t sci_interrupt; - uint32_t smi_command_port; - uint8_t acpi_enable; - uint8_t acpi_disable; - uint8_t s4bios_req; - uint8_t pstate_control; - uint32_t pm1_a_event_block; - uint32_t pm1_b_event_block; - uint32_t pm1_a_control_block; - uint32_t pm1_b_control_block; - uint32_t pm2_control_block; - uint32_t pm_timer_block; - uint32_t gpe0_block; - uint32_t gpe1_block; - uint8_t pm1_event_length; - uint8_t pm1_control_length; - uint8_t pm2_control_length; - uint8_t pm_timer_length; - uint8_t gpe0_length; - uint8_t gpe1_length; - uint8_t gpe1_base; - uint8_t cstate_control; - uint16_t worst_c2_latency; - uint16_t worst_c3_latency; - uint16_t flush_size; - uint16_t flush_stride; - uint8_t duty_offset; - uint8_t duty_width; - uint8_t day_alarm; - uint8_t month_alarm; - uint8_t century; - - // reserved in ACPI 1.0; used since ACPI 2.0+ - uint16_t boot_architecture_flags; - - uint8_t reserved_2; - uint32_t flags; - - // 12 byte structure; see below for details - struct gas reset_reg; - - uint8_t reset_value; - uint8_t reserved_3[3]; - - // 64bit pointers - Available on ACPI 2.0+ - uint64_t x_firmware_control; - uint64_t x_dsdt; - - struct gas x_pm1_a_event_block; - struct gas x_pm1_b_event_block; - struct gas x_pm1_a_control_block; - struct gas x_pm1_b_control_block; - struct gas x_pm2_control_block; - struct gas x_pm_timer_block; - struct gas x_gpe0_block; - struct gas x_gpe1_block; -} __attribute__((packed)); - -struct acpi_state { - union { - struct xsdt *xsdt; - struct rsdt *rsdt; - } sdt; - struct fadt *fadt; - struct dsdt *dsdt; - struct apic *apic; - struct hept *hept; - struct waet *waet; - uint8_t version; - - uint16_t SLP_TYPa; - uint16_t SLP_TYPb; - uint16_t SLP_EN; - uint16_t SCI_EN; -}; +#define ACPI_INTERNAL +#include /* global state, idk a better way rn */ static struct acpi_state state; @@ -284,7 +118,6 @@ static void acpi_handle_table(struct acpi_header *header) { static void acpi_load_table(uint64_t addr) { struct acpi_header *temp, *mapped; uint32_t length; - temp = (struct acpi_header * ) (uintptr_t) addr; mapped = mmap(temp, sizeof(struct acpi_header)); length = mapped->length; @@ -299,18 +132,14 @@ static void acpi_load_table(uint64_t addr) { } int acpi_init(void *rootsdp) { - memset(&state, 0, sizeof(struct acpi_state)); - struct rsdp *rsdp = (struct rsdp *) rootsdp; - - if (!checksum((uint8_t *)rsdp, sizeof(struct rsdp))) + if (!checksum((uint8_t *)rsdp, sizeof(struct rsdp))) { return -1; - + } if (memcmp(rsdp->signature, "RSD PTR ", 8) != 0) { panic("invalid acpi rsdp signature: %.*s\n", 8, rsdp->signature); } - if (rsdp->revision == 0) { state.version = 0; kprintf("ACPI 1.0\n"); @@ -323,15 +152,11 @@ int acpi_init(void *rootsdp) { } else { panic("invalid acpi rev: %d\n", rsdp->revision); } - kprintf("\n"); - - outb(state.fadt->smi_command_port,state.fadt->acpi_enable); - + acpi_sys_enable(&state); return 0; } int acpi_shutdown(void) { - outw((unsigned int) state.fadt->pm1_a_control_block, state.SLP_TYPb | state.SLP_EN); - return -1; + return acpi_sys_shutdown(&state); } diff --git a/src/arch/amd64/cpu/idt.c b/src/arch/amd64/cpu/idt.c index 5c2ef5c..a2da88f 100644 --- a/src/arch/amd64/cpu/idt.c +++ b/src/arch/amd64/cpu/idt.c @@ -1,14 +1,14 @@ #include #include #include +#include +#include #include "idt.h" #include "backtrace.h" #include "debugger.h" #include "registers.h" #include "../paging.h" -#include "../bindings.h" -#include "../drivers/pic.h" #define IDT_SIZE 256 @@ -182,7 +182,7 @@ void idt_exception_handler(uint64_t exception, uint64_t code, struct isr_regs *s } kputs("\n"); - + isr_print_regs(state); kputs("\n"); diff --git a/src/arch/amd64/fpu.c b/src/arch/amd64/fpu.c index 5a8aa92..292264c 100644 --- a/src/arch/amd64/fpu.c +++ b/src/arch/amd64/fpu.c @@ -1,9 +1,10 @@ -#include #include #include #include -void enable_fpu(void) { +#include "fpu.h" + +void fpu_enable(void) { size_t cr4; uint16_t cw = 0x37F; __asm__ volatile ("mov %%cr4, %0" : "=r"(cr4)); diff --git a/src/arch/amd64/fpu.h b/src/arch/amd64/fpu.h new file mode 100644 index 0000000..bd7ca67 --- /dev/null +++ b/src/arch/amd64/fpu.h @@ -0,0 +1,3 @@ +#pragma once + +void fpu_enable(void); diff --git a/src/arch/amd64/paging.c b/src/arch/amd64/paging.c index c857d0b..7a718e1 100644 --- a/src/arch/amd64/paging.c +++ b/src/arch/amd64/paging.c @@ -3,13 +3,13 @@ #include #include #include +#include #define MEMORY_INTERNAL -#include -#include +#include +#include #include "paging.h" -#include "bindings.h" // PAGE MAP LEVEL 4 ENTRY struct pml4e { diff --git a/src/arch/amd64/panic.c b/src/arch/amd64/panic.c index 48e65f5..6acc88c 100644 --- a/src/arch/amd64/panic.c +++ b/src/arch/amd64/panic.c @@ -1,11 +1,9 @@ #include #include #include - +#include #include -#include "bindings.h" - _Noreturn void _panic_impl(char *line, char *file, char *format, ...) { cli(); va_list list; diff --git a/src/arch/amd64/shim.c b/src/arch/amd64/shim.c index c1c3368..05d995c 100644 --- a/src/arch/amd64/shim.c +++ b/src/arch/amd64/shim.c @@ -3,11 +3,12 @@ #include #include #include +#include +#include #include "paging.h" -#include "mboot.h" +#include "fpu.h" #include "cpu/idt.h" -#include "drivers/pic.h" static struct boot_info boot_info; @@ -16,6 +17,7 @@ void *amd64_shim(long mboot_magic, volatile void *mboot_data_ptr) { paging_init(); pic_remap(); idt_init(); + fpu_enable(); mboot_load_info(mboot_magic, mboot_data_ptr, &boot_info); diff --git a/src/arch/x86_common/acpi.c b/src/arch/x86_common/acpi.c new file mode 100644 index 0000000..2392185 --- /dev/null +++ b/src/arch/x86_common/acpi.c @@ -0,0 +1,13 @@ +#include + +#define ACPI_INTERNAL +#include + +void acpi_sys_enable(struct acpi_state *state) { + outb(state->fadt->smi_command_port, state->fadt->acpi_enable); +} + +int acpi_sys_shutdown(struct acpi_state *state) { + outw((unsigned int) state->fadt->pm1_a_control_block, state->SLP_TYPb | state->SLP_EN); + return -1; +} diff --git a/src/arch/amd64/drivers/bochs.c b/src/arch/x86_common/drivers/bochs.c similarity index 98% rename from src/arch/amd64/drivers/bochs.c rename to src/arch/x86_common/drivers/bochs.c index b3908f9..8e9ca2b 100644 --- a/src/arch/amd64/drivers/bochs.c +++ b/src/arch/x86_common/drivers/bochs.c @@ -4,8 +4,7 @@ #include #include #include - -#include "../bindings.h" +#include #define INDEX 0x1CE #define DATA 0x1CF diff --git a/src/arch/x86_common/drivers/pci.c b/src/arch/x86_common/drivers/pci.c new file mode 100644 index 0000000..579562a --- /dev/null +++ b/src/arch/x86_common/drivers/pci.c @@ -0,0 +1,57 @@ +#include +#include + +#define PCI_INTERNAL +#include + +#define CONF_ADDR 0xCF8 +#define CONF_DATA 0xCFC + +uint32_t pci_sys_rcfg_d(struct pci_device dev, uint8_t offset) { + uint32_t addr = 0x80000000; + addr |= ((uint32_t)dev.bus) << 16; + addr |= ((uint32_t)dev.device) << 11; + addr |= ((uint32_t)dev.function) << 8; + addr |= offset & 0xFC; + + outl(CONF_ADDR, addr); + uint32_t in = inl(CONF_DATA); + return in; +} + +uint16_t pci_sys_rcfg_w(struct pci_device dev, uint8_t offset) { + uint32_t dword = pci_sys_rcfg_d(dev, offset); + return (uint16_t)((dword >> ((offset & 2) * 8)) & 0xFFFF); +} + +uint8_t pci_sys_rcfg_b(struct pci_device dev, uint8_t offset) { + uint32_t dword = pci_sys_rcfg_d(dev, offset); + return (uint8_t)((dword >> ((offset & 3) * 8)) & 0xFF); +} + +void pci_sys_wcfg_d(struct pci_device dev, uint8_t offset, uint32_t dword) { + uint32_t addr = 0x80000000; + addr |= ((uint32_t)dev.bus) << 16; + addr |= ((uint32_t)dev.device) << 11; + addr |= ((uint32_t)dev.function) << 8; + addr |= offset & 0xFC; + + outl(CONF_ADDR, addr); + outl(CONF_DATA, dword); +} + +void pci_sys_wcfg_w(struct pci_device dev, uint8_t offset, uint16_t word) { + size_t shift = (offset & 2) * 8; + uint32_t dword = pci_sys_rcfg_d(dev, offset); + dword &= ~(0xFFFF << shift); + dword |= word << shift; + pci_sys_wcfg_d(dev, offset, dword); +} + +void pci_sys_wcfg_b(struct pci_device dev, uint8_t offset, uint8_t byte) { + size_t shift = (offset & 3) * 8; + uint32_t dword = pci_sys_rcfg_d(dev, offset); + dword &= ~(0xFF << shift); + dword |= byte << shift; + pci_sys_wcfg_d(dev, offset, dword); +} diff --git a/src/arch/amd64/drivers/pic.c b/src/arch/x86_common/drivers/pic.c similarity index 98% rename from src/arch/amd64/drivers/pic.c rename to src/arch/x86_common/drivers/pic.c index be7716f..d911648 100644 --- a/src/arch/amd64/drivers/pic.c +++ b/src/arch/x86_common/drivers/pic.c @@ -1,5 +1,5 @@ -#include "../bindings.h" -#include "pic.h" +#include +#include #define PIC1 0x20 /* IO base address for master PIC */ #define PIC2 0xA0 /* IO base address for slave PIC */ diff --git a/src/arch/amd64/drivers/serial.c b/src/arch/x86_common/drivers/serial.c similarity index 98% rename from src/arch/amd64/drivers/serial.c rename to src/arch/x86_common/drivers/serial.c index b9e351e..255f8fc 100644 --- a/src/arch/amd64/drivers/serial.c +++ b/src/arch/x86_common/drivers/serial.c @@ -1,6 +1,5 @@ #include - -#include "../bindings.h" +#include #define PORT 0x3F8 diff --git a/src/arch/amd64/bindings.h b/src/arch/x86_common/include/bindings.h similarity index 100% rename from src/arch/amd64/bindings.h rename to src/arch/x86_common/include/bindings.h diff --git a/src/arch/amd64/mboot.h b/src/arch/x86_common/include/mboot.h similarity index 100% rename from src/arch/amd64/mboot.h rename to src/arch/x86_common/include/mboot.h diff --git a/src/arch/amd64/drivers/pic.h b/src/arch/x86_common/include/pic.h similarity index 100% rename from src/arch/amd64/drivers/pic.h rename to src/arch/x86_common/include/pic.h diff --git a/src/arch/amd64/mboot.c b/src/arch/x86_common/mboot.c similarity index 99% rename from src/arch/amd64/mboot.c rename to src/arch/x86_common/mboot.c index 9fd7fc2..db82b9d 100644 --- a/src/arch/amd64/mboot.c +++ b/src/arch/x86_common/mboot.c @@ -2,8 +2,7 @@ #include #include #include - -#include "mboot.h" +#include #define MBOOT_HEADER_MAGIC 0x36D76289 diff --git a/src/arch/amd64/drivers/pci.c b/src/drivers/pci.c similarity index 73% rename from src/arch/amd64/drivers/pci.c rename to src/drivers/pci.c index 7aa11c8..6e87b86 100644 --- a/src/arch/amd64/drivers/pci.c +++ b/src/drivers/pci.c @@ -1,12 +1,9 @@ -#include #include -#include #include +#include -#include "../bindings.h" - -#define CONF_ADDR 0xCF8 -#define CONF_DATA 0xCFC +#define PCI_INTERNAL +#include #define TABLE_LEN 16 @@ -20,58 +17,34 @@ struct pci_table_entry { uint8_t revision; }; -static struct pci_table_entry pci_table[TABLE_LEN]; -static size_t pci_table_next = 0; - uint32_t pci_rcfg_d(struct pci_device dev, uint8_t offset) { - uint32_t addr = 0x80000000; - addr |= ((uint32_t)dev.bus) << 16; - addr |= ((uint32_t)dev.device) << 11; - addr |= ((uint32_t)dev.function) << 8; - addr |= offset & 0xFC; - - outl(CONF_ADDR, addr); - uint32_t in = inl(CONF_DATA); - return in; + return pci_sys_rcfg_d(dev, offset); } uint16_t pci_rcfg_w(struct pci_device dev, uint8_t offset) { - uint32_t dword = pci_rcfg_d(dev, offset); - return (uint16_t)((dword >> ((offset & 2) * 8)) & 0xFFFF); + return pci_sys_rcfg_w(dev, offset); } -uint8_t pci_rcfg_b(struct pci_device dev, uint8_t offset) { - uint32_t dword = pci_rcfg_d(dev, offset); - return (uint8_t)((dword >> ((offset & 3) * 8)) & 0xFF); +uint8_t pci_rcfg_b(struct pci_device dev, uint8_t offset) { + return pci_sys_rcfg_b(dev, offset); } void pci_wcfg_d(struct pci_device dev, uint8_t offset, uint32_t dword) { - uint32_t addr = 0x80000000; - addr |= ((uint32_t)dev.bus) << 16; - addr |= ((uint32_t)dev.device) << 11; - addr |= ((uint32_t)dev.function) << 8; - addr |= offset & 0xFC; - - outl(CONF_ADDR, addr); - outl(CONF_DATA, dword); + pci_sys_wcfg_d(dev, offset, dword); } void pci_wcfg_w(struct pci_device dev, uint8_t offset, uint16_t word) { - size_t shift = (offset & 2) * 8; - uint32_t dword = pci_rcfg_d(dev, offset); - dword &= ~(0xFFFF << shift); - dword |= word << shift; - pci_wcfg_d(dev, offset, dword); + pci_sys_wcfg_w(dev, offset, word); } void pci_wcfg_b(struct pci_device dev, uint8_t offset, uint8_t byte) { - size_t shift = (offset & 3) * 8; - uint32_t dword = pci_rcfg_d(dev, offset); - dword &= ~(0xFF << shift); - dword |= byte << shift; - pci_wcfg_d(dev, offset, dword); + pci_sys_wcfg_b(dev, offset, byte); } +static struct pci_table_entry pci_table[TABLE_LEN]; +static size_t pci_table_next = 0; + + static void print_device(struct pci_table_entry *entry) { kprintf( "BUS: %#-4x DEV: %#-4x FUNC: %#-4x ID: %04x:%04x CLASS: %02x:%02x:%02x REV: %#02x\n", diff --git a/src/kmain.c b/src/kmain.c index b04de49..5621256 100644 --- a/src/kmain.c +++ b/src/kmain.c @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -7,7 +6,6 @@ #include void kmain(struct boot_info *info) { - enable_fpu(); memory_init(&info->map); pci_init(); screen_init(); diff --git a/src/memory/physalloc.c b/src/memory/physalloc.c index 3115e35..ec1cc0d 100644 --- a/src/memory/physalloc.c +++ b/src/memory/physalloc.c @@ -4,8 +4,8 @@ #include #define MEMORY_INTERNAL -#include -#include +#include +#include extern char kernel_start; extern char kernel_end; diff --git a/src/memory/virtalloc.c b/src/memory/virtalloc.c index b5cc126..c9c6dbf 100644 --- a/src/memory/virtalloc.c +++ b/src/memory/virtalloc.c @@ -6,7 +6,7 @@ #include #define MEMORY_INTERNAL -#include +#include struct addr_node { uintptr_t start;