1;++ 2; 3; Copyright (c) Microsoft Corporation. All rights reserved. 4; 5; 6; Module: 7; 8; macamd64.w 9; 10; Astract: 11; 12; Contains AMD64 public architecture constants and assembly macros. 13; 14; Author: 15;-- 16 17;++ 18; 19; push_reg <reg> 20; 21; Macro Description: 22; 23; This macro emits a single-byte push <reg> instruction in a 24; nested prologue, as well as the associated unwind code. 25; 26; Arguments: 27; 28; reg - supplies the integer register to push 29; 30;-- 31 32push_reg macro Reg 33 34 push Reg 35 .pushreg Reg 36 37 endm 38 39;++ 40; 41; rex_push_reg <reg> 42; 43; Macro Description: 44; 45; This macro emits a single-byte push <reg> instruction in a 46; nested prologue, as well as the associated unwind code. 47; 48; This differs from push_reg only in that a redundant rex prefix 49; is added. rex_push_reg must be used in lieu of push_reg when it 50; appears as the first instruction in a function, as the calling 51; standard dictates that functions must not begin with a single 52; byte instruction. 53; 54; Arguments: 55; 56; reg - supplies the integer register to push 57; 58;-- 59 60rex_push_reg macro Reg 61 62 db 048h 63 push Reg 64 .pushreg Reg 65 66 endm 67 68;++ 69; 70; push_eflags 71; 72; Macro Description: 73; 74; This macro emits a single-byte pushfq instruction in a 75; nested prologue, as well as the associated unwind code. 76; 77; Arguments: 78; 79; none 80; 81;-- 82 83push_eflags macro 84 85 pushfq 86 .allocstack 8 87 88 endm 89 90;++ 91; 92; rex_push_eflags 93; 94; Macro Description: 95; 96; This macro emits a single-byte pushfq instruction in a 97; nested prologue, as well as the associated unwind code. 98; 99; This differs from push_eflags only in that a redundant rex prefix 100; is added. rex_push_eflags must be used in lieu of push_eflags when it 101; appears as the first instruction in a function, as the calling 102; standard dictates that functions must not begin with a single 103; byte instruction. 104; 105; Arguments: 106; 107; none 108; 109;-- 110 111rex_push_eflags macro 112 113 db 048h 114 pushfq 115 .allocstack 8 116 117 endm 118 119;++ 120; 121; rex_jmp_reg <reg> 122; 123; Macro Description: 124; 125; This macro emits a jmp <reg> instruction in a nested epilogue. 126; 127; This differs from jmp reg only in that a redundant rex prefix 128; is added. rex_jmp_reg must be be used in lieu of jmp when it 129; appears as a tail call terminating an epilogue of a function, 130; as the calling dictates that functions that exit an epilogue 131; with a jmp reg must include a redundant rex prefix to signify 132; the presence of a tail call epilogue to the unwinder. 133; 134; Arguments: 135; 136; reg - supplies the integer register to jump to. 137; 138;-- 139 140rex_jmp_reg macro Reg 141 142 rexw jmp Reg 143 144 endm 145 146;++ 147; 148; ret_zero 149; 150; Macro Description: 151; 152; This macro emits a three byte return instruction. 153; 154; This differs from the typical ret in that it adds additional padding bytes 155; that prevent branch misprediction problems when the ret is the target of 156; a (un)conditional branch, or is immediately preceded by a conditional branch. 157; 158; Arguments: 159; 160; none 161; 162;-- 163 164ret_zero macro 165 166 ret 167 168 endm 169 170;++ 171; 172; alloc_stack <Size> 173; 174; Macro Description: 175; 176; This macro emits an opcode to subtract <Size> from rsp, as well 177; as the associated unwind code. 178; 179; Arguments: 180; 181; Size - The number of bytes to subtract from rsp. 182; 183;-- 184 185alloc_stack macro Size 186 187 sub rsp, Size 188 .allocstack Size 189 190 endm 191 192;++ 193; 194; save_reg <Reg>, <Offset> 195; 196; Macro Description: 197; 198; This macro emits an opcode to save the non-volatile 64-bit general purpose 199; register indicated by <Reg> at offset <Offset> relative to the current 200; position of the stack pointer. It also generates the associated unwind 201; code. 202; 203; Arguments: 204; 205; Reg - Supplies the integer register to save 206; 207; Offset - Supplies the offset relative to the current position of the stack 208; pointer. 209; 210;-- 211 212save_reg macro Reg, Offset 213 214 mov Offset[rsp], Reg 215 .savereg Reg, Offset 216 217 endm 218 219;++ 220; 221; save_xmm128 <Reg>, <Offset> 222; 223; Macro Description: 224; 225; This macro emits an opcode to save the 128-bit non-volatile xmm register 226; indicated by <Reg> at offset <Offset> relative to the current position 227; of the stack pointer. It also generates the associated unwind code. 228; 229; Arguments: 230; 231; Reg - Supplies the xmm register register to save 232; 233; Offset - Supplies the offset relative to the current position of the stack 234; pointer. 235; 236;-- 237 238save_xmm128 macro Reg, Offset 239 240 movaps Offset[rsp], Reg 241 .savexmm128 Reg, Offset 242 243 endm 244 245;++ 246; 247; push_frame 248; 249; Macro Description: 250; 251; This macro emits unwind data indicating that a machine frame has been 252; pushed on the stack (usually by the CPU in response to a trap or fault). 253; 254; Arguments: 255; 256; None. 257; 258;-- 259 260push_frame macro Code 261 262 .pushframe Code 263 264 endm 265 266;++ 267; 268; set_frame <Reg>, <Offset> 269; 270; Macro Description: 271; 272; This macro emits an opcode and unwind data establishing the use of <Reg> 273; as the current stack frame pointer. 274; 275; Arguments: 276; 277; Reg - Supplies the integer register to use as the current stack frame 278; pointer. 279; 280; Offset - Supplies the optional offset of the frame pointer relative to 281; the stack frame. In stack frames greater than 080h bytes, 282; a non-zero offset can help reduce the size of subsequent opcodes 283; that access portions of the stack frame by facilitating the use of 284; positive and negative single-byte displacements. 285; 286; If not supplied, no offset is assumed. 287; 288;-- 289 290set_frame macro Reg, Offset 291 292if Offset 293 294 lea Reg, Offset[rsp] 295 296else 297 298 mov Reg, rsp 299 300endif 301 302 .setframe Reg, Offset 303 304 endm 305 306;++ 307; 308; END_PROLOGUE 309; 310; Macro Description: 311; 312; This macro marks the end of the prologue. This must appear after all 313; of the prologue directives in a nested function. 314; 315; Arguments: 316; 317; None. 318; 319;-- 320 321END_PROLOGUE macro 322 323 .endprolog 324 325 endm 326 327;++ 328; 329; Macro Description: 330; 331; This macro marks the beginning of a function epilogue. It may appear 332; one or more times within a function body. The epilogue ends at the 333; next control transfer instruction. 334; 335; Arguments: 336; 337; None. 338; 339;-- 340 341BEGIN_EPILOGUE macro 342 343 .beginepilog 344 345 endm 346 347;++ 348; 349; LEAF_ENTRY <Name>, <Section>, <NoPad> 350; 351; Macro Description: 352; 353; This macro indicates the beginning of a leaf function. 354; 355; A leaf function is one that DOES NOT: 356; 357; - manipulate non-volatile registers 358; - manipulate the stack pointer 359; - call other functions 360; - reference an exception handler 361; - contain a prologue 362; - have any unwind data associated with it 363; 364; Arguments: 365; 366; Name - Supplies the name of the function 367; 368; Section - Supplies the name of the section within which the function 369; is to appear 370; 371; NoPad - If present, indicates that the function should not be prefixed 372; with 6 bytes of padding. This is for internal use only - the 373; calling standard dictates that functions (nested and leaf) must 374; be prefixed with padding. 375; 376;-- 377 378LEAF_ENTRY macro Name, Section, NoPad 379 380Section segment para 'CODE' 381 382ifb <NoPad> 383 384 db 6 dup (0cch) 385 386endif 387 388 align 16 389 390 public Name 391Name proc frame 392 393 END_PROLOGUE 394 395 endm 396 397;++ 398; 399; LEAF_ENTRY_ARG1 <Name>, <Section>, <Arg1>, <NoPad> 400; 401; Macro Description: 402; 403; Indicates the beginning of a leaf function, as LEAF_ENTRY above, 404; and declares one input parameter so that debug info will be 405; generated for it. The other forms, LEAF_ENTRY_ARG2 and LEAF_ENTRY_ARG3, 406; are similar. 407; 408;-- 409 410LEAF_ENTRY_ARG1 macro Name, Section, Arg1, NoPad 411 412Section segment para 'CODE' 413 414ifb <NoPad> 415 416 db 6 dup (0cch) 417 418endif 419 420 align 16 421 422 public Name 423Name proc frame 424 425 END_PROLOGUE 426 427 endm 428 429;++ 430; 431; LEAF_ENTRY_ARG2 <Name>, <Section>, <Arg1>, <Arg2>, <NoPad> 432; 433; Macro Description: 434; 435; As LEAF_ENTRY_ARG1 above, marks the entry to a leaf function 436; and defines 2 input parameters. 437; 438;-- 439 440LEAF_ENTRY_ARG2 macro Name, Section, Arg1, Arg2, NoPad 441 442Section segment para 'CODE' 443 444ifb <NoPad> 445 446 db 6 dup (0cch) 447 448endif 449 450 align 16 451 452 public Name 453Name proc frame 454 455 END_PROLOGUE 456 457 endm 458 459;++ 460; 461; LEAF_ENTRY_ARG3 <Name>, <Section>, <Arg1>, <Arg2>, <Arg3>, <NoPad> 462; 463; Macro Description: 464; 465; As LEAF_ENTRY_ARG1 above, marks the entry to a leaf function 466; and defines 3 input parameters. 467; 468;-- 469 470LEAF_ENTRY_ARG3 macro Name, Section, Arg1, Arg2, Arg3, NoPad 471 472Section segment para 'CODE' 473 474ifb <NoPad> 475 476 db 6 dup (0cch) 477 478endif 479 480 align 16 481 482 public Name 483Name proc frame 484 485 END_PROLOGUE 486 487 endm 488 489;++ 490; 491; LEAF_END <Name>, <Section> 492; 493; Macro Description: 494; 495; This macro indicates the end of a leaf function. It must be paired 496; with a LEAF_ENTRY macro that includes matching Name and Section 497; parameters. 498; 499; Arguments: 500; 501; Name - Supplies the name of the function. Must match that supplied to 502; the corresponding LEAF_ENTRY macro. 503; 504; Section - Supplies the name of the section within which the function 505; is to appear. Must match that supplied to the corresponding 506; LEAF_ENTRY macro. 507; 508;-- 509 510LEAF_END macro Name, section 511 512Name endp 513 514Section ends 515 516 endm 517 518;++ 519; 520; NESTED_ENTRY <Name>, <Section>, <Handler>, <NoPad> 521; 522; Macro Description: 523; 524; This macro indicates the beginning of a nested function. 525; 526; A nested function is one that does any of the following: 527; 528; - manipulates non-volatile registers 529; - manipulates the stack pointer 530; - references an exception handler 531; - calls other functions 532; 533; A nested function must include a prologue with unwind data. 534; 535; Arguments: 536; 537; Name - Supplies the name of the function. 538; 539; Section - Supplies the name of the section within which the function 540; is to appear. 541; 542; Handler - Supplies the name of the handler for exceptions raised 543; within the scope of this function. 544; 545; NoPad - If present, indicates that the function should not be prefixed 546; with 6 bytes of padding. This is for internal use only - the 547; calling standard dictates that functions (nested and leaf) must 548; be prefixed with padding. 549; 550;-- 551 552NESTED_ENTRY macro Name, Section, Handler, NoPad 553 554ifdef _CurrentSection_ 555 556ifdif <Section>, _CurrentSection_ 557 558.err <NESTED_ENTRY invoked for different sections within same module> 559 560endif 561 562endif 563 564_CurrentSection_ EQU <Section> 565 566Section segment para 'CODE' 567 568ifb <NoPad> 569 570 db 6 dup (0cch) 571 572endif 573 574 align 16 575 576 public Name 577 578ifb <Handler> 579 580Name proc frame 581 582else 583 584Name proc frame:Handler 585 586endif 587 588 endm 589 590;++ 591; 592; NESTED_END <Name>, <Section> 593; 594; Macro Description: 595; 596; This macro indicates the end of a nested function. It must be paired 597; with a NESTED_ENTRY macro that includes matching Name and Section 598; parameters. 599; 600; Arguments: 601; 602; Name - Supplies the name of the function. Must match that supplied to 603; the corresponding NESTED_ENTRY macro. 604; 605; Section - Supplies the name of the section within which the function 606; is to appear. Must match that supplied to the corresponding 607; NESTED_ENTRY macro. 608; 609;-- 610 611NESTED_END macro Name, section 612 613Name endp 614 615Section ends 616 617 endm 618 619;++ 620; 621; ALTERNATE_ENTRY <Name> 622; 623; Macro Description: 624; 625; This macro indicates an alternate entry point in a function, or 626; a synonymous name for an existing function. 627; 628; Arguments: 629; 630; Name - Supplies the name of the alternate entry point. 631; 632;-- 633 634ALTERNATE_ENTRY macro Name 635 636Name: 637 endm 638 639;++ 640; 641; Yield 642; 643; Macro Description: 644; 645; This macro generates a yield instruction, interpreted by SMT processors 646; as an indication of a stall or idle condition. 647; 648; Arguments: 649; 650; None. 651; 652;-- 653 654Yield macro 655 656 pause ; yield execution on SMT processors 657 658 endm 659 660;++ 661; 662; RetpolineIgnore 663; 664; Macro Description: 665; 666; This macro generates a retpoline ignore directive which informs tools that 667; retpoline instrumentation is not required. 668; 669; Arguments: 670; 671; None. 672; 673;-- 674 675RetpolineIgnore macro 676 677ifdef _RETPOLINE 678 679 .retpolineignore ; mark branch as retpoline-ignored 680 681endif 682 683 endm 684 685 686