stack_operations.py revision 6344:b7104eda0795
113531Sjairo.balart@metempsy.com# Copyright (c) 2007-2008 The Hewlett-Packard Development Company 214227Sgiacomo.travaglini@arm.com# All rights reserved. 314227Sgiacomo.travaglini@arm.com# 414227Sgiacomo.travaglini@arm.com# Redistribution and use of this software in source and binary forms, 514227Sgiacomo.travaglini@arm.com# with or without modification, are permitted provided that the 614227Sgiacomo.travaglini@arm.com# following conditions are met: 714227Sgiacomo.travaglini@arm.com# 814227Sgiacomo.travaglini@arm.com# The software must be used only for Non-Commercial Use which means any 914227Sgiacomo.travaglini@arm.com# use which is NOT directed to receiving any direct monetary 1014227Sgiacomo.travaglini@arm.com# compensation for, or commercial advantage from such use. Illustrative 1114227Sgiacomo.travaglini@arm.com# examples of non-commercial use are academic research, personal study, 1214227Sgiacomo.travaglini@arm.com# teaching, education and corporate research & development. 1314227Sgiacomo.travaglini@arm.com# Illustrative examples of commercial use are distributing products for 1413531Sjairo.balart@metempsy.com# commercial advantage and providing services using the software for 1513531Sjairo.balart@metempsy.com# commercial advantage. 1613531Sjairo.balart@metempsy.com# 1713531Sjairo.balart@metempsy.com# If you wish to use this software or functionality therein that may be 1813531Sjairo.balart@metempsy.com# covered by patents for commercial use, please contact: 1913531Sjairo.balart@metempsy.com# Director of Intellectual Property Licensing 2013531Sjairo.balart@metempsy.com# Office of Strategy and Technology 2113531Sjairo.balart@metempsy.com# Hewlett-Packard Company 2213531Sjairo.balart@metempsy.com# 1501 Page Mill Road 2313531Sjairo.balart@metempsy.com# Palo Alto, California 94304 2413531Sjairo.balart@metempsy.com# 2513531Sjairo.balart@metempsy.com# Redistributions of source code must retain the above copyright notice, 2613531Sjairo.balart@metempsy.com# this list of conditions and the following disclaimer. Redistributions 2713531Sjairo.balart@metempsy.com# in binary form must reproduce the above copyright notice, this list of 2813531Sjairo.balart@metempsy.com# conditions and the following disclaimer in the documentation and/or 2913531Sjairo.balart@metempsy.com# other materials provided with the distribution. Neither the name of 3013531Sjairo.balart@metempsy.com# the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 3113531Sjairo.balart@metempsy.com# contributors may be used to endorse or promote products derived from 3213531Sjairo.balart@metempsy.com# this software without specific prior written permission. No right of 3313531Sjairo.balart@metempsy.com# sublicense is granted herewith. Derivatives of the software and 3413531Sjairo.balart@metempsy.com# output created using the software may be prepared, but only for 3513531Sjairo.balart@metempsy.com# Non-Commercial Uses. Derivatives of the software may be shared with 3613531Sjairo.balart@metempsy.com# others provided: (i) the others agree to abide by the list of 3713531Sjairo.balart@metempsy.com# conditions herein which includes the Non-Commercial Use restrictions; 3813531Sjairo.balart@metempsy.com# and (ii) such Derivatives of the software include the above copyright 3913531Sjairo.balart@metempsy.com# notice to acknowledge the contribution from this software where 4013531Sjairo.balart@metempsy.com# applicable, this list of conditions and the disclaimer below. 4113531Sjairo.balart@metempsy.com# 4213531Sjairo.balart@metempsy.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4313531Sjairo.balart@metempsy.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 4413531Sjairo.balart@metempsy.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 4513531Sjairo.balart@metempsy.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 4613531Sjairo.balart@metempsy.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4713531Sjairo.balart@metempsy.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 4813531Sjairo.balart@metempsy.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 4913760Sjairo.balart@metempsy.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 5013531Sjairo.balart@metempsy.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 5113531Sjairo.balart@metempsy.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 5213531Sjairo.balart@metempsy.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5313531Sjairo.balart@metempsy.com# 5413531Sjairo.balart@metempsy.com# Authors: Gabe Black 5513531Sjairo.balart@metempsy.com 5613760Sjairo.balart@metempsy.commicrocode = ''' 5713531Sjairo.balart@metempsy.comdef macroop POP_R { 5813531Sjairo.balart@metempsy.com # Make the default data size of pops 64 bits in 64 bit mode 5913531Sjairo.balart@metempsy.com .adjust_env oszIn64Override 6013531Sjairo.balart@metempsy.com 6113531Sjairo.balart@metempsy.com ld t1, ss, [1, t0, rsp], dataSize=ssz 6213531Sjairo.balart@metempsy.com addi rsp, rsp, ssz, dataSize=asz 6313531Sjairo.balart@metempsy.com mov reg, reg, t1 6413531Sjairo.balart@metempsy.com}; 6513531Sjairo.balart@metempsy.com 6613826Sgiacomo.travaglini@arm.comdef macroop POP_M { 6713826Sgiacomo.travaglini@arm.com # Make the default data size of pops 64 bits in 64 bit mode 6813760Sjairo.balart@metempsy.com .adjust_env oszIn64Override 6913760Sjairo.balart@metempsy.com 7013760Sjairo.balart@metempsy.com ld t1, ss, [1, t0, rsp], dataSize=ssz 7113760Sjairo.balart@metempsy.com cda seg, sib, disp, dataSize=ssz 7213760Sjairo.balart@metempsy.com addi rsp, rsp, ssz, dataSize=asz 7313760Sjairo.balart@metempsy.com st t1, seg, sib, disp, dataSize=ssz 7413760Sjairo.balart@metempsy.com}; 7513760Sjairo.balart@metempsy.com 7613760Sjairo.balart@metempsy.comdef macroop POP_P { 7713760Sjairo.balart@metempsy.com # Make the default data size of pops 64 bits in 64 bit mode 7813760Sjairo.balart@metempsy.com .adjust_env oszIn64Override 7913760Sjairo.balart@metempsy.com 8013760Sjairo.balart@metempsy.com rdip t7 8113760Sjairo.balart@metempsy.com ld t1, ss, [1, t0, rsp], dataSize=ssz 8213760Sjairo.balart@metempsy.com cda seg, sib, disp, dataSize=ssz 8313531Sjairo.balart@metempsy.com addi rsp, rsp, ssz, dataSize=asz 8413760Sjairo.balart@metempsy.com st t1, seg, riprel, disp, dataSize=ssz 8513760Sjairo.balart@metempsy.com}; 8613760Sjairo.balart@metempsy.com 8713760Sjairo.balart@metempsy.comdef macroop PUSH_R { 8813760Sjairo.balart@metempsy.com # Make the default data size of pops 64 bits in 64 bit mode 8913760Sjairo.balart@metempsy.com .adjust_env oszIn64Override 9013760Sjairo.balart@metempsy.com 9113760Sjairo.balart@metempsy.com stupd reg, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 9213760Sjairo.balart@metempsy.com}; 9313760Sjairo.balart@metempsy.com 9413760Sjairo.balart@metempsy.comdef macroop PUSH_I { 9513760Sjairo.balart@metempsy.com # Make the default data size of pops 64 bits in 64 bit mode 9613760Sjairo.balart@metempsy.com .adjust_env oszIn64Override 9713760Sjairo.balart@metempsy.com 9813760Sjairo.balart@metempsy.com limm t1, imm 9913760Sjairo.balart@metempsy.com stupd t1, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 10013760Sjairo.balart@metempsy.com}; 10113760Sjairo.balart@metempsy.com 10213760Sjairo.balart@metempsy.comdef macroop PUSH_M { 10313531Sjairo.balart@metempsy.com # Make the default data size of pops 64 bits in 64 bit mode 10413760Sjairo.balart@metempsy.com .adjust_env oszIn64Override 10513760Sjairo.balart@metempsy.com 10613760Sjairo.balart@metempsy.com ld t1, seg, sib, disp, dataSize=ssz 10713760Sjairo.balart@metempsy.com stupd t1, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 10813531Sjairo.balart@metempsy.com}; 10913760Sjairo.balart@metempsy.com 11013760Sjairo.balart@metempsy.comdef macroop PUSH_P { 11113760Sjairo.balart@metempsy.com # Make the default data size of pops 64 bits in 64 bit mode 11213760Sjairo.balart@metempsy.com .adjust_env oszIn64Override 11313531Sjairo.balart@metempsy.com 11413760Sjairo.balart@metempsy.com rdip t7 11513760Sjairo.balart@metempsy.com ld t1, seg, riprel, disp, dataSize=ssz 11613760Sjairo.balart@metempsy.com stupd t1, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 11713760Sjairo.balart@metempsy.com}; 11813760Sjairo.balart@metempsy.com 11913531Sjairo.balart@metempsy.comdef macroop PUSHA { 12013760Sjairo.balart@metempsy.com # Check all the stack addresses. We'll assume that if the beginning and 12113760Sjairo.balart@metempsy.com # end are ok, then the stuff in the middle should be as well. 12213760Sjairo.balart@metempsy.com cda ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 12313760Sjairo.balart@metempsy.com cda ss, [1, t0, rsp], "-8 * env.stackSize", dataSize=ssz 12413760Sjairo.balart@metempsy.com stupd rax, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 12513760Sjairo.balart@metempsy.com stupd rcx, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 12613531Sjairo.balart@metempsy.com stupd rdx, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 12713760Sjairo.balart@metempsy.com stupd rbx, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 12813760Sjairo.balart@metempsy.com stupd rsp, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 12913760Sjairo.balart@metempsy.com stupd rbp, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 13013760Sjairo.balart@metempsy.com stupd rsi, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 13113760Sjairo.balart@metempsy.com stupd rdi, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 13213760Sjairo.balart@metempsy.com}; 13313760Sjairo.balart@metempsy.com 13413760Sjairo.balart@metempsy.comdef macroop POPA { 13513760Sjairo.balart@metempsy.com # Check all the stack addresses. We'll assume that if the beginning and 13613760Sjairo.balart@metempsy.com # end are ok, then the stuff in the middle should be as well. 13713760Sjairo.balart@metempsy.com ld t1, ss, [1, t0, rsp], "0 * env.stackSize", dataSize=ssz 13813760Sjairo.balart@metempsy.com ld t2, ss, [1, t0, rsp], "7 * env.stackSize", dataSize=ssz 13913760Sjairo.balart@metempsy.com mov rdi, rdi, t1, dataSize=ssz 14013760Sjairo.balart@metempsy.com ld rsi, ss, [1, t0, rsp], "1 * env.stackSize", dataSize=ssz 14113760Sjairo.balart@metempsy.com ld rbp, ss, [1, t0, rsp], "2 * env.stackSize", dataSize=ssz 14213531Sjairo.balart@metempsy.com ld rbx, ss, [1, t0, rsp], "4 * env.stackSize", dataSize=ssz 14313531Sjairo.balart@metempsy.com ld rdx, ss, [1, t0, rsp], "5 * env.stackSize", dataSize=ssz 14413531Sjairo.balart@metempsy.com ld rcx, ss, [1, t0, rsp], "6 * env.stackSize", dataSize=ssz 14513760Sjairo.balart@metempsy.com mov rax, rax, t2, dataSize=ssz 14613531Sjairo.balart@metempsy.com addi rsp, rsp, "8 * env.stackSize", dataSize=asz 14713760Sjairo.balart@metempsy.com}; 14813531Sjairo.balart@metempsy.com 14913531Sjairo.balart@metempsy.comdef macroop LEAVE { 15013760Sjairo.balart@metempsy.com # Make the default data size of pops 64 bits in 64 bit mode 15113531Sjairo.balart@metempsy.com .adjust_env oszIn64Override 15213760Sjairo.balart@metempsy.com 15313531Sjairo.balart@metempsy.com mov t1, t1, rbp, dataSize=asz 15413531Sjairo.balart@metempsy.com ld rbp, ss, [1, t0, t1], dataSize=ssz 15513531Sjairo.balart@metempsy.com mov rsp, rsp, t1, dataSize=asz 15613531Sjairo.balart@metempsy.com addi rsp, rsp, ssz, dataSize=asz 15713531Sjairo.balart@metempsy.com}; 15813531Sjairo.balart@metempsy.com 15913531Sjairo.balart@metempsy.comdef macroop ENTER_I_I { 16013531Sjairo.balart@metempsy.com # This needs to check all the addresses it writes to before it actually 16113531Sjairo.balart@metempsy.com # writes any values. 16213531Sjairo.balart@metempsy.com 16313531Sjairo.balart@metempsy.com # Pull the different components out of the immediate 16413531Sjairo.balart@metempsy.com limm t1, imm 16513531Sjairo.balart@metempsy.com zexti t2, t1, 15, dataSize=8 16613760Sjairo.balart@metempsy.com srli t1, t1, 16 16713760Sjairo.balart@metempsy.com zexti t1, t1, 5, dataSize=8 16813760Sjairo.balart@metempsy.com # t1 is now the masked nesting level, and t2 is the amount of storage. 16913760Sjairo.balart@metempsy.com 17013760Sjairo.balart@metempsy.com # Push rbp. 17113760Sjairo.balart@metempsy.com stupd rbp, ss, [1, t0, rsp], "-env.stackSize", dataSize=ssz 17213760Sjairo.balart@metempsy.com 17313760Sjairo.balart@metempsy.com # Save the stack pointer for later 17413760Sjairo.balart@metempsy.com mov t6, t6, rsp, dataSize=asz 17513760Sjairo.balart@metempsy.com 17613760Sjairo.balart@metempsy.com # If the nesting level is zero, skip all this stuff. 17713531Sjairo.balart@metempsy.com sub t0, t1, t0, flags=(EZF,), dataSize=2 17813760Sjairo.balart@metempsy.com br label("skipLoop"), flags=(CEZF,) 17913531Sjairo.balart@metempsy.com 18013531Sjairo.balart@metempsy.com # If the level was 1, only push the saved rbp 18113531Sjairo.balart@metempsy.com subi t0, t1, 1, flags=(EZF,) 18213531Sjairo.balart@metempsy.com br label("bottomOfLoop"), flags=(CEZF,) 18313531Sjairo.balart@metempsy.com 18413531Sjairo.balart@metempsy.com limm t4, "ULL(-1)", dataSize=8 18513531Sjairo.balart@metempsy.comtopOfLoop: 18613760Sjairo.balart@metempsy.com ld t5, ss, [ssz, t4, rbp], dataSize=ssz 18713760Sjairo.balart@metempsy.com stupd t5, ss, [1, t0, rsp], "-env.stackSize" 18813760Sjairo.balart@metempsy.com 18913760Sjairo.balart@metempsy.com # If we're not done yet, loop 19013760Sjairo.balart@metempsy.com subi t4, t4, 1, dataSize=8 19113531Sjairo.balart@metempsy.com add t0, t4, t1, flags=(EZF,) 19213531Sjairo.balart@metempsy.com br label("topOfLoop"), flags=(nCEZF,) 19313531Sjairo.balart@metempsy.com 19413531Sjairo.balart@metempsy.combottomOfLoop: 19513531Sjairo.balart@metempsy.com # Push the old rbp onto the stack 19613531Sjairo.balart@metempsy.com stupd t6, ss, [1, t0, rsp], "-env.stackSize" 19713760Sjairo.balart@metempsy.com 19813760Sjairo.balart@metempsy.comskipLoop: 19913760Sjairo.balart@metempsy.com sub rsp, rsp, t2, dataSize=asz 20013760Sjairo.balart@metempsy.com mov rbp, rbp, t6, dataSize=asz 20113760Sjairo.balart@metempsy.com}; 20213760Sjairo.balart@metempsy.com''' 20313760Sjairo.balart@metempsy.com