diff options
author | Marvin Borner | 2021-02-27 18:24:38 +0100 |
---|---|---|
committer | Marvin Borner | 2021-02-27 18:24:38 +0100 |
commit | 7304e20731980078a7bfe138a20a8d13653fed7b (patch) | |
tree | fbfce00a6a8017f842e8a165b563ab15a094eb84 /kernel/inc | |
parent | 4309322f9d2b3e31421a3cc5399ab1f4368e0652 (diff) |
Started basic paging port from skiftOS
Diffstat (limited to 'kernel/inc')
-rw-r--r-- | kernel/inc/memory.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/kernel/inc/memory.h b/kernel/inc/memory.h new file mode 100644 index 0000000..4647c3e --- /dev/null +++ b/kernel/inc/memory.h @@ -0,0 +1,79 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef PAGING_H +#define PAGING_H + +#include <def.h> + +/** + * Physical + */ + +/** + * Virtual + */ + +#define PAGE_SIZE 0x1000 +#define PAGE_COUNT 1024 +#define PAGE_ALIGN(x) ((x) + PAGE_SIZE - ((x) % PAGE_SIZE)) +#define PAGE_ALIGNED(x) ((x) % PAGE_SIZE == 0) + +union page_table_entry { + struct PACKED { + u32 present : 1; + u32 writable : 1; + u32 user : 1; + u32 write_through : 1; + u32 cache_disable : 1; + u32 accessed : 1; + u32 dirty : 1; + u32 attribute : 1; + u32 global : 1; + u32 available : 3; + u32 address : 20; + } bits; + u32 uint; +} PACKED; + +struct page_table { + union page_table_entry entries[PAGE_COUNT]; +} PACKED; + +union page_dir_entry { + struct PACKED { + u32 present : 1; + u32 writable : 1; + u32 user : 1; + u32 write_through : 1; + u32 cache_disable : 1; + u32 accessed : 1; + u32 reserved : 1; + u32 page_size : 1; + u32 global : 1; + u32 available : 3; + u32 address : 20; + } bits; + u32 uint; +} PACKED; + +struct page_dir { + union page_dir_entry entries[PAGE_COUNT]; +} PACKED; + +void paging_install(void); + +/** + * Memory wrappers + */ + +#define MEMORY_NONE (0 << 0) +#define MEMORY_USER (1 << 0) +#define MEMORY_CLEAR (1 << 1) +#define memory_range(base, size) ((struct memory_range){ (base), (size) }) + +struct memory_range { + u32 base; + u32 size; +}; + +#endif |