Ticket #6310: x86_64_system_headers.patch

File x86_64_system_headers.patch, 53.3 KB (added by nmentley, 14 years ago)

adds incomplete x86_64 system headers to allow kernel compilation

  • headers/os/kernel/OS.h

     
    410410
    411411#if __INTEL__
    412412#   define B_MAX_CPU_COUNT  8
     413#elif __x86_64__
     414#   define B_MAX_CPU_COUNT  8
    413415#elif __POWERPC__
    414416#   define B_MAX_CPU_COUNT  8
    415417#elif __M68K__
     
    662664                        uint32 cpuNum);
    663665#endif
    664666
    665 
    666667typedef enum platform_types {
    667668    B_BEBOX_PLATFORM = 0,
    668669    B_MAC_PLATFORM,
  • 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>
     
    2122
    2223#ifdef __INTEL__
    2324    typedef struct x86_debug_cpu_state debug_cpu_state;
     25#elif __x86_64__
     26    typedef struct x86_64_debug_cpu_state debug_cpu_state;
    2427#elif __POWERPC__
    2528    typedef struct ppc_debug_cpu_state debug_cpu_state;
    2629#elif __M68K__
  • 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    uint32  gs;
     47    uint32  fs;
     48    uint32  es;
     49    uint32  ds;
     50    uint32  edi;
     51    uint32  esi;
     52    uint32  ebp;
     53    uint32  esp;
     54    uint32  ebx;
     55    uint32  edx;
     56    uint32  ecx;
     57    uint32  eax;
     58    uint32  vector;
     59    uint32  error_code;
     60    uint32  eip;
     61    uint32  cs;
     62    uint32  eflags;
     63    uint32  user_esp;
     64    uint32  user_ss;
     65} __attribute__((aligned(16)));
     66
     67
     68#endif  // _ARCH_X86_64_DEBUGGER_H
  • headers/private/kernel/boot/platform/bios_x86_64/platform_kernel_args.h

     
     1/*
     2 * Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de.
     3 * Distributed under the terms of the MIT License.
     4 */
     5#ifndef KERNEL_BOOT_PLATFORM_BIOS_X86_64_KERNEL_ARGS_H
     6#define KERNEL_BOOT_PLATFORM_BIOS_X86_64_KERNEL_ARGS_H
     7
     8#ifndef KERNEL_BOOT_KERNEL_ARGS_H
     9#   error This file is included from <boot/kernel_args.h> only
     10#endif
     11
     12
     13#include <apm.h>
     14#include <bios_drive.h>
     15
     16
     17// must match SMP_MAX_CPUS in arch_smp.h
     18#define MAX_BOOT_CPUS 8
     19#define MAX_PHYSICAL_MEMORY_RANGE 8
     20#define MAX_PHYSICAL_ALLOCATED_RANGE 8
     21#define MAX_VIRTUAL_ALLOCATED_RANGE 8
     22
     23#define MAX_SERIAL_PORTS 4
     24
     25typedef struct {
     26    uint16      serial_base_ports[MAX_SERIAL_PORTS];
     27
     28    bios_drive  *drives;    // this does not contain the boot drive
     29
     30    apm_info    apm;
     31} platform_kernel_args;
     32
     33#endif  /* KERNEL_BOOT_PLATFORM_BIOS_X86_64_KERNEL_ARGS_H */
  • headers/private/kernel/boot/platform/bios_x86_64/bios_drive.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_BOOT_PLATFORM_BIOS_X86_64_BIOS_DRIVE_H
     6#define KERNEL_BOOT_PLATFORM_BIOS_X86_64_BIOS_DRIVE_H
     7
     8
     9#include <boot/disk_identifier.h>
     10
     11
     12typedef struct bios_drive {
     13    struct bios_drive   *next;
     14    uint16              drive_number;
     15    disk_identifier     identifier;
     16} bios_drive;
     17
     18#endif  /* KERNEL_BOOT_PLATFORM_BIOS_X86_64_BIOS_DRIVE_H */
  • headers/private/kernel/boot/platform/bios_x86_64/platform_stage2_args.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_BOOT_PLATFORM_BIOS_X86_64_STAGE2_H
     6#define KERNEL_BOOT_PLATFORM_BIOS_X86_64_STAGE2_H
     7
     8#ifndef KERNEL_BOOT_STAGE2_ARGS_H
     9#   error This file is included from <boot/stage2_args.h> only
     10#endif
     11
     12struct platform_stage2_args {
     13};
     14
     15#endif  /* KERNEL_BOOT_PLATFORM_BIOS_X86_64_STAGE2_H */
  • headers/private/kernel/boot/elf.h

     
    1414struct preloaded_image {
    1515    struct preloaded_image *next;
    1616    char        *name;
     17    uint8       elf_size;
    1718    elf_region  text_region;
    1819    elf_region  data_region;
    1920    addr_range  dynamic_section;
    20     struct Elf32_Ehdr elf_header;
    21 
    22     struct Elf32_Sym    *syms;
    23     struct Elf32_Rel    *rel;
     21    union
     22    {
     23        struct Elf32_Ehdr elf_header;
     24        struct Elf64_Ehdr elf_header64;
     25    };
     26    union
     27    {
     28        struct Elf32_Sym    *syms;
     29        struct Elf64_Sym    *syms64;
     30    };
     31    union
     32    {
     33        struct Elf32_Rel    *rel;
     34        struct Elf64_Rel    *rel64;
     35    };
    2436    int                 rel_len;
    25     struct Elf32_Rela   *rela;
     37    union
     38    {
     39        struct Elf32_Rela   *rela;
     40        struct Elf64_Rela   *rela64;
     41    };
    2642    int                 rela_len;
    27     struct Elf32_Rel    *pltrel;
     43    union
     44    {
     45        struct Elf32_Rel    *pltrel;
     46        struct Elf64_Rel    *pltrel64;
     47    };
    2848    int                 pltrel_len;
    2949    int                 pltrel_type;
    3050
    31     struct Elf32_Sym *debug_symbols;
     51    union
     52    {
     53        struct Elf32_Sym *debug_symbols;
     54        struct Elf64_Sym *debug_symbols64;
     55    };
    3256    const char  *debug_string_table;
    3357    uint32      num_debug_symbols, debug_string_table_size;
    3458
     
    4670extern status_t boot_elf_resolve_symbol(struct preloaded_image *image,
    4771    struct Elf32_Sym *symbol, addr_t *symbolAddress);
    4872
     73extern status_t boot_elf64_resolve_symbol(struct preloaded_image *image,
     74    struct Elf64_Sym *symbol, addr_t *symbolAddress);
     75
    4976#ifdef __cplusplus
    5077}
    5178#endif
  • 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/arch/x86_64/arch_kernel_args.h

     
     1/*
     2** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
     3** Distributed under the terms of the NewOS License.
     4*/
     5#ifndef KERNEL_ARCH_x86_64_KERNEL_ARGS_H
     6#define KERNEL_ARCH_x86_64_KERNEL_ARGS_H
     7
     8#ifndef KERNEL_BOOT_KERNEL_ARGS_H
     9#   error This file is included from <boot/kernel_args.h> only
     10#endif
     11
     12#define MAX_BOOT_PTABLES 4
     13
     14#define _PACKED __attribute__((packed))
     15
     16#define IDT_LIMIT 0x800
     17#define GDT_LIMIT 0x800
     18
     19// kernel args
     20typedef struct {
     21    // architecture specific
     22    uint32  system_time_cv_factor;
     23    uint64  cpu_clock_speed;
     24    uint32  phys_pgdir;
     25    uint32  vir_pgdir;
     26    uint32  num_pgtables;
     27    uint32  pgtables[MAX_BOOT_PTABLES];
     28    uint32  virtual_end;
     29    uint32  phys_idt;
     30    uint32  vir_idt;
     31    uint32  phys_gdt;
     32    uint32  vir_gdt;
     33    uint32  page_hole;
     34    // smp stuff
     35    uint32  apic_time_cv_factor; // apic ticks per second
     36    uint32  apic_phys;
     37    uint32  *apic;
     38    uint32  ioapic_phys;
     39    uint32  *ioapic;
     40    uint32  cpu_apic_id[MAX_BOOT_CPUS];
     41    uint32  cpu_os_id[MAX_BOOT_CPUS];
     42    uint32  cpu_apic_version[MAX_BOOT_CPUS];
     43    // hpet stuff
     44    uint32  hpet_phys;
     45    uint32  *hpet;
     46} arch_kernel_args;
     47
     48#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
     6/* TODO: edit header for x86_64 */
     7
     8#ifndef _KERNEL_ARCH_x86_VM_TRANSLATION_MAP_H
     9#define _KERNEL_ARCH_x86_VM_TRANSLATION_MAP_H
     10
     11#include <arch/vm_translation_map.h>
     12
     13
     14// quick function to return the physical pgdir of a mapping, needed for a context switch
     15#ifdef __cplusplus
     16extern "C"
     17#endif
     18void *i386_translation_map_get_pgdir(VMTranslationMap *map);
     19
     20#endif /* _KERNEL_ARCH_x86_VM_TRANSLATION_MAP_H */
  • headers/private/kernel/arch/x86_64/arch_system_info.h

     
     1/*
     2 * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     3 * Distributed under the terms of the MIT License.
     4 */
     5
     6/* TODO: Edit header from x86 to x86_64 */
     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, uint32 eax);
     19uint32 get_eflags(void);
     20void set_eflags(uint32 value);
     21
     22status_t _user_get_cpuid(cpuid_info *info, uint32 eax, uint32 cpu);
     23
     24#ifdef __cplusplus
     25}
     26#endif
     27
     28#endif  /* _KRENEL_ARCH_x86_SYSTEM_INFO_H */
  • headers/private/kernel/arch/x86_64/arch_smp.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_ARCH_SMP_H
     10#define _KERNEL_ARCH_x86_64_ARCH_SMP_H
     11
     12#define MP_FLOATING_SIGNATURE           '_PM_'
     13#define MP_CONFIG_TABLE_SIGNATURE       'PCMP'
     14
     15/*
     16#define IPI_CACHE_FLUSH         0x40
     17#define IPI_INV_TLB             0x41
     18#define IPI_INV_PTE             0x42
     19#define IPI_INV_RESCHED         0x43
     20#define IPI_STOP                0x44
     21*/
     22
     23struct mp_config_table {
     24    uint32  signature;          /* "PCMP" */
     25    uint16  base_table_length;  /* length of the base table entries and this structure */
     26    uint8   spec_revision;      /* spec supported, 1 for 1.1 or 4 for 1.4 */
     27    uint8   checksum;           /* checksum, all bytes add up to zero */
     28    char    oem[8];             /* oem identification, not null-terminated */
     29    char    product[12];        /* product name, not null-terminated */
     30    void    *oem_table;         /* addr of oem-defined table, zero if none */
     31    uint16  oem_length;         /* length of oem table */
     32    uint16  num_base_entries;   /* number of entries in base table */
     33    uint64  apic;               /* address of apic */
     34    uint16  ext_length;         /* length of extended section */
     35    uint8   ext_checksum;       /* checksum of extended table entries */
     36    uint8   reserved;
     37};
     38
     39struct mp_floating_struct {
     40    uint32  signature;          /* "_MP_" */
     41    struct mp_config_table *config_table; /* address of mp configuration table */
     42    uint8   config_length;      /* length of the table in 16-byte units */
     43    uint8   spec_revision;      /* spec supported, 1 for 1.1 or 4 for 1.4 */
     44    uint8   checksum;           /* checksum, all bytes add up to zero */
     45    uint8   mp_feature_1;       /* mp system configuration type if no mpc */
     46    uint8   mp_feature_2;       /* imcrp */
     47    uint8   mp_feature_3, mp_feature_4, mp_feature_5; /* reserved */
     48};
     49
     50/* base config entry types */
     51enum {
     52    MP_BASE_PROCESSOR = 0,
     53    MP_BASE_BUS,
     54    MP_BASE_IO_APIC,
     55    MP_BASE_IO_INTR,
     56    MP_BASE_LOCAL_INTR,
     57};
     58
     59struct mp_base_processor {
     60    uint8   type;
     61    uint8   apic_id;
     62    uint8   apic_version;
     63    uint8   cpu_flags;
     64    uint32  signature;          /* stepping, model, family, each four bits */
     65    uint32  feature_flags;
     66    uint32  res1, res2;
     67};
     68
     69struct mp_base_ioapic {
     70    uint8   type;
     71    uint8   ioapic_id;
     72    uint8   ioapic_version;
     73    uint8   ioapic_flags;
     74    uint64  *addr;
     75};
     76
     77struct mp_base_bus {
     78    uint8   type;
     79    uint8   bus_id;
     80    char    name[6];
     81};
     82
     83struct mp_base_interrupt {
     84    uint8   type;
     85    uint8   interrupt_type;
     86    uint16  polarity : 2;
     87    uint16  trigger_mode : 2;
     88    uint16  _reserved : 12;
     89    uint8   source_bus_id;
     90    uint8   source_bus_irq;
     91    uint8   dest_apic_id;
     92    uint8   dest_apic_int;
     93};
     94
     95enum {
     96    MP_INTR_TYPE_INT = 0,
     97    MP_INTR_TYPE_NMI,
     98    MP_INTR_TYPE_SMI,
     99    MP_INTR_TYPE_ExtINT,
     100};
     101
     102#endif  /* _KERNEL_ARCH_x86_64_ARCH_SMP_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
     6/* TODO: Edit header from x86 to x86_64 */
     7
     8#ifndef _KERNEL_ARCH_x86_64_HPET_H
     9#define _KERNEL_ARCH_x86_64_HPET_H
     10
     11#include <arch/x86/arch_acpi.h>
     12
     13/* All masks are 32 bits wide to represent relative bit locations */
     14/* Doing it this way is Required since the HPET only supports 32/64-bit aligned reads. */
     15
     16/* Global Capability Register Masks */
     17#define HPET_CAP_MASK_REVID         0x00000000000000FFULL
     18#define HPET_CAP_MASK_NUMTIMERS         0x0000000000001F00ULL
     19#define HPET_CAP_MASK_WIDTH         0x0000000000002000ULL
     20#define HPET_CAP_MASK_LEGACY            0x0000000000008000ULL
     21#define HPET_CAP_MASK_VENDOR_ID         0x00000000FFFF0000ULL
     22#define HPET_CAP_MASK_PERIOD            0xFFFFFFFF00000000ULL
     23
     24/* Retrieve Global Capabilities */
     25#define HPET_GET_REVID(regs)        ((regs)->capabilities & HPET_CAP_MASK_REVID)
     26#define HPET_GET_NUM_TIMERS(regs)   (((regs)->capabilities & HPET_CAP_MASK_NUMTIMERS) >> 8)
     27#define HPET_IS_64BIT(regs)     (((regs)->capabilities & HPET_CAP_MASK_WIDTH) >> 13)
     28#define HPET_IS_LEGACY_CAPABLE(regs)    (((regs)->capabilities & HPET_CAP_MASK_LEGACY) >> 15)
     29#define HPET_GET_VENDOR_ID(regs)    (((regs)->capabilities & HPET_CAP_MASK_VENDOR_ID) >> 16)
     30#define HPET_GET_PERIOD(regs)       (((regs)->capabilities & HPET_CAP_MASK_PERIOD) >> 32)
     31
     32/* Global Config Register Masks */
     33#define HPET_CONF_MASK_ENABLED          0x00000001
     34#define HPET_CONF_MASK_LEGACY           0x00000002
     35
     36/* Retrieve Global Configuration */
     37#define HPET_IS_ENABLED(regs)       ((regs)->config & HPET_CONF_MASK_ENABLED)
     38#define HPET_IS_LEGACY(regs)        (((regs)->config & HPET_CONF_MASK_LEGACY) >> 1)
     39
     40/* Timer Configuration and Capabilities*/
     41#define HPET_CAP_TIMER_MASK         0xFFFFFFFF00000000ULL
     42#define HPET_CONF_TIMER_INT_ROUTE_MASK      0x3e00UL
     43#define HPET_CONF_TIMER_INT_ROUTE_SHIFT     9   
     44#define HPET_CONF_TIMER_INT_TYPE        0x00000002UL
     45#define HPET_CONF_TIMER_INT_ENABLE      0x00000004UL
     46#define HPET_CONF_TIMER_TYPE            0x00000008UL
     47#define HPET_CONF_TIMER_VAL_SET         0x00000040UL
     48#define HPET_CONF_TIMER_32MODE          0x00000100UL
     49#define HPET_CONF_TIMER_FSB_ENABLE      0x00004000UL
     50#define HPET_CAP_TIMER_PER_INT          0x00000010UL
     51#define HPET_CAP_TIMER_SIZE         0x00000020UL
     52#define HPET_CAP_TIMER_FSB_INT_DEL      0x00008000UL
     53
     54#define HPET_GET_CAP_TIMER_ROUTE(timer)     (((timer)->config & HPET_CAP_TIMER_MASK) >> 32)
     55#define HPET_GET_CONF_TIMER_INT_ROUTE(timer)    (((timer)->config & HPET_CONF_TIMER_INT_ROUTE_MASK) >> HPET_CONF_TIMER_INT_ROUTE_SHIFT)
     56
     57#define ACPI_HPET_SIGNATURE         "HPET"
     58
     59struct hpet_timer {
     60    /* Timer Configuration/Capability bits, Reversed because x86 is LSB */ 
     61    volatile uint64 config;
     62                    /* R/W: Each bit represents one allowed interrupt for this timer. */
     63                    /* If interrupt 16 is allowed, bit 16 will be 1. */
     64    union {
     65        volatile uint64 comparator64;   /* R/W: Comparator value */
     66        volatile uint32 comparator32;   
     67    } u0;               /* non-periodic mode: fires once when main counter = this comparator */
     68                    /* periodic mode: fires when timer reaches this value, is increased by the original value */
     69   
     70    volatile uint64 fsb_route[2];   /* R/W: FSB Interrupt Route values */
     71};
     72
     73
     74struct hpet_regs {
     75    volatile uint64 capabilities;       /* Read Only */
     76   
     77    volatile uint64 reserved1;
     78
     79    volatile uint64 config;         /* R/W: Config Bits */
     80
     81    volatile uint64 reserved2;
     82
     83    /* Interrupt Status bits */
     84    volatile uint64 interrupt_status;   /* Interrupt Config bits for timers 0-31 */
     85                        /* Level Tigger: 0 = off, 1 = set by hardware, timer is active */
     86                        /* Edge Trigger: ignored */
     87                        /* Writing 0 will not clear these. Must write 1 again. */
     88    volatile uint64 reserved3[25];
     89
     90    union {
     91        volatile uint64 counter64;  /* R/W */
     92        volatile uint32 counter32;
     93    } u0;
     94
     95    volatile uint64 reserved4;
     96
     97    volatile struct hpet_timer timer[1];
     98};
     99
     100
     101typedef struct acpi_hpet {
     102    acpi_descriptor_header  header; /* "HPET" signature and acpi header */
     103    uint16  vendor_id;
     104    uint8   legacy_capable : 1;
     105    uint8   reserved1 : 1;
     106    uint8   countersize : 1;
     107    uint8   comparators : 5;
     108    uint8   hw_revision;
     109    struct hpet_addr {
     110        uint8   address_space;
     111        uint8   register_width;
     112        uint8   register_offset;
     113        uint8   reserved;
     114        uint64  address;
     115    } hpet_address;
     116    uint8   number;
     117    uint16  min_tick;
     118} _PACKED acpi_hpet;
     119
     120#endif
  • 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#endif  /* _KERNEL_ARCH_x86_64_VM_TYPES_H */
  • headers/private/kernel/arch/x86_64/arch_thread.h

     
     1/*
     2 * Copyright 2002-2009, 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
     9/* TODO: Edit header from x86 to x86_64 */
     10
     11#ifndef _KERNEL_ARCH_x86_THREAD_H
     12#define _KERNEL_ARCH_x86_THREAD_H
     13
     14
     15#include <arch/cpu.h>
     16
     17
     18#ifdef __cplusplus
     19extern "C" {
     20#endif
     21
     22struct iframe *i386_get_user_iframe(void);
     23struct iframe *i386_get_current_iframe(void);
     24struct iframe *i386_get_thread_user_iframe(struct thread *thread);
     25
     26void *x86_next_page_directory(struct thread *from, struct thread *to);
     27
     28void x86_restart_syscall(struct iframe* frame);
     29
     30void i386_return_from_signal();
     31void i386_end_return_from_signal();
     32
     33// override empty macro
     34#undef arch_syscall_64_bit_return_value
     35void arch_syscall_64_bit_return_value(void);
     36
     37
     38static
     39inline struct thread *
     40arch_thread_get_current_thread(void)
     41{
     42    struct thread *t;
     43    read_dr3(t);
     44    return t;
     45}
     46
     47static inline void
     48arch_thread_set_current_thread(struct thread *t)
     49{
     50    write_dr3(t);
     51}
     52
     53#ifdef __cplusplus
     54}
     55#endif
     56
     57#endif /* _KERNEL_ARCH_x86_THREAD_H */
     58
  • 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#define ACPI_RSDP_SIGNATURE     "RSD PTR "
     10#define ACPI_RSDT_SIGNATURE     "RSDT"
     11#define ACPI_MADT_SIGNATURE     "APIC"
     12
     13#define ACPI_LOCAL_APIC_ENABLED 0x01
     14
     15typedef struct acpi_rsdp {
     16    char    signature[8];           /* "RSD PTR " including blank */
     17    uint8   checksum;               /* checksum of bytes 0-19 (per ACPI 1.0) */
     18    char    oem_id[6];              /* not null terminated */
     19    uint8   revision;               /* 0 = ACPI 1.0, 2 = ACPI 3.0 */
     20    uint64  rsdt_address;           /* physical memory address of RSDT */
     21    uint32  rsdt_length;            /* length in bytes including header */
     22    uint64  xsdt_address;           /* 64bit physical memory address of XSDT */
     23    uint8   extended_checksum;      /* including entire table */
     24    uint8   reserved[3];
     25} _PACKED acpi_rsdp;
     26
     27typedef struct acpi_descriptor_header {
     28    char    signature[4];           /* table identifier as ASCII string */
     29    uint32  length;                 /* length in bytes of the entire table */
     30    uint8   revision;
     31    uint8   checksum;               /* checksum of entire table */
     32    char    oem_id[6];              /* not null terminated */
     33    char    oem_table_id[8];        /* oem supplied table identifier */
     34    uint32  oem_revision;           /* oem supplied revision number */
     35    char    creator_id[4];          /* creator / asl compiler id */
     36    uint32  creator_revision;       /* compiler revision */
     37} _PACKED acpi_descriptor_header;
     38
     39typedef struct acpi_madt {
     40    acpi_descriptor_header  header;     /* "APIC" signature */
     41    uint64  local_apic_address;     /* physical address for local CPUs APICs */
     42    uint32  flags;
     43} _PACKED acpi_madt;
     44
     45enum {
     46    ACPI_MADT_LOCAL_APIC = 0,
     47    ACPI_MADT_IO_APIC = 1
     48};
     49
     50typedef struct acpi_apic {
     51    uint8   type;
     52    uint8   length;
     53} _PACKED acpi_apic;
     54
     55typedef struct acpi_local_apic {
     56    uint8   type;                   /* 0 = processor local APIC */
     57    uint8   length;                 /* 8 bytes */
     58    uint8   acpi_processor_id;
     59    uint8   apic_id;                /* the id of this APIC */
     60    uint32  flags;                  /* 1 = enabled */
     61} _PACKED acpi_local_apic;
     62
     63typedef struct acpi_io_apic {
     64    uint8   type;                   /* 1 = I/O APIC */
     65    uint8   length;                 /* 12 bytes */
     66    uint8   io_apic_id;             /* the id of this APIC */
     67    uint8   reserved;
     68    uint64  io_apic_address;        /* phyisical address of I/O APIC */
     69    uint64  interrupt_base;         /* global system interrupt base */
     70} _PACKED acpi_io_apic;
     71
     72#endif  /* _KERNEL_ARCH_x86_64_ARCH_ACPI_H */
  • headers/private/kernel/arch/x86_64/apm.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_H
     6#define KERNEL_APM_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_H */
  • headers/private/kernel/arch/x86_64/arch_kernel.h

     
     1/*
     2 * Copyright 2004-2008, 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 * TODO: introduce the 1Mb lower barrier again - it's only used for vm86 mode,
     28 *  and this should be moved into the kernel (and address space) completely.
     29 */
     30#define USER_BASE     0x00
     31#define USER_BASE_ANY 0x100000
     32#define USER_SIZE     (KERNEL_BASE - 0x10000)
     33#define USER_TOP      (USER_BASE + USER_SIZE)
     34
     35#define KERNEL_USER_DATA_BASE   0x6fff0000
     36#define USER_STACK_REGION       0x70000000
     37#define USER_STACK_REGION_SIZE  (USER_TOP - USER_STACK_REGION)
     38
     39#endif  /* _KERNEL_ARCH_x86_64_KERNEL_H */
  • headers/private/kernel/arch/x86_64/arch_user_debugger.h

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

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

     
     1/*
     2 * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
     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
     9/* TODO: Edit header from x86 to x86_64 */
     10
     11#ifndef _KERNEL_ARCH_x86_CPU_H
     12#define _KERNEL_ARCH_x86_CPU_H
     13
     14
     15#ifndef _ASSEMBLER
     16
     17#include <module.h>
     18#include <arch/x86/descriptors.h>
     19
     20#endif  // !_ASSEMBLER
     21
     22
     23#undef PAUSE
     24#define PAUSE() asm volatile ("pause;")
     25
     26
     27// MSR registers (possibly Intel specific)
     28#define IA32_MSR_TSC                    0x10
     29#define IA32_MSR_APIC_BASE              0x1b
     30
     31#define IA32_MSR_MTRR_CAPABILITIES      0xfe
     32#define IA32_MSR_SYSENTER_CS            0x174
     33#define IA32_MSR_SYSENTER_ESP           0x175
     34#define IA32_MSR_SYSENTER_EIP           0x176
     35#define IA32_MSR_MTRR_DEFAULT_TYPE      0x2ff
     36#define IA32_MSR_MTRR_PHYSICAL_BASE_0   0x200
     37#define IA32_MSR_MTRR_PHYSICAL_MASK_0   0x201
     38
     39// x86 features from cpuid eax 1, edx register
     40#define IA32_FEATURE_FPU    0x00000001 // x87 fpu
     41#define IA32_FEATURE_VME    0x00000002 // virtual 8086
     42#define IA32_FEATURE_DE     0x00000004 // debugging extensions
     43#define IA32_FEATURE_PSE    0x00000008 // page size extensions
     44#define IA32_FEATURE_TSC    0x00000010 // rdtsc instruction
     45#define IA32_FEATURE_MSR    0x00000020 // rdmsr/wrmsr instruction
     46#define IA32_FEATURE_PAE    0x00000040 // extended 3 level page table addressing
     47#define IA32_FEATURE_MCE    0x00000080 // machine check exception
     48#define IA32_FEATURE_CX8    0x00000100 // cmpxchg8b instruction
     49#define IA32_FEATURE_APIC   0x00000200 // local apic on chip
     50#define IA32_FEATURE_SEP    0x00000800 // SYSENTER/SYSEXIT
     51#define IA32_FEATURE_MTRR   0x00001000 // MTRR
     52#define IA32_FEATURE_PGE    0x00002000 // paging global bit
     53#define IA32_FEATURE_MCA    0x00004000 // machine check architecture
     54#define IA32_FEATURE_CMOV   0x00008000 // cmov instruction
     55#define IA32_FEATURE_PAT    0x00010000 // page attribute table
     56#define IA32_FEATURE_PSE36  0x00020000 // page size extensions with 4MB pages
     57#define IA32_FEATURE_PSN    0x00040000 // processor serial number
     58#define IA32_FEATURE_CLFSH  0x00080000 // cflush instruction
     59#define IA32_FEATURE_DS     0x00200000 // debug store
     60#define IA32_FEATURE_ACPI   0x00400000 // thermal monitor and clock ctrl
     61#define IA32_FEATURE_MMX    0x00800000 // mmx instructions
     62#define IA32_FEATURE_FXSR   0x01000000 // FXSAVE/FXRSTOR instruction
     63#define IA32_FEATURE_SSE    0x02000000 // SSE
     64#define IA32_FEATURE_SSE2   0x04000000 // SSE2
     65#define IA32_FEATURE_SS     0x08000000 // self snoop
     66#define IA32_FEATURE_HTT    0x10000000 // hyperthreading
     67#define IA32_FEATURE_TM     0x20000000 // thermal monitor
     68#define IA32_FEATURE_PBE    0x80000000 // pending break enable
     69
     70// x86 features from cpuid eax 1, ecx register
     71#define IA32_FEATURE_EXT_SSE3           0x00000001  // SSE3
     72#define IA32_FEATURE_EXT_MONITOR        0x00000008  // MONITOR/MWAIT
     73#define IA32_FEATURE_EXT_DSCPL          0x00000010  // CPL qualified debug store
     74#define IA32_FEATURE_EXT_EST            0x00000080  // speedstep
     75#define IA32_FEATURE_EXT_TM2            0x00000100  // thermal monitor 2
     76#define IA32_FEATURE_EXT_CNXTID         0x00000400  // L1 context ID
     77
     78// x86 features from cpuid eax 0x80000001, edx register (AMD)
     79// only care about the ones that are unique to this register
     80#define IA32_FEATURE_AMD_EXT_SYSCALL    (1 << 11)   // SYSCALL/SYSRET
     81#define IA32_FEATURE_AMD_EXT_NX         (1 << 20)   // no execute bit
     82#define IA32_FEATURE_AMD_EXT_MMXEXT     (1 << 22)   // mmx extensions
     83#define IA32_FEATURE_AMD_EXT_FFXSR      (1 << 25)   // fast FXSAVE/FXRSTOR
     84#define IA32_FEATURE_AMD_EXT_RDTSCP     (1 << 27)   // rdtscp instruction
     85#define IA32_FEATURE_AMD_EXT_LONG       (1 << 29)   // long mode
     86#define IA32_FEATURE_AMD_EXT_3DNOWEXT   (1 << 30)   // 3DNow! extensions
     87#define IA32_FEATURE_AMD_EXT_3DNOW      (1 << 31)   // 3DNow!
     88
     89// cr4 flags
     90#define IA32_CR4_GLOBAL_PAGES           (1UL << 7)
     91
     92// Memory type ranges
     93#define IA32_MTR_UNCACHED               0
     94#define IA32_MTR_WRITE_COMBINING        1
     95#define IA32_MTR_WRITE_THROUGH          4
     96#define IA32_MTR_WRITE_PROTECTED        5
     97#define IA32_MTR_WRITE_BACK             6
     98
     99
     100// iframe types
     101#define IFRAME_TYPE_SYSCALL             0x1
     102#define IFRAME_TYPE_OTHER               0x2
     103#define IFRAME_TYPE_MASK                0xf
     104
     105
     106#ifndef _ASSEMBLER
     107
     108typedef struct x86_mtrr_info {
     109    uint64  base;
     110    uint64  size;
     111    uint8   type;
     112} x86_mtrr_info;
     113
     114typedef struct x86_optimized_functions {
     115    void    (*memcpy)(void* dest, const void* source, size_t count);
     116    void*   memcpy_end;
     117    void    (*memset)(void* dest, int value, size_t count);
     118    void*   memset_end;
     119} x86_optimized_functions;
     120
     121typedef struct x86_cpu_module_info {
     122    module_info info;
     123    uint32      (*count_mtrrs)(void);
     124    void        (*init_mtrrs)(void);
     125
     126    void        (*set_mtrr)(uint32 index, uint64 base, uint64 length,
     127                    uint8 type);
     128    status_t    (*get_mtrr)(uint32 index, uint64* _base, uint64* _length,
     129                    uint8* _type);
     130    void        (*set_mtrrs)(uint8 defaultType, const x86_mtrr_info* infos,
     131                    uint32 count);
     132
     133    void        (*get_optimized_functions)(x86_optimized_functions* functions);
     134} x86_cpu_module_info;
     135
     136
     137struct tss {
     138    uint16 prev_task;
     139    uint16 unused0;
     140    uint32 sp0;
     141    uint32 ss0;
     142    uint32 sp1;
     143    uint32 ss1;
     144    uint32 sp2;
     145    uint32 ss2;
     146    uint32 cr3;
     147    uint32 eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;
     148    uint32 es, cs, ss, ds, fs, gs;
     149    uint32 ldt_seg_selector;
     150    uint16 unused1;
     151    uint16 io_map_base;
     152};
     153
     154struct iframe {
     155    uint32 type;    // iframe type
     156    uint32 gs;
     157    uint32 fs;
     158    uint32 es;
     159    uint32 ds;
     160    uint32 edi;
     161    uint32 esi;
     162    uint32 ebp;
     163    uint32 esp;
     164    uint32 ebx;
     165    uint32 edx;
     166    uint32 ecx;
     167    uint32 eax;
     168    uint32 orig_eax;
     169    uint32 orig_edx;
     170    uint32 vector;
     171    uint32 error_code;
     172    uint32 eip;
     173    uint32 cs;
     174    uint32 flags;
     175
     176    // user_esp and user_ss are only present when the iframe is a userland
     177    // iframe (IFRAME_IS_USER()). A kernel iframe is shorter.
     178    uint32 user_esp;
     179    uint32 user_ss;
     180};
     181
     182struct vm86_iframe {
     183    uint32 type;    // iframe type
     184    uint32 __null_gs;
     185    uint32 __null_fs;
     186    uint32 __null_es;
     187    uint32 __null_ds;
     188    uint32 edi;
     189    uint32 esi;
     190    uint32 ebp;
     191    uint32 __kern_esp;
     192    uint32 ebx;
     193    uint32 edx;
     194    uint32 ecx;
     195    uint32 eax;
     196    uint32 orig_eax;
     197    uint32 orig_edx;
     198    uint32 vector;
     199    uint32 error_code;
     200    uint32 eip;
     201    uint16 cs, __csh;
     202    uint32 flags;
     203    uint32 esp;
     204    uint16 ss, __ssh;
     205
     206    /* vm86 mode specific part */
     207    uint16 es, __esh;
     208    uint16 ds, __dsh;
     209    uint16 fs, __fsh;
     210    uint16 gs, __gsh;
     211};
     212
     213#define IFRAME_IS_USER(f) ((f)->cs == USER_CODE_SEG \
     214                            || ((f)->flags & 0x20000) != 0)
     215#define IFRAME_IS_VM86(f) (((f)->flags & 0x20000) != 0)
     216
     217// features
     218enum x86_feature_type {
     219    FEATURE_COMMON = 0,     // cpuid eax=1, ecx register
     220    FEATURE_EXT,            // cpuid eax=1, edx register
     221    FEATURE_EXT_AMD,        // cpuid eax=0x80000001, edx register (AMD)
     222
     223    FEATURE_NUM
     224};
     225
     226enum x86_vendors {
     227    VENDOR_INTEL = 0,
     228    VENDOR_AMD,
     229    VENDOR_CYRIX,
     230    VENDOR_UMC,
     231    VENDOR_NEXGEN,
     232    VENDOR_CENTAUR,
     233    VENDOR_RISE,
     234    VENDOR_TRANSMETA,
     235    VENDOR_NSC,
     236
     237    VENDOR_NUM,
     238    VENDOR_UNKNOWN,
     239};
     240
     241typedef struct arch_cpu_info {
     242    // saved cpu info
     243    enum x86_vendors    vendor;
     244    uint32              feature[FEATURE_NUM];
     245    char                model_name[49];
     246    const char*         vendor_name;
     247    int                 type;
     248    int                 family;
     249    int                 extended_family;
     250    int                 stepping;
     251    int                 model;
     252    int                 extended_model;
     253
     254    struct vm_translation_map_arch_info* active_translation_map;
     255
     256    uint32              dr6;    // temporary storage for debug registers (cf.
     257    uint32              dr7;    // x86_exit_user_debug_at_kernel_entry())
     258
     259    // local TSS for this cpu
     260    struct tss          tss;
     261    struct tss          double_fault_tss;
     262} arch_cpu_info;
     263
     264#ifdef __cplusplus
     265extern "C" {
     266#endif
     267
     268#define nop() __asm__ ("nop"::)
     269
     270struct arch_thread;
     271
     272void __x86_setup_system_time(uint32 conversionFactor,
     273    uint32 conversionFactorNsecs, bool conversionFactorNsecsShift);
     274void i386_context_switch(struct arch_thread* oldState,
     275    struct arch_thread* newState, uint32 newPageDir);
     276void x86_userspace_thread_exit(void);
     277void x86_end_userspace_thread_exit(void);
     278void x86_enter_userspace(addr_t entry, addr_t stackTop);
     279void i386_set_tss_and_kstack(addr_t kstack);
     280void i386_swap_pgdir(uint32 newPageDir);
     281void i386_fnsave(void* fpuState);
     282void i386_fxsave(void* fpuState);
     283void i386_frstor(const void* fpuState);
     284void i386_fxrstor(const void* fpuState);
     285void i386_fnsave_swap(void* oldFpuState, const void* newFpuState);
     286void i386_fxsave_swap(void* oldFpuState, const void* newFpuState);
     287uint32 x86_read_ebp();
     288uint32 x86_read_cr0();
     289void x86_write_cr0(uint32 value);
     290uint32 x86_read_cr4();
     291void x86_write_cr4(uint32 value);
     292uint64 x86_read_msr(uint32 registerNumber);
     293void x86_write_msr(uint32 registerNumber, uint64 value);
     294void x86_set_task_gate(int32 cpu, int32 n, int32 segment);
     295void* x86_get_idt(int32 cpu);
     296uint32 x86_count_mtrrs(void);
     297void x86_set_mtrr(uint32 index, uint64 base, uint64 length, uint8 type);
     298status_t x86_get_mtrr(uint32 index, uint64* _base, uint64* _length,
     299    uint8* _type);
     300void x86_set_mtrrs(uint8 defaultType, const x86_mtrr_info* infos,
     301    uint32 count);
     302bool x86_check_feature(uint32 feature, enum x86_feature_type type);
     303void* x86_get_double_fault_stack(int32 cpu, size_t* _size);
     304int32 x86_double_fault_get_cpu(void);
     305void x86_double_fault_exception(struct iframe* frame);
     306void x86_page_fault_exception_double_fault(struct iframe* frame);
     307
     308/* this won't do */
     309#define read_cr3(value) \
     310    __asm__("nop")
     311//  __asm__("movl   %%cr3,%0" : "=r" (value))
     312
     313#define write_cr3(value) \
     314    __asm__("nop")
     315//  __asm__("movl   %0,%%cr3" : : "r" (value))
     316
     317#define read_dr3(value) \
     318    __asm__("nop")
     319//  __asm__("movl   %%dr3,%0" : "=r" (value))
     320
     321#define write_dr3(value) \
     322    __asm__("nop")
     323//  __asm__("movl   %0,%%dr3" : : "r" (value))
     324
     325#define invalidate_TLB(va) \
     326    __asm__("nop")
     327//  __asm__("invlpg (%0)" : : "r" (va))
     328
     329#define wbinvd() \
     330    __asm__("nop")
     331//  __asm__("wbinvd")
     332
     333#define out8(value,port) \
     334    __asm__ ("outb %%al,%%dx" : : "a" (value), "d" (port))
     335
     336#define out16(value,port) \
     337    __asm__ ("outw %%ax,%%dx" : : "a" (value), "d" (port))
     338
     339#define out32(value,port) \
     340    __asm__ ("outl %%eax,%%dx" : : "a" (value), "d" (port))
     341
     342#define in8(port) \
     343({ \
     344    uint8 _v; \
     345    __asm__ volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); \
     346    _v; \
     347})
     348
     349#define in16(port) \
     350({ \
     351    uint16 _v; \
     352    __asm__ volatile ("inw %%dx,%%ax":"=a" (_v) : "d" (port)); \
     353    _v; \
     354})
     355
     356#define in32(port) \
     357({ \
     358    uint32 _v; \
     359    __asm__ volatile ("inl %%dx,%%eax":"=a" (_v) : "d" (port)); \
     360    _v; \
     361})
     362
     363#define out8_p(value,port) \
     364    __asm__("nop")
     365/*  __asm__ ("outb %%al,%%dx\n" \
     366        "\tjmp 1f\n" \
     367        "1:\tjmp 1f\n" \
     368        "1:" : : "a" (value), "d" (port))
     369*/
     370#define in8_p(port) \
     371    __asm__("nop")
     372/*({ \
     373    uint8 _v; \
     374    __asm__ volatile ("inb %%dx,%%al\n" \
     375        "\tjmp 1f\n" \
     376        "1:\tjmp 1f\n" \
     377        "1:" : "=a" (_v) : "d" (port)); \
     378    _v; \
     379})*/
     380
     381extern segment_descriptor* gGDT;
     382
     383
     384#ifdef __cplusplus
     385}   // extern "C" {
     386#endif
     387
     388#endif  // !_ASSEMBLER
     389
     390#endif  /* _KERNEL_ARCH_x86_CPU_H */
  • headers/private/kernel/arch/x86_64/arch_int.h

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

     
     1/*
     2 * Copyright 2002-2006, 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 *esp;
     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    uint8 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#endif  /* _KERNEL_ARCH_x86_64_THREAD_TYPES_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_APM_DEFS_H
     6#define SYSTEM_ARCH_X86_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_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_ASM_DEFS_H
     6#define SYSTEM_ARCH_X86_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_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_CONFIG_H
     6#define _KERNEL_ARCH_x86_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_DEFS_H
     6#define _SYSTEM_ARCH_X86_DEFS_H
     7
     8
     9#define SPINLOCK_PAUSE()    asm volatile("pause;")
     10
     11
     12#endif  /* _SYSTEM_ARCH_X86_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_COMMPAGE_DEFS_H
     6#define _SYSTEM_ARCH_x86_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_SYSCALL  (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 0)
     13#define COMMPAGE_ENTRY_X86_MEMCPY   (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 1)
     14#define COMMPAGE_ENTRY_X86_MEMSET   (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 2)
     15
     16#define ARCH_USER_COMMPAGE_ADDR (0xffff0000)
     17
     18#endif  /* _SYSTEM_ARCH_x86_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 */