AK: Rename the common integer typedefs to make it obvious what they are.

These types can be picked up by including <AK/Types.h>:

* u8, u16, u32, u64 (unsigned)
* i8, i16, i32, i64 (signed)
This commit is contained in:
Andreas Kling 2019-07-03 21:17:35 +02:00
parent c4c4bbc5ba
commit 27f699ef0c
Notes: sideshowbarker 2024-07-19 13:23:47 +09:00
208 changed files with 1603 additions and 1621 deletions

View file

@ -10,7 +10,7 @@ namespace AK {
class Bitmap { class Bitmap {
public: public:
// NOTE: A wrapping Bitmap won't try to free the wrapped data. // NOTE: A wrapping Bitmap won't try to free the wrapped data.
static Bitmap wrap(byte* data, int size) static Bitmap wrap(u8* data, int size)
{ {
return Bitmap(data, size); return Bitmap(data, size);
} }
@ -42,13 +42,13 @@ public:
{ {
ASSERT(index < m_size); ASSERT(index < m_size);
if (value) if (value)
m_data[index / 8] |= static_cast<byte>((1u << (index % 8))); m_data[index / 8] |= static_cast<u8>((1u << (index % 8)));
else else
m_data[index / 8] &= static_cast<byte>(~(1u << (index % 8))); m_data[index / 8] &= static_cast<u8>(~(1u << (index % 8)));
} }
byte* data() { return m_data; } u8* data() { return m_data; }
const byte* data() const { return m_data; } const u8* data() const { return m_data; }
void grow(int size, bool default_value) void grow(int size, bool default_value)
{ {
@ -59,7 +59,7 @@ public:
auto previous_data = m_data; auto previous_data = m_data;
m_size = size; m_size = size;
m_data = reinterpret_cast<byte*>(kmalloc(size_in_bytes())); m_data = reinterpret_cast<u8*>(kmalloc(size_in_bytes()));
fill(default_value); fill(default_value);
@ -123,11 +123,11 @@ private:
, m_owned(true) , m_owned(true)
{ {
ASSERT(m_size != 0); ASSERT(m_size != 0);
m_data = reinterpret_cast<byte*>(kmalloc(size_in_bytes())); m_data = reinterpret_cast<u8*>(kmalloc(size_in_bytes()));
fill(default_value); fill(default_value);
} }
Bitmap(byte* data, int size) Bitmap(u8* data, int size)
: m_data(data) : m_data(data)
, m_size(size) , m_size(size)
, m_owned(false) , m_owned(false)
@ -136,7 +136,7 @@ private:
int size_in_bytes() const { return ceil_div(m_size, 8); } int size_in_bytes() const { return ceil_div(m_size, 8); }
byte* m_data { nullptr }; u8* m_data { nullptr };
int m_size { 0 }; int m_size { 0 };
bool m_owned { false }; bool m_owned { false };
}; };

View file

@ -12,28 +12,28 @@ public:
{ {
} }
void operator<<(byte value) void operator<<(u8 value)
{ {
m_buffer[m_offset++] = value & 0xffu; m_buffer[m_offset++] = value & 0xffu;
} }
void operator<<(char value) void operator<<(char value)
{ {
m_buffer[m_offset++] = (byte)value; m_buffer[m_offset++] = (u8)value;
} }
void operator<<(word value) void operator<<(u16 value)
{ {
m_buffer[m_offset++] = value & 0xffu; m_buffer[m_offset++] = value & 0xffu;
m_buffer[m_offset++] = (byte)(value >> 8) & 0xffu; m_buffer[m_offset++] = (u8)(value >> 8) & 0xffu;
} }
void operator<<(dword value) void operator<<(u32 value)
{ {
m_buffer[m_offset++] = value & 0xffu; m_buffer[m_offset++] = value & 0xffu;
m_buffer[m_offset++] = (byte)(value >> 8) & 0xffu; m_buffer[m_offset++] = (u8)(value >> 8) & 0xffu;
m_buffer[m_offset++] = (byte)(value >> 16) & 0xffu; m_buffer[m_offset++] = (u8)(value >> 16) & 0xffu;
m_buffer[m_offset++] = (byte)(value >> 24) & 0xffu; m_buffer[m_offset++] = (u8)(value >> 24) & 0xffu;
} }
void operator<<(const StringView& value) void operator<<(const StringView& value)
@ -53,7 +53,7 @@ public:
return m_offset == m_buffer.size(); return m_offset == m_buffer.size();
} }
void fill_to_end(byte ch) void fill_to_end(u8 ch)
{ {
while (!at_end()) while (!at_end())
m_buffer[m_offset++] = ch; m_buffer[m_offset++] = ch;

View file

@ -28,12 +28,12 @@ public:
m_data = nullptr; m_data = nullptr;
} }
byte& operator[](int i) u8& operator[](int i)
{ {
ASSERT(i < m_size); ASSERT(i < m_size);
return m_data[i]; return m_data[i];
} }
const byte& operator[](int i) const const u8& operator[](int i) const
{ {
ASSERT(i < m_size); ASSERT(i < m_size);
return m_data[i]; return m_data[i];
@ -41,11 +41,11 @@ public:
bool is_empty() const { return !m_size; } bool is_empty() const { return !m_size; }
int size() const { return m_size; } int size() const { return m_size; }
byte* pointer() { return m_data; } u8* pointer() { return m_data; }
const byte* pointer() const { return m_data; } const u8* pointer() const { return m_data; }
byte* offset_pointer(int offset) { return m_data + offset; } u8* offset_pointer(int offset) { return m_data + offset; }
const byte* offset_pointer(int offset) const { return m_data + offset; } const u8* offset_pointer(int offset) const { return m_data + offset; }
void* end_pointer() { return m_data + m_size; } void* end_pointer() { return m_data + m_size; }
const void* end_pointer() const { return m_data + m_size; } const void* end_pointer() const { return m_data + m_size; }
@ -71,7 +71,7 @@ private:
ByteBufferImpl(void*, int, ConstructionMode); // For ConstructionMode=Wrap/Adopt ByteBufferImpl(void*, int, ConstructionMode); // For ConstructionMode=Wrap/Adopt
ByteBufferImpl() {} ByteBufferImpl() {}
byte* m_data { nullptr }; u8* m_data { nullptr };
int m_size { 0 }; int m_size { 0 };
bool m_owned { false }; bool m_owned { false };
}; };
@ -114,12 +114,12 @@ public:
bool operator!() const { return is_null(); } bool operator!() const { return is_null(); }
bool is_null() const { return m_impl == nullptr; } bool is_null() const { return m_impl == nullptr; }
byte& operator[](int i) u8& operator[](int i)
{ {
ASSERT(m_impl); ASSERT(m_impl);
return (*m_impl)[i]; return (*m_impl)[i];
} }
byte operator[](int i) const u8 operator[](int i) const
{ {
ASSERT(m_impl); ASSERT(m_impl);
return (*m_impl)[i]; return (*m_impl)[i];
@ -127,14 +127,14 @@ public:
bool is_empty() const { return !m_impl || m_impl->is_empty(); } bool is_empty() const { return !m_impl || m_impl->is_empty(); }
int size() const { return m_impl ? m_impl->size() : 0; } int size() const { return m_impl ? m_impl->size() : 0; }
byte* data() { return pointer(); } u8* data() { return pointer(); }
const byte* data() const { return pointer(); } const u8* data() const { return pointer(); }
byte* pointer() { return m_impl ? m_impl->pointer() : nullptr; } u8* pointer() { return m_impl ? m_impl->pointer() : nullptr; }
const byte* pointer() const { return m_impl ? m_impl->pointer() : nullptr; } const u8* pointer() const { return m_impl ? m_impl->pointer() : nullptr; }
byte* offset_pointer(int offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } u8* offset_pointer(int offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
const byte* offset_pointer(int offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } const u8* offset_pointer(int offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
void* end_pointer() { return m_impl ? m_impl->end_pointer() : nullptr; } void* end_pointer() { return m_impl ? m_impl->end_pointer() : nullptr; }
const void* end_pointer() const { return m_impl ? m_impl->end_pointer() : nullptr; } const void* end_pointer() const { return m_impl ? m_impl->end_pointer() : nullptr; }
@ -191,7 +191,7 @@ private:
inline ByteBufferImpl::ByteBufferImpl(int size) inline ByteBufferImpl::ByteBufferImpl(int size)
: m_size(size) : m_size(size)
{ {
m_data = static_cast<byte*>(kmalloc(size)); m_data = static_cast<u8*>(kmalloc(size));
m_owned = true; m_owned = true;
} }
@ -199,13 +199,13 @@ inline ByteBufferImpl::ByteBufferImpl(const void* data, int size, ConstructionMo
: m_size(size) : m_size(size)
{ {
ASSERT(mode == Copy); ASSERT(mode == Copy);
m_data = static_cast<byte*>(kmalloc(size)); m_data = static_cast<u8*>(kmalloc(size));
memcpy(m_data, data, size); memcpy(m_data, data, size);
m_owned = true; m_owned = true;
} }
inline ByteBufferImpl::ByteBufferImpl(void* data, int size, ConstructionMode mode) inline ByteBufferImpl::ByteBufferImpl(void* data, int size, ConstructionMode mode)
: m_data(static_cast<byte*>(data)) : m_data(static_cast<u8*>(data))
, m_size(size) , m_size(size)
{ {
if (mode == Adopt) { if (mode == Adopt) {
@ -219,9 +219,9 @@ inline void ByteBufferImpl::grow(int size)
{ {
ASSERT(size > m_size); ASSERT(size > m_size);
ASSERT(m_owned); ASSERT(m_owned);
byte* new_data = static_cast<byte*>(kmalloc(size)); u8* new_data = static_cast<u8*>(kmalloc(size));
memcpy(new_data, m_data, m_size); memcpy(new_data, m_data, m_size);
byte* old_data = m_data; u8* old_data = m_data;
m_data = new_data; m_data = new_data;
m_size = size; m_size = size;
kfree(old_data); kfree(old_data);

View file

@ -1,7 +1,7 @@
#include "ELFImage.h" #include "ELFImage.h"
#include <AK/kstdio.h> #include <AK/kstdio.h>
ELFImage::ELFImage(const byte* buffer) ELFImage::ELFImage(const u8* buffer)
: m_buffer(buffer) : m_buffer(buffer)
{ {
m_valid = parse(); m_valid = parse();

View file

@ -7,7 +7,7 @@
class ELFImage { class ELFImage {
public: public:
explicit ELFImage(const byte*); explicit ELFImage(const u8*);
~ELFImage(); ~ELFImage();
void dump(); void dump();
bool is_valid() const { return m_valid; } bool is_valid() const { return m_valid; }
@ -54,13 +54,13 @@ public:
~ProgramHeader() {} ~ProgramHeader() {}
unsigned index() const { return m_program_header_index; } unsigned index() const { return m_program_header_index; }
dword type() const { return m_program_header.p_type; } u32 type() const { return m_program_header.p_type; }
dword flags() const { return m_program_header.p_flags; } u32 flags() const { return m_program_header.p_flags; }
dword offset() const { return m_program_header.p_offset; } u32 offset() const { return m_program_header.p_offset; }
VirtualAddress vaddr() const { return VirtualAddress(m_program_header.p_vaddr); } VirtualAddress vaddr() const { return VirtualAddress(m_program_header.p_vaddr); }
dword size_in_memory() const { return m_program_header.p_memsz; } u32 size_in_memory() const { return m_program_header.p_memsz; }
dword size_in_image() const { return m_program_header.p_filesz; } u32 size_in_image() const { return m_program_header.p_filesz; }
dword alignment() const { return m_program_header.p_align; } u32 alignment() const { return m_program_header.p_align; }
bool is_readable() const { return flags() & PF_R; } bool is_readable() const { return flags() & PF_R; }
bool is_writable() const { return flags() & PF_W; } bool is_writable() const { return flags() & PF_W; }
bool is_executable() const { return flags() & PF_X; } bool is_executable() const { return flags() & PF_X; }
@ -88,10 +88,10 @@ public:
unsigned size() const { return m_section_header.sh_size; } unsigned size() const { return m_section_header.sh_size; }
unsigned entry_size() const { return m_section_header.sh_entsize; } unsigned entry_size() const { return m_section_header.sh_entsize; }
unsigned entry_count() const { return !entry_size() ? 0 : size() / entry_size(); } unsigned entry_count() const { return !entry_size() ? 0 : size() / entry_size(); }
dword address() const { return m_section_header.sh_addr; } u32 address() const { return m_section_header.sh_addr; }
const char* raw_data() const { return m_image.raw_data(m_section_header.sh_offset); } const char* raw_data() const { return m_image.raw_data(m_section_header.sh_offset); }
bool is_undefined() const { return m_section_index == SHN_UNDEF; } bool is_undefined() const { return m_section_index == SHN_UNDEF; }
dword flags() const { return m_section_header.sh_flags; } u32 flags() const { return m_section_header.sh_flags; }
bool is_writable() const { return flags() & SHF_WRITE; } bool is_writable() const { return flags() & SHF_WRITE; }
bool is_executable() const { return flags() & PF_X; } bool is_executable() const { return flags() & PF_X; }
@ -134,7 +134,7 @@ private:
const char* section_header_table_string(unsigned offset) const; const char* section_header_table_string(unsigned offset) const;
const char* section_index_to_string(unsigned index); const char* section_index_to_string(unsigned index);
const byte* m_buffer { nullptr }; const u8* m_buffer { nullptr };
bool m_valid { false }; bool m_valid { false };
unsigned m_symbol_table_section_index { 0 }; unsigned m_symbol_table_section_index { 0 };
unsigned m_string_table_section_index { 0 }; unsigned m_string_table_section_index { 0 };

View file

@ -8,7 +8,7 @@
//#define ELFLOADER_DEBUG //#define ELFLOADER_DEBUG
ELFLoader::ELFLoader(const byte* buffer) ELFLoader::ELFLoader(const u8* buffer)
: m_image(buffer) : m_image(buffer)
{ {
} }
@ -81,7 +81,7 @@ char* ELFLoader::symbol_ptr(const char* name)
return found_ptr; return found_ptr;
} }
String ELFLoader::symbolicate(dword address) const String ELFLoader::symbolicate(u32 address) const
{ {
SortedSymbol* sorted_symbols = nullptr; SortedSymbol* sorted_symbols = nullptr;
#ifdef KERNEL #ifdef KERNEL

View file

@ -13,7 +13,7 @@ class Region;
class ELFLoader { class ELFLoader {
public: public:
explicit ELFLoader(const byte*); explicit ELFLoader(const u8*);
~ELFLoader(); ~ELFLoader();
bool load(); bool load();
@ -26,7 +26,7 @@ public:
bool has_symbols() const { return m_image.symbol_count(); } bool has_symbols() const { return m_image.symbol_count(); }
String symbolicate(dword address) const; String symbolicate(u32 address) const;
private: private:
bool layout(); bool layout();
@ -49,7 +49,7 @@ private:
ELFImage m_image; ELFImage m_image;
struct SortedSymbol { struct SortedSymbol {
dword address; u32 address;
const char* name; const char* name;
}; };
#ifdef KERNEL #ifdef KERNEL

View file

@ -2,7 +2,7 @@
#include "Types.h" #include "Types.h"
inline unsigned int_hash(dword key) inline unsigned int_hash(u32 key)
{ {
key += ~(key << 15); key += ~(key << 15);
key ^= (key >> 10); key ^= (key >> 10);
@ -13,7 +13,7 @@ inline unsigned int_hash(dword key)
return key; return key;
} }
inline unsigned pair_int_hash(dword key1, dword key2) inline unsigned pair_int_hash(u32 key1, u32 key2)
{ {
return int_hash((int_hash(key1) * 209) ^ (int_hash(key2 * 413))); return int_hash((int_hash(key1) * 209) ^ (int_hash(key2 * 413)));
} }

View file

@ -9,26 +9,26 @@ class [[gnu::packed]] IPv4Address
{ {
public: public:
IPv4Address() {} IPv4Address() {}
IPv4Address(const byte data[4]) IPv4Address(const u8 data[4])
{ {
m_data[0] = data[0]; m_data[0] = data[0];
m_data[1] = data[1]; m_data[1] = data[1];
m_data[2] = data[2]; m_data[2] = data[2];
m_data[3] = data[3]; m_data[3] = data[3];
} }
IPv4Address(byte a, byte b, byte c, byte d) IPv4Address(u8 a, u8 b, u8 c, u8 d)
{ {
m_data[0] = a; m_data[0] = a;
m_data[1] = b; m_data[1] = b;
m_data[2] = c; m_data[2] = c;
m_data[3] = d; m_data[3] = d;
} }
IPv4Address(NetworkOrdered<dword> address) IPv4Address(NetworkOrdered<u32> address)
: m_data_as_dword(address) : m_data_as_u32(address)
{ {
} }
byte operator[](int i) const u8 operator[](int i) const
{ {
ASSERT(i >= 0 && i < 4); ASSERT(i >= 0 && i < 4);
return m_data[i]; return m_data[i];
@ -39,13 +39,13 @@ public:
return String::format("%u.%u.%u.%u", m_data[0], m_data[1], m_data[2], m_data[3]); return String::format("%u.%u.%u.%u", m_data[0], m_data[1], m_data[2], m_data[3]);
} }
bool operator==(const IPv4Address& other) const { return m_data_as_dword == other.m_data_as_dword; } bool operator==(const IPv4Address& other) const { return m_data_as_u32 == other.m_data_as_u32; }
bool operator!=(const IPv4Address& other) const { return m_data_as_dword != other.m_data_as_dword; } bool operator!=(const IPv4Address& other) const { return m_data_as_u32 != other.m_data_as_u32; }
private: private:
union { union {
byte m_data[4]; u8 m_data[4];
dword m_data_as_dword { 0 }; u32 m_data_as_u32 { 0 };
}; };
}; };

View file

@ -117,18 +117,18 @@ public:
#endif #endif
} }
dword to_dword(dword default_value = 0) const u32 to_u32(u32 default_value = 0) const
{ {
if (!is_number()) if (!is_number())
return default_value; return default_value;
#ifdef KERNEL #ifdef KERNEL
return (dword)m_value.as_int; return (u32)m_value.as_int;
#else #else
if (type() == Type::Int) if (type() == Type::Int)
return (dword)m_value.as_int; return (u32)m_value.as_int;
if (type() == Type::UnsignedInt) if (type() == Type::UnsignedInt)
return m_value.as_uint; return m_value.as_uint;
return (dword)m_value.as_double; return (u32)m_value.as_double;
#endif #endif
} }

View file

@ -12,10 +12,10 @@ extern "C" size_t strlen(const char*);
#endif #endif
template<typename PutChFunc, typename T> template<typename PutChFunc, typename T>
[[gnu::always_inline]] inline int print_hex(PutChFunc putch, char*& bufptr, T number, byte fields) [[gnu::always_inline]] inline int print_hex(PutChFunc putch, char*& bufptr, T number, u8 fields)
{ {
int ret = 0; int ret = 0;
byte shr_count = fields * 4; u8 shr_count = fields * 4;
while (shr_count) { while (shr_count) {
shr_count -= 4; shr_count -= 4;
putch(bufptr, printf_hex_digits[(number >> shr_count) & 0x0F]); putch(bufptr, printf_hex_digits[(number >> shr_count) & 0x0F]);
@ -25,9 +25,9 @@ template<typename PutChFunc, typename T>
} }
template<typename PutChFunc> template<typename PutChFunc>
[[gnu::always_inline]] inline int print_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth) [[gnu::always_inline]] inline int print_number(PutChFunc putch, char*& bufptr, u32 number, bool leftPad, bool zeroPad, u32 fieldWidth)
{ {
dword divisor = 1000000000; u32 divisor = 1000000000;
char ch; char ch;
char padding = 1; char padding = 1;
char buf[16]; char buf[16];
@ -66,9 +66,9 @@ template<typename PutChFunc>
} }
template<typename PutChFunc> template<typename PutChFunc>
[[gnu::always_inline]] inline int print_qword(PutChFunc putch, char*& bufptr, qword number, bool leftPad, bool zeroPad, dword fieldWidth) [[gnu::always_inline]] inline int print_u64(PutChFunc putch, char*& bufptr, u64 number, bool leftPad, bool zeroPad, u32 fieldWidth)
{ {
qword divisor = 10000000000000000000LLU; u64 divisor = 10000000000000000000LLU;
char ch; char ch;
char padding = 1; char padding = 1;
char buf[16]; char buf[16];
@ -107,19 +107,19 @@ template<typename PutChFunc>
} }
template<typename PutChFunc> template<typename PutChFunc>
[[gnu::always_inline]] inline int print_signed_qword(PutChFunc putch, char*& bufptr, signed_qword number, bool leftPad, bool zeroPad, dword fieldWidth) [[gnu::always_inline]] inline int print_i64(PutChFunc putch, char*& bufptr, i64 number, bool leftPad, bool zeroPad, u32 fieldWidth)
{ {
if (number < 0) { if (number < 0) {
putch(bufptr, '-'); putch(bufptr, '-');
return print_qword(putch, bufptr, 0 - number, leftPad, zeroPad, fieldWidth) + 1; return print_u64(putch, bufptr, 0 - number, leftPad, zeroPad, fieldWidth) + 1;
} }
return print_qword(putch, bufptr, number, leftPad, zeroPad, fieldWidth); return print_u64(putch, bufptr, number, leftPad, zeroPad, fieldWidth);
} }
template<typename PutChFunc> template<typename PutChFunc>
[[gnu::always_inline]] inline int print_octal_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth) [[gnu::always_inline]] inline int print_octal_number(PutChFunc putch, char*& bufptr, u32 number, bool leftPad, bool zeroPad, u32 fieldWidth)
{ {
dword divisor = 134217728; u32 divisor = 134217728;
char ch; char ch;
char padding = 1; char padding = 1;
char buf[32]; char buf[32];
@ -158,7 +158,7 @@ template<typename PutChFunc>
} }
template<typename PutChFunc> template<typename PutChFunc>
[[gnu::always_inline]] inline int print_string(PutChFunc putch, char*& bufptr, const char* str, bool leftPad, dword fieldWidth) [[gnu::always_inline]] inline int print_string(PutChFunc putch, char*& bufptr, const char* str, bool leftPad, u32 fieldWidth)
{ {
size_t len = strlen(str); size_t len = strlen(str);
if (!fieldWidth || fieldWidth < len) if (!fieldWidth || fieldWidth < len)
@ -178,7 +178,7 @@ template<typename PutChFunc>
} }
template<typename PutChFunc> template<typename PutChFunc>
[[gnu::always_inline]] inline int print_signed_number(PutChFunc putch, char*& bufptr, int number, bool leftPad, bool zeroPad, dword fieldWidth) [[gnu::always_inline]] inline int print_signed_number(PutChFunc putch, char*& bufptr, int number, bool leftPad, bool zeroPad, u32 fieldWidth)
{ {
if (number < 0) { if (number < 0) {
putch(bufptr, '-'); putch(bufptr, '-');
@ -248,22 +248,22 @@ template<typename PutChFunc>
break; break;
case 'u': case 'u':
ret += print_number(putch, bufptr, va_arg(ap, dword), left_pad, zeroPad, fieldWidth); ret += print_number(putch, bufptr, va_arg(ap, u32), left_pad, zeroPad, fieldWidth);
break; break;
case 'Q': case 'Q':
ret += print_qword(putch, bufptr, va_arg(ap, qword), left_pad, zeroPad, fieldWidth); ret += print_u64(putch, bufptr, va_arg(ap, u64), left_pad, zeroPad, fieldWidth);
break; break;
case 'q': case 'q':
ret += print_hex(putch, bufptr, va_arg(ap, qword), 16); ret += print_hex(putch, bufptr, va_arg(ap, u64), 16);
break; break;
#ifndef KERNEL #ifndef KERNEL
case 'g': case 'g':
case 'f': case 'f':
// FIXME: Print as float! // FIXME: Print as float!
ret += print_signed_qword(putch, bufptr, (qword)va_arg(ap, double), left_pad, zeroPad, fieldWidth); ret += print_i64(putch, bufptr, (u64)va_arg(ap, double), left_pad, zeroPad, fieldWidth);
break; break;
#endif #endif
@ -272,7 +272,7 @@ template<typename PutChFunc>
putch(bufptr, '0'); putch(bufptr, '0');
++ret; ++ret;
} }
ret += print_octal_number(putch, bufptr, va_arg(ap, dword), left_pad, zeroPad, fieldWidth); ret += print_octal_number(putch, bufptr, va_arg(ap, u32), left_pad, zeroPad, fieldWidth);
break; break;
case 'x': case 'x':
@ -281,7 +281,7 @@ template<typename PutChFunc>
putch(bufptr, 'x'); putch(bufptr, 'x');
ret += 2; ret += 2;
} }
ret += print_hex(putch, bufptr, va_arg(ap, dword), 8); ret += print_hex(putch, bufptr, va_arg(ap, u32), 8);
break; break;
case 'w': case 'w':
@ -306,7 +306,7 @@ template<typename PutChFunc>
putch(bufptr, '0'); putch(bufptr, '0');
putch(bufptr, 'x'); putch(bufptr, 'x');
ret += 2; ret += 2;
ret += print_hex(putch, bufptr, va_arg(ap, dword), 8); ret += print_hex(putch, bufptr, va_arg(ap, u32), 8);
break; break;
} }
} else { } else {

View file

@ -10,11 +10,11 @@ void* mmx_memcpy(void* dest, const void* src, size_t len)
{ {
ASSERT(len >= 1024); ASSERT(len >= 1024);
auto* dest_ptr = (byte*)dest; auto* dest_ptr = (u8*)dest;
auto* src_ptr = (const byte*)src; auto* src_ptr = (const u8*)src;
if ((dword)dest_ptr & 7) { if ((u32)dest_ptr & 7) {
dword prologue = 8 - ((dword)dest_ptr & 7); u32 prologue = 8 - ((u32)dest_ptr & 7);
len -= prologue; len -= prologue;
asm volatile( asm volatile(
"rep movsb\n" "rep movsb\n"
@ -22,7 +22,7 @@ void* mmx_memcpy(void* dest, const void* src, size_t len)
: "0"(src_ptr), "1"(dest_ptr), "2"(prologue) : "0"(src_ptr), "1"(dest_ptr), "2"(prologue)
: "memory"); : "memory");
} }
for (dword i = len / 64; i; --i) { for (u32 i = len / 64; i; --i) {
asm volatile( asm volatile(
"movq (%0), %%mm0\n" "movq (%0), %%mm0\n"
"movq 8(%0), %%mm1\n" "movq 8(%0), %%mm1\n"

View file

@ -15,7 +15,7 @@
extern "C" void* mmx_memcpy(void* to, const void* from, size_t); extern "C" void* mmx_memcpy(void* to, const void* from, size_t);
#endif #endif
[[gnu::always_inline]] inline void fast_dword_copy(dword* dest, const dword* src, size_t count) [[gnu::always_inline]] inline void fast_u32_copy(u32* dest, const u32* src, size_t count)
{ {
#ifndef KERNEL #ifndef KERNEL
if (count >= 256) { if (count >= 256) {
@ -30,7 +30,7 @@ extern "C" void* mmx_memcpy(void* to, const void* from, size_t);
: "memory"); : "memory");
} }
[[gnu::always_inline]] inline void fast_dword_fill(dword* dest, dword value, size_t count) [[gnu::always_inline]] inline void fast_u32_fill(u32* dest, u32 value, size_t count)
{ {
asm volatile( asm volatile(
"rep stosl\n" "rep stosl\n"
@ -39,7 +39,7 @@ extern "C" void* mmx_memcpy(void* to, const void* from, size_t);
: "memory"); : "memory");
} }
inline constexpr dword round_up_to_power_of_two(dword value, dword power_of_two) inline constexpr u32 round_up_to_power_of_two(u32 value, u32 power_of_two)
{ {
return ((value - 1) & ~(power_of_two - 1)) + power_of_two; return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
} }

View file

@ -124,7 +124,7 @@ ByteBuffer String::to_byte_buffer() const
{ {
if (!m_impl) if (!m_impl)
return nullptr; return nullptr;
return ByteBuffer::copy(reinterpret_cast<const byte*>(characters()), length()); return ByteBuffer::copy(reinterpret_cast<const u8*>(characters()), length());
} }
int String::to_int(bool& ok) const int String::to_int(bool& ok) const

View file

@ -66,11 +66,11 @@ private:
char m_inline_buffer[0]; char m_inline_buffer[0];
}; };
inline constexpr dword string_hash(const char* characters, int length) inline constexpr u32 string_hash(const char* characters, int length)
{ {
dword hash = 0; u32 hash = 0;
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
hash += (dword)characters[i]; hash += (u32)characters[i];
hash += (hash << 10); hash += (hash << 10);
hash ^= (hash >> 6); hash ^= (hash >> 6);
} }

View file

@ -27,9 +27,9 @@ struct Traits<unsigned> : public GenericTraits<unsigned> {
}; };
template<> template<>
struct Traits<word> : public GenericTraits<word> { struct Traits<u16> : public GenericTraits<u16> {
static unsigned hash(word u) { return int_hash(u); } static unsigned hash(u16 u) { return int_hash(u); }
static void dump(word u) { kprintf("%u", u); } static void dump(u16 u) { kprintf("%u", u); }
}; };
template<typename T> template<typename T>

View file

@ -21,33 +21,23 @@ static_assert(sizeof(i16) == 2);
static_assert(sizeof(i32) == 4); static_assert(sizeof(i32) == 4);
static_assert(sizeof(i64) == 8); static_assert(sizeof(i64) == 8);
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned int dword;
typedef unsigned long long int qword;
typedef signed char signed_byte;
typedef signed short signed_word;
typedef signed int signed_dword;
typedef signed long long int signed_qword;
typedef __SIZE_TYPE__ size_t; typedef __SIZE_TYPE__ size_t;
typedef signed_dword ssize_t; typedef i32 ssize_t;
static_assert(sizeof(size_t) == sizeof(dword)); static_assert(sizeof(size_t) == sizeof(u32));
static_assert(sizeof(ssize_t) == sizeof(signed_dword)); static_assert(sizeof(ssize_t) == sizeof(i32));
typedef __PTRDIFF_TYPE__ ptrdiff_t; typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef byte uint8_t; typedef u8 uint8_t;
typedef word uint16_t; typedef u16 uint16_t;
typedef dword uint32_t; typedef u32 uint32_t;
typedef qword uint64_t; typedef u64 uint64_t;
typedef signed_byte int8_t; typedef i8 int8_t;
typedef signed_word int16_t; typedef i16 int16_t;
typedef signed_dword int32_t; typedef i32 int32_t;
typedef signed_qword int64_t; typedef i64 int64_t;
#else #else
# include <stdint.h> # include <stdint.h>
@ -62,16 +52,6 @@ typedef int8_t i8;
typedef int16_t i16; typedef int16_t i16;
typedef int32_t i32; typedef int32_t i32;
typedef int64_t i64; typedef int64_t i64;
typedef uint8_t byte;
typedef uint16_t word;
typedef uint32_t dword;
typedef uint64_t qword;
typedef int8_t signed_byte;
typedef int16_t signed_word;
typedef int32_t signed_dword;
typedef int64_t signed_qword;
#endif #endif
constexpr unsigned KB = 1024; constexpr unsigned KB = 1024;
@ -82,7 +62,7 @@ namespace std {
typedef decltype(nullptr) nullptr_t; typedef decltype(nullptr) nullptr_t;
} }
static constexpr dword explode_byte(byte b) static constexpr u32 explode_byte(u8 b)
{ {
return b << 24 | b << 16 | b << 8 | b; return b << 24 | b << 16 | b << 8 | b;
} }

View file

@ -427,7 +427,7 @@ private:
int m_size { 0 }; int m_size { 0 };
int m_capacity { 0 }; int m_capacity { 0 };
alignas(T) byte m_inline_buffer_storage[sizeof(T) * inline_capacity]; alignas(T) u8 m_inline_buffer_storage[sizeof(T) * inline_capacity];
T* m_outline_buffer { nullptr }; T* m_outline_buffer { nullptr };
}; };

View file

@ -91,12 +91,12 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Font>&& edited_fon
demo_label_2->update(); demo_label_2->update();
}; };
m_glyph_editor_widget->on_glyph_altered = [this, update_demo](byte glyph) { m_glyph_editor_widget->on_glyph_altered = [this, update_demo](u8 glyph) {
m_glyph_map_widget->update_glyph(glyph); m_glyph_map_widget->update_glyph(glyph);
update_demo(); update_demo();
}; };
m_glyph_map_widget->on_glyph_selected = [this, info_label, width_spinbox](byte glyph) { m_glyph_map_widget->on_glyph_selected = [this, info_label, width_spinbox](u8 glyph) {
m_glyph_editor_widget->set_glyph(glyph); m_glyph_editor_widget->set_glyph(glyph);
width_spinbox->set_value(m_edited_font->glyph_width(m_glyph_map_widget->selected_glyph())); width_spinbox->set_value(m_edited_font->glyph_width(m_glyph_map_widget->selected_glyph()));
info_label->set_text(String::format("0x%b (%c)", glyph, glyph)); info_label->set_text(String::format("0x%b (%c)", glyph, glyph));

View file

@ -15,7 +15,7 @@ GlyphEditorWidget::~GlyphEditorWidget()
{ {
} }
void GlyphEditorWidget::set_glyph(byte glyph) void GlyphEditorWidget::set_glyph(u8 glyph)
{ {
if (m_glyph == glyph) if (m_glyph == glyph)
return; return;

View file

@ -6,8 +6,8 @@ public:
GlyphEditorWidget(Font&, GWidget* parent); GlyphEditorWidget(Font&, GWidget* parent);
virtual ~GlyphEditorWidget() override; virtual ~GlyphEditorWidget() override;
byte glyph() const { return m_glyph; } u8 glyph() const { return m_glyph; }
void set_glyph(byte); void set_glyph(u8);
int preferred_width() const; int preferred_width() const;
int preferred_height() const; int preferred_height() const;
@ -15,7 +15,7 @@ public:
Font& font() { return *m_font; } Font& font() { return *m_font; }
const Font& font() const { return *m_font; } const Font& font() const { return *m_font; }
Function<void(byte)> on_glyph_altered; Function<void(u8)> on_glyph_altered;
private: private:
virtual void paint_event(GPaintEvent&) override; virtual void paint_event(GPaintEvent&) override;
@ -25,6 +25,6 @@ private:
void draw_at_mouse(const GMouseEvent&); void draw_at_mouse(const GMouseEvent&);
RefPtr<Font> m_font; RefPtr<Font> m_font;
byte m_glyph { 0 }; u8 m_glyph { 0 };
int m_scale { 10 }; int m_scale { 10 };
}; };

View file

@ -25,7 +25,7 @@ int GlyphMapWidget::preferred_height() const
return rows() * (font().glyph_height() + m_vertical_spacing) + 2 + frame_thickness() * 2; return rows() * (font().glyph_height() + m_vertical_spacing) + 2 + frame_thickness() * 2;
} }
void GlyphMapWidget::set_selected_glyph(byte glyph) void GlyphMapWidget::set_selected_glyph(u8 glyph)
{ {
if (m_selected_glyph == glyph) if (m_selected_glyph == glyph)
return; return;
@ -35,7 +35,7 @@ void GlyphMapWidget::set_selected_glyph(byte glyph)
update(); update();
} }
Rect GlyphMapWidget::get_outer_rect(byte glyph) const Rect GlyphMapWidget::get_outer_rect(u8 glyph) const
{ {
int row = glyph / columns(); int row = glyph / columns();
int column = glyph % columns(); int column = glyph % columns();
@ -48,7 +48,7 @@ Rect GlyphMapWidget::get_outer_rect(byte glyph) const
.translated(frame_thickness(), frame_thickness()); .translated(frame_thickness(), frame_thickness());
} }
void GlyphMapWidget::update_glyph(byte glyph) void GlyphMapWidget::update_glyph(u8 glyph)
{ {
update(get_outer_rect(glyph)); update(get_outer_rect(glyph));
} }
@ -63,7 +63,7 @@ void GlyphMapWidget::paint_event(GPaintEvent& event)
painter.set_font(font()); painter.set_font(font());
painter.fill_rect(frame_inner_rect(), Color::White); painter.fill_rect(frame_inner_rect(), Color::White);
byte glyph = 0; u8 glyph = 0;
for (int row = 0; row < rows(); ++row) { for (int row = 0; row < rows(); ++row) {
for (int column = 0; column < columns(); ++column, ++glyph) { for (int column = 0; column < columns(); ++column, ++glyph) {

View file

@ -8,8 +8,8 @@ public:
GlyphMapWidget(Font&, GWidget* parent); GlyphMapWidget(Font&, GWidget* parent);
virtual ~GlyphMapWidget() override; virtual ~GlyphMapWidget() override;
byte selected_glyph() const { return m_selected_glyph; } u8 selected_glyph() const { return m_selected_glyph; }
void set_selected_glyph(byte); void set_selected_glyph(u8);
int rows() const { return m_rows; } int rows() const { return m_rows; }
int columns() const { return 256 / m_rows; } int columns() const { return 256 / m_rows; }
@ -20,19 +20,19 @@ public:
Font& font() { return *m_font; } Font& font() { return *m_font; }
const Font& font() const { return *m_font; } const Font& font() const { return *m_font; }
void update_glyph(byte); void update_glyph(u8);
Function<void(byte)> on_glyph_selected; Function<void(u8)> on_glyph_selected;
private: private:
virtual void paint_event(GPaintEvent&) override; virtual void paint_event(GPaintEvent&) override;
virtual void mousedown_event(GMouseEvent&) override; virtual void mousedown_event(GMouseEvent&) override;
Rect get_outer_rect(byte glyph) const; Rect get_outer_rect(u8 glyph) const;
RefPtr<Font> m_font; RefPtr<Font> m_font;
int m_rows { 8 }; int m_rows { 8 };
int m_horizontal_spacing { 2 }; int m_horizontal_spacing { 2 };
int m_vertical_spacing { 2 }; int m_vertical_spacing { 2 };
byte m_selected_glyph { 0 }; u8 m_selected_glyph { 0 };
}; };

View file

@ -64,16 +64,16 @@ void MemoryStatsWidget::refresh()
auto file_contents = m_proc_memstat.read_all(); auto file_contents = m_proc_memstat.read_all();
auto json = JsonValue::from_string(file_contents).as_object(); auto json = JsonValue::from_string(file_contents).as_object();
unsigned kmalloc_eternal_allocated = json.get("kmalloc_eternal_allocated").to_dword(); unsigned kmalloc_eternal_allocated = json.get("kmalloc_eternal_allocated").to_u32();
(void)kmalloc_eternal_allocated; (void)kmalloc_eternal_allocated;
unsigned kmalloc_allocated = json.get("kmalloc_allocated").to_dword(); unsigned kmalloc_allocated = json.get("kmalloc_allocated").to_u32();
unsigned kmalloc_available = json.get("kmalloc_available").to_dword(); unsigned kmalloc_available = json.get("kmalloc_available").to_u32();
unsigned user_physical_allocated = json.get("user_physical_allocated").to_dword(); unsigned user_physical_allocated = json.get("user_physical_allocated").to_u32();
unsigned user_physical_available = json.get("user_physical_available").to_dword(); unsigned user_physical_available = json.get("user_physical_available").to_u32();
unsigned super_physical_alloc = json.get("super_physical_allocated").to_dword(); unsigned super_physical_alloc = json.get("super_physical_allocated").to_u32();
unsigned super_physical_free = json.get("super_physical_available").to_dword(); unsigned super_physical_free = json.get("super_physical_available").to_u32();
unsigned kmalloc_call_count = json.get("kmalloc_call_count").to_dword(); unsigned kmalloc_call_count = json.get("kmalloc_call_count").to_u32();
unsigned kfree_call_count = json.get("kfree_call_count").to_dword(); unsigned kfree_call_count = json.get("kfree_call_count").to_u32();
size_t kmalloc_sum_available = kmalloc_allocated + kmalloc_available; size_t kmalloc_sum_available = kmalloc_allocated + kmalloc_available;
size_t user_pages_available = user_physical_allocated + user_physical_available; size_t user_pages_available = user_physical_allocated + user_physical_available;

View file

@ -198,12 +198,12 @@ void ProcessModel::update()
auto json = JsonValue::from_string({ file_contents.data(), file_contents.size() }); auto json = JsonValue::from_string({ file_contents.data(), file_contents.size() });
json.as_array().for_each([&](auto& value) { json.as_array().for_each([&](auto& value) {
const JsonObject& process_object = value.as_object(); const JsonObject& process_object = value.as_object();
pid_t pid = process_object.get("pid").to_dword(); pid_t pid = process_object.get("pid").to_u32();
unsigned nsched = process_object.get("times_scheduled").to_dword(); unsigned nsched = process_object.get("times_scheduled").to_u32();
ProcessState state; ProcessState state;
state.pid = pid; state.pid = pid;
state.nsched = nsched; state.nsched = nsched;
unsigned uid = process_object.get("uid").to_dword(); unsigned uid = process_object.get("uid").to_u32();
{ {
auto it = m_usernames.find((uid_t)uid); auto it = m_usernames.find((uid_t)uid);
if (it != m_usernames.end()) if (it != m_usernames.end())
@ -212,11 +212,11 @@ void ProcessModel::update()
state.user = String::number(uid); state.user = String::number(uid);
} }
state.priority = process_object.get("priority").to_string(); state.priority = process_object.get("priority").to_string();
state.syscalls = process_object.get("syscall_count").to_dword(); state.syscalls = process_object.get("syscall_count").to_u32();
state.state = process_object.get("state").to_string(); state.state = process_object.get("state").to_string();
state.name = process_object.get("name").to_string(); state.name = process_object.get("name").to_string();
state.virtual_size = process_object.get("amount_virtual").to_dword(); state.virtual_size = process_object.get("amount_virtual").to_u32();
state.physical_size = process_object.get("amount_resident").to_dword(); state.physical_size = process_object.get("amount_resident").to_u32();
sum_nsched += nsched; sum_nsched += nsched;
{ {
auto it = m_processes.find(pid); auto it = m_processes.find(pid);
@ -240,7 +240,7 @@ void ProcessModel::update()
continue; continue;
} }
auto& process = *it.value; auto& process = *it.value;
dword nsched_diff = process.current_state.nsched - process.previous_state.nsched; u32 nsched_diff = process.current_state.nsched - process.previous_state.nsched;
process.current_state.cpu_percent = ((float)nsched_diff * 100) / (float)(sum_nsched - last_sum_nsched); process.current_state.cpu_percent = ((float)nsched_diff * 100) / (float)(sum_nsched - last_sum_nsched);
if (it.key != 0) { if (it.key != 0) {
total_cpu_percent += process.current_state.cpu_percent; total_cpu_percent += process.current_state.cpu_percent;

View file

@ -17,8 +17,8 @@
#include <unistd.h> #include <unistd.h>
//#define TERMINAL_DEBUG //#define TERMINAL_DEBUG
byte Terminal::Attribute::default_foreground_color = 7; u8 Terminal::Attribute::default_foreground_color = 7;
byte Terminal::Attribute::default_background_color = 0; u8 Terminal::Attribute::default_background_color = 0;
Terminal::Terminal(int ptm_fd, RefPtr<CConfigFile> config) Terminal::Terminal(int ptm_fd, RefPtr<CConfigFile> config)
: m_ptm_fd(ptm_fd) : m_ptm_fd(ptm_fd)
@ -45,7 +45,7 @@ Terminal::Terminal(int ptm_fd, RefPtr<CConfigFile> config)
set_font(Font::load_from_file(font_entry)); set_font(Font::load_from_file(font_entry));
m_notifier.on_ready_to_read = [this] { m_notifier.on_ready_to_read = [this] {
byte buffer[BUFSIZ]; u8 buffer[BUFSIZ];
ssize_t nread = read(m_ptm_fd, buffer, sizeof(buffer)); ssize_t nread = read(m_ptm_fd, buffer, sizeof(buffer));
if (nread < 0) { if (nread < 0) {
dbgprintf("Terminal read error: %s\n", strerror(errno)); dbgprintf("Terminal read error: %s\n", strerror(errno));
@ -69,7 +69,7 @@ Terminal::Terminal(int ptm_fd, RefPtr<CConfigFile> config)
m_config->read_num_entry("Window", "Height", 25)); m_config->read_num_entry("Window", "Height", 25));
} }
Terminal::Line::Line(word length) Terminal::Line::Line(u16 length)
{ {
set_length(length); set_length(length);
} }
@ -80,11 +80,11 @@ Terminal::Line::~Line()
delete[] attributes; delete[] attributes;
} }
void Terminal::Line::set_length(word new_length) void Terminal::Line::set_length(u16 new_length)
{ {
if (m_length == new_length) if (m_length == new_length)
return; return;
auto* new_characters = new byte[new_length]; auto* new_characters = new u8[new_length];
auto* new_attributes = new Attribute[new_length]; auto* new_attributes = new Attribute[new_length];
memset(new_characters, ' ', new_length); memset(new_characters, ' ', new_length);
delete[] characters; delete[] characters;
@ -98,7 +98,7 @@ void Terminal::Line::clear(Attribute attribute)
{ {
if (dirty) { if (dirty) {
memset(characters, ' ', m_length); memset(characters, ' ', m_length);
for (word i = 0; i < m_length; ++i) for (u16 i = 0; i < m_length; ++i)
attributes[i] = attribute; attributes[i] = attribute;
return; return;
} }
@ -125,17 +125,17 @@ void Terminal::clear()
set_cursor(0, 0); set_cursor(0, 0);
} }
inline bool is_valid_parameter_character(byte ch) inline bool is_valid_parameter_character(u8 ch)
{ {
return ch >= 0x30 && ch <= 0x3f; return ch >= 0x30 && ch <= 0x3f;
} }
inline bool is_valid_intermediate_character(byte ch) inline bool is_valid_intermediate_character(u8 ch)
{ {
return ch >= 0x20 && ch <= 0x2f; return ch >= 0x20 && ch <= 0x2f;
} }
inline bool is_valid_final_character(byte ch) inline bool is_valid_final_character(u8 ch)
{ {
return ch >= 0x40 && ch <= 0x7e; return ch >= 0x40 && ch <= 0x7e;
} }
@ -481,7 +481,7 @@ void Terminal::escape$S(const ParamVector& params)
if (params.size() >= 1) if (params.size() >= 1)
count = params[0]; count = params[0];
for (word i = 0; i < count; i++) for (u16 i = 0; i < count; i++)
scroll_up(); scroll_up();
} }
@ -491,7 +491,7 @@ void Terminal::escape$T(const ParamVector& params)
if (params.size() >= 1) if (params.size() >= 1)
count = params[0]; count = params[0];
for (word i = 0; i < count; i++) for (u16 i = 0; i < count; i++)
scroll_down(); scroll_down();
} }
@ -577,7 +577,7 @@ void Terminal::execute_xterm_command()
m_xterm_param2.clear_with_capacity(); m_xterm_param2.clear_with_capacity();
} }
void Terminal::execute_escape_sequence(byte final) void Terminal::execute_escape_sequence(u8 final)
{ {
bool question_param = false; bool question_param = false;
m_final = final; m_final = final;
@ -701,7 +701,7 @@ void Terminal::execute_escape_sequence(byte final)
void Terminal::newline() void Terminal::newline()
{ {
word new_row = m_cursor_row; u16 new_row = m_cursor_row;
if (m_cursor_row == m_scroll_region_bottom) { if (m_cursor_row == m_scroll_region_bottom) {
scroll_up(); scroll_up();
} else { } else {
@ -744,7 +744,7 @@ void Terminal::set_cursor(unsigned a_row, unsigned a_column)
invalidate_cursor(); invalidate_cursor();
} }
void Terminal::put_character_at(unsigned row, unsigned column, byte ch) void Terminal::put_character_at(unsigned row, unsigned column, u8 ch)
{ {
ASSERT(row < rows()); ASSERT(row < rows());
ASSERT(column < columns()); ASSERT(column < columns());
@ -757,7 +757,7 @@ void Terminal::put_character_at(unsigned row, unsigned column, byte ch)
m_last_char = ch; m_last_char = ch;
} }
void Terminal::on_char(byte ch) void Terminal::on_char(u8 ch)
{ {
#ifdef TERMINAL_DEBUG #ifdef TERMINAL_DEBUG
dbgprintf("Terminal::on_char: %b (%c), fg=%u, bg=%u\n", ch, ch, m_current_attribute.foreground_color, m_current_attribute.background_color); dbgprintf("Terminal::on_char: %b (%c), fg=%u, bg=%u\n", ch, ch, m_current_attribute.foreground_color, m_current_attribute.background_color);
@ -913,7 +913,7 @@ void Terminal::unimplemented_xterm_escape()
inject_string(message); inject_string(message);
} }
void Terminal::set_size(word columns, word rows) void Terminal::set_size(u16 columns, u16 rows)
{ {
if (columns == m_columns && rows == m_rows) if (columns == m_columns && rows == m_rows)
return; return;
@ -965,14 +965,14 @@ void Terminal::set_size(word columns, word rows)
ASSERT(rc == 0); ASSERT(rc == 0);
} }
Rect Terminal::glyph_rect(word row, word column) Rect Terminal::glyph_rect(u16 row, u16 column)
{ {
int y = row * m_line_height; int y = row * m_line_height;
int x = column * font().glyph_width('x'); int x = column * font().glyph_width('x');
return { x + frame_thickness() + m_inset, y + frame_thickness() + m_inset, font().glyph_width('x'), font().glyph_height() }; return { x + frame_thickness() + m_inset, y + frame_thickness() + m_inset, font().glyph_width('x'), font().glyph_height() };
} }
Rect Terminal::row_rect(word row) Rect Terminal::row_rect(u16 row)
{ {
int y = row * m_line_height; int y = row * m_line_height;
Rect rect = { frame_thickness() + m_inset, y + frame_thickness() + m_inset, font().glyph_width('x') * m_columns, font().glyph_height() }; Rect rect = { frame_thickness() + m_inset, y + frame_thickness() + m_inset, font().glyph_width('x') * m_columns, font().glyph_height() };
@ -1083,14 +1083,14 @@ void Terminal::paint_event(GPaintEvent& event)
painter.fill_rect(frame_inner_rect(), Color(Color::Black).with_alpha(m_opacity)); painter.fill_rect(frame_inner_rect(), Color(Color::Black).with_alpha(m_opacity));
invalidate_cursor(); invalidate_cursor();
for (word row = 0; row < m_rows; ++row) { for (u16 row = 0; row < m_rows; ++row) {
auto& line = this->line(row); auto& line = this->line(row);
bool has_only_one_background_color = line.has_only_one_background_color(); bool has_only_one_background_color = line.has_only_one_background_color();
if (m_visual_beep_timer.is_active()) if (m_visual_beep_timer.is_active())
painter.fill_rect(row_rect(row), Color::Red); painter.fill_rect(row_rect(row), Color::Red);
else if (has_only_one_background_color) else if (has_only_one_background_color)
painter.fill_rect(row_rect(row), lookup_color(line.attributes[0].background_color).with_alpha(m_opacity)); painter.fill_rect(row_rect(row), lookup_color(line.attributes[0].background_color).with_alpha(m_opacity));
for (word column = 0; column < m_columns; ++column) { for (u16 column = 0; column < m_columns; ++column) {
char ch = line.characters[column]; char ch = line.characters[column];
bool should_reverse_fill_for_cursor_or_selection = (m_cursor_blink_state && m_in_active_window && row == m_cursor_row && column == m_cursor_column) bool should_reverse_fill_for_cursor_or_selection = (m_cursor_blink_state && m_in_active_window && row == m_cursor_row && column == m_cursor_column)
|| selection_contains({ row, column }); || selection_contains({ row, column });
@ -1167,7 +1167,7 @@ void Terminal::update_cursor()
flush_dirty_lines(); flush_dirty_lines();
} }
void Terminal::set_opacity(byte new_opacity) void Terminal::set_opacity(u8 new_opacity)
{ {
if (m_opacity == new_opacity) if (m_opacity == new_opacity)
return; return;

View file

@ -61,14 +61,14 @@ public:
virtual ~Terminal() override; virtual ~Terminal() override;
void create_window(); void create_window();
void on_char(byte); void on_char(u8);
void flush_dirty_lines(); void flush_dirty_lines();
void force_repaint(); void force_repaint();
void apply_size_increments_to_window(GWindow&); void apply_size_increments_to_window(GWindow&);
void set_opacity(byte); void set_opacity(u8);
float opacity() { return m_opacity; }; float opacity() { return m_opacity; };
bool should_beep() { return m_should_beep; } bool should_beep() { return m_should_beep; }
void set_should_beep(bool sb) { m_should_beep = sb; }; void set_should_beep(bool sb) { m_should_beep = sb; };
@ -98,7 +98,7 @@ private:
void scroll_down(); void scroll_down();
void newline(); void newline();
void set_cursor(unsigned row, unsigned column); void set_cursor(unsigned row, unsigned column);
void put_character_at(unsigned row, unsigned column, byte ch); void put_character_at(unsigned row, unsigned column, u8 ch);
void invalidate_cursor(); void invalidate_cursor();
void set_window_title(const String&); void set_window_title(const String&);
@ -131,18 +131,18 @@ private:
void clear(); void clear();
void set_size(word columns, word rows); void set_size(u16 columns, u16 rows);
word columns() const { return m_columns; } u16 columns() const { return m_columns; }
word rows() const { return m_rows; } u16 rows() const { return m_rows; }
Rect glyph_rect(word row, word column); Rect glyph_rect(u16 row, u16 column);
Rect row_rect(word row); Rect row_rect(u16 row);
void update_cursor(); void update_cursor();
struct Attribute { struct Attribute {
Attribute() { reset(); } Attribute() { reset(); }
static byte default_foreground_color; static u8 default_foreground_color;
static byte default_background_color; static u8 default_background_color;
void reset() void reset()
{ {
@ -150,8 +150,8 @@ private:
background_color = default_background_color; background_color = default_background_color;
flags = Flags::NoAttributes; flags = Flags::NoAttributes;
} }
byte foreground_color; u8 foreground_color;
byte background_color; u8 background_color;
enum Flags { enum Flags {
NoAttributes = 0x00, NoAttributes = 0x00,
@ -180,15 +180,15 @@ private:
}; };
struct Line { struct Line {
explicit Line(word columns); explicit Line(u16 columns);
~Line(); ~Line();
void clear(Attribute); void clear(Attribute);
bool has_only_one_background_color() const; bool has_only_one_background_color() const;
void set_length(word); void set_length(u16);
byte* characters { nullptr }; u8* characters { nullptr };
Attribute* attributes { nullptr }; Attribute* attributes { nullptr };
bool dirty { false }; bool dirty { false };
word m_length { 0 }; u16 m_length { 0 };
}; };
Line& line(size_t index) Line& line(size_t index)
{ {
@ -209,20 +209,20 @@ private:
int m_scroll_region_top { 0 }; int m_scroll_region_top { 0 };
int m_scroll_region_bottom { 0 }; int m_scroll_region_bottom { 0 };
word m_columns { 0 }; u16 m_columns { 0 };
word m_rows { 0 }; u16 m_rows { 0 };
byte m_cursor_row { 0 }; u8 m_cursor_row { 0 };
byte m_cursor_column { 0 }; u8 m_cursor_column { 0 };
byte m_saved_cursor_row { 0 }; u8 m_saved_cursor_row { 0 };
byte m_saved_cursor_column { 0 }; u8 m_saved_cursor_column { 0 };
bool m_stomp { false }; bool m_stomp { false };
bool m_should_beep { false }; bool m_should_beep { false };
Attribute m_current_attribute; Attribute m_current_attribute;
void execute_escape_sequence(byte final); void execute_escape_sequence(u8 final);
void execute_xterm_command(); void execute_xterm_command();
enum EscapeState { enum EscapeState {
@ -237,12 +237,12 @@ private:
ExpectXtermFinal, ExpectXtermFinal,
}; };
EscapeState m_escape_state { Normal }; EscapeState m_escape_state { Normal };
Vector<byte> m_parameters; Vector<u8> m_parameters;
Vector<byte> m_intermediates; Vector<u8> m_intermediates;
Vector<byte> m_xterm_param1; Vector<u8> m_xterm_param1;
Vector<byte> m_xterm_param2; Vector<u8> m_xterm_param2;
Vector<bool> m_horizontal_tabs; Vector<bool> m_horizontal_tabs;
byte m_final { 0 }; u8 m_final { 0 };
bool m_belling { false }; bool m_belling { false };
int m_pixel_width { 0 }; int m_pixel_width { 0 };
@ -261,7 +261,7 @@ private:
CNotifier m_notifier; CNotifier m_notifier;
byte m_opacity { 255 }; u8 m_opacity { 255 };
bool m_needs_background_fill { true }; bool m_needs_background_fill { true };
bool m_cursor_blink_state { true }; bool m_cursor_blink_state { true };
@ -271,5 +271,5 @@ private:
CTimer m_visual_beep_timer; CTimer m_visual_beep_timer;
RefPtr<CConfigFile> m_config; RefPtr<CConfigFile> m_config;
byte m_last_char { 0 }; u8 m_last_char { 0 };
}; };

View file

@ -146,7 +146,7 @@ void Fire::timer_event(CTimerEvent&)
int rnd = my_rand() % 3; int rnd = my_rand() % 3;
/* Calculate new pixel value, don't go below 0 */ /* Calculate new pixel value, don't go below 0 */
byte nv = bitmap->bits(py)[px]; u8 nv = bitmap->bits(py)[px];
if (nv > 0) if (nv > 0)
nv -= (rnd & 1); nv -= (rnd & 1);

View file

@ -13,7 +13,7 @@
struct [[gnu::packed]] DescriptorTablePointer struct [[gnu::packed]] DescriptorTablePointer
{ {
word limit; u16 limit;
void* address; void* address;
}; };
@ -24,18 +24,18 @@ static Descriptor s_gdt[256];
static IRQHandler* s_irq_handler[16]; static IRQHandler* s_irq_handler[16];
static Vector<word>* s_gdt_freelist; static Vector<u16>* s_gdt_freelist;
static word s_gdt_length; static u16 s_gdt_length;
word gdt_alloc_entry() u16 gdt_alloc_entry()
{ {
ASSERT(s_gdt_freelist); ASSERT(s_gdt_freelist);
ASSERT(!s_gdt_freelist->is_empty()); ASSERT(!s_gdt_freelist->is_empty());
return s_gdt_freelist->take_last(); return s_gdt_freelist->take_last();
} }
void gdt_free_entry(word entry) void gdt_free_entry(u16 entry)
{ {
s_gdt_freelist->append(entry); s_gdt_freelist->append(entry);
} }
@ -123,8 +123,8 @@ asm(
template<typename DumpType> template<typename DumpType>
static void dump(const DumpType& regs) static void dump(const DumpType& regs)
{ {
word ss; u16 ss;
dword esp; u32 esp;
if (!current || current->process().is_ring0()) { if (!current || current->process().is_ring0()) {
ss = regs.ds; ss = regs.ds;
esp = regs.esp; esp = regs.esp;
@ -144,7 +144,7 @@ static void dump(const DumpType& regs)
kprintf("ebp=%x esp=%x esi=%x edi=%x\n", regs.ebp, esp, regs.esi, regs.edi); kprintf("ebp=%x esp=%x esi=%x edi=%x\n", regs.ebp, esp, regs.esi, regs.edi);
if (current && current->process().validate_read((void*)regs.eip, 8)) { if (current && current->process().validate_read((void*)regs.eip, 8)) {
byte* codeptr = (byte*)regs.eip; u8* codeptr = (u8*)regs.eip;
kprintf("code: %b %b %b %b %b %b %b %b\n", kprintf("code: %b %b %b %b %b %b %b %b\n",
codeptr[0], codeptr[0],
codeptr[1], codeptr[1],
@ -236,11 +236,11 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
{ {
ASSERT(current); ASSERT(current);
dword fault_address; u32 fault_address;
asm("movl %%cr2, %%eax" asm("movl %%cr2, %%eax"
: "=a"(fault_address)); : "=a"(fault_address));
dword fault_page_directory; u32 fault_page_directory;
asm("movl %%cr3, %%eax" asm("movl %%cr3, %%eax"
: "=a"(fault_page_directory)); : "=a"(fault_page_directory));
@ -269,8 +269,8 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
regs.exception_code & 2 ? "write to" : "read from", regs.exception_code & 2 ? "write to" : "read from",
fault_address); fault_address);
dword malloc_scrub_pattern = explode_byte(MALLOC_SCRUB_BYTE); u32 malloc_scrub_pattern = explode_byte(MALLOC_SCRUB_BYTE);
dword free_scrub_pattern = explode_byte(FREE_SCRUB_BYTE); u32 free_scrub_pattern = explode_byte(FREE_SCRUB_BYTE);
if ((fault_address & 0xffff0000) == (malloc_scrub_pattern & 0xffff0000)) { if ((fault_address & 0xffff0000) == (malloc_scrub_pattern & 0xffff0000)) {
kprintf("\033[33;1mNote: Address %p looks like it may be uninitialized malloc() memory\033[0m\n", fault_address); kprintf("\033[33;1mNote: Address %p looks like it may be uninitialized malloc() memory\033[0m\n", fault_address);
} else if ((fault_address & 0xffff0000) == (free_scrub_pattern & 0xffff0000)) { } else if ((fault_address & 0xffff0000) == (free_scrub_pattern & 0xffff0000)) {
@ -293,7 +293,7 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
static void _exception##i() \ static void _exception##i() \
{ \ { \
kprintf(msg "\n"); \ kprintf(msg "\n"); \
dword cr0, cr2, cr3, cr4; \ u32 cr0, cr2, cr3, cr4; \
asm("movl %%cr0, %%eax" \ asm("movl %%cr0, %%eax" \
: "=a"(cr0)); \ : "=a"(cr0)); \
asm("movl %%cr2, %%eax" \ asm("movl %%cr2, %%eax" \
@ -319,9 +319,9 @@ EH(12, "Stack exception")
EH(15, "Unknown error") EH(15, "Unknown error")
EH(16, "Coprocessor error") EH(16, "Coprocessor error")
static void write_raw_gdt_entry(word selector, dword low, dword high) static void write_raw_gdt_entry(u16 selector, u32 low, u32 high)
{ {
word i = (selector & 0xfffc) >> 3; u16 i = (selector & 0xfffc) >> 3;
s_gdt[i].low = low; s_gdt[i].low = low;
s_gdt[i].high = high; s_gdt[i].high = high;
@ -329,14 +329,14 @@ static void write_raw_gdt_entry(word selector, dword low, dword high)
s_gdtr.limit = (s_gdt_length + 1) * 8 - 1; s_gdtr.limit = (s_gdt_length + 1) * 8 - 1;
} }
void write_gdt_entry(word selector, Descriptor& descriptor) void write_gdt_entry(u16 selector, Descriptor& descriptor)
{ {
write_raw_gdt_entry(selector, descriptor.low, descriptor.high); write_raw_gdt_entry(selector, descriptor.low, descriptor.high);
} }
Descriptor& get_gdt_entry(word selector) Descriptor& get_gdt_entry(u16 selector)
{ {
word i = (selector & 0xfffc) >> 3; u16 i = (selector & 0xfffc) >> 3;
return *(Descriptor*)(&s_gdt[i]); return *(Descriptor*)(&s_gdt[i]);
} }
@ -352,7 +352,7 @@ void gdt_init()
{ {
s_gdt_length = 5; s_gdt_length = 5;
s_gdt_freelist = new Vector<word>(); s_gdt_freelist = new Vector<u16>();
s_gdt_freelist->ensure_capacity(256); s_gdt_freelist->ensure_capacity(256);
for (size_t i = s_gdt_length; i < 256; ++i) for (size_t i = s_gdt_length; i < 256; ++i)
s_gdt_freelist->append(i * 8); s_gdt_freelist->append(i * 8);
@ -389,30 +389,30 @@ static void unimp_trap()
hang(); hang();
} }
void register_irq_handler(byte irq, IRQHandler& handler) void register_irq_handler(u8 irq, IRQHandler& handler)
{ {
ASSERT(!s_irq_handler[irq]); ASSERT(!s_irq_handler[irq]);
s_irq_handler[irq] = &handler; s_irq_handler[irq] = &handler;
register_interrupt_handler(IRQ_VECTOR_BASE + irq, asm_irq_entry); register_interrupt_handler(IRQ_VECTOR_BASE + irq, asm_irq_entry);
} }
void unregister_irq_handler(byte irq, IRQHandler& handler) void unregister_irq_handler(u8 irq, IRQHandler& handler)
{ {
ASSERT(s_irq_handler[irq] == &handler); ASSERT(s_irq_handler[irq] == &handler);
s_irq_handler[irq] = nullptr; s_irq_handler[irq] = nullptr;
} }
void register_interrupt_handler(byte index, void (*f)()) void register_interrupt_handler(u8 index, void (*f)())
{ {
s_idt[index].low = 0x00080000 | LSW((f)); s_idt[index].low = 0x00080000 | LSW((f));
s_idt[index].high = ((dword)(f)&0xffff0000) | 0x8e00; s_idt[index].high = ((u32)(f)&0xffff0000) | 0x8e00;
flush_idt(); flush_idt();
} }
void register_user_callable_interrupt_handler(byte index, void (*f)()) void register_user_callable_interrupt_handler(u8 index, void (*f)())
{ {
s_idt[index].low = 0x00080000 | LSW((f)); s_idt[index].low = 0x00080000 | LSW((f));
s_idt[index].high = ((dword)(f)&0xffff0000) | 0xef00; s_idt[index].high = ((u32)(f)&0xffff0000) | 0xef00;
flush_idt(); flush_idt();
} }
@ -437,7 +437,7 @@ void idt_init()
s_idtr.address = s_idt; s_idtr.address = s_idt;
s_idtr.limit = 0x100 * 8 - 1; s_idtr.limit = 0x100 * 8 - 1;
for (byte i = 0xff; i > 0x10; --i) for (u8 i = 0xff; i > 0x10; --i)
register_interrupt_handler(i, unimp_trap); register_interrupt_handler(i, unimp_trap);
register_interrupt_handler(0x00, exception_0_entry); register_interrupt_handler(0x00, exception_0_entry);
@ -460,28 +460,28 @@ void idt_init()
register_interrupt_handler(0x57, irq7_handler); register_interrupt_handler(0x57, irq7_handler);
for (byte i = 0; i < 16; ++i) { for (u8 i = 0; i < 16; ++i) {
s_irq_handler[i] = nullptr; s_irq_handler[i] = nullptr;
} }
flush_idt(); flush_idt();
} }
void load_task_register(word selector) void load_task_register(u16 selector)
{ {
asm("ltr %0" ::"r"(selector)); asm("ltr %0" ::"r"(selector));
} }
void handle_irq() void handle_irq()
{ {
word isr = PIC::get_isr(); u16 isr = PIC::get_isr();
if (!isr) { if (!isr) {
kprintf("Spurious IRQ\n"); kprintf("Spurious IRQ\n");
return; return;
} }
byte irq = 0; u8 irq = 0;
for (byte i = 0; i < 16; ++i) { for (u8 i = 0; i < 16; ++i) {
if (i == 2) if (i == 2)
continue; continue;
if (isr & (1 << i)) { if (isr & (1 << i)) {

View file

@ -13,45 +13,45 @@ class PageTableEntry;
struct [[gnu::packed]] TSS32 struct [[gnu::packed]] TSS32
{ {
word backlink, __blh; u16 backlink, __blh;
dword esp0; u32 esp0;
word ss0, __ss0h; u16 ss0, __ss0h;
dword esp1; u32 esp1;
word ss1, __ss1h; u16 ss1, __ss1h;
dword esp2; u32 esp2;
word ss2, __ss2h; u16 ss2, __ss2h;
dword cr3, eip, eflags; u32 cr3, eip, eflags;
dword eax, ecx, edx, ebx, esp, ebp, esi, edi; u32 eax, ecx, edx, ebx, esp, ebp, esi, edi;
word es, __esh; u16 es, __esh;
word cs, __csh; u16 cs, __csh;
word ss, __ssh; u16 ss, __ssh;
word ds, __dsh; u16 ds, __dsh;
word fs, __fsh; u16 fs, __fsh;
word gs, __gsh; u16 gs, __gsh;
word ldt, __ldth; u16 ldt, __ldth;
word trace, iomapbase; u16 trace, iomapbase;
}; };
union [[gnu::packed]] Descriptor union [[gnu::packed]] Descriptor
{ {
struct { struct {
word limit_lo; u16 limit_lo;
word base_lo; u16 base_lo;
byte base_hi; u8 base_hi;
byte type : 4; u8 type : 4;
byte descriptor_type : 1; u8 descriptor_type : 1;
byte dpl : 2; u8 dpl : 2;
byte segment_present : 1; u8 segment_present : 1;
byte limit_hi : 4; u8 limit_hi : 4;
byte : 1; u8 : 1;
byte zero : 1; u8 zero : 1;
byte operation_size : 1; u8 operation_size : 1;
byte granularity : 1; u8 granularity : 1;
byte base_hi2; u8 base_hi2;
}; };
struct { struct {
dword low; u32 low;
dword high; u32 high;
}; };
enum Type { enum Type {
@ -72,15 +72,15 @@ union [[gnu::packed]] Descriptor
void set_base(void* b) void set_base(void* b)
{ {
base_lo = (dword)(b)&0xffff; base_lo = (u32)(b)&0xffff;
base_hi = ((dword)(b) >> 16) & 0xff; base_hi = ((u32)(b) >> 16) & 0xff;
base_hi2 = ((dword)(b) >> 24) & 0xff; base_hi2 = ((u32)(b) >> 24) & 0xff;
} }
void set_limit(dword l) void set_limit(u32 l)
{ {
limit_lo = (dword)l & 0xffff; limit_lo = (u32)l & 0xffff;
limit_hi = ((dword)l >> 16) & 0xff; limit_hi = ((u32)l >> 16) & 0xff;
} }
}; };
@ -89,13 +89,13 @@ class PageDirectoryEntry {
public: public:
PageTableEntry* page_table_base() { return reinterpret_cast<PageTableEntry*>(m_raw & 0xfffff000u); } PageTableEntry* page_table_base() { return reinterpret_cast<PageTableEntry*>(m_raw & 0xfffff000u); }
void set_page_table_base(dword value) void set_page_table_base(u32 value)
{ {
m_raw &= 0xfff; m_raw &= 0xfff;
m_raw |= value & 0xfffff000; m_raw |= value & 0xfffff000;
} }
dword raw() const { return m_raw; } u32 raw() const { return m_raw; }
void copy_from(Badge<MemoryManager>, const PageDirectoryEntry& other) { m_raw = other.m_raw; } void copy_from(Badge<MemoryManager>, const PageDirectoryEntry& other) { m_raw = other.m_raw; }
enum Flags { enum Flags {
@ -121,7 +121,7 @@ public:
bool is_cache_disabled() const { return raw() & CacheDisabled; } bool is_cache_disabled() const { return raw() & CacheDisabled; }
void set_cache_disabled(bool b) { set_bit(CacheDisabled, b); } void set_cache_disabled(bool b) { set_bit(CacheDisabled, b); }
void set_bit(byte bit, bool value) void set_bit(u8 bit, bool value)
{ {
if (value) if (value)
m_raw |= bit; m_raw |= bit;
@ -130,7 +130,7 @@ public:
} }
private: private:
dword m_raw; u32 m_raw;
}; };
class PageTableEntry { class PageTableEntry {
@ -138,13 +138,13 @@ class PageTableEntry {
public: public:
void* physical_page_base() { return reinterpret_cast<void*>(m_raw & 0xfffff000u); } void* physical_page_base() { return reinterpret_cast<void*>(m_raw & 0xfffff000u); }
void set_physical_page_base(dword value) void set_physical_page_base(u32 value)
{ {
m_raw &= 0xfff; m_raw &= 0xfff;
m_raw |= value & 0xfffff000; m_raw |= value & 0xfffff000;
} }
dword raw() const { return m_raw; } u32 raw() const { return m_raw; }
enum Flags { enum Flags {
Present = 1 << 0, Present = 1 << 0,
@ -169,7 +169,7 @@ public:
bool is_cache_disabled() const { return raw() & CacheDisabled; } bool is_cache_disabled() const { return raw() & CacheDisabled; }
void set_cache_disabled(bool b) { set_bit(CacheDisabled, b); } void set_cache_disabled(bool b) { set_bit(CacheDisabled, b); }
void set_bit(byte bit, bool value) void set_bit(u8 bit, bool value)
{ {
if (value) if (value)
m_raw |= bit; m_raw |= bit;
@ -178,7 +178,7 @@ public:
} }
private: private:
dword m_raw; u32 m_raw;
}; };
static_assert(sizeof(PageDirectoryEntry) == 4); static_assert(sizeof(PageDirectoryEntry) == 4);
@ -189,17 +189,17 @@ class IRQHandler;
void gdt_init(); void gdt_init();
void idt_init(); void idt_init();
void sse_init(); void sse_init();
void register_interrupt_handler(byte number, void (*f)()); void register_interrupt_handler(u8 number, void (*f)());
void register_user_callable_interrupt_handler(byte number, void (*f)()); void register_user_callable_interrupt_handler(u8 number, void (*f)());
void register_irq_handler(byte number, IRQHandler&); void register_irq_handler(u8 number, IRQHandler&);
void unregister_irq_handler(byte number, IRQHandler&); void unregister_irq_handler(u8 number, IRQHandler&);
void flush_idt(); void flush_idt();
void flush_gdt(); void flush_gdt();
void load_task_register(word selector); void load_task_register(u16 selector);
word gdt_alloc_entry(); u16 gdt_alloc_entry();
void gdt_free_entry(word); void gdt_free_entry(u16);
Descriptor& get_gdt_entry(word selector); Descriptor& get_gdt_entry(u16 selector);
void write_gdt_entry(word selector, Descriptor&); void write_gdt_entry(u16 selector, Descriptor&);
[[noreturn]] static inline void hang() [[noreturn]] static inline void hang()
{ {
@ -208,8 +208,8 @@ void write_gdt_entry(word selector, Descriptor&);
} }
} }
#define LSW(x) ((dword)(x)&0xFFFF) #define LSW(x) ((u32)(x)&0xFFFF)
#define MSW(x) (((dword)(x) >> 16) & 0xFFFF) #define MSW(x) (((u32)(x) >> 16) & 0xFFFF)
#define LSB(x) ((x)&0xFF) #define LSB(x) ((x)&0xFF)
#define MSB(x) (((x) >> 8) & 0xFF) #define MSB(x) (((x) >> 8) & 0xFF)
@ -220,17 +220,17 @@ void write_gdt_entry(word selector, Descriptor&);
#define memory_barrier() asm volatile("" :: \ #define memory_barrier() asm volatile("" :: \
: "memory") : "memory")
inline dword cpu_cr3() inline u32 cpu_cr3()
{ {
dword cr3; u32 cr3;
asm volatile("movl %%cr3, %%eax" asm volatile("movl %%cr3, %%eax"
: "=a"(cr3)); : "=a"(cr3));
return cr3; return cr3;
} }
inline dword cpu_flags() inline u32 cpu_flags()
{ {
dword flags; u32 flags;
asm volatile( asm volatile(
"pushf\n" "pushf\n"
"pop %0\n" "pop %0\n"
@ -259,7 +259,7 @@ public:
} }
private: private:
dword m_flags; u32 m_flags;
}; };
class InterruptDisabler { class InterruptDisabler {
@ -277,7 +277,7 @@ public:
} }
private: private:
dword m_flags; u32 m_flags;
}; };
/* Map IRQ0-15 @ ISR 0x50-0x5F */ /* Map IRQ0-15 @ ISR 0x50-0x5F */
@ -297,14 +297,14 @@ struct PageFaultFlags {
class PageFault { class PageFault {
public: public:
PageFault(word code, VirtualAddress vaddr) PageFault(u16 code, VirtualAddress vaddr)
: m_code(code) : m_code(code)
, m_vaddr(vaddr) , m_vaddr(vaddr)
{ {
} }
VirtualAddress vaddr() const { return m_vaddr; } VirtualAddress vaddr() const { return m_vaddr; }
word code() const { return m_code; } u16 code() const { return m_code; }
bool is_not_present() const { return (m_code & 1) == PageFaultFlags::NotPresent; } bool is_not_present() const { return (m_code & 1) == PageFaultFlags::NotPresent; }
bool is_protection_violation() const { return (m_code & 1) == PageFaultFlags::ProtectionViolation; } bool is_protection_violation() const { return (m_code & 1) == PageFaultFlags::ProtectionViolation; }
@ -315,86 +315,86 @@ public:
bool is_instruction_fetch() const { return (m_code & 8) == PageFaultFlags::InstructionFetch; } bool is_instruction_fetch() const { return (m_code & 8) == PageFaultFlags::InstructionFetch; }
private: private:
word m_code; u16 m_code;
VirtualAddress m_vaddr; VirtualAddress m_vaddr;
}; };
struct [[gnu::packed]] RegisterDump struct [[gnu::packed]] RegisterDump
{ {
word ss; u16 ss;
word gs; u16 gs;
word fs; u16 fs;
word es; u16 es;
word ds; u16 ds;
dword edi; u32 edi;
dword esi; u32 esi;
dword ebp; u32 ebp;
dword esp; u32 esp;
dword ebx; u32 ebx;
dword edx; u32 edx;
dword ecx; u32 ecx;
dword eax; u32 eax;
dword eip; u32 eip;
word cs; u16 cs;
word __csPadding; u16 __csPadding;
dword eflags; u32 eflags;
dword esp_if_crossRing; u32 esp_if_crossRing;
word ss_if_crossRing; u16 ss_if_crossRing;
}; };
struct [[gnu::packed]] RegisterDumpWithExceptionCode struct [[gnu::packed]] RegisterDumpWithExceptionCode
{ {
word ss; u16 ss;
word gs; u16 gs;
word fs; u16 fs;
word es; u16 es;
word ds; u16 ds;
dword edi; u32 edi;
dword esi; u32 esi;
dword ebp; u32 ebp;
dword esp; u32 esp;
dword ebx; u32 ebx;
dword edx; u32 edx;
dword ecx; u32 ecx;
dword eax; u32 eax;
word exception_code; u16 exception_code;
word __exception_code_padding; u16 __exception_code_padding;
dword eip; u32 eip;
word cs; u16 cs;
word __csPadding; u16 __csPadding;
dword eflags; u32 eflags;
dword esp_if_crossRing; u32 esp_if_crossRing;
word ss_if_crossRing; u16 ss_if_crossRing;
}; };
struct [[gnu::aligned(16)]] FPUState struct [[gnu::aligned(16)]] FPUState
{ {
byte buffer[512]; u8 buffer[512];
}; };
inline constexpr dword page_base_of(dword address) inline constexpr u32 page_base_of(u32 address)
{ {
return address & 0xfffff000; return address & 0xfffff000;
} }
class CPUID { class CPUID {
public: public:
CPUID(dword function) { asm volatile("cpuid" CPUID(u32 function) { asm volatile("cpuid"
: "=a"(m_eax), "=b"(m_ebx), "=c"(m_ecx), "=d"(m_edx) : "=a"(m_eax), "=b"(m_ebx), "=c"(m_ecx), "=d"(m_edx)
: "a"(function), "c"(0)); } : "a"(function), "c"(0)); }
dword eax() const { return m_eax; } u32 eax() const { return m_eax; }
dword ebx() const { return m_ebx; } u32 ebx() const { return m_ebx; }
dword ecx() const { return m_ecx; } u32 ecx() const { return m_ecx; }
dword edx() const { return m_edx; } u32 edx() const { return m_edx; }
private: private:
dword m_eax { 0xffffffff }; u32 m_eax { 0xffffffff };
dword m_ebx { 0xffffffff }; u32 m_ebx { 0xffffffff };
dword m_ecx { 0xffffffff }; u32 m_ecx { 0xffffffff };
dword m_edx { 0xffffffff }; u32 m_edx { 0xffffffff };
}; };
inline void read_tsc(dword& lsw, dword& msw) inline void read_tsc(u32& lsw, u32& msw)
{ {
asm volatile("rdtsc" asm volatile("rdtsc"
: "=d"(msw), "=a"(lsw)); : "=d"(msw), "=a"(lsw));

View file

@ -3,13 +3,13 @@
namespace CMOS { namespace CMOS {
byte read(byte index) u8 read(u8 index)
{ {
IO::out8(0x70, index); IO::out8(0x70, index);
return IO::in8(0x71); return IO::in8(0x71);
} }
void write(byte index, byte data) void write(u8 index, u8 data)
{ {
IO::out8(0x70, index); IO::out8(0x70, index);
IO::out8(0x71, data); IO::out8(0x71, data);

View file

@ -4,7 +4,7 @@
namespace CMOS { namespace CMOS {
byte read(byte index); u8 read(u8 index);
void write(byte index, byte data); void write(u8 index, u8 data);
} }

View file

@ -28,14 +28,14 @@ bool Console::can_read(FileDescription&) const
return false; return false;
} }
ssize_t Console::read(FileDescription&, byte*, ssize_t) ssize_t Console::read(FileDescription&, u8*, ssize_t)
{ {
// FIXME: Implement reading from the console. // FIXME: Implement reading from the console.
// Maybe we could use a ring buffer for this device? // Maybe we could use a ring buffer for this device?
return 0; return 0;
} }
ssize_t Console::write(FileDescription&, const byte* data, ssize_t size) ssize_t Console::write(FileDescription&, const u8* data, ssize_t size)
{ {
if (!size) if (!size)
return 0; return 0;

View file

@ -7,7 +7,7 @@
class ConsoleImplementation { class ConsoleImplementation {
public: public:
virtual ~ConsoleImplementation(); virtual ~ConsoleImplementation();
virtual void on_sysconsole_receive(byte) = 0; virtual void on_sysconsole_receive(u8) = 0;
}; };
class Console final : public CharacterDevice { class Console final : public CharacterDevice {
@ -21,8 +21,8 @@ public:
// ^CharacterDevice // ^CharacterDevice
virtual bool can_read(FileDescription&) const override; virtual bool can_read(FileDescription&) const override;
virtual bool can_write(FileDescription&) const override { return true; } virtual bool can_write(FileDescription&) const override { return true; }
virtual ssize_t read(FileDescription&, byte*, ssize_t) override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
virtual const char* class_name() const override { return "Console"; } virtual const char* class_name() const override { return "Console"; }
void set_implementation(ConsoleImplementation* implementation) { m_implementation = implementation; } void set_implementation(ConsoleImplementation* implementation) { m_implementation = implementation; }

View file

@ -43,7 +43,7 @@ BXVGADevice::BXVGADevice()
m_framebuffer_address = PhysicalAddress(find_framebuffer_address()); m_framebuffer_address = PhysicalAddress(find_framebuffer_address());
} }
void BXVGADevice::set_register(word index, word data) void BXVGADevice::set_register(u16 index, u16 data)
{ {
IO::out16(VBE_DISPI_IOPORT_INDEX, index); IO::out16(VBE_DISPI_IOPORT_INDEX, index);
IO::out16(VBE_DISPI_IOPORT_DATA, data); IO::out16(VBE_DISPI_IOPORT_DATA, data);
@ -54,10 +54,10 @@ void BXVGADevice::set_resolution(int width, int height)
m_framebuffer_size = { width, height }; m_framebuffer_size = { width, height };
set_register(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_DISABLED); set_register(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_DISABLED);
set_register(VBE_DISPI_INDEX_XRES, (word)width); set_register(VBE_DISPI_INDEX_XRES, (u16)width);
set_register(VBE_DISPI_INDEX_YRES, (word)height); set_register(VBE_DISPI_INDEX_YRES, (u16)height);
set_register(VBE_DISPI_INDEX_VIRT_WIDTH, (word)width); set_register(VBE_DISPI_INDEX_VIRT_WIDTH, (u16)width);
set_register(VBE_DISPI_INDEX_VIRT_HEIGHT, (word)height * 2); set_register(VBE_DISPI_INDEX_VIRT_HEIGHT, (u16)height * 2);
set_register(VBE_DISPI_INDEX_BPP, 32); set_register(VBE_DISPI_INDEX_BPP, 32);
set_register(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED); set_register(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED);
set_register(VBE_DISPI_INDEX_BANK, 0); set_register(VBE_DISPI_INDEX_BANK, 0);
@ -66,15 +66,15 @@ void BXVGADevice::set_resolution(int width, int height)
void BXVGADevice::set_y_offset(int offset) void BXVGADevice::set_y_offset(int offset)
{ {
ASSERT(offset <= m_framebuffer_size.height()); ASSERT(offset <= m_framebuffer_size.height());
set_register(VBE_DISPI_INDEX_Y_OFFSET, (word)offset); set_register(VBE_DISPI_INDEX_Y_OFFSET, (u16)offset);
} }
dword BXVGADevice::find_framebuffer_address() u32 BXVGADevice::find_framebuffer_address()
{ {
// NOTE: The QEMU card has the same PCI ID as the Bochs one. // NOTE: The QEMU card has the same PCI ID as the Bochs one.
static const PCI::ID bochs_vga_id = { 0x1234, 0x1111 }; static const PCI::ID bochs_vga_id = { 0x1234, 0x1111 };
static const PCI::ID virtualbox_vga_id = { 0x80ee, 0xbeef }; static const PCI::ID virtualbox_vga_id = { 0x80ee, 0xbeef };
dword framebuffer_address = 0; u32 framebuffer_address = 0;
PCI::enumerate_all([&framebuffer_address](const PCI::Address& address, PCI::ID id) { PCI::enumerate_all([&framebuffer_address](const PCI::Address& address, PCI::ID id) {
if (id == bochs_vga_id || id == virtualbox_vga_id) { if (id == bochs_vga_id || id == virtualbox_vga_id) {
framebuffer_address = PCI::get_BAR0(address) & 0xfffffff0; framebuffer_address = PCI::get_BAR0(address) & 0xfffffff0;
@ -133,12 +133,12 @@ bool BXVGADevice::can_write(FileDescription&) const
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
ssize_t BXVGADevice::read(FileDescription&, byte*, ssize_t) ssize_t BXVGADevice::read(FileDescription&, u8*, ssize_t)
{ {
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
ssize_t BXVGADevice::write(FileDescription&, const byte*, ssize_t) ssize_t BXVGADevice::write(FileDescription&, const u8*, ssize_t)
{ {
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }

View file

@ -20,18 +20,18 @@ public:
virtual int ioctl(FileDescription&, unsigned request, unsigned arg) override; virtual int ioctl(FileDescription&, unsigned request, unsigned arg) override;
virtual KResultOr<Region*> mmap(Process&, FileDescription&, VirtualAddress preferred_vaddr, size_t offset, size_t, int prot) override; virtual KResultOr<Region*> mmap(Process&, FileDescription&, VirtualAddress preferred_vaddr, size_t offset, size_t, int prot) override;
size_t framebuffer_size_in_bytes() const { return m_framebuffer_size.area() * sizeof(dword) * 2; } size_t framebuffer_size_in_bytes() const { return m_framebuffer_size.area() * sizeof(u32) * 2; }
Size framebuffer_size() const { return m_framebuffer_size; } Size framebuffer_size() const { return m_framebuffer_size; }
private: private:
virtual const char* class_name() const override { return "BXVGA"; } virtual const char* class_name() const override { return "BXVGA"; }
virtual bool can_read(FileDescription&) const override; virtual bool can_read(FileDescription&) const override;
virtual bool can_write(FileDescription&) const override; virtual bool can_write(FileDescription&) const override;
virtual ssize_t read(FileDescription&, byte*, ssize_t) override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
void set_register(word index, word value); void set_register(u16 index, u16 value);
dword find_framebuffer_address(); u32 find_framebuffer_address();
PhysicalAddress m_framebuffer_address; PhysicalAddress m_framebuffer_address;
Size m_framebuffer_size; Size m_framebuffer_size;

View file

@ -19,7 +19,7 @@ DebugLogDevice::~DebugLogDevice()
{ {
} }
ssize_t DebugLogDevice::write(FileDescription&, const byte* data, ssize_t data_size) ssize_t DebugLogDevice::write(FileDescription&, const u8* data, ssize_t data_size)
{ {
for (int i = 0; i < data_size; ++i) for (int i = 0; i < data_size; ++i)
IO::out8(0xe9, data[i]); IO::out8(0xe9, data[i]);

View file

@ -9,8 +9,8 @@ public:
private: private:
// ^CharacterDevice // ^CharacterDevice
virtual ssize_t read(FileDescription&, byte*, ssize_t) override { return 0; } virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return 0; }
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
virtual bool can_write(FileDescription&) const override { return true; } virtual bool can_write(FileDescription&) const override { return true; }
virtual bool can_read(FileDescription&) const override { return true; } virtual bool can_read(FileDescription&) const override { return true; }
virtual const char* class_name() const override { return "DebugLogDevice"; } virtual const char* class_name() const override { return "DebugLogDevice"; }

View file

@ -8,21 +8,21 @@ DiskDevice::~DiskDevice()
{ {
} }
bool DiskDevice::read(DiskOffset offset, unsigned length, byte* out) const bool DiskDevice::read(DiskOffset offset, unsigned length, u8* out) const
{ {
ASSERT((offset % block_size()) == 0); ASSERT((offset % block_size()) == 0);
ASSERT((length % block_size()) == 0); ASSERT((length % block_size()) == 0);
dword first_block = offset / block_size(); u32 first_block = offset / block_size();
dword end_block = (offset + length) / block_size(); u32 end_block = (offset + length) / block_size();
return const_cast<DiskDevice*>(this)->read_blocks(first_block, end_block - first_block, out); return const_cast<DiskDevice*>(this)->read_blocks(first_block, end_block - first_block, out);
} }
bool DiskDevice::write(DiskOffset offset, unsigned length, const byte* in) bool DiskDevice::write(DiskOffset offset, unsigned length, const u8* in)
{ {
ASSERT((offset % block_size()) == 0); ASSERT((offset % block_size()) == 0);
ASSERT((length % block_size()) == 0); ASSERT((length % block_size()) == 0);
dword first_block = offset / block_size(); u32 first_block = offset / block_size();
dword end_block = (offset + length) / block_size(); u32 end_block = (offset + length) / block_size();
ASSERT(first_block <= 0xffffffff); ASSERT(first_block <= 0xffffffff);
ASSERT(end_block <= 0xffffffff); ASSERT(end_block <= 0xffffffff);
return write_blocks(first_block, end_block - first_block, in); return write_blocks(first_block, end_block - first_block, in);

View file

@ -4,21 +4,21 @@
#include <AK/Types.h> #include <AK/Types.h>
// FIXME: Support 64-bit DiskOffset // FIXME: Support 64-bit DiskOffset
typedef dword DiskOffset; typedef u32 DiskOffset;
class DiskDevice : public RefCounted<DiskDevice> { class DiskDevice : public RefCounted<DiskDevice> {
public: public:
virtual ~DiskDevice(); virtual ~DiskDevice();
virtual unsigned block_size() const = 0; virtual unsigned block_size() const = 0;
virtual bool read_block(unsigned index, byte*) const = 0; virtual bool read_block(unsigned index, u8*) const = 0;
virtual bool write_block(unsigned index, const byte*) = 0; virtual bool write_block(unsigned index, const u8*) = 0;
virtual const char* class_name() const = 0; virtual const char* class_name() const = 0;
bool read(DiskOffset, unsigned length, byte*) const; bool read(DiskOffset, unsigned length, u8*) const;
bool write(DiskOffset, unsigned length, const byte*); bool write(DiskOffset, unsigned length, const u8*);
virtual bool read_blocks(unsigned index, word count, byte*) = 0; virtual bool read_blocks(unsigned index, u16 count, u8*) = 0;
virtual bool write_blocks(unsigned index, word count, const byte*) = 0; virtual bool write_blocks(unsigned index, u16 count, const u8*) = 0;
protected: protected:
DiskDevice(); DiskDevice();

View file

@ -22,7 +22,7 @@ unsigned DiskPartition::block_size() const
return m_device->block_size(); return m_device->block_size();
} }
bool DiskPartition::read_block(unsigned index, byte* out) const bool DiskPartition::read_block(unsigned index, u8* out) const
{ {
#ifdef OFFD_DEBUG #ifdef OFFD_DEBUG
kprintf("DiskPartition::read_block %u (really: %u)\n", index, m_block_offset + index); kprintf("DiskPartition::read_block %u (really: %u)\n", index, m_block_offset + index);
@ -31,7 +31,7 @@ bool DiskPartition::read_block(unsigned index, byte* out) const
return m_device->read_block(m_block_offset + index, out); return m_device->read_block(m_block_offset + index, out);
} }
bool DiskPartition::write_block(unsigned index, const byte* data) bool DiskPartition::write_block(unsigned index, const u8* data)
{ {
#ifdef OFFD_DEBUG #ifdef OFFD_DEBUG
kprintf("DiskPartition::write_block %u (really: %u)\n", index, m_block_offset + index); kprintf("DiskPartition::write_block %u (really: %u)\n", index, m_block_offset + index);
@ -40,7 +40,7 @@ bool DiskPartition::write_block(unsigned index, const byte* data)
return m_device->write_block(m_block_offset + index, data); return m_device->write_block(m_block_offset + index, data);
} }
bool DiskPartition::read_blocks(unsigned index, word count, byte* out) bool DiskPartition::read_blocks(unsigned index, u16 count, u8* out)
{ {
#ifdef OFFD_DEBUG #ifdef OFFD_DEBUG
kprintf("DiskPartition::read_blocks %u (really: %u) count=%u\n", index, m_block_offset + index, count); kprintf("DiskPartition::read_blocks %u (really: %u) count=%u\n", index, m_block_offset + index, count);
@ -49,7 +49,7 @@ bool DiskPartition::read_blocks(unsigned index, word count, byte* out)
return m_device->read_blocks(m_block_offset + index, count, out); return m_device->read_blocks(m_block_offset + index, count, out);
} }
bool DiskPartition::write_blocks(unsigned index, word count, const byte* data) bool DiskPartition::write_blocks(unsigned index, u16 count, const u8* data)
{ {
#ifdef OFFD_DEBUG #ifdef OFFD_DEBUG
kprintf("DiskPartition::write_blocks %u (really: %u) count=%u\n", index, m_block_offset + index, count); kprintf("DiskPartition::write_blocks %u (really: %u) count=%u\n", index, m_block_offset + index, count);

View file

@ -9,10 +9,10 @@ public:
virtual ~DiskPartition(); virtual ~DiskPartition();
virtual unsigned block_size() const override; virtual unsigned block_size() const override;
virtual bool read_block(unsigned index, byte* out) const override; virtual bool read_block(unsigned index, u8* out) const override;
virtual bool write_block(unsigned index, const byte*) override; virtual bool write_block(unsigned index, const u8*) override;
virtual bool read_blocks(unsigned index, word count, byte*) override; virtual bool read_blocks(unsigned index, u16 count, u8*) override;
virtual bool write_blocks(unsigned index, word count, const byte*) override; virtual bool write_blocks(unsigned index, u16 count, const u8*) override;
private: private:
virtual const char* class_name() const override; virtual const char* class_name() const override;

View file

@ -32,19 +32,19 @@ unsigned FileBackedDiskDevice::block_size() const
return m_block_size; return m_block_size;
} }
bool FileBackedDiskDevice::read_block(unsigned index, byte* out) const bool FileBackedDiskDevice::read_block(unsigned index, u8* out) const
{ {
DiskOffset offset = index * m_block_size; DiskOffset offset = index * m_block_size;
return read_internal(offset, block_size(), out); return read_internal(offset, block_size(), out);
} }
bool FileBackedDiskDevice::write_block(unsigned index, const byte* data) bool FileBackedDiskDevice::write_block(unsigned index, const u8* data)
{ {
DiskOffset offset = index * m_block_size; DiskOffset offset = index * m_block_size;
return write_internal(offset, block_size(), data); return write_internal(offset, block_size(), data);
} }
bool FileBackedDiskDevice::read_internal(DiskOffset offset, unsigned length, byte* out) const bool FileBackedDiskDevice::read_internal(DiskOffset offset, unsigned length, u8* out) const
{ {
#ifndef IGNORE_FILE_LENGTH #ifndef IGNORE_FILE_LENGTH
if (offset + length >= m_file_length) if (offset + length >= m_file_length)
@ -54,12 +54,12 @@ bool FileBackedDiskDevice::read_internal(DiskOffset offset, unsigned length, byt
printf("[FileBackedDiskDevice] Read device @ offset %llx, length %u\n", offset, length); printf("[FileBackedDiskDevice] Read device @ offset %llx, length %u\n", offset, length);
#endif #endif
fseeko(m_file, offset, SEEK_SET); fseeko(m_file, offset, SEEK_SET);
unsigned nread = fread(out, sizeof(byte), length, m_file); unsigned nread = fread(out, sizeof(u8), length, m_file);
ASSERT(nread == length); ASSERT(nread == length);
return true; return true;
} }
bool FileBackedDiskDevice::write_internal(DiskOffset offset, unsigned length, const byte* data) bool FileBackedDiskDevice::write_internal(DiskOffset offset, unsigned length, const u8* data)
{ {
#ifndef IGNORE_FILE_LENGTH #ifndef IGNORE_FILE_LENGTH
if (offset + length >= m_file_length) if (offset + length >= m_file_length)
@ -70,7 +70,7 @@ bool FileBackedDiskDevice::write_internal(DiskOffset offset, unsigned length, co
#endif #endif
fseeko(m_file, offset, SEEK_SET); fseeko(m_file, offset, SEEK_SET);
// size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); // size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
unsigned nwritten = fwrite(data, sizeof(byte), length, m_file); unsigned nwritten = fwrite(data, sizeof(u8), length, m_file);
ASSERT(nwritten == length); ASSERT(nwritten == length);
return true; return true;
} }

View file

@ -14,14 +14,14 @@ public:
bool is_valid() const { return m_file; } bool is_valid() const { return m_file; }
virtual unsigned block_size() const override; virtual unsigned block_size() const override;
virtual bool read_block(unsigned index, byte* out) const override; virtual bool read_block(unsigned index, u8* out) const override;
virtual bool write_block(unsigned index, const byte*) override; virtual bool write_block(unsigned index, const u8*) override;
private: private:
virtual const char* class_name() const override; virtual const char* class_name() const override;
bool read_internal(DiskOffset, unsigned length, byte* out) const; bool read_internal(DiskOffset, unsigned length, u8* out) const;
bool write_internal(DiskOffset, unsigned length, const byte* data); bool write_internal(DiskOffset, unsigned length, const u8* data);
FileBackedDiskDevice(String&& imagePath, unsigned block_size); FileBackedDiskDevice(String&& imagePath, unsigned block_size);

View file

@ -17,14 +17,14 @@ bool FullDevice::can_read(FileDescription&) const
return true; return true;
} }
ssize_t FullDevice::read(FileDescription&, byte* buffer, ssize_t size) ssize_t FullDevice::read(FileDescription&, u8* buffer, ssize_t size)
{ {
ssize_t count = min(PAGE_SIZE, size); ssize_t count = min(PAGE_SIZE, size);
memset(buffer, 0, (size_t)count); memset(buffer, 0, (size_t)count);
return count; return count;
} }
ssize_t FullDevice::write(FileDescription&, const byte*, ssize_t size) ssize_t FullDevice::write(FileDescription&, const u8*, ssize_t size)
{ {
if (size == 0) if (size == 0)
return 0; return 0;

View file

@ -10,8 +10,8 @@ public:
private: private:
// ^CharacterDevice // ^CharacterDevice
virtual ssize_t read(FileDescription&, byte*, ssize_t) override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
virtual bool can_read(FileDescription&) const override; virtual bool can_read(FileDescription&) const override;
virtual bool can_write(FileDescription&) const override { return true; } virtual bool can_write(FileDescription&) const override { return true; }
virtual const char* class_name() const override { return "FullDevice"; } virtual const char* class_name() const override { return "FullDevice"; }

View file

@ -106,19 +106,19 @@ unsigned IDEDiskDevice::block_size() const
return 512; return 512;
} }
bool IDEDiskDevice::read_blocks(unsigned index, word count, byte* out) bool IDEDiskDevice::read_blocks(unsigned index, u16 count, u8* out)
{ {
if (m_bus_master_base && m_dma_enabled.resource()) if (m_bus_master_base && m_dma_enabled.resource())
return read_sectors_with_dma(index, count, out); return read_sectors_with_dma(index, count, out);
return read_sectors(index, count, out); return read_sectors(index, count, out);
} }
bool IDEDiskDevice::read_block(unsigned index, byte* out) const bool IDEDiskDevice::read_block(unsigned index, u8* out) const
{ {
return const_cast<IDEDiskDevice*>(this)->read_blocks(index, 1, out); return const_cast<IDEDiskDevice*>(this)->read_blocks(index, 1, out);
} }
bool IDEDiskDevice::write_blocks(unsigned index, word count, const byte* data) bool IDEDiskDevice::write_blocks(unsigned index, u16 count, const u8* data)
{ {
if (m_bus_master_base && m_dma_enabled.resource()) if (m_bus_master_base && m_dma_enabled.resource())
return write_sectors_with_dma(index, count, data); return write_sectors_with_dma(index, count, data);
@ -129,12 +129,12 @@ bool IDEDiskDevice::write_blocks(unsigned index, word count, const byte* data)
return true; return true;
} }
bool IDEDiskDevice::write_block(unsigned index, const byte* data) bool IDEDiskDevice::write_block(unsigned index, const u8* data)
{ {
return write_blocks(index, 1, data); return write_blocks(index, 1, data);
} }
static void print_ide_status(byte status) static void print_ide_status(u8 status)
{ {
kprintf("DRQ=%u BSY=%u DRDY=%u DSC=%u DF=%u CORR=%u IDX=%u ERR=%u\n", kprintf("DRQ=%u BSY=%u DRDY=%u DSC=%u DF=%u CORR=%u IDX=%u ERR=%u\n",
(status & ATA_SR_DRQ) != 0, (status & ATA_SR_DRQ) != 0,
@ -166,7 +166,7 @@ bool IDEDiskDevice::wait_for_irq()
void IDEDiskDevice::handle_irq() void IDEDiskDevice::handle_irq()
{ {
byte status = IO::in8(m_io_base + ATA_REG_STATUS); u8 status = IO::in8(m_io_base + ATA_REG_STATUS);
if (status & ATA_SR_ERR) { if (status & ATA_SR_ERR) {
print_ide_status(status); print_ide_status(status);
m_device_error = IO::in8(m_io_base + ATA_REG_ERROR); m_device_error = IO::in8(m_io_base + ATA_REG_ERROR);
@ -192,7 +192,7 @@ void IDEDiskDevice::initialize()
}); });
#ifdef DISK_DEBUG #ifdef DISK_DEBUG
byte status = IO::in8(m_io_base + ATA_REG_STATUS); u8 status = IO::in8(m_io_base + ATA_REG_STATUS);
kprintf("initial status: "); kprintf("initial status: ");
print_ide_status(status); print_ide_status(status);
#endif #endif
@ -213,19 +213,19 @@ void IDEDiskDevice::initialize()
ByteBuffer wbuf = ByteBuffer::create_uninitialized(512); ByteBuffer wbuf = ByteBuffer::create_uninitialized(512);
ByteBuffer bbuf = ByteBuffer::create_uninitialized(512); ByteBuffer bbuf = ByteBuffer::create_uninitialized(512);
byte* b = bbuf.pointer(); u8* b = bbuf.pointer();
word* w = (word*)wbuf.pointer(); u16* w = (u16*)wbuf.pointer();
const word* wbufbase = (word*)wbuf.pointer(); const u16* wbufbase = (u16*)wbuf.pointer();
for (dword i = 0; i < 256; ++i) { for (u32 i = 0; i < 256; ++i) {
word data = IO::in16(m_io_base + ATA_REG_DATA); u16 data = IO::in16(m_io_base + ATA_REG_DATA);
*(w++) = data; *(w++) = data;
*(b++) = MSB(data); *(b++) = MSB(data);
*(b++) = LSB(data); *(b++) = LSB(data);
} }
// "Unpad" the device name string. // "Unpad" the device name string.
for (dword i = 93; i > 54 && bbuf[i] == ' '; --i) for (u32 i = 93; i > 54 && bbuf[i] == ' '; --i)
bbuf[i] = 0; bbuf[i] = 0;
m_cylinders = wbufbase[1]; m_cylinders = wbufbase[1];
@ -249,13 +249,13 @@ void IDEDiskDevice::initialize()
} }
} }
static void wait_400ns(word io_base) static void wait_400ns(u16 io_base)
{ {
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
IO::in8(io_base + ATA_REG_ALTSTATUS); IO::in8(io_base + ATA_REG_ALTSTATUS);
} }
bool IDEDiskDevice::read_sectors_with_dma(dword lba, word count, byte* outbuf) bool IDEDiskDevice::read_sectors_with_dma(u32 lba, u16 count, u8* outbuf)
{ {
LOCKER(m_lock); LOCKER(m_lock);
#ifdef DISK_DEBUG #ifdef DISK_DEBUG
@ -275,7 +275,7 @@ bool IDEDiskDevice::read_sectors_with_dma(dword lba, word count, byte* outbuf)
IO::out8(m_bus_master_base, 0); IO::out8(m_bus_master_base, 0);
// Write the PRDT location // Write the PRDT location
IO::out32(m_bus_master_base + 4, (dword)&m_prdt); IO::out32(m_bus_master_base + 4, (u32)&m_prdt);
// Turn on "Interrupt" and "Error" flag. The error flag should be cleared by hardware. // Turn on "Interrupt" and "Error" flag. The error flag should be cleared by hardware.
IO::out8(m_bus_master_base + 2, IO::in8(m_bus_master_base + 2) | 0x6); IO::out8(m_bus_master_base + 2, IO::in8(m_bus_master_base + 2) | 0x6);
@ -332,7 +332,7 @@ bool IDEDiskDevice::read_sectors_with_dma(dword lba, word count, byte* outbuf)
return true; return true;
} }
bool IDEDiskDevice::read_sectors(dword start_sector, word count, byte* outbuf) bool IDEDiskDevice::read_sectors(u32 start_sector, u16 count, u8* outbuf)
{ {
ASSERT(count <= 256); ASSERT(count <= 256);
LOCKER(m_lock); LOCKER(m_lock);
@ -369,7 +369,7 @@ bool IDEDiskDevice::read_sectors(dword start_sector, word count, byte* outbuf)
if (m_device_error) if (m_device_error)
return false; return false;
byte status = IO::in8(m_io_base + ATA_REG_STATUS); u8 status = IO::in8(m_io_base + ATA_REG_STATUS);
ASSERT(status & ATA_SR_DRQ); ASSERT(status & ATA_SR_DRQ);
#ifdef DISK_DEBUG #ifdef DISK_DEBUG
kprintf("Retrieving %u bytes (status=%b), outbuf=%p...\n", count * 512, status, outbuf); kprintf("Retrieving %u bytes (status=%b), outbuf=%p...\n", count * 512, status, outbuf);
@ -379,7 +379,7 @@ bool IDEDiskDevice::read_sectors(dword start_sector, word count, byte* outbuf)
return true; return true;
} }
bool IDEDiskDevice::write_sectors_with_dma(dword lba, word count, const byte* inbuf) bool IDEDiskDevice::write_sectors_with_dma(u32 lba, u16 count, const u8* inbuf)
{ {
LOCKER(m_lock); LOCKER(m_lock);
#ifdef DISK_DEBUG #ifdef DISK_DEBUG
@ -401,7 +401,7 @@ bool IDEDiskDevice::write_sectors_with_dma(dword lba, word count, const byte* in
IO::out8(m_bus_master_base, 0); IO::out8(m_bus_master_base, 0);
// Write the PRDT location // Write the PRDT location
IO::out32(m_bus_master_base + 4, (dword)&m_prdt); IO::out32(m_bus_master_base + 4, (u32)&m_prdt);
// Turn on "Interrupt" and "Error" flag. The error flag should be cleared by hardware. // Turn on "Interrupt" and "Error" flag. The error flag should be cleared by hardware.
IO::out8(m_bus_master_base + 2, IO::in8(m_bus_master_base + 2) | 0x6); IO::out8(m_bus_master_base + 2, IO::in8(m_bus_master_base + 2) | 0x6);
@ -453,7 +453,7 @@ bool IDEDiskDevice::write_sectors_with_dma(dword lba, word count, const byte* in
return true; return true;
} }
bool IDEDiskDevice::write_sectors(dword start_sector, word count, const byte* data) bool IDEDiskDevice::write_sectors(u32 start_sector, u16 count, const u8* data)
{ {
ASSERT(count <= 256); ASSERT(count <= 256);
LOCKER(m_lock); LOCKER(m_lock);
@ -484,7 +484,7 @@ bool IDEDiskDevice::write_sectors(dword start_sector, word count, const byte* da
while (!(IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_DRQ)) while (!(IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_DRQ))
; ;
byte status = IO::in8(m_io_base + ATA_REG_STATUS); u8 status = IO::in8(m_io_base + ATA_REG_STATUS);
ASSERT(status & ATA_SR_DRQ); ASSERT(status & ATA_SR_DRQ);
IO::repeated_out16(m_io_base + ATA_REG_DATA, data, count * 256); IO::repeated_out16(m_io_base + ATA_REG_DATA, data, count * 256);

View file

@ -10,8 +10,8 @@
struct PhysicalRegionDescriptor { struct PhysicalRegionDescriptor {
PhysicalAddress offset; PhysicalAddress offset;
word size { 0 }; u16 size { 0 };
word end_of_table { 0 }; u16 end_of_table { 0 };
}; };
class IDEDiskDevice final : public IRQHandler class IDEDiskDevice final : public IRQHandler
@ -23,10 +23,10 @@ public:
// ^DiskDevice // ^DiskDevice
virtual unsigned block_size() const override; virtual unsigned block_size() const override;
virtual bool read_block(unsigned index, byte*) const override; virtual bool read_block(unsigned index, u8*) const override;
virtual bool write_block(unsigned index, const byte*) override; virtual bool write_block(unsigned index, const u8*) override;
virtual bool read_blocks(unsigned index, word count, byte*) override; virtual bool read_blocks(unsigned index, u16 count, u8*) override;
virtual bool write_blocks(unsigned index, word count, const byte*) override; virtual bool write_blocks(unsigned index, u16 count, const u8*) override;
protected: protected:
IDEDiskDevice(); IDEDiskDevice();
@ -40,22 +40,22 @@ private:
void initialize(); void initialize();
bool wait_for_irq(); bool wait_for_irq();
bool read_sectors_with_dma(dword lba, word count, byte*); bool read_sectors_with_dma(u32 lba, u16 count, u8*);
bool write_sectors_with_dma(dword lba, word count, const byte*); bool write_sectors_with_dma(u32 lba, u16 count, const u8*);
bool read_sectors(dword lba, word count, byte* buffer); bool read_sectors(u32 lba, u16 count, u8* buffer);
bool write_sectors(dword lba, word count, const byte* data); bool write_sectors(u32 lba, u16 count, const u8* data);
Lock m_lock { "IDEDiskDevice" }; Lock m_lock { "IDEDiskDevice" };
word m_cylinders { 0 }; u16 m_cylinders { 0 };
word m_heads { 0 }; u16 m_heads { 0 };
word m_sectors_per_track { 0 }; u16 m_sectors_per_track { 0 };
word m_io_base { 0 }; u16 m_io_base { 0 };
volatile bool m_interrupted { false }; volatile bool m_interrupted { false };
volatile byte m_device_error { 0 }; volatile u8 m_device_error { 0 };
PCI::Address m_pci_address; PCI::Address m_pci_address;
PhysicalRegionDescriptor m_prdt; PhysicalRegionDescriptor m_prdt;
RefPtr<PhysicalPage> m_dma_buffer_page; RefPtr<PhysicalPage> m_dma_buffer_page;
word m_bus_master_base { 0 }; u16 m_bus_master_base { 0 };
Lockable<bool> m_dma_enabled; Lockable<bool> m_dma_enabled;
}; };

View file

@ -223,7 +223,7 @@ static KeyCode shifted_key_map[0x100] = {
Key_Logo, Key_Logo,
}; };
void KeyboardDevice::key_state_changed(byte raw, bool pressed) void KeyboardDevice::key_state_changed(u8 raw, bool pressed)
{ {
Event event; Event event;
event.key = (m_modifiers & Mod_Shift) ? shifted_key_map[raw] : unshifted_key_map[raw]; event.key = (m_modifiers & Mod_Shift) ? shifted_key_map[raw] : unshifted_key_map[raw];
@ -239,11 +239,11 @@ void KeyboardDevice::key_state_changed(byte raw, bool pressed)
void KeyboardDevice::handle_irq() void KeyboardDevice::handle_irq()
{ {
for (;;) { for (;;) {
byte status = IO::in8(I8042_STATUS); u8 status = IO::in8(I8042_STATUS);
if (!(((status & I8042_WHICH_BUFFER) == I8042_KEYBOARD_BUFFER) && (status & I8042_BUFFER_FULL))) if (!(((status & I8042_WHICH_BUFFER) == I8042_KEYBOARD_BUFFER) && (status & I8042_BUFFER_FULL)))
return; return;
byte raw = IO::in8(I8042_BUFFER); u8 raw = IO::in8(I8042_BUFFER);
byte ch = raw & 0x7f; u8 ch = raw & 0x7f;
bool pressed = !(raw & 0x80); bool pressed = !(raw & 0x80);
#ifdef KEYBOARD_DEBUG #ifdef KEYBOARD_DEBUG
@ -316,7 +316,7 @@ bool KeyboardDevice::can_read(FileDescription&) const
return !m_queue.is_empty(); return !m_queue.is_empty();
} }
ssize_t KeyboardDevice::read(FileDescription&, byte* buffer, ssize_t size) ssize_t KeyboardDevice::read(FileDescription&, u8* buffer, ssize_t size)
{ {
ssize_t nread = 0; ssize_t nread = 0;
while (nread < size) { while (nread < size) {
@ -332,7 +332,7 @@ ssize_t KeyboardDevice::read(FileDescription&, byte* buffer, ssize_t size)
return nread; return nread;
} }
ssize_t KeyboardDevice::write(FileDescription&, const byte*, ssize_t) ssize_t KeyboardDevice::write(FileDescription&, const u8*, ssize_t)
{ {
return 0; return 0;
} }

View file

@ -23,9 +23,9 @@ public:
void set_client(KeyboardClient* client) { m_client = client; } void set_client(KeyboardClient* client) { m_client = client; }
// ^CharacterDevice // ^CharacterDevice
virtual ssize_t read(FileDescription&, byte* buffer, ssize_t) override; virtual ssize_t read(FileDescription&, u8* buffer, ssize_t) override;
virtual bool can_read(FileDescription&) const override; virtual bool can_read(FileDescription&) const override;
virtual ssize_t write(FileDescription&, const byte* buffer, ssize_t) override; virtual ssize_t write(FileDescription&, const u8* buffer, ssize_t) override;
virtual bool can_write(FileDescription&) const override { return true; } virtual bool can_write(FileDescription&) const override { return true; }
private: private:
@ -35,8 +35,8 @@ private:
// ^CharacterDevice // ^CharacterDevice
virtual const char* class_name() const override { return "KeyboardDevice"; } virtual const char* class_name() const override { return "KeyboardDevice"; }
void key_state_changed(byte raw, bool pressed); void key_state_changed(u8 raw, bool pressed);
void update_modifier(byte modifier, bool state) void update_modifier(u8 modifier, bool state)
{ {
if (state) if (state)
m_modifiers |= modifier; m_modifiers |= modifier;
@ -46,7 +46,7 @@ private:
KeyboardClient* m_client { nullptr }; KeyboardClient* m_client { nullptr };
CircularQueue<Event, 16> m_queue; CircularQueue<Event, 16> m_queue;
byte m_modifiers { 0 }; u8 m_modifiers { 0 };
}; };
class KeyboardClient { class KeyboardClient {

View file

@ -8,23 +8,23 @@
#define MBR_SIGNATURE 0xaa55 #define MBR_SIGNATURE 0xaa55
struct MBRPartitionEntry { struct MBRPartitionEntry {
byte status; u8 status;
byte chs1[3]; u8 chs1[3];
byte type; u8 type;
byte chs2[3]; u8 chs2[3];
dword offset; u32 offset;
dword length; u32 length;
} __attribute__((packed)); } __attribute__((packed));
struct MBRPartitionHeader { struct MBRPartitionHeader {
byte code1[218]; u8 code1[218];
word ts_zero; u16 ts_zero;
byte ts_drive, ts_seconds, ts_minutes, ts_hours; u8 ts_drive, ts_seconds, ts_minutes, ts_hours;
byte code2[216]; u8 code2[216];
dword disk_signature; u32 disk_signature;
word disk_signature_zero; u16 disk_signature_zero;
MBRPartitionEntry entry[4]; MBRPartitionEntry entry[4];
word mbr_signature; u16 mbr_signature;
} __attribute__((packed)); } __attribute__((packed));
class MBRPartitionTable { class MBRPartitionTable {
@ -43,5 +43,5 @@ private:
ByteBuffer read_header() const; ByteBuffer read_header() const;
const MBRPartitionHeader& header() const; const MBRPartitionHeader& header() const;
byte m_cached_header[512]; u8 m_cached_header[512];
}; };

View file

@ -25,12 +25,12 @@ bool NullDevice::can_read(FileDescription&) const
return true; return true;
} }
ssize_t NullDevice::read(FileDescription&, byte*, ssize_t) ssize_t NullDevice::read(FileDescription&, u8*, ssize_t)
{ {
return 0; return 0;
} }
ssize_t NullDevice::write(FileDescription&, const byte*, ssize_t buffer_size) ssize_t NullDevice::write(FileDescription&, const u8*, ssize_t buffer_size)
{ {
return min(PAGE_SIZE, buffer_size); return min(PAGE_SIZE, buffer_size);
} }

View file

@ -12,8 +12,8 @@ public:
private: private:
// ^CharacterDevice // ^CharacterDevice
virtual ssize_t read(FileDescription&, byte*, ssize_t) override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
virtual bool can_write(FileDescription&) const override { return true; } virtual bool can_write(FileDescription&) const override { return true; }
virtual bool can_read(FileDescription&) const override; virtual bool can_read(FileDescription&) const override;
virtual const char* class_name() const override { return "NullDevice"; } virtual const char* class_name() const override { return "NullDevice"; }

View file

@ -6,7 +6,7 @@
void PCSpeaker::tone_on(int frequency) void PCSpeaker::tone_on(int frequency)
{ {
IO::out8(PIT_CTL, TIMER2_SELECT | WRITE_WORD | MODE_SQUARE_WAVE); IO::out8(PIT_CTL, TIMER2_SELECT | WRITE_WORD | MODE_SQUARE_WAVE);
word timer_reload = BASE_FREQUENCY / frequency; u16 timer_reload = BASE_FREQUENCY / frequency;
IO::out8(TIMER2_CTL, LSB(timer_reload)); IO::out8(TIMER2_CTL, LSB(timer_reload));
IO::out8(TIMER2_CTL, MSB(timer_reload)); IO::out8(TIMER2_CTL, MSB(timer_reload));

View file

@ -39,11 +39,11 @@ PS2MouseDevice& PS2MouseDevice::the()
void PS2MouseDevice::handle_irq() void PS2MouseDevice::handle_irq()
{ {
for (;;) { for (;;) {
byte status = IO::in8(I8042_STATUS); u8 status = IO::in8(I8042_STATUS);
if (!(((status & I8042_WHICH_BUFFER) == I8042_MOUSE_BUFFER) && (status & I8042_BUFFER_FULL))) if (!(((status & I8042_WHICH_BUFFER) == I8042_MOUSE_BUFFER) && (status & I8042_BUFFER_FULL)))
return; return;
byte data = IO::in8(I8042_BUFFER); u8 data = IO::in8(I8042_BUFFER);
m_data[m_data_state] = data; m_data[m_data_state] = data;
auto commit_packet = [&] { auto commit_packet = [&] {
@ -113,13 +113,13 @@ void PS2MouseDevice::parse_data_packet()
m_queue.enqueue(packet); m_queue.enqueue(packet);
} }
void PS2MouseDevice::wait_then_write(byte port, byte data) void PS2MouseDevice::wait_then_write(u8 port, u8 data)
{ {
prepare_for_output(); prepare_for_output();
IO::out8(port, data); IO::out8(port, data);
} }
byte PS2MouseDevice::wait_then_read(byte port) u8 PS2MouseDevice::wait_then_read(u8 port)
{ {
prepare_for_input(); prepare_for_input();
return IO::in8(port); return IO::in8(port);
@ -135,7 +135,7 @@ void PS2MouseDevice::initialize()
// Enable the PS/2 mouse IRQ (12). // Enable the PS/2 mouse IRQ (12).
// NOTE: The keyboard uses IRQ 1 (and is enabled by bit 0 in this register). // NOTE: The keyboard uses IRQ 1 (and is enabled by bit 0 in this register).
byte status = wait_then_read(0x60) | 2; u8 status = wait_then_read(0x60) | 2;
wait_then_write(0x64, 0x60); wait_then_write(0x64, 0x60);
wait_then_write(0x60, status); wait_then_write(0x60, status);
@ -149,7 +149,7 @@ void PS2MouseDevice::initialize()
mouse_write(PS2MOUSE_GET_DEVICE_ID); mouse_write(PS2MOUSE_GET_DEVICE_ID);
expect_ack(); expect_ack();
byte device_id = mouse_read(); u8 device_id = mouse_read();
if (device_id != PS2MOUSE_INTELLIMOUSE_ID) { if (device_id != PS2MOUSE_INTELLIMOUSE_ID) {
// Send magical wheel initiation sequence. // Send magical wheel initiation sequence.
@ -183,7 +183,7 @@ void PS2MouseDevice::initialize()
void PS2MouseDevice::expect_ack() void PS2MouseDevice::expect_ack()
{ {
byte data = mouse_read(); u8 data = mouse_read();
ASSERT(data == I8042_ACK); ASSERT(data == I8042_ACK);
} }
@ -203,7 +203,7 @@ void PS2MouseDevice::prepare_for_output()
} }
} }
void PS2MouseDevice::mouse_write(byte data) void PS2MouseDevice::mouse_write(u8 data)
{ {
prepare_for_output(); prepare_for_output();
IO::out8(0x64, 0xd4); IO::out8(0x64, 0xd4);
@ -211,7 +211,7 @@ void PS2MouseDevice::mouse_write(byte data)
IO::out8(0x60, data); IO::out8(0x60, data);
} }
byte PS2MouseDevice::mouse_read() u8 PS2MouseDevice::mouse_read()
{ {
prepare_for_input(); prepare_for_input();
return IO::in8(0x60); return IO::in8(0x60);
@ -222,7 +222,7 @@ bool PS2MouseDevice::can_read(FileDescription&) const
return !m_queue.is_empty(); return !m_queue.is_empty();
} }
ssize_t PS2MouseDevice::read(FileDescription&, byte* buffer, ssize_t size) ssize_t PS2MouseDevice::read(FileDescription&, u8* buffer, ssize_t size)
{ {
ssize_t nread = 0; ssize_t nread = 0;
while (nread < size) { while (nread < size) {
@ -238,7 +238,7 @@ ssize_t PS2MouseDevice::read(FileDescription&, byte* buffer, ssize_t size)
return nread; return nread;
} }
ssize_t PS2MouseDevice::write(FileDescription&, const byte*, ssize_t) ssize_t PS2MouseDevice::write(FileDescription&, const u8*, ssize_t)
{ {
return 0; return 0;
} }

View file

@ -15,8 +15,8 @@ public:
// ^CharacterDevice // ^CharacterDevice
virtual bool can_read(FileDescription&) const override; virtual bool can_read(FileDescription&) const override;
virtual ssize_t read(FileDescription&, byte*, ssize_t) override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
virtual bool can_write(FileDescription&) const override { return true; } virtual bool can_write(FileDescription&) const override { return true; }
private: private:
@ -29,15 +29,15 @@ private:
void initialize(); void initialize();
void prepare_for_input(); void prepare_for_input();
void prepare_for_output(); void prepare_for_output();
void mouse_write(byte); void mouse_write(u8);
byte mouse_read(); u8 mouse_read();
void wait_then_write(byte port, byte data); void wait_then_write(u8 port, u8 data);
byte wait_then_read(byte port); u8 wait_then_read(u8 port);
void parse_data_packet(); void parse_data_packet();
void expect_ack(); void expect_ack();
CircularQueue<MousePacket, 100> m_queue; CircularQueue<MousePacket, 100> m_queue;
byte m_data_state { 0 }; u8 m_data_state { 0 };
byte m_data[4]; u8 m_data[4];
bool m_has_wheel { false }; bool m_has_wheel { false };
}; };

View file

@ -10,10 +10,10 @@ RandomDevice::~RandomDevice()
{ {
} }
static dword next = 1; static u32 next = 1;
#define MY_RAND_MAX 4294967295U #define MY_RAND_MAX 4294967295U
dword RandomDevice::random_value() u32 RandomDevice::random_value()
{ {
next = next * 1103515245 + 12345; next = next * 1103515245 + 12345;
return next; return next;
@ -31,18 +31,18 @@ bool RandomDevice::can_read(FileDescription&) const
return true; return true;
} }
ssize_t RandomDevice::read(FileDescription&, byte* buffer, ssize_t size) ssize_t RandomDevice::read(FileDescription&, u8* buffer, ssize_t size)
{ {
const int range = 'z' - 'a'; const int range = 'z' - 'a';
ssize_t nread = min(size, PAGE_SIZE); ssize_t nread = min(size, PAGE_SIZE);
for (ssize_t i = 0; i < nread; ++i) { for (ssize_t i = 0; i < nread; ++i) {
dword r = random_value() % range; u32 r = random_value() % range;
buffer[i] = (byte)('a' + r); buffer[i] = (u8)('a' + r);
} }
return nread; return nread;
} }
ssize_t RandomDevice::write(FileDescription&, const byte*, ssize_t size) ssize_t RandomDevice::write(FileDescription&, const u8*, ssize_t size)
{ {
// FIXME: Use input for entropy? I guess that could be a neat feature? // FIXME: Use input for entropy? I guess that could be a neat feature?
return min(PAGE_SIZE, size); return min(PAGE_SIZE, size);

View file

@ -8,12 +8,12 @@ public:
RandomDevice(); RandomDevice();
virtual ~RandomDevice() override; virtual ~RandomDevice() override;
static dword random_value(); static u32 random_value();
private: private:
// ^CharacterDevice // ^CharacterDevice
virtual ssize_t read(FileDescription&, byte*, ssize_t) override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
virtual bool can_read(FileDescription&) const override; virtual bool can_read(FileDescription&) const override;
virtual bool can_write(FileDescription&) const override { return true; } virtual bool can_write(FileDescription&) const override { return true; }
virtual const char* class_name() const override { return "RandomDevice"; } virtual const char* class_name() const override { return "RandomDevice"; }

View file

@ -17,7 +17,7 @@ bool SerialDevice::can_read(FileDescription&) const
return (get_line_status() & DataReady) != 0; return (get_line_status() & DataReady) != 0;
} }
ssize_t SerialDevice::read(FileDescription&, byte* buffer, ssize_t size) ssize_t SerialDevice::read(FileDescription&, u8* buffer, ssize_t size)
{ {
if (!size) if (!size)
return 0; return 0;
@ -35,7 +35,7 @@ bool SerialDevice::can_write(FileDescription&) const
return (get_line_status() & EmptyTransmitterHoldingRegister) != 0; return (get_line_status() & EmptyTransmitterHoldingRegister) != 0;
} }
ssize_t SerialDevice::write(FileDescription&, const byte* buffer, ssize_t size) ssize_t SerialDevice::write(FileDescription&, const u8* buffer, ssize_t size)
{ {
if (!size) if (!size)
return 0; return 0;

View file

@ -13,9 +13,9 @@ public:
// ^CharacterDevice // ^CharacterDevice
virtual bool can_read(FileDescription&) const override; virtual bool can_read(FileDescription&) const override;
virtual ssize_t read(FileDescription&, byte*, ssize_t) override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
virtual bool can_write(FileDescription&) const override; virtual bool can_write(FileDescription&) const override;
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
enum InterruptEnable { enum InterruptEnable {
LowPowerMode = 0x01 << 5, LowPowerMode = 0x01 << 5,

View file

@ -16,14 +16,14 @@ bool ZeroDevice::can_read(FileDescription&) const
return true; return true;
} }
ssize_t ZeroDevice::read(FileDescription&, byte* buffer, ssize_t size) ssize_t ZeroDevice::read(FileDescription&, u8* buffer, ssize_t size)
{ {
ssize_t count = min(PAGE_SIZE, size); ssize_t count = min(PAGE_SIZE, size);
memset(buffer, 0, (size_t)count); memset(buffer, 0, (size_t)count);
return count; return count;
} }
ssize_t ZeroDevice::write(FileDescription&, const byte*, ssize_t size) ssize_t ZeroDevice::write(FileDescription&, const u8*, ssize_t size)
{ {
return min(PAGE_SIZE, size); return min(PAGE_SIZE, size);
} }

View file

@ -10,8 +10,8 @@ public:
private: private:
// ^CharacterDevice // ^CharacterDevice
virtual ssize_t read(FileDescription&, byte*, ssize_t) override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
virtual bool can_read(FileDescription&) const override; virtual bool can_read(FileDescription&) const override;
virtual bool can_write(FileDescription&) const override { return true; } virtual bool can_write(FileDescription&) const override { return true; }
virtual const char* class_name() const override { return "ZeroDevice"; } virtual const char* class_name() const override { return "ZeroDevice"; }

View file

@ -17,7 +17,7 @@ void DoubleBuffer::flip()
compute_emptiness(); compute_emptiness();
} }
ssize_t DoubleBuffer::write(const byte* data, ssize_t size) ssize_t DoubleBuffer::write(const u8* data, ssize_t size)
{ {
if (!size) if (!size)
return 0; return 0;
@ -27,7 +27,7 @@ ssize_t DoubleBuffer::write(const byte* data, ssize_t size)
return size; return size;
} }
ssize_t DoubleBuffer::read(byte* data, ssize_t size) ssize_t DoubleBuffer::read(u8* data, ssize_t size)
{ {
if (!size) if (!size)
return 0; return 0;

View file

@ -12,8 +12,8 @@ public:
{ {
} }
ssize_t write(const byte*, ssize_t); ssize_t write(const u8*, ssize_t);
ssize_t read(byte*, ssize_t); ssize_t read(u8*, ssize_t);
bool is_empty() const { return m_empty; } bool is_empty() const { return m_empty; }
@ -24,10 +24,10 @@ private:
void flip(); void flip();
void compute_emptiness(); void compute_emptiness();
Vector<byte>* m_write_buffer { nullptr }; Vector<u8>* m_write_buffer { nullptr };
Vector<byte>* m_read_buffer { nullptr }; Vector<u8>* m_read_buffer { nullptr };
Vector<byte> m_buffer1; Vector<u8> m_buffer1;
Vector<byte> m_buffer2; Vector<u8> m_buffer2;
ssize_t m_read_buffer_index { 0 }; ssize_t m_read_buffer_index { 0 };
bool m_empty { true }; bool m_empty { true };
Lock m_lock { "DoubleBuffer" }; Lock m_lock { "DoubleBuffer" };

View file

@ -49,8 +49,8 @@ public:
virtual bool can_read(FileDescription&) const = 0; virtual bool can_read(FileDescription&) const = 0;
virtual bool can_write(FileDescription&) const = 0; virtual bool can_write(FileDescription&) const = 0;
virtual ssize_t read(FileDescription&, byte*, ssize_t) = 0; virtual ssize_t read(FileDescription&, u8*, ssize_t) = 0;
virtual ssize_t write(FileDescription&, const byte*, ssize_t) = 0; virtual ssize_t write(FileDescription&, const u8*, ssize_t) = 0;
virtual int ioctl(FileDescription&, unsigned request, unsigned arg); virtual int ioctl(FileDescription&, unsigned request, unsigned arg);
virtual KResultOr<Region*> mmap(Process&, FileDescription&, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot); virtual KResultOr<Region*> mmap(Process&, FileDescription&, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot);

View file

@ -126,7 +126,7 @@ ByteBuffer DiskBackedFS::read_blocks(unsigned index, unsigned count) const
if (count == 1) if (count == 1)
return read_block(index); return read_block(index);
auto blocks = ByteBuffer::create_uninitialized(count * block_size()); auto blocks = ByteBuffer::create_uninitialized(count * block_size());
byte* out = blocks.pointer(); u8* out = blocks.pointer();
for (unsigned i = 0; i < count; ++i) { for (unsigned i = 0; i < count; ++i) {
auto block = read_block(index + i); auto block = read_block(index + i);

View file

@ -12,7 +12,7 @@
static const ssize_t max_inline_symlink_length = 60; static const ssize_t max_inline_symlink_length = 60;
static byte to_ext2_file_type(mode_t mode) static u8 to_ext2_file_type(mode_t mode)
{ {
if (is_regular_file(mode)) if (is_regular_file(mode))
return EXT2_FT_REG_FILE; return EXT2_FT_REG_FILE;
@ -59,7 +59,7 @@ ByteBuffer Ext2FS::read_super_block() const
bool Ext2FS::write_super_block(const ext2_super_block& sb) bool Ext2FS::write_super_block(const ext2_super_block& sb)
{ {
LOCKER(m_lock); LOCKER(m_lock);
const byte* raw = (const byte*)&sb; const u8* raw = (const u8*)&sb;
bool success; bool success;
success = device().write_block(2, raw); success = device().write_block(2, raw);
ASSERT(success); ASSERT(success);
@ -479,7 +479,7 @@ RefPtr<Inode> Ext2FS::get_inode(InodeIdentifier inode) const
return new_inode; return new_inode;
} }
ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription*) const ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDescription*) const
{ {
Locker inode_locker(m_lock); Locker inode_locker(m_lock);
ASSERT(offset >= 0); ASSERT(offset >= 0);
@ -490,7 +490,7 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileD
// This avoids wasting an entire block on short links. (Most links are short.) // This avoids wasting an entire block on short links. (Most links are short.)
if (is_symlink() && size() < max_inline_symlink_length) { if (is_symlink() && size() < max_inline_symlink_length) {
ssize_t nread = min((off_t)size() - offset, static_cast<off_t>(count)); ssize_t nread = min((off_t)size() - offset, static_cast<off_t>(count));
memcpy(buffer, ((const byte*)m_raw_inode.i_block) + offset, (size_t)nread); memcpy(buffer, ((const u8*)m_raw_inode.i_block) + offset, (size_t)nread);
return nread; return nread;
} }
@ -518,7 +518,7 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileD
ssize_t nread = 0; ssize_t nread = 0;
int remaining_count = min((off_t)count, (off_t)size() - offset); int remaining_count = min((off_t)count, (off_t)size() - offset);
byte* out = buffer; u8* out = buffer;
#ifdef EXT2_DEBUG #ifdef EXT2_DEBUG
kprintf("Ext2FS: Reading up to %u bytes %d bytes into inode %u:%u to %p\n", count, offset, identifier().fsid(), identifier().index(), buffer); kprintf("Ext2FS: Reading up to %u bytes %d bytes into inode %u:%u to %p\n", count, offset, identifier().fsid(), identifier().index(), buffer);
@ -543,10 +543,10 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileD
return nread; return nread;
} }
bool Ext2FSInode::resize(qword new_size) bool Ext2FSInode::resize(u64 new_size)
{ {
qword block_size = fs().block_size(); u64 block_size = fs().block_size();
qword old_size = size(); u64 old_size = size();
int blocks_needed_before = ceil_div(old_size, block_size); int blocks_needed_before = ceil_div(old_size, block_size);
int blocks_needed_after = ceil_div(new_size, block_size); int blocks_needed_after = ceil_div(new_size, block_size);
@ -585,7 +585,7 @@ bool Ext2FSInode::resize(qword new_size)
return true; return true;
} }
ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const byte* data, FileDescription*) ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const u8* data, FileDescription*)
{ {
ASSERT(offset >= 0); ASSERT(offset >= 0);
ASSERT(count >= 0); ASSERT(count >= 0);
@ -598,7 +598,7 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const byte* data,
#ifdef EXT2_DEBUG #ifdef EXT2_DEBUG
dbgprintf("Ext2FSInode: write_bytes poking into i_block array for inline symlink '%s' (%u bytes)\n", String((const char*)data, count).characters(), count); dbgprintf("Ext2FSInode: write_bytes poking into i_block array for inline symlink '%s' (%u bytes)\n", String((const char*)data, count).characters(), count);
#endif #endif
memcpy(((byte*)m_raw_inode.i_block) + offset, data, (size_t)count); memcpy(((u8*)m_raw_inode.i_block) + offset, data, (size_t)count);
if ((offset + count) > (off_t)m_raw_inode.i_size) if ((offset + count) > (off_t)m_raw_inode.i_size)
m_raw_inode.i_size = offset + count; m_raw_inode.i_size = offset + count;
set_metadata_dirty(true); set_metadata_dirty(true);
@ -607,8 +607,8 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const byte* data,
} }
const ssize_t block_size = fs().block_size(); const ssize_t block_size = fs().block_size();
qword old_size = size(); u64 old_size = size();
qword new_size = max(static_cast<qword>(offset) + count, (qword)size()); u64 new_size = max(static_cast<u64>(offset) + count, (u64)size());
if (!resize(new_size)) if (!resize(new_size))
return -EIO; return -EIO;
@ -624,7 +624,7 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const byte* data,
ssize_t nwritten = 0; ssize_t nwritten = 0;
int remaining_count = min((off_t)count, (off_t)new_size - offset); int remaining_count = min((off_t)count, (off_t)new_size - offset);
const byte* in = data; const u8* in = data;
#ifdef EXT2_DEBUG #ifdef EXT2_DEBUG
dbgprintf("Ext2FSInode::write_bytes: Writing %u bytes %d bytes into inode %u:%u from %p\n", count, offset, fsid(), index(), data); dbgprintf("Ext2FSInode::write_bytes: Writing %u bytes %d bytes into inode %u:%u from %p\n", count, offset, fsid(), index(), data);
@ -733,20 +733,20 @@ bool Ext2FSInode::write_directory(const Vector<FS::DirectoryEntry>& entries)
record_length += occupied_size - directory_size; record_length += occupied_size - directory_size;
dbgprintf("* inode: %u", entry.inode.index()); dbgprintf("* inode: %u", entry.inode.index());
dbgprintf(", name_len: %u", word(entry.name_length)); dbgprintf(", name_len: %u", u16(entry.name_length));
dbgprintf(", rec_len: %u", word(record_length)); dbgprintf(", rec_len: %u", u16(record_length));
dbgprintf(", file_type: %u", byte(entry.file_type)); dbgprintf(", file_type: %u", u8(entry.file_type));
dbgprintf(", name: %s\n", entry.name); dbgprintf(", name: %s\n", entry.name);
stream << dword(entry.inode.index()); stream << u32(entry.inode.index());
stream << word(record_length); stream << u16(record_length);
stream << byte(entry.name_length); stream << u8(entry.name_length);
stream << byte(entry.file_type); stream << u8(entry.file_type);
stream << entry.name; stream << entry.name;
int padding = record_length - entry.name_length - 8; int padding = record_length - entry.name_length - 8;
for (int j = 0; j < padding; ++j) for (int j = 0; j < padding; ++j)
stream << byte(0); stream << u8(0);
} }
stream.fill_to_end(0); stream.fill_to_end(0);

View file

@ -25,12 +25,12 @@ public:
private: private:
// ^Inode // ^Inode
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescription*) const override; virtual ssize_t read_bytes(off_t, ssize_t, u8* buffer, FileDescription*) const override;
virtual InodeMetadata metadata() const override; virtual InodeMetadata metadata() const override;
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override; virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override;
virtual InodeIdentifier lookup(StringView name) override; virtual InodeIdentifier lookup(StringView name) override;
virtual void flush_metadata() override; virtual void flush_metadata() override;
virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescription*) override; virtual ssize_t write_bytes(off_t, ssize_t, const u8* data, FileDescription*) override;
virtual KResult add_child(InodeIdentifier child_id, const StringView& name, mode_t) override; virtual KResult add_child(InodeIdentifier child_id, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override; virtual KResult remove_child(const StringView& name) override;
virtual int set_atime(time_t) override; virtual int set_atime(time_t) override;
@ -45,7 +45,7 @@ private:
bool write_directory(const Vector<FS::DirectoryEntry>&); bool write_directory(const Vector<FS::DirectoryEntry>&);
void populate_lookup_cache() const; void populate_lookup_cache() const;
bool resize(qword); bool resize(u64);
Ext2FS& fs(); Ext2FS& fs();
const Ext2FS& fs() const; const Ext2FS& fs() const;

View file

@ -16,7 +16,7 @@ Lockable<HashTable<FIFO*>>& all_fifos()
return *s_table; return *s_table;
} }
RefPtr<FIFO> FIFO::from_fifo_id(dword id) RefPtr<FIFO> FIFO::from_fifo_id(u32 id)
{ {
auto* ptr = reinterpret_cast<FIFO*>(id); auto* ptr = reinterpret_cast<FIFO*>(id);
LOCKER(all_fifos().lock()); LOCKER(all_fifos().lock());
@ -93,7 +93,7 @@ bool FIFO::can_write(FileDescription&) const
return m_buffer.bytes_in_write_buffer() < 4096 || !m_readers; return m_buffer.bytes_in_write_buffer() < 4096 || !m_readers;
} }
ssize_t FIFO::read(FileDescription&, byte* buffer, ssize_t size) ssize_t FIFO::read(FileDescription&, u8* buffer, ssize_t size)
{ {
if (!m_writers && m_buffer.is_empty()) if (!m_writers && m_buffer.is_empty())
return 0; return 0;
@ -107,7 +107,7 @@ ssize_t FIFO::read(FileDescription&, byte* buffer, ssize_t size)
return nread; return nread;
} }
ssize_t FIFO::write(FileDescription&, const byte* buffer, ssize_t size) ssize_t FIFO::write(FileDescription&, const u8* buffer, ssize_t size)
{ {
if (!m_readers) { if (!m_readers) {
current->process().send_signal(SIGPIPE, &current->process()); current->process().send_signal(SIGPIPE, &current->process());

View file

@ -8,13 +8,13 @@ class FileDescription;
class FIFO final : public File { class FIFO final : public File {
public: public:
enum class Direction : byte { enum class Direction : u8 {
Neither, Neither,
Reader, Reader,
Writer Writer
}; };
static RefPtr<FIFO> from_fifo_id(dword); static RefPtr<FIFO> from_fifo_id(u32);
static NonnullRefPtr<FIFO> create(uid_t); static NonnullRefPtr<FIFO> create(uid_t);
virtual ~FIFO() override; virtual ~FIFO() override;
@ -28,8 +28,8 @@ public:
private: private:
// ^File // ^File
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
virtual ssize_t read(FileDescription&, byte*, ssize_t) override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
virtual bool can_read(FileDescription&) const override; virtual bool can_read(FileDescription&) const override;
virtual bool can_write(FileDescription&) const override; virtual bool can_write(FileDescription&) const override;
virtual String absolute_path(const FileDescription&) const override; virtual String absolute_path(const FileDescription&) const override;

View file

@ -127,7 +127,7 @@ off_t FileDescription::seek(off_t offset, int whence)
return m_current_offset; return m_current_offset;
} }
ssize_t FileDescription::read(byte* buffer, ssize_t count) ssize_t FileDescription::read(u8* buffer, ssize_t count)
{ {
int nread = m_file->read(*this, buffer, count); int nread = m_file->read(*this, buffer, count);
if (m_file->is_seekable()) if (m_file->is_seekable())
@ -135,7 +135,7 @@ ssize_t FileDescription::read(byte* buffer, ssize_t count)
return nread; return nread;
} }
ssize_t FileDescription::write(const byte* data, ssize_t size) ssize_t FileDescription::write(const u8* data, ssize_t size)
{ {
int nwritten = m_file->write(*this, data, size); int nwritten = m_file->write(*this, data, size);
if (m_file->is_seekable()) if (m_file->is_seekable())
@ -167,7 +167,7 @@ bool FileDescription::is_directory() const
return metadata().is_directory(); return metadata().is_directory();
} }
ssize_t FileDescription::get_dir_entries(byte* buffer, ssize_t size) ssize_t FileDescription::get_dir_entries(u8* buffer, ssize_t size)
{ {
auto metadata = this->metadata(); auto metadata = this->metadata();
if (!metadata.is_valid()) if (!metadata.is_valid())
@ -180,9 +180,9 @@ ssize_t FileDescription::get_dir_entries(byte* buffer, ssize_t size)
auto temp_buffer = ByteBuffer::create_uninitialized(size_to_allocate); auto temp_buffer = ByteBuffer::create_uninitialized(size_to_allocate);
BufferStream stream(temp_buffer); BufferStream stream(temp_buffer);
VFS::the().traverse_directory_inode(*m_inode, [&stream](auto& entry) { VFS::the().traverse_directory_inode(*m_inode, [&stream](auto& entry) {
stream << (dword)entry.inode.index(); stream << (u32)entry.inode.index();
stream << (byte)entry.file_type; stream << (u8)entry.file_type;
stream << (dword)entry.name_length; stream << (u32)entry.name_length;
stream << entry.name; stream << entry.name;
return true; return true;
}); });
@ -318,7 +318,7 @@ const Socket* FileDescription::socket() const
return static_cast<const Socket*>(m_file.ptr()); return static_cast<const Socket*>(m_file.ptr());
} }
void FileDescription::set_file_flags(dword flags) void FileDescription::set_file_flags(u32 flags)
{ {
m_is_blocking = !(flags & O_NONBLOCK); m_is_blocking = !(flags & O_NONBLOCK);
m_should_append = flags & O_APPEND; m_should_append = flags & O_APPEND;

View file

@ -30,8 +30,8 @@ public:
int close(); int close();
off_t seek(off_t, int whence); off_t seek(off_t, int whence);
ssize_t read(byte*, ssize_t); ssize_t read(u8*, ssize_t);
ssize_t write(const byte* data, ssize_t); ssize_t write(const u8* data, ssize_t);
KResult fstat(stat&); KResult fstat(stat&);
KResult fchmod(mode_t); KResult fchmod(mode_t);
@ -39,7 +39,7 @@ public:
bool can_read(); bool can_read();
bool can_write(); bool can_write();
ssize_t get_dir_entries(byte* buffer, ssize_t); ssize_t get_dir_entries(u8* buffer, ssize_t);
ByteBuffer read_entire_file(); ByteBuffer read_entire_file();
@ -74,8 +74,8 @@ public:
bool should_append() const { return m_should_append; } bool should_append() const { return m_should_append; }
void set_should_append(bool s) { m_should_append = s; } void set_should_append(bool s) { m_should_append = s; }
dword file_flags() const { return m_file_flags; } u32 file_flags() const { return m_file_flags; }
void set_file_flags(dword); void set_file_flags(u32);
bool is_socket() const; bool is_socket() const;
Socket* socket(); Socket* socket();
@ -116,7 +116,7 @@ private:
ByteBuffer m_generator_cache; ByteBuffer m_generator_cache;
dword m_file_flags { 0 }; u32 m_file_flags { 0 };
bool m_is_blocking { true }; bool m_is_blocking { true };
bool m_should_append { false }; bool m_should_append { false };

View file

@ -7,13 +7,13 @@
#include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/MemoryManager.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
static dword s_lastFileSystemID; static u32 s_lastFileSystemID;
static HashMap<dword, FS*>* s_fs_map; static HashMap<u32, FS*>* s_fs_map;
static HashMap<dword, FS*>& all_fses() static HashMap<u32, FS*>& all_fses()
{ {
if (!s_fs_map) if (!s_fs_map)
s_fs_map = new HashMap<dword, FS*>(); s_fs_map = new HashMap<u32, FS*>();
return *s_fs_map; return *s_fs_map;
} }
@ -28,7 +28,7 @@ FS::~FS()
all_fses().remove(m_fsid); all_fses().remove(m_fsid);
} }
FS* FS::from_fsid(dword id) FS* FS::from_fsid(u32 id)
{ {
auto it = all_fses().find(id); auto it = all_fses().find(id);
if (it != all_fses().end()) if (it != all_fses().end())
@ -36,7 +36,7 @@ FS* FS::from_fsid(dword id)
return nullptr; return nullptr;
} }
FS::DirectoryEntry::DirectoryEntry(const char* n, InodeIdentifier i, byte ft) FS::DirectoryEntry::DirectoryEntry(const char* n, InodeIdentifier i, u8 ft)
: name_length(strlen(n)) : name_length(strlen(n))
, inode(i) , inode(i)
, file_type(ft) , file_type(ft)
@ -45,7 +45,7 @@ FS::DirectoryEntry::DirectoryEntry(const char* n, InodeIdentifier i, byte ft)
name[name_length] = '\0'; name[name_length] = '\0';
} }
FS::DirectoryEntry::DirectoryEntry(const char* n, int nl, InodeIdentifier i, byte ft) FS::DirectoryEntry::DirectoryEntry(const char* n, int nl, InodeIdentifier i, u8 ft)
: name_length(nl) : name_length(nl)
, inode(i) , inode(i)
, file_type(ft) , file_type(ft)

View file

@ -16,7 +16,7 @@
#include <Kernel/KResult.h> #include <Kernel/KResult.h>
#include <Kernel/Lock.h> #include <Kernel/Lock.h>
static const dword mepoch = 476763780; static const u32 mepoch = 476763780;
class Inode; class Inode;
class FileDescription; class FileDescription;
@ -30,7 +30,7 @@ public:
virtual ~FS(); virtual ~FS();
unsigned fsid() const { return m_fsid; } unsigned fsid() const { return m_fsid; }
static FS* from_fsid(dword); static FS* from_fsid(u32);
static void sync(); static void sync();
static void lock_all(); static void lock_all();
@ -46,12 +46,12 @@ public:
virtual unsigned free_inode_count() const { return 0; } virtual unsigned free_inode_count() const { return 0; }
struct DirectoryEntry { struct DirectoryEntry {
DirectoryEntry(const char* name, InodeIdentifier, byte file_type); DirectoryEntry(const char* name, InodeIdentifier, u8 file_type);
DirectoryEntry(const char* name, int name_length, InodeIdentifier, byte file_type); DirectoryEntry(const char* name, int name_length, InodeIdentifier, u8 file_type);
char name[256]; char name[256];
int name_length { 0 }; int name_length { 0 };
InodeIdentifier inode; InodeIdentifier inode;
byte file_type { 0 }; u8 file_type { 0 };
}; };
virtual RefPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, off_t size, dev_t, int& error) = 0; virtual RefPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, off_t size, dev_t, int& error) = 0;

View file

@ -35,7 +35,7 @@ ByteBuffer Inode::read_entire(FileDescription* descriptor) const
StringBuilder builder(initial_size); StringBuilder builder(initial_size);
ssize_t nread; ssize_t nread;
byte buffer[4096]; u8 buffer[4096];
off_t offset = 0; off_t offset = 0;
for (;;) { for (;;) {
nread = read_bytes(offset, sizeof(buffer), buffer, descriptor); nread = read_bytes(offset, sizeof(buffer), buffer, descriptor);
@ -76,7 +76,7 @@ void Inode::will_be_destroyed()
flush_metadata(); flush_metadata();
} }
void Inode::inode_contents_changed(off_t offset, ssize_t size, const byte* data) void Inode::inode_contents_changed(off_t offset, ssize_t size, const u8* data)
{ {
if (m_vmo) if (m_vmo)
m_vmo->inode_contents_changed({}, offset, size, data); m_vmo->inode_contents_changed({}, offset, size, data);

View file

@ -39,10 +39,10 @@ public:
ByteBuffer read_entire(FileDescription* = nullptr) const; ByteBuffer read_entire(FileDescription* = nullptr) const;
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescription*) const = 0; virtual ssize_t read_bytes(off_t, ssize_t, u8* buffer, FileDescription*) const = 0;
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const = 0; virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const = 0;
virtual InodeIdentifier lookup(StringView name) = 0; virtual InodeIdentifier lookup(StringView name) = 0;
virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescription*) = 0; virtual ssize_t write_bytes(off_t, ssize_t, const u8* data, FileDescription*) = 0;
virtual KResult add_child(InodeIdentifier child_id, const StringView& name, mode_t) = 0; virtual KResult add_child(InodeIdentifier child_id, const StringView& name, mode_t) = 0;
virtual KResult remove_child(const StringView& name) = 0; virtual KResult remove_child(const StringView& name) = 0;
virtual size_t directory_entry_count() const = 0; virtual size_t directory_entry_count() const = 0;
@ -76,7 +76,7 @@ public:
protected: protected:
Inode(FS& fs, unsigned index); Inode(FS& fs, unsigned index);
void set_metadata_dirty(bool b) { m_metadata_dirty = b; } void set_metadata_dirty(bool b) { m_metadata_dirty = b; }
void inode_contents_changed(off_t, ssize_t, const byte*); void inode_contents_changed(off_t, ssize_t, const u8*);
void inode_size_changed(size_t old_size, size_t new_size); void inode_size_changed(size_t old_size, size_t new_size);
mutable Lock m_lock { "Inode" }; mutable Lock m_lock { "Inode" };

View file

@ -13,12 +13,12 @@ InodeFile::~InodeFile()
{ {
} }
ssize_t InodeFile::read(FileDescription& description, byte* buffer, ssize_t count) ssize_t InodeFile::read(FileDescription& description, u8* buffer, ssize_t count)
{ {
return m_inode->read_bytes(description.offset(), count, buffer, &description); return m_inode->read_bytes(description.offset(), count, buffer, &description);
} }
ssize_t InodeFile::write(FileDescription& description, const byte* data, ssize_t count) ssize_t InodeFile::write(FileDescription& description, const u8* data, ssize_t count)
{ {
return m_inode->write_bytes(description.offset(), count, data, &description); return m_inode->write_bytes(description.offset(), count, data, &description);
} }

View file

@ -19,8 +19,8 @@ public:
virtual bool can_read(FileDescription&) const override { return true; } virtual bool can_read(FileDescription&) const override { return true; }
virtual bool can_write(FileDescription&) const override { return true; } virtual bool can_write(FileDescription&) const override { return true; }
virtual ssize_t read(FileDescription&, byte*, ssize_t) override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
virtual KResultOr<Region*> mmap(Process&, FileDescription&, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot) override; virtual KResultOr<Region*> mmap(Process&, FileDescription&, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot) override;
virtual String absolute_path(const FileDescription&) const override; virtual String absolute_path(const FileDescription&) const override;

View file

@ -10,7 +10,7 @@ struct InodeMetadata;
class InodeIdentifier { class InodeIdentifier {
public: public:
InodeIdentifier() {} InodeIdentifier() {}
InodeIdentifier(dword fsid, dword inode) InodeIdentifier(u32 fsid, u32 inode)
: m_fsid(fsid) : m_fsid(fsid)
, m_index(inode) , m_index(inode)
{ {
@ -18,8 +18,8 @@ public:
bool is_valid() const { return m_fsid != 0 && m_index != 0; } bool is_valid() const { return m_fsid != 0 && m_index != 0; }
dword fsid() const { return m_fsid; } u32 fsid() const { return m_fsid; }
dword index() const { return m_index; } u32 index() const { return m_index; }
FS* fs(); FS* fs();
const FS* fs() const; const FS* fs() const;
@ -39,6 +39,6 @@ public:
String to_string() const { return String::format("%u:%u", m_fsid, m_index); } String to_string() const { return String::format("%u:%u", m_fsid, m_index); }
private: private:
dword m_fsid { 0 }; u32 m_fsid { 0 };
dword m_index { 0 }; u32 m_index { 0 };
}; };

View file

@ -7,7 +7,7 @@
class Process; class Process;
inline constexpr dword encoded_device(unsigned major, unsigned minor) inline constexpr u32 encoded_device(unsigned major, unsigned minor)
{ {
return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12); return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
} }

View file

@ -125,7 +125,7 @@ static inline InodeIdentifier to_parent_id(const InodeIdentifier& identifier)
} }
#if 0 #if 0
static inline byte to_unused_metadata(const InodeIdentifier& identifier) static inline u8 to_unused_metadata(const InodeIdentifier& identifier)
{ {
return (identifier.index() >> 8) & 0xf; return (identifier.index() >> 8) & 0xf;
} }
@ -254,7 +254,7 @@ ByteBuffer procfs$pci(InodeIdentifier)
ByteBuffer procfs$uptime(InodeIdentifier) ByteBuffer procfs$uptime(InodeIdentifier)
{ {
StringBuilder builder; StringBuilder builder;
builder.appendf("%u\n", (dword)(g_uptime / 1000)); builder.appendf("%u\n", (u32)(g_uptime / 1000));
return builder.to_byte_buffer(); return builder.to_byte_buffer();
} }
@ -317,7 +317,7 @@ ByteBuffer procfs$pid_stack(InodeIdentifier identifier)
auto& process = handle->process(); auto& process = handle->process();
ProcessPagingScope paging_scope(process); ProcessPagingScope paging_scope(process);
struct RecognizedSymbol { struct RecognizedSymbol {
dword address; u32 address;
const KSym* ksym; const KSym* ksym;
}; };
StringBuilder builder; StringBuilder builder;
@ -325,8 +325,8 @@ ByteBuffer procfs$pid_stack(InodeIdentifier identifier)
builder.appendf("Thread %d:\n", thread.tid()); builder.appendf("Thread %d:\n", thread.tid());
Vector<RecognizedSymbol, 64> recognized_symbols; Vector<RecognizedSymbol, 64> recognized_symbols;
recognized_symbols.append({ thread.tss().eip, ksymbolicate(thread.tss().eip) }); recognized_symbols.append({ thread.tss().eip, ksymbolicate(thread.tss().eip) });
for (dword* stack_ptr = (dword*)thread.frame_ptr(); process.validate_read_from_kernel(VirtualAddress((dword)stack_ptr)); stack_ptr = (dword*)*stack_ptr) { for (u32* stack_ptr = (u32*)thread.frame_ptr(); process.validate_read_from_kernel(VirtualAddress((u32)stack_ptr)); stack_ptr = (u32*)*stack_ptr) {
dword retaddr = stack_ptr[1]; u32 retaddr = stack_ptr[1];
recognized_symbols.append({ retaddr, ksymbolicate(retaddr) }); recognized_symbols.append({ retaddr, ksymbolicate(retaddr) });
} }
@ -397,7 +397,7 @@ ByteBuffer procfs$self(InodeIdentifier)
{ {
char buffer[16]; char buffer[16];
ksprintf(buffer, "%u", current->pid()); ksprintf(buffer, "%u", current->pid());
return ByteBuffer::copy((const byte*)buffer, strlen(buffer)); return ByteBuffer::copy((const u8*)buffer, strlen(buffer));
} }
ByteBuffer procfs$mm(InodeIdentifier) ByteBuffer procfs$mm(InodeIdentifier)
@ -471,28 +471,28 @@ ByteBuffer procfs$cpuinfo(InodeIdentifier)
{ {
CPUID cpuid(0); CPUID cpuid(0);
builder.appendf("cpuid: "); builder.appendf("cpuid: ");
auto emit_dword = [&](dword value) { auto emit_u32 = [&](u32 value) {
builder.appendf("%c%c%c%c", builder.appendf("%c%c%c%c",
value & 0xff, value & 0xff,
(value >> 8) & 0xff, (value >> 8) & 0xff,
(value >> 16) & 0xff, (value >> 16) & 0xff,
(value >> 24) & 0xff); (value >> 24) & 0xff);
}; };
emit_dword(cpuid.ebx()); emit_u32(cpuid.ebx());
emit_dword(cpuid.edx()); emit_u32(cpuid.edx());
emit_dword(cpuid.ecx()); emit_u32(cpuid.ecx());
builder.appendf("\n"); builder.appendf("\n");
} }
{ {
CPUID cpuid(1); CPUID cpuid(1);
dword stepping = cpuid.eax() & 0xf; u32 stepping = cpuid.eax() & 0xf;
dword model = (cpuid.eax() >> 4) & 0xf; u32 model = (cpuid.eax() >> 4) & 0xf;
dword family = (cpuid.eax() >> 8) & 0xf; u32 family = (cpuid.eax() >> 8) & 0xf;
dword type = (cpuid.eax() >> 12) & 0x3; u32 type = (cpuid.eax() >> 12) & 0x3;
dword extended_model = (cpuid.eax() >> 16) & 0xf; u32 extended_model = (cpuid.eax() >> 16) & 0xf;
dword extended_family = (cpuid.eax() >> 20) & 0xff; u32 extended_family = (cpuid.eax() >> 20) & 0xff;
dword display_model; u32 display_model;
dword display_family; u32 display_family;
if (family == 15) { if (family == 15) {
display_family = family + extended_family; display_family = family + extended_family;
display_model = model + (extended_model << 4); display_model = model + (extended_model << 4);
@ -512,8 +512,8 @@ ByteBuffer procfs$cpuinfo(InodeIdentifier)
// FIXME: Check first that this is supported by calling CPUID with eax=0x80000000 // FIXME: Check first that this is supported by calling CPUID with eax=0x80000000
// and verifying that the returned eax>=0x80000004. // and verifying that the returned eax>=0x80000004.
char buffer[48]; char buffer[48];
dword* bufptr = reinterpret_cast<dword*>(buffer); u32* bufptr = reinterpret_cast<u32*>(buffer);
auto copy_brand_string_part_to_buffer = [&](dword i) { auto copy_brand_string_part_to_buffer = [&](u32 i) {
CPUID cpuid(0x80000002 + i); CPUID cpuid(0x80000002 + i);
*bufptr++ = cpuid.eax(); *bufptr++ = cpuid.eax();
*bufptr++ = cpuid.ebx(); *bufptr++ = cpuid.ebx();
@ -858,7 +858,7 @@ InodeMetadata ProcFSInode::metadata() const
return metadata; return metadata;
} }
ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription* description) const ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDescription* description) const
{ {
#ifdef PROCFS_DEBUG #ifdef PROCFS_DEBUG
dbgprintf("ProcFS: read_bytes %u\n", index()); dbgprintf("ProcFS: read_bytes %u\n", index());
@ -1061,7 +1061,7 @@ void ProcFSInode::flush_metadata()
{ {
} }
ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescription*) ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const u8* buffer, FileDescription*)
{ {
auto* directory_entry = fs().get_directory_entry(identifier()); auto* directory_entry = fs().get_directory_entry(identifier());
if (!directory_entry || !directory_entry->write_callback) if (!directory_entry || !directory_entry->write_callback)

View file

@ -80,12 +80,12 @@ public:
private: private:
// ^Inode // ^Inode
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescription*) const override; virtual ssize_t read_bytes(off_t, ssize_t, u8* buffer, FileDescription*) const override;
virtual InodeMetadata metadata() const override; virtual InodeMetadata metadata() const override;
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override; virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override;
virtual InodeIdentifier lookup(StringView name) override; virtual InodeIdentifier lookup(StringView name) override;
virtual void flush_metadata() override; virtual void flush_metadata() override;
virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescription*) override; virtual ssize_t write_bytes(off_t, ssize_t, const u8* buffer, FileDescription*) override;
virtual KResult add_child(InodeIdentifier child_id, const StringView& name, mode_t) override; virtual KResult add_child(InodeIdentifier child_id, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override; virtual KResult remove_child(const StringView& name) override;
virtual size_t directory_entry_count() const override; virtual size_t directory_entry_count() const override;

View file

@ -185,7 +185,7 @@ InodeMetadata SynthFSInode::metadata() const
return m_metadata; return m_metadata;
} }
ssize_t SynthFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription* description) const ssize_t SynthFSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDescription* description) const
{ {
LOCKER(m_lock); LOCKER(m_lock);
#ifdef SYNTHFS_DEBUG #ifdef SYNTHFS_DEBUG
@ -227,7 +227,7 @@ bool SynthFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&
callback({ "..", 2, m_parent, 2 }); callback({ "..", 2, m_parent, 2 });
for (auto& child : m_children) for (auto& child : m_children)
callback({ child->m_name.characters(), child->m_name.length(), child->m_metadata.inode, child->m_metadata.is_directory() ? (byte)2 : (byte)1 }); callback({ child->m_name.characters(), child->m_name.length(), child->m_metadata.inode, child->m_metadata.is_directory() ? (u8)2 : (u8)1 });
return true; return true;
} }
@ -250,7 +250,7 @@ void SynthFSInode::flush_metadata()
{ {
} }
ssize_t SynthFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescription*) ssize_t SynthFSInode::write_bytes(off_t offset, ssize_t size, const u8* buffer, FileDescription*)
{ {
LOCKER(m_lock); LOCKER(m_lock);
if (!m_write_callback) if (!m_write_callback)

View file

@ -57,12 +57,12 @@ public:
private: private:
// ^Inode // ^Inode
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescription*) const override; virtual ssize_t read_bytes(off_t, ssize_t, u8* buffer, FileDescription*) const override;
virtual InodeMetadata metadata() const override; virtual InodeMetadata metadata() const override;
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override; virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override;
virtual InodeIdentifier lookup(StringView name) override; virtual InodeIdentifier lookup(StringView name) override;
virtual void flush_metadata() override; virtual void flush_metadata() override;
virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescription*) override; virtual ssize_t write_bytes(off_t, ssize_t, const u8* buffer, FileDescription*) override;
virtual KResult add_child(InodeIdentifier child_id, const StringView& name, mode_t) override; virtual KResult add_child(InodeIdentifier child_id, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override; virtual KResult remove_child(const StringView& name) override;
virtual size_t directory_entry_count() const override; virtual size_t directory_entry_count() const override;

View file

@ -516,7 +516,7 @@ KResult VFS::symlink(StringView target, StringView linkpath, Custody& base)
auto new_file = parent_inode.fs().create_inode(parent_inode.identifier(), p.basename(), 0120644, 0, 0, error); auto new_file = parent_inode.fs().create_inode(parent_inode.identifier(), p.basename(), 0120644, 0, 0, error);
if (!new_file) if (!new_file)
return KResult(error); return KResult(error);
ssize_t nwritten = new_file->write_bytes(0, target.length(), (const byte*)target.characters(), nullptr); ssize_t nwritten = new_file->write_bytes(0, target.length(), (const u8*)target.characters(), nullptr);
if (nwritten < 0) if (nwritten < 0)
return KResult(nwritten); return KResult(nwritten);
return KSuccess; return KSuccess;

View file

@ -107,7 +107,7 @@ private:
RefPtr<Inode> m_root_inode; RefPtr<Inode> m_root_inode;
Vector<OwnPtr<Mount>> m_mounts; Vector<OwnPtr<Mount>> m_mounts;
HashMap<dword, Device*> m_devices; HashMap<u32, Device*> m_devices;
RefPtr<Custody> m_root_custody; RefPtr<Custody> m_root_custody;
}; };

View file

@ -4,34 +4,34 @@
namespace IO { namespace IO {
inline byte in8(word port) inline u8 in8(u16 port)
{ {
byte value; u8 value;
asm volatile("inb %1, %0" asm volatile("inb %1, %0"
: "=a"(value) : "=a"(value)
: "Nd"(port)); : "Nd"(port));
return value; return value;
} }
inline word in16(word port) inline u16 in16(u16 port)
{ {
word value; u16 value;
asm volatile("inw %1, %0" asm volatile("inw %1, %0"
: "=a"(value) : "=a"(value)
: "Nd"(port)); : "Nd"(port));
return value; return value;
} }
inline dword in32(word port) inline u32 in32(u16 port)
{ {
dword value; u32 value;
asm volatile("inl %1, %0" asm volatile("inl %1, %0"
: "=a"(value) : "=a"(value)
: "Nd"(port)); : "Nd"(port));
return value; return value;
} }
inline void repeated_in16(word port, byte* buffer, int buffer_size) inline void repeated_in16(u16 port, u8* buffer, int buffer_size)
{ {
asm volatile("rep insw" asm volatile("rep insw"
: "+D"(buffer), "+c"(buffer_size) : "+D"(buffer), "+c"(buffer_size)
@ -39,22 +39,22 @@ inline void repeated_in16(word port, byte* buffer, int buffer_size)
: "memory"); : "memory");
} }
inline void out8(word port, byte value) inline void out8(u16 port, u8 value)
{ {
asm volatile("outb %0, %1" ::"a"(value), "Nd"(port)); asm volatile("outb %0, %1" ::"a"(value), "Nd"(port));
} }
inline void out16(word port, word value) inline void out16(u16 port, u16 value)
{ {
asm volatile("outw %0, %1" ::"a"(value), "Nd"(port)); asm volatile("outw %0, %1" ::"a"(value), "Nd"(port));
} }
inline void out32(word port, dword value) inline void out32(u16 port, u32 value)
{ {
asm volatile("outl %0, %1" ::"a"(value), "Nd"(port)); asm volatile("outl %0, %1" ::"a"(value), "Nd"(port));
} }
inline void repeated_out16(word port, const byte* data, int data_size) inline void repeated_out16(u16 port, const u8* data, int data_size)
{ {
asm volatile("rep outsw" asm volatile("rep outsw"
: "+S"(data), "+c"(data_size) : "+S"(data), "+c"(data_size)

View file

@ -2,7 +2,7 @@
#include "PIC.h" #include "PIC.h"
#include <Kernel/Arch/i386/CPU.h> #include <Kernel/Arch/i386/CPU.h>
IRQHandler::IRQHandler(byte irq) IRQHandler::IRQHandler(u8 irq)
: m_irq_number(irq) : m_irq_number(irq)
{ {
register_irq_handler(m_irq_number, *this); register_irq_handler(m_irq_number, *this);

View file

@ -7,14 +7,14 @@ public:
virtual ~IRQHandler(); virtual ~IRQHandler();
virtual void handle_irq() = 0; virtual void handle_irq() = 0;
byte irq_number() const { return m_irq_number; } u8 irq_number() const { return m_irq_number; }
void enable_irq(); void enable_irq();
void disable_irq(); void disable_irq();
protected: protected:
explicit IRQHandler(byte irq); explicit IRQHandler(u8 irq);
private: private:
byte m_irq_number { 0 }; u8 m_irq_number { 0 };
}; };

View file

@ -6,12 +6,12 @@
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
static KSym* s_ksyms; static KSym* s_ksyms;
dword ksym_lowest_address; u32 ksym_lowest_address;
dword ksym_highest_address; u32 ksym_highest_address;
dword ksym_count; u32 ksym_count;
bool ksyms_ready; bool ksyms_ready;
static byte parse_hex_digit(char nibble) static u8 parse_hex_digit(char nibble)
{ {
if (nibble >= '0' && nibble <= '9') if (nibble >= '0' && nibble <= '9')
return nibble - '0'; return nibble - '0';
@ -19,7 +19,7 @@ static byte parse_hex_digit(char nibble)
return 10 + (nibble - 'a'); return 10 + (nibble - 'a');
} }
const KSym* ksymbolicate(dword address) const KSym* ksymbolicate(u32 address)
{ {
if (address < ksym_lowest_address || address > ksym_highest_address) if (address < ksym_lowest_address || address > ksym_highest_address)
return nullptr; return nullptr;
@ -36,7 +36,7 @@ static void load_ksyms_from_data(const ByteBuffer& buffer)
ksym_highest_address = 0; ksym_highest_address = 0;
auto* bufptr = (const char*)buffer.pointer(); auto* bufptr = (const char*)buffer.pointer();
auto* start_of_name = bufptr; auto* start_of_name = bufptr;
dword address = 0; u32 address = 0;
for (unsigned i = 0; i < 8; ++i) for (unsigned i = 0; i < 8; ++i)
ksym_count = (ksym_count << 4) | parse_hex_digit(*(bufptr++)); ksym_count = (ksym_count << 4) | parse_hex_digit(*(bufptr++));
@ -76,7 +76,7 @@ static void load_ksyms_from_data(const ByteBuffer& buffer)
ksyms_ready = true; ksyms_ready = true;
} }
[[gnu::noinline]] void dump_backtrace_impl(dword ebp, bool use_ksyms) [[gnu::noinline]] void dump_backtrace_impl(u32 ebp, bool use_ksyms)
{ {
if (!current) { if (!current) {
//hang(); //hang();
@ -87,21 +87,21 @@ static void load_ksyms_from_data(const ByteBuffer& buffer)
return; return;
} }
struct RecognizedSymbol { struct RecognizedSymbol {
dword address; u32 address;
const KSym* ksym; const KSym* ksym;
}; };
int max_recognized_symbol_count = 256; int max_recognized_symbol_count = 256;
RecognizedSymbol recognized_symbols[max_recognized_symbol_count]; RecognizedSymbol recognized_symbols[max_recognized_symbol_count];
int recognized_symbol_count = 0; int recognized_symbol_count = 0;
if (use_ksyms) { if (use_ksyms) {
for (dword* stack_ptr = (dword*)ebp; current->process().validate_read_from_kernel(VirtualAddress((dword)stack_ptr)); stack_ptr = (dword*)*stack_ptr) { for (u32* stack_ptr = (u32*)ebp; current->process().validate_read_from_kernel(VirtualAddress((u32)stack_ptr)); stack_ptr = (u32*)*stack_ptr) {
dword retaddr = stack_ptr[1]; u32 retaddr = stack_ptr[1];
recognized_symbols[recognized_symbol_count++] = { retaddr, ksymbolicate(retaddr) }; recognized_symbols[recognized_symbol_count++] = { retaddr, ksymbolicate(retaddr) };
} }
} else { } else {
for (dword* stack_ptr = (dword*)ebp; current->process().validate_read_from_kernel(VirtualAddress((dword)stack_ptr)); stack_ptr = (dword*)*stack_ptr) { for (u32* stack_ptr = (u32*)ebp; current->process().validate_read_from_kernel(VirtualAddress((u32)stack_ptr)); stack_ptr = (u32*)*stack_ptr) {
dword retaddr = stack_ptr[1]; u32 retaddr = stack_ptr[1];
dbgprintf("%x (next: %x)\n", retaddr, stack_ptr ? (dword*)*stack_ptr : 0); dbgprintf("%x (next: %x)\n", retaddr, stack_ptr ? (u32*)*stack_ptr : 0);
} }
return; return;
} }
@ -139,7 +139,7 @@ void dump_backtrace()
return; return;
} }
TemporaryChange change(in_dump_backtrace, true); TemporaryChange change(in_dump_backtrace, true);
dword ebp; u32 ebp;
asm volatile("movl %%ebp, %%eax" asm volatile("movl %%ebp, %%eax"
: "=a"(ebp)); : "=a"(ebp));
dump_backtrace_impl(ebp, ksyms_ready); dump_backtrace_impl(ebp, ksyms_ready);

View file

@ -4,16 +4,16 @@
#include <AK/Vector.h> #include <AK/Vector.h>
struct KSym { struct KSym {
dword address; u32 address;
const char* name; const char* name;
}; };
const KSym* ksymbolicate(dword address); const KSym* ksymbolicate(u32 address);
void load_ksyms(); void load_ksyms();
void init_ksyms(); void init_ksyms();
extern bool ksyms_ready; extern bool ksyms_ready;
extern dword ksym_lowest_address; extern u32 ksym_lowest_address;
extern dword ksym_highest_address; extern u32 ksym_highest_address;
void dump_backtrace(); void dump_backtrace();

View file

@ -2,7 +2,7 @@
#include <AK/Types.h> #include <AK/Types.h>
enum KeyCode : byte { enum KeyCode : u8 {
Key_Invalid = 0, Key_Invalid = 0,
Key_Escape, Key_Escape,
Key_Tab, Key_Tab,
@ -126,8 +126,8 @@ enum KeyModifier {
struct KeyEvent { struct KeyEvent {
KeyCode key { Key_Invalid }; KeyCode key { Key_Invalid };
byte character { 0 }; u8 character { 0 };
byte flags { 0 }; u8 flags { 0 };
bool alt() const { return flags & Mod_Alt; } bool alt() const { return flags & Mod_Alt; }
bool ctrl() const { return flags & Mod_Ctrl; } bool ctrl() const { return flags & Mod_Ctrl; }
bool shift() const { return flags & Mod_Shift; } bool shift() const { return flags & Mod_Shift; }

View file

@ -9,9 +9,9 @@
class Thread; class Thread;
extern Thread* current; extern Thread* current;
static inline dword CAS(volatile dword* mem, dword newval, dword oldval) static inline u32 CAS(volatile u32* mem, u32 newval, u32 oldval)
{ {
dword ret; u32 ret;
asm volatile( asm volatile(
"cmpxchgl %2, %1" "cmpxchgl %2, %1"
: "=a"(ret), "+m"(*mem) : "=a"(ret), "+m"(*mem)
@ -35,8 +35,8 @@ public:
const char* name() const { return m_name; } const char* name() const { return m_name; }
private: private:
volatile dword m_lock { 0 }; volatile u32 m_lock { 0 };
dword m_level { 0 }; u32 m_level { 0 };
Thread* m_holder { nullptr }; Thread* m_holder { nullptr };
const char* m_name { nullptr }; const char* m_name { nullptr };
}; };

View file

@ -4,5 +4,5 @@ struct MousePacket {
int dx { 0 }; int dx { 0 };
int dy { 0 }; int dy { 0 };
int dz { 0 }; int dz { 0 };
byte buttons { 0 }; unsigned char buttons { 0 };
}; };

View file

@ -3,18 +3,18 @@
#include <AK/Types.h> #include <AK/Types.h>
struct multiboot_aout_symbol_table { struct multiboot_aout_symbol_table {
dword tabsize; u32 tabsize;
dword strsize; u32 strsize;
dword addr; u32 addr;
dword reserved; u32 reserved;
}; };
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t; typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
struct multiboot_elf_section_header_table { struct multiboot_elf_section_header_table {
dword num; u32 num;
dword size; u32 size;
dword addr; u32 addr;
dword shndx; u32 shndx;
}; };
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t; typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
@ -25,30 +25,30 @@ typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_t
#define MULTIBOOT_MEMORY_BADRAM 5 #define MULTIBOOT_MEMORY_BADRAM 5
struct multiboot_mmap_entry { struct multiboot_mmap_entry {
dword size; u32 size;
qword addr; u64 addr;
qword len; u64 len;
dword type; u32 type;
} __attribute__((packed)); } __attribute__((packed));
typedef struct multiboot_mmap_entry multiboot_memory_map_t; typedef struct multiboot_mmap_entry multiboot_memory_map_t;
struct multiboot_info { struct multiboot_info {
// Multiboot info version number. // Multiboot info version number.
dword flags; u32 flags;
// Available memory from BIOS. // Available memory from BIOS.
dword mem_lower; u32 mem_lower;
dword mem_upper; u32 mem_upper;
// "root" partition. // "root" partition.
dword boot_device; u32 boot_device;
// Kernel command line. // Kernel command line.
dword cmdline; u32 cmdline;
// Boot-Module list. // Boot-Module list.
dword mods_count; u32 mods_count;
dword mods_addr; u32 mods_addr;
union { union {
multiboot_aout_symbol_table_t aout_sym; multiboot_aout_symbol_table_t aout_sym;
@ -56,53 +56,53 @@ struct multiboot_info {
} u; } u;
// Memory Mapping buffer. // Memory Mapping buffer.
dword mmap_length; u32 mmap_length;
dword mmap_addr; u32 mmap_addr;
// Drive Info buffer. // Drive Info buffer.
dword drives_length; u32 drives_length;
dword drives_addr; u32 drives_addr;
// ROM configuration table. // ROM configuration table.
dword config_table; u32 config_table;
// Boot Loader Name. // Boot Loader Name.
dword boot_loader_name; u32 boot_loader_name;
// APM table. // APM table.
dword apm_table; u32 apm_table;
// Video. // Video.
dword vbe_control_info; u32 vbe_control_info;
dword vbe_mode_info; u32 vbe_mode_info;
word vbe_mode; u16 vbe_mode;
word vbe_interface_seg; u16 vbe_interface_seg;
word vbe_interface_off; u16 vbe_interface_off;
word vbe_interface_len; u16 vbe_interface_len;
qword framebuffer_addr; u64 framebuffer_addr;
dword framebuffer_pitch; u32 framebuffer_pitch;
dword framebuffer_width; u32 framebuffer_width;
dword framebuffer_height; u32 framebuffer_height;
byte framebuffer_bpp; u8 framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 #define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 #define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 #define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
byte framebuffer_type; u8 framebuffer_type;
union { union {
struct struct
{ {
dword framebuffer_palette_addr; u32 framebuffer_palette_addr;
word framebuffer_palette_num_colors; u16 framebuffer_palette_num_colors;
}; };
struct struct
{ {
byte framebuffer_red_field_position; u8 framebuffer_red_field_position;
byte framebuffer_red_mask_size; u8 framebuffer_red_mask_size;
byte framebuffer_green_field_position; u8 framebuffer_green_field_position;
byte framebuffer_green_mask_size; u8 framebuffer_green_mask_size;
byte framebuffer_blue_field_position; u8 framebuffer_blue_field_position;
byte framebuffer_blue_mask_size; u8 framebuffer_blue_mask_size;
}; };
}; };
}; };

View file

@ -6,14 +6,14 @@
#include <Kernel/Net/MACAddress.h> #include <Kernel/Net/MACAddress.h>
struct ARPOperation { struct ARPOperation {
enum : word { enum : u16 {
Request = 1, Request = 1,
Response = 2, Response = 2,
}; };
}; };
struct ARPHardwareType { struct ARPHardwareType {
enum : word { enum : u16 {
Ethernet = 1, Ethernet = 1,
}; };
}; };
@ -21,20 +21,20 @@ struct ARPHardwareType {
class [[gnu::packed]] ARPPacket class [[gnu::packed]] ARPPacket
{ {
public: public:
word hardware_type() const { return m_hardware_type; } u16 hardware_type() const { return m_hardware_type; }
void set_hardware_type(word w) { m_hardware_type = w; } void set_hardware_type(u16 w) { m_hardware_type = w; }
word protocol_type() const { return m_protocol_type; } u16 protocol_type() const { return m_protocol_type; }
void set_protocol_type(word w) { m_protocol_type = w; } void set_protocol_type(u16 w) { m_protocol_type = w; }
byte hardware_address_length() const { return m_hardware_address_length; } u8 hardware_address_length() const { return m_hardware_address_length; }
void set_hardware_address_length(byte b) { m_hardware_address_length = b; } void set_hardware_address_length(u8 b) { m_hardware_address_length = b; }
byte protocol_address_length() const { return m_protocol_address_length; } u8 protocol_address_length() const { return m_protocol_address_length; }
void set_protocol_address_length(byte b) { m_protocol_address_length = b; } void set_protocol_address_length(u8 b) { m_protocol_address_length = b; }
word operation() const { return m_operation; } u16 operation() const { return m_operation; }
void set_operation(word w) { m_operation = w; } void set_operation(u16 w) { m_operation = w; }
const MACAddress& sender_hardware_address() const { return m_sender_hardware_address; } const MACAddress& sender_hardware_address() const { return m_sender_hardware_address; }
void set_sender_hardware_address(const MACAddress& address) { m_sender_hardware_address = address; } void set_sender_hardware_address(const MACAddress& address) { m_sender_hardware_address = address; }
@ -49,11 +49,11 @@ public:
void set_target_protocol_address(const IPv4Address& address) { m_target_protocol_address = address; } void set_target_protocol_address(const IPv4Address& address) { m_target_protocol_address = address; }
private: private:
NetworkOrdered<word> m_hardware_type { ARPHardwareType::Ethernet }; NetworkOrdered<u16> m_hardware_type { ARPHardwareType::Ethernet };
NetworkOrdered<word> m_protocol_type { EtherType::IPv4 }; NetworkOrdered<u16> m_protocol_type { EtherType::IPv4 };
byte m_hardware_address_length { sizeof(MACAddress) }; u8 m_hardware_address_length { sizeof(MACAddress) };
byte m_protocol_address_length { sizeof(IPv4Address) }; u8 m_protocol_address_length { sizeof(IPv4Address) };
NetworkOrdered<word> m_operation; NetworkOrdered<u16> m_operation;
MACAddress m_sender_hardware_address; MACAddress m_sender_hardware_address;
IPv4Address m_sender_protocol_address; IPv4Address m_sender_protocol_address;
MACAddress m_target_hardware_address; MACAddress m_target_hardware_address;

View file

@ -92,7 +92,7 @@ OwnPtr<E1000NetworkAdapter> E1000NetworkAdapter::autodetect()
}); });
if (found_address.is_null()) if (found_address.is_null())
return nullptr; return nullptr;
byte irq = PCI::get_interrupt_line(found_address); u8 irq = PCI::get_interrupt_line(found_address);
return make<E1000NetworkAdapter>(found_address, irq); return make<E1000NetworkAdapter>(found_address, irq);
} }
@ -102,7 +102,7 @@ E1000NetworkAdapter* E1000NetworkAdapter::the()
return s_the; return s_the;
} }
E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address pci_address, byte irq) E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address pci_address, u8 irq)
: IRQHandler(irq) : IRQHandler(irq)
, m_pci_address(pci_address) , m_pci_address(pci_address)
{ {
@ -132,7 +132,7 @@ E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address pci_address, byte irq)
const auto& mac = mac_address(); const auto& mac = mac_address();
kprintf("E1000: MAC address: %b:%b:%b:%b:%b:%b\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); kprintf("E1000: MAC address: %b:%b:%b:%b:%b:%b\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
dword flags = in32(REG_CTRL); u32 flags = in32(REG_CTRL);
out32(REG_CTRL, flags | ECTRL_SLU); out32(REG_CTRL, flags | ECTRL_SLU);
initialize_rx_descriptors(); initialize_rx_descriptors();
@ -153,9 +153,9 @@ void E1000NetworkAdapter::handle_irq()
{ {
out32(REG_IMASK, 0x1); out32(REG_IMASK, 0x1);
dword status = in32(0xc0); u32 status = in32(0xc0);
if (status & 4) { if (status & 4) {
dword flags = in32(REG_CTRL); u32 flags = in32(REG_CTRL);
out32(REG_CTRL, flags | ECTRL_SLU); out32(REG_CTRL, flags | ECTRL_SLU);
} }
if (status & 0x10) { if (status & 0x10) {
@ -170,7 +170,7 @@ void E1000NetworkAdapter::detect_eeprom()
{ {
out32(REG_EEPROM, 0x1); out32(REG_EEPROM, 0x1);
for (volatile int i = 0; i < 999; ++i) { for (volatile int i = 0; i < 999; ++i) {
dword data = in32(REG_EEPROM); u32 data = in32(REG_EEPROM);
if (data & 0x10) { if (data & 0x10) {
m_has_eeprom = true; m_has_eeprom = true;
return; return;
@ -179,16 +179,16 @@ void E1000NetworkAdapter::detect_eeprom()
m_has_eeprom = false; m_has_eeprom = false;
} }
dword E1000NetworkAdapter::read_eeprom(byte address) u32 E1000NetworkAdapter::read_eeprom(u8 address)
{ {
word data = 0; u16 data = 0;
dword tmp = 0; u32 tmp = 0;
if (m_has_eeprom) { if (m_has_eeprom) {
out32(REG_EEPROM, ((dword)address << 8) | 1); out32(REG_EEPROM, ((u32)address << 8) | 1);
while (!((tmp = in32(REG_EEPROM)) & (1 << 4))) while (!((tmp = in32(REG_EEPROM)) & (1 << 4)))
; ;
} else { } else {
out32(REG_EEPROM, ((dword)address << 2) | 1); out32(REG_EEPROM, ((u32)address << 2) | 1);
while (!((tmp = in32(REG_EEPROM)) & (1 << 1))) while (!((tmp = in32(REG_EEPROM)) & (1 << 1)))
; ;
} }
@ -199,8 +199,8 @@ dword E1000NetworkAdapter::read_eeprom(byte address)
void E1000NetworkAdapter::read_mac_address() void E1000NetworkAdapter::read_mac_address()
{ {
if (m_has_eeprom) { if (m_has_eeprom) {
byte mac[6]; u8 mac[6];
dword tmp = read_eeprom(0); u32 tmp = read_eeprom(0);
mac[0] = tmp & 0xff; mac[0] = tmp & 0xff;
mac[1] = tmp >> 8; mac[1] = tmp >> 8;
tmp = read_eeprom(1); tmp = read_eeprom(1);
@ -217,14 +217,14 @@ void E1000NetworkAdapter::read_mac_address()
void E1000NetworkAdapter::initialize_rx_descriptors() void E1000NetworkAdapter::initialize_rx_descriptors()
{ {
auto ptr = (dword)kmalloc_eternal(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16); auto ptr = (u32)kmalloc_eternal(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16);
// Make sure it's 16-byte aligned. // Make sure it's 16-byte aligned.
if (ptr % 16) if (ptr % 16)
ptr = (ptr + 16) - (ptr % 16); ptr = (ptr + 16) - (ptr % 16);
m_rx_descriptors = (e1000_rx_desc*)ptr; m_rx_descriptors = (e1000_rx_desc*)ptr;
for (int i = 0; i < number_of_rx_descriptors; ++i) { for (int i = 0; i < number_of_rx_descriptors; ++i) {
auto& descriptor = m_rx_descriptors[i]; auto& descriptor = m_rx_descriptors[i];
descriptor.addr = (qword)kmalloc_eternal(8192 + 16); descriptor.addr = (u64)kmalloc_eternal(8192 + 16);
descriptor.status = 0; descriptor.status = 0;
} }
@ -239,14 +239,14 @@ void E1000NetworkAdapter::initialize_rx_descriptors()
void E1000NetworkAdapter::initialize_tx_descriptors() void E1000NetworkAdapter::initialize_tx_descriptors()
{ {
auto ptr = (dword)kmalloc_eternal(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16); auto ptr = (u32)kmalloc_eternal(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16);
// Make sure it's 16-byte aligned. // Make sure it's 16-byte aligned.
if (ptr % 16) if (ptr % 16)
ptr = (ptr + 16) - (ptr % 16); ptr = (ptr + 16) - (ptr % 16);
m_tx_descriptors = (e1000_tx_desc*)ptr; m_tx_descriptors = (e1000_tx_desc*)ptr;
for (int i = 0; i < number_of_tx_descriptors; ++i) { for (int i = 0; i < number_of_tx_descriptors; ++i) {
auto& descriptor = m_tx_descriptors[i]; auto& descriptor = m_tx_descriptors[i];
descriptor.addr = (qword)kmalloc_eternal(8192 + 16); descriptor.addr = (u64)kmalloc_eternal(8192 + 16);
descriptor.cmd = 0; descriptor.cmd = 0;
} }
@ -260,60 +260,60 @@ void E1000NetworkAdapter::initialize_tx_descriptors()
out32(REG_TIPG, 0x0060200A); out32(REG_TIPG, 0x0060200A);
} }
void E1000NetworkAdapter::out8(word address, byte data) void E1000NetworkAdapter::out8(u16 address, u8 data)
{ {
if (m_use_mmio) { if (m_use_mmio) {
auto* ptr = (volatile byte*)(m_mmio_base.get() + address); auto* ptr = (volatile u8*)(m_mmio_base.get() + address);
*ptr = data; *ptr = data;
return; return;
} }
IO::out8(m_io_base + address, data); IO::out8(m_io_base + address, data);
} }
void E1000NetworkAdapter::out16(word address, word data) void E1000NetworkAdapter::out16(u16 address, u16 data)
{ {
if (m_use_mmio) { if (m_use_mmio) {
auto* ptr = (volatile word*)(m_mmio_base.get() + address); auto* ptr = (volatile u16*)(m_mmio_base.get() + address);
*ptr = data; *ptr = data;
return; return;
} }
IO::out16(m_io_base + address, data); IO::out16(m_io_base + address, data);
} }
void E1000NetworkAdapter::out32(word address, dword data) void E1000NetworkAdapter::out32(u16 address, u32 data)
{ {
if (m_use_mmio) { if (m_use_mmio) {
auto* ptr = (volatile dword*)(m_mmio_base.get() + address); auto* ptr = (volatile u32*)(m_mmio_base.get() + address);
*ptr = data; *ptr = data;
return; return;
} }
IO::out32(m_io_base + address, data); IO::out32(m_io_base + address, data);
} }
byte E1000NetworkAdapter::in8(word address) u8 E1000NetworkAdapter::in8(u16 address)
{ {
if (m_use_mmio) if (m_use_mmio)
return *(volatile byte*)(m_mmio_base.get() + address); return *(volatile u8*)(m_mmio_base.get() + address);
return IO::in8(m_io_base + address); return IO::in8(m_io_base + address);
} }
word E1000NetworkAdapter::in16(word address) u16 E1000NetworkAdapter::in16(u16 address)
{ {
if (m_use_mmio) if (m_use_mmio)
return *(volatile word*)(m_mmio_base.get() + address); return *(volatile u16*)(m_mmio_base.get() + address);
return IO::in16(m_io_base + address); return IO::in16(m_io_base + address);
} }
dword E1000NetworkAdapter::in32(word address) u32 E1000NetworkAdapter::in32(u16 address)
{ {
if (m_use_mmio) if (m_use_mmio)
return *(volatile dword*)(m_mmio_base.get() + address); return *(volatile u32*)(m_mmio_base.get() + address);
return IO::in32(m_io_base + address); return IO::in32(m_io_base + address);
} }
void E1000NetworkAdapter::send_raw(const byte* data, int length) void E1000NetworkAdapter::send_raw(const u8* data, int length)
{ {
dword tx_current = in32(REG_TXDESCTAIL); u32 tx_current = in32(REG_TXDESCTAIL);
#ifdef E1000_DEBUG #ifdef E1000_DEBUG
kprintf("E1000: Sending packet (%d bytes)\n", length); kprintf("E1000: Sending packet (%d bytes)\n", length);
#endif #endif
@ -337,7 +337,7 @@ void E1000NetworkAdapter::send_raw(const byte* data, int length)
void E1000NetworkAdapter::receive() void E1000NetworkAdapter::receive()
{ {
dword rx_current; u32 rx_current;
for (;;) { for (;;) {
rx_current = in32(REG_RXDESCTAIL); rx_current = in32(REG_RXDESCTAIL);
if (rx_current == in32(REG_RXDESCHEAD)) if (rx_current == in32(REG_RXDESCHEAD))
@ -345,8 +345,8 @@ void E1000NetworkAdapter::receive()
rx_current = (rx_current + 1) % number_of_rx_descriptors; rx_current = (rx_current + 1) % number_of_rx_descriptors;
if (!(m_rx_descriptors[rx_current].status & 1)) if (!(m_rx_descriptors[rx_current].status & 1))
break; break;
auto* buffer = (byte*)m_rx_descriptors[rx_current].addr; auto* buffer = (u8*)m_rx_descriptors[rx_current].addr;
word length = m_rx_descriptors[rx_current].length; u16 length = m_rx_descriptors[rx_current].length;
#ifdef E1000_DEBUG #ifdef E1000_DEBUG
kprintf("E1000: Received 1 packet @ %p (%u) bytes!\n", buffer, length); kprintf("E1000: Received 1 packet @ %p (%u) bytes!\n", buffer, length);
#endif #endif

View file

@ -13,10 +13,10 @@ public:
static OwnPtr<E1000NetworkAdapter> autodetect(); static OwnPtr<E1000NetworkAdapter> autodetect();
E1000NetworkAdapter(PCI::Address, byte irq); E1000NetworkAdapter(PCI::Address, u8 irq);
virtual ~E1000NetworkAdapter() override; virtual ~E1000NetworkAdapter() override;
virtual void send_raw(const byte*, int) override; virtual void send_raw(const u8*, int) override;
private: private:
virtual void handle_irq() override; virtual void handle_irq() override;
@ -44,28 +44,28 @@ private:
}; };
void detect_eeprom(); void detect_eeprom();
dword read_eeprom(byte address); u32 read_eeprom(u8 address);
void read_mac_address(); void read_mac_address();
void write_command(word address, dword); void write_command(u16 address, u32);
dword read_command(word address); u32 read_command(u16 address);
void initialize_rx_descriptors(); void initialize_rx_descriptors();
void initialize_tx_descriptors(); void initialize_tx_descriptors();
void out8(word address, byte); void out8(u16 address, u8);
void out16(word address, word); void out16(u16 address, u16);
void out32(word address, dword); void out32(u16 address, u32);
byte in8(word address); u8 in8(u16 address);
word in16(word address); u16 in16(u16 address);
dword in32(word address); u32 in32(u16 address);
void receive(); void receive();
PCI::Address m_pci_address; PCI::Address m_pci_address;
word m_io_base { 0 }; u16 m_io_base { 0 };
PhysicalAddress m_mmio_base; PhysicalAddress m_mmio_base;
byte m_interrupt_line { 0 }; u8 m_interrupt_line { 0 };
bool m_has_eeprom { false }; bool m_has_eeprom { false };
bool m_use_mmio { false }; bool m_use_mmio { false };

View file

@ -3,7 +3,7 @@
#include <AK/Types.h> #include <AK/Types.h>
struct EtherType { struct EtherType {
enum : word { enum : u16 {
ARP = 0x0806, ARP = 0x0806,
IPv4 = 0x0800, IPv4 = 0x0800,
}; };

View file

@ -15,8 +15,8 @@ public:
MACAddress source() const { return m_source; } MACAddress source() const { return m_source; }
void set_source(const MACAddress& address) { m_source = address; } void set_source(const MACAddress& address) { m_source = address; }
word ether_type() const { return m_ether_type; } u16 ether_type() const { return m_ether_type; }
void set_ether_type(word ether_type) { m_ether_type = ether_type; } void set_ether_type(u16 ether_type) { m_ether_type = ether_type; }
const void* payload() const { return &m_payload[0]; } const void* payload() const { return &m_payload[0]; }
void* payload() { return &m_payload[0]; } void* payload() { return &m_payload[0]; }
@ -24,8 +24,8 @@ public:
private: private:
MACAddress m_destination; MACAddress m_destination;
MACAddress m_source; MACAddress m_source;
NetworkOrdered<word> m_ether_type; NetworkOrdered<u16> m_ether_type;
dword m_payload[0]; u32 m_payload[0];
}; };
static_assert(sizeof(EthernetFrameHeader) == 14); static_assert(sizeof(EthernetFrameHeader) == 14);

Some files were not shown because too many files have changed in this diff Show more