VirtualBox

Changeset 54254 in vbox


Ignore:
Timestamp:
Feb 17, 2015 10:58:55 PM (10 years ago)
Author:
vboxsync
Message:

Added ASMGetIdtrLimit.

Location:
trunk
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/asm-amd64-x86.h

    r54251 r54254  
    2828
    2929#include <iprt/types.h>
     30#include <iprt/assert.h>
    3031#if !defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86)
    3132# error "Not on AMD64 or x86"
     
    8384 */
    8485
    85 /** @todo find a more proper place for this structure? */
     86/** @todo find a more proper place for these structures? */
     87
    8688#pragma pack(1)
    8789/** IDTR */
     
    9698
    9799#pragma pack(1)
     100/** @internal */
     101typedef struct RTIDTRALIGNEDINT
     102{
     103    /** Alignment padding.   */
     104    uint8_t     au16Padding[ARCH_BITS == 64 ? 3 : 1];
     105    /** The IDTR structure.  */
     106    RTIDTR      Idtr;
     107} RTIDTRALIGNEDINT;
     108#pragma pack()
     109
     110/** Wrapped RTIDTR for preventing misalignment exceptions. */
     111typedef union RTIDTRALIGNED
     112{
     113    /** Try make sure this structure has optimal alignment. */
     114    uint64_t            auAlignmentHack[ARCH_BITS == 64 ? 2 : 1];
     115    /** Aligned structure. */
     116    RTIDTRALIGNEDINT    s;
     117} RTIDTRALIGNED;
     118AssertCompileSize(RTIDTRALIGNED, ARCH_BITS * 2 / 8);
     119/** Pointer to a an RTIDTR alignment wrapper. */
     120typedef RTIDTRALIGNED *PRIDTRALIGNED;
     121
     122
     123#pragma pack(1)
    98124/** GDTR */
    99125typedef struct RTGDTR
     
    106132#pragma pack()
    107133
     134#pragma pack(1)
     135/** @internal */
     136typedef struct RTGDTRALIGNEDINT
     137{
     138    /** Alignment padding.   */
     139    uint8_t     au16Padding[ARCH_BITS == 64 ? 3 : 1];
     140    /** The GDTR structure.  */
     141    RTGDTR      Gdtr;
     142} RTGDTRALIGNEDINT;
     143#pragma pack()
     144
     145/** Wrapped RTGDTR for preventing misalignment exceptions. */
     146typedef union RTGDTRALIGNED
     147{
     148    /** Try make sure this structure has optimal alignment. */
     149    uint64_t            auAlignmentHack[ARCH_BITS == 64 ? 2 : 1];
     150    /** Aligned structure. */
     151    RTGDTRALIGNEDINT    s;
     152} RTGDTRALIGNED;
     153AssertCompileSize(RTGDTRALIGNED, ARCH_BITS * 2 / 8);
     154/** Pointer to a an RTGDTR alignment wrapper. */
     155typedef RTGDTRALIGNED *PRGDTRALIGNED;
     156
    108157
    109158/**
     
    130179    }
    131180# endif
     181}
     182#endif
     183
     184
     185/**
     186 * Gets the content of the IDTR.LIMIT CPU register.
     187 * @returns IDTR limit.
     188 */
     189#if RT_INLINE_ASM_EXTERNAL
     190DECLASM(uint16_t) ASMGetIdtrLimit(void);
     191#else
     192DECLINLINE(uint16_t) ASMGetIdtrLimit(void)
     193{
     194    RTIDTRALIGNED TmpIdtr;
     195# if RT_INLINE_ASM_GNU_STYLE
     196    __asm__ __volatile__("sidt %0" : "=m" (TmpIdtr.s.Idtr));
     197# else
     198    __asm
     199    {
     200        sidt    [TmpIdtr.s.Idtr]
     201    }
     202# endif
     203    return TmpIdtr.s.Idtr.cbIdt;
    132204}
    133205#endif
  • trunk/src/VBox/Runtime/Makefile.kmk

    r53993 r54254  
    187187        common/asm/ASMNopPause.asm \
    188188        common/asm/ASMGetIDTR.asm \
     189        common/asm/ASMGetIdtrLimit.asm \
    189190        common/asm/ASMSetIDTR.asm \
    190191        common/asm/ASMGetGDTR.asm \
  • trunk/src/VBox/Runtime/common/asm/ASMGetIdtrLimit.asm

    r54253 r54254  
    11; $Id$
    22;; @file
    3 ; IPRT - ASMGetIDTR().
     3; IPRT - ASMGetIdtrLimit().
    44;
    55
    66;
    7 ; Copyright (C) 2006-2013 Oracle Corporation
     7; Copyright (C) 2006-2015 Oracle Corporation
    88;
    99; This file is part of VirtualBox Open Source Edition (OSE), as
     
    2828;* Header Files                                                                *
    2929;*******************************************************************************
     30%define RT_ASM_WITH_SEH64
    3031%include "iprt/asmdefs.mac"
    3132
     
    3435;;
    3536; Gets the content of the IDTR CPU register.
    36 ; @param    pIdtr   Where to store the IDTR contents.
    37 ;                   msc=rcx, gcc=rdi, x86=[esp+4]
     37; @returns  IDTR.LIMIT in ax
    3838;
    39 BEGINPROC_EXPORTED ASMGetIDTR
    40 %ifdef ASM_CALL64_MSC
    41         mov     rax, rcx
    42 %elifdef ASM_CALL64_GCC
    43         mov     rax, rdi
    44 %elifdef RT_ARCH_X86
    45         mov     eax, [esp + 4]
    46 %else
    47  %error "Undefined arch?"
    48 %endif
    49         sidt    [xAX]
     39BEGINPROC_EXPORTED ASMGetIdtrLimit
     40        sub     xSP, 18h
     41        SEH64_ALLOCATE_STACK 18h
     42SEH64_END_PROLOGUE
     43        sidt    [xSP + 6]
     44        mov     ax, [xSP + 6]
     45        add     xSP, 18h
    5046        ret
    51 ENDPROC ASMGetIDTR
     47ENDPROC ASMGetIdtrLimit
    5248
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette