stack_operations.py (5081:2ccce8600a9d) stack_operations.py (5119:a4469f2919f3)
1# Copyright (c) 2007 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use of this software in source and binary forms,
5# with or without modification, are permitted provided that the
6# following conditions are met:
7#
8# The software must be used only for Non-Commercial Use which means any
9# use which is NOT directed to receiving any direct monetary
10# compensation for, or commercial advantage from such use. Illustrative
11# examples of non-commercial use are academic research, personal study,
12# teaching, education and corporate research & development.
13# Illustrative examples of commercial use are distributing products for
14# commercial advantage and providing services using the software for
15# commercial advantage.
16#
17# If you wish to use this software or functionality therein that may be
18# covered by patents for commercial use, please contact:
19# Director of Intellectual Property Licensing
20# Office of Strategy and Technology
21# Hewlett-Packard Company
22# 1501 Page Mill Road
23# Palo Alto, California 94304
24#
25# Redistributions of source code must retain the above copyright notice,
26# this list of conditions and the following disclaimer. Redistributions
27# in binary form must reproduce the above copyright notice, this list of
28# conditions and the following disclaimer in the documentation and/or
29# other materials provided with the distribution. Neither the name of
30# the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
31# contributors may be used to endorse or promote products derived from
32# this software without specific prior written permission. No right of
33# sublicense is granted herewith. Derivatives of the software and
34# output created using the software may be prepared, but only for
35# Non-Commercial Uses. Derivatives of the software may be shared with
36# others provided: (i) the others agree to abide by the list of
37# conditions herein which includes the Non-Commercial Use restrictions;
38# and (ii) such Derivatives of the software include the above copyright
39# notice to acknowledge the contribution from this software where
40# applicable, this list of conditions and the disclaimer below.
41#
42# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53#
54# Authors: Gabe Black
55
56microcode = '''
57def macroop POP_R {
58 # Make the default data size of pops 64 bits in 64 bit mode
59 .adjust_env oszIn64Override
60
61 ld reg, ss, [1, t0, rsp]
62 addi rsp, rsp, dsz
63};
64
65def macroop POP_M {
66 # Make the default data size of pops 64 bits in 64 bit mode
67 .adjust_env oszIn64Override
68
69 ld t1, ss, [1, t0, rsp]
1# Copyright (c) 2007 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use of this software in source and binary forms,
5# with or without modification, are permitted provided that the
6# following conditions are met:
7#
8# The software must be used only for Non-Commercial Use which means any
9# use which is NOT directed to receiving any direct monetary
10# compensation for, or commercial advantage from such use. Illustrative
11# examples of non-commercial use are academic research, personal study,
12# teaching, education and corporate research & development.
13# Illustrative examples of commercial use are distributing products for
14# commercial advantage and providing services using the software for
15# commercial advantage.
16#
17# If you wish to use this software or functionality therein that may be
18# covered by patents for commercial use, please contact:
19# Director of Intellectual Property Licensing
20# Office of Strategy and Technology
21# Hewlett-Packard Company
22# 1501 Page Mill Road
23# Palo Alto, California 94304
24#
25# Redistributions of source code must retain the above copyright notice,
26# this list of conditions and the following disclaimer. Redistributions
27# in binary form must reproduce the above copyright notice, this list of
28# conditions and the following disclaimer in the documentation and/or
29# other materials provided with the distribution. Neither the name of
30# the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
31# contributors may be used to endorse or promote products derived from
32# this software without specific prior written permission. No right of
33# sublicense is granted herewith. Derivatives of the software and
34# output created using the software may be prepared, but only for
35# Non-Commercial Uses. Derivatives of the software may be shared with
36# others provided: (i) the others agree to abide by the list of
37# conditions herein which includes the Non-Commercial Use restrictions;
38# and (ii) such Derivatives of the software include the above copyright
39# notice to acknowledge the contribution from this software where
40# applicable, this list of conditions and the disclaimer below.
41#
42# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53#
54# Authors: Gabe Black
55
56microcode = '''
57def macroop POP_R {
58 # Make the default data size of pops 64 bits in 64 bit mode
59 .adjust_env oszIn64Override
60
61 ld reg, ss, [1, t0, rsp]
62 addi rsp, rsp, dsz
63};
64
65def macroop POP_M {
66 # Make the default data size of pops 64 bits in 64 bit mode
67 .adjust_env oszIn64Override
68
69 ld t1, ss, [1, t0, rsp]
70 # Check stack address
70 addi rsp, rsp, dsz
71 st t1, seg, sib, disp
72};
73
74def macroop POP_P {
75 # Make the default data size of pops 64 bits in 64 bit mode
76 .adjust_env oszIn64Override
77
78 rdip t7
79 ld t1, ss, [1, t0, rsp]
71 addi rsp, rsp, dsz
72 st t1, seg, sib, disp
73};
74
75def macroop POP_P {
76 # Make the default data size of pops 64 bits in 64 bit mode
77 .adjust_env oszIn64Override
78
79 rdip t7
80 ld t1, ss, [1, t0, rsp]
81 # Check stack address
80 addi rsp, rsp, dsz
81 st t1, seg, riprel, disp
82};
83
84def macroop PUSH_R {
85 # Make the default data size of pops 64 bits in 64 bit mode
86 .adjust_env oszIn64Override
87
88 # This needs to work slightly differently from the other versions of push
89 # because the -original- version of the stack pointer is what gets pushed
90 st reg, ss, [1, t0, rsp], "-env.dataSize"
91 subi rsp, rsp, dsz
92};
93
94def macroop PUSH_I {
95 # Make the default data size of pops 64 bits in 64 bit mode
96 .adjust_env oszIn64Override
97
98 limm t1, imm
82 addi rsp, rsp, dsz
83 st t1, seg, riprel, disp
84};
85
86def macroop PUSH_R {
87 # Make the default data size of pops 64 bits in 64 bit mode
88 .adjust_env oszIn64Override
89
90 # This needs to work slightly differently from the other versions of push
91 # because the -original- version of the stack pointer is what gets pushed
92 st reg, ss, [1, t0, rsp], "-env.dataSize"
93 subi rsp, rsp, dsz
94};
95
96def macroop PUSH_I {
97 # Make the default data size of pops 64 bits in 64 bit mode
98 .adjust_env oszIn64Override
99
100 limm t1, imm
101 st t1, ss, [1, t0, rsp], "-env.dataSize"
99 subi rsp, rsp, dsz
102 subi rsp, rsp, dsz
100 st t1, ss, [1, t0, rsp]
101};
102
103def macroop PUSH_M {
104 # Make the default data size of pops 64 bits in 64 bit mode
105 .adjust_env oszIn64Override
106
107 ld t1, seg, sib, disp
103};
104
105def macroop PUSH_M {
106 # Make the default data size of pops 64 bits in 64 bit mode
107 .adjust_env oszIn64Override
108
109 ld t1, seg, sib, disp
110 st t1, ss, [1, t0, rsp], "-env.dataSize"
108 subi rsp, rsp, dsz
111 subi rsp, rsp, dsz
109 st t1, ss, [1, t0, rsp]
110};
111
112def macroop PUSH_P {
113 # Make the default data size of pops 64 bits in 64 bit mode
114 .adjust_env oszIn64Override
115
116 rdip t7
117 ld t1, seg, riprel, disp
112};
113
114def macroop PUSH_P {
115 # Make the default data size of pops 64 bits in 64 bit mode
116 .adjust_env oszIn64Override
117
118 rdip t7
119 ld t1, seg, riprel, disp
120 # Check stack address
118 subi rsp, rsp, dsz
119 st t1, ss, [1, t0, rsp]
120};
121
122def macroop PUSHA {
121 subi rsp, rsp, dsz
122 st t1, ss, [1, t0, rsp]
123};
124
125def macroop PUSHA {
126 # Check all the stack addresses.
123 st rax, ss, [1, t0, rsp], "-0 * env.dataSize"
124 st rcx, ss, [1, t0, rsp], "-1 * env.dataSize"
125 st rdx, ss, [1, t0, rsp], "-2 * env.dataSize"
126 st rbx, ss, [1, t0, rsp], "-3 * env.dataSize"
127 st rsp, ss, [1, t0, rsp], "-4 * env.dataSize"
128 st rbp, ss, [1, t0, rsp], "-5 * env.dataSize"
129 st rsi, ss, [1, t0, rsp], "-6 * env.dataSize"
130 st rdi, ss, [1, t0, rsp], "-7 * env.dataSize"
131 subi rsp, rsp, "8 * env.dataSize"
132};
133
134def macroop POPA {
127 st rax, ss, [1, t0, rsp], "-0 * env.dataSize"
128 st rcx, ss, [1, t0, rsp], "-1 * env.dataSize"
129 st rdx, ss, [1, t0, rsp], "-2 * env.dataSize"
130 st rbx, ss, [1, t0, rsp], "-3 * env.dataSize"
131 st rsp, ss, [1, t0, rsp], "-4 * env.dataSize"
132 st rbp, ss, [1, t0, rsp], "-5 * env.dataSize"
133 st rsi, ss, [1, t0, rsp], "-6 * env.dataSize"
134 st rdi, ss, [1, t0, rsp], "-7 * env.dataSize"
135 subi rsp, rsp, "8 * env.dataSize"
136};
137
138def macroop POPA {
139 # Check all the stack addresses.
135 ld rdi, ss, [1, t0, rsp], "0 * env.dataSize"
136 ld rsi, ss, [1, t0, rsp], "1 * env.dataSize"
137 ld rbp, ss, [1, t0, rsp], "2 * env.dataSize"
138 ld rbx, ss, [1, t0, rsp], "4 * env.dataSize"
139 ld rdx, ss, [1, t0, rsp], "5 * env.dataSize"
140 ld rcx, ss, [1, t0, rsp], "6 * env.dataSize"
141 ld rax, ss, [1, t0, rsp], "7 * env.dataSize"
142 addi rsp, rsp, "8 * env.dataSize"
143};
144
145def macroop LEAVE {
146 # Make the default data size of pops 64 bits in 64 bit mode
147 .adjust_env oszIn64Override
148
140 ld rdi, ss, [1, t0, rsp], "0 * env.dataSize"
141 ld rsi, ss, [1, t0, rsp], "1 * env.dataSize"
142 ld rbp, ss, [1, t0, rsp], "2 * env.dataSize"
143 ld rbx, ss, [1, t0, rsp], "4 * env.dataSize"
144 ld rdx, ss, [1, t0, rsp], "5 * env.dataSize"
145 ld rcx, ss, [1, t0, rsp], "6 * env.dataSize"
146 ld rax, ss, [1, t0, rsp], "7 * env.dataSize"
147 addi rsp, rsp, "8 * env.dataSize"
148};
149
150def macroop LEAVE {
151 # Make the default data size of pops 64 bits in 64 bit mode
152 .adjust_env oszIn64Override
153
149 mov rsp, rsp, rbp
150 ld rbp, ss, [1, t0, rsp]
154 mov t1, t1, rbp
155 ld rbp, ss, [1, t0, t1]
156 mov rsp, rsp, t1
151 addi rsp, rsp, dsz
152};
153'''
154#let {{
155# class ENTER(Inst):
156# "GenFault ${new UnimpInstFault}"
157#}};
157 addi rsp, rsp, dsz
158};
159'''
160#let {{
161# class ENTER(Inst):
162# "GenFault ${new UnimpInstFault}"
163#}};