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