Removed the x86_64 headers/source directories, now all merged with x86.
This commit is contained in:
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_X86_64_CPU_H
|
||||
#define _KERNEL_ARCH_X86_64_CPU_H
|
||||
|
||||
|
||||
#include "../common_x86/cpu.h"
|
||||
|
||||
#ifndef _ASSEMBLER
|
||||
# ifndef _BOOT_MODE
|
||||
# include <arch/x86_64/descriptors.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
// iframe types
|
||||
#define IFRAME_TYPE_SYSCALL 0x1
|
||||
#define IFRAME_TYPE_OTHER 0x2
|
||||
#define IFRAME_TYPE_MASK 0xf
|
||||
|
||||
|
||||
#ifndef _ASSEMBLER
|
||||
|
||||
|
||||
struct tss {
|
||||
uint32 _reserved1;
|
||||
uint64 rsp0;
|
||||
uint64 rsp1;
|
||||
uint64 rsp2;
|
||||
uint64 _reserved2;
|
||||
uint64 ist1;
|
||||
uint64 ist2;
|
||||
uint64 ist3;
|
||||
uint64 ist4;
|
||||
uint64 ist5;
|
||||
uint64 ist6;
|
||||
uint64 ist7;
|
||||
uint64 _reserved3;
|
||||
uint16 _reserved4;
|
||||
uint16 io_bitmap;
|
||||
} _PACKED;
|
||||
|
||||
|
||||
struct iframe {
|
||||
unsigned long type;
|
||||
unsigned long r15;
|
||||
unsigned long r14;
|
||||
unsigned long r13;
|
||||
unsigned long r12;
|
||||
unsigned long r11;
|
||||
unsigned long r10;
|
||||
unsigned long r9;
|
||||
unsigned long r8;
|
||||
unsigned long rbp;
|
||||
unsigned long rsi;
|
||||
unsigned long rdi;
|
||||
unsigned long rdx;
|
||||
unsigned long rcx;
|
||||
unsigned long rbx;
|
||||
unsigned long rax;
|
||||
unsigned long vector;
|
||||
unsigned long error_code;
|
||||
unsigned long rip;
|
||||
unsigned long cs;
|
||||
unsigned long flags;
|
||||
|
||||
// Only present when the iframe is a userland iframe (IFRAME_IS_USER()).
|
||||
unsigned long user_rsp;
|
||||
unsigned long user_ss;
|
||||
} _PACKED;
|
||||
|
||||
#define IFRAME_IS_USER(f) (((f)->cs & DPL_USER) == DPL_USER)
|
||||
|
||||
|
||||
typedef struct arch_cpu_info {
|
||||
// CPU identification/feature information.
|
||||
enum x86_vendors vendor;
|
||||
uint32 feature[FEATURE_NUM];
|
||||
char model_name[49];
|
||||
const char* vendor_name;
|
||||
int type;
|
||||
int family;
|
||||
int extended_family;
|
||||
int stepping;
|
||||
int model;
|
||||
int extended_model;
|
||||
|
||||
// TSS for this CPU.
|
||||
struct tss tss;
|
||||
} arch_cpu_info;
|
||||
|
||||
|
||||
#ifndef _BOOT_MODE
|
||||
extern segment_descriptor* gGDT;
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _ASSEMBLER */
|
||||
|
||||
#endif /* _KERNEL_ARCH_X86_64_CPU_H */
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_X86_64_DEBUG_H
|
||||
#define _KERNEL_ARCH_X86_64_DEBUG_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
struct arch_debug_registers {
|
||||
uint64 rbp;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _KERNEL_ARCH_X86_64_DEBUG_H */
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2009, Axel Dörfler, [email protected].
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_X86_64_INT_H
|
||||
#define _KERNEL_ARCH_X86_64_INT_H
|
||||
|
||||
|
||||
#define ARCH_INTERRUPT_BASE 0x20
|
||||
#define NUM_IO_VECTORS (256 - ARCH_INTERRUPT_BASE)
|
||||
|
||||
|
||||
static inline void
|
||||
arch_int_enable_interrupts_inline(void)
|
||||
{
|
||||
asm volatile("sti");
|
||||
}
|
||||
|
||||
|
||||
static inline int
|
||||
arch_int_disable_interrupts_inline(void)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
asm volatile("pushf;\n"
|
||||
"pop %0;\n"
|
||||
"cli" : "=g" (flags));
|
||||
return (flags & 0x200) != 0;
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
arch_int_restore_interrupts_inline(int oldState)
|
||||
{
|
||||
if (oldState)
|
||||
asm("sti");
|
||||
}
|
||||
|
||||
|
||||
static inline bool
|
||||
arch_int_are_interrupts_enabled_inline(void)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
asm volatile("pushf;\n"
|
||||
"pop %0;\n" : "=g" (flags));
|
||||
return (flags & 0x200) != 0;
|
||||
}
|
||||
|
||||
|
||||
// map the functions to the inline versions
|
||||
#define arch_int_enable_interrupts() arch_int_enable_interrupts_inline()
|
||||
#define arch_int_disable_interrupts() arch_int_disable_interrupts_inline()
|
||||
#define arch_int_restore_interrupts(status) \
|
||||
arch_int_restore_interrupts_inline(status)
|
||||
#define arch_int_are_interrupts_enabled() \
|
||||
arch_int_are_interrupts_enabled_inline()
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
typedef struct interrupt_controller_s {
|
||||
const char *name;
|
||||
void (*enable_io_interrupt)(int32 num);
|
||||
void (*disable_io_interrupt)(int32 num);
|
||||
void (*configure_io_interrupt)(int32 num, uint32 config);
|
||||
bool (*is_spurious_interrupt)(int32 num);
|
||||
bool (*is_level_triggered_interrupt)(int32 num);
|
||||
bool (*end_of_interrupt)(int32 num);
|
||||
} interrupt_controller;
|
||||
|
||||
|
||||
void arch_int_set_interrupt_controller(const interrupt_controller &controller);
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif /* _KERNEL_ARCH_X86_64_INT_H */
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_X86_64_KERNEL_H
|
||||
#define _KERNEL_ARCH_X86_64_KERNEL_H
|
||||
|
||||
|
||||
#ifndef _ASSEMBLER
|
||||
# include <arch/cpu.h>
|
||||
#endif
|
||||
|
||||
|
||||
// Base of the kernel address space.
|
||||
// When compiling the bootloader, KERNEL_BASE is set to the x86 base address,
|
||||
// KERNEL_BASE_64BIT is set to where the kernel loaded to.
|
||||
// For the kernel, KERNEL_BASE is the base of the kernel address space. This is
|
||||
// NOT the address where the kernel is loaded to: the kernel is loaded in the
|
||||
// top 2GB of the virtual address space as required by GCC's kernel code model.
|
||||
// The whole kernel address space is the top 512GB of the address space.
|
||||
#ifdef _BOOT_MODE
|
||||
# define KERNEL_BASE 0x80000000
|
||||
# define KERNEL_BASE_64BIT 0xffffffff80000000ll
|
||||
#else
|
||||
# define KERNEL_BASE 0xffffff8000000000
|
||||
#endif
|
||||
|
||||
#define KERNEL_SIZE 0x8000000000
|
||||
#define KERNEL_TOP (KERNEL_BASE + (KERNEL_SIZE - 1))
|
||||
|
||||
|
||||
// Userspace address space layout.
|
||||
#define USER_BASE 0x0
|
||||
#define USER_BASE_ANY 0x100000
|
||||
#define USER_SIZE 0x800000000000
|
||||
#define USER_TOP (USER_BASE + USER_SIZE)
|
||||
|
||||
#define KERNEL_USER_DATA_BASE 0x7fffefff0000
|
||||
#define USER_STACK_REGION 0x7ffff0000000
|
||||
#define USER_STACK_REGION_SIZE (USER_TOP - USER_STACK_REGION)
|
||||
|
||||
|
||||
#endif /* _KERNEL_ARCH_X86_64_KERNEL_H */
|
||||
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_X86_64_KERNEL_ARGS_H
|
||||
#define _KERNEL_ARCH_X86_64_KERNEL_ARGS_H
|
||||
|
||||
|
||||
// x86_64 kernel is loaded loaded by the x86 bootloader, kernel_args is
|
||||
// identical to x86.
|
||||
#include "../x86/arch_kernel_args.h"
|
||||
|
||||
|
||||
#endif /* _KERNEL_ARCH_X86_64_KERNEL_ARGS_H */
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2005, Axel Dörfler, [email protected]. All rights reserved.
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_X86_64_SYSTEM_INFO_H
|
||||
#define _KERNEL_ARCH_X86_64_SYSTEM_INFO_H
|
||||
|
||||
|
||||
#include <OS.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef _BOOT_MODE
|
||||
status_t get_current_cpuid(cpuid_info *info, uint32 eax);
|
||||
uint32 get_eflags(void);
|
||||
void set_eflags(uint32 value);
|
||||
#endif
|
||||
|
||||
//status_t _user_get_cpuid(cpuid_info *info, uint32 eax, uint32 cpu);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _KRENEL_ARCH_X86_64_SYSTEM_INFO_H */
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_X86_64_THREAD_H
|
||||
#define _KERNEL_ARCH_X86_64_THREAD_H
|
||||
|
||||
|
||||
#include <arch/cpu.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline Thread *
|
||||
arch_thread_get_current_thread(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline void
|
||||
arch_thread_set_current_thread(Thread *t)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _KERNEL_ARCH_X86_64_THREAD_H */
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_X86_64_THREAD_TYPES_H
|
||||
#define _KERNEL_ARCH_X86_64_THREAD_TYPES_H
|
||||
|
||||
|
||||
#include <arch_cpu.h>
|
||||
|
||||
|
||||
// x86_64-specific thread information.
|
||||
struct arch_thread {
|
||||
// Stack pointer.
|
||||
addr_t rsp;
|
||||
|
||||
// FPU saved state - this must be 16 byte aligned.
|
||||
uint8 fpu_state[512] __attribute__((aligned(16)));
|
||||
} __attribute__((aligned(16)));
|
||||
|
||||
struct arch_team {
|
||||
// gcc treats empty structures as zero-length in C, but as if they contain
|
||||
// a char in C++. So we have to put a dummy in to be able to use the struct
|
||||
// from both in a consistent way.
|
||||
char dummy;
|
||||
};
|
||||
|
||||
struct arch_fork_arg {
|
||||
struct iframe iframe;
|
||||
};
|
||||
|
||||
#endif /* _KERNEL_ARCH_X86_64_THREAD_TYPES_H */
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef _KERNEL_ARCH_X86_64_USER_DEBUGGER_H
|
||||
#define _KERNEL_ARCH_X86_64_USER_DEBUGGER_H
|
||||
|
||||
#include "../x86/arch_user_debugger.h"
|
||||
|
||||
#endif /* _KERNEL_ARCH_X86_64_USER_DEBUGGER_H */
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Copyright 2004, Axel Dörfler, [email protected]. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_X86_64_VM_H
|
||||
#define _KERNEL_ARCH_X86_64_VM_H
|
||||
|
||||
/* This many pages will be read/written on I/O if possible */
|
||||
|
||||
#define NUM_IO_PAGES 4
|
||||
/* 16 kB */
|
||||
|
||||
#define PAGE_SHIFT 12
|
||||
|
||||
#endif /* _KERNEL_ARCH_X86_64_VM_H */
|
||||
@@ -1,9 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_X86_64_VM_TRANSLATION_MAP_H
|
||||
#define _KERNEL_ARCH_X86_64_VM_TRANSLATION_MAP_H
|
||||
|
||||
|
||||
#endif /* _KERNEL_ARCH_X86_64_VM_TRANSLATION_MAP_H */
|
||||
@@ -1,9 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_X86_64_VM_TYPES_H
|
||||
#define _KERNEL_ARCH_X86_64_VM_TYPES_H
|
||||
|
||||
|
||||
#endif /* _KERNEL_ARCH_X86_64_VM_TYPES_H */
|
||||
@@ -1,180 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _KERNEL_ARCH_X86_64_DESCRIPTORS_H
|
||||
#define _KERNEL_ARCH_X86_64_DESCRIPTORS_H
|
||||
|
||||
|
||||
// Segment definitions.
|
||||
// Note that the ordering of these is important to SYSCALL/SYSRET.
|
||||
#define KERNEL_CODE_SEG 0x08
|
||||
#define KERNEL_DATA_SEG 0x10
|
||||
#define USER_DATA_SEG 0x1b
|
||||
#define USER_CODE_SEG 0x23
|
||||
|
||||
|
||||
#ifndef _ASSEMBLER
|
||||
|
||||
|
||||
#define TSS_BASE_SEGMENT 5
|
||||
#define TLS_BASE_SEGMENT (TSS_BASE_SEGMENT + smp_get_num_cpus())
|
||||
|
||||
|
||||
// Structure of a segment descriptor.
|
||||
struct segment_descriptor {
|
||||
uint32 limit0 : 16;
|
||||
uint32 base0 : 24;
|
||||
uint32 type : 4;
|
||||
uint32 desc_type : 1;
|
||||
uint32 dpl : 2;
|
||||
uint32 present : 1;
|
||||
uint32 limit1 : 4;
|
||||
uint32 available : 1;
|
||||
uint32 long_mode : 1;
|
||||
uint32 d_b : 1;
|
||||
uint32 granularity : 1;
|
||||
uint32 base1 : 8;
|
||||
} _PACKED;
|
||||
|
||||
// Structure of a TSS segment descriptor.
|
||||
struct tss_descriptor {
|
||||
uint32 limit0 : 16;
|
||||
uint32 base0 : 24;
|
||||
uint32 type : 4;
|
||||
uint32 desc_type : 1;
|
||||
uint32 dpl : 2;
|
||||
uint32 present : 1;
|
||||
uint32 limit1 : 4;
|
||||
uint32 available : 1;
|
||||
uint32 unused1 : 2;
|
||||
uint32 granularity : 1;
|
||||
uint32 base1 : 8;
|
||||
uint32 base2 : 32;
|
||||
uint32 unused2 : 32;
|
||||
} _PACKED;
|
||||
|
||||
// Structure of an interrupt descriptor.
|
||||
struct interrupt_descriptor {
|
||||
uint32 base0 : 16;
|
||||
uint32 sel : 16;
|
||||
uint32 ist : 3;
|
||||
uint32 unused1 : 5;
|
||||
uint32 type : 4;
|
||||
uint32 unused2 : 1;
|
||||
uint32 dpl : 2;
|
||||
uint32 present : 1;
|
||||
uint32 base1 : 16;
|
||||
uint32 base2 : 32;
|
||||
uint32 reserved : 32;
|
||||
} _PACKED;
|
||||
|
||||
struct gdt_idt_descr {
|
||||
uint16 limit;
|
||||
addr_t base;
|
||||
} _PACKED;
|
||||
|
||||
enum descriptor_privilege_levels {
|
||||
DPL_KERNEL = 0,
|
||||
DPL_USER = 3,
|
||||
};
|
||||
|
||||
enum descriptor_types {
|
||||
// Code/data descriptor types.
|
||||
DT_CODE_EXECUTE_ONLY = 0x8,
|
||||
DT_CODE_ACCESSED = 0x9,
|
||||
DT_CODE_READABLE = 0xa,
|
||||
DT_CODE_CONFORM = 0xc,
|
||||
DT_DATA_READ_ONLY = 0x0,
|
||||
DT_DATA_ACCESSED = 0x1,
|
||||
DT_DATA_WRITEABLE = 0x2,
|
||||
DT_DATA_EXPANSION_DOWN = 0x4,
|
||||
|
||||
// System descriptor types.
|
||||
DT_TSS = 9,
|
||||
|
||||
// Descriptor types
|
||||
DT_SYSTEM_SEGMENT = 0,
|
||||
DT_CODE_DATA_SEGMENT = 1,
|
||||
};
|
||||
|
||||
enum gate_types {
|
||||
GATE_INTERRUPT = 14,
|
||||
GATE_TRAP = 15,
|
||||
};
|
||||
|
||||
|
||||
static inline void
|
||||
clear_segment_descriptor(segment_descriptor* desc)
|
||||
{
|
||||
*(uint64*)desc = 0;
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
set_segment_descriptor(segment_descriptor* desc, uint8 type, uint8 dpl)
|
||||
{
|
||||
clear_segment_descriptor(desc);
|
||||
|
||||
// In 64-bit mode the CPU ignores the base/limit of code/data segments,
|
||||
// it always treats base as 0 and does no limit checks.
|
||||
desc->base0 = 0;
|
||||
desc->base1 = 0;
|
||||
desc->limit0 = 0xffff;
|
||||
desc->limit1 = 0xf;
|
||||
desc->granularity = 1;
|
||||
|
||||
desc->type = type;
|
||||
desc->desc_type = DT_CODE_DATA_SEGMENT;
|
||||
desc->dpl = dpl;
|
||||
desc->present = 1;
|
||||
|
||||
desc->long_mode = (type & DT_CODE_EXECUTE_ONLY) ? 1 : 0;
|
||||
// Must be set to 1 for code segments only.
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
set_tss_descriptor(segment_descriptor* _desc, uint64 base, uint32 limit)
|
||||
{
|
||||
clear_segment_descriptor(_desc);
|
||||
clear_segment_descriptor(&_desc[1]);
|
||||
|
||||
// The TSS descriptor is a special format in 64-bit mode, it is 16 bytes
|
||||
// instead of 8.
|
||||
tss_descriptor* desc = (tss_descriptor*)_desc;
|
||||
|
||||
desc->base0 = base & 0xffffff;
|
||||
desc->base1 = (base >> 24) & 0xff;
|
||||
desc->base2 = (base >> 32);
|
||||
desc->limit0 = limit & 0xffff;
|
||||
desc->limit1 = (limit >> 16) & 0xf;
|
||||
|
||||
desc->present = 1;
|
||||
desc->type = DT_TSS;
|
||||
desc->desc_type = DT_SYSTEM_SEGMENT;
|
||||
desc->dpl = DPL_KERNEL;
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
set_interrupt_descriptor(interrupt_descriptor* desc, uint64 addr, uint32 type,
|
||||
uint16 seg, uint32 dpl, uint32 ist)
|
||||
{
|
||||
desc->base0 = addr & 0xffff;
|
||||
desc->base1 = (addr >> 16) & 0xffff;
|
||||
desc->base2 = (addr >> 32) & 0xffffffff;
|
||||
desc->sel = seg;
|
||||
desc->ist = ist;
|
||||
desc->type = type;
|
||||
desc->dpl = dpl;
|
||||
desc->present = 1;
|
||||
desc->unused1 = 0;
|
||||
desc->unused2 = 0;
|
||||
desc->reserved = 0;
|
||||
}
|
||||
|
||||
|
||||
#endif /* _ASSEMBLER */
|
||||
|
||||
#endif /* _KERNEL_ARCH_X86_64_DESCRIPTORS_H */
|
||||
Reference in New Issue
Block a user