diff --git a/Disk/AHCI/AHCI.cpp b/Disk/AHCI/AHCI.cpp index f58abe3..75e06e0 100644 --- a/Disk/AHCI/AHCI.cpp +++ b/Disk/AHCI/AHCI.cpp @@ -29,6 +29,8 @@ __attribute__((section(".extended"))) FexExtended ExtendedHeader = { KernelAPI *KAPI; +#define print(msg) KAPI->Util.DebugPrint((char *)(msg), KAPI->Info.DriverUID) + /* --------------------------------------------------------------------------------------------------------- */ #define ATA_DEV_BUSY 0x80 @@ -190,9 +192,11 @@ typedef enum _URC_CONTINUE_UNWIND = 8 } _Unwind_Reason_Code; +struct _Unwind_Context; typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__))); typedef unsigned _Unwind_Word __attribute__((__mode__(__unwind_word__))); typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code, struct _Unwind_Exception *); +typedef int _Unwind_Action; struct _Unwind_Exception { @@ -206,7 +210,13 @@ struct _Unwind_Exception #endif } __attribute__((__aligned__)); -extern "C" void _Unwind_Resume(_Unwind_Exception *) { KAPI->Util.DebugPrint(((char *)"_Unwind_Resume" + KAPI->Info.Offset), KAPI->Info.DriverUID); } +extern "C" _Unwind_Reason_Code __gxx_personality_v0(int, _Unwind_Action, _Unwind_Exception_Class, _Unwind_Exception *, _Unwind_Context *) +{ + print("__gxx_personality_v0"); + return _URC_NO_REASON; +} + +extern "C" void _Unwind_Resume(_Unwind_Exception *) { print("_Unwind_Resume"); } void *operator new(size_t Size) { return KAPI->Memory.RequestPage(Size / KAPI->Memory.PageSize + 1); } void operator delete(void *Ptr) { KAPI->Memory.FreePage(Ptr, 1); } // Potential memory leak @@ -284,7 +294,7 @@ public: if (this->PortNumber == PortType::SATAPI && Write) { // err("SATAPI port does not support write."); - KAPI->Util.DebugPrint(((char *)"SATAPI port does not support write." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("SATAPI port does not support write."); return false; } @@ -336,7 +346,7 @@ public: if (Spin == 1000000) { // err("Port not responding."); - KAPI->Util.DebugPrint(((char *)"Port not responding." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Port not responding."); return false; } @@ -350,7 +360,7 @@ public: if (Spin > 100000000) { // err("Port %d not responding. (%d)", this->PortNumber, TryCount); - KAPI->Util.DebugPrint(((char *)"Port not responding." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Port not responding."); Spin = 0; TryCount++; if (TryCount > 10) @@ -362,7 +372,7 @@ public: if (HBAPortPtr->InterruptStatus & HBA_PxIS_TFES) { // err("Error reading/writing (%d).", Write); - KAPI->Util.DebugPrint(((char *)"Error reading/writing." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Error reading/writing."); return false; } } @@ -425,12 +435,12 @@ int CallbackHandler(KernelCallback *Data) { case AcknowledgeReason: { - KAPI->Util.DebugPrint(((char *)"Kernel acknowledged the driver." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel acknowledged the driver."); break; } case ConfigurationReason: { - KAPI->Util.DebugPrint(((char *)"Kernel received configuration data." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel received configuration data."); PCIBaseAddress = reinterpret_cast(Data->RawPtr); ABAR = reinterpret_cast(((PCIHeader0 *)PCIBaseAddress)->BAR5); KAPI->Memory.Map((void *)ABAR, (void *)ABAR, (1 << 1)); @@ -444,14 +454,14 @@ int CallbackHandler(KernelCallback *Data) if (portType == PortType::SATA || portType == PortType::SATAPI) { // trace("%s drive found at port %d", PortTypeName[portType], i); - KAPI->Util.DebugPrint(((char *)"SATA drive found." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("SATA drive found."); Ports[PortCount] = new Port(portType, &ABAR->Ports[i], PortCount); PortCount++; } else { if (portType != PortType::None) - KAPI->Util.DebugPrint(((char *)"Unsupported port type found." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Unsupported port type found."); // warn("Unsupported drive type %s found at port %d", PortTypeName[portType], i); } } @@ -467,6 +477,12 @@ int CallbackHandler(KernelCallback *Data) Data->DiskCallback.Fetch.BytesPerSector = 512; break; } + case StopReason: + { + // TODO: Stop the driver. + print("Driver stopped."); + break; + } case SendReason: case ReceiveReason: { @@ -478,7 +494,7 @@ int CallbackHandler(KernelCallback *Data) } default: { - KAPI->Util.DebugPrint(((char *)"Unknown reason." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Unknown reason."); break; } } diff --git a/Disk/AHCI/Makefile b/Disk/AHCI/Makefile index 48cf01d..9b449dd 100644 --- a/Disk/AHCI/Makefile +++ b/Disk/AHCI/Makefile @@ -29,12 +29,12 @@ 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 +LDFLAGS := \ + -fPIC -fPIE -pie -Wl,-eDriverEntry \ + -Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment \ + -nostdlib -nodefaultlibs -nolibc \ + -zmax-page-size=0x1000 \ + -Wl,-Map file.map -static -Tlinker.ld WARNCFLAG = -Wall -Wextra @@ -45,23 +45,20 @@ CFLAGS := \ 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 +CFLAGS += -fPIC -fPIE -pie -mno-80387 -mno-mmx -mno-3dnow \ + -mno-red-zone -mno-sse -mno-sse2 \ + -march=x86-64 -pipe -ffunction-sections \ + -msoft-float -fno-builtin else ifeq ($(OSARCH), i686) -CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ +CFLAGS += -fPIC -fPIE -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 diff --git a/Generic/ExampleDriver/arch/amd64/linker.ld b/Disk/AHCI/linker.ld similarity index 100% rename from Generic/ExampleDriver/arch/amd64/linker.ld rename to Disk/AHCI/linker.ld diff --git a/Disk/ATA/ATA.cpp b/Disk/ATA/ATA.cpp index f26a3a5..27a01a8 100644 --- a/Disk/ATA/ATA.cpp +++ b/Disk/ATA/ATA.cpp @@ -25,6 +25,8 @@ __attribute__((section(".extended"))) FexExtended ExtendedHeader = { KernelAPI *KAPI; +#define print(msg) KAPI->Util.DebugPrint((char *)(msg), KAPI->Info.DriverUID) + /* --------------------------------------------------------------------------------------------------------- */ int DriverEntry(void *Data) @@ -43,12 +45,12 @@ int CallbackHandler(KernelCallback *Data) { case AcknowledgeReason: { - KAPI->Util.DebugPrint(((char *)"Kernel acknowledged the driver." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel acknowledged the driver."); break; } case ConfigurationReason: { - KAPI->Util.DebugPrint(((char *)"Kernel received configuration data." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel received configuration data."); break; } case FetchReason: @@ -59,11 +61,11 @@ int CallbackHandler(KernelCallback *Data) { if (Data->InterruptInfo.Vector == 0xE) { - KAPI->Util.DebugPrint(((char *)"IRQ14" + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("IRQ14"); } else if (Data->InterruptInfo.Vector == 0xF) { - KAPI->Util.DebugPrint(((char *)"IRQ15" + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("IRQ15"); } break; } @@ -72,9 +74,15 @@ int CallbackHandler(KernelCallback *Data) { break; } + case StopReason: + { + // TODO: Stop the driver. + print("Driver stopped."); + break; + } default: { - KAPI->Util.DebugPrint(((char *)"Unknown reason." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Unknown reason."); break; } } diff --git a/Disk/ATA/Makefile b/Disk/ATA/Makefile index 0c668bb..cb538fc 100644 --- a/Disk/ATA/Makefile +++ b/Disk/ATA/Makefile @@ -29,12 +29,12 @@ 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 +LDFLAGS := \ + -fPIC -fPIE -pie -Wl,-eDriverEntry \ + -Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment \ + -nostdlib -nodefaultlibs -nolibc \ + -zmax-page-size=0x1000 \ + -Wl,-Map file.map -static -Tlinker.ld WARNCFLAG = -Wall -Wextra @@ -45,23 +45,20 @@ CFLAGS := \ 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 +CFLAGS += -fPIC -fPIE -pie -mno-80387 -mno-mmx -mno-3dnow \ + -mno-red-zone -mno-sse -mno-sse2 \ + -march=x86-64 -pipe -ffunction-sections \ + -msoft-float -fno-builtin else ifeq ($(OSARCH), i686) -CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ - -mno-red-zone -mno-sse -mno-sse2 -ffunction-sections \ +CFLAGS += -fPIC -fPIE -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 diff --git a/Disk/AHCI/arch/amd64/linker.ld b/Disk/ATA/linker.ld similarity index 95% rename from Disk/AHCI/arch/amd64/linker.ld rename to Disk/ATA/linker.ld index 511369e..29cd11c 100644 --- a/Disk/AHCI/arch/amd64/linker.ld +++ b/Disk/ATA/linker.ld @@ -1,5 +1,3 @@ -/* EXPERIMENTAL */ - OUTPUT_FORMAT(binary) OUTPUT_ARCH(i386:x86-64) diff --git a/Generic/ExampleDriver/Example.cpp b/Generic/ExampleDriver/Example.cpp index 2527e52..f2cb0e6 100644 --- a/Generic/ExampleDriver/Example.cpp +++ b/Generic/ExampleDriver/Example.cpp @@ -27,6 +27,9 @@ __attribute__((section(".extended"))) FexExtended ExtendedHeader = { // Global variable that holds the kernel API KernelAPI *KAPI; +// Macro that prints a message to UART +#define print(msg) KAPI->Util.DebugPrint((char *)(msg), KAPI->Info.DriverUID) + /* --------------------------------------------------------------------------------------------------------- */ // Driver entry point. This is called at initialization. "Data" argument points to the kernel API structure. @@ -44,7 +47,7 @@ int DriverEntry(void *Data) return KERNEL_API_VERSION_NOT_SUPPORTED; // We print "Hello World!" to UART. - KAPI->Util.DebugPrint(((char *)"Hello World!" + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Hello World!"); return OK; } @@ -55,17 +58,22 @@ int CallbackHandler(KernelCallback *Data) { case AcknowledgeReason: { - KAPI->Util.DebugPrint(((char *)"Kernel acknowledged the driver." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel acknowledged the driver."); break; } case InterruptReason: { - KAPI->Util.DebugPrint(((char *)"Interrupt received." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Interrupt received."); + break; + } + case StopReason: + { + print("Driver stopped."); break; } default: { - KAPI->Util.DebugPrint(((char *)"Unknown reason." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Unknown reason."); break; } } diff --git a/Generic/ExampleDriver/Makefile b/Generic/ExampleDriver/Makefile index bd2e99b..79b4593 100644 --- a/Generic/ExampleDriver/Makefile +++ b/Generic/ExampleDriver/Makefile @@ -29,12 +29,12 @@ 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 +LDFLAGS := \ + -fPIC -fPIE -pie -Wl,-eDriverEntry \ + -Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment \ + -nostdlib -nodefaultlibs -nolibc \ + -zmax-page-size=0x1000 \ + -Wl,-Map file.map -static -Tlinker.ld WARNCFLAG = -Wall -Wextra @@ -45,23 +45,20 @@ CFLAGS := \ 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 +CFLAGS += -fPIC -fPIE -pie -mno-80387 -mno-mmx -mno-3dnow \ + -mno-red-zone -mno-sse -mno-sse2 \ + -march=x86-64 -pipe -ffunction-sections \ + -msoft-float -fno-builtin else ifeq ($(OSARCH), i686) -CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ +CFLAGS += -fPIC -fPIE -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 @@ -88,13 +85,7 @@ $(FILENAME): $(OBJ) %.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/Generic/ExampleDriver/linker.ld similarity index 95% rename from Disk/ATA/arch/amd64/linker.ld rename to Generic/ExampleDriver/linker.ld index 511369e..29cd11c 100644 --- a/Disk/ATA/arch/amd64/linker.ld +++ b/Generic/ExampleDriver/linker.ld @@ -1,5 +1,3 @@ -/* EXPERIMENTAL */ - OUTPUT_FORMAT(binary) OUTPUT_ARCH(i386:x86-64) diff --git a/Input/VMwareMouse/Makefile b/Input/VMwareMouse/Makefile index 7476487..c50a950 100644 --- a/Input/VMwareMouse/Makefile +++ b/Input/VMwareMouse/Makefile @@ -1,7 +1,7 @@ # Config file include ../../../Makefile.conf -FILENAME = VMwareGuestDriver.fex +FILENAME = VMwareMouseDriver.fex CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc CPP = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ @@ -29,12 +29,12 @@ 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 +LDFLAGS := \ + -fPIC -fPIE -pie -Wl,-eDriverEntry \ + -Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment \ + -nostdlib -nodefaultlibs -nolibc \ + -zmax-page-size=0x1000 \ + -Wl,-Map file.map -static -Tlinker.ld WARNCFLAG = -Wall -Wextra @@ -45,23 +45,20 @@ CFLAGS := \ 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 +CFLAGS += -fPIC -fPIE -pie -mno-80387 -mno-mmx -mno-3dnow \ + -mno-red-zone -mno-sse -mno-sse2 \ + -march=x86-64 -pipe -ffunction-sections \ + -msoft-float -fno-builtin else ifeq ($(OSARCH), i686) -CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ +CFLAGS += -fPIC -fPIE -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 diff --git a/Input/VMwareMouse/arch/amd64/linker.ld b/Input/VMwareMouse/linker.ld similarity index 95% rename from Input/VMwareMouse/arch/amd64/linker.ld rename to Input/VMwareMouse/linker.ld index 511369e..29cd11c 100644 --- a/Input/VMwareMouse/arch/amd64/linker.ld +++ b/Input/VMwareMouse/linker.ld @@ -1,5 +1,3 @@ -/* EXPERIMENTAL */ - OUTPUT_FORMAT(binary) OUTPUT_ARCH(i386:x86-64) diff --git a/Input/VMwareMouse/vmware_mouse.cpp b/Input/VMwareMouse/vmware_mouse.cpp index 2cb45aa..63a9bfe 100644 --- a/Input/VMwareMouse/vmware_mouse.cpp +++ b/Input/VMwareMouse/vmware_mouse.cpp @@ -24,6 +24,8 @@ __attribute__((section(".extended"))) FexExtended ExtendedHeader = { KernelAPI *KAPI; +#define print(msg) KAPI->Util.DebugPrint((char *)(msg), KAPI->Info.DriverUID) + /* --------------------------------------------------------------------------------------------------------- */ /* https://wiki.osdev.org/VMware_tools */ @@ -189,7 +191,7 @@ int CallbackHandler(KernelCallback *Data) { case AcknowledgeReason: { - KAPI->Util.DebugPrint(((char *)"Kernel acknowledged the driver." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel acknowledged the driver."); break; } case ConfigurationReason: @@ -207,7 +209,33 @@ int CallbackHandler(KernelCallback *Data) Write(DATA, 0xF4); Read(); Absolute(); - KAPI->Util.DebugPrint(((char *)"VMware mouse configured." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("VMware mouse configured."); + break; + } + case FetchReason: + { + Data->InputCallback.Mouse.X = MouseX; + Data->InputCallback.Mouse.Y = MouseY; + Data->InputCallback.Mouse.Z = MouseZ; + Data->InputCallback.Mouse.Buttons.Left = MouseButton & 0x20; + Data->InputCallback.Mouse.Buttons.Right = MouseButton & 0x10; + Data->InputCallback.Mouse.Buttons.Middle = MouseButton & 0x08; + break; + } + case StopReason: + { + Relative(); + // TODO: UNTESTED!!! + outb(COMMAND, 0xA8); + Write(COMMAND, READ_CONFIG); + uint8_t Status = Read(); + Status &= ~0b10; + Write(COMMAND, WRITE_CONFIG); + Write(DATA, Status); + Write(COMMAND, 0xD4); + Write(DATA, 0xF5); + Read(); + print("Driver stopped."); break; } case InterruptReason: @@ -221,7 +249,7 @@ int CallbackHandler(KernelCallback *Data) if (cmd.ax == 0xFFFF0000) { - KAPI->Util.DebugPrint(((char *)"VMware mouse is not connected?" + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("VMware mouse is not connected?"); Relative(); Absolute(); return ERROR; @@ -235,25 +263,16 @@ int CallbackHandler(KernelCallback *Data) int flags = (cmd.ax & 0xFFFF0000) >> 16; /* Not important */ (void)flags; - MouseButton = (cmd.ax & 0xFFFF); /* 0x10 = Right, 0x20 = Left, 0x08 = Middle */ - MouseX = cmd.bx; /* Both X and Y are scaled from 0 to 0xFFFF */ - MouseY = cmd.cx; /* You should map these somewhere to the actual resolution. */ - MouseZ = (int8_t)cmd.dx; /* Z is a single signed byte indicating scroll direction. */ - break; - } - case FetchReason: - { - Data->InputCallback.Mouse.X = MouseX; - Data->InputCallback.Mouse.Y = MouseY; - Data->InputCallback.Mouse.Z = MouseZ; - Data->InputCallback.Mouse.Buttons.Left = MouseButton & 0x20; - Data->InputCallback.Mouse.Buttons.Right = MouseButton & 0x10; - Data->InputCallback.Mouse.Buttons.Middle = MouseButton & 0x08; + MouseButton = (cmd.ax & 0xFFFF); /* 0x10 = Right, 0x20 = Left, 0x08 = Middle */ + MouseX = cmd.bx; /* Both X and Y are scaled from 0 to 0xFFFF */ + MouseY = cmd.cx; /* You should map these somewhere to the actual resolution. */ + MouseZ = (int8_t)cmd.dx; /* Z is a single signed byte indicating scroll direction. */ break; } + default: { - KAPI->Util.DebugPrint(((char *)"Unknown reason." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Unknown reason."); break; } } diff --git a/Network/AMDPCNET/Makefile b/Network/AMDPCNET/Makefile index 3cfe77d..721e4d7 100644 --- a/Network/AMDPCNET/Makefile +++ b/Network/AMDPCNET/Makefile @@ -1,7 +1,7 @@ # Config file include ../../../Makefile.conf -FILENAME = amd_pcnet.fex +FILENAME = AMD-PCNET.fex CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc CPP = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ @@ -29,12 +29,12 @@ 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 +LDFLAGS := \ + -fPIC -fPIE -pie -Wl,-eDriverEntry \ + -Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment \ + -nostdlib -nodefaultlibs -nolibc \ + -zmax-page-size=0x1000 \ + -Wl,-Map file.map -static -Tlinker.ld WARNCFLAG = -Wall -Wextra @@ -45,23 +45,20 @@ CFLAGS := \ 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 +CFLAGS += -fPIC -fPIE -pie -mno-80387 -mno-mmx -mno-3dnow \ + -mno-red-zone -mno-sse -mno-sse2 \ + -march=x86-64 -pipe -ffunction-sections \ + -msoft-float -fno-builtin else ifeq ($(OSARCH), i686) -CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ +CFLAGS += -fPIC -fPIE -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 diff --git a/Network/AMDPCNET/arch/amd64/linker.ld b/Network/AMDPCNET/linker.ld similarity index 95% rename from Network/AMDPCNET/arch/amd64/linker.ld rename to Network/AMDPCNET/linker.ld index 511369e..29cd11c 100644 --- a/Network/AMDPCNET/arch/amd64/linker.ld +++ b/Network/AMDPCNET/linker.ld @@ -1,5 +1,3 @@ -/* EXPERIMENTAL */ - OUTPUT_FORMAT(binary) OUTPUT_ARCH(i386:x86-64) diff --git a/Network/AMDPCNET/pcnet.cpp b/Network/AMDPCNET/pcnet.cpp index 4f0f823..39a8eae 100644 --- a/Network/AMDPCNET/pcnet.cpp +++ b/Network/AMDPCNET/pcnet.cpp @@ -29,6 +29,8 @@ __attribute__((section(".extended"))) FexExtended ExtendedHeader = { KernelAPI *KAPI; +#define print(msg) KAPI->Util.DebugPrint((char *)(msg), KAPI->Info.DriverUID) + /* --------------------------------------------------------------------------------------------------------- */ struct BARData @@ -87,16 +89,16 @@ int CallbackHandler(KernelCallback *Data) { case AcknowledgeReason: { - KAPI->Util.DebugPrint(((char *)"Kernel acknowledged the driver." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel acknowledged the driver."); break; } case ConfigurationReason: { - KAPI->Util.DebugPrint(((char *)"Kernel received configuration data." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel received configuration data."); PCIBaseAddress = reinterpret_cast(Data->RawPtr); if (PCIBaseAddress->VendorID == 0x1022 && PCIBaseAddress->DeviceID == 0x2000) { - KAPI->Util.DebugPrint(((char *)"Found AMD PCNET." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Found AMD PCNET."); uint32_t PCIBAR = ((PCIHeader0 *)PCIBaseAddress)->BAR0; BAR.Type = PCIBAR & 1; BAR.IOBase = PCIBAR & (~3); @@ -112,10 +114,17 @@ int CallbackHandler(KernelCallback *Data) } case SendReason: { + break; + } + case StopReason: + { + // TODO: Stop the driver. + print("Driver stopped."); + break; } default: { - KAPI->Util.DebugPrint(((char *)"Unknown reason." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Unknown reason."); break; } } diff --git a/Network/E1000/Makefile b/Network/E1000/Makefile index b42225d..ea0fa76 100644 --- a/Network/E1000/Makefile +++ b/Network/E1000/Makefile @@ -1,7 +1,7 @@ # Config file include ../../../Makefile.conf -FILENAME = e1000.fex +FILENAME = E1000.fex CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc CPP = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ @@ -29,12 +29,12 @@ 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 +LDFLAGS := \ + -fPIC -fPIE -pie -Wl,-eDriverEntry \ + -Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment \ + -nostdlib -nodefaultlibs -nolibc \ + -zmax-page-size=0x1000 \ + -Wl,-Map file.map -static -Tlinker.ld WARNCFLAG = -Wall -Wextra @@ -45,23 +45,20 @@ CFLAGS := \ 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 +CFLAGS += -fPIC -fPIE -pie -mno-80387 -mno-mmx -mno-3dnow \ + -mno-red-zone -mno-sse -mno-sse2 \ + -march=x86-64 -pipe -ffunction-sections \ + -msoft-float -fno-builtin else ifeq ($(OSARCH), i686) -CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ +CFLAGS += -fPIC -fPIE -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 diff --git a/Network/E1000/arch/amd64/linker.ld b/Network/E1000/arch/amd64/linker.ld deleted file mode 100644 index 511369e..0000000 --- a/Network/E1000/arch/amd64/linker.ld +++ /dev/null @@ -1,42 +0,0 @@ -/* 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.*) - } -} diff --git a/Network/E1000/e1000.cpp b/Network/E1000/e1000.cpp index e156914..ba61bb8 100644 --- a/Network/E1000/e1000.cpp +++ b/Network/E1000/e1000.cpp @@ -29,6 +29,8 @@ __attribute__((section(".extended"))) FexExtended ExtendedHeader = { KernelAPI *KAPI; +#define print(msg) KAPI->Util.DebugPrint((char *)(msg), KAPI->Info.DriverUID) + /* --------------------------------------------------------------------------------------------------------- */ enum REG @@ -242,7 +244,7 @@ MediaAccessControl GetMAC() mac.Address[i] = BaseMac8[i]; else { - KAPI->Util.DebugPrint(((char *)"No MAC address found." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("No MAC address found."); return MediaAccessControl(); } } @@ -251,6 +253,7 @@ MediaAccessControl GetMAC() void InitializeRX() { + print("Initializing RX..."); uint8_t *Ptr = (uint8_t *)KAPI->Memory.RequestPage((((sizeof(RXDescriptor) * E1000_NUM_RX_DESC + 16)) / KAPI->Memory.PageSize) + 1); RXDescriptor *Descriptor = (RXDescriptor *)Ptr; @@ -277,6 +280,7 @@ void InitializeRX() void InitializeTX() { + print("Initializing TX..."); uint8_t *Ptr = (uint8_t *)KAPI->Memory.RequestPage(((sizeof(TXDescriptor) * E1000_NUM_RX_DESC + 16) / KAPI->Memory.PageSize) + 1); TXDescriptor *Descriptor = (TXDescriptor *)Ptr; @@ -318,16 +322,16 @@ int CallbackHandler(KernelCallback *Data) { case AcknowledgeReason: { - KAPI->Util.DebugPrint(((char *)"Kernel acknowledged the driver." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel acknowledged the driver."); break; } case ConfigurationReason: { - KAPI->Util.DebugPrint(((char *)"Kernel received configuration data." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel received configuration data."); PCIBaseAddress = reinterpret_cast(Data->RawPtr); if (PCIBaseAddress->VendorID == 0x8086 && PCIBaseAddress->DeviceID == 0x100E) { - KAPI->Util.DebugPrint(((char *)"Found Intel 82540EM Gigabit Ethernet Controller." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Found Intel 82540EM Gigabit Ethernet Controller."); PCIBaseAddress->Command |= PCI_COMMAND_MASTER | PCI_COMMAND_IO | PCI_COMMAND_MEMORY; uint32_t PCIBAR0 = ((PCIHeader0 *)PCIBaseAddress)->BAR0; @@ -349,7 +353,7 @@ int CallbackHandler(KernelCallback *Data) if (!GetMAC().Valid()) return NOT_AVAILABLE; else - KAPI->Util.DebugPrint(((char *)"MAC address found." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("MAC address found."); MAC = GetMAC(); // Start link @@ -368,12 +372,12 @@ int CallbackHandler(KernelCallback *Data) } else if (PCIBaseAddress->VendorID == 0x8086 && PCIBaseAddress->DeviceID == 0x153A) { - KAPI->Util.DebugPrint(((char *)"Found Intel I217 Gigabit Ethernet Controller." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Found Intel I217 Gigabit Ethernet Controller."); return NOT_IMPLEMENTED; } else if (PCIBaseAddress->VendorID == 0x8086 && PCIBaseAddress->DeviceID == 0x10EA) { - KAPI->Util.DebugPrint(((char *)"Found Intel 82577LM Gigabit Ethernet Controller." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Found Intel 82577LM Gigabit Ethernet Controller."); return NOT_IMPLEMENTED; } else @@ -411,9 +415,17 @@ int CallbackHandler(KernelCallback *Data) ; break; } + case StopReason: + { + // TODO: UNTESTED!!! + uint64_t cmdret = InCMD(REG::CTRL); + OutCMD(REG::CTRL, cmdret & ~ECTRL::SLU); + print("Driver stopped."); + break; + } default: { - KAPI->Util.DebugPrint(((char *)"Unknown reason." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Unknown reason."); break; } } diff --git a/Network/E1000/linker.ld b/Network/E1000/linker.ld new file mode 100644 index 0000000..29cd11c --- /dev/null +++ b/Network/E1000/linker.ld @@ -0,0 +1,40 @@ +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.*) + } +} diff --git a/Network/RTL8139/Makefile b/Network/RTL8139/Makefile index 5c37a4c..7751db3 100644 --- a/Network/RTL8139/Makefile +++ b/Network/RTL8139/Makefile @@ -1,7 +1,7 @@ # Config file include ../../../Makefile.conf -FILENAME = rtl8139.fex +FILENAME = Realtek-8139.fex CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc CPP = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ @@ -29,12 +29,12 @@ 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 +LDFLAGS := \ + -fPIC -fPIE -pie -Wl,-eDriverEntry \ + -Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment \ + -nostdlib -nodefaultlibs -nolibc \ + -zmax-page-size=0x1000 \ + -Wl,-Map file.map -static -Tlinker.ld WARNCFLAG = -Wall -Wextra @@ -45,23 +45,20 @@ CFLAGS := \ 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 +CFLAGS += -fPIC -fPIE -pie -mno-80387 -mno-mmx -mno-3dnow \ + -mno-red-zone -mno-sse -mno-sse2 \ + -march=x86-64 -pipe -ffunction-sections \ + -msoft-float -fno-builtin else ifeq ($(OSARCH), i686) -CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ +CFLAGS += -fPIC -fPIE -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 diff --git a/Network/RTL8139/arch/amd64/linker.ld b/Network/RTL8139/arch/amd64/linker.ld deleted file mode 100644 index 511369e..0000000 --- a/Network/RTL8139/arch/amd64/linker.ld +++ /dev/null @@ -1,42 +0,0 @@ -/* 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.*) - } -} diff --git a/Network/RTL8139/linker.ld b/Network/RTL8139/linker.ld new file mode 100644 index 0000000..29cd11c --- /dev/null +++ b/Network/RTL8139/linker.ld @@ -0,0 +1,40 @@ +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.*) + } +} diff --git a/Network/RTL8139/rtl8139.cpp b/Network/RTL8139/rtl8139.cpp index 55ba787..02914b9 100644 --- a/Network/RTL8139/rtl8139.cpp +++ b/Network/RTL8139/rtl8139.cpp @@ -29,6 +29,8 @@ __attribute__((section(".extended"))) FexExtended ExtendedHeader = { KernelAPI *KAPI; +#define print(msg) KAPI->Util.DebugPrint((char *)(msg), KAPI->Info.DriverUID) + /* --------------------------------------------------------------------------------------------------------- */ struct BARData @@ -129,16 +131,16 @@ int CallbackHandler(KernelCallback *Data) { case AcknowledgeReason: { - KAPI->Util.DebugPrint(((char *)"Kernel acknowledged the driver." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel acknowledged the driver."); break; } case ConfigurationReason: { - KAPI->Util.DebugPrint(((char *)"Kernel received configuration data." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel received configuration data."); PCIBaseAddress = reinterpret_cast(Data->RawPtr); if (PCIBaseAddress->VendorID == 0x10EC && PCIBaseAddress->DeviceID == 0x8139) { - KAPI->Util.DebugPrint(((char *)"Found RTL-8139." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Found RTL-8139."); PCIBaseAddress->Command |= PCI_COMMAND_MASTER | PCI_COMMAND_IO | PCI_COMMAND_MEMORY; uint32_t PCIBAR0 = ((PCIHeader0 *)PCIBaseAddress)->BAR0; @@ -190,9 +192,15 @@ int CallbackHandler(KernelCallback *Data) TXCurrent = 0; break; } + case StopReason: + { + // TODO: Stop the driver. + print("Driver stopped."); + break; + } default: { - KAPI->Util.DebugPrint(((char *)"Unknown reason." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Unknown reason."); break; } } diff --git a/Network/RTL8169/Makefile b/Network/RTL8169/Makefile index c991bea..d00ba27 100644 --- a/Network/RTL8169/Makefile +++ b/Network/RTL8169/Makefile @@ -1,7 +1,7 @@ # Config file include ../../../Makefile.conf -FILENAME = rtl8169.fex +FILENAME = Realtek-8169.fex CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc CPP = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ @@ -29,12 +29,12 @@ 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 +LDFLAGS := \ + -fPIC -fPIE -pie -Wl,-eDriverEntry \ + -Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment \ + -nostdlib -nodefaultlibs -nolibc \ + -zmax-page-size=0x1000 \ + -Wl,-Map file.map -static -Tlinker.ld WARNCFLAG = -Wall -Wextra @@ -45,23 +45,20 @@ CFLAGS := \ 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 +CFLAGS += -fPIC -fPIE -pie -mno-80387 -mno-mmx -mno-3dnow \ + -mno-red-zone -mno-sse -mno-sse2 \ + -march=x86-64 -pipe -ffunction-sections \ + -msoft-float -fno-builtin else ifeq ($(OSARCH), i686) -CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ +CFLAGS += -fPIC -fPIE -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 diff --git a/Network/RTL8169/arch/amd64/linker.ld b/Network/RTL8169/arch/amd64/linker.ld deleted file mode 100644 index 511369e..0000000 --- a/Network/RTL8169/arch/amd64/linker.ld +++ /dev/null @@ -1,42 +0,0 @@ -/* 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.*) - } -} diff --git a/Network/RTL8169/linker.ld b/Network/RTL8169/linker.ld new file mode 100644 index 0000000..29cd11c --- /dev/null +++ b/Network/RTL8169/linker.ld @@ -0,0 +1,40 @@ +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.*) + } +} diff --git a/Network/RTL8169/rtl8169.cpp b/Network/RTL8169/rtl8169.cpp index 3c54110..27ea49f 100644 --- a/Network/RTL8169/rtl8169.cpp +++ b/Network/RTL8169/rtl8169.cpp @@ -29,6 +29,8 @@ __attribute__((section(".extended"))) FexExtended ExtendedHeader = { KernelAPI *KAPI; +#define print(msg) KAPI->Util.DebugPrint((char *)(msg), KAPI->Info.DriverUID) + /* --------------------------------------------------------------------------------------------------------- */ struct BARData @@ -60,16 +62,16 @@ int CallbackHandler(KernelCallback *Data) { case AcknowledgeReason: { - KAPI->Util.DebugPrint(((char *)"Kernel acknowledged the driver." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel acknowledged the driver."); break; } case ConfigurationReason: { - KAPI->Util.DebugPrint(((char *)"Kernel received configuration data." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel received configuration data."); PCIBaseAddress = reinterpret_cast(Data->RawPtr); if (PCIBaseAddress->VendorID == 0x10EC && PCIBaseAddress->DeviceID == 0x8169) { - KAPI->Util.DebugPrint(((char *)"Found RTL-8169." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Found RTL-8169."); return NOT_IMPLEMENTED; } else @@ -84,9 +86,15 @@ int CallbackHandler(KernelCallback *Data) { break; } + case StopReason: + { + // TODO: Stop the driver. + print("Driver stopped."); + break; + } default: { - KAPI->Util.DebugPrint(((char *)"Unknown reason." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Unknown reason."); break; } } diff --git a/Network/Virtio/Makefile b/Network/Virtio/Makefile index 2865a26..c62ab5a 100644 --- a/Network/Virtio/Makefile +++ b/Network/Virtio/Makefile @@ -1,7 +1,7 @@ # Config file include ../../../Makefile.conf -FILENAME = virtio_net.fex +FILENAME = VirtioNetworkDriver.fex CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc CPP = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ @@ -29,12 +29,12 @@ 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 +LDFLAGS := \ + -fPIC -fPIE -pie -Wl,-eDriverEntry \ + -Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment \ + -nostdlib -nodefaultlibs -nolibc \ + -zmax-page-size=0x1000 \ + -Wl,-Map file.map -static -Tlinker.ld WARNCFLAG = -Wall -Wextra @@ -45,23 +45,20 @@ CFLAGS := \ 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 +CFLAGS += -fPIC -fPIE -pie -mno-80387 -mno-mmx -mno-3dnow \ + -mno-red-zone -mno-sse -mno-sse2 \ + -march=x86-64 -pipe -ffunction-sections \ + -msoft-float -fno-builtin else ifeq ($(OSARCH), i686) -CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ +CFLAGS += -fPIC -fPIE -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 diff --git a/Network/Virtio/Virtio.cpp b/Network/Virtio/Virtio.cpp index 7e0b8d6..7e609af 100644 --- a/Network/Virtio/Virtio.cpp +++ b/Network/Virtio/Virtio.cpp @@ -29,6 +29,8 @@ __attribute__((section(".extended"))) FexExtended ExtendedHeader = { KernelAPI *KAPI; +#define print(msg) KAPI->Util.DebugPrint((char *)(msg), KAPI->Info.DriverUID) + /* --------------------------------------------------------------------------------------------------------- */ struct BARData @@ -60,16 +62,16 @@ int CallbackHandler(KernelCallback *Data) { case AcknowledgeReason: { - KAPI->Util.DebugPrint(((char *)"Kernel acknowledged the driver." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel acknowledged the driver."); break; } case ConfigurationReason: { - KAPI->Util.DebugPrint(((char *)"Kernel received configuration data." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Kernel received configuration data."); PCIBaseAddress = reinterpret_cast(Data->RawPtr); if (PCIBaseAddress->VendorID == 0x1AF4 && PCIBaseAddress->DeviceID == 0x1000) { - KAPI->Util.DebugPrint(((char *)"Found Virtio Network." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Found Virtio Network."); return NOT_IMPLEMENTED; } else @@ -84,9 +86,15 @@ int CallbackHandler(KernelCallback *Data) { break; } + case StopReason: + { + // TODO: Stop the driver. + print("Driver stopped."); + break; + } default: { - KAPI->Util.DebugPrint(((char *)"Unknown reason." + KAPI->Info.Offset), KAPI->Info.DriverUID); + print("Unknown reason."); break; } } diff --git a/Network/Virtio/arch/amd64/linker.ld b/Network/Virtio/arch/amd64/linker.ld deleted file mode 100644 index 511369e..0000000 --- a/Network/Virtio/arch/amd64/linker.ld +++ /dev/null @@ -1,42 +0,0 @@ -/* 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.*) - } -} diff --git a/Network/Virtio/linker.ld b/Network/Virtio/linker.ld new file mode 100644 index 0000000..29cd11c --- /dev/null +++ b/Network/Virtio/linker.ld @@ -0,0 +1,40 @@ +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.*) + } +}