mirror of
https://github.com/Fennix-Project/Drivers.git
synced 2025-07-11 15:19:23 +00:00
Added drivers
This commit is contained in:
73
Generic/ExampleDriver/Example.cpp
Normal file
73
Generic/ExampleDriver/Example.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
#include "../../../Kernel/DAPI.hpp"
|
||||
#include "../../../Kernel/Fex.hpp"
|
||||
|
||||
extern "C" int DriverEntry(KernelAPI *Data);
|
||||
int CallbackHandler(KernelCallback *Data);
|
||||
|
||||
/* The driver is
|
||||
* This is a driver for Fennix Driver Entry Extended Header
|
||||
* * * * */
|
||||
HEAD(FexFormatType_Driver, FexOSType_Fennix, DriverEntry);
|
||||
|
||||
// Ignore the warning about missing field initializers
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
|
||||
// Extended header which is used to give additional information to the kernel
|
||||
__attribute__((section(".extended"))) FexExtended ExtendedHeader = {
|
||||
.Driver = {
|
||||
.Name = "Example Driver",
|
||||
.Type = FexDriverType_Generic,
|
||||
.Callback = CallbackHandler,
|
||||
.Bind = {
|
||||
.Type = BIND_INTERRUPT,
|
||||
.Interrupt = {
|
||||
.Vector = 0xFE,
|
||||
}}}};
|
||||
|
||||
// Global variable that holds the kernel API
|
||||
KernelAPI *KAPI;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
// Driver entry point. This is called at initialization. "Data" argument points to the kernel API structure.
|
||||
int DriverEntry(KernelAPI *Data)
|
||||
{
|
||||
// Check if kernel API is valid
|
||||
if (!Data)
|
||||
return INVALID_KERNEL_API;
|
||||
|
||||
// // Check if kernel API version is valid. this is important because the kernel API may change in the future.
|
||||
if (Data->Version.Major < 0 || Data->Version.Minor < 0 || Data->Version.Patch < 0)
|
||||
return KERNEL_API_VERSION_NOT_SUPPORTED;
|
||||
|
||||
// Set the global variable to the kernel API
|
||||
KAPI = Data;
|
||||
|
||||
// We print "Hello World!" to UART.
|
||||
KAPI->Util.DebugPrint(((char *)"Hello World!" + KAPI->Info.Offset), KAPI->Info.DriverUID);
|
||||
return OK;
|
||||
}
|
||||
|
||||
// This is called when the driver is bound to an interrupt, process, or PCI device or when the kernel wants to send a message to the driver.
|
||||
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 InterruptReason:
|
||||
{
|
||||
KAPI->Util.DebugPrint(((char *)"Interrupt received." + KAPI->Info.Offset), KAPI->Info.DriverUID);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
KAPI->Util.DebugPrint(((char *)"Unknown reason." + KAPI->Info.Offset), KAPI->Info.DriverUID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
100
Generic/ExampleDriver/Makefile
Normal file
100
Generic/ExampleDriver/Makefile
Normal file
@ -0,0 +1,100 @@
|
||||
# Config file
|
||||
include ../../../Makefile.conf
|
||||
|
||||
FILENAME = ExampleDriver.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)
|
40
Generic/ExampleDriver/arch/amd64/linker.ld
Normal file
40
Generic/ExampleDriver/arch/amd64/linker.ld
Normal file
@ -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.*)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user