Ticket #6310: system.headers.patch

File system.headers.patch, 85.8 KB (added by mmlr, 10 years ago)
  • headers/os/kernel/debugger.h

     
    1313
    1414// include architecture specific definitions
    1515#include <arch/x86/arch_debugger.h>
     16#include <arch/x86_64/arch_debugger.h>
    1617#include <arch/ppc/arch_debugger.h>
    1718#include <arch/m68k/arch_debugger.h>
    1819#include <arch/mipsel/arch_debugger.h>
    1920#include <arch/arm/arch_debugger.h>
    2021
    2122
    22 #ifdef __INTEL__
     23#ifdef __x86_64__
     24    typedef struct x86_64_debug_cpu_state debug_cpu_state;
     25#elif __INTEL__
    2326    typedef struct x86_debug_cpu_state debug_cpu_state;
    2427#elif __POWERPC__
    2528    typedef struct ppc_debug_cpu_state debug_cpu_state;
  • headers/os/arch/x86_64/arch_debugger.h

     
     1/*
     2 * Copyright 2005-2010, Haiku Inc.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef _ARCH_X86_86_DEBUGGER_H
     6#define _ARCH_X86_86_DEBUGGER_H
     7
     8
     9typedef struct x86_64_fp_register {
     10    uint8       value[10];
     11    uint8       reserved[6];
     12} x86_64_fp_register;
     13
     14
     15typedef struct x86_64_xmm_register {
     16    uint8       value[16];
     17} x86_64_xmm_register;
     18
     19
     20typedef struct x86_64_extended_registers {
     21    uint16              control;
     22    uint16              status;
     23    uint8               tag;
     24    uint8               reserved1;
     25    uint16              opcode;
     26    uint32              instruction_pointer;
     27    uint16              cs;
     28    uint16              reserved2;
     29    uint32              data_pointer;
     30    uint16              ds;
     31    uint16              reserved3;
     32    uint32              mxcsr;
     33    uint32              mxcsr_mask;
     34    union {
     35        x86_64_fp_register  fp_registers[8];    // st0-st7
     36        x86_64_fp_register  mmx_registers[8];   // mm0-mm7
     37    };
     38    x86_64_xmm_register xmm_registers[8];   // xmm0-xmm7
     39    uint8               reserved4[224];     // 288 - 512
     40} x86_64_extended_registers;
     41
     42
     43struct x86_64_debug_cpu_state {
     44    x86_64_extended_registers   extended_registers;
     45
     46    uint64  gs;
     47    uint64  fs;
     48    uint64  es;
     49    uint64  ds;
     50    uint64  rdi;
     51    uint64  rsi;
     52    uint64  rbp;
     53    uint64  rsp;
     54    uint64  rbx;
     55    uint64  rdx;
     56    uint64  rcx;
     57    uint64  rax;
     58    uint64  r8;
     59    uint64  r9;
     60    uint64  r10;
     61    uint64  r11;
     62    uint64  r12;
     63    uint64  r13;
     64    uint64  r14;
     65    uint64  r15;
     66    uint32  vector;
     67    uint32  error_code;
     68    uint64  rip;
     69    uint64  cs;
     70    uint32  eflags;
     71    uint64  user_rsp;
     72    uint64  user_ss;
     73} __attribute__((aligned(16)));
     74
     75
     76#endif  // _ARCH_X86_64_DEBUGGER_H
  • headers/posix/arch/x86_64/signal.h

     
    1010 */
    1111
    1212#if __x86_64__
     13/*
     14typedef struct xmmx_regs {
     15    unsigned char   xmm0[16];
     16    unsigned char   xmm1[16];
     17    unsigned char   xmm2[16];
     18    unsigned char   xmm3[16];
     19    unsigned char   xmm4[16];
     20    unsigned char   xmm5[16];
     21    unsigned char   xmm6[16];
     22    unsigned char   xmm7[16];
     23    unsigned char   xmm8[16];
     24    unsigned char   xmm9[16];
     25    unsigned char   xmm10[16];
     26    unsigned char   xmm11[16];
     27    unsigned char   xmm12[16];
     28    unsigned char   xmm13[16];
     29    unsigned char   xmm14[16];
     30    unsigned char   xmm15[16];
     31} xmmx_regs;
    1332
     33typedef struct mmx_regs {
     34    unsigned char   mm0[10];
     35    unsigned char   mm1[10];
     36    unsigned char   mm2[10];
     37    unsigned char   mm3[10];
     38    unsigned char   mm4[10];
     39    unsigned char   mm5[10];
     40    unsigned char   mm6[10];
     41    unsigned char   mm7[10];
     42} packed_mmx_regs;
     43*/
     44
     45typedef struct extended_regs {
     46/* TODO: Finish extended regs */
     47//  mmx_regs mmx;
     48//  xmmx_regs sse;
     49} extended_regs;
     50
    1451struct vregs {
    15     unsigned long           rax;    /* gp regs */
    16     unsigned long           rdx;
    17     unsigned long           rcx;
    18     unsigned long           rbx;
    19     unsigned long           rsi;
    20     unsigned long           rdi;
    21     unsigned long           rbp;
    22     unsigned long           rsp;
     52    unsigned long long      rip;        /* gp regs */
     53    unsigned long           eflags;
     54    unsigned long long      rax;
     55    unsigned long long      rcx;
     56    unsigned long long      rdx;
     57    unsigned long long      rsp;
     58    unsigned long long      rbp;
    2359
    24     unsigned long           r8; /* egp regs */
    25     unsigned long           r9;
    26     unsigned long           r10;
    27     unsigned long           r11;
    28     unsigned long           r12;
    29     unsigned long           r13;
    30     unsigned long           r14;
    31     unsigned long           r15;
     60    unsigned long long      r8;     /* egp regs */
     61    unsigned long long      r9;
     62    unsigned long long      r10;
     63    unsigned long long      r11;
     64    unsigned long long      r12;
     65    unsigned long long      r13;
     66    unsigned long long      r14;
     67    unsigned long long      r15;
    3268
    33     unsigned long           rip;
     69    unsigned long long      _reserved_1;
     70    unsigned long long      _reserved_2[3];
    3471
    35 /*TODO: add
    36 *   Floatpoint
    37 *   MMX
    38 *   SSE
    39 */
    4072
     73    extended_regs   xregs;
    4174};
    4275 
    4376#endif /* __x86_64__ */
  • headers/private/kernel/boot/elf.h

     
    99#include <boot/addr_range.h>
    1010#include <sys/stat.h>
    1111#include <elf_priv.h>
     12#include <util/FixedWidthPointer.h>
    1213
    1314
    1415struct preloaded_image {
    15     struct preloaded_image *next;
    16     char        *name;
     16    FixedWidthPointer<struct preloaded_image>   next;
     17    FixedWidthPointer<char>             name;
     18    uint8       elf_size;
    1719    elf_region  text_region;
    1820    elf_region  data_region;
    1921    addr_range  dynamic_section;
    20     struct Elf32_Ehdr elf_header;
    21 
    22     struct Elf32_Sym    *syms;
    23     struct Elf32_Rel    *rel;
     22    union
     23    {
     24        struct Elf32_Ehdr elf_header;
     25        struct Elf64_Ehdr elf_header64;
     26    };
     27    union
     28    {
     29        FixedWidthPointer<struct Elf32_Sym> syms;
     30        FixedWidthPointer<struct Elf64_Sym> syms64;
     31    };
     32    union
     33    {
     34        FixedWidthPointer<struct Elf32_Rel> rel;
     35        FixedWidthPointer<struct Elf64_Rel> rel64;
     36    };
    2437    int                 rel_len;
    25     struct Elf32_Rela   *rela;
     38    union
     39    {
     40        FixedWidthPointer<struct Elf32_Rela>    rela;
     41        FixedWidthPointer<struct Elf64_Rela>    rela64;
     42    };
    2643    int                 rela_len;
    27     struct Elf32_Rel    *pltrel;
     44    union
     45    {
     46        FixedWidthPointer<struct Elf32_Rel> pltrel;
     47        FixedWidthPointer<struct Elf64_Rel> pltrel64;
     48    };
    2849    int                 pltrel_len;
    2950    int                 pltrel_type;
    3051
    31     struct Elf32_Sym *debug_symbols;
    32     const char  *debug_string_table;
     52    union
     53    {
     54        FixedWidthPointer<struct Elf32_Sym> debug_symbols;
     55        FixedWidthPointer<struct Elf64_Sym> debug_symbols64;
     56    };
     57    FixedWidthPointer<const char>   debug_string_table;
    3358    uint32      num_debug_symbols, debug_string_table_size;
    3459
    3560    ino_t       inode;
     
    3964        // set by the module initialization code
    4065};
    4166
    42 #ifdef __cplusplus
    43 extern "C" {
    44 #endif
    45 
    4667extern status_t boot_elf_resolve_symbol(struct preloaded_image *image,
    4768    struct Elf32_Sym *symbol, addr_t *symbolAddress);
    4869
    49 #ifdef __cplusplus
    50 }
    51 #endif
     70extern status_t boot_elf64_resolve_symbol(struct preloaded_image *image,
     71    struct Elf64_Sym *symbol, addr_t *symbolAddress);
    5272
     73
    5374#endif  /* KERNEL_BOOT_ELF_H */
  • headers/private/kernel/boot/arch.h

     
    1 /*
    2  * Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
    3  * Distributed under the terms of the MIT License.
    4  */
    5 #ifndef KERNEL_BOOT_ARCH_H
    6 #define KERNEL_BOOT_ARCH_H
    7 
    8 #include <SupportDefs.h>
    9 #include <boot/elf.h>
    10 
    11 
    12 #ifdef __cplusplus
    13 extern "C" {
    14 #endif
    15 
    16 /* ELF support */
    17 
    18 extern status_t boot_arch_elf_relocate_rel(struct preloaded_image *image,
    19     struct Elf32_Rel *rel, int rel_len);
    20 extern status_t boot_arch_elf_relocate_rela(struct preloaded_image *image,
    21     struct Elf32_Rela *rel, int rel_len);
    22 
    23 
    24 #ifdef __cplusplus
    25 }
    26 #endif
    27 
    28 #endif  /* KERNEL_BOOT_ARCH_H */
     1/*
     2 * Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef KERNEL_BOOT_ARCH_H
     6#define KERNEL_BOOT_ARCH_H
     7
     8#include <SupportDefs.h>
     9#include <boot/elf.h>
     10
     11
     12#ifdef __cplusplus
     13extern "C" {
     14#endif
     15
     16/* ELF support */
     17
     18extern status_t boot_arch_elf_relocate_rel(struct preloaded_image *image,
     19    struct Elf32_Rel *rel, int rel_len);
     20extern status_t boot_arch_elf_relocate_rela(struct preloaded_image *image,
     21    struct Elf32_Rela *rel, int rel_len);
     22
     23extern status_t boot_arch_elf64_relocate_rel(struct preloaded_image *image,
     24    struct Elf64_Rel *rel, int rel_len);
     25extern status_t boot_arch_elf64_relocate_rela(struct preloaded_image *image,
     26    struct Elf64_Rela *rel, int rel_len);
     27
     28
     29#ifdef __cplusplus
     30}
     31#endif
     32
     33#endif  /* KERNEL_BOOT_ARCH_H */
  • headers/private/kernel/boot/addr_range.h

     
    66#ifndef KERNEL_BOOT_ADDR_RANGE_H
    77#define KERNEL_BOOT_ADDR_RANGE_H
    88
    9 
    109#include <SupportDefs.h>
    1110
    12 
    1311typedef struct addr_range {
    14     addr_t start;
    15     size_t size;
     12    uint64 start;
     13    uint64 size;
    1614} addr_range;
    1715
    1816
    1917typedef struct phys_addr_range {
    20     phys_addr_t start;
    21     phys_size_t size;
     18    uint64 start;
     19    uint64 size;
    2220} phys_addr_range;
    2321
    24 
    2522#ifdef __cplusplus
    2623extern "C" {
    2724#endif
  • headers/private/kernel/elf_priv.h

     
    1010
    1111
    1212#include <elf32.h>
     13#include <elf64.h>
    1314#include <image.h>
    1415
    1516
     
    3435    addr_t      dynamic_section;        // pointer to the dynamic section
    3536    struct elf_linked_image *linked_images;
    3637
    37     struct Elf32_Ehdr *elf_header;
     38    union{
     39        struct Elf32_Ehdr *elf_header;
     40        struct Elf64_Ehdr *elf_header64;
     41    };
    3842
    3943    // pointer to symbol participation data structures
    4044    char        *needed;
    4145    uint32      *symhash;
    42     struct Elf32_Sym *syms;
     46    union{
     47        struct Elf32_Sym *syms;
     48        struct Elf64_Sym *syms64;
     49    };
    4350    char        *strtab;
    44     struct Elf32_Rel *rel;
     51    union{
     52        struct Elf32_Rel *rel;
     53        struct Elf64_Rel *rel64;
     54    };
    4555    int         rel_len;
    46     struct Elf32_Rela *rela;
     56    union{
     57        struct Elf32_Rela *rela;
     58        struct Elf64_Rela *rela64;
     59    };
    4760    int         rela_len;
    48     struct Elf32_Rel *pltrel;
     61    union{
     62        struct Elf32_Rel *pltrel;
     63        struct Elf64_Rel *pltrel64;
     64    };
    4965    int         pltrel_len;
    5066    int         pltrel_type;
    51 
    52     struct Elf32_Sym *debug_symbols;
     67    union{
     68        struct Elf32_Sym *debug_symbols;
     69        struct Elf64_Sym *debug_symbols64;
     70    };
    5371    uint32      num_debug_symbols;
    5472    const char  *debug_string_table;
    5573
    5674    // versioning related structures
    5775    uint32              num_version_definitions;
    58     struct Elf32_Verdef *version_definitions;
     76    union{
     77        struct Elf32_Verdef *version_definitions;
     78        struct Elf64_Verdef *version_definitions64;
     79    };
    5980    uint32              num_needed_versions;
    60     struct Elf32_Verneed *needed_versions;
    61     Elf32_Versym        *symbol_versions;
     81    union{
     82        struct Elf32_Verneed    *needed_versions;
     83        struct Elf64_Verneed    *needed_versions64;
     84    };
     85    union{
     86        Elf32_Versym        *symbol_versions;
     87        Elf64_Versym        *symbol_versions64;
     88    };
    6289    struct elf_version_info *versions;
    6390    uint32              num_versions;
    6491};
     
    6794#define STRING(image, offset) ((char *)(&(image)->strtab[(offset)]))
    6895#define SYMNAME(image, sym) STRING(image, (sym)->st_name)
    6996#define SYMBOL(image, num) ((struct Elf32_Sym *)&(image)->syms[num])
     97#define SYMBOL64(image, num) ((struct Elf64_Sym *)&(image)->syms64[num])
    7098#define HASHTABSIZE(image) ((image)->symhash[0])
    7199#define HASHBUCKETS(image) ((unsigned int *)&(image)->symhash[2])
    72100#define HASHCHAINS(image) ((unsigned int *)&(image)->symhash[2+HASHTABSIZE(image)])
  • headers/private/kernel/util/FixedWidthPointer.h

     
     1/*
     2 * Distributed under the terms of the MIT License.
     3 */
     4#ifndef KERNEL_UTIL_FIXED_WIDTH_POINTER_H
     5#define KERNEL_UTIL_FIXED_WIDTH_POINTER_H
     6
     7
     8#include <SupportDefs.h>
     9
     10
     11template<typename Type>
     12class FixedWidthPointer {
     13public:
     14        operator Type*() const
     15        {
     16                return (Type*)(addr_t)fValue;
     17        }
     18
     19        operator addr_t() const
     20        {
     21                return (addr_t)fValue;
     22        }
     23
     24        Type& operator*() const
     25        {
     26                return *(Type*)*this;
     27        }
     28
     29        Type* operator->() const
     30        {
     31                return *this;
     32        }
     33
     34        FixedWidthPointer<Type> operator=(void* pointer)
     35        {
     36                fValue = (addr_t)pointer;
     37                return *this;
     38        }
     39private:
     40        uint64  fValue;
     41};
     42
     43
     44#endif  // _KERNEL_UTIL_FIXED_WIDTH_POINTER_H
  • headers/private/kernel/arch/x86/arch_kernel_args.h

     
    2121    // architecture specific
    2222    uint32  system_time_cv_factor;
    2323    uint64  cpu_clock_speed;
     24    uint64  vir_pml4;
     25    uint64  phys_pml4;
     26    uint64  vir_pgdirpointer;   //pml3
     27    uint64  phys_pgdirpointer;
    2428    uint32  phys_pgdir;
    2529    uint32  vir_pgdir;
    2630    uint32  num_pgtables;
  • headers/private/kernel/arch/x86/descriptors.h

     
    9191
    9292static inline void
    9393set_segment_descriptor(struct segment_descriptor *desc, addr_t base, uint32 limit,
    94     uint8 type, uint8 privilegeLevel)
     94    uint8 type, uint8 privilegeLevel, bool longmode)
    9595{
    9696    set_segment_descriptor_base(desc, base);
    9797
     
    114114
    115115    desc->present = 1;
    116116    desc->available = 0;    // system available bit is currently not used
    117     desc->d_b = 1;          // 32-bit code
    118 
    119     desc->zero = 0;
     117    if(longmode)
     118    {
     119        desc->d_b = 0;      // 32-bit code
     120        desc->zero = 1;     // 64-bit code
     121    }
     122    else
     123    {
     124        desc->d_b = 1;      // 32-bit code
     125        desc->zero = 0;     // 64-bit code
     126    }
    120127}
    121128
    122129
  • headers/private/kernel/arch/x86/apm.h

     
    55#ifndef KERNEL_APM_H
    66#define KERNEL_APM_H
    77
    8 #include <SupportDefs.h>
     8#include "../x86_common/apm_common.h"
    99
    10 #include <apm_defs.h>
    1110
    12 
    13 struct kernel_args;
    14 
    15 
    16 // int 0x15 APM definitions
    17 #define BIOS_APM_CHECK              0x5300
    18 #define BIOS_APM_CONNECT_32_BIT     0x5303
    19 #define BIOS_APM_DISCONNECT         0x5304
    20 #define BIOS_APM_CPU_IDLE           0x5305
    21 #define BIOS_APM_CPU_BUSY           0x5306
    22 #define BIOS_APM_SET_STATE          0x5307
    23 #define BIOS_APM_ENABLE             0x5308
    24 #define BIOS_APM_GET_POWER_STATUS   0x530a
    25 #define BIOS_APM_GET_EVENT          0x530b
    26 #define BIOS_APM_GET_STATE          0x530c
    27 #define BIOS_APM_VERSION            0x530e
    28 #define BIOS_APM_ENGAGE             0x530f
    29 
    30 // APM devices
    31 #define APM_ALL_DEVICES             0x0001
    32 
    33 // APM power states
    34 #define APM_POWER_STATE_ENABLED     0x0000
    35 #define APM_POWER_STATE_STANDBY     0x0001
    36 #define APM_POWER_STATE_SUSPEND     0x0002
    37 #define APM_POWER_STATE_OFF         0x0003
    38 
    39 typedef struct apm_info {
    40     uint16  version;
    41     uint16  flags;
    42     uint16  code32_segment_base;
    43     uint32  code32_segment_offset;
    44     uint16  code32_segment_length;
    45     uint16  code16_segment_base;
    46     uint16  code16_segment_length;
    47     uint16  data_segment_base;
    48     uint16  data_segment_length;
    49 } apm_info;
    50 
    51 
    52 #ifndef _BOOT_MODE
    53 #ifdef __cplusplus
    54 extern "C" {
    55 #endif
    56 
    57 status_t apm_shutdown(void);
    58 status_t apm_init(struct kernel_args *args);
    59 
    60 #ifdef __cplusplus
    61 }
    62 #endif
    63 #endif  // !_BOOT_MODE
    64 
    6511#endif  /* KERNEL_APM_H */
  • headers/private/kernel/arch/elf.h

     
    99struct Elf32_Rela;
    1010struct elf_image_info;
    1111
    12 #ifdef __cplusplus
    13 extern "C" {
    14 #endif
    15 
    1612extern int arch_elf_relocate_rel(struct elf_image_info *image,
    1713    struct elf_image_info *resolve_image, struct Elf32_Rel *rel, int rel_len);
    1814extern int arch_elf_relocate_rela(struct elf_image_info *image,
    1915    struct elf_image_info *resolve_image, struct Elf32_Rela *rel, int rel_len);
    2016
    21 #ifdef __cplusplus
    22 }
    23 #endif
    24 
    2517#include <arch_elf.h>
    2618
    2719#endif  /* _KERNEL_ARCH_ELF_H */
  • headers/private/kernel/arch/x86_common/apm_common.h

     
     1/*
     2 * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef KERNEL_APM_COMMON_H
     6#define KERNEL_APM_COMMON_H
     7
     8#include <SupportDefs.h>
     9
     10#include <apm_defs.h>
     11
     12
     13struct kernel_args;
     14
     15
     16// int 0x15 APM definitions
     17#define BIOS_APM_CHECK              0x5300
     18#define BIOS_APM_CONNECT_32_BIT     0x5303
     19#define BIOS_APM_DISCONNECT         0x5304
     20#define BIOS_APM_CPU_IDLE           0x5305
     21#define BIOS_APM_CPU_BUSY           0x5306
     22#define BIOS_APM_SET_STATE          0x5307
     23#define BIOS_APM_ENABLE             0x5308
     24#define BIOS_APM_GET_POWER_STATUS   0x530a
     25#define BIOS_APM_GET_EVENT          0x530b
     26#define BIOS_APM_GET_STATE          0x530c
     27#define BIOS_APM_VERSION            0x530e
     28#define BIOS_APM_ENGAGE             0x530f
     29
     30// APM devices
     31#define APM_ALL_DEVICES             0x0001
     32
     33// APM power states
     34#define APM_POWER_STATE_ENABLED     0x0000
     35#define APM_POWER_STATE_STANDBY     0x0001
     36#define APM_POWER_STATE_SUSPEND     0x0002
     37#define APM_POWER_STATE_OFF         0x0003
     38
     39typedef struct apm_info {
     40    uint16  version;
     41    uint16  flags;
     42    uint16  code32_segment_base;
     43    uint32  code32_segment_offset;
     44    uint16  code32_segment_length;
     45    uint16  code16_segment_base;
     46    uint16  code16_segment_length;
     47    uint16  data_segment_base;
     48    uint16  data_segment_length;
     49} apm_info;
     50
     51
     52#ifndef _BOOT_MODE
     53#ifdef __cplusplus
     54extern "C" {
     55#endif
     56
     57status_t apm_shutdown(void);
     58status_t apm_init(struct kernel_args *args);
     59
     60#ifdef __cplusplus
     61}
     62#endif
     63#endif  // !_BOOT_MODE
     64
     65#endif  /* KERNEL_APM_COMMON_H */
  • headers/private/kernel/arch/x86_64/arch_kernel_args.h

     
     1/*
     2 * Copyright 2010, Nathan Mentley, nathanmentley@gmail.com. All rights reserved.
     3 * Distributed under the terms of the NewOS License.
     4 *
     5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
     6 * Distributed under the terms of the NewOS License.
     7 */
     8#ifndef KERNEL_ARCH_x86_64_KERNEL_ARGS_H
     9#define KERNEL_ARCH_x86_64_KERNEL_ARGS_H
     10
     11#ifndef KERNEL_BOOT_KERNEL_ARGS_H
     12#   error This file is included from <boot/kernel_args.h> only
     13#endif
     14
     15#define MAX_BOOT_PTABLES 4
     16
     17#define _PACKED __attribute__((packed))
     18
     19#define IDT_LIMIT 0x800
     20#define GDT_LIMIT 0x800
     21
     22
     23#include <util/FixedWidthPointer.h>
     24
     25
     26// kernel args
     27typedef struct {
     28    // architecture specific
     29    uint32  system_time_cv_factor;
     30    uint64  cpu_clock_speed;
     31
     32    uint64  vir_pml4;
     33    uint64  phys_pml4;
     34
     35    uint64  vir_pgdirpointer;   //pml3
     36    uint64  phys_pgdirpointer;
     37
     38    uint32  phys_pgdir; //pml2
     39    uint32  vir_pgdir;
     40
     41    uint32  num_pgtables;
     42    uint32  pgtables[MAX_BOOT_PTABLES];
     43    uint32  virtual_end;
     44    uint32  phys_idt;
     45    uint32  vir_idt;
     46    uint32  phys_gdt;
     47    uint32  vir_gdt;
     48    uint32  page_hole;
     49    // smp stuff
     50    uint32  apic_time_cv_factor; // apic ticks per second
     51    uint32  apic_phys;
     52    FixedWidthPointer<uint32>   apic;
     53    uint32  ioapic_phys;
     54    FixedWidthPointer<uint32>   ioapic;
     55    uint32  cpu_apic_id[MAX_BOOT_CPUS];
     56    uint32  cpu_os_id[MAX_BOOT_CPUS];
     57    uint32  cpu_apic_version[MAX_BOOT_CPUS];
     58    // hpet stuff
     59    uint32  hpet_phys;
     60    FixedWidthPointer<uint32>   hpet;
     61} arch_kernel_args;
     62
     63#endif  /* KERNEL_ARCH_x86_64_KERNEL_ARGS_H */
  • headers/private/kernel/arch/x86_64/arch_vm_translation_map.h

     
     1/*
     2** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     3** Distributed under the terms of the OpenBeOS License.
     4*/
     5#ifndef _KERNEL_ARCH_x86_64_VM_TRANSLATION_MAP_H
     6#define _KERNEL_ARCH_x86_64_VM_TRANSLATION_MAP_H
     7
     8
     9#include <arch/vm_translation_map.h>
     10
     11
     12#endif /* _KERNEL_ARCH_x86_64_VM_TRANSLATION_MAP_H */
  • headers/private/kernel/arch/x86_64/arch_system_info.h

     
     1/*
     2 * Copyright 2010, Nathan Mentley, nathanmentley@gmail.com.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     6 * Distributed under the terms of the MIT License.
     7 */
     8#ifndef _KERNEL_ARCH_x86_64_SYSTEM_INFO_H
     9#define _KERNEL_ARCH_x86_64_SYSTEM_INFO_H
     10
     11
     12#include <OS.h>
     13
     14#ifdef __cplusplus
     15extern "C" {
     16#endif
     17
     18status_t get_current_cpuid(cpuid_info *info, uint64 rax);
     19uint32 get_eflags(void);
     20void set_eflags(uint32 value);
     21
     22status_t _user_get_cpuid(cpuid_info *info, uint64 rax, uint32 cpu);
     23
     24
     25#ifdef __cplusplus
     26}
     27#endif
     28
     29
     30#endif  /* _KRENEL_ARCH_x86_64_SYSTEM_INFO_H */
  • headers/private/kernel/arch/x86_64/arch_hpet.h

     
     1/*
     2 * Copyright 2008, Dustin Howett, dustin.howett@gmail.com. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef _KERNEL_ARCH_x86_64_HPET_H
     6#define _KERNEL_ARCH_x86_64_HPET_H
     7
     8#include <arch/x86_64/arch_acpi.h>
     9
     10/* All masks are 32 bits wide to represent relative bit locations */
     11/* Doing it this way is Required since the HPET only supports 32/64-bit aligned reads. */
     12
     13/* Global Capability Register Masks */
     14#define HPET_CAP_MASK_REVID         0x00000000000000FFULL
     15#define HPET_CAP_MASK_NUMTIMERS         0x0000000000001F00ULL
     16#define HPET_CAP_MASK_WIDTH         0x0000000000002000ULL
     17#define HPET_CAP_MASK_LEGACY            0x0000000000008000ULL
     18#define HPET_CAP_MASK_VENDOR_ID         0x00000000FFFF0000ULL
     19#define HPET_CAP_MASK_PERIOD            0xFFFFFFFF00000000ULL
     20
     21/* Retrieve Global Capabilities */
     22#define HPET_GET_REVID(regs)        ((regs)->capabilities & HPET_CAP_MASK_REVID)
     23#define HPET_GET_NUM_TIMERS(regs)   (((regs)->capabilities & HPET_CAP_MASK_NUMTIMERS) >> 8)
     24#define HPET_IS_64BIT(regs)     (((regs)->capabilities & HPET_CAP_MASK_WIDTH) >> 13)
     25#define HPET_IS_LEGACY_CAPABLE(regs)    (((regs)->capabilities & HPET_CAP_MASK_LEGACY) >> 15)
     26#define HPET_GET_VENDOR_ID(regs)    (((regs)->capabilities & HPET_CAP_MASK_VENDOR_ID) >> 16)
     27#define HPET_GET_PERIOD(regs)       (((regs)->capabilities & HPET_CAP_MASK_PERIOD) >> 32)
     28
     29/* Global Config Register Masks */
     30#define HPET_CONF_MASK_ENABLED          0x00000001
     31#define HPET_CONF_MASK_LEGACY           0x00000002
     32
     33/* Retrieve Global Configuration */
     34#define HPET_IS_ENABLED(regs)       ((regs)->config & HPET_CONF_MASK_ENABLED)
     35#define HPET_IS_LEGACY(regs)        (((regs)->config & HPET_CONF_MASK_LEGACY) >> 1)
     36
     37/* Timer Configuration and Capabilities*/
     38#define HPET_CAP_TIMER_MASK         0xFFFFFFFF00000000ULL
     39#define HPET_CONF_TIMER_INT_ROUTE_MASK      0x3e00UL
     40#define HPET_CONF_TIMER_INT_ROUTE_SHIFT     9   
     41#define HPET_CONF_TIMER_INT_TYPE        0x00000002UL
     42#define HPET_CONF_TIMER_INT_ENABLE      0x00000004UL
     43#define HPET_CONF_TIMER_TYPE            0x00000008UL
     44#define HPET_CONF_TIMER_VAL_SET         0x00000040UL
     45#define HPET_CONF_TIMER_32MODE          0x00000100UL
     46#define HPET_CONF_TIMER_FSB_ENABLE      0x00004000UL
     47#define HPET_CAP_TIMER_PER_INT          0x00000010UL
     48#define HPET_CAP_TIMER_SIZE         0x00000020UL
     49#define HPET_CAP_TIMER_FSB_INT_DEL      0x00008000UL
     50
     51#define HPET_GET_CAP_TIMER_ROUTE(timer)     (((timer)->config & HPET_CAP_TIMER_MASK) >> 32)
     52#define HPET_GET_CONF_TIMER_INT_ROUTE(timer)    (((timer)->config & HPET_CONF_TIMER_INT_ROUTE_MASK) >> HPET_CONF_TIMER_INT_ROUTE_SHIFT)
     53
     54#define ACPI_HPET_SIGNATURE         "HPET"
     55
     56struct hpet_timer {
     57    /* Timer Configuration/Capability bits, Reversed because x86 is LSB */ 
     58    volatile uint64 config;
     59                    /* R/W: Each bit represents one allowed interrupt for this timer. */
     60                    /* If interrupt 16 is allowed, bit 16 will be 1. */
     61    union {
     62        volatile uint64 comparator64;   /* R/W: Comparator value */
     63        volatile uint32 comparator32;   
     64    } u0;               /* non-periodic mode: fires once when main counter = this comparator */
     65                    /* periodic mode: fires when timer reaches this value, is increased by the original value */
     66   
     67    volatile uint64 fsb_route[2];   /* R/W: FSB Interrupt Route values */
     68};
     69
     70
     71struct hpet_regs {
     72    volatile uint64 capabilities;       /* Read Only */
     73   
     74    volatile uint64 reserved1;
     75
     76    volatile uint64 config;         /* R/W: Config Bits */
     77
     78    volatile uint64 reserved2;
     79
     80    /* Interrupt Status bits */
     81    volatile uint64 interrupt_status;   /* Interrupt Config bits for timers 0-31 */
     82                        /* Level Tigger: 0 = off, 1 = set by hardware, timer is active */
     83                        /* Edge Trigger: ignored */
     84                        /* Writing 0 will not clear these. Must write 1 again. */
     85    volatile uint64 reserved3[25];
     86
     87    union {
     88        volatile uint64 counter64;  /* R/W */
     89        volatile uint32 counter32;
     90    } u0;
     91
     92    volatile uint64 reserved4;
     93
     94    volatile struct hpet_timer timer[1];
     95};
     96
     97
     98typedef struct acpi_hpet {
     99    acpi_descriptor_header  header; /* "HPET" signature and acpi header */
     100    uint16  vendor_id;
     101    uint8   legacy_capable : 1;
     102    uint8   reserved1 : 1;
     103    uint8   countersize : 1;
     104    uint8   comparators : 5;
     105    uint8   hw_revision;
     106    struct hpet_addr {
     107        uint8   address_space;
     108        uint8   register_width;
     109        uint8   register_offset;
     110        uint8   reserved;
     111        uint64  address;
     112    } hpet_address;
     113    uint8   number;
     114    uint16  min_tick;
     115} _PACKED acpi_hpet;
     116
     117#endif
  • headers/private/kernel/arch/x86_64/descriptors.h

     
     1/*
     2 * Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
     6 * Distributed under the terms of the NewOS License.
     7 */
     8#ifndef _KERNEL_ARCH_x86_64_DESCRIPTORS_H
     9#define _KERNEL_ARCH_x86_64_DESCRIPTORS_H
     10
     11
     12#define KERNEL_CODE_SEG 0x8
     13#define KERNEL_DATA_SEG 0x10
     14
     15#define USER_CODE_SEG   0x1b
     16#define USER_DATA_SEG   0x23
     17
     18#ifndef _ASSEMBLER
     19    // this file can also be included from assembler as well
     20    // (and is in arch_interrupts.S)
     21
     22
     23#define DOUBLE_FAULT_TSS_BASE_SEGMENT 9
     24#define TSS_BASE_SEGMENT (DOUBLE_FAULT_TSS_BASE_SEGMENT + smp_get_num_cpus())
     25#define TLS_BASE_SEGMENT (TSS_BASE_SEGMENT + smp_get_num_cpus())
     26
     27
     28// defines entries in the GDT/LDT
     29
     30typedef struct segment_descriptor {
     31    uint16 limit_00_15;             // bit   0 - 15
     32    uint16 base_00_15;              //      16 - 31
     33    uint32 base_23_16 : 8;          //       0 -  7
     34    uint32 type : 4;                //       8 - 11
     35    uint32 desc_type : 1;           //      12      (0 = system, 1 = code/data)
     36    uint32 privilege_level : 2;     //      13 - 14
     37    uint32 present : 1;             //      15
     38    uint32 limit_19_16 : 4;         //      16 - 19
     39    uint32 available : 1;           //      20
     40    uint32 zero : 1;                //      21
     41    uint32 d_b : 1;                 //      22
     42    uint32 granularity : 1;         //      23
     43    uint32 base_31_24 : 8;          //      24 - 31
     44} segment_descriptor;
     45
     46enum descriptor_privilege_levels {
     47    DPL_KERNEL = 0,
     48    DPL_USER = 3,
     49};
     50
     51enum descriptor_types {
     52    // segment types
     53    DT_CODE_EXECUTE_ONLY = 0x8,
     54    DT_CODE_ACCESSED = 0x9,
     55    DT_CODE_READABLE = 0xa,
     56    DT_CODE_CONFORM = 0xc,
     57    DT_DATA_READ_ONLY = 0x0,
     58    DT_DATA_ACCESSED = 0x1,
     59    DT_DATA_WRITEABLE = 0x2,
     60    DT_DATA_EXPANSION_DOWN = 0x4,
     61
     62    DT_TSS = 9,
     63        /* non busy, 32 bit */
     64
     65    // descriptor types
     66    DT_SYSTEM_SEGMENT = 0,
     67    DT_CODE_DATA_SEGMENT = 1,
     68};
     69
     70static inline void
     71clear_segment_descriptor(struct segment_descriptor *desc)
     72{
     73    *(long long *)desc = 0;
     74}
     75
     76
     77static inline void
     78set_segment_descriptor_base(struct segment_descriptor *desc, addr_t base)
     79{
     80    desc->base_00_15 = (addr_t)base & 0xffff;   // base is 32 bits long
     81    desc->base_23_16 = ((addr_t)base >> 16) & 0xff;
     82    desc->base_31_24 = ((addr_t)base >> 24) & 0xff;
     83}
     84
     85
     86static inline void
     87set_segment_descriptor(struct segment_descriptor *desc, addr_t base, uint32 limit,
     88    uint8 type, uint8 privilegeLevel, bool longmode)
     89{
     90    set_segment_descriptor_base(desc, base);
     91
     92    // limit is 20 bits long
     93    if (limit & 0xfff00000) {
     94        desc->limit_00_15 = ((addr_t)limit >> 12) & 0x0ffff;
     95        desc->limit_19_16 = ((addr_t)limit >> 28) & 0xf;
     96        desc->granularity = 1;  // 4 KB granularity
     97    } else {
     98        desc->limit_00_15 = (addr_t)limit & 0x0ffff;
     99        desc->limit_19_16 = ((addr_t)limit >> 16) & 0xf;
     100        desc->granularity = 0;  // 1 byte granularity
     101    }
     102        limit >>= 12;
     103
     104
     105    desc->type = type;
     106    desc->desc_type = DT_CODE_DATA_SEGMENT;
     107    desc->privilege_level = privilegeLevel;
     108
     109    desc->present = 1;
     110    desc->available = 0;    // system available bit is currently not used
     111    if(longmode)
     112    {
     113        desc->d_b = 0;      // 32-bit code
     114        desc->zero = 1;     // 64-bit code
     115    }
     116    else
     117    {
     118        desc->d_b = 1;      // 32-bit code
     119        desc->zero = 0;     // 64-bit code
     120    }
     121}
     122
     123
     124static inline void
     125set_tss_descriptor(struct segment_descriptor *desc, addr_t base, uint32 limit)
     126{
     127    // the TSS descriptor has a special layout different from the standard descriptor
     128    set_segment_descriptor_base(desc, base);
     129
     130    desc->limit_00_15 = (addr_t)limit & 0x0ffff;
     131    desc->limit_19_16 = 0;
     132
     133    desc->type = DT_TSS;
     134    desc->desc_type = DT_SYSTEM_SEGMENT;
     135    desc->privilege_level = DPL_KERNEL;
     136
     137    desc->present = 1;
     138    desc->granularity = 0;  // 1 Byte granularity
     139    desc->available = 0;    // system available bit is currently not used
     140    desc->d_b = 0;
     141
     142    desc->zero = 0;
     143}
     144
     145#endif  /* _ASSEMBLER */
     146
     147#endif  /* _KERNEL_ARCH_x86_64_DESCRIPTORS_H */
  • headers/private/kernel/arch/x86_64/arch_vm_types.h

     
     1/*
     2 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef _KERNEL_ARCH_x86_64_VM_TYPES_H
     6#define _KERNEL_ARCH_x86_64_VM_TYPES_H
     7
     8
     9#endif  /* _KERNEL_ARCH_x86_64_VM_TYPES_H */
  • headers/private/kernel/arch/x86_64/arch_thread.h

     
     1/*
     2 * Copyright 2002-2010, The Haiku Team. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2002, Travis Geiselbrecht. All rights reserved.
     6 * Distributed under the terms of the NewOS License.
     7 */
     8#ifndef _KERNEL_ARCH_x86_64_THREAD_H
     9#define _KERNEL_ARCH_x86_64_THREAD_H
     10
     11
     12#include <arch/cpu.h>
     13
     14
     15#ifdef __cplusplus
     16extern "C" {
     17#endif
     18
     19struct iframe *x86_64_get_current_iframe(void);
     20struct iframe *x86_64_get_user_iframe(void);
     21
     22uint64 x86_64_next_page_directory(struct thread *from, struct thread *to);
     23
     24void x86_64_return_from_signal();
     25void x86_64_end_return_from_signal();
     26
     27// override empty macro
     28#undef arch_syscall_64_bit_return_value
     29void arch_syscall_64_bit_return_value(void);
     30
     31
     32static
     33inline struct thread *
     34arch_thread_get_current_thread(void)
     35{
     36    struct thread *t;
     37    read_dr3(t);
     38    return t;
     39}
     40
     41static inline void
     42arch_thread_set_current_thread(struct thread *t)
     43{
     44    write_dr3(t);
     45}
     46
     47
     48#ifdef __cplusplus
     49}
     50#endif
     51
     52
     53#endif /* _KERNEL_ARCH_x86_64_THREAD_H */
  • headers/private/kernel/arch/x86_64/arch_acpi.h

     
     1/*
     2 * Copyright 2008, Dustin Howett, dustin.howett@gmail.com. All rights reserved.
     3 * Copyright 2007, Michael Lotz, mmlr@mlotz.ch. All rights reserved.
     4 * Distributed under the terms of the MIT License.
     5 */
     6#ifndef _KERNEL_ARCH_x86_64_ARCH_ACPI_H
     7#define _KERNEL_ARCH_x86_64_ARCH_ACPI_H
     8
     9
     10typedef struct acpi_descriptor_header {
     11    char    signature[4];           /* table identifier as ASCII string */
     12    uint32  length;                 /* length in bytes of the entire table */
     13    uint8   revision;
     14    uint8   checksum;               /* checksum of entire table */
     15    char    oem_id[6];              /* not null terminated */
     16    char    oem_table_id[8];        /* oem supplied table identifier */
     17    uint32  oem_revision;           /* oem supplied revision number */
     18    char    creator_id[4];          /* creator / asl compiler id */
     19    uint32  creator_revision;       /* compiler revision */
     20} _PACKED acpi_descriptor_header;
     21
     22
     23#endif  /* _KERNEL_ARCH_x86_64_ARCH_ACPI_H */
  • headers/private/kernel/arch/x86_64/apic.h

     
     1/*
     2 * Copyright 2008, Dustin Howett, dustin.howett@gmail.com. All rights reserved.
     3 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     4 * Distributed under the terms of the MIT License.
     5 *
     6 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
     7 * Distributed under the terms of the NewOS License.
     8 */
     9#ifndef _KERNEL_ARCH_x86_64_APIC_H
     10#define _KERNEL_ARCH_x86_64_APIC_H
     11
     12#include <boot/kernel_args.h>
     13#include <SupportDefs.h>
     14
     15#define APIC_ENABLE             0x100
     16#define APIC_FOCUS              (~(1 << 9))
     17#define APIC_SIV                (0xff)
     18
     19// offsets to APIC register
     20#define APIC_ID                         0x020
     21#define APIC_VERSION                    0x030
     22#define APIC_TASK_PRIORITY              0x080
     23#define APIC_ARBITRATION_PRIORITY       0x090
     24#define APIC_PROCESSOR_PRIORITY         0x0a0
     25#define APIC_EOI                        0x0b0
     26#define APIC_LOGICAL_DEST               0x0d0
     27#define APIC_DEST_FORMAT                0x0e0
     28#define APIC_SPURIOUS_INTR_VECTOR       0x0f0
     29#define APIC_ERROR_STATUS               0x280
     30#define APIC_INTR_COMMAND_1             0x300   // bits 0-31
     31#define APIC_INTR_COMMAND_2             0x310   // bits 32-63
     32#define APIC_LVT_TIMER                  0x320
     33#define APIC_LVT_THERMAL_SENSOR         0x330
     34#define APIC_LVT_PERFMON_COUNTERS       0x340
     35#define APIC_LVT_LINT0                  0x350
     36#define APIC_LVT_LINT1                  0x360
     37#define APIC_LVT_ERROR                  0x370
     38#define APIC_INITIAL_TIMER_COUNT        0x380
     39#define APIC_CURRENT_TIMER_COUNT        0x390
     40#define APIC_TIMER_DIVIDE_CONFIG        0x3e0
     41
     42/* standard APIC interrupt defines */
     43#define APIC_DELIVERY_MODE_FIXED                0
     44#define APIC_DELIVERY_MODE_LOWESTPRI            (1 << 8)    // ICR1 only
     45#define APIC_DELIVERY_MODE_SMI                  (2 << 8)
     46#define APIC_DELIVERY_MODE_NMI                  (4 << 8)
     47#define APIC_DELIVERY_MODE_INIT                 (5 << 8)
     48#define APIC_DELIVERY_MODE_STARTUP              (6 << 8)    // ICR1 only
     49#define APIC_DELIVERY_MODE_ExtINT               (7 << 8)    // LINT0/1 only
     50
     51#define APIC_DELIVERY_STATUS                    (1 << 12)
     52#define APIC_TRIGGER_MODE_LEVEL                 (1 << 15)
     53
     54/* Interrupt Command defines */
     55#define APIC_INTR_COMMAND_1_MASK                0xfff3f000
     56#define APIC_INTR_COMMAND_2_MASK                0x00ffffff
     57
     58#define APIC_INTR_COMMAND_1_DEST_MODE_PHYSICAL  0
     59#define APIC_INTR_COMMAND_1_DEST_MODE_LOGICAL   (1 << 11)
     60
     61#define APIC_INTR_COMMAND_1_ASSERT              (1 << 14)
     62
     63#define APIC_INTR_COMMAND_1_DEST_FIELD          0
     64#define APIC_INTR_COMMAND_1_DEST_SELF           (1 << 18)
     65#define APIC_INTR_COMMAND_1_DEST_ALL            (2 << 18)
     66#define APIC_INTR_COMMAND_1_DEST_ALL_BUT_SELF   (3 << 18)
     67
     68/* Local Vector Table defines */
     69#define APIC_LVT_MASKED                         (1 << 16)
     70
     71// timer defines
     72#define APIC_LVT_TIMER_MASK                     0xfffcef00
     73
     74// LINT0/1 defines
     75#define APIC_LVT_LINT_MASK                      0xfffe0800
     76#define APIC_LVT_LINT_INPUT_POLARITY            (1 << 13)
     77
     78// Timer Divide Config Divisors
     79#define APIC_TIMER_DIVIDE_CONFIG_1              0x0b
     80#define APIC_TIMER_DIVIDE_CONFIG_2              0x00
     81#define APIC_TIMER_DIVIDE_CONFIG_4              0x01
     82#define APIC_TIMER_DIVIDE_CONFIG_8              0x02
     83#define APIC_TIMER_DIVIDE_CONFIG_16             0x03
     84#define APIC_TIMER_DIVIDE_CONFIG_32             0x08
     85#define APIC_TIMER_DIVIDE_CONFIG_64             0x09
     86#define APIC_TIMER_DIVIDE_CONFIG_128            0x0a
     87
     88/*
     89#define APIC_LVT_DM             0x00000700
     90#define APIC_LVT_DM_ExtINT      0x00000700
     91#define APIC_LVT_DM_NMI         0x00000400
     92#define APIC_LVT_IIPP           0x00002000
     93#define APIC_LVT_TM             0x00008000
     94#define APIC_LVT_M              0x00010000
     95#define APIC_LVT_OS             0x00020000
     96
     97#define APIC_TPR_PRIO           0x000000ff
     98#define APIC_TPR_INT            0x000000f0
     99#define APIC_TPR_SUB            0x0000000f
     100
     101#define APIC_SVR_SWEN           0x00000100
     102#define APIC_SVR_FOCUS          0x00000200
     103
     104#define IOAPIC_ID               0x0
     105#define IOAPIC_VERSION          0x1
     106#define IOAPIC_ARB              0x2
     107#define IOAPIC_REDIR_TABLE      0x10
     108*/
     109
     110#if !_BOOT_MODE
     111
     112bool        apic_available();
     113uint32      apic_read(uint32 offset);
     114void        apic_write(uint32 offset, uint32 data);
     115uint32      apic_local_id();
     116void        apic_end_of_interrupt();
     117
     118status_t    apic_init(kernel_args *args);
     119status_t    apic_per_cpu_init(kernel_args *args, int32 cpu);
     120
     121#endif // !_BOOT_MODE
     122
     123#endif  /* _KERNEL_ARCH_x86_64_APIC_H */
  • headers/private/kernel/arch/x86_64/apm.h

     
     1/*
     2 * Copyright 2010, Nathan Mentley, nathanmentley@gmail.com. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 */
     5
     6
     7#ifndef KERNEL_APM_H
     8#define KERNEL_APM_H
     9
     10
     11#include "../x86_common/apm_common.h"
     12
     13
     14#endif  /* KERNEL_APM_H */
  • headers/private/kernel/arch/x86_64/arch_kernel.h

     
     1/*
     2 * Copyright 2004-2010, Haiku Inc. All rights reserved.
     3 * Distributes under the terms of the MIT license.
     4 *
     5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
     6 * Distributed under the terms of the NewOS License.
     7 */
     8#ifndef _KERNEL_ARCH_x86_64_KERNEL_H
     9#define _KERNEL_ARCH_x86_64_KERNEL_H
     10
     11#ifndef _ASSEMBLER
     12#   include <arch/cpu.h>
     13#endif
     14
     15// memory layout
     16#define KERNEL_BASE 0x80000000
     17#define KERNEL_SIZE 0x80000000
     18#define KERNEL_TOP  (KERNEL_BASE + (KERNEL_SIZE - 1))
     19
     20/* User space layout is a little special:
     21 * The user space does not completely cover the space not covered by the
     22 * kernel. There is a gap of 64kb between the user and kernel space. The 64kb
     23 * region assures a user space thread cannot pass a buffer into the kernel as
     24 * part of a syscall that would cross into kernel space.
     25 * Furthermore no areas are placed in the lower 1Mb unless the application
     26 * explicitly requests it to find null pointer references.
     27 */
     28#define USER_BASE     0x00
     29#define USER_BASE_ANY 0x100000
     30#define USER_SIZE     (KERNEL_BASE - 0x10000)
     31#define USER_TOP      (USER_BASE + USER_SIZE)
     32
     33#define KERNEL_USER_DATA_BASE   0x6fff0000
     34#define USER_STACK_REGION       0x70000000
     35#define USER_STACK_REGION_SIZE  (USER_TOP - USER_STACK_REGION)
     36
     37#endif  /* _KERNEL_ARCH_x86_64_KERNEL_H */
  • headers/private/kernel/arch/x86_64/arch_user_debugger.h

     
     1/*
     2 * Copyright 2010, Nathan Mentley, nathanmentley@gmail.com.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2005-2009, Ingo Weinhold, bonefish@users.sf.net.
     6 * Distributed under the terms of the MIT License.
     7 */
     8#ifndef _KERNEL_ARCH_X86_64_USER_DEBUGGER_H
     9#define _KERNEL_ARCH_X86_64_USER_DEBUGGER_H
     10
     11#define ARCH_INIT_USER_DEBUG x86_64_init_user_debug
     12
     13// number of breakpoints the CPU supports
     14// Actually it supports 4, but DR3 is used to hold the struct thread*.
     15#define X86_BREAKPOINT_COUNT    3
     16
     17
     18// debug status register DR6
     19enum {
     20    X86_DR6_B0          = 0,    // breakpoint condition detected
     21    X86_DR6_B1          = 1,    //
     22    X86_DR6_B2          = 2,    //
     23    X86_DR6_B3          = 3,    //
     24    X86_DR6_BD          = 13,   // debug register access detected
     25    X86_DR6_BS          = 14,   // single step
     26    X86_DR6_BT          = 15,   // task switch
     27
     28    X86_DR6_BREAKPOINT_MASK = (1 << X86_DR6_B0) | (1 << X86_DR6_B1)
     29                                | (1 << X86_DR6_B2) | (1 << X86_DR6_B3),
     30};
     31
     32// debug control register DR7 layout:
     33// 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
     34// LEN3  R/W3  LEN2  R/W2  LEN1  R/W1  LEN0  R/W0
     35//
     36// 15 14 13 12 11 10 9  8  7  6  5  4  3  2  1  0
     37// 0  0  GD 0  0  1  GE LE G3 L3 G2 L2 G1 L1 G0 L0
     38//
     39enum {
     40    X86_DR7_L0          = 0,    // local/global breakpoints enable
     41    X86_DR7_G0          = 1,    //
     42    X86_DR7_L1          = 2,    //
     43    X86_DR7_G1          = 3,    //
     44    X86_DR7_L2          = 4,    //
     45    X86_DR7_G2          = 5,    //
     46    X86_DR7_L3          = 6,    //
     47    X86_DR7_G3          = 7,    //
     48    X86_DR7_LE          = 8,    // local/global exact breakpoint
     49    X86_DR7_GE          = 9,    //
     50    X86_DR7_GD          = 13,   // general detect enable: disallows debug
     51                                // register access
     52    X86_DR7_RW0_LSB     = 16,   // breakpoints type and len
     53    X86_DR7_LEN0_LSB    = 18,   //
     54    X86_DR7_RW1_LSB     = 20,   //
     55    X86_DR7_LEN1_LSB    = 22,   //
     56    X86_DR7_RW2_LSB     = 24,   //
     57    X86_DR7_LEN2_LSB    = 26,   //
     58    X86_DR7_RW3_LSB     = 28,   //
     59    X86_DR7_LEN3_LSB    = 30,   //
     60
     61    X86_BREAKPOINTS_DISABLED_DR7
     62        = (1 << 10) | (1 << X86_DR7_GE) | (1 << X86_DR7_LE),
     63        // all breakpoints disabled
     64};
     65
     66// the EFLAGS flags we need
     67enum {
     68    X86_EFLAGS_CF   = 0,        // carry flag
     69    X86_EFLAGS_PF   = 2,        // parity flag
     70    X86_EFLAGS_AF   = 4,        // auxiliary carry flag (adjust flag)
     71    X86_EFLAGS_ZF   = 6,        // zero flag
     72    X86_EFLAGS_SF   = 7,        // sign flag
     73    X86_EFLAGS_TF   = 8,        // trap flag (single stepping)
     74    X86_EFLAGS_DF   = 10,       // direction flag
     75    X86_EFLAGS_OF   = 11,       // overflow flag
     76    X86_EFLAGS_RF   = 16,       // resume flag (skips instruction breakpoint)
     77
     78    X86_EFLAGS_USER_SETTABLE_FLAGS
     79        = (1 << X86_EFLAGS_CF) | (1 << X86_EFLAGS_PF) | (1 << X86_EFLAGS_AF)
     80            | (1 << X86_EFLAGS_ZF) | (1 << X86_EFLAGS_SF) | (1 << X86_EFLAGS_DF)
     81            | (1 << X86_EFLAGS_OF),
     82};
     83
     84// x86 breakpoint types
     85enum {
     86    X86_INSTRUCTION_BREAKPOINT      = 0x0,
     87    X86_DATA_WRITE_BREAKPOINT       = 0x1,
     88    X86_IO_READ_WRITE_BREAKPOINT    = 0x2,      // >= 586
     89    X86_DATA_READ_WRITE_BREAKPOINT  = 0x3,
     90};
     91
     92// x86 breakpoint lengths
     93enum {
     94    X86_BREAKPOINT_LENGTH_1 = 0x0,
     95    X86_BREAKPOINT_LENGTH_2 = 0x1,
     96    X86_BREAKPOINT_LENGTH_4 = 0x3,
     97};
     98
     99
     100struct arch_breakpoint {
     101    void    *address;   // NULL, if deactivated
     102    uint32  type;       // one of the architecture types above
     103    uint32  length;     // one of the length values above
     104};
     105
     106struct arch_team_debug_info {
     107    struct arch_breakpoint  breakpoints[X86_BREAKPOINT_COUNT];
     108
     109    uint64                  dr7;    // debug control register DR7
     110};
     111
     112struct arch_thread_debug_info {
     113    uint32  flags;
     114};
     115
     116
     117#ifdef __cplusplus
     118extern "C" {
     119#endif
     120
     121
     122extern void x86_64_init_user_debug();
     123extern void x86_64_init_user_debug_at_kernel_exit(struct iframe *frame);
     124
     125extern void x86_64_handle_debug_exception(struct iframe *frame);
     126extern void x86_64_handle_breakpoint_exception(struct iframe *frame);
     127
     128
     129#ifdef __cplusplus
     130}
     131#endif
     132
     133
     134#endif  // _KERNEL_ARCH_X86_64_USER_DEBUGGER_H
  • headers/private/kernel/arch/x86_64/arch_vm.h

     
     1/*
     2 * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef ARCH_x86_64_VM_H
     6#define ARCH_x86_64_VM_H
     7
     8
     9#define PAGE_SHIFT 12
     10
     11
     12#endif  /* ARCH_x86_64_VM_H */
  • headers/private/kernel/arch/x86_64/timer.h

     
     1/*
     2 * Copyright 2010, Nathan Mentley, nathanmentley@gmail.com.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
     6 * Distributed under the terms of the NewOS License.
     7 */
     8#ifndef _KERNEL_ARCH_X86_64_TIMER
     9#define _KERNEL_ARCH_X86_64_TIMER
     10
     11#define ISA_TIMER_MODULE_NAME "timers/x86_64/isa/v1"
     12#define APIC_TIMER_MODULE_NAME "timers/x86_64/apic/v1"
     13#define HPET_TIMER_MODULE_NAME "timers/x86_64/hpet/v1"
     14
     15#endif
     16
  • headers/private/kernel/arch/x86_64/arch_debug.h

     
     1/*
     2 * Copyright 2010, Nathan Mentley, nathanmentley@gmail.com.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
     6 * Distributed under the terms of the MIT License.
     7 */
     8#ifndef _KERNEL_ARCH_X86_64_DEBUG_H
     9#define _KERNEL_ARCH_X86_64_DEBUG_H
     10
     11
     12#include <SupportDefs.h>
     13
     14
     15struct arch_debug_registers {
     16    uint64  rbp;
     17};
     18
     19
     20#endif  // _KERNEL_ARCH_X86_64_DEBUG_H
  • headers/private/kernel/arch/x86_64/arch_cpu.h

     
     1/*
     2 * Copyright 2010, Nathan Mentley, nathanmentley@gmail.com.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
     6 * Distributed under the terms of the MIT License.
     7 *
     8 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
     9 * Distributed under the terms of the NewOS License.
     10 */
     11#ifndef _KERNEL_ARCH_x86_64_CPU_H
     12#define _KERNEL_ARCH_x86_64_CPU_H
     13
     14
     15#ifndef _ASSEMBLER
     16
     17#include <arch/x86_64/descriptors.h>
     18
     19
     20// MSR registers (possibly Intel specific)
     21#define IA32_MSR_TSC                    0x10
     22#define IA32_MSR_APIC_BASE              0x1b
     23
     24#define IA32_MSR_MTRR_CAPABILITIES      0xfe
     25#define IA32_MSR_SYSENTER_CS            0x174
     26#define IA32_MSR_SYSENTER_ESP           0x175
     27#define IA32_MSR_SYSENTER_EIP           0x176
     28#define IA32_MSR_MTRR_DEFAULT_TYPE      0x2ff
     29#define IA32_MSR_MTRR_PHYSICAL_BASE_0   0x200
     30#define IA32_MSR_MTRR_PHYSICAL_MASK_0   0x201
     31
     32
     33// x86 features from cpuid eax 1, edx register
     34#define IA32_FEATURE_FPU    0x00000001 // x87 fpu
     35#define IA32_FEATURE_VME    0x00000002 // virtual 8086
     36#define IA32_FEATURE_DE     0x00000004 // debugging extensions
     37#define IA32_FEATURE_PSE    0x00000008 // page size extensions
     38#define IA32_FEATURE_TSC    0x00000010 // rdtsc instruction
     39#define IA32_FEATURE_MSR    0x00000020 // rdmsr/wrmsr instruction
     40#define IA32_FEATURE_PAE    0x00000040 // extended 3 level page table addressing
     41#define IA32_FEATURE_MCE    0x00000080 // machine check exception
     42#define IA32_FEATURE_CX8    0x00000100 // cmpxchg8b instruction
     43#define IA32_FEATURE_APIC   0x00000200 // local apic on chip
     44#define IA32_FEATURE_SEP    0x00000800 // SYSENTER/SYSEXIT
     45#define IA32_FEATURE_MTRR   0x00001000 // MTRR
     46#define IA32_FEATURE_PGE    0x00002000 // paging global bit
     47#define IA32_FEATURE_MCA    0x00004000 // machine check architecture
     48#define IA32_FEATURE_CMOV   0x00008000 // cmov instruction
     49#define IA32_FEATURE_PAT    0x00010000 // page attribute table
     50#define IA32_FEATURE_PSE36  0x00020000 // page size extensions with 4MB pages
     51#define IA32_FEATURE_PSN    0x00040000 // processor serial number
     52#define IA32_FEATURE_CLFSH  0x00080000 // cflush instruction
     53#define IA32_FEATURE_DS     0x00200000 // debug store
     54#define IA32_FEATURE_ACPI   0x00400000 // thermal monitor and clock ctrl
     55#define IA32_FEATURE_MMX    0x00800000 // mmx instructions
     56#define IA32_FEATURE_FXSR   0x01000000 // FXSAVE/FXRSTOR instruction
     57#define IA32_FEATURE_SSE    0x02000000 // SSE
     58#define IA32_FEATURE_SSE2   0x04000000 // SSE2
     59#define IA32_FEATURE_SS     0x08000000 // self snoop
     60#define IA32_FEATURE_HTT    0x10000000 // hyperthreading
     61#define IA32_FEATURE_TM     0x20000000 // thermal monitor
     62#define IA32_FEATURE_PBE    0x80000000 // pending break enable
     63
     64// x86 features from cpuid eax 1, ecx register
     65#define IA32_FEATURE_EXT_SSE3           0x00000001  // SSE3
     66#define IA32_FEATURE_EXT_MONITOR        0x00000008  // MONITOR/MWAIT
     67#define IA32_FEATURE_EXT_DSCPL          0x00000010  // CPL qualified debug store
     68#define IA32_FEATURE_EXT_EST            0x00000080  // speedstep
     69#define IA32_FEATURE_EXT_TM2            0x00000100  // thermal monitor 2
     70#define IA32_FEATURE_EXT_CNXTID         0x00000400  // L1 context ID
     71
     72// x86 features from cpuid eax 0x80000001, edx register (AMD)
     73// only care about the ones that are unique to this register
     74#define IA32_FEATURE_AMD_EXT_SYSCALL    (1 << 11)   // SYSCALL/SYSRET
     75#define IA32_FEATURE_AMD_EXT_NX         (1 << 20)   // no execute bit
     76#define IA32_FEATURE_AMD_EXT_MMXEXT     (1 << 22)   // mmx extensions
     77#define IA32_FEATURE_AMD_EXT_FFXSR      (1 << 25)   // fast FXSAVE/FXRSTOR
     78#define IA32_FEATURE_AMD_EXT_RDTSCP     (1 << 27)   // rdtscp instruction
     79#define IA32_FEATURE_AMD_EXT_LONG       (1 << 29)   // long mode
     80#define IA32_FEATURE_AMD_EXT_3DNOWEXT   (1 << 30)   // 3DNow! extensions
     81#define IA32_FEATURE_AMD_EXT_3DNOW      (1 << 31)   // 3DNow!
     82
     83
     84// cr4 flags
     85#define IA32_CR4_PAE                    (1UL << 5)
     86#define IA32_CR4_GLOBAL_PAGES           (1UL << 7)
     87
     88
     89// Memory type ranges
     90#define IA32_MTR_UNCACHED               0
     91#define IA32_MTR_WRITE_COMBINING        1
     92#define IA32_MTR_WRITE_THROUGH          4
     93#define IA32_MTR_WRITE_PROTECTED        5
     94#define IA32_MTR_WRITE_BACK             6
     95
     96
     97// iframe types
     98#define IFRAME_TYPE_SYSCALL             0x1
     99#define IFRAME_TYPE_OTHER               0x2
     100#define IFRAME_TYPE_MASK                0xf
     101
     102
     103enum x86_feature_type {
     104    FEATURE_COMMON = 0,     // cpuid eax=1, ecx register
     105    FEATURE_EXT,            // cpuid eax=1, edx register
     106    FEATURE_EXT_AMD,        // cpuid eax=0x80000001, edx register (AMD)
     107
     108    FEATURE_NUM
     109};
     110
     111enum x86_vendors {
     112    VENDOR_INTEL = 0,
     113    VENDOR_AMD,
     114    VENDOR_CYRIX,
     115    VENDOR_UMC,
     116    VENDOR_NEXGEN,
     117    VENDOR_CENTAUR,
     118    VENDOR_RISE,
     119    VENDOR_TRANSMETA,
     120    VENDOR_NSC,
     121
     122    VENDOR_NUM,
     123    VENDOR_UNKNOWN,
     124};
     125
     126
     127struct tss {
     128    uint16 prev_task;
     129    uint16 unused0;
     130    uint32 sp0;
     131    uint32 ss0;
     132    uint32 sp1;
     133    uint32 ss1;
     134    uint32 sp2;
     135    uint32 ss2;
     136    uint32 cr3;
     137    uint64 rip, eflags, rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15;
     138    uint64 es, cs, ss, ds, fs, gs;
     139    uint32 ldt_seg_selector;
     140    uint16 unused1;
     141    uint16 io_map_base;
     142};
     143
     144
     145typedef struct arch_cpu_info {
     146    // saved cpu info
     147    enum x86_vendors    vendor;
     148    uint32              feature[FEATURE_NUM];
     149    char                model_name[49];
     150    const char*         vendor_name;
     151    int                 type;
     152    int                 family;
     153    int                 extended_family;
     154    int                 stepping;
     155    int                 model;
     156    int                 extended_model;
     157
     158    struct X86_64PagingStructures* active_paging_structures;
     159
     160    uint32              dr6;    // temporary storage for debug registers (cf.
     161    uint32              dr7;    // x86_exit_user_debug_at_kernel_entry())
     162
     163    // local TSS for this cpu
     164    struct tss          tss;
     165    struct tss          double_fault_tss;
     166} arch_cpu_info;
     167
     168#ifdef __cplusplus
     169extern "C" {
     170#endif
     171
     172extern segment_descriptor* gGDT;
     173
     174struct arch_thread;
     175
     176
     177struct iframe {
     178    uint64 type;    // iframe type
     179    uint64 gs;
     180    uint64 fs;
     181    uint64 es;
     182    uint64 ds;
     183    uint64 rdi;
     184    uint64 rsi;
     185    uint64 rbp;
     186    uint64 rsp;
     187    uint64 rbx;
     188    uint64 rdx;
     189    uint64 rcx;
     190    uint64 rax;
     191    uint64 r8;
     192    uint64 r9;
     193    uint64 r10;
     194    uint64 r11;
     195    uint64 r12;
     196    uint64 r13;
     197    uint64 r14;
     198    uint64 r15;
     199    uint64 orig_rax;
     200    uint64 orig_rdx;
     201    uint64 vector;
     202    uint64 error_code;
     203    uint64 rip;
     204    uint64 cs;
     205    uint32 flags;
     206
     207    // user_rsp and user_ss are only present when the iframe is a userland
     208    // iframe (IFRAME_IS_USER()). A kernel iframe is shorter.
     209    uint64 user_rsp;
     210    uint64 user_ss;
     211};
     212
     213
     214typedef struct x86_64_mtrr_info {
     215    uint64  base;
     216    uint64  size;
     217    uint8   type;
     218} x86_64_mtrr_info;
     219
     220
     221typedef struct x86_64_optimized_functions {
     222    void    (*memcpy)(void* dest, const void* source, size_t count);
     223    void*   memcpy_end;
     224    void    (*memset)(void* dest, int value, size_t count);
     225    void*   memset_end;
     226} x86_64_optimized_functions;
     227
     228
     229typedef struct x86_64_cpu_module_info {
     230//  module_info info;
     231    uint32      (*count_mtrrs)(void);
     232    void        (*init_mtrrs)(void);
     233
     234    void        (*set_mtrr)(uint32 index, uint64 base, uint64 length,
     235                    uint8 type);
     236    status_t    (*get_mtrr)(uint32 index, uint64* _base, uint64* _length,
     237                    uint8* _type);
     238    void        (*set_mtrrs)(uint8 defaultType, const x86_64_mtrr_info* infos,
     239                    uint32 count);
     240
     241    void        (*get_optimized_functions)(x86_64_optimized_functions* functions);
     242} x86_64_cpu_module_info;
     243
     244
     245/* cpu vendor info */
     246struct cpu_vendor_info {
     247    const char *vendor;
     248    const char *ident_string[2];
     249};
     250
     251static const struct cpu_vendor_info vendor_info[VENDOR_NUM] = {
     252    { "Intel", { "GenuineIntel" } },
     253    { "AMD", { "AuthenticAMD" } },
     254    { "Cyrix", { "CyrixInstead" } },
     255    { "UMC", { "UMC UMC UMC" } },
     256    { "NexGen", { "NexGenDriven" } },
     257    { "Centaur", { "CentaurHauls" } },
     258    { "Rise", { "RiseRiseRise" } },
     259    { "Transmeta", { "GenuineTMx86", "TransmetaCPU" } },
     260    { "NSC", { "Geode by NSC" } },
     261};
     262
     263
     264#define IFRAME_IS_USER(f) ((f)->cs == USER_CODE_SEG \
     265                            || ((f)->flags & 0x20000) != 0)
     266#define IFRAME_IS_VM86(f) (((f)->flags & 0x20000) != 0)
     267
     268
     269void __x86_64_setup_system_time(uint32 conversionFactor,
     270    uint32 conversionFactorNsecs, bool conversionFactorNsecsShift);
     271uint64 x86_64_read_rbp();
     272uint64 x86_64_read_cr0();
     273void x86_64_write_cr0(uint64 value);
     274uint64 x86_64_read_cr4();
     275void x86_64_write_cr4(uint64 value);
     276uint64 x86_64_read_msr(uint32 registerNumber);
     277void x86_64_write_msr(uint32 registerNumber, uint64 value);
     278
     279void x86_64_fxsave(void* fpuState);
     280void x86_64_fnsave(void *fpu_state);
     281void x86_64_fxrstor(const void* fpuState);
     282void x86_64_frstor(const void* fpuState);
     283void x86_64_fnsave_swap(void* oldFpuState, const void* newFpuState);
     284void x86_64_fxsave_swap(void* oldFpuState, const void* newFpuState);
     285
     286void* x86_64_get_double_fault_stack(int32 cpu, size_t* _size);
     287void* x86_64_set_tss_and_kstack(addr_t kstack);
     288void x86_64_set_task_gate(int32 cpu, int32 n, int32 segment);
     289
     290int64 x86_64_double_fault_get_cpu(void);
     291
     292void x86_64_set_mtrrs(uint8 defaultType, const x86_64_mtrr_info* infos,
     293    uint32 count);
     294uint32 x86_64_count_mtrrs(void);
     295
     296void x86_64_swap_pgdir(uint64 newPageDir);
     297void x86_64_context_switch(struct arch_thread* oldState,
     298    struct arch_thread* newState);
     299
     300void x86_64_enter_userspace(addr_t entry, addr_t stackTop);
     301void x86_64_userspace_thread_exit(void);
     302void x86_64_end_userspace_thread_exit(void);
     303
     304#define read_cr3(value) \
     305    __asm__("nop")
     306//  __asm__("mov    %%cr3,%0" : "=r" (value))
     307
     308#define write_cr3(value) \
     309    __asm__("nop")
     310//  __asm__("mov    %0,%%cr3" : : "r" (value))
     311
     312#define read_dr3(value) \
     313    __asm__("nop")
     314//  __asm__("mov    %%dr3,%0" : "=r" (value))
     315
     316#define write_dr3(value) \
     317    __asm__("nop")
     318//  __asm__("mov    %0,%%dr3" : : "r" (value))
     319
     320#define invalidate_TLB(va) \
     321    __asm__("invlpg (%0)" : : "r" (va))
     322
     323#define wbinvd() \
     324    __asm__("wbinvd")
     325
     326#define out8(value,port) \
     327    __asm__ ("outb %%al,%%dx" : : "a" (value), "d" (port))
     328
     329#define out16(value,port) \
     330    __asm__ ("outw %%ax,%%dx" : : "a" (value), "d" (port))
     331
     332#define out32(value,port) \
     333    __asm__ ("outl %%eax,%%dx" : : "a" (value), "d" (port))
     334
     335#define in8(port) ({ \
     336    uint8 _v; \
     337    __asm__ volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); \
     338    _v; \
     339})
     340
     341#define in16(port) ({ \
     342    uint16 _v; \
     343    __asm__ volatile ("inw %%dx,%%ax":"=a" (_v) : "d" (port)); \
     344    _v; \
     345})
     346
     347#define in32(port) ({ \
     348    uint32 _v; \
     349    __asm__ volatile ("inl %%dx,%%eax":"=a" (_v) : "d" (port)); \
     350    _v; \
     351})
     352
     353#ifdef __cplusplus
     354}   // extern "C" {
     355#endif
     356
     357#endif  // !_ASSEMBLER
     358
     359#endif  /* _KERNEL_ARCH_x86_64_CPU_H */
  • headers/private/kernel/arch/x86_64/arch_int.h

     
     1/*
     2 * Copyright 2010, Nathan Mentley, nathanmentley@gmail.com.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de.
     6 * Distributed under the terms of the MIT License.
     7 */
     8#ifndef _KERNEL_ARCH_x86_64_INT_H
     9#define _KERNEL_ARCH_x86_64_INT_H
     10
     11
     12#define ARCH_INTERRUPT_BASE 0x20
     13#define NUM_IO_VECTORS      (256 - ARCH_INTERRUPT_BASE)
     14
     15
     16void* x86_64_get_idt(int32 cpu);
     17
     18
     19static inline void
     20arch_int_enable_interrupts_inline(void)
     21{
     22    asm volatile("sti");
     23}
     24
     25
     26static inline int
     27arch_int_disable_interrupts_inline(void)
     28{
     29    int flags;
     30
     31    asm volatile("pushfq;\n"
     32        "pop %%rax;\n"
     33        "cli" : "=g" (flags));
     34    return flags ;
     35}
     36
     37
     38static inline void
     39arch_int_restore_interrupts_inline(int oldState)
     40{
     41    if (oldState & 0x200)
     42            asm volatile("sti");
     43}
     44
     45
     46static inline bool
     47arch_int_are_interrupts_enabled_inline(void)
     48{
     49    int flags;
     50
     51    asm volatile("pushfq;\n"
     52        "pop %%rax;\n" : "=g" (flags));
     53    return (flags & 0x200) != 0;
     54}
     55
     56
     57// map the functions to the inline versions
     58#define arch_int_enable_interrupts()    arch_int_enable_interrupts_inline()
     59#define arch_int_disable_interrupts()   arch_int_disable_interrupts_inline()
     60#define arch_int_restore_interrupts(status) \
     61    arch_int_restore_interrupts_inline(status)
     62#define arch_int_are_interrupts_enabled()   \
     63    arch_int_are_interrupts_enabled_inline()
     64
     65
     66#endif /* _KERNEL_ARCH_x86_64_INT_H */
  • headers/private/kernel/arch/x86_64/arch_thread_types.h

     
     1/*
     2 * Copyright 2002-2010, The Haiku Team. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
     6 * Distributed under the terms of the NewOS License.
     7 */
     8#ifndef _KERNEL_ARCH_x86_64_THREAD_TYPES_H
     9#define _KERNEL_ARCH_x86_64_THREAD_TYPES_H
     10
     11
     12#include <arch/cpu.h>
     13
     14#define _ALIGNED(bytes) __attribute__((aligned(bytes)))
     15    // move this to somewhere else, maybe BeBuild.h?
     16
     17struct farcall {
     18    uint64 *rsp;
     19    uint64 *ss;
     20};
     21
     22// architecture specific thread info
     23struct arch_thread {
     24    struct farcall current_stack;
     25    struct farcall interrupt_stack;
     26
     27    // 512 byte floating point save point - this must be 16 byte aligned
     28    char fpu_state[512];
     29} _ALIGNED(16);
     30
     31struct arch_team {
     32    // gcc treats empty structures as zero-length in C, but as if they contain
     33    // a char in C++. So we have to put a dummy in to be able to use the struct
     34    // from both in a consistent way.
     35    char    dummy;
     36};
     37
     38struct arch_fork_arg {
     39    struct iframe   iframe;
     40};
     41
     42
     43#endif  /* _KERNEL_ARCH_x86_64_THREAD_TYPES_H */
  • headers/private/system/elf32.h

     
    11/*
    2  * Copyright 2002-2009, Haiku Inc. All Rights Reserved.
     2 * Copyright 2002-2010, Haiku Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT license.
    44 *
    55 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
     
    88#ifndef _ELF32_H
    99#define _ELF32_H
    1010
    11 
    1211#include <SupportDefs.h>
    1312#include <ByteOrder.h>
    1413
    1514#include <arch_elf.h>
     15#include <elf_common.h>
    1616
    17 
    1817typedef uint32 Elf32_Addr;
    1918typedef uint16 Elf32_Half;
    2019typedef uint32 Elf32_Off;
     
    2524
    2625/*** ELF header ***/
    2726
    28 #define EI_NIDENT   16
    29 
    3027struct Elf32_Ehdr {
    3128    uint8       e_ident[EI_NIDENT];
    3229    Elf32_Half  e_type;
     
    4845#endif
    4946};
    5047
    51 #define ELF_MAGIC   "\x7f""ELF"
    52 
    53 // e_ident[] indices
    54 #define EI_MAG0     0
    55 #define EI_MAG1     1
    56 #define EI_MAG2     2
    57 #define EI_MAG3     3
    58 #define EI_CLASS    4
    59 #define EI_DATA     5
    60 #define EI_VERSION  6
    61 #define EI_PAD      7
    62 
    63 // architecture class (EI_CLASS)
    64 #define ELFCLASS32  1
    65 #define ELFCLASS64  2
    66 // endian (EI_DATA)
    67 #define ELFDATA2LSB 1   /* little endian */
    68 #define ELFDATA2MSB 2   /* big endian */
    69 
    70 
    7148/*** section header ***/
    7249
    7350struct Elf32_Shdr {
     
    8360    Elf32_Word  sh_entsize;
    8461};
    8562
    86 // special section indices
    87 #define SHN_UNDEF       0
    88 #define SHN_LORESERVE   0xff00
    89 #define SHN_LOPROC      0xff00
    90 #define SHN_HIPROC      0xff1f
    91 #define SHN_ABS         0xfff1
    92 #define SHN_COMMON      0xfff2
    93 #define SHN_HIRESERVE   0xffff
    9463
    95 // section header type
    96 #define SHT_NULL        0
    97 #define SHT_PROGBITS    1
    98 #define SHT_SYMTAB      2
    99 #define SHT_STRTAB      3
    100 #define SHT_RELA        4
    101 #define SHT_HASH        5
    102 #define SHT_DYNAMIC     6
    103 #define SHT_NOTE        7
    104 #define SHT_NOBITS      8
    105 #define SHT_REL         9
    106 #define SHT_SHLIB       10
    107 #define SHT_DYNSYM      11
    108 
    109 #define SHT_GNU_verdef  0x6ffffffd    /* version definition section */
    110 #define SHT_GNU_verneed 0x6ffffffe    /* version needs section */
    111 #define SHT_GNU_versym  0x6fffffff    /* version symbol table */
    112 
    113 #define SHT_LOPROC      0x70000000
    114 #define SHT_HIPROC      0x7fffffff
    115 #define SHT_LOUSER      0x80000000
    116 #define SHT_HIUSER      0xffffffff
    117 
    118 // section header flags
    119 #define SHF_WRITE       1
    120 #define SHF_ALLOC       2
    121 #define SHF_EXECINSTR   4
    122 
    123 #define SHF_MASKPROC    0xf0000000
    124 
    125 
    12664/*** program header ***/
    12765
    12866struct Elf32_Phdr {
     
    14179#endif
    14280};
    14381
    144 // program header segment types
    145 #define PT_NULL     0
    146 #define PT_LOAD     1
    147 #define PT_DYNAMIC  2
    148 #define PT_INTERP   3
    149 #define PT_NOTE     4
    150 #define PT_SHLIB    5
    151 #define PT_PHDR     6
    152 #define PT_STACK    0x6474e551
    153 
    154 #define PT_LOPROC   0x70000000
    155 #define PT_HIPROC   0x7fffffff
    156 
    157 // program header segment flags
    158 #define PF_EXECUTE  0x1
    159 #define PF_WRITE    0x2
    160 #define PF_READ     0x4
    161 #define PF_PROTECTION_MASK (PF_EXECUTE | PF_WRITE | PF_READ)
    162 
    163 #define PF_MASKPROC 0xf0000000
    164 
    16582struct Elf32_Sym {
    16683    Elf32_Word  st_name;
    16784    Elf32_Addr  st_value;
     
    18097#define ELF32_ST_TYPE(i) ((i) & 0xf)
    18198#define ELF32_ST_INFO(b, t) (((b) << 4) + ((t) & 0xf))
    18299
    183 #define STT_NOTYPE 0
    184 #define STT_OBJECT 1
    185 #define STT_FUNC 2
    186 #define STT_SECTION 3
    187 #define STT_FILE 4
    188 #define STT_LOPROC 13
    189 #define STT_HIPROC 15
    190 
    191 #define STB_LOCAL 0
    192 #define STB_GLOBAL 1
    193 #define STB_WEAK 2
    194 #define STB_LOPROC 13
    195 #define STB_HIPROC 15
    196 
    197 #define STN_UNDEF 0
    198 
    199100struct Elf32_Rel {
    200101    Elf32_Addr r_offset;
    201102    Elf32_Word r_info;
     
    228129    } d_un;
    229130};
    230131
    231 #define DT_NULL     0
    232 #define DT_NEEDED   1
    233 #define DT_PLTRELSZ 2
    234 #define DT_PLTGOT   3
    235 #define DT_HASH     4
    236 #define DT_STRTAB   5
    237 #define DT_SYMTAB   6
    238 #define DT_RELA     7
    239 #define DT_RELASZ   8
    240 #define DT_RELAENT  9
    241 #define DT_STRSZ    10
    242 #define DT_SYMENT   11
    243 #define DT_INIT     12
    244 #define DT_FINI     13
    245 #define DT_SONAME   14
    246 #define DT_RPATH    15
    247 #define DT_SYMBOLIC 16
    248 #define DT_REL      17
    249 #define DT_RELSZ    18
    250 #define DT_RELENT   19
    251 #define DT_PLTREL   20
    252 #define DT_DEBUG    21
    253 #define DT_TEXTREL  22
    254 #define DT_JMPREL   23
    255 
    256 #define DT_VERSYM       0x6ffffff0  /* symbol version table */
    257 #define DT_VERDEF       0x6ffffffc  /* version definition table */
    258 #define DT_VERDEFNUM    0x6ffffffd  /* number of version definitions */
    259 #define DT_VERNEED      0x6ffffffe  /* table with needed versions */
    260 #define DT_VERNEEDNUM   0x6fffffff  /* number of needed versions */
    261 
    262 #define DT_LOPROC       0x70000000
    263 #define DT_HIPROC       0x7fffffff
    264 
    265 
    266132/* version definition section */
    267133
    268134struct Elf32_Verdef {
     
    276142    Elf32_Word  vd_next;        /* byte offset to next verdef entry */
    277143};
    278144
    279 /* values for vd_version (version revision) */
    280 #define VER_DEF_NONE        0       /* no version */
    281 #define VER_DEF_CURRENT     1       /* current version */
    282 #define VER_DEF_NUM         2       /* given version number */
    283 
    284 /* values for vd_flags (version information flags) */
    285 #define VER_FLG_BASE        0x1     /* version definition of file itself */
    286 #define VER_FLG_WEAK        0x2     /* weak version identifier */
    287 
    288 /* values for versym symbol index */
    289 #define VER_NDX_LOCAL       0       /* symbol is local */
    290 #define VER_NDX_GLOBAL      1       /* symbol is global/unversioned */
    291 #define VER_NDX_INITIAL     2       /* initial version -- that's the one given
    292                                        to symbols when a library becomes
    293                                        versioned; handled by the linker (and
    294                                        runtime loader) similar to
    295                                        VER_NDX_GLOBAL */
    296 #define VER_NDX_LORESERVE   0xff00  /* beginning of reserved entries */
    297 #define VER_NDX_ELIMINATE   0xff01  /* symbol is to be eliminated */
    298 
    299 #define VER_NDX_FLAG_HIDDEN 0x8000  /* flag: version is hidden */
    300 #define VER_NDX_MASK        0x7fff  /* mask to get the actual version index */
    301 #define VER_NDX(x)          ((x) & VER_NDX_MASK)
    302 
    303 
    304145/* auxiliary version information */
    305146
    306147struct Elf32_Verdaux {
     
    321162    Elf32_Word  vn_next;        /* byte offset to next verneed entry */
    322163};
    323164
    324 /* values for vn_version (version revision) */
    325 #define VER_NEED_NONE       0   /* no version */
    326 #define VER_NEED_CURRENT    1   /* current version */
    327 #define VER_NEED_NUM        2   /* given version number */
    328 
    329 
    330165/* auxiliary needed version information */
    331166
    332167struct Elf32_Vernaux {
     
    338173    Elf32_Word  vna_next;       /* byte offset to next vernaux entry */
    339174};
    340175
    341 /* values for vna_flags */
    342 #define VER_FLG_WEAK    0x2     /* weak version identifier */
    343 
    344 
    345176/*** inline functions ***/
    346177
    347178#ifdef __cplusplus
  • headers/private/system/elf_common.h

     
     1/*
     2 * Copyright 2002-2010, Haiku Inc. All Rights Reserved.
     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#ifndef _ELF_COMMON_H
     9#define _ELF_COMMON_H
     10
     11#define EI_NIDENT   16
     12#define ELF_MAGIC   "\x7f""ELF"
     13
     14// e_ident[] indices
     15#define EI_MAG0     0
     16#define EI_MAG1     1
     17#define EI_MAG2     2
     18#define EI_MAG3     3
     19#define EI_CLASS    4
     20#define EI_DATA     5
     21#define EI_VERSION  6
     22#define EI_OSABI    7
     23#define EI_ABIVERSION   8
     24#define EI_PAD      9
     25
     26// architecture class (EI_CLASS)
     27#define ELFCLASS32  1
     28#define ELFCLASS64  2
     29// endian (EI_DATA)
     30#define ELFDATA2LSB 1   /* little endian */
     31#define ELFDATA2MSB 2   /* big endian */
     32
     33
     34// special section indices
     35#define SHN_LORESERVE       0xff00
     36#define SHN_HIRESERVE       0xffff
     37
     38#define SHN_UNDEF       0
     39#define SHN_LOPROC      0xff00
     40#define SHN_HIPROC      0xff1f
     41#define SHN_LODS        0xff20
     42#define SHN_HIOS        0xff3f
     43#define SHN_ABS         0xfff1
     44#define SHN_COMMON      0xfff2
     45
     46// section header type
     47#define SHT_NULL        0
     48#define SHT_PROGBITS        1
     49#define SHT_SYMTAB      2
     50#define SHT_STRTAB      3
     51#define SHT_RELA        4
     52#define SHT_HASH        5
     53#define SHT_DYNAMIC     6
     54#define SHT_NOTE        7
     55#define SHT_NOBITS      8
     56#define SHT_REL         9
     57#define SHT_SHLIB       10
     58#define SHT_DYNSYM      11
     59
     60#define SHT_GNU_verdef  0x6ffffffd    /* version definition section */
     61#define SHT_GNU_verneed 0x6ffffffe    /* version needs section */
     62#define SHT_GNU_versym  0x6fffffff    /* version symbol table */
     63
     64#define SHT_LODS        0x60000000
     65#define SHT_HIOS        0x6fffffff
     66#define SHT_LOPROC      0x70000000
     67#define SHT_HIPROC      0x7fffffff
     68#define SHT_LOUSER      0x80000000
     69#define SHT_HIUSER      0xffffffff
     70
     71// section header flags
     72#define SHF_WRITE       1
     73#define SHF_ALLOC       2
     74#define SHF_EXECINSTR       4
     75
     76#define SHF_MASKOS  0x0f000000
     77#define SHF_MASKPROC    0xf0000000
     78
     79// program header segment types
     80#define PT_NULL     0
     81#define PT_LOAD     1
     82#define PT_DYNAMIC  2
     83#define PT_INTERP   3
     84#define PT_NOTE     4
     85#define PT_SHLIB    5
     86#define PT_PHDR     6
     87#define PT_STACK    0x6474e551
     88
     89#define PT_LOOS     0x60000000
     90#define PT_HIOS     0x6fffffff
     91#define PT_LOPROC   0x70000000
     92#define PT_HIPROC   0x7fffffff
     93
     94// program header segment flags
     95#define PF_EXECUTE  0x1
     96#define PF_WRITE    0x2
     97#define PF_READ     0x4
     98#define PF_PROTECTION_MASK (PF_EXECUTE | PF_WRITE | PF_READ)
     99
     100#define PF_MASKOS   0x00ff0000
     101#define PF_MASKPROC 0xff000000
     102
     103#define STT_NOTYPE  0
     104#define STT_OBJECT  1
     105#define STT_FUNC    2
     106#define STT_SECTION 3
     107#define STT_FILE    4
     108#define STT_LOOS    10
     109#define STT_HIOS    12
     110#define STT_LOPROC  13
     111#define STT_HIPROC  15
     112
     113#define STB_LOCAL   0
     114#define STB_GLOBAL  1
     115#define STB_WEAK    2
     116#define STB_LOOS    10
     117#define STB_HIOS    11
     118#define STB_LOPROC  13
     119#define STB_HIPROC  15
     120
     121#define STN_UNDEF   0
     122
     123#define DT_NULL     0
     124#define DT_NEEDED   1
     125#define DT_PLTRELSZ 2
     126#define DT_PLTGOT   3
     127#define DT_HASH     4
     128#define DT_STRTAB   5
     129#define DT_SYMTAB   6
     130#define DT_RELA     7
     131#define DT_RELASZ   8
     132#define DT_RELAENT  9
     133#define DT_STRSZ    10
     134#define DT_SYMENT   11
     135#define DT_INIT     12
     136#define DT_FINI     13
     137#define DT_SONAME   14
     138#define DT_RPATH    15
     139#define DT_SYMBOLIC 16
     140#define DT_REL      17
     141#define DT_RELSZ    18
     142#define DT_RELENT   19
     143#define DT_PLTREL   20
     144#define DT_DEBUG    21
     145#define DT_TEXTREL  22
     146#define DT_JMPREL   23
     147#define DT_BIND_NOW 24
     148#define DT_INIT_ARRAY   25
     149#define DT_FINI_ARRAY   26
     150#define DT_INIT_ARRAYSZ 27
     151#define DT_FINI_ARRAYSZ 28
     152
     153
     154#define DT_VERSYM       0x6ffffff0  /* symbol version table */
     155#define DT_VERDEF       0x6ffffffc  /* version definition table */
     156#define DT_VERDEFNUM    0x6ffffffd  /* number of version definitions */
     157#define DT_VERNEED      0x6ffffffe  /* table with needed versions */
     158#define DT_VERNEEDNUM   0x6fffffff  /* number of needed versions */
     159
     160#define DT_LOPROC       0x70000000
     161#define DT_HIPROC       0x7fffffff
     162
     163
     164/* values for vd_version (version revision) */
     165#define VER_DEF_NONE        0       /* no version */
     166#define VER_DEF_CURRENT     1       /* current version */
     167#define VER_DEF_NUM         2       /* given version number */
     168
     169/* values for vd_flags (version information flags) */
     170#define VER_FLG_BASE        0x1     /* version definition of file itself */
     171#define VER_FLG_WEAK        0x2     /* weak version identifier */
     172
     173/* values for versym symbol index */
     174#define VER_NDX_LOCAL       0       /* symbol is local */
     175#define VER_NDX_GLOBAL      1       /* symbol is global/unversioned */
     176#define VER_NDX_INITIAL     2       /* initial version -- that's the one given
     177                                       to symbols when a library becomes
     178                                       versioned; handled by the linker (and
     179                                       runtime loader) similar to
     180                                       VER_NDX_GLOBAL */
     181#define VER_NDX_LORESERVE   0xff00  /* beginning of reserved entries */
     182#define VER_NDX_ELIMINATE   0xff01  /* symbol is to be eliminated */
     183
     184#define VER_NDX_FLAG_HIDDEN 0x8000  /* flag: version is hidden */
     185#define VER_NDX_MASK        0x7fff  /* mask to get the actual version index */
     186#define VER_NDX(x)          ((x) & VER_NDX_MASK)
     187
     188/* values for vn_version (version revision) */
     189#define VER_NEED_NONE       0   /* no version */
     190#define VER_NEED_CURRENT    1   /* current version */
     191#define VER_NEED_NUM        2   /* given version number */
     192
     193/* values for vna_flags */
     194#define VER_FLG_WEAK    0x2     /* weak version identifier */
     195
     196
     197#endif  /* _ELF_COMMON_H */
  • headers/private/system/elf64.h

     
     1/*
     2 * Copyright 2002-2010, Haiku Inc. All Rights Reserved.
     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#ifndef _ELF64_H
     9#define _ELF64_H
     10
     11#include <SupportDefs.h>
     12#include <ByteOrder.h>
     13
     14#include <arch_elf.h>
     15#include <elf_common.h>
     16
     17typedef uint64 Elf64_Addr;
     18typedef uint16 Elf64_Half;
     19typedef uint64 Elf64_Off;
     20typedef int32 Elf64_Sword;
     21typedef uint32 Elf64_Word;
     22typedef int64 Elf64_Sxword;
     23typedef uint64 Elf64_Xword;
     24
     25typedef Elf64_Half Elf64_Versym;
     26
     27/*** ELF header ***/
     28
     29struct Elf64_Ehdr {
     30    uint8       e_ident[EI_NIDENT];
     31    Elf64_Half  e_type;
     32    Elf64_Half  e_machine;
     33    Elf64_Word  e_version;
     34    Elf64_Addr  e_entry;
     35    Elf64_Off   e_phoff;
     36    Elf64_Off   e_shoff;
     37    Elf64_Word  e_flags;
     38    Elf64_Half  e_ehsize;
     39    Elf64_Half  e_phentsize;
     40    Elf64_Half  e_phnum;
     41    Elf64_Half  e_shentsize;
     42    Elf64_Half  e_shnum;
     43    Elf64_Half  e_shstrndx;
     44
     45#ifdef __cplusplus
     46    bool IsHostEndian() const;
     47#endif
     48};
     49
     50/*** section header ***/
     51
     52struct Elf64_Shdr {
     53    Elf64_Word  sh_name;
     54    Elf64_Word  sh_type;
     55    Elf64_Xword sh_flags;
     56    Elf64_Addr  sh_addr;
     57    Elf64_Off   sh_offset;
     58    Elf64_Xword sh_size;
     59    Elf64_Word  sh_link;
     60    Elf64_Word  sh_info;
     61    Elf64_Xword sh_addralign;
     62    Elf64_Xword sh_entsize;
     63};
     64
     65/*** program header ***/
     66
     67struct Elf64_Phdr {
     68    Elf64_Word  p_type;
     69    Elf64_Word  p_flags;
     70    Elf64_Off   p_offset;   /* offset from the beginning of the file of the segment */
     71    Elf64_Addr  p_vaddr;    /* virtual address for the segment in memory */
     72    Elf64_Addr  p_paddr;
     73    Elf64_Xword p_filesz;   /* the size of the segment in the file */
     74    Elf64_Xword p_memsz;    /* the size of the segment in memory */
     75    Elf64_Xword p_align;
     76
     77#ifdef __cplusplus
     78    bool IsReadWrite() const;
     79    bool IsExecutable() const;
     80#endif
     81};
     82
     83struct Elf64_Sym {
     84    Elf64_Word  st_name;
     85    uint8       st_info;
     86    uint8       st_other;
     87    Elf64_Half  st_shndx;
     88    Elf64_Addr  st_value;
     89    Elf64_Xword st_size;
     90
     91#ifdef __cplusplus
     92    uint8 Bind() const;
     93    uint8 Type() const;
     94#endif
     95};
     96
     97/* TODO: CHECK THESE DEFINES */
     98#define ELF64_ST_BIND(i) ((i) >> 8)
     99#define ELF64_ST_TYPE(i) ((i) & 0xffffffffL)
     100#define ELF64_ST_INFO(b, t) (((b) << 8) + ((t) & 0xffffffffL))
     101
     102struct Elf64_Rel {
     103    Elf64_Addr r_offset;
     104    Elf64_Xword r_info;
     105
     106#ifdef __cplusplus
     107    uint8 SymbolIndex() const;
     108    uint8 Type() const;
     109#endif
     110};
     111
     112#ifdef __cplusplus
     113struct Elf64_Rela : public Elf64_Rel {
     114#else
     115struct Elf64_Rela {
     116    Elf64_Addr r_offset;
     117    Elf64_Xword r_info;
     118#endif
     119    Elf64_Sxword r_addend;
     120};
     121
     122#define ELF64_R_SYM(i)((i) >> 32)
     123#define ELF64_R_TYPE(i)((i) & 0xffffffffL)
     124#define ELF64_R_INFO(s, t)(((s) << 32) + ((t) & 0xffffffffL))
     125
     126
     127struct Elf64_Dyn {
     128    Elf64_Sxword d_tag;
     129    union {
     130        Elf64_Xword d_val;
     131        Elf64_Addr d_ptr;
     132    } d_un;
     133};
     134
     135/* version definition section */
     136
     137struct Elf64_Verdef {
     138    Elf64_Half  vd_version;     /* version revision */
     139    Elf64_Half  vd_flags;       /* version information flags */
     140    Elf64_Half  vd_ndx;         /* version index as specified in the
     141                                   symbol version table */
     142    Elf64_Half  vd_cnt;         /* number of associated verdaux entries */
     143    Elf64_Word  vd_hash;        /* version name hash value */
     144    Elf64_Word  vd_aux;         /* byte offset to verdaux array */
     145    Elf64_Word  vd_next;        /* byte offset to next verdef entry */
     146};
     147
     148/* auxiliary version information */
     149
     150struct Elf64_Verdaux {
     151    Elf64_Word  vda_name;       /* string table offset to version or dependency
     152                           name */
     153    Elf64_Word  vda_next;       /* byte offset to next verdaux entry */
     154};
     155
     156/* version dependency section */
     157
     158struct Elf64_Verneed {
     159    Elf64_Half  vn_version;     /* version of structure */
     160    Elf64_Half  vn_cnt;         /* number of associated vernaux entries */
     161    Elf64_Word  vn_file;        /* byte offset to file name for this
     162                           dependency */
     163    Elf64_Word  vn_aux;         /* byte offset to vernaux array */
     164    Elf64_Word  vn_next;        /* byte offset to next verneed entry */
     165};
     166
     167/* auxiliary needed version information */
     168
     169struct Elf64_Vernaux {
     170    Elf64_Word  vna_hash;       /* dependency name hash value */
     171    Elf64_Half  vna_flags;      /* dependency specific information flags */
     172    Elf64_Half  vna_other;      /* version index as specified in the symbol
     173                           version table */
     174    Elf64_Word  vna_name;       /* string table offset to dependency name */
     175    Elf64_Word  vna_next;       /* byte offset to next vernaux entry */
     176};
     177
     178/*** inline functions ***/
     179
     180#ifdef __cplusplus
     181
     182inline bool
     183Elf64_Ehdr::IsHostEndian() const
     184{
     185#if B_HOST_IS_LENDIAN
     186    return e_ident[EI_DATA] == ELFDATA2LSB;
     187#elif B_HOST_IS_BENDIAN
     188    return e_ident[EI_DATA] == ELFDATA2MSB;
     189#endif
     190}
     191
     192
     193inline bool
     194Elf64_Phdr::IsReadWrite() const
     195{
     196    return !(~p_flags & (PF_READ | PF_WRITE));
     197}
     198
     199
     200inline bool
     201Elf64_Phdr::IsExecutable() const
     202{
     203    return (p_flags & PF_PROTECTION_MASK) == (PF_READ | PF_EXECUTE);
     204}
     205
     206
     207inline uint8
     208Elf64_Sym::Bind() const
     209{
     210    return ELF64_ST_BIND(st_info);
     211}
     212
     213
     214inline uint8
     215Elf64_Sym::Type() const
     216{
     217    return ELF64_ST_TYPE(st_info);
     218}
     219
     220
     221inline uint8
     222Elf64_Rel::SymbolIndex() const
     223{
     224    return ELF64_R_SYM(r_info);
     225}
     226
     227
     228inline uint8
     229Elf64_Rel::Type() const
     230{
     231    return ELF64_R_TYPE(r_info);
     232}
     233
     234#endif  /* __cplusplus */
     235
     236#endif  /* _ELF64_H_ */
  • headers/private/system/arch/x86/arch_elf.h

     
    1919#define R_386_GOTOFF    9   /* add GOT relative symbol address */
    2020#define R_386_GOTPC     10  /* add PC relative GOT table address */
    2121
     22#define R_X86_64_NONE       0
     23#define R_X86_64_64     1   /* add symbol value */
     24#define R_X86_64_PC32       2   /* add PC relative symbol value */
     25#define R_X86_64_GOT32      3   /* add PC relative GOT offset */
     26#define R_X86_64_PLT32      4   /* add PC relative PLT offset */
     27#define R_X86_64_COPY       5   /* copy data from shared object */
     28#define R_X86_64_GLOB_DAT   6   /* set GOT entry to data address */
     29#define R_X86_64_JMP_SLOT   7   /* set GOT entry to code address */
     30#define R_X86_64_RELATIVE   8   /* add load address of shared object */
     31#define R_X86_64_GOTOFF     9   /* add GOT relative symbol address */
     32#define R_X86_64_32     10      /* Add 32 bit zero extended symbol value */
     33#define R_X86_64_32S        11      /* Add 32 bit sign extended symbol value */
     34#define R_X86_64_16     12      /* Add 16 bit zero extended symbol value */
     35#define R_X86_64_PC16       13      /* Add 16 bit signed extended pc relative symbol value */
     36#define R_X86_64_8      14      /* Add 8 bit zero extended symbol value */
     37#define R_X86_64_PC8        15      /* Add 8 bit signed extended pc relative symbol value */
     38
     39
    2240#endif  /* _KERNEL_ARCH_x86_ELF_H */
  • headers/private/system/arch/x86_64/apm_defs.h

     
     1/*
     2 * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef SYSTEM_ARCH_X86_64_APM_DEFS_H
     6#define SYSTEM_ARCH_X86_64_APM_DEFS_H
     7
     8
     9#include <SupportDefs.h>
     10
     11
     12// temporary generic syscall interface
     13#define APM_SYSCALLS "apm"
     14#define APM_GET_BATTERY_INFO    1
     15
     16struct apm_battery_info {
     17    bool    online;
     18    int32   percent;
     19    time_t  time_left;
     20};
     21
     22
     23#endif  /* SYSTEM_ARCH_X86_64_APM_DEFS_H */
  • headers/private/system/arch/x86_64/asm_defs.h

     
     1/*
     2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef SYSTEM_ARCH_X86_64_ASM_DEFS_H
     6#define SYSTEM_ARCH_X86_64_ASM_DEFS_H
     7
     8
     9#define SYMBOL(name)            .global name; name
     10#define SYMBOL_END(name)        1: .size name, 1b - name
     11#define STATIC_FUNCTION(name)   .type name, @function; name
     12#define FUNCTION(name)          .global name; .type name, @function; name
     13#define FUNCTION_END(name)      1: .size name, 1b - name
     14
     15
     16#endif  /* SYSTEM_ARCH_X86_64_ASM_DEFS_H */
     17
  • headers/private/system/arch/x86_64/arch_config.h

     
     1/*
     2 * Copyright 2004, Axel Dörfler, axeld@pinc-software.de.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef _KERNEL_ARCH_x86_64_CONFIG_H
     6#define _KERNEL_ARCH_x86_64_CONFIG_H
     7
     8//#define FUNCTION_CALL_PARAMETER_ALIGNMENT_TYPE  unsigned int
     9
     10#define STACK_GROWS_DOWNWARDS
     11
     12//#define ATOMIC_FUNCS_ARE_SYSCALLS
     13//#define ATOMIC64_FUNCS_ARE_SYSCALLS
     14
     15#endif /* _KERNEL_ARCH_x86_CONFIG_H */
  • headers/private/system/arch/x86_64/arch_elf.h

     
     1/*
     2** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     3** Distributed under the terms of the OpenBeOS License.
     4*/
     5#ifndef _KERNEL_ARCH_x86_64_ELF_H
     6#define _KERNEL_ARCH_x86_64_ELF_H
     7
     8/* relocation types */
     9
     10#define R_386_NONE      0
     11#define R_386_32        1   /* add symbol value */
     12#define R_386_PC32      2   /* add PC relative symbol value */
     13#define R_386_GOT32     3   /* add PC relative GOT offset */
     14#define R_386_PLT32     4   /* add PC relative PLT offset */
     15#define R_386_COPY      5   /* copy data from shared object */
     16#define R_386_GLOB_DAT  6   /* set GOT entry to data address */
     17#define R_386_JMP_SLOT  7   /* set GOT entry to code address */
     18#define R_386_RELATIVE  8   /* add load address of shared object */
     19#define R_386_GOTOFF    9   /* add GOT relative symbol address */
     20#define R_386_GOTPC     10  /* add PC relative GOT table address */
     21
     22#define R_X86_64_NONE       0
     23#define R_X86_64_64     1   /* add symbol value */
     24#define R_X86_64_PC32       2   /* add PC relative symbol value */
     25#define R_X86_64_GOT32      3   /* add PC relative GOT offset */
     26#define R_X86_64_PLT32      4   /* add PC relative PLT offset */
     27#define R_X86_64_COPY       5   /* copy data from shared object */
     28#define R_X86_64_GLOB_DAT   6   /* set GOT entry to data address */
     29#define R_X86_64_JMP_SLOT   7   /* set GOT entry to code address */
     30#define R_X86_64_RELATIVE   8   /* add load address of shared object */
     31#define R_X86_64_GOTOFF     9   /* add GOT relative symbol address */
     32#define R_X86_64_32     10      /* Add 32 bit zero extended symbol value */
     33#define R_X86_64_32S        11      /* Add 32 bit sign extended symbol value */
     34#define R_X86_64_16     12      /* Add 16 bit zero extended symbol value */
     35#define R_X86_64_PC16       13      /* Add 16 bit signed extended pc relative symbol value */
     36#define R_X86_64_8      14      /* Add 8 bit zero extended symbol value */
     37#define R_X86_64_PC8        15      /* Add 8 bit signed extended pc relative symbol value */
     38
     39#endif  /* _KERNEL_ARCH_x86_64_ELF_H */
  • headers/private/system/arch/x86_64/arch_cpu_defs.h

     
     1/*
     2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef _SYSTEM_ARCH_X86_64_DEFS_H
     6#define _SYSTEM_ARCH_X86_64_DEFS_H
     7
     8
     9#define SPINLOCK_PAUSE()    asm volatile("pause;")
     10
     11
     12#endif  /* _SYSTEM_ARCH_X86_64_DEFS_H */
  • headers/private/system/arch/x86_64/arch_commpage_defs.h

     
     1/*
     2 * Copyright 2007, Travis Geiselbrecht. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef _SYSTEM_ARCH_x86_64_COMMPAGE_DEFS_H
     6#define _SYSTEM_ARCH_x86_64_COMMPAGE_DEFS_H
     7
     8#ifndef _SYSTEM_COMMPAGE_DEFS_H
     9#   error Must not be included directly. Include <commpage_defs.h> instead!
     10#endif
     11
     12#define COMMPAGE_ENTRY_X86_64_SYSCALL   (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 0)
     13#define COMMPAGE_ENTRY_X86_64_MEMCPY    (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 1)
     14#define COMMPAGE_ENTRY_X86_64_MEMSET    (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 2)
     15
     16#define ARCH_USER_COMMPAGE_ADDR (0xffff0000)
     17
     18#endif  /* _SYSTEM_ARCH_x86_64_COMMPAGE_DEFS_H */
  • headers/private/system/arch/x86_64/arch_real_time_data.h

     
     1/*
     2 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
     3 * All rights reserved. Distributed under the terms of the MIT License.
     4 */
     5#ifndef _KERNEL_ARCH_REAL_TIME_DATA_H
     6#define _KERNEL_ARCH_REAL_TIME_DATA_H
     7
     8#include <StorageDefs.h>
     9#include <SupportDefs.h>
     10
     11
     12struct arch_real_time_data {
     13    bigtime_t   system_time_offset;
     14    uint32      system_time_conversion_factor;
     15};
     16
     17#endif  /* _KERNEL_ARCH_REAL_TIME_DATA_H */