Skip to content

Commit

Permalink
Kernel: Get rid of Kernel/types.h, separate LinearAddress/PhysicalAdd…
Browse files Browse the repository at this point in the history
…ress.
  • Loading branch information
awesomekling committed Apr 6, 2019
1 parent 6306cf5 commit a58d7fd
Show file tree
Hide file tree
Showing 27 changed files with 119 additions and 121 deletions.
2 changes: 1 addition & 1 deletion Kernel/CMOS.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "types.h"
#include <AK/Types.h>

namespace CMOS {

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/BXVGADevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <AK/Types.h>
#include <AK/AKString.h>
#include <SharedGraphics/Size.h>
#include <Kernel/types.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/Devices/BlockDevice.h>

class BXVGADevice final : public BlockDevice {
Expand Down
1 change: 1 addition & 0 deletions Kernel/Devices/BlockDevice.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <Kernel/Devices/Device.h>
#include <Kernel/LinearAddress.h>

class BlockDevice : public Device {
public:
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/IDEDiskDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "IDEDiskDevice.h"
#include "types.h"
#include <AK/Types.h>
#include "Process.h"
#include "StdLib.h"
#include "IO.h"
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/KeyboardDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "types.h"
#include <AK/Types.h>
#include "i386.h"
#include "IO.h"
#include "PIC.h"
Expand Down
1 change: 0 additions & 1 deletion Kernel/ELF/ELFImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <AK/HashMap.h>
#include <AK/AKString.h>
#include <Kernel/ELF/exec_elf.h>
#include <Kernel/types.h>

class ELFImage {
public:
Expand Down
3 changes: 2 additions & 1 deletion Kernel/FileDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/FileSystem/InodeMetadata.h>
#include "FIFO.h"
#include <Kernel/LinearAddress.h>
#include <Kernel/FIFO.h>
#include <AK/ByteBuffer.h>
#include <AK/CircularQueue.h>
#include <AK/Retainable.h>
Expand Down
2 changes: 1 addition & 1 deletion Kernel/IO.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "types.h"
#include <AK/Types.h>

namespace IO {

Expand Down
36 changes: 36 additions & 0 deletions Kernel/LinearAddress.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <AK/Types.h>

class LinearAddress {
public:
LinearAddress() { }
explicit LinearAddress(dword address) : m_address(address) { }

bool is_null() const { return m_address == 0; }

LinearAddress offset(dword o) const { return LinearAddress(m_address + o); }
dword get() const { return m_address; }
void set(dword address) { m_address = address; }
void mask(dword m) { m_address &= m; }

bool operator<=(const LinearAddress& other) const { return m_address <= other.m_address; }
bool operator>=(const LinearAddress& other) const { return m_address >= other.m_address; }
bool operator>(const LinearAddress& other) const { return m_address > other.m_address; }
bool operator<(const LinearAddress& other) const { return m_address < other.m_address; }
bool operator==(const LinearAddress& other) const { return m_address == other.m_address; }
bool operator!=(const LinearAddress& other) const { return m_address != other.m_address; }

byte* as_ptr() { return reinterpret_cast<byte*>(m_address); }
const byte* as_ptr() const { return reinterpret_cast<const byte*>(m_address); }

dword page_base() const { return m_address & 0xfffff000; }

private:
dword m_address { 0 };
};

inline LinearAddress operator-(const LinearAddress& a, const LinearAddress& b)
{
return LinearAddress(a.get() - b.get());
}
2 changes: 1 addition & 1 deletion Kernel/PIC.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "types.h"
#include <AK/Types.h>
#include "i386.h"
#include "IO.h"
#include "PIC.h"
Expand Down
25 changes: 25 additions & 0 deletions Kernel/PhysicalAddress.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

class PhysicalAddress {
public:
PhysicalAddress() { }
explicit PhysicalAddress(dword address) : m_address(address) { }

PhysicalAddress offset(dword o) const { return PhysicalAddress(m_address + o); }
dword get() const { return m_address; }
void set(dword address) { m_address = address; }
void mask(dword m) { m_address &= m; }

bool is_null() const { return m_address == 0; }

byte* as_ptr() { return reinterpret_cast<byte*>(m_address); }
const byte* as_ptr() const { return reinterpret_cast<const byte*>(m_address); }

dword page_base() const { return m_address & 0xfffff000; }

bool operator==(const PhysicalAddress& other) const { return m_address == other.m_address; }

private:
dword m_address { 0 };
};

2 changes: 1 addition & 1 deletion Kernel/Process.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "types.h"
#include <AK/Types.h>
#include "Process.h"
#include "kmalloc.h"
#include "StdLib.h"
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Process.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "types.h"
#include <AK/Types.h>
#include <Kernel/TTY/TTY.h>
#include "Syscall.h"
#include <Kernel/FileSystem/VirtualFileSystem.h>
Expand Down
2 changes: 1 addition & 1 deletion Kernel/RTC.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "types.h"
#include <Kernel/UnixTypes.h>

namespace RTC {

Expand Down
2 changes: 1 addition & 1 deletion Kernel/StdLib.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "types.h"
#include <AK/Types.h>
#include "Assertions.h"
#include "kmalloc.h"
#include <AK/StdLibExtras.h>
Expand Down
2 changes: 1 addition & 1 deletion Kernel/StdLib.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <Kernel/types.h>
#include <AK/Types.h>

extern "C" {

Expand Down
2 changes: 2 additions & 0 deletions Kernel/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <Kernel/i386.h>
#include <Kernel/TSS.h>
#include <Kernel/KResult.h>
#include <Kernel/LinearAddress.h>
#include <Kernel/UnixTypes.h>
#include <AK/AKString.h>
#include <AK/InlineLinkedList.h>
#include <AK/RetainPtr.h>
Expand Down
32 changes: 32 additions & 0 deletions Kernel/UnixTypes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <AK/Types.h>

#define WNOHANG 1

#define R_OK 4
Expand Down Expand Up @@ -222,6 +224,7 @@ typedef dword uid_t;
typedef dword gid_t;
typedef dword clock_t;
typedef dword socklen_t;
typedef int pid_t;

struct tms {
clock_t tms_utime;
Expand Down Expand Up @@ -359,3 +362,32 @@ struct sockaddr_in {
struct in_addr sin_addr;
char sin_zero[8];
};

typedef dword __u32;
typedef word __u16;
typedef byte __u8;
typedef int __s32;
typedef short __s16;

typedef dword useconds_t;
typedef signed_dword suseconds_t;

struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};

#define UTSNAME_ENTRY_LEN 65

struct utsname {
char sysname[UTSNAME_ENTRY_LEN];
char nodename[UTSNAME_ENTRY_LEN];
char release[UTSNAME_ENTRY_LEN];
char version[UTSNAME_ENTRY_LEN];
char machine[UTSNAME_ENTRY_LEN];
};

struct [[gnu::packed]] FarPtr {
dword offset { 0 };
word selector { 0 };
};
3 changes: 2 additions & 1 deletion Kernel/VM/MemoryManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "types.h"
#include <AK/Types.h>
#include "i386.h"
#include <AK/Bitmap.h>
#include <AK/ByteBuffer.h>
Expand All @@ -11,6 +11,7 @@
#include <AK/AKString.h>
#include <AK/Badge.h>
#include <AK/Weakable.h>
#include <Kernel/LinearAddress.h>
#include <Kernel/VM/PhysicalPage.h>
#include <Kernel/VM/Region.h>
#include <Kernel/VM/VMObject.h>
Expand Down
2 changes: 1 addition & 1 deletion Kernel/VM/PhysicalPage.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <Kernel/Assertions.h>
#include <Kernel/types.h>
#include <Kernel/PhysicalAddress.h>
#include <AK/Retained.h>

class PhysicalPage {
Expand Down
2 changes: 2 additions & 0 deletions Kernel/VM/VMObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <AK/Vector.h>
#include <AK/AKString.h>
#include <Kernel/Lock.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/UnixTypes.h>

class Inode;
class PhysicalPage;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/i386.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "types.h"
#include <AK/Types.h>
#include "kmalloc.h"
#include "i386.h"
#include "Assertions.h"
Expand Down
2 changes: 1 addition & 1 deletion Kernel/i386.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "types.h"
#include "kprintf.h"
#include <Kernel/LinearAddress.h>

#define PAGE_SIZE 4096
#define PAGE_MASK 0xfffff000
Expand Down
2 changes: 1 addition & 1 deletion Kernel/init.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "types.h"
#include <AK/Types.h>
#include "kmalloc.h"
#include "i386.h"
#include "i8253.h"
Expand Down
2 changes: 1 addition & 1 deletion Kernel/kmalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* just to get going. Don't ever let anyone see this shit. :^)
*/

#include <Kernel/types.h>
#include <AK/Types.h>
#include <Kernel/kmalloc.h>
#include <Kernel/StdLib.h>
#include <Kernel/i386.h>
Expand Down
2 changes: 1 addition & 1 deletion Kernel/system.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "types.h"
#include <AK/Types.h>

struct system_t
{
Expand Down
Loading

0 comments on commit a58d7fd

Please sign in to comment.