jump.py revision 6060:3d524dc980a8
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 JMP_I
58{
59    # Make the default data size of jumps 64 bits in 64 bit mode
60    .adjust_env oszIn64Override
61
62    rdip t1
63    limm t2, imm
64    wrip t1, t2
65};
66
67def macroop JMP_R
68{
69    # Make the default data size of jumps 64 bits in 64 bit mode
70    .adjust_env oszIn64Override
71
72    wripi reg, 0
73};
74
75def macroop JMP_M
76{
77    # Make the default data size of jumps 64 bits in 64 bit mode
78    .adjust_env oszIn64Override
79
80    ld t1, seg, sib, disp
81    wripi t1, 0
82};
83
84def macroop JMP_P
85{
86    # Make the default data size of jumps 64 bits in 64 bit mode
87    .adjust_env oszIn64Override
88
89    rdip t7
90    ld t1, seg, riprel, disp
91    wripi t1, 0
92};
93
94def macroop JMP_FAR_M
95{
96    limm t1, 0, dataSize=8
97    limm t2, 0, dataSize=8
98    lea t1, seg, sib, disp, dataSize=asz
99    ld t2, seg, [1, t0, t1], dsz
100    ld t1, seg, [1, t0, t1]
101    br rom_label("jmpFarWork")
102};
103
104def macroop JMP_FAR_P
105{
106    limm t1, 0, dataSize=8
107    limm t2, 0, dataSize=8
108    rdip t7, dataSize=asz
109    lea t1, seg, riprel, disp, dataSize=asz
110    ld t2, seg, [1, t0, t1], dsz
111    ld t1, seg, [1, t0, t1]
112    br rom_label("jmpFarWork")
113};
114
115def macroop JMP_FAR_I
116{
117    # Put the whole far pointer into a register.
118    limm t2, imm, dataSize=8
119    # Figure out the width of the offset.
120    limm t3, dsz, dataSize=8
121    sll t3, t3, 3, dataSize=8
122    # Get the selector into t1.
123    sll t1, t2, t3, dataSize=8
124    mov t1, t0, t1, dataSize=2
125    # And get the offset into t2
126    mov t2, t0, t2
127    br rom_label("jmpFarWork")
128};
129
130def rom
131{
132    extern jmpFarWork:
133    # t1 has the offset and t2 has the new selector.
134    # This is intended to run in protected mode.
135    andi t0, t2, 0xFC, flags=(EZF,), dataSize=2
136    fault "new GeneralProtection(0)", flags=(CEZF,)
137    andi t3, t2, 0xF8, dataSize=8
138    andi t0, t2, 0x4, flags=(EZF,), dataSize=2
139    br rom_local_label("farJmpGlobalDescriptor"), flags=(CEZF,)
140    ld t4, tsl, [1, t0, t3], dataSize=8, addressSize=8, atCPL0=True
141    br rom_local_label("farJmpProcessDescriptor")
142farJmpGlobalDescriptor:
143    ld t4, tsg, [1, t0, t3], dataSize=8, addressSize=8, atCPL0=True
144farJmpProcessDescriptor:
145    rcri t0, t4, 13, flags=(ECF,), dataSize=2
146    br rom_local_label("farJmpSystemDescriptor"), flags=(nCECF,)
147    chks t2, t4, CSCheck, dataSize=8
148    wrdl cs, t4, t2
149    wrsel cs, t2
150    wrip t0, t1
151    eret
152
153farJmpSystemDescriptor:
154    panic "Far jumps to system descriptors aren't implemented"
155    eret
156};
157
158def macroop JMP_FAR_REAL_M
159{
160    lea t1, seg, sib, disp, dataSize=asz
161    ld t2, seg, [1, t0, t1], dsz
162    ld t1, seg, [1, t0, t1]
163    zexti t3, t1, 15, dataSize=8
164    slli t3, t3, 4, dataSize=8
165    wrsel cs, t1, dataSize=2
166    wrbase cs, t3
167    wrip t0, t2, dataSize=asz
168};
169
170def macroop JMP_FAR_REAL_P
171{
172    panic "Real mode far jump executed in 64 bit mode!"
173};
174
175def macroop JMP_FAR_REAL_I
176{
177    # Put the whole far pointer into a register.
178    limm t2, imm, dataSize=8
179    # Figure out the width of the offset.
180    limm t3, dsz, dataSize=8
181    sll t3, t3, 3, dataSize=8
182    # Get the selector into t1.
183    sll t1, t2, t3, dataSize=8
184    mov t1, t0, t1, dataSize=2
185    # And get the offset into t2
186    mov t2, t0, t2
187    slli t3, t3, 4, dataSize=8
188    wrsel cs, t1, dataSize=2
189    wrbase cs, t3
190    wrip t0, t2, dataSize=asz
191};
192'''
193