system_calls.py revision 7087:fb8d5786ff30
113540Sandrea.mondelli@ucf.edu# Copyright (c) 2007 The Hewlett-Packard Development Company 24479Sbinkertn@umich.edu# All rights reserved. 34479Sbinkertn@umich.edu# 44479Sbinkertn@umich.edu# The license below extends only to copyright in the software and shall 54479Sbinkertn@umich.edu# not be construed as granting a license to any other intellectual 64479Sbinkertn@umich.edu# property including but not limited to intellectual property relating 74479Sbinkertn@umich.edu# to a hardware implementation of the functionality of the software 84479Sbinkertn@umich.edu# licensed hereunder. You may use the software subject to the license 94479Sbinkertn@umich.edu# terms below provided that you ensure that this notice is replicated 104479Sbinkertn@umich.edu# unmodified and in its entirety in all distributions of the software, 114479Sbinkertn@umich.edu# modified or unmodified, in source code or in binary form. 124479Sbinkertn@umich.edu# 134479Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 144479Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 154479Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 164479Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 176498Snate@binkert.org# redistributions in binary form must reproduce the above copyright 186498Snate@binkert.org# notice, this list of conditions and the following disclaimer in the 196498Snate@binkert.org# documentation and/or other materials provided with the distribution; 204479Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 214479Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 224479Sbinkertn@umich.edu# this software without specific prior written permission. 234479Sbinkertn@umich.edu# 244479Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 254479Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 264479Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 274479Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 284479Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 294479Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 304479Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 314479Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 324479Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 334479Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 344479Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 354479Sbinkertn@umich.edu# 364479Sbinkertn@umich.edu# Authors: Gabe Black 374479Sbinkertn@umich.edu 384479Sbinkertn@umich.edumicrocode = ''' 394479Sbinkertn@umich.edudef macroop SYSCALL_64 404479Sbinkertn@umich.edu{ 414479Sbinkertn@umich.edu # All 1s. 424479Sbinkertn@umich.edu limm t1, "(uint64_t)(-1)", dataSize=8 434479Sbinkertn@umich.edu 444479Sbinkertn@umich.edu # Save the next RIP. 454479Sbinkertn@umich.edu rdip rcx 464479Sbinkertn@umich.edu 474479Sbinkertn@umich.edu # Stick rflags with RF masked into r11. 484479Sbinkertn@umich.edu rflags t2 494479Sbinkertn@umich.edu limm t3, "~RFBit", dataSize=8 504479Sbinkertn@umich.edu and r11, t2, t3, dataSize=8 514479Sbinkertn@umich.edu 524479Sbinkertn@umich.edu rdval t3, star 534479Sbinkertn@umich.edu srli t3, t3, 32, dataSize=8 544479Sbinkertn@umich.edu andi t3, t3, 0xFC, dataSize=1 554479Sbinkertn@umich.edu 566498Snate@binkert.org # Set up CS. 574479Sbinkertn@umich.edu wrsel cs, t3 584479Sbinkertn@umich.edu wrbase cs, t0, dataSize=8 596498Snate@binkert.org wrlimit cs, t1, dataSize=4 604479Sbinkertn@umich.edu # Not writable, read/execute-able, not expandDown, 614479Sbinkertn@umich.edu # dpl=0, defaultSize=0, long mode 624479Sbinkertn@umich.edu limm t4, ((0 << 0) | (0 << 2) | (0 << 3) | \ 634479Sbinkertn@umich.edu (1 << 4) | (0 << 5) | (1 << 6) | \ 644479Sbinkertn@umich.edu (1 << 7) | (10 << 8) | (0 << 12) | \ 654479Sbinkertn@umich.edu (1 << 13) | (0 << 14) | (1 << 15)), dataSize=8 664479Sbinkertn@umich.edu wrattr cs, t4 674479Sbinkertn@umich.edu 684479Sbinkertn@umich.edu # Set up SS. 694479Sbinkertn@umich.edu addi t3, t3, 8 704479Sbinkertn@umich.edu wrsel ss, t3 714479Sbinkertn@umich.edu wrbase ss, t0, dataSize=8 724479Sbinkertn@umich.edu wrlimit ss, t1, dataSize=4 734479Sbinkertn@umich.edu # Writable, readable, not expandDown, 744479Sbinkertn@umich.edu # dpl=0, defaultSize=0, not long mode 754479Sbinkertn@umich.edu limm t4, ((0 << 0) | (0 << 2) | (1 << 3) | \ 764479Sbinkertn@umich.edu (0 << 4) | (0 << 5) | (1 << 6) | \ 774479Sbinkertn@umich.edu (1 << 7) | (2 << 8) | (1 << 12) | \ 784479Sbinkertn@umich.edu (1 << 13) | (0 << 14) | (1 << 15)), dataSize=8 794479Sbinkertn@umich.edu wrattr ss, t4 804479Sbinkertn@umich.edu 814479Sbinkertn@umich.edu # Set the new rip. 824479Sbinkertn@umich.edu rdval t7, lstar 834479Sbinkertn@umich.edu wrip t0, t7 844479Sbinkertn@umich.edu 856498Snate@binkert.org # Mask the flags against sf_mask and leave RF turned off. 864479Sbinkertn@umich.edu rdval t3, sf_mask, dataSize=8 874479Sbinkertn@umich.edu xor t3, t3, t1, dataSize=8 884479Sbinkertn@umich.edu and t3, t3, r11, dataSize=8 894479Sbinkertn@umich.edu wrflags t3, t0 904479Sbinkertn@umich.edu}; 914479Sbinkertn@umich.edu 924479Sbinkertn@umich.edudef macroop SYSCALL_COMPAT 934479Sbinkertn@umich.edu{ 944479Sbinkertn@umich.edu # All 1s. 956498Snate@binkert.org limm t1, "(uint64_t)(-1)", dataSize=8 964479Sbinkertn@umich.edu 976498Snate@binkert.org # Save the next RIP. 984479Sbinkertn@umich.edu rdip rcx 994479Sbinkertn@umich.edu 1004479Sbinkertn@umich.edu # Stick rflags with RF masked into r11. 1014479Sbinkertn@umich.edu rflags t2 1024479Sbinkertn@umich.edu limm t3, "~RFBit", dataSize=8 1034479Sbinkertn@umich.edu and r11, t2, t3, dataSize=8 1044479Sbinkertn@umich.edu 1054479Sbinkertn@umich.edu rdval t3, star 1064479Sbinkertn@umich.edu srli t3, t3, 32, dataSize=8 1074479Sbinkertn@umich.edu andi t3, t3, 0xFC, dataSize=1 1084479Sbinkertn@umich.edu 1094479Sbinkertn@umich.edu # Set up CS. 1104479Sbinkertn@umich.edu wrsel cs, t3 1114479Sbinkertn@umich.edu wrbase cs, t0, dataSize=8 1124479Sbinkertn@umich.edu wrlimit cs, t1, dataSize=4 1134479Sbinkertn@umich.edu # Not writable, read/execute-able, not expandDown, 1144479Sbinkertn@umich.edu # dpl=0, defaultSize=0, long mode 1156498Snate@binkert.org limm t4, ((0 << 0) | (0 << 2) | (0 << 3) | \ 1164479Sbinkertn@umich.edu (1 << 4) | (0 << 5) | (1 << 6) | \ 1174479Sbinkertn@umich.edu (1 << 7) | (10 << 8) | (0 << 12) | \ 1184479Sbinkertn@umich.edu (1 << 13) | (0 << 14) | (1 << 15)), dataSize=8 1194479Sbinkertn@umich.edu wrattr cs, t4 1204479Sbinkertn@umich.edu 1214479Sbinkertn@umich.edu # Set up SS. 1224479Sbinkertn@umich.edu addi t3, t3, 8 1234479Sbinkertn@umich.edu wrsel ss, t3 1244479Sbinkertn@umich.edu wrbase ss, t0, dataSize=8 1254479Sbinkertn@umich.edu wrlimit ss, t1, dataSize=4 1264479Sbinkertn@umich.edu # Writable, readable, not expandDown, 1274479Sbinkertn@umich.edu # dpl=0, defaultSize=0, not long mode 1284479Sbinkertn@umich.edu limm t4, ((0 << 0) | (0 << 2) | (1 << 3) | \ 1294479Sbinkertn@umich.edu (0 << 4) | (0 << 5) | (1 << 6) | \ 1304479Sbinkertn@umich.edu (1 << 7) | (2 << 8) | (1 << 12) | \ 1314479Sbinkertn@umich.edu (1 << 13) | (0 << 14) | (1 << 15)), dataSize=8 1324479Sbinkertn@umich.edu wrattr ss, t4 1334479Sbinkertn@umich.edu 1344479Sbinkertn@umich.edu # Set the new rip. 1354479Sbinkertn@umich.edu rdval t7, cstar 1364479Sbinkertn@umich.edu wrip t0, t7 1374479Sbinkertn@umich.edu 1384479Sbinkertn@umich.edu # Mask the flags against sf_mask and leave RF turned off. 1394479Sbinkertn@umich.edu rdval t3, sf_mask, dataSize=8 1404479Sbinkertn@umich.edu xor t3, t3, t1, dataSize=8 1414479Sbinkertn@umich.edu and t3, t3, r11, dataSize=8 1424479Sbinkertn@umich.edu wrflags t3, t0 1434479Sbinkertn@umich.edu}; 1444479Sbinkertn@umich.edu 1454479Sbinkertn@umich.edudef macroop SYSCALL_LEGACY 1464479Sbinkertn@umich.edu{ 1474479Sbinkertn@umich.edu panic "The syscall instruction isn't implemented in legacy mode." 1484479Sbinkertn@umich.edu}; 1496498Snate@binkert.org 1504479Sbinkertn@umich.edudef macroop SYSRET_TO_64 1514479Sbinkertn@umich.edu{ 1524479Sbinkertn@umich.edu # All 1s. 1536498Snate@binkert.org limm t1, "(uint64_t)(-1)", dataSize=8 1546498Snate@binkert.org 1556498Snate@binkert.org rdval t3, star 1566498Snate@binkert.org srli t3, t3, 48, dataSize=8 1574479Sbinkertn@umich.edu ori t3, t3, 3, dataSize=1 1584479Sbinkertn@umich.edu 1594479Sbinkertn@umich.edu # Set rflags to r11 with RF and VM cleared. 1604479Sbinkertn@umich.edu limm t4, "~(RFBit | VMBit)", dataSize=8 161 and t4, t4, r11, dataSize=8 162 wrflags t4, t0 163 164 # Set up CS. 165 addi t4, t3, 16, dataSize=8 166 wrsel cs, t4 167 wrbase cs, t0, dataSize=8 168 wrlimit cs, t1, dataSize=4 169 # Not writable, read/execute-able, not expandDown, 170 # dpl=3, defaultSize=0, long mode 171 limm t4, ((3 << 0) | (0 << 2) | (0 << 3) | \ 172 (1 << 4) | (0 << 5) | (1 << 6) | \ 173 (1 << 7) | (10 << 8) | (0 << 12) | \ 174 (1 << 13) | (0 << 14) | (1 << 15)), dataSize=8 175 wrattr cs, t4 176 177 # Only the selector is changed for SS. 178 addi t4, t3, 8, dataSize=8 179 wrsel ss, t4 180 181 # Set the RIP back. 182 wrip rcx, t0, dataSize=8 183}; 184 185def macroop SYSRET_TO_COMPAT 186{ 187 # All 1s. 188 limm t1, "(uint64_t)(-1)", dataSize=8 189 190 rdval t3, star 191 srli t3, t3, 48, dataSize=8 192 ori t3, t3, 3, dataSize=1 193 194 # Set rflags to r11 with RF and VM cleared. 195 limm t4, "~(RFBit | VMBit)", dataSize=8 196 and t4, t4, r11, dataSize=8 197 wrflags t4, t0 198 199 # Set up CS. 200 wrsel cs, t3 201 wrbase cs, t0, dataSize=8 202 wrlimit cs, t1, dataSize=4 203 # Not writable, read/execute-able, not expandDown, 204 # dpl=3, defaultSize=1, not long mode 205 limm t4, ((3 << 0) | (0 << 2) | (0 << 3) | \ 206 (1 << 4) | (0 << 5) | (1 << 6) | \ 207 (1 << 7) | (10 << 8) | (0 << 12) | \ 208 (1 << 13) | (0 << 14) | (1 << 15)), dataSize=8 209 wrattr cs, t4 210 211 # Only the selector is changed for SS. 212 addi t4, t3, 8, dataSize=8 213 wrsel ss, t4 214 215 # Set the RIP back. 216 wrip rcx, t0, dataSize=8 217}; 218 219def macroop SYSRET_NON_64 220{ 221 panic "The sysret instruction isn't implemented in legacy mode." 222}; 223''' 224#let {{ 225# class SYSENTER(Inst): 226# "GenFault ${new UnimpInstFault}" 227# class SYSEXIT(Inst): 228# "GenFault ${new UnimpInstFault}" 229#}}; 230