Ticket #6310: x86_64.kernel_void_functions.patch

File x86_64.kernel_void_functions.patch, 71.5 KB (added by nmentley, 14 years ago)

adds blank functions for x86_64 kernel to allow compilation.

  • src/system/kernel/platform/bios_x86_64/platform.cpp

     
     1/*
     2    Just a dummy. No BIOS services are required in the kernel.
     3*/
  • src/system/kernel/platform/bios_x86_64/Jamfile

     
     1SubDir HAIKU_TOP src system kernel platform bios_x86_64 ;
     2
     3SubDirCcFlags $(TARGET_KERNEL_PIC_CCFLAGS) ;
     4SubDirC++Flags $(TARGET_KERNEL_PIC_CCFLAGS) ;
     5
     6KernelMergeObject kernel_platform_bios_x86_64.o :
     7    platform.cpp
     8;
  • src/system/kernel/device_manager/IOCache.cpp

     
    242242        off_t lineOffset = (offset >> fLineSizeShift) << fLineSizeShift;
    243243
    244244        // intersection of request and cache line
    245         off_t cacheLineEnd = std::min(lineOffset + fLineSize, fDeviceCapacity);
     245//      off_t cacheLineEnd = std::min(lineOffset + fLineSize, fDeviceCapacity);
     246        off_t cacheLineEnd;
     247        if((lineOffset + fLineSize) < fDeviceCapacity)
     248            cacheLineEnd = (lineOffset + fLineSize);
     249        else
     250            cacheLineEnd = fDeviceCapacity;
     251
    246252        size_t requestLineLength
    247253            = std::min(cacheLineEnd - offset, (off_t)length);
    248254
  • src/system/kernel/lib/arch/x86_64/arch_string.S

     
     1/*
     2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
     6 * Distributed under the terms of the NewOS License.
     7*/
     8
     9#if !_BOOT_MODE
     10#   include "asm_offsets.h"
     11#endif
     12
     13#include <asm_defs.h>
     14
     15
     16// We don't need the indirection in the boot loader.
     17#if _BOOT_MODE
     18#   define memcpy_generic   memcpy
     19#   define memset_generic   memset
     20#endif
     21
     22
     23.align 4
     24FUNCTION(memcpy_generic):
     25//  pushl   %esi
     26//  pushl   %edi
     27//  movl    12(%esp),%edi   /* dest */
     28//  movl    %edi,%eax   /* save dest ptr as return address */
     29//  movl    16(%esp),%esi   /* source */
     30//  movl    20(%esp),%ecx   /* count */
     31
     32    /* move by words */
     33    // TODO: The addresses might not be aligned!
     34//  cld
     35//  shrl    $2,%ecx
     36//  rep
     37//  movsl
     38
     39    /* move any remaining data by bytes */
     40//  movl    20(%esp),%ecx
     41//  andl    $3,%ecx
     42//  rep
     43//  movsb
     44
     45//  popl    %edi
     46//  popl    %esi
     47    ret
     48FUNCTION_END(memcpy_generic)
     49SYMBOL(memcpy_generic_end):
     50
     51
     52/* void *memset(void *dest, int value, size_t length); */
     53.align 4
     54FUNCTION(memset_generic):
     55//  push    %ebp
     56//  mov     %esp, %ebp
     57
     58    // %eax, %ecx, and %edx are scratch registers -- we only have to save %edi
     59//  push    %edi
     60
     61    // get the parameters
     62//  mov     16(%ebp), %ecx
     63//  mov     12(%ebp), %eax
     64//  mov     8(%ebp), %edi
     65
     66    // When touching less than 12 bytes, we just do it bytewise. We might be
     67    // able to process one or two lwords lwordwise, but the additional overhead
     68    // isn't worth it.
     69//  cmp     $12, %ecx
     70//  jl      2f
     71
     72    // buffer address lword-aligned?
     73//  mov     %edi, %edx
     74//  and     $0x3, %edx
     75//  jz      1f
     76
     77    // the buffer is unaligned -- copy the first bytes bytewise
     78//  mov     $4, %ecx
     79//  sub     %edx, %ecx
     80//  rep     stosb
     81
     82//  mov     16(%ebp), %ecx
     83//  sub     $4, %ecx
     84//  add     %edx, %ecx
     85
     861:  // lwordwise
     87    // prepare %eax -- the low byte must be copied to the other bytes
     88//  mov     %al, %ah
     89//  mov     %eax, %edx
     90//  shl     $16, %eax
     91//  mov     %dx, %ax
     92
     93    // get the unaligned remainder into %edx
     94//  mov     %ecx, %edx
     95//  and     $0x3, %edx
     96
     97    // write words
     98//  shr     $2, %ecx
     99//  rep     stosl
     100
     101//  mov     %edx, %ecx
     102
     1032:  // bytewise (remaining bytes)
     104//  rep     stosb
     105
     106//  pop     %edi
     107
     108    // return value is the value passed in
     109//  mov     8(%ebp), %eax
     110
     111//  mov     %ebp, %esp
     112//  pop     %ebp
     113    ret
     114FUNCTION_END(memset_generic)
     115SYMBOL(memset_generic_end):
     116
     117
     118#if !_BOOT_MODE
     119
     120.align 4
     121FUNCTION(memcpy):
     122//  jmp     *(gOptimizedFunctions + X86_OPTIMIZED_FUNCTIONS_memcpy)
     123FUNCTION_END(memcpy)
     124
     125FUNCTION(memset):
     126//  jmp     *(gOptimizedFunctions + X86_OPTIMIZED_FUNCTIONS_memset)
     127FUNCTION_END(memset)
     128
     129#endif  // !_BOOT_MODE
  • src/system/kernel/lib/arch/x86_64/Jamfile

     
     1SubDir HAIKU_TOP src system kernel lib arch x86_64 ;
     2
     3# find the generated asm_offsets.h
     4SubDirHdrs [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR) system kernel arch
     5    $(TARGET_ARCH) ] ;
     6
     7SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ;
     8
     9local librootSources = [ FDirName $(HAIKU_TOP) src system libroot ] ;
     10local posixSources = [ FDirName $(librootSources) posix ] ;
     11
     12SEARCH_SOURCE += [ FDirName $(librootSources) os arch $(TARGET_ARCH) ] ;
     13
     14KernelMergeObject kernel_os_arch_$(TARGET_ARCH).o :
     15    atomic.S
     16    byteorder.S
     17    system_time_asm.S
     18    system_time.c
     19
     20    : $(TARGET_KERNEL_PIC_CCFLAGS)
     21;
     22
     23SEARCH_SOURCE += [ FDirName $(posixSources) arch $(TARGET_ARCH) ] ;
     24SEARCH_SOURCE += [ FDirName $(posixSources) string arch generic ] ;
     25
     26KernelMergeObject kernel_lib_posix_arch_$(TARGET_ARCH).o :
     27    siglongjmp.S
     28    sigsetjmp.S
     29    kernel_longjmp_return.c
     30    kernel_setjmp_save_sigs.c
     31
     32    arch_string.S
     33
     34    : $(TARGET_KERNEL_PIC_CCFLAGS)
     35;
     36
     37# Explicitly tell the build system that arch_string.S includes the generated
     38# asm_offsets.h.
     39Includes [ FGristFiles arch_string.S ]
     40    : <src!system!kernel!arch!x86_64>asm_offsets.h ;
  • src/system/kernel/arch/x86/arch_elf.cpp

     
    179179    return B_ERROR;
    180180}
    181181
     182
     183
     184/*  ELF64 support. only needed in bootmode. */
     185#ifdef _BOOT_MODE
     186status_t
     187boot_arch_elf64_relocate_rel(struct preloaded_image *image, struct Elf64_Rel *rel, int relLength)
     188{
     189    addr_t S;
     190    addr_t A;
     191    addr_t P;
     192    addr_t finalAddress;
     193    addr_t *resolveAddress;
     194    int i;
     195
     196    S = A = P = 0;
     197
     198    for (i = 0; i * (int)sizeof(struct Elf64_Rel) < relLength; i++) {
     199        TRACE(("looking at rel type %s, offset 0x%lx\n",
     200            kRelocations[ELF32_R_TYPE(rel[i].r_info)], rel[i].r_offset));
     201
     202        // calc S
     203        switch (ELF64_R_TYPE(rel[i].r_info)) {
     204            case R_X86_64_64:
     205            case R_X86_64_PC32:
     206            case R_X86_64_GLOB_DAT:
     207            case R_X86_64_JMP_SLOT:
     208            case R_X86_64_GOTOFF:
     209            {
     210                struct Elf64_Sym *symbol;
     211                status_t status;
     212
     213                symbol = SYMBOL64(image, ELF64_R_SYM(rel[i].r_info));
     214
     215                status = boot_elf64_resolve_symbol(image, symbol, &S);
     216
     217                if (status < B_OK)
     218                    return status;
     219                TRACE(("S %p (%s)\n", (void *)S, SYMNAME(image, symbol)));
     220            }
     221        }
     222        // calc A
     223        switch (ELF64_R_TYPE(rel[i].r_info)) {
     224            case R_X86_64_64:
     225            case R_X86_64_PC32:
     226            case R_X86_64_GOT32:
     227            case R_X86_64_PLT32:
     228            case R_X86_64_RELATIVE:
     229            case R_X86_64_GOTOFF:
     230                A = *(addr_t *)(image->text_region.delta + rel[i].r_offset);
     231                TRACE(("A %p\n", (void *)A));
     232                break;
     233        }
     234        // calc P
     235        switch (ELF64_R_TYPE(rel[i].r_info)) {
     236            case R_X86_64_PC32:
     237            case R_X86_64_GOT32:
     238            case R_X86_64_PLT32:
     239                P = image->text_region.delta + rel[i].r_offset;
     240                TRACE(("P %p\n", (void *)P));
     241                break;
     242        }
     243
     244        switch (ELF64_R_TYPE(rel[i].r_info)) {
     245            case R_X86_64_NONE:
     246                continue;
     247            case R_X86_64_64:
     248                finalAddress = S + A;
     249                break;
     250            case R_X86_64_PC32:
     251                finalAddress = S + A - P;
     252                break;
     253            case R_X86_64_RELATIVE:
     254                // B + A;
     255                finalAddress = image->text_region.delta + A;
     256                break;
     257            case R_X86_64_JMP_SLOT:
     258            case R_X86_64_GLOB_DAT:
     259                finalAddress = S;
     260                break;
     261
     262            default:
     263                dprintf("arch_elf_relocate_rel: unhandled relocation type %d\n",
     264                    ELF64_R_TYPE(rel[i].r_info));
     265                return B_BAD_DATA;
     266        }
     267
     268        resolveAddress = (addr_t *)(image->text_region.delta + rel[i].r_offset);
     269        *resolveAddress = finalAddress;
     270        TRACE(("-> offset %#lx = %#lx\n",
     271            (image->text_region.delta + rel[i].r_offset), finalAddress));
     272    }
     273
     274    return B_NO_ERROR;
     275}
     276
     277status_t
     278boot_arch_elf64_relocate_rela(struct preloaded_image *image,
     279    struct Elf64_Rela *rel, int relLength)
     280{
     281    dprintf("arch_elf_relocate_rela: not supported on x86\n");
     282    return B_ERROR;
     283}
     284#endif
  • src/system/kernel/arch/x86_64/arch_elf.cpp

     
     1/*
     2 * Copyright 2009, Johannes Wischert, johanneswi@gmail.com.
     3 * All rights reserved. Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
     6 * All rights reserved. Distributed under the terms of the MIT License.
     7 *
     8 * Copyright 2002, Travis Geiselbrecht. All rights reserved.
     9 * Distributed under the terms of the NewOS License.
     10 */
     11
     12#ifdef _BOOT_MODE
     13#include <boot/arch.h>
     14#endif
     15
     16#include <KernelExport.h>
     17
     18#include <elf_priv.h>
     19#include <arch/elf.h>
     20
     21
     22#define TRACE_ARCH_ELF
     23#ifdef TRACE_ARCH_ELF
     24#   define TRACE(x) dprintf x
     25#   define CHATTY 1
     26#else
     27#   define TRACE(x) ;
     28#   define CHATTY 0
     29#endif
     30
     31#ifdef _BOOT_MODE
     32status_t
     33boot_arch_elf_relocate_rel(struct preloaded_image *image,
     34    struct Elf32_Rel *rel, int rel_len)
     35#else
     36int
     37arch_elf_relocate_rel(struct elf_image_info *image,
     38    struct elf_image_info *resolve_image, struct Elf32_Rel *rel, int rel_len)
     39#endif
     40{
     41    return B_NO_ERROR;
     42}
     43
     44
     45static inline void
     46write_32(addr_t P, Elf32_Word value)
     47{
     48}
     49
     50
     51static inline void
     52write_16(addr_t P, Elf32_Word value)
     53{
     54}
     55
     56
     57static inline bool
     58write_16_check(addr_t P, Elf32_Word value)
     59{
     60    return true;
     61}
     62
     63
     64static inline bool
     65write_8(addr_t P, Elf32_Word value)
     66{
     67    return true;
     68}
     69
     70
     71static inline bool
     72write_8_check(addr_t P, Elf32_Word value)
     73{
     74    return true;
     75}
     76
     77
     78#ifdef _BOOT_MODE
     79status_t
     80boot_arch_elf_relocate_rela(struct preloaded_image *image,
     81    struct Elf32_Rela *rel, int rel_len)
     82#else
     83int
     84arch_elf_relocate_rela(struct elf_image_info *image,
     85    struct elf_image_info *resolve_image, struct Elf32_Rela *rel, int rel_len)
     86#endif
     87{
     88    return B_OK;
     89}
     90
  • src/system/kernel/arch/x86_64/arch_thread.cpp

     
     1/*
     2 * Copyright 2003-2010, Haiku Inc. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Axel Dörfler <axeld@pinc-software.de>
     7 *      Ingo Weinhold <bonefish@cs.tu-berlin.de>
     8 *      François Revol <revol@free.fr>
     9 *
     10 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
     11 * Distributed under the terms of the NewOS License.
     12 */
     13
     14#include <arch/thread.h>
     15
     16#include <string.h>
     17
     18#include <arch/user_debugger.h>
     19#include <arch_cpu.h>
     20#include <cpu.h>
     21#include <debug.h>
     22#include <kernel.h>
     23#include <ksignal.h>
     24#include <int.h>
     25#include <team.h>
     26#include <thread.h>
     27#include <tls.h>
     28#include <tracing.h>
     29#include <vm/vm_types.h>
     30#include <vm/VMAddressSpace.h>
     31
     32// static struct arch_thread sInitialState;
     33
     34struct thread *gCurrentThread;
     35
     36
     37status_t
     38arch_thread_init(struct kernel_args *args)
     39{
     40    // Initialize the static initial arch_thread state (sInitialState).
     41    // Currently nothing to do, i.e. zero initialized is just fine.
     42
     43    return B_OK;
     44}
     45
     46
     47status_t
     48arch_team_init_team_struct(struct team *team, bool kernel)
     49{
     50    // Nothing to do. The structure is empty.
     51    return B_OK;
     52}
     53
     54
     55status_t
     56arch_thread_init_thread_struct(struct thread *thread)
     57{
     58
     59    return B_OK;
     60}
     61
     62
     63status_t
     64arch_thread_init_kthread_stack(struct thread *t, int (*start_func)(void),
     65    void (*entry_func)(void), void (*exit_func)(void))
     66{
     67/*  addr_t *kstack = (addr_t *)t->kernel_stack_base;
     68    addr_t *kstackTop = (addr_t *)t->kernel_stack_base;
     69
     70    // clear the kernel stack
     71#ifdef DEBUG_KERNEL_STACKS
     72#   ifdef STACK_GROWS_DOWNWARDS
     73    memset((void *)((addr_t)kstack + KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE), 0,
     74        KERNEL_STACK_SIZE);
     75#   else
     76    memset(kstack, 0, KERNEL_STACK_SIZE);
     77#   endif
     78#else
     79    memset(kstack, 0, KERNEL_STACK_SIZE);
     80#endif
     81
     82    // space for frame pointer and return address, and stack frames must be
     83    // 16 byte aligned
     84    kstackTop -= 2;
     85    kstackTop = (addr_t*)((addr_t)kstackTop & ~0xf);
     86
     87    // LR, CR, r2, r13-r31, f13-f31, as pushed by m68k_context_switch()
     88    kstackTop -= 22 + 2 * 19;
     89
     90    // let LR point to m68k_kernel_thread_root()
     91    kstackTop[0] = (addr_t)&m68k_kernel_thread_root;
     92
     93    // the arguments of m68k_kernel_thread_root() are the functions to call,
     94    // provided in registers r13-r15
     95    kstackTop[3] = (addr_t)entry_func;
     96    kstackTop[4] = (addr_t)start_func;
     97    kstackTop[5] = (addr_t)exit_func;
     98
     99    // save this stack position
     100    t->arch_info.sp = (void *)kstackTop;
     101*/
     102    return B_OK;
     103}
     104
     105
     106status_t
     107arch_thread_init_tls(struct thread *thread)
     108{
     109    // TODO: Implement!
     110    return B_OK;
     111}
     112
     113
     114void
     115arch_thread_context_switch(struct thread *from, struct thread *to)
     116{
     117/*  addr_t newPageDirectory;
     118
     119    newPageDirectory = (addr_t)m68k_next_page_directory(from, to);
     120
     121    if ((newPageDirectory % B_PAGE_SIZE) != 0)
     122        panic("arch_thread_context_switch: bad pgdir 0x%lx\n", newPageDirectory);
     123#warning M68K: export from arch_vm.c
     124    m68k_set_pgdir(newPageDirectory);
     125    m68k_context_switch(&from->arch_info.sp, to->arch_info.sp);*/
     126}
     127
     128
     129void
     130arch_thread_dump_info(void *info)
     131{
     132}
     133
     134
     135status_t
     136arch_thread_enter_userspace(struct thread *thread, addr_t entry, void *arg1, void *arg2)
     137{
     138    panic("arch_thread_enter_uspace(): not yet implemented\n");
     139    return B_ERROR;
     140}
     141
     142
     143bool
     144arch_on_signal_stack(struct thread *thread)
     145{
     146    return false;
     147}
     148
     149
     150status_t
     151arch_setup_signal_frame(struct thread *thread, struct sigaction *sa, int sig, int sigMask)
     152{
     153    return B_ERROR;
     154}
     155
     156
     157int64
     158arch_restore_signal_frame(void)
     159{
     160    return 0;
     161}
     162
     163
     164void
     165arch_check_syscall_restart(struct thread *thread)
     166{
     167}
     168
     169
     170/** Saves everything needed to restore the frame in the child fork in the
     171 *  arch_fork_arg structure to be passed to arch_restore_fork_frame().
     172 *  Also makes sure to return the right value.
     173 */
     174
     175void
     176arch_store_fork_frame(struct arch_fork_arg *arg)
     177{
     178}
     179
     180
     181/** Restores the frame from a forked team as specified by the provided
     182 *  arch_fork_arg structure.
     183 *  Needs to be called from within the child team, ie. instead of
     184 *  arch_thread_enter_uspace() as thread "starter".
     185 *  This function does not return to the caller, but will enter userland
     186 *  in the child team at the same position where the parent team left of.
     187 */
     188
     189void
     190arch_restore_fork_frame(struct arch_fork_arg *arg)
     191{
     192}
     193
     194void
     195arch_syscall_64_bit_return_value(void)
     196{
     197    struct thread* thread = thread_get_current_thread();
     198    atomic_or(&thread->flags, THREAD_FLAGS_64_BIT_SYSCALL_RETURN);
     199}
  • src/system/kernel/arch/x86_64/arch_debug_console.cpp

     
     1/*
     2 * Copyright 2007, François Revol, revol@free.fr.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2003-2006, Axel Dörfler, axeld@pinc-software.de.
     6 * Distributed under the terms of the MIT License.
     7 *
     8 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
     9 * Distributed under the terms of the NewOS License.
     10 */
     11
     12
     13//#include <arch_platform.h>
     14#include <arch/debug_console.h>
     15#include <boot/kernel_args.h>
     16#include <kernel.h>
     17#include <vm/vm.h>
     18#include <arch/arm/uart.h>
     19#include <string.h>
     20
     21
     22void
     23arch_debug_remove_interrupt_handler(uint32 line)
     24{
     25}
     26
     27
     28void
     29arch_debug_install_interrupt_handlers(void)
     30{
     31}
     32
     33
     34char
     35arch_debug_blue_screen_getchar(void)
     36{
     37    return 0;
     38//M68KPlatform::Default()->BlueScreenGetChar();
     39}
     40
     41
     42char
     43arch_debug_serial_getchar(void)
     44{
     45    return 0;
     46//M68KPlatform::Default()->SerialDebugGetChar();
     47}
     48
     49
     50void
     51arch_debug_serial_putchar(const char c)
     52{
     53
     54//  return 0;
     55//M68KPlatform::Default()->SerialDebugPutChar(c);
     56}
     57
     58
     59void
     60arch_debug_serial_puts(const char *s)
     61{
     62    while (*s != '\0') {
     63        arch_debug_serial_putchar(*s);
     64        s++;
     65    }
     66}
     67
     68
     69void
     70arch_debug_serial_early_boot_message(const char *string)
     71{
     72    // this function will only be called in fatal situations
     73}
     74
     75
     76status_t
     77arch_debug_console_init(kernel_args *args)
     78{
     79
     80    return 0;
     81//M68KPlatform::Default()->InitSerialDebug(args);
     82}
     83
     84
     85status_t
     86arch_debug_console_init_settings(kernel_args *args)
     87{
     88    return B_OK;
     89}
     90
  • src/system/kernel/arch/x86_64/asm_offsets.cpp

     
     1/*
     2 * Copyright 2007-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
     3 * Distributed under the terms of the MIT License.
     4 */
     5
     6// This file is used to get C structure offsets into assembly code.
     7// The build system assembles the file and processes the output to create
     8// a header file with macro definitions, that can be included from assembly
     9// code.
     10
     11
     12#include <computed_asm_macros.h>
     13
     14#include <arch_cpu.h>
     15#include <cpu.h>
     16#include <ksyscalls.h>
     17#include <thread_types.h>
     18
     19
     20#define DEFINE_MACRO(macro, value) DEFINE_COMPUTED_ASM_MACRO(macro, value)
     21
     22#define DEFINE_OFFSET_MACRO(prefix, structure, member) \
     23    DEFINE_MACRO(prefix##_##member, offsetof(struct structure, member));
     24
     25#define DEFINE_SIZEOF_MACRO(prefix, structure) \
     26    DEFINE_MACRO(prefix##_sizeof, sizeof(struct structure));
     27
     28
     29void
     30dummy()
     31{
     32    // struct cpu_ent
     33    DEFINE_OFFSET_MACRO(CPU_ENT, cpu_ent, fault_handler);
     34    DEFINE_OFFSET_MACRO(CPU_ENT, cpu_ent, fault_handler_stack_pointer);
     35
     36    // struct thread
     37    DEFINE_OFFSET_MACRO(THREAD, thread, kernel_time);
     38    DEFINE_OFFSET_MACRO(THREAD, thread, user_time);
     39    DEFINE_OFFSET_MACRO(THREAD, thread, last_time);
     40    DEFINE_OFFSET_MACRO(THREAD, thread, in_kernel);
     41    DEFINE_OFFSET_MACRO(THREAD, thread, flags);
     42    DEFINE_OFFSET_MACRO(THREAD, thread, kernel_stack_top);
     43    DEFINE_OFFSET_MACRO(THREAD, thread, fault_handler);
     44
     45    // struct iframe
     46    DEFINE_OFFSET_MACRO(IFRAME, iframe, cs);
     47    DEFINE_OFFSET_MACRO(IFRAME, iframe, eax);
     48    DEFINE_OFFSET_MACRO(IFRAME, iframe, edx);
     49    DEFINE_OFFSET_MACRO(IFRAME, iframe, orig_eax);
     50    DEFINE_OFFSET_MACRO(IFRAME, iframe, vector);
     51    DEFINE_OFFSET_MACRO(IFRAME, iframe, eip);
     52    DEFINE_OFFSET_MACRO(IFRAME, iframe, flags);
     53    DEFINE_OFFSET_MACRO(IFRAME, iframe, user_esp);
     54
     55    // struct vm86_iframe
     56    DEFINE_SIZEOF_MACRO(VM86_IFRAME, vm86_iframe);
     57    DEFINE_OFFSET_MACRO(VM86_IFRAME, vm86_iframe, flags);
     58
     59    // struct syscall_info
     60    DEFINE_SIZEOF_MACRO(SYSCALL_INFO, syscall_info);
     61    DEFINE_OFFSET_MACRO(SYSCALL_INFO, syscall_info, function);
     62    DEFINE_OFFSET_MACRO(SYSCALL_INFO, syscall_info, parameter_size);
     63
     64    // struct x86_optimized_functions
     65    DEFINE_OFFSET_MACRO(X86_OPTIMIZED_FUNCTIONS, x86_optimized_functions,
     66        memcpy);
     67    DEFINE_OFFSET_MACRO(X86_OPTIMIZED_FUNCTIONS, x86_optimized_functions,
     68        memset);
     69}
  • src/system/kernel/arch/x86_64/arch_real_time_clock.cpp

     
     1/*
     2 * Copyright 2007, François Revol, revol@free.fr.
     3 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>. All rights reserved.
     4 * Copyright 2005-2007, Axel Dörfler, axeld@pinc-software.de
     5 * Copyright 2003, Jeff Ward, jeff@r2d2.stcloudstate.edu. All rights reserved.
     6 *
     7 * Distributed under the terms of the MIT License.
     8 */
     9
     10#include <arch/real_time_clock.h>
     11
     12//#include <arch_platform.h>
     13#include <real_time_clock.h>
     14#include <real_time_data.h>
     15#include <smp.h>
     16/*
     17typedef struct  {
     18    uint8 second;
     19    uint8 minute;
     20    uint8 hour;
     21    uint8 day;
     22    uint8 month;
     23    uint8 year;
     24    uint8 century;
     25} cmos_time;
     26
     27
     28static uint32
     29bcd_to_int(uint8 bcd)
     30{
     31    uint32 numl;
     32    uint32 numh;
     33
     34    numl = bcd & 0x0f;
     35    numh = (bcd & 0xf0) >> 4;
     36
     37    return numh * 10 + numl;
     38}
     39
     40
     41static uint8
     42int_to_bcd(uint32 number)
     43{
     44    uint8 low;
     45    uint8 high;
     46
     47    if (number > 99)
     48        return 0;
     49
     50    high = number / 10;
     51    low = number % 10;
     52
     53    return (high << 4) | low;
     54}
     55
     56
     57static int
     58same_time(const cmos_time *time1, const cmos_time *time2)
     59{
     60    return time1->second == time2->second
     61        && time1->minute == time2->minute
     62        && time1->hour == time2->hour
     63        && time1->day == time2->day
     64        && time1->month == time2->month
     65        && time1->year == time2->year
     66        && time1->century == time2->century;
     67}
     68
     69
     70static uint8
     71cmos_read(uint8 addr)
     72{
     73    return M68KPlatform::Default()->ReadRTCReg(addr);
     74}
     75
     76
     77static void
     78cmos_write(uint8 addr, uint8 data)
     79{
     80    M68KPlatform::Default()->WriteRTCReg(addr, data);
     81}
     82
     83
     84static void
     85set_24_hour_mode(void)
     86{
     87    uint8 status_b;
     88
     89    status_b = cmos_read(0x0b);
     90    status_b |= 0x02;
     91    cmos_write(0x0b, status_b);
     92}
     93
     94
     95static void
     96read_cmos_clock(cmos_time *cmos)
     97{
     98    set_24_hour_mode();
     99
     100    cmos->century = cmos_read(0x32);
     101    cmos->year = cmos_read(0x09);
     102    cmos->month = cmos_read(0x08);
     103    cmos->day = cmos_read(0x07);
     104    cmos->hour = cmos_read(0x04);
     105    cmos->minute = cmos_read(0x02);
     106    cmos->second = cmos_read(0x00);
     107}
     108
     109
     110static void
     111write_cmos_clock(cmos_time *cmos)
     112{
     113    set_24_hour_mode();
     114
     115    cmos_write(0x32, cmos->century);
     116    cmos_write(0x09, cmos->year);
     117    cmos_write(0x08, cmos->month);
     118    cmos_write(0x07, cmos->day);
     119    cmos_write(0x04, cmos->hour);
     120    cmos_write(0x02, cmos->minute);
     121    cmos_write(0x00, cmos->second);
     122}
     123
     124
     125static uint32
     126cmos_to_secs(const cmos_time *cmos)
     127{
     128    struct tm t;
     129    t.tm_year = bcd_to_int(cmos->century) * 100 + bcd_to_int(cmos->year)
     130        - RTC_EPOCH_BASE_YEAR;
     131    t.tm_mon = bcd_to_int(cmos->month) - 1;
     132    t.tm_mday = bcd_to_int(cmos->day);
     133    t.tm_hour = bcd_to_int(cmos->hour);
     134    t.tm_min = bcd_to_int(cmos->minute);
     135    t.tm_sec = bcd_to_int(cmos->second);
     136
     137    return rtc_tm_to_secs(&t);
     138}
     139
     140
     141static void
     142secs_to_cmos(uint32 seconds, cmos_time *cmos)
     143{
     144    int wholeYear;
     145
     146    struct tm t;
     147    rtc_secs_to_tm(seconds, &t);
     148
     149    wholeYear = t.tm_year + RTC_EPOCH_BASE_YEAR;
     150
     151    cmos->century = int_to_bcd(wholeYear / 100);
     152    cmos->year = int_to_bcd(wholeYear % 100);
     153    cmos->month = int_to_bcd(t.tm_mon + 1);
     154    cmos->day = int_to_bcd(t.tm_mday);
     155    cmos->hour = int_to_bcd(t.tm_hour);
     156    cmos->minute = int_to_bcd(t.tm_min);
     157    cmos->second = int_to_bcd(t.tm_sec);
     158}
     159
     160
     161//  #pragma mark -
     162
     163
     164
     165static spinlock sSetArchDataLock;
     166*/
     167status_t
     168arch_rtc_init(kernel_args *args, struct real_time_data *data)
     169{
     170/*
     171    // init the platform RTC service
     172    status_t error = M68KPlatform::Default()->InitRTC(args, data);
     173    if (error != B_OK)
     174        return error;
     175
     176    // init the arch specific part of the real_time_data
     177    data->arch_data.data[0].system_time_offset = 0;
     178    // cvFactor = 2^32 * 1000000 / tbFreq
     179    // => (tb * cvFactor) >> 32 = (tb * 2^32 * 1000000 / tbFreq) >> 32
     180    //    = tb / tbFreq * 1000000 = time in us
     181    data->arch_data.system_time_conversion_factor
     182        = uint32((uint64(1) << 32) * 1000000
     183            / args->arch_args.time_base_frequency);
     184    data->arch_data.version = 0;
     185
     186    // init spinlock
     187    sSetArchDataLock = 0;
     188
     189    // init system_time() conversion factor
     190    __m68k_setup_system_time(&data->arch_data.system_time_conversion_factor);
     191*/
     192    return B_OK;
     193}
     194
     195
     196uint32
     197arch_rtc_get_hw_time(void)
     198{
     199
     200    return 0;
     201//M68KPlatform::Default()->GetHardwareRTC();
     202}
     203
     204
     205void
     206arch_rtc_set_hw_time(uint32 seconds)
     207{
     208
     209//  M68KPlatform::Default()->SetHardwareRTC(seconds);
     210}
     211
     212
     213void
     214arch_rtc_set_system_time_offset(struct real_time_data *data, bigtime_t offset)
     215{
     216/*
     217    cpu_status state = disable_interrupts();
     218    acquire_spinlock(&sSetArchDataLock);
     219
     220    int32 version = data->arch_data.version + 1;
     221    data->arch_data.data[version % 2].system_time_offset = offset;
     222    data->arch_data.version = version;
     223
     224    release_spinlock(&sSetArchDataLock);
     225    restore_interrupts(state);
     226*/
     227
     228}
     229
     230
     231bigtime_t
     232arch_rtc_get_system_time_offset(struct real_time_data *data)
     233{
     234/*
     235    int32 version;
     236    bigtime_t offset;
     237    do {
     238        version = data->arch_data.version;
     239        offset = data->arch_data.data[version % 2].system_time_offset;
     240    } while (version != data->arch_data.version);
     241
     242    return offset;
     243*/
     244return 0;
     245}
  • src/system/kernel/arch/x86_64/arch_timer.cpp

     
     1/*
     2 * Copyright 2007, Haiku Inc. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      François Revol <revol@free.fr>
     7 *
     8 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
     9 * Distributed under the terms of the NewOS License.
     10 */
     11
     12
     13#include <boot/stage2.h>
     14#include <kernel.h>
     15#include <debug.h>
     16
     17#include <timer.h>
     18#include <arch/timer.h>
     19//#include <arch_platform.h>
     20
     21
     22void
     23arch_timer_set_hardware_timer(bigtime_t timeout)
     24{
     25//  M68KPlatform::Default()->SetHardwareTimer(timeout);
     26}
     27
     28
     29void
     30arch_timer_clear_hardware_timer()
     31{
     32//  M68KPlatform::Default()->ClearHardwareTimer();
     33}
     34
     35
     36int
     37arch_init_timer(kernel_args *args)
     38{
     39
     40    return 0;
     41//M68KPlatform::Default()->InitTimer(args);
     42}
     43
  • src/system/kernel/arch/x86_64/arch_vm.cpp

     
     1/*
     2 * Copyright 2007, François Revol, revol@free.fr.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de.
     6 * Distributed under the terms of the MIT License.
     7 *
     8 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
     9 * Distributed under the terms of the NewOS License.
     10 */
     11
     12#include <KernelExport.h>
     13
     14#include <kernel.h>
     15#include <boot/kernel_args.h>
     16
     17#include <vm/vm.h>
     18#include <vm/vm_types.h>
     19#include <arch/vm.h>
     20//#include <arch_mmu.h>
     21
     22
     23//#define TRACE_ARCH_VM
     24#ifdef TRACE_ARCH_VM
     25#   define TRACE(x) dprintf x
     26#else
     27#   define TRACE(x) ;
     28#endif
     29
     30//TODO: WRITEME
     31
     32status_t
     33arch_vm_init(kernel_args *args)
     34{
     35    return B_OK;
     36}
     37
     38
     39status_t
     40arch_vm_init2(kernel_args *args)
     41{
     42//  int bats[8];
     43//  int i;
     44
     45    /**/
     46//TODO: WRITEME
     47
     48    return B_OK;
     49}
     50
     51
     52status_t
     53arch_vm_init_post_area(kernel_args *args)
     54{
     55    return B_OK;
     56}
     57
     58
     59status_t
     60arch_vm_init_end(kernel_args *args)
     61{
     62
     63//TODO: WRITEME
     64    return B_OK;
     65}
     66
     67
     68status_t
     69arch_vm_init_post_modules(kernel_args *args)
     70{
     71    return B_OK;
     72}
     73
     74
     75void
     76arch_vm_aspace_swap(struct VMAddressSpace *from, struct VMAddressSpace *to)
     77{
     78//TODO: WRITEME
     79//  m68k_set_pgdir(m68k_translation_map_get_pgdir(&to->TranslationMap()));
     80}
     81
     82
     83bool
     84arch_vm_supports_protection(uint32 protection)
     85{
     86    return true;
     87}
     88
     89
     90void
     91arch_vm_unset_memory_type(VMArea *area)
     92{
     93}
     94
     95
     96status_t
     97arch_vm_set_memory_type(VMArea *area, phys_addr_t physicalBase, uint32 type)
     98{
     99    if (type == 0)
     100        return B_OK;
     101
     102    return B_ERROR;
     103}
  • src/system/kernel/arch/x86_64/arch_user_debugger.cpp

     
     1/*
     2 * Copyright 2007, François Revol, revol@free.fr.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2005, Axel Dörfler, axeld@pinc-softare.de
     6 * Distributed under the terms of the MIT License.
     7 */
     8
     9
     10#include <debugger.h>
     11#include <int.h>
     12#include <thread.h>
     13#include <arch/user_debugger.h>
     14
     15const uint8 kX86SoftwareBreakpoint[1] = { 0xcc };
     16
     17void
     18arch_clear_team_debug_info(struct arch_team_debug_info *info)
     19{
     20}
     21
     22
     23void
     24arch_destroy_team_debug_info(struct arch_team_debug_info *info)
     25{
     26    arch_clear_team_debug_info(info);
     27}
     28
     29
     30void
     31arch_clear_thread_debug_info(struct arch_thread_debug_info *info)
     32{
     33}
     34
     35
     36void
     37arch_destroy_thread_debug_info(struct arch_thread_debug_info *info)
     38{
     39    arch_clear_thread_debug_info(info);
     40}
     41
     42
     43void
     44arch_update_thread_single_step()
     45{
     46}
     47
     48
     49void
     50arch_set_debug_cpu_state(const debug_cpu_state *cpuState)
     51{
     52}
     53
     54
     55void
     56arch_get_debug_cpu_state(debug_cpu_state *cpuState)
     57{
     58}
     59
     60
     61status_t
     62arch_get_thread_debug_cpu_state(struct thread *thread,
     63        debug_cpu_state *cpuState)
     64{
     65        return B_ERROR;
     66}
     67
     68
     69
     70status_t
     71arch_set_breakpoint(void *address)
     72{
     73    return B_ERROR;
     74}
     75
     76
     77status_t
     78arch_clear_breakpoint(void *address)
     79{
     80    return B_ERROR;
     81}
     82
     83
     84status_t
     85arch_set_watchpoint(void *address, uint32 type, int32 length)
     86{
     87    return B_ERROR;
     88}
     89
     90
     91status_t
     92arch_clear_watchpoint(void *address)
     93{
     94    return B_ERROR;
     95}
     96
     97bool
     98arch_has_breakpoints(struct arch_team_debug_info *info)
     99{
     100    return false;
     101}
     102
     103void
     104x86_init_user_debug()
     105{
     106}
  • src/system/kernel/arch/x86_64/arch_platform.cpp

     
     1/*
     2 * Copyright 2007, François Revol, revol@free.fr.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
     6 * All rights reserved. Distributed under the terms of the MIT License.
     7 */
     8
     9//#include <arch_platform.h>
     10
     11#include <new>
     12
     13#include <KernelExport.h>
     14#include <arch/platform.h>
     15#include <boot/kernel_args.h>
     16//#include <platform/openfirmware/openfirmware.h>
     17#include <real_time_clock.h>
     18#include <util/kernel_cpp.h>
     19
     20/*
     21static M68KPlatform *sM68KPlatform;
     22
     23
     24// constructor
     25M68KPlatform::M68KPlatform(platform_type platformType,
     26    m68k_platform_type m68kPlatformType)
     27    : fPlatformType(platformType),
     28      fM68KPlatformType(m68kPlatformType)
     29{
     30}
     31
     32// destructor
     33M68KPlatform::~M68KPlatform()
     34{
     35}
     36
     37// Default
     38M68KPlatform *
     39M68KPlatform::Default()
     40{
     41    return sM68KPlatform;
     42}
     43
     44
     45// # pragma mark -
     46*/
     47
     48status_t
     49arch_platform_init(struct kernel_args *kernelArgs)
     50{
     51
     52    return B_OK;
     53}
     54
     55
     56status_t
     57arch_platform_init_post_vm(struct kernel_args *kernelArgs)
     58{
     59    return B_OK;
     60//sM68KPlatform->InitPostVM(kernelArgs);
     61}
     62
     63
     64status_t
     65arch_platform_init_post_thread(struct kernel_args *kernelArgs)
     66{
     67    return B_OK;
     68}
  • src/system/kernel/arch/x86_64/entry.S

     
     1;Temp entry to x86_64 code.
     2;
     3
     4.code 32
     5
     6.external _start
     7.global init_long_mode
     8
     9init_long_mode:
     10
     11ov eax, cr0 ; Read CR0.
     12and eax,7FFFFFFFh; Set PE=0
     13mov cr0, eax ; Write CR0.
     14
     15mov eax, cr4
     16bts eax, 5
     17mov cr4, eax
     18
     19mov ecx, 0c0000080h ; EFER MSR number.
     20rdmsr ; Read EFER.
     21bts eax, 8 ; Set LME=1.
     22wrmsr ; Write EFER.
     23
     24mov eax, cr0 ; Read CR0.
     25or eax,80000000h ; Set PE=1.
     26mov cr0, eax ; Write CR0.
     27
     28.code 64
     29call _start
     30
     31ret
     32
     33end
  • src/system/kernel/arch/x86_64/arch_debug.cpp

     
     1/*
     2 * Copyright 2003-2009, Haiku Inc. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Axel Dörfler <axeld@pinc-software.de>
     7 *      Ingo Weinhold <bonefish@cs.tu-berlin.de>
     8 *      François Revol <revol@free.fr>
     9 */
     10
     11
     12#include <arch/debug.h>
     13
     14#include <arch_cpu.h>
     15#include <debug.h>
     16#include <elf.h>
     17#include <kernel.h>
     18#include <kimage.h>
     19#include <thread.h>
     20
     21
     22struct stack_frame {
     23    struct stack_frame  *previous;
     24    addr_t              return_address;
     25};
     26
     27#define NUM_PREVIOUS_LOCATIONS 32
     28
     29extern struct iframe_stack gBootFrameStack;
     30/*
     31
     32static bool
     33already_visited(uint32 *visited, int32 *_last, int32 *_num, uint32 framePointer)
     34{
     35    int32 last = *_last;
     36    int32 num = *_num;
     37    int32 i;
     38
     39    for (i = 0; i < num; i++) {
     40        if (visited[(NUM_PREVIOUS_LOCATIONS + last - i)
     41                % NUM_PREVIOUS_LOCATIONS] == framePointer) {
     42            return true;
     43        }
     44    }
     45
     46    *_last = last = (last + 1) % NUM_PREVIOUS_LOCATIONS;
     47    visited[last] = framePointer;
     48
     49    if (num < NUM_PREVIOUS_LOCATIONS)
     50        *_num = num + 1;
     51
     52    return false;
     53}
     54
     55
     56static inline stack_frame *
     57get_current_stack_frame()
     58{
     59    stack_frame *frame;
     60    asm volatile("move.l %%fp,%0" : "=r"(frame));
     61    return frame;
     62}
     63
     64
     65static status_t
     66get_next_frame(addr_t framePointer, addr_t *next, addr_t *ip)
     67{
     68    struct thread *thread = thread_get_current_thread();
     69    addr_t oldFaultHandler = thread->fault_handler;
     70
     71    // set fault handler, so that we can safely access user stacks
     72    if (thread) {
     73        if (m68k_set_fault_handler(&thread->fault_handler, (addr_t)&&error))
     74            goto error;
     75    }
     76
     77    *ip = ((struct stack_frame *)framePointer)->return_address;
     78    *next = (addr_t)((struct stack_frame *)framePointer)->previous;
     79
     80    if (thread)
     81        thread->fault_handler = oldFaultHandler;
     82    return B_OK;
     83
     84error:
     85    thread->fault_handler = oldFaultHandler;
     86    return B_BAD_ADDRESS;
     87}
     88
     89
     90static void
     91print_stack_frame(struct thread *thread, addr_t ip, addr_t framePointer,
     92    addr_t nextFramePointer)
     93{
     94    addr_t diff = nextFramePointer - framePointer;
     95
     96    // kernel space/user space switch
     97    if (diff & 0x80000000)
     98        diff = 0;
     99
     100    // lookup symbol
     101    const char *symbol, *image;
     102    addr_t baseAddress;
     103    bool exactMatch;
     104    status_t status = elf_debug_lookup_symbol_address(ip, &baseAddress, &symbol,
     105        &image, &exactMatch);
     106    if (status != B_OK && !IS_KERNEL_ADDRESS(ip) && thread) {
     107        // try to locate the image in the images loaded into user space
     108        status = image_debug_lookup_user_symbol_address(thread->team, ip,
     109            &baseAddress, &symbol, &image, &exactMatch);
     110    }
     111    if (status == B_OK) {
     112        if (symbol != NULL) {
     113            kprintf("%08lx (+%4ld) %08lx   <%s>:%s + 0x%04lx%s\n", framePointer,
     114                diff, ip, image, symbol, ip - baseAddress,
     115                (exactMatch ? "" : " (nearest)"));
     116        } else {
     117            kprintf("%08lx (+%4ld) %08lx   <%s@%p>:unknown + 0x%04lx\n",
     118                framePointer, diff, ip, image, (void *)baseAddress,
     119                ip - baseAddress);
     120        }
     121    } else
     122        kprintf("%08lx (+%4ld) %08lx\n", framePointer, diff, ip);
     123}
     124
     125
     126static int
     127stack_trace(int argc, char **argv)
     128{
     129    uint32 previousLocations[NUM_PREVIOUS_LOCATIONS];
     130    struct iframe_stack *frameStack;
     131    struct thread *thread;
     132    addr_t framePointer;
     133    int32 i, num = 0, last = 0;
     134
     135    if (argc < 2) {
     136        thread = thread_get_current_thread();
     137        framePointer = (addr_t)get_current_stack_frame();
     138    } else {
     139kprintf("Stack traces of other threads not supported yet!\n");
     140return 0;
     141    }
     142
     143    // We don't have a thread pointer early in the boot process
     144    if (thread != NULL)
     145        frameStack = &thread->arch_info.iframes;
     146    else
     147        frameStack = &gBootFrameStack;
     148
     149    for (i = 0; i < frameStack->index; i++) {
     150        kprintf("iframe %p (end = %p)\n",
     151            frameStack->frames[i], frameStack->frames[i] + 1);
     152    }
     153
     154    if (thread != NULL) {
     155        kprintf("stack trace for thread 0x%lx \"%s\"\n", thread->id,
     156            thread->name);
     157
     158        kprintf("    kernel stack: %p to %p\n",
     159            (void *)thread->kernel_stack_base,
     160            (void *)(thread->kernel_stack_top));
     161        if (thread->user_stack_base != 0) {
     162            kprintf("      user stack: %p to %p\n",
     163                (void *)thread->user_stack_base,
     164                (void *)(thread->user_stack_base + thread->user_stack_size));
     165        }
     166    }
     167
     168    kprintf("frame            caller     <image>:function + offset\n");
     169
     170    for (;;) {
     171        // see if the frame pointer matches the iframe
     172        struct iframe *frame = NULL;
     173        for (i = 0; i < frameStack->index; i++) {
     174            if (framePointer == (addr_t)frameStack->frames[i]) {
     175                // it's an iframe
     176                frame = frameStack->frames[i];
     177                break;
     178            }
     179        }
     180
     181        if (frame) {
     182            kprintf("iframe at %p\n", frame);
     183            kprintf("   d0 0x%08lx    d1 0x%08lx    d2 0x%08lx    d3 0x%08lx\n",
     184                frame->d[0], frame->d[1], frame->d[2], frame->d[3]);
     185            kprintf("   d4 0x%08lx    d5 0x%08lx    d6 0x%08lx    d7 0x%08lx\n",
     186                frame->d[4], frame->d[5], frame->d[6], frame->d[7]);
     187            kprintf("   a0 0x%08lx    a1 0x%08lx    a2 0x%08lx    a3 0x%08lx\n",
     188                frame->a[0], frame->a[1], frame->a[2], frame->a[3]);
     189            kprintf("   a4 0x%08lx    a5 0x%08lx    a6 0x%08lx    a7 0x%08lx (sp)\n",
     190#warning M68K: a7 in iframe ??
     191                frame->a[4], frame->a[5], frame->a[6], -1L);
     192            kprintf("   pc 0x%08lx        sr 0x%04x\n",
     193                frame->cpu.pc, frame->cpu.sr);
     194#warning M68K: missing regs
     195
     196            print_stack_frame(thread, frame->cpu.pc, framePointer, frame->a[6]);
     197            framePointer = frame->a[6];
     198        } else {
     199            addr_t ip, nextFramePointer;
     200
     201            if (get_next_frame(framePointer, &nextFramePointer, &ip) != B_OK) {
     202                kprintf("%08lx -- read fault\n", framePointer);
     203                break;
     204            }
     205
     206            if (ip == 0 || framePointer == 0)
     207                break;
     208
     209            print_stack_frame(thread, ip, framePointer, nextFramePointer);
     210            framePointer = nextFramePointer;
     211        }
     212
     213        if (already_visited(previousLocations, &last, &num, framePointer)) {
     214            kprintf("circular stack frame: %p!\n", (void *)framePointer);
     215            break;
     216        }
     217        if (framePointer == 0)
     218            break;
     219    }
     220
     221
     222    return 0;
     223}
     224
     225*/
     226
     227// #pragma mark -
     228
     229
     230void
     231arch_debug_save_registers(struct arch_debug_registers* registers)
     232{
     233}
     234
     235
     236bool
     237arch_debug_contains_call(struct thread *thread, const char *symbol,
     238    addr_t start, addr_t end)
     239{
     240    return false;
     241}
     242
     243
     244void
     245arch_debug_stack_trace(void)
     246{
     247}
     248
     249
     250void *
     251arch_debug_get_caller(void)
     252{
     253    // TODO: implement me
     254    //return __builtin_frame_address(1);
     255//  struct stack_frame *frame;
     256    //frame = __builtin_frame_address(0);
     257//  frame = get_current_stack_frame();
     258//  return (void *)frame->previous->return_address;
     259    return NULL;
     260}
     261
     262
     263int32
     264arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount,
     265    int32 skipIframes, int32 skipFrames, uint32 flags)
     266{
     267
     268    return 0;
     269}
     270
     271
     272void*
     273arch_debug_get_interrupt_pc(bool* _isSyscall)
     274{
     275    // TODO: Implement!
     276    return NULL;
     277}
     278
     279
     280bool
     281arch_is_debug_variable_defined(const char* variableName)
     282{
     283    // TODO: Implement!
     284    return false;
     285}
     286
     287
     288status_t
     289arch_set_debug_variable(const char* variableName, uint64 value)
     290{
     291    // TODO: Implement!
     292    return B_ENTRY_NOT_FOUND;
     293}
     294
     295
     296status_t
     297arch_get_debug_variable(const char* variableName, uint64* value)
     298{
     299    // TODO: Implement!
     300    return B_ENTRY_NOT_FOUND;
     301}
     302
     303
     304status_t
     305arch_debug_init(kernel_args *args)
     306{
     307//  add_debugger_command("where", &stack_trace, "Same as \"sc\"");
     308//  add_debugger_command("bt", &stack_trace, "Same as \"sc\" (as in gdb)");
     309//  add_debugger_command("sc", &stack_trace, "Stack crawl for current thread");
     310
     311    return B_NO_ERROR;
     312}
     313
     314
     315void
     316arch_debug_call_with_fault_handler(cpu_ent* cpu, jmp_buf jumpBuffer,
     317    void (*function)(void*), void* parameter)
     318{
     319    // TODO: Implement! Most likely in assembly.
     320//  longjmp(jumpBuffer, 1);
     321}
     322
     323
     324void
     325arch_debug_unset_current_thread(void)
     326{
     327    // TODO: Implement!
     328}
     329
     330
  • src/system/kernel/arch/x86_64/arch_cpu.cpp

     
     1/*
     2 * Copyright 2007, François Revol, revol@free.fr.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de.
     6 * Distributed under the terms of the MIT License.
     7 *
     8 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
     9 * Distributed under the terms of the NewOS License.
     10 */
     11
     12
     13#include <KernelExport.h>
     14
     15//#include <arch_platform.h>
     16#include <arch_thread.h>
     17#include <arch/cpu.h>
     18#include <boot/kernel_args.h>
     19#include <commpage.h>
     20#include <elf.h>
     21
     22
     23int arch_cpu_type;
     24int arch_fpu_type;
     25int arch_mmu_type;
     26int arch_platform;
     27
     28x86_optimized_functions gOptimizedFunctions = {
     29};
     30
     31status_t
     32arch_cpu_preboot_init_percpu(kernel_args *args, int curr_cpu)
     33{
     34    // enable FPU
     35    //ppc:set_msr(get_msr() | MSR_FP_AVAILABLE);
     36
     37    // The current thread must be NULL for all CPUs till we have threads.
     38    // Some boot code relies on this.
     39//  arch_thread_set_current_thread(NULL);
     40
     41    return B_OK;
     42}
     43
     44
     45status_t
     46arch_cpu_init_percpu(kernel_args *args, int curr_cpu)
     47{
     48    //detect_cpu(curr_cpu);
     49
     50    // we only support one anyway...
     51    return 0;
     52}
     53
     54
     55status_t
     56arch_cpu_init(kernel_args *args)
     57{
     58// TODO: FINISH
     59
     60    return B_OK;
     61}
     62
     63
     64status_t
     65arch_cpu_init_post_vm(kernel_args *args)
     66{
     67    return B_OK;
     68}
     69
     70status_t
     71arch_cpu_init_post_modules(kernel_args *args)
     72{
     73    // add the functions to the commpage image
     74//  image_id image = get_commpage_image();
     75
     76    return B_OK;
     77}
     78
     79
     80void
     81arch_cpu_sync_icache(void *address, size_t len)
     82{
     83
     84//  cpu_ops.flush_icache((addr_t)address, len);
     85}
     86
     87
     88void
     89arch_cpu_memory_read_barrier(void)
     90{
     91}
     92
     93
     94void
     95arch_cpu_memory_write_barrier(void)
     96{
     97}
     98
     99
     100void
     101arch_cpu_invalidate_TLB_range(addr_t start, addr_t end)
     102{
     103/*  int32 num_pages = end / B_PAGE_SIZE - start / B_PAGE_SIZE;
     104    cpu_ops.flush_insn_pipeline();
     105    while (num_pages-- >= 0) {
     106        cpu_ops.flush_atc_addr(start);
     107        cpu_ops.flush_insn_pipeline();
     108        start += B_PAGE_SIZE;
     109    }
     110    cpu_ops.flush_insn_pipeline();
     111*/
     112}
     113
     114
     115void
     116arch_cpu_invalidate_TLB_list(addr_t pages[], int num_pages)
     117{
     118/*
     119    int i;
     120   
     121    cpu_ops.flush_insn_pipeline();
     122    for (i = 0; i < num_pages; i++) {
     123        cpu_ops.flush_atc_addr(pages[i]);
     124        cpu_ops.flush_insn_pipeline();
     125    }
     126    cpu_ops.flush_insn_pipeline();
     127*/
     128}
     129
     130
     131void
     132arch_cpu_global_TLB_invalidate(void)
     133{
     134/*  cpu_ops.flush_insn_pipeline();
     135    cpu_ops.flush_atc_all();
     136    cpu_ops.flush_insn_pipeline();
     137*/
     138}
     139
     140
     141void
     142arch_cpu_user_TLB_invalidate(void)
     143{/*
     144    cpu_ops.flush_insn_pipeline();
     145    cpu_ops.flush_atc_user();
     146    cpu_ops.flush_insn_pipeline();
     147*/
     148}
     149
     150
     151status_t
     152arch_cpu_user_memcpy(void *to, const void *from, size_t size,
     153    addr_t *faultHandler)
     154{
     155/*
     156    char *tmp = (char *)to;
     157    char *s = (char *)from;
     158    addr_t oldFaultHandler = *faultHandler;
     159
     160    if (m68k_set_fault_handler(faultHandler, (addr_t)&&error))
     161        goto error;
     162
     163    while (size--)
     164        *tmp++ = *s++;
     165
     166    *faultHandler = oldFaultHandler;
     167    return 0;
     168
     169error:
     170    *faultHandler = oldFaultHandler;*/
     171    return B_BAD_ADDRESS;
     172}
     173
     174
     175/** \brief Copies at most (\a size - 1) characters from the string in \a from to
     176 *  the string in \a to, NULL-terminating the result.
     177 *
     178 *  \param to Pointer to the destination C-string.
     179 *  \param from Pointer to the source C-string.
     180 *  \param size Size in bytes of the string buffer pointed to by \a to.
     181 * 
     182 *  \return strlen(\a from).
     183 */
     184
     185ssize_t
     186arch_cpu_user_strlcpy(char *to, const char *from, size_t size, addr_t *faultHandler)
     187{
     188/*
     189    int from_length = 0;
     190    addr_t oldFaultHandler = *faultHandler;
     191
     192    if (m68k_set_fault_handler(faultHandler, (addr_t)&&error))
     193        goto error;
     194
     195    if (size > 0) {
     196        to[--size] = '\0';
     197        // copy
     198        for ( ; size; size--, from_length++, to++, from++) {
     199            if ((*to = *from) == '\0')
     200                break;
     201        }
     202    }
     203    // count any leftover from chars
     204    while (*from++ != '\0')
     205        from_length++;
     206
     207    *faultHandler = oldFaultHandler;
     208    return from_length;
     209
     210error:
     211    *faultHandler = oldFaultHandler;*/
     212    return B_BAD_ADDRESS;
     213}
     214
     215
     216status_t
     217arch_cpu_user_memset(void *s, char c, size_t count, addr_t *faultHandler)
     218{
     219/*
     220    char *xs = (char *)s;
     221    addr_t oldFaultHandler = *faultHandler;
     222
     223    if (m68k_set_fault_handler(faultHandler, (addr_t)&&error))
     224        goto error;
     225
     226    while (count--)
     227        *xs++ = c;
     228
     229    *faultHandler = oldFaultHandler;
     230    return 0;
     231
     232error:
     233    *faultHandler = oldFaultHandler;*/
     234
     235    return B_BAD_ADDRESS;
     236}
     237
     238
     239status_t
     240arch_cpu_shutdown(bool reboot)
     241{
     242//  M68KPlatform::Default()->ShutDown(reboot);
     243    return B_ERROR;
     244}
     245
     246
     247void
     248arch_cpu_idle(void)
     249{
     250//  if (cpu_ops.idle)
     251//      cpu_ops.idle();
     252//#warning M68K: use LPSTOP ?
     253    //asm volatile ("lpstop");
     254}
     255
  • src/system/kernel/arch/x86_64/arch_commpage.cpp

     
     1/*
     2 * Copyright 2009, Johannes Wischert, johanneswi@gmail.com.
     3 * Distributed under the terms of the MIT License.
     4 */
     5
     6
     7#include <commpage.h>
     8
     9#include <string.h>
     10
     11#include <KernelExport.h>
     12
     13#include <cpu.h>
     14#include <elf.h>
     15#include <smp.h>
     16
     17
     18status_t
     19arch_commpage_init(void)
     20{
     21    /* no optimized memcpy or anything yet */
     22    /* we don't use it for syscall yet either */
     23    // add syscall to the commpage image
     24//  image_id image = get_commpage_image();
     25    return B_OK;
     26}
     27
     28
     29status_t
     30arch_commpage_init_post_cpus(void)
     31{
     32        return B_OK;
     33}
     34
  • src/system/kernel/arch/x86_64/Jamfile

     
     1SubDir HAIKU_TOP src system kernel arch x86_64 ;
     2
     3SubDirHdrs $(SUBDIR) $(DOTDOT) generic ;
     4UsePrivateKernelHeaders ;
     5
     6
     7SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ;
     8
     9
     10KernelMergeObject kernel_arch_x86_64.o :
     11#   entry.S
     12
     13#   arch_atomic.c
     14    arch_commpage.cpp
     15    arch_cpu.cpp
     16#   arch_cpu_asm.S
     17    arch_debug_console.cpp
     18    arch_debug.cpp
     19    arch_elf.cpp
     20#   arch_exceptions.S
     21    arch_int.cpp
     22    arch_platform.cpp
     23    arch_real_time_clock.cpp
     24    arch_smp.cpp
     25    arch_system_info.cpp
     26    arch_thread.cpp
     27    arch_timer.cpp
     28    arch_user_debugger.cpp
     29    arch_vm.cpp
     30    arch_vm_translation_map.cpp
     31    generic_vm_physical_page_mapper.cpp
     32    generic_vm_physical_page_ops.cpp
     33
     34    :
     35    $(TARGET_KERNEL_PIC_CCFLAGS)
     36    :
     37
     38;
     39
     40CreateAsmStructOffsetsHeader asm_offsets.h : asm_offsets.cpp ;
     41
  • src/system/kernel/arch/x86_64/arch_int.cpp

     
     1/*
     2 * Copyright 2003-2010, Haiku Inc. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Axel Dörfler <axeld@pinc-software.de>
     7 *      Ingo Weinhold <bonefish@cs.tu-berlin.de>
     8 *      François Revol <revol@free.fr>
     9 *
     10 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
     11 * Distributed under the terms of the NewOS License.
     12 */
     13
     14
     15#include <int.h>
     16
     17#include <arch/smp.h>
     18#include <boot/kernel_args.h>
     19#include <device_manager.h>
     20#include <kscheduler.h>
     21#include <interrupt_controller.h>
     22#include <smp.h>
     23#include <thread.h>
     24#include <timer.h>
     25#include <util/DoublyLinkedList.h>
     26#include <util/kernel_cpp.h>
     27#include <vm/vm.h>
     28#include <vm/vm_priv.h>
     29#include <vm/VMAddressSpace.h>
     30#include <string.h>
     31
     32
     33//#define TRACE_ARCH_INT
     34#ifdef TRACE_ARCH_INT
     35#   define TRACE(x) dprintf x
     36#else
     37#   define TRACE(x) ;
     38#endif
     39
     40/*typedef void (*m68k_exception_handler)(void);
     41#define M68K_EXCEPTION_VECTOR_COUNT 256
     42#warning M68K: align on 4 ?
     43//m68k_exception_handler gExceptionVectors[M68K_EXCEPTION_VECTOR_COUNT];
     44m68k_exception_handler *gExceptionVectors;
     45
     46// defined in arch_exceptions.S
     47extern "C" void __m68k_exception_noop(void);
     48extern "C" void __m68k_exception_common(void);
     49*/
     50extern int __irqvec_start;
     51extern int __irqvec_end;
     52
     53//extern"C" void m68k_exception_tail(void);
     54
     55// current fault handler
     56addr_t gFaultHandler;
     57
     58// interrupt controller interface (initialized
     59// in arch_int_init_post_device_manager())
     60//static struct interrupt_controller_module_info *sPIC;
     61//static void *sPICCookie;
     62
     63
     64void
     65arch_int_enable_io_interrupt(int irq)
     66{
     67    //if (!sPIC)
     68    //  return;
     69
     70    // TODO: I have no idea, what IRQ type is appropriate.
     71    //sPIC->enable_io_interrupt(sPICCookie, irq, IRQ_TYPE_LEVEL);
     72//  M68KPlatform::Default()->EnableIOInterrupt(irq);
     73}
     74
     75
     76void
     77arch_int_disable_io_interrupt(int irq)
     78{
     79
     80    //if (!sPIC)
     81    //  return;
     82
     83    //sPIC->disable_io_interrupt(sPICCookie, irq);
     84//  M68KPlatform::Default()->DisableIOInterrupt(irq);
     85}
     86
     87
     88/* arch_int_*_interrupts() and friends are in arch_asm.S */
     89
     90/*
     91static void
     92print_iframe(struct iframe *frame)
     93{
     94    dprintf("r0-r3:   0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", frame->r0, frame->r1, frame->r2, frame->r3);
     95    dprintf("r4-r7:   0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", frame->r4, frame->r5, frame->r6, frame->r7);
     96    dprintf("r8-r11:  0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", frame->r8, frame->r9, frame->r10, frame->r11);
     97    dprintf("r12-r15: 0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", frame->r12, frame->r13, frame->a6, frame->a7);
     98    dprintf("      pc 0x%08lx         sr 0x%08lx\n", frame->pc, frame->sr);
     99}
     100*/
     101
     102status_t
     103arch_int_init(kernel_args *args)
     104{
     105//  status_t err;
     106//  addr_t vbr;
     107//  int i;
     108
     109//  gExceptionVectors = (m68k_exception_handler *)args->arch_args.vir_vbr;
     110
     111    /* fill in the vector table */
     112//  for (i = 0; i < M68K_EXCEPTION_VECTOR_COUNT; i++)
     113//      gExceptionVectors[i] = &__m68k_exception_common;
     114
     115//  vbr = args->arch_args.phys_vbr;
     116    /* point VBR to the new table */
     117//  asm volatile  ("movec %0,%%vbr" : : "r"(vbr):);
     118
     119    return B_OK;
     120}
     121
     122
     123status_t
     124arch_int_init_post_vm(kernel_args *args)
     125{
     126    return B_OK;
     127}
     128
     129
     130status_t
     131arch_int_init_io(kernel_args* args)
     132{
     133    return B_OK;
     134}
     135
     136
     137status_t
     138arch_int_init_post_device_manager(struct kernel_args *args)
     139{
     140    // no PIC found
     141    panic("arch_int_init_post_device_manager(): Found no supported PIC!");
     142
     143    return B_ENTRY_NOT_FOUND;
     144}
     145
     146
  • src/system/kernel/arch/x86_64/arch_vm_translation_map.cpp

     
     1/*
     2 * Copyright 2007, François Revol, revol@free.fr.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de.
     6 * Distributed under the terms of the MIT License.
     7 *
     8 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
     9 * Distributed under the terms of the NewOS License.
     10 */
     11
     12#include <KernelExport.h>
     13#include <kernel.h>
     14#include <vm/vm.h>
     15#include <vm/vm_priv.h>
     16#include <vm/VMAddressSpace.h>
     17#include <int.h>
     18#include <boot/kernel_args.h>
     19#include <arch/vm_translation_map.h>
     20#include <arch/cpu.h>
     21//#include <arch_mmu.h>
     22#include <stdlib.h>
     23
     24#include "generic_vm_physical_page_mapper.h"
     25
     26
     27void *
     28m68k_translation_map_get_pgdir(VMTranslationMap *map)
     29{
     30    return NULL;
     31//TODO: WRITEME
     32//get_vm_ops()->m68k_translation_map_get_pgdir(map);
     33}
     34
     35//  #pragma mark -
     36//  VM API
     37
     38
     39status_t
     40arch_vm_translation_map_init(kernel_args *args,
     41        VMPhysicalPageMapper** _physicalPageMapper)
     42{
     43    return NULL;
     44//TODO: WRITEME
     45
     46//get_vm_ops()->arch_vm_translation_map_init_map(map, kernel);
     47}
     48
     49status_t
     50arch_vm_translation_map_create_map(bool kernel, VMTranslationMap** _map)
     51{
     52    return NULL;
     53//TODO: WRITEME
     54}
     55
     56status_t
     57arch_vm_translation_map_init_kernel_map_post_sem(VMTranslationMap *map)
     58{
     59    return NULL;
     60//TODO: WRITEME
     61
     62//get_vm_ops()->arch_vm_translation_map_init_kernel_map_post_sem(map);
     63}
     64
     65
     66status_t
     67arch_vm_translation_map_init(kernel_args *args)
     68{
     69    return NULL;
     70//TODO: WRITEME
     71
     72//get_vm_ops()->arch_vm_translation_map_init(args);
     73}
     74
     75
     76status_t
     77arch_vm_translation_map_init_post_area(kernel_args *args)
     78{
     79    return NULL;
     80//TODO: WRITEME
     81
     82//get_vm_ops()->arch_vm_translation_map_init_post_area(args);
     83}
     84
     85
     86status_t
     87arch_vm_translation_map_init_post_sem(kernel_args *args)
     88{
     89    return NULL;
     90//TODO: WRITEME
     91
     92//get_vm_ops()->arch_vm_translation_map_init_post_sem(args);
     93}
     94
     95
     96/** Directly maps a page without having knowledge of any kernel structures.
     97 *  Used only during VM setup.
     98 *  It currently ignores the "attributes" parameter and sets all pages
     99 *  read/write.
     100 */
     101
     102status_t
     103arch_vm_translation_map_early_map(kernel_args *ka, addr_t virtualAddress,
     104    phys_addr_t physicalAddress, uint8 attributes,
     105    phys_addr_t (*get_free_page)(kernel_args *))
     106{
     107    return NULL;
     108//TODO: WRITEME
     109
     110//get_vm_ops()->arch_vm_translation_map_early_map(ka, virtualAddress, physicalAddress,
     111//      attributes, get_free_page);
     112}
     113
     114
     115// XXX currently assumes this translation map is active
     116
     117status_t
     118arch_vm_translation_map_early_query(addr_t va, phys_addr_t *out_physical)
     119{
     120    return NULL;
     121//TODO: WRITEME
     122
     123//get_vm_ops()->arch_vm_translation_map_early_query(va, out_physical);
     124}
     125
     126
     127bool
     128arch_vm_translation_map_is_kernel_page_accessible(addr_t virtualAddress,
     129        uint32 protection)
     130{
     131//TODO: WRITEME
     132        return TRUE;
     133//get_vm_ops()-arch_vm_translation_map_is_kernel_page_accessible(virtualAddress,
     134  //              protection);
     135}
     136
  • src/system/kernel/arch/x86_64/arch_smp.cpp

     
     1/*
     2 * Copyright 2007, Haiku Inc. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      François Revol <revol@free.fr>
     7 *
     8 * Copyright 2004, Axel Dörfler, axeld@pinc-software.de
     9 * Distributed under the terms of the OpenBeOS License.
     10 */
     11
     12
     13#include <KernelExport.h>
     14
     15#include <boot/stage2.h>
     16#include <arch/smp.h>
     17#include <debug.h>
     18
     19
     20status_t
     21arch_smp_init(kernel_args *args)
     22{
     23    return B_OK;
     24}
     25
     26
     27status_t
     28arch_smp_per_cpu_init(kernel_args *args, int32 cpu)
     29{
     30    return B_OK;
     31}
     32
     33
     34void
     35arch_smp_send_ici(int32 target_cpu)
     36{
     37    panic("called arch_smp_send_ici!\n");
     38}
     39
     40
     41void
     42arch_smp_send_broadcast_ici()
     43{
     44    panic("called arch_smp_send_broadcast_ici\n");
     45}
     46
  • src/system/kernel/arch/x86_64/arch_system_info.cpp

     
     1/*
     2 * Copyright 2007, Haiku Inc. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      François Revol <revol@free.fr>
     7 *
     8 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
     9 * All rights reserved. Distributed under the terms of the MIT License.
     10 */
     11
     12#include <OS.h>
     13
     14#include <arch_cpu.h>
     15//#include <arch_platform.h>
     16#include <arch/system_info.h>
     17#include <boot/kernel_args.h>
     18
     19/*
     20static uint64 sCPUClockFrequency;
     21static uint64 sBusClockFrequency;
     22static enum cpu_types sCPUType;
     23static uint16 sCPURevision;
     24*/
     25status_t
     26arch_get_system_info(system_info *info, size_t size)
     27{
     28    return B_OK;
     29}
     30
     31
     32status_t
     33arch_system_info_init(struct kernel_args *args)
     34{
     35    return B_OK;
     36}
     37
     38status_t
     39_user_get_cpuid(cpuid_info *userInfo, uint32 eaxRegister, uint32 cpuNum)
     40{
     41    return B_OK;
     42}
  • src/system/libroot/os/arch/x86_64/byteorder.S

     
     1/*
     2 * Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 */
     5
     6#include <asm_defs.h>
     7
     8
     9/* uint16 __swap_int16(uint16 value) */
     10FUNCTION(__swap_int16):
     11    movl    4(%esp), %eax
     12    bswap   %eax
     13    shr     $16, %eax
     14    ret
     15FUNCTION_END(__swap_int16)
     16
     17/* this one is much faster on a P4, courtesy of Marcus Overhagen,
     18 * a good candidate for per processor optimizations: */
     19/*
     20FUNCTION(__swap_int16_p4):
     21    movl    4(%esp), %eax
     22    rolw    $8, %ax
     23    ret
     24*/
     25
     26/* uint32 __swap_int32(uint32 value) */
     27FUNCTION(__swap_int32):
     28    movl    4(%esp), %eax
     29    bswap   %eax
     30    ret
     31FUNCTION_END(__swap_int32)
     32
     33/* uint64 __swap_int64(uint64 value) */
     34FUNCTION(__swap_int64):
     35    movl    4(%esp), %edx   /* the 32-bits registers are swapped here */
     36    movl    8(%esp), %eax
     37    bswap   %eax
     38    bswap   %edx
     39    ret
     40FUNCTION_END(__swap_int64)
     41
     42/* float __swap_float(float value) */
     43FUNCTION(__swap_float):
     44    movl    4(%esp), %eax
     45    bswap   %eax
     46    movl    %eax, 4(%esp)
     47    fld     4(%esp)
     48    ret
     49FUNCTION_END(__swap_float)
     50
     51/* double __swap_double(double value) */
     52FUNCTION(__swap_double):
     53    movl    4(%esp), %edx   /* the 32-bits registers are swapped here */
     54    movl    8(%esp), %eax
     55    bswap   %eax
     56    bswap   %edx
     57    movl    %eax, 4(%esp)
     58    movl    %edx, 8(%esp)
     59    fldl    4(%esp)
     60    ret
     61FUNCTION_END(__swap_double)
  • src/system/libroot/os/arch/x86_64/system_time.c

     
     1/*
     2    Just a dummy to avoid a special case in the build system. system_time()
     3    is implemented in system_time_asm.S.
     4*/
  • src/system/libroot/os/arch/x86_64/system_time_asm.S

     
     1/*
     2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
     6 * Distributed under the terms of the NewOS License.
     7 */
     8
     9#include <asm_defs.h>
     10
     11
     12/* saves the conversion factor needed for system_time */
     13.lcomm cv_factor                4
     14.lcomm cv_factor_nsecs          4
     15.lcomm cv_factor_nsecs_shift    1
     16
     17
     18.text
     19
     20
     21FUNCTION(__x86_setup_system_time):
     22//  movl    4(%esp), %eax
     23//  movl    %eax, cv_factor
     24//  movl    8(%esp), %eax
     25//  movl    %eax, cv_factor_nsecs
     26//  movb    12(%esp), %al
     27//  movb    %al, cv_factor_nsecs_shift
     28    ret
     29FUNCTION_END(__x86_setup_system_time)
     30
     31
     32/* int64 system_time(); */
     33FUNCTION(system_time):
     34//  pushl   %ebx
     35//  pushl   %ecx
     36//  movl    cv_factor, %ebx
     37
     38    /* load 64-bit factor into %eax (low), %edx (high) */
     39//  rdtsc       /* time in %edx,%eax */
     40
     41//  movl    %edx, %ecx  /* save high half */
     42//  mull    %ebx        /* truncate %eax, but keep %edx */
     43//  movl    %ecx, %eax
     44//  movl    %edx, %ecx  /* save high half of low */
     45//  mull    %ebx /*, %eax*/
     46    /* now compute  [%edx, %eax] + [%ecx], propagating carry */
     47//  subl    %ebx, %ebx  /* need zero to propagate carry */
     48//  addl    %ecx, %eax
     49//  adc     %ebx, %edx
     50//  popl    %ecx
     51//  popl    %ebx
     52    ret
     53FUNCTION_END(system_time)
     54
     55
     56/* int64 system_time_nsecs(); */
     57FUNCTION(system_time_nsecs):
     58//  testb   $0, cv_factor_nsecs_shift
     59//  jne     1f
     60
     61    /* same algorithm as system_time(), just with a different factor */
     62
     63//  pushl   %ebx
     64//  pushl   %ecx
     65//  movl    cv_factor_nsecs, %ebx
     66
     67    /* load 64-bit factor into %eax (low), %edx (high) */
     68//  rdtsc       /* time in %edx,%eax */
     69
     70//  movl    %edx, %ecx  /* save high half */
     71//  mull    %ebx        /* truncate %eax, but keep %edx */
     72//  movl    %ecx, %eax
     73//  movl    %edx, %ecx  /* save high half of low */
     74//  mull    %ebx /*, %eax*/
     75    /* now compute  [%edx, %eax] + [%ecx], propagating carry */
     76//  subl    %ebx, %ebx  /* need zero to propagate carry */
     77//  addl    %ecx, %eax
     78//  adc     %ebx, %edx
     79//  popl    %ecx
     80//  popl    %ebx
     81    ret
     82
     831:
     84    /* TSC frequency is less than 1 GHz -- we shift everything up 16 bit */
     85
     86//  pushl   %ebx
     87//  pushl   %ecx
     88//  pushl   %esi
     89//  movl    cv_factor_nsecs, %ebx
     90
     91    /* load 64-bit factor into %eax (low), %edx (high) */
     92//  rdtsc       /* time in %edx,%eax */
     93
     94    /* save high half */
     95//  movl    %edx, %ecx
     96
     97    /* multiply low half by conversion factor */
     98//  mull    %ebx
     99
     100    /* save result */
     101//  movl    %eax, %esi  /* low half -> %esi */
     102//  movl    %ecx, %eax
     103//  movl    %edx, %ecx  /* high half -> %ecx */
     104
     105    /* multiply high half by conversion factor */
     106//  mull    %ebx
     107
     108    /* now compute  [%edx, %eax] + [%ecx], propagating carry */
     109//  xorl    %ebx, %ebx  /* need zero to propagate carry */
     110//  addl    %ecx, %eax
     111//  adc     %ebx, %edx
     112
     113    /* shift the result left 16 bit */
     114//  shl     $16, %edx
     115//  movl    %eax, %ebx
     116//  shr     $16, %ebx
     117//  orw     %bx, %dx
     118//  shl     $16, %eax
     119
     120    /* add the high 16 bit of the low half of the low product */
     121//  shr     $16, %esi
     122//  orw     %si, %ax
     123
     124//  popl    %esi
     125//  popl    %ecx
     126//  popl    %ebx
     127    ret
     128FUNCTION_END(system_time_nsecs)
  • src/system/libroot/os/arch/x86_64/atomic.S

     
     1/*
     2** Copyright 2003, Marcus Overhagen. All rights reserved.
     3** Distributed under the terms of the OpenBeOS license.
     4**
     5** Copyright 2001, Travis Geiselbrecht. All rights reserved.
     6** Distributed under the terms of the NewOS License.
     7*/
     8
     9#include <asm_defs.h>
     10
     11
     12.text
     13
     14/* int32    atomic_set(vint32 *value, int32 newValue) */
     15FUNCTION(atomic_set):
     16//  movl        4(%esp),%edx
     17//  movl        8(%esp),%eax
     18//  lock
     19//  xchg        %eax,(%edx)
     20    ret
     21FUNCTION_END(atomic_set)
     22
     23/* int32    atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst) */
     24FUNCTION(atomic_test_and_set):
     25//  movl        4(%esp),%edx
     26//  movl        8(%esp),%ecx
     27//  movl        12(%esp),%eax
     28//  lock
     29//  cmpxchgl    %ecx,(%edx)
     30    ret
     31FUNCTION_END(atomic_test_and_set)
     32
     33/* int32    atomic_add(vint32 *value, int32 addValue) */
     34FUNCTION(atomic_add):
     35//  movl        4(%esp),%edx
     36//  movl        8(%esp),%eax
     37//  lock
     38//  xaddl       %eax,(%edx)
     39    ret
     40FUNCTION_END(atomic_add)
     41
     42/* int32    atomic_and(vint32 *value, int32 andValue) */
     43FUNCTION(atomic_and):
     44//  movl        4(%esp),%edx
     45//_atomic_and1:
     46//  movl        8(%esp),%ecx
     47//  movl        (%edx),%eax
     48//  andl        %eax,%ecx
     49//  lock
     50//  cmpxchgl    %ecx,(%edx)
     51//  jnz         _atomic_and1
     52    ret
     53FUNCTION_END(atomic_and)
     54
     55/* int32    atomic_or(vint32 *value, int32 orValue) */
     56FUNCTION(atomic_or):
     57//  movl        4(%esp),%edx
     58//_atomic_or1:
     59//  movl        8(%esp),%ecx
     60//  movl        (%edx),%eax
     61//  orl         %eax,%ecx
     62//  lock
     63//  cmpxchgl    %ecx,(%edx)
     64//  jnz         _atomic_or1
     65    ret
     66FUNCTION_END(atomic_or)
     67
     68/* int32    atomic_get(vint32 *value) */
     69FUNCTION(atomic_get):
     70//  movl        4(%esp), %edx
     71//_atomic_get1:
     72//  movl        (%edx), %eax
     73//  movl        %eax, %ecx
     74//  lock
     75//  cmpxchgl    %ecx, (%edx)
     76//  jnz         _atomic_get1
     77    ret
     78FUNCTION_END(atomic_get)
     79
     80/* int64    atomic_set64(vint64 *value, int64 newValue) */
     81FUNCTION(atomic_set64):
     82//  push        %esi
     83//  push        %ebx
     84//  movl        12(%esp), %esi  /* value */
     85//  movl        16(%esp), %ebx  /* newValue low */
     86//  movl        20(%esp), %ecx  /* newValue high */
     87//_atomic_set64_1:
     88//  movl        (%esi), %eax    /* testAgainst low */
     89//  movl        4(%esi), %edx   /* testAgainst high */
     90//  lock
     91//  cmpxchg8b   (%esi)
     92//  jnz         _atomic_set64_1
     93//  pop         %ebx
     94//  pop         %esi
     95    ret
     96FUNCTION_END(atomic_set64)
     97
     98/* int64    atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst) */
     99FUNCTION(atomic_test_and_set64):
     100//  push        %esi
     101//  push        %ebx
     102//  movl        12(%esp), %esi  /* value */
     103//  movl        16(%esp), %ebx  /* newValue low */
     104//  movl        20(%esp), %ecx  /* newValue high */
     105//  movl        24(%esp), %eax  /* testAgainst low */
     106//  movl        28(%esp), %edx  /* testAgainst high */
     107//  lock
     108//  cmpxchg8b   (%esi)
     109//  pop         %ebx
     110//  pop         %esi
     111    ret
     112FUNCTION_END(atomic_test_and_set64)
     113
     114/* int64    atomic_add64(vint64 *value, int64 addValue) */
     115FUNCTION(atomic_add64):
     116//  push        %esi
     117//  push        %ebx
     118//  movl        12(%esp), %esi
     119//_atomic_add64_1:
     120//  movl        (%esi), %eax
     121//  movl        4(%esi), %edx
     122//  movl        %eax, %ebx
     123//  movl        %edx, %ecx
     124//  addl        16(%esp), %ebx
     125//  adcl        20(%esp), %ecx
     126//  lock
     127//  cmpxchg8b   (%esi)
     128//  jnz         _atomic_add64_1
     129//  pop         %ebx
     130//  pop         %esi
     131    ret
     132FUNCTION_END(atomic_add64)
     133
     134/* int64    atomic_and64(vint64 *value, int64 andValue) */
     135FUNCTION(atomic_and64):
     136//  push        %esi
     137//  push        %ebx
     138//  movl        12(%esp), %esi
     139//_atomic_and64_1:
     140//  movl        (%esi), %eax
     141//  movl        4(%esi), %edx
     142//  movl        %eax, %ebx
     143//  movl        %edx, %ecx
     144//  andl        16(%esp), %ebx
     145//  andl        20(%esp), %ecx
     146//  lock
     147//  cmpxchg8b   (%esi)
     148//  jnz         _atomic_and64_1
     149//  pop         %ebx
     150//  pop         %esi
     151    ret
     152FUNCTION_END(atomic_and64)
     153
     154/* int64    atomic_or64(vint64 *value, int64 orValue) */
     155FUNCTION(atomic_or64):
     156//  push        %esi
     157//  push        %ebx
     158//  movl        12(%esp), %esi
     159//_atomic_or64_1:
     160//  movl        (%esi), %eax
     161//  movl        4(%esi), %edx
     162//  movl        %eax, %ebx
     163//  movl        %edx, %ecx
     164//  orl         16(%esp), %ebx
     165//  orl         20(%esp), %ecx
     166//  lock
     167//  cmpxchg8b   (%esi)
     168//  jnz         _atomic_or64_1
     169//  pop         %ebx
     170//  pop         %esi
     171    ret
     172FUNCTION_END(atomic_or64)
     173
     174/* int64    atomic_get64(vint64 *value) */
     175FUNCTION(atomic_get64):
     176//  push        %esi
     177//  push        %ebx
     178//  movl        12(%esp), %esi
     179//_atomic_get64_1:
     180//  movl        (%esi), %eax
     181//  movl        4(%esi), %edx
     182//  movl        %eax, %ebx
     183//  movl        %edx, %ecx
     184//  lock
     185//  cmpxchg8b   (%esi)
     186//  jnz         _atomic_get64_1
     187//  pop         %ebx
     188//  pop         %esi
     189    ret
     190FUNCTION_END(atomic_get64)
  • src/system/libroot/posix/stdlib/strtod.c

     
    126126#if defined(__i386__) || defined(__ia64__) || defined(__alpha__) || \
    127127    defined(__sparc64__) || defined(__powerpc__) || defined(__POWERPC__) || \
    128128    defined(__m68k__) || defined(__M68K__) || defined(__arm__) || \
    129     defined(__ARM__) || defined(__mipsel__) || defined(__MIPSEL__)
     129    defined(__ARM__) || defined(__mipsel__) || defined(__MIPSEL__) || \
     130    defined(__X86_64__) || defined(__x86_64__)
    130131#   include <sys/types.h>
    131132#   if BYTE_ORDER == BIG_ENDIAN
    132133#       define IEEE_BIG_ENDIAN
  • src/system/libroot/posix/arch/x86_64/setjmp_internal.h

     
     1/*
     2** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     3** Distributed under the terms of the Haiku License.
     4*/
     5#ifndef SETJMP_INTERNAL_H
     6#define SETJMP_INTERNAL_H
     7
     8/* These are the fields of the __jmp_regs structure */
     9
     10#define JMP_REGS_RBX    0
     11#define JMP_REGS_RSI    4
     12#define JMP_REGS_RDI    8
     13#define JMP_REGS_RBP    12
     14#define JMP_REGS_RSP    16
     15#define JMP_REGS_PC 20
     16
     17#include <asm_defs.h>
     18
     19#endif  /* SETJMP_INTERNAL_H */
  • src/system/libroot/posix/arch/x86_64/sigsetjmp.S

     
     1/*
     2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
     3 * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     4 * Distributed under the terms of the MIT License.
     5 */
     6
     7#include "setjmp_internal.h"
     8
     9
     10/** This is a BeOS compatible __sigsetjmp() implementation; there,
     11 *  setjmp() and sigsetjmp() are both macros to this function.
     12 *
     13 *  It first saves the register/stack environment of the running thread,
     14 *  and then calls __setjmp_save_sigs() which will save the signal state
     15 *  if it was asked to do this.
     16 */
     17
     18/* int sigsetjmp(jmp_buf buffer, int saveMask) */
     19FUNCTION(__sigsetjmp):
     20FUNCTION(sigsetjmp):
     21    // return address to %edx, stack pointer for return to %ecx (both are
     22    // scratch registers)
     23//  mov     0(%esp), %edx
     24//  lea     4(%esp), %ecx
     25
     26    // buffer to %eax
     27//  mov     4(%esp), %eax
     28
     29sigsetjmp_setjmp_entry:
     30    // fill __jmp_buf structure with current registers
     31//  mov     %ebx, JMP_REGS_EBX(%eax)
     32//  mov     %esi, JMP_REGS_ESI(%eax)
     33//  mov     %edi, JMP_REGS_EDI(%eax)
     34//  mov     %ebp, JMP_REGS_EBP(%eax)
     35
     36    // save stack and return address (because that's where we intend to jump to)
     37//  mov     %ecx, JMP_REGS_ESP(%eax)
     38//  mov     %edx, JMP_REGS_PC(%eax)
     39
     40    jmp     __setjmp_save_sigs
     41FUNCTION_END(sigsetjmp)
     42
     43
     44/* int setjmp(jmp_buf buffer) */
     45FUNCTION(setjmp):
     46    // prepare %edx, %ecx, and %eax for sigsetjmp
     47//  mov     0(%esp), %edx
     48//  lea     4(%esp), %ecx
     49//  mov     (%ecx), %eax
     50
     51    // let sigsetjmp do the real work
     52//  pushl   $0                          // saveMask
     53//  push    %eax                        // buffer
     54//  call    sigsetjmp_setjmp_entry
     55//  add     $8, %esp
     56
     57    ret
     58FUNCTION_END(setjmp)
     59
     60
     61#pragma weak _setjmp=setjmp
  • src/system/libroot/posix/arch/x86_64/siglongjmp.S

     
     1/*
     2** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     3** Distributed under the terms of the Haiku License.
     4*/
     5
     6#include "setjmp_internal.h"
     7
     8
     9/** This is a BeOS compatible siglongjmp() implementation;
     10 *  longjmp() and _longjmp() are both calling this function.
     11 */
     12
     13
     14/* int __siglongjmp(jmp_buf buffer, int value) */
     15FUNCTION(siglongjmp):
     16FUNCTION(longjmp):
     17FUNCTION(_longjmp):
     18//  mov     4(%esp), %ecx
     19//  mov     8(%esp), %eax
     20
     21    // restore registers
     22//  mov     JMP_REGS_EBX(%ecx), %ebx
     23//  mov     JMP_REGS_ESI(%ecx), %esi
     24//  mov     JMP_REGS_EDI(%ecx), %edi
     25//  mov     JMP_REGS_EBP(%ecx), %ebp
     26//  mov     JMP_REGS_ESP(%ecx), %esp
     27
     28    // prepare the stack so that we will return to the setjmp() program location
     29//  mov     JMP_REGS_PC(%ecx), %edx
     30//  push    %edx                // return address
     31
     32    // let __setjmp_save_sigs deal with the signal mask and the return value
     33//  push    %eax                // value
     34//  push    %ecx                // buffer
     35//  call    __longjmp_return
     36//  add     $8, %esp
     37//
     38    ret
     39FUNCTION_END(siglongjmp)
     40
     41
     42#pragma weak longjmp=siglongjmp
  • src/system/glue/arch/x86_64/crti.S

     
     1/*
     2 * Copyright 2005-2006, Axel Dörfler, axeld@pinc-software.de.
     3 * Distributed under the terms of the MIT License.
     4 */
     5
     6/** This file contains the first part of the ".init" and ".fini" sections in
     7 *  the ELF executable.
     8 *  The functions defined here will be called during initialization/termination
     9 *  of the loaded executable/library. The ".init" and ".fini" sections are
     10 *  stacked together like this:
     11 *
     12 *  crti.S      entry point
     13 *              call to _init_before/_term_before
     14 *  crtbegin.S  GCC specific: constructors/destructors are called, ...
     15 *  crtend.S
     16 *  crtn.S      call to _init_after/_term_after
     17 *              exit
     18 */
     19
     20#define FUNCTION(x) .global x; .type x,@function; x
     21
     22.section .init
     23FUNCTION(_init):
     24    pushl   %rbp
     25    movl    %rsp, %rbp
     26    pushl   8(%rbp)     // put image ID on the stack again
     27    call    _init_before
     28    // crtbegin.o stuff comes here
     29
     30.section .fini
     31FUNCTION(_fini):
     32    pushl   %rbp
     33    movl    %rsp, %rbp
     34    pushl   8(%rbp)
     35    call    _term_before
     36    // crtend.o stuff comes here
  • src/system/glue/arch/x86_64/crtn.S

     
     1/*
     2 * Copyright 2005-2006, Axel Dörfler, axeld@pinc-software.de.
     3 * Distributed under the terms of the MIT License.
     4 */
     5
     6/** This file contains the final part of the ".init" and ".fini" sections in
     7 *  the ELF executable. It is tightly connected to crti.S.
     8 *  Have a look at crti.S to find a description of what happens here.
     9 */
     10
     11.section .init
     12    // the image ID is still on the stack
     13    call    _init_after
     14    movl    %rbp, %rsp
     15    popl    %rbp
     16    ret
     17
     18.section .fini
     19    // the image ID is still on the stack
     20    call    _term_after
     21    movl    %rbp, %rsp
     22    popl    %rbp
     23    ret
  • src/system/glue/arch/x86_64/Jamfile

     
     1SubDir HAIKU_TOP src system glue arch x86_64 ;
     2
     3KernelObjects
     4    crti.S
     5    crtn.S
     6    ;
     7
  • src/tools/gensyscalls/arch/x86_64/arch_gensyscalls.h

     
     1#define SYSCALL_RETURN_TYPE_ALIGNMENT_TYPE  int
     2#define SYSCALL_PARAMETER_ALIGNMENT_TYPE    int