mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:27:43 +00:00
AK: Generalize ByteReader
Also use it instead of CPU.h's possibly_unaligned_data interface
This commit is contained in:
parent
b98e741237
commit
d761c5024b
4 changed files with 20 additions and 113 deletions
|
@ -30,62 +30,6 @@ inline u32 get_iopl_from_eflags(u32 eflags)
|
|||
return (eflags & iopl_mask) >> 12;
|
||||
}
|
||||
|
||||
template<Integral T>
|
||||
void read_possibly_unaligned_data(u8* where, T& data) requires(sizeof(T) == 8 || sizeof(T) == 4 || sizeof(T) == 2)
|
||||
{
|
||||
if (((FlatPtr)where % alignof(T)) == 0) {
|
||||
data = *(T*)where;
|
||||
return;
|
||||
}
|
||||
if constexpr (sizeof(T) == 2) {
|
||||
data = *where | ((u16)(*(where + 1)) << 8);
|
||||
return;
|
||||
}
|
||||
if constexpr (sizeof(T) == 4) {
|
||||
data = *where | (((u32) * (where + 1)) << 8) | (((u32) * (where + 2)) << 16) | (((u32) * (where + 3)) << 24);
|
||||
return;
|
||||
}
|
||||
if constexpr (sizeof(T) == 8) {
|
||||
data = *where | (((u32) * (where + 1)) << 8) | (((u64) * (where + 2)) << 16) | (((u64) * (where + 3)) << 24)
|
||||
| (((u64) * (where + 4)) << 32) | (((u64) * (where + 5)) << 40) | (((u64) * (where + 6)) << 48) | (((u64) * (where + 7)) << 56);
|
||||
return;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
template<Integral T>
|
||||
void write_possibly_unaligned_data(u8* where, T data) requires(sizeof(T) == 8 || sizeof(T) == 4 || sizeof(T) == 2)
|
||||
{
|
||||
if (((FlatPtr)where % alignof(T)) == 0) {
|
||||
*(T*)where = data;
|
||||
return;
|
||||
}
|
||||
if constexpr (sizeof(T) == 2) {
|
||||
where[0] = (u8)(data & 0xFF);
|
||||
where[1] = (u8)((data >> 8) & 0xFF);
|
||||
return;
|
||||
}
|
||||
if constexpr (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;
|
||||
}
|
||||
if constexpr (sizeof(T) == 8) {
|
||||
where[0] = (u8)(data & 0xFF);
|
||||
where[1] = (u8)((data >> 8) & 0xFF);
|
||||
where[2] = (u8)((data >> 16) & 0xFF);
|
||||
where[3] = (u8)((data >> 24) & 0xFF);
|
||||
where[5] = (u8)(data >> 32 & 0xFF);
|
||||
where[5] = (u8)((data >> 40) & 0xFF);
|
||||
where[6] = (u8)((data >> 48) & 0xFF);
|
||||
where[7] = (u8)((data >> 52) & 0xFF);
|
||||
return;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
const DescriptorTablePointer& get_gdtr();
|
||||
const DescriptorTablePointer& get_idtr();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue