system_calls.py (5908:c24a1ffc4ad0) system_calls.py (6062:2116d308076f)
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

--- 43 unchanged lines hidden (view full) ---

52# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53#
54# Authors: Gabe Black
55
56microcode = '''
57def macroop SYSCALL_64
58{
59 # All 1s.
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

--- 43 unchanged lines hidden (view full) ---

52# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53#
54# Authors: Gabe Black
55
56microcode = '''
57def macroop SYSCALL_64
58{
59 # All 1s.
60 limm t1, "(uint64_t)(-1)"
60 limm t1, "(uint64_t)(-1)", dataSize=8
61
62 # Save the next RIP.
63 rdip rcx
64
65 # Stick rflags with RF masked into r11.
66 rflags t2
61
62 # Save the next RIP.
63 rdip rcx
64
65 # Stick rflags with RF masked into r11.
66 rflags t2
67 limm t3, "~RFBit"
67 limm t3, "~RFBit", dataSize=8
68 andi r11, t2, t3, dataSize=8
69
70 rdval t3, star
71 srli t3, t3, 32, dataSize=8
72 andi t3, t3, 0xFC, dataSize=1
73
74 # Set up CS.
75 wrsel cs, t3
76 wrbase cs, t0, dataSize=8
77 wrlimit cs, t1, dataSize=4
78 # Not writable, read/execute-able, not expandDown,
79 # dpl=0, defaultSize=0, long mode
80 limm t4, ((0 << 0) | (1 << 1) | (0 << 2) | \
68 andi r11, t2, t3, dataSize=8
69
70 rdval t3, star
71 srli t3, t3, 32, dataSize=8
72 andi t3, t3, 0xFC, dataSize=1
73
74 # Set up CS.
75 wrsel cs, t3
76 wrbase cs, t0, dataSize=8
77 wrlimit cs, t1, dataSize=4
78 # Not writable, read/execute-able, not expandDown,
79 # dpl=0, defaultSize=0, long mode
80 limm t4, ((0 << 0) | (1 << 1) | (0 << 2) | \
81 (0 << 3) | (0 << 5) | (1 << 6))
81 (0 << 3) | (0 << 5) | (1 << 6)), dataSize=8
82 wrattr cs, t4
83
84 # Set up SS.
85 addi t3, t3, 8
86 wrsel ss, t3
87 wrbase ss, t0, dataSize=8
88 wrlimit ss, t1, dataSize=4
89 # Writable, readable, not expandDown,
90 # dpl=0, defaultSize=0, not long mode
91 limm t4, ((1 << 0) | (1 << 1) | (0 << 2) | \
82 wrattr cs, t4
83
84 # Set up SS.
85 addi t3, t3, 8
86 wrsel ss, t3
87 wrbase ss, t0, dataSize=8
88 wrlimit ss, t1, dataSize=4
89 # Writable, readable, not expandDown,
90 # dpl=0, defaultSize=0, not long mode
91 limm t4, ((1 << 0) | (1 << 1) | (0 << 2) | \
92 (0 << 3) | (0 << 5) | (0 << 6))
92 (0 << 3) | (0 << 5) | (0 << 6)), dataSize=8
93 wrattr ss, t4
94
95 # Set the new rip.
96 rdval t7, lstar
97 wrip t0, t7
98
99 # Mask the flags against sf_mask and leave RF turned off.
100 rdval t3, sf_mask, dataSize=8
101 xor t3, t3, t1, dataSize=8
102 and t3, t3, r11, dataSize=8
103 wrflags t3, t0
104};
105
106def macroop SYSCALL_COMPAT
107{
108 # All 1s.
93 wrattr ss, t4
94
95 # Set the new rip.
96 rdval t7, lstar
97 wrip t0, t7
98
99 # Mask the flags against sf_mask and leave RF turned off.
100 rdval t3, sf_mask, dataSize=8
101 xor t3, t3, t1, dataSize=8
102 and t3, t3, r11, dataSize=8
103 wrflags t3, t0
104};
105
106def macroop SYSCALL_COMPAT
107{
108 # All 1s.
109 limm t1, "(uint64_t)(-1)"
109 limm t1, "(uint64_t)(-1)", dataSize=8
110
111 # Save the next RIP.
112 rdip rcx
113
114 # Stick rflags with RF masked into r11.
115 rflags t2
110
111 # Save the next RIP.
112 rdip rcx
113
114 # Stick rflags with RF masked into r11.
115 rflags t2
116 limm t3, "~RFBit"
116 limm t3, "~RFBit", dataSize=8
117 andi r11, t2, t3, dataSize=8
118
119 rdval t3, star
120 srli t3, t3, 32, dataSize=8
121 andi t3, t3, 0xFC, dataSize=1
122
123 # Set up CS.
124 wrsel cs, t3
125 wrbase cs, t0, dataSize=8
126 wrlimit cs, t1, dataSize=4
127 # Not writable, read/execute-able, not expandDown,
128 # dpl=0, defaultSize=0, long mode
129 limm t4, ((0 << 0) | (1 << 1) | (0 << 2) | \
117 andi r11, t2, t3, dataSize=8
118
119 rdval t3, star
120 srli t3, t3, 32, dataSize=8
121 andi t3, t3, 0xFC, dataSize=1
122
123 # Set up CS.
124 wrsel cs, t3
125 wrbase cs, t0, dataSize=8
126 wrlimit cs, t1, dataSize=4
127 # Not writable, read/execute-able, not expandDown,
128 # dpl=0, defaultSize=0, long mode
129 limm t4, ((0 << 0) | (1 << 1) | (0 << 2) | \
130 (0 << 3) | (0 << 5) | (1 << 6))
130 (0 << 3) | (0 << 5) | (1 << 6)), dataSize=8
131 wrattr cs, t4
132
133 # Set up SS.
134 addi t3, t3, 8
135 wrsel ss, t3
136 wrbase ss, t0, dataSize=8
137 wrlimit ss, t1, dataSize=4
138 # Writable, readable, not expandDown,
139 # dpl=0, defaultSize=0, not long mode
140 limm t4, ((1 << 0) | (1 << 1) | (0 << 2) | \
131 wrattr cs, t4
132
133 # Set up SS.
134 addi t3, t3, 8
135 wrsel ss, t3
136 wrbase ss, t0, dataSize=8
137 wrlimit ss, t1, dataSize=4
138 # Writable, readable, not expandDown,
139 # dpl=0, defaultSize=0, not long mode
140 limm t4, ((1 << 0) | (1 << 1) | (0 << 2) | \
141 (0 << 3) | (0 << 5) | (0 << 6))
141 (0 << 3) | (0 << 5) | (0 << 6)), dataSize=8
142 wrattr ss, t4
143
144 # Set the new rip.
145 rdval t7, cstar
146 wrip t0, t7
147
148 # Mask the flags against sf_mask and leave RF turned off.
149 rdval t3, sf_mask, dataSize=8

--- 5 unchanged lines hidden (view full) ---

155def macroop SYSCALL_LEGACY
156{
157 panic "The syscall instruction isn't implemented in legacy mode."
158};
159
160def macroop SYSRET_TO_64
161{
162 # All 1s.
142 wrattr ss, t4
143
144 # Set the new rip.
145 rdval t7, cstar
146 wrip t0, t7
147
148 # Mask the flags against sf_mask and leave RF turned off.
149 rdval t3, sf_mask, dataSize=8

--- 5 unchanged lines hidden (view full) ---

155def macroop SYSCALL_LEGACY
156{
157 panic "The syscall instruction isn't implemented in legacy mode."
158};
159
160def macroop SYSRET_TO_64
161{
162 # All 1s.
163 limm t1, "(uint64_t)(-1)"
163 limm t1, "(uint64_t)(-1)", dataSize=8
164
165 rdval t3, star
166 srli t3, t3, 48, dataSize=8
167 ori t3, t3, 3, dataSize=1
168
169 # Set rflags to r11 with RF and VM cleared.
164
165 rdval t3, star
166 srli t3, t3, 48, dataSize=8
167 ori t3, t3, 3, dataSize=1
168
169 # Set rflags to r11 with RF and VM cleared.
170 limm t4, "~(RFBit | VMBit)"
170 limm t4, "~(RFBit | VMBit)", dataSize=8
171 and t4, t4, r11, dataSize=8
172 wrflags t4, t0
173
174 # Set up CS.
175 addi t4, t3, 16, dataSize=8
176 wrsel cs, t4
177 wrbase cs, t0, dataSize=8
178 wrlimit cs, t1, dataSize=4
179 # Not writable, read/execute-able, not expandDown,
180 # dpl=3, defaultSize=0, long mode
181 limm t4, ((0 << 0) | (1 << 1) | (0 << 2) | \
171 and t4, t4, r11, dataSize=8
172 wrflags t4, t0
173
174 # Set up CS.
175 addi t4, t3, 16, dataSize=8
176 wrsel cs, t4
177 wrbase cs, t0, dataSize=8
178 wrlimit cs, t1, dataSize=4
179 # Not writable, read/execute-able, not expandDown,
180 # dpl=3, defaultSize=0, long mode
181 limm t4, ((0 << 0) | (1 << 1) | (0 << 2) | \
182 (3 << 3) | (0 << 5) | (1 << 6))
182 (3 << 3) | (0 << 5) | (1 << 6)), dataSize=8
183 wrattr cs, t4
184
185 # Only the selector is changed for SS.
186 addi t4, t3, 8, dataSize=8
187 wrsel ss, t4
188
189 # Set the RIP back.
190 wrip rcx, t0, dataSize=8
191};
192
193def macroop SYSRET_TO_COMPAT
194{
195 # All 1s.
183 wrattr cs, t4
184
185 # Only the selector is changed for SS.
186 addi t4, t3, 8, dataSize=8
187 wrsel ss, t4
188
189 # Set the RIP back.
190 wrip rcx, t0, dataSize=8
191};
192
193def macroop SYSRET_TO_COMPAT
194{
195 # All 1s.
196 limm t1, "(uint64_t)(-1)"
196 limm t1, "(uint64_t)(-1)", dataSize=8
197
198 rdval t3, star
199 srli t3, t3, 48, dataSize=8
200 ori t3, t3, 3, dataSize=1
201
202 # Set rflags to r11 with RF and VM cleared.
197
198 rdval t3, star
199 srli t3, t3, 48, dataSize=8
200 ori t3, t3, 3, dataSize=1
201
202 # Set rflags to r11 with RF and VM cleared.
203 limm t4, "~(RFBit | VMBit)"
203 limm t4, "~(RFBit | VMBit)", dataSize=8
204 and t4, t4, r11, dataSize=8
205 wrflags t4, t0
206
207 # Set up CS.
208 wrsel cs, t3
209 wrbase cs, t0, dataSize=8
210 wrlimit cs, t1, dataSize=4
211 # Not writable, read/execute-able, not expandDown,
212 # dpl=3, defaultSize=1, not long mode
213 limm t4, ((0 << 0) | (1 << 1) | (0 << 2) | \
204 and t4, t4, r11, dataSize=8
205 wrflags t4, t0
206
207 # Set up CS.
208 wrsel cs, t3
209 wrbase cs, t0, dataSize=8
210 wrlimit cs, t1, dataSize=4
211 # Not writable, read/execute-able, not expandDown,
212 # dpl=3, defaultSize=1, not long mode
213 limm t4, ((0 << 0) | (1 << 1) | (0 << 2) | \
214 (3 << 3) | (1 << 5) | (0 << 6))
214 (3 << 3) | (1 << 5) | (0 << 6)), dataSize=8
215 wrattr cs, t4
216
217 # Only the selector is changed for SS.
218 addi t4, t3, 8, dataSize=8
219 wrsel ss, t4
220
221 # Set the RIP back.
222 wrip rcx, t0, dataSize=8

--- 13 unchanged lines hidden ---
215 wrattr cs, t4
216
217 # Only the selector is changed for SS.
218 addi t4, t3, 8, dataSize=8
219 wrsel ss, t4
220
221 # Set the RIP back.
222 wrip rcx, t0, dataSize=8

--- 13 unchanged lines hidden ---