VirtualBox

Changeset 87456 in vbox


Ignore:
Timestamp:
Jan 28, 2021 12:11:20 PM (4 years ago)
Author:
vboxsync
Message:

iprt/asmdefs.mac,VMM: Implemented an alternative to the YASM unwind info directives. Applied it to HMR0A.asm and VMMR0JmpA-amd64.asm.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/asmdefs.mac

    r85460 r87456  
    101101%define RT_CONCAT4(a_1,a_2,a_3,a_4)     a_1 %+ a_2 %+ a_3 %+ a_4
    102102
     103;;
     104; Trick for using RT_CONCAT and the like on %define names.
     105; @param 1  The name (expression.
     106; @param 2  The value.
     107%macro RT_DEFINE_EX 2
     108 %error 1=%1 2=%2
     109 %define %1 %2
     110%endmacro
     111
     112;;
     113; Trick for using RT_CONCAT and the like on %xdefine names.
     114; @param 1  The name (expression.
     115; @param 2  The value.
     116%macro RT_XDEFINE_EX 2
     117 %xdefine %1 %2
     118%endmacro
     119
     120;;
     121; Trick for using RT_CONCAT and the like on %undef names.
     122; @param 1  The name (expression.
     123%macro RT_UNDEF_EX 1
     124 %error 1=%1
     125 %undef %1
     126%endmacro
     127
    103128
    104129;; Define ASM_FORMAT_PE64 if applicable.
     
    117142%endif
    118143
     144%ifdef RT_ASM_WITH_SEH64_ALT
     145 %ifdef ASM_FORMAT_PE64
     146  ;; @name Register numbers. Used with RT_CONCAT to convert macro inputs to numbers.
     147  ;; @{
     148  %define SEH64_PE_GREG_rax     0
     149  %define SEH64_PE_GREG_xAX     0
     150  %define SEH64_PE_GREG_rcx     1
     151  %define SEH64_PE_GREG_xCX     1
     152  %define SEH64_PE_GREG_rdx     2
     153  %define SEH64_PE_GREG_xDX     2
     154  %define SEH64_PE_GREG_rbx     3
     155  %define SEH64_PE_GREG_xBX     3
     156  %define SEH64_PE_GREG_rsp     4
     157  %define SEH64_PE_GREG_xSP     4
     158  %define SEH64_PE_GREG_rbp     5
     159  %define SEH64_PE_GREG_xBP     5
     160  %define SEH64_PE_GREG_rsi     6
     161  %define SEH64_PE_GREG_xSI     6
     162  %define SEH64_PE_GREG_rdi     7
     163  %define SEH64_PE_GREG_xDI     7
     164  %define SEH64_PE_GREG_r8      8
     165  %define SEH64_PE_GREG_r9      9
     166  %define SEH64_PE_GREG_r10     10
     167  %define SEH64_PE_GREG_r11     11
     168  %define SEH64_PE_GREG_r12     12
     169  %define SEH64_PE_GREG_r13     13
     170  %define SEH64_PE_GREG_r14     14
     171  %define SEH64_PE_GREG_r15     15
     172  ;; @}
     173
     174  ;; @name PE unwind operations.
     175  ;; @{
     176  %define SEH64_PE_PUSH_NONVOL      0
     177  %define SEH64_PE_ALLOC_LARGE      1
     178  %define SEH64_PE_ALLOC_SMALL      2
     179  %define SEH64_PE_SET_FPREG        3
     180  %define SEH64_PE_SAVE_NONVOL      4
     181  %define SEH64_PE_SAVE_NONVOL_FAR  5
     182  %define SEH64_PE_SAVE_XMM128      8
     183  %define SEH64_PE_SAVE_XMM128_FAR  9
     184  ;; @}
     185
     186  ;;
     187  ; Starts the unwind info for the manual SEH64 info generation.
     188  ; @param 1 Function name.
     189  %macro SEH64_ALT_START_UNWIND_INFO 1
     190   %assign seh64_idxOps   0
     191   %assign seh64_FrameReg SEH64_PE_GREG_rsp
     192   %assign seh64_offFrame 0
     193   %define asm_seh64_proc %1
     194   %undef  seh64_slot_bytes
     195  %endmacro
     196
     197  ;; We keep the unwind bytes in the seh64_slot_bytes (x)define, in reverse order as per spec.
     198  %macro SEH64_APPEND_SLOT_PAIR 2
     199   %ifdef seh64_slot_bytes
     200    %xdefine seh64_slot_bytes %1, %2, seh64_slot_bytes
     201   %else
     202    %xdefine seh64_slot_bytes %1, %2
     203   %endif
     204  %endmacro
     205
     206  ;; For multi-slot unwind info.
     207  %macro SEH64_APPEND_SLOT_BYTES 2+
     208   %rep %0
     209    %rotate -1
     210    %ifdef seh64_slot_bytes
     211     %xdefine seh64_slot_bytes %1, seh64_slot_bytes
     212    %else
     213     %xdefine seh64_slot_bytes %1
     214    %endif
     215   %endrep
     216  %endmacro
     217
     218 %else
     219  %undef RT_ASM_WITH_SEH64_ALT
     220 %endif
     221%endif
     222
    119223;;
    120224; Records a xBP push.
    121225%macro SEH64_PUSH_xBP 0
    122226 %ifdef RT_ASM_WITH_SEH64
    123   [pushreg rbp]
     227        [pushreg rbp]
     228
     229 %elifdef RT_ASM_WITH_SEH64_ALT
     230RT_CONCAT(.seh64_op_label_,seh64_idxOps):
     231  %ifdef ASM_FORMAT_PE64
     232   SEH64_APPEND_SLOT_PAIR   RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
     233                            SEH64_PE_PUSH_NONVOL | (SEH64_PE_GREG_rbp << 4)
     234  %endif
     235  %assign seh64_idxOps      seh64_idxOps + 1
    124236 %endif
    125237%endmacro
     
    130242%macro SEH64_PUSH_GREG 1
    131243 %ifdef RT_ASM_WITH_SEH64
    132   [pushreg %1]
     244        [pushreg %1]
     245
     246 %elifdef RT_ASM_WITH_SEH64_ALT
     247RT_CONCAT(.seh64_op_label_,seh64_idxOps):
     248  %ifdef ASM_FORMAT_PE64
     249   SEH64_APPEND_SLOT_PAIR   RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
     250                            SEH64_PE_PUSH_NONVOL | (RT_CONCAT(SEH64_PE_GREG_,%1) << 4)
     251  %endif
     252  %assign seh64_idxOps      seh64_idxOps + 1
    133253 %endif
    134254%endmacro
     
    139259 %ifdef RT_ASM_WITH_SEH64
    140260  [setframe rbp, %1]
     261
     262 %elifdef RT_ASM_WITH_SEH64_ALT
     263RT_CONCAT(.seh64_op_label_,seh64_idxOps):
     264  %ifdef ASM_FORMAT_PE64
     265   SEH64_APPEND_SLOT_PAIR   RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
     266                            SEH64_PE_SET_FPREG | 0 ; vs2019 seems to put the offset in the info field
     267   %assign seh64_FrameReg   SEH64_PE_GREG_rbp
     268   %assign seh64_offFrame   %1
     269  %endif
     270  %assign seh64_idxOps      seh64_idxOps + 1
    141271 %endif
    142272%endmacro
     
    146276%macro SEH64_ALLOCATE_STACK 1
    147277 %ifdef RT_ASM_WITH_SEH64
    148   [allocstack %1]
    149  %endif
     278        [allocstack %1]
     279
     280 %elifdef RT_ASM_WITH_SEH64_ALT
     281RT_CONCAT(.seh64_op_label_,seh64_idxOps):
     282  %ifdef ASM_FORMAT_PE64
     283   %if (%1) & 7
     284    %error "SEH64_ALLOCATE_STACK must be a multiple of 8"
     285   %endif
     286   %if (%1) < 8
     287    %error "SEH64_ALLOCATE_STACK must have an argument that's 8 or higher."
     288   %elif (%1) <= 128
     289    SEH64_APPEND_SLOT_PAIR RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
     290                           SEH64_PE_ALLOC_SMALL | ((((%1) / 8) - 1) << 4)
     291   %elif (%1) < 512
     292    SEH64_APPEND_SLOT_BYTES RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
     293                            SEH64_PE_ALLOC_LARGE | 0, \
     294                            ((%1) / 8) & 0xff, ((%1) / 8) >> 8
     295   %else
     296    SEH64_APPEND_SLOT_BYTES RT_CONCAT(.seh64_op_label_,seh64_idxOps) - .start_of_prologue, \
     297                            SEH64_PE_ALLOC_LARGE | 1, \
     298                            (%1) & 0xff, ((%1) >> 8) & 0xff, ((%1) >> 16) & 0xff, ((%1) >> 24) & 0xff
     299   %endif
     300  %endif
     301  %assign seh64_idxOps      seh64_idxOps + 1
     302 %endif
     303%endmacro
     304
     305%macro SEH64_INFO_HELPER 1
     306%if defined(%1)
     307        dw      %1
     308%endif
    150309%endmacro
    151310
     
    153312; Ends the prologue.
    154313%macro SEH64_END_PROLOGUE 0
     314.end_of_prologue:
    155315 %ifdef RT_ASM_WITH_SEH64
    156  [endprolog]
     316        [endprolog]
     317
     318 %elifdef RT_ASM_WITH_SEH64_ALT
     319  %ifdef ASM_FORMAT_PE
     320        ; Emit the unwind info now.
     321   %ifndef ASM_DEFINED_XDATA_SECTION
     322    %define ASM_DEFINED_XDATA_SECTION
     323        section .xdata rdata align=4
     324   %else
     325        section .xdata
     326        align   4, db 0
     327   %endif
     328.unwind_info:
     329        db      1                       ; version 1 (3 bit), no flags (5 bits)
     330        db      .end_of_prologue - .start_of_prologue
     331
     332        db      (.unwind_info_array_end - .unwind_info_array) / 2
     333        db      seh64_FrameReg | (seh64_offFrame & 0xf0) ; framereg and offset/16.
     334.unwind_info_array:
     335   %ifdef seh64_slot_bytes
     336        db      seh64_slot_bytes
     337    %undef seh64_slot_bytes
     338   %endif
     339.unwind_info_array_end:
     340
     341        ; Reset the segment
     342        BEGINCODE
     343  %endif
    157344 %endif
    158345%endmacro
     
    320507; Begins a C callable procedure.
    321508%macro BEGINPROC 1
     509 %ifdef RT_ASM_WITH_SEH64_ALT
     510  SEH64_ALT_START_UNWIND_INFO %1
     511 %endif
    322512 %ifdef RT_ASM_WITH_SEH64
    323513global     NAME(%1):function
     
    326516GLOBALNAME_EX %1, function hidden
    327517 %endif
     518.start_of_prologue:
    328519%endmacro
    329520
     
    331522; Begins a C callable exported procedure.
    332523%macro BEGINPROC_EXPORTED 1
     524 %ifdef RT_ASM_WITH_SEH64_ALT
     525  SEH64_ALT_START_UNWIND_INFO %1
     526 %endif
    333527 %ifdef RT_ASM_WITH_SEH64
    334528  %ifdef ASM_FORMAT_PE
     
    340534EXPORTEDNAME_EX %1, function
    341535 %endif
     536.start_of_prologue:
    342537%endmacro
    343538
     
    356551%endif
    357552    db  0xCC, 0xCC, 0xCC, 0xCC
     553
     554 %ifdef RT_ASM_WITH_SEH64_ALT
     555  %ifdef ASM_FORMAT_PE
     556        ; Emit the RUNTIME_FUNCTION entry.  The linker is picky here, no label.
     557   %ifndef ASM_DEFINED_PDATA_SECTION
     558    %define ASM_DEFINED_PDATA_SECTION
     559        section .pdata rdata align=4
     560   %else
     561        section .pdata
     562   %endif
     563        dd      NAME(%1)                    wrt ..imagebase
     564        dd      NAME(%1 %+ _EndProc)        wrt ..imagebase
     565        dd      NAME(%1 %+ .unwind_info)    wrt ..imagebase
     566
     567        ; Restore code section.
     568        BEGINCODE
     569  %endif
     570 %endif
    358571%endmacro
    359572
  • trunk/src/VBox/VMM/VMMR0/HMR0A.asm

    r87451 r87456  
    2020;*********************************************************************************************************************************
    2121;%define RT_ASM_WITH_SEH64  - trouble with SEH, alignment and (probably) 2nd pass optimizations.
     22%define RT_ASM_WITH_SEH64_ALT ; Use asmdefs.mac hackery for manually emitting unwind info.
    2223%include "VBox/asmdefs.mac"
    2324%include "VBox/err.mac"
     
    761762 %endif
    762763 %assign cbBaseFrame         cbFrame
    763         sub     rsp, cbFrame - 8
     764        sub     rsp, cbFrame - 8h
     765        SEH64_ALLOCATE_STACK cbFrame
    764766
    765767        ; Save all general purpose host registers.
  • trunk/src/VBox/VMM/VMMR0/VMMR0JmpA-amd64.asm

    r82968 r87456  
    1919;* Header Files                                                                *
    2020;*******************************************************************************
    21 %define RT_ASM_WITH_SEH64
     21%define RT_ASM_WITH_SEH64_ALT
    2222%include "VBox/asmdefs.mac"
    2323%include "VMMInternal.mac"
     
    5656; @param    pvUser2 msc:r9  gcc:rcx x86:[esp+0x10]     The argument of that function.
    5757;
    58 BEGINPROC vmmR0CallRing3SetJmp
    5958GLOBALNAME vmmR0CallRing3SetJmp2
    6059GLOBALNAME vmmR0CallRing3SetJmpEx
     60BEGINPROC vmmR0CallRing3SetJmp
    6161    ;
    6262    ; Save the registers.
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