Squash commits for public release
This commit is contained in:
26
kernel/include/platform/x86/i386/tasking/context.h
Normal file
26
kernel/include/platform/x86/i386/tasking/context.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef _KERNEL_PLATFORM_X86_I386_TASKING_CONTEXT_H
|
||||
#define _KERNEL_PLATFORM_X86_I386_TASKING_CONTEXT_H
|
||||
|
||||
#include <libkern/c_attrs.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
struct PACKED context {
|
||||
uint32_t edi;
|
||||
uint32_t esi;
|
||||
uint32_t ebx;
|
||||
uint32_t ebp;
|
||||
uint32_t eip;
|
||||
};
|
||||
typedef struct context context_t;
|
||||
|
||||
static inline uintptr_t context_get_instruction_pointer(context_t* ctx)
|
||||
{
|
||||
return ctx->eip;
|
||||
}
|
||||
|
||||
static inline void context_set_instruction_pointer(context_t* ctx, uintptr_t ip)
|
||||
{
|
||||
ctx->eip = ip;
|
||||
}
|
||||
|
||||
#endif // _KERNEL_PLATFORM_X86_I386_TASKING_CONTEXT_H
|
||||
125
kernel/include/platform/x86/i386/tasking/trapframe.h
Normal file
125
kernel/include/platform/x86/i386/tasking/trapframe.h
Normal file
@@ -0,0 +1,125 @@
|
||||
#ifndef _KERNEL_PLATFORM_X86_I386_TASKING_TRAPFRAME_H
|
||||
#define _KERNEL_PLATFORM_X86_I386_TASKING_TRAPFRAME_H
|
||||
|
||||
#include <libkern/c_attrs.h>
|
||||
#include <libkern/types.h>
|
||||
#include <platform/x86/gdt.h>
|
||||
#include <platform/x86/tasking/tss.h>
|
||||
|
||||
struct PACKED trapframe {
|
||||
// registers as pushed by pusha
|
||||
uint32_t edi;
|
||||
uint32_t esi;
|
||||
uint32_t ebp;
|
||||
uint32_t oesp; // useless & ignored
|
||||
uint32_t ebx;
|
||||
uint32_t edx;
|
||||
uint32_t ecx;
|
||||
uint32_t eax;
|
||||
|
||||
// rest of trap frame
|
||||
uint16_t gs;
|
||||
uint16_t padding1;
|
||||
uint16_t fs;
|
||||
uint16_t padding2;
|
||||
uint16_t es;
|
||||
uint16_t padding3;
|
||||
uint16_t ds;
|
||||
uint16_t padding4;
|
||||
uint32_t int_no;
|
||||
|
||||
// below here defined by x86 hardware
|
||||
uint32_t err;
|
||||
uint32_t eip;
|
||||
uint16_t cs;
|
||||
uint16_t padding5;
|
||||
uint32_t eflags;
|
||||
|
||||
// below here only when crossing rings, such as from user to kernel
|
||||
uint32_t esp;
|
||||
uint16_t ss;
|
||||
uint16_t padding6;
|
||||
};
|
||||
typedef struct trapframe trapframe_t;
|
||||
|
||||
static inline uintptr_t get_stack_pointer(trapframe_t* tf)
|
||||
{
|
||||
return tf->esp;
|
||||
}
|
||||
|
||||
static inline void set_stack_pointer(trapframe_t* tf, uintptr_t sp)
|
||||
{
|
||||
tf->esp = sp;
|
||||
}
|
||||
|
||||
static inline uintptr_t get_frame_pointer(trapframe_t* tf)
|
||||
{
|
||||
return tf->ebp;
|
||||
}
|
||||
|
||||
static inline void set_frame_pointer(trapframe_t* tf, uintptr_t bp)
|
||||
{
|
||||
tf->ebp = bp;
|
||||
}
|
||||
|
||||
static inline uintptr_t get_instruction_pointer(trapframe_t* tf)
|
||||
{
|
||||
return tf->eip;
|
||||
}
|
||||
|
||||
static inline void set_instruction_pointer(trapframe_t* tf, uintptr_t ip)
|
||||
{
|
||||
tf->eip = ip;
|
||||
}
|
||||
|
||||
static inline uintptr_t get_syscall_result(trapframe_t* tf)
|
||||
{
|
||||
return tf->eax;
|
||||
}
|
||||
|
||||
static inline void set_syscall_result(trapframe_t* tf, uintptr_t val)
|
||||
{
|
||||
tf->eax = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* STACK FUNCTIONS
|
||||
*/
|
||||
|
||||
static inline void tf_push_to_stack(trapframe_t* tf, uintptr_t val)
|
||||
{
|
||||
tf->esp -= sizeof(uintptr_t);
|
||||
*((uintptr_t*)tf->esp) = val;
|
||||
}
|
||||
|
||||
static inline uint32_t tf_pop_to_stack(trapframe_t* tf)
|
||||
{
|
||||
uintptr_t val = *((uintptr_t*)tf->esp);
|
||||
tf->esp += sizeof(uintptr_t);
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline void tf_move_stack_pointer(trapframe_t* tf, int32_t val)
|
||||
{
|
||||
tf->esp += val;
|
||||
}
|
||||
|
||||
static inline void tf_setup_as_user_thread(trapframe_t* tf)
|
||||
{
|
||||
tf->cs = (GDT_SEG_UCODE << 3) | DPL_USER;
|
||||
tf->ds = (GDT_SEG_UDATA << 3) | DPL_USER;
|
||||
tf->es = tf->ds;
|
||||
tf->ss = tf->ds;
|
||||
tf->eflags = FL_IF;
|
||||
}
|
||||
|
||||
static inline void tf_setup_as_kernel_thread(trapframe_t* tf)
|
||||
{
|
||||
tf->cs = (GDT_SEG_KCODE << 3);
|
||||
tf->ds = (GDT_SEG_KDATA << 3);
|
||||
tf->es = tf->ds;
|
||||
tf->ss = tf->ds;
|
||||
tf->eflags = FL_IF;
|
||||
}
|
||||
|
||||
#endif // _KERNEL_PLATFORM_X86_I386_TASKING_TRAPFRAME_H
|
||||
29
kernel/include/platform/x86/i386/vmm/consts.h
Normal file
29
kernel/include/platform/x86/i386/vmm/consts.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef _KERNEL_PLATFORM_X86_I386_VMM_CONSTS_H
|
||||
#define _KERNEL_PLATFORM_X86_I386_VMM_CONSTS_H
|
||||
|
||||
static inline int vm_page_mask()
|
||||
{
|
||||
return 0xfff;
|
||||
}
|
||||
|
||||
#define VMM_LV0_ENTITY_COUNT (1024)
|
||||
#define VMM_LV1_ENTITY_COUNT (1024)
|
||||
#define VMM_PAGE_SIZE (4096)
|
||||
|
||||
#define VMM_OFFSET_IN_DIRECTORY(a) (((a) >> 22) & 0x3ff)
|
||||
#define VMM_OFFSET_IN_TABLE(a) (((a) >> 12) & 0x3ff)
|
||||
#define VMM_OFFSET_IN_PAGE(a) ((a)&0xfff)
|
||||
#define TABLE_START(vaddr) ((vaddr >> 22) << 22)
|
||||
#define PAGE_START(vaddr) ((vaddr >> 12) << 12)
|
||||
#define FRAME(addr) (addr / VMM_PAGE_SIZE)
|
||||
|
||||
#define PTABLE_TOP_KERNEL_OFFSET 768
|
||||
|
||||
#define PTABLE_LV_TOP (1)
|
||||
#define PTABLE_LV0_VADDR_OFFSET (12)
|
||||
#define PTABLE_LV1_VADDR_OFFSET (22)
|
||||
|
||||
#define USER_HIGH 0xbfffffff
|
||||
#define KERNEL_BASE 0xc0000000
|
||||
|
||||
#endif //_KERNEL_PLATFORM_X86_I386_VMM_CONSTS_H
|
||||
29
kernel/include/platform/x86/i386/vmm/mmu.h
Normal file
29
kernel/include/platform/x86/i386/vmm/mmu.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef _KERNEL_PLATFORM_X86_I386_VMM_MMU_H
|
||||
#define _KERNEL_PLATFORM_X86_I386_VMM_MMU_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
#include <mem/bits/mmu.h>
|
||||
#include <platform/x86/i386/vmm/pde.h>
|
||||
#include <platform/x86/i386/vmm/pte.h>
|
||||
|
||||
typedef uint32_t ptable_entity_t;
|
||||
typedef uint32_t arch_pf_info_t;
|
||||
|
||||
ptable_entity_t vm_mmu_to_arch_flags(mmu_flags_t mmu_flags, ptable_lv_t lv);
|
||||
mmu_flags_t vm_arch_to_mmu_flags(ptable_entity_t* entity, ptable_lv_t lv);
|
||||
mmu_pf_info_flags_t vm_arch_parse_pf_info(arch_pf_info_t info);
|
||||
|
||||
void vm_ptable_entity_set_default_flags(ptable_entity_t* entity, ptable_lv_t lv);
|
||||
void vm_ptable_entity_allocated(ptable_entity_t* entity, ptable_lv_t lv);
|
||||
void vm_ptable_entity_invalidate(ptable_entity_t* entity, ptable_lv_t lv);
|
||||
|
||||
void vm_ptable_entity_set_mmu_flags(ptable_entity_t* entity, ptable_lv_t lv, mmu_flags_t mmu_flags);
|
||||
void vm_ptable_entity_rm_mmu_flags(ptable_entity_t* entity, ptable_lv_t lv, mmu_flags_t mmu_flags);
|
||||
void vm_ptable_entity_set_frame(ptable_entity_t* entity, ptable_lv_t lv, uintptr_t frame);
|
||||
uintptr_t vm_ptable_entity_get_frame(ptable_entity_t* entity, ptable_lv_t lv);
|
||||
|
||||
ptable_state_t vm_ptable_entity_state(ptable_entity_t* entity, ptable_lv_t lv);
|
||||
bool vm_ptable_entity_is_present(ptable_entity_t* entity, ptable_lv_t lv);
|
||||
bool vm_ptable_entity_is_only_allocated(ptable_entity_t* entity, ptable_lv_t lv);
|
||||
|
||||
#endif // _KERNEL_PLATFORM_X86_I386_VMM_MMU_H
|
||||
25
kernel/include/platform/x86/i386/vmm/pde.h
Normal file
25
kernel/include/platform/x86/i386/vmm/pde.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef _KERNEL_PLATFORM_X86_I386_VMM_PDE_H
|
||||
#define _KERNEL_PLATFORM_X86_I386_VMM_PDE_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
#define table_desc_t uint32_t
|
||||
#define pde_t uint32_t
|
||||
|
||||
#define TABLE_DESC_FRAME_OFFSET 12
|
||||
|
||||
enum TABLE_DESC_PAGE_FLAGS {
|
||||
TABLE_DESC_PRESENT = 0x1,
|
||||
TABLE_DESC_WRITABLE = 0x2,
|
||||
TABLE_DESC_USER = 0x4,
|
||||
TABLE_DESC_PWT = 0x8,
|
||||
TABLE_DESC_PCD = 0x10,
|
||||
TABLE_DESC_ACCESSED = 0x20,
|
||||
TABLE_DESC_DIRTY = 0x40,
|
||||
TABLE_DESC_4MB = 0x80,
|
||||
TABLE_DESC_CPU_GLOBAL = 0x100,
|
||||
TABLE_DESC_LV4_GLOBAL = 0x200,
|
||||
TABLE_DESC_COPY_ON_WRITE = 0x400,
|
||||
};
|
||||
|
||||
#endif //_KERNEL_PLATFORM_X86_I386_VMM_PDE_H
|
||||
23
kernel/include/platform/x86/i386/vmm/pte.h
Normal file
23
kernel/include/platform/x86/i386/vmm/pte.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef _KERNEL_PLATFORM_X86_I386_VMM_PTE_H
|
||||
#define _KERNEL_PLATFORM_X86_I386_VMM_PTE_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
#include <mem/bits/mmu.h>
|
||||
|
||||
#define PAGE_DESC_FRAME_OFFSET 12
|
||||
|
||||
enum PAGE_DESC_PAGE_FLAGS {
|
||||
PAGE_DESC_PRESENT = 0x1,
|
||||
PAGE_DESC_WRITABLE = 0x2,
|
||||
PAGE_DESC_USER = 0x4,
|
||||
PAGE_DESC_WRITETHOUGH = 0x8,
|
||||
PAGE_DESC_NOT_CACHEABLE = 0x10,
|
||||
PAGE_DESC_ACCESSED = 0x20,
|
||||
PAGE_DESC_DIRTY = 0x40,
|
||||
PAGE_DESC_PAT = 0x80,
|
||||
PAGE_DESC_CPU_GLOBAL = 0x100,
|
||||
PAGE_DESC_LV4_GLOBAL = 0x200,
|
||||
PAGE_DESC_COPY_ON_WRITE = 0x400,
|
||||
};
|
||||
|
||||
#endif //_KERNEL_PLATFORM_X86_I386_VMM_PTE_H
|
||||
Reference in New Issue
Block a user