jump.py (10474:799c8ee4ecba) jump.py (10543:8fb2884b0a75)
1# Copyright (c) 2007 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license
9# terms below provided that you ensure that this notice is replicated
10# unmodified and in its entirety in all distributions of the software,
11# modified or unmodified, in source code or in binary form.
12#
13# Redistribution and use in source and binary forms, with or without
14# modification, are permitted provided that the following conditions are
15# met: redistributions of source code must retain the above copyright
16# notice, this list of conditions and the following disclaimer;
17# redistributions in binary form must reproduce the above copyright
18# notice, this list of conditions and the following disclaimer in the
19# documentation and/or other materials provided with the distribution;
20# neither the name of the copyright holders nor the names of its
21# contributors may be used to endorse or promote products derived from
22# this software without specific prior written permission.
23#
24# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35#
36# Authors: Gabe Black
37
38microcode = '''
39def macroop JMP_I
40{
41 # Make the default data size of jumps 64 bits in 64 bit mode
42 .adjust_env oszIn64Override
43
44 rdip t1
45 limm t2, imm
46 wrip t1, t2
47};
48
49def macroop JMP_R
50{
51 # Make the default data size of jumps 64 bits in 64 bit mode
52 .adjust_env oszIn64Override
53
54 wripi reg, 0
55};
56
57def macroop JMP_M
58{
59 # Make the default data size of jumps 64 bits in 64 bit mode
60 .adjust_env oszIn64Override
61
62 ld t1, seg, sib, disp
63 wripi t1, 0
64};
65
66def macroop JMP_P
67{
68 # Make the default data size of jumps 64 bits in 64 bit mode
69 .adjust_env oszIn64Override
70
71 rdip t7
72 ld t1, seg, riprel, disp
73 wripi t1, 0
74};
75
76def macroop JMP_FAR_M
77{
78 limm t1, 0, dataSize=8
79 limm t2, 0, dataSize=8
80 lea t1, seg, sib, disp, dataSize=asz
81 ld t2, seg, [1, t0, t1], dsz
82 ld t1, seg, [1, t0, t1]
83 br rom_label("jmpFarWork")
84};
85
86def macroop JMP_FAR_P
87{
88 limm t1, 0, dataSize=8
89 limm t2, 0, dataSize=8
90 rdip t7, dataSize=asz
91 lea t1, seg, riprel, disp, dataSize=asz
92 ld t2, seg, [1, t0, t1], dsz
93 ld t1, seg, [1, t0, t1]
94 br rom_label("jmpFarWork")
95};
96
97def macroop JMP_FAR_I
98{
99 # Put the whole far pointer into a register.
100 limm t2, imm, dataSize=8
101 # Figure out the width of the offset.
102 limm t3, dsz, dataSize=8
103 slli t3, t3, 3, dataSize=8
104 # Get the offset into t1.
105 mov t1, t0, t2
106 # Get the selector into t2.
107 srl t2, t2, t3, dataSize=8
108 mov t2, t0, t2, dataSize=2
109 br rom_label("jmpFarWork")
110};
111
112def rom
113{
114 extern jmpFarWork:
115 # t1 has the offset and t2 has the new selector.
116 # This is intended to run in protected mode.
117 andi t0, t2, 0xFC, flags=(EZF,), dataSize=2
118 fault "std::make_shared<GeneralProtection>(0)", flags=(CEZF,)
119 andi t3, t2, 0xF8, dataSize=8
120 andi t0, t2, 0x4, flags=(EZF,), dataSize=2
121 br rom_local_label("farJmpGlobalDescriptor"), flags=(CEZF,)
122 ld t4, tsl, [1, t0, t3], dataSize=8, addressSize=8, atCPL0=True
123 br rom_local_label("farJmpProcessDescriptor")
124farJmpGlobalDescriptor:
125 ld t4, tsg, [1, t0, t3], dataSize=8, addressSize=8, atCPL0=True
126farJmpProcessDescriptor:
127 rcri t0, t4, 13, flags=(ECF,), dataSize=2
128 br rom_local_label("farJmpSystemDescriptor"), flags=(nCECF,)
129 chks t2, t4, CSCheck, dataSize=8
130 wrdl cs, t4, t2
131 wrsel cs, t2
132 wrip t0, t1
133 eret
134
135farJmpSystemDescriptor:
136 panic "Far jumps to system descriptors aren't implemented"
137 eret
138};
139
140def macroop JMP_FAR_REAL_M
141{
142 lea t1, seg, sib, disp, dataSize=asz
143 ld t2, seg, [1, t0, t1], dsz
144 ld t1, seg, [1, t0, t1]
145 zexti t3, t1, 15, dataSize=8
146 slli t3, t3, 4, dataSize=8
147 wrsel cs, t1, dataSize=2
148 wrbase cs, t3
149 wrip t0, t2, dataSize=asz
150};
151
152def macroop JMP_FAR_REAL_P
153{
154 panic "Real mode far jump executed in 64 bit mode!"
155};
156
157def macroop JMP_FAR_REAL_I
158{
159 # Put the whole far pointer into a register.
160 limm t2, imm, dataSize=8
161 # Figure out the width of the offset.
162 limm t3, dsz, dataSize=8
163 slli t3, t3, 3, dataSize=8
164 # Get the selector into t1.
1# Copyright (c) 2007 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license
9# terms below provided that you ensure that this notice is replicated
10# unmodified and in its entirety in all distributions of the software,
11# modified or unmodified, in source code or in binary form.
12#
13# Redistribution and use in source and binary forms, with or without
14# modification, are permitted provided that the following conditions are
15# met: redistributions of source code must retain the above copyright
16# notice, this list of conditions and the following disclaimer;
17# redistributions in binary form must reproduce the above copyright
18# notice, this list of conditions and the following disclaimer in the
19# documentation and/or other materials provided with the distribution;
20# neither the name of the copyright holders nor the names of its
21# contributors may be used to endorse or promote products derived from
22# this software without specific prior written permission.
23#
24# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35#
36# Authors: Gabe Black
37
38microcode = '''
39def macroop JMP_I
40{
41 # Make the default data size of jumps 64 bits in 64 bit mode
42 .adjust_env oszIn64Override
43
44 rdip t1
45 limm t2, imm
46 wrip t1, t2
47};
48
49def macroop JMP_R
50{
51 # Make the default data size of jumps 64 bits in 64 bit mode
52 .adjust_env oszIn64Override
53
54 wripi reg, 0
55};
56
57def macroop JMP_M
58{
59 # Make the default data size of jumps 64 bits in 64 bit mode
60 .adjust_env oszIn64Override
61
62 ld t1, seg, sib, disp
63 wripi t1, 0
64};
65
66def macroop JMP_P
67{
68 # Make the default data size of jumps 64 bits in 64 bit mode
69 .adjust_env oszIn64Override
70
71 rdip t7
72 ld t1, seg, riprel, disp
73 wripi t1, 0
74};
75
76def macroop JMP_FAR_M
77{
78 limm t1, 0, dataSize=8
79 limm t2, 0, dataSize=8
80 lea t1, seg, sib, disp, dataSize=asz
81 ld t2, seg, [1, t0, t1], dsz
82 ld t1, seg, [1, t0, t1]
83 br rom_label("jmpFarWork")
84};
85
86def macroop JMP_FAR_P
87{
88 limm t1, 0, dataSize=8
89 limm t2, 0, dataSize=8
90 rdip t7, dataSize=asz
91 lea t1, seg, riprel, disp, dataSize=asz
92 ld t2, seg, [1, t0, t1], dsz
93 ld t1, seg, [1, t0, t1]
94 br rom_label("jmpFarWork")
95};
96
97def macroop JMP_FAR_I
98{
99 # Put the whole far pointer into a register.
100 limm t2, imm, dataSize=8
101 # Figure out the width of the offset.
102 limm t3, dsz, dataSize=8
103 slli t3, t3, 3, dataSize=8
104 # Get the offset into t1.
105 mov t1, t0, t2
106 # Get the selector into t2.
107 srl t2, t2, t3, dataSize=8
108 mov t2, t0, t2, dataSize=2
109 br rom_label("jmpFarWork")
110};
111
112def rom
113{
114 extern jmpFarWork:
115 # t1 has the offset and t2 has the new selector.
116 # This is intended to run in protected mode.
117 andi t0, t2, 0xFC, flags=(EZF,), dataSize=2
118 fault "std::make_shared<GeneralProtection>(0)", flags=(CEZF,)
119 andi t3, t2, 0xF8, dataSize=8
120 andi t0, t2, 0x4, flags=(EZF,), dataSize=2
121 br rom_local_label("farJmpGlobalDescriptor"), flags=(CEZF,)
122 ld t4, tsl, [1, t0, t3], dataSize=8, addressSize=8, atCPL0=True
123 br rom_local_label("farJmpProcessDescriptor")
124farJmpGlobalDescriptor:
125 ld t4, tsg, [1, t0, t3], dataSize=8, addressSize=8, atCPL0=True
126farJmpProcessDescriptor:
127 rcri t0, t4, 13, flags=(ECF,), dataSize=2
128 br rom_local_label("farJmpSystemDescriptor"), flags=(nCECF,)
129 chks t2, t4, CSCheck, dataSize=8
130 wrdl cs, t4, t2
131 wrsel cs, t2
132 wrip t0, t1
133 eret
134
135farJmpSystemDescriptor:
136 panic "Far jumps to system descriptors aren't implemented"
137 eret
138};
139
140def macroop JMP_FAR_REAL_M
141{
142 lea t1, seg, sib, disp, dataSize=asz
143 ld t2, seg, [1, t0, t1], dsz
144 ld t1, seg, [1, t0, t1]
145 zexti t3, t1, 15, dataSize=8
146 slli t3, t3, 4, dataSize=8
147 wrsel cs, t1, dataSize=2
148 wrbase cs, t3
149 wrip t0, t2, dataSize=asz
150};
151
152def macroop JMP_FAR_REAL_P
153{
154 panic "Real mode far jump executed in 64 bit mode!"
155};
156
157def macroop JMP_FAR_REAL_I
158{
159 # Put the whole far pointer into a register.
160 limm t2, imm, dataSize=8
161 # Figure out the width of the offset.
162 limm t3, dsz, dataSize=8
163 slli t3, t3, 3, dataSize=8
164 # Get the selector into t1.
165 sll t1, t2, t3, dataSize=8
165 srl t1, t2, t3, dataSize=8
166 mov t1, t0, t1, dataSize=2
167 # And get the offset into t2
168 mov t2, t0, t2
166 mov t1, t0, t1, dataSize=2
167 # And get the offset into t2
168 mov t2, t0, t2
169 slli t3, t3, 4, dataSize=8
169 slli t3, t1, 4, dataSize=8
170 wrsel cs, t1, dataSize=2
171 wrbase cs, t3
172 wrip t0, t2, dataSize=asz
173};
174'''
170 wrsel cs, t1, dataSize=2
171 wrbase cs, t3
172 wrip t0, t2, dataSize=asz
173};
174'''