mirror of
https://github.com/Fennix-Project/Drivers.git
synced 2025-07-10 22:59:25 +00:00
Fix driver implementation
This commit is contained in:
@ -1,83 +1,22 @@
|
||||
# Config file
|
||||
# Config files
|
||||
include ../../../Makefile.conf
|
||||
|
||||
FILENAME = aip.drv
|
||||
|
||||
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
|
||||
include ../../config.mk
|
||||
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S')
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c')
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp')
|
||||
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)
|
||||
OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(S_SOURCES:.S=.o)
|
||||
STACK_USAGE_OBJ = $(C_SOURCES:.c=.su) $(CPP_SOURCES:.cpp=.su)
|
||||
INCLUDE_DIR = ../../include
|
||||
|
||||
LIBS := ../../out/dcrt0.o -L../../out -ldriver
|
||||
|
||||
LDFLAGS := \
|
||||
-fPIC -fPIE -pie \
|
||||
-Wl,--no-dynamic-linker,-ztext,--no-warn-rwx-segment \
|
||||
-nostdlib -nodefaultlibs -nolibc \
|
||||
-zmax-page-size=0x1000 \
|
||||
-Wl,-Map file.map -shared -fvisibility=hidden
|
||||
|
||||
WARNCFLAG = -Wall -Wextra
|
||||
|
||||
CFLAGS := -I$(INCLUDE_DIR) -fvisibility=hidden
|
||||
|
||||
ifeq ($(OSARCH), amd64)
|
||||
|
||||
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), i386)
|
||||
|
||||
CFLAGS += -fPIC -fPIE -pie -mno-80387 -mno-mmx -mno-3dnow \
|
||||
-mno-red-zone -mno-sse -mno-sse2 -ffunction-sections \
|
||||
-march=i386 -pipe -msoft-float -fno-builtin
|
||||
|
||||
else ifeq ($(OSARCH), aarch64)
|
||||
|
||||
CFLAGS += -pipe -fno-builtin -fPIC
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fstack-usage
|
||||
ifeq ($(OSARCH), amd64)
|
||||
CFLAGS += -fverbose-asm
|
||||
endif
|
||||
ifneq ($(OSARCH), aarch64)
|
||||
CFLAGS += -fstack-check
|
||||
endif
|
||||
LDFLAGS += -ggdb3 -O0
|
||||
endif
|
||||
FILENAME = aip.drv
|
||||
|
||||
build: $(FILENAME)
|
||||
mv $(FILENAME) ../../out/$(FILENAME)
|
||||
|
||||
$(FILENAME): $(OBJ)
|
||||
$(info Linking $@)
|
||||
$(CC) $(LDFLAGS) $(OBJ) $(LIBS) -o $@
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CC) $(CFLAGS) $(WARNCFLAG) -std=c17 -c $< -o $@
|
||||
|
||||
%.o: %.cpp $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -fno-exceptions -fno-rtti -c $< -o $@
|
||||
|
||||
%.o: %.S
|
||||
$(info Compiling $<)
|
||||
$(AS) -o $@ $<
|
||||
$(CC) $(DRIVER_LDFLAGS) $(OBJ) ../../out/dcrt0.o -L../../out -lkernel -o $@
|
||||
|
||||
clean:
|
||||
rm -f file.map $(OBJ) $(STACK_USAGE_OBJ)
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include <driver.h>
|
||||
#include <errno.h>
|
||||
#include <fs.h>
|
||||
#include <input.h>
|
||||
#include <base.h>
|
||||
#include <io.h>
|
||||
@ -161,6 +162,17 @@ const unsigned short ScanCodeSet3[] = {
|
||||
[0x4B] = KEY_L,
|
||||
[0x4D] = KEY_P};
|
||||
|
||||
InputReport kir = {0};
|
||||
int ReportKeyboardEvent(dev_t Device, KeyScanCodes ScanCode, uint8_t Pressed)
|
||||
{
|
||||
kir.Type = INPUT_TYPE_KEYBOARD;
|
||||
kir.Device = Device;
|
||||
kir.Keyboard.Key = ScanCode;
|
||||
kir.Keyboard.Key |= Pressed ? KEY_PRESSED : 0;
|
||||
ReportInputEvent(&kir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool IsE0 = false;
|
||||
bool IsE1 = false;
|
||||
void PS2KbdInterruptHandler(TrapFrame *)
|
||||
@ -217,12 +229,21 @@ void PS2KbdInterruptHandler(TrapFrame *)
|
||||
{
|
||||
if (IsE0)
|
||||
IsE0 = false;
|
||||
Log("Unknown PS/2 Keyboard Scan Code Set: %#x", KeyboardScanCodeSet);
|
||||
KernelLog("Unknown PS/2 Keyboard Scan Code Set: %#x", KeyboardScanCodeSet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int __fs_kb_Ioctl(struct Inode *, unsigned long, void *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct InodeOperations KbdOps = {
|
||||
.Ioctl = __fs_kb_Ioctl,
|
||||
};
|
||||
|
||||
int InitializeKeyboard()
|
||||
{
|
||||
// PS2WriteData(PS2_KBD_CMD_RESET);
|
||||
@ -230,45 +251,50 @@ int InitializeKeyboard()
|
||||
// if (test != PS2_KBD_RESP_TEST_PASSED &&
|
||||
// test != PS2_KBD_RESP_ACK)
|
||||
// {
|
||||
// Log("PS/2 keyboard reset failed (%#x)", test);
|
||||
// KernelLog("PS/2 keyboard reset failed (%#x)", test);
|
||||
// return -EFAULT;
|
||||
// }
|
||||
|
||||
PS2WriteData(PS2_KBD_CMD_DEFAULTS);
|
||||
if (PS2ACKTimeout() != 0)
|
||||
Log("PS/2 keyboard failed to set defaults");
|
||||
KernelLog("PS/2 keyboard failed to set defaults");
|
||||
|
||||
PS2WriteData(PS2_KBD_CMD_SCAN_CODE_SET);
|
||||
if (PS2ACKTimeout() != 0)
|
||||
Log("PS/2 keyboard failed to set scan code set");
|
||||
KernelLog("PS/2 keyboard failed to set scan code set");
|
||||
|
||||
/* We want Scan Code Set 1 */
|
||||
PS2WriteData(PS2_KBD_SCAN_CODE_SET_2); /* It will set to 1 but with translation? */
|
||||
if (PS2ACKTimeout() != 0)
|
||||
Log("PS/2 keyboard failed to set scan code set 2");
|
||||
KernelLog("PS/2 keyboard failed to set scan code set 2");
|
||||
|
||||
PS2WriteData(PS2_KBD_CMD_SCAN_CODE_SET);
|
||||
if (PS2ACKTimeout() != 0)
|
||||
Log("PS/2 keyboard failed to set scan code set");
|
||||
KernelLog("PS/2 keyboard failed to set scan code set");
|
||||
|
||||
PS2WriteData(PS2_KBD_SCAN_CODE_GET_CURRENT);
|
||||
if (PS2ACKTimeout() != 0)
|
||||
Log("PS/2 keyboard failed to get current scan code set");
|
||||
KernelLog("PS/2 keyboard failed to get current scan code set");
|
||||
|
||||
KeyboardScanCodeSet = PS2ReadAfterACK();
|
||||
Log("PS/2 Keyboard Scan Code Set: 0x%X", KeyboardScanCodeSet);
|
||||
KernelLog("PS/2 Keyboard Scan Code Set: 0x%X", KeyboardScanCodeSet);
|
||||
PS2ClearOutputBuffer();
|
||||
|
||||
PS2WriteData(PS2_KBD_CMD_ENABLE_SCANNING);
|
||||
|
||||
RegisterInterruptHandler(1, PS2KbdInterruptHandler);
|
||||
KeyboardDevID = RegisterInputDevice(ddt_Keyboard);
|
||||
|
||||
KeyboardDevID = RegisterDevice(INPUT_TYPE_KEYBOARD, &KbdOps);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FinalizeKeyboard()
|
||||
{
|
||||
UnregisterInputDevice(KeyboardDevID, ddt_Keyboard);
|
||||
PS2WriteData(PS2_KBD_CMD_DISABLE_SCANNING);
|
||||
if (PS2ACKTimeout() != 0)
|
||||
KernelLog("PS/2 keyboard failed to disable scanning");
|
||||
|
||||
UnregisterDevice(KeyboardDevID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -276,11 +302,11 @@ int DetectPS2Keyboard()
|
||||
{
|
||||
PS2WriteData(PS2_KBD_CMD_DISABLE_SCANNING);
|
||||
if (PS2ACKTimeout() != 0)
|
||||
Log("PS/2 keyboard failed to disable scanning");
|
||||
KernelLog("PS/2 keyboard failed to disable scanning");
|
||||
|
||||
PS2WriteData(PS2_KBD_CMD_IDENTIFY);
|
||||
if (PS2ACKTimeout() != 0)
|
||||
Log("PS/2 keyboard failed to identify");
|
||||
KernelLog("PS/2 keyboard failed to identify");
|
||||
|
||||
uint8_t recByte;
|
||||
int timeout = 1000000;
|
||||
@ -300,10 +326,10 @@ int DetectPS2Keyboard()
|
||||
break;
|
||||
}
|
||||
if (timeout == 0)
|
||||
Log("PS/2 keyboard second byte timed out");
|
||||
KernelLog("PS/2 keyboard second byte timed out");
|
||||
else
|
||||
Device1ID[1] = recByte;
|
||||
|
||||
Log("PS2 Keyboard Device: 0x%X 0x%X", Device1ID[0], Device1ID[1]);
|
||||
KernelLog("PS2 Keyboard Device: 0x%X 0x%X", Device1ID[0], Device1ID[1]);
|
||||
return 0;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ int DriverEntry()
|
||||
|
||||
DualChannel = cfg.Port2Clock;
|
||||
if (DualChannel)
|
||||
Log("Dual channel PS/2 controller detected");
|
||||
KernelLog("Dual channel PS/2 controller detected");
|
||||
cfg.Port1Interrupt = 1;
|
||||
cfg.Port2Interrupt = 1;
|
||||
cfg.Port1Translation = 1;
|
||||
@ -116,7 +116,7 @@ int DriverEntry()
|
||||
uint8_t test = PS2ReadData();
|
||||
if (test != PS2_TEST_PASSED)
|
||||
{
|
||||
Log("PS/2 controller self test failed (%#x)", test);
|
||||
KernelLog("PS/2 controller self test failed (%#x)", test);
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ int DriverEntry()
|
||||
test = PS2ReadData();
|
||||
if (test != 0x00)
|
||||
{
|
||||
Log("PS/2 Port 1 self test failed (%#x)", test);
|
||||
KernelLog("PS/2 Port 1 self test failed (%#x)", test);
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ int DriverEntry()
|
||||
test = PS2ReadData();
|
||||
if (test != 0x00)
|
||||
{
|
||||
Log("PS/2 Port 2 self test failed (%#x)", test);
|
||||
KernelLog("PS/2 Port 2 self test failed (%#x)", test);
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
@ -204,7 +204,7 @@ int DriverProbe()
|
||||
{
|
||||
if (!IsKeyboard(Device1ID[0]))
|
||||
{
|
||||
Log("PS/2 Port 1 is not a keyboard");
|
||||
KernelLog("PS/2 Port 1 is not a keyboard");
|
||||
// return -EINVAL;
|
||||
}
|
||||
}
|
||||
@ -213,15 +213,15 @@ int DriverProbe()
|
||||
{
|
||||
if (!IsMouse(Device2ID[0]))
|
||||
{
|
||||
Log("PS/2 Port 2 is not a mouse");
|
||||
KernelLog("PS/2 Port 2 is not a mouse");
|
||||
// return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
KPrint("PS/2 Port 1: %s (0x%X 0x%X)",
|
||||
KernelPrint("PS/2 Port 1: %s (0x%X 0x%X)",
|
||||
GetPS2DeviceName(Device1ID[0], Device1ID[1]),
|
||||
Device1ID[0], Device1ID[1]);
|
||||
KPrint("PS/2 Port 2: %s (0x%X 0x%X)",
|
||||
KernelPrint("PS/2 Port 2: %s (0x%X 0x%X)",
|
||||
GetPS2DeviceName(Device2ID[0], Device2ID[1]),
|
||||
Device2ID[0], Device2ID[1]);
|
||||
return 0;
|
||||
@ -230,5 +230,5 @@ int DriverProbe()
|
||||
DriverInfo("aip",
|
||||
"Advanced Integrated Peripheral Driver",
|
||||
"EnderIce2",
|
||||
"0.1",
|
||||
0, 0, 1,
|
||||
"GPLv3");
|
||||
|
@ -18,8 +18,9 @@
|
||||
#include "aip.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <input.h>
|
||||
#include <base.h>
|
||||
#include <fs.h>
|
||||
#include <input.h>
|
||||
|
||||
dev_t MouseDevID = -1;
|
||||
bool PacketReady = false;
|
||||
@ -28,6 +29,7 @@ bool MouseButton45 = false;
|
||||
uint8_t Cycle = 0;
|
||||
PS2_MOUSE_PACKET Packet = {0};
|
||||
|
||||
InputReport mir = {0};
|
||||
void PS2MouseInterruptHandler(TrapFrame *)
|
||||
{
|
||||
uint8_t data = PS2ReadData();
|
||||
@ -114,18 +116,17 @@ void PS2MouseInterruptHandler(TrapFrame *)
|
||||
if (Packet.Base.YOverflow)
|
||||
Y = 0;
|
||||
|
||||
MouseReport mr = {
|
||||
.LeftButton = Packet.Base.LeftButton,
|
||||
.RightButton = Packet.Base.RightButton,
|
||||
.MiddleButton = Packet.Base.MiddleButton,
|
||||
.Button4 = Packet.ZMovement.Button4,
|
||||
.Button5 = Packet.ZMovement.Button5,
|
||||
.X = X,
|
||||
.Y = -Y,
|
||||
.Z = Packet.ZMovement.Z,
|
||||
};
|
||||
ReportRelativeMouseEvent(MouseDevID, mr);
|
||||
|
||||
mir.Type = INPUT_TYPE_MOUSE;
|
||||
mir.Device = MouseDevID;
|
||||
mir.Mouse.LeftButton = Packet.Base.LeftButton;
|
||||
mir.Mouse.RightButton = Packet.Base.RightButton;
|
||||
mir.Mouse.MiddleButton = Packet.Base.MiddleButton;
|
||||
mir.Mouse.Button4 = Packet.ZMovement.Button4;
|
||||
mir.Mouse.Button5 = Packet.ZMovement.Button5;
|
||||
mir.Mouse.X = X;
|
||||
mir.Mouse.Y = -Y;
|
||||
mir.Mouse.Z = Packet.ZMovement.Z;
|
||||
ReportInputEvent(&mir);
|
||||
PacketReady = false;
|
||||
}
|
||||
|
||||
@ -140,6 +141,15 @@ void MouseSampleRate(uint8_t SampleRate)
|
||||
PS2ReadData();
|
||||
}
|
||||
|
||||
int __fs_ms_Ioctl(struct Inode *, unsigned long, void *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct InodeOperations MouseOps = {
|
||||
.Ioctl = __fs_ms_Ioctl,
|
||||
};
|
||||
|
||||
int InitializeMouse()
|
||||
{
|
||||
PS2WriteData(PS2_CMD_WRITE_NEXT_BYTE_TO_PS2_PORT_2_INPUT);
|
||||
@ -148,12 +158,13 @@ int InitializeMouse()
|
||||
if (test != PS2_MOUSE_RESP_TEST_PASSED &&
|
||||
test != PS2_MOUSE_RESP_ACK)
|
||||
{
|
||||
Log("PS/2 mouse reset failed! (%#x)", test);
|
||||
KernelLog("PS/2 mouse reset failed! (%#x)", test);
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
RegisterInterruptHandler(12, PS2MouseInterruptHandler);
|
||||
MouseDevID = RegisterInputDevice(ddt_Mouse);
|
||||
|
||||
MouseDevID = RegisterDevice(INPUT_TYPE_MOUSE, &MouseOps);
|
||||
|
||||
PS2WriteCommand(PS2_CMD_WRITE_NEXT_BYTE_TO_PS2_PORT_2_INPUT);
|
||||
PS2WriteData(PS2_MOUSE_CMD_SET_DEFAULTS);
|
||||
@ -169,7 +180,7 @@ int InitializeMouse()
|
||||
PS2WriteCommand(PS2_CMD_WRITE_NEXT_BYTE_TO_PS2_PORT_2_INPUT);
|
||||
PS2WriteData(PS2_MOUSE_CMD_READ_ID);
|
||||
uint8_t Device2ID = PS2ReadData();
|
||||
Log("PS/2 Mouse ID: %#x", Device2ID);
|
||||
KernelLog("PS/2 Mouse ID: %#x", Device2ID);
|
||||
|
||||
MouseSampleRate(200);
|
||||
MouseSampleRate(200);
|
||||
@ -178,7 +189,7 @@ int InitializeMouse()
|
||||
PS2WriteCommand(PS2_CMD_WRITE_NEXT_BYTE_TO_PS2_PORT_2_INPUT);
|
||||
PS2WriteData(PS2_MOUSE_CMD_READ_ID);
|
||||
Device2ID = PS2ReadData();
|
||||
Log("PS/2 Mouse ID: %#x", Device2ID);
|
||||
KernelLog("PS/2 Mouse ID: %#x", Device2ID);
|
||||
|
||||
if (Device2ID >= 3 && Device2ID <= 4)
|
||||
FourPackets = true;
|
||||
@ -190,10 +201,10 @@ int InitializeMouse()
|
||||
|
||||
int FinalizeMouse()
|
||||
{
|
||||
UnregisterInputDevice(MouseDevID, ddt_Mouse);
|
||||
|
||||
PS2WriteCommand(PS2_CMD_WRITE_NEXT_BYTE_TO_PS2_PORT_2_INPUT);
|
||||
PS2WriteData(PS2_MOUSE_CMD_DISABLE_DATA_REPORTING);
|
||||
|
||||
UnregisterDevice(MouseDevID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -202,12 +213,12 @@ int DetectPS2Mouse()
|
||||
PS2WriteCommand(PS2_CMD_WRITE_NEXT_BYTE_TO_PS2_PORT_2_INPUT);
|
||||
PS2WriteData(PS2_MOUSE_CMD_DISABLE_DATA_REPORTING);
|
||||
if (PS2ACKTimeout() != 0)
|
||||
Log("PS/2 mouse failed to disable data reporting!");
|
||||
KernelLog("PS/2 mouse failed to disable data reporting!");
|
||||
|
||||
PS2WriteCommand(PS2_CMD_WRITE_NEXT_BYTE_TO_PS2_PORT_2_INPUT);
|
||||
PS2WriteData(PS2_MOUSE_CMD_READ_ID);
|
||||
if (PS2ACKTimeout() != 0)
|
||||
Log("PS/2 mouse failed to read ID!");
|
||||
KernelLog("PS/2 mouse failed to read ID!");
|
||||
|
||||
uint8_t recByte;
|
||||
int timeout = 1000000;
|
||||
@ -228,6 +239,6 @@ int DetectPS2Mouse()
|
||||
}
|
||||
Device2ID[1] = recByte;
|
||||
|
||||
Log("PS2 Mouse Device: 0x%X 0x%X", Device2ID[0], Device2ID[1]);
|
||||
KernelLog("PS2 Mouse Device: 0x%X 0x%X", Device2ID[0], Device2ID[1]);
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user