1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

Kernel/PCI + CPU: Allow to access unaligned data

This commit is contained in:
Liav A 2021-04-04 22:13:20 +03:00 committed by Andreas Kling
parent 543c29377b
commit 210754a93a
3 changed files with 62 additions and 8 deletions

View file

@ -195,6 +195,50 @@ public:
class GenericInterruptHandler;
struct RegisterState;
template<typename T>
void read_possibly_unaligned_data(u8* where, T& data)
{
// FIXME: Implement 64 bit unaligned data access
VERIFY(sizeof(T) == 8 || sizeof(T) == 4 || sizeof(T) == 2);
if (((FlatPtr)where % sizeof(T)) == 0) {
data = *(T*)where;
return;
}
if (sizeof(T) == 2) {
data = *(u8*)where | ((u16)(*(where + 1)) << 8);
return;
}
if (sizeof(T) == 4) {
data = *(u8*)where | (((u32) * (where + 1)) << 8) | (((u32) * (where + 2)) << 16) | (((u32) * (u8*)(where + 3)) << 24);
return;
}
VERIFY_NOT_REACHED();
}
template<typename T>
void write_possibly_unaligned_data(u8* where, T data)
{
// FIXME: Implement 64 bit unaligned data access
VERIFY(sizeof(T) == 8 || sizeof(T) == 4 || sizeof(T) == 2);
if (((FlatPtr)where % sizeof(T)) == 0) {
*(T*)where = data;
return;
}
if (sizeof(T) == 2) {
where[0] = (u8)(data & 0xFF);
where[1] = (u8)((data >> 8) & 0xFF);
return;
}
if (sizeof(T) == 4) {
where[0] = (u8)(data & 0xFF);
where[1] = (u8)((data >> 8) & 0xFF);
where[2] = (u8)((data >> 16) & 0xFF);
where[3] = (u8)((data >> 24) & 0xFF);
return;
}
VERIFY_NOT_REACHED();
}
const DescriptorTablePointer& get_gdtr();
const DescriptorTablePointer& get_idtr();
void register_interrupt_handler(u8 number, void (*handler)());