Removed the x86_64 headers/source directories, now all merged with x86.

This commit is contained in:
Alex Smith 2012-07-03 11:17:56 +01:00
parent 4f419b518f
commit c005e747ef
30 changed files with 3 additions and 1889 deletions

View File

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

View File

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

View File

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

View File

@ -1,28 +0,0 @@
/*
* 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 <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 */

View File

@ -1,32 +0,0 @@
/*
* 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 <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,32 +0,0 @@
/*
* 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 <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 +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 */

View File

@ -1,16 +0,0 @@
/*
* 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

@ -1,9 +0,0 @@
/*
* 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

@ -1,9 +0,0 @@
/*
* 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

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

View File

@ -6,7 +6,9 @@
#include <asm_defs.h>
#include <arch/x86_64/descriptors.h>
#define __x86_64__
#include <arch/x86/descriptors.h>
#undef __x86_64__
.code32

View File

@ -1,36 +0,0 @@
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_commpage.cpp
arch_cpu.cpp
arch_debug.cpp
arch_debug_console.cpp
arch_elf.cpp
arch_int.cpp
arch_interrupts.S
arch_platform.cpp
arch_real_time_clock.cpp
arch_smp.cpp
arch_system_info.cpp
arch_thread.cpp
arch_timer.cpp
arch_user_debugger.cpp
arch_vm.cpp
arch_vm_translation_map.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

@ -1,21 +0,0 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#include <commpage.h>
status_t
arch_commpage_init(void)
{
return B_OK;
}
status_t
arch_commpage_init_post_cpus(void)
{
return B_OK;
}

View File

@ -1,199 +0,0 @@
/*
* Copyright 2002-2010, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
* Distributed under the terms of the NewOS License.
*/
#include <cpu.h>
#include <boot/kernel_args.h>
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_user_TLB_invalidate(void)
{
}
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_memcpy(void* to, const void* from, size_t size,
addr_t* faultHandler)
{
char* d = (char*)to;
const char* s = (const char*)from;
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;
for (; size != 0; size--) {
*d++ = *s++;
}
*faultHandler = oldFaultHandler;
return 0;
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("lfence" : : : "memory");
}
void
arch_cpu_memory_write_barrier(void)
{
asm volatile("sfence" : : : "memory");
}

View File

@ -1,102 +0,0 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#include <debug.h>
#include <arch/debug.h>
void
arch_debug_save_registers(struct arch_debug_registers* registers)
{
}
void
arch_debug_stack_trace(void)
{
}
bool
arch_debug_contains_call(Thread *thread, const char *symbol,
addr_t start, addr_t end)
{
return false;
}
void *
arch_debug_get_caller(void)
{
return NULL;
}
int32
arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount,
int32 skipIframes, int32 skipFrames, uint32 flags)
{
return 0;
}
void*
arch_debug_get_interrupt_pc(bool* _isSyscall)
{
return NULL;
}
void
arch_debug_unset_current_thread(void)
{
}
bool
arch_is_debug_variable_defined(const char* variableName)
{
return false;
}
status_t
arch_set_debug_variable(const char* variableName, uint64 value)
{
return B_OK;
}
status_t
arch_get_debug_variable(const char* variableName, uint64* value)
{
return B_OK;
}
ssize_t
arch_debug_gdb_get_registers(char* buffer, size_t bufferSize)
{
return B_ERROR;
}
status_t
arch_debug_init(kernel_args *args)
{
return B_OK;
}
void
arch_debug_call_with_fault_handler(cpu_ent* cpu, jmp_buf jumpBuffer,
void (*function)(void*), void* parameter)
{
// To be implemented in asm, not here.
}

View File

@ -1,218 +0,0 @@
/*
* Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de
* Copyright 2001, Rob Judd <judd@ob-wan.com>
* Copyright 2002, Marcus Overhagen <marcus@overhagen.de>
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*
* Copyright 2001, Travis Geiselbrecht. All rights reserved.
* Distributed under the terms of the NewOS License.
*/
#include <KernelExport.h>
#include <driver_settings.h>
#include <int.h>
#include <arch/cpu.h>
#include <arch/debug_console.h>
#include <boot/stage2.h>
#include <debug.h>
#include <string.h>
#include <stdlib.h>
enum serial_register_offsets {
SERIAL_TRANSMIT_BUFFER = 0,
SERIAL_RECEIVE_BUFFER = 0,
SERIAL_DIVISOR_LATCH_LOW = 0,
SERIAL_DIVISOR_LATCH_HIGH = 1,
SERIAL_FIFO_CONTROL = 2,
SERIAL_LINE_CONTROL = 3,
SERIAL_MODEM_CONTROL = 4,
SERIAL_LINE_STATUS = 5,
SERIAL_MODEM_STATUS = 6,
};
static const uint32 kSerialBaudRate = 115200;
static uint16 sSerialBasePort = 0x3f8;
// COM1 is the default debug output port
static spinlock sSerialOutputSpinlock = B_SPINLOCK_INITIALIZER;
static void
init_serial_port(uint16 basePort, uint32 baudRate)
{
sSerialBasePort = basePort;
uint16 divisor = (uint16)(115200 / baudRate);
out8(0x80, sSerialBasePort + SERIAL_LINE_CONTROL); /* set divisor latch access bit */
out8(divisor & 0xf, sSerialBasePort + SERIAL_DIVISOR_LATCH_LOW);
out8(divisor >> 8, sSerialBasePort + SERIAL_DIVISOR_LATCH_HIGH);
out8(3, sSerialBasePort + SERIAL_LINE_CONTROL); /* 8N1 */
}
static void
put_char(const char c)
{
// wait until the transmitter empty bit is set
while ((in8(sSerialBasePort + SERIAL_LINE_STATUS) & 0x20) == 0)
asm volatile ("pause;");
out8(c, sSerialBasePort + SERIAL_TRANSMIT_BUFFER);
}
// #pragma mark -
void
arch_debug_remove_interrupt_handler(uint32 line)
{
}
void
arch_debug_install_interrupt_handlers(void)
{
}
int
arch_debug_blue_screen_try_getchar(void)
{
return -1;
}
char
arch_debug_blue_screen_getchar(void)
{
while(true)
PAUSE();
return 0;
}
int
arch_debug_serial_try_getchar(void)
{
uint8 lineStatus = in8(sSerialBasePort + SERIAL_LINE_STATUS);
if (lineStatus == 0xff) {
// The "data available" bit is set, but also all error bits. Likely we
// don't have a valid I/O port.
return -1;
}
if ((lineStatus & 0x1) == 0)
return -1;
return in8(sSerialBasePort + SERIAL_RECEIVE_BUFFER);
}
char
arch_debug_serial_getchar(void)
{
while (true) {
uint8 lineStatus = in8(sSerialBasePort + SERIAL_LINE_STATUS);
if (lineStatus == 0xff) {
// The "data available" bit is set, but also all error bits. Likely
// we don't have a valid I/O port.
return 0;
}
if ((lineStatus & 0x1) != 0)
break;
PAUSE();
}
return in8(sSerialBasePort + SERIAL_RECEIVE_BUFFER);
}
static void
_arch_debug_serial_putchar(const char c)
{
if (c == '\n') {
put_char('\r');
put_char('\n');
} else if (c != '\r')
put_char(c);
}
void
arch_debug_serial_putchar(const char c)
{
cpu_status state = 0;
if (!debug_debugger_running()) {
state = disable_interrupts();
acquire_spinlock(&sSerialOutputSpinlock);
}
_arch_debug_serial_putchar(c);
if (!debug_debugger_running()) {
release_spinlock(&sSerialOutputSpinlock);
restore_interrupts(state);
}
}
void
arch_debug_serial_puts(const char *s)
{
cpu_status state = 0;
if (!debug_debugger_running()) {
state = disable_interrupts();
acquire_spinlock(&sSerialOutputSpinlock);
}
while (*s != '\0') {
_arch_debug_serial_putchar(*s);
s++;
}
if (!debug_debugger_running()) {
release_spinlock(&sSerialOutputSpinlock);
restore_interrupts(state);
}
}
void
arch_debug_serial_early_boot_message(const char *string)
{
// this function will only be called in fatal situations
// ToDo: also enable output via text console?!
arch_debug_console_init(NULL);
arch_debug_serial_puts(string);
}
status_t
arch_debug_console_init(kernel_args *args)
{
// only use the port if we could find one, else use the standard port
if (args != NULL && args->platform_args.serial_base_ports[0] != 0)
sSerialBasePort = args->platform_args.serial_base_ports[0];
init_serial_port(sSerialBasePort, kSerialBaudRate);
return B_OK;
}
status_t
arch_debug_console_init_settings(kernel_args *args)
{
return B_OK;
}

View File

@ -1,173 +0,0 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#ifdef _BOOT_MODE
# include <boot/arch.h>
#endif
#include <KernelExport.h>
#include <elf.h>
#include <elf_priv.h>
#include <arch/elf.h>
#ifndef _BOOT_MODE
// Currently got generic elf.cpp #ifdef'd out for x86_64, define stub versions here.
status_t
elf_load_user_image(const char *path, Team *team, int flags, addr_t *_entry)
{
return B_ERROR;
}
image_id
load_kernel_add_on(const char *path)
{
return 0;
}
status_t
unload_kernel_add_on(image_id id)
{
return B_ERROR;
}
status_t
elf_debug_lookup_symbol_address(addr_t address, addr_t *_baseAddress,
const char **_symbolName, const char **_imageName, bool *_exactMatch)
{
return B_ERROR;
}
addr_t
elf_debug_lookup_symbol(const char* searchName)
{
return 0;
}
struct elf_image_info *
elf_get_kernel_image()
{
return NULL;
}
image_id
elf_create_memory_image(const char* imageName, addr_t text, size_t textSize,
addr_t data, size_t dataSize)
{
return B_ERROR;
}
status_t
elf_add_memory_image_symbol(image_id id, const char* name, addr_t address,
size_t size, int32 type)
{
return B_ERROR;
}
status_t
elf_init(struct kernel_args *args)
{
return B_OK;
}
status_t
get_image_symbol(image_id image, const char *name, int32 symbolType,
void **_symbolLocation)
{
return B_OK;
}
status_t
_user_read_kernel_image_symbols(image_id id, struct Elf32_Sym* symbolTable,
int32* _symbolCount, char* stringTable, size_t* _stringTableSize,
addr_t* _imageDelta)
{
return B_ERROR;
}
#endif
#ifdef _BOOT_MODE
status_t
boot_arch_elf_relocate_rel(preloaded_elf64_image* image, Elf64_Rel* rel,
int relLength)
//#else
//int
//arch_elf_relocate_rel(struct elf_image_info *image,
// struct elf_image_info *resolveImage, struct Elf32_Rel *rel, int relLength)
//#endif
{
dprintf("arch_elf_relocate_rel: not supported on x86_64\n");
return B_ERROR;
}
//#ifdef _BOOT_MODE
status_t
boot_arch_elf_relocate_rela(preloaded_elf64_image* image, Elf64_Rela* rel,
int relLength)
//#else
//int
//arch_elf_relocate_rela(struct elf_image_info *image,
// struct elf_image_info *resolveImage, struct Elf32_Rela *rel, int relLength)
//#endif
{
for (int i = 0; i < relLength / (int)sizeof(Elf64_Rela); i++) {
int type = ELF64_R_TYPE(rel[i].r_info);
int symIndex = ELF64_R_SYM(rel[i].r_info);
Elf64_Addr symAddr = 0;
// Resolve the symbol, if any.
if (symIndex != 0) {
Elf64_Sym* symbol = SYMBOL(image, symIndex);
status_t status;
//#ifdef _BOOT_MODE
status = boot_elf_resolve_symbol(image, symbol, &symAddr);
//#else
// status = elf_resolve_symbol(image, symbol, resolveImage, &S);
//#endif
if (status < B_OK)
return status;
}
// Address of the relocation.
Elf64_Addr relocAddr = image->text_region.delta + rel[i].r_offset;
// Calculate the relocation value.
Elf64_Addr relocValue;
switch(type) {
case R_X86_64_NONE:
continue;
case R_X86_64_64:
relocValue = symAddr + rel[i].r_addend;
break;
case R_X86_64_PC32:
relocValue = symAddr + rel[i].r_addend - rel[i].r_offset;
break;
case R_X86_64_GLOB_DAT:
case R_X86_64_JUMP_SLOT:
relocValue = symAddr + rel[i].r_addend;
break;
case R_X86_64_RELATIVE:
relocValue = image->text_region.delta + rel[i].r_addend;
break;
default:
dprintf("arch_elf_relocate_rel: unhandled relocation type %d\n",
type);
return B_BAD_DATA;
}
#ifdef _BOOT_MODE
boot_elf64_set_relocation(relocAddr, relocValue);
#else
*(Elf64_Addr *)relocAddr = relocValue;
#endif
}
return B_OK;
}
#endif

View File

@ -1,35 +0,0 @@
/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
* Axel Dörfler, axeld@pinc-software.de
*/
#include <arch/platform.h>
//#include <apm.h>
status_t
arch_platform_init(struct kernel_args *args)
{
return B_OK;
}
status_t
arch_platform_init_post_vm(struct kernel_args *args)
{
return B_OK;
}
status_t
arch_platform_init_post_thread(struct kernel_args *args)
{
//apm_init(args);
return B_OK;
}

View File

@ -1,45 +0,0 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#include <arch/real_time_clock.h>
#include <real_time_clock.h>
#include <real_time_data.h>
status_t
arch_rtc_init(struct kernel_args *args, struct real_time_data *data)
{
return B_OK;
}
uint32
arch_rtc_get_hw_time(void)
{
return 0;
}
void
arch_rtc_set_hw_time(uint32 seconds)
{
}
void
arch_rtc_set_system_time_offset(struct real_time_data *data, bigtime_t offset)
{
}
bigtime_t
arch_rtc_get_system_time_offset(struct real_time_data *data)
{
return 0;
}

View File

@ -1,37 +0,0 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#include <smp.h>
#include <arch/smp.h>
status_t
arch_smp_init(kernel_args *args)
{
return B_OK;
}
status_t
arch_smp_per_cpu_init(kernel_args *args, int32 cpu)
{
return B_OK;
}
void
arch_smp_send_broadcast_ici(void)
{
}
void
arch_smp_send_ici(int32 target_cpu)
{
}

View File

@ -1,21 +0,0 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#include <arch/system_info.h>
status_t
arch_get_system_info(system_info *info, size_t size)
{
return B_OK;
}
status_t
arch_system_info_init(struct kernel_args *args)
{
return B_OK;
}

View File

@ -1,104 +0,0 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#include <arch/thread.h>
#include <team.h>
#include <thread.h>
status_t
arch_thread_init(struct kernel_args *args)
{
return B_OK;
}
status_t
arch_team_init_team_struct(Team *p, bool kernel)
{
return B_ERROR;
}
status_t
arch_thread_init_thread_struct(Thread *thread)
{
return B_ERROR;
}
void
arch_thread_init_kthread_stack(Thread* thread, void* _stack, void* _stackTop,
void (*function)(void*), const void* data)
{
}
status_t
arch_thread_init_tls(Thread *thread)
{
return B_ERROR;
}
void
arch_thread_context_switch(Thread *from, Thread *to)
{
}
void
arch_thread_dump_info(void *info)
{
}
status_t
arch_thread_enter_userspace(Thread* thread, addr_t entry, void* args1,
void* args2)
{
return B_ERROR;
}
bool
arch_on_signal_stack(Thread *thread)
{
return false;
}
status_t
arch_setup_signal_frame(Thread* thread, struct sigaction* action,
struct signal_frame_data* signalFrameData)
{
return B_ERROR;
}
int64
arch_restore_signal_frame(struct signal_frame_data* signalFrameData)
{
return 0;
}
void
arch_store_fork_frame(struct arch_fork_arg *arg)
{
}
void
arch_restore_fork_frame(struct arch_fork_arg* arg)
{
}

View File

@ -1,30 +0,0 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#include <timer.h>
#include <arch/timer.h>
void
arch_timer_set_hardware_timer(bigtime_t timeout)
{
}
void
arch_timer_clear_hardware_timer(void)
{
}
int
arch_init_timer(kernel_args *args)
{
return 0;
}

View File

@ -1,106 +0,0 @@
/*
* Copyright 2005-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#include <arch/user_debugger.h>
#include <debugger.h>
// The software breakpoint instruction (int3).
const uint8 kX86SoftwareBreakpoint[1] = { 0xcc };
void
arch_clear_team_debug_info(struct arch_team_debug_info *info)
{
}
void
arch_destroy_team_debug_info(struct arch_team_debug_info *info)
{
}
void
arch_clear_thread_debug_info(struct arch_thread_debug_info *info)
{
}
void
arch_destroy_thread_debug_info(struct arch_thread_debug_info *info)
{
}
void
arch_update_thread_single_step()
{
}
void
arch_set_debug_cpu_state(const debug_cpu_state *cpuState)
{
}
void
arch_get_debug_cpu_state(debug_cpu_state *cpuState)
{
}
status_t
arch_set_breakpoint(void *address)
{
return B_OK;
}
status_t
arch_clear_breakpoint(void *address)
{
return B_OK;
}
status_t
arch_set_watchpoint(void *address, uint32 type, int32 length)
{
return B_OK;
}
status_t
arch_clear_watchpoint(void *address)
{
return B_OK;
}
bool
arch_has_breakpoints(struct arch_team_debug_info *info)
{
return false;
}
void
x86_init_user_debug()
{
}

View File

@ -1,66 +0,0 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#include <vm/vm.h>
#include <arch/vm.h>
status_t
arch_vm_init(kernel_args *args)
{
return B_OK;
}
status_t
arch_vm_init_post_area(kernel_args *args)
{
return B_OK;
}
status_t
arch_vm_init_end(kernel_args *args)
{
return B_OK;
}
status_t
arch_vm_init_post_modules(kernel_args *args)
{
return B_OK;
}
void
arch_vm_aspace_swap(struct VMAddressSpace *from, struct VMAddressSpace *to)
{
}
bool
arch_vm_supports_protection(uint32 protection)
{
return true;
}
void
arch_vm_unset_memory_type(struct VMArea *area)
{
}
status_t
arch_vm_set_memory_type(struct VMArea *area, phys_addr_t physicalBase,
uint32 type)
{
return B_OK;
}

View File

@ -1,52 +0,0 @@
/*
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
* Distributed under the terms of the MIT License.
*/
#include <arch/vm_translation_map.h>
status_t
arch_vm_translation_map_create_map(bool kernel, VMTranslationMap** _map)
{
return B_ERROR;
}
status_t
arch_vm_translation_map_init(kernel_args *args,
VMPhysicalPageMapper** _physicalPageMapper)
{
return B_OK;
}
status_t
arch_vm_translation_map_init_post_sem(kernel_args *args)
{
return B_OK;
}
status_t
arch_vm_translation_map_init_post_area(kernel_args *args)
{
return B_OK;
}
status_t
arch_vm_translation_map_early_map(kernel_args *args, addr_t va, phys_addr_t pa,
uint8 attributes, phys_addr_t (*get_free_page)(kernel_args *))
{
return B_ERROR;
}
bool
arch_vm_translation_map_is_kernel_page_accessible(addr_t virtualAddress,
uint32 protection)
{
return true;
}

View File

@ -1,77 +0,0 @@
/*
* 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, vector);
// 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);
}