diff --git a/Disk/ATA/ATA.cpp b/Disk/ATA/ATA.cpp new file mode 100644 index 00000000..f26a3a55 --- /dev/null +++ b/Disk/ATA/ATA.cpp @@ -0,0 +1,82 @@ +#include +#include +#include + +#include "../../../Kernel/DAPI.hpp" +#include "../../../Kernel/Fex.hpp" + +extern "C" int DriverEntry(void *Data); +int CallbackHandler(KernelCallback *Data); + +HEAD(FexFormatType_Driver, FexOSType_Fennix, DriverEntry); + +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" + +__attribute__((section(".extended"))) FexExtended ExtendedHeader = { + .Driver = { + .Name = "ATA", + .Type = FexDriverType_Storage, + .Callback = CallbackHandler, + .Bind = { + .Type = BIND_INTERRUPT, + .Interrupt = { + .Vector = {0xE, 0xF}, // IRQ14, IRQ15 + }}}}; + +KernelAPI *KAPI; + +/* --------------------------------------------------------------------------------------------------------- */ + +int DriverEntry(void *Data) +{ + if (!Data) + return INVALID_KERNEL_API; + KAPI = (KernelAPI *)Data; + if (KAPI->Version.Major < 0 || KAPI->Version.Minor < 0 || KAPI->Version.Patch < 0) + return KERNEL_API_VERSION_NOT_SUPPORTED; + return OK; +} + +int CallbackHandler(KernelCallback *Data) +{ + switch (Data->Reason) + { + case AcknowledgeReason: + { + KAPI->Util.DebugPrint(((char *)"Kernel acknowledged the driver." + KAPI->Info.Offset), KAPI->Info.DriverUID); + break; + } + case ConfigurationReason: + { + KAPI->Util.DebugPrint(((char *)"Kernel received configuration data." + KAPI->Info.Offset), KAPI->Info.DriverUID); + break; + } + case FetchReason: + { + break; + } + case InterruptReason: + { + if (Data->InterruptInfo.Vector == 0xE) + { + KAPI->Util.DebugPrint(((char *)"IRQ14" + KAPI->Info.Offset), KAPI->Info.DriverUID); + } + else if (Data->InterruptInfo.Vector == 0xF) + { + KAPI->Util.DebugPrint(((char *)"IRQ15" + KAPI->Info.Offset), KAPI->Info.DriverUID); + } + break; + } + case SendReason: + case ReceiveReason: + { + break; + } + default: + { + KAPI->Util.DebugPrint(((char *)"Unknown reason." + KAPI->Info.Offset), KAPI->Info.DriverUID); + break; + } + } + return OK; +} diff --git a/Disk/ATA/Makefile b/Disk/ATA/Makefile new file mode 100644 index 00000000..0c668bb8 --- /dev/null +++ b/Disk/ATA/Makefile @@ -0,0 +1,100 @@ +# Config file +include ../../../Makefile.conf + +FILENAME = ata.fex + +CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc +CPP = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ +LD = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ld +AS = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)as +OBJDUMP = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)objdump + +GIT_COMMIT = $(shell git rev-parse HEAD) +GIT_COMMIT_SHORT = $(shell git rev-parse --short HEAD) + +ifeq ($(OSARCH), amd64) +S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/i686/*" -not -path "./arch/aarch64/*") +C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/i686/*" -not -path "./arch/aarch64/*") +CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/i686/*" -not -path "./arch/aarch64/*") +else ifeq ($(OSARCH), i686) +S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*") +C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*") +CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*") +else ifeq ($(OSARCH), aarch64) +S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/i686/*") +C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/i686/*") +CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/i686/*") +endif +HEADERS = $(sort $(dir $(wildcard ../../include/*))) +OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURCES:.S=.o) $(PSF_SOURCES:.psf=.o) $(BMP_SOURCES:.bmp=.o) +INCLUDE_DIR = ../../include + +LDFLAGS := \ + -fPIC -fno-pie \ + -Wl,-static,--no-dynamic-linker,-ztext \ + -nostdlib -nodefaultlibs -nolibc \ + -zmax-page-size=0x1000 \ + -Wl,-Map file.map -shared + +WARNCFLAG = -Wall -Wextra + +CFLAGS := \ + -I$(INCLUDE_DIR) \ + -DGIT_COMMIT='"$(GIT_COMMIT)"' \ + -DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"' + +ifeq ($(OSARCH), amd64) + +CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ + -mno-red-zone -mno-sse -mno-sse2 \ + -march=x86-64 -pipe -ffunction-sections \ + -mcmodel=kernel -msoft-float -fno-builtin +LDFLAGS += -Tarch/amd64/linker.ld + +else ifeq ($(OSARCH), i686) + +CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ + -mno-red-zone -mno-sse -mno-sse2 -ffunction-sections \ + -march=i686 -pipe -msoft-float -fno-builtin +LDFLAGS += -Tarch/i686/linker.ld + +else ifeq ($(OSARCH), aarch64) + +CFLAGS += -pipe -fno-builtin -fPIC +LDFLAGS += -Tarch/aarch64/linker.ld + +endif + +build: $(FILENAME) +ifeq ($(OSARCH), amd64) + $(OBJDUMP) -b binary -D -m i386:x86-64 -d $(FILENAME) > file_dump.map +else ifeq ($(OSARCH), i686) + +else ifeq ($(OSARCH), aarch64) + +endif + mv $(FILENAME) ../../out/$(FILENAME) + +$(FILENAME): $(OBJ) + $(CC) $(LDFLAGS) $(OBJ) -o $@ + +%.o: %.c $(HEADERS) + $(info Compiling $<) + $(CC) $(CFLAGS) $(WARNCFLAG) -std=c17 -c $< -o $@ + +%.o: %.cpp $(HEADERS) + $(info Compiling $<) + $(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -fexceptions -c $< -o $@ -fno-rtti + +%.o: %.S + $(info Compiling $<) +ifeq ($(OSARCH), amd64) + $(AS) -o $@ $< +else ifeq ($(OSARCH), i686) + $(AS) -o $@ $< +else ifeq ($(OSARCH), aarch64) + $(AS) -o $@ $< +endif + +clean: + rm -f *.o file.map file_dump.map $(OBJ) diff --git a/Disk/ATA/arch/amd64/linker.ld b/Disk/ATA/arch/amd64/linker.ld new file mode 100644 index 00000000..511369e8 --- /dev/null +++ b/Disk/ATA/arch/amd64/linker.ld @@ -0,0 +1,42 @@ +/* EXPERIMENTAL */ + +OUTPUT_FORMAT(binary) +OUTPUT_ARCH(i386:x86-64) + +ENTRY(DriverEntry) + +SECTIONS +{ + .header : + { + *(.header .header.*) + *(.extended .extended.*) + } + + .text : + { + *(.text .text.*) + } + + .data : + { + *(.data .data.*) + } + + .rodata : + { + *(.rodata .rodata.*) + } + + .bss : + { + *(COMMON) + *(.bss .bss.*) + } + + /DISCARD/ : + { + *(.eh_frame) + *(.note .note.*) + } +}