Added some x86_64 system/kernel headers and kernel Jamfiles.

* Not all of these headers are correct yet, just adding what's necessary
  to get things to compile for the time being.
This commit is contained in:
Alex Smith 2012-06-13 17:45:22 +01:00
parent 0e88a887b4
commit f76bc433e1
21 changed files with 669 additions and 29 deletions

View File

@ -0,0 +1,71 @@
/*
* Copyright 2005-2012, Haiku Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _ARCH_X86_64_DEBUGGER_H
#define _ARCH_X86_64_DEBUGGER_H
typedef struct x86_64_fp_register {
uint8 value[10];
uint8 reserved[6];
} x86_64_fp_register;
typedef struct x86_64_xmm_register {
uint8 value[16];
} x86_64_xmm_register;
typedef struct x86_64_extended_registers {
uint16 control;
uint16 status;
uint8 tag;
uint8 reserved1;
uint16 opcode;
uint64 instruction_pointer;
uint64 data_pointer;
uint32 mxcsr;
uint32 mxcsr_mask;
union {
x86_64_fp_register fp_registers[8]; // st0-st7
x86_64_fp_register mmx_registers[8]; // mm0-mm7
};
x86_64_xmm_register xmm_registers[16]; // xmm0-xmm15
uint8 reserved4[96]; // 416 - 512
} x86_64_extended_registers;
struct x86_64_debug_cpu_state {
x86_64_extended_registers extended_registers;
uint64 gs;
uint64 fs;
uint64 es;
uint64 ds;
uint64 r15;
uint64 r14;
uint64 r13;
uint64 r12;
uint64 r11;
uint64 r10;
uint64 r9;
uint64 r8;
uint64 rbp;
uint64 rsi;
uint64 rdi;
uint64 rdx;
uint64 rcx;
uint64 rbx;
uint64 rax;
uint64 vector;
uint64 error_code;
uint64 rip;
uint64 cs;
uint64 rflags;
uint64 rsp;
uint64 ss;
} __attribute__((aligned(16)));
#endif // _ARCH_X86_64_DEBUGGER_H

View File

@ -13,13 +13,16 @@
// include architecture specific definitions
#include <arch/x86/arch_debugger.h>
#include <arch/x86_64/arch_debugger.h>
#include <arch/ppc/arch_debugger.h>
#include <arch/m68k/arch_debugger.h>
#include <arch/mipsel/arch_debugger.h>
#include <arch/arm/arch_debugger.h>
#ifdef __INTEL__
#ifdef __x86_64__
typedef struct x86_64_debug_cpu_state debug_cpu_state;
#elif __INTEL__
typedef struct x86_debug_cpu_state debug_cpu_state;
#elif __POWERPC__
typedef struct ppc_debug_cpu_state debug_cpu_state;

View File

@ -1,6 +1,6 @@
#ifndef _KERNEL_ARCH_x86_64_CPU_H
#define _KERNEL_ARCH_x86_64_CPU_H
#ifndef _KERNEL_ARCH_X86_64_CPU_H
#define _KERNEL_ARCH_X86_64_CPU_H
#include "../x86/arch_cpu.h"
#endif /* _KERNEL_ARCH_x86_64_CPU_H */
#endif /* _KERNEL_ARCH_X86_64_CPU_H */

View File

@ -0,0 +1,17 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* 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 */

View File

@ -1,6 +1,78 @@
#ifndef _KERNEL_ARCH_x86_64_INT_H
#define _KERNEL_ARCH_x86_64_INT_H
/*
* Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#ifndef _KERNEL_ARCH_X86_64_INT_H
#define _KERNEL_ARCH_X86_64_INT_H
#include "../x86/arch_int.h"
#endif /* _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 */

View File

@ -1,6 +1,6 @@
#ifndef _KERNEL_ARCH_x86_64_KERNEL_H
#define _KERNEL_ARCH_x86_64_KERNEL_H
#ifndef _KERNEL_ARCH_X86_64_KERNEL_H
#define _KERNEL_ARCH_X86_64_KERNEL_H
#include "../x86/arch_kernel.h"
#endif /* _KERNEL_ARCH_x86_64_KERNEL_H */
#endif /* _KERNEL_ARCH_X86_64_KERNEL_H */

View File

@ -1,6 +1,6 @@
#ifndef _KERNEL_ARCH_x86_64_KERNEL_ARGS_H
#define _KERNEL_ARCH_x86_64_KERNEL_ARGS_H
#ifndef _KERNEL_ARCH_X86_64_KERNEL_ARGS_H
#define _KERNEL_ARCH_X86_64_KERNEL_ARGS_H
#include "../x86/arch_kernel_args.h"
#endif /* _KERNEL_ARCH_x86_64_KERNEL_ARGS_H */
#endif /* _KERNEL_ARCH_X86_64_KERNEL_ARGS_H */

View File

@ -1,6 +1,26 @@
#ifndef _KERNEL_ARCH_x86_64_SYSTEM_INFO_H
#define _KERNEL_ARCH_x86_64_SYSTEM_INFO_H
/*
* Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* 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 "../x86/arch_system_info.h"
#endif /* _KERNEL_ARCH_x86_64_SYSTEM_INFO_H */
#include <OS.h>
#ifdef __cplusplus
extern "C" {
#endif
//status_t get_current_cpuid(cpuid_info *info, uint32 eax);
//uint32 get_eflags(void);
//void set_eflags(uint32 value);
//status_t _user_get_cpuid(cpuid_info *info, uint32 eax, uint32 cpu);
#ifdef __cplusplus
}
#endif
#endif /* _KRENEL_ARCH_X86_64_SYSTEM_INFO_H */

View File

@ -1,6 +1,32 @@
#ifndef _KERNEL_ARCH_x86_64_THREAD_H
#define _KERNEL_ARCH_x86_64_THREAD_H
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#ifndef _KERNEL_ARCH_X86_64_THREAD_H
#define _KERNEL_ARCH_X86_64_THREAD_H
#include "../x86/arch_thread.h"
#endif /* _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 */

View File

@ -1,6 +1,32 @@
#ifndef _KERNEL_ARCH_x86_64_THREAD_TYPES_H
#define _KERNEL_ARCH_x86_64_THREAD_TYPES_H
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* 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 "../x86/arch_thread_types.h"
#endif /* _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 */

View File

@ -1,6 +1,6 @@
#ifndef _KERNEL_ARCH_x86_64_USER_DEBUGGER_H
#define _KERNEL_ARCH_x86_64_USER_DEBUGGER_H
#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 */
#endif /* _KERNEL_ARCH_X86_64_USER_DEBUGGER_H */

View File

@ -0,0 +1,16 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Copyright 2004, Axel Dörfler, axeld@pinc-software.de. 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 */

View File

@ -0,0 +1,9 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* 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 */

View File

@ -0,0 +1,9 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* 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 */

View File

@ -0,0 +1,15 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#ifndef _SYSTEM_ARCH_x86_64_COMMPAGE_DEFS_H
#define _SYSTEM_ARCH_x86_64_COMMPAGE_DEFS_H
#ifndef _SYSTEM_COMMPAGE_DEFS_H
# error Must not be included directly. Include <commpage_defs.h> instead!
#endif
// FIXME: correct address
#define ARCH_USER_COMMPAGE_ADDR (0xffff0000)
#endif /* _SYSTEM_ARCH_x86_64_COMMPAGE_DEFS_H */

View File

@ -0,0 +1,17 @@
/*
* Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef _KERNEL_ARCH_REAL_TIME_DATA_H
#define _KERNEL_ARCH_REAL_TIME_DATA_H
#include <StorageDefs.h>
#include <SupportDefs.h>
struct arch_real_time_data {
bigtime_t system_time_offset;
uint32 system_time_conversion_factor;
};
#endif /* _KERNEL_ARCH_REAL_TIME_DATA_H */

View File

@ -0,0 +1,21 @@
SubDir HAIKU_TOP src system kernel arch x86_64 ;
SubDirHdrs [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR) system kernel ] ;
# for syscall_numbers.h
UsePrivateKernelHeaders ;
UsePrivateHeaders shared ;
KernelMergeObject kernel_arch_x86_64.o :
arch_cpu.cpp
:
$(TARGET_KERNEL_PIC_CCFLAGS)
;
CreateAsmStructOffsetsHeader asm_offsets.h : asm_offsets.cpp ;
# We need to specify the dependency on the generated syscalls file explicitly.
#Includes [ FGristFiles arch_x86.S arch_interrupts.S ]
# : <syscalls>syscall_numbers.h ;
#Includes [ FGristFiles arch_interrupts.S ]
# : <syscalls>syscall_table.h ;

View File

@ -0,0 +1,164 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk
* Distributed under the terms of the MIT License.
*/
#include <cpu.h>
#include <boot/kernel_args.h>
// #pragma mark -
status_t
arch_cpu_preboot_init_percpu(kernel_args *args, int cpu)
{
return B_OK;
}
status_t
arch_cpu_init_percpu(kernel_args *args, int cpu)
{
return B_OK;
}
status_t
arch_cpu_init(kernel_args *args)
{
return B_OK;
}
status_t
arch_cpu_init_post_vm(kernel_args *args)
{
return B_OK;
}
status_t
arch_cpu_init_post_modules(kernel_args *args)
{
return B_OK;
}
void
arch_cpu_global_TLB_invalidate(void)
{
}
void
arch_cpu_invalidate_TLB_range(addr_t start, addr_t end)
{
}
void
arch_cpu_invalidate_TLB_list(addr_t pages[], int num_pages)
{
}
ssize_t
arch_cpu_user_strlcpy(char *to, const char *from, size_t size,
addr_t *faultHandler)
{
int fromLength = 0;
addr_t oldFaultHandler = *faultHandler;
// this check is to trick the gcc4 compiler and have it keep the error label
if (to == NULL && size > 0)
goto error;
*faultHandler = (addr_t)&&error;
if (size > 0) {
to[--size] = '\0';
// copy
for ( ; size; size--, fromLength++, to++, from++) {
if ((*to = *from) == '\0')
break;
}
}
// count any leftover from chars
while (*from++ != '\0') {
fromLength++;
}
*faultHandler = oldFaultHandler;
return fromLength;
error:
*faultHandler = oldFaultHandler;
return B_BAD_ADDRESS;
}
status_t
arch_cpu_user_memset(void *s, char c, size_t count, addr_t *faultHandler)
{
char *xs = (char *)s;
addr_t oldFaultHandler = *faultHandler;
// this check is to trick the gcc4 compiler and have it keep the error label
if (s == NULL)
goto error;
*faultHandler = (addr_t)&&error;
while (count--)
*xs++ = c;
*faultHandler = oldFaultHandler;
return 0;
error:
*faultHandler = oldFaultHandler;
return B_BAD_ADDRESS;
}
status_t
arch_cpu_shutdown(bool rebootSystem)
{
return B_ERROR;
}
void
arch_cpu_idle(void)
{
asm("hlt");
}
void
arch_cpu_sync_icache(void *address, size_t length)
{
// instruction cache is always consistent on x86
}
void
arch_cpu_memory_read_barrier(void)
{
asm volatile ("lock;" : : : "memory");
asm volatile ("addl $0, 0(%%esp);" : : : "memory");
}
void
arch_cpu_memory_write_barrier(void)
{
asm volatile ("lock;" : : : "memory");
asm volatile ("addl $0, 0(%%esp);" : : : "memory");
}

View File

@ -0,0 +1,88 @@
/*
* Copyright 2007-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
// This file is used to get C structure offsets into assembly code.
// The build system assembles the file and processes the output to create
// a header file with macro definitions, that can be included from assembly
// code.
#include <computed_asm_macros.h>
//#include <arch_cpu.h>
//#include <cpu.h>
//#include <ksignal.h>
//#include <ksyscalls.h>
//#include <thread_types.h>
#define DEFINE_MACRO(macro, value) DEFINE_COMPUTED_ASM_MACRO(macro, value)
#define DEFINE_OFFSET_MACRO(prefix, structure, member) \
DEFINE_MACRO(prefix##_##member, offsetof(struct structure, member));
#define DEFINE_SIZEOF_MACRO(prefix, structure) \
DEFINE_MACRO(prefix##_sizeof, sizeof(struct structure));
void
dummy()
{
// struct cpu_ent
//DEFINE_OFFSET_MACRO(CPU_ENT, cpu_ent, fault_handler);
//DEFINE_OFFSET_MACRO(CPU_ENT, cpu_ent, fault_handler_stack_pointer);
// struct Thread
//DEFINE_OFFSET_MACRO(THREAD, Thread, time_lock);
//DEFINE_OFFSET_MACRO(THREAD, Thread, kernel_time);
//DEFINE_OFFSET_MACRO(THREAD, Thread, user_time);
//DEFINE_OFFSET_MACRO(THREAD, Thread, last_time);
//DEFINE_OFFSET_MACRO(THREAD, Thread, in_kernel);
//DEFINE_OFFSET_MACRO(THREAD, Thread, flags);
//DEFINE_OFFSET_MACRO(THREAD, Thread, kernel_stack_top);
//DEFINE_OFFSET_MACRO(THREAD, Thread, fault_handler);
// struct iframe
//DEFINE_SIZEOF_MACRO(IFRAME, iframe);
//DEFINE_OFFSET_MACRO(IFRAME, iframe, cs);
//DEFINE_OFFSET_MACRO(IFRAME, iframe, eax);
//DEFINE_OFFSET_MACRO(IFRAME, iframe, edx);
//DEFINE_OFFSET_MACRO(IFRAME, iframe, orig_eax);
//DEFINE_OFFSET_MACRO(IFRAME, iframe, vector);
//DEFINE_OFFSET_MACRO(IFRAME, iframe, eip);
//DEFINE_OFFSET_MACRO(IFRAME, iframe, flags);
//DEFINE_OFFSET_MACRO(IFRAME, iframe, user_esp);
// struct vm86_iframe
//DEFINE_SIZEOF_MACRO(VM86_IFRAME, vm86_iframe);
//DEFINE_OFFSET_MACRO(VM86_IFRAME, vm86_iframe, flags);
// struct syscall_info
//DEFINE_SIZEOF_MACRO(SYSCALL_INFO, syscall_info);
//DEFINE_OFFSET_MACRO(SYSCALL_INFO, syscall_info, function);
//DEFINE_OFFSET_MACRO(SYSCALL_INFO, syscall_info, parameter_size);
// struct x86_optimized_functions
//DEFINE_OFFSET_MACRO(X86_OPTIMIZED_FUNCTIONS, x86_optimized_functions,
// memcpy);
//DEFINE_OFFSET_MACRO(X86_OPTIMIZED_FUNCTIONS, x86_optimized_functions,
// memset);
// struct signal_frame_data
//DEFINE_SIZEOF_MACRO(SIGNAL_FRAME_DATA, signal_frame_data);
//DEFINE_OFFSET_MACRO(SIGNAL_FRAME_DATA, signal_frame_data, info);
//DEFINE_OFFSET_MACRO(SIGNAL_FRAME_DATA, signal_frame_data, context);
//DEFINE_OFFSET_MACRO(SIGNAL_FRAME_DATA, signal_frame_data, user_data);
//DEFINE_OFFSET_MACRO(SIGNAL_FRAME_DATA, signal_frame_data, handler);
// struct ucontext_t
//DEFINE_OFFSET_MACRO(UCONTEXT_T, __ucontext_t, uc_mcontext);
// struct vregs
//DEFINE_SIZEOF_MACRO(VREGS, vregs);
// struct siginfo_t
//DEFINE_OFFSET_MACRO(SIGINFO_T, __siginfo_t, si_signo);
}

View File

@ -0,0 +1,30 @@
SubDir HAIKU_TOP src system kernel lib arch x86_64 ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ;
local librootSources = [ FDirName $(HAIKU_TOP) src system libroot ] ;
local posixSources = [ FDirName $(librootSources) posix ] ;
SEARCH_SOURCE += [ FDirName $(librootSources) os arch $(TARGET_ARCH) ] ;
KernelMergeObject kernel_os_arch_$(TARGET_ARCH).o :
atomic.S
byteorder.S
system_time_asm.S
system_time.c
: $(TARGET_KERNEL_PIC_CCFLAGS)
;
SEARCH_SOURCE += [ FDirName $(posixSources) arch $(TARGET_ARCH) ] ;
KernelMergeObject kernel_lib_posix_arch_$(TARGET_ARCH).o :
siglongjmp.S
sigsetjmp.S
kernel_longjmp_return.c
kernel_setjmp_save_sigs.c
arch_string.cpp
: $(TARGET_KERNEL_PIC_CCFLAGS)
;

View File

@ -0,0 +1,36 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
// TODO: Replace these with optimized implementations.
#include <string.h>
void *
memcpy(void *dest, const void *src, size_t count)
{
const unsigned char *s = src;
unsigned char *d = dest;
for (; count != 0; count--) {
*d++ = *s++;
}
return dest;
}
void *
memset(void *dest, int val, size_t count)
{
unsigned char *d = dest;
for (; count != 0; count--) {
*d++ = static_cast<unsigned char>(val);
}
return dest;
}