types.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #pragma once
  2. #include <AK/Compiler.h>
  3. #include <AK/Types.h>
  4. #define PACKED __attribute__ ((packed))
  5. #define PURE __attribute__ ((pure))
  6. typedef dword __u32;
  7. typedef word __u16;
  8. typedef byte __u8;
  9. typedef int __s32;
  10. typedef short __s16;
  11. typedef dword uid_t;
  12. typedef dword gid_t;
  13. typedef int pid_t;
  14. typedef dword time_t;
  15. typedef dword suseconds_t;
  16. struct timeval {
  17. time_t tv_sec;
  18. suseconds_t tv_usec;
  19. };
  20. #define UTSNAME_ENTRY_LEN 65
  21. struct utsname {
  22. char sysname[UTSNAME_ENTRY_LEN];
  23. char nodename[UTSNAME_ENTRY_LEN];
  24. char release[UTSNAME_ENTRY_LEN];
  25. char version[UTSNAME_ENTRY_LEN];
  26. char machine[UTSNAME_ENTRY_LEN];
  27. };
  28. typedef dword ino_t;
  29. typedef signed_dword off_t;
  30. typedef dword dev_t;
  31. typedef word mode_t;
  32. typedef dword nlink_t;
  33. typedef dword blksize_t;
  34. typedef dword blkcnt_t;
  35. struct FarPtr {
  36. dword offset { 0 };
  37. word selector { 0 };
  38. } PACKED;
  39. class PhysicalAddress {
  40. public:
  41. PhysicalAddress() { }
  42. explicit PhysicalAddress(dword address) : m_address(address) { }
  43. PhysicalAddress offset(dword o) const { return PhysicalAddress(m_address + o); }
  44. dword get() const { return m_address; }
  45. void set(dword address) { m_address = address; }
  46. void mask(dword m) { m_address &= m; }
  47. bool is_null() const { return m_address == 0; }
  48. byte* as_ptr() { return reinterpret_cast<byte*>(m_address); }
  49. const byte* as_ptr() const { return reinterpret_cast<const byte*>(m_address); }
  50. dword page_base() const { return m_address & 0xfffff000; }
  51. bool operator==(const PhysicalAddress& other) const { return m_address == other.m_address; }
  52. private:
  53. dword m_address { 0 };
  54. };
  55. class LinearAddress {
  56. public:
  57. LinearAddress() { }
  58. explicit LinearAddress(dword address) : m_address(address) { }
  59. bool is_null() const { return m_address == 0; }
  60. LinearAddress offset(dword o) const { return LinearAddress(m_address + o); }
  61. dword get() const { return m_address; }
  62. void set(dword address) { m_address = address; }
  63. void mask(dword m) { m_address &= m; }
  64. bool operator<=(const LinearAddress& other) const { return m_address <= other.m_address; }
  65. bool operator>=(const LinearAddress& other) const { return m_address >= other.m_address; }
  66. bool operator>(const LinearAddress& other) const { return m_address > other.m_address; }
  67. bool operator<(const LinearAddress& other) const { return m_address < other.m_address; }
  68. bool operator==(const LinearAddress& other) const { return m_address == other.m_address; }
  69. bool operator!=(const LinearAddress& other) const { return m_address != other.m_address; }
  70. byte* as_ptr() { return reinterpret_cast<byte*>(m_address); }
  71. const byte* as_ptr() const { return reinterpret_cast<const byte*>(m_address); }
  72. dword page_base() const { return m_address & 0xfffff000; }
  73. private:
  74. dword m_address { 0 };
  75. };
  76. inline LinearAddress operator-(const LinearAddress& a, const LinearAddress& b)
  77. {
  78. return LinearAddress(a.get() - b.get());
  79. }