diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-10-18 01:42:51 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-10-18 01:44:52 -0700 |
commit | f44c49c776b2199dd83b0de4e203a26bafa9c7ba (patch) | |
tree | 1339971877f5f67ae96516be06e6f4c8244de801 | |
parent | 9e45873ff4a5af5fc2bb2fcab90accef171900f1 (diff) | |
download | mu-f44c49c776b2199dd83b0de4e203a26bafa9c7ba.tar.gz |
4080
subx: correct 'push' register. It gets its operand right from the opcode, not a new modrm byte. Have I misinterpreted any other instructions in this manner (`+rd` in the Intel manual)?
-rw-r--r-- | html/subx/011direct_addressing.cc.html | 32 | ||||
-rw-r--r-- | subx/011direct_addressing.cc | 14 |
2 files changed, 29 insertions, 17 deletions
diff --git a/html/subx/011direct_addressing.cc.html b/html/subx/011direct_addressing.cc.html index dba0b3cf..a08f0e3f 100644 --- a/html/subx/011direct_addressing.cc.html +++ b/html/subx/011direct_addressing.cc.html @@ -286,25 +286,31 @@ if ('onhashchange' in window) { <span id="L221" class="LineNr">221 </span><span class="Special">% Reg[ESP].u = 0x64;</span> <span id="L222" class="LineNr">222 </span><span class="Special">% Reg[EBX].i = 10;</span> <span id="L223" class="LineNr">223 </span><span class="Comment"># op ModRM SIB displacement immediate</span> -<span id="L224" class="LineNr">224 </span> <span class="Constant">50</span> <span class="PreProc">0</span><span class="Constant">3</span> <span class="Comment"># push EBX (reg 3) to stack</span> +<span id="L224" class="LineNr">224 </span> <span class="Constant">53</span> <span class="Comment"># push EBX (reg 3) to stack</span> <span id="L225" class="LineNr">225 </span><span class="traceContains">+run: push <a href='010core.cc.html#L17'>reg</a> 3</span> <span id="L226" class="LineNr">226 </span><span class="traceContains">+run: pushing value 0x0000000a</span> <span id="L227" class="LineNr">227 </span><span class="traceContains">+run: <a href='010core.cc.html#L11'>ESP</a> is now 0x00000060</span> <span id="L228" class="LineNr">228 </span><span class="traceContains">+run: <a href='003trace.cc.html#L74'>contents</a> at <a href='010core.cc.html#L11'>ESP</a>: 0x0000000a</span> <span id="L229" class="LineNr">229 </span> <span id="L230" class="LineNr">230 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> -<span id="L231" class="LineNr">231 </span><span class="Normal">case</span> <span class="Constant">0x50</span>: <span class="Delimiter">{</span> -<span id="L232" class="LineNr">232 </span> <span class="Normal">uint8_t</span> modrm = <a href='010core.cc.html#L214'>next</a><span class="Delimiter">();</span> -<span id="L233" class="LineNr">233 </span> <span class="Normal">uint8_t</span> <a href='010core.cc.html#L17'>reg</a> = modrm & <span class="Constant">0x7</span><span class="Delimiter">;</span> -<span id="L234" class="LineNr">234 </span> <a href='003trace.cc.html#L160'>trace</a><span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"push <a href='010core.cc.html#L17'>reg</a> "</span> << <a href='010core.cc.html#L232'>NUM</a><span class="Delimiter">(</span><a href='010core.cc.html#L17'>reg</a><span class="Delimiter">)</span> << <a href='003trace.cc.html#L184'>end</a><span class="Delimiter">();</span> -<span id="L235" class="LineNr">235 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> val = Reg[reg]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> -<span id="L236" class="LineNr">236 </span> <a href='003trace.cc.html#L160'>trace</a><span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"pushing value 0x"</span> << <a href='010core.cc.html#L230'>HEXWORD</a> << val << <a href='003trace.cc.html#L184'>end</a><span class="Delimiter">();</span> -<span id="L237" class="LineNr">237 </span> Reg[ESP]<span class="Delimiter">.</span>u -= <span class="Constant">4</span><span class="Delimiter">;</span> -<span id="L238" class="LineNr">238 </span> *<span class="Normal">reinterpret_cast</span><<span class="Normal">uint32_t</span>*><span class="Delimiter">(</span>&Mem<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">))</span> = val<span class="Delimiter">;</span> -<span id="L239" class="LineNr">239 </span> <a href='003trace.cc.html#L160'>trace</a><span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ESP is now 0x"</span> << <a href='010core.cc.html#L230'>HEXWORD</a> << Reg[ESP]<span class="Delimiter">.</span>u << <a href='003trace.cc.html#L184'>end</a><span class="Delimiter">();</span> -<span id="L240" class="LineNr">240 </span> <a href='003trace.cc.html#L160'>trace</a><span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"contents at <a href='010core.cc.html#L11'>ESP</a>: 0x"</span> << <a href='010core.cc.html#L230'>HEXWORD</a> << *<span class="Normal">reinterpret_cast</span><<span class="Normal">uint32_t</span>*><span class="Delimiter">(</span>&Mem<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">))</span> << <a href='003trace.cc.html#L184'>end</a><span class="Delimiter">();</span> -<span id="L241" class="LineNr">241 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L242" class="LineNr">242 </span><span class="Delimiter">}</span> +<span id="L231" class="LineNr">231 </span><span class="Normal">case</span> <span class="Constant">0x50</span>: +<span id="L232" class="LineNr">232 </span><span class="Normal">case</span> <span class="Constant">0x51</span>: +<span id="L233" class="LineNr">233 </span><span class="Normal">case</span> <span class="Constant">0x52</span>: +<span id="L234" class="LineNr">234 </span><span class="Normal">case</span> <span class="Constant">0x53</span>: +<span id="L235" class="LineNr">235 </span><span class="Normal">case</span> <span class="Constant">0x54</span>: +<span id="L236" class="LineNr">236 </span><span class="Normal">case</span> <span class="Constant">0x55</span>: +<span id="L237" class="LineNr">237 </span><span class="Normal">case</span> <span class="Constant">0x56</span>: +<span id="L238" class="LineNr">238 </span><span class="Normal">case</span> <span class="Constant">0x57</span>: <span class="Delimiter">{</span> +<span id="L239" class="LineNr">239 </span> <span class="Normal">uint8_t</span> <a href='010core.cc.html#L17'>reg</a> = op & <span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L240" class="LineNr">240 </span> <a href='003trace.cc.html#L160'>trace</a><span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"push <a href='010core.cc.html#L17'>reg</a> "</span> << <a href='010core.cc.html#L232'>NUM</a><span class="Delimiter">(</span><a href='010core.cc.html#L17'>reg</a><span class="Delimiter">)</span> << <a href='003trace.cc.html#L184'>end</a><span class="Delimiter">();</span> +<span id="L241" class="LineNr">241 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> val = Reg[reg]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L242" class="LineNr">242 </span> <a href='003trace.cc.html#L160'>trace</a><span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"pushing value 0x"</span> << <a href='010core.cc.html#L230'>HEXWORD</a> << val << <a href='003trace.cc.html#L184'>end</a><span class="Delimiter">();</span> +<span id="L243" class="LineNr">243 </span> Reg[ESP]<span class="Delimiter">.</span>u -= <span class="Constant">4</span><span class="Delimiter">;</span> +<span id="L244" class="LineNr">244 </span> *<span class="Normal">reinterpret_cast</span><<span class="Normal">uint32_t</span>*><span class="Delimiter">(</span>&Mem<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">))</span> = val<span class="Delimiter">;</span> +<span id="L245" class="LineNr">245 </span> <a href='003trace.cc.html#L160'>trace</a><span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ESP is now 0x"</span> << <a href='010core.cc.html#L230'>HEXWORD</a> << Reg[ESP]<span class="Delimiter">.</span>u << <a href='003trace.cc.html#L184'>end</a><span class="Delimiter">();</span> +<span id="L246" class="LineNr">246 </span> <a href='003trace.cc.html#L160'>trace</a><span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"contents at <a href='010core.cc.html#L11'>ESP</a>: 0x"</span> << <a href='010core.cc.html#L230'>HEXWORD</a> << *<span class="Normal">reinterpret_cast</span><<span class="Normal">uint32_t</span>*><span class="Delimiter">(</span>&Mem<span class="Delimiter">.</span>at<span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">))</span> << <a href='003trace.cc.html#L184'>end</a><span class="Delimiter">();</span> +<span id="L247" class="LineNr">247 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L248" class="LineNr">248 </span><span class="Delimiter">}</span> </pre> </body> </html> diff --git a/subx/011direct_addressing.cc b/subx/011direct_addressing.cc index 2defcfec..827ce41e 100644 --- a/subx/011direct_addressing.cc +++ b/subx/011direct_addressing.cc @@ -221,16 +221,22 @@ case 0x89: { // copy r32 to r/m32 % Reg[ESP].u = 0x64; % Reg[EBX].i = 10; # op ModRM SIB displacement immediate - 50 03 # push EBX (reg 3) to stack + 53 # push EBX (reg 3) to stack +run: push reg 3 +run: pushing value 0x0000000a +run: ESP is now 0x00000060 +run: contents at ESP: 0x0000000a :(before "End Single-Byte Opcodes") -case 0x50: { - uint8_t modrm = next(); - uint8_t reg = modrm & 0x7; +case 0x50: +case 0x51: +case 0x52: +case 0x53: +case 0x54: +case 0x55: +case 0x56: +case 0x57: { + uint8_t reg = op & 0x7; trace(2, "run") << "push reg " << NUM(reg) << end(); const int32_t val = Reg[reg].u; trace(2, "run") << "pushing value 0x" << HEXWORD << val << end(); |