mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 20:58:22 +00:00
kernel: ldt support
This commit is contained in:
@@ -13,6 +13,10 @@
|
||||
|
||||
#include <kernel/thread.h>
|
||||
|
||||
#ifdef __x86_64__
|
||||
#include <arch/ldt.h>
|
||||
#endif
|
||||
|
||||
#define PROC_STATE_NORMAL 0
|
||||
#define PROC_STATE_ZOMBIE 1
|
||||
|
||||
@@ -46,6 +50,10 @@ typedef struct proc_t {
|
||||
spinlock_t exiting;
|
||||
int nice;
|
||||
|
||||
#ifdef __x86_64__
|
||||
ldt_entry_t *ldt;
|
||||
#endif
|
||||
|
||||
spinlock_t jobctllock;
|
||||
struct {
|
||||
// NULL if this process is leader
|
||||
|
||||
@@ -42,6 +42,7 @@ typedef struct {
|
||||
uint64_t gsbase;
|
||||
uint64_t fsbase;
|
||||
void *xsave;
|
||||
uint16_t fs, gs;
|
||||
} extracontext_t;
|
||||
|
||||
extern size_t arch_xsave_size;
|
||||
@@ -106,6 +107,6 @@ void arch_extracontext_copy(extracontext_t *dst, const extracontext_t *src);
|
||||
arch_extracontext_save(c);
|
||||
|
||||
#define ARCH_CONTEXT_INTSTATUS(x) ((x)->rflags & 0x200 ? true : false)
|
||||
#define ARCH_CONTEXT_ISUSER(x) ((x)->cs == 0x23)
|
||||
#define ARCH_CONTEXT_ISUSER(x) ((x)->cs != 0x8)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -75,7 +75,7 @@ typedef struct cpu_t {
|
||||
|
||||
// architecture specific, does not need to be exposed
|
||||
|
||||
uint64_t gdt[7];
|
||||
uint64_t gdt[9];
|
||||
char vendor[13];
|
||||
ist_t ist;
|
||||
int acpiid;
|
||||
@@ -90,6 +90,11 @@ typedef struct cpu_t {
|
||||
#define CPU_HALT() asm volatile("hlt")
|
||||
#define CPU_PAUSE() asm volatile("pause")
|
||||
|
||||
bool load_seg_gs(int segment);
|
||||
void load_seg_gs_fallback(void);
|
||||
bool load_seg_fs(int segment);
|
||||
void load_seg_fs_fallback(void);
|
||||
|
||||
static inline uint32_t cpu_to_be_d(uint32_t d) {
|
||||
return __builtin_bswap32(d);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#ifndef _GDT_H
|
||||
#define _GDT_H
|
||||
|
||||
void arch_gdt_reload();
|
||||
#include <stddef.h>
|
||||
|
||||
void arch_gdt_reload(void);
|
||||
|
||||
// should be called with preemption DISABLED
|
||||
void arch_gdt_set_ldt(void *base, size_t limit);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef _LDT_H
|
||||
#define _LDT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint64_t ldt_entry_t;
|
||||
void arch_ldt_invalidate(void);
|
||||
int arch_ldt_set_entry(int which, ldt_entry_t entry);
|
||||
int arch_ldt_fork(ldt_entry_t **dst, ldt_entry_t *src);
|
||||
|
||||
#endif
|
||||
@@ -66,6 +66,12 @@ static inline void arch_sigframe_init(sigframe_t *sigframe) {
|
||||
sigframe->extracontext.xsave = sigframe->xsave;
|
||||
}
|
||||
|
||||
#define CS_sig(context) (*((WORD *)&(context)->uc_mcontext.gregs[REG_CSGSFS] + 0))
|
||||
#define GS_sig(context) (*((WORD *)&(context)->uc_mcontext.gregs[REG_CSGSFS] + 1))
|
||||
#define FS_sig(context) (*((WORD *)&(context)->uc_mcontext.gregs[REG_CSGSFS] + 2))
|
||||
#define SS_sig(context) (*((WORD *)&(context)->uc_mcontext.gregs[REG_CSGSFS] + 3))
|
||||
|
||||
|
||||
static inline void arch_sigframe_prepare_mcontext(void *stack, sigframe_t *sigframe) {
|
||||
context_t *context = &sigframe->context;
|
||||
extracontext_t *extracontext = &sigframe->extracontext;
|
||||
@@ -89,7 +95,7 @@ static inline void arch_sigframe_prepare_mcontext(void *stack, sigframe_t *sigfr
|
||||
gregs[MCONTEXT_REG_RSP] = context->rsp;
|
||||
gregs[MCONTEXT_REG_RIP] = context->rip;
|
||||
gregs[MCONTEXT_REG_EFL] = context->rflags;
|
||||
gregs[MCONTEXT_REG_CSGSFS] = 0;
|
||||
gregs[MCONTEXT_REG_CSGSFS] = (uint64_t)context->cs | ((uint64_t)context->gs << 16) | ((uint64_t)context->fs << 32) | ((uint64_t)context->ss << 48);
|
||||
gregs[MCONTEXT_REG_ERR] = context->error;
|
||||
gregs[MCONTEXT_REG_TRAPNO] = context->irq;
|
||||
gregs[MCONTEXT_REG_OLDMASK] = 0;
|
||||
@@ -124,6 +130,10 @@ static inline void arch_sigframe_get_context_from_mcontext(sigframe_t *sigframe)
|
||||
context->rflags = gregs[MCONTEXT_REG_EFL];
|
||||
context->error = gregs[MCONTEXT_REG_ERR];
|
||||
context->cr2 = gregs[MCONTEXT_REG_CR2];
|
||||
context->cs = gregs[MCONTEXT_REG_CSGSFS] & 0xffff;
|
||||
context->gs = (gregs[MCONTEXT_REG_CSGSFS] >> 16) & 0xffff;
|
||||
context->fs = (gregs[MCONTEXT_REG_CSGSFS] >> 32) & 0xffff;
|
||||
context->ss = (gregs[MCONTEXT_REG_CSGSFS] >> 48) & 0xffff;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user