1;; Copyright 2020 the V8 project authors. All rights reserved. 2;; Use of this source code is governed by a BSD-style license that can be 3;; found in the LICENSE file. 4 5;; MASM syntax 6;; https://docs.microsoft.com/en-us/cpp/assembler/masm/microsoft-macro-assembler-reference?view=vs-2019 7 8.model flat, C 9 10public PushAllRegistersAndIterateStack 11 12.code 13PushAllRegistersAndIterateStack: 14 ;; Push all callee-saved registers to get them on the stack for conservative 15 ;; stack scanning. 16 ;; 17 ;; We maintain 16-byte alignment at calls. There is an 8-byte return address 18 ;; on the stack and we push 72 bytes which maintains 16-byte stack alignment 19 ;; at the call. 20 ;; 21 ;; The following assumes cdecl calling convention. 22 ;; Source: https://docs.microsoft.com/en-us/cpp/cpp/cdecl?view=vs-2019 23 ;; 24 ;; [ IterateStackCallback ] 25 ;; [ StackVisitor* ] 26 ;; [ Stack* ] 27 ;; [ ret ] 28 push ebp 29 mov ebp, esp 30 push ebx 31 push esi 32 push edi 33 ;; Save 3rd parameter (IterateStackCallback). 34 mov ecx, [ esp + 28 ] 35 ;; Pass 3rd parameter as esp (stack pointer). 36 push esp 37 ;; Pass 2nd parameter (StackVisitor*). 38 push [ esp + 28 ] 39 ;; Pass 1st parameter (Stack*). 40 push [ esp + 28 ] 41 call ecx 42 ;; Pop the callee-saved registers. 43 add esp, 24 44 ;; Restore rbp as it was used as frame pointer. 45 pop ebp 46 ret 47 48end 49