2020-12-07 21:56:38 -05:00
|
|
|
#ifndef KERNAUX_INCLUDED_ARCH_I386
|
2021-12-20 01:17:53 -05:00
|
|
|
#define KERNAUX_INCLUDED_ARCH_I386
|
2020-12-07 21:56:38 -05:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-12-16 11:04:41 -05:00
|
|
|
#include <stdint.h>
|
2020-12-07 21:56:38 -05:00
|
|
|
|
2021-12-21 00:15:20 -05:00
|
|
|
#define KERNAUX_ARCH_I386_PAGE_SIZE (1024 * 4) // 4 KiB
|
|
|
|
#define KERNAUX_ARCH_I386_PAGE_BIG_SIZE (1024 * 1024 * 4) // 4 MiB
|
|
|
|
|
|
|
|
#define KERNAUX_ARCH_I386_PAGE_DIR_ENTRIES_COUNT 1024
|
|
|
|
#define KERNAUX_ARCH_I386_PAGE_TABLE_ENTRIES_COUNT 1024
|
|
|
|
|
|
|
|
#define KERNAUX_ARCH_I386_PAGES_COUNT_MAX (1024 * 1024)
|
2021-12-18 21:56:17 -05:00
|
|
|
|
2021-12-21 00:43:30 -05:00
|
|
|
#define KERNAUX_ARCH_I386_ADDR_TO_PDE_INDEX(addr) \
|
|
|
|
((((uint32_t)addr) & 0xFFFFFFFF) >> 22)
|
|
|
|
#define KERNAUX_ARCH_I386_ADDR_TO_PTE_INDEX(addr) \
|
|
|
|
(((((uint32_t)addr) & 0xFFFFFFFF) >> 12) & 0x3FF)
|
|
|
|
|
|
|
|
#define KERNAUX_ARCH_I386_ADDR_TO_PDE_ADDR(addr) \
|
|
|
|
((((uint32_t)addr) & 0xFFFFFFFF) >> 12)
|
|
|
|
#define KERNAUX_ARCH_I386_ADDR_TO_PTE_ADDR(addr) \
|
|
|
|
KERNAUX_ARCH_I386_ADDR_TO_PDE_ADDR(addr)
|
|
|
|
|
2021-12-17 22:22:55 -05:00
|
|
|
// CR0 bits
|
|
|
|
#define KERNAUX_ARCH_I386_CR0_PE ((uint32_t)0x00000001) // 0: Protected Mode Enable
|
|
|
|
#define KERNAUX_ARCH_I386_CR0_MP ((uint32_t)0x00000002) // 1: Monitor co-processor
|
|
|
|
#define KERNAUX_ARCH_I386_CR0_EM ((uint32_t)0x00000004) // 2: x87 FPU Emulation
|
|
|
|
#define KERNAUX_ARCH_I386_CR0_TS ((uint32_t)0x00000008) // 3: Task switched
|
|
|
|
#define KERNAUX_ARCH_I386_CR0_ET ((uint32_t)0x00000010) // 4: Extension type
|
|
|
|
#define KERNAUX_ARCH_I386_CR0_NE ((uint32_t)0x00000020) // 5: Numeric error
|
|
|
|
#define KERNAUX_ARCH_I386_CR0_WP ((uint32_t)0x00010000) // 16: Write protect
|
|
|
|
#define KERNAUX_ARCH_I386_CR0_AM ((uint32_t)0x00040000) // 18: Alignment mask
|
|
|
|
#define KERNAUX_ARCH_I386_CR0_NW ((uint32_t)0x20000000) // 29: Not-write trough
|
|
|
|
#define KERNAUX_ARCH_I386_CR0_CD ((uint32_t)0x40000000) // 30: Cache disable
|
|
|
|
#define KERNAUX_ARCH_I386_CR0_PG ((uint32_t)0x80000000) // 31: Paging
|
|
|
|
|
2021-12-17 22:30:26 -05:00
|
|
|
// Some CR4 bits
|
|
|
|
#define KERNAUX_ARCH_I386_CR4_VME ((uint32_t)0x00000001) // 0: Virtual 8086 Mode Extensions
|
|
|
|
#define KERNAUX_ARCH_I386_CR4_PVI ((uint32_t)0x00000002) // 1: Protected-mode Virtual Interrupts
|
|
|
|
#define KERNAUX_ARCH_I386_CR4_TSD ((uint32_t)0x00000004) // 2: Time Stamp Disable
|
|
|
|
#define KERNAUX_ARCH_I386_CR4_DE ((uint32_t)0x00000008) // 3: Debugging Extensions
|
|
|
|
#define KERNAUX_ARCH_I386_CR4_PSE ((uint32_t)0x00000010) // 4: Page Size Extension
|
|
|
|
#define KERNAUX_ARCH_I386_CR4_PAE ((uint32_t)0x00000020) // 5: Physical Address Extension
|
|
|
|
#define KERNAUX_ARCH_I386_CR4_MCE ((uint32_t)0x00000040) // 6: Machine Check Exception
|
|
|
|
#define KERNAUX_ARCH_I386_CR4_PGE ((uint32_t)0x00000080) // 7: Page Global Enabled
|
|
|
|
// TODO: bits 8-31
|
|
|
|
|
2021-12-18 18:42:04 -05:00
|
|
|
// Global descriptor table entry
|
|
|
|
// TODO: validate this according to spec
|
|
|
|
struct KernAux_Arch_I386_GDTE {
|
2022-01-11 01:28:36 -05:00
|
|
|
unsigned limit_low : 16;
|
|
|
|
unsigned base_low : 24;
|
|
|
|
unsigned accessed : 1;
|
|
|
|
unsigned read_write : 1;
|
|
|
|
unsigned conforming_expand_down : 1;
|
|
|
|
unsigned code : 1;
|
|
|
|
unsigned always_1 : 1;
|
|
|
|
unsigned DPL : 2;
|
|
|
|
unsigned present : 1;
|
|
|
|
unsigned limit_high : 4;
|
|
|
|
unsigned available : 1;
|
|
|
|
unsigned always_0 : 1;
|
|
|
|
unsigned big : 1;
|
|
|
|
unsigned gran : 1;
|
|
|
|
unsigned base_high : 8;
|
2021-12-18 18:42:04 -05:00
|
|
|
}
|
|
|
|
__attribute__((packed));
|
|
|
|
|
2021-12-18 21:51:41 -05:00
|
|
|
// Page directory entry
|
2021-12-18 18:42:04 -05:00
|
|
|
// TODO: validate this according to spec
|
2021-12-18 21:51:41 -05:00
|
|
|
struct KernAux_Arch_I386_PDE {
|
2021-12-18 16:07:39 -05:00
|
|
|
unsigned present : 1;
|
|
|
|
unsigned writable : 1;
|
|
|
|
unsigned user : 1;
|
|
|
|
unsigned write_through : 1;
|
|
|
|
unsigned cache_disabled : 1;
|
|
|
|
unsigned accessed : 1;
|
2021-12-18 21:51:41 -05:00
|
|
|
unsigned available0 : 1;
|
|
|
|
unsigned page_size : 1;
|
|
|
|
unsigned available1 : 4;
|
2021-12-18 16:07:39 -05:00
|
|
|
unsigned addr : 20;
|
|
|
|
}
|
|
|
|
__attribute__((packed));
|
|
|
|
|
2021-12-18 21:51:41 -05:00
|
|
|
// Page table entry
|
2021-12-18 18:42:04 -05:00
|
|
|
// TODO: validate this according to spec
|
2021-12-18 21:51:41 -05:00
|
|
|
struct KernAux_Arch_I386_PTE {
|
2021-12-17 23:06:55 -05:00
|
|
|
unsigned present : 1;
|
|
|
|
unsigned writable : 1;
|
|
|
|
unsigned user : 1;
|
|
|
|
unsigned write_through : 1;
|
|
|
|
unsigned cache_disabled : 1;
|
|
|
|
unsigned accessed : 1;
|
2021-12-18 21:51:41 -05:00
|
|
|
unsigned dirty : 1;
|
|
|
|
unsigned attr_table : 1;
|
|
|
|
unsigned global : 1;
|
|
|
|
unsigned available : 3;
|
2021-12-17 23:06:55 -05:00
|
|
|
unsigned addr : 20;
|
|
|
|
}
|
|
|
|
__attribute__((packed));
|
|
|
|
|
2021-12-18 21:56:17 -05:00
|
|
|
// Page directory
|
|
|
|
struct KernAux_Arch_I386_PageDir {
|
2021-12-21 00:15:20 -05:00
|
|
|
struct KernAux_Arch_I386_PDE pdes[KERNAUX_ARCH_I386_PAGE_DIR_ENTRIES_COUNT];
|
2021-12-18 21:56:17 -05:00
|
|
|
}
|
|
|
|
__attribute__((packed));
|
|
|
|
|
|
|
|
// Page table
|
|
|
|
struct KernAux_Arch_I386_PageTable {
|
2021-12-21 00:15:20 -05:00
|
|
|
struct KernAux_Arch_I386_PTE ptes[KERNAUX_ARCH_I386_PAGE_TABLE_ENTRIES_COUNT];
|
2021-12-18 21:56:17 -05:00
|
|
|
}
|
|
|
|
__attribute__((packed));
|
|
|
|
|
2020-12-07 21:56:38 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|