xreturn.py revision 5590
15433Sgblack@eecs.umich.edu# Copyright (c) 2007-2008 The Hewlett-Packard Development Company 25081Sgblack@eecs.umich.edu# All rights reserved. 35081Sgblack@eecs.umich.edu# 45081Sgblack@eecs.umich.edu# Redistribution and use of this software in source and binary forms, 55081Sgblack@eecs.umich.edu# with or without modification, are permitted provided that the 65081Sgblack@eecs.umich.edu# following conditions are met: 75081Sgblack@eecs.umich.edu# 85081Sgblack@eecs.umich.edu# The software must be used only for Non-Commercial Use which means any 95081Sgblack@eecs.umich.edu# use which is NOT directed to receiving any direct monetary 105081Sgblack@eecs.umich.edu# compensation for, or commercial advantage from such use. Illustrative 115081Sgblack@eecs.umich.edu# examples of non-commercial use are academic research, personal study, 125081Sgblack@eecs.umich.edu# teaching, education and corporate research & development. 135081Sgblack@eecs.umich.edu# Illustrative examples of commercial use are distributing products for 145081Sgblack@eecs.umich.edu# commercial advantage and providing services using the software for 155081Sgblack@eecs.umich.edu# commercial advantage. 165081Sgblack@eecs.umich.edu# 175081Sgblack@eecs.umich.edu# If you wish to use this software or functionality therein that may be 185081Sgblack@eecs.umich.edu# covered by patents for commercial use, please contact: 195081Sgblack@eecs.umich.edu# Director of Intellectual Property Licensing 205081Sgblack@eecs.umich.edu# Office of Strategy and Technology 215081Sgblack@eecs.umich.edu# Hewlett-Packard Company 225081Sgblack@eecs.umich.edu# 1501 Page Mill Road 235081Sgblack@eecs.umich.edu# Palo Alto, California 94304 245081Sgblack@eecs.umich.edu# 255081Sgblack@eecs.umich.edu# Redistributions of source code must retain the above copyright notice, 265081Sgblack@eecs.umich.edu# this list of conditions and the following disclaimer. Redistributions 275081Sgblack@eecs.umich.edu# in binary form must reproduce the above copyright notice, this list of 285081Sgblack@eecs.umich.edu# conditions and the following disclaimer in the documentation and/or 295081Sgblack@eecs.umich.edu# other materials provided with the distribution. Neither the name of 305081Sgblack@eecs.umich.edu# the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 315081Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from 325081Sgblack@eecs.umich.edu# this software without specific prior written permission. No right of 335081Sgblack@eecs.umich.edu# sublicense is granted herewith. Derivatives of the software and 345081Sgblack@eecs.umich.edu# output created using the software may be prepared, but only for 355081Sgblack@eecs.umich.edu# Non-Commercial Uses. Derivatives of the software may be shared with 365081Sgblack@eecs.umich.edu# others provided: (i) the others agree to abide by the list of 375081Sgblack@eecs.umich.edu# conditions herein which includes the Non-Commercial Use restrictions; 385081Sgblack@eecs.umich.edu# and (ii) such Derivatives of the software include the above copyright 395081Sgblack@eecs.umich.edu# notice to acknowledge the contribution from this software where 405081Sgblack@eecs.umich.edu# applicable, this list of conditions and the disclaimer below. 415081Sgblack@eecs.umich.edu# 425081Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 435081Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 445081Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 455081Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 465081Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 475081Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 485081Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 495081Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 505081Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 515081Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 525081Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 535081Sgblack@eecs.umich.edu# 545081Sgblack@eecs.umich.edu# Authors: Gabe Black 555081Sgblack@eecs.umich.edu 565081Sgblack@eecs.umich.edumicrocode = ''' 575081Sgblack@eecs.umich.edudef macroop RET_NEAR 585081Sgblack@eecs.umich.edu{ 595081Sgblack@eecs.umich.edu # Make the default data size of rets 64 bits in 64 bit mode 605081Sgblack@eecs.umich.edu .adjust_env oszIn64Override 615081Sgblack@eecs.umich.edu 625081Sgblack@eecs.umich.edu ld t1, ss, [1, t0, rsp] 635119Sgblack@eecs.umich.edu # Check address of return 645081Sgblack@eecs.umich.edu addi rsp, rsp, dsz 655081Sgblack@eecs.umich.edu wripi t1, 0 665081Sgblack@eecs.umich.edu}; 675081Sgblack@eecs.umich.edu 685081Sgblack@eecs.umich.edudef macroop RET_NEAR_I 695081Sgblack@eecs.umich.edu{ 705081Sgblack@eecs.umich.edu # Make the default data size of rets 64 bits in 64 bit mode 715081Sgblack@eecs.umich.edu .adjust_env oszIn64Override 725081Sgblack@eecs.umich.edu 735081Sgblack@eecs.umich.edu limm t2, imm 745081Sgblack@eecs.umich.edu ld t1, ss, [1, t0, rsp] 755119Sgblack@eecs.umich.edu # Check address of return 765081Sgblack@eecs.umich.edu addi rsp, rsp, dsz 775081Sgblack@eecs.umich.edu add rsp, rsp, t2 785081Sgblack@eecs.umich.edu wripi t1, 0 795081Sgblack@eecs.umich.edu}; 805295Sgblack@eecs.umich.edu 815295Sgblack@eecs.umich.edudef macroop RET_FAR { 825295Sgblack@eecs.umich.edu .adjust_env oszIn64Override 835295Sgblack@eecs.umich.edu 845295Sgblack@eecs.umich.edu # Get the return RIP 855295Sgblack@eecs.umich.edu ld t1, ss, [1, t0, rsp] 865295Sgblack@eecs.umich.edu 875295Sgblack@eecs.umich.edu # Get the return CS 885433Sgblack@eecs.umich.edu ld t2, ss, [1, t0, rsp], ssz 895295Sgblack@eecs.umich.edu 905295Sgblack@eecs.umich.edu # Get the rpl 915295Sgblack@eecs.umich.edu andi t3, t2, 0x3 925295Sgblack@eecs.umich.edu 935295Sgblack@eecs.umich.edu # Get the cpl 945295Sgblack@eecs.umich.edu 955295Sgblack@eecs.umich.edu # Here we'd check if we're changing priviledge levels. We'll just hope 965295Sgblack@eecs.umich.edu # that doesn't happen yet. 975295Sgblack@eecs.umich.edu 985295Sgblack@eecs.umich.edu # Do stuff if they're equal 995433Sgblack@eecs.umich.edu andi t0, t2, 0xFC, flags=(EZF,), dataSize=2 1005433Sgblack@eecs.umich.edu bri t0, label("processDescriptor"), flags=(CEZF,) 1015433Sgblack@eecs.umich.edu andi t3, t2, 0xF8, dataSize=8 1025433Sgblack@eecs.umich.edu andi t0, t2, 0x4, flags=(EZF,), dataSize=2 1035433Sgblack@eecs.umich.edu bri t0, label("globalDescriptor"), flags=(CEZF,) 1045433Sgblack@eecs.umich.edu ld t3, tsl, [1, t0, t3], dataSize=8 1055433Sgblack@eecs.umich.edu bri t0, label("processDescriptor") 1065433Sgblack@eecs.umich.eduglobalDescriptor: 1075433Sgblack@eecs.umich.edu ld t3, tsg, [1, t0, t3], dataSize=8 1085433Sgblack@eecs.umich.eduprocessDescriptor: 1095433Sgblack@eecs.umich.edu chks t2, t3, IretCheck, dataSize=8 1105295Sgblack@eecs.umich.edu # There should be validity checks on the RIP checks here, but I'll do 1115295Sgblack@eecs.umich.edu # that later. 1125590Sgblack@eecs.umich.edu wrdl cs, t3, t2 1135590Sgblack@eecs.umich.edu wrsel cs, t2 1145295Sgblack@eecs.umich.edu wrip t0, t1 1155295Sgblack@eecs.umich.edu bri t0, label("end") 1165295Sgblack@eecs.umich.edu 1175295Sgblack@eecs.umich.edu # Do other stuff if they're not. 1185295Sgblack@eecs.umich.eduend: 1195295Sgblack@eecs.umich.edu fault "NoFault" 1205295Sgblack@eecs.umich.edu}; 1215081Sgblack@eecs.umich.edu''' 122