diff options
Diffstat (limited to 'html/linux/bootstrap')
30 files changed, 13032 insertions, 0 deletions
diff --git a/html/linux/bootstrap/000organization.cc.html b/html/linux/bootstrap/000organization.cc.html new file mode 100644 index 00000000..56125b37 --- /dev/null +++ b/html/linux/bootstrap/000organization.cc.html @@ -0,0 +1,227 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/000organization.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.PreProc { color: #c000c0; } +.LineNr { } +.Delimiter { color: #c000c0; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Comment { color: #005faf; } +.Constant { color: #008787; } +.cSpecial { color: #008000; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/000organization.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/000organization.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: You guessed right: the '000' prefix means you should start reading here.</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//:</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: This project is set up to load all files with a numeric prefix. Just</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: create a new file and start hacking.</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//:</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment">//: The first few files (00*) are independent of what this program does, an</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment">//: experimental skeleton that will hopefully make it both easier for others to</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment">//: understand and more malleable, easier to rewrite and remould into radically</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment">//: different shapes without breaking in subtle corner cases. The premise is</span> +<span id="L10" class="LineNr"> 10 </span><span class="Comment">//: that understandability and rewrite-friendliness are related in a virtuous</span> +<span id="L11" class="LineNr"> 11 </span><span class="Comment">//: cycle. Doing one well makes it easier to do the other.</span> +<span id="L12" class="LineNr"> 12 </span><span class="Comment">//:</span> +<span id="L13" class="LineNr"> 13 </span><span class="Comment">//: Lower down, this file contains a legal, bare-bones C++ program. It doesn't</span> +<span id="L14" class="LineNr"> 14 </span><span class="Comment">//: do anything yet; subsequent files will contain :(...) directives to insert</span> +<span id="L15" class="LineNr"> 15 </span><span class="Comment">//: lines into it. For example:</span> +<span id="L16" class="LineNr"> 16 </span><span class="Comment">//: :(after "more events")</span> +<span id="L17" class="LineNr"> 17 </span><span class="Comment">//: This directive means: insert the following lines after a line in the</span> +<span id="L18" class="LineNr"> 18 </span><span class="Comment">//: program containing the words "more events".</span> +<span id="L19" class="LineNr"> 19 </span><span class="Comment">//:</span> +<span id="L20" class="LineNr"> 20 </span><span class="Comment">//: A simple tool is included to 'tangle' all the files together in sequence</span> +<span id="L21" class="LineNr"> 21 </span><span class="Comment">//: according to their directives into a single source file containing all the</span> +<span id="L22" class="LineNr"> 22 </span><span class="Comment">//: code for the project, and then feed the source file to the compiler.</span> +<span id="L23" class="LineNr"> 23 </span><span class="Comment">//: (It'll drop these comments starting with a '//:' prefix that only make</span> +<span id="L24" class="LineNr"> 24 </span><span class="Comment">//: sense before tangling.)</span> +<span id="L25" class="LineNr"> 25 </span><span class="Comment">//:</span> +<span id="L26" class="LineNr"> 26 </span><span class="Comment">//: Directives free up the programmer to order code for others to read rather</span> +<span id="L27" class="LineNr"> 27 </span><span class="Comment">//: than as forced by the computer or compiler. Each individual feature can be</span> +<span id="L28" class="LineNr"> 28 </span><span class="Comment">//: organized in a self-contained 'layer' that adds code to many different data</span> +<span id="L29" class="LineNr"> 29 </span><span class="Comment">//: structures and functions all over the program. The right decomposition into</span> +<span id="L30" class="LineNr"> 30 </span><span class="Comment">//: layers will let each layer make sense in isolation.</span> +<span id="L31" class="LineNr"> 31 </span><span class="Comment">//:</span> +<span id="L32" class="LineNr"> 32 </span><span class="Comment">//: "If I look at any small part of it, I can see what is going on -- I don't</span> +<span id="L33" class="LineNr"> 33 </span><span class="Comment">//: need to refer to other parts to understand what something is doing.</span> +<span id="L34" class="LineNr"> 34 </span><span class="Comment">//:</span> +<span id="L35" class="LineNr"> 35 </span><span class="Comment">//: If I look at any large part in overview, I can see what is going on -- I</span> +<span id="L36" class="LineNr"> 36 </span><span class="Comment">//: don't need to know all the details to get it.</span> +<span id="L37" class="LineNr"> 37 </span><span class="Comment">//:</span> +<span id="L38" class="LineNr"> 38 </span><span class="Comment">//: Every level of detail is as locally coherent and as well thought-out as</span> +<span id="L39" class="LineNr"> 39 </span><span class="Comment">//: any other level."</span> +<span id="L40" class="LineNr"> 40 </span><span class="Comment">//:</span> +<span id="L41" class="LineNr"> 41 </span><span class="Comment">//: -- Richard Gabriel, "The Quality Without A Name"</span> +<span id="L42" class="LineNr"> 42 </span><span class="Comment">//: (<a href="http://dreamsongs.com/Files/PatternsOfSoftware.pdf">http://dreamsongs.com/Files/PatternsOfSoftware.pdf</a>, page 42)</span> +<span id="L43" class="LineNr"> 43 </span><span class="Comment">//:</span> +<span id="L44" class="LineNr"> 44 </span><span class="Comment">//: Directives are powerful; they permit inserting or modifying any point in</span> +<span id="L45" class="LineNr"> 45 </span><span class="Comment">//: the program. Using them tastefully requires mapping out specific lines as</span> +<span id="L46" class="LineNr"> 46 </span><span class="Comment">//: waypoints for future layers to hook into. Often such waypoints will be in</span> +<span id="L47" class="LineNr"> 47 </span><span class="Comment">//: comments, capitalized to hint that other layers rely on their presence.</span> +<span id="L48" class="LineNr"> 48 </span><span class="Comment">//:</span> +<span id="L49" class="LineNr"> 49 </span><span class="Comment">//: A single waypoint might have many different code fragments hooking into</span> +<span id="L50" class="LineNr"> 50 </span><span class="Comment">//: it from all over the codebase. Use 'before' directives to insert</span> +<span id="L51" class="LineNr"> 51 </span><span class="Comment">//: code at a location in order, top to bottom, and 'after' directives to</span> +<span id="L52" class="LineNr"> 52 </span><span class="Comment">//: insert code in reverse order. By convention waypoints intended for insertion</span> +<span id="L53" class="LineNr"> 53 </span><span class="Comment">//: before begin with 'End'. Notice below how the layers line up above the "End</span> +<span id="L54" class="LineNr"> 54 </span><span class="Comment">//: Foo" waypoint.</span> +<span id="L55" class="LineNr"> 55 </span><span class="Comment">//:</span> +<span id="L56" class="LineNr"> 56 </span><span class="Comment">//: File 001 File 002 File 003</span> +<span id="L57" class="LineNr"> 57 </span><span class="Comment">//: ============ =================== ===================</span> +<span id="L58" class="LineNr"> 58 </span><span class="Comment">//: // Foo</span> +<span id="L59" class="LineNr"> 59 </span><span class="Comment">//: ------------</span> +<span id="L60" class="LineNr"> 60 </span><span class="Comment">//: <---- :(before "End Foo")</span> +<span id="L61" class="LineNr"> 61 </span><span class="Comment">//: ....</span> +<span id="L62" class="LineNr"> 62 </span><span class="Comment">//: ...</span> +<span id="L63" class="LineNr"> 63 </span><span class="Comment">//: ------------</span> +<span id="L64" class="LineNr"> 64 </span><span class="Comment">//: <---------------------------- :(before "End Foo")</span> +<span id="L65" class="LineNr"> 65 </span><span class="Comment">//: ....</span> +<span id="L66" class="LineNr"> 66 </span><span class="Comment">//: ...</span> +<span id="L67" class="LineNr"> 67 </span><span class="Comment">//: // End Foo</span> +<span id="L68" class="LineNr"> 68 </span><span class="Comment">//: ============</span> +<span id="L69" class="LineNr"> 69 </span><span class="Comment">//:</span> +<span id="L70" class="LineNr"> 70 </span><span class="Comment">//: Here's part of a layer in color: <a href="http://i.imgur.com/0eONnyX.png">http://i.imgur.com/0eONnyX.png</a>. Directives</span> +<span id="L71" class="LineNr"> 71 </span><span class="Comment">//: are shaded dark.</span> +<span id="L72" class="LineNr"> 72 </span><span class="Comment">//:</span> +<span id="L73" class="LineNr"> 73 </span><span class="Comment">//: Layers do more than just shuffle code around. In a well-organized codebase</span> +<span id="L74" class="LineNr"> 74 </span><span class="Comment">//: it should be possible to stop loading after any file/layer, build and run</span> +<span id="L75" class="LineNr"> 75 </span><span class="Comment">//: the program, and pass all tests for loaded features. (Relevant is</span> +<span id="L76" class="LineNr"> 76 </span><span class="Comment">//: <a href="http://youtube.com/watch?v=c8N72t7aScY">http://youtube.com/watch?v=c8N72t7aScY</a>, a scene from "2001: A Space</span> +<span id="L77" class="LineNr"> 77 </span><span class="Comment">//: Odyssey".) Get into the habit of running the included script called</span> +<span id="L78" class="LineNr"> 78 </span><span class="Comment">//: 'test_layers' before you commit any changes.</span> +<span id="L79" class="LineNr"> 79 </span><span class="Comment">//:</span> +<span id="L80" class="LineNr"> 80 </span><span class="Comment">//: This 'subsetting guarantee' ensures that this directory contains a</span> +<span id="L81" class="LineNr"> 81 </span><span class="Comment">//: cleaned-up narrative of the evolution of this codebase. Organizing</span> +<span id="L82" class="LineNr"> 82 </span><span class="Comment">//: autobiographically allows newcomers to rapidly orient themselves, reading</span> +<span id="L83" class="LineNr"> 83 </span><span class="Comment">//: the first few files to understand a simple gestalt of a program's core</span> +<span id="L84" class="LineNr"> 84 </span><span class="Comment">//: purpose and features, and later gradually working their way through other</span> +<span id="L85" class="LineNr"> 85 </span><span class="Comment">//: features as the need arises.</span> +<span id="L86" class="LineNr"> 86 </span><span class="Comment">//:</span> +<span id="L87" class="LineNr"> 87 </span><span class="Comment">//: Programmers shouldn't need to understand everything about a program to</span> +<span id="L88" class="LineNr"> 88 </span><span class="Comment">//: hack on it. But they shouldn't be prevented from a thorough understanding</span> +<span id="L89" class="LineNr"> 89 </span><span class="Comment">//: of each aspect either. The goal of layers is to reward curiosity.</span> +<span id="L90" class="LineNr"> 90 </span><span class="Comment">//:</span> +<span id="L91" class="LineNr"> 91 </span><span class="Comment">//: More information: <a href="http://akkartik.name/post/wart-layers">http://akkartik.name/post/wart-layers</a></span> +<span id="L92" class="LineNr"> 92 </span> +<span id="L93" class="LineNr"> 93 </span><span class="Comment">// Includes</span> +<span id="L94" class="LineNr"> 94 </span><span class="Comment">// End Includes</span> +<span id="L95" class="LineNr"> 95 </span> +<span id="L96" class="LineNr"> 96 </span><span class="Comment">// Types</span> +<span id="L97" class="LineNr"> 97 </span><span class="Comment">// End Types</span> +<span id="L98" class="LineNr"> 98 </span> +<span id="L99" class="LineNr"> 99 </span><span class="Comment">// Function prototypes are auto-generated in the 'build' script; define your</span> +<span id="L100" class="LineNr">100 </span><span class="Comment">// functions in any order. Just be sure to declare each function header all on</span> +<span id="L101" class="LineNr">101 </span><span class="Comment">// one line, ending with the '{'. Our auto-generation scripts are too minimal</span> +<span id="L102" class="LineNr">102 </span><span class="Comment">// and simple-minded to handle anything else.</span> +<span id="L103" class="LineNr">103 </span><span class="PreProc">#include </span><span class="Constant">"function_list"</span> <span class="Comment">// by convention, files ending with '_list' are auto-generated</span> +<span id="L104" class="LineNr">104 </span> +<span id="L105" class="LineNr">105 </span><span class="Comment">// Globals</span> +<span id="L106" class="LineNr">106 </span><span class="Comment">//</span> +<span id="L107" class="LineNr">107 </span><span class="Comment">// All statements in this section should always define a single variable on a</span> +<span id="L108" class="LineNr">108 </span><span class="Comment">// single line. The 'build' script will simple-mindedly auto-generate extern</span> +<span id="L109" class="LineNr">109 </span><span class="Comment">// declarations for them. Remember to define (not just declare) constants with</span> +<span id="L110" class="LineNr">110 </span><span class="Comment">// extern linkage in this section, since C++ global constants have internal</span> +<span id="L111" class="LineNr">111 </span><span class="Comment">// linkage by default.</span> +<span id="L112" class="LineNr">112 </span><span class="Comment">//</span> +<span id="L113" class="LineNr">113 </span><span class="Comment">// End Globals</span> +<span id="L114" class="LineNr">114 </span> +<span id="L115" class="LineNr">115 </span><span class="Normal">int</span> <a href='000organization.cc.html#L115'>main</a><span class="Delimiter">(</span><span class="Normal">int</span> argc<span class="Delimiter">,</span> <span class="Normal">char</span>* argv[]<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L116" class="LineNr">116 </span> atexit<span class="Delimiter">(</span><a href='000organization.cc.html#L150'>reset</a><span class="Delimiter">);</span> +<span id="L117" class="LineNr">117 </span> <span class="Comment">// we require a 32-bit little-endian system</span> +<span id="L118" class="LineNr">118 </span> assert<span class="Delimiter">(</span><span class="Normal">sizeof</span><span class="Delimiter">(</span><span class="Normal">int</span><span class="Delimiter">)</span> == <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L119" class="LineNr">119 </span> assert<span class="Delimiter">(</span><span class="Normal">sizeof</span><span class="Delimiter">(</span><span class="Normal">float</span><span class="Delimiter">)</span> == <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L120" class="LineNr">120 </span> <a href='000organization.cc.html#L154'>assert_little_endian</a><span class="Delimiter">();</span> +<span id="L121" class="LineNr">121 </span> +<span id="L122" class="LineNr">122 </span> <span class="Comment">// End One-time Setup</span> +<span id="L123" class="LineNr">123 </span> +<span id="L124" class="LineNr">124 </span> <span class="Comment">// Commandline Parsing</span> +<span id="L125" class="LineNr">125 </span> <span class="Comment">// End Commandline Parsing</span> +<span id="L126" class="LineNr">126 </span> +<span id="L127" class="LineNr">127 </span> <span class="Comment">// End Main</span> +<span id="L128" class="LineNr">128 </span> +<span id="L129" class="LineNr">129 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L130" class="LineNr">130 </span><span class="Delimiter">}</span> +<span id="L131" class="LineNr">131 </span> +<span id="L132" class="LineNr">132 </span><span class="Comment">// Unit Tests</span> +<span id="L133" class="LineNr">133 </span><span class="Comment">// End Unit Tests</span> +<span id="L134" class="LineNr">134 </span> +<span id="L135" class="LineNr">135 </span><span class="Comment">//: our first directive; insert the following headers at the start of the program</span> +<span id="L136" class="LineNr">136 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L137" class="LineNr">137 </span><span class="PreProc">#include </span><span class="Constant"><assert.h></span> +<span id="L138" class="LineNr">138 </span><span class="PreProc">#include </span><span class="Constant"><stdlib.h></span> +<span id="L139" class="LineNr">139 </span> +<span id="L140" class="LineNr">140 </span><span class="Comment">//: Without directives or with the :(code) directive, lines get added at the</span> +<span id="L141" class="LineNr">141 </span><span class="Comment">//: end.</span> +<span id="L142" class="LineNr">142 </span><span class="Comment">//:</span> +<span id="L143" class="LineNr">143 </span><span class="Comment">//: Regardless of where functions are defined, we can call them anywhere we</span> +<span id="L144" class="LineNr">144 </span><span class="Comment">//: like as long as we format the function header in a specific way: put it</span> +<span id="L145" class="LineNr">145 </span><span class="Comment">//: all on a single line without indent, end the line with ') {' and no</span> +<span id="L146" class="LineNr">146 </span><span class="Comment">//: trailing whitespace. As long as functions uniformly start this way, our</span> +<span id="L147" class="LineNr">147 </span><span class="Comment">//: 'build' script contains a little command to automatically generate</span> +<span id="L148" class="LineNr">148 </span><span class="Comment">//: declarations for them.</span> +<span id="L149" class="LineNr">149 </span><span class="Delimiter">:(code)</span> +<span id="L150" class="LineNr">150 </span><span class="Normal">void</span> <a href='000organization.cc.html#L150'>reset</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L151" class="LineNr">151 </span> <span class="Comment">// End Reset</span> +<span id="L152" class="LineNr">152 </span><span class="Delimiter">}</span> +<span id="L153" class="LineNr">153 </span> +<span id="L154" class="LineNr">154 </span><span class="Normal">void</span> <a href='000organization.cc.html#L154'>assert_little_endian</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L155" class="LineNr">155 </span> <span class="Normal">const</span> <span class="Normal">int</span> x = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L156" class="LineNr">156 </span> <span class="Normal">const</span> <span class="Normal">char</span>* y = <span class="Normal">reinterpret_cast</span><<span class="Normal">const</span> <span class="Normal">char</span>*><span class="Delimiter">(</span>&x<span class="Delimiter">);</span> +<span id="L157" class="LineNr">157 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*y != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L158" class="LineNr">158 </span> cerr << <span class="Constant">"SubX requires a little-endian processor. Do you have Intel (or AMD or Atom) inside?</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L159" class="LineNr">159 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L160" class="LineNr">160 </span> <span class="Delimiter">}</span> +<span id="L161" class="LineNr">161 </span><span class="Delimiter">}</span> +<span id="L162" class="LineNr">162 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L163" class="LineNr">163 </span><span class="PreProc">#include</span><span class="Constant"><iostream></span> +<span id="L164" class="LineNr">164 </span><span class="Normal">using</span> std::cerr<span class="Delimiter">;</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/001help.cc.html b/html/linux/bootstrap/001help.cc.html new file mode 100644 index 00000000..ff76f367 --- /dev/null +++ b/html/linux/bootstrap/001help.cc.html @@ -0,0 +1,335 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/001help.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.CommentedCode { color: #8a8a8a; } +.Identifier { color: #af5f00; } +.PreProc { color: #c000c0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/001help.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/001help.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: Everything this project/binary supports.</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: This should give you a sense for what to look forward to in later layers.</span> +<span id="L3" class="LineNr"> 3 </span> +<span id="L4" class="LineNr"> 4 </span><span class="Delimiter">:(before "End Commandline Parsing")</span> +<span id="L5" class="LineNr"> 5 </span><span class="Normal">if</span> <span class="Delimiter">(</span>argc <= <span class="Constant">1</span> || <a href='001help.cc.html#L98'>is_equal</a><span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"--help"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L6" class="LineNr"> 6 </span> <span class="Comment">//: this is the functionality later layers will provide</span> +<span id="L7" class="LineNr"> 7 </span> <span class="Comment">// currently no automated tests for commandline arg parsing</span> +<span id="L8" class="LineNr"> 8 </span> cerr << get<span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"usage"</span><span class="Delimiter">);</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L10" class="LineNr"> 10 </span><span class="Delimiter">}</span> +<span id="L11" class="LineNr"> 11 </span> +<span id="L12" class="LineNr"> 12 </span><span class="Comment">//: Support for option parsing.</span> +<span id="L13" class="LineNr"> 13 </span><span class="Comment">//: Options always begin with '--' and are always the first arguments. An</span> +<span id="L14" class="LineNr"> 14 </span><span class="Comment">//: option will never follow a non-option.</span> +<span id="L15" class="LineNr"> 15 </span><span class="Normal">char</span>** <a href='001help.cc.html#L15'>arg</a> = &argv[<span class="Constant">1</span>]<span class="Delimiter">;</span> +<span id="L16" class="LineNr"> 16 </span><span class="Normal">while</span> <span class="Delimiter">(</span>argc > <span class="Constant">1</span> && <a href='001help.cc.html#L104'>starts_with</a><span class="Delimiter">(</span>*arg<span class="Delimiter">,</span> <span class="Constant">"--"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">)</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Delimiter">;</span> <span class="Comment">// no-op branch just so any further additions can consistently always start with 'else'</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Comment">// End Commandline Options(*arg)</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Normal">else</span> +<span id="L21" class="LineNr"> 21 </span> cerr << <span class="Constant">"skipping unknown option "</span> << *arg << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L22" class="LineNr"> 22 </span> --argc<span class="Delimiter">;</span> ++argv<span class="Delimiter">;</span> ++arg<span class="Delimiter">;</span> +<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">}</span> +<span id="L24" class="LineNr"> 24 </span> +<span id="L25" class="LineNr"> 25 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L98'>is_equal</a><span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"help"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L26" class="LineNr"> 26 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>argc == <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L27" class="LineNr"> 27 </span> cerr << <span class="Constant">"help on what?</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L28" class="LineNr"> 28 </span> <a href='001help.cc.html#L46'>help_contents</a><span class="Delimiter">();</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Delimiter">}</span> +<span id="L31" class="LineNr"> 31 </span> string key<span class="Delimiter">(</span>argv[<span class="Constant">2</span>]<span class="Delimiter">);</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Comment">// End Help Special-cases(key)</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L231'>contains_key</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> key<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L34" class="LineNr"> 34 </span> cerr << get<span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> key<span class="Delimiter">);</span> +<span id="L35" class="LineNr"> 35 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Delimiter">}</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L38" class="LineNr"> 38 </span> cerr << <span class="Constant">"No help found for '"</span> << key << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L39" class="LineNr"> 39 </span> <a href='001help.cc.html#L46'>help_contents</a><span class="Delimiter">();</span> +<span id="L40" class="LineNr"> 40 </span> cerr << <span class="Constant">"Please check your command for typos.</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L41" class="LineNr"> 41 </span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Delimiter">}</span> +<span id="L43" class="LineNr"> 43 </span><span class="Delimiter">}</span> +<span id="L44" class="LineNr"> 44 </span> +<span id="L45" class="LineNr"> 45 </span><span class="Delimiter">:(code)</span> +<span id="L46" class="LineNr"> 46 </span><span class="Normal">void</span> <a href='001help.cc.html#L46'>help_contents</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L47" class="LineNr"> 47 </span> cerr << <span class="Constant">"Available top-level topics:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L48" class="LineNr"> 48 </span> cerr << <span class="Constant">" usage</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Comment">// End Help Contents</span> +<span id="L50" class="LineNr"> 50 </span><span class="Delimiter">}</span> +<span id="L51" class="LineNr"> 51 </span> +<span id="L52" class="LineNr"> 52 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L53" class="LineNr"> 53 </span>map<string<span class="Delimiter">,</span> string> <a href='001help.cc.html#L53'>Help</a><span class="Delimiter">;</span> +<span id="L54" class="LineNr"> 54 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L55" class="LineNr"> 55 </span><span class="PreProc">#include </span><span class="Constant"><map></span> +<span id="L56" class="LineNr"> 56 </span><span class="Normal">using</span> std::map<span class="Delimiter">;</span> +<span id="L57" class="LineNr"> 57 </span><span class="Delimiter">:(before "End One-time Setup")</span> +<span id="L58" class="LineNr"> 58 </span><a href='001help.cc.html#L60'>init_help</a><span class="Delimiter">();</span> +<span id="L59" class="LineNr"> 59 </span><span class="Delimiter">:(code)</span> +<span id="L60" class="LineNr"> 60 </span><span class="Normal">void</span> <a href='001help.cc.html#L60'>init_help</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L61" class="LineNr"> 61 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"usage"</span><span class="Delimiter">,</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Constant">"bootstrap: the bootstrap translator for SubX.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Constant">"This program also wraps some miscellaneous useful functionality:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Constant">" - an x86 emulator: `bootstrap run`</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Constant">" - online help: `bootstrap help`</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Constant">"== Ways to invoke bootstrap</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Constant">"- See this message:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Constant">" bootstrap --help</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Constant">"- Convert a textual SubX program into a standard ELF binary that you can</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Constant">" <a href='011run.cc.html#L82'>run</a> on your computer:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Constant">" bootstrap translate input1.subx input2.subx ... -o <output ELF binary></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">"- Run a SubX binary using SubX itself (for better error messages):</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Constant">" bootstrap <a href='011run.cc.html#L82'>run</a> <ELF binary></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Constant">"- Run all bootstrap's unit tests:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L76" class="LineNr"> 76 </span> <span class="Constant">" bootstrap test</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Constant">"- Run a single unit test:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Constant">" bootstrap test <test name></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Constant">" e.g. bootstrap test <a href='011run.cc.html#L36'>test_copy_imm32_to_EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Constant">"== Debugging aids</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Constant">"- Add '--trace' to any of these commands to save a <a href='003trace.cc.html#L96'>trace</a> to disk at the end.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Constant">" This can <a href='011run.cc.html#L82'>run</a> out of memory for long-running commands.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Constant">"- Add '--debug' to emit additional debug information during translation.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Constant">" 'bootstrap --debug translate' will save metadata to disk that</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Constant">" 'bootstrap --trace run' uses to make traces more informative.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Constant">"Options starting with '--' must always come before any other arguments.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Constant">"To start learning how to write SubX programs, see Readme.md (particularly</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Constant">"the section on the x86 instruction set) and then <a href='011run.cc.html#L82'>run</a>:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Constant">" bootstrap help</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Delimiter">);</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Comment">// End Help Texts</span> +<span id="L95" class="LineNr"> 95 </span><span class="Delimiter">}</span> +<span id="L96" class="LineNr"> 96 </span> +<span id="L97" class="LineNr"> 97 </span><span class="Delimiter">:(code)</span> +<span id="L98" class="LineNr"> 98 </span><span class="Normal">bool</span> <a href='001help.cc.html#L98'>is_equal</a><span class="Delimiter">(</span><span class="Normal">const</span> <span class="Normal">char</span>* s<span class="Delimiter">,</span> <span class="Normal">const</span> <span class="Normal">char</span>* lit<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L99" class="LineNr"> 99 </span> <span class="Normal">size_t</span> len = strlen<span class="Delimiter">(</span>lit<span class="Delimiter">);</span> +<span id="L100" class="LineNr">100 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>strlen<span class="Delimiter">(</span>s<span class="Delimiter">)</span> != len<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L101" class="LineNr">101 </span> <span class="Identifier">return</span> strncmp<span class="Delimiter">(</span>s<span class="Delimiter">,</span> lit<span class="Delimiter">,</span> len<span class="Delimiter">)</span> == <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L102" class="LineNr">102 </span><span class="Delimiter">}</span> +<span id="L103" class="LineNr">103 </span> +<span id="L104" class="LineNr">104 </span><span class="Normal">bool</span> <a href='001help.cc.html#L104'>starts_with</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">,</span> <span class="Normal">const</span> string& pat<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L105" class="LineNr">105 </span> string::const_iterator a=s<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> b=pat<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> +<span id="L106" class="LineNr">106 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">nada</span><span class="Comment">*/</span><span class="Delimiter">;</span> a!=s<span class="Delimiter">.</span>end<span class="Delimiter">()</span> && b!=pat<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++a<span class="Delimiter">,</span> ++b<span class="Delimiter">)</span> +<span id="L107" class="LineNr">107 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*a != *b<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L108" class="LineNr">108 </span> <span class="Identifier">return</span> b == pat<span class="Delimiter">.</span>end<span class="Delimiter">();</span> +<span id="L109" class="LineNr">109 </span><span class="Delimiter">}</span> +<span id="L110" class="LineNr">110 </span> +<span id="L111" class="LineNr">111 </span><span class="Comment">//: I'll throw some style conventions here for want of a better place for them.</span> +<span id="L112" class="LineNr">112 </span><span class="Comment">//: As a rule I hate style guides. Do what you want, that's my motto. But since</span> +<span id="L113" class="LineNr">113 </span><span class="Comment">//: we're dealing with C/C++, the one big thing we want to avoid is undefined</span> +<span id="L114" class="LineNr">114 </span><span class="Comment">//: behavior. If a compiler ever encounters undefined behavior it can make</span> +<span id="L115" class="LineNr">115 </span><span class="Comment">//: your program do anything it wants.</span> +<span id="L116" class="LineNr">116 </span><span class="Comment">//:</span> +<span id="L117" class="LineNr">117 </span><span class="Comment">//: For reference, my checklist of undefined behaviors to watch out for:</span> +<span id="L118" class="LineNr">118 </span><span class="Comment">//: out-of-bounds access</span> +<span id="L119" class="LineNr">119 </span><span class="Comment">//: uninitialized variables</span> +<span id="L120" class="LineNr">120 </span><span class="Comment">//: use after free</span> +<span id="L121" class="LineNr">121 </span><span class="Comment">//: dereferencing invalid pointers: null, a new of size 0, others</span> +<span id="L122" class="LineNr">122 </span><span class="Comment">//:</span> +<span id="L123" class="LineNr">123 </span><span class="Comment">//: casting a large number to a type too small to hold it</span> +<span id="L124" class="LineNr">124 </span><span class="Comment">//:</span> +<span id="L125" class="LineNr">125 </span><span class="Comment">//: integer overflow</span> +<span id="L126" class="LineNr">126 </span><span class="Comment">//: division by zero and other undefined expressions</span> +<span id="L127" class="LineNr">127 </span><span class="Comment">//: left-shift by negative count</span> +<span id="L128" class="LineNr">128 </span><span class="Comment">//: shifting values by more than or equal to the number of bits they contain</span> +<span id="L129" class="LineNr">129 </span><span class="Comment">//: bitwise operations on signed numbers</span> +<span id="L130" class="LineNr">130 </span><span class="Comment">//:</span> +<span id="L131" class="LineNr">131 </span><span class="Comment">//: Converting pointers to types of different alignment requirements</span> +<span id="L132" class="LineNr">132 </span><span class="Comment">//: T* -> void* -> T*: defined</span> +<span id="L133" class="LineNr">133 </span><span class="Comment">//: T* -> U* -> T*: defined if non-function pointers and alignment requirements are same</span> +<span id="L134" class="LineNr">134 </span><span class="Comment">//: function pointers may be cast to other function pointers</span> +<span id="L135" class="LineNr">135 </span><span class="Comment">//:</span> +<span id="L136" class="LineNr">136 </span><span class="Comment">//: Casting a numeric value into a value that can't be represented by the target type (either directly or via static_cast)</span> +<span id="L137" class="LineNr">137 </span><span class="Comment">//:</span> +<span id="L138" class="LineNr">138 </span><span class="Comment">//: To guard against these, some conventions:</span> +<span id="L139" class="LineNr">139 </span><span class="Comment">//:</span> +<span id="L140" class="LineNr">140 </span><span class="Comment">//: 0. Initialize all primitive variables in functions and constructors.</span> +<span id="L141" class="LineNr">141 </span><span class="Comment">//:</span> +<span id="L142" class="LineNr">142 </span><span class="Comment">//: 1. Minimize use of pointers and pointer arithmetic. Avoid 'new' and</span> +<span id="L143" class="LineNr">143 </span><span class="Comment">//: 'delete' as far as possible. Rely on STL to perform memory management to</span> +<span id="L144" class="LineNr">144 </span><span class="Comment">//: avoid use-after-free issues (and memory leaks).</span> +<span id="L145" class="LineNr">145 </span><span class="Comment">//:</span> +<span id="L146" class="LineNr">146 </span><span class="Comment">//: 2. Avoid naked arrays to avoid out-of-bounds access. Never use operator[]</span> +<span id="L147" class="LineNr">147 </span><span class="Comment">//: except with map. Use at() with STL vectors and so on.</span> +<span id="L148" class="LineNr">148 </span><span class="Comment">//:</span> +<span id="L149" class="LineNr">149 </span><span class="Comment">//: 3. Valgrind all the things.</span> +<span id="L150" class="LineNr">150 </span><span class="Comment">//:</span> +<span id="L151" class="LineNr">151 </span><span class="Comment">//: 4. Avoid unsigned numbers. Not strictly an undefined-behavior issue, but</span> +<span id="L152" class="LineNr">152 </span><span class="Comment">//: the extra range doesn't matter, and it's one less confusing category of</span> +<span id="L153" class="LineNr">153 </span><span class="Comment">//: interaction gotchas to worry about.</span> +<span id="L154" class="LineNr">154 </span><span class="Comment">//:</span> +<span id="L155" class="LineNr">155 </span><span class="Comment">//: Corollary: don't use the size() method on containers, since it returns an</span> +<span id="L156" class="LineNr">156 </span><span class="Comment">//: unsigned and that'll cause warnings about mixing signed and unsigned,</span> +<span id="L157" class="LineNr">157 </span><span class="Comment">//: yadda-yadda. Instead use this macro below to perform an unsafe cast to</span> +<span id="L158" class="LineNr">158 </span><span class="Comment">//: signed. We'll just give up immediately if a container's ever too large.</span> +<span id="L159" class="LineNr">159 </span><span class="Comment">//: Basically, Mu is not concerned about this being a little slower than it</span> +<span id="L160" class="LineNr">160 </span><span class="Comment">//: could be. (<a href="https://gist.github.com/rygorous/e0f055bfb74e3d5f0af20690759de5a7)">https://gist.github.com/rygorous/e0f055bfb74e3d5f0af20690759de5a7)</a></span> +<span id="L161" class="LineNr">161 </span><span class="Comment">//:</span> +<span id="L162" class="LineNr">162 </span><span class="Comment">//: Addendum to corollary: We're going to uniformly use int everywhere, to</span> +<span id="L163" class="LineNr">163 </span><span class="Comment">//: indicate that we're oblivious to number size, and since Clang on 32-bit</span> +<span id="L164" class="LineNr">164 </span><span class="Comment">//: platforms doesn't yet support multiplication over 64-bit integers, and</span> +<span id="L165" class="LineNr">165 </span><span class="Comment">//: since multiplying two integers seems like a more common situation to end</span> +<span id="L166" class="LineNr">166 </span><span class="Comment">//: up in than integer overflow.</span> +<span id="L167" class="LineNr">167 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L168" class="LineNr">168 </span><span class="PreProc">#define SIZE(X) (assert((X)</span><span class="Delimiter">.</span><span class="PreProc">size() < (</span><span class="Constant">1LL</span><span class="PreProc"><<(</span><span class="Normal">sizeof</span><span class="PreProc">(</span><span class="Normal">int</span><span class="PreProc">)*</span><span class="Constant">8</span><span class="PreProc">-</span><span class="Constant">2</span><span class="PreProc">)))</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Normal">static_cast</span><span class="PreProc"><</span><span class="Normal">int</span><span class="PreProc">>((X)</span><span class="Delimiter">.</span><span class="PreProc">size()))</span> +<span id="L169" class="LineNr">169 </span> +<span id="L170" class="LineNr">170 </span><span class="Comment">//: 5. Integer overflow is guarded against at runtime using the -ftrapv flag</span> +<span id="L171" class="LineNr">171 </span><span class="Comment">//: to the compiler, supported by Clang (GCC version only works sometimes:</span> +<span id="L172" class="LineNr">172 </span><span class="Comment">//: <a href="http://stackoverflow.com/questions/20851061/how-to-make-gcc-ftrapv-work).">http://stackoverflow.com/questions/20851061/how-to-make-gcc-ftrapv-work).</a></span> +<span id="L173" class="LineNr">173 </span><span class="Delimiter">:(before "atexit(<a href='000organization.cc.html#L150'>reset</a>)")</span> +<span id="L174" class="LineNr">174 </span><a href='001help.cc.html#L179'>initialize_signal_handlers</a><span class="Delimiter">();</span> <span class="Comment">// not always necessary, but doesn't hurt</span> +<span id="L175" class="LineNr">175 </span><span class="CommentedCode">//? cerr << INT_MAX+1 << '\n'; // test overflow</span> +<span id="L176" class="LineNr">176 </span><span class="CommentedCode">//? assert(false); // test SIGABRT</span> +<span id="L177" class="LineNr">177 </span><span class="Delimiter">:(code)</span> +<span id="L178" class="LineNr">178 </span><span class="Comment">// based on <a href="https://spin.atomicobject.com/2013/01/13/exceptions-stack-traces-c">https://spin.atomicobject.com/2013/01/13/exceptions-stack-traces-c</a></span> +<span id="L179" class="LineNr">179 </span><span class="Normal">void</span> <a href='001help.cc.html#L179'>initialize_signal_handlers</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L180" class="LineNr">180 </span> <span class="Normal">struct</span> sigaction action<span class="Delimiter">;</span> +<span id="L181" class="LineNr">181 </span> bzero<span class="Delimiter">(</span>&action<span class="Delimiter">,</span> <span class="Normal">sizeof</span><span class="Delimiter">(</span>action<span class="Delimiter">));</span> +<span id="L182" class="LineNr">182 </span> action<span class="Delimiter">.</span>sa_sigaction = <a href='001help.cc.html#L187'>dump_and_exit</a><span class="Delimiter">;</span> +<span id="L183" class="LineNr">183 </span> sigemptyset<span class="Delimiter">(</span>&action<span class="Delimiter">.</span>sa_mask<span class="Delimiter">);</span> +<span id="L184" class="LineNr">184 </span> sigaction<span class="Delimiter">(</span><span class="Constant">SIGABRT</span><span class="Delimiter">,</span> &action<span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">);</span> <span class="Comment">// assert() failure or integer overflow on linux (with -ftrapv)</span> +<span id="L185" class="LineNr">185 </span> sigaction<span class="Delimiter">(</span><span class="Constant">SIGILL</span><span class="Delimiter">,</span> &action<span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">);</span> <span class="Comment">// integer overflow on OS X (with -ftrapv)</span> +<span id="L186" class="LineNr">186 </span><span class="Delimiter">}</span> +<span id="L187" class="LineNr">187 </span><span class="Normal">void</span> <a href='001help.cc.html#L187'>dump_and_exit</a><span class="Delimiter">(</span><span class="Normal">int</span> sig<span class="Delimiter">,</span> siginfo_t* <span class="Comment">/*</span><span class="Comment">unused</span><span class="Comment">*/</span><span class="Delimiter">,</span> <span class="Normal">void</span>* <span class="Comment">/*</span><span class="Comment">unused</span><span class="Comment">*/</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L188" class="LineNr">188 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>sig<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L189" class="LineNr">189 </span> <span class="Normal">case</span> <span class="Constant">SIGABRT</span>: +<span id="L190" class="LineNr">190 </span> <span class="PreProc">#ifndef __APPLE__</span> +<span id="L191" class="LineNr">191 </span> cerr << <span class="Constant">"SIGABRT: might be an integer overflow if it wasn't an assert() failure</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L192" class="LineNr">192 </span> _Exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L193" class="LineNr">193 </span> <span class="PreProc">#endif</span> +<span id="L194" class="LineNr">194 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L195" class="LineNr">195 </span> <span class="Normal">case</span> <span class="Constant">SIGILL</span>: +<span id="L196" class="LineNr">196 </span> <span class="PreProc">#ifdef __APPLE__</span> +<span id="L197" class="LineNr">197 </span> cerr << <span class="Constant">"SIGILL: most likely caused by integer overflow</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L198" class="LineNr">198 </span> _Exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L199" class="LineNr">199 </span> <span class="PreProc">#endif</span> +<span id="L200" class="LineNr">200 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L201" class="LineNr">201 </span> <span class="Normal">default</span>: +<span id="L202" class="LineNr">202 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L203" class="LineNr">203 </span> <span class="Delimiter">}</span> +<span id="L204" class="LineNr">204 </span><span class="Delimiter">}</span> +<span id="L205" class="LineNr">205 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L206" class="LineNr">206 </span><span class="PreProc">#include </span><span class="Constant"><signal.h></span> +<span id="L207" class="LineNr">207 </span> +<span id="L208" class="LineNr">208 </span><span class="Comment">//: 6. Map's operator[] being non-const is fucking evil.</span> +<span id="L209" class="LineNr">209 </span><span class="Delimiter">:(before "Globals")</span> <span class="Comment">// can't generate prototypes for these</span> +<span id="L210" class="LineNr">210 </span><span class="Comment">// from <a href="http://stackoverflow.com/questions/152643/idiomatic-c-for-reading-from-a-const-map">http://stackoverflow.com/questions/152643/idiomatic-c-for-reading-from-a-const-map</a></span> +<span id="L211" class="LineNr">211 </span><span class="Normal">template</span><<span class="Normal">typename</span> T> <span class="Normal">typename</span> T::mapped_type& get<span class="Delimiter">(</span>T& map<span class="Delimiter">,</span> <span class="Normal">typename</span> T::key_type <span class="Normal">const</span>& key<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L212" class="LineNr">212 </span> <span class="Normal">typename</span> T::iterator iter<span class="Delimiter">(</span>map<span class="Delimiter">.</span>find<span class="Delimiter">(</span>key<span class="Delimiter">));</span> +<span id="L213" class="LineNr">213 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>iter == map<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L214" class="LineNr">214 </span> cerr << <span class="Constant">"get couldn't find key '"</span> << key << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L215" class="LineNr">215 </span> assert<span class="Delimiter">(</span>iter != map<span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L216" class="LineNr">216 </span> <span class="Delimiter">}</span> +<span id="L217" class="LineNr">217 </span> <span class="Identifier">return</span> iter<span class="Delimiter">-></span>second<span class="Delimiter">;</span> +<span id="L218" class="LineNr">218 </span><span class="Delimiter">}</span> +<span id="L219" class="LineNr">219 </span><span class="Normal">template</span><<span class="Normal">typename</span> T> <span class="Normal">typename</span> T::mapped_type <span class="Normal">const</span>& get<span class="Delimiter">(</span><span class="Normal">const</span> T& map<span class="Delimiter">,</span> <span class="Normal">typename</span> T::key_type <span class="Normal">const</span>& key<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L220" class="LineNr">220 </span> <span class="Normal">typename</span> T::const_iterator iter<span class="Delimiter">(</span>map<span class="Delimiter">.</span>find<span class="Delimiter">(</span>key<span class="Delimiter">));</span> +<span id="L221" class="LineNr">221 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>iter == map<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L222" class="LineNr">222 </span> cerr << <span class="Constant">"get couldn't find key '"</span> << key << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L223" class="LineNr">223 </span> assert<span class="Delimiter">(</span>iter != map<span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L224" class="LineNr">224 </span> <span class="Delimiter">}</span> +<span id="L225" class="LineNr">225 </span> <span class="Identifier">return</span> iter<span class="Delimiter">-></span>second<span class="Delimiter">;</span> +<span id="L226" class="LineNr">226 </span><span class="Delimiter">}</span> +<span id="L227" class="LineNr">227 </span><span class="Normal">template</span><<span class="Normal">typename</span> T> <span class="Normal">typename</span> T::mapped_type <span class="Normal">const</span>& <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span>T& map<span class="Delimiter">,</span> <span class="Normal">typename</span> T::key_type <span class="Normal">const</span>& key<span class="Delimiter">,</span> <span class="Normal">typename</span> T::mapped_type <span class="Normal">const</span>& value<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L228" class="LineNr">228 </span> map[key] = value<span class="Delimiter">;</span> +<span id="L229" class="LineNr">229 </span> <span class="Identifier">return</span> map[key]<span class="Delimiter">;</span> +<span id="L230" class="LineNr">230 </span><span class="Delimiter">}</span> +<span id="L231" class="LineNr">231 </span><span class="Normal">template</span><<span class="Normal">typename</span> T> <span class="Normal">bool</span> <a href='001help.cc.html#L231'>contains_key</a><span class="Delimiter">(</span>T& map<span class="Delimiter">,</span> <span class="Normal">typename</span> T::key_type <span class="Normal">const</span>& key<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L232" class="LineNr">232 </span> <span class="Identifier">return</span> map<span class="Delimiter">.</span>find<span class="Delimiter">(</span>key<span class="Delimiter">)</span> != map<span class="Delimiter">.</span>end<span class="Delimiter">();</span> +<span id="L233" class="LineNr">233 </span><span class="Delimiter">}</span> +<span id="L234" class="LineNr">234 </span><span class="Normal">template</span><<span class="Normal">typename</span> T> <span class="Normal">typename</span> T::mapped_type& <a href='001help.cc.html#L234'>get_or_insert</a><span class="Delimiter">(</span>T& map<span class="Delimiter">,</span> <span class="Normal">typename</span> T::key_type <span class="Normal">const</span>& key<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L235" class="LineNr">235 </span> <span class="Identifier">return</span> map[key]<span class="Delimiter">;</span> +<span id="L236" class="LineNr">236 </span><span class="Delimiter">}</span> +<span id="L237" class="LineNr">237 </span><span class="Normal">template</span><<span class="Normal">typename</span> T> <span class="Normal">typename</span> T::mapped_type <span class="Normal">const</span>& <a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span>T& map<span class="Delimiter">,</span> <span class="Normal">typename</span> T::key_type <span class="Normal">const</span>& key<span class="Delimiter">,</span> <span class="Normal">typename</span> T::mapped_type <span class="Normal">const</span>& value<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L238" class="LineNr">238 </span> assert<span class="Delimiter">(</span>map<span class="Delimiter">.</span>find<span class="Delimiter">(</span>key<span class="Delimiter">)</span> == map<span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L239" class="LineNr">239 </span> map[key] = value<span class="Delimiter">;</span> +<span id="L240" class="LineNr">240 </span> <span class="Identifier">return</span> map[key]<span class="Delimiter">;</span> +<span id="L241" class="LineNr">241 </span><span class="Delimiter">}</span> +<span id="L242" class="LineNr">242 </span><span class="Comment">//: The contract: any container that relies on get_or_insert should never call</span> +<span id="L243" class="LineNr">243 </span><span class="Comment">//: contains_key.</span> +<span id="L244" class="LineNr">244 </span> +<span id="L245" class="LineNr">245 </span><span class="Comment">//: 7. istreams are a royal pain in the arse. You have to be careful about</span> +<span id="L246" class="LineNr">246 </span><span class="Comment">//: what subclass you try to putback into. You have to watch out for the pesky</span> +<span id="L247" class="LineNr">247 </span><span class="Comment">//: failbit and badbit. Just avoid eof() and use this helper instead.</span> +<span id="L248" class="LineNr">248 </span><span class="Delimiter">:(code)</span> +<span id="L249" class="LineNr">249 </span><span class="Normal">bool</span> <a href='001help.cc.html#L249'>has_data</a><span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L250" class="LineNr">250 </span> <span class="Identifier">return</span> in && !in<span class="Delimiter">.</span>eof<span class="Delimiter">();</span> +<span id="L251" class="LineNr">251 </span><span class="Delimiter">}</span> +<span id="L252" class="LineNr">252 </span> +<span id="L253" class="LineNr">253 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L254" class="LineNr">254 </span><span class="PreProc">#include </span><span class="Constant"><assert.h></span> +<span id="L255" class="LineNr">255 </span> +<span id="L256" class="LineNr">256 </span><span class="PreProc">#include </span><span class="Constant"><iostream></span> +<span id="L257" class="LineNr">257 </span><span class="Normal">using</span> std::istream<span class="Delimiter">;</span> +<span id="L258" class="LineNr">258 </span><span class="Normal">using</span> std::ostream<span class="Delimiter">;</span> +<span id="L259" class="LineNr">259 </span><span class="Normal">using</span> std::iostream<span class="Delimiter">;</span> +<span id="L260" class="LineNr">260 </span><span class="Normal">using</span> std::cin<span class="Delimiter">;</span> +<span id="L261" class="LineNr">261 </span><span class="Normal">using</span> std::cout<span class="Delimiter">;</span> +<span id="L262" class="LineNr">262 </span><span class="Normal">using</span> std::cerr<span class="Delimiter">;</span> +<span id="L263" class="LineNr">263 </span><span class="PreProc">#include </span><span class="Constant"><iomanip></span> +<span id="L264" class="LineNr">264 </span> +<span id="L265" class="LineNr">265 </span><span class="PreProc">#include </span><span class="Constant"><string.h></span> +<span id="L266" class="LineNr">266 </span><span class="PreProc">#include </span><span class="Constant"><string></span> +<span id="L267" class="LineNr">267 </span><span class="Normal">using</span> std::string<span class="Delimiter">;</span> +<span id="L268" class="LineNr">268 </span> +<span id="L269" class="LineNr">269 </span><span class="PreProc">#include </span><span class="Constant"><algorithm></span> +<span id="L270" class="LineNr">270 </span><span class="Normal">using</span> std::min<span class="Delimiter">;</span> +<span id="L271" class="LineNr">271 </span><span class="Normal">using</span> std::max<span class="Delimiter">;</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/002test.cc.html b/html/linux/bootstrap/002test.cc.html new file mode 100644 index 00000000..1c6d84f8 --- /dev/null +++ b/html/linux/bootstrap/002test.cc.html @@ -0,0 +1,187 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/002test.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.PreProc { color: #c000c0; } +.LineNr { } +.Constant { color: #008787; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.cSpecial { color: #008000; } +.Identifier { color: #af5f00; } +.CommentedCode { color: #8a8a8a; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/002test.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/002test.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: A simple test harness. To create new tests, define functions starting with</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: 'test_'. To run all tests so defined, run:</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: $ ./bootstrap test</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//:</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: Every layer should include tests, and can reach into previous layers.</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment">//: However, it seems like a good idea never to reach into tests from previous</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment">//: layers. Every test should be a contract that always passes as originally</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment">//: written, regardless of any later layers. Avoid writing 'temporary' tests</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment">//: that are only meant to work until some layer.</span> +<span id="L10" class="LineNr"> 10 </span> +<span id="L11" class="LineNr"> 11 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L12" class="LineNr"> 12 </span><span class="Normal">typedef</span> <span class="Normal">void</span> <span class="Delimiter">(</span>*test_fn<span class="Delimiter">)(</span><span class="Normal">void</span><span class="Delimiter">);</span> +<span id="L13" class="LineNr"> 13 </span><span class="Delimiter">:(before "Globals")</span> +<span id="L14" class="LineNr"> 14 </span><span class="Comment">// move a global ahead into types that we can't generate an extern declaration for</span> +<span id="L15" class="LineNr"> 15 </span><span class="Normal">const</span> <a href='002test.cc.html#L12'>test_fn</a> Tests[] = <span class="Delimiter">{</span> +<span id="L16" class="LineNr"> 16 </span> <span class="PreProc">#include </span><span class="Constant">"test_list"</span> <span class="Comment">// auto-generated; see 'build*' scripts</span> +<span id="L17" class="LineNr"> 17 </span><span class="Delimiter">};</span> +<span id="L18" class="LineNr"> 18 </span> +<span id="L19" class="LineNr"> 19 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L20" class="LineNr"> 20 </span><span class="Normal">bool</span> <a href='002test.cc.html#L20'>Run_tests</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L21" class="LineNr"> 21 </span><span class="Normal">bool</span> <a href='002test.cc.html#L21'>Passed</a> = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// set this to false inside any test to indicate failure</span> +<span id="L22" class="LineNr"> 22 </span> +<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L24" class="LineNr"> 24 </span><span class="PreProc">#define CHECK(X) \</span> +<span id="L25" class="LineNr"> 25 </span><span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (<a href='002test.cc.html#L21'>Passed</a> && !(X)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> +<span id="L26" class="LineNr"> 26 </span><span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L27" class="LineNr"> 27 </span><span class="PreProc"> <a href='002test.cc.html#L21'>Passed</a> = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L28" class="LineNr"> 28 </span><span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> +<span id="L29" class="LineNr"> 29 </span><span class="PreProc"> </span><span class="Delimiter">}</span> +<span id="L30" class="LineNr"> 30 </span> +<span id="L31" class="LineNr"> 31 </span><span class="PreProc">#define CHECK_EQ(X</span><span class="Delimiter">,</span><span class="PreProc"> Y) \</span> +<span id="L32" class="LineNr"> 32 </span><span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (<a href='002test.cc.html#L21'>Passed</a> && (X) != (Y)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> +<span id="L33" class="LineNr"> 33 </span><span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="Constant">" == "</span><span class="PreProc"> << #Y << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L34" class="LineNr"> 34 </span><span class="PreProc"> cerr << </span><span class="Constant">" got "</span><span class="PreProc"> << (X) << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> BEWARE: multiple eval </span><span class="Comment">*/</span><span class="PreProc"> \</span> +<span id="L35" class="LineNr"> 35 </span><span class="PreProc"> <a href='002test.cc.html#L21'>Passed</a> = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L36" class="LineNr"> 36 </span><span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> +<span id="L37" class="LineNr"> 37 </span><span class="PreProc"> </span><span class="Delimiter">}</span> +<span id="L38" class="LineNr"> 38 </span> +<span id="L39" class="LineNr"> 39 </span><span class="Delimiter">:(before "End Reset")</span> +<span id="L40" class="LineNr"> 40 </span><a href='002test.cc.html#L21'>Passed</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L41" class="LineNr"> 41 </span> +<span id="L42" class="LineNr"> 42 </span><span class="Delimiter">:(before "End Commandline Parsing")</span> +<span id="L43" class="LineNr"> 43 </span><span class="Normal">if</span> <span class="Delimiter">(</span>argc > <span class="Constant">1</span> && <a href='001help.cc.html#L98'>is_equal</a><span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"test"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L44" class="LineNr"> 44 </span> <a href='002test.cc.html#L20'>Run_tests</a> = <span class="Constant">true</span><span class="Delimiter">;</span> --argc<span class="Delimiter">;</span> ++argv<span class="Delimiter">;</span> <span class="Comment">// shift 'test' out of commandline args</span> +<span id="L45" class="LineNr"> 45 </span><span class="Delimiter">}</span> +<span id="L46" class="LineNr"> 46 </span> +<span id="L47" class="LineNr"> 47 </span><span class="Delimiter">:(before "End Main")</span> +<span id="L48" class="LineNr"> 48 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L20'>Run_tests</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Comment">// Test Runs</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Comment">// we run some tests and then exit; assume no state need be maintained afterward</span> +<span id="L51" class="LineNr"> 51 </span> +<span id="L52" class="LineNr"> 52 </span> <span class="Normal">long</span> num_failures = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Comment">// End Test Run Initialization</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Normal">time_t</span> t<span class="Delimiter">;</span> time<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> +<span id="L55" class="LineNr"> 55 </span> cerr << <span class="Constant">"C tests: "</span> << ctime<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i=<span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='002test.cc.html#L15'>Tests</a><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L57" class="LineNr"> 57 </span><span class="CommentedCode">//? cerr << "running " << Test_names[i] << '\n';</span> +<span id="L58" class="LineNr"> 58 </span> <a href='002test.cc.html#L81'>run_test</a><span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L21'>Passed</a><span class="Delimiter">)</span> cerr << <span class="Constant">'.'</span><span class="Delimiter">;</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Normal">else</span> ++num_failures<span class="Delimiter">;</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Delimiter">}</span> +<span id="L62" class="LineNr"> 62 </span> cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Comment">// End Tests</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>num_failures > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L65" class="LineNr"> 65 </span> cerr << num_failures << <span class="Constant">" failure"</span> +<span id="L66" class="LineNr"> 66 </span> << <span class="Delimiter">(</span>num_failures > <span class="Constant">1</span> ? <span class="Constant">"s"</span> : <span class="Constant">""</span><span class="Delimiter">)</span> +<span id="L67" class="LineNr"> 67 </span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Delimiter">}</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L71" class="LineNr"> 71 </span><span class="Delimiter">}</span> +<span id="L72" class="LineNr"> 72 </span> +<span id="L73" class="LineNr"> 73 </span><span class="Delimiter">:(after "End Main")</span> +<span id="L74" class="LineNr"> 74 </span><span class="Comment">//: Raise other unrecognized sub-commands as errors.</span> +<span id="L75" class="LineNr"> 75 </span><span class="Comment">//: We couldn't do this until now because we want `./bootstrap test` to always</span> +<span id="L76" class="LineNr"> 76 </span><span class="Comment">//: succeed, no matter how many layers are included in the build.</span> +<span id="L77" class="LineNr"> 77 </span>cerr << <span class="Constant">"nothing to do</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L78" class="LineNr"> 78 </span><span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L79" class="LineNr"> 79 </span> +<span id="L80" class="LineNr"> 80 </span><span class="Delimiter">:(code)</span> +<span id="L81" class="LineNr"> 81 </span><span class="Normal">void</span> <a href='002test.cc.html#L81'>run_test</a><span class="Delimiter">(</span><span class="Normal">size_t</span> i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i >= <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='002test.cc.html#L15'>Tests</a><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L83" class="LineNr"> 83 </span> cerr << <span class="Constant">"no test "</span> << i << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Delimiter">}</span> +<span id="L86" class="LineNr"> 86 </span> <a href='000organization.cc.html#L150'>reset</a><span class="Delimiter">();</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Comment">// End Test Setup</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Delimiter">(</span>*Tests[i]<span class="Delimiter">)();</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Comment">// End Test Teardown</span> +<span id="L90" class="LineNr"> 90 </span><span class="Delimiter">}</span> +<span id="L91" class="LineNr"> 91 </span> +<span id="L92" class="LineNr"> 92 </span><span class="Comment">//: Convenience: run a single test</span> +<span id="L93" class="LineNr"> 93 </span><span class="Delimiter">:(before "Globals")</span> +<span id="L94" class="LineNr"> 94 </span><span class="Comment">// Names for each element of the 'Tests' global, respectively.</span> +<span id="L95" class="LineNr"> 95 </span><span class="Normal">const</span> string Test_names[] = <span class="Delimiter">{</span> +<span id="L96" class="LineNr"> 96 </span> <span class="PreProc">#include </span><span class="Constant">"test_name_list"</span> <span class="Comment">// auto-generated; see 'build*' scripts</span> +<span id="L97" class="LineNr"> 97 </span><span class="Delimiter">};</span> +<span id="L98" class="LineNr"> 98 </span><span class="Delimiter">:(after "Test Runs")</span> +<span id="L99" class="LineNr"> 99 </span>string <a href='002test.cc.html#L99'>maybe_single_test_to_run</a> = argv[argc-<span class="Constant">1</span>]<span class="Delimiter">;</span> +<span id="L100" class="LineNr">100 </span><span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i=<span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='002test.cc.html#L15'>Tests</a><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L101" class="LineNr">101 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Test_names[i] == <a href='002test.cc.html#L99'>maybe_single_test_to_run</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L102" class="LineNr">102 </span> <a href='002test.cc.html#L81'>run_test</a><span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L103" class="LineNr">103 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L21'>Passed</a><span class="Delimiter">)</span> cerr << <span class="Constant">".</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L104" class="LineNr">104 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L105" class="LineNr">105 </span> <span class="Delimiter">}</span> +<span id="L106" class="LineNr">106 </span><span class="Delimiter">}</span> +<span id="L107" class="LineNr">107 </span> +<span id="L108" class="LineNr">108 </span><span class="Comment">//: A pending test that also serves to put our test harness through its paces.</span> +<span id="L109" class="LineNr">109 </span> +<span id="L110" class="LineNr">110 </span><span class="Delimiter">:(code)</span> +<span id="L111" class="LineNr">111 </span><span class="Normal">void</span> <a href='002test.cc.html#L111'>test_is_equal</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L112" class="LineNr">112 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span><a href='001help.cc.html#L98'>is_equal</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">));</span> +<span id="L113" class="LineNr">113 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_equal<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">));</span> +<span id="L114" class="LineNr">114 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_equal<span class="Delimiter">(</span><span class="Constant">"foo"</span><span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">));</span> +<span id="L115" class="LineNr">115 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_equal<span class="Delimiter">(</span><span class="Constant">"f"</span><span class="Delimiter">,</span> <span class="Constant">"bar"</span><span class="Delimiter">));</span> +<span id="L116" class="LineNr">116 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_equal<span class="Delimiter">(</span><span class="Constant">"bar"</span><span class="Delimiter">,</span> <span class="Constant">"f"</span><span class="Delimiter">));</span> +<span id="L117" class="LineNr">117 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_equal<span class="Delimiter">(</span><span class="Constant">"bar"</span><span class="Delimiter">,</span> <span class="Constant">"ba"</span><span class="Delimiter">));</span> +<span id="L118" class="LineNr">118 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_equal<span class="Delimiter">(</span><span class="Constant">"ba"</span><span class="Delimiter">,</span> <span class="Constant">"bar"</span><span class="Delimiter">));</span> +<span id="L119" class="LineNr">119 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span><a href='001help.cc.html#L98'>is_equal</a><span class="Delimiter">(</span><span class="Constant">"bar"</span><span class="Delimiter">,</span> <span class="Constant">"bar"</span><span class="Delimiter">));</span> +<span id="L120" class="LineNr">120 </span><span class="Delimiter">}</span> +<span id="L121" class="LineNr">121 </span> +<span id="L122" class="LineNr">122 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L123" class="LineNr">123 </span><span class="PreProc">#include </span><span class="Constant"><stdlib.h></span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/003trace.cc.html b/html/linux/bootstrap/003trace.cc.html new file mode 100644 index 00000000..e417260d --- /dev/null +++ b/html/linux/bootstrap/003trace.cc.html @@ -0,0 +1,586 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/003trace.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.PreProc { color: #c000c0; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.LineNr { } +.cSpecial { color: #008000; } +.Constant { color: #008787; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/003trace.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/003trace.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: The goal of layers is to make programs more easy to understand and more</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: malleable, easy to rewrite in radical ways without accidentally breaking</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: some corner case. Tests further both goals. They help understandability by</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: letting one make small changes and get feedback. What if I wrote this line</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: like so? What if I removed this function call, is it really necessary?</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment">//: Just try it, see if the tests pass. Want to explore rewriting this bit in</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment">//: this way? Tests put many refactorings on a firmer footing.</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment">//:</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment">//: But the usual way we write tests seems incomplete. Refactorings tend to</span> +<span id="L10" class="LineNr"> 10 </span><span class="Comment">//: work in the small, but don't help with changes to function boundaries. If</span> +<span id="L11" class="LineNr"> 11 </span><span class="Comment">//: you want to extract a new function you have to manually test-drive it to</span> +<span id="L12" class="LineNr"> 12 </span><span class="Comment">//: create tests for it. If you want to inline a function its tests are no</span> +<span id="L13" class="LineNr"> 13 </span><span class="Comment">//: longer valid. In both cases you end up having to reorganize code as well as</span> +<span id="L14" class="LineNr"> 14 </span><span class="Comment">//: tests, an error-prone activity.</span> +<span id="L15" class="LineNr"> 15 </span><span class="Comment">//:</span> +<span id="L16" class="LineNr"> 16 </span><span class="Comment">//: In response, this layer introduces the notion of domain-driven *white-box*</span> +<span id="L17" class="LineNr"> 17 </span><span class="Comment">//: testing. We focus on the domain of inputs the whole program needs to</span> +<span id="L18" class="LineNr"> 18 </span><span class="Comment">//: handle rather than the correctness of individual functions. All white-box</span> +<span id="L19" class="LineNr"> 19 </span><span class="Comment">//: tests invoke the program in a single way: by calling run() with some</span> +<span id="L20" class="LineNr"> 20 </span><span class="Comment">//: input. As the program operates on the input, it traces out a list of</span> +<span id="L21" class="LineNr"> 21 </span><span class="Comment">//: _facts_ deduced about the domain:</span> +<span id="L22" class="LineNr"> 22 </span><span class="Comment">//: trace("label") << "fact 1: " << val;</span> +<span id="L23" class="LineNr"> 23 </span><span class="Comment">//:</span> +<span id="L24" class="LineNr"> 24 </span><span class="Comment">//: Tests can now check for these facts in the trace:</span> +<span id="L25" class="LineNr"> 25 </span><span class="Comment">//: CHECK_TRACE_CONTENTS("label", "fact 1: 34\n"</span> +<span id="L26" class="LineNr"> 26 </span><span class="Comment">//: "fact 2: 35\n");</span> +<span id="L27" class="LineNr"> 27 </span><span class="Comment">//:</span> +<span id="L28" class="LineNr"> 28 </span><span class="Comment">//: Since we never call anything but the run() function directly, we never have</span> +<span id="L29" class="LineNr"> 29 </span><span class="Comment">//: to rewrite the tests when we reorganize the internals of the program. We</span> +<span id="L30" class="LineNr"> 30 </span><span class="Comment">//: just have to make sure our rewrite deduces the same facts about the domain,</span> +<span id="L31" class="LineNr"> 31 </span><span class="Comment">//: and that's something we're going to have to do anyway.</span> +<span id="L32" class="LineNr"> 32 </span><span class="Comment">//:</span> +<span id="L33" class="LineNr"> 33 </span><span class="Comment">//: To avoid the combinatorial explosion of integration tests, each layer</span> +<span id="L34" class="LineNr"> 34 </span><span class="Comment">//: mainly logs facts to the trace with a common *label*. All tests in a layer</span> +<span id="L35" class="LineNr"> 35 </span><span class="Comment">//: tend to check facts with this label. Validating the facts logged with a</span> +<span id="L36" class="LineNr"> 36 </span><span class="Comment">//: specific label is like calling functions of that layer directly.</span> +<span id="L37" class="LineNr"> 37 </span><span class="Comment">//:</span> +<span id="L38" class="LineNr"> 38 </span><span class="Comment">//: To build robust tests, trace facts about your domain rather than details of</span> +<span id="L39" class="LineNr"> 39 </span><span class="Comment">//: how you computed them.</span> +<span id="L40" class="LineNr"> 40 </span><span class="Comment">//:</span> +<span id="L41" class="LineNr"> 41 </span><span class="Comment">//: More details: <a href="http://akkartik.name/blog/tracing-tests">http://akkartik.name/blog/tracing-tests</a></span> +<span id="L42" class="LineNr"> 42 </span><span class="Comment">//:</span> +<span id="L43" class="LineNr"> 43 </span><span class="Comment">//: ---</span> +<span id="L44" class="LineNr"> 44 </span><span class="Comment">//:</span> +<span id="L45" class="LineNr"> 45 </span><span class="Comment">//: Between layers and domain-driven testing, programming starts to look like a</span> +<span id="L46" class="LineNr"> 46 </span><span class="Comment">//: fundamentally different activity. Instead of focusing on a) superficial,</span> +<span id="L47" class="LineNr"> 47 </span><span class="Comment">//: b) local rules on c) code [like say <a href="http://blog.bbv.ch/2013/06/05/clean-code-cheat-sheet],">http://blog.bbv.ch/2013/06/05/clean-code-cheat-sheet],</a></span> +<span id="L48" class="LineNr"> 48 </span><span class="Comment">//: we allow programmers to engage with the a) deep, b) global structure of</span> +<span id="L49" class="LineNr"> 49 </span><span class="Comment">//: the c) domain. If you can systematically track discontinuities in the</span> +<span id="L50" class="LineNr"> 50 </span><span class="Comment">//: domain, you don't care if the code used gotos as long as it passed all</span> +<span id="L51" class="LineNr"> 51 </span><span class="Comment">//: tests. If tests become more robust to run, it becomes easier to try out</span> +<span id="L52" class="LineNr"> 52 </span><span class="Comment">//: radically different implementations for the same program. If code is</span> +<span id="L53" class="LineNr"> 53 </span><span class="Comment">//: super-easy to rewrite, it becomes less important what indentation style it</span> +<span id="L54" class="LineNr"> 54 </span><span class="Comment">//: uses, or that the objects are appropriately encapsulated, or that the</span> +<span id="L55" class="LineNr"> 55 </span><span class="Comment">//: functions are referentially transparent.</span> +<span id="L56" class="LineNr"> 56 </span><span class="Comment">//:</span> +<span id="L57" class="LineNr"> 57 </span><span class="Comment">//: Instead of plumbing, programming becomes building and gradually refining a</span> +<span id="L58" class="LineNr"> 58 </span><span class="Comment">//: map of the environment the program must operate under. Whether a program</span> +<span id="L59" class="LineNr"> 59 </span><span class="Comment">//: is 'correct' at a given point in time is a red herring; what matters is</span> +<span id="L60" class="LineNr"> 60 </span><span class="Comment">//: avoiding regression by monotonically nailing down the more 'eventful'</span> +<span id="L61" class="LineNr"> 61 </span><span class="Comment">//: parts of the terrain. It helps readers new and old, and rewards curiosity,</span> +<span id="L62" class="LineNr"> 62 </span><span class="Comment">//: to organize large programs in self-similar hierarchies of example tests</span> +<span id="L63" class="LineNr"> 63 </span><span class="Comment">//: colocated with the code that makes them work.</span> +<span id="L64" class="LineNr"> 64 </span><span class="Comment">//:</span> +<span id="L65" class="LineNr"> 65 </span><span class="Comment">//: "Programming properly should be regarded as an activity by which</span> +<span id="L66" class="LineNr"> 66 </span><span class="Comment">//: programmers form a mental model, rather than as production of a program."</span> +<span id="L67" class="LineNr"> 67 </span><span class="Comment">//: -- Peter Naur (<a href="http://akkartik.name/naur.pdf)">http://akkartik.name/naur.pdf)</a></span> +<span id="L68" class="LineNr"> 68 </span> +<span id="L69" class="LineNr"> 69 </span><span class="Comment">//:: == Core data structures</span> +<span id="L70" class="LineNr"> 70 </span> +<span id="L71" class="LineNr"> 71 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L72" class="LineNr"> 72 </span>trace_stream* <a href='003trace.cc.html#L72'>Trace_stream</a> = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L73" class="LineNr"> 73 </span> +<span id="L74" class="LineNr"> 74 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L75" class="LineNr"> 75 </span><span class="Normal">struct</span> trace_stream <span class="Delimiter">{</span> +<span id="L76" class="LineNr"> 76 </span> vector<trace_line> <a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">;</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Comment">// End trace_stream Fields</span> +<span id="L78" class="LineNr"> 78 </span> +<span id="L79" class="LineNr"> 79 </span> trace_stream<span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Comment">// End trace_stream Constructor</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Delimiter">}</span> +<span id="L82" class="LineNr"> 82 </span> <a href='003trace.cc.html#L82'>~trace_stream</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Comment">// End trace_stream Destructor</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Delimiter">}</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Comment">// End trace_stream Methods</span> +<span id="L86" class="LineNr"> 86 </span><span class="Delimiter">};</span> +<span id="L87" class="LineNr"> 87 </span> +<span id="L88" class="LineNr"> 88 </span><span class="Comment">//:: == Adding to the trace</span> +<span id="L89" class="LineNr"> 89 </span> +<span id="L90" class="LineNr"> 90 </span><span class="Comment">//: Top-level method is trace() which can be used like an ostream. Usage:</span> +<span id="L91" class="LineNr"> 91 </span><span class="Comment">//: trace(depth, label) << ... << end();</span> +<span id="L92" class="LineNr"> 92 </span><span class="Comment">//: Don't forget the 'end()' to actually append to the trace.</span> +<span id="L93" class="LineNr"> 93 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L94" class="LineNr"> 94 </span><span class="Comment">// No brackets around the expansion so that it prints nothing if Trace_stream</span> +<span id="L95" class="LineNr"> 95 </span><span class="Comment">// isn't initialized.</span> +<span id="L96" class="LineNr"> 96 </span><span class="PreProc">#define trace(</span><span class="Delimiter">...</span><span class="PreProc">) !Trace_stream ? cerr : Trace_stream</span><span class="Delimiter">-></span><span class="PreProc">stream(</span><span class="Constant">__VA_ARGS__</span><span class="PreProc">)</span> +<span id="L97" class="LineNr"> 97 </span> +<span id="L98" class="LineNr"> 98 </span><span class="Delimiter">:(before "End trace_stream Fields")</span> +<span id="L99" class="LineNr"> 99 </span><span class="Comment">// accumulator for current trace_line</span> +<span id="L100" class="LineNr">100 </span>ostringstream* curr_stream<span class="Delimiter">;</span> +<span id="L101" class="LineNr">101 </span>string <a href='003trace.cc.html#L101'>curr_label</a><span class="Delimiter">;</span> +<span id="L102" class="LineNr">102 </span><span class="Normal">int</span> <a href='003trace.cc.html#L102'>curr_depth</a><span class="Delimiter">;</span> +<span id="L103" class="LineNr">103 </span><span class="Comment">// other stuff</span> +<span id="L104" class="LineNr">104 </span><span class="Normal">int</span> <a href='003trace.cc.html#L104'>collect_depth</a><span class="Delimiter">;</span> <span class="Comment">// avoid tracing lower levels for speed</span> +<span id="L105" class="LineNr">105 </span>ofstream <a href='003trace.cc.html#L105'>null_stream</a><span class="Delimiter">;</span> <span class="Comment">// never opened, so writes to it silently fail</span> +<span id="L106" class="LineNr">106 </span> +<span id="L107" class="LineNr">107 </span><span class="Comment">//: Some constants.</span> +<span id="L108" class="LineNr">108 </span><span class="Delimiter">:(before "struct trace_stream")</span> <span class="Comment">// include constants in all cleaved compilation units</span> +<span id="L109" class="LineNr">109 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='003trace.cc.html#L109'>Max_depth</a> = <span class="Constant">9999</span><span class="Delimiter">;</span> +<span id="L110" class="LineNr">110 </span><span class="Delimiter">:(before "End trace_stream Constructor")</span> +<span id="L111" class="LineNr">111 </span>curr_stream = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L112" class="LineNr">112 </span><a href='003trace.cc.html#L102'>curr_depth</a> = <a href='003trace.cc.html#L109'>Max_depth</a><span class="Delimiter">;</span> +<span id="L113" class="LineNr">113 </span><a href='003trace.cc.html#L104'>collect_depth</a> = <a href='003trace.cc.html#L109'>Max_depth</a><span class="Delimiter">;</span> +<span id="L114" class="LineNr">114 </span> +<span id="L115" class="LineNr">115 </span><span class="Delimiter">:(before "struct trace_stream")</span> +<span id="L116" class="LineNr">116 </span><span class="Normal">struct</span> trace_line <span class="Delimiter">{</span> +<span id="L117" class="LineNr">117 </span> string <a href='003trace.cc.html#L117'>contents</a><span class="Delimiter">;</span> +<span id="L118" class="LineNr">118 </span> string label<span class="Delimiter">;</span> +<span id="L119" class="LineNr">119 </span> <span class="Normal">int</span> <a href='003trace.cc.html#L119'>depth</a><span class="Delimiter">;</span> <span class="Comment">// 0 is 'sea level'; positive integers are progressively 'deeper' and lower level</span> +<span id="L120" class="LineNr">120 </span> trace_line<span class="Delimiter">(</span>string c<span class="Delimiter">,</span> string l<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L121" class="LineNr">121 </span> <a href='003trace.cc.html#L117'>contents</a> = c<span class="Delimiter">;</span> +<span id="L122" class="LineNr">122 </span> label = l<span class="Delimiter">;</span> +<span id="L123" class="LineNr">123 </span> <a href='003trace.cc.html#L119'>depth</a> = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L124" class="LineNr">124 </span> <span class="Delimiter">}</span> +<span id="L125" class="LineNr">125 </span> trace_line<span class="Delimiter">(</span>string c<span class="Delimiter">,</span> string l<span class="Delimiter">,</span> <span class="Normal">int</span> d<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L126" class="LineNr">126 </span> <a href='003trace.cc.html#L117'>contents</a> = c<span class="Delimiter">;</span> +<span id="L127" class="LineNr">127 </span> label = l<span class="Delimiter">;</span> +<span id="L128" class="LineNr">128 </span> <a href='003trace.cc.html#L119'>depth</a> = d<span class="Delimiter">;</span> +<span id="L129" class="LineNr">129 </span> <span class="Delimiter">}</span> +<span id="L130" class="LineNr">130 </span><span class="Delimiter">};</span> +<span id="L131" class="LineNr">131 </span> +<span id="L132" class="LineNr">132 </span>string <a href='003trace.cc.html#L132'>unescape_newline</a><span class="Delimiter">(</span>string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L133" class="LineNr">133 </span> std::stringstream ss<span class="Delimiter">;</span> +<span id="L134" class="LineNr">134 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L135" class="LineNr">135 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> +<span id="L136" class="LineNr">136 </span> ss << <span class="Constant">"</span><span class="cSpecial">\\</span><span class="Constant">n"</span><span class="Delimiter">;</span> +<span id="L137" class="LineNr">137 </span> <span class="Normal">else</span> +<span id="L138" class="LineNr">138 </span> ss << s<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L139" class="LineNr">139 </span> <span class="Delimiter">}</span> +<span id="L140" class="LineNr">140 </span> <span class="Identifier">return</span> ss<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L141" class="LineNr">141 </span><span class="Delimiter">}</span> +<span id="L142" class="LineNr">142 </span> +<span id="L143" class="LineNr">143 </span><span class="Normal">void</span> <a href='003trace.cc.html#L143'>dump_trace_line</a><span class="Delimiter">(</span>ostream& s<span class="Delimiter">,</span> trace_line& t<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L144" class="LineNr">144 </span> s << std::setw<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">)</span> << t<span class="Delimiter">.</span><a href='003trace.cc.html#L119'>depth</a> << <span class="Constant">' '</span> << t<span class="Delimiter">.</span>label << <span class="Constant">": "</span> << <a href='003trace.cc.html#L132'>unescape_newline</a><span class="Delimiter">(</span>t<span class="Delimiter">.</span><a href='003trace.cc.html#L117'>contents</a><span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L145" class="LineNr">145 </span><span class="Delimiter">}</span> +<span id="L146" class="LineNr">146 </span> +<span id="L147" class="LineNr">147 </span><span class="Comment">//: Starting a new trace line.</span> +<span id="L148" class="LineNr">148 </span><span class="Delimiter">:(before "End trace_stream Methods")</span> +<span id="L149" class="LineNr">149 </span>ostream& stream<span class="Delimiter">(</span>string label<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L150" class="LineNr">150 </span> <span class="Identifier">return</span> stream<span class="Delimiter">(</span><a href='003trace.cc.html#L109'>Max_depth</a><span class="Delimiter">,</span> label<span class="Delimiter">);</span> +<span id="L151" class="LineNr">151 </span><span class="Delimiter">}</span> +<span id="L152" class="LineNr">152 </span> +<span id="L153" class="LineNr">153 </span>ostream& stream<span class="Delimiter">(</span><span class="Normal">int</span> <a href='003trace.cc.html#L119'>depth</a><span class="Delimiter">,</span> string label<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L154" class="LineNr">154 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L119'>depth</a> > <a href='003trace.cc.html#L104'>collect_depth</a><span class="Delimiter">)</span> <span class="Identifier">return</span> <a href='003trace.cc.html#L105'>null_stream</a><span class="Delimiter">;</span> +<span id="L155" class="LineNr">155 </span> curr_stream = <span class="Normal">new</span> ostringstream<span class="Delimiter">;</span> +<span id="L156" class="LineNr">156 </span> <a href='003trace.cc.html#L101'>curr_label</a> = label<span class="Delimiter">;</span> +<span id="L157" class="LineNr">157 </span> <a href='003trace.cc.html#L102'>curr_depth</a> = <a href='003trace.cc.html#L119'>depth</a><span class="Delimiter">;</span> +<span id="L158" class="LineNr">158 </span> <span class="Delimiter">(</span>*curr_stream<span class="Delimiter">)</span> << std::hex<span class="Delimiter">;</span> <span class="Comment">// printing addresses is the common case</span> +<span id="L159" class="LineNr">159 </span> <span class="Identifier">return</span> *curr_stream<span class="Delimiter">;</span> +<span id="L160" class="LineNr">160 </span><span class="Delimiter">}</span> +<span id="L161" class="LineNr">161 </span> +<span id="L162" class="LineNr">162 </span><span class="Comment">//: End of a trace line; append it to the trace.</span> +<span id="L163" class="LineNr">163 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L164" class="LineNr">164 </span><span class="Normal">struct</span> end <span class="Delimiter">{};</span> +<span id="L165" class="LineNr">165 </span><span class="Delimiter">:(code)</span> +<span id="L166" class="LineNr">166 </span>ostream& <span class="Normal">operator</span><<<span class="Delimiter">(</span>ostream& os<span class="Delimiter">,</span> end <span class="Comment">/*</span><span class="Comment">unused</span><span class="Comment">*/</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L167" class="LineNr">167 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">)</span> <a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L183'>newline</a><span class="Delimiter">();</span> +<span id="L168" class="LineNr">168 </span> <span class="Identifier">return</span> os<span class="Delimiter">;</span> +<span id="L169" class="LineNr">169 </span><span class="Delimiter">}</span> +<span id="L170" class="LineNr">170 </span> +<span id="L171" class="LineNr">171 </span><span class="Comment">//: Fatal error.</span> +<span id="L172" class="LineNr">172 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L173" class="LineNr">173 </span><span class="Normal">struct</span> <a href='003trace.cc.html#L173'>die</a> <span class="Delimiter">{};</span> +<span id="L174" class="LineNr">174 </span><span class="Delimiter">:(code)</span> +<span id="L175" class="LineNr">175 </span>ostream& <span class="Normal">operator</span><<<span class="Delimiter">(</span>ostream& <span class="Comment">/*</span><span class="Comment">unused</span><span class="Comment">*/</span><span class="Delimiter">,</span> <a href='003trace.cc.html#L173'>die</a> <span class="Comment">/*</span><span class="Comment">unused</span><span class="Comment">*/</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L176" class="LineNr">176 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">)</span> <a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L183'>newline</a><span class="Delimiter">();</span> +<span id="L177" class="LineNr">177 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L178" class="LineNr">178 </span><span class="Delimiter">}</span> +<span id="L179" class="LineNr">179 </span> +<span id="L180" class="LineNr">180 </span><span class="Delimiter">:(before "End trace_stream Methods")</span> +<span id="L181" class="LineNr">181 </span><span class="Normal">void</span> <a href='003trace.cc.html#L183'>newline</a><span class="Delimiter">();</span> +<span id="L182" class="LineNr">182 </span><span class="Delimiter">:(code)</span> +<span id="L183" class="LineNr">183 </span><span class="Normal">void</span> trace_stream::<a href='003trace.cc.html#L183'>newline</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L184" class="LineNr">184 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!curr_stream<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L185" class="LineNr">185 </span> string curr_contents = curr_stream<span class="Delimiter">-></span>str<span class="Delimiter">();</span> +<span id="L186" class="LineNr">186 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!curr_contents<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L187" class="LineNr">187 </span> <a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>trace_line<span class="Delimiter">(</span>curr_contents<span class="Delimiter">,</span> <a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><a href='003trace.cc.html#L101'>curr_label</a><span class="Delimiter">),</span> <a href='003trace.cc.html#L102'>curr_depth</a><span class="Delimiter">));</span> <span class="Comment">// preserve indent in contents</span> +<span id="L188" class="LineNr">188 </span> <span class="Comment">// maybe print this line to stderr</span> +<span id="L189" class="LineNr">189 </span> trace_line& t = <a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>back<span class="Delimiter">();</span> +<span id="L190" class="LineNr">190 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L243'>should_incrementally_print_trace</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L191" class="LineNr">191 </span> <a href='003trace.cc.html#L143'>dump_trace_line</a><span class="Delimiter">(</span>cerr<span class="Delimiter">,</span> t<span class="Delimiter">);</span> +<span id="L192" class="LineNr">192 </span> <span class="Delimiter">}</span> +<span id="L193" class="LineNr">193 </span> <span class="Comment">// End trace Commit</span> +<span id="L194" class="LineNr">194 </span> <span class="Delimiter">}</span> +<span id="L195" class="LineNr">195 </span> +<span id="L196" class="LineNr">196 </span> <span class="Comment">// clean up</span> +<span id="L197" class="LineNr">197 </span> <span class="Normal">delete</span> curr_stream<span class="Delimiter">;</span> +<span id="L198" class="LineNr">198 </span> curr_stream = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L199" class="LineNr">199 </span> <a href='003trace.cc.html#L101'>curr_label</a><span class="Delimiter">.</span>clear<span class="Delimiter">();</span> +<span id="L200" class="LineNr">200 </span> <a href='003trace.cc.html#L102'>curr_depth</a> = <a href='003trace.cc.html#L109'>Max_depth</a><span class="Delimiter">;</span> +<span id="L201" class="LineNr">201 </span><span class="Delimiter">}</span> +<span id="L202" class="LineNr">202 </span> +<span id="L203" class="LineNr">203 </span><span class="Comment">//:: == Initializing the trace in tests</span> +<span id="L204" class="LineNr">204 </span> +<span id="L205" class="LineNr">205 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L206" class="LineNr">206 </span><span class="PreProc">#define START_TRACING_UNTIL_END_OF_SCOPE lease_tracer leased_tracer</span><span class="Delimiter">;</span> +<span id="L207" class="LineNr">207 </span><span class="Delimiter">:(before "End Test Setup")</span> +<span id="L208" class="LineNr">208 </span><a href='003trace.cc.html#L206'>START_TRACING_UNTIL_END_OF_SCOPE</a> +<span id="L209" class="LineNr">209 </span> +<span id="L210" class="LineNr">210 </span><span class="Comment">//: Trace_stream is a resource, lease_tracer uses RAII to manage it.</span> +<span id="L211" class="LineNr">211 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L212" class="LineNr">212 </span><span class="Normal">struct</span> lease_tracer <span class="Delimiter">{</span> +<span id="L213" class="LineNr">213 </span> lease_tracer<span class="Delimiter">();</span> +<span id="L214" class="LineNr">214 </span> <a href='003trace.cc.html#L218'>~lease_tracer</a><span class="Delimiter">();</span> +<span id="L215" class="LineNr">215 </span><span class="Delimiter">};</span> +<span id="L216" class="LineNr">216 </span><span class="Delimiter">:(code)</span> +<span id="L217" class="LineNr">217 </span>lease_tracer::lease_tracer<span class="Delimiter">()</span> <span class="Delimiter">{</span> <a href='003trace.cc.html#L72'>Trace_stream</a> = <span class="Normal">new</span> trace_stream<span class="Delimiter">;</span> <span class="Delimiter">}</span> +<span id="L218" class="LineNr">218 </span>lease_tracer::<a href='003trace.cc.html#L218'>~lease_tracer</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L219" class="LineNr">219 </span> <span class="Normal">delete</span> <a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">;</span> +<span id="L220" class="LineNr">220 </span> <a href='003trace.cc.html#L72'>Trace_stream</a> = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L221" class="LineNr">221 </span><span class="Delimiter">}</span> +<span id="L222" class="LineNr">222 </span> +<span id="L223" class="LineNr">223 </span><span class="Comment">//:: == Errors and warnings using traces</span> +<span id="L224" class="LineNr">224 </span> +<span id="L225" class="LineNr">225 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L226" class="LineNr">226 </span><span class="PreProc">#define raise (!Trace_stream ? (++Trace_errors</span><span class="Delimiter">,</span><span class="PreProc">cerr) </span><span class="Comment">/*</span><span class="Comment">do print</span><span class="Comment">*/</span><span class="PreProc"> : Trace_stream</span><span class="Delimiter">-></span><span class="PreProc">stream(Error_depth</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Constant">"error"</span><span class="PreProc">))</span> +<span id="L227" class="LineNr">227 </span><span class="PreProc">#define warn (!Trace_stream ? (++Trace_errors</span><span class="Delimiter">,</span><span class="PreProc">cerr) </span><span class="Comment">/*</span><span class="Comment">do print</span><span class="Comment">*/</span><span class="PreProc"> : Trace_stream</span><span class="Delimiter">-></span><span class="PreProc">stream(Warn_depth</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Constant">"warn"</span><span class="PreProc">))</span> +<span id="L228" class="LineNr">228 </span> +<span id="L229" class="LineNr">229 </span><span class="Comment">//: Print errors and warnings to the screen by default.</span> +<span id="L230" class="LineNr">230 </span><span class="Delimiter">:(before "struct trace_stream")</span> <span class="Comment">// include constants in all cleaved compilation units</span> +<span id="L231" class="LineNr">231 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='003trace.cc.html#L231'>Error_depth</a> = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L232" class="LineNr">232 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='003trace.cc.html#L232'>Warn_depth</a> = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L233" class="LineNr">233 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L234" class="LineNr">234 </span><span class="Normal">int</span> Hide_errors = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// if set, don't print errors or warnings to screen</span> +<span id="L235" class="LineNr">235 </span><span class="Normal">int</span> Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// if set, don't print warnings to screen</span> +<span id="L236" class="LineNr">236 </span><span class="Delimiter">:(before "End Reset")</span> +<span id="L237" class="LineNr">237 </span>Hide_errors = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L238" class="LineNr">238 </span>Hide_warnings = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L239" class="LineNr">239 </span><span class="Comment">//: Never dump warnings in tests</span> +<span id="L240" class="LineNr">240 </span><span class="Delimiter">:(before "End Test Setup")</span> +<span id="L241" class="LineNr">241 </span>Hide_warnings = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L242" class="LineNr">242 </span><span class="Delimiter">:(code)</span> +<span id="L243" class="LineNr">243 </span><span class="Normal">bool</span> trace_stream::<a href='003trace.cc.html#L243'>should_incrementally_print_trace</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L244" class="LineNr">244 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Hide_errors && <a href='003trace.cc.html#L102'>curr_depth</a> == <a href='003trace.cc.html#L231'>Error_depth</a><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L245" class="LineNr">245 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Hide_warnings && !Hide_errors && <a href='003trace.cc.html#L102'>curr_depth</a> == <a href='003trace.cc.html#L232'>Warn_depth</a><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L246" class="LineNr">246 </span> <span class="Comment">// End Incremental Trace Print Conditions</span> +<span id="L247" class="LineNr">247 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L248" class="LineNr">248 </span><span class="Delimiter">}</span> +<span id="L249" class="LineNr">249 </span><span class="Delimiter">:(before "End trace_stream Methods")</span> +<span id="L250" class="LineNr">250 </span><span class="Normal">bool</span> <a href='003trace.cc.html#L243'>should_incrementally_print_trace</a><span class="Delimiter">();</span> +<span id="L251" class="LineNr">251 </span> +<span id="L252" class="LineNr">252 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L253" class="LineNr">253 </span><span class="Normal">int</span> <a href='003trace.cc.html#L253'>Trace_errors</a> = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// used only when Trace_stream is NULL</span> +<span id="L254" class="LineNr">254 </span> +<span id="L255" class="LineNr">255 </span><span class="Comment">// Fail tests that displayed (unexpected) errors.</span> +<span id="L256" class="LineNr">256 </span><span class="Comment">// Expected errors should always be hidden and silently checked for.</span> +<span id="L257" class="LineNr">257 </span><span class="Delimiter">:(before "End Test Teardown")</span> +<span id="L258" class="LineNr">258 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L21'>Passed</a> && !Hide_errors && <a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L259" class="LineNr">259 </span> <a href='002test.cc.html#L21'>Passed</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L260" class="LineNr">260 </span><span class="Delimiter">}</span> +<span id="L261" class="LineNr">261 </span><span class="Delimiter">:(code)</span> +<span id="L262" class="LineNr">262 </span><span class="Normal">bool</span> <a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L263" class="LineNr">263 </span> <span class="Identifier">return</span> <a href='003trace.cc.html#L253'>Trace_errors</a> > <span class="Constant">0</span> || trace_count<span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">)</span> > <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L264" class="LineNr">264 </span><span class="Delimiter">}</span> +<span id="L265" class="LineNr">265 </span> +<span id="L266" class="LineNr">266 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L267" class="LineNr">267 </span><span class="Comment">// If we aren't yet sure how to deal with some corner case, use assert_for_now</span> +<span id="L268" class="LineNr">268 </span><span class="Comment">// to indicate that it isn't an inviolable invariant.</span> +<span id="L269" class="LineNr">269 </span><span class="PreProc">#define assert_for_now assert</span> +<span id="L270" class="LineNr">270 </span><span class="PreProc">#define raise_for_now raise</span> +<span id="L271" class="LineNr">271 </span> +<span id="L272" class="LineNr">272 </span><span class="Comment">//:: == Other assertions on traces</span> +<span id="L273" class="LineNr">273 </span><span class="Comment">//: Primitives:</span> +<span id="L274" class="LineNr">274 </span><span class="Comment">//: - CHECK_TRACE_CONTENTS(lines)</span> +<span id="L275" class="LineNr">275 </span><span class="Comment">//: Assert that the trace contains the given lines (separated by newlines)</span> +<span id="L276" class="LineNr">276 </span><span class="Comment">//: in order. There can be other intervening lines between them.</span> +<span id="L277" class="LineNr">277 </span><span class="Comment">//: - CHECK_TRACE_DOESNT_CONTAIN(line)</span> +<span id="L278" class="LineNr">278 </span><span class="Comment">//: - CHECK_TRACE_DOESNT_CONTAIN(label, contents)</span> +<span id="L279" class="LineNr">279 </span><span class="Comment">//: Assert that the trace doesn't contain the given (single) line.</span> +<span id="L280" class="LineNr">280 </span><span class="Comment">//: - CHECK_TRACE_COUNT(label, count)</span> +<span id="L281" class="LineNr">281 </span><span class="Comment">//: Assert that the trace contains exactly 'count' lines with the given</span> +<span id="L282" class="LineNr">282 </span><span class="Comment">//: 'label'.</span> +<span id="L283" class="LineNr">283 </span><span class="Comment">//: - CHECK_TRACE_CONTAINS_ERRORS()</span> +<span id="L284" class="LineNr">284 </span><span class="Comment">//: - CHECK_TRACE_DOESNT_CONTAIN_ERRORS()</span> +<span id="L285" class="LineNr">285 </span><span class="Comment">//: - trace_count_prefix(label, prefix)</span> +<span id="L286" class="LineNr">286 </span><span class="Comment">//: Count the number of trace lines with the given 'label' that start with</span> +<span id="L287" class="LineNr">287 </span><span class="Comment">//: the given 'prefix'.</span> +<span id="L288" class="LineNr">288 </span> +<span id="L289" class="LineNr">289 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L290" class="LineNr">290 </span><span class="PreProc">#define CHECK_TRACE_CONTENTS(</span><span class="Delimiter">...</span><span class="PreProc">) check_trace_contents(__FUNCTION__</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Constant">__FILE__</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Constant">__LINE__</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Constant">__VA_ARGS__</span><span class="PreProc">)</span> +<span id="L291" class="LineNr">291 </span> +<span id="L292" class="LineNr">292 </span><span class="PreProc">#define CHECK_TRACE_DOESNT_CONTAIN(</span><span class="Delimiter">...</span><span class="PreProc">) CHECK(trace_doesnt_contain(</span><span class="Constant">__VA_ARGS__</span><span class="PreProc">))</span> +<span id="L293" class="LineNr">293 </span> +<span id="L294" class="LineNr">294 </span><span class="PreProc">#define CHECK_TRACE_COUNT(label</span><span class="Delimiter">,</span><span class="PreProc"> count) \</span> +<span id="L295" class="LineNr">295 </span><span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (<a href='002test.cc.html#L21'>Passed</a> && trace_count(label) != (count)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> +<span id="L296" class="LineNr">296 </span><span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): trace_count of "</span><span class="PreProc"> << label << </span><span class="Constant">" should be "</span><span class="PreProc"> << count << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L297" class="LineNr">297 </span><span class="PreProc"> cerr << </span><span class="Constant">" got "</span><span class="PreProc"> << trace_count(label) << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> multiple eval </span><span class="Comment">*/</span><span class="PreProc"> \</span> +<span id="L298" class="LineNr">298 </span><span class="PreProc"> <a href='003trace.cc.html#L435'>DUMP</a>(label)</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L299" class="LineNr">299 </span><span class="PreProc"> <a href='002test.cc.html#L21'>Passed</a> = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L300" class="LineNr">300 </span><span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> +<span id="L301" class="LineNr">301 </span><span class="PreProc"> </span><span class="Delimiter">}</span> +<span id="L302" class="LineNr">302 </span> +<span id="L303" class="LineNr">303 </span><span class="PreProc">#define CHECK_TRACE_CONTAINS_ERRORS() CHECK(trace_contains_errors())</span> +<span id="L304" class="LineNr">304 </span><span class="PreProc">#define CHECK_TRACE_DOESNT_CONTAIN_ERRORS() \</span> +<span id="L305" class="LineNr">305 </span><span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (<a href='002test.cc.html#L21'>Passed</a> && <a href='003trace.cc.html#L262'>trace_contains_errors</a>()) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> +<span id="L306" class="LineNr">306 </span><span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): unexpected errors</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L307" class="LineNr">307 </span><span class="PreProc"> <a href='003trace.cc.html#L435'>DUMP</a>(</span><span class="Constant">"error"</span><span class="PreProc">)</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L308" class="LineNr">308 </span><span class="PreProc"> <a href='002test.cc.html#L21'>Passed</a> = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L309" class="LineNr">309 </span><span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L310" class="LineNr">310 </span><span class="PreProc"> </span><span class="Delimiter">}</span> +<span id="L311" class="LineNr">311 </span> +<span id="L312" class="LineNr">312 </span><span class="Comment">// Allow tests to ignore trace lines generated during setup.</span> +<span id="L313" class="LineNr">313 </span><span class="PreProc">#define CLEAR_TRACE </span><span class="Normal">delete</span><span class="PreProc"> Trace_stream</span><span class="Delimiter">,</span><span class="PreProc"> Trace_stream = </span><span class="Normal">new</span><span class="PreProc"> trace_stream</span> +<span id="L314" class="LineNr">314 </span> +<span id="L315" class="LineNr">315 </span><span class="Delimiter">:(code)</span> +<span id="L316" class="LineNr">316 </span><span class="Normal">bool</span> <a href='003trace.cc.html#L316'>check_trace_contents</a><span class="Delimiter">(</span>string FUNCTION<span class="Delimiter">,</span> string <span class="Normal">FILE</span><span class="Delimiter">,</span> <span class="Normal">int</span> LINE<span class="Delimiter">,</span> string expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L317" class="LineNr">317 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L318" class="LineNr">318 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L319" class="LineNr">319 </span> vector<string> expected_lines = <a href='003trace.cc.html#L407'>split</a><span class="Delimiter">(</span>expected<span class="Delimiter">,</span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">);</span> +<span id="L320" class="LineNr">320 </span> <span class="Normal">int</span> curr_expected_line = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L321" class="LineNr">321 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>curr_expected_line < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>expected_lines<span class="Delimiter">)</span> && expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>empty<span class="Delimiter">())</span> +<span id="L322" class="LineNr">322 </span> ++curr_expected_line<span class="Delimiter">;</span> +<span id="L323" class="LineNr">323 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr_expected_line == <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>expected_lines<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L324" class="LineNr">324 </span> string label<span class="Delimiter">,</span> <a href='003trace.cc.html#L117'>contents</a><span class="Delimiter">;</span> +<span id="L325" class="LineNr">325 </span> <a href='003trace.cc.html#L386'>split_label_contents</a><span class="Delimiter">(</span>expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">),</span> &label<span class="Delimiter">,</span> &contents<span class="Delimiter">);</span> +<span id="L326" class="LineNr">326 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L327" class="LineNr">327 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>label != p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L328" class="LineNr">328 </span> string t = <a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span>p<span class="Delimiter">-></span><a href='003trace.cc.html#L117'>contents</a><span class="Delimiter">);</span> +<span id="L329" class="LineNr">329 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L117'>contents</a> != <a href='003trace.cc.html#L132'>unescape_newline</a><span class="Delimiter">(</span>t<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L330" class="LineNr">330 </span> ++curr_expected_line<span class="Delimiter">;</span> +<span id="L331" class="LineNr">331 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>curr_expected_line < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>expected_lines<span class="Delimiter">)</span> && expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>empty<span class="Delimiter">())</span> +<span id="L332" class="LineNr">332 </span> ++curr_expected_line<span class="Delimiter">;</span> +<span id="L333" class="LineNr">333 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr_expected_line == <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>expected_lines<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L334" class="LineNr">334 </span> <a href='003trace.cc.html#L386'>split_label_contents</a><span class="Delimiter">(</span>expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">),</span> &label<span class="Delimiter">,</span> &contents<span class="Delimiter">);</span> +<span id="L335" class="LineNr">335 </span> <span class="Delimiter">}</span> +<span id="L336" class="LineNr">336 </span> +<span id="L337" class="LineNr">337 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L399'>line_exists_anywhere</a><span class="Delimiter">(</span>label<span class="Delimiter">,</span> <a href='003trace.cc.html#L117'>contents</a><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L338" class="LineNr">338 </span> cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << FUNCTION << <span class="Constant">"("</span> << <span class="Normal">FILE</span> << <span class="Constant">":"</span> << LINE << <span class="Constant">"): <a href='011run.cc.html#L121'>line</a> ["</span> << label << <span class="Constant">": "</span> << <a href='003trace.cc.html#L117'>contents</a> << <span class="Constant">"] out of order in <a href='003trace.cc.html#L96'>trace</a>:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L339" class="LineNr">339 </span> <a href='003trace.cc.html#L435'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L340" class="LineNr">340 </span> <span class="Delimiter">}</span> +<span id="L341" class="LineNr">341 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L342" class="LineNr">342 </span> cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << FUNCTION << <span class="Constant">"("</span> << <span class="Normal">FILE</span> << <span class="Constant">":"</span> << LINE << <span class="Constant">"): missing ["</span> << <a href='003trace.cc.html#L117'>contents</a> << <span class="Constant">"] in <a href='003trace.cc.html#L96'>trace</a>:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L343" class="LineNr">343 </span> <a href='003trace.cc.html#L435'>DUMP</a><span class="Delimiter">(</span>label<span class="Delimiter">);</span> +<span id="L344" class="LineNr">344 </span> <span class="Delimiter">}</span> +<span id="L345" class="LineNr">345 </span> <a href='002test.cc.html#L21'>Passed</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L346" class="LineNr">346 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L347" class="LineNr">347 </span><span class="Delimiter">}</span> +<span id="L348" class="LineNr">348 </span> +<span id="L349" class="LineNr">349 </span><span class="Normal">bool</span> <a href='003trace.cc.html#L349'>trace_doesnt_contain</a><span class="Delimiter">(</span>string expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L350" class="LineNr">350 </span> vector<string> tmp = <a href='003trace.cc.html#L422'>split_first</a><span class="Delimiter">(</span>expected<span class="Delimiter">,</span> <span class="Constant">": "</span><span class="Delimiter">);</span> +<span id="L351" class="LineNr">351 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>tmp<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L352" class="LineNr">352 </span> <a href='003trace.cc.html#L226'>raise</a> << expected << <span class="Constant">": missing label or <a href='003trace.cc.html#L117'>contents</a> in <a href='003trace.cc.html#L96'>trace</a> <a href='011run.cc.html#L121'>line</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L353" class="LineNr">353 </span> assert<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span> +<span id="L354" class="LineNr">354 </span> <span class="Delimiter">}</span> +<span id="L355" class="LineNr">355 </span> <span class="Identifier">return</span> trace_count<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> tmp<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">))</span> == <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L356" class="LineNr">356 </span><span class="Delimiter">}</span> +<span id="L357" class="LineNr">357 </span> +<span id="L358" class="LineNr">358 </span><span class="Normal">int</span> trace_count<span class="Delimiter">(</span>string label<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L359" class="LineNr">359 </span> <span class="Identifier">return</span> trace_count<span class="Delimiter">(</span>label<span class="Delimiter">,</span> <span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L360" class="LineNr">360 </span><span class="Delimiter">}</span> +<span id="L361" class="LineNr">361 </span> +<span id="L362" class="LineNr">362 </span><span class="Normal">int</span> trace_count<span class="Delimiter">(</span>string label<span class="Delimiter">,</span> string <a href='011run.cc.html#L121'>line</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L363" class="LineNr">363 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L364" class="LineNr">364 </span> <span class="Normal">long</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L365" class="LineNr">365 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L366" class="LineNr">366 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>label == p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L367" class="LineNr">367 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='011run.cc.html#L121'>line</a> == <span class="Constant">""</span> || <a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><a href='011run.cc.html#L121'>line</a><span class="Delimiter">)</span> == <a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span>p<span class="Delimiter">-></span><a href='003trace.cc.html#L117'>contents</a><span class="Delimiter">))</span> +<span id="L368" class="LineNr">368 </span> ++result<span class="Delimiter">;</span> +<span id="L369" class="LineNr">369 </span> <span class="Delimiter">}</span> +<span id="L370" class="LineNr">370 </span> <span class="Delimiter">}</span> +<span id="L371" class="LineNr">371 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L372" class="LineNr">372 </span><span class="Delimiter">}</span> +<span id="L373" class="LineNr">373 </span> +<span id="L374" class="LineNr">374 </span><span class="Normal">int</span> <a href='003trace.cc.html#L374'>trace_count_prefix</a><span class="Delimiter">(</span>string label<span class="Delimiter">,</span> string prefix<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L375" class="LineNr">375 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L376" class="LineNr">376 </span> <span class="Normal">long</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L377" class="LineNr">377 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L378" class="LineNr">378 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>label == p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L379" class="LineNr">379 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L104'>starts_with</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span>p<span class="Delimiter">-></span><a href='003trace.cc.html#L117'>contents</a><span class="Delimiter">),</span> <a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span>prefix<span class="Delimiter">)))</span> +<span id="L380" class="LineNr">380 </span> ++result<span class="Delimiter">;</span> +<span id="L381" class="LineNr">381 </span> <span class="Delimiter">}</span> +<span id="L382" class="LineNr">382 </span> <span class="Delimiter">}</span> +<span id="L383" class="LineNr">383 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L384" class="LineNr">384 </span><span class="Delimiter">}</span> +<span id="L385" class="LineNr">385 </span> +<span id="L386" class="LineNr">386 </span><span class="Normal">void</span> <a href='003trace.cc.html#L386'>split_label_contents</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">,</span> string* label<span class="Delimiter">,</span> string* <a href='003trace.cc.html#L117'>contents</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L387" class="LineNr">387 </span> <span class="Normal">static</span> <span class="Normal">const</span> string delim<span class="Delimiter">(</span><span class="Constant">": "</span><span class="Delimiter">);</span> +<span id="L388" class="LineNr">388 </span> <span class="Normal">size_t</span> pos = s<span class="Delimiter">.</span>find<span class="Delimiter">(</span>delim<span class="Delimiter">);</span> +<span id="L389" class="LineNr">389 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>pos == string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L390" class="LineNr">390 </span> *label = <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L391" class="LineNr">391 </span> *contents = <a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span>s<span class="Delimiter">);</span> +<span id="L392" class="LineNr">392 </span> <span class="Delimiter">}</span> +<span id="L393" class="LineNr">393 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L394" class="LineNr">394 </span> *label = <a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> pos<span class="Delimiter">));</span> +<span id="L395" class="LineNr">395 </span> *contents = <a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span>pos+SIZE<span class="Delimiter">(</span>delim<span class="Delimiter">)));</span> +<span id="L396" class="LineNr">396 </span> <span class="Delimiter">}</span> +<span id="L397" class="LineNr">397 </span><span class="Delimiter">}</span> +<span id="L398" class="LineNr">398 </span> +<span id="L399" class="LineNr">399 </span><span class="Normal">bool</span> <a href='003trace.cc.html#L399'>line_exists_anywhere</a><span class="Delimiter">(</span><span class="Normal">const</span> string& label<span class="Delimiter">,</span> <span class="Normal">const</span> string& <a href='003trace.cc.html#L117'>contents</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L400" class="LineNr">400 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='003trace.cc.html#L72'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L401" class="LineNr">401 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>label != p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L402" class="LineNr">402 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L117'>contents</a> == <a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span>p<span class="Delimiter">-></span><a href='003trace.cc.html#L117'>contents</a><span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L403" class="LineNr">403 </span> <span class="Delimiter">}</span> +<span id="L404" class="LineNr">404 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L405" class="LineNr">405 </span><span class="Delimiter">}</span> +<span id="L406" class="LineNr">406 </span> +<span id="L407" class="LineNr">407 </span>vector<string> <a href='003trace.cc.html#L407'>split</a><span class="Delimiter">(</span>string s<span class="Delimiter">,</span> string delim<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L408" class="LineNr">408 </span> vector<string> result<span class="Delimiter">;</span> +<span id="L409" class="LineNr">409 </span> <span class="Normal">size_t</span> begin=<span class="Constant">0</span><span class="Delimiter">,</span> end=s<span class="Delimiter">.</span>find<span class="Delimiter">(</span>delim<span class="Delimiter">);</span> +<span id="L410" class="LineNr">410 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L411" class="LineNr">411 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>end == string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L412" class="LineNr">412 </span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>string<span class="Delimiter">(</span>s<span class="Delimiter">,</span> begin<span class="Delimiter">,</span> string::npos<span class="Delimiter">));</span> +<span id="L413" class="LineNr">413 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L414" class="LineNr">414 </span> <span class="Delimiter">}</span> +<span id="L415" class="LineNr">415 </span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>string<span class="Delimiter">(</span>s<span class="Delimiter">,</span> begin<span class="Delimiter">,</span> end-begin<span class="Delimiter">));</span> +<span id="L416" class="LineNr">416 </span> begin = end+SIZE<span class="Delimiter">(</span>delim<span class="Delimiter">);</span> +<span id="L417" class="LineNr">417 </span> end = s<span class="Delimiter">.</span>find<span class="Delimiter">(</span>delim<span class="Delimiter">,</span> begin<span class="Delimiter">);</span> +<span id="L418" class="LineNr">418 </span> <span class="Delimiter">}</span> +<span id="L419" class="LineNr">419 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L420" class="LineNr">420 </span><span class="Delimiter">}</span> +<span id="L421" class="LineNr">421 </span> +<span id="L422" class="LineNr">422 </span>vector<string> <a href='003trace.cc.html#L422'>split_first</a><span class="Delimiter">(</span>string s<span class="Delimiter">,</span> string delim<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L423" class="LineNr">423 </span> vector<string> result<span class="Delimiter">;</span> +<span id="L424" class="LineNr">424 </span> <span class="Normal">size_t</span> end=s<span class="Delimiter">.</span>find<span class="Delimiter">(</span>delim<span class="Delimiter">);</span> +<span id="L425" class="LineNr">425 </span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>string<span class="Delimiter">(</span>s<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">,</span> end<span class="Delimiter">));</span> +<span id="L426" class="LineNr">426 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>end != string::npos<span class="Delimiter">)</span> +<span id="L427" class="LineNr">427 </span> result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>string<span class="Delimiter">(</span>s<span class="Delimiter">,</span> end+SIZE<span class="Delimiter">(</span>delim<span class="Delimiter">),</span> string::npos<span class="Delimiter">));</span> +<span id="L428" class="LineNr">428 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L429" class="LineNr">429 </span><span class="Delimiter">}</span> +<span id="L430" class="LineNr">430 </span> +<span id="L431" class="LineNr">431 </span><span class="Comment">//:: == Helpers for debugging using traces</span> +<span id="L432" class="LineNr">432 </span> +<span id="L433" class="LineNr">433 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L434" class="LineNr">434 </span><span class="Comment">// To debug why a test is failing, dump its trace using '?'.</span> +<span id="L435" class="LineNr">435 </span><span class="PreProc">#define DUMP(label) </span><span class="Normal">if</span><span class="PreProc"> (Trace_stream) cerr << Trace_stream</span><span class="Delimiter">-></span><span class="PreProc">readable_contents(label)</span><span class="Delimiter">;</span> +<span id="L436" class="LineNr">436 </span> +<span id="L437" class="LineNr">437 </span><span class="Comment">// To add temporary prints to the trace, use 'dbg'.</span> +<span id="L438" class="LineNr">438 </span><span class="Comment">// `git log` should never show any calls to 'dbg'.</span> +<span id="L439" class="LineNr">439 </span><span class="PreProc">#define dbg trace(</span><span class="Constant">0</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Constant">"a"</span><span class="PreProc">)</span> +<span id="L440" class="LineNr">440 </span> +<span id="L441" class="LineNr">441 </span><span class="Comment">//: Dump the entire trace to file where it can be browsed offline.</span> +<span id="L442" class="LineNr">442 </span><span class="Comment">//: Dump the trace as it happens; that way you get something even if the</span> +<span id="L443" class="LineNr">443 </span><span class="Comment">//: program crashes.</span> +<span id="L444" class="LineNr">444 </span> +<span id="L445" class="LineNr">445 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L446" class="LineNr">446 </span>ofstream <a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">;</span> +<span id="L447" class="LineNr">447 </span><span class="Delimiter">:(before "End Commandline Options(*arg)")</span> +<span id="L448" class="LineNr">448 </span><span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L98'>is_equal</a><span class="Delimiter">(</span>*arg<span class="Delimiter">,</span> <span class="Constant">"--trace"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L449" class="LineNr">449 </span> cerr << <span class="Constant">"saving <a href='003trace.cc.html#L96'>trace</a> to 'last_run'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L450" class="LineNr">450 </span> <a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">.</span>open<span class="Delimiter">(</span><span class="Constant">"last_run"</span><span class="Delimiter">);</span> +<span id="L451" class="LineNr">451 </span> <span class="Comment">// Add a dummy line up top; otherwise the `browse_trace` tool currently has</span> +<span id="L452" class="LineNr">452 </span> <span class="Comment">// no way to expand any lines above an error.</span> +<span id="L453" class="LineNr">453 </span> <a href='003trace.cc.html#L446'>Trace_file</a> << <span class="Constant">" 0 dummy: start</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L454" class="LineNr">454 </span> <span class="Comment">// End --trace Settings</span> +<span id="L455" class="LineNr">455 </span><span class="Delimiter">}</span> +<span id="L456" class="LineNr">456 </span><span class="Delimiter">:(before "End <a href='003trace.cc.html#L96'>trace</a> Commit")</span> +<span id="L457" class="LineNr">457 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L458" class="LineNr">458 </span> <a href='003trace.cc.html#L143'>dump_trace_line</a><span class="Delimiter">(</span><a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">,</span> t<span class="Delimiter">);</span> +<span id="L459" class="LineNr">459 </span> <a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">.</span><a href='011run.cc.html#L198'>flush</a><span class="Delimiter">();</span> +<span id="L460" class="LineNr">460 </span> <a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>pop_back<span class="Delimiter">();</span> <span class="Comment">// economize on memory</span> +<span id="L461" class="LineNr">461 </span><span class="Delimiter">}</span> +<span id="L462" class="LineNr">462 </span><span class="Delimiter">:(before "End One-time Setup")</span> +<span id="L463" class="LineNr">463 </span>atexit<span class="Delimiter">(</span><a href='003trace.cc.html#L465'>cleanup_main</a><span class="Delimiter">);</span> +<span id="L464" class="LineNr">464 </span><span class="Delimiter">:(code)</span> +<span id="L465" class="LineNr">465 </span><span class="Normal">void</span> <a href='003trace.cc.html#L465'>cleanup_main</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L466" class="LineNr">466 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> <a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">.</span>close<span class="Delimiter">();</span> +<span id="L467" class="LineNr">467 </span> <span class="Comment">// End cleanup_main</span> +<span id="L468" class="LineNr">468 </span><span class="Delimiter">}</span> +<span id="L469" class="LineNr">469 </span> +<span id="L470" class="LineNr">470 </span><span class="Delimiter">:(before "End trace_stream Methods")</span> +<span id="L471" class="LineNr">471 </span>string <a href='003trace.cc.html#L471'>readable_contents</a><span class="Delimiter">(</span>string label<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L472" class="LineNr">472 </span> string <a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">);</span> <span class="Comment">// prototype</span> +<span id="L473" class="LineNr">473 </span> ostringstream output<span class="Delimiter">;</span> +<span id="L474" class="LineNr">474 </span> label = <a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span>label<span class="Delimiter">);</span> +<span id="L475" class="LineNr">475 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='003trace.cc.html#L76'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> +<span id="L476" class="LineNr">476 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>label<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> || label == p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> +<span id="L477" class="LineNr">477 </span> <a href='003trace.cc.html#L143'>dump_trace_line</a><span class="Delimiter">(</span>output<span class="Delimiter">,</span> *p<span class="Delimiter">);</span> +<span id="L478" class="LineNr">478 </span> <span class="Identifier">return</span> output<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L479" class="LineNr">479 </span><span class="Delimiter">}</span> +<span id="L480" class="LineNr">480 </span> +<span id="L481" class="LineNr">481 </span><span class="Comment">//: Print traces to the screen as they happen.</span> +<span id="L482" class="LineNr">482 </span><span class="Comment">//: Particularly useful when juggling multiple trace streams, like when</span> +<span id="L483" class="LineNr">483 </span><span class="Comment">//: debugging sandboxes.</span> +<span id="L484" class="LineNr">484 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L485" class="LineNr">485 </span><span class="Normal">bool</span> <a href='003trace.cc.html#L485'>Dump_trace</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L486" class="LineNr">486 </span><span class="Delimiter">:(before "End Commandline Options(*arg)")</span> +<span id="L487" class="LineNr">487 </span><span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L98'>is_equal</a><span class="Delimiter">(</span>*arg<span class="Delimiter">,</span> <span class="Constant">"--dump"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L488" class="LineNr">488 </span> <a href='003trace.cc.html#L485'>Dump_trace</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L489" class="LineNr">489 </span><span class="Delimiter">}</span> +<span id="L490" class="LineNr">490 </span><span class="Delimiter">:(before "End Incremental Trace Print Conditions")</span> +<span id="L491" class="LineNr">491 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L485'>Dump_trace</a><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L492" class="LineNr">492 </span> +<span id="L493" class="LineNr">493 </span><span class="Comment">//: Miscellaneous helpers.</span> +<span id="L494" class="LineNr">494 </span> +<span id="L495" class="LineNr">495 </span><span class="Delimiter">:(code)</span> +<span id="L496" class="LineNr">496 </span>string <a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L497" class="LineNr">497 </span> string::const_iterator first = s<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> +<span id="L498" class="LineNr">498 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>first != s<span class="Delimiter">.</span>end<span class="Delimiter">()</span> && isspace<span class="Delimiter">(</span>*first<span class="Delimiter">))</span> +<span id="L499" class="LineNr">499 </span> ++first<span class="Delimiter">;</span> +<span id="L500" class="LineNr">500 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>first == s<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L501" class="LineNr">501 </span> +<span id="L502" class="LineNr">502 </span> string::const_iterator last = --s<span class="Delimiter">.</span>end<span class="Delimiter">();</span> +<span id="L503" class="LineNr">503 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>last != s<span class="Delimiter">.</span>begin<span class="Delimiter">()</span> && isspace<span class="Delimiter">(</span>*last<span class="Delimiter">))</span> +<span id="L504" class="LineNr">504 </span> --last<span class="Delimiter">;</span> +<span id="L505" class="LineNr">505 </span> ++last<span class="Delimiter">;</span> +<span id="L506" class="LineNr">506 </span> <span class="Identifier">return</span> string<span class="Delimiter">(</span>first<span class="Delimiter">,</span> last<span class="Delimiter">);</span> +<span id="L507" class="LineNr">507 </span><span class="Delimiter">}</span> +<span id="L508" class="LineNr">508 </span> +<span id="L509" class="LineNr">509 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L510" class="LineNr">510 </span><span class="PreProc">#include </span><span class="Constant"><vector></span> +<span id="L511" class="LineNr">511 </span><span class="Normal">using</span> std::vector<span class="Delimiter">;</span> +<span id="L512" class="LineNr">512 </span><span class="PreProc">#include </span><span class="Constant"><list></span> +<span id="L513" class="LineNr">513 </span><span class="Normal">using</span> std::list<span class="Delimiter">;</span> +<span id="L514" class="LineNr">514 </span><span class="PreProc">#include </span><span class="Constant"><set></span> +<span id="L515" class="LineNr">515 </span><span class="Normal">using</span> std::set<span class="Delimiter">;</span> +<span id="L516" class="LineNr">516 </span> +<span id="L517" class="LineNr">517 </span><span class="PreProc">#include </span><span class="Constant"><sstream></span> +<span id="L518" class="LineNr">518 </span><span class="Normal">using</span> std::istringstream<span class="Delimiter">;</span> +<span id="L519" class="LineNr">519 </span><span class="Normal">using</span> std::ostringstream<span class="Delimiter">;</span> +<span id="L520" class="LineNr">520 </span> +<span id="L521" class="LineNr">521 </span><span class="PreProc">#include </span><span class="Constant"><fstream></span> +<span id="L522" class="LineNr">522 </span><span class="Normal">using</span> std::ifstream<span class="Delimiter">;</span> +<span id="L523" class="LineNr">523 </span><span class="Normal">using</span> std::ofstream<span class="Delimiter">;</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/003trace.test.cc.html b/html/linux/bootstrap/003trace.test.cc.html new file mode 100644 index 00000000..412f55e3 --- /dev/null +++ b/html/linux/bootstrap/003trace.test.cc.html @@ -0,0 +1,194 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/003trace.test.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.Delimiter { color: #c000c0; } +.Comment { color: #005faf; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/003trace.test.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/003trace.test.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L1'>test_trace_check_compares</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L2" class="LineNr"> 2 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> +<span id="L3" class="LineNr"> 3 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span><span class="Constant">"test layer: foo"</span><span class="Delimiter">);</span> +<span id="L4" class="LineNr"> 4 </span><span class="Delimiter">}</span> +<span id="L5" class="LineNr"> 5 </span> +<span id="L6" class="LineNr"> 6 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L6'>test_trace_check_ignores_other_layers</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L7" class="LineNr"> 7 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> +<span id="L8" class="LineNr"> 8 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 2"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span> << end<span class="Delimiter">();</span> +<span id="L9" class="LineNr"> 9 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span><span class="Constant">"test layer 1: foo"</span><span class="Delimiter">);</span> +<span id="L10" class="LineNr"> 10 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"test layer 2: foo"</span><span class="Delimiter">);</span> +<span id="L11" class="LineNr"> 11 </span><span class="Delimiter">}</span> +<span id="L12" class="LineNr"> 12 </span> +<span id="L13" class="LineNr"> 13 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L13'>test_trace_check_ignores_leading_whitespace</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L14" class="LineNr"> 14 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">" foo"</span> << end<span class="Delimiter">();</span> +<span id="L15" class="LineNr"> 15 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">too little whitespace</span><span class="Comment">*/</span><span class="Constant">"foo"</span><span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L16" class="LineNr"> 16 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">too much whitespace</span><span class="Comment">*/</span><span class="Constant">" foo"</span><span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L17" class="LineNr"> 17 </span><span class="Delimiter">}</span> +<span id="L18" class="LineNr"> 18 </span> +<span id="L19" class="LineNr"> 19 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L19'>test_trace_check_ignores_other_lines</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L20" class="LineNr"> 20 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> +<span id="L21" class="LineNr"> 21 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span> << end<span class="Delimiter">();</span> +<span id="L22" class="LineNr"> 22 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span><span class="Constant">"test layer 1: foo"</span><span class="Delimiter">);</span> +<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">}</span> +<span id="L24" class="LineNr"> 24 </span> +<span id="L25" class="LineNr"> 25 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L25'>test_trace_check_ignores_other_lines2</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L26" class="LineNr"> 26 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> +<span id="L27" class="LineNr"> 27 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span> << end<span class="Delimiter">();</span> +<span id="L28" class="LineNr"> 28 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span><span class="Constant">"test layer 1: bar"</span><span class="Delimiter">);</span> +<span id="L29" class="LineNr"> 29 </span><span class="Delimiter">}</span> +<span id="L30" class="LineNr"> 30 </span> +<span id="L31" class="LineNr"> 31 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L31'>test_trace_ignores_trailing_whitespace</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L32" class="LineNr"> 32 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L33" class="LineNr"> 33 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span><span class="Constant">"test layer 1: foo"</span><span class="Delimiter">);</span> +<span id="L34" class="LineNr"> 34 </span><span class="Delimiter">}</span> +<span id="L35" class="LineNr"> 35 </span> +<span id="L36" class="LineNr"> 36 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L36'>test_trace_ignores_trailing_whitespace2</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L37" class="LineNr"> 37 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo "</span> << end<span class="Delimiter">();</span> +<span id="L38" class="LineNr"> 38 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span><span class="Constant">"test layer 1: foo"</span><span class="Delimiter">);</span> +<span id="L39" class="LineNr"> 39 </span><span class="Delimiter">}</span> +<span id="L40" class="LineNr"> 40 </span> +<span id="L41" class="LineNr"> 41 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L41'>test_trace_orders_across_layers</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L42" class="LineNr"> 42 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> +<span id="L43" class="LineNr"> 43 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 2"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span> << end<span class="Delimiter">();</span> +<span id="L44" class="LineNr"> 44 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"qux"</span> << end<span class="Delimiter">();</span> +<span id="L45" class="LineNr"> 45 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span><span class="Constant">"test layer 1: foo</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Constant">"test layer 2: bar</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Constant">"test layer 1: qux</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">);</span> +<span id="L48" class="LineNr"> 48 </span><span class="Delimiter">}</span> +<span id="L49" class="LineNr"> 49 </span> +<span id="L50" class="LineNr"> 50 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L50'>test_trace_supports_count</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L51" class="LineNr"> 51 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> +<span id="L52" class="LineNr"> 52 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> +<span id="L53" class="LineNr"> 53 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">),</span> <span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L54" class="LineNr"> 54 </span><span class="Delimiter">}</span> +<span id="L55" class="LineNr"> 55 </span> +<span id="L56" class="LineNr"> 56 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L56'>test_trace_supports_count2</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L57" class="LineNr"> 57 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo"</span> << end<span class="Delimiter">();</span> +<span id="L58" class="LineNr"> 58 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"bar"</span> << end<span class="Delimiter">();</span> +<span id="L59" class="LineNr"> 59 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">),</span> <span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L60" class="LineNr"> 60 </span><span class="Delimiter">}</span> +<span id="L61" class="LineNr"> 61 </span> +<span id="L62" class="LineNr"> 62 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L62'>test_trace_count_ignores_trailing_whitespace</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L63" class="LineNr"> 63 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L64" class="LineNr"> 64 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L65" class="LineNr"> 65 </span><span class="Delimiter">}</span> +<span id="L66" class="LineNr"> 66 </span> +<span id="L67" class="LineNr"> 67 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L67'>test_trace_unescapes_newlines</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L68" class="LineNr"> 68 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"f</span><span class="cSpecial">\n</span><span class="Constant">o</span><span class="cSpecial">\n</span><span class="Constant">o</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L69" class="LineNr"> 69 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span><span class="Constant">"test layer 1: f</span><span class="cSpecial">\\</span><span class="Constant">no</span><span class="cSpecial">\\</span><span class="Constant">no"</span><span class="Delimiter">);</span> +<span id="L70" class="LineNr"> 70 </span><span class="Delimiter">}</span> +<span id="L71" class="LineNr"> 71 </span> +<span id="L72" class="LineNr"> 72 </span><span class="Comment">// pending: DUMP tests</span> +<span id="L73" class="LineNr"> 73 </span><span class="Comment">// pending: readable_contents() adds newline if necessary.</span> +<span id="L74" class="LineNr"> 74 </span><span class="Comment">// pending: raise also prints to stderr.</span> +<span id="L75" class="LineNr"> 75 </span><span class="Comment">// pending: raise doesn't print to stderr if Hide_errors is set.</span> +<span id="L76" class="LineNr"> 76 </span><span class="Comment">// pending: warn doesn't print to stderr if Hide_errors is set.</span> +<span id="L77" class="LineNr"> 77 </span><span class="Comment">// pending: warn doesn't print to stderr if Hide_warnings is set.</span> +<span id="L78" class="LineNr"> 78 </span><span class="Comment">// pending: raise doesn't have to be saved if Hide_errors is set, just printed.</span> +<span id="L79" class="LineNr"> 79 </span><span class="Comment">// pending: raise prints to stderr if Trace_stream is NULL.</span> +<span id="L80" class="LineNr"> 80 </span><span class="Comment">// pending: raise prints to stderr if Trace_stream is NULL even if Hide_errors is set.</span> +<span id="L81" class="LineNr"> 81 </span> +<span id="L82" class="LineNr"> 82 </span><span class="Comment">// can't check trace because trace methods call 'split'</span> +<span id="L83" class="LineNr"> 83 </span> +<span id="L84" class="LineNr"> 84 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L84'>test_split_returns_at_least_one_elem</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L85" class="LineNr"> 85 </span> vector<string> result = <a href='003trace.cc.html#L407'>split</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">,</span> <span class="Constant">","</span><span class="Delimiter">);</span> +<span id="L86" class="LineNr"> 86 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L87" class="LineNr"> 87 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L88" class="LineNr"> 88 </span><span class="Delimiter">}</span> +<span id="L89" class="LineNr"> 89 </span> +<span id="L90" class="LineNr"> 90 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L90'>test_split_returns_entire_input_when_no_delim</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L91" class="LineNr"> 91 </span> vector<string> result = <a href='003trace.cc.html#L407'>split</a><span class="Delimiter">(</span><span class="Constant">"abc"</span><span class="Delimiter">,</span> <span class="Constant">","</span><span class="Delimiter">);</span> +<span id="L92" class="LineNr"> 92 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L93" class="LineNr"> 93 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span> +<span id="L94" class="LineNr"> 94 </span><span class="Delimiter">}</span> +<span id="L95" class="LineNr"> 95 </span> +<span id="L96" class="LineNr"> 96 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L96'>test_split_works</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L97" class="LineNr"> 97 </span> vector<string> result = <a href='003trace.cc.html#L407'>split</a><span class="Delimiter">(</span><span class="Constant">"abc,def"</span><span class="Delimiter">,</span> <span class="Constant">","</span><span class="Delimiter">);</span> +<span id="L98" class="LineNr"> 98 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L99" class="LineNr"> 99 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span> +<span id="L100" class="LineNr">100 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">),</span> <span class="Constant">"def"</span><span class="Delimiter">);</span> +<span id="L101" class="LineNr">101 </span><span class="Delimiter">}</span> +<span id="L102" class="LineNr">102 </span> +<span id="L103" class="LineNr">103 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L103'>test_split_works2</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L104" class="LineNr">104 </span> vector<string> result = <a href='003trace.cc.html#L407'>split</a><span class="Delimiter">(</span><span class="Constant">"abc,def,ghi"</span><span class="Delimiter">,</span> <span class="Constant">","</span><span class="Delimiter">);</span> +<span id="L105" class="LineNr">105 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L106" class="LineNr">106 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span> +<span id="L107" class="LineNr">107 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">),</span> <span class="Constant">"def"</span><span class="Delimiter">);</span> +<span id="L108" class="LineNr">108 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">),</span> <span class="Constant">"ghi"</span><span class="Delimiter">);</span> +<span id="L109" class="LineNr">109 </span><span class="Delimiter">}</span> +<span id="L110" class="LineNr">110 </span> +<span id="L111" class="LineNr">111 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L111'>test_split_handles_multichar_delim</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L112" class="LineNr">112 </span> vector<string> result = <a href='003trace.cc.html#L407'>split</a><span class="Delimiter">(</span><span class="Constant">"abc,,def,,ghi"</span><span class="Delimiter">,</span> <span class="Constant">",,"</span><span class="Delimiter">);</span> +<span id="L113" class="LineNr">113 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L114" class="LineNr">114 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">"abc"</span><span class="Delimiter">);</span> +<span id="L115" class="LineNr">115 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">),</span> <span class="Constant">"def"</span><span class="Delimiter">);</span> +<span id="L116" class="LineNr">116 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">),</span> <span class="Constant">"ghi"</span><span class="Delimiter">);</span> +<span id="L117" class="LineNr">117 </span><span class="Delimiter">}</span> +<span id="L118" class="LineNr">118 </span> +<span id="L119" class="LineNr">119 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L119'>test_trim</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L120" class="LineNr">120 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">),</span> <span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L121" class="LineNr">121 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">" "</span><span class="Delimiter">),</span> <span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L122" class="LineNr">122 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">" "</span><span class="Delimiter">),</span> <span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L123" class="LineNr">123 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">"a"</span><span class="Delimiter">),</span> <span class="Constant">"a"</span><span class="Delimiter">);</span> +<span id="L124" class="LineNr">124 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">" a"</span><span class="Delimiter">),</span> <span class="Constant">"a"</span><span class="Delimiter">);</span> +<span id="L125" class="LineNr">125 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">" a"</span><span class="Delimiter">),</span> <span class="Constant">"a"</span><span class="Delimiter">);</span> +<span id="L126" class="LineNr">126 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">" ab"</span><span class="Delimiter">),</span> <span class="Constant">"ab"</span><span class="Delimiter">);</span> +<span id="L127" class="LineNr">127 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">"a "</span><span class="Delimiter">),</span> <span class="Constant">"a"</span><span class="Delimiter">);</span> +<span id="L128" class="LineNr">128 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">"a "</span><span class="Delimiter">),</span> <span class="Constant">"a"</span><span class="Delimiter">);</span> +<span id="L129" class="LineNr">129 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">"ab "</span><span class="Delimiter">),</span> <span class="Constant">"ab"</span><span class="Delimiter">);</span> +<span id="L130" class="LineNr">130 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">" a "</span><span class="Delimiter">),</span> <span class="Constant">"a"</span><span class="Delimiter">);</span> +<span id="L131" class="LineNr">131 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">" a "</span><span class="Delimiter">),</span> <span class="Constant">"a"</span><span class="Delimiter">);</span> +<span id="L132" class="LineNr">132 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='003trace.cc.html#L496'>trim</a><span class="Delimiter">(</span><span class="Constant">" ab "</span><span class="Delimiter">),</span> <span class="Constant">"ab"</span><span class="Delimiter">);</span> +<span id="L133" class="LineNr">133 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/010vm.cc.html b/html/linux/bootstrap/010vm.cc.html new file mode 100644 index 00000000..f60b6abf --- /dev/null +++ b/html/linux/bootstrap/010vm.cc.html @@ -0,0 +1,474 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/010vm.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +.PreProc { color: #c000c0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/010vm.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/010vm.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: Core data structures for simulating the SubX VM (subset of an x86 processor),</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: either in tests or debug aids.</span> +<span id="L3" class="LineNr"> 3 </span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//:: registers</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: assume segment registers are hard-coded to 0</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment">//: no MMX, etc.</span> +<span id="L7" class="LineNr"> 7 </span> +<span id="L8" class="LineNr"> 8 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L9" class="LineNr"> 9 </span><span class="Normal">enum</span> <span class="Delimiter">{</span> +<span id="L10" class="LineNr"> 10 </span> <a href='010vm.cc.html#L10'>EAX</a><span class="Delimiter">,</span> +<span id="L11" class="LineNr"> 11 </span> <a href='010vm.cc.html#L11'>ECX</a><span class="Delimiter">,</span> +<span id="L12" class="LineNr"> 12 </span> <a href='010vm.cc.html#L12'>EDX</a><span class="Delimiter">,</span> +<span id="L13" class="LineNr"> 13 </span> <a href='010vm.cc.html#L13'>EBX</a><span class="Delimiter">,</span> +<span id="L14" class="LineNr"> 14 </span> <a href='010vm.cc.html#L14'>ESP</a><span class="Delimiter">,</span> +<span id="L15" class="LineNr"> 15 </span> <a href='010vm.cc.html#L15'>EBP</a><span class="Delimiter">,</span> +<span id="L16" class="LineNr"> 16 </span> <a href='010vm.cc.html#L16'>ESI</a><span class="Delimiter">,</span> +<span id="L17" class="LineNr"> 17 </span> <a href='010vm.cc.html#L17'>EDI</a><span class="Delimiter">,</span> +<span id="L18" class="LineNr"> 18 </span> <a href='010vm.cc.html#L18'>NUM_INT_REGISTERS</a><span class="Delimiter">,</span> +<span id="L19" class="LineNr"> 19 </span><span class="Delimiter">};</span> +<span id="L20" class="LineNr"> 20 </span><span class="Normal">union</span> <a href='010vm.cc.html#L20'>reg</a> <span class="Delimiter">{</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Normal">int32_t</span> i<span class="Delimiter">;</span> +<span id="L22" class="LineNr"> 22 </span> <span class="Normal">uint32_t</span> u<span class="Delimiter">;</span> +<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">};</span> +<span id="L24" class="LineNr"> 24 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L25" class="LineNr"> 25 </span><a href='010vm.cc.html#L20'>reg</a> Reg[NUM_INT_REGISTERS] = <span class="Delimiter">{</span> <span class="Delimiter">{</span><span class="Constant">0</span><span class="Delimiter">}</span> <span class="Delimiter">};</span> +<span id="L26" class="LineNr"> 26 </span><span class="Normal">uint32_t</span> <a href='010vm.cc.html#L26'>EIP</a> = <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// preserve null pointer</span> +<span id="L27" class="LineNr"> 27 </span><span class="Delimiter">:(before "End Reset")</span> +<span id="L28" class="LineNr"> 28 </span>bzero<span class="Delimiter">(</span><a href='010vm.cc.html#L25'>Reg</a><span class="Delimiter">,</span> <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='010vm.cc.html#L25'>Reg</a><span class="Delimiter">));</span> +<span id="L29" class="LineNr"> 29 </span><a href='010vm.cc.html#L26'>EIP</a> = <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// preserve null pointer</span> +<span id="L30" class="LineNr"> 30 </span> +<span id="L31" class="LineNr"> 31 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L32" class="LineNr"> 32 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='010vm.cc.html#L32'>NUM_XMM_REGISTERS</a> = <span class="Constant">8</span><span class="Delimiter">;</span> +<span id="L33" class="LineNr"> 33 </span><span class="Normal">float</span> Xmm[NUM_XMM_REGISTERS] = <span class="Delimiter">{</span> <span class="Constant">0.0</span> <span class="Delimiter">};</span> +<span id="L34" class="LineNr"> 34 </span><span class="Normal">const</span> string Xname[NUM_XMM_REGISTERS] = <span class="Delimiter">{</span> <span class="Constant">"XMM0"</span><span class="Delimiter">,</span> <span class="Constant">"XMM1"</span><span class="Delimiter">,</span> <span class="Constant">"XMM2"</span><span class="Delimiter">,</span> <span class="Constant">"XMM3"</span><span class="Delimiter">,</span> <span class="Constant">"XMM4"</span><span class="Delimiter">,</span> <span class="Constant">"XMM5"</span><span class="Delimiter">,</span> <span class="Constant">"XMM6"</span><span class="Delimiter">,</span> <span class="Constant">"XMM7"</span> <span class="Delimiter">};</span> +<span id="L35" class="LineNr"> 35 </span><span class="Delimiter">:(before "End Reset")</span> +<span id="L36" class="LineNr"> 36 </span>bzero<span class="Delimiter">(</span><a href='010vm.cc.html#L33'>Xmm</a><span class="Delimiter">,</span> <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='010vm.cc.html#L33'>Xmm</a><span class="Delimiter">));</span> +<span id="L37" class="LineNr"> 37 </span> +<span id="L38" class="LineNr"> 38 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Contents")</span> +<span id="L39" class="LineNr"> 39 </span>cerr << <span class="Constant">" registers</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L40" class="LineNr"> 40 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Texts")</span> +<span id="L41" class="LineNr"> 41 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"registers"</span><span class="Delimiter">,</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Constant">"SubX supports 16 registers: eight 32-bit integer registers and eight single-precision</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Constant">"floating-point registers. From 0 to 7, they are:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Constant">" integer: <a href='010vm.cc.html#L10'>EAX</a> <a href='010vm.cc.html#L11'>ECX</a> <a href='010vm.cc.html#L12'>EDX</a> <a href='010vm.cc.html#L13'>EBX</a> <a href='010vm.cc.html#L14'>ESP</a> <a href='010vm.cc.html#L15'>EBP</a> <a href='010vm.cc.html#L16'>ESI</a> <a href='010vm.cc.html#L17'>EDI</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Constant">" floating point: XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Constant">"ESP contains the top of the stack.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Constant">"-- 8-bit registers</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Constant">"Some instructions operate on eight *overlapping* 8-bit registers.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Constant">"From 0 to 7, they are:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Constant">" AL CL DL BL AH CH DH BH</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Constant">"The 8-bit registers overlap with the 32-bit ones. AL is the lowest signicant byte</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Constant">"of <a href='010vm.cc.html#L10'>EAX</a>, AH is the second lowest significant byte, and so on.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L55" class="LineNr"> 55 </span> <span class="Constant">"For example, if <a href='010vm.cc.html#L13'>EBX</a> contains 0x11223344, then BL contains 0x44, and BH contains 0x33.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Constant">"There is no way to access bytes within <a href='010vm.cc.html#L14'>ESP</a>, <a href='010vm.cc.html#L15'>EBP</a>, <a href='010vm.cc.html#L16'>ESI</a> or EDI.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Constant">"For complete details consult the IA-32 software developer's manual, volume 2,</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Constant">"table 2-2, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing forms with the ModR/M byte</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Constant">"It is included in this repository as 'modrm.pdf'.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Constant">"The register encodings are described in the top row of the table, but you'll need</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Constant">"to spend some time with it.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Constant">"-- flag registers</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Constant">"Various instructions (particularly 'compare') modify one or more of four 1-bit</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Constant">"'flag' registers, as a side-effect:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Constant">"- the sign flag (SF): usually set if an arithmetic result is negative, or</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Constant">" <a href='000organization.cc.html#L150'>reset</a> if not.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Constant">"- the zero flag (<a href='010vm.cc.html#L89'>ZF</a>): usually set if a result is zero, or <a href='000organization.cc.html#L150'>reset</a> if not.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Constant">"- the carry flag (<a href='010vm.cc.html#L90'>CF</a>): usually set if an arithmetic result overflows by just one bit.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Constant">" Useful for operating on unsigned numbers.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">"- the overflow flag (<a href='010vm.cc.html#L91'>OF</a>): usually set if an arithmetic result overflows by more</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Constant">" than one bit. Useful for operating on signed numbers.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Constant">"The flag bits are read by conditional jumps.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L76" class="LineNr"> 76 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Constant">"For complete details on how different instructions update the flags, consult the IA-32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Constant">"manual (volume 2). There's various versions of it online, such as <a href="https://c9x.me/x86,">https://c9x.me/x86,</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Constant">"though of course you'll need to be careful to ignore instructions and flag registers</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Constant">"that SubX doesn't support.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Constant">"It isn't simple, but if this is the processor you have running on your computer,</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Constant">"might as well get good at it.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L84" class="LineNr"> 84 </span><span class="Delimiter">);</span> +<span id="L85" class="LineNr"> 85 </span> +<span id="L86" class="LineNr"> 86 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L87" class="LineNr"> 87 </span><span class="Comment">// the subset of x86 flag registers we care about</span> +<span id="L88" class="LineNr"> 88 </span><span class="Normal">bool</span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// sign flag</span> +<span id="L89" class="LineNr"> 89 </span><span class="Normal">bool</span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// zero flag</span> +<span id="L90" class="LineNr"> 90 </span><span class="Normal">bool</span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// carry flag</span> +<span id="L91" class="LineNr"> 91 </span><span class="Normal">bool</span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// overflow flag</span> +<span id="L92" class="LineNr"> 92 </span><span class="Delimiter">:(before "End Reset")</span> +<span id="L93" class="LineNr"> 93 </span>SF = <a href='010vm.cc.html#L89'>ZF</a> = <a href='010vm.cc.html#L90'>CF</a> = <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L94" class="LineNr"> 94 </span> +<span id="L95" class="LineNr"> 95 </span><span class="Comment">//:: simulated RAM</span> +<span id="L96" class="LineNr"> 96 </span> +<span id="L97" class="LineNr"> 97 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L98" class="LineNr"> 98 </span><span class="Normal">const</span> <span class="Normal">uint32_t</span> <a href='010vm.cc.html#L98'>SEGMENT_ALIGNMENT</a> = <span class="Constant">0x1000000</span><span class="Delimiter">;</span> <span class="Comment">// 16MB</span> +<span id="L99" class="LineNr"> 99 </span><span class="Normal">inline</span> <span class="Normal">uint32_t</span> <a href='010vm.cc.html#L99'>align_upwards</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> x<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> align<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L100" class="LineNr">100 </span> <span class="Identifier">return</span> <span class="Delimiter">(</span>x+align-<span class="Constant">1</span><span class="Delimiter">)</span> & -<span class="Delimiter">(</span>align<span class="Delimiter">);</span> +<span id="L101" class="LineNr">101 </span><span class="Delimiter">}</span> +<span id="L102" class="LineNr">102 </span> +<span id="L103" class="LineNr">103 </span><span class="Comment">// Like in real-world Linux, we'll allocate RAM for our programs in disjoint</span> +<span id="L104" class="LineNr">104 </span><span class="Comment">// slabs called VMAs or Virtual Memory Areas.</span> +<span id="L105" class="LineNr">105 </span><span class="Normal">struct</span> vma <span class="Delimiter">{</span> +<span id="L106" class="LineNr">106 </span> <span class="Normal">uint32_t</span> start<span class="Delimiter">;</span> <span class="Comment">// inclusive</span> +<span id="L107" class="LineNr">107 </span> <span class="Normal">uint32_t</span> end<span class="Delimiter">;</span> <span class="Comment">// exclusive</span> +<span id="L108" class="LineNr">108 </span> vector<<span class="Normal">uint8_t</span>> <a href='010vm.cc.html#L108'>_data</a><span class="Delimiter">;</span> +<span id="L109" class="LineNr">109 </span> vma<span class="Delimiter">(</span><span class="Normal">uint32_t</span> s<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> e<span class="Delimiter">)</span> :start<span class="Delimiter">(</span>s<span class="Delimiter">),</span> end<span class="Delimiter">(</span>e<span class="Delimiter">)</span> <span class="Delimiter">{}</span> +<span id="L110" class="LineNr">110 </span> vma<span class="Delimiter">(</span><span class="Normal">uint32_t</span> s<span class="Delimiter">)</span> :start<span class="Delimiter">(</span>s<span class="Delimiter">),</span> end<span class="Delimiter">(</span><a href='010vm.cc.html#L99'>align_upwards</a><span class="Delimiter">(</span>s+<span class="Constant">1</span><span class="Delimiter">,</span> <a href='010vm.cc.html#L98'>SEGMENT_ALIGNMENT</a><span class="Delimiter">))</span> <span class="Delimiter">{}</span> +<span id="L111" class="LineNr">111 </span> <span class="Normal">bool</span> <a href='010vm.cc.html#L111'>match</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> a<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L112" class="LineNr">112 </span> <span class="Identifier">return</span> a >= start && a < end<span class="Delimiter">;</span> +<span id="L113" class="LineNr">113 </span> <span class="Delimiter">}</span> +<span id="L114" class="LineNr">114 </span> <span class="Normal">bool</span> <a href='010vm.cc.html#L114'>match32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> a<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L115" class="LineNr">115 </span> <span class="Identifier">return</span> a >= start && a+<span class="Constant">4</span> <= end<span class="Delimiter">;</span> +<span id="L116" class="LineNr">116 </span> <span class="Delimiter">}</span> +<span id="L117" class="LineNr">117 </span> <span class="Normal">uint8_t</span>& data<span class="Delimiter">(</span><span class="Normal">uint32_t</span> a<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L118" class="LineNr">118 </span> assert<span class="Delimiter">(</span><a href='010vm.cc.html#L111'>match</a><span class="Delimiter">(</span>a<span class="Delimiter">));</span> +<span id="L119" class="LineNr">119 </span> <span class="Normal">uint32_t</span> result_index = a-start<span class="Delimiter">;</span> +<span id="L120" class="LineNr">120 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L108'>_data</a><span class="Delimiter">.</span>size<span class="Delimiter">()</span> <= result_index+<span class="Comment">/*</span><span class="Comment">largest <a href='011run.cc.html#L127'>word</a> size that can be accessed in one instruction</span><span class="Comment">*/</span><span class="Normal">sizeof</span><span class="Delimiter">(</span><span class="Normal">int</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L121" class="LineNr">121 </span> <span class="Normal">const</span> <span class="Normal">int</span> align = <span class="Constant">0x1000</span><span class="Delimiter">;</span> +<span id="L122" class="LineNr">122 </span> <span class="Normal">uint32_t</span> result_size = result_index + <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// size needed for result_index to be valid</span> +<span id="L123" class="LineNr">123 </span> <span class="Normal">uint32_t</span> new_size = <a href='010vm.cc.html#L99'>align_upwards</a><span class="Delimiter">(</span>result_size<span class="Delimiter">,</span> align<span class="Delimiter">);</span> +<span id="L124" class="LineNr">124 </span> <span class="Comment">// grow at least 2x to maintain some amortized complexity guarantees</span> +<span id="L125" class="LineNr">125 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>new_size < <a href='010vm.cc.html#L108'>_data</a><span class="Delimiter">.</span>size<span class="Delimiter">()</span> * <span class="Constant">2</span><span class="Delimiter">)</span> +<span id="L126" class="LineNr">126 </span> new_size = <a href='010vm.cc.html#L108'>_data</a><span class="Delimiter">.</span>size<span class="Delimiter">()</span> * <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L127" class="LineNr">127 </span> <span class="Comment">// never grow past the stated limit</span> +<span id="L128" class="LineNr">128 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>new_size > end-start<span class="Delimiter">)</span> +<span id="L129" class="LineNr">129 </span> new_size = end-start<span class="Delimiter">;</span> +<span id="L130" class="LineNr">130 </span> <a href='010vm.cc.html#L108'>_data</a><span class="Delimiter">.</span>resize<span class="Delimiter">(</span>new_size<span class="Delimiter">);</span> +<span id="L131" class="LineNr">131 </span> <span class="Delimiter">}</span> +<span id="L132" class="LineNr">132 </span> <span class="Identifier">return</span> <a href='010vm.cc.html#L108'>_data</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>result_index<span class="Delimiter">);</span> +<span id="L133" class="LineNr">133 </span> <span class="Delimiter">}</span> +<span id="L134" class="LineNr">134 </span> <span class="Normal">void</span> <a href='010vm.cc.html#L134'>grow_until</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> new_end_address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L135" class="LineNr">135 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>new_end_address < end<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L136" class="LineNr">136 </span> <span class="Comment">// Ugly: vma knows about the global Memory list of vmas</span> +<span id="L137" class="LineNr">137 </span> <span class="Normal">void</span> <a href='010vm.cc.html#L144'>sanity_check</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> start<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> end<span class="Delimiter">);</span> +<span id="L138" class="LineNr">138 </span> <a href='010vm.cc.html#L144'>sanity_check</a><span class="Delimiter">(</span>start<span class="Delimiter">,</span> new_end_address<span class="Delimiter">);</span> +<span id="L139" class="LineNr">139 </span> end = new_end_address<span class="Delimiter">;</span> +<span id="L140" class="LineNr">140 </span> <span class="Delimiter">}</span> +<span id="L141" class="LineNr">141 </span> <span class="Comment">// End vma Methods</span> +<span id="L142" class="LineNr">142 </span><span class="Delimiter">};</span> +<span id="L143" class="LineNr">143 </span><span class="Delimiter">:(code)</span> +<span id="L144" class="LineNr">144 </span><span class="Normal">void</span> <a href='010vm.cc.html#L144'>sanity_check</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> start<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> end<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L145" class="LineNr">145 </span> <span class="Normal">bool</span> dup_found = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L146" class="LineNr">146 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span><a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L147" class="LineNr">147 </span> <span class="Normal">const</span> vma& curr = <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L148" class="LineNr">148 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start == start<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L149" class="LineNr">149 </span> assert<span class="Delimiter">(</span>!dup_found<span class="Delimiter">);</span> +<span id="L150" class="LineNr">150 </span> dup_found = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L151" class="LineNr">151 </span> <span class="Delimiter">}</span> +<span id="L152" class="LineNr">152 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start > start<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L153" class="LineNr">153 </span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start > end<span class="Delimiter">);</span> +<span id="L154" class="LineNr">154 </span> <span class="Delimiter">}</span> +<span id="L155" class="LineNr">155 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start < start<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L156" class="LineNr">156 </span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>end < start<span class="Delimiter">);</span> +<span id="L157" class="LineNr">157 </span> <span class="Delimiter">}</span> +<span id="L158" class="LineNr">158 </span> <span class="Delimiter">}</span> +<span id="L159" class="LineNr">159 </span><span class="Delimiter">}</span> +<span id="L160" class="LineNr">160 </span> +<span id="L161" class="LineNr">161 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L162" class="LineNr">162 </span><span class="Comment">// RAM is made of VMAs.</span> +<span id="L163" class="LineNr">163 </span>vector<vma> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">;</span> +<span id="L164" class="LineNr">164 </span><span class="Delimiter">:(code)</span> +<span id="L165" class="LineNr">165 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L166" class="LineNr">166 </span><span class="Normal">uint32_t</span> <a href='010vm.cc.html#L166'>End_of_program</a> = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// when the program executes past this address in tests we'll stop the test</span> +<span id="L167" class="LineNr">167 </span><span class="Comment">// The stack grows downward. Can't increase its size for now.</span> +<span id="L168" class="LineNr">168 </span><span class="Delimiter">:(before "End Reset")</span> +<span id="L169" class="LineNr">169 </span><a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>clear<span class="Delimiter">();</span> +<span id="L170" class="LineNr">170 </span><a href='010vm.cc.html#L166'>End_of_program</a> = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L171" class="LineNr">171 </span><span class="Delimiter">:(code)</span> +<span id="L172" class="LineNr">172 </span><span class="Comment">// These helpers depend on Mem being laid out contiguously (so you can't use a</span> +<span id="L173" class="LineNr">173 </span><span class="Comment">// map, etc.) and on the host also being little-endian.</span> +<span id="L174" class="LineNr">174 </span><span class="Normal">inline</span> <span class="Normal">uint8_t</span> <a href='010vm.cc.html#L174'>read_mem_u8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L175" class="LineNr">175 </span> <span class="Normal">uint8_t</span>* handle = <a href='010vm.cc.html#L192'>mem_addr_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> <span class="Comment">// error messages get printed here</span> +<span id="L176" class="LineNr">176 </span> <span class="Identifier">return</span> handle ? *handle : <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L177" class="LineNr">177 </span><span class="Delimiter">}</span> +<span id="L178" class="LineNr">178 </span><span class="Normal">inline</span> <span class="Normal">int8_t</span> <a href='010vm.cc.html#L178'>read_mem_i8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L179" class="LineNr">179 </span> <span class="Identifier">return</span> <span class="Normal">static_cast</span><<span class="Normal">int8_t</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L174'>read_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L180" class="LineNr">180 </span><span class="Delimiter">}</span> +<span id="L181" class="LineNr">181 </span><span class="Normal">inline</span> <span class="Normal">uint32_t</span> <a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L182" class="LineNr">182 </span> <span class="Normal">uint32_t</span>* handle = <a href='010vm.cc.html#L211'>mem_addr_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> <span class="Comment">// error messages get printed here</span> +<span id="L183" class="LineNr">183 </span> <span class="Identifier">return</span> handle ? *handle : <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L184" class="LineNr">184 </span><span class="Delimiter">}</span> +<span id="L185" class="LineNr">185 </span><span class="Normal">inline</span> <span class="Normal">int32_t</span> <a href='010vm.cc.html#L185'>read_mem_i32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L186" class="LineNr">186 </span> <span class="Identifier">return</span> <span class="Normal">static_cast</span><<span class="Normal">int32_t</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L187" class="LineNr">187 </span><span class="Delimiter">}</span> +<span id="L188" class="LineNr">188 </span><span class="Normal">inline</span> <span class="Normal">float</span> <a href='010vm.cc.html#L188'>read_mem_f32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L189" class="LineNr">189 </span> <span class="Identifier">return</span> <span class="Normal">static_cast</span><<span class="Normal">float</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L190" class="LineNr">190 </span><span class="Delimiter">}</span> +<span id="L191" class="LineNr">191 </span> +<span id="L192" class="LineNr">192 </span><span class="Normal">inline</span> <span class="Normal">uint8_t</span>* <a href='010vm.cc.html#L192'>mem_addr_u8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L193" class="LineNr">193 </span> <span class="Normal">uint8_t</span>* result = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L194" class="LineNr">194 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span><a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L195" class="LineNr">195 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='010vm.cc.html#L111'>match</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L196" class="LineNr">196 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> +<span id="L197" class="LineNr">197 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"address 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" is in two <a href='011run.cc.html#L106'>segments</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L198" class="LineNr">198 </span> result = &Mem<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>data<span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L199" class="LineNr">199 </span> <span class="Delimiter">}</span> +<span id="L200" class="LineNr">200 </span> <span class="Delimiter">}</span> +<span id="L201" class="LineNr">201 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L202" class="LineNr">202 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> <a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">.</span><a href='011run.cc.html#L198'>flush</a><span class="Delimiter">();</span> +<span id="L203" class="LineNr">203 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Tried to access uninitialized memory at address 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L204" class="LineNr">204 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L205" class="LineNr">205 </span> <span class="Delimiter">}</span> +<span id="L206" class="LineNr">206 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L207" class="LineNr">207 </span><span class="Delimiter">}</span> +<span id="L208" class="LineNr">208 </span><span class="Normal">inline</span> <span class="Normal">int8_t</span>* <a href='010vm.cc.html#L208'>mem_addr_i8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L209" class="LineNr">209 </span> <span class="Identifier">return</span> <span class="Normal">reinterpret_cast</span><<span class="Normal">int8_t</span>*><span class="Delimiter">(</span><a href='010vm.cc.html#L192'>mem_addr_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L210" class="LineNr">210 </span><span class="Delimiter">}</span> +<span id="L211" class="LineNr">211 </span><span class="Normal">inline</span> <span class="Normal">uint32_t</span>* <a href='010vm.cc.html#L211'>mem_addr_u32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L212" class="LineNr">212 </span> <span class="Normal">uint32_t</span>* result = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L213" class="LineNr">213 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span><a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L214" class="LineNr">214 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='010vm.cc.html#L114'>match32</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L215" class="LineNr">215 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> +<span id="L216" class="LineNr">216 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"address 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" is in two <a href='011run.cc.html#L106'>segments</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L217" class="LineNr">217 </span> result = <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>i<span class="Delimiter">).</span>data<span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L218" class="LineNr">218 </span> <span class="Delimiter">}</span> +<span id="L219" class="LineNr">219 </span> <span class="Delimiter">}</span> +<span id="L220" class="LineNr">220 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L221" class="LineNr">221 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> <a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">.</span><a href='011run.cc.html#L198'>flush</a><span class="Delimiter">();</span> +<span id="L222" class="LineNr">222 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Tried to access uninitialized memory at address 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L223" class="LineNr">223 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L224" class="LineNr">224 </span> <span class="Delimiter">}</span> +<span id="L225" class="LineNr">225 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L226" class="LineNr">226 </span><span class="Delimiter">}</span> +<span id="L227" class="LineNr">227 </span><span class="Normal">inline</span> <span class="Normal">int32_t</span>* <a href='010vm.cc.html#L227'>mem_addr_i32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L228" class="LineNr">228 </span> <span class="Identifier">return</span> <span class="Normal">reinterpret_cast</span><<span class="Normal">int32_t</span>*><span class="Delimiter">(</span><a href='010vm.cc.html#L211'>mem_addr_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L229" class="LineNr">229 </span><span class="Delimiter">}</span> +<span id="L230" class="LineNr">230 </span><span class="Normal">inline</span> <span class="Normal">float</span>* <a href='010vm.cc.html#L230'>mem_addr_f32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L231" class="LineNr">231 </span> <span class="Identifier">return</span> <span class="Normal">reinterpret_cast</span><<span class="Normal">float</span>*><span class="Delimiter">(</span><a href='010vm.cc.html#L211'>mem_addr_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L232" class="LineNr">232 </span><span class="Delimiter">}</span> +<span id="L233" class="LineNr">233 </span><span class="Comment">// helper for some syscalls. But read-only.</span> +<span id="L234" class="LineNr">234 </span><span class="Normal">inline</span> <span class="Normal">const</span> <span class="Normal">char</span>* <a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L235" class="LineNr">235 </span> <span class="Identifier">return</span> <span class="Normal">reinterpret_cast</span><<span class="Normal">const</span> <span class="Normal">char</span>*><span class="Delimiter">(</span><a href='010vm.cc.html#L192'>mem_addr_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L236" class="LineNr">236 </span><span class="Delimiter">}</span> +<span id="L237" class="LineNr">237 </span><span class="Normal">inline</span> string <a href='010vm.cc.html#L237'>mem_addr_string</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> size<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L238" class="LineNr">238 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L239" class="LineNr">239 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < size<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> +<span id="L240" class="LineNr">240 </span> out << <a href='010vm.cc.html#L174'>read_mem_u8</a><span class="Delimiter">(</span>addr+i<span class="Delimiter">);</span> +<span id="L241" class="LineNr">241 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L242" class="LineNr">242 </span><span class="Delimiter">}</span> +<span id="L243" class="LineNr">243 </span> +<span id="L244" class="LineNr">244 </span><span class="Normal">inline</span> <span class="Normal">void</span> <a href='010vm.cc.html#L244'>write_mem_u8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">uint8_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L245" class="LineNr">245 </span> <span class="Normal">uint8_t</span>* handle = <a href='010vm.cc.html#L192'>mem_addr_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L246" class="LineNr">246 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>handle != <span class="Constant">NULL</span><span class="Delimiter">)</span> *handle = val<span class="Delimiter">;</span> +<span id="L247" class="LineNr">247 </span><span class="Delimiter">}</span> +<span id="L248" class="LineNr">248 </span><span class="Normal">inline</span> <span class="Normal">void</span> <a href='010vm.cc.html#L248'>write_mem_i8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">int8_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L249" class="LineNr">249 </span> <span class="Normal">int8_t</span>* handle = <a href='010vm.cc.html#L208'>mem_addr_i8</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L250" class="LineNr">250 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>handle != <span class="Constant">NULL</span><span class="Delimiter">)</span> *handle = val<span class="Delimiter">;</span> +<span id="L251" class="LineNr">251 </span><span class="Delimiter">}</span> +<span id="L252" class="LineNr">252 </span><span class="Normal">inline</span> <span class="Normal">void</span> <a href='010vm.cc.html#L252'>write_mem_u32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L253" class="LineNr">253 </span> <span class="Normal">uint32_t</span>* handle = <a href='010vm.cc.html#L211'>mem_addr_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L254" class="LineNr">254 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>handle != <span class="Constant">NULL</span><span class="Delimiter">)</span> *handle = val<span class="Delimiter">;</span> +<span id="L255" class="LineNr">255 </span><span class="Delimiter">}</span> +<span id="L256" class="LineNr">256 </span><span class="Normal">inline</span> <span class="Normal">void</span> <a href='010vm.cc.html#L256'>write_mem_i32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">int32_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L257" class="LineNr">257 </span> <span class="Normal">int32_t</span>* handle = <a href='010vm.cc.html#L227'>mem_addr_i32</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L258" class="LineNr">258 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>handle != <span class="Constant">NULL</span><span class="Delimiter">)</span> *handle = val<span class="Delimiter">;</span> +<span id="L259" class="LineNr">259 </span><span class="Delimiter">}</span> +<span id="L260" class="LineNr">260 </span> +<span id="L261" class="LineNr">261 </span><span class="Normal">inline</span> <span class="Normal">bool</span> <a href='010vm.cc.html#L261'>already_allocated</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L262" class="LineNr">262 </span> <span class="Normal">bool</span> result = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L263" class="LineNr">263 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span><a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L264" class="LineNr">264 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='010vm.cc.html#L111'>match</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L265" class="LineNr">265 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> +<span id="L266" class="LineNr">266 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"address 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" is in two <a href='011run.cc.html#L106'>segments</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L267" class="LineNr">267 </span> result = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L268" class="LineNr">268 </span> <span class="Delimiter">}</span> +<span id="L269" class="LineNr">269 </span> <span class="Delimiter">}</span> +<span id="L270" class="LineNr">270 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L271" class="LineNr">271 </span><span class="Delimiter">}</span> +<span id="L272" class="LineNr">272 </span> +<span id="L273" class="LineNr">273 </span><span class="Comment">//:: core interpreter loop</span> +<span id="L274" class="LineNr">274 </span> +<span id="L275" class="LineNr">275 </span><span class="Delimiter">:(code)</span> +<span id="L276" class="LineNr">276 </span><span class="Comment">// skeleton of how x86 instructions are decoded</span> +<span id="L277" class="LineNr">277 </span><span class="Normal">void</span> <a href='010vm.cc.html#L277'>run_one_instruction</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L278" class="LineNr">278 </span> <span class="Normal">uint8_t</span> op=<span class="Constant">0</span><span class="Delimiter">,</span> op2=<span class="Constant">0</span><span class="Delimiter">,</span> op3=<span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L279" class="LineNr">279 </span> <span class="Comment">// Run One Instruction</span> +<span id="L280" class="LineNr">280 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L281" class="LineNr">281 </span> <a href='010vm.cc.html#L342'>dump_registers</a><span class="Delimiter">();</span> +<span id="L282" class="LineNr">282 </span> <span class="Comment">// End Dump Info for Instruction</span> +<span id="L283" class="LineNr">283 </span> <span class="Delimiter">}</span> +<span id="L284" class="LineNr">284 </span> <span class="Normal">uint32_t</span> inst_start_address = <a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">;</span> +<span id="L285" class="LineNr">285 </span> op = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L286" class="LineNr">286 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << inst_start_address << <span class="Constant">" opcode: "</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L287" class="LineNr">287 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L288" class="LineNr">288 </span> <span class="Normal">case</span> <span class="Constant">0xf4</span>: <span class="Comment">// hlt</span> +<span id="L289" class="LineNr">289 </span> <a href='010vm.cc.html#L26'>EIP</a> = <a href='010vm.cc.html#L166'>End_of_program</a><span class="Delimiter">;</span> +<span id="L290" class="LineNr">290 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L291" class="LineNr">291 </span> <span class="Comment">// End Single-Byte Opcodes</span> +<span id="L292" class="LineNr">292 </span> <span class="Normal">case</span> <span class="Constant">0x0f</span>: +<span id="L293" class="LineNr">293 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op2 = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L294" class="LineNr">294 </span> <span class="Comment">// End Two-Byte Opcodes Starting With 0f</span> +<span id="L295" class="LineNr">295 </span> <span class="Normal">default</span>: +<span id="L296" class="LineNr">296 </span> cerr << <span class="Constant">"unrecognized second opcode after 0f: "</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>op2<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L297" class="LineNr">297 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L298" class="LineNr">298 </span> <span class="Delimiter">}</span> +<span id="L299" class="LineNr">299 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L300" class="LineNr">300 </span> <span class="Normal">case</span> <span class="Constant">0xf2</span>: +<span id="L301" class="LineNr">301 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op2 = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L302" class="LineNr">302 </span> <span class="Comment">// End Two-Byte Opcodes Starting With f2</span> +<span id="L303" class="LineNr">303 </span> <span class="Normal">case</span> <span class="Constant">0x0f</span>: +<span id="L304" class="LineNr">304 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op3 = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L305" class="LineNr">305 </span> <span class="Comment">// End Three-Byte Opcodes Starting With f2 0f</span> +<span id="L306" class="LineNr">306 </span> <span class="Normal">default</span>: +<span id="L307" class="LineNr">307 </span> cerr << <span class="Constant">"unrecognized third opcode after f2 0f: "</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>op3<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L308" class="LineNr">308 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L309" class="LineNr">309 </span> <span class="Delimiter">}</span> +<span id="L310" class="LineNr">310 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L311" class="LineNr">311 </span> <span class="Normal">default</span>: +<span id="L312" class="LineNr">312 </span> cerr << <span class="Constant">"unrecognized second opcode after f2: "</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>op2<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L313" class="LineNr">313 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L314" class="LineNr">314 </span> <span class="Delimiter">}</span> +<span id="L315" class="LineNr">315 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L316" class="LineNr">316 </span> <span class="Normal">case</span> <span class="Constant">0xf3</span>: +<span id="L317" class="LineNr">317 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op2 = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L318" class="LineNr">318 </span> <span class="Comment">// End Two-Byte Opcodes Starting With f3</span> +<span id="L319" class="LineNr">319 </span> <span class="Normal">case</span> <span class="Constant">0x0f</span>: +<span id="L320" class="LineNr">320 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op3 = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L321" class="LineNr">321 </span> <span class="Comment">// End Three-Byte Opcodes Starting With f3 0f</span> +<span id="L322" class="LineNr">322 </span> <span class="Normal">default</span>: +<span id="L323" class="LineNr">323 </span> cerr << <span class="Constant">"unrecognized third opcode after f3 0f: "</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>op3<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L324" class="LineNr">324 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L325" class="LineNr">325 </span> <span class="Delimiter">}</span> +<span id="L326" class="LineNr">326 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L327" class="LineNr">327 </span> <span class="Normal">default</span>: +<span id="L328" class="LineNr">328 </span> cerr << <span class="Constant">"unrecognized second opcode after f3: "</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>op2<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L329" class="LineNr">329 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L330" class="LineNr">330 </span> <span class="Delimiter">}</span> +<span id="L331" class="LineNr">331 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L332" class="LineNr">332 </span> <span class="Normal">default</span>: +<span id="L333" class="LineNr">333 </span> cerr << <span class="Constant">"unrecognized opcode: "</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L334" class="LineNr">334 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L335" class="LineNr">335 </span> <span class="Delimiter">}</span> +<span id="L336" class="LineNr">336 </span><span class="Delimiter">}</span> +<span id="L337" class="LineNr">337 </span> +<span id="L338" class="LineNr">338 </span><span class="Normal">inline</span> <span class="Normal">uint8_t</span> <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L339" class="LineNr">339 </span> <span class="Identifier">return</span> <a href='010vm.cc.html#L174'>read_mem_u8</a><span class="Delimiter">(</span>EIP++<span class="Delimiter">);</span> +<span id="L340" class="LineNr">340 </span><span class="Delimiter">}</span> +<span id="L341" class="LineNr">341 </span> +<span id="L342" class="LineNr">342 </span><span class="Normal">void</span> <a href='010vm.cc.html#L342'>dump_registers</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L343" class="LineNr">343 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L344" class="LineNr">344 </span> out << <span class="Constant">"regs: "</span><span class="Delimiter">;</span> +<span id="L345" class="LineNr">345 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='010vm.cc.html#L18'>NUM_INT_REGISTERS</a><span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L346" class="LineNr">346 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">" "</span><span class="Delimiter">;</span> +<span id="L347" class="LineNr">347 </span> out << i << <span class="Constant">": "</span> << std::hex << std::setw<span class="Delimiter">(</span><span class="Constant">8</span><span class="Delimiter">)</span> << std::setfill<span class="Delimiter">(</span><span class="Constant">'_'</span><span class="Delimiter">)</span> << Reg[i]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L348" class="LineNr">348 </span> <span class="Delimiter">}</span> +<span id="L349" class="LineNr">349 </span> out << <span class="Constant">" -- SF: "</span> << SF << <span class="Constant">"; <a href='010vm.cc.html#L89'>ZF</a>: "</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; <a href='010vm.cc.html#L90'>CF</a>: "</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; <a href='010vm.cc.html#L91'>OF</a>: "</span> << <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">;</span> +<span id="L350" class="LineNr">350 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << out<span class="Delimiter">.</span>str<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> +<span id="L351" class="LineNr">351 </span><span class="Delimiter">}</span> +<span id="L352" class="LineNr">352 </span> +<span id="L353" class="LineNr">353 </span><span class="Comment">//: start tracking supported opcodes</span> +<span id="L354" class="LineNr">354 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L355" class="LineNr">355 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> string> <a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">;</span> +<span id="L356" class="LineNr">356 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> string> <a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">;</span> +<span id="L357" class="LineNr">357 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> string> <a href='010vm.cc.html#L357'>Name_f3</a><span class="Delimiter">;</span> +<span id="L358" class="LineNr">358 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> string> <a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">;</span> +<span id="L359" class="LineNr">359 </span><span class="Delimiter">:(before "End One-time Setup")</span> +<span id="L360" class="LineNr">360 </span><a href='010vm.cc.html#L362'>init_op_names</a><span class="Delimiter">();</span> +<span id="L361" class="LineNr">361 </span><span class="Delimiter">:(code)</span> +<span id="L362" class="LineNr">362 </span><span class="Normal">void</span> <a href='010vm.cc.html#L362'>init_op_names</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L363" class="LineNr">363 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"f4"</span><span class="Delimiter">,</span> <span class="Constant">"halt (hlt)"</span><span class="Delimiter">);</span> +<span id="L364" class="LineNr">364 </span> <span class="Comment">// End Initialize Op Names</span> +<span id="L365" class="LineNr">365 </span><span class="Delimiter">}</span> +<span id="L366" class="LineNr">366 </span> +<span id="L367" class="LineNr">367 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Special-cases(key)")</span> +<span id="L368" class="LineNr">368 </span><span class="Normal">if</span> <span class="Delimiter">(</span>key == <span class="Constant">"opcodes"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L369" class="LineNr">369 </span> cerr << <span class="Constant">"Opcodes currently supported by SubX:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L370" class="LineNr">370 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> string>::iterator p = <a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> +<span id="L371" class="LineNr">371 </span> cerr << <span class="Constant">" "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L372" class="LineNr">372 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> string>::iterator p = <a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> +<span id="L373" class="LineNr">373 </span> cerr << <span class="Constant">" 0f "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L374" class="LineNr">374 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> string>::iterator p = <a href='010vm.cc.html#L357'>Name_f3</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='010vm.cc.html#L357'>Name_f3</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> +<span id="L375" class="LineNr">375 </span> cerr << <span class="Constant">" f3 "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L376" class="LineNr">376 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> string>::iterator p = <a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> +<span id="L377" class="LineNr">377 </span> cerr << <span class="Constant">" f3 0f "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L378" class="LineNr">378 </span> cerr << <span class="Constant">"Run `bootstrap help instructions` for details on <a href='011run.cc.html#L122'>words</a> like 'r32' and 'disp8'.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L379" class="LineNr">379 </span> <span class="Constant">"For complete details on these instructions, consult the IA-32 manual (volume 2).</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L380" class="LineNr">380 </span> <span class="Constant">"There's various versions of it online, such as <a href="https://c9x.me/x86.">https://c9x.me/x86.</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L381" class="LineNr">381 </span> <span class="Constant">"The mnemonics in brackets will help you locate each instruction.</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L382" class="LineNr">382 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L383" class="LineNr">383 </span><span class="Delimiter">}</span> +<span id="L384" class="LineNr">384 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Contents")</span> +<span id="L385" class="LineNr">385 </span>cerr << <span class="Constant">" opcodes</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L386" class="LineNr">386 </span> +<span id="L387" class="LineNr">387 </span><span class="Comment">//: Helpers for managing trace depths</span> +<span id="L388" class="LineNr">388 </span><span class="Comment">//:</span> +<span id="L389" class="LineNr">389 </span><span class="Comment">//: We're going to use trace depths primarily to segment code running at</span> +<span id="L390" class="LineNr">390 </span><span class="Comment">//: different frames of the call stack. This will make it easy for the trace</span> +<span id="L391" class="LineNr">391 </span><span class="Comment">//: browser to collapse over entire calls.</span> +<span id="L392" class="LineNr">392 </span><span class="Comment">//:</span> +<span id="L393" class="LineNr">393 </span><span class="Comment">//: Errors will be at depth 0.</span> +<span id="L394" class="LineNr">394 </span><span class="Comment">//: Warnings will be at depth 1.</span> +<span id="L395" class="LineNr">395 </span><span class="Comment">//: SubX instructions will occupy depth 2 and up to Max_depth, organized by</span> +<span id="L396" class="LineNr">396 </span><span class="Comment">//: stack frames. Each instruction's internal details will be one level deeper</span> +<span id="L397" class="LineNr">397 </span><span class="Comment">//: than its 'main' depth. So 'call' instruction details will be at the same</span> +<span id="L398" class="LineNr">398 </span><span class="Comment">//: depth as the instructions of the function it calls.</span> +<span id="L399" class="LineNr">399 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L400" class="LineNr">400 </span><span class="Normal">extern</span> <span class="Normal">const</span> <span class="Normal">int</span> <a href='010vm.cc.html#L400'>Initial_callstack_depth</a> = <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L401" class="LineNr">401 </span><span class="Normal">int</span> Callstack_depth = <a href='010vm.cc.html#L400'>Initial_callstack_depth</a><span class="Delimiter">;</span> +<span id="L402" class="LineNr">402 </span><span class="Delimiter">:(before "End Reset")</span> +<span id="L403" class="LineNr">403 </span>Callstack_depth = <a href='010vm.cc.html#L400'>Initial_callstack_depth</a><span class="Delimiter">;</span> +<span id="L404" class="LineNr">404 </span> +<span id="L405" class="LineNr">405 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L406" class="LineNr">406 </span><span class="PreProc">#include </span><span class="Constant"><iomanip></span> +<span id="L407" class="LineNr">407 </span><span class="PreProc">#define HEXBYTE std::hex << std::setw(</span><span class="Constant">2</span><span class="PreProc">) << std::setfill(</span><span class="Constant">'0'</span><span class="PreProc">)</span> +<span id="L408" class="LineNr">408 </span><span class="PreProc">#define HEXWORD std::hex << std::setw(</span><span class="Constant">8</span><span class="PreProc">) << std::setfill(</span><span class="Constant">'0'</span><span class="PreProc">)</span> +<span id="L409" class="LineNr">409 </span><span class="Comment">// ugly that iostream doesn't print uint8_t as an integer</span> +<span id="L410" class="LineNr">410 </span><span class="PreProc">#define NUM(X) </span><span class="Normal">static_cast</span><span class="PreProc"><</span><span class="Normal">int</span><span class="PreProc">>(X)</span> +<span id="L411" class="LineNr">411 </span><span class="PreProc">#include </span><span class="Constant"><stdint.h></span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/011run.cc.html b/html/linux/bootstrap/011run.cc.html new file mode 100644 index 00000000..bc7b84ae --- /dev/null +++ b/html/linux/bootstrap/011run.cc.html @@ -0,0 +1,515 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/011run.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.LineNr { } +.Constant { color: #008787; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/011run.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/011run.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: Running SubX programs on the VM.</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: (Not to be confused with the 'run' subcommand for running ELF binaries on</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: the VM. That comes later.)</span> +<span id="L5" class="LineNr"> 5 </span> +<span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Texts")</span> +<span id="L7" class="LineNr"> 7 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"syntax"</span><span class="Delimiter">,</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Constant">"SubX programs consist of <a href='011run.cc.html#L106'>segments</a>, each segment in turn consisting of lines.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Constant">"Line-endings are significant; each <a href='011run.cc.html#L121'>line</a> should contain a single</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L10" class="LineNr"> 10 </span> <span class="Constant">"instruction, macro or directive.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Constant">"Comments start with the '#' character. It should be at the start of a <a href='011run.cc.html#L127'>word</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Constant">"(start of <a href='011run.cc.html#L121'>line</a>, or following a space).</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Constant">"Each segment starts with a header <a href='011run.cc.html#L121'>line</a>: a '==' delimiter followed by the <a href='011run.cc.html#L111'>name</a> of</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Constant">"the segment and a (sometimes approximate) starting address in memory.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Constant">"The <a href='011run.cc.html#L111'>name</a> 'code' is special; instructions to execute should always go here.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"The resulting binary starts running code from a label called 'Entry'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"in the code segment.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L22" class="LineNr"> 22 </span> <span class="Constant">"Segments with the same <a href='011run.cc.html#L111'>name</a> get merged together. This rule helps keep functions</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L23" class="LineNr"> 23 </span> <span class="Constant">"and their data close together in .subx files.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Constant">"You don't have to specify the starting address after the first time.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L26" class="LineNr"> 26 </span> <span class="Constant">"Lines consist of a series of words. Words can contain arbitrary metadata</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Constant">"after a '/', but they can never contain whitespace. Metadata has no effect</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L28" class="LineNr"> 28 </span> <span class="Constant">"at runtime, but can be handy when rewriting macros.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Constant">"Check out the example programs in the apps/ directory, particularly apps/ex*.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L31" class="LineNr"> 31 </span><span class="Delimiter">);</span> +<span id="L32" class="LineNr"> 32 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Contents")</span> +<span id="L33" class="LineNr"> 33 </span>cerr << <span class="Constant">" syntax</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L34" class="LineNr"> 34 </span> +<span id="L35" class="LineNr"> 35 </span><span class="Delimiter">:(code)</span> +<span id="L36" class="LineNr"> 36 </span><span class="Normal">void</span> <a href='011run.cc.html#L36'>test_copy_imm32_to_EAX</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Comment">// At the lowest level, SubX programs are a series of hex bytes, each</span> +<span id="L38" class="LineNr"> 38 </span> <span class="Comment">// (variable-length) instruction on one line.</span> +<span id="L39" class="LineNr"> 39 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L40" class="LineNr"> 40 </span> <span class="Comment">// Comments start with '#' and are ignored.</span> +<span id="L41" class="LineNr"> 41 </span> <span class="Constant">"# comment</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Comment">// Segment headers start with '==', a name and a starting hex address.</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Comment">// There's usually one code and one data segment. The code segment</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Comment">// always comes first.</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L46" class="LineNr"> 46 </span> +<span id="L47" class="LineNr"> 47 </span> <span class="Comment">// After the header, each segment consists of lines, and each line</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Comment">// consists of words separated by whitespace.</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Comment">//</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Comment">// All words can have metadata after a '/'. No spaces allowed in</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Comment">// metadata, of course.</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Comment">// Unrecognized metadata never causes errors, so you can use it for</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Comment">// documentation.</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Comment">//</span> +<span id="L55" class="LineNr"> 55 </span> <span class="Comment">// Within the code segment in particular, x86 instructions consist of</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Comment">// some number of the following parts and sub-parts (see the Readme and</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Comment">// cheatsheet.pdf for details):</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Comment">// opcodes: 1-3 bytes</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Comment">// ModR/M byte</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Comment">// SIB byte</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Comment">// displacement: 0/1/2/4 bytes</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Comment">// immediate: 0/1/2/4 bytes</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Comment">// opcode ModR/M SIB displacement immediate</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Comment">// instruction mod, reg, Reg/Mem bits scale, index, base</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Comment">// 1-3 bytes 0/1 byte 0/1 byte 0/1/2/4 bytes 0/1/2/4 bytes</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Constant">" b8 . . . 0a 0b 0c 0d</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy 0x0d0c0b0a to EAX</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Comment">// The periods are just to help the eye track long gaps between columns,</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Comment">// and are otherwise ignored.</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Delimiter">);</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Comment">// This program, when run, causes the following events in the trace:</span> +<span id="L71" class="LineNr"> 71 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Constant">"load: 0x00000001 -> b8</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">"load: 0x00000002 -> 0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Constant">"load: 0x00000003 -> 0b</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Constant">"load: 0x00000004 -> 0c</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L76" class="LineNr"> 76 </span> <span class="Constant">"load: 0x00000005 -> 0d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Constant">"run: copy imm32 0x0d0c0b0a to <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Delimiter">);</span> +<span id="L79" class="LineNr"> 79 </span><span class="Delimiter">}</span> +<span id="L80" class="LineNr"> 80 </span> +<span id="L81" class="LineNr"> 81 </span><span class="Comment">// top-level helper for tests: parse the input, load the hex bytes into memory, run</span> +<span id="L82" class="LineNr"> 82 </span><span class="Normal">void</span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span><span class="Normal">const</span> string& text_bytes<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L83" class="LineNr"> 83 </span> program p<span class="Delimiter">;</span> +<span id="L84" class="LineNr"> 84 </span> istringstream in<span class="Delimiter">(</span>text_bytes<span class="Delimiter">);</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Comment">// Loading Test Program</span> +<span id="L86" class="LineNr"> 86 </span> parse<span class="Delimiter">(</span>in<span class="Delimiter">,</span> p<span class="Delimiter">);</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// if any stage raises errors, stop immediately</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Comment">// Running Test Program</span> +<span id="L89" class="LineNr"> 89 </span> <a href='011run.cc.html#L248'>load</a><span class="Delimiter">(</span>p<span class="Delimiter">);</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Comment">// convenience to keep tests concise: 'Entry' label need not be provided</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Comment">// not allowed in real programs</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L105'>entry</a><span class="Delimiter">)</span> +<span id="L94" class="LineNr"> 94 </span> <a href='010vm.cc.html#L26'>EIP</a> = p<span class="Delimiter">.</span><a href='011run.cc.html#L105'>entry</a><span class="Delimiter">;</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Normal">else</span> +<span id="L96" class="LineNr"> 96 </span> <a href='010vm.cc.html#L26'>EIP</a> = find<span class="Delimiter">(</span>p<span class="Delimiter">,</span> <span class="Constant">"code"</span><span class="Delimiter">)-></span>start<span class="Delimiter">;</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L26'>EIP</a> < <a href='010vm.cc.html#L166'>End_of_program</a><span class="Delimiter">)</span> +<span id="L98" class="LineNr"> 98 </span> <a href='010vm.cc.html#L277'>run_one_instruction</a><span class="Delimiter">();</span> +<span id="L99" class="LineNr"> 99 </span><span class="Delimiter">}</span> +<span id="L100" class="LineNr">100 </span> +<span id="L101" class="LineNr">101 </span><span class="Comment">//:: core data structures</span> +<span id="L102" class="LineNr">102 </span> +<span id="L103" class="LineNr">103 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L104" class="LineNr">104 </span><span class="Normal">struct</span> program <span class="Delimiter">{</span> +<span id="L105" class="LineNr">105 </span> <span class="Normal">uint32_t</span> <a href='011run.cc.html#L105'>entry</a><span class="Delimiter">;</span> +<span id="L106" class="LineNr">106 </span> vector<segment> <a href='011run.cc.html#L106'>segments</a><span class="Delimiter">;</span> +<span id="L107" class="LineNr">107 </span> program<span class="Delimiter">()</span> <span class="Delimiter">{</span> <a href='011run.cc.html#L105'>entry</a> = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> +<span id="L108" class="LineNr">108 </span><span class="Delimiter">};</span> +<span id="L109" class="LineNr">109 </span><span class="Delimiter">:(before "struct program")</span> +<span id="L110" class="LineNr">110 </span><span class="Normal">struct</span> segment <span class="Delimiter">{</span> +<span id="L111" class="LineNr">111 </span> string <a href='011run.cc.html#L111'>name</a><span class="Delimiter">;</span> +<span id="L112" class="LineNr">112 </span> <span class="Normal">uint32_t</span> start<span class="Delimiter">;</span> +<span id="L113" class="LineNr">113 </span> vector<line> <a href='011run.cc.html#L113'>lines</a><span class="Delimiter">;</span> +<span id="L114" class="LineNr">114 </span> <span class="Comment">// End segment Fields</span> +<span id="L115" class="LineNr">115 </span> segment<span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L116" class="LineNr">116 </span> start = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L117" class="LineNr">117 </span> <span class="Comment">// End segment Constructor</span> +<span id="L118" class="LineNr">118 </span> <span class="Delimiter">}</span> +<span id="L119" class="LineNr">119 </span><span class="Delimiter">};</span> +<span id="L120" class="LineNr">120 </span><span class="Delimiter">:(before "struct segment")</span> +<span id="L121" class="LineNr">121 </span><span class="Normal">struct</span> <a href='011run.cc.html#L121'>line</a> <span class="Delimiter">{</span> +<span id="L122" class="LineNr">122 </span> vector<word> <a href='011run.cc.html#L122'>words</a><span class="Delimiter">;</span> +<span id="L123" class="LineNr">123 </span> vector<string> metadata<span class="Delimiter">;</span> +<span id="L124" class="LineNr">124 </span> string original<span class="Delimiter">;</span> +<span id="L125" class="LineNr">125 </span><span class="Delimiter">};</span> +<span id="L126" class="LineNr">126 </span><span class="Delimiter">:(before "struct line")</span> +<span id="L127" class="LineNr">127 </span><span class="Normal">struct</span> <a href='011run.cc.html#L127'>word</a> <span class="Delimiter">{</span> +<span id="L128" class="LineNr">128 </span> string original<span class="Delimiter">;</span> +<span id="L129" class="LineNr">129 </span> string data<span class="Delimiter">;</span> +<span id="L130" class="LineNr">130 </span> vector<string> metadata<span class="Delimiter">;</span> +<span id="L131" class="LineNr">131 </span><span class="Delimiter">};</span> +<span id="L132" class="LineNr">132 </span> +<span id="L133" class="LineNr">133 </span><span class="Comment">//:: parse</span> +<span id="L134" class="LineNr">134 </span> +<span id="L135" class="LineNr">135 </span><span class="Delimiter">:(code)</span> +<span id="L136" class="LineNr">136 </span><span class="Normal">void</span> parse<span class="Delimiter">(</span>istream& fin<span class="Delimiter">,</span> program& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L137" class="LineNr">137 </span> segment* curr_segment = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L138" class="LineNr">138 </span> vector<line> l<span class="Delimiter">;</span> +<span id="L139" class="LineNr">139 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L249'>has_data</a><span class="Delimiter">(</span>fin<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L140" class="LineNr">140 </span> string line_data<span class="Delimiter">;</span> +<span id="L141" class="LineNr">141 </span> <a href='011run.cc.html#L121'>line</a> curr<span class="Delimiter">;</span> +<span id="L142" class="LineNr">142 </span> getline<span class="Delimiter">(</span>fin<span class="Delimiter">,</span> line_data<span class="Delimiter">);</span> +<span id="L143" class="LineNr">143 </span> curr<span class="Delimiter">.</span>original = line_data<span class="Delimiter">;</span> +<span id="L144" class="LineNr">144 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"line: "</span> << line_data << end<span class="Delimiter">();</span> +<span id="L145" class="LineNr">145 </span> <span class="Comment">// End Line Parsing Special-cases(line_data -> l)</span> +<span id="L146" class="LineNr">146 </span> istringstream lin<span class="Delimiter">(</span>line_data<span class="Delimiter">);</span> +<span id="L147" class="LineNr">147 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L249'>has_data</a><span class="Delimiter">(</span>lin<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L148" class="LineNr">148 </span> string word_data<span class="Delimiter">;</span> +<span id="L149" class="LineNr">149 </span> lin >> word_data<span class="Delimiter">;</span> +<span id="L150" class="LineNr">150 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>word_data<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L151" class="LineNr">151 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>word_data[<span class="Constant">0</span>] == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// comment</span> +<span id="L152" class="LineNr">152 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>word_data == <span class="Constant">"."</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// comment token</span> +<span id="L153" class="LineNr">153 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>word_data == <span class="Constant">"=="</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L154" class="LineNr">154 </span> <a href='011run.cc.html#L198'>flush</a><span class="Delimiter">(</span>curr_segment<span class="Delimiter">,</span> l<span class="Delimiter">);</span> +<span id="L155" class="LineNr">155 </span> string segment_name<span class="Delimiter">;</span> +<span id="L156" class="LineNr">156 </span> lin >> segment_name<span class="Delimiter">;</span> +<span id="L157" class="LineNr">157 </span> curr_segment = find<span class="Delimiter">(</span>out<span class="Delimiter">,</span> segment_name<span class="Delimiter">);</span> +<span id="L158" class="LineNr">158 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr_segment != <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L159" class="LineNr">159 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"appending to segment '"</span> << segment_name << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> +<span id="L160" class="LineNr">160 </span> <span class="Delimiter">}</span> +<span id="L161" class="LineNr">161 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L162" class="LineNr">162 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"new segment '"</span> << segment_name << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> +<span id="L163" class="LineNr">163 </span> <span class="Normal">uint32_t</span> seg_start = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L164" class="LineNr">164 </span> lin >> std::hex >> seg_start<span class="Delimiter">;</span> +<span id="L165" class="LineNr">165 </span> <a href='011run.cc.html#L219'>sanity_check_program_segment</a><span class="Delimiter">(</span>out<span class="Delimiter">,</span> seg_start<span class="Delimiter">);</span> +<span id="L166" class="LineNr">166 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>segment<span class="Delimiter">());</span> +<span id="L167" class="LineNr">167 </span> curr_segment = &out<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>back<span class="Delimiter">();</span> +<span id="L168" class="LineNr">168 </span> curr_segment<span class="Delimiter">-></span><a href='011run.cc.html#L111'>name</a> = segment_name<span class="Delimiter">;</span> +<span id="L169" class="LineNr">169 </span> curr_segment<span class="Delimiter">-></span>start = seg_start<span class="Delimiter">;</span> +<span id="L170" class="LineNr">170 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L171" class="LineNr">171 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"starts at address 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << curr_segment<span class="Delimiter">-></span>start << end<span class="Delimiter">();</span> +<span id="L172" class="LineNr">172 </span> <span class="Delimiter">}</span> +<span id="L173" class="LineNr">173 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// skip rest of line</span> +<span id="L174" class="LineNr">174 </span> <span class="Delimiter">}</span> +<span id="L175" class="LineNr">175 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>word_data[<span class="Constant">0</span>] == <span class="Constant">':'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L176" class="LineNr">176 </span> <span class="Comment">// todo: line metadata</span> +<span id="L177" class="LineNr">177 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L178" class="LineNr">178 </span> <span class="Delimiter">}</span> +<span id="L179" class="LineNr">179 </span> curr<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='011run.cc.html#L127'>word</a><span class="Delimiter">());</span> +<span id="L180" class="LineNr">180 </span> <a href='011run.cc.html#L209'>parse_word</a><span class="Delimiter">(</span>word_data<span class="Delimiter">,</span> curr<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">());</span> +<span id="L181" class="LineNr">181 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"word: "</span> << to_string<span class="Delimiter">(</span>curr<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">());</span> +<span id="L182" class="LineNr">182 </span> <span class="Delimiter">}</span> +<span id="L183" class="LineNr">183 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!curr<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> +<span id="L184" class="LineNr">184 </span> l<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L185" class="LineNr">185 </span> <span class="Delimiter">}</span> +<span id="L186" class="LineNr">186 </span> <a href='011run.cc.html#L198'>flush</a><span class="Delimiter">(</span>curr_segment<span class="Delimiter">,</span> l<span class="Delimiter">);</span> +<span id="L187" class="LineNr">187 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"done"</span> << end<span class="Delimiter">();</span> +<span id="L188" class="LineNr">188 </span><span class="Delimiter">}</span> +<span id="L189" class="LineNr">189 </span> +<span id="L190" class="LineNr">190 </span>segment* find<span class="Delimiter">(</span>program& p<span class="Delimiter">,</span> <span class="Normal">const</span> string& segment_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L191" class="LineNr">191 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L192" class="LineNr">192 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='011run.cc.html#L111'>name</a> == segment_name<span class="Delimiter">)</span> +<span id="L193" class="LineNr">193 </span> <span class="Identifier">return</span> &p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L194" class="LineNr">194 </span> <span class="Delimiter">}</span> +<span id="L195" class="LineNr">195 </span> <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L196" class="LineNr">196 </span><span class="Delimiter">}</span> +<span id="L197" class="LineNr">197 </span> +<span id="L198" class="LineNr">198 </span><span class="Normal">void</span> <a href='011run.cc.html#L198'>flush</a><span class="Delimiter">(</span>segment* s<span class="Delimiter">,</span> vector<line>& <a href='011run.cc.html#L113'>lines</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L199" class="LineNr">199 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L200" class="LineNr">200 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L201" class="LineNr">201 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"input does not start with a '==' section header</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L202" class="LineNr">202 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L203" class="LineNr">203 </span> <span class="Delimiter">}</span> +<span id="L204" class="LineNr">204 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"flushing segment"</span> << end<span class="Delimiter">();</span> +<span id="L205" class="LineNr">205 </span> s<span class="Delimiter">-></span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span>s<span class="Delimiter">-></span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> <a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L206" class="LineNr">206 </span> <a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>clear<span class="Delimiter">();</span> +<span id="L207" class="LineNr">207 </span><span class="Delimiter">}</span> +<span id="L208" class="LineNr">208 </span> +<span id="L209" class="LineNr">209 </span><span class="Normal">void</span> <a href='011run.cc.html#L209'>parse_word</a><span class="Delimiter">(</span><span class="Normal">const</span> string& data<span class="Delimiter">,</span> word& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L210" class="LineNr">210 </span> out<span class="Delimiter">.</span>original = data<span class="Delimiter">;</span> +<span id="L211" class="LineNr">211 </span> istringstream win<span class="Delimiter">(</span>data<span class="Delimiter">);</span> +<span id="L212" class="LineNr">212 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>getline<span class="Delimiter">(</span>win<span class="Delimiter">,</span> out<span class="Delimiter">.</span>data<span class="Delimiter">,</span> <span class="Constant">'/'</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L213" class="LineNr">213 </span> string m<span class="Delimiter">;</span> +<span id="L214" class="LineNr">214 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>getline<span class="Delimiter">(</span>win<span class="Delimiter">,</span> m<span class="Delimiter">,</span> <span class="Constant">'/'</span><span class="Delimiter">))</span> +<span id="L215" class="LineNr">215 </span> out<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>m<span class="Delimiter">);</span> +<span id="L216" class="LineNr">216 </span> <span class="Delimiter">}</span> +<span id="L217" class="LineNr">217 </span><span class="Delimiter">}</span> +<span id="L218" class="LineNr">218 </span> +<span id="L219" class="LineNr">219 </span><span class="Normal">void</span> <a href='011run.cc.html#L219'>sanity_check_program_segment</a><span class="Delimiter">(</span><span class="Normal">const</span> program& p<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L220" class="LineNr">220 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L221" class="LineNr">221 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>start == addr<span class="Delimiter">)</span> +<span id="L222" class="LineNr">222 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"can't have multiple segments starting at address 0x"</span> << HEXWORD << addr << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L223" class="LineNr">223 </span> <span class="Delimiter">}</span> +<span id="L224" class="LineNr">224 </span><span class="Delimiter">}</span> +<span id="L225" class="LineNr">225 </span> +<span id="L226" class="LineNr">226 </span><span class="Comment">// helper for tests</span> +<span id="L227" class="LineNr">227 </span><span class="Normal">void</span> parse<span class="Delimiter">(</span><span class="Normal">const</span> string& text_bytes<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L228" class="LineNr">228 </span> program p<span class="Delimiter">;</span> +<span id="L229" class="LineNr">229 </span> istringstream in<span class="Delimiter">(</span>text_bytes<span class="Delimiter">);</span> +<span id="L230" class="LineNr">230 </span> parse<span class="Delimiter">(</span>in<span class="Delimiter">,</span> p<span class="Delimiter">);</span> +<span id="L231" class="LineNr">231 </span><span class="Delimiter">}</span> +<span id="L232" class="LineNr">232 </span> +<span id="L233" class="LineNr">233 </span><span class="Normal">void</span> <a href='011run.cc.html#L233'>test_detect_duplicate_segments</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L234" class="LineNr">234 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L235" class="LineNr">235 </span> parse<span class="Delimiter">(</span> +<span id="L236" class="LineNr">236 </span> <span class="Constant">"== segment1 0xee</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L237" class="LineNr">237 </span> <span class="Constant">"ab</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L238" class="LineNr">238 </span> <span class="Constant">"== segment2 0xee</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L239" class="LineNr">239 </span> <span class="Constant">"cd</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L240" class="LineNr">240 </span> <span class="Delimiter">);</span> +<span id="L241" class="LineNr">241 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L242" class="LineNr">242 </span> <span class="Constant">"error: can't have multiple segments starting at address 0x000000ee</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L243" class="LineNr">243 </span> <span class="Delimiter">);</span> +<span id="L244" class="LineNr">244 </span><span class="Delimiter">}</span> +<span id="L245" class="LineNr">245 </span> +<span id="L246" class="LineNr">246 </span><span class="Comment">//:: load</span> +<span id="L247" class="LineNr">247 </span> +<span id="L248" class="LineNr">248 </span><span class="Normal">void</span> <a href='011run.cc.html#L248'>load</a><span class="Delimiter">(</span><span class="Normal">const</span> program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L249" class="LineNr">249 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>find<span class="Delimiter">(</span>p<span class="Delimiter">,</span> <span class="Constant">"code"</span><span class="Delimiter">)</span> == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L250" class="LineNr">250 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"no code to <a href='011run.cc.html#L82'>run</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L251" class="LineNr">251 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L252" class="LineNr">252 </span> <span class="Delimiter">}</span> +<span id="L253" class="LineNr">253 </span> <span class="Comment">// Ensure segments are disjoint.</span> +<span id="L254" class="LineNr">254 </span> set<<span class="Normal">uint32_t</span>> overlap<span class="Delimiter">;</span> +<span id="L255" class="LineNr">255 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L256" class="LineNr">256 </span> <span class="Normal">const</span> segment& seg = p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L257" class="LineNr">257 </span> <span class="Normal">uint32_t</span> addr = seg<span class="Delimiter">.</span>start<span class="Delimiter">;</span> +<span id="L258" class="LineNr">258 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!already_allocated<span class="Delimiter">(</span>addr<span class="Delimiter">))</span> +<span id="L259" class="LineNr">259 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span>seg<span class="Delimiter">.</span>start<span class="Delimiter">));</span> +<span id="L260" class="LineNr">260 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"loading segment "</span> << i << <span class="Constant">" from "</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << end<span class="Delimiter">();</span> +<span id="L261" class="LineNr">261 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>seg<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L262" class="LineNr">262 </span> <span class="Normal">const</span> line& l = seg<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L263" class="LineNr">263 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> k = <span class="Constant">0</span><span class="Delimiter">;</span> k < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>l<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++k<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L264" class="LineNr">264 </span> <span class="Normal">const</span> word& w = l<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>k<span class="Delimiter">);</span> +<span id="L265" class="LineNr">265 </span> <span class="Normal">uint8_t</span> val = <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L266" class="LineNr">266 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L267" class="LineNr">267 </span> assert<span class="Delimiter">(</span>overlap<span class="Delimiter">.</span>find<span class="Delimiter">(</span>addr<span class="Delimiter">)</span> == overlap<span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L268" class="LineNr">268 </span> <a href='010vm.cc.html#L244'>write_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">,</span> val<span class="Delimiter">);</span> +<span id="L269" class="LineNr">269 </span> overlap<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L270" class="LineNr">270 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" -> "</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span><a href='010vm.cc.html#L174'>read_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> +<span id="L271" class="LineNr">271 </span> ++addr<span class="Delimiter">;</span> +<span id="L272" class="LineNr">272 </span> <span class="Delimiter">}</span> +<span id="L273" class="LineNr">273 </span> <span class="Delimiter">}</span> +<span id="L274" class="LineNr">274 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>seg<span class="Delimiter">.</span><a href='011run.cc.html#L111'>name</a> == <span class="Constant">"code"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L275" class="LineNr">275 </span> <a href='010vm.cc.html#L166'>End_of_program</a> = addr<span class="Delimiter">;</span> +<span id="L276" class="LineNr">276 </span> <span class="Delimiter">}</span> +<span id="L277" class="LineNr">277 </span> <span class="Delimiter">}</span> +<span id="L278" class="LineNr">278 </span><span class="Delimiter">}</span> +<span id="L279" class="LineNr">279 </span> +<span id="L280" class="LineNr">280 </span><span class="Normal">const</span> segment* find<span class="Delimiter">(</span><span class="Normal">const</span> program& p<span class="Delimiter">,</span> <span class="Normal">const</span> string& segment_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L281" class="LineNr">281 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L282" class="LineNr">282 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='011run.cc.html#L111'>name</a> == segment_name<span class="Delimiter">)</span> +<span id="L283" class="LineNr">283 </span> <span class="Identifier">return</span> &p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L284" class="LineNr">284 </span> <span class="Delimiter">}</span> +<span id="L285" class="LineNr">285 </span> <span class="Identifier">return</span> <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L286" class="LineNr">286 </span><span class="Delimiter">}</span> +<span id="L287" class="LineNr">287 </span> +<span id="L288" class="LineNr">288 </span><span class="Normal">uint8_t</span> <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L289" class="LineNr">289 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='011run.cc.html#L449'>contains_uppercase</a><span class="Delimiter">(</span>s<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L290" class="LineNr">290 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"uppercase hex not allowed: "</span> << s << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L291" class="LineNr">291 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L292" class="LineNr">292 </span> <span class="Delimiter">}</span> +<span id="L293" class="LineNr">293 </span> istringstream in<span class="Delimiter">(</span>s<span class="Delimiter">);</span> +<span id="L294" class="LineNr">294 </span> <span class="Normal">int</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L295" class="LineNr">295 </span> in >> std::hex >> result<span class="Delimiter">;</span> +<span id="L296" class="LineNr">296 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!in || !in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L297" class="LineNr">297 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"token '"</span> << s << <span class="Constant">"' is not a hex byte</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L298" class="LineNr">298 </span> <span class="Identifier">return</span> <span class="cSpecial">'\0'</span><span class="Delimiter">;</span> +<span id="L299" class="LineNr">299 </span> <span class="Delimiter">}</span> +<span id="L300" class="LineNr">300 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result > <span class="Constant">0xff</span> || result < -<span class="Constant">0x8f</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L301" class="LineNr">301 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"token '"</span> << s << <span class="Constant">"' is not a hex byte</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L302" class="LineNr">302 </span> <span class="Identifier">return</span> <span class="cSpecial">'\0'</span><span class="Delimiter">;</span> +<span id="L303" class="LineNr">303 </span> <span class="Delimiter">}</span> +<span id="L304" class="LineNr">304 </span> <span class="Identifier">return</span> <span class="Normal">static_cast</span><<span class="Normal">uint8_t</span>><span class="Delimiter">(</span>result<span class="Delimiter">);</span> +<span id="L305" class="LineNr">305 </span><span class="Delimiter">}</span> +<span id="L306" class="LineNr">306 </span> +<span id="L307" class="LineNr">307 </span><span class="Normal">void</span> <a href='011run.cc.html#L307'>test_number_too_large</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L308" class="LineNr">308 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L309" class="LineNr">309 </span> <a href='011run.cc.html#L397'>parse_and_load</a><span class="Delimiter">(</span> +<span id="L310" class="LineNr">310 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L311" class="LineNr">311 </span> <span class="Constant">"01 cab</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L312" class="LineNr">312 </span> <span class="Delimiter">);</span> +<span id="L313" class="LineNr">313 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L314" class="LineNr">314 </span> <span class="Constant">"error: token 'cab' is not a hex byte</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L315" class="LineNr">315 </span> <span class="Delimiter">);</span> +<span id="L316" class="LineNr">316 </span><span class="Delimiter">}</span> +<span id="L317" class="LineNr">317 </span> +<span id="L318" class="LineNr">318 </span><span class="Normal">void</span> <a href='011run.cc.html#L318'>test_invalid_hex</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L319" class="LineNr">319 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L320" class="LineNr">320 </span> <a href='011run.cc.html#L397'>parse_and_load</a><span class="Delimiter">(</span> +<span id="L321" class="LineNr">321 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L322" class="LineNr">322 </span> <span class="Constant">"01 cx</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L323" class="LineNr">323 </span> <span class="Delimiter">);</span> +<span id="L324" class="LineNr">324 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L325" class="LineNr">325 </span> <span class="Constant">"error: token 'cx' is not a hex byte</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L326" class="LineNr">326 </span> <span class="Delimiter">);</span> +<span id="L327" class="LineNr">327 </span><span class="Delimiter">}</span> +<span id="L328" class="LineNr">328 </span> +<span id="L329" class="LineNr">329 </span><span class="Normal">void</span> <a href='011run.cc.html#L329'>test_negative_number</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L330" class="LineNr">330 </span> <a href='011run.cc.html#L397'>parse_and_load</a><span class="Delimiter">(</span> +<span id="L331" class="LineNr">331 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L332" class="LineNr">332 </span> <span class="Constant">"01 -02</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L333" class="LineNr">333 </span> <span class="Delimiter">);</span> +<span id="L334" class="LineNr">334 </span> <a href='003trace.cc.html#L294'>CHECK_TRACE_COUNT</a><span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L335" class="LineNr">335 </span><span class="Delimiter">}</span> +<span id="L336" class="LineNr">336 </span> +<span id="L337" class="LineNr">337 </span><span class="Normal">void</span> <a href='011run.cc.html#L337'>test_negative_number_too_small</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L338" class="LineNr">338 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L339" class="LineNr">339 </span> <a href='011run.cc.html#L397'>parse_and_load</a><span class="Delimiter">(</span> +<span id="L340" class="LineNr">340 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L341" class="LineNr">341 </span> <span class="Constant">"01 -12345</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L342" class="LineNr">342 </span> <span class="Delimiter">);</span> +<span id="L343" class="LineNr">343 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L344" class="LineNr">344 </span> <span class="Constant">"error: token '-12345' is not a hex byte</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L345" class="LineNr">345 </span> <span class="Delimiter">);</span> +<span id="L346" class="LineNr">346 </span><span class="Delimiter">}</span> +<span id="L347" class="LineNr">347 </span> +<span id="L348" class="LineNr">348 </span><span class="Normal">void</span> <a href='011run.cc.html#L348'>test_hex_prefix</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L349" class="LineNr">349 </span> <a href='011run.cc.html#L397'>parse_and_load</a><span class="Delimiter">(</span> +<span id="L350" class="LineNr">350 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L351" class="LineNr">351 </span> <span class="Constant">"0x01 -0x02</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L352" class="LineNr">352 </span> <span class="Delimiter">);</span> +<span id="L353" class="LineNr">353 </span> <a href='003trace.cc.html#L294'>CHECK_TRACE_COUNT</a><span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L354" class="LineNr">354 </span><span class="Delimiter">}</span> +<span id="L355" class="LineNr">355 </span> +<span id="L356" class="LineNr">356 </span><span class="Normal">void</span> <a href='011run.cc.html#L356'>test_repeated_segment_merges_data</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L357" class="LineNr">357 </span> <a href='011run.cc.html#L397'>parse_and_load</a><span class="Delimiter">(</span> +<span id="L358" class="LineNr">358 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L359" class="LineNr">359 </span> <span class="Constant">"11 22</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L360" class="LineNr">360 </span> <span class="Constant">"== code</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// again</span> +<span id="L361" class="LineNr">361 </span> <span class="Constant">"33 44</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L362" class="LineNr">362 </span> <span class="Delimiter">);</span> +<span id="L363" class="LineNr">363 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L364" class="LineNr">364 </span> <span class="Constant">"parse: new segment 'code'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L365" class="LineNr">365 </span> <span class="Constant">"parse: appending to segment 'code'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L366" class="LineNr">366 </span> <span class="Comment">// first segment</span> +<span id="L367" class="LineNr">367 </span> <span class="Constant">"load: 0x00000001 -> 11</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L368" class="LineNr">368 </span> <span class="Constant">"load: 0x00000002 -> 22</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L369" class="LineNr">369 </span> <span class="Comment">// second segment</span> +<span id="L370" class="LineNr">370 </span> <span class="Constant">"load: 0x00000003 -> 33</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L371" class="LineNr">371 </span> <span class="Constant">"load: 0x00000004 -> 44</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L372" class="LineNr">372 </span> <span class="Delimiter">);</span> +<span id="L373" class="LineNr">373 </span><span class="Delimiter">}</span> +<span id="L374" class="LineNr">374 </span> +<span id="L375" class="LineNr">375 </span><span class="Normal">void</span> <a href='011run.cc.html#L375'>test_error_on_missing_segment_header</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L376" class="LineNr">376 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L377" class="LineNr">377 </span> <a href='011run.cc.html#L397'>parse_and_load</a><span class="Delimiter">(</span> +<span id="L378" class="LineNr">378 </span> <span class="Constant">"01 02</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L379" class="LineNr">379 </span> <span class="Delimiter">);</span> +<span id="L380" class="LineNr">380 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L381" class="LineNr">381 </span> <span class="Constant">"error: input does not start with a '==' section header</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L382" class="LineNr">382 </span> <span class="Delimiter">);</span> +<span id="L383" class="LineNr">383 </span><span class="Delimiter">}</span> +<span id="L384" class="LineNr">384 </span> +<span id="L385" class="LineNr">385 </span><span class="Normal">void</span> <a href='011run.cc.html#L385'>test_error_on_uppercase_hex</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L386" class="LineNr">386 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L387" class="LineNr">387 </span> <a href='011run.cc.html#L397'>parse_and_load</a><span class="Delimiter">(</span> +<span id="L388" class="LineNr">388 </span> <span class="Constant">"== code</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L389" class="LineNr">389 </span> <span class="Constant">"01 Ab</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L390" class="LineNr">390 </span> <span class="Delimiter">);</span> +<span id="L391" class="LineNr">391 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L392" class="LineNr">392 </span> <span class="Constant">"error: uppercase hex not allowed: Ab</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L393" class="LineNr">393 </span> <span class="Delimiter">);</span> +<span id="L394" class="LineNr">394 </span><span class="Delimiter">}</span> +<span id="L395" class="LineNr">395 </span> +<span id="L396" class="LineNr">396 </span><span class="Comment">//: helper for tests</span> +<span id="L397" class="LineNr">397 </span><span class="Normal">void</span> <a href='011run.cc.html#L397'>parse_and_load</a><span class="Delimiter">(</span><span class="Normal">const</span> string& text_bytes<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L398" class="LineNr">398 </span> program p<span class="Delimiter">;</span> +<span id="L399" class="LineNr">399 </span> istringstream in<span class="Delimiter">(</span>text_bytes<span class="Delimiter">);</span> +<span id="L400" class="LineNr">400 </span> parse<span class="Delimiter">(</span>in<span class="Delimiter">,</span> p<span class="Delimiter">);</span> +<span id="L401" class="LineNr">401 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// if any stage raises errors, stop immediately</span> +<span id="L402" class="LineNr">402 </span> <a href='011run.cc.html#L248'>load</a><span class="Delimiter">(</span>p<span class="Delimiter">);</span> +<span id="L403" class="LineNr">403 </span><span class="Delimiter">}</span> +<span id="L404" class="LineNr">404 </span> +<span id="L405" class="LineNr">405 </span><span class="Comment">//:: run</span> +<span id="L406" class="LineNr">406 </span> +<span id="L407" class="LineNr">407 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L408" class="LineNr">408 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"b8"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010vm.cc.html#L10'>EAX</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L409" class="LineNr">409 </span> +<span id="L410" class="LineNr">410 </span><span class="Comment">//: our first opcode</span> +<span id="L411" class="LineNr">411 </span> +<span id="L412" class="LineNr">412 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L413" class="LineNr">413 </span><span class="Normal">case</span> <span class="Constant">0xb8</span>: <span class="Delimiter">{</span> <span class="Comment">// copy imm32 to EAX</span> +<span id="L414" class="LineNr">414 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> src = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L415" class="LineNr">415 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy imm32 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << src << <span class="Constant">" to EAX"</span> << end<span class="Delimiter">();</span> +<span id="L416" class="LineNr">416 </span> Reg[EAX]<span class="Delimiter">.</span>i = src<span class="Delimiter">;</span> +<span id="L417" class="LineNr">417 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L418" class="LineNr">418 </span><span class="Delimiter">}</span> +<span id="L419" class="LineNr">419 </span> +<span id="L420" class="LineNr">420 </span><span class="Delimiter">:(code)</span> +<span id="L421" class="LineNr">421 </span><span class="Normal">void</span> <a href='011run.cc.html#L421'>test_copy_imm32_to_EAX_again</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L422" class="LineNr">422 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L423" class="LineNr">423 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L424" class="LineNr">424 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L425" class="LineNr">425 </span> <span class="Constant">" b8 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy 0x0d0c0b0a to EAX</span> +<span id="L426" class="LineNr">426 </span> <span class="Delimiter">);</span> +<span id="L427" class="LineNr">427 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L428" class="LineNr">428 </span> <span class="Constant">"run: copy imm32 0x0d0c0b0a to <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L429" class="LineNr">429 </span> <span class="Delimiter">);</span> +<span id="L430" class="LineNr">430 </span><span class="Delimiter">}</span> +<span id="L431" class="LineNr">431 </span> +<span id="L432" class="LineNr">432 </span><span class="Comment">// read a 32-bit int in little-endian order from the instruction stream</span> +<span id="L433" class="LineNr">433 </span><span class="Normal">int32_t</span> <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L434" class="LineNr">434 </span> <span class="Normal">int32_t</span> result = <a href='010vm.cc.html#L185'>read_mem_i32</a><span class="Delimiter">(</span><a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">);</span> +<span id="L435" class="LineNr">435 </span> EIP+=<span class="Constant">4</span><span class="Delimiter">;</span> +<span id="L436" class="LineNr">436 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L437" class="LineNr">437 </span><span class="Delimiter">}</span> +<span id="L438" class="LineNr">438 </span> +<span id="L439" class="LineNr">439 </span><span class="Comment">//:: helpers</span> +<span id="L440" class="LineNr">440 </span> +<span id="L441" class="LineNr">441 </span>string to_string<span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L442" class="LineNr">442 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L443" class="LineNr">443 </span> out << w<span class="Delimiter">.</span>data<span class="Delimiter">;</span> +<span id="L444" class="LineNr">444 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>metadata<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L445" class="LineNr">445 </span> out << <span class="Constant">" /"</span> << w<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L446" class="LineNr">446 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L447" class="LineNr">447 </span><span class="Delimiter">}</span> +<span id="L448" class="LineNr">448 </span> +<span id="L449" class="LineNr">449 </span><span class="Normal">bool</span> <a href='011run.cc.html#L449'>contains_uppercase</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L450" class="LineNr">450 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L451" class="LineNr">451 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>isupper<span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L452" class="LineNr">452 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L453" class="LineNr">453 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/012elf.cc.html b/html/linux/bootstrap/012elf.cc.html new file mode 100644 index 00000000..0e14b780 --- /dev/null +++ b/html/linux/bootstrap/012elf.cc.html @@ -0,0 +1,257 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/012elf.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.LineNr { } +.Constant { color: #008787; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.CommentedCode { color: #8a8a8a; } +.Identifier { color: #af5f00; } +.PreProc { color: #c000c0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/012elf.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/012elf.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: Loading SubX programs from ELF binaries.</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: This will allow us to run them natively on a Linux kernel.</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: Based on <a href="https://github.com/kragen/stoneknifeforth/blob/702d2ebe1b/386.c">https://github.com/kragen/stoneknifeforth/blob/702d2ebe1b/386.c</a></span> +<span id="L4" class="LineNr"> 4 </span> +<span id="L5" class="LineNr"> 5 </span><span class="Delimiter">:(before "End Main")</span> +<span id="L6" class="LineNr"> 6 </span>assert<span class="Delimiter">(</span>argc > <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L7" class="LineNr"> 7 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L98'>is_equal</a><span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Comment">// Outside of tests, traces must be explicitly requested.</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> <a href='003trace.cc.html#L72'>Trace_stream</a> = <span class="Normal">new</span> trace_stream<span class="Delimiter">;</span> +<span id="L10" class="LineNr"> 10 </span> <a href='003trace.cc.html#L96'>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">"=== Starting to run"</span> << end<span class="Delimiter">();</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>argc <= <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L12" class="LineNr"> 12 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Not enough arguments provided.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Delimiter">}</span> +<span id="L14" class="LineNr"> 14 </span> <a href='000organization.cc.html#L150'>reset</a><span class="Delimiter">();</span> +<span id="L15" class="LineNr"> 15 </span> cerr << std::hex<span class="Delimiter">;</span> +<span id="L16" class="LineNr"> 16 </span> <a href='012elf.cc.html#L24'>load_elf</a><span class="Delimiter">(</span>argv[<span class="Constant">2</span>]<span class="Delimiter">,</span> argc<span class="Delimiter">,</span> argv<span class="Delimiter">);</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L26'>EIP</a> < <a href='010vm.cc.html#L166'>End_of_program</a><span class="Delimiter">)</span> <span class="Comment">// weak final-gasp termination check</span> +<span id="L18" class="LineNr"> 18 </span> <a href='010vm.cc.html#L277'>run_one_instruction</a><span class="Delimiter">();</span> +<span id="L19" class="LineNr"> 19 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"executed past end of the world: "</span> << <a href='010vm.cc.html#L26'>EIP</a> << <span class="Constant">" vs "</span> << <a href='010vm.cc.html#L166'>End_of_program</a> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L21" class="LineNr"> 21 </span><span class="Delimiter">}</span> +<span id="L22" class="LineNr"> 22 </span> +<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">:(code)</span> +<span id="L24" class="LineNr"> 24 </span><span class="Normal">void</span> <a href='012elf.cc.html#L24'>load_elf</a><span class="Delimiter">(</span><span class="Normal">const</span> string& filename<span class="Delimiter">,</span> <span class="Normal">int</span> argc<span class="Delimiter">,</span> <span class="Normal">char</span>* argv[]<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Normal">int</span> fd = open<span class="Delimiter">(</span>filename<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> O_RDONLY<span class="Delimiter">);</span> +<span id="L26" class="LineNr"> 26 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>fd < <span class="Constant">0</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> << filename<span class="Delimiter">.</span>c_str<span class="Delimiter">()</span> << <span class="Constant">": open"</span> << <a href='012elf.cc.html#L179'>perr</a><span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Normal">off_t</span> size = lseek<span class="Delimiter">(</span>fd<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">SEEK_END</span><span class="Delimiter">);</span> +<span id="L28" class="LineNr"> 28 </span> lseek<span class="Delimiter">(</span>fd<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">SEEK_SET</span><span class="Delimiter">);</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Normal">uint8_t</span>* elf_contents = <span class="Normal">static_cast</span><<span class="Normal">uint8_t</span>*><span class="Delimiter">(</span>malloc<span class="Delimiter">(</span>size<span class="Delimiter">));</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>elf_contents == <span class="Constant">NULL</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"malloc("</span> << size << <span class="Constant">')'</span> << <a href='012elf.cc.html#L179'>perr</a><span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> +<span id="L31" class="LineNr"> 31 </span> <span class="Normal">ssize_t</span> read_size = read<span class="Delimiter">(</span>fd<span class="Delimiter">,</span> elf_contents<span class="Delimiter">,</span> size<span class="Delimiter">);</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>size != read_size<span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"read → "</span> << size << <span class="Constant">" (!= "</span> << read_size << <span class="Constant">')'</span> << <a href='012elf.cc.html#L179'>perr</a><span class="Delimiter">()</span> << <span class="cSpecial">'\n'</span> << <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> +<span id="L33" class="LineNr"> 33 </span> <a href='012elf.cc.html#L37'>load_elf_contents</a><span class="Delimiter">(</span>elf_contents<span class="Delimiter">,</span> size<span class="Delimiter">,</span> argc<span class="Delimiter">,</span> argv<span class="Delimiter">);</span> +<span id="L34" class="LineNr"> 34 </span> free<span class="Delimiter">(</span>elf_contents<span class="Delimiter">);</span> +<span id="L35" class="LineNr"> 35 </span><span class="Delimiter">}</span> +<span id="L36" class="LineNr"> 36 </span> +<span id="L37" class="LineNr"> 37 </span><span class="Normal">void</span> <a href='012elf.cc.html#L37'>load_elf_contents</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span>* elf_contents<span class="Delimiter">,</span> <span class="Normal">size_t</span> size<span class="Delimiter">,</span> <span class="Normal">int</span> argc<span class="Delimiter">,</span> <span class="Normal">char</span>* argv[]<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L38" class="LineNr"> 38 </span> <span class="Normal">uint8_t</span> magic[<span class="Constant">5</span>] = <span class="Delimiter">{</span><span class="Constant">0</span><span class="Delimiter">};</span> +<span id="L39" class="LineNr"> 39 </span> memcpy<span class="Delimiter">(</span>magic<span class="Delimiter">,</span> elf_contents<span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L40" class="LineNr"> 40 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>memcmp<span class="Delimiter">(</span>magic<span class="Delimiter">,</span> <span class="Constant">"</span><span class="cSpecial">\177</span><span class="Constant">ELF"</span><span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">)</span> != <span class="Constant">0</span><span class="Delimiter">)</span> +<span id="L41" class="LineNr"> 41 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Invalid ELF file; starts with </span><span class="cSpecial">\"</span><span class="Constant">"</span> << magic << <span class="Constant">'"'</span> << <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>elf_contents[<span class="Constant">4</span>] != <span class="Constant">1</span><span class="Delimiter">)</span> +<span id="L43" class="LineNr"> 43 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Only 32-bit ELF files (4-byte words; virtual addresses up to 4GB) supported.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>elf_contents[<span class="Constant">5</span>] != <span class="Constant">1</span><span class="Delimiter">)</span> +<span id="L45" class="LineNr"> 45 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Only little-endian ELF files supported.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Comment">// unused: remaining 10 bytes of e_ident</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Normal">uint32_t</span> e_machine_type = <a href='012elf.cc.html#L170'>u32_in</a><span class="Delimiter">(</span>&elf_contents[<span class="Constant">16</span>]<span class="Delimiter">);</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>e_machine_type != <span class="Constant">0x00030002</span><span class="Delimiter">)</span> +<span id="L49" class="LineNr"> 49 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"ELF type/machine 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << e_machine_type << <span class="Constant">" isn't i386 executable</span><span class="cSpecial">\n</span><span class="Constant">"</span> << die<span class="Delimiter">();</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Comment">// unused: e_version. We only support version 1, and later versions will be backwards compatible.</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Normal">uint32_t</span> e_entry = <a href='012elf.cc.html#L170'>u32_in</a><span class="Delimiter">(</span>&elf_contents[<span class="Constant">24</span>]<span class="Delimiter">);</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Normal">uint32_t</span> e_phoff = <a href='012elf.cc.html#L170'>u32_in</a><span class="Delimiter">(</span>&elf_contents[<span class="Constant">28</span>]<span class="Delimiter">);</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Comment">// unused: e_shoff</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Comment">// unused: e_flags</span> +<span id="L55" class="LineNr"> 55 </span> <span class="Normal">uint32_t</span> e_ehsize = <a href='012elf.cc.html#L174'>u16_in</a><span class="Delimiter">(</span>&elf_contents[<span class="Constant">40</span>]<span class="Delimiter">);</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>e_ehsize < <span class="Constant">52</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Invalid binary; ELF header too small</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Normal">uint32_t</span> e_phentsize = <a href='012elf.cc.html#L174'>u16_in</a><span class="Delimiter">(</span>&elf_contents[<span class="Constant">42</span>]<span class="Delimiter">);</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Normal">uint32_t</span> e_phnum = <a href='012elf.cc.html#L174'>u16_in</a><span class="Delimiter">(</span>&elf_contents[<span class="Constant">44</span>]<span class="Delimiter">);</span> +<span id="L59" class="LineNr"> 59 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << e_phnum << <span class="Constant">" entries in the program header, each "</span> << e_phentsize << <span class="Constant">" bytes long"</span> << end<span class="Delimiter">();</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Comment">// unused: e_shentsize</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Comment">// unused: e_shnum</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Comment">// unused: e_shstrndx</span> +<span id="L63" class="LineNr"> 63 </span> +<span id="L64" class="LineNr"> 64 </span> set<<span class="Normal">uint32_t</span>> overlap<span class="Delimiter">;</span> <span class="Comment">// to detect overlapping segments</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < e_phnum<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> +<span id="L66" class="LineNr"> 66 </span> <a href='012elf.cc.html#L107'>load_segment_from_program_header</a><span class="Delimiter">(</span>elf_contents<span class="Delimiter">,</span> i<span class="Delimiter">,</span> size<span class="Delimiter">,</span> e_phoff + i*e_phentsize<span class="Delimiter">,</span> e_ehsize<span class="Delimiter">,</span> overlap<span class="Delimiter">);</span> +<span id="L67" class="LineNr"> 67 </span> +<span id="L68" class="LineNr"> 68 </span> <span class="Comment">// initialize code and stack</span> +<span id="L69" class="LineNr"> 69 </span> assert<span class="Delimiter">(</span>overlap<span class="Delimiter">.</span>find<span class="Delimiter">(</span><a href='012elf.cc.html#L152'>STACK_SEGMENT</a><span class="Delimiter">)</span> == overlap<span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L70" class="LineNr"> 70 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><a href='012elf.cc.html#L152'>STACK_SEGMENT</a><span class="Delimiter">));</span> +<span id="L71" class="LineNr"> 71 </span> assert<span class="Delimiter">(</span>overlap<span class="Delimiter">.</span>find<span class="Delimiter">(</span><a href='012elf.cc.html#L153'>AFTER_STACK</a><span class="Delimiter">)</span> == overlap<span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Comment">// The stack grows downward.</span> +<span id="L73" class="LineNr"> 73 </span> Reg[ESP]<span class="Delimiter">.</span>u = <a href='012elf.cc.html#L153'>AFTER_STACK</a><span class="Delimiter">;</span> +<span id="L74" class="LineNr"> 74 </span> Reg[EBP]<span class="Delimiter">.</span>u = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L75" class="LineNr"> 75 </span> <a href='010vm.cc.html#L26'>EIP</a> = e_entry<span class="Delimiter">;</span> +<span id="L76" class="LineNr"> 76 </span> +<span id="L77" class="LineNr"> 77 </span> <span class="Comment">// initialize args on stack</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Comment">// no envp for now</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Comment">// we wastefully use a separate page of memory for argv</span> +<span id="L80" class="LineNr"> 80 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><a href='012elf.cc.html#L154'>ARGV_DATA_SEGMENT</a><span class="Delimiter">));</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Normal">uint32_t</span> argv_data = <a href='012elf.cc.html#L154'>ARGV_DATA_SEGMENT</a><span class="Delimiter">;</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = argc-<span class="Constant">1</span><span class="Delimiter">;</span> i >= <span class="Comment">/*</span><span class="Comment">skip 'subx_bin' and 'run'</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">;</span> --i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L83" class="LineNr"> 83 </span> <a href='012elf.cc.html#L94'>push</a><span class="Delimiter">(</span>argv_data<span class="Delimiter">);</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j <= strlen<span class="Delimiter">(</span>argv[i]<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L85" class="LineNr"> 85 </span> assert<span class="Delimiter">(</span>overlap<span class="Delimiter">.</span>find<span class="Delimiter">(</span>argv_data<span class="Delimiter">)</span> == overlap<span class="Delimiter">.</span>end<span class="Delimiter">());</span> <span class="Comment">// don't bother comparing ARGV and STACK</span> +<span id="L86" class="LineNr"> 86 </span> <a href='010vm.cc.html#L244'>write_mem_u8</a><span class="Delimiter">(</span>argv_data<span class="Delimiter">,</span> argv[i][j]<span class="Delimiter">);</span> +<span id="L87" class="LineNr"> 87 </span> argv_data += <span class="Normal">sizeof</span><span class="Delimiter">(</span><span class="Normal">char</span><span class="Delimiter">);</span> +<span id="L88" class="LineNr"> 88 </span> assert<span class="Delimiter">(</span>argv_data < <a href='012elf.cc.html#L154'>ARGV_DATA_SEGMENT</a> + <a href='010vm.cc.html#L98'>SEGMENT_ALIGNMENT</a><span class="Delimiter">);</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Delimiter">}</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Delimiter">}</span> +<span id="L91" class="LineNr"> 91 </span> <a href='012elf.cc.html#L94'>push</a><span class="Delimiter">(</span>argc-<span class="Comment">/*</span><span class="Comment">skip 'subx_bin' and 'run'</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L92" class="LineNr"> 92 </span><span class="Delimiter">}</span> +<span id="L93" class="LineNr"> 93 </span> +<span id="L94" class="LineNr"> 94 </span><span class="Normal">void</span> <a href='012elf.cc.html#L94'>push</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L95" class="LineNr"> 95 </span> Reg[ESP]<span class="Delimiter">.</span>u -= <span class="Constant">4</span><span class="Delimiter">;</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u < <a href='012elf.cc.html#L152'>STACK_SEGMENT</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L97" class="LineNr"> 97 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"The stack overflowed its segment. "</span> +<span id="L98" class="LineNr"> 98 </span> << <span class="Constant">"Maybe SPACE_FOR_SEGMENT should be larger? "</span> +<span id="L99" class="LineNr"> 99 </span> << <span class="Constant">"Or you need to carve out an exception for the stack segment "</span> +<span id="L100" class="LineNr">100 </span> << <span class="Constant">"to be larger.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> +<span id="L101" class="LineNr">101 </span> <span class="Delimiter">}</span> +<span id="L102" class="LineNr">102 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"decrementing <a href='010vm.cc.html#L14'>ESP</a> to 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[ESP]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L103" class="LineNr">103 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"pushing value 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << val << end<span class="Delimiter">();</span> +<span id="L104" class="LineNr">104 </span> <a href='010vm.cc.html#L252'>write_mem_u32</a><span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> val<span class="Delimiter">);</span> +<span id="L105" class="LineNr">105 </span><span class="Delimiter">}</span> +<span id="L106" class="LineNr">106 </span> +<span id="L107" class="LineNr">107 </span><span class="Normal">void</span> <a href='012elf.cc.html#L107'>load_segment_from_program_header</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span>* elf_contents<span class="Delimiter">,</span> <span class="Normal">int</span> segment_index<span class="Delimiter">,</span> <span class="Normal">size_t</span> size<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> offset<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> e_ehsize<span class="Delimiter">,</span> set<<span class="Normal">uint32_t</span>>& overlap<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L108" class="LineNr">108 </span> <span class="Normal">uint32_t</span> p_type = <a href='012elf.cc.html#L170'>u32_in</a><span class="Delimiter">(</span>&elf_contents[offset]<span class="Delimiter">);</span> +<span id="L109" class="LineNr">109 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"program header at offset "</span> << offset << <span class="Constant">": type "</span> << p_type << end<span class="Delimiter">();</span> +<span id="L110" class="LineNr">110 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p_type != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L111" class="LineNr">111 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"ignoring segment at offset "</span> << offset << <span class="Constant">" of non PT_LOAD type "</span> << p_type << <span class="Constant">" (see <a href="http://refspecs.linuxbase.org/elf/elf.pdf)">http://refspecs.linuxbase.org/elf/elf.pdf)</a>"</span> << end<span class="Delimiter">();</span> +<span id="L112" class="LineNr">112 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L113" class="LineNr">113 </span> <span class="Delimiter">}</span> +<span id="L114" class="LineNr">114 </span> <span class="Normal">uint32_t</span> p_offset = <a href='012elf.cc.html#L170'>u32_in</a><span class="Delimiter">(</span>&elf_contents[offset + <span class="Constant">4</span>]<span class="Delimiter">);</span> +<span id="L115" class="LineNr">115 </span> <span class="Normal">uint32_t</span> p_vaddr = <a href='012elf.cc.html#L170'>u32_in</a><span class="Delimiter">(</span>&elf_contents[offset + <span class="Constant">8</span>]<span class="Delimiter">);</span> +<span id="L116" class="LineNr">116 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>e_ehsize > p_vaddr<span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Invalid binary; program header overlaps ELF header</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> +<span id="L117" class="LineNr">117 </span> <span class="Comment">// unused: p_paddr</span> +<span id="L118" class="LineNr">118 </span> <span class="Normal">uint32_t</span> p_filesz = <a href='012elf.cc.html#L170'>u32_in</a><span class="Delimiter">(</span>&elf_contents[offset + <span class="Constant">16</span>]<span class="Delimiter">);</span> +<span id="L119" class="LineNr">119 </span> <span class="Normal">uint32_t</span> p_memsz = <a href='012elf.cc.html#L170'>u32_in</a><span class="Delimiter">(</span>&elf_contents[offset + <span class="Constant">20</span>]<span class="Delimiter">);</span> +<span id="L120" class="LineNr">120 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p_filesz != p_memsz<span class="Delimiter">)</span> +<span id="L121" class="LineNr">121 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Can't yet handle segments where p_filesz != p_memsz (see <a href="http://refspecs.linuxbase.org/elf/elf.pdf)">http://refspecs.linuxbase.org/elf/elf.pdf)</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << die<span class="Delimiter">();</span> +<span id="L122" class="LineNr">122 </span> +<span id="L123" class="LineNr">123 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p_offset + p_filesz > size<span class="Delimiter">)</span> +<span id="L124" class="LineNr">124 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Invalid binary; segment at offset "</span> << offset << <span class="Constant">" is too large: wants to end at "</span> << p_offset+p_filesz << <span class="Constant">" but the file ends at "</span> << size << <span class="cSpecial">'\n'</span> << <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> +<span id="L125" class="LineNr">125 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p_memsz >= <a href='010vm.cc.html#L98'>SEGMENT_ALIGNMENT</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L126" class="LineNr">126 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Code segment too small for SubX; for now please manually increase SEGMENT_ALIGNMENT.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L127" class="LineNr">127 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L128" class="LineNr">128 </span> <span class="Delimiter">}</span> +<span id="L129" class="LineNr">129 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"blitting file offsets ("</span> << p_offset << <span class="Constant">", "</span> << <span class="Delimiter">(</span>p_offset+p_filesz<span class="Delimiter">)</span> << <span class="Constant">") to addresses ("</span> << p_vaddr << <span class="Constant">", "</span> << <span class="Delimiter">(</span>p_vaddr+p_memsz<span class="Delimiter">)</span> << <span class="Constant">')'</span> << end<span class="Delimiter">();</span> +<span id="L130" class="LineNr">130 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>size > p_memsz<span class="Delimiter">)</span> size = p_memsz<span class="Delimiter">;</span> +<span id="L131" class="LineNr">131 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span>p_vaddr<span class="Delimiter">));</span> +<span id="L132" class="LineNr">132 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < p_filesz<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L133" class="LineNr">133 </span> assert<span class="Delimiter">(</span>overlap<span class="Delimiter">.</span>find<span class="Delimiter">(</span>p_vaddr+i<span class="Delimiter">)</span> == overlap<span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L134" class="LineNr">134 </span> <a href='010vm.cc.html#L244'>write_mem_u8</a><span class="Delimiter">(</span>p_vaddr+i<span class="Delimiter">,</span> elf_contents[p_offset+i]<span class="Delimiter">);</span> +<span id="L135" class="LineNr">135 </span> overlap<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>p_vaddr+i<span class="Delimiter">);</span> +<span id="L136" class="LineNr">136 </span> <span class="Delimiter">}</span> +<span id="L137" class="LineNr">137 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>segment_index == <span class="Constant">0</span> && <a href='010vm.cc.html#L166'>End_of_program</a> < p_vaddr+p_memsz<span class="Delimiter">)</span> +<span id="L138" class="LineNr">138 </span> <a href='010vm.cc.html#L166'>End_of_program</a> = p_vaddr+p_memsz<span class="Delimiter">;</span> +<span id="L139" class="LineNr">139 </span><span class="Delimiter">}</span> +<span id="L140" class="LineNr">140 </span> +<span id="L141" class="LineNr">141 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L142" class="LineNr">142 </span><span class="Comment">// Very primitive/fixed/insecure ELF segments for now.</span> +<span id="L143" class="LineNr">143 </span><span class="Comment">// --- inaccessible: 0x00000000 -> 0x08047fff</span> +<span id="L144" class="LineNr">144 </span><span class="Comment">// code: 0x09000000 -> 0x09ffffff (specified in ELF binary)</span> +<span id="L145" class="LineNr">145 </span><span class="Comment">// data: 0x0a000000 -> 0x0affffff (specified in ELF binary)</span> +<span id="L146" class="LineNr">146 </span><span class="Comment">// --- heap gets mmap'd somewhere here ---</span> +<span id="L147" class="LineNr">147 </span><span class="Comment">// stack: 0xbdffffff -> 0xbd000000 (downward; not in ELF binary)</span> +<span id="L148" class="LineNr">148 </span><span class="Comment">// argv hack: 0xbf000000 -> 0xbfffffff (not in ELF binary)</span> +<span id="L149" class="LineNr">149 </span><span class="Comment">// --- reserved for kernel: 0xc0000000 -> ...</span> +<span id="L150" class="LineNr">150 </span><span class="Normal">const</span> <span class="Normal">uint32_t</span> <a href='012elf.cc.html#L150'>START_HEAP</a> = <span class="Constant">0x0b000000</span><span class="Delimiter">;</span> +<span id="L151" class="LineNr">151 </span><span class="Normal">const</span> <span class="Normal">uint32_t</span> <a href='012elf.cc.html#L151'>END_HEAP</a> = <span class="Constant">0xbd000000</span><span class="Delimiter">;</span> +<span id="L152" class="LineNr">152 </span><span class="Normal">const</span> <span class="Normal">uint32_t</span> <a href='012elf.cc.html#L152'>STACK_SEGMENT</a> = <span class="Constant">0xbd000000</span><span class="Delimiter">;</span> +<span id="L153" class="LineNr">153 </span><span class="Normal">const</span> <span class="Normal">uint32_t</span> <a href='012elf.cc.html#L153'>AFTER_STACK</a> = <span class="Constant">0xbe000000</span><span class="Delimiter">;</span> +<span id="L154" class="LineNr">154 </span><span class="Normal">const</span> <span class="Normal">uint32_t</span> <a href='012elf.cc.html#L154'>ARGV_DATA_SEGMENT</a> = <span class="Constant">0xbf000000</span><span class="Delimiter">;</span> +<span id="L155" class="LineNr">155 </span><span class="Comment">// When updating the above memory map, don't forget to update `mmap`'s</span> +<span id="L156" class="LineNr">156 </span><span class="Comment">// implementation in the 'syscalls' layer.</span> +<span id="L157" class="LineNr">157 </span><span class="Delimiter">:(before "End Dump Info for Instruction")</span> +<span id="L158" class="LineNr">158 </span><span class="CommentedCode">//? dump_stack(); // slow</span> +<span id="L159" class="LineNr">159 </span><span class="Delimiter">:(code)</span> +<span id="L160" class="LineNr">160 </span><span class="Normal">void</span> dump_stack<span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L161" class="LineNr">161 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L162" class="LineNr">162 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"stack:"</span> << end<span class="Delimiter">();</span> +<span id="L163" class="LineNr">163 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">uint32_t</span> a = AFTER_STACK-<span class="Constant">4</span><span class="Delimiter">;</span> a > Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> a -= <span class="Constant">4</span><span class="Delimiter">)</span> +<span id="L164" class="LineNr">164 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">" 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << a << <span class="Constant">" => 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span>a<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L165" class="LineNr">165 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">" 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[ESP]<span class="Delimiter">.</span>u << <span class="Constant">" => 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << <span class="Constant">" <=== ESP"</span> << end<span class="Delimiter">();</span> +<span id="L166" class="LineNr">166 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">uint32_t</span> a = Reg[ESP]<span class="Delimiter">.</span>u-<span class="Constant">4</span><span class="Delimiter">;</span> a > Reg[ESP]<span class="Delimiter">.</span>u-<span class="Constant">40</span><span class="Delimiter">;</span> a -= <span class="Constant">4</span><span class="Delimiter">)</span> +<span id="L167" class="LineNr">167 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">" 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << a << <span class="Constant">" => 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span>a<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L168" class="LineNr">168 </span><span class="Delimiter">}</span> +<span id="L169" class="LineNr">169 </span> +<span id="L170" class="LineNr">170 </span><span class="Normal">inline</span> <span class="Normal">uint32_t</span> <a href='012elf.cc.html#L170'>u32_in</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span>* p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L171" class="LineNr">171 </span> <span class="Identifier">return</span> p[<span class="Constant">0</span>] | p[<span class="Constant">1</span>] << <span class="Constant">8</span> | p[<span class="Constant">2</span>] << <span class="Constant">16</span> | p[<span class="Constant">3</span>] << <span class="Constant">24</span><span class="Delimiter">;</span> +<span id="L172" class="LineNr">172 </span><span class="Delimiter">}</span> +<span id="L173" class="LineNr">173 </span> +<span id="L174" class="LineNr">174 </span><span class="Normal">inline</span> <span class="Normal">uint16_t</span> <a href='012elf.cc.html#L174'>u16_in</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span>* p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L175" class="LineNr">175 </span> <span class="Identifier">return</span> p[<span class="Constant">0</span>] | p[<span class="Constant">1</span>] << <span class="Constant">8</span><span class="Delimiter">;</span> +<span id="L176" class="LineNr">176 </span><span class="Delimiter">}</span> +<span id="L177" class="LineNr">177 </span> +<span id="L178" class="LineNr">178 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L179" class="LineNr">179 </span><span class="Normal">struct</span> <a href='012elf.cc.html#L179'>perr</a> <span class="Delimiter">{};</span> +<span id="L180" class="LineNr">180 </span><span class="Delimiter">:(code)</span> +<span id="L181" class="LineNr">181 </span>ostream& <span class="Normal">operator</span><<<span class="Delimiter">(</span>ostream& os<span class="Delimiter">,</span> <a href='012elf.cc.html#L179'>perr</a> <span class="Comment">/*</span><span class="Comment">unused</span><span class="Comment">*/</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L182" class="LineNr">182 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>errno<span class="Delimiter">)</span> +<span id="L183" class="LineNr">183 </span> os << <span class="Constant">": "</span> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">);</span> +<span id="L184" class="LineNr">184 </span> <span class="Identifier">return</span> os<span class="Delimiter">;</span> +<span id="L185" class="LineNr">185 </span><span class="Delimiter">}</span> +<span id="L186" class="LineNr">186 </span> +<span id="L187" class="LineNr">187 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L188" class="LineNr">188 </span><span class="PreProc">#include </span><span class="Constant"><sys/types.h></span> +<span id="L189" class="LineNr">189 </span><span class="PreProc">#include </span><span class="Constant"><sys/stat.h></span> +<span id="L190" class="LineNr">190 </span><span class="PreProc">#include </span><span class="Constant"><fcntl.h></span> +<span id="L191" class="LineNr">191 </span><span class="PreProc">#include </span><span class="Constant"><stdarg.h></span> +<span id="L192" class="LineNr">192 </span><span class="PreProc">#include </span><span class="Constant"><errno.h></span> +<span id="L193" class="LineNr">193 </span><span class="PreProc">#include </span><span class="Constant"><unistd.h></span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/013direct_addressing.cc.html b/html/linux/bootstrap/013direct_addressing.cc.html new file mode 100644 index 00000000..e0ec4b6d --- /dev/null +++ b/html/linux/bootstrap/013direct_addressing.cc.html @@ -0,0 +1,1344 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/013direct_addressing.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.LineNr { } +.Constant { color: #008787; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.CommentedCode { color: #8a8a8a; } +.Identifier { color: #af5f00; } +.PreProc { color: #c000c0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/013direct_addressing.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/013direct_addressing.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: operating directly on a register</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L4" class="LineNr"> 4 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"01"</span><span class="Delimiter">,</span> <span class="Constant">"add r32 to rm32 (add)"</span><span class="Delimiter">);</span> +<span id="L5" class="LineNr"> 5 </span> +<span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(code)</span> +<span id="L7" class="LineNr"> 7 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L7'>test_add_r32_to_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L8" class="LineNr"> 8 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> +<span id="L9" class="LineNr"> 9 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L10" class="LineNr"> 10 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Constant">" 01 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to EAX</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Delimiter">);</span> +<span id="L16" class="LineNr"> 16 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Delimiter">);</span> +<span id="L21" class="LineNr"> 21 </span><span class="Delimiter">}</span> +<span id="L22" class="LineNr"> 22 </span> +<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L24" class="LineNr"> 24 </span><span class="Normal">case</span> <span class="Constant">0x01</span>: <span class="Delimiter">{</span> <span class="Comment">// add r32 to r/m32</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L26" class="LineNr"> 26 </span> <span class="Normal">uint8_t</span> arg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L27" class="LineNr"> 27 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"add "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>arg2<span class="Delimiter">)</span> << <span class="Constant">" to r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L28" class="LineNr"> 28 </span> <span class="Normal">int32_t</span>* signed_arg1 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Normal">int32_t</span> signed_result = *signed_arg1 + Reg[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L30" class="LineNr"> 30 </span> SF = <span class="Delimiter">(</span>signed_result < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L31" class="LineNr"> 31 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>signed_result == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Normal">int64_t</span> signed_full_result = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">)</span> + Reg[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L33" class="LineNr"> 33 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>signed_result != signed_full_result<span class="Delimiter">);</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Comment">// set CF</span> +<span id="L35" class="LineNr"> 35 </span> <span class="Normal">uint32_t</span> unsigned_arg1 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">);</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Normal">uint32_t</span> unsigned_result = unsigned_arg1 + Reg[arg2]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Normal">uint64_t</span> unsigned_full_result = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>unsigned_arg1<span class="Delimiter">)</span> + Reg[arg2]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L38" class="LineNr"> 38 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>unsigned_result != unsigned_full_result<span class="Delimiter">);</span> +<span id="L39" class="LineNr"> 39 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L40" class="LineNr"> 40 </span> *signed_arg1 = signed_result<span class="Delimiter">;</span> +<span id="L41" class="LineNr"> 41 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *signed_arg1 << end<span class="Delimiter">();</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L43" class="LineNr"> 43 </span><span class="Delimiter">}</span> +<span id="L44" class="LineNr"> 44 </span> +<span id="L45" class="LineNr"> 45 </span><span class="Delimiter">:(code)</span> +<span id="L46" class="LineNr"> 46 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L46'>test_add_r32_to_r32_signed_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L47" class="LineNr"> 47 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MAX</span><span class="Delimiter">;</span> +<span id="L48" class="LineNr"> 48 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L49" class="LineNr"> 49 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Constant">" 01 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to EAX</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Delimiter">);</span> +<span id="L55" class="LineNr"> 55 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Constant">"run: SF=1; ZF=0; CF=0; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Constant">"run: storing 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Delimiter">);</span> +<span id="L61" class="LineNr"> 61 </span><span class="Delimiter">}</span> +<span id="L62" class="LineNr"> 62 </span> +<span id="L63" class="LineNr"> 63 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L63'>test_add_r32_to_r32_unsigned_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L64" class="LineNr"> 64 </span> Reg[EAX]<span class="Delimiter">.</span>u = <span class="Constant">UINT32_MAX</span><span class="Delimiter">;</span> +<span id="L65" class="LineNr"> 65 </span> Reg[EBX]<span class="Delimiter">.</span>u = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L66" class="LineNr"> 66 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Constant">" 01 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to EAX</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Delimiter">);</span> +<span id="L72" class="LineNr"> 72 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Constant">"run: SF=0; ZF=1; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L76" class="LineNr"> 76 </span> <span class="Constant">"run: storing 0x00000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Delimiter">);</span> +<span id="L78" class="LineNr"> 78 </span><span class="Delimiter">}</span> +<span id="L79" class="LineNr"> 79 </span> +<span id="L80" class="LineNr"> 80 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L80'>test_add_r32_to_r32_unsigned_and_signed_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L81" class="LineNr"> 81 </span> Reg[EAX]<span class="Delimiter">.</span>i = Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MIN</span><span class="Delimiter">;</span> +<span id="L82" class="LineNr"> 82 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Constant">" 01 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to EAX</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Delimiter">);</span> +<span id="L88" class="LineNr"> 88 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Constant">"run: SF=0; ZF=1; CF=1; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Constant">"run: storing 0x00000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Delimiter">);</span> +<span id="L94" class="LineNr"> 94 </span><span class="Delimiter">}</span> +<span id="L95" class="LineNr"> 95 </span> +<span id="L96" class="LineNr"> 96 </span><span class="Delimiter">:(code)</span> +<span id="L97" class="LineNr"> 97 </span><span class="Comment">// Implement tables 2-2 and 2-3 in the Intel manual, Volume 2.</span> +<span id="L98" class="LineNr"> 98 </span><span class="Comment">// We return a pointer so that instructions can write to multiple bytes in</span> +<span id="L99" class="LineNr"> 99 </span><span class="Comment">// 'Mem' at once.</span> +<span id="L100" class="LineNr"> 100 </span><span class="Comment">// beware: will eventually have side-effects</span> +<span id="L101" class="LineNr"> 101 </span><span class="Normal">int32_t</span>* <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> modrm<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L102" class="LineNr"> 102 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> mod = <span class="Delimiter">(</span>modrm>><span class="Constant">6</span><span class="Delimiter">);</span> +<span id="L103" class="LineNr"> 103 </span> <span class="Comment">// ignore middle 3 'reg opcode' bits</span> +<span id="L104" class="LineNr"> 104 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rm = modrm & <span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L105" class="LineNr"> 105 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod == <span class="Constant">3</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L106" class="LineNr"> 106 </span> <span class="Comment">// mod 3 is just register direct addressing</span> +<span id="L107" class="LineNr"> 107 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"r/m32 is "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>rm<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L108" class="LineNr"> 108 </span> <span class="Identifier">return</span> &Reg[rm]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L109" class="LineNr"> 109 </span> <span class="Delimiter">}</span> +<span id="L110" class="LineNr"> 110 </span> <span class="Normal">uint32_t</span> addr = <a href='013direct_addressing.cc.html#L116'>effective_address_number</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L111" class="LineNr"> 111 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address contains 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L185'>read_mem_i32</a><span class="Delimiter">(</span>addr<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L112" class="LineNr"> 112 </span> <span class="Identifier">return</span> <a href='010vm.cc.html#L227'>mem_addr_i32</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L113" class="LineNr"> 113 </span><span class="Delimiter">}</span> +<span id="L114" class="LineNr"> 114 </span> +<span id="L115" class="LineNr"> 115 </span><span class="Comment">// beware: will eventually have side-effects</span> +<span id="L116" class="LineNr"> 116 </span><span class="Normal">uint32_t</span> <a href='013direct_addressing.cc.html#L116'>effective_address_number</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> modrm<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L117" class="LineNr"> 117 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> mod = <span class="Delimiter">(</span>modrm>><span class="Constant">6</span><span class="Delimiter">);</span> +<span id="L118" class="LineNr"> 118 </span> <span class="Comment">// ignore middle 3 'reg opcode' bits</span> +<span id="L119" class="LineNr"> 119 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rm = modrm & <span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L120" class="LineNr"> 120 </span> <span class="Normal">uint32_t</span> addr = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L121" class="LineNr"> 121 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>mod<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L122" class="LineNr"> 122 </span> <span class="Normal">case</span> <span class="Constant">3</span>: +<span id="L123" class="LineNr"> 123 </span> <span class="Comment">// mod 3 is just register direct addressing</span> +<span id="L124" class="LineNr"> 124 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"unexpected direct addressing mode</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L125" class="LineNr"> 125 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L126" class="LineNr"> 126 </span> <span class="Comment">// End Mod Special-cases(addr)</span> +<span id="L127" class="LineNr"> 127 </span> <span class="Normal">default</span>: +<span id="L128" class="LineNr"> 128 </span> cerr << <span class="Constant">"unrecognized mod bits: "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>mod<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L129" class="LineNr"> 129 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L130" class="LineNr"> 130 </span> <span class="Delimiter">}</span> +<span id="L131" class="LineNr"> 131 </span> <span class="Comment">//: other mods are indirect, and they'll set addr appropriately</span> +<span id="L132" class="LineNr"> 132 </span> <span class="Comment">// Found effective_address(addr)</span> +<span id="L133" class="LineNr"> 133 </span> <span class="Identifier">return</span> addr<span class="Delimiter">;</span> +<span id="L134" class="LineNr"> 134 </span><span class="Delimiter">}</span> +<span id="L135" class="LineNr"> 135 </span> +<span id="L136" class="LineNr"> 136 </span>string <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L137" class="LineNr"> 137 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L138" class="LineNr"> 138 </span> <span class="Normal">case</span> <span class="Constant">0</span>: <span class="Identifier">return</span> <span class="Constant">"EAX"</span><span class="Delimiter">;</span> +<span id="L139" class="LineNr"> 139 </span> <span class="Normal">case</span> <span class="Constant">1</span>: <span class="Identifier">return</span> <span class="Constant">"ECX"</span><span class="Delimiter">;</span> +<span id="L140" class="LineNr"> 140 </span> <span class="Normal">case</span> <span class="Constant">2</span>: <span class="Identifier">return</span> <span class="Constant">"EDX"</span><span class="Delimiter">;</span> +<span id="L141" class="LineNr"> 141 </span> <span class="Normal">case</span> <span class="Constant">3</span>: <span class="Identifier">return</span> <span class="Constant">"EBX"</span><span class="Delimiter">;</span> +<span id="L142" class="LineNr"> 142 </span> <span class="Normal">case</span> <span class="Constant">4</span>: <span class="Identifier">return</span> <span class="Constant">"ESP"</span><span class="Delimiter">;</span> +<span id="L143" class="LineNr"> 143 </span> <span class="Normal">case</span> <span class="Constant">5</span>: <span class="Identifier">return</span> <span class="Constant">"EBP"</span><span class="Delimiter">;</span> +<span id="L144" class="LineNr"> 144 </span> <span class="Normal">case</span> <span class="Constant">6</span>: <span class="Identifier">return</span> <span class="Constant">"ESI"</span><span class="Delimiter">;</span> +<span id="L145" class="LineNr"> 145 </span> <span class="Normal">case</span> <span class="Constant">7</span>: <span class="Identifier">return</span> <span class="Constant">"EDI"</span><span class="Delimiter">;</span> +<span id="L146" class="LineNr"> 146 </span> <span class="Normal">default</span>: <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"invalid register "</span> << r << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L147" class="LineNr"> 147 </span> <span class="Delimiter">}</span> +<span id="L148" class="LineNr"> 148 </span><span class="Delimiter">}</span> +<span id="L149" class="LineNr"> 149 </span> +<span id="L150" class="LineNr"> 150 </span><span class="Comment">//:: subtract</span> +<span id="L151" class="LineNr"> 151 </span> +<span id="L152" class="LineNr"> 152 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L153" class="LineNr"> 153 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"29"</span><span class="Delimiter">,</span> <span class="Constant">"subtract r32 from rm32 (sub)"</span><span class="Delimiter">);</span> +<span id="L154" class="LineNr"> 154 </span> +<span id="L155" class="LineNr"> 155 </span><span class="Delimiter">:(code)</span> +<span id="L156" class="LineNr"> 156 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L156'>test_subtract_r32_from_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L157" class="LineNr"> 157 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">10</span><span class="Delimiter">;</span> +<span id="L158" class="LineNr"> 158 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L159" class="LineNr"> 159 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L160" class="LineNr"> 160 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L161" class="LineNr"> 161 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L162" class="LineNr"> 162 </span> <span class="Constant">" 29 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract EBX from EAX</span> +<span id="L163" class="LineNr"> 163 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L164" class="LineNr"> 164 </span> <span class="Delimiter">);</span> +<span id="L165" class="LineNr"> 165 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L166" class="LineNr"> 166 </span> <span class="Constant">"run: subtract <a href='010vm.cc.html#L13'>EBX</a> from r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L167" class="LineNr"> 167 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L168" class="LineNr"> 168 </span> <span class="Constant">"run: storing 0x00000009</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L169" class="LineNr"> 169 </span> <span class="Delimiter">);</span> +<span id="L170" class="LineNr"> 170 </span><span class="Delimiter">}</span> +<span id="L171" class="LineNr"> 171 </span> +<span id="L172" class="LineNr"> 172 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L173" class="LineNr"> 173 </span><span class="Normal">case</span> <span class="Constant">0x29</span>: <span class="Delimiter">{</span> <span class="Comment">// subtract r32 from r/m32</span> +<span id="L174" class="LineNr"> 174 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L175" class="LineNr"> 175 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L176" class="LineNr"> 176 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subtract "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>arg2<span class="Delimiter">)</span> << <span class="Constant">" from r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L177" class="LineNr"> 177 </span> <span class="Normal">int32_t</span>* signed_arg1 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L178" class="LineNr"> 178 </span> <span class="Normal">int32_t</span> signed_result = *signed_arg1 - Reg[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L179" class="LineNr"> 179 </span> SF = <span class="Delimiter">(</span>signed_result < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L180" class="LineNr"> 180 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>signed_result == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L181" class="LineNr"> 181 </span> <span class="Normal">int64_t</span> signed_full_result = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">)</span> - Reg[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L182" class="LineNr"> 182 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>signed_result != signed_full_result<span class="Delimiter">);</span> +<span id="L183" class="LineNr"> 183 </span> <span class="Comment">// set CF</span> +<span id="L184" class="LineNr"> 184 </span> <span class="Normal">uint32_t</span> unsigned_arg1 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">);</span> +<span id="L185" class="LineNr"> 185 </span> <span class="Normal">uint32_t</span> unsigned_result = unsigned_arg1 - Reg[arg2]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L186" class="LineNr"> 186 </span> <span class="Normal">uint64_t</span> unsigned_full_result = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>unsigned_arg1<span class="Delimiter">)</span> - Reg[arg2]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L187" class="LineNr"> 187 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>unsigned_result != unsigned_full_result<span class="Delimiter">);</span> +<span id="L188" class="LineNr"> 188 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L189" class="LineNr"> 189 </span> *signed_arg1 = signed_result<span class="Delimiter">;</span> +<span id="L190" class="LineNr"> 190 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *signed_arg1 << end<span class="Delimiter">();</span> +<span id="L191" class="LineNr"> 191 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L192" class="LineNr"> 192 </span><span class="Delimiter">}</span> +<span id="L193" class="LineNr"> 193 </span> +<span id="L194" class="LineNr"> 194 </span><span class="Delimiter">:(code)</span> +<span id="L195" class="LineNr"> 195 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L195'>test_subtract_r32_from_r32_signed_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L196" class="LineNr"> 196 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MIN</span><span class="Delimiter">;</span> +<span id="L197" class="LineNr"> 197 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MAX</span><span class="Delimiter">;</span> +<span id="L198" class="LineNr"> 198 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L199" class="LineNr"> 199 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L200" class="LineNr"> 200 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L201" class="LineNr"> 201 </span> <span class="Constant">" 29 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract EBX from EAX</span> +<span id="L202" class="LineNr"> 202 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L203" class="LineNr"> 203 </span> <span class="Delimiter">);</span> +<span id="L204" class="LineNr"> 204 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L205" class="LineNr"> 205 </span> <span class="Constant">"run: subtract <a href='010vm.cc.html#L13'>EBX</a> from r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L206" class="LineNr"> 206 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L207" class="LineNr"> 207 </span> <span class="Constant">"run: SF=0; ZF=0; CF=0; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L208" class="LineNr"> 208 </span> <span class="Constant">"run: storing 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L209" class="LineNr"> 209 </span> <span class="Delimiter">);</span> +<span id="L210" class="LineNr"> 210 </span><span class="Delimiter">}</span> +<span id="L211" class="LineNr"> 211 </span> +<span id="L212" class="LineNr"> 212 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L212'>test_subtract_r32_from_r32_unsigned_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L213" class="LineNr"> 213 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L214" class="LineNr"> 214 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L215" class="LineNr"> 215 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L216" class="LineNr"> 216 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L217" class="LineNr"> 217 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L218" class="LineNr"> 218 </span> <span class="Constant">" 29 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract EBX from EAX</span> +<span id="L219" class="LineNr"> 219 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L220" class="LineNr"> 220 </span> <span class="Delimiter">);</span> +<span id="L221" class="LineNr"> 221 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L222" class="LineNr"> 222 </span> <span class="Constant">"run: subtract <a href='010vm.cc.html#L13'>EBX</a> from r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L223" class="LineNr"> 223 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L224" class="LineNr"> 224 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L225" class="LineNr"> 225 </span> <span class="Constant">"run: storing 0xffffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L226" class="LineNr"> 226 </span> <span class="Delimiter">);</span> +<span id="L227" class="LineNr"> 227 </span><span class="Delimiter">}</span> +<span id="L228" class="LineNr"> 228 </span> +<span id="L229" class="LineNr"> 229 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L229'>test_subtract_r32_from_r32_signed_and_unsigned_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L230" class="LineNr"> 230 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L231" class="LineNr"> 231 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MIN</span><span class="Delimiter">;</span> +<span id="L232" class="LineNr"> 232 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L233" class="LineNr"> 233 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L234" class="LineNr"> 234 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L235" class="LineNr"> 235 </span> <span class="Constant">" 29 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract EBX from EAX</span> +<span id="L236" class="LineNr"> 236 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L237" class="LineNr"> 237 </span> <span class="Delimiter">);</span> +<span id="L238" class="LineNr"> 238 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L239" class="LineNr"> 239 </span> <span class="Constant">"run: subtract <a href='010vm.cc.html#L13'>EBX</a> from r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L240" class="LineNr"> 240 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L241" class="LineNr"> 241 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L242" class="LineNr"> 242 </span> <span class="Constant">"run: storing 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L243" class="LineNr"> 243 </span> <span class="Delimiter">);</span> +<span id="L244" class="LineNr"> 244 </span><span class="Delimiter">}</span> +<span id="L245" class="LineNr"> 245 </span> +<span id="L246" class="LineNr"> 246 </span><span class="Comment">//:: multiply</span> +<span id="L247" class="LineNr"> 247 </span> +<span id="L248" class="LineNr"> 248 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L249" class="LineNr"> 249 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"f7"</span><span class="Delimiter">,</span> <span class="Constant">"negate/multiply/divide rm32 (with <a href='010vm.cc.html#L10'>EAX</a> and <a href='010vm.cc.html#L12'>EDX</a> if necessary) depending on subop (neg/mul/idiv)"</span><span class="Delimiter">);</span> +<span id="L250" class="LineNr"> 250 </span> +<span id="L251" class="LineNr"> 251 </span><span class="Delimiter">:(code)</span> +<span id="L252" class="LineNr"> 252 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L252'>test_multiply_EAX_by_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L253" class="LineNr"> 253 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">4</span><span class="Delimiter">;</span> +<span id="L254" class="LineNr"> 254 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">3</span><span class="Delimiter">;</span> +<span id="L255" class="LineNr"> 255 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L256" class="LineNr"> 256 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L257" class="LineNr"> 257 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L258" class="LineNr"> 258 </span> <span class="Constant">" f7 e1 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// multiply EAX by ECX</span> +<span id="L259" class="LineNr"> 259 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 100 (subop mul) 001 (src ECX)</span> +<span id="L260" class="LineNr"> 260 </span> <span class="Delimiter">);</span> +<span id="L261" class="LineNr"> 261 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L262" class="LineNr"> 262 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L263" class="LineNr"> 263 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L11'>ECX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L264" class="LineNr"> 264 </span> <span class="Constant">"run: subop: multiply <a href='010vm.cc.html#L10'>EAX</a> by r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L265" class="LineNr"> 265 </span> <span class="Constant">"run: storing 0x0000000c</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L266" class="LineNr"> 266 </span> <span class="Delimiter">);</span> +<span id="L267" class="LineNr"> 267 </span><span class="Delimiter">}</span> +<span id="L268" class="LineNr"> 268 </span> +<span id="L269" class="LineNr"> 269 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L270" class="LineNr"> 270 </span><span class="Normal">case</span> <span class="Constant">0xf7</span>: <span class="Delimiter">{</span> +<span id="L271" class="LineNr"> 271 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L272" class="LineNr"> 272 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"operate on r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L273" class="LineNr"> 273 </span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L274" class="LineNr"> 274 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> subop = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span class="Comment">// middle 3 'reg opcode' bits</span> +<span id="L275" class="LineNr"> 275 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>subop<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L276" class="LineNr"> 276 </span> <span class="Normal">case</span> <span class="Constant">4</span>: <span class="Delimiter">{</span> <span class="Comment">// mul unsigned EAX by r/m32</span> +<span id="L277" class="LineNr"> 277 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop: multiply <a href='010vm.cc.html#L10'>EAX</a> by r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L278" class="LineNr"> 278 </span> <span class="Normal">const</span> <span class="Normal">uint64_t</span> result = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> * <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*arg1<span class="Delimiter">);</span> +<span id="L279" class="LineNr"> 279 </span> Reg[EAX]<span class="Delimiter">.</span>u = result & <span class="Constant">0xffffffff</span><span class="Delimiter">;</span> +<span id="L280" class="LineNr"> 280 </span> Reg[EDX]<span class="Delimiter">.</span>u = result >> <span class="Constant">32</span><span class="Delimiter">;</span> +<span id="L281" class="LineNr"> 281 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>Reg[EDX]<span class="Delimiter">.</span>u != <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L282" class="LineNr"> 282 </span> <a href='010vm.cc.html#L90'>CF</a> = <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">;</span> +<span id="L283" class="LineNr"> 283 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L284" class="LineNr"> 284 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[EAX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L285" class="LineNr"> 285 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L286" class="LineNr"> 286 </span> <span class="Delimiter">}</span> +<span id="L287" class="LineNr"> 287 </span> <span class="Comment">// End Op f7 Subops</span> +<span id="L288" class="LineNr"> 288 </span> <span class="Normal">default</span>: +<span id="L289" class="LineNr"> 289 </span> cerr << <span class="Constant">"unrecognized subop for opcode f7: "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L290" class="LineNr"> 290 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L291" class="LineNr"> 291 </span> <span class="Delimiter">}</span> +<span id="L292" class="LineNr"> 292 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L293" class="LineNr"> 293 </span><span class="Delimiter">}</span> +<span id="L294" class="LineNr"> 294 </span> +<span id="L295" class="LineNr"> 295 </span><span class="Comment">//:</span> +<span id="L296" class="LineNr"> 296 </span> +<span id="L297" class="LineNr"> 297 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L298" class="LineNr"> 298 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"af"</span><span class="Delimiter">,</span> <span class="Constant">"multiply rm32 into r32 (imul)"</span><span class="Delimiter">);</span> +<span id="L299" class="LineNr"> 299 </span> +<span id="L300" class="LineNr"> 300 </span><span class="Delimiter">:(code)</span> +<span id="L301" class="LineNr"> 301 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L301'>test_multiply_r32_into_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L302" class="LineNr"> 302 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">4</span><span class="Delimiter">;</span> +<span id="L303" class="LineNr"> 303 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L304" class="LineNr"> 304 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L305" class="LineNr"> 305 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L306" class="LineNr"> 306 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L307" class="LineNr"> 307 </span> <span class="Constant">" 0f af d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract EBX into EAX</span> +<span id="L308" class="LineNr"> 308 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L309" class="LineNr"> 309 </span> <span class="Delimiter">);</span> +<span id="L310" class="LineNr"> 310 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L311" class="LineNr"> 311 </span> <span class="Constant">"run: multiply <a href='010vm.cc.html#L13'>EBX</a> by r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L312" class="LineNr"> 312 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L313" class="LineNr"> 313 </span> <span class="Constant">"run: storing 0x00000008</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L314" class="LineNr"> 314 </span> <span class="Delimiter">);</span> +<span id="L315" class="LineNr"> 315 </span><span class="Delimiter">}</span> +<span id="L316" class="LineNr"> 316 </span> +<span id="L317" class="LineNr"> 317 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L318" class="LineNr"> 318 </span><span class="Normal">case</span> <span class="Constant">0xaf</span>: <span class="Delimiter">{</span> <span class="Comment">// multiply r32 by r/m32</span> +<span id="L319" class="LineNr"> 319 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L320" class="LineNr"> 320 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L321" class="LineNr"> 321 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"multiply "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << <span class="Constant">" by r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L322" class="LineNr"> 322 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* arg2 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L323" class="LineNr"> 323 </span> <span class="Normal">int32_t</span> result = Reg[arg1]<span class="Delimiter">.</span>i * <span class="Delimiter">(</span>*arg2<span class="Delimiter">);</span> +<span id="L324" class="LineNr"> 324 </span> <span class="Normal">int64_t</span> full_result = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>Reg[arg1]<span class="Delimiter">.</span>i<span class="Delimiter">)</span> * <span class="Delimiter">(</span>*arg2<span class="Delimiter">);</span> +<span id="L325" class="LineNr"> 325 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>result != full_result<span class="Delimiter">);</span> +<span id="L326" class="LineNr"> 326 </span> <a href='010vm.cc.html#L90'>CF</a> = <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">;</span> +<span id="L327" class="LineNr"> 327 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L328" class="LineNr"> 328 </span> Reg[arg1]<span class="Delimiter">.</span>i = result<span class="Delimiter">;</span> +<span id="L329" class="LineNr"> 329 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[arg1]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L330" class="LineNr"> 330 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L331" class="LineNr"> 331 </span><span class="Delimiter">}</span> +<span id="L332" class="LineNr"> 332 </span> +<span id="L333" class="LineNr"> 333 </span><span class="Comment">//:: negate</span> +<span id="L334" class="LineNr"> 334 </span> +<span id="L335" class="LineNr"> 335 </span><span class="Delimiter">:(code)</span> +<span id="L336" class="LineNr"> 336 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L336'>test_negate_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L337" class="LineNr"> 337 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L338" class="LineNr"> 338 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L339" class="LineNr"> 339 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L340" class="LineNr"> 340 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L341" class="LineNr"> 341 </span> <span class="Constant">" f7 db </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// negate EBX</span> +<span id="L342" class="LineNr"> 342 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (subop negate) 011 (dest EBX)</span> +<span id="L343" class="LineNr"> 343 </span> <span class="Delimiter">);</span> +<span id="L344" class="LineNr"> 344 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L345" class="LineNr"> 345 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L346" class="LineNr"> 346 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L347" class="LineNr"> 347 </span> <span class="Constant">"run: subop: negate</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L348" class="LineNr"> 348 </span> <span class="Constant">"run: storing 0xffffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L349" class="LineNr"> 349 </span> <span class="Delimiter">);</span> +<span id="L350" class="LineNr"> 350 </span><span class="Delimiter">}</span> +<span id="L351" class="LineNr"> 351 </span> +<span id="L352" class="LineNr"> 352 </span><span class="Delimiter">:(before "End Op f7 Subops")</span> +<span id="L353" class="LineNr"> 353 </span><span class="Normal">case</span> <span class="Constant">3</span>: <span class="Delimiter">{</span> <span class="Comment">// negate r/m32</span> +<span id="L354" class="LineNr"> 354 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop: negate"</span> << end<span class="Delimiter">();</span> +<span id="L355" class="LineNr"> 355 </span> <span class="Comment">// one case that can overflow</span> +<span id="L356" class="LineNr"> 356 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*arg1<span class="Delimiter">)</span> == <span class="Constant">0x80000000</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L357" class="LineNr"> 357 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"overflow"</span> << end<span class="Delimiter">();</span> +<span id="L358" class="LineNr"> 358 </span> SF = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L359" class="LineNr"> 359 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L360" class="LineNr"> 360 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L361" class="LineNr"> 361 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L362" class="LineNr"> 362 </span> <span class="Delimiter">}</span> +<span id="L363" class="LineNr"> 363 </span> <span class="Normal">int32_t</span> result = -<span class="Delimiter">(</span>*arg1<span class="Delimiter">);</span> +<span id="L364" class="LineNr"> 364 </span> SF = <span class="Delimiter">(</span>result >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L365" class="LineNr"> 365 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>result == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L366" class="LineNr"> 366 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L367" class="LineNr"> 367 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>*arg1 != <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L368" class="LineNr"> 368 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L369" class="LineNr"> 369 </span> *arg1 = result<span class="Delimiter">;</span> +<span id="L370" class="LineNr"> 370 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *arg1 << end<span class="Delimiter">();</span> +<span id="L371" class="LineNr"> 371 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L372" class="LineNr"> 372 </span><span class="Delimiter">}</span> +<span id="L373" class="LineNr"> 373 </span> +<span id="L374" class="LineNr"> 374 </span><span class="Delimiter">:(code)</span> +<span id="L375" class="LineNr"> 375 </span><span class="Comment">// negate can overflow in exactly one situation</span> +<span id="L376" class="LineNr"> 376 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L376'>test_negate_can_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L377" class="LineNr"> 377 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MIN</span><span class="Delimiter">;</span> +<span id="L378" class="LineNr"> 378 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L379" class="LineNr"> 379 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L380" class="LineNr"> 380 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L381" class="LineNr"> 381 </span> <span class="Constant">" f7 db </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// negate EBX</span> +<span id="L382" class="LineNr"> 382 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (subop negate) 011 (dest EBX)</span> +<span id="L383" class="LineNr"> 383 </span> <span class="Delimiter">);</span> +<span id="L384" class="LineNr"> 384 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L385" class="LineNr"> 385 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L386" class="LineNr"> 386 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L387" class="LineNr"> 387 </span> <span class="Constant">"run: subop: negate</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L388" class="LineNr"> 388 </span> <span class="Constant">"run: overflow</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L389" class="LineNr"> 389 </span> <span class="Delimiter">);</span> +<span id="L390" class="LineNr"> 390 </span><span class="Delimiter">}</span> +<span id="L391" class="LineNr"> 391 </span> +<span id="L392" class="LineNr"> 392 </span><span class="Comment">//:: divide with remainder</span> +<span id="L393" class="LineNr"> 393 </span> +<span id="L394" class="LineNr"> 394 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L394'>test_divide_EAX_by_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L395" class="LineNr"> 395 </span> Reg[EAX]<span class="Delimiter">.</span>u = <span class="Constant">7</span><span class="Delimiter">;</span> +<span id="L396" class="LineNr"> 396 </span> Reg[EDX]<span class="Delimiter">.</span>u = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L397" class="LineNr"> 397 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">3</span><span class="Delimiter">;</span> +<span id="L398" class="LineNr"> 398 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L399" class="LineNr"> 399 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L400" class="LineNr"> 400 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L401" class="LineNr"> 401 </span> <span class="Constant">" f7 f9 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// multiply EAX by ECX</span> +<span id="L402" class="LineNr"> 402 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop idiv) 001 (divisor ECX)</span> +<span id="L403" class="LineNr"> 403 </span> <span class="Delimiter">);</span> +<span id="L404" class="LineNr"> 404 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L405" class="LineNr"> 405 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L406" class="LineNr"> 406 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L11'>ECX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L407" class="LineNr"> 407 </span> <span class="Constant">"run: subop: divide <a href='010vm.cc.html#L12'>EDX</a>:<a href='010vm.cc.html#L10'>EAX</a> by r/m32, storing quotient in <a href='010vm.cc.html#L10'>EAX</a> and remainder in <a href='010vm.cc.html#L12'>EDX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L408" class="LineNr"> 408 </span> <span class="Constant">"run: quotient: 0x00000002</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L409" class="LineNr"> 409 </span> <span class="Constant">"run: remainder: 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L410" class="LineNr"> 410 </span> <span class="Delimiter">);</span> +<span id="L411" class="LineNr"> 411 </span><span class="Delimiter">}</span> +<span id="L412" class="LineNr"> 412 </span> +<span id="L413" class="LineNr"> 413 </span><span class="Delimiter">:(before "End Op f7 Subops")</span> +<span id="L414" class="LineNr"> 414 </span><span class="Normal">case</span> <span class="Constant">7</span>: <span class="Delimiter">{</span> <span class="Comment">// divide EDX:EAX by r/m32, storing quotient in EAX and remainder in EDX</span> +<span id="L415" class="LineNr"> 415 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop: divide <a href='010vm.cc.html#L12'>EDX</a>:<a href='010vm.cc.html#L10'>EAX</a> by r/m32, storing quotient in <a href='010vm.cc.html#L10'>EAX</a> and remainder in EDX"</span> << end<span class="Delimiter">();</span> +<span id="L416" class="LineNr"> 416 </span> <span class="Normal">int64_t</span> dividend = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">((</span><span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>Reg[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << <span class="Constant">32</span><span class="Delimiter">)</span> | Reg[EAX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L417" class="LineNr"> 417 </span> <span class="Normal">int32_t</span> divisor = *arg1<span class="Delimiter">;</span> +<span id="L418" class="LineNr"> 418 </span> assert<span class="Delimiter">(</span>divisor != <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L419" class="LineNr"> 419 </span> Reg[EAX]<span class="Delimiter">.</span>i = dividend/divisor<span class="Delimiter">;</span> <span class="Comment">// quotient</span> +<span id="L420" class="LineNr"> 420 </span> Reg[EDX]<span class="Delimiter">.</span>i = dividend%divisor<span class="Delimiter">;</span> <span class="Comment">// remainder</span> +<span id="L421" class="LineNr"> 421 </span> <span class="Comment">// flag state undefined</span> +<span id="L422" class="LineNr"> 422 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"quotient: 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L423" class="LineNr"> 423 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"remainder: 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[EDX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L424" class="LineNr"> 424 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L425" class="LineNr"> 425 </span><span class="Delimiter">}</span> +<span id="L426" class="LineNr"> 426 </span> +<span id="L427" class="LineNr"> 427 </span><span class="Delimiter">:(code)</span> +<span id="L428" class="LineNr"> 428 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L428'>test_divide_EAX_by_negative_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L429" class="LineNr"> 429 </span> Reg[EAX]<span class="Delimiter">.</span>u = <span class="Constant">7</span><span class="Delimiter">;</span> +<span id="L430" class="LineNr"> 430 </span> Reg[EDX]<span class="Delimiter">.</span>u = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L431" class="LineNr"> 431 </span> Reg[ECX]<span class="Delimiter">.</span>i = -<span class="Constant">3</span><span class="Delimiter">;</span> +<span id="L432" class="LineNr"> 432 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L433" class="LineNr"> 433 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L434" class="LineNr"> 434 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L435" class="LineNr"> 435 </span> <span class="Constant">" f7 f9 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// multiply EAX by ECX</span> +<span id="L436" class="LineNr"> 436 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop idiv) 001 (divisor ECX)</span> +<span id="L437" class="LineNr"> 437 </span> <span class="Delimiter">);</span> +<span id="L438" class="LineNr"> 438 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L439" class="LineNr"> 439 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L440" class="LineNr"> 440 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L11'>ECX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L441" class="LineNr"> 441 </span> <span class="Constant">"run: subop: divide <a href='010vm.cc.html#L12'>EDX</a>:<a href='010vm.cc.html#L10'>EAX</a> by r/m32, storing quotient in <a href='010vm.cc.html#L10'>EAX</a> and remainder in <a href='010vm.cc.html#L12'>EDX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L442" class="LineNr"> 442 </span> <span class="Constant">"run: quotient: 0xfffffffe</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// -2</span> +<span id="L443" class="LineNr"> 443 </span> <span class="Constant">"run: remainder: 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L444" class="LineNr"> 444 </span> <span class="Delimiter">);</span> +<span id="L445" class="LineNr"> 445 </span><span class="Delimiter">}</span> +<span id="L446" class="LineNr"> 446 </span> +<span id="L447" class="LineNr"> 447 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L447'>test_divide_negative_EAX_by_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L448" class="LineNr"> 448 </span> Reg[EAX]<span class="Delimiter">.</span>i = -<span class="Constant">7</span><span class="Delimiter">;</span> +<span id="L449" class="LineNr"> 449 </span> Reg[EDX]<span class="Delimiter">.</span>i = -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// sign extend</span> +<span id="L450" class="LineNr"> 450 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">3</span><span class="Delimiter">;</span> +<span id="L451" class="LineNr"> 451 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L452" class="LineNr"> 452 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L453" class="LineNr"> 453 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L454" class="LineNr"> 454 </span> <span class="Constant">" f7 f9 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// multiply EAX by ECX</span> +<span id="L455" class="LineNr"> 455 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop idiv) 001 (divisor ECX)</span> +<span id="L456" class="LineNr"> 456 </span> <span class="Delimiter">);</span> +<span id="L457" class="LineNr"> 457 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L458" class="LineNr"> 458 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L459" class="LineNr"> 459 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L11'>ECX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L460" class="LineNr"> 460 </span> <span class="Constant">"run: subop: divide <a href='010vm.cc.html#L12'>EDX</a>:<a href='010vm.cc.html#L10'>EAX</a> by r/m32, storing quotient in <a href='010vm.cc.html#L10'>EAX</a> and remainder in <a href='010vm.cc.html#L12'>EDX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L461" class="LineNr"> 461 </span> <span class="Constant">"run: quotient: 0xfffffffe</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// -2</span> +<span id="L462" class="LineNr"> 462 </span> <span class="Constant">"run: remainder: 0xffffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// -1, same sign as divident (EDX:EAX)</span> +<span id="L463" class="LineNr"> 463 </span> <span class="Delimiter">);</span> +<span id="L464" class="LineNr"> 464 </span><span class="Delimiter">}</span> +<span id="L465" class="LineNr"> 465 </span> +<span id="L466" class="LineNr"> 466 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L466'>test_divide_negative_EDX_EAX_by_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L467" class="LineNr"> 467 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// lower 32 bits are clear</span> +<span id="L468" class="LineNr"> 468 </span> Reg[EDX]<span class="Delimiter">.</span>i = -<span class="Constant">7</span><span class="Delimiter">;</span> +<span id="L469" class="LineNr"> 469 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">0x40000000</span><span class="Delimiter">;</span> <span class="Comment">// 2^30 (largest positive power of 2)</span> +<span id="L470" class="LineNr"> 470 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L471" class="LineNr"> 471 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L472" class="LineNr"> 472 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L473" class="LineNr"> 473 </span> <span class="Constant">" f7 f9 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// multiply EAX by ECX</span> +<span id="L474" class="LineNr"> 474 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop idiv) 001 (divisor ECX)</span> +<span id="L475" class="LineNr"> 475 </span> <span class="Delimiter">);</span> +<span id="L476" class="LineNr"> 476 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L477" class="LineNr"> 477 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L478" class="LineNr"> 478 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L11'>ECX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L479" class="LineNr"> 479 </span> <span class="Constant">"run: subop: divide <a href='010vm.cc.html#L12'>EDX</a>:<a href='010vm.cc.html#L10'>EAX</a> by r/m32, storing quotient in <a href='010vm.cc.html#L10'>EAX</a> and remainder in <a href='010vm.cc.html#L12'>EDX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L480" class="LineNr"> 480 </span> <span class="Constant">"run: quotient: 0xffffffe4</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// (-7 << 32) / (1 << 30) = -7 << 2 = -28</span> +<span id="L481" class="LineNr"> 481 </span> <span class="Constant">"run: remainder: 0x00000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L482" class="LineNr"> 482 </span> <span class="Delimiter">);</span> +<span id="L483" class="LineNr"> 483 </span><span class="Delimiter">}</span> +<span id="L484" class="LineNr"> 484 </span> +<span id="L485" class="LineNr"> 485 </span><span class="Comment">//:: shift left</span> +<span id="L486" class="LineNr"> 486 </span> +<span id="L487" class="LineNr"> 487 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L488" class="LineNr"> 488 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"d3"</span><span class="Delimiter">,</span> <span class="Constant">"shift rm32 by CL bits depending on subop (sal/sar/shl/shr)"</span><span class="Delimiter">);</span> +<span id="L489" class="LineNr"> 489 </span> +<span id="L490" class="LineNr"> 490 </span><span class="Delimiter">:(code)</span> +<span id="L491" class="LineNr"> 491 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L491'>test_shift_left_r32_with_cl</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L492" class="LineNr"> 492 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">13</span><span class="Delimiter">;</span> +<span id="L493" class="LineNr"> 493 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L494" class="LineNr"> 494 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L495" class="LineNr"> 495 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L496" class="LineNr"> 496 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L497" class="LineNr"> 497 </span> <span class="Constant">" d3 e3 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX left by CL bits</span> +<span id="L498" class="LineNr"> 498 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 100 (subop shift left) 011 (dest EBX)</span> +<span id="L499" class="LineNr"> 499 </span> <span class="Delimiter">);</span> +<span id="L500" class="LineNr"> 500 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L501" class="LineNr"> 501 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L502" class="LineNr"> 502 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L503" class="LineNr"> 503 </span> <span class="Constant">"run: subop: shift left by CL bits</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L504" class="LineNr"> 504 </span> <span class="Constant">"run: storing 0x0000001a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L505" class="LineNr"> 505 </span> <span class="Delimiter">);</span> +<span id="L506" class="LineNr"> 506 </span><span class="Delimiter">}</span> +<span id="L507" class="LineNr"> 507 </span> +<span id="L508" class="LineNr"> 508 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L509" class="LineNr"> 509 </span><span class="Normal">case</span> <span class="Constant">0xd3</span>: <span class="Delimiter">{</span> +<span id="L510" class="LineNr"> 510 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L511" class="LineNr"> 511 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"operate on r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L512" class="LineNr"> 512 </span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L513" class="LineNr"> 513 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> subop = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span class="Comment">// middle 3 'reg opcode' bits</span> +<span id="L514" class="LineNr"> 514 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>subop<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L515" class="LineNr"> 515 </span> <span class="Normal">case</span> <span class="Constant">4</span>: <span class="Delimiter">{</span> <span class="Comment">// shift left r/m32 by CL</span> +<span id="L516" class="LineNr"> 516 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop: shift left by CL bits"</span> << end<span class="Delimiter">();</span> +<span id="L517" class="LineNr"> 517 </span> <span class="Normal">uint8_t</span> count = Reg[ECX]<span class="Delimiter">.</span>u & <span class="Constant">0x1f</span><span class="Delimiter">;</span> +<span id="L518" class="LineNr"> 518 </span> <span class="Comment">// OF is only defined if count is 1</span> +<span id="L519" class="LineNr"> 519 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>count == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L520" class="LineNr"> 520 </span> <span class="Normal">bool</span> msb = <span class="Delimiter">(</span>*arg1 & <span class="Constant">0x80000000</span><span class="Delimiter">)</span> >> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L521" class="LineNr"> 521 </span> <span class="Normal">bool</span> pnsb = <span class="Delimiter">(</span>*arg1 & <span class="Constant">0x40000000</span><span class="Delimiter">);</span> +<span id="L522" class="LineNr"> 522 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>msb != pnsb<span class="Delimiter">);</span> +<span id="L523" class="LineNr"> 523 </span> <span class="Delimiter">}</span> +<span id="L524" class="LineNr"> 524 </span> <span class="Normal">int32_t</span> result = <span class="Delimiter">(</span>*arg1 << count<span class="Delimiter">);</span> +<span id="L525" class="LineNr"> 525 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>result == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L526" class="LineNr"> 526 </span> SF = <span class="Delimiter">(</span>result < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L527" class="LineNr"> 527 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>*arg1 << <span class="Delimiter">(</span>count-<span class="Constant">1</span><span class="Delimiter">))</span> & <span class="Constant">0x80000000</span><span class="Delimiter">;</span> +<span id="L528" class="LineNr"> 528 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L529" class="LineNr"> 529 </span> *arg1 = result<span class="Delimiter">;</span> +<span id="L530" class="LineNr"> 530 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *arg1 << end<span class="Delimiter">();</span> +<span id="L531" class="LineNr"> 531 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L532" class="LineNr"> 532 </span> <span class="Delimiter">}</span> +<span id="L533" class="LineNr"> 533 </span> <span class="Comment">// End Op d3 Subops</span> +<span id="L534" class="LineNr"> 534 </span> <span class="Normal">default</span>: +<span id="L535" class="LineNr"> 535 </span> cerr << <span class="Constant">"unrecognized subop for opcode d3: "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L536" class="LineNr"> 536 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L537" class="LineNr"> 537 </span> <span class="Delimiter">}</span> +<span id="L538" class="LineNr"> 538 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L539" class="LineNr"> 539 </span><span class="Delimiter">}</span> +<span id="L540" class="LineNr"> 540 </span> +<span id="L541" class="LineNr"> 541 </span><span class="Comment">//:: shift right arithmetic</span> +<span id="L542" class="LineNr"> 542 </span> +<span id="L543" class="LineNr"> 543 </span><span class="Delimiter">:(code)</span> +<span id="L544" class="LineNr"> 544 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L544'>test_shift_right_arithmetic_r32_with_cl</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L545" class="LineNr"> 545 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">26</span><span class="Delimiter">;</span> +<span id="L546" class="LineNr"> 546 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L547" class="LineNr"> 547 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L548" class="LineNr"> 548 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L549" class="LineNr"> 549 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L550" class="LineNr"> 550 </span> <span class="Constant">" d3 fb </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX right by CL bits, while preserving sign</span> +<span id="L551" class="LineNr"> 551 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop shift right arithmetic) 011 (dest EBX)</span> +<span id="L552" class="LineNr"> 552 </span> <span class="Delimiter">);</span> +<span id="L553" class="LineNr"> 553 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L554" class="LineNr"> 554 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L555" class="LineNr"> 555 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L556" class="LineNr"> 556 </span> <span class="Constant">"run: subop: shift right by CL bits, while preserving sign</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L557" class="LineNr"> 557 </span> <span class="Constant">"run: storing 0x0000000d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L558" class="LineNr"> 558 </span> <span class="Delimiter">);</span> +<span id="L559" class="LineNr"> 559 </span><span class="Delimiter">}</span> +<span id="L560" class="LineNr"> 560 </span> +<span id="L561" class="LineNr"> 561 </span><span class="Delimiter">:(before "End Op d3 Subops")</span> +<span id="L562" class="LineNr"> 562 </span><span class="Normal">case</span> <span class="Constant">7</span>: <span class="Delimiter">{</span> <span class="Comment">// shift right r/m32 by CL, preserving sign</span> +<span id="L563" class="LineNr"> 563 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop: shift right by CL bits, while preserving sign"</span> << end<span class="Delimiter">();</span> +<span id="L564" class="LineNr"> 564 </span> <span class="Normal">uint8_t</span> count = Reg[ECX]<span class="Delimiter">.</span>u & <span class="Constant">0x1f</span><span class="Delimiter">;</span> +<span id="L565" class="LineNr"> 565 </span> *arg1 = <span class="Delimiter">(</span>*arg1 >> count<span class="Delimiter">);</span> +<span id="L566" class="LineNr"> 566 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>*arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L567" class="LineNr"> 567 </span> SF = <span class="Delimiter">(</span>*arg1 < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L568" class="LineNr"> 568 </span> <span class="Comment">// OF is only defined if count is 1</span> +<span id="L569" class="LineNr"> 569 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>count == <span class="Constant">1</span><span class="Delimiter">)</span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L570" class="LineNr"> 570 </span> <span class="Comment">// CF undefined</span> +<span id="L571" class="LineNr"> 571 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *arg1 << end<span class="Delimiter">();</span> +<span id="L572" class="LineNr"> 572 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L573" class="LineNr"> 573 </span><span class="Delimiter">}</span> +<span id="L574" class="LineNr"> 574 </span> +<span id="L575" class="LineNr"> 575 </span><span class="Delimiter">:(code)</span> +<span id="L576" class="LineNr"> 576 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L576'>test_shift_right_arithmetic_odd_r32_with_cl</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L577" class="LineNr"> 577 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">27</span><span class="Delimiter">;</span> +<span id="L578" class="LineNr"> 578 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L579" class="LineNr"> 579 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L580" class="LineNr"> 580 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L581" class="LineNr"> 581 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L582" class="LineNr"> 582 </span> <span class="Constant">" d3 fb </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX right by CL bits, while preserving sign</span> +<span id="L583" class="LineNr"> 583 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop shift right arithmetic) 011 (dest EBX)</span> +<span id="L584" class="LineNr"> 584 </span> <span class="Delimiter">);</span> +<span id="L585" class="LineNr"> 585 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L586" class="LineNr"> 586 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L587" class="LineNr"> 587 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L588" class="LineNr"> 588 </span> <span class="Constant">"run: subop: shift right by CL bits, while preserving sign</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L589" class="LineNr"> 589 </span> <span class="Comment">// result: 13</span> +<span id="L590" class="LineNr"> 590 </span> <span class="Constant">"run: storing 0x0000000d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L591" class="LineNr"> 591 </span> <span class="Delimiter">);</span> +<span id="L592" class="LineNr"> 592 </span><span class="Delimiter">}</span> +<span id="L593" class="LineNr"> 593 </span> +<span id="L594" class="LineNr"> 594 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L594'>test_shift_right_arithmetic_negative_r32_with_cl</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L595" class="LineNr"> 595 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xfffffffd</span><span class="Delimiter">;</span> <span class="Comment">// -3</span> +<span id="L596" class="LineNr"> 596 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L597" class="LineNr"> 597 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L598" class="LineNr"> 598 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L599" class="LineNr"> 599 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L600" class="LineNr"> 600 </span> <span class="Constant">" d3 fb </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX right by CL bits, while preserving sign</span> +<span id="L601" class="LineNr"> 601 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop shift right arithmetic) 011 (dest EBX)</span> +<span id="L602" class="LineNr"> 602 </span> <span class="Delimiter">);</span> +<span id="L603" class="LineNr"> 603 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L604" class="LineNr"> 604 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L605" class="LineNr"> 605 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L606" class="LineNr"> 606 </span> <span class="Constant">"run: subop: shift right by CL bits, while preserving sign</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L607" class="LineNr"> 607 </span> <span class="Comment">// result: -2</span> +<span id="L608" class="LineNr"> 608 </span> <span class="Constant">"run: storing 0xfffffffe</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L609" class="LineNr"> 609 </span> <span class="Delimiter">);</span> +<span id="L610" class="LineNr"> 610 </span><span class="Delimiter">}</span> +<span id="L611" class="LineNr"> 611 </span> +<span id="L612" class="LineNr"> 612 </span><span class="Comment">//:: shift right logical</span> +<span id="L613" class="LineNr"> 613 </span> +<span id="L614" class="LineNr"> 614 </span><span class="Delimiter">:(code)</span> +<span id="L615" class="LineNr"> 615 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L615'>test_shift_right_logical_r32_with_cl</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L616" class="LineNr"> 616 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">26</span><span class="Delimiter">;</span> +<span id="L617" class="LineNr"> 617 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L618" class="LineNr"> 618 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L619" class="LineNr"> 619 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L620" class="LineNr"> 620 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L621" class="LineNr"> 621 </span> <span class="Constant">" d3 eb </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX right by CL bits, while padding zeroes</span> +<span id="L622" class="LineNr"> 622 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 101 (subop shift right logical) 011 (dest EBX)</span> +<span id="L623" class="LineNr"> 623 </span> <span class="Delimiter">);</span> +<span id="L624" class="LineNr"> 624 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L625" class="LineNr"> 625 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L626" class="LineNr"> 626 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L627" class="LineNr"> 627 </span> <span class="Constant">"run: subop: shift right by CL bits, while padding zeroes</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L628" class="LineNr"> 628 </span> <span class="Comment">// result: 13</span> +<span id="L629" class="LineNr"> 629 </span> <span class="Constant">"run: storing 0x0000000d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L630" class="LineNr"> 630 </span> <span class="Delimiter">);</span> +<span id="L631" class="LineNr"> 631 </span><span class="Delimiter">}</span> +<span id="L632" class="LineNr"> 632 </span> +<span id="L633" class="LineNr"> 633 </span><span class="Delimiter">:(before "End Op d3 Subops")</span> +<span id="L634" class="LineNr"> 634 </span><span class="Normal">case</span> <span class="Constant">5</span>: <span class="Delimiter">{</span> <span class="Comment">// shift right r/m32 by CL, padding zeroes</span> +<span id="L635" class="LineNr"> 635 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop: shift right by CL bits, while padding zeroes"</span> << end<span class="Delimiter">();</span> +<span id="L636" class="LineNr"> 636 </span> <span class="Normal">uint8_t</span> count = Reg[ECX]<span class="Delimiter">.</span>u & <span class="Constant">0x1f</span><span class="Delimiter">;</span> +<span id="L637" class="LineNr"> 637 </span> <span class="Comment">// OF is only defined if count is 1</span> +<span id="L638" class="LineNr"> 638 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>count == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L639" class="LineNr"> 639 </span> <span class="Normal">bool</span> msb = <span class="Delimiter">(</span>*arg1 & <span class="Constant">0x80000000</span><span class="Delimiter">)</span> >> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L640" class="LineNr"> 640 </span> <span class="Normal">bool</span> pnsb = <span class="Delimiter">(</span>*arg1 & <span class="Constant">0x40000000</span><span class="Delimiter">);</span> +<span id="L641" class="LineNr"> 641 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>msb != pnsb<span class="Delimiter">);</span> +<span id="L642" class="LineNr"> 642 </span> <span class="Delimiter">}</span> +<span id="L643" class="LineNr"> 643 </span> <span class="Normal">uint32_t</span>* uarg1 = <span class="Normal">reinterpret_cast</span><<span class="Normal">uint32_t</span>*><span class="Delimiter">(</span>arg1<span class="Delimiter">);</span> +<span id="L644" class="LineNr"> 644 </span> *uarg1 = <span class="Delimiter">(</span>*uarg1 >> count<span class="Delimiter">);</span> +<span id="L645" class="LineNr"> 645 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>*uarg1 == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L646" class="LineNr"> 646 </span> <span class="Comment">// result is always positive by definition</span> +<span id="L647" class="LineNr"> 647 </span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L648" class="LineNr"> 648 </span> <span class="Comment">// CF undefined</span> +<span id="L649" class="LineNr"> 649 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *arg1 << end<span class="Delimiter">();</span> +<span id="L650" class="LineNr"> 650 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L651" class="LineNr"> 651 </span><span class="Delimiter">}</span> +<span id="L652" class="LineNr"> 652 </span> +<span id="L653" class="LineNr"> 653 </span><span class="Delimiter">:(code)</span> +<span id="L654" class="LineNr"> 654 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L654'>test_shift_right_logical_odd_r32_with_cl</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L655" class="LineNr"> 655 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">27</span><span class="Delimiter">;</span> +<span id="L656" class="LineNr"> 656 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L657" class="LineNr"> 657 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L658" class="LineNr"> 658 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L659" class="LineNr"> 659 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L660" class="LineNr"> 660 </span> <span class="Constant">" d3 eb </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX right by CL bits, while padding zeroes</span> +<span id="L661" class="LineNr"> 661 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 101 (subop shift right logical) 011 (dest EBX)</span> +<span id="L662" class="LineNr"> 662 </span> <span class="Delimiter">);</span> +<span id="L663" class="LineNr"> 663 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L664" class="LineNr"> 664 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L665" class="LineNr"> 665 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L666" class="LineNr"> 666 </span> <span class="Constant">"run: subop: shift right by CL bits, while padding zeroes</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L667" class="LineNr"> 667 </span> <span class="Comment">// result: 13</span> +<span id="L668" class="LineNr"> 668 </span> <span class="Constant">"run: storing 0x0000000d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L669" class="LineNr"> 669 </span> <span class="Delimiter">);</span> +<span id="L670" class="LineNr"> 670 </span><span class="Delimiter">}</span> +<span id="L671" class="LineNr"> 671 </span> +<span id="L672" class="LineNr"> 672 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L672'>test_shift_right_logical_negative_r32_with_cl</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L673" class="LineNr"> 673 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xfffffffd</span><span class="Delimiter">;</span> +<span id="L674" class="LineNr"> 674 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L675" class="LineNr"> 675 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L676" class="LineNr"> 676 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L677" class="LineNr"> 677 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L678" class="LineNr"> 678 </span> <span class="Constant">" d3 eb </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX right by CL bits, while padding zeroes</span> +<span id="L679" class="LineNr"> 679 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 101 (subop shift right logical) 011 (dest EBX)</span> +<span id="L680" class="LineNr"> 680 </span> <span class="Delimiter">);</span> +<span id="L681" class="LineNr"> 681 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L682" class="LineNr"> 682 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L683" class="LineNr"> 683 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L684" class="LineNr"> 684 </span> <span class="Constant">"run: subop: shift right by CL bits, while padding zeroes</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L685" class="LineNr"> 685 </span> <span class="Constant">"run: storing 0x7ffffffe</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L686" class="LineNr"> 686 </span> <span class="Delimiter">);</span> +<span id="L687" class="LineNr"> 687 </span><span class="Delimiter">}</span> +<span id="L688" class="LineNr"> 688 </span> +<span id="L689" class="LineNr"> 689 </span><span class="Comment">//:: and</span> +<span id="L690" class="LineNr"> 690 </span> +<span id="L691" class="LineNr"> 691 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L692" class="LineNr"> 692 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"21"</span><span class="Delimiter">,</span> <span class="Constant">"rm32 = bitwise AND of r32 with rm32 (and)"</span><span class="Delimiter">);</span> +<span id="L693" class="LineNr"> 693 </span> +<span id="L694" class="LineNr"> 694 </span><span class="Delimiter">:(code)</span> +<span id="L695" class="LineNr"> 695 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L695'>test_and_r32_with_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L696" class="LineNr"> 696 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c0d</span><span class="Delimiter">;</span> +<span id="L697" class="LineNr"> 697 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x000000ff</span><span class="Delimiter">;</span> +<span id="L698" class="LineNr"> 698 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L699" class="LineNr"> 699 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L700" class="LineNr"> 700 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L701" class="LineNr"> 701 </span> <span class="Constant">" 21 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// and EBX with destination EAX</span> +<span id="L702" class="LineNr"> 702 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L703" class="LineNr"> 703 </span> <span class="Delimiter">);</span> +<span id="L704" class="LineNr"> 704 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L705" class="LineNr"> 705 </span> <span class="Constant">"run: and <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L706" class="LineNr"> 706 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L707" class="LineNr"> 707 </span> <span class="Constant">"run: storing 0x0000000d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L708" class="LineNr"> 708 </span> <span class="Delimiter">);</span> +<span id="L709" class="LineNr"> 709 </span><span class="Delimiter">}</span> +<span id="L710" class="LineNr"> 710 </span> +<span id="L711" class="LineNr"> 711 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L712" class="LineNr"> 712 </span><span class="Normal">case</span> <span class="Constant">0x21</span>: <span class="Delimiter">{</span> <span class="Comment">// and r32 with r/m32</span> +<span id="L713" class="LineNr"> 713 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L714" class="LineNr"> 714 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L715" class="LineNr"> 715 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"and "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>arg2<span class="Delimiter">)</span> << <span class="Constant">" with r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L716" class="LineNr"> 716 </span> <span class="Comment">// bitwise ops technically operate on unsigned numbers, but it makes no</span> +<span id="L717" class="LineNr"> 717 </span> <span class="Comment">// difference</span> +<span id="L718" class="LineNr"> 718 </span> <span class="Normal">int32_t</span>* signed_arg1 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L719" class="LineNr"> 719 </span> *signed_arg1 &= Reg[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L720" class="LineNr"> 720 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *signed_arg1 << end<span class="Delimiter">();</span> +<span id="L721" class="LineNr"> 721 </span> SF = <span class="Delimiter">(</span>*signed_arg1 >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L722" class="LineNr"> 722 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>*signed_arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L723" class="LineNr"> 723 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L724" class="LineNr"> 724 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L725" class="LineNr"> 725 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L726" class="LineNr"> 726 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L727" class="LineNr"> 727 </span><span class="Delimiter">}</span> +<span id="L728" class="LineNr"> 728 </span> +<span id="L729" class="LineNr"> 729 </span><span class="Comment">//:: or</span> +<span id="L730" class="LineNr"> 730 </span> +<span id="L731" class="LineNr"> 731 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L732" class="LineNr"> 732 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"09"</span><span class="Delimiter">,</span> <span class="Constant">"rm32 = bitwise OR of r32 with rm32 (or)"</span><span class="Delimiter">);</span> +<span id="L733" class="LineNr"> 733 </span> +<span id="L734" class="LineNr"> 734 </span><span class="Delimiter">:(code)</span> +<span id="L735" class="LineNr"> 735 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L735'>test_or_r32_with_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L736" class="LineNr"> 736 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c0d</span><span class="Delimiter">;</span> +<span id="L737" class="LineNr"> 737 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xa0b0c0d0</span><span class="Delimiter">;</span> +<span id="L738" class="LineNr"> 738 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L739" class="LineNr"> 739 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L740" class="LineNr"> 740 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L741" class="LineNr"> 741 </span> <span class="Constant">" 09 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// or EBX with destination EAX</span> +<span id="L742" class="LineNr"> 742 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L743" class="LineNr"> 743 </span> <span class="Delimiter">);</span> +<span id="L744" class="LineNr"> 744 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L745" class="LineNr"> 745 </span> <span class="Constant">"run: or <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L746" class="LineNr"> 746 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L747" class="LineNr"> 747 </span> <span class="Constant">"run: storing 0xaabbccdd</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L748" class="LineNr"> 748 </span> <span class="Delimiter">);</span> +<span id="L749" class="LineNr"> 749 </span><span class="Delimiter">}</span> +<span id="L750" class="LineNr"> 750 </span> +<span id="L751" class="LineNr"> 751 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L752" class="LineNr"> 752 </span><span class="Normal">case</span> <span class="Constant">0x09</span>: <span class="Delimiter">{</span> <span class="Comment">// or r32 with r/m32</span> +<span id="L753" class="LineNr"> 753 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L754" class="LineNr"> 754 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L755" class="LineNr"> 755 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"or "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>arg2<span class="Delimiter">)</span> << <span class="Constant">" with r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L756" class="LineNr"> 756 </span> <span class="Comment">// bitwise ops technically operate on unsigned numbers, but it makes no</span> +<span id="L757" class="LineNr"> 757 </span> <span class="Comment">// difference</span> +<span id="L758" class="LineNr"> 758 </span> <span class="Normal">int32_t</span>* signed_arg1 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L759" class="LineNr"> 759 </span> *signed_arg1 |= Reg[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L760" class="LineNr"> 760 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *signed_arg1 << end<span class="Delimiter">();</span> +<span id="L761" class="LineNr"> 761 </span> SF = <span class="Delimiter">(</span>*signed_arg1 >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L762" class="LineNr"> 762 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>*signed_arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L763" class="LineNr"> 763 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L764" class="LineNr"> 764 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L765" class="LineNr"> 765 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L766" class="LineNr"> 766 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L767" class="LineNr"> 767 </span><span class="Delimiter">}</span> +<span id="L768" class="LineNr"> 768 </span> +<span id="L769" class="LineNr"> 769 </span><span class="Comment">//:: xor</span> +<span id="L770" class="LineNr"> 770 </span> +<span id="L771" class="LineNr"> 771 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L772" class="LineNr"> 772 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"31"</span><span class="Delimiter">,</span> <span class="Constant">"rm32 = bitwise XOR of r32 with rm32 (xor)"</span><span class="Delimiter">);</span> +<span id="L773" class="LineNr"> 773 </span> +<span id="L774" class="LineNr"> 774 </span><span class="Delimiter">:(code)</span> +<span id="L775" class="LineNr"> 775 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L775'>test_xor_r32_with_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L776" class="LineNr"> 776 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c0d</span><span class="Delimiter">;</span> +<span id="L777" class="LineNr"> 777 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xaabbc0d0</span><span class="Delimiter">;</span> +<span id="L778" class="LineNr"> 778 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L779" class="LineNr"> 779 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L780" class="LineNr"> 780 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L781" class="LineNr"> 781 </span> <span class="Constant">" 31 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// xor EBX with destination EAX</span> +<span id="L782" class="LineNr"> 782 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L783" class="LineNr"> 783 </span> <span class="Delimiter">);</span> +<span id="L784" class="LineNr"> 784 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L785" class="LineNr"> 785 </span> <span class="Constant">"run: xor <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L786" class="LineNr"> 786 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L787" class="LineNr"> 787 </span> <span class="Constant">"run: storing 0xa0b0ccdd</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L788" class="LineNr"> 788 </span> <span class="Delimiter">);</span> +<span id="L789" class="LineNr"> 789 </span><span class="Delimiter">}</span> +<span id="L790" class="LineNr"> 790 </span> +<span id="L791" class="LineNr"> 791 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L792" class="LineNr"> 792 </span><span class="Normal">case</span> <span class="Constant">0x31</span>: <span class="Delimiter">{</span> <span class="Comment">// xor r32 with r/m32</span> +<span id="L793" class="LineNr"> 793 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L794" class="LineNr"> 794 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L795" class="LineNr"> 795 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"xor "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>arg2<span class="Delimiter">)</span> << <span class="Constant">" with r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L796" class="LineNr"> 796 </span> <span class="Comment">// bitwise ops technically operate on unsigned numbers, but it makes no</span> +<span id="L797" class="LineNr"> 797 </span> <span class="Comment">// difference</span> +<span id="L798" class="LineNr"> 798 </span> <span class="Normal">int32_t</span>* signed_arg1 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L799" class="LineNr"> 799 </span> *signed_arg1 ^= Reg[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L800" class="LineNr"> 800 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *signed_arg1 << end<span class="Delimiter">();</span> +<span id="L801" class="LineNr"> 801 </span> SF = <span class="Delimiter">(</span>*signed_arg1 >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L802" class="LineNr"> 802 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>*signed_arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L803" class="LineNr"> 803 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L804" class="LineNr"> 804 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L805" class="LineNr"> 805 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L806" class="LineNr"> 806 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L807" class="LineNr"> 807 </span><span class="Delimiter">}</span> +<span id="L808" class="LineNr"> 808 </span> +<span id="L809" class="LineNr"> 809 </span><span class="Comment">//:: not</span> +<span id="L810" class="LineNr"> 810 </span> +<span id="L811" class="LineNr"> 811 </span><span class="Delimiter">:(code)</span> +<span id="L812" class="LineNr"> 812 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L812'>test_not_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L813" class="LineNr"> 813 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0f0f00ff</span><span class="Delimiter">;</span> +<span id="L814" class="LineNr"> 814 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L815" class="LineNr"> 815 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L816" class="LineNr"> 816 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L817" class="LineNr"> 817 </span> <span class="Constant">" f7 d3 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// not EBX</span> +<span id="L818" class="LineNr"> 818 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 010 (subop not) 011 (dest EBX)</span> +<span id="L819" class="LineNr"> 819 </span> <span class="Delimiter">);</span> +<span id="L820" class="LineNr"> 820 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L821" class="LineNr"> 821 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L822" class="LineNr"> 822 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L823" class="LineNr"> 823 </span> <span class="Constant">"run: subop: not</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L824" class="LineNr"> 824 </span> <span class="Constant">"run: storing 0xf0f0ff00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L825" class="LineNr"> 825 </span> <span class="Delimiter">);</span> +<span id="L826" class="LineNr"> 826 </span><span class="Delimiter">}</span> +<span id="L827" class="LineNr"> 827 </span> +<span id="L828" class="LineNr"> 828 </span><span class="Delimiter">:(before "End Op f7 Subops")</span> +<span id="L829" class="LineNr"> 829 </span><span class="Normal">case</span> <span class="Constant">2</span>: <span class="Delimiter">{</span> <span class="Comment">// not r/m32</span> +<span id="L830" class="LineNr"> 830 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop: not"</span> << end<span class="Delimiter">();</span> +<span id="L831" class="LineNr"> 831 </span> *arg1 = ~<span class="Delimiter">(</span>*arg1<span class="Delimiter">);</span> +<span id="L832" class="LineNr"> 832 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *arg1 << end<span class="Delimiter">();</span> +<span id="L833" class="LineNr"> 833 </span> <span class="Comment">// no flags affected</span> +<span id="L834" class="LineNr"> 834 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L835" class="LineNr"> 835 </span><span class="Delimiter">}</span> +<span id="L836" class="LineNr"> 836 </span> +<span id="L837" class="LineNr"> 837 </span><span class="Comment">//:: compare (cmp)</span> +<span id="L838" class="LineNr"> 838 </span> +<span id="L839" class="LineNr"> 839 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L840" class="LineNr"> 840 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"39"</span><span class="Delimiter">,</span> <span class="Constant">"compare: set SF if rm32 < r32 (cmp)"</span><span class="Delimiter">);</span> +<span id="L841" class="LineNr"> 841 </span> +<span id="L842" class="LineNr"> 842 </span><span class="Delimiter">:(code)</span> +<span id="L843" class="LineNr"> 843 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L843'>test_compare_r32_with_r32_greater</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L844" class="LineNr"> 844 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c0d</span><span class="Delimiter">;</span> +<span id="L845" class="LineNr"> 845 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c07</span><span class="Delimiter">;</span> +<span id="L846" class="LineNr"> 846 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L847" class="LineNr"> 847 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L848" class="LineNr"> 848 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L849" class="LineNr"> 849 </span> <span class="Constant">" 39 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with EBX</span> +<span id="L850" class="LineNr"> 850 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (rhs EBX) 000 (lhs EAX)</span> +<span id="L851" class="LineNr"> 851 </span> <span class="Delimiter">);</span> +<span id="L852" class="LineNr"> 852 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L853" class="LineNr"> 853 </span> <span class="Constant">"run: compare r/m32 with <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L854" class="LineNr"> 854 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L855" class="LineNr"> 855 </span> <span class="Constant">"run: SF=0; ZF=0; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L856" class="LineNr"> 856 </span> <span class="Delimiter">);</span> +<span id="L857" class="LineNr"> 857 </span><span class="Delimiter">}</span> +<span id="L858" class="LineNr"> 858 </span> +<span id="L859" class="LineNr"> 859 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L860" class="LineNr"> 860 </span><span class="Normal">case</span> <span class="Constant">0x39</span>: <span class="Delimiter">{</span> <span class="Comment">// set SF if r/m32 < r32</span> +<span id="L861" class="LineNr"> 861 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L862" class="LineNr"> 862 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> reg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L863" class="LineNr"> 863 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"compare r/m32 with "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>reg2<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L864" class="LineNr"> 864 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* signed_arg1 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L865" class="LineNr"> 865 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> signed_difference = *signed_arg1 - Reg[reg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L866" class="LineNr"> 866 </span> SF = <span class="Delimiter">(</span>signed_difference < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L867" class="LineNr"> 867 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>signed_difference == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L868" class="LineNr"> 868 </span> <span class="Normal">const</span> <span class="Normal">int64_t</span> signed_full_difference = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">)</span> - Reg[reg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L869" class="LineNr"> 869 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>signed_difference != signed_full_difference<span class="Delimiter">);</span> +<span id="L870" class="LineNr"> 870 </span> <span class="Comment">// set CF</span> +<span id="L871" class="LineNr"> 871 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> unsigned_arg1 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">);</span> +<span id="L872" class="LineNr"> 872 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> unsigned_difference = unsigned_arg1 - Reg[reg2]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L873" class="LineNr"> 873 </span> <span class="Normal">const</span> <span class="Normal">uint64_t</span> unsigned_full_difference = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>unsigned_arg1<span class="Delimiter">)</span> - Reg[reg2]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L874" class="LineNr"> 874 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>unsigned_difference != unsigned_full_difference<span class="Delimiter">);</span> +<span id="L875" class="LineNr"> 875 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L876" class="LineNr"> 876 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L877" class="LineNr"> 877 </span><span class="Delimiter">}</span> +<span id="L878" class="LineNr"> 878 </span> +<span id="L879" class="LineNr"> 879 </span><span class="Delimiter">:(code)</span> +<span id="L880" class="LineNr"> 880 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L880'>test_compare_r32_with_r32_lesser_unsigned_and_signed</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L881" class="LineNr"> 881 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c07</span><span class="Delimiter">;</span> +<span id="L882" class="LineNr"> 882 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c0d</span><span class="Delimiter">;</span> +<span id="L883" class="LineNr"> 883 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L884" class="LineNr"> 884 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L885" class="LineNr"> 885 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L886" class="LineNr"> 886 </span> <span class="Constant">" 39 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with EBX</span> +<span id="L887" class="LineNr"> 887 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (rhs EBX) 000 (lhs EAX)</span> +<span id="L888" class="LineNr"> 888 </span> <span class="Delimiter">);</span> +<span id="L889" class="LineNr"> 889 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L890" class="LineNr"> 890 </span> <span class="Constant">"run: compare r/m32 with <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L891" class="LineNr"> 891 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L892" class="LineNr"> 892 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L893" class="LineNr"> 893 </span> <span class="Delimiter">);</span> +<span id="L894" class="LineNr"> 894 </span><span class="Delimiter">}</span> +<span id="L895" class="LineNr"> 895 </span> +<span id="L896" class="LineNr"> 896 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L896'>test_compare_r32_with_r32_lesser_unsigned_and_signed_due_to_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L897" class="LineNr"> 897 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MAX</span><span class="Delimiter">;</span> +<span id="L898" class="LineNr"> 898 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MIN</span><span class="Delimiter">;</span> +<span id="L899" class="LineNr"> 899 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L900" class="LineNr"> 900 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L901" class="LineNr"> 901 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L902" class="LineNr"> 902 </span> <span class="Constant">" 39 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with EBX</span> +<span id="L903" class="LineNr"> 903 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (rhs EBX) 000 (lhs EAX)</span> +<span id="L904" class="LineNr"> 904 </span> <span class="Delimiter">);</span> +<span id="L905" class="LineNr"> 905 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L906" class="LineNr"> 906 </span> <span class="Constant">"run: compare r/m32 with <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L907" class="LineNr"> 907 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L908" class="LineNr"> 908 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L909" class="LineNr"> 909 </span> <span class="Delimiter">);</span> +<span id="L910" class="LineNr"> 910 </span><span class="Delimiter">}</span> +<span id="L911" class="LineNr"> 911 </span> +<span id="L912" class="LineNr"> 912 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L912'>test_compare_r32_with_r32_lesser_signed</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L913" class="LineNr"> 913 </span> Reg[EAX]<span class="Delimiter">.</span>i = -<span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L914" class="LineNr"> 914 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L915" class="LineNr"> 915 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L916" class="LineNr"> 916 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L917" class="LineNr"> 917 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L918" class="LineNr"> 918 </span> <span class="Constant">" 39 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with EBX</span> +<span id="L919" class="LineNr"> 919 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (rhs EBX) 000 (lhs EAX)</span> +<span id="L920" class="LineNr"> 920 </span> <span class="Delimiter">);</span> +<span id="L921" class="LineNr"> 921 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L922" class="LineNr"> 922 </span> <span class="Constant">"run: compare r/m32 with <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L923" class="LineNr"> 923 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L924" class="LineNr"> 924 </span> <span class="Constant">"run: SF=1; ZF=0; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L925" class="LineNr"> 925 </span> <span class="Delimiter">);</span> +<span id="L926" class="LineNr"> 926 </span><span class="Delimiter">}</span> +<span id="L927" class="LineNr"> 927 </span> +<span id="L928" class="LineNr"> 928 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L928'>test_compare_r32_with_r32_lesser_unsigned</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L929" class="LineNr"> 929 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L930" class="LineNr"> 930 </span> Reg[EBX]<span class="Delimiter">.</span>i = -<span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L931" class="LineNr"> 931 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L932" class="LineNr"> 932 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L933" class="LineNr"> 933 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L934" class="LineNr"> 934 </span> <span class="Constant">" 39 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with EBX</span> +<span id="L935" class="LineNr"> 935 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (rhs EBX) 000 (lhs EAX)</span> +<span id="L936" class="LineNr"> 936 </span> <span class="Delimiter">);</span> +<span id="L937" class="LineNr"> 937 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L938" class="LineNr"> 938 </span> <span class="Constant">"run: compare r/m32 with <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L939" class="LineNr"> 939 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L940" class="LineNr"> 940 </span> <span class="Constant">"run: SF=0; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L941" class="LineNr"> 941 </span> <span class="Delimiter">);</span> +<span id="L942" class="LineNr"> 942 </span><span class="Delimiter">}</span> +<span id="L943" class="LineNr"> 943 </span> +<span id="L944" class="LineNr"> 944 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L944'>test_compare_r32_with_r32_equal</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L945" class="LineNr"> 945 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c0d</span><span class="Delimiter">;</span> +<span id="L946" class="LineNr"> 946 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c0d</span><span class="Delimiter">;</span> +<span id="L947" class="LineNr"> 947 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L948" class="LineNr"> 948 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L949" class="LineNr"> 949 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L950" class="LineNr"> 950 </span> <span class="Constant">" 39 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX and EBX</span> +<span id="L951" class="LineNr"> 951 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (rhs EBX) 000 (lhs EAX)</span> +<span id="L952" class="LineNr"> 952 </span> <span class="Delimiter">);</span> +<span id="L953" class="LineNr"> 953 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L954" class="LineNr"> 954 </span> <span class="Constant">"run: compare r/m32 with <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L955" class="LineNr"> 955 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L956" class="LineNr"> 956 </span> <span class="Constant">"run: SF=0; ZF=1; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L957" class="LineNr"> 957 </span> <span class="Delimiter">);</span> +<span id="L958" class="LineNr"> 958 </span><span class="Delimiter">}</span> +<span id="L959" class="LineNr"> 959 </span> +<span id="L960" class="LineNr"> 960 </span><span class="Comment">//:: copy (mov)</span> +<span id="L961" class="LineNr"> 961 </span> +<span id="L962" class="LineNr"> 962 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L963" class="LineNr"> 963 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"89"</span><span class="Delimiter">,</span> <span class="Constant">"copy r32 to rm32 (mov)"</span><span class="Delimiter">);</span> +<span id="L964" class="LineNr"> 964 </span> +<span id="L965" class="LineNr"> 965 </span><span class="Delimiter">:(code)</span> +<span id="L966" class="LineNr"> 966 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L966'>test_copy_r32_to_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L967" class="LineNr"> 967 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xaf</span><span class="Delimiter">;</span> +<span id="L968" class="LineNr"> 968 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L969" class="LineNr"> 969 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L970" class="LineNr"> 970 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L971" class="LineNr"> 971 </span> <span class="Constant">" 89 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy EBX to EAX</span> +<span id="L972" class="LineNr"> 972 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L973" class="LineNr"> 973 </span> <span class="Delimiter">);</span> +<span id="L974" class="LineNr"> 974 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L975" class="LineNr"> 975 </span> <span class="Constant">"run: copy <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L976" class="LineNr"> 976 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L977" class="LineNr"> 977 </span> <span class="Constant">"run: storing 0x000000af</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L978" class="LineNr"> 978 </span> <span class="Delimiter">);</span> +<span id="L979" class="LineNr"> 979 </span><span class="Delimiter">}</span> +<span id="L980" class="LineNr"> 980 </span> +<span id="L981" class="LineNr"> 981 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L982" class="LineNr"> 982 </span><span class="Normal">case</span> <span class="Constant">0x89</span>: <span class="Delimiter">{</span> <span class="Comment">// copy r32 to r/m32</span> +<span id="L983" class="LineNr"> 983 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L984" class="LineNr"> 984 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rsrc = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L985" class="LineNr"> 985 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>rsrc<span class="Delimiter">)</span> << <span class="Constant">" to r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L986" class="LineNr"> 986 </span> <span class="Normal">int32_t</span>* dest = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L987" class="LineNr"> 987 </span> *dest = Reg[rsrc]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> <span class="Comment">// Write multiple elements of vector<uint8_t> at once. Assumes sizeof(int) == 4 on the host as well.</span> +<span id="L988" class="LineNr"> 988 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *dest << end<span class="Delimiter">();</span> +<span id="L989" class="LineNr"> 989 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L990" class="LineNr"> 990 </span><span class="Delimiter">}</span> +<span id="L991" class="LineNr"> 991 </span> +<span id="L992" class="LineNr"> 992 </span><span class="Comment">//:: xchg</span> +<span id="L993" class="LineNr"> 993 </span> +<span id="L994" class="LineNr"> 994 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L995" class="LineNr"> 995 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"87"</span><span class="Delimiter">,</span> <span class="Constant">"swap the <a href='003trace.cc.html#L117'>contents</a> of r32 and rm32 (xchg)"</span><span class="Delimiter">);</span> +<span id="L996" class="LineNr"> 996 </span> +<span id="L997" class="LineNr"> 997 </span><span class="Delimiter">:(code)</span> +<span id="L998" class="LineNr"> 998 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L998'>test_xchg_r32_with_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L999" class="LineNr"> 999 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xaf</span><span class="Delimiter">;</span> +<span id="L1000" class="LineNr">1000 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2e</span><span class="Delimiter">;</span> +<span id="L1001" class="LineNr">1001 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1002" class="LineNr">1002 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L1003" class="LineNr">1003 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1004" class="LineNr">1004 </span> <span class="Constant">" 87 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// exchange EBX with EAX</span> +<span id="L1005" class="LineNr">1005 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L1006" class="LineNr">1006 </span> <span class="Delimiter">);</span> +<span id="L1007" class="LineNr">1007 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1008" class="LineNr">1008 </span> <span class="Constant">"run: exchange <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1009" class="LineNr">1009 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1010" class="LineNr">1010 </span> <span class="Constant">"run: storing 0x000000af in r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1011" class="LineNr">1011 </span> <span class="Constant">"run: storing 0x0000002e in <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1012" class="LineNr">1012 </span> <span class="Delimiter">);</span> +<span id="L1013" class="LineNr">1013 </span><span class="Delimiter">}</span> +<span id="L1014" class="LineNr">1014 </span> +<span id="L1015" class="LineNr">1015 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L1016" class="LineNr">1016 </span><span class="Normal">case</span> <span class="Constant">0x87</span>: <span class="Delimiter">{</span> <span class="Comment">// exchange r32 with r/m32</span> +<span id="L1017" class="LineNr">1017 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L1018" class="LineNr">1018 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> reg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L1019" class="LineNr">1019 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"exchange "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>reg2<span class="Delimiter">)</span> << <span class="Constant">" with r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L1020" class="LineNr">1020 </span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L1021" class="LineNr">1021 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> tmp = *arg1<span class="Delimiter">;</span> +<span id="L1022" class="LineNr">1022 </span> *arg1 = Reg[reg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L1023" class="LineNr">1023 </span> Reg[reg2]<span class="Delimiter">.</span>i = tmp<span class="Delimiter">;</span> +<span id="L1024" class="LineNr">1024 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *arg1 << <span class="Constant">" in r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L1025" class="LineNr">1025 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[reg2]<span class="Delimiter">.</span>i << <span class="Constant">" in "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>reg2<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L1026" class="LineNr">1026 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1027" class="LineNr">1027 </span><span class="Delimiter">}</span> +<span id="L1028" class="LineNr">1028 </span> +<span id="L1029" class="LineNr">1029 </span><span class="Comment">//:: increment</span> +<span id="L1030" class="LineNr">1030 </span> +<span id="L1031" class="LineNr">1031 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L1032" class="LineNr">1032 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"40"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010vm.cc.html#L10'>EAX</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L1033" class="LineNr">1033 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"41"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010vm.cc.html#L11'>ECX</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L1034" class="LineNr">1034 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"42"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010vm.cc.html#L12'>EDX</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L1035" class="LineNr">1035 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"43"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010vm.cc.html#L13'>EBX</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L1036" class="LineNr">1036 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"44"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010vm.cc.html#L14'>ESP</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L1037" class="LineNr">1037 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"45"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010vm.cc.html#L15'>EBP</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L1038" class="LineNr">1038 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"46"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010vm.cc.html#L16'>ESI</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L1039" class="LineNr">1039 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"47"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010vm.cc.html#L17'>EDI</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L1040" class="LineNr">1040 </span> +<span id="L1041" class="LineNr">1041 </span><span class="Delimiter">:(code)</span> +<span id="L1042" class="LineNr">1042 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L1042'>test_increment_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1043" class="LineNr">1043 </span> Reg[ECX]<span class="Delimiter">.</span>u = <span class="Constant">0x1f</span><span class="Delimiter">;</span> +<span id="L1044" class="LineNr">1044 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1045" class="LineNr">1045 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L1046" class="LineNr">1046 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1047" class="LineNr">1047 </span> <span class="Constant">" 41 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// increment ECX</span> +<span id="L1048" class="LineNr">1048 </span> <span class="Delimiter">);</span> +<span id="L1049" class="LineNr">1049 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1050" class="LineNr">1050 </span> <span class="Constant">"run: increment <a href='010vm.cc.html#L11'>ECX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1051" class="LineNr">1051 </span> <span class="Constant">"run: storing value 0x00000020</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1052" class="LineNr">1052 </span> <span class="Delimiter">);</span> +<span id="L1053" class="LineNr">1053 </span><span class="Delimiter">}</span> +<span id="L1054" class="LineNr">1054 </span> +<span id="L1055" class="LineNr">1055 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L1056" class="LineNr">1056 </span><span class="Normal">case</span> <span class="Constant">0x40</span>: +<span id="L1057" class="LineNr">1057 </span><span class="Normal">case</span> <span class="Constant">0x41</span>: +<span id="L1058" class="LineNr">1058 </span><span class="Normal">case</span> <span class="Constant">0x42</span>: +<span id="L1059" class="LineNr">1059 </span><span class="Normal">case</span> <span class="Constant">0x43</span>: +<span id="L1060" class="LineNr">1060 </span><span class="Normal">case</span> <span class="Constant">0x44</span>: +<span id="L1061" class="LineNr">1061 </span><span class="Normal">case</span> <span class="Constant">0x45</span>: +<span id="L1062" class="LineNr">1062 </span><span class="Normal">case</span> <span class="Constant">0x46</span>: +<span id="L1063" class="LineNr">1063 </span><span class="Normal">case</span> <span class="Constant">0x47</span>: <span class="Delimiter">{</span> <span class="Comment">// increment r32</span> +<span id="L1064" class="LineNr">1064 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> <a href='010vm.cc.html#L20'>reg</a> = op & <span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L1065" class="LineNr">1065 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"increment "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span><a href='010vm.cc.html#L20'>reg</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L1066" class="LineNr">1066 </span> ++Reg[reg]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L1067" class="LineNr">1067 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing value 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[reg]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L1068" class="LineNr">1068 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1069" class="LineNr">1069 </span><span class="Delimiter">}</span> +<span id="L1070" class="LineNr">1070 </span> +<span id="L1071" class="LineNr">1071 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L1072" class="LineNr">1072 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"ff"</span><span class="Delimiter">,</span> <span class="Constant">"increment/decrement/jump/push/call rm32 based on subop (inc/dec/jmp/push/call)"</span><span class="Delimiter">);</span> +<span id="L1073" class="LineNr">1073 </span> +<span id="L1074" class="LineNr">1074 </span><span class="Delimiter">:(code)</span> +<span id="L1075" class="LineNr">1075 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L1075'>test_increment_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1076" class="LineNr">1076 </span> Reg[EAX]<span class="Delimiter">.</span>u = <span class="Constant">0x20</span><span class="Delimiter">;</span> +<span id="L1077" class="LineNr">1077 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1078" class="LineNr">1078 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L1079" class="LineNr">1079 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1080" class="LineNr">1080 </span> <span class="Constant">" ff c0 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// increment EAX</span> +<span id="L1081" class="LineNr">1081 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (subop inc) 000 (EAX)</span> +<span id="L1082" class="LineNr">1082 </span> <span class="Delimiter">);</span> +<span id="L1083" class="LineNr">1083 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1084" class="LineNr">1084 </span> <span class="Constant">"run: increment r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1085" class="LineNr">1085 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1086" class="LineNr">1086 </span> <span class="Constant">"run: storing value 0x00000021</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1087" class="LineNr">1087 </span> <span class="Delimiter">);</span> +<span id="L1088" class="LineNr">1088 </span><span class="Delimiter">}</span> +<span id="L1089" class="LineNr">1089 </span> +<span id="L1090" class="LineNr">1090 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L1091" class="LineNr">1091 </span><span class="Normal">case</span> <span class="Constant">0xff</span>: <span class="Delimiter">{</span> +<span id="L1092" class="LineNr">1092 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L1093" class="LineNr">1093 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> subop = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span class="Comment">// middle 3 'reg opcode' bits</span> +<span id="L1094" class="LineNr">1094 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>subop<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L1095" class="LineNr">1095 </span> <span class="Normal">case</span> <span class="Constant">0</span>: <span class="Delimiter">{</span> <span class="Comment">// increment r/m32</span> +<span id="L1096" class="LineNr">1096 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"increment r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L1097" class="LineNr">1097 </span> <span class="Normal">int32_t</span>* <a href='001help.cc.html#L15'>arg</a> = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L1098" class="LineNr">1098 </span> ++*arg<span class="Delimiter">;</span> +<span id="L1099" class="LineNr">1099 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing value 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *arg << end<span class="Delimiter">();</span> +<span id="L1100" class="LineNr">1100 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1101" class="LineNr">1101 </span> <span class="Delimiter">}</span> +<span id="L1102" class="LineNr">1102 </span> <span class="Normal">default</span>: +<span id="L1103" class="LineNr">1103 </span> cerr << <span class="Constant">"unrecognized subop for ff: "</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L1104" class="LineNr">1104 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L1105" class="LineNr">1105 </span> <span class="Comment">// End Op ff Subops</span> +<span id="L1106" class="LineNr">1106 </span> <span class="Delimiter">}</span> +<span id="L1107" class="LineNr">1107 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1108" class="LineNr">1108 </span><span class="Delimiter">}</span> +<span id="L1109" class="LineNr">1109 </span> +<span id="L1110" class="LineNr">1110 </span><span class="Comment">//:: decrement</span> +<span id="L1111" class="LineNr">1111 </span> +<span id="L1112" class="LineNr">1112 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L1113" class="LineNr">1113 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"48"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010vm.cc.html#L10'>EAX</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L1114" class="LineNr">1114 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"49"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010vm.cc.html#L11'>ECX</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L1115" class="LineNr">1115 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"4a"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010vm.cc.html#L12'>EDX</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L1116" class="LineNr">1116 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"4b"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010vm.cc.html#L13'>EBX</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L1117" class="LineNr">1117 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"4c"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010vm.cc.html#L14'>ESP</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L1118" class="LineNr">1118 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"4d"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010vm.cc.html#L15'>EBP</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L1119" class="LineNr">1119 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"4e"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010vm.cc.html#L16'>ESI</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L1120" class="LineNr">1120 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"4f"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010vm.cc.html#L17'>EDI</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L1121" class="LineNr">1121 </span> +<span id="L1122" class="LineNr">1122 </span><span class="Delimiter">:(code)</span> +<span id="L1123" class="LineNr">1123 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L1123'>test_decrement_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1124" class="LineNr">1124 </span> Reg[ECX]<span class="Delimiter">.</span>u = <span class="Constant">0x1f</span><span class="Delimiter">;</span> +<span id="L1125" class="LineNr">1125 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1126" class="LineNr">1126 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L1127" class="LineNr">1127 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1128" class="LineNr">1128 </span> <span class="Constant">" 49 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// decrement ECX</span> +<span id="L1129" class="LineNr">1129 </span> <span class="Delimiter">);</span> +<span id="L1130" class="LineNr">1130 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1131" class="LineNr">1131 </span> <span class="Constant">"run: decrement <a href='010vm.cc.html#L11'>ECX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1132" class="LineNr">1132 </span> <span class="Constant">"run: storing value 0x0000001e</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1133" class="LineNr">1133 </span> <span class="Delimiter">);</span> +<span id="L1134" class="LineNr">1134 </span><span class="Delimiter">}</span> +<span id="L1135" class="LineNr">1135 </span> +<span id="L1136" class="LineNr">1136 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L1137" class="LineNr">1137 </span><span class="Normal">case</span> <span class="Constant">0x48</span>: +<span id="L1138" class="LineNr">1138 </span><span class="Normal">case</span> <span class="Constant">0x49</span>: +<span id="L1139" class="LineNr">1139 </span><span class="Normal">case</span> <span class="Constant">0x4a</span>: +<span id="L1140" class="LineNr">1140 </span><span class="Normal">case</span> <span class="Constant">0x4b</span>: +<span id="L1141" class="LineNr">1141 </span><span class="Normal">case</span> <span class="Constant">0x4c</span>: +<span id="L1142" class="LineNr">1142 </span><span class="Normal">case</span> <span class="Constant">0x4d</span>: +<span id="L1143" class="LineNr">1143 </span><span class="Normal">case</span> <span class="Constant">0x4e</span>: +<span id="L1144" class="LineNr">1144 </span><span class="Normal">case</span> <span class="Constant">0x4f</span>: <span class="Delimiter">{</span> <span class="Comment">// decrement r32</span> +<span id="L1145" class="LineNr">1145 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> <a href='010vm.cc.html#L20'>reg</a> = op & <span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L1146" class="LineNr">1146 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"decrement "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span><a href='010vm.cc.html#L20'>reg</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L1147" class="LineNr">1147 </span> --Reg[reg]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L1148" class="LineNr">1148 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing value 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[reg]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L1149" class="LineNr">1149 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1150" class="LineNr">1150 </span><span class="Delimiter">}</span> +<span id="L1151" class="LineNr">1151 </span> +<span id="L1152" class="LineNr">1152 </span><span class="Delimiter">:(code)</span> +<span id="L1153" class="LineNr">1153 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L1153'>test_decrement_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1154" class="LineNr">1154 </span> Reg[EAX]<span class="Delimiter">.</span>u = <span class="Constant">0x20</span><span class="Delimiter">;</span> +<span id="L1155" class="LineNr">1155 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1156" class="LineNr">1156 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L1157" class="LineNr">1157 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1158" class="LineNr">1158 </span> <span class="Constant">" ff c8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// decrement EAX</span> +<span id="L1159" class="LineNr">1159 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 001 (subop inc) 000 (EAX)</span> +<span id="L1160" class="LineNr">1160 </span> <span class="Delimiter">);</span> +<span id="L1161" class="LineNr">1161 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1162" class="LineNr">1162 </span> <span class="Constant">"run: decrement r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1163" class="LineNr">1163 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1164" class="LineNr">1164 </span> <span class="Constant">"run: storing value 0x0000001f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1165" class="LineNr">1165 </span> <span class="Delimiter">);</span> +<span id="L1166" class="LineNr">1166 </span><span class="Delimiter">}</span> +<span id="L1167" class="LineNr">1167 </span> +<span id="L1168" class="LineNr">1168 </span><span class="Delimiter">:(before "End Op ff Subops")</span> +<span id="L1169" class="LineNr">1169 </span><span class="Normal">case</span> <span class="Constant">1</span>: <span class="Delimiter">{</span> <span class="Comment">// decrement r/m32</span> +<span id="L1170" class="LineNr">1170 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"decrement r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L1171" class="LineNr">1171 </span> <span class="Normal">int32_t</span>* <a href='001help.cc.html#L15'>arg</a> = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L1172" class="LineNr">1172 </span> --*arg<span class="Delimiter">;</span> +<span id="L1173" class="LineNr">1173 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing value 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *arg << end<span class="Delimiter">();</span> +<span id="L1174" class="LineNr">1174 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1175" class="LineNr">1175 </span><span class="Delimiter">}</span> +<span id="L1176" class="LineNr">1176 </span> +<span id="L1177" class="LineNr">1177 </span><span class="Comment">//:: push</span> +<span id="L1178" class="LineNr">1178 </span> +<span id="L1179" class="LineNr">1179 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L1180" class="LineNr">1180 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"50"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010vm.cc.html#L10'>EAX</a> to stack (<a href='012elf.cc.html#L94'>push</a>)"</span><span class="Delimiter">);</span> +<span id="L1181" class="LineNr">1181 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"51"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010vm.cc.html#L11'>ECX</a> to stack (<a href='012elf.cc.html#L94'>push</a>)"</span><span class="Delimiter">);</span> +<span id="L1182" class="LineNr">1182 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"52"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010vm.cc.html#L12'>EDX</a> to stack (<a href='012elf.cc.html#L94'>push</a>)"</span><span class="Delimiter">);</span> +<span id="L1183" class="LineNr">1183 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"53"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010vm.cc.html#L13'>EBX</a> to stack (<a href='012elf.cc.html#L94'>push</a>)"</span><span class="Delimiter">);</span> +<span id="L1184" class="LineNr">1184 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"54"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010vm.cc.html#L14'>ESP</a> to stack (<a href='012elf.cc.html#L94'>push</a>)"</span><span class="Delimiter">);</span> +<span id="L1185" class="LineNr">1185 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"55"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010vm.cc.html#L15'>EBP</a> to stack (<a href='012elf.cc.html#L94'>push</a>)"</span><span class="Delimiter">);</span> +<span id="L1186" class="LineNr">1186 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"56"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010vm.cc.html#L16'>ESI</a> to stack (<a href='012elf.cc.html#L94'>push</a>)"</span><span class="Delimiter">);</span> +<span id="L1187" class="LineNr">1187 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"57"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010vm.cc.html#L17'>EDI</a> to stack (<a href='012elf.cc.html#L94'>push</a>)"</span><span class="Delimiter">);</span> +<span id="L1188" class="LineNr">1188 </span> +<span id="L1189" class="LineNr">1189 </span><span class="Delimiter">:(code)</span> +<span id="L1190" class="LineNr">1190 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L1190'>test_push_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1191" class="LineNr">1191 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><span class="Constant">0xbd000000</span><span class="Delimiter">));</span> <span class="Comment">// manually allocate memory</span> +<span id="L1192" class="LineNr">1192 </span> Reg[ESP]<span class="Delimiter">.</span>u = <span class="Constant">0xbd000008</span><span class="Delimiter">;</span> +<span id="L1193" class="LineNr">1193 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0000000a</span><span class="Delimiter">;</span> +<span id="L1194" class="LineNr">1194 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1195" class="LineNr">1195 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L1196" class="LineNr">1196 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1197" class="LineNr">1197 </span> <span class="Constant">" 53 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// push EBX to stack</span> +<span id="L1198" class="LineNr">1198 </span> <span class="Delimiter">);</span> +<span id="L1199" class="LineNr">1199 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1200" class="LineNr">1200 </span> <span class="Constant">"run: <a href='012elf.cc.html#L94'>push</a> <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1201" class="LineNr">1201 </span> <span class="Constant">"run: decrementing <a href='010vm.cc.html#L14'>ESP</a> to 0xbd000004</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1202" class="LineNr">1202 </span> <span class="Constant">"run: pushing value 0x0000000a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1203" class="LineNr">1203 </span> <span class="Delimiter">);</span> +<span id="L1204" class="LineNr">1204 </span><span class="Delimiter">}</span> +<span id="L1205" class="LineNr">1205 </span> +<span id="L1206" class="LineNr">1206 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L1207" class="LineNr">1207 </span><span class="Normal">case</span> <span class="Constant">0x50</span>: +<span id="L1208" class="LineNr">1208 </span><span class="Normal">case</span> <span class="Constant">0x51</span>: +<span id="L1209" class="LineNr">1209 </span><span class="Normal">case</span> <span class="Constant">0x52</span>: +<span id="L1210" class="LineNr">1210 </span><span class="Normal">case</span> <span class="Constant">0x53</span>: +<span id="L1211" class="LineNr">1211 </span><span class="Normal">case</span> <span class="Constant">0x54</span>: +<span id="L1212" class="LineNr">1212 </span><span class="Normal">case</span> <span class="Constant">0x55</span>: +<span id="L1213" class="LineNr">1213 </span><span class="Normal">case</span> <span class="Constant">0x56</span>: +<span id="L1214" class="LineNr">1214 </span><span class="Normal">case</span> <span class="Constant">0x57</span>: <span class="Delimiter">{</span> <span class="Comment">// push r32 to stack</span> +<span id="L1215" class="LineNr">1215 </span> <span class="Normal">uint8_t</span> <a href='010vm.cc.html#L20'>reg</a> = op & <span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L1216" class="LineNr">1216 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"push "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span><a href='010vm.cc.html#L20'>reg</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L1217" class="LineNr">1217 </span><span class="CommentedCode">//? cerr << "push: " << NUM(reg) << ": " << Reg[reg].u << " => " << Reg[ESP].u << '\n';</span> +<span id="L1218" class="LineNr">1218 </span> <a href='012elf.cc.html#L94'>push</a><span class="Delimiter">(</span>Reg[reg]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L1219" class="LineNr">1219 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1220" class="LineNr">1220 </span><span class="Delimiter">}</span> +<span id="L1221" class="LineNr">1221 </span> +<span id="L1222" class="LineNr">1222 </span><span class="Comment">//:: pop</span> +<span id="L1223" class="LineNr">1223 </span> +<span id="L1224" class="LineNr">1224 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L1225" class="LineNr">1225 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"58"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010vm.cc.html#L10'>EAX</a> (<a href='013direct_addressing.cc.html#L1270'>pop</a>)"</span><span class="Delimiter">);</span> +<span id="L1226" class="LineNr">1226 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"59"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010vm.cc.html#L11'>ECX</a> (<a href='013direct_addressing.cc.html#L1270'>pop</a>)"</span><span class="Delimiter">);</span> +<span id="L1227" class="LineNr">1227 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"5a"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010vm.cc.html#L12'>EDX</a> (<a href='013direct_addressing.cc.html#L1270'>pop</a>)"</span><span class="Delimiter">);</span> +<span id="L1228" class="LineNr">1228 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"5b"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010vm.cc.html#L13'>EBX</a> (<a href='013direct_addressing.cc.html#L1270'>pop</a>)"</span><span class="Delimiter">);</span> +<span id="L1229" class="LineNr">1229 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"5c"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010vm.cc.html#L14'>ESP</a> (<a href='013direct_addressing.cc.html#L1270'>pop</a>)"</span><span class="Delimiter">);</span> +<span id="L1230" class="LineNr">1230 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"5d"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010vm.cc.html#L15'>EBP</a> (<a href='013direct_addressing.cc.html#L1270'>pop</a>)"</span><span class="Delimiter">);</span> +<span id="L1231" class="LineNr">1231 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"5e"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010vm.cc.html#L16'>ESI</a> (<a href='013direct_addressing.cc.html#L1270'>pop</a>)"</span><span class="Delimiter">);</span> +<span id="L1232" class="LineNr">1232 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"5f"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010vm.cc.html#L17'>EDI</a> (<a href='013direct_addressing.cc.html#L1270'>pop</a>)"</span><span class="Delimiter">);</span> +<span id="L1233" class="LineNr">1233 </span> +<span id="L1234" class="LineNr">1234 </span><span class="Delimiter">:(code)</span> +<span id="L1235" class="LineNr">1235 </span><span class="Normal">void</span> <a href='013direct_addressing.cc.html#L1235'>test_pop_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1236" class="LineNr">1236 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><span class="Constant">0xbd000000</span><span class="Delimiter">));</span> <span class="Comment">// manually allocate memory</span> +<span id="L1237" class="LineNr">1237 </span> Reg[ESP]<span class="Delimiter">.</span>u = <span class="Constant">0xbd000008</span><span class="Delimiter">;</span> +<span id="L1238" class="LineNr">1238 </span> <a href='010vm.cc.html#L256'>write_mem_i32</a><span class="Delimiter">(</span><span class="Constant">0xbd000008</span><span class="Delimiter">,</span> <span class="Constant">0x0000000a</span><span class="Delimiter">);</span> <span class="Comment">// ..before this write</span> +<span id="L1239" class="LineNr">1239 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1240" class="LineNr">1240 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L1241" class="LineNr">1241 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1242" class="LineNr">1242 </span> <span class="Constant">" 5b </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// pop stack to EBX</span> +<span id="L1243" class="LineNr">1243 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// data segment</span> +<span id="L1244" class="LineNr">1244 </span> <span class="Constant">"0a 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0xa</span> +<span id="L1245" class="LineNr">1245 </span> <span class="Delimiter">);</span> +<span id="L1246" class="LineNr">1246 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1247" class="LineNr">1247 </span> <span class="Constant">"run: <a href='013direct_addressing.cc.html#L1270'>pop</a> into <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1248" class="LineNr">1248 </span> <span class="Constant">"run: popping value 0x0000000a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1249" class="LineNr">1249 </span> <span class="Constant">"run: incrementing <a href='010vm.cc.html#L14'>ESP</a> to 0xbd00000c</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1250" class="LineNr">1250 </span> <span class="Delimiter">);</span> +<span id="L1251" class="LineNr">1251 </span><span class="Delimiter">}</span> +<span id="L1252" class="LineNr">1252 </span> +<span id="L1253" class="LineNr">1253 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L1254" class="LineNr">1254 </span><span class="Normal">case</span> <span class="Constant">0x58</span>: +<span id="L1255" class="LineNr">1255 </span><span class="Normal">case</span> <span class="Constant">0x59</span>: +<span id="L1256" class="LineNr">1256 </span><span class="Normal">case</span> <span class="Constant">0x5a</span>: +<span id="L1257" class="LineNr">1257 </span><span class="Normal">case</span> <span class="Constant">0x5b</span>: +<span id="L1258" class="LineNr">1258 </span><span class="Normal">case</span> <span class="Constant">0x5c</span>: +<span id="L1259" class="LineNr">1259 </span><span class="Normal">case</span> <span class="Constant">0x5d</span>: +<span id="L1260" class="LineNr">1260 </span><span class="Normal">case</span> <span class="Constant">0x5e</span>: +<span id="L1261" class="LineNr">1261 </span><span class="Normal">case</span> <span class="Constant">0x5f</span>: <span class="Delimiter">{</span> <span class="Comment">// pop stack into r32</span> +<span id="L1262" class="LineNr">1262 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> <a href='010vm.cc.html#L20'>reg</a> = op & <span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L1263" class="LineNr">1263 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"pop into "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span><a href='010vm.cc.html#L20'>reg</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L1264" class="LineNr">1264 </span><span class="CommentedCode">//? cerr << "pop from " << Reg[ESP].u << '\n';</span> +<span id="L1265" class="LineNr">1265 </span> Reg[reg]<span class="Delimiter">.</span>u = <a href='013direct_addressing.cc.html#L1270'>pop</a><span class="Delimiter">();</span> +<span id="L1266" class="LineNr">1266 </span><span class="CommentedCode">//? cerr << "=> " << NUM(reg) << ": " << Reg[reg].u << '\n';</span> +<span id="L1267" class="LineNr">1267 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1268" class="LineNr">1268 </span><span class="Delimiter">}</span> +<span id="L1269" class="LineNr">1269 </span><span class="Delimiter">:(code)</span> +<span id="L1270" class="LineNr">1270 </span><span class="Normal">uint32_t</span> <a href='013direct_addressing.cc.html#L1270'>pop</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1271" class="LineNr">1271 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> result = <a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L1272" class="LineNr">1272 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"popping value 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << result << end<span class="Delimiter">();</span> +<span id="L1273" class="LineNr">1273 </span> Reg[ESP]<span class="Delimiter">.</span>u += <span class="Constant">4</span><span class="Delimiter">;</span> +<span id="L1274" class="LineNr">1274 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"incrementing <a href='010vm.cc.html#L14'>ESP</a> to 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[ESP]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L1275" class="LineNr">1275 </span> assert<span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u < <a href='012elf.cc.html#L153'>AFTER_STACK</a><span class="Delimiter">);</span> +<span id="L1276" class="LineNr">1276 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L1277" class="LineNr">1277 </span><span class="Delimiter">}</span> +<span id="L1278" class="LineNr">1278 </span> +<span id="L1279" class="LineNr">1279 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L1280" class="LineNr">1280 </span><span class="PreProc">#include </span><span class="Constant"><climits></span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/014indirect_addressing.cc.html b/html/linux/bootstrap/014indirect_addressing.cc.html new file mode 100644 index 00000000..27f28f32 --- /dev/null +++ b/html/linux/bootstrap/014indirect_addressing.cc.html @@ -0,0 +1,1067 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/014indirect_addressing.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.Delimiter { color: #c000c0; } +.Comment { color: #005faf; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/014indirect_addressing.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/014indirect_addressing.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: operating on memory at the address provided by some register</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: we'll now start providing data in a separate segment</span> +<span id="L3" class="LineNr"> 3 </span> +<span id="L4" class="LineNr"> 4 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L4'>test_add_r32_to_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L5" class="LineNr"> 5 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> +<span id="L6" class="LineNr"> 6 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L7" class="LineNr"> 7 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L10" class="LineNr"> 10 </span> <span class="Constant">" 01 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to *EAX</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Delimiter">);</span> +<span id="L15" class="LineNr"> 15 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Delimiter">);</span> +<span id="L20" class="LineNr"> 20 </span><span class="Delimiter">}</span> +<span id="L21" class="LineNr"> 21 </span> +<span id="L22" class="LineNr"> 22 </span><span class="Delimiter">:(before "End Mod Special-cases(addr)")</span> +<span id="L23" class="LineNr"> 23 </span><span class="Normal">case</span> <span class="Constant">0</span>: <span class="Comment">// indirect addressing</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>rm<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Normal">default</span>: <span class="Comment">// address in register</span> +<span id="L26" class="LineNr"> 26 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[rm]<span class="Delimiter">.</span>u << <span class="Constant">" ("</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>rm<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> +<span id="L27" class="LineNr"> 27 </span> addr = Reg[rm]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L28" class="LineNr"> 28 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Comment">// End Mod 0 Special-cases(addr)</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Delimiter">}</span> +<span id="L31" class="LineNr"> 31 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L32" class="LineNr"> 32 </span> +<span id="L33" class="LineNr"> 33 </span><span class="Comment">//:</span> +<span id="L34" class="LineNr"> 34 </span> +<span id="L35" class="LineNr"> 35 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L36" class="LineNr"> 36 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"03"</span><span class="Delimiter">,</span> <span class="Constant">"add rm32 to r32 (add)"</span><span class="Delimiter">);</span> +<span id="L37" class="LineNr"> 37 </span> +<span id="L38" class="LineNr"> 38 </span><span class="Delimiter">:(code)</span> +<span id="L39" class="LineNr"> 39 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L39'>test_add_mem_at_rm32_to_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L40" class="LineNr"> 40 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L41" class="LineNr"> 41 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> +<span id="L42" class="LineNr"> 42 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Constant">" 03 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add *EAX to EBX</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Delimiter">);</span> +<span id="L50" class="LineNr"> 50 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Constant">"run: add r/m32 to <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Delimiter">);</span> +<span id="L55" class="LineNr"> 55 </span><span class="Delimiter">}</span> +<span id="L56" class="LineNr"> 56 </span> +<span id="L57" class="LineNr"> 57 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L58" class="LineNr"> 58 </span><span class="Normal">case</span> <span class="Constant">0x03</span>: <span class="Delimiter">{</span> <span class="Comment">// add r/m32 to r32</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L61" class="LineNr"> 61 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"add r/m32 to "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* signed_arg2 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Normal">int32_t</span> signed_result = Reg[arg1]<span class="Delimiter">.</span>i + *signed_arg2<span class="Delimiter">;</span> +<span id="L64" class="LineNr"> 64 </span> SF = <span class="Delimiter">(</span>signed_result < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L65" class="LineNr"> 65 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>signed_result == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Normal">int64_t</span> signed_full_result = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>Reg[arg1]<span class="Delimiter">.</span>i<span class="Delimiter">)</span> + *signed_arg2<span class="Delimiter">;</span> +<span id="L67" class="LineNr"> 67 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>signed_result != signed_full_result<span class="Delimiter">);</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Comment">// set CF</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Normal">uint32_t</span> unsigned_arg2 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*signed_arg2<span class="Delimiter">);</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Normal">uint32_t</span> unsigned_result = Reg[arg1]<span class="Delimiter">.</span>u + unsigned_arg2<span class="Delimiter">;</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Normal">uint64_t</span> unsigned_full_result = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>Reg[arg1]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> + unsigned_arg2<span class="Delimiter">;</span> +<span id="L72" class="LineNr"> 72 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>unsigned_result != unsigned_full_result<span class="Delimiter">);</span> +<span id="L73" class="LineNr"> 73 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L74" class="LineNr"> 74 </span> Reg[arg1]<span class="Delimiter">.</span>i = signed_result<span class="Delimiter">;</span> +<span id="L75" class="LineNr"> 75 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[arg1]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L76" class="LineNr"> 76 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L77" class="LineNr"> 77 </span><span class="Delimiter">}</span> +<span id="L78" class="LineNr"> 78 </span> +<span id="L79" class="LineNr"> 79 </span><span class="Delimiter">:(code)</span> +<span id="L80" class="LineNr"> 80 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L80'>test_add_mem_at_rm32_to_r32_signed_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L81" class="LineNr"> 81 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L82" class="LineNr"> 82 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MAX</span><span class="Delimiter">;</span> +<span id="L83" class="LineNr"> 83 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Constant">" 03 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add *EAX to EBX</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Delimiter">);</span> +<span id="L91" class="LineNr"> 91 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Constant">"run: add r/m32 to <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Constant">"run: effective address contains 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Constant">"run: SF=1; ZF=0; CF=0; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Constant">"run: storing 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Delimiter">);</span> +<span id="L98" class="LineNr"> 98 </span><span class="Delimiter">}</span> +<span id="L99" class="LineNr"> 99 </span> +<span id="L100" class="LineNr"> 100 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L100'>test_add_mem_at_rm32_to_r32_unsigned_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L101" class="LineNr"> 101 </span> Reg[EAX]<span class="Delimiter">.</span>u = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L102" class="LineNr"> 102 </span> Reg[EBX]<span class="Delimiter">.</span>u = <span class="Constant">UINT32_MAX</span><span class="Delimiter">;</span> +<span id="L103" class="LineNr"> 103 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L104" class="LineNr"> 104 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L105" class="LineNr"> 105 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L106" class="LineNr"> 106 </span> <span class="Constant">" 03 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add *EAX to EBX</span> +<span id="L107" class="LineNr"> 107 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L108" class="LineNr"> 108 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L109" class="LineNr"> 109 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L110" class="LineNr"> 110 </span> <span class="Delimiter">);</span> +<span id="L111" class="LineNr"> 111 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L112" class="LineNr"> 112 </span> <span class="Constant">"run: add r/m32 to <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L113" class="LineNr"> 113 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L114" class="LineNr"> 114 </span> <span class="Constant">"run: effective address contains 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L115" class="LineNr"> 115 </span> <span class="Constant">"run: SF=0; ZF=1; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L116" class="LineNr"> 116 </span> <span class="Constant">"run: storing 0x00000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L117" class="LineNr"> 117 </span> <span class="Delimiter">);</span> +<span id="L118" class="LineNr"> 118 </span><span class="Delimiter">}</span> +<span id="L119" class="LineNr"> 119 </span> +<span id="L120" class="LineNr"> 120 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L120'>test_add_mem_at_rm32_to_r32_unsigned_and_signed_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L121" class="LineNr"> 121 </span> Reg[EAX]<span class="Delimiter">.</span>u = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L122" class="LineNr"> 122 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MIN</span><span class="Delimiter">;</span> +<span id="L123" class="LineNr"> 123 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L124" class="LineNr"> 124 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L125" class="LineNr"> 125 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L126" class="LineNr"> 126 </span> <span class="Constant">" 03 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add *EAX to EBX</span> +<span id="L127" class="LineNr"> 127 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L128" class="LineNr"> 128 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L129" class="LineNr"> 129 </span> <span class="Constant">"00 00 00 80</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// INT32_MIN</span> +<span id="L130" class="LineNr"> 130 </span> <span class="Delimiter">);</span> +<span id="L131" class="LineNr"> 131 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L132" class="LineNr"> 132 </span> <span class="Constant">"run: add r/m32 to <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L133" class="LineNr"> 133 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L134" class="LineNr"> 134 </span> <span class="Constant">"run: effective address contains 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L135" class="LineNr"> 135 </span> <span class="Constant">"run: SF=0; ZF=1; CF=1; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L136" class="LineNr"> 136 </span> <span class="Constant">"run: storing 0x00000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L137" class="LineNr"> 137 </span> <span class="Delimiter">);</span> +<span id="L138" class="LineNr"> 138 </span><span class="Delimiter">}</span> +<span id="L139" class="LineNr"> 139 </span> +<span id="L140" class="LineNr"> 140 </span><span class="Comment">//:: subtract</span> +<span id="L141" class="LineNr"> 141 </span> +<span id="L142" class="LineNr"> 142 </span><span class="Delimiter">:(code)</span> +<span id="L143" class="LineNr"> 143 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L143'>test_subtract_r32_from_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L144" class="LineNr"> 144 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L145" class="LineNr"> 145 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L146" class="LineNr"> 146 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L147" class="LineNr"> 147 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L148" class="LineNr"> 148 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L149" class="LineNr"> 149 </span> <span class="Constant">" 29 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract EBX from *EAX</span> +<span id="L150" class="LineNr"> 150 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L151" class="LineNr"> 151 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L152" class="LineNr"> 152 </span> <span class="Constant">"0a 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0xa</span> +<span id="L153" class="LineNr"> 153 </span> <span class="Delimiter">);</span> +<span id="L154" class="LineNr"> 154 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L155" class="LineNr"> 155 </span> <span class="Constant">"run: subtract <a href='010vm.cc.html#L13'>EBX</a> from r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L156" class="LineNr"> 156 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L157" class="LineNr"> 157 </span> <span class="Constant">"run: storing 0x00000009</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L158" class="LineNr"> 158 </span> <span class="Delimiter">);</span> +<span id="L159" class="LineNr"> 159 </span><span class="Delimiter">}</span> +<span id="L160" class="LineNr"> 160 </span> +<span id="L161" class="LineNr"> 161 </span><span class="Comment">//:</span> +<span id="L162" class="LineNr"> 162 </span> +<span id="L163" class="LineNr"> 163 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L164" class="LineNr"> 164 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"2b"</span><span class="Delimiter">,</span> <span class="Constant">"subtract rm32 from r32 (sub)"</span><span class="Delimiter">);</span> +<span id="L165" class="LineNr"> 165 </span> +<span id="L166" class="LineNr"> 166 </span><span class="Delimiter">:(code)</span> +<span id="L167" class="LineNr"> 167 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L167'>test_subtract_mem_at_rm32_from_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L168" class="LineNr"> 168 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L169" class="LineNr"> 169 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">10</span><span class="Delimiter">;</span> +<span id="L170" class="LineNr"> 170 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L171" class="LineNr"> 171 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L172" class="LineNr"> 172 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L173" class="LineNr"> 173 </span> <span class="Constant">" 2b 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract *EAX from EBX</span> +<span id="L174" class="LineNr"> 174 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L175" class="LineNr"> 175 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L176" class="LineNr"> 176 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L177" class="LineNr"> 177 </span> <span class="Delimiter">);</span> +<span id="L178" class="LineNr"> 178 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L179" class="LineNr"> 179 </span> <span class="Constant">"run: subtract r/m32 from <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L180" class="LineNr"> 180 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L181" class="LineNr"> 181 </span> <span class="Constant">"run: storing 0x00000009</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L182" class="LineNr"> 182 </span> <span class="Delimiter">);</span> +<span id="L183" class="LineNr"> 183 </span><span class="Delimiter">}</span> +<span id="L184" class="LineNr"> 184 </span> +<span id="L185" class="LineNr"> 185 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L186" class="LineNr"> 186 </span><span class="Normal">case</span> <span class="Constant">0x2b</span>: <span class="Delimiter">{</span> <span class="Comment">// subtract r/m32 from r32</span> +<span id="L187" class="LineNr"> 187 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L188" class="LineNr"> 188 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L189" class="LineNr"> 189 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subtract r/m32 from "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L190" class="LineNr"> 190 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* signed_arg2 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L191" class="LineNr"> 191 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> signed_result = Reg[arg1]<span class="Delimiter">.</span>i - *signed_arg2<span class="Delimiter">;</span> +<span id="L192" class="LineNr"> 192 </span> SF = <span class="Delimiter">(</span>signed_result < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L193" class="LineNr"> 193 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>signed_result == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L194" class="LineNr"> 194 </span> <span class="Normal">int64_t</span> signed_full_result = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>Reg[arg1]<span class="Delimiter">.</span>i<span class="Delimiter">)</span> - *signed_arg2<span class="Delimiter">;</span> +<span id="L195" class="LineNr"> 195 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>signed_result != signed_full_result<span class="Delimiter">);</span> +<span id="L196" class="LineNr"> 196 </span> <span class="Comment">// set CF</span> +<span id="L197" class="LineNr"> 197 </span> <span class="Normal">uint32_t</span> unsigned_arg2 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*signed_arg2<span class="Delimiter">);</span> +<span id="L198" class="LineNr"> 198 </span> <span class="Normal">uint32_t</span> unsigned_result = Reg[arg1]<span class="Delimiter">.</span>u - unsigned_arg2<span class="Delimiter">;</span> +<span id="L199" class="LineNr"> 199 </span> <span class="Normal">uint64_t</span> unsigned_full_result = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>Reg[arg1]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> - unsigned_arg2<span class="Delimiter">;</span> +<span id="L200" class="LineNr"> 200 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>unsigned_result != unsigned_full_result<span class="Delimiter">);</span> +<span id="L201" class="LineNr"> 201 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L202" class="LineNr"> 202 </span> Reg[arg1]<span class="Delimiter">.</span>i = signed_result<span class="Delimiter">;</span> +<span id="L203" class="LineNr"> 203 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[arg1]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L204" class="LineNr"> 204 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L205" class="LineNr"> 205 </span><span class="Delimiter">}</span> +<span id="L206" class="LineNr"> 206 </span> +<span id="L207" class="LineNr"> 207 </span><span class="Delimiter">:(code)</span> +<span id="L208" class="LineNr"> 208 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L208'>test_subtract_mem_at_rm32_from_r32_signed_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L209" class="LineNr"> 209 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L210" class="LineNr"> 210 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MIN</span><span class="Delimiter">;</span> +<span id="L211" class="LineNr"> 211 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L212" class="LineNr"> 212 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L213" class="LineNr"> 213 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L214" class="LineNr"> 214 </span> <span class="Constant">" 2b 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract *EAX from EBX</span> +<span id="L215" class="LineNr"> 215 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L216" class="LineNr"> 216 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L217" class="LineNr"> 217 </span> <span class="Constant">"ff ff ff 7f</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// INT32_MAX</span> +<span id="L218" class="LineNr"> 218 </span> <span class="Delimiter">);</span> +<span id="L219" class="LineNr"> 219 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L220" class="LineNr"> 220 </span> <span class="Constant">"run: subtract r/m32 from <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L221" class="LineNr"> 221 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L222" class="LineNr"> 222 </span> <span class="Constant">"run: effective address contains 0x7fffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L223" class="LineNr"> 223 </span> <span class="Constant">"run: SF=0; ZF=0; CF=0; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L224" class="LineNr"> 224 </span> <span class="Constant">"run: storing 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L225" class="LineNr"> 225 </span> <span class="Delimiter">);</span> +<span id="L226" class="LineNr"> 226 </span><span class="Delimiter">}</span> +<span id="L227" class="LineNr"> 227 </span> +<span id="L228" class="LineNr"> 228 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L228'>test_subtract_mem_at_rm32_from_r32_unsigned_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L229" class="LineNr"> 229 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L230" class="LineNr"> 230 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L231" class="LineNr"> 231 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L232" class="LineNr"> 232 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L233" class="LineNr"> 233 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L234" class="LineNr"> 234 </span> <span class="Constant">" 2b 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract *EAX from EBX</span> +<span id="L235" class="LineNr"> 235 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L236" class="LineNr"> 236 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L237" class="LineNr"> 237 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L238" class="LineNr"> 238 </span> <span class="Delimiter">);</span> +<span id="L239" class="LineNr"> 239 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L240" class="LineNr"> 240 </span> <span class="Constant">"run: subtract r/m32 from <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L241" class="LineNr"> 241 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L242" class="LineNr"> 242 </span> <span class="Constant">"run: effective address contains 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L243" class="LineNr"> 243 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L244" class="LineNr"> 244 </span> <span class="Constant">"run: storing 0xffffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L245" class="LineNr"> 245 </span> <span class="Delimiter">);</span> +<span id="L246" class="LineNr"> 246 </span><span class="Delimiter">}</span> +<span id="L247" class="LineNr"> 247 </span> +<span id="L248" class="LineNr"> 248 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L248'>test_subtract_mem_at_rm32_from_r32_signed_and_unsigned_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L249" class="LineNr"> 249 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L250" class="LineNr"> 250 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L251" class="LineNr"> 251 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L252" class="LineNr"> 252 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L253" class="LineNr"> 253 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L254" class="LineNr"> 254 </span> <span class="Constant">" 2b 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract *EAX from EBX</span> +<span id="L255" class="LineNr"> 255 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L256" class="LineNr"> 256 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L257" class="LineNr"> 257 </span> <span class="Constant">"00 00 00 80</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// INT32_MIN</span> +<span id="L258" class="LineNr"> 258 </span> <span class="Delimiter">);</span> +<span id="L259" class="LineNr"> 259 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L260" class="LineNr"> 260 </span> <span class="Constant">"run: subtract r/m32 from <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L261" class="LineNr"> 261 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L262" class="LineNr"> 262 </span> <span class="Constant">"run: effective address contains 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L263" class="LineNr"> 263 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L264" class="LineNr"> 264 </span> <span class="Constant">"run: storing 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L265" class="LineNr"> 265 </span> <span class="Delimiter">);</span> +<span id="L266" class="LineNr"> 266 </span><span class="Delimiter">}</span> +<span id="L267" class="LineNr"> 267 </span> +<span id="L268" class="LineNr"> 268 </span><span class="Comment">//:: and</span> +<span id="L269" class="LineNr"> 269 </span><span class="Delimiter">:(code)</span> +<span id="L270" class="LineNr"> 270 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L270'>test_and_r32_with_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L271" class="LineNr"> 271 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L272" class="LineNr"> 272 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xff</span><span class="Delimiter">;</span> +<span id="L273" class="LineNr"> 273 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L274" class="LineNr"> 274 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L275" class="LineNr"> 275 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L276" class="LineNr"> 276 </span> <span class="Constant">" 21 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// and EBX with *EAX</span> +<span id="L277" class="LineNr"> 277 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L278" class="LineNr"> 278 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L279" class="LineNr"> 279 </span> <span class="Constant">"0d 0c 0b 0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0a0b0c0d</span> +<span id="L280" class="LineNr"> 280 </span> <span class="Delimiter">);</span> +<span id="L281" class="LineNr"> 281 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L282" class="LineNr"> 282 </span> <span class="Constant">"run: and <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L283" class="LineNr"> 283 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L284" class="LineNr"> 284 </span> <span class="Constant">"run: storing 0x0000000d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L285" class="LineNr"> 285 </span> <span class="Delimiter">);</span> +<span id="L286" class="LineNr"> 286 </span><span class="Delimiter">}</span> +<span id="L287" class="LineNr"> 287 </span> +<span id="L288" class="LineNr"> 288 </span><span class="Comment">//:</span> +<span id="L289" class="LineNr"> 289 </span> +<span id="L290" class="LineNr"> 290 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L291" class="LineNr"> 291 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"23"</span><span class="Delimiter">,</span> <span class="Constant">"r32 = bitwise AND of r32 with rm32 (and)"</span><span class="Delimiter">);</span> +<span id="L292" class="LineNr"> 292 </span> +<span id="L293" class="LineNr"> 293 </span><span class="Delimiter">:(code)</span> +<span id="L294" class="LineNr"> 294 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L294'>test_and_mem_at_rm32_with_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L295" class="LineNr"> 295 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L296" class="LineNr"> 296 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c0d</span><span class="Delimiter">;</span> +<span id="L297" class="LineNr"> 297 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L298" class="LineNr"> 298 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L299" class="LineNr"> 299 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L300" class="LineNr"> 300 </span> <span class="Constant">" 23 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// and *EAX with EBX</span> +<span id="L301" class="LineNr"> 301 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L302" class="LineNr"> 302 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L303" class="LineNr"> 303 </span> <span class="Constant">"ff 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0xff</span> +<span id="L304" class="LineNr"> 304 </span> <span class="Delimiter">);</span> +<span id="L305" class="LineNr"> 305 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L306" class="LineNr"> 306 </span> <span class="Constant">"run: and r/m32 with <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L307" class="LineNr"> 307 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L308" class="LineNr"> 308 </span> <span class="Constant">"run: storing 0x0000000d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L309" class="LineNr"> 309 </span> <span class="Delimiter">);</span> +<span id="L310" class="LineNr"> 310 </span><span class="Delimiter">}</span> +<span id="L311" class="LineNr"> 311 </span> +<span id="L312" class="LineNr"> 312 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L313" class="LineNr"> 313 </span><span class="Normal">case</span> <span class="Constant">0x23</span>: <span class="Delimiter">{</span> <span class="Comment">// and r/m32 with r32</span> +<span id="L314" class="LineNr"> 314 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L315" class="LineNr"> 315 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L316" class="LineNr"> 316 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"and r/m32 with "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L317" class="LineNr"> 317 </span> <span class="Comment">// bitwise ops technically operate on unsigned numbers, but it makes no</span> +<span id="L318" class="LineNr"> 318 </span> <span class="Comment">// difference</span> +<span id="L319" class="LineNr"> 319 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* signed_arg2 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L320" class="LineNr"> 320 </span> Reg[arg1]<span class="Delimiter">.</span>i &= *signed_arg2<span class="Delimiter">;</span> +<span id="L321" class="LineNr"> 321 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[arg1]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L322" class="LineNr"> 322 </span> SF = <span class="Delimiter">(</span>Reg[arg1]<span class="Delimiter">.</span>i >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L323" class="LineNr"> 323 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>Reg[arg1]<span class="Delimiter">.</span>i == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L324" class="LineNr"> 324 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L325" class="LineNr"> 325 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L326" class="LineNr"> 326 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L327" class="LineNr"> 327 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L328" class="LineNr"> 328 </span><span class="Delimiter">}</span> +<span id="L329" class="LineNr"> 329 </span> +<span id="L330" class="LineNr"> 330 </span><span class="Comment">//:: or</span> +<span id="L331" class="LineNr"> 331 </span> +<span id="L332" class="LineNr"> 332 </span><span class="Delimiter">:(code)</span> +<span id="L333" class="LineNr"> 333 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L333'>test_or_r32_with_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L334" class="LineNr"> 334 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L335" class="LineNr"> 335 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xa0b0c0d0</span><span class="Delimiter">;</span> +<span id="L336" class="LineNr"> 336 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L337" class="LineNr"> 337 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L338" class="LineNr"> 338 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L339" class="LineNr"> 339 </span> <span class="Constant">" 09 18 #</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// EBX with *EAX</span> +<span id="L340" class="LineNr"> 340 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L341" class="LineNr"> 341 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L342" class="LineNr"> 342 </span> <span class="Constant">"0d 0c 0b 0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0a0b0c0d</span> +<span id="L343" class="LineNr"> 343 </span> <span class="Delimiter">);</span> +<span id="L344" class="LineNr"> 344 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L345" class="LineNr"> 345 </span> <span class="Constant">"run: or <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L346" class="LineNr"> 346 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L347" class="LineNr"> 347 </span> <span class="Constant">"run: storing 0xaabbccdd</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L348" class="LineNr"> 348 </span> <span class="Delimiter">);</span> +<span id="L349" class="LineNr"> 349 </span><span class="Delimiter">}</span> +<span id="L350" class="LineNr"> 350 </span> +<span id="L351" class="LineNr"> 351 </span><span class="Comment">//:</span> +<span id="L352" class="LineNr"> 352 </span> +<span id="L353" class="LineNr"> 353 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L354" class="LineNr"> 354 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"0b"</span><span class="Delimiter">,</span> <span class="Constant">"r32 = bitwise OR of r32 with rm32 (or)"</span><span class="Delimiter">);</span> +<span id="L355" class="LineNr"> 355 </span> +<span id="L356" class="LineNr"> 356 </span><span class="Delimiter">:(code)</span> +<span id="L357" class="LineNr"> 357 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L357'>test_or_mem_at_rm32_with_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L358" class="LineNr"> 358 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L359" class="LineNr"> 359 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xa0b0c0d0</span><span class="Delimiter">;</span> +<span id="L360" class="LineNr"> 360 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L361" class="LineNr"> 361 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L362" class="LineNr"> 362 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L363" class="LineNr"> 363 </span> <span class="Constant">" 0b 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// or *EAX with EBX</span> +<span id="L364" class="LineNr"> 364 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L365" class="LineNr"> 365 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L366" class="LineNr"> 366 </span> <span class="Constant">"0d 0c 0b 0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0a0b0c0d</span> +<span id="L367" class="LineNr"> 367 </span> <span class="Delimiter">);</span> +<span id="L368" class="LineNr"> 368 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L369" class="LineNr"> 369 </span> <span class="Constant">"run: or r/m32 with <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L370" class="LineNr"> 370 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L371" class="LineNr"> 371 </span> <span class="Constant">"run: storing 0xaabbccdd</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L372" class="LineNr"> 372 </span> <span class="Delimiter">);</span> +<span id="L373" class="LineNr"> 373 </span><span class="Delimiter">}</span> +<span id="L374" class="LineNr"> 374 </span> +<span id="L375" class="LineNr"> 375 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L376" class="LineNr"> 376 </span><span class="Normal">case</span> <span class="Constant">0x0b</span>: <span class="Delimiter">{</span> <span class="Comment">// or r/m32 with r32</span> +<span id="L377" class="LineNr"> 377 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L378" class="LineNr"> 378 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L379" class="LineNr"> 379 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"or r/m32 with "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L380" class="LineNr"> 380 </span> <span class="Comment">// bitwise ops technically operate on unsigned numbers, but it makes no</span> +<span id="L381" class="LineNr"> 381 </span> <span class="Comment">// difference</span> +<span id="L382" class="LineNr"> 382 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* signed_arg2 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L383" class="LineNr"> 383 </span> Reg[arg1]<span class="Delimiter">.</span>i |= *signed_arg2<span class="Delimiter">;</span> +<span id="L384" class="LineNr"> 384 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[arg1]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L385" class="LineNr"> 385 </span> SF = <span class="Delimiter">(</span>Reg[arg1]<span class="Delimiter">.</span>i >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L386" class="LineNr"> 386 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>Reg[arg1]<span class="Delimiter">.</span>i == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L387" class="LineNr"> 387 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L388" class="LineNr"> 388 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L389" class="LineNr"> 389 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L390" class="LineNr"> 390 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L391" class="LineNr"> 391 </span><span class="Delimiter">}</span> +<span id="L392" class="LineNr"> 392 </span> +<span id="L393" class="LineNr"> 393 </span><span class="Comment">//:: xor</span> +<span id="L394" class="LineNr"> 394 </span> +<span id="L395" class="LineNr"> 395 </span><span class="Delimiter">:(code)</span> +<span id="L396" class="LineNr"> 396 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L396'>test_xor_r32_with_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L397" class="LineNr"> 397 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L398" class="LineNr"> 398 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xa0b0c0d0</span><span class="Delimiter">;</span> +<span id="L399" class="LineNr"> 399 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L400" class="LineNr"> 400 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L401" class="LineNr"> 401 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L402" class="LineNr"> 402 </span> <span class="Constant">" 31 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// xor EBX with *EAX</span> +<span id="L403" class="LineNr"> 403 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L404" class="LineNr"> 404 </span> <span class="Constant">"0d 0c bb aa</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0xaabb0c0d</span> +<span id="L405" class="LineNr"> 405 </span> <span class="Delimiter">);</span> +<span id="L406" class="LineNr"> 406 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L407" class="LineNr"> 407 </span> <span class="Constant">"run: xor <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L408" class="LineNr"> 408 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L409" class="LineNr"> 409 </span> <span class="Constant">"run: storing 0x0a0bccdd</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L410" class="LineNr"> 410 </span> <span class="Delimiter">);</span> +<span id="L411" class="LineNr"> 411 </span><span class="Delimiter">}</span> +<span id="L412" class="LineNr"> 412 </span> +<span id="L413" class="LineNr"> 413 </span><span class="Comment">//:</span> +<span id="L414" class="LineNr"> 414 </span> +<span id="L415" class="LineNr"> 415 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L416" class="LineNr"> 416 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"33"</span><span class="Delimiter">,</span> <span class="Constant">"r32 = bitwise XOR of r32 with rm32 (xor)"</span><span class="Delimiter">);</span> +<span id="L417" class="LineNr"> 417 </span> +<span id="L418" class="LineNr"> 418 </span><span class="Delimiter">:(code)</span> +<span id="L419" class="LineNr"> 419 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L419'>test_xor_mem_at_rm32_with_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L420" class="LineNr"> 420 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L421" class="LineNr"> 421 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xa0b0c0d0</span><span class="Delimiter">;</span> +<span id="L422" class="LineNr"> 422 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L423" class="LineNr"> 423 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L424" class="LineNr"> 424 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L425" class="LineNr"> 425 </span> <span class="Constant">" 33 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// xor *EAX with EBX</span> +<span id="L426" class="LineNr"> 426 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L427" class="LineNr"> 427 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L428" class="LineNr"> 428 </span> <span class="Constant">"0d 0c 0b 0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0a0b0c0d</span> +<span id="L429" class="LineNr"> 429 </span> <span class="Delimiter">);</span> +<span id="L430" class="LineNr"> 430 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L431" class="LineNr"> 431 </span> <span class="Constant">"run: xor r/m32 with <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L432" class="LineNr"> 432 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L433" class="LineNr"> 433 </span> <span class="Constant">"run: storing 0xaabbccdd</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L434" class="LineNr"> 434 </span> <span class="Delimiter">);</span> +<span id="L435" class="LineNr"> 435 </span><span class="Delimiter">}</span> +<span id="L436" class="LineNr"> 436 </span> +<span id="L437" class="LineNr"> 437 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L438" class="LineNr"> 438 </span><span class="Normal">case</span> <span class="Constant">0x33</span>: <span class="Delimiter">{</span> <span class="Comment">// xor r/m32 with r32</span> +<span id="L439" class="LineNr"> 439 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L440" class="LineNr"> 440 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L441" class="LineNr"> 441 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"xor r/m32 with "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L442" class="LineNr"> 442 </span> <span class="Comment">// bitwise ops technically operate on unsigned numbers, but it makes no</span> +<span id="L443" class="LineNr"> 443 </span> <span class="Comment">// difference</span> +<span id="L444" class="LineNr"> 444 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* signed_arg2 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L445" class="LineNr"> 445 </span> Reg[arg1]<span class="Delimiter">.</span>i |= *signed_arg2<span class="Delimiter">;</span> +<span id="L446" class="LineNr"> 446 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[arg1]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L447" class="LineNr"> 447 </span> SF = <span class="Delimiter">(</span>Reg[arg1]<span class="Delimiter">.</span>i >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L448" class="LineNr"> 448 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>Reg[arg1]<span class="Delimiter">.</span>i == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L449" class="LineNr"> 449 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L450" class="LineNr"> 450 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L451" class="LineNr"> 451 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L452" class="LineNr"> 452 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L453" class="LineNr"> 453 </span><span class="Delimiter">}</span> +<span id="L454" class="LineNr"> 454 </span> +<span id="L455" class="LineNr"> 455 </span><span class="Comment">//:: not</span> +<span id="L456" class="LineNr"> 456 </span> +<span id="L457" class="LineNr"> 457 </span><span class="Delimiter">:(code)</span> +<span id="L458" class="LineNr"> 458 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L458'>test_not_of_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L459" class="LineNr"> 459 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L460" class="LineNr"> 460 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L461" class="LineNr"> 461 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L462" class="LineNr"> 462 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L463" class="LineNr"> 463 </span> <span class="Constant">" f7 13 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// not *EBX</span> +<span id="L464" class="LineNr"> 464 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 010 (subop not) 011 (dest EBX)</span> +<span id="L465" class="LineNr"> 465 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L466" class="LineNr"> 466 </span> <span class="Constant">"ff 00 0f 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0f0f00ff</span> +<span id="L467" class="LineNr"> 467 </span> <span class="Delimiter">);</span> +<span id="L468" class="LineNr"> 468 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L469" class="LineNr"> 469 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L470" class="LineNr"> 470 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L471" class="LineNr"> 471 </span> <span class="Constant">"run: subop: not</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L472" class="LineNr"> 472 </span> <span class="Constant">"run: storing 0xf0f0ff00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L473" class="LineNr"> 473 </span> <span class="Delimiter">);</span> +<span id="L474" class="LineNr"> 474 </span><span class="Delimiter">}</span> +<span id="L475" class="LineNr"> 475 </span> +<span id="L476" class="LineNr"> 476 </span><span class="Comment">//:: compare (cmp)</span> +<span id="L477" class="LineNr"> 477 </span> +<span id="L478" class="LineNr"> 478 </span><span class="Delimiter">:(code)</span> +<span id="L479" class="LineNr"> 479 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L479'>test_compare_mem_at_rm32_with_r32_greater</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L480" class="LineNr"> 480 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L481" class="LineNr"> 481 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c07</span><span class="Delimiter">;</span> +<span id="L482" class="LineNr"> 482 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L483" class="LineNr"> 483 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L484" class="LineNr"> 484 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L485" class="LineNr"> 485 </span> <span class="Constant">" 39 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare *EAX with EBX</span> +<span id="L486" class="LineNr"> 486 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L487" class="LineNr"> 487 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L488" class="LineNr"> 488 </span> <span class="Constant">"0d 0c 0b 0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0a0b0c0d</span> +<span id="L489" class="LineNr"> 489 </span> <span class="Delimiter">);</span> +<span id="L490" class="LineNr"> 490 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L491" class="LineNr"> 491 </span> <span class="Constant">"run: compare r/m32 with <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L492" class="LineNr"> 492 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L493" class="LineNr"> 493 </span> <span class="Constant">"run: SF=0; ZF=0; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L494" class="LineNr"> 494 </span> <span class="Delimiter">);</span> +<span id="L495" class="LineNr"> 495 </span><span class="Delimiter">}</span> +<span id="L496" class="LineNr"> 496 </span> +<span id="L497" class="LineNr"> 497 </span><span class="Delimiter">:(code)</span> +<span id="L498" class="LineNr"> 498 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L498'>test_compare_mem_at_rm32_with_r32_lesser</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L499" class="LineNr"> 499 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L500" class="LineNr"> 500 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c0d</span><span class="Delimiter">;</span> +<span id="L501" class="LineNr"> 501 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L502" class="LineNr"> 502 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L503" class="LineNr"> 503 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L504" class="LineNr"> 504 </span> <span class="Constant">" 39 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare *EAX with EBX</span> +<span id="L505" class="LineNr"> 505 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L506" class="LineNr"> 506 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L507" class="LineNr"> 507 </span> <span class="Constant">"07 0c 0b 0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0a0b0c0d</span> +<span id="L508" class="LineNr"> 508 </span> <span class="Delimiter">);</span> +<span id="L509" class="LineNr"> 509 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L510" class="LineNr"> 510 </span> <span class="Constant">"run: compare r/m32 with <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L511" class="LineNr"> 511 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L512" class="LineNr"> 512 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L513" class="LineNr"> 513 </span> <span class="Delimiter">);</span> +<span id="L514" class="LineNr"> 514 </span><span class="Delimiter">}</span> +<span id="L515" class="LineNr"> 515 </span> +<span id="L516" class="LineNr"> 516 </span><span class="Delimiter">:(code)</span> +<span id="L517" class="LineNr"> 517 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L517'>test_compare_mem_at_rm32_with_r32_equal</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L518" class="LineNr"> 518 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L519" class="LineNr"> 519 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c0d</span><span class="Delimiter">;</span> +<span id="L520" class="LineNr"> 520 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L521" class="LineNr"> 521 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L522" class="LineNr"> 522 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L523" class="LineNr"> 523 </span> <span class="Constant">" 39 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare *EAX and EBX</span> +<span id="L524" class="LineNr"> 524 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L525" class="LineNr"> 525 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L526" class="LineNr"> 526 </span> <span class="Constant">"0d 0c 0b 0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0a0b0c0d</span> +<span id="L527" class="LineNr"> 527 </span> <span class="Delimiter">);</span> +<span id="L528" class="LineNr"> 528 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L529" class="LineNr"> 529 </span> <span class="Constant">"run: compare r/m32 with <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L530" class="LineNr"> 530 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L531" class="LineNr"> 531 </span> <span class="Constant">"run: SF=0; ZF=1; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L532" class="LineNr"> 532 </span> <span class="Delimiter">);</span> +<span id="L533" class="LineNr"> 533 </span><span class="Delimiter">}</span> +<span id="L534" class="LineNr"> 534 </span> +<span id="L535" class="LineNr"> 535 </span><span class="Comment">//:</span> +<span id="L536" class="LineNr"> 536 </span> +<span id="L537" class="LineNr"> 537 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L538" class="LineNr"> 538 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"3b"</span><span class="Delimiter">,</span> <span class="Constant">"compare: set SF if r32 < rm32 (cmp)"</span><span class="Delimiter">);</span> +<span id="L539" class="LineNr"> 539 </span> +<span id="L540" class="LineNr"> 540 </span><span class="Delimiter">:(code)</span> +<span id="L541" class="LineNr"> 541 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L541'>test_compare_r32_with_mem_at_rm32_greater</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L542" class="LineNr"> 542 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L543" class="LineNr"> 543 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c0d</span><span class="Delimiter">;</span> +<span id="L544" class="LineNr"> 544 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L545" class="LineNr"> 545 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L546" class="LineNr"> 546 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L547" class="LineNr"> 547 </span> <span class="Constant">" 3b 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EBX with *EAX</span> +<span id="L548" class="LineNr"> 548 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (lhs EBX) 000 (rhs EAX)</span> +<span id="L549" class="LineNr"> 549 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L550" class="LineNr"> 550 </span> <span class="Constant">"07 0c 0b 0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0a0b0c07</span> +<span id="L551" class="LineNr"> 551 </span> <span class="Delimiter">);</span> +<span id="L552" class="LineNr"> 552 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L553" class="LineNr"> 553 </span> <span class="Constant">"run: compare <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L554" class="LineNr"> 554 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L555" class="LineNr"> 555 </span> <span class="Constant">"run: SF=0; ZF=0; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L556" class="LineNr"> 556 </span> <span class="Delimiter">);</span> +<span id="L557" class="LineNr"> 557 </span><span class="Delimiter">}</span> +<span id="L558" class="LineNr"> 558 </span> +<span id="L559" class="LineNr"> 559 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L560" class="LineNr"> 560 </span><span class="Normal">case</span> <span class="Constant">0x3b</span>: <span class="Delimiter">{</span> <span class="Comment">// set SF if r32 < r/m32</span> +<span id="L561" class="LineNr"> 561 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L562" class="LineNr"> 562 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> reg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L563" class="LineNr"> 563 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"compare "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>reg1<span class="Delimiter">)</span> << <span class="Constant">" with r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L564" class="LineNr"> 564 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* signed_arg2 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L565" class="LineNr"> 565 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> signed_difference = Reg[reg1]<span class="Delimiter">.</span>i - *signed_arg2<span class="Delimiter">;</span> +<span id="L566" class="LineNr"> 566 </span> SF = <span class="Delimiter">(</span>signed_difference < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L567" class="LineNr"> 567 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>signed_difference == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L568" class="LineNr"> 568 </span> <span class="Normal">int64_t</span> full_signed_difference = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>Reg[reg1]<span class="Delimiter">.</span>i<span class="Delimiter">)</span> - *signed_arg2<span class="Delimiter">;</span> +<span id="L569" class="LineNr"> 569 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>signed_difference != full_signed_difference<span class="Delimiter">);</span> +<span id="L570" class="LineNr"> 570 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> unsigned_arg2 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*signed_arg2<span class="Delimiter">);</span> +<span id="L571" class="LineNr"> 571 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> unsigned_difference = Reg[reg1]<span class="Delimiter">.</span>u - unsigned_arg2<span class="Delimiter">;</span> +<span id="L572" class="LineNr"> 572 </span> <span class="Normal">const</span> <span class="Normal">uint64_t</span> full_unsigned_difference = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>Reg[reg1]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> - unsigned_arg2<span class="Delimiter">;</span> +<span id="L573" class="LineNr"> 573 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>unsigned_difference != full_unsigned_difference<span class="Delimiter">);</span> +<span id="L574" class="LineNr"> 574 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L575" class="LineNr"> 575 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L576" class="LineNr"> 576 </span><span class="Delimiter">}</span> +<span id="L577" class="LineNr"> 577 </span> +<span id="L578" class="LineNr"> 578 </span><span class="Delimiter">:(code)</span> +<span id="L579" class="LineNr"> 579 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L579'>test_compare_r32_with_mem_at_rm32_lesser_unsigned_and_signed</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L580" class="LineNr"> 580 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L581" class="LineNr"> 581 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c07</span><span class="Delimiter">;</span> +<span id="L582" class="LineNr"> 582 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L583" class="LineNr"> 583 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L584" class="LineNr"> 584 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L585" class="LineNr"> 585 </span> <span class="Constant">" 3b 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EBX with *EAX</span> +<span id="L586" class="LineNr"> 586 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (lhs EBX) 000 (rhs EAX)</span> +<span id="L587" class="LineNr"> 587 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L588" class="LineNr"> 588 </span> <span class="Constant">"0d 0c 0b 0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0a0b0c0d</span> +<span id="L589" class="LineNr"> 589 </span> <span class="Delimiter">);</span> +<span id="L590" class="LineNr"> 590 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L591" class="LineNr"> 591 </span> <span class="Constant">"run: compare <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L592" class="LineNr"> 592 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L593" class="LineNr"> 593 </span> <span class="Constant">"run: effective address contains 0x0a0b0c0d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L594" class="LineNr"> 594 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L595" class="LineNr"> 595 </span> <span class="Delimiter">);</span> +<span id="L596" class="LineNr"> 596 </span><span class="Delimiter">}</span> +<span id="L597" class="LineNr"> 597 </span> +<span id="L598" class="LineNr"> 598 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L598'>test_compare_r32_with_mem_at_rm32_lesser_unsigned_and_signed_due_to_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L599" class="LineNr"> 599 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L600" class="LineNr"> 600 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MAX</span><span class="Delimiter">;</span> +<span id="L601" class="LineNr"> 601 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L602" class="LineNr"> 602 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L603" class="LineNr"> 603 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L604" class="LineNr"> 604 </span> <span class="Constant">" 3b 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EBX with *EAX</span> +<span id="L605" class="LineNr"> 605 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (lhs EBX) 000 (rhs EAX)</span> +<span id="L606" class="LineNr"> 606 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L607" class="LineNr"> 607 </span> <span class="Constant">"00 00 00 80</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// INT32_MIN</span> +<span id="L608" class="LineNr"> 608 </span> <span class="Delimiter">);</span> +<span id="L609" class="LineNr"> 609 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L610" class="LineNr"> 610 </span> <span class="Constant">"run: compare <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L611" class="LineNr"> 611 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L612" class="LineNr"> 612 </span> <span class="Constant">"run: effective address contains 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L613" class="LineNr"> 613 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L614" class="LineNr"> 614 </span> <span class="Delimiter">);</span> +<span id="L615" class="LineNr"> 615 </span><span class="Delimiter">}</span> +<span id="L616" class="LineNr"> 616 </span> +<span id="L617" class="LineNr"> 617 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L617'>test_compare_r32_with_mem_at_rm32_lesser_signed</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L618" class="LineNr"> 618 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L619" class="LineNr"> 619 </span> Reg[EBX]<span class="Delimiter">.</span>i = -<span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L620" class="LineNr"> 620 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L621" class="LineNr"> 621 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L622" class="LineNr"> 622 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L623" class="LineNr"> 623 </span> <span class="Constant">" 3b 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EBX with *EAX</span> +<span id="L624" class="LineNr"> 624 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (lhs EBX) 000 (rhs EAX)</span> +<span id="L625" class="LineNr"> 625 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L626" class="LineNr"> 626 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L627" class="LineNr"> 627 </span> <span class="Delimiter">);</span> +<span id="L628" class="LineNr"> 628 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L629" class="LineNr"> 629 </span> <span class="Constant">"run: compare <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L630" class="LineNr"> 630 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L631" class="LineNr"> 631 </span> <span class="Constant">"run: effective address contains 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L632" class="LineNr"> 632 </span> <span class="Constant">"run: SF=1; ZF=0; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L633" class="LineNr"> 633 </span> <span class="Delimiter">);</span> +<span id="L634" class="LineNr"> 634 </span><span class="Delimiter">}</span> +<span id="L635" class="LineNr"> 635 </span> +<span id="L636" class="LineNr"> 636 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L636'>test_compare_r32_with_mem_at_rm32_lesser_unsigned</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L637" class="LineNr"> 637 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L638" class="LineNr"> 638 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L639" class="LineNr"> 639 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L640" class="LineNr"> 640 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L641" class="LineNr"> 641 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L642" class="LineNr"> 642 </span> <span class="Constant">" 3b 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EBX with *EAX</span> +<span id="L643" class="LineNr"> 643 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (lhs EBX) 000 (rhs EAX)</span> +<span id="L644" class="LineNr"> 644 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L645" class="LineNr"> 645 </span> <span class="Constant">"ff ff ff ff</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// -1</span> +<span id="L646" class="LineNr"> 646 </span> <span class="Delimiter">);</span> +<span id="L647" class="LineNr"> 647 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L648" class="LineNr"> 648 </span> <span class="Constant">"run: compare <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L649" class="LineNr"> 649 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L650" class="LineNr"> 650 </span> <span class="Constant">"run: effective address contains 0xffffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L651" class="LineNr"> 651 </span> <span class="Constant">"run: SF=0; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L652" class="LineNr"> 652 </span> <span class="Delimiter">);</span> +<span id="L653" class="LineNr"> 653 </span><span class="Delimiter">}</span> +<span id="L654" class="LineNr"> 654 </span> +<span id="L655" class="LineNr"> 655 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L655'>test_compare_r32_with_mem_at_rm32_equal</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L656" class="LineNr"> 656 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L657" class="LineNr"> 657 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c0d</span><span class="Delimiter">;</span> +<span id="L658" class="LineNr"> 658 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L659" class="LineNr"> 659 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L660" class="LineNr"> 660 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L661" class="LineNr"> 661 </span> <span class="Constant">" 3b 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EBX with *EAX</span> +<span id="L662" class="LineNr"> 662 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (lhs EBX) 000 (rhs EAX)</span> +<span id="L663" class="LineNr"> 663 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L664" class="LineNr"> 664 </span> <span class="Constant">"0d 0c 0b 0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0a0b0c0d</span> +<span id="L665" class="LineNr"> 665 </span> <span class="Delimiter">);</span> +<span id="L666" class="LineNr"> 666 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L667" class="LineNr"> 667 </span> <span class="Constant">"run: compare <a href='010vm.cc.html#L13'>EBX</a> with r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L668" class="LineNr"> 668 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L669" class="LineNr"> 669 </span> <span class="Constant">"run: SF=0; ZF=1; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L670" class="LineNr"> 670 </span> <span class="Delimiter">);</span> +<span id="L671" class="LineNr"> 671 </span><span class="Delimiter">}</span> +<span id="L672" class="LineNr"> 672 </span> +<span id="L673" class="LineNr"> 673 </span><span class="Comment">//:: copy (mov)</span> +<span id="L674" class="LineNr"> 674 </span> +<span id="L675" class="LineNr"> 675 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L675'>test_copy_r32_to_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L676" class="LineNr"> 676 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xaf</span><span class="Delimiter">;</span> +<span id="L677" class="LineNr"> 677 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x60</span><span class="Delimiter">;</span> +<span id="L678" class="LineNr"> 678 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L679" class="LineNr"> 679 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L680" class="LineNr"> 680 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L681" class="LineNr"> 681 </span> <span class="Constant">" 89 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy EBX to *EAX</span> +<span id="L682" class="LineNr"> 682 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L683" class="LineNr"> 683 </span> <span class="Delimiter">);</span> +<span id="L684" class="LineNr"> 684 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L685" class="LineNr"> 685 </span> <span class="Constant">"run: copy <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L686" class="LineNr"> 686 </span> <span class="Constant">"run: effective address is 0x00000060 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L687" class="LineNr"> 687 </span> <span class="Constant">"run: storing 0x000000af</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L688" class="LineNr"> 688 </span> <span class="Delimiter">);</span> +<span id="L689" class="LineNr"> 689 </span><span class="Delimiter">}</span> +<span id="L690" class="LineNr"> 690 </span> +<span id="L691" class="LineNr"> 691 </span><span class="Comment">//:</span> +<span id="L692" class="LineNr"> 692 </span> +<span id="L693" class="LineNr"> 693 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L694" class="LineNr"> 694 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"8b"</span><span class="Delimiter">,</span> <span class="Constant">"copy rm32 to r32 (mov)"</span><span class="Delimiter">);</span> +<span id="L695" class="LineNr"> 695 </span> +<span id="L696" class="LineNr"> 696 </span><span class="Delimiter">:(code)</span> +<span id="L697" class="LineNr"> 697 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L697'>test_copy_mem_at_rm32_to_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L698" class="LineNr"> 698 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L699" class="LineNr"> 699 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L700" class="LineNr"> 700 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L701" class="LineNr"> 701 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L702" class="LineNr"> 702 </span> <span class="Constant">" 8b 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy *EAX to EBX</span> +<span id="L703" class="LineNr"> 703 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L704" class="LineNr"> 704 </span> <span class="Constant">"af 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0xaf</span> +<span id="L705" class="LineNr"> 705 </span> <span class="Delimiter">);</span> +<span id="L706" class="LineNr"> 706 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L707" class="LineNr"> 707 </span> <span class="Constant">"run: copy r/m32 to <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L708" class="LineNr"> 708 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L709" class="LineNr"> 709 </span> <span class="Constant">"run: storing 0x000000af</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L710" class="LineNr"> 710 </span> <span class="Delimiter">);</span> +<span id="L711" class="LineNr"> 711 </span><span class="Delimiter">}</span> +<span id="L712" class="LineNr"> 712 </span> +<span id="L713" class="LineNr"> 713 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L714" class="LineNr"> 714 </span><span class="Normal">case</span> <span class="Constant">0x8b</span>: <span class="Delimiter">{</span> <span class="Comment">// copy r32 to r/m32</span> +<span id="L715" class="LineNr"> 715 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L716" class="LineNr"> 716 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rdest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L717" class="LineNr"> 717 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy r/m32 to "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>rdest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L718" class="LineNr"> 718 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* src = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L719" class="LineNr"> 719 </span> Reg[rdest]<span class="Delimiter">.</span>i = *src<span class="Delimiter">;</span> +<span id="L720" class="LineNr"> 720 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *src << end<span class="Delimiter">();</span> +<span id="L721" class="LineNr"> 721 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L722" class="LineNr"> 722 </span><span class="Delimiter">}</span> +<span id="L723" class="LineNr"> 723 </span> +<span id="L724" class="LineNr"> 724 </span><span class="Comment">//:: jump</span> +<span id="L725" class="LineNr"> 725 </span> +<span id="L726" class="LineNr"> 726 </span><span class="Delimiter">:(code)</span> +<span id="L727" class="LineNr"> 727 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L727'>test_jump_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L728" class="LineNr"> 728 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L729" class="LineNr"> 729 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L730" class="LineNr"> 730 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L731" class="LineNr"> 731 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L732" class="LineNr"> 732 </span> <span class="Constant">" ff 20 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// jump to *EAX</span> +<span id="L733" class="LineNr"> 733 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 100 (jump to r/m32) 000 (src EAX)</span> +<span id="L734" class="LineNr"> 734 </span> <span class="Constant">" b8 00 00 00 01</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L735" class="LineNr"> 735 </span> <span class="Constant">" b8 00 00 00 02</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L736" class="LineNr"> 736 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L737" class="LineNr"> 737 </span> <span class="Constant">"08 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x8</span> +<span id="L738" class="LineNr"> 738 </span> <span class="Delimiter">);</span> +<span id="L739" class="LineNr"> 739 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L740" class="LineNr"> 740 </span> <span class="Constant">"run: 0x00000001 opcode: ff</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L741" class="LineNr"> 741 </span> <span class="Constant">"run: jump to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L742" class="LineNr"> 742 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L743" class="LineNr"> 743 </span> <span class="Constant">"run: jumping to 0x00000008</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L744" class="LineNr"> 744 </span> <span class="Constant">"run: 0x00000008 opcode: b8</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L745" class="LineNr"> 745 </span> <span class="Delimiter">);</span> +<span id="L746" class="LineNr"> 746 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000003 opcode: b8"</span><span class="Delimiter">);</span> +<span id="L747" class="LineNr"> 747 </span><span class="Delimiter">}</span> +<span id="L748" class="LineNr"> 748 </span> +<span id="L749" class="LineNr"> 749 </span><span class="Delimiter">:(before "End Op ff Subops")</span> +<span id="L750" class="LineNr"> 750 </span><span class="Normal">case</span> <span class="Constant">4</span>: <span class="Delimiter">{</span> <span class="Comment">// jump to r/m32</span> +<span id="L751" class="LineNr"> 751 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump to r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L752" class="LineNr"> 752 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* arg2 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L753" class="LineNr"> 753 </span> <a href='010vm.cc.html#L26'>EIP</a> = *arg2<span class="Delimiter">;</span> +<span id="L754" class="LineNr"> 754 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L26'>EIP</a> << end<span class="Delimiter">();</span> +<span id="L755" class="LineNr"> 755 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L756" class="LineNr"> 756 </span><span class="Delimiter">}</span> +<span id="L757" class="LineNr"> 757 </span> +<span id="L758" class="LineNr"> 758 </span><span class="Comment">//:: push</span> +<span id="L759" class="LineNr"> 759 </span> +<span id="L760" class="LineNr"> 760 </span><span class="Delimiter">:(code)</span> +<span id="L761" class="LineNr"> 761 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L761'>test_push_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L762" class="LineNr"> 762 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L763" class="LineNr"> 763 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><span class="Constant">0xbd000000</span><span class="Delimiter">));</span> <span class="Comment">// manually allocate memory</span> +<span id="L764" class="LineNr"> 764 </span> Reg[ESP]<span class="Delimiter">.</span>u = <span class="Constant">0xbd000014</span><span class="Delimiter">;</span> +<span id="L765" class="LineNr"> 765 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L766" class="LineNr"> 766 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L767" class="LineNr"> 767 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L768" class="LineNr"> 768 </span> <span class="Constant">" ff 30 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// push *EAX to stack</span> +<span id="L769" class="LineNr"> 769 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L770" class="LineNr"> 770 </span> <span class="Constant">"af 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0xaf</span> +<span id="L771" class="LineNr"> 771 </span> <span class="Delimiter">);</span> +<span id="L772" class="LineNr"> 772 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L773" class="LineNr"> 773 </span> <span class="Constant">"run: <a href='012elf.cc.html#L94'>push</a> r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L774" class="LineNr"> 774 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L775" class="LineNr"> 775 </span> <span class="Constant">"run: decrementing <a href='010vm.cc.html#L14'>ESP</a> to 0xbd000010</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L776" class="LineNr"> 776 </span> <span class="Constant">"run: pushing value 0x000000af</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L777" class="LineNr"> 777 </span> <span class="Delimiter">);</span> +<span id="L778" class="LineNr"> 778 </span><span class="Delimiter">}</span> +<span id="L779" class="LineNr"> 779 </span> +<span id="L780" class="LineNr"> 780 </span><span class="Delimiter">:(before "End Op ff Subops")</span> +<span id="L781" class="LineNr"> 781 </span><span class="Normal">case</span> <span class="Constant">6</span>: <span class="Delimiter">{</span> <span class="Comment">// push r/m32 to stack</span> +<span id="L782" class="LineNr"> 782 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"push r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L783" class="LineNr"> 783 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* val = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L784" class="LineNr"> 784 </span> <a href='012elf.cc.html#L94'>push</a><span class="Delimiter">(</span>*val<span class="Delimiter">);</span> +<span id="L785" class="LineNr"> 785 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L786" class="LineNr"> 786 </span><span class="Delimiter">}</span> +<span id="L787" class="LineNr"> 787 </span> +<span id="L788" class="LineNr"> 788 </span><span class="Comment">//:: pop</span> +<span id="L789" class="LineNr"> 789 </span> +<span id="L790" class="LineNr"> 790 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L791" class="LineNr"> 791 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"8f"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to rm32 (<a href='013direct_addressing.cc.html#L1270'>pop</a>)"</span><span class="Delimiter">);</span> +<span id="L792" class="LineNr"> 792 </span> +<span id="L793" class="LineNr"> 793 </span><span class="Delimiter">:(code)</span> +<span id="L794" class="LineNr"> 794 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L794'>test_pop_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L795" class="LineNr"> 795 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x60</span><span class="Delimiter">;</span> +<span id="L796" class="LineNr"> 796 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><span class="Constant">0xbd000000</span><span class="Delimiter">));</span> <span class="Comment">// manually allocate memory</span> +<span id="L797" class="LineNr"> 797 </span> Reg[ESP]<span class="Delimiter">.</span>u = <span class="Constant">0xbd000000</span><span class="Delimiter">;</span> +<span id="L798" class="LineNr"> 798 </span> <a href='010vm.cc.html#L256'>write_mem_i32</a><span class="Delimiter">(</span><span class="Constant">0xbd000000</span><span class="Delimiter">,</span> <span class="Constant">0x00000030</span><span class="Delimiter">);</span> +<span id="L799" class="LineNr"> 799 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L800" class="LineNr"> 800 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L801" class="LineNr"> 801 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L802" class="LineNr"> 802 </span> <span class="Constant">" 8f 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// pop stack into *EAX</span> +<span id="L803" class="LineNr"> 803 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 000 (pop r/m32) 000 (dest EAX)</span> +<span id="L804" class="LineNr"> 804 </span> <span class="Delimiter">);</span> +<span id="L805" class="LineNr"> 805 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L806" class="LineNr"> 806 </span> <span class="Constant">"run: <a href='013direct_addressing.cc.html#L1270'>pop</a> into r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L807" class="LineNr"> 807 </span> <span class="Constant">"run: effective address is 0x00000060 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L808" class="LineNr"> 808 </span> <span class="Constant">"run: popping value 0x00000030</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L809" class="LineNr"> 809 </span> <span class="Constant">"run: incrementing <a href='010vm.cc.html#L14'>ESP</a> to 0xbd000004</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L810" class="LineNr"> 810 </span> <span class="Delimiter">);</span> +<span id="L811" class="LineNr"> 811 </span><span class="Delimiter">}</span> +<span id="L812" class="LineNr"> 812 </span> +<span id="L813" class="LineNr"> 813 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L814" class="LineNr"> 814 </span><span class="Normal">case</span> <span class="Constant">0x8f</span>: <span class="Delimiter">{</span> <span class="Comment">// pop stack into r/m32</span> +<span id="L815" class="LineNr"> 815 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L816" class="LineNr"> 816 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> subop = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L817" class="LineNr"> 817 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>subop<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L818" class="LineNr"> 818 </span> <span class="Normal">case</span> <span class="Constant">0</span>: <span class="Delimiter">{</span> +<span id="L819" class="LineNr"> 819 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"pop into r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L820" class="LineNr"> 820 </span> <span class="Normal">int32_t</span>* dest = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L821" class="LineNr"> 821 </span> *dest = <a href='013direct_addressing.cc.html#L1270'>pop</a><span class="Delimiter">();</span> <span class="Comment">// Write multiple elements of vector<uint8_t> at once. Assumes sizeof(int) == 4 on the host as well.</span> +<span id="L822" class="LineNr"> 822 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L823" class="LineNr"> 823 </span> <span class="Delimiter">}</span> +<span id="L824" class="LineNr"> 824 </span> <span class="Delimiter">}</span> +<span id="L825" class="LineNr"> 825 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L826" class="LineNr"> 826 </span><span class="Delimiter">}</span> +<span id="L827" class="LineNr"> 827 </span> +<span id="L828" class="LineNr"> 828 </span><span class="Comment">//:: special-case for loading address from disp32 rather than register</span> +<span id="L829" class="LineNr"> 829 </span> +<span id="L830" class="LineNr"> 830 </span><span class="Delimiter">:(code)</span> +<span id="L831" class="LineNr"> 831 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L831'>test_add_r32_to_mem_at_displacement</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L832" class="LineNr"> 832 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> <span class="Comment">// source</span> +<span id="L833" class="LineNr"> 833 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L834" class="LineNr"> 834 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L835" class="LineNr"> 835 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L836" class="LineNr"> 836 </span> <span class="Constant">" 01 1d 00 20 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to *0x2000</span> +<span id="L837" class="LineNr"> 837 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 101 (dest in disp32)</span> +<span id="L838" class="LineNr"> 838 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L839" class="LineNr"> 839 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L840" class="LineNr"> 840 </span> <span class="Delimiter">);</span> +<span id="L841" class="LineNr"> 841 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L842" class="LineNr"> 842 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L843" class="LineNr"> 843 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='040tests.cc.html#L82'>disp32</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L844" class="LineNr"> 844 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L845" class="LineNr"> 845 </span> <span class="Delimiter">);</span> +<span id="L846" class="LineNr"> 846 </span><span class="Delimiter">}</span> +<span id="L847" class="LineNr"> 847 </span> +<span id="L848" class="LineNr"> 848 </span><span class="Delimiter">:(before "End Mod 0 Special-cases(addr)")</span> +<span id="L849" class="LineNr"> 849 </span><span class="Normal">case</span> <span class="Constant">5</span>: <span class="Comment">// exception: mod 0b00 rm 0b101 => incoming disp32</span> +<span id="L850" class="LineNr"> 850 </span> addr = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L851" class="LineNr"> 851 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" (<a href='040tests.cc.html#L82'>disp32</a>)"</span> << end<span class="Delimiter">();</span> +<span id="L852" class="LineNr"> 852 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L853" class="LineNr"> 853 </span> +<span id="L854" class="LineNr"> 854 </span><span class="Comment">//:</span> +<span id="L855" class="LineNr"> 855 </span> +<span id="L856" class="LineNr"> 856 </span><span class="Delimiter">:(code)</span> +<span id="L857" class="LineNr"> 857 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L857'>test_add_r32_to_mem_at_rm32_plus_disp8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L858" class="LineNr"> 858 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> <span class="Comment">// source</span> +<span id="L859" class="LineNr"> 859 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x1ffe</span><span class="Delimiter">;</span> <span class="Comment">// dest</span> +<span id="L860" class="LineNr"> 860 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L861" class="LineNr"> 861 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L862" class="LineNr"> 862 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L863" class="LineNr"> 863 </span> <span class="Constant">" 01 58 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to *(EAX+2)</span> +<span id="L864" class="LineNr"> 864 </span> <span class="Comment">// ModR/M in binary: 01 (indirect+disp8 mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L865" class="LineNr"> 865 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L866" class="LineNr"> 866 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L867" class="LineNr"> 867 </span> <span class="Delimiter">);</span> +<span id="L868" class="LineNr"> 868 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L869" class="LineNr"> 869 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L870" class="LineNr"> 870 </span> <span class="Constant">"run: effective address is initially 0x00001ffe (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L871" class="LineNr"> 871 </span> <span class="Constant">"run: effective address is 0x00002000 (after adding disp8)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L872" class="LineNr"> 872 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L873" class="LineNr"> 873 </span> <span class="Delimiter">);</span> +<span id="L874" class="LineNr"> 874 </span><span class="Delimiter">}</span> +<span id="L875" class="LineNr"> 875 </span> +<span id="L876" class="LineNr"> 876 </span><span class="Delimiter">:(before "End Mod Special-cases(addr)")</span> +<span id="L877" class="LineNr"> 877 </span><span class="Normal">case</span> <span class="Constant">1</span>: <span class="Delimiter">{</span> <span class="Comment">// indirect + disp8 addressing</span> +<span id="L878" class="LineNr"> 878 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>rm<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L879" class="LineNr"> 879 </span> <span class="Normal">default</span>: +<span id="L880" class="LineNr"> 880 </span> addr = Reg[rm]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L881" class="LineNr"> 881 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is initially 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" ("</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>rm<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> +<span id="L882" class="LineNr"> 882 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L883" class="LineNr"> 883 </span> <span class="Comment">// End Mod 1 Special-cases(addr)</span> +<span id="L884" class="LineNr"> 884 </span> <span class="Delimiter">}</span> +<span id="L885" class="LineNr"> 885 </span> <span class="Normal">int8_t</span> displacement = <span class="Normal">static_cast</span><<span class="Normal">int8_t</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L338'>next</a><span class="Delimiter">());</span> +<span id="L886" class="LineNr"> 886 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>addr > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L887" class="LineNr"> 887 </span> addr += displacement<span class="Delimiter">;</span> +<span id="L888" class="LineNr"> 888 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" (after adding disp8)"</span> << end<span class="Delimiter">();</span> +<span id="L889" class="LineNr"> 889 </span> <span class="Delimiter">}</span> +<span id="L890" class="LineNr"> 890 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L891" class="LineNr"> 891 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"null address; skipping displacement"</span> << end<span class="Delimiter">();</span> +<span id="L892" class="LineNr"> 892 </span> <span class="Delimiter">}</span> +<span id="L893" class="LineNr"> 893 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L894" class="LineNr"> 894 </span><span class="Delimiter">}</span> +<span id="L895" class="LineNr"> 895 </span> +<span id="L896" class="LineNr"> 896 </span><span class="Delimiter">:(code)</span> +<span id="L897" class="LineNr"> 897 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L897'>test_add_r32_to_mem_at_rm32_plus_negative_disp8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L898" class="LineNr"> 898 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> <span class="Comment">// source</span> +<span id="L899" class="LineNr"> 899 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2001</span><span class="Delimiter">;</span> <span class="Comment">// dest</span> +<span id="L900" class="LineNr"> 900 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L901" class="LineNr"> 901 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L902" class="LineNr"> 902 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L903" class="LineNr"> 903 </span> <span class="Constant">" 01 58 ff </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to *(EAX-1)</span> +<span id="L904" class="LineNr"> 904 </span> <span class="Comment">// ModR/M in binary: 01 (indirect+disp8 mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L905" class="LineNr"> 905 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L906" class="LineNr"> 906 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L907" class="LineNr"> 907 </span> <span class="Delimiter">);</span> +<span id="L908" class="LineNr"> 908 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L909" class="LineNr"> 909 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L910" class="LineNr"> 910 </span> <span class="Constant">"run: effective address is initially 0x00002001 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L911" class="LineNr"> 911 </span> <span class="Constant">"run: effective address is 0x00002000 (after adding disp8)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L912" class="LineNr"> 912 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L913" class="LineNr"> 913 </span> <span class="Delimiter">);</span> +<span id="L914" class="LineNr"> 914 </span><span class="Delimiter">}</span> +<span id="L915" class="LineNr"> 915 </span> +<span id="L916" class="LineNr"> 916 </span><span class="Comment">//:</span> +<span id="L917" class="LineNr"> 917 </span> +<span id="L918" class="LineNr"> 918 </span><span class="Delimiter">:(code)</span> +<span id="L919" class="LineNr"> 919 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L919'>test_add_r32_to_mem_at_rm32_plus_disp32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L920" class="LineNr"> 920 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> <span class="Comment">// source</span> +<span id="L921" class="LineNr"> 921 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x1ffe</span><span class="Delimiter">;</span> <span class="Comment">// dest</span> +<span id="L922" class="LineNr"> 922 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L923" class="LineNr"> 923 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L924" class="LineNr"> 924 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L925" class="LineNr"> 925 </span> <span class="Constant">" 01 98 02 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to *(EAX+2)</span> +<span id="L926" class="LineNr"> 926 </span> <span class="Comment">// ModR/M in binary: 10 (indirect+disp32 mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L927" class="LineNr"> 927 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L928" class="LineNr"> 928 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L929" class="LineNr"> 929 </span> <span class="Delimiter">);</span> +<span id="L930" class="LineNr"> 930 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L931" class="LineNr"> 931 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L932" class="LineNr"> 932 </span> <span class="Constant">"run: effective address is initially 0x00001ffe (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L933" class="LineNr"> 933 </span> <span class="Constant">"run: effective address is 0x00002000 (after adding <a href='040tests.cc.html#L82'>disp32</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L934" class="LineNr"> 934 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L935" class="LineNr"> 935 </span> <span class="Delimiter">);</span> +<span id="L936" class="LineNr"> 936 </span><span class="Delimiter">}</span> +<span id="L937" class="LineNr"> 937 </span> +<span id="L938" class="LineNr"> 938 </span><span class="Delimiter">:(before "End Mod Special-cases(addr)")</span> +<span id="L939" class="LineNr"> 939 </span><span class="Normal">case</span> <span class="Constant">2</span>: <span class="Delimiter">{</span> <span class="Comment">// indirect + disp32 addressing</span> +<span id="L940" class="LineNr"> 940 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>rm<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L941" class="LineNr"> 941 </span> <span class="Normal">default</span>: +<span id="L942" class="LineNr"> 942 </span> addr = Reg[rm]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L943" class="LineNr"> 943 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is initially 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" ("</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>rm<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> +<span id="L944" class="LineNr"> 944 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L945" class="LineNr"> 945 </span> <span class="Comment">// End Mod 2 Special-cases(addr)</span> +<span id="L946" class="LineNr"> 946 </span> <span class="Delimiter">}</span> +<span id="L947" class="LineNr"> 947 </span> <span class="Normal">int32_t</span> displacement = <span class="Normal">static_cast</span><<span class="Normal">int32_t</span>><span class="Delimiter">(</span><a href='011run.cc.html#L433'>next32</a><span class="Delimiter">());</span> +<span id="L948" class="LineNr"> 948 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>addr > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L949" class="LineNr"> 949 </span> addr += displacement<span class="Delimiter">;</span> +<span id="L950" class="LineNr"> 950 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" (after adding <a href='040tests.cc.html#L82'>disp32</a>)"</span> << end<span class="Delimiter">();</span> +<span id="L951" class="LineNr"> 951 </span> <span class="Delimiter">}</span> +<span id="L952" class="LineNr"> 952 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L953" class="LineNr"> 953 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"null address; skipping displacement"</span> << end<span class="Delimiter">();</span> +<span id="L954" class="LineNr"> 954 </span> <span class="Delimiter">}</span> +<span id="L955" class="LineNr"> 955 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L956" class="LineNr"> 956 </span><span class="Delimiter">}</span> +<span id="L957" class="LineNr"> 957 </span> +<span id="L958" class="LineNr"> 958 </span><span class="Delimiter">:(code)</span> +<span id="L959" class="LineNr"> 959 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L959'>test_add_r32_to_mem_at_rm32_plus_negative_disp32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L960" class="LineNr"> 960 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> <span class="Comment">// source</span> +<span id="L961" class="LineNr"> 961 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2001</span><span class="Delimiter">;</span> <span class="Comment">// dest</span> +<span id="L962" class="LineNr"> 962 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L963" class="LineNr"> 963 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L964" class="LineNr"> 964 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L965" class="LineNr"> 965 </span> <span class="Constant">" 01 98 ff ff ff ff </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to *(EAX-1)</span> +<span id="L966" class="LineNr"> 966 </span> <span class="Comment">// ModR/M in binary: 10 (indirect+disp32 mode) 011 (src EBX) 000 (dest EAX)</span> +<span id="L967" class="LineNr"> 967 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L968" class="LineNr"> 968 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L969" class="LineNr"> 969 </span> <span class="Delimiter">);</span> +<span id="L970" class="LineNr"> 970 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L971" class="LineNr"> 971 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L972" class="LineNr"> 972 </span> <span class="Constant">"run: effective address is initially 0x00002001 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L973" class="LineNr"> 973 </span> <span class="Constant">"run: effective address is 0x00002000 (after adding <a href='040tests.cc.html#L82'>disp32</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L974" class="LineNr"> 974 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L975" class="LineNr"> 975 </span> <span class="Delimiter">);</span> +<span id="L976" class="LineNr"> 976 </span><span class="Delimiter">}</span> +<span id="L977" class="LineNr"> 977 </span> +<span id="L978" class="LineNr"> 978 </span><span class="Comment">//:: copy address (lea)</span> +<span id="L979" class="LineNr"> 979 </span> +<span id="L980" class="LineNr"> 980 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L981" class="LineNr"> 981 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"8d"</span><span class="Delimiter">,</span> <span class="Constant">"copy address in rm32 into r32 (lea)"</span><span class="Delimiter">);</span> +<span id="L982" class="LineNr"> 982 </span> +<span id="L983" class="LineNr"> 983 </span><span class="Delimiter">:(code)</span> +<span id="L984" class="LineNr"> 984 </span><span class="Normal">void</span> <a href='014indirect_addressing.cc.html#L984'>test_copy_address</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L985" class="LineNr"> 985 </span> Reg[EAX]<span class="Delimiter">.</span>u = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L986" class="LineNr"> 986 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L987" class="LineNr"> 987 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L988" class="LineNr"> 988 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L989" class="LineNr"> 989 </span> <span class="Constant">" 8d 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy address in EAX into EBX</span> +<span id="L990" class="LineNr"> 990 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (dest EBX) 000 (src EAX)</span> +<span id="L991" class="LineNr"> 991 </span> <span class="Delimiter">);</span> +<span id="L992" class="LineNr"> 992 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L993" class="LineNr"> 993 </span> <span class="Constant">"run: copy address into <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L994" class="LineNr"> 994 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L995" class="LineNr"> 995 </span> <span class="Delimiter">);</span> +<span id="L996" class="LineNr"> 996 </span><span class="Delimiter">}</span> +<span id="L997" class="LineNr"> 997 </span> +<span id="L998" class="LineNr"> 998 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L999" class="LineNr"> 999 </span><span class="Normal">case</span> <span class="Constant">0x8d</span>: <span class="Delimiter">{</span> <span class="Comment">// copy address of m32 to r32</span> +<span id="L1000" class="LineNr">1000 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L1001" class="LineNr">1001 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L1002" class="LineNr">1002 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy address into "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L1003" class="LineNr">1003 </span> Reg[arg1]<span class="Delimiter">.</span>u = <a href='013direct_addressing.cc.html#L116'>effective_address_number</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L1004" class="LineNr">1004 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1005" class="LineNr">1005 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/015immediate_addressing.cc.html b/html/linux/bootstrap/015immediate_addressing.cc.html new file mode 100644 index 00000000..6d5b873b --- /dev/null +++ b/html/linux/bootstrap/015immediate_addressing.cc.html @@ -0,0 +1,1374 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/015immediate_addressing.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.LineNr { } +.Constant { color: #008787; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.CommentedCode { color: #8a8a8a; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/015immediate_addressing.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/015immediate_addressing.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: instructions that (immediately) contain an argument to act with</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L4" class="LineNr"> 4 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"05"</span><span class="Delimiter">,</span> <span class="Constant">"add imm32 to <a href='010vm.cc.html#L10'>EAX</a> (add)"</span><span class="Delimiter">);</span> +<span id="L5" class="LineNr"> 5 </span> +<span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L7" class="LineNr"> 7 </span><span class="Normal">case</span> <span class="Constant">0x05</span>: <span class="Delimiter">{</span> <span class="Comment">// add imm32 to EAX</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Normal">int32_t</span> signed_arg2 = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L9" class="LineNr"> 9 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"add imm32 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << signed_arg2 << <span class="Constant">" to EAX"</span> << end<span class="Delimiter">();</span> +<span id="L10" class="LineNr"> 10 </span> <span class="Normal">int32_t</span> signed_result = Reg[EAX]<span class="Delimiter">.</span>i + signed_arg2<span class="Delimiter">;</span> +<span id="L11" class="LineNr"> 11 </span> SF = <span class="Delimiter">(</span>signed_result < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L12" class="LineNr"> 12 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>signed_result == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Normal">int64_t</span> signed_full_result = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">)</span> + signed_arg2<span class="Delimiter">;</span> +<span id="L14" class="LineNr"> 14 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>signed_result != signed_full_result<span class="Delimiter">);</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Comment">// set CF</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Normal">uint32_t</span> unsigned_arg2 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>signed_arg2<span class="Delimiter">);</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Normal">uint32_t</span> unsigned_result = Reg[EAX]<span class="Delimiter">.</span>u + unsigned_arg2<span class="Delimiter">;</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Normal">uint64_t</span> unsigned_full_result = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> + unsigned_arg2<span class="Delimiter">;</span> +<span id="L19" class="LineNr"> 19 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>unsigned_result != unsigned_full_result<span class="Delimiter">);</span> +<span id="L20" class="LineNr"> 20 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L21" class="LineNr"> 21 </span> Reg[EAX]<span class="Delimiter">.</span>i = signed_result<span class="Delimiter">;</span> +<span id="L22" class="LineNr"> 22 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L23" class="LineNr"> 23 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L24" class="LineNr"> 24 </span><span class="Delimiter">}</span> +<span id="L25" class="LineNr"> 25 </span> +<span id="L26" class="LineNr"> 26 </span><span class="Delimiter">:(code)</span> +<span id="L27" class="LineNr"> 27 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L27'>test_add_imm32_to_EAX_signed_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L28" class="LineNr"> 28 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MAX</span><span class="Delimiter">;</span> +<span id="L29" class="LineNr"> 29 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L31" class="LineNr"> 31 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Constant">" 05 01 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add 1 to EAX</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Delimiter">);</span> +<span id="L34" class="LineNr"> 34 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L35" class="LineNr"> 35 </span> <span class="Constant">"run: add imm32 0x00000001 to <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Constant">"run: SF=1; ZF=0; CF=0; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Constant">"run: storing 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L38" class="LineNr"> 38 </span> <span class="Delimiter">);</span> +<span id="L39" class="LineNr"> 39 </span><span class="Delimiter">}</span> +<span id="L40" class="LineNr"> 40 </span> +<span id="L41" class="LineNr"> 41 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L41'>test_add_imm32_to_EAX_unsigned_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L42" class="LineNr"> 42 </span> Reg[EAX]<span class="Delimiter">.</span>u = <span class="Constant">UINT32_MAX</span><span class="Delimiter">;</span> +<span id="L43" class="LineNr"> 43 </span> Reg[EBX]<span class="Delimiter">.</span>u = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L44" class="LineNr"> 44 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Constant">" 05 01 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add 1 to EAX</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Delimiter">);</span> +<span id="L49" class="LineNr"> 49 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Constant">"run: add imm32 0x00000001 to <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Constant">"run: SF=0; ZF=1; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Constant">"run: storing 0x00000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Delimiter">);</span> +<span id="L54" class="LineNr"> 54 </span><span class="Delimiter">}</span> +<span id="L55" class="LineNr"> 55 </span> +<span id="L56" class="LineNr"> 56 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L56'>test_add_imm32_to_EAX_unsigned_and_signed_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L57" class="LineNr"> 57 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MIN</span><span class="Delimiter">;</span> +<span id="L58" class="LineNr"> 58 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Constant">" 05 00 00 00 80 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add 0x80000000 to EAX</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Delimiter">);</span> +<span id="L63" class="LineNr"> 63 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Constant">"run: add imm32 0x80000000 to <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Constant">"run: SF=0; ZF=1; CF=1; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Constant">"run: storing 0x00000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Delimiter">);</span> +<span id="L68" class="LineNr"> 68 </span><span class="Delimiter">}</span> +<span id="L69" class="LineNr"> 69 </span> +<span id="L70" class="LineNr"> 70 </span><span class="Comment">//:</span> +<span id="L71" class="LineNr"> 71 </span> +<span id="L72" class="LineNr"> 72 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L73" class="LineNr"> 73 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"81"</span><span class="Delimiter">,</span> <span class="Constant">"combine rm32 with imm32 based on subop (add/sub/and/or/xor/cmp)"</span><span class="Delimiter">);</span> +<span id="L74" class="LineNr"> 74 </span> +<span id="L75" class="LineNr"> 75 </span><span class="Delimiter">:(code)</span> +<span id="L76" class="LineNr"> 76 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L76'>test_add_imm32_to_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L77" class="LineNr"> 77 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L78" class="LineNr"> 78 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Constant">" 81 c3 0a 0b 0c 0d</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add 0x0d0c0b0a to EBX</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (subop add) 011 (dest EBX)</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Delimiter">);</span> +<span id="L84" class="LineNr"> 84 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Constant">"run: imm32 is 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Constant">"run: subop add</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Constant">"run: storing 0x0d0c0b0b</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Delimiter">);</span> +<span id="L91" class="LineNr"> 91 </span><span class="Delimiter">}</span> +<span id="L92" class="LineNr"> 92 </span> +<span id="L93" class="LineNr"> 93 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L94" class="LineNr"> 94 </span><span class="Normal">case</span> <span class="Constant">0x81</span>: <span class="Delimiter">{</span> <span class="Comment">// combine r/m32 with imm32</span> +<span id="L95" class="LineNr"> 95 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"combine r/m32 with imm32"</span> << end<span class="Delimiter">();</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Normal">int32_t</span>* signed_arg1 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> signed_arg2 = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L99" class="LineNr"> 99 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"imm32 is 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << signed_arg2 << end<span class="Delimiter">();</span> +<span id="L100" class="LineNr"> 100 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> subop = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span class="Comment">// middle 3 'reg opcode' bits</span> +<span id="L101" class="LineNr"> 101 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>subop<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L102" class="LineNr"> 102 </span> <span class="Normal">case</span> <span class="Constant">0</span>: <span class="Delimiter">{</span> +<span id="L103" class="LineNr"> 103 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop add"</span> << end<span class="Delimiter">();</span> +<span id="L104" class="LineNr"> 104 </span> <span class="Normal">int32_t</span> signed_result = *signed_arg1 + signed_arg2<span class="Delimiter">;</span> +<span id="L105" class="LineNr"> 105 </span> SF = <span class="Delimiter">(</span>signed_result < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L106" class="LineNr"> 106 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>signed_result == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L107" class="LineNr"> 107 </span> <span class="Normal">int64_t</span> signed_full_result = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">)</span> + signed_arg2<span class="Delimiter">;</span> +<span id="L108" class="LineNr"> 108 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>signed_result != signed_full_result<span class="Delimiter">);</span> +<span id="L109" class="LineNr"> 109 </span> <span class="Comment">// set CF</span> +<span id="L110" class="LineNr"> 110 </span> <span class="Normal">uint32_t</span> unsigned_arg1 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">);</span> +<span id="L111" class="LineNr"> 111 </span> <span class="Normal">uint32_t</span> unsigned_arg2 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>signed_arg2<span class="Delimiter">);</span> +<span id="L112" class="LineNr"> 112 </span> <span class="Normal">uint32_t</span> unsigned_result = unsigned_arg1 + unsigned_arg2<span class="Delimiter">;</span> +<span id="L113" class="LineNr"> 113 </span> <span class="Normal">uint64_t</span> unsigned_full_result = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>unsigned_arg1<span class="Delimiter">)</span> + unsigned_arg2<span class="Delimiter">;</span> +<span id="L114" class="LineNr"> 114 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>unsigned_result != unsigned_full_result<span class="Delimiter">);</span> +<span id="L115" class="LineNr"> 115 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L116" class="LineNr"> 116 </span> *signed_arg1 = signed_result<span class="Delimiter">;</span> +<span id="L117" class="LineNr"> 117 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *signed_arg1 << end<span class="Delimiter">();</span> +<span id="L118" class="LineNr"> 118 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L119" class="LineNr"> 119 </span> <span class="Delimiter">}</span> +<span id="L120" class="LineNr"> 120 </span> <span class="Comment">// End Op 81 Subops</span> +<span id="L121" class="LineNr"> 121 </span> <span class="Normal">default</span>: +<span id="L122" class="LineNr"> 122 </span> cerr << <span class="Constant">"unrecognized subop for opcode 81: "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L123" class="LineNr"> 123 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L124" class="LineNr"> 124 </span> <span class="Delimiter">}</span> +<span id="L125" class="LineNr"> 125 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L126" class="LineNr"> 126 </span><span class="Delimiter">}</span> +<span id="L127" class="LineNr"> 127 </span> +<span id="L128" class="LineNr"> 128 </span><span class="Delimiter">:(code)</span> +<span id="L129" class="LineNr"> 129 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L129'>test_add_imm32_to_r32_signed_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L130" class="LineNr"> 130 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MAX</span><span class="Delimiter">;</span> +<span id="L131" class="LineNr"> 131 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L132" class="LineNr"> 132 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L133" class="LineNr"> 133 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L134" class="LineNr"> 134 </span> <span class="Constant">" 81 c3 01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add 1 to EBX</span> +<span id="L135" class="LineNr"> 135 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (subop add) 011 (dest EBX)</span> +<span id="L136" class="LineNr"> 136 </span> <span class="Delimiter">);</span> +<span id="L137" class="LineNr"> 137 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L138" class="LineNr"> 138 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L139" class="LineNr"> 139 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L140" class="LineNr"> 140 </span> <span class="Constant">"run: imm32 is 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L141" class="LineNr"> 141 </span> <span class="Constant">"run: subop add</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L142" class="LineNr"> 142 </span> <span class="Constant">"run: SF=1; ZF=0; CF=0; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L143" class="LineNr"> 143 </span> <span class="Constant">"run: storing 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L144" class="LineNr"> 144 </span> <span class="Delimiter">);</span> +<span id="L145" class="LineNr"> 145 </span><span class="Delimiter">}</span> +<span id="L146" class="LineNr"> 146 </span> +<span id="L147" class="LineNr"> 147 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L147'>test_add_imm32_to_r32_unsigned_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L148" class="LineNr"> 148 </span> Reg[EBX]<span class="Delimiter">.</span>u = <span class="Constant">UINT32_MAX</span><span class="Delimiter">;</span> +<span id="L149" class="LineNr"> 149 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L150" class="LineNr"> 150 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L151" class="LineNr"> 151 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L152" class="LineNr"> 152 </span> <span class="Constant">" 81 c3 01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add 1 to EBX</span> +<span id="L153" class="LineNr"> 153 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (subop add) 011 (dest EBX)</span> +<span id="L154" class="LineNr"> 154 </span> <span class="Delimiter">);</span> +<span id="L155" class="LineNr"> 155 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L156" class="LineNr"> 156 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L157" class="LineNr"> 157 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L158" class="LineNr"> 158 </span> <span class="Constant">"run: imm32 is 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L159" class="LineNr"> 159 </span> <span class="Constant">"run: subop add</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L160" class="LineNr"> 160 </span> <span class="Constant">"run: SF=0; ZF=1; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L161" class="LineNr"> 161 </span> <span class="Constant">"run: storing 0x00000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L162" class="LineNr"> 162 </span> <span class="Delimiter">);</span> +<span id="L163" class="LineNr"> 163 </span><span class="Delimiter">}</span> +<span id="L164" class="LineNr"> 164 </span> +<span id="L165" class="LineNr"> 165 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L165'>test_add_imm32_to_r32_unsigned_and_signed_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L166" class="LineNr"> 166 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MIN</span><span class="Delimiter">;</span> +<span id="L167" class="LineNr"> 167 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L168" class="LineNr"> 168 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L169" class="LineNr"> 169 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L170" class="LineNr"> 170 </span> <span class="Constant">" 81 c3 00 00 00 80</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add 0x80000000 to EBX</span> +<span id="L171" class="LineNr"> 171 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (subop add) 011 (dest EBX)</span> +<span id="L172" class="LineNr"> 172 </span> <span class="Delimiter">);</span> +<span id="L173" class="LineNr"> 173 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L174" class="LineNr"> 174 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L175" class="LineNr"> 175 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L176" class="LineNr"> 176 </span> <span class="Constant">"run: imm32 is 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L177" class="LineNr"> 177 </span> <span class="Constant">"run: subop add</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L178" class="LineNr"> 178 </span> <span class="Constant">"run: SF=0; ZF=1; CF=1; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L179" class="LineNr"> 179 </span> <span class="Constant">"run: storing 0x00000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L180" class="LineNr"> 180 </span> <span class="Delimiter">);</span> +<span id="L181" class="LineNr"> 181 </span><span class="Delimiter">}</span> +<span id="L182" class="LineNr"> 182 </span> +<span id="L183" class="LineNr"> 183 </span><span class="Comment">//:</span> +<span id="L184" class="LineNr"> 184 </span> +<span id="L185" class="LineNr"> 185 </span><span class="Delimiter">:(code)</span> +<span id="L186" class="LineNr"> 186 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L186'>test_add_imm32_to_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L187" class="LineNr"> 187 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L188" class="LineNr"> 188 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L189" class="LineNr"> 189 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L190" class="LineNr"> 190 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L191" class="LineNr"> 191 </span> <span class="Constant">" 81 03 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add 0x0d0c0b0a to *EBX</span> +<span id="L192" class="LineNr"> 192 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 000 (subop add) 011 (dest EBX)</span> +<span id="L193" class="LineNr"> 193 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L194" class="LineNr"> 194 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L195" class="LineNr"> 195 </span> <span class="Delimiter">);</span> +<span id="L196" class="LineNr"> 196 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L197" class="LineNr"> 197 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L198" class="LineNr"> 198 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L199" class="LineNr"> 199 </span> <span class="Constant">"run: imm32 is 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L200" class="LineNr"> 200 </span> <span class="Constant">"run: subop add</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L201" class="LineNr"> 201 </span> <span class="Constant">"run: storing 0x0d0c0b0b</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L202" class="LineNr"> 202 </span> <span class="Delimiter">);</span> +<span id="L203" class="LineNr"> 203 </span><span class="Delimiter">}</span> +<span id="L204" class="LineNr"> 204 </span> +<span id="L205" class="LineNr"> 205 </span><span class="Comment">//:: subtract</span> +<span id="L206" class="LineNr"> 206 </span> +<span id="L207" class="LineNr"> 207 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L208" class="LineNr"> 208 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"2d"</span><span class="Delimiter">,</span> <span class="Constant">"subtract imm32 from <a href='010vm.cc.html#L10'>EAX</a> (sub)"</span><span class="Delimiter">);</span> +<span id="L209" class="LineNr"> 209 </span> +<span id="L210" class="LineNr"> 210 </span><span class="Delimiter">:(code)</span> +<span id="L211" class="LineNr"> 211 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L211'>test_subtract_imm32_from_EAX</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L212" class="LineNr"> 212 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x0d0c0baa</span><span class="Delimiter">;</span> +<span id="L213" class="LineNr"> 213 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L214" class="LineNr"> 214 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L215" class="LineNr"> 215 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L216" class="LineNr"> 216 </span> <span class="Constant">" 2d 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract 0x0d0c0b0a from EAX</span> +<span id="L217" class="LineNr"> 217 </span> <span class="Delimiter">);</span> +<span id="L218" class="LineNr"> 218 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L219" class="LineNr"> 219 </span> <span class="Constant">"run: subtract imm32 0x0d0c0b0a from <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L220" class="LineNr"> 220 </span> <span class="Constant">"run: storing 0x000000a0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L221" class="LineNr"> 221 </span> <span class="Delimiter">);</span> +<span id="L222" class="LineNr"> 222 </span><span class="Delimiter">}</span> +<span id="L223" class="LineNr"> 223 </span> +<span id="L224" class="LineNr"> 224 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L225" class="LineNr"> 225 </span><span class="Normal">case</span> <span class="Constant">0x2d</span>: <span class="Delimiter">{</span> <span class="Comment">// subtract imm32 from EAX</span> +<span id="L226" class="LineNr"> 226 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> signed_arg2 = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L227" class="LineNr"> 227 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subtract imm32 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << signed_arg2 << <span class="Constant">" from EAX"</span> << end<span class="Delimiter">();</span> +<span id="L228" class="LineNr"> 228 </span> <span class="Normal">int32_t</span> signed_result = Reg[EAX]<span class="Delimiter">.</span>i - signed_arg2<span class="Delimiter">;</span> +<span id="L229" class="LineNr"> 229 </span> SF = <span class="Delimiter">(</span>signed_result < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L230" class="LineNr"> 230 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>signed_result == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L231" class="LineNr"> 231 </span> <span class="Normal">int64_t</span> signed_full_result = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">)</span> - signed_arg2<span class="Delimiter">;</span> +<span id="L232" class="LineNr"> 232 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>signed_result != signed_full_result<span class="Delimiter">);</span> +<span id="L233" class="LineNr"> 233 </span> <span class="Comment">// set CF</span> +<span id="L234" class="LineNr"> 234 </span> <span class="Normal">uint32_t</span> unsigned_arg2 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>signed_arg2<span class="Delimiter">);</span> +<span id="L235" class="LineNr"> 235 </span> <span class="Normal">uint32_t</span> unsigned_result = Reg[EAX]<span class="Delimiter">.</span>u - unsigned_arg2<span class="Delimiter">;</span> +<span id="L236" class="LineNr"> 236 </span> <span class="Normal">uint64_t</span> unsigned_full_result = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> - unsigned_arg2<span class="Delimiter">;</span> +<span id="L237" class="LineNr"> 237 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>unsigned_result != unsigned_full_result<span class="Delimiter">);</span> +<span id="L238" class="LineNr"> 238 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L239" class="LineNr"> 239 </span> Reg[EAX]<span class="Delimiter">.</span>i = signed_result<span class="Delimiter">;</span> +<span id="L240" class="LineNr"> 240 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[EAX]<span class="Delimiter">.</span>i << end<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="L243" class="LineNr"> 243 </span> +<span id="L244" class="LineNr"> 244 </span><span class="Delimiter">:(code)</span> +<span id="L245" class="LineNr"> 245 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L245'>test_subtract_imm32_from_EAX_signed_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L246" class="LineNr"> 246 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MIN</span><span class="Delimiter">;</span> +<span id="L247" class="LineNr"> 247 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L248" class="LineNr"> 248 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L249" class="LineNr"> 249 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L250" class="LineNr"> 250 </span> <span class="Constant">" 2d 01 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract 1 from EAX</span> +<span id="L251" class="LineNr"> 251 </span> <span class="Delimiter">);</span> +<span id="L252" class="LineNr"> 252 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L253" class="LineNr"> 253 </span> <span class="Constant">"run: subtract imm32 0x00000001 from <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L254" class="LineNr"> 254 </span> <span class="Constant">"run: SF=0; ZF=0; CF=0; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L255" class="LineNr"> 255 </span> <span class="Constant">"run: storing 0x7fffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// INT32_MAX</span> +<span id="L256" class="LineNr"> 256 </span> <span class="Delimiter">);</span> +<span id="L257" class="LineNr"> 257 </span><span class="Delimiter">}</span> +<span id="L258" class="LineNr"> 258 </span> +<span id="L259" class="LineNr"> 259 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L259'>test_subtract_imm32_from_EAX_unsigned_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L260" class="LineNr"> 260 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L261" class="LineNr"> 261 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L262" class="LineNr"> 262 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L263" class="LineNr"> 263 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L264" class="LineNr"> 264 </span> <span class="Constant">" 2d 01 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract 1 from EAX</span> +<span id="L265" class="LineNr"> 265 </span> <span class="Delimiter">);</span> +<span id="L266" class="LineNr"> 266 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L267" class="LineNr"> 267 </span> <span class="Constant">"run: subtract imm32 0x00000001 from <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L268" class="LineNr"> 268 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L269" class="LineNr"> 269 </span> <span class="Constant">"run: storing 0xffffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L270" class="LineNr"> 270 </span> <span class="Delimiter">);</span> +<span id="L271" class="LineNr"> 271 </span><span class="Delimiter">}</span> +<span id="L272" class="LineNr"> 272 </span> +<span id="L273" class="LineNr"> 273 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L273'>test_subtract_imm32_from_EAX_signed_and_unsigned_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L274" class="LineNr"> 274 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L275" class="LineNr"> 275 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L276" class="LineNr"> 276 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L277" class="LineNr"> 277 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L278" class="LineNr"> 278 </span> <span class="Constant">" 2d 00 00 00 80 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract INT32_MIN from EAX</span> +<span id="L279" class="LineNr"> 279 </span> <span class="Delimiter">);</span> +<span id="L280" class="LineNr"> 280 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L281" class="LineNr"> 281 </span> <span class="Constant">"run: subtract imm32 0x80000000 from <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L282" class="LineNr"> 282 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L283" class="LineNr"> 283 </span> <span class="Constant">"run: storing 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L284" class="LineNr"> 284 </span> <span class="Delimiter">);</span> +<span id="L285" class="LineNr"> 285 </span><span class="Delimiter">}</span> +<span id="L286" class="LineNr"> 286 </span> +<span id="L287" class="LineNr"> 287 </span><span class="Comment">//:</span> +<span id="L288" class="LineNr"> 288 </span> +<span id="L289" class="LineNr"> 289 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L289'>test_subtract_imm32_from_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L290" class="LineNr"> 290 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L291" class="LineNr"> 291 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L292" class="LineNr"> 292 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L293" class="LineNr"> 293 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L294" class="LineNr"> 294 </span> <span class="Constant">" 81 2b 01 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract 1 from *EBX</span> +<span id="L295" class="LineNr"> 295 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 101 (subop subtract) 011 (dest EBX)</span> +<span id="L296" class="LineNr"> 296 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L297" class="LineNr"> 297 </span> <span class="Constant">"0a 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0xa</span> +<span id="L298" class="LineNr"> 298 </span> <span class="Delimiter">);</span> +<span id="L299" class="LineNr"> 299 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L300" class="LineNr"> 300 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L301" class="LineNr"> 301 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L302" class="LineNr"> 302 </span> <span class="Constant">"run: imm32 is 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L303" class="LineNr"> 303 </span> <span class="Constant">"run: subop subtract</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L304" class="LineNr"> 304 </span> <span class="Constant">"run: storing 0x00000009</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L305" class="LineNr"> 305 </span> <span class="Delimiter">);</span> +<span id="L306" class="LineNr"> 306 </span><span class="Delimiter">}</span> +<span id="L307" class="LineNr"> 307 </span> +<span id="L308" class="LineNr"> 308 </span><span class="Delimiter">:(before "End Op 81 Subops")</span> +<span id="L309" class="LineNr"> 309 </span><span class="Normal">case</span> <span class="Constant">5</span>: <span class="Delimiter">{</span> +<span id="L310" class="LineNr"> 310 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop subtract"</span> << end<span class="Delimiter">();</span> +<span id="L311" class="LineNr"> 311 </span> <span class="Normal">int32_t</span> signed_result = *signed_arg1 - signed_arg2<span class="Delimiter">;</span> +<span id="L312" class="LineNr"> 312 </span> SF = <span class="Delimiter">(</span>signed_result < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L313" class="LineNr"> 313 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>signed_result == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L314" class="LineNr"> 314 </span> <span class="Normal">int64_t</span> signed_full_result = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">)</span> - signed_arg2<span class="Delimiter">;</span> +<span id="L315" class="LineNr"> 315 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>signed_result != signed_full_result<span class="Delimiter">);</span> +<span id="L316" class="LineNr"> 316 </span> <span class="Comment">// set CF</span> +<span id="L317" class="LineNr"> 317 </span> <span class="Normal">uint32_t</span> unsigned_arg1 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">);</span> +<span id="L318" class="LineNr"> 318 </span> <span class="Normal">uint32_t</span> unsigned_arg2 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>signed_arg2<span class="Delimiter">);</span> +<span id="L319" class="LineNr"> 319 </span> <span class="Normal">uint32_t</span> unsigned_result = unsigned_arg1 - unsigned_arg2<span class="Delimiter">;</span> +<span id="L320" class="LineNr"> 320 </span> <span class="Normal">uint64_t</span> unsigned_full_result = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>unsigned_arg1<span class="Delimiter">)</span> - unsigned_arg2<span class="Delimiter">;</span> +<span id="L321" class="LineNr"> 321 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>unsigned_result != unsigned_full_result<span class="Delimiter">);</span> +<span id="L322" class="LineNr"> 322 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L323" class="LineNr"> 323 </span> *signed_arg1 = signed_result<span class="Delimiter">;</span> +<span id="L324" class="LineNr"> 324 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *signed_arg1 << end<span class="Delimiter">();</span> +<span id="L325" class="LineNr"> 325 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L326" class="LineNr"> 326 </span><span class="Delimiter">}</span> +<span id="L327" class="LineNr"> 327 </span> +<span id="L328" class="LineNr"> 328 </span><span class="Delimiter">:(code)</span> +<span id="L329" class="LineNr"> 329 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L329'>test_subtract_imm32_from_mem_at_rm32_signed_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L330" class="LineNr"> 330 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L331" class="LineNr"> 331 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L332" class="LineNr"> 332 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L333" class="LineNr"> 333 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L334" class="LineNr"> 334 </span> <span class="Constant">" 81 2b ff ff ff 7f </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract INT32_MAX from *EBX</span> +<span id="L335" class="LineNr"> 335 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 101 (subop subtract) 011 (dest EBX)</span> +<span id="L336" class="LineNr"> 336 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L337" class="LineNr"> 337 </span> <span class="Constant">"00 00 00 80</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// INT32_MIN</span> +<span id="L338" class="LineNr"> 338 </span> <span class="Delimiter">);</span> +<span id="L339" class="LineNr"> 339 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L340" class="LineNr"> 340 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L341" class="LineNr"> 341 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L342" class="LineNr"> 342 </span> <span class="Constant">"run: effective address contains 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L343" class="LineNr"> 343 </span> <span class="Constant">"run: imm32 is 0x7fffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L344" class="LineNr"> 344 </span> <span class="Constant">"run: subop subtract</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L345" class="LineNr"> 345 </span> <span class="Constant">"run: SF=0; ZF=0; CF=0; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L346" class="LineNr"> 346 </span> <span class="Constant">"run: storing 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L347" class="LineNr"> 347 </span> <span class="Delimiter">);</span> +<span id="L348" class="LineNr"> 348 </span><span class="Delimiter">}</span> +<span id="L349" class="LineNr"> 349 </span> +<span id="L350" class="LineNr"> 350 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L350'>test_subtract_imm32_from_mem_at_rm32_unsigned_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L351" class="LineNr"> 351 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L352" class="LineNr"> 352 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L353" class="LineNr"> 353 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L354" class="LineNr"> 354 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L355" class="LineNr"> 355 </span> <span class="Constant">" 81 2b 01 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract 1 from *EBX</span> +<span id="L356" class="LineNr"> 356 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 101 (subop subtract) 011 (dest EBX)</span> +<span id="L357" class="LineNr"> 357 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L358" class="LineNr"> 358 </span> <span class="Constant">"00 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0</span> +<span id="L359" class="LineNr"> 359 </span> <span class="Delimiter">);</span> +<span id="L360" class="LineNr"> 360 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L361" class="LineNr"> 361 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L362" class="LineNr"> 362 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L363" class="LineNr"> 363 </span> <span class="Constant">"run: effective address contains 0x00000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L364" class="LineNr"> 364 </span> <span class="Constant">"run: imm32 is 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L365" class="LineNr"> 365 </span> <span class="Constant">"run: subop subtract</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L366" class="LineNr"> 366 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L367" class="LineNr"> 367 </span> <span class="Constant">"run: storing 0xffffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L368" class="LineNr"> 368 </span> <span class="Delimiter">);</span> +<span id="L369" class="LineNr"> 369 </span><span class="Delimiter">}</span> +<span id="L370" class="LineNr"> 370 </span> +<span id="L371" class="LineNr"> 371 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L371'>test_subtract_imm32_from_mem_at_rm32_signed_and_unsigned_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L372" class="LineNr"> 372 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L373" class="LineNr"> 373 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L374" class="LineNr"> 374 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L375" class="LineNr"> 375 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L376" class="LineNr"> 376 </span> <span class="Constant">" 81 2b 00 00 00 80 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract INT32_MIN from *EBX</span> +<span id="L377" class="LineNr"> 377 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 101 (subop subtract) 011 (dest EBX)</span> +<span id="L378" class="LineNr"> 378 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L379" class="LineNr"> 379 </span> <span class="Constant">"00 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0</span> +<span id="L380" class="LineNr"> 380 </span> <span class="Delimiter">);</span> +<span id="L381" class="LineNr"> 381 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L382" class="LineNr"> 382 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L383" class="LineNr"> 383 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L384" class="LineNr"> 384 </span> <span class="Constant">"run: effective address contains 0x00000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L385" class="LineNr"> 385 </span> <span class="Constant">"run: imm32 is 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L386" class="LineNr"> 386 </span> <span class="Constant">"run: subop subtract</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L387" class="LineNr"> 387 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L388" class="LineNr"> 388 </span> <span class="Constant">"run: storing 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L389" class="LineNr"> 389 </span> <span class="Delimiter">);</span> +<span id="L390" class="LineNr"> 390 </span><span class="Delimiter">}</span> +<span id="L391" class="LineNr"> 391 </span> +<span id="L392" class="LineNr"> 392 </span><span class="Comment">//:</span> +<span id="L393" class="LineNr"> 393 </span> +<span id="L394" class="LineNr"> 394 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L394'>test_subtract_imm32_from_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L395" class="LineNr"> 395 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">10</span><span class="Delimiter">;</span> +<span id="L396" class="LineNr"> 396 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L397" class="LineNr"> 397 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L398" class="LineNr"> 398 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L399" class="LineNr"> 399 </span> <span class="Constant">" 81 eb 01 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// subtract 1 from EBX</span> +<span id="L400" class="LineNr"> 400 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 101 (subop subtract) 011 (dest EBX)</span> +<span id="L401" class="LineNr"> 401 </span> <span class="Delimiter">);</span> +<span id="L402" class="LineNr"> 402 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L403" class="LineNr"> 403 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L404" class="LineNr"> 404 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L405" class="LineNr"> 405 </span> <span class="Constant">"run: imm32 is 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L406" class="LineNr"> 406 </span> <span class="Constant">"run: subop subtract</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L407" class="LineNr"> 407 </span> <span class="Constant">"run: storing 0x00000009</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L408" class="LineNr"> 408 </span> <span class="Delimiter">);</span> +<span id="L409" class="LineNr"> 409 </span><span class="Delimiter">}</span> +<span id="L410" class="LineNr"> 410 </span> +<span id="L411" class="LineNr"> 411 </span><span class="Comment">//:: shift left</span> +<span id="L412" class="LineNr"> 412 </span> +<span id="L413" class="LineNr"> 413 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L414" class="LineNr"> 414 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"c1"</span><span class="Delimiter">,</span> <span class="Constant">"shift rm32 by imm8 bits depending on subop (sal/sar/shl/shr)"</span><span class="Delimiter">);</span> +<span id="L415" class="LineNr"> 415 </span> +<span id="L416" class="LineNr"> 416 </span><span class="Delimiter">:(code)</span> +<span id="L417" class="LineNr"> 417 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L417'>test_shift_left_r32_with_imm8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L418" class="LineNr"> 418 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">13</span><span class="Delimiter">;</span> +<span id="L419" class="LineNr"> 419 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L420" class="LineNr"> 420 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L421" class="LineNr"> 421 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L422" class="LineNr"> 422 </span> <span class="Constant">" c1 e3 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX left by 1 bit</span> +<span id="L423" class="LineNr"> 423 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 100 (subop shift left) 011 (dest EBX)</span> +<span id="L424" class="LineNr"> 424 </span> <span class="Delimiter">);</span> +<span id="L425" class="LineNr"> 425 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L426" class="LineNr"> 426 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L427" class="LineNr"> 427 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L428" class="LineNr"> 428 </span> <span class="Constant">"run: subop: shift left by CL bits</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L429" class="LineNr"> 429 </span> <span class="Constant">"run: storing 0x0000001a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L430" class="LineNr"> 430 </span> <span class="Delimiter">);</span> +<span id="L431" class="LineNr"> 431 </span><span class="Delimiter">}</span> +<span id="L432" class="LineNr"> 432 </span> +<span id="L433" class="LineNr"> 433 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L434" class="LineNr"> 434 </span><span class="Normal">case</span> <span class="Constant">0xc1</span>: <span class="Delimiter">{</span> +<span id="L435" class="LineNr"> 435 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L436" class="LineNr"> 436 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"operate on r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L437" class="LineNr"> 437 </span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L438" class="LineNr"> 438 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> subop = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span class="Comment">// middle 3 'reg opcode' bits</span> +<span id="L439" class="LineNr"> 439 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>subop<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L440" class="LineNr"> 440 </span> <span class="Normal">case</span> <span class="Constant">4</span>: <span class="Delimiter">{</span> <span class="Comment">// shift left r/m32 by CL</span> +<span id="L441" class="LineNr"> 441 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop: shift left by CL bits"</span> << end<span class="Delimiter">();</span> +<span id="L442" class="LineNr"> 442 </span> <span class="Normal">uint8_t</span> count = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">()</span> & <span class="Constant">0x1f</span><span class="Delimiter">;</span> +<span id="L443" class="LineNr"> 443 </span> <span class="Comment">// OF is only defined if count is 1</span> +<span id="L444" class="LineNr"> 444 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>count == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L445" class="LineNr"> 445 </span> <span class="Normal">bool</span> msb = <span class="Delimiter">(</span>*arg1 & <span class="Constant">0x80000000</span><span class="Delimiter">)</span> >> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L446" class="LineNr"> 446 </span> <span class="Normal">bool</span> pnsb = <span class="Delimiter">(</span>*arg1 & <span class="Constant">0x40000000</span><span class="Delimiter">);</span> +<span id="L447" class="LineNr"> 447 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>msb != pnsb<span class="Delimiter">);</span> +<span id="L448" class="LineNr"> 448 </span> <span class="Delimiter">}</span> +<span id="L449" class="LineNr"> 449 </span> *arg1 = <span class="Delimiter">(</span>*arg1 << count<span class="Delimiter">);</span> +<span id="L450" class="LineNr"> 450 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>*arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L451" class="LineNr"> 451 </span> SF = <span class="Delimiter">(</span>*arg1 < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L452" class="LineNr"> 452 </span> <span class="Comment">// CF undefined</span> +<span id="L453" class="LineNr"> 453 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L454" class="LineNr"> 454 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *arg1 << end<span class="Delimiter">();</span> +<span id="L455" class="LineNr"> 455 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L456" class="LineNr"> 456 </span> <span class="Delimiter">}</span> +<span id="L457" class="LineNr"> 457 </span> <span class="Comment">// End Op c1 Subops</span> +<span id="L458" class="LineNr"> 458 </span> <span class="Normal">default</span>: +<span id="L459" class="LineNr"> 459 </span> cerr << <span class="Constant">"unrecognized subop for opcode c1: "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L460" class="LineNr"> 460 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L461" class="LineNr"> 461 </span> <span class="Delimiter">}</span> +<span id="L462" class="LineNr"> 462 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L463" class="LineNr"> 463 </span><span class="Delimiter">}</span> +<span id="L464" class="LineNr"> 464 </span> +<span id="L465" class="LineNr"> 465 </span><span class="Comment">//:: shift right arithmetic</span> +<span id="L466" class="LineNr"> 466 </span> +<span id="L467" class="LineNr"> 467 </span><span class="Delimiter">:(code)</span> +<span id="L468" class="LineNr"> 468 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L468'>test_shift_right_arithmetic_r32_with_imm8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L469" class="LineNr"> 469 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">26</span><span class="Delimiter">;</span> +<span id="L470" class="LineNr"> 470 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L471" class="LineNr"> 471 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L472" class="LineNr"> 472 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L473" class="LineNr"> 473 </span> <span class="Constant">" c1 fb 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX right by 1 bit</span> +<span id="L474" class="LineNr"> 474 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop shift right arithmetic) 011 (dest EBX)</span> +<span id="L475" class="LineNr"> 475 </span> <span class="Delimiter">);</span> +<span id="L476" class="LineNr"> 476 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L477" class="LineNr"> 477 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L478" class="LineNr"> 478 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L479" class="LineNr"> 479 </span> <span class="Constant">"run: subop: shift right by CL bits, while preserving sign</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L480" class="LineNr"> 480 </span> <span class="Constant">"run: storing 0x0000000d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L481" class="LineNr"> 481 </span> <span class="Delimiter">);</span> +<span id="L482" class="LineNr"> 482 </span><span class="Delimiter">}</span> +<span id="L483" class="LineNr"> 483 </span> +<span id="L484" class="LineNr"> 484 </span><span class="Delimiter">:(before "End Op c1 Subops")</span> +<span id="L485" class="LineNr"> 485 </span><span class="Normal">case</span> <span class="Constant">7</span>: <span class="Delimiter">{</span> <span class="Comment">// shift right r/m32 by CL, preserving sign</span> +<span id="L486" class="LineNr"> 486 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop: shift right by CL bits, while preserving sign"</span> << end<span class="Delimiter">();</span> +<span id="L487" class="LineNr"> 487 </span> <span class="Normal">uint8_t</span> count = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">()</span> & <span class="Constant">0x1f</span><span class="Delimiter">;</span> +<span id="L488" class="LineNr"> 488 </span> <span class="Normal">int32_t</span> result = <span class="Delimiter">(</span>*arg1 >> count<span class="Delimiter">);</span> +<span id="L489" class="LineNr"> 489 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>*arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L490" class="LineNr"> 490 </span> SF = <span class="Delimiter">(</span>*arg1 < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L491" class="LineNr"> 491 </span> <span class="Comment">// OF is only defined if count is 1</span> +<span id="L492" class="LineNr"> 492 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>count == <span class="Constant">1</span><span class="Delimiter">)</span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L493" class="LineNr"> 493 </span> <span class="Comment">// CF</span> +<span id="L494" class="LineNr"> 494 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">((</span>*arg1 >> <span class="Delimiter">(</span>count-<span class="Constant">1</span><span class="Delimiter">))</span> & <span class="Constant">0x1</span><span class="Delimiter">);</span> +<span id="L495" class="LineNr"> 495 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L496" class="LineNr"> 496 </span> *arg1 = result<span class="Delimiter">;</span> +<span id="L497" class="LineNr"> 497 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *arg1 << end<span class="Delimiter">();</span> +<span id="L498" class="LineNr"> 498 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L499" class="LineNr"> 499 </span><span class="Delimiter">}</span> +<span id="L500" class="LineNr"> 500 </span> +<span id="L501" class="LineNr"> 501 </span><span class="Delimiter">:(code)</span> +<span id="L502" class="LineNr"> 502 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L502'>test_shift_right_arithmetic_odd_r32_with_imm8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L503" class="LineNr"> 503 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">27</span><span class="Delimiter">;</span> +<span id="L504" class="LineNr"> 504 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L505" class="LineNr"> 505 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L506" class="LineNr"> 506 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L507" class="LineNr"> 507 </span> <span class="Constant">" c1 fb 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX right by 1 bit</span> +<span id="L508" class="LineNr"> 508 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop shift right arithmetic) 011 (dest EBX)</span> +<span id="L509" class="LineNr"> 509 </span> <span class="Delimiter">);</span> +<span id="L510" class="LineNr"> 510 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L511" class="LineNr"> 511 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L512" class="LineNr"> 512 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L513" class="LineNr"> 513 </span> <span class="Constant">"run: subop: shift right by CL bits, while preserving sign</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L514" class="LineNr"> 514 </span> <span class="Comment">// result: 13</span> +<span id="L515" class="LineNr"> 515 </span> <span class="Constant">"run: storing 0x0000000d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L516" class="LineNr"> 516 </span> <span class="Delimiter">);</span> +<span id="L517" class="LineNr"> 517 </span><span class="Delimiter">}</span> +<span id="L518" class="LineNr"> 518 </span> +<span id="L519" class="LineNr"> 519 </span><span class="Delimiter">:(code)</span> +<span id="L520" class="LineNr"> 520 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L520'>test_shift_right_arithmetic_negative_r32_with_imm8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L521" class="LineNr"> 521 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xfffffffd</span><span class="Delimiter">;</span> <span class="Comment">// -3</span> +<span id="L522" class="LineNr"> 522 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L523" class="LineNr"> 523 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L524" class="LineNr"> 524 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L525" class="LineNr"> 525 </span> <span class="Constant">" c1 fb 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX right by 1 bit, while preserving sign</span> +<span id="L526" class="LineNr"> 526 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop shift right arithmetic) 011 (dest EBX)</span> +<span id="L527" class="LineNr"> 527 </span> <span class="Delimiter">);</span> +<span id="L528" class="LineNr"> 528 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L529" class="LineNr"> 529 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L530" class="LineNr"> 530 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L531" class="LineNr"> 531 </span> <span class="Constant">"run: subop: shift right by CL bits, while preserving sign</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L532" class="LineNr"> 532 </span> <span class="Comment">// result: -2</span> +<span id="L533" class="LineNr"> 533 </span> <span class="Constant">"run: storing 0xfffffffe</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L534" class="LineNr"> 534 </span> <span class="Delimiter">);</span> +<span id="L535" class="LineNr"> 535 </span><span class="Delimiter">}</span> +<span id="L536" class="LineNr"> 536 </span> +<span id="L537" class="LineNr"> 537 </span><span class="Comment">//:: shift right logical</span> +<span id="L538" class="LineNr"> 538 </span> +<span id="L539" class="LineNr"> 539 </span><span class="Delimiter">:(code)</span> +<span id="L540" class="LineNr"> 540 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L540'>test_shift_right_logical_r32_with_imm8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L541" class="LineNr"> 541 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">26</span><span class="Delimiter">;</span> +<span id="L542" class="LineNr"> 542 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L543" class="LineNr"> 543 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L544" class="LineNr"> 544 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L545" class="LineNr"> 545 </span> <span class="Constant">" c1 eb 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX right by 1 bit, while padding zeroes</span> +<span id="L546" class="LineNr"> 546 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 101 (subop shift right logical) 011 (dest EBX)</span> +<span id="L547" class="LineNr"> 547 </span> <span class="Delimiter">);</span> +<span id="L548" class="LineNr"> 548 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L549" class="LineNr"> 549 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L550" class="LineNr"> 550 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L551" class="LineNr"> 551 </span> <span class="Constant">"run: subop: shift right by CL bits, while padding zeroes</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L552" class="LineNr"> 552 </span> <span class="Constant">"run: storing 0x0000000d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L553" class="LineNr"> 553 </span> <span class="Delimiter">);</span> +<span id="L554" class="LineNr"> 554 </span><span class="Delimiter">}</span> +<span id="L555" class="LineNr"> 555 </span> +<span id="L556" class="LineNr"> 556 </span><span class="Delimiter">:(before "End Op c1 Subops")</span> +<span id="L557" class="LineNr"> 557 </span><span class="Normal">case</span> <span class="Constant">5</span>: <span class="Delimiter">{</span> <span class="Comment">// shift right r/m32 by CL, preserving sign</span> +<span id="L558" class="LineNr"> 558 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop: shift right by CL bits, while padding zeroes"</span> << end<span class="Delimiter">();</span> +<span id="L559" class="LineNr"> 559 </span> <span class="Normal">uint8_t</span> count = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">()</span> & <span class="Constant">0x1f</span><span class="Delimiter">;</span> +<span id="L560" class="LineNr"> 560 </span> <span class="Comment">// OF is only defined if count is 1</span> +<span id="L561" class="LineNr"> 561 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>count == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L562" class="LineNr"> 562 </span> <span class="Normal">bool</span> msb = <span class="Delimiter">(</span>*arg1 & <span class="Constant">0x80000000</span><span class="Delimiter">)</span> >> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L563" class="LineNr"> 563 </span> <span class="Normal">bool</span> pnsb = <span class="Delimiter">(</span>*arg1 & <span class="Constant">0x40000000</span><span class="Delimiter">);</span> +<span id="L564" class="LineNr"> 564 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>msb != pnsb<span class="Delimiter">);</span> +<span id="L565" class="LineNr"> 565 </span> <span class="Delimiter">}</span> +<span id="L566" class="LineNr"> 566 </span> <span class="Normal">uint32_t</span>* uarg1 = <span class="Normal">reinterpret_cast</span><<span class="Normal">uint32_t</span>*><span class="Delimiter">(</span>arg1<span class="Delimiter">);</span> +<span id="L567" class="LineNr"> 567 </span> *uarg1 = <span class="Delimiter">(</span>*uarg1 >> count<span class="Delimiter">);</span> +<span id="L568" class="LineNr"> 568 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>*uarg1 == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L569" class="LineNr"> 569 </span> <span class="Comment">// result is always positive by definition</span> +<span id="L570" class="LineNr"> 570 </span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L571" class="LineNr"> 571 </span> <span class="Comment">// CF undefined</span> +<span id="L572" class="LineNr"> 572 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L573" class="LineNr"> 573 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *arg1 << end<span class="Delimiter">();</span> +<span id="L574" class="LineNr"> 574 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L575" class="LineNr"> 575 </span><span class="Delimiter">}</span> +<span id="L576" class="LineNr"> 576 </span> +<span id="L577" class="LineNr"> 577 </span><span class="Delimiter">:(code)</span> +<span id="L578" class="LineNr"> 578 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L578'>test_shift_right_logical_odd_r32_with_imm8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L579" class="LineNr"> 579 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">27</span><span class="Delimiter">;</span> +<span id="L580" class="LineNr"> 580 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L581" class="LineNr"> 581 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L582" class="LineNr"> 582 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L583" class="LineNr"> 583 </span> <span class="Constant">" c1 eb 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX right by 1 bit, while padding zeroes</span> +<span id="L584" class="LineNr"> 584 </span> <span class="Delimiter">);</span> +<span id="L585" class="LineNr"> 585 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L586" class="LineNr"> 586 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L587" class="LineNr"> 587 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L588" class="LineNr"> 588 </span> <span class="Constant">"run: subop: shift right by CL bits, while padding zeroes</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L589" class="LineNr"> 589 </span> <span class="Comment">// result: 13</span> +<span id="L590" class="LineNr"> 590 </span> <span class="Constant">"run: storing 0x0000000d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L591" class="LineNr"> 591 </span> <span class="Delimiter">);</span> +<span id="L592" class="LineNr"> 592 </span><span class="Delimiter">}</span> +<span id="L593" class="LineNr"> 593 </span> +<span id="L594" class="LineNr"> 594 </span><span class="Delimiter">:(code)</span> +<span id="L595" class="LineNr"> 595 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L595'>test_shift_right_logical_negative_r32_with_imm8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L596" class="LineNr"> 596 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xfffffffd</span><span class="Delimiter">;</span> +<span id="L597" class="LineNr"> 597 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L598" class="LineNr"> 598 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L599" class="LineNr"> 599 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L600" class="LineNr"> 600 </span> <span class="Constant">" c1 eb 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// shift EBX right by 1 bit, while padding zeroes</span> +<span id="L601" class="LineNr"> 601 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 101 (subop shift right logical) 011 (dest EBX)</span> +<span id="L602" class="LineNr"> 602 </span> <span class="Delimiter">);</span> +<span id="L603" class="LineNr"> 603 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L604" class="LineNr"> 604 </span> <span class="Constant">"run: operate on r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L605" class="LineNr"> 605 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L606" class="LineNr"> 606 </span> <span class="Constant">"run: subop: shift right by CL bits, while padding zeroes</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L607" class="LineNr"> 607 </span> <span class="Constant">"run: storing 0x7ffffffe</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L608" class="LineNr"> 608 </span> <span class="Delimiter">);</span> +<span id="L609" class="LineNr"> 609 </span><span class="Delimiter">}</span> +<span id="L610" class="LineNr"> 610 </span> +<span id="L611" class="LineNr"> 611 </span><span class="Comment">//:: and</span> +<span id="L612" class="LineNr"> 612 </span> +<span id="L613" class="LineNr"> 613 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L614" class="LineNr"> 614 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"25"</span><span class="Delimiter">,</span> <span class="Constant">"EAX = bitwise AND of imm32 with <a href='010vm.cc.html#L10'>EAX</a> (and)"</span><span class="Delimiter">);</span> +<span id="L615" class="LineNr"> 615 </span> +<span id="L616" class="LineNr"> 616 </span><span class="Delimiter">:(code)</span> +<span id="L617" class="LineNr"> 617 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L617'>test_and_EAX_with_imm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L618" class="LineNr"> 618 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0xff</span><span class="Delimiter">;</span> +<span id="L619" class="LineNr"> 619 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L620" class="LineNr"> 620 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L621" class="LineNr"> 621 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L622" class="LineNr"> 622 </span> <span class="Constant">" 25 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// and 0x0d0c0b0a with EAX</span> +<span id="L623" class="LineNr"> 623 </span> <span class="Delimiter">);</span> +<span id="L624" class="LineNr"> 624 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L625" class="LineNr"> 625 </span> <span class="Constant">"run: and imm32 0x0d0c0b0a with <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L626" class="LineNr"> 626 </span> <span class="Constant">"run: storing 0x0000000a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L627" class="LineNr"> 627 </span> <span class="Delimiter">);</span> +<span id="L628" class="LineNr"> 628 </span><span class="Delimiter">}</span> +<span id="L629" class="LineNr"> 629 </span> +<span id="L630" class="LineNr"> 630 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L631" class="LineNr"> 631 </span><span class="Normal">case</span> <span class="Constant">0x25</span>: <span class="Delimiter">{</span> <span class="Comment">// and imm32 with EAX</span> +<span id="L632" class="LineNr"> 632 </span> <span class="Comment">// bitwise ops technically operate on unsigned numbers, but it makes no</span> +<span id="L633" class="LineNr"> 633 </span> <span class="Comment">// difference</span> +<span id="L634" class="LineNr"> 634 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> signed_arg2 = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L635" class="LineNr"> 635 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"and imm32 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << signed_arg2 << <span class="Constant">" with EAX"</span> << end<span class="Delimiter">();</span> +<span id="L636" class="LineNr"> 636 </span> Reg[EAX]<span class="Delimiter">.</span>i &= signed_arg2<span class="Delimiter">;</span> +<span id="L637" class="LineNr"> 637 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L638" class="LineNr"> 638 </span> SF = <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L639" class="LineNr"> 639 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L640" class="LineNr"> 640 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L641" class="LineNr"> 641 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L642" class="LineNr"> 642 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L643" class="LineNr"> 643 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L644" class="LineNr"> 644 </span><span class="Delimiter">}</span> +<span id="L645" class="LineNr"> 645 </span> +<span id="L646" class="LineNr"> 646 </span><span class="Comment">//:</span> +<span id="L647" class="LineNr"> 647 </span> +<span id="L648" class="LineNr"> 648 </span><span class="Delimiter">:(code)</span> +<span id="L649" class="LineNr"> 649 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L649'>test_and_imm32_with_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L650" class="LineNr"> 650 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L651" class="LineNr"> 651 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L652" class="LineNr"> 652 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L653" class="LineNr"> 653 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L654" class="LineNr"> 654 </span> <span class="Constant">" 81 23 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// and 0x0d0c0b0a with *EBX</span> +<span id="L655" class="LineNr"> 655 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 100 (subop and) 011 (dest EBX)</span> +<span id="L656" class="LineNr"> 656 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L657" class="LineNr"> 657 </span> <span class="Constant">"ff 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0xff</span> +<span id="L658" class="LineNr"> 658 </span> <span class="Delimiter">);</span> +<span id="L659" class="LineNr"> 659 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L660" class="LineNr"> 660 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L661" class="LineNr"> 661 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L662" class="LineNr"> 662 </span> <span class="Constant">"run: imm32 is 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L663" class="LineNr"> 663 </span> <span class="Constant">"run: subop and</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L664" class="LineNr"> 664 </span> <span class="Constant">"run: storing 0x0000000a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L665" class="LineNr"> 665 </span> <span class="Delimiter">);</span> +<span id="L666" class="LineNr"> 666 </span><span class="Delimiter">}</span> +<span id="L667" class="LineNr"> 667 </span> +<span id="L668" class="LineNr"> 668 </span><span class="Delimiter">:(before "End Op 81 Subops")</span> +<span id="L669" class="LineNr"> 669 </span><span class="Normal">case</span> <span class="Constant">4</span>: <span class="Delimiter">{</span> +<span id="L670" class="LineNr"> 670 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop and"</span> << end<span class="Delimiter">();</span> +<span id="L671" class="LineNr"> 671 </span> <span class="Comment">// bitwise ops technically operate on unsigned numbers, but it makes no</span> +<span id="L672" class="LineNr"> 672 </span> <span class="Comment">// difference</span> +<span id="L673" class="LineNr"> 673 </span> *signed_arg1 &= signed_arg2<span class="Delimiter">;</span> +<span id="L674" class="LineNr"> 674 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *signed_arg1 << end<span class="Delimiter">();</span> +<span id="L675" class="LineNr"> 675 </span> SF = <span class="Delimiter">(</span>*signed_arg1 >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L676" class="LineNr"> 676 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>*signed_arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L677" class="LineNr"> 677 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L678" class="LineNr"> 678 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L679" class="LineNr"> 679 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L680" class="LineNr"> 680 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L681" class="LineNr"> 681 </span><span class="Delimiter">}</span> +<span id="L682" class="LineNr"> 682 </span> +<span id="L683" class="LineNr"> 683 </span><span class="Comment">//:</span> +<span id="L684" class="LineNr"> 684 </span> +<span id="L685" class="LineNr"> 685 </span><span class="Delimiter">:(code)</span> +<span id="L686" class="LineNr"> 686 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L686'>test_and_imm32_with_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L687" class="LineNr"> 687 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xff</span><span class="Delimiter">;</span> +<span id="L688" class="LineNr"> 688 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L689" class="LineNr"> 689 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L690" class="LineNr"> 690 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L691" class="LineNr"> 691 </span> <span class="Constant">" 81 e3 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// and 0x0d0c0b0a with EBX</span> +<span id="L692" class="LineNr"> 692 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 100 (subop and) 011 (dest EBX)</span> +<span id="L693" class="LineNr"> 693 </span> <span class="Delimiter">);</span> +<span id="L694" class="LineNr"> 694 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L695" class="LineNr"> 695 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L696" class="LineNr"> 696 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L697" class="LineNr"> 697 </span> <span class="Constant">"run: imm32 is 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L698" class="LineNr"> 698 </span> <span class="Constant">"run: subop and</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L699" class="LineNr"> 699 </span> <span class="Constant">"run: storing 0x0000000a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L700" class="LineNr"> 700 </span> <span class="Delimiter">);</span> +<span id="L701" class="LineNr"> 701 </span><span class="Delimiter">}</span> +<span id="L702" class="LineNr"> 702 </span> +<span id="L703" class="LineNr"> 703 </span><span class="Comment">//:: or</span> +<span id="L704" class="LineNr"> 704 </span> +<span id="L705" class="LineNr"> 705 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L706" class="LineNr"> 706 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"0d"</span><span class="Delimiter">,</span> <span class="Constant">"EAX = bitwise OR of imm32 with <a href='010vm.cc.html#L10'>EAX</a> (or)"</span><span class="Delimiter">);</span> +<span id="L707" class="LineNr"> 707 </span> +<span id="L708" class="LineNr"> 708 </span><span class="Delimiter">:(code)</span> +<span id="L709" class="LineNr"> 709 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L709'>test_or_EAX_with_imm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L710" class="LineNr"> 710 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0xd0c0b0a0</span><span class="Delimiter">;</span> +<span id="L711" class="LineNr"> 711 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L712" class="LineNr"> 712 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L713" class="LineNr"> 713 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L714" class="LineNr"> 714 </span> <span class="Constant">" 0d 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// or 0x0d0c0b0a with EAX</span> +<span id="L715" class="LineNr"> 715 </span> <span class="Delimiter">);</span> +<span id="L716" class="LineNr"> 716 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L717" class="LineNr"> 717 </span> <span class="Constant">"run: or imm32 0x0d0c0b0a with <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L718" class="LineNr"> 718 </span> <span class="Constant">"run: storing 0xddccbbaa</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L719" class="LineNr"> 719 </span> <span class="Delimiter">);</span> +<span id="L720" class="LineNr"> 720 </span><span class="Delimiter">}</span> +<span id="L721" class="LineNr"> 721 </span> +<span id="L722" class="LineNr"> 722 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L723" class="LineNr"> 723 </span><span class="Normal">case</span> <span class="Constant">0x0d</span>: <span class="Delimiter">{</span> <span class="Comment">// or imm32 with EAX</span> +<span id="L724" class="LineNr"> 724 </span> <span class="Comment">// bitwise ops technically operate on unsigned numbers, but it makes no</span> +<span id="L725" class="LineNr"> 725 </span> <span class="Comment">// difference</span> +<span id="L726" class="LineNr"> 726 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> signed_arg2 = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L727" class="LineNr"> 727 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"or imm32 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << signed_arg2 << <span class="Constant">" with EAX"</span> << end<span class="Delimiter">();</span> +<span id="L728" class="LineNr"> 728 </span> Reg[EAX]<span class="Delimiter">.</span>i |= signed_arg2<span class="Delimiter">;</span> +<span id="L729" class="LineNr"> 729 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L730" class="LineNr"> 730 </span> SF = <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L731" class="LineNr"> 731 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L732" class="LineNr"> 732 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L733" class="LineNr"> 733 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L734" class="LineNr"> 734 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L735" class="LineNr"> 735 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L736" class="LineNr"> 736 </span><span class="Delimiter">}</span> +<span id="L737" class="LineNr"> 737 </span> +<span id="L738" class="LineNr"> 738 </span><span class="Comment">//:</span> +<span id="L739" class="LineNr"> 739 </span> +<span id="L740" class="LineNr"> 740 </span><span class="Delimiter">:(code)</span> +<span id="L741" class="LineNr"> 741 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L741'>test_or_imm32_with_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L742" class="LineNr"> 742 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L743" class="LineNr"> 743 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L744" class="LineNr"> 744 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L745" class="LineNr"> 745 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L746" class="LineNr"> 746 </span> <span class="Constant">" 81 0b 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// or 0x0d0c0b0a with *EBX</span> +<span id="L747" class="LineNr"> 747 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 001 (subop or) 011 (dest EBX)</span> +<span id="L748" class="LineNr"> 748 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L749" class="LineNr"> 749 </span> <span class="Constant">"a0 b0 c0 d0</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0xd0c0b0a0</span> +<span id="L750" class="LineNr"> 750 </span> <span class="Delimiter">);</span> +<span id="L751" class="LineNr"> 751 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L752" class="LineNr"> 752 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L753" class="LineNr"> 753 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L754" class="LineNr"> 754 </span> <span class="Constant">"run: imm32 is 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L755" class="LineNr"> 755 </span> <span class="Constant">"run: subop or</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L756" class="LineNr"> 756 </span> <span class="Constant">"run: storing 0xddccbbaa</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L757" class="LineNr"> 757 </span> <span class="Delimiter">);</span> +<span id="L758" class="LineNr"> 758 </span><span class="Delimiter">}</span> +<span id="L759" class="LineNr"> 759 </span> +<span id="L760" class="LineNr"> 760 </span><span class="Delimiter">:(before "End Op 81 Subops")</span> +<span id="L761" class="LineNr"> 761 </span><span class="Normal">case</span> <span class="Constant">1</span>: <span class="Delimiter">{</span> +<span id="L762" class="LineNr"> 762 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop or"</span> << end<span class="Delimiter">();</span> +<span id="L763" class="LineNr"> 763 </span> <span class="Comment">// bitwise ops technically operate on unsigned numbers, but it makes no</span> +<span id="L764" class="LineNr"> 764 </span> <span class="Comment">// difference</span> +<span id="L765" class="LineNr"> 765 </span> *signed_arg1 |= signed_arg2<span class="Delimiter">;</span> +<span id="L766" class="LineNr"> 766 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *signed_arg1 << end<span class="Delimiter">();</span> +<span id="L767" class="LineNr"> 767 </span> SF = <span class="Delimiter">(</span>*signed_arg1 >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L768" class="LineNr"> 768 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>*signed_arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L769" class="LineNr"> 769 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L770" class="LineNr"> 770 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L771" class="LineNr"> 771 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L772" class="LineNr"> 772 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L773" class="LineNr"> 773 </span><span class="Delimiter">}</span> +<span id="L774" class="LineNr"> 774 </span> +<span id="L775" class="LineNr"> 775 </span><span class="Delimiter">:(code)</span> +<span id="L776" class="LineNr"> 776 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L776'>test_or_imm32_with_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L777" class="LineNr"> 777 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xd0c0b0a0</span><span class="Delimiter">;</span> +<span id="L778" class="LineNr"> 778 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L779" class="LineNr"> 779 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L780" class="LineNr"> 780 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L781" class="LineNr"> 781 </span> <span class="Constant">" 81 cb 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// or 0x0d0c0b0a with EBX</span> +<span id="L782" class="LineNr"> 782 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 001 (subop or) 011 (dest EBX)</span> +<span id="L783" class="LineNr"> 783 </span> <span class="Delimiter">);</span> +<span id="L784" class="LineNr"> 784 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L785" class="LineNr"> 785 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L786" class="LineNr"> 786 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L787" class="LineNr"> 787 </span> <span class="Constant">"run: imm32 is 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L788" class="LineNr"> 788 </span> <span class="Constant">"run: subop or</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L789" class="LineNr"> 789 </span> <span class="Constant">"run: storing 0xddccbbaa</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L790" class="LineNr"> 790 </span> <span class="Delimiter">);</span> +<span id="L791" class="LineNr"> 791 </span><span class="Delimiter">}</span> +<span id="L792" class="LineNr"> 792 </span> +<span id="L793" class="LineNr"> 793 </span><span class="Comment">//:: xor</span> +<span id="L794" class="LineNr"> 794 </span> +<span id="L795" class="LineNr"> 795 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L796" class="LineNr"> 796 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"35"</span><span class="Delimiter">,</span> <span class="Constant">"EAX = bitwise XOR of imm32 with <a href='010vm.cc.html#L10'>EAX</a> (xor)"</span><span class="Delimiter">);</span> +<span id="L797" class="LineNr"> 797 </span> +<span id="L798" class="LineNr"> 798 </span><span class="Delimiter">:(code)</span> +<span id="L799" class="LineNr"> 799 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L799'>test_xor_EAX_with_imm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L800" class="LineNr"> 800 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0xddccb0a0</span><span class="Delimiter">;</span> +<span id="L801" class="LineNr"> 801 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L802" class="LineNr"> 802 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L803" class="LineNr"> 803 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L804" class="LineNr"> 804 </span> <span class="Constant">" 35 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// xor 0x0d0c0b0a with EAX</span> +<span id="L805" class="LineNr"> 805 </span> <span class="Delimiter">);</span> +<span id="L806" class="LineNr"> 806 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L807" class="LineNr"> 807 </span> <span class="Constant">"run: xor imm32 0x0d0c0b0a with <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L808" class="LineNr"> 808 </span> <span class="Constant">"run: storing 0xd0c0bbaa</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L809" class="LineNr"> 809 </span> <span class="Delimiter">);</span> +<span id="L810" class="LineNr"> 810 </span><span class="Delimiter">}</span> +<span id="L811" class="LineNr"> 811 </span> +<span id="L812" class="LineNr"> 812 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L813" class="LineNr"> 813 </span><span class="Normal">case</span> <span class="Constant">0x35</span>: <span class="Delimiter">{</span> <span class="Comment">// xor imm32 with EAX</span> +<span id="L814" class="LineNr"> 814 </span> <span class="Comment">// bitwise ops technically operate on unsigned numbers, but it makes no</span> +<span id="L815" class="LineNr"> 815 </span> <span class="Comment">// difference</span> +<span id="L816" class="LineNr"> 816 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> signed_arg2 = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L817" class="LineNr"> 817 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"xor imm32 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << signed_arg2 << <span class="Constant">" with EAX"</span> << end<span class="Delimiter">();</span> +<span id="L818" class="LineNr"> 818 </span> Reg[EAX]<span class="Delimiter">.</span>i ^= signed_arg2<span class="Delimiter">;</span> +<span id="L819" class="LineNr"> 819 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L820" class="LineNr"> 820 </span> SF = <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L821" class="LineNr"> 821 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L822" class="LineNr"> 822 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L823" class="LineNr"> 823 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L824" class="LineNr"> 824 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L825" class="LineNr"> 825 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L826" class="LineNr"> 826 </span><span class="Delimiter">}</span> +<span id="L827" class="LineNr"> 827 </span> +<span id="L828" class="LineNr"> 828 </span><span class="Comment">//:</span> +<span id="L829" class="LineNr"> 829 </span> +<span id="L830" class="LineNr"> 830 </span><span class="Delimiter">:(code)</span> +<span id="L831" class="LineNr"> 831 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L831'>test_xor_imm32_with_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L832" class="LineNr"> 832 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L833" class="LineNr"> 833 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L834" class="LineNr"> 834 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L835" class="LineNr"> 835 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L836" class="LineNr"> 836 </span> <span class="Constant">" 81 33 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// xor 0x0d0c0b0a with *EBX</span> +<span id="L837" class="LineNr"> 837 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 110 (subop xor) 011 (dest EBX)</span> +<span id="L838" class="LineNr"> 838 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L839" class="LineNr"> 839 </span> <span class="Constant">"a0 b0 c0 d0</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0xd0c0b0a0</span> +<span id="L840" class="LineNr"> 840 </span> <span class="Delimiter">);</span> +<span id="L841" class="LineNr"> 841 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L842" class="LineNr"> 842 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L843" class="LineNr"> 843 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L844" class="LineNr"> 844 </span> <span class="Constant">"run: imm32 is 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L845" class="LineNr"> 845 </span> <span class="Constant">"run: subop xor</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L846" class="LineNr"> 846 </span> <span class="Constant">"run: storing 0xddccbbaa</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L847" class="LineNr"> 847 </span> <span class="Delimiter">);</span> +<span id="L848" class="LineNr"> 848 </span><span class="Delimiter">}</span> +<span id="L849" class="LineNr"> 849 </span> +<span id="L850" class="LineNr"> 850 </span><span class="Delimiter">:(before "End Op 81 Subops")</span> +<span id="L851" class="LineNr"> 851 </span><span class="Normal">case</span> <span class="Constant">6</span>: <span class="Delimiter">{</span> +<span id="L852" class="LineNr"> 852 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop xor"</span> << end<span class="Delimiter">();</span> +<span id="L853" class="LineNr"> 853 </span> <span class="Comment">// bitwise ops technically operate on unsigned numbers, but it makes no</span> +<span id="L854" class="LineNr"> 854 </span> <span class="Comment">// difference</span> +<span id="L855" class="LineNr"> 855 </span> *signed_arg1 ^= signed_arg2<span class="Delimiter">;</span> +<span id="L856" class="LineNr"> 856 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << *signed_arg1 << end<span class="Delimiter">();</span> +<span id="L857" class="LineNr"> 857 </span> SF = <span class="Delimiter">(</span>*signed_arg1 >> <span class="Constant">31</span><span class="Delimiter">);</span> +<span id="L858" class="LineNr"> 858 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>*signed_arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L859" class="LineNr"> 859 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L860" class="LineNr"> 860 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L861" class="LineNr"> 861 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L862" class="LineNr"> 862 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L863" class="LineNr"> 863 </span><span class="Delimiter">}</span> +<span id="L864" class="LineNr"> 864 </span> +<span id="L865" class="LineNr"> 865 </span><span class="Delimiter">:(code)</span> +<span id="L866" class="LineNr"> 866 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L866'>test_xor_imm32_with_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L867" class="LineNr"> 867 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xd0c0b0a0</span><span class="Delimiter">;</span> +<span id="L868" class="LineNr"> 868 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L869" class="LineNr"> 869 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L870" class="LineNr"> 870 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L871" class="LineNr"> 871 </span> <span class="Constant">" 81 f3 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// xor 0x0d0c0b0a with EBX</span> +<span id="L872" class="LineNr"> 872 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 110 (subop xor) 011 (dest EBX)</span> +<span id="L873" class="LineNr"> 873 </span> <span class="Delimiter">);</span> +<span id="L874" class="LineNr"> 874 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L875" class="LineNr"> 875 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L876" class="LineNr"> 876 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L877" class="LineNr"> 877 </span> <span class="Constant">"run: imm32 is 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L878" class="LineNr"> 878 </span> <span class="Constant">"run: subop xor</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L879" class="LineNr"> 879 </span> <span class="Constant">"run: storing 0xddccbbaa</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L880" class="LineNr"> 880 </span> <span class="Delimiter">);</span> +<span id="L881" class="LineNr"> 881 </span><span class="Delimiter">}</span> +<span id="L882" class="LineNr"> 882 </span> +<span id="L883" class="LineNr"> 883 </span><span class="Comment">//:: compare (cmp)</span> +<span id="L884" class="LineNr"> 884 </span> +<span id="L885" class="LineNr"> 885 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L886" class="LineNr"> 886 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"3d"</span><span class="Delimiter">,</span> <span class="Constant">"compare: set SF if <a href='010vm.cc.html#L10'>EAX</a> < imm32 (cmp)"</span><span class="Delimiter">);</span> +<span id="L887" class="LineNr"> 887 </span> +<span id="L888" class="LineNr"> 888 </span><span class="Delimiter">:(code)</span> +<span id="L889" class="LineNr"> 889 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L889'>test_compare_EAX_with_imm32_greater</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L890" class="LineNr"> 890 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x0d0c0b0a</span><span class="Delimiter">;</span> +<span id="L891" class="LineNr"> 891 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L892" class="LineNr"> 892 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L893" class="LineNr"> 893 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L894" class="LineNr"> 894 </span> <span class="Constant">" 3d 07 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with 0x0d0c0b07</span> +<span id="L895" class="LineNr"> 895 </span> <span class="Delimiter">);</span> +<span id="L896" class="LineNr"> 896 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L897" class="LineNr"> 897 </span> <span class="Constant">"run: compare <a href='010vm.cc.html#L10'>EAX</a> with imm32 0x0d0c0b07</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L898" class="LineNr"> 898 </span> <span class="Constant">"run: SF=0; ZF=0; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L899" class="LineNr"> 899 </span> <span class="Delimiter">);</span> +<span id="L900" class="LineNr"> 900 </span><span class="Delimiter">}</span> +<span id="L901" class="LineNr"> 901 </span> +<span id="L902" class="LineNr"> 902 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L903" class="LineNr"> 903 </span><span class="Normal">case</span> <span class="Constant">0x3d</span>: <span class="Delimiter">{</span> <span class="Comment">// compare EAX with imm32</span> +<span id="L904" class="LineNr"> 904 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> signed_arg1 = Reg[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L905" class="LineNr"> 905 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> signed_arg2 = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L906" class="LineNr"> 906 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"compare <a href='010vm.cc.html#L10'>EAX</a> with imm32 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << signed_arg2 << end<span class="Delimiter">();</span> +<span id="L907" class="LineNr"> 907 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> signed_difference = signed_arg1 - signed_arg2<span class="Delimiter">;</span> +<span id="L908" class="LineNr"> 908 </span> SF = <span class="Delimiter">(</span>signed_difference < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L909" class="LineNr"> 909 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>signed_difference == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L910" class="LineNr"> 910 </span> <span class="Normal">const</span> <span class="Normal">int64_t</span> full_signed_difference = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>signed_arg1<span class="Delimiter">)</span> - signed_arg2<span class="Delimiter">;</span> +<span id="L911" class="LineNr"> 911 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>signed_difference != full_signed_difference<span class="Delimiter">);</span> +<span id="L912" class="LineNr"> 912 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> unsigned_arg1 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>signed_arg1<span class="Delimiter">);</span> +<span id="L913" class="LineNr"> 913 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> unsigned_arg2 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>signed_arg2<span class="Delimiter">);</span> +<span id="L914" class="LineNr"> 914 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> unsigned_difference = unsigned_arg1 - unsigned_arg2<span class="Delimiter">;</span> +<span id="L915" class="LineNr"> 915 </span> <span class="Normal">const</span> <span class="Normal">uint64_t</span> full_unsigned_difference = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>unsigned_arg1<span class="Delimiter">)</span> - unsigned_arg2<span class="Delimiter">;</span> +<span id="L916" class="LineNr"> 916 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>unsigned_difference != full_unsigned_difference<span class="Delimiter">);</span> +<span id="L917" class="LineNr"> 917 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L918" class="LineNr"> 918 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L919" class="LineNr"> 919 </span><span class="Delimiter">}</span> +<span id="L920" class="LineNr"> 920 </span> +<span id="L921" class="LineNr"> 921 </span><span class="Delimiter">:(code)</span> +<span id="L922" class="LineNr"> 922 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L922'>test_compare_EAX_with_imm32_lesser_unsigned_and_signed</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L923" class="LineNr"> 923 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c07</span><span class="Delimiter">;</span> +<span id="L924" class="LineNr"> 924 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L925" class="LineNr"> 925 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L926" class="LineNr"> 926 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L927" class="LineNr"> 927 </span> <span class="Constant">" 3d 0d 0c 0b 0a </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with imm32</span> +<span id="L928" class="LineNr"> 928 </span> <span class="Delimiter">);</span> +<span id="L929" class="LineNr"> 929 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L930" class="LineNr"> 930 </span> <span class="Constant">"run: compare <a href='010vm.cc.html#L10'>EAX</a> with imm32 0x0a0b0c0d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L931" class="LineNr"> 931 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L932" class="LineNr"> 932 </span> <span class="Delimiter">);</span> +<span id="L933" class="LineNr"> 933 </span><span class="Delimiter">}</span> +<span id="L934" class="LineNr"> 934 </span> +<span id="L935" class="LineNr"> 935 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L935'>test_compare_EAX_with_imm32_lesser_unsigned_and_signed_due_to_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L936" class="LineNr"> 936 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MAX</span><span class="Delimiter">;</span> +<span id="L937" class="LineNr"> 937 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L938" class="LineNr"> 938 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L939" class="LineNr"> 939 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L940" class="LineNr"> 940 </span> <span class="Constant">" 3d 00 00 00 80</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with INT32_MIN</span> +<span id="L941" class="LineNr"> 941 </span> <span class="Delimiter">);</span> +<span id="L942" class="LineNr"> 942 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L943" class="LineNr"> 943 </span> <span class="Constant">"run: compare <a href='010vm.cc.html#L10'>EAX</a> with imm32 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L944" class="LineNr"> 944 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L945" class="LineNr"> 945 </span> <span class="Delimiter">);</span> +<span id="L946" class="LineNr"> 946 </span><span class="Delimiter">}</span> +<span id="L947" class="LineNr"> 947 </span> +<span id="L948" class="LineNr"> 948 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L948'>test_compare_EAX_with_imm32_lesser_signed</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L949" class="LineNr"> 949 </span> Reg[EAX]<span class="Delimiter">.</span>i = -<span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L950" class="LineNr"> 950 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L951" class="LineNr"> 951 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L952" class="LineNr"> 952 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L953" class="LineNr"> 953 </span> <span class="Constant">" 3d 01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with 1</span> +<span id="L954" class="LineNr"> 954 </span> <span class="Delimiter">);</span> +<span id="L955" class="LineNr"> 955 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L956" class="LineNr"> 956 </span> <span class="Constant">"run: compare <a href='010vm.cc.html#L10'>EAX</a> with imm32 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L957" class="LineNr"> 957 </span> <span class="Constant">"run: SF=1; ZF=0; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L958" class="LineNr"> 958 </span> <span class="Delimiter">);</span> +<span id="L959" class="LineNr"> 959 </span><span class="Delimiter">}</span> +<span id="L960" class="LineNr"> 960 </span> +<span id="L961" class="LineNr"> 961 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L961'>test_compare_EAX_with_imm32_lesser_unsigned</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L962" class="LineNr"> 962 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L963" class="LineNr"> 963 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L964" class="LineNr"> 964 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L965" class="LineNr"> 965 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L966" class="LineNr"> 966 </span> <span class="Constant">" 3d ff ff ff ff</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with -1</span> +<span id="L967" class="LineNr"> 967 </span> <span class="Delimiter">);</span> +<span id="L968" class="LineNr"> 968 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L969" class="LineNr"> 969 </span> <span class="Constant">"run: compare <a href='010vm.cc.html#L10'>EAX</a> with imm32 0xffffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L970" class="LineNr"> 970 </span> <span class="Constant">"run: SF=0; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L971" class="LineNr"> 971 </span> <span class="Delimiter">);</span> +<span id="L972" class="LineNr"> 972 </span><span class="Delimiter">}</span> +<span id="L973" class="LineNr"> 973 </span> +<span id="L974" class="LineNr"> 974 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L974'>test_compare_EAX_with_imm32_equal</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L975" class="LineNr"> 975 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x0d0c0b0a</span><span class="Delimiter">;</span> +<span id="L976" class="LineNr"> 976 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L977" class="LineNr"> 977 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L978" class="LineNr"> 978 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L979" class="LineNr"> 979 </span> <span class="Constant">" 3d 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare 0x0d0c0b0a with EAX</span> +<span id="L980" class="LineNr"> 980 </span> <span class="Delimiter">);</span> +<span id="L981" class="LineNr"> 981 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L982" class="LineNr"> 982 </span> <span class="Constant">"run: compare <a href='010vm.cc.html#L10'>EAX</a> with imm32 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L983" class="LineNr"> 983 </span> <span class="Constant">"run: SF=0; ZF=1; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L984" class="LineNr"> 984 </span> <span class="Delimiter">);</span> +<span id="L985" class="LineNr"> 985 </span><span class="Delimiter">}</span> +<span id="L986" class="LineNr"> 986 </span> +<span id="L987" class="LineNr"> 987 </span><span class="Comment">//:</span> +<span id="L988" class="LineNr"> 988 </span> +<span id="L989" class="LineNr"> 989 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L989'>test_compare_imm32_with_r32_greater</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L990" class="LineNr"> 990 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0d0c0b0a</span><span class="Delimiter">;</span> +<span id="L991" class="LineNr"> 991 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L992" class="LineNr"> 992 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L993" class="LineNr"> 993 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L994" class="LineNr"> 994 </span> <span class="Constant">" 81 fb 07 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare 0x0d0c0b07 with EBX</span> +<span id="L995" class="LineNr"> 995 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop compare) 011 (dest EBX)</span> +<span id="L996" class="LineNr"> 996 </span> <span class="Delimiter">);</span> +<span id="L997" class="LineNr"> 997 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L998" class="LineNr"> 998 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L999" class="LineNr"> 999 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1000" class="LineNr">1000 </span> <span class="Constant">"run: imm32 is 0x0d0c0b07</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1001" class="LineNr">1001 </span> <span class="Constant">"run: SF=0; ZF=0; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1002" class="LineNr">1002 </span> <span class="Delimiter">);</span> +<span id="L1003" class="LineNr">1003 </span><span class="Delimiter">}</span> +<span id="L1004" class="LineNr">1004 </span> +<span id="L1005" class="LineNr">1005 </span><span class="Delimiter">:(before "End Op 81 Subops")</span> +<span id="L1006" class="LineNr">1006 </span><span class="Normal">case</span> <span class="Constant">7</span>: <span class="Delimiter">{</span> +<span id="L1007" class="LineNr">1007 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop compare"</span> << end<span class="Delimiter">();</span> +<span id="L1008" class="LineNr">1008 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> tmp1 = *signed_arg1 - signed_arg2<span class="Delimiter">;</span> +<span id="L1009" class="LineNr">1009 </span> SF = <span class="Delimiter">(</span>tmp1 < <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L1010" class="LineNr">1010 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Delimiter">(</span>tmp1 == <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L1011" class="LineNr">1011 </span> <span class="Normal">const</span> <span class="Normal">int64_t</span> tmp2 = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">)</span> - signed_arg2<span class="Delimiter">;</span> +<span id="L1012" class="LineNr">1012 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>tmp1 != tmp2<span class="Delimiter">);</span> +<span id="L1013" class="LineNr">1013 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> unsigned_arg1 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">);</span> +<span id="L1014" class="LineNr">1014 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> unsigned_arg2 = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>signed_arg2<span class="Delimiter">);</span> +<span id="L1015" class="LineNr">1015 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> tmp3 = unsigned_arg1 - unsigned_arg2<span class="Delimiter">;</span> +<span id="L1016" class="LineNr">1016 </span> <span class="Normal">const</span> <span class="Normal">uint64_t</span> tmp4 = <span class="Normal">static_cast</span><<span class="Normal">uint64_t</span>><span class="Delimiter">(</span>unsigned_arg1<span class="Delimiter">)</span> - unsigned_arg2<span class="Delimiter">;</span> +<span id="L1017" class="LineNr">1017 </span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Delimiter">(</span>tmp3 != tmp4<span class="Delimiter">);</span> +<span id="L1018" class="LineNr">1018 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L1019" class="LineNr">1019 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1020" class="LineNr">1020 </span><span class="Delimiter">}</span> +<span id="L1021" class="LineNr">1021 </span> +<span id="L1022" class="LineNr">1022 </span><span class="Delimiter">:(code)</span> +<span id="L1023" class="LineNr">1023 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L1023'>test_compare_rm32_with_imm32_lesser_unsigned_and_signed</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1024" class="LineNr">1024 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x0a0b0c07</span><span class="Delimiter">;</span> +<span id="L1025" class="LineNr">1025 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1026" class="LineNr">1026 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1027" class="LineNr">1027 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1028" class="LineNr">1028 </span> <span class="Constant">" 81 f8 0d 0c 0b 0a </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with imm32</span> +<span id="L1029" class="LineNr">1029 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop compare) 000 (dest EAX)</span> +<span id="L1030" class="LineNr">1030 </span> <span class="Delimiter">);</span> +<span id="L1031" class="LineNr">1031 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1032" class="LineNr">1032 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1033" class="LineNr">1033 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1034" class="LineNr">1034 </span> <span class="Constant">"run: imm32 is 0x0a0b0c0d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1035" class="LineNr">1035 </span> <span class="Constant">"run: subop compare</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1036" class="LineNr">1036 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1037" class="LineNr">1037 </span> <span class="Delimiter">);</span> +<span id="L1038" class="LineNr">1038 </span><span class="Delimiter">}</span> +<span id="L1039" class="LineNr">1039 </span> +<span id="L1040" class="LineNr">1040 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L1040'>test_compare_rm32_with_imm32_lesser_unsigned_and_signed_due_to_overflow</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1041" class="LineNr">1041 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">INT32_MAX</span><span class="Delimiter">;</span> +<span id="L1042" class="LineNr">1042 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1043" class="LineNr">1043 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1044" class="LineNr">1044 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1045" class="LineNr">1045 </span> <span class="Constant">" 81 f8 00 00 00 80</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with INT32_MIN</span> +<span id="L1046" class="LineNr">1046 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop compare) 000 (dest EAX)</span> +<span id="L1047" class="LineNr">1047 </span> <span class="Delimiter">);</span> +<span id="L1048" class="LineNr">1048 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1049" class="LineNr">1049 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1050" class="LineNr">1050 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1051" class="LineNr">1051 </span> <span class="Constant">"run: imm32 is 0x80000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1052" class="LineNr">1052 </span> <span class="Constant">"run: subop compare</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1053" class="LineNr">1053 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1054" class="LineNr">1054 </span> <span class="Delimiter">);</span> +<span id="L1055" class="LineNr">1055 </span><span class="Delimiter">}</span> +<span id="L1056" class="LineNr">1056 </span> +<span id="L1057" class="LineNr">1057 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L1057'>test_compare_rm32_with_imm32_lesser_signed</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1058" class="LineNr">1058 </span> Reg[EAX]<span class="Delimiter">.</span>i = -<span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L1059" class="LineNr">1059 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1060" class="LineNr">1060 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1061" class="LineNr">1061 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1062" class="LineNr">1062 </span> <span class="Constant">" 81 f8 01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with 1</span> +<span id="L1063" class="LineNr">1063 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop compare) 000 (dest EAX)</span> +<span id="L1064" class="LineNr">1064 </span> <span class="Delimiter">);</span> +<span id="L1065" class="LineNr">1065 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1066" class="LineNr">1066 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1067" class="LineNr">1067 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1068" class="LineNr">1068 </span> <span class="Constant">"run: imm32 is 0x00000001</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1069" class="LineNr">1069 </span> <span class="Constant">"run: subop compare</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1070" class="LineNr">1070 </span> <span class="Constant">"run: SF=1; ZF=0; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1071" class="LineNr">1071 </span> <span class="Delimiter">);</span> +<span id="L1072" class="LineNr">1072 </span><span class="Delimiter">}</span> +<span id="L1073" class="LineNr">1073 </span> +<span id="L1074" class="LineNr">1074 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L1074'>test_compare_rm32_with_imm32_lesser_unsigned</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1075" class="LineNr">1075 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L1076" class="LineNr">1076 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1077" class="LineNr">1077 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1078" class="LineNr">1078 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1079" class="LineNr">1079 </span> <span class="Constant">" 81 f8 ff ff ff ff</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare EAX with -1</span> +<span id="L1080" class="LineNr">1080 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop compare) 000 (dest EAX)</span> +<span id="L1081" class="LineNr">1081 </span> <span class="Delimiter">);</span> +<span id="L1082" class="LineNr">1082 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1083" class="LineNr">1083 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1084" class="LineNr">1084 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1085" class="LineNr">1085 </span> <span class="Constant">"run: imm32 is 0xffffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1086" class="LineNr">1086 </span> <span class="Constant">"run: subop compare</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1087" class="LineNr">1087 </span> <span class="Constant">"run: SF=0; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1088" class="LineNr">1088 </span> <span class="Delimiter">);</span> +<span id="L1089" class="LineNr">1089 </span><span class="Delimiter">}</span> +<span id="L1090" class="LineNr">1090 </span> +<span id="L1091" class="LineNr">1091 </span><span class="Delimiter">:(code)</span> +<span id="L1092" class="LineNr">1092 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L1092'>test_compare_imm32_with_r32_equal</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1093" class="LineNr">1093 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0d0c0b0a</span><span class="Delimiter">;</span> +<span id="L1094" class="LineNr">1094 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1095" class="LineNr">1095 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1096" class="LineNr">1096 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1097" class="LineNr">1097 </span> <span class="Constant">" 81 fb 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare 0x0d0c0b0a with EBX</span> +<span id="L1098" class="LineNr">1098 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 111 (subop compare) 011 (dest EBX)</span> +<span id="L1099" class="LineNr">1099 </span> <span class="Delimiter">);</span> +<span id="L1100" class="LineNr">1100 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1101" class="LineNr">1101 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1102" class="LineNr">1102 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1103" class="LineNr">1103 </span> <span class="Constant">"run: imm32 is 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1104" class="LineNr">1104 </span> <span class="Constant">"run: SF=0; ZF=1; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1105" class="LineNr">1105 </span> <span class="Delimiter">);</span> +<span id="L1106" class="LineNr">1106 </span><span class="Delimiter">}</span> +<span id="L1107" class="LineNr">1107 </span> +<span id="L1108" class="LineNr">1108 </span><span class="Delimiter">:(code)</span> +<span id="L1109" class="LineNr">1109 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L1109'>test_compare_imm32_with_mem_at_rm32_greater</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1110" class="LineNr">1110 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L1111" class="LineNr">1111 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1112" class="LineNr">1112 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1113" class="LineNr">1113 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1114" class="LineNr">1114 </span> <span class="Constant">" 81 3b 07 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare 0x0d0c0b07 with *EBX</span> +<span id="L1115" class="LineNr">1115 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 111 (subop compare) 011 (dest EBX)</span> +<span id="L1116" class="LineNr">1116 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1117" class="LineNr">1117 </span> <span class="Constant">"0a 0b 0c 0d</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0d0c0b0a</span> +<span id="L1118" class="LineNr">1118 </span> <span class="Delimiter">);</span> +<span id="L1119" class="LineNr">1119 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1120" class="LineNr">1120 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1121" class="LineNr">1121 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1122" class="LineNr">1122 </span> <span class="Constant">"run: imm32 is 0x0d0c0b07</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1123" class="LineNr">1123 </span> <span class="Constant">"run: SF=0; ZF=0; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1124" class="LineNr">1124 </span> <span class="Delimiter">);</span> +<span id="L1125" class="LineNr">1125 </span><span class="Delimiter">}</span> +<span id="L1126" class="LineNr">1126 </span> +<span id="L1127" class="LineNr">1127 </span><span class="Delimiter">:(code)</span> +<span id="L1128" class="LineNr">1128 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L1128'>test_compare_imm32_with_mem_at_rm32_lesser</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1129" class="LineNr">1129 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L1130" class="LineNr">1130 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1131" class="LineNr">1131 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1132" class="LineNr">1132 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1133" class="LineNr">1133 </span> <span class="Constant">" 81 38 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare 0x0d0c0b0a with *EAX</span> +<span id="L1134" class="LineNr">1134 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 111 (subop compare) 000 (dest EAX)</span> +<span id="L1135" class="LineNr">1135 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1136" class="LineNr">1136 </span> <span class="Constant">"07 0b 0c 0d</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0d0c0b07</span> +<span id="L1137" class="LineNr">1137 </span> <span class="Delimiter">);</span> +<span id="L1138" class="LineNr">1138 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1139" class="LineNr">1139 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1140" class="LineNr">1140 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1141" class="LineNr">1141 </span> <span class="Constant">"run: imm32 is 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1142" class="LineNr">1142 </span> <span class="Constant">"run: SF=1; ZF=0; CF=1; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1143" class="LineNr">1143 </span> <span class="Delimiter">);</span> +<span id="L1144" class="LineNr">1144 </span><span class="Delimiter">}</span> +<span id="L1145" class="LineNr">1145 </span> +<span id="L1146" class="LineNr">1146 </span><span class="Delimiter">:(code)</span> +<span id="L1147" class="LineNr">1147 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L1147'>test_compare_imm32_with_mem_at_rm32_equal</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1148" class="LineNr">1148 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x0d0c0b0a</span><span class="Delimiter">;</span> +<span id="L1149" class="LineNr">1149 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L1150" class="LineNr">1150 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1151" class="LineNr">1151 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1152" class="LineNr">1152 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1153" class="LineNr">1153 </span> <span class="Constant">" 81 3b 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare 0x0d0c0b0a with *EBX</span> +<span id="L1154" class="LineNr">1154 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 111 (subop compare) 011 (dest EBX)</span> +<span id="L1155" class="LineNr">1155 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1156" class="LineNr">1156 </span> <span class="Constant">"0a 0b 0c 0d</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x0d0c0b0a</span> +<span id="L1157" class="LineNr">1157 </span> <span class="Delimiter">);</span> +<span id="L1158" class="LineNr">1158 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1159" class="LineNr">1159 </span> <span class="Constant">"run: combine r/m32 with imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1160" class="LineNr">1160 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1161" class="LineNr">1161 </span> <span class="Constant">"run: imm32 is 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1162" class="LineNr">1162 </span> <span class="Constant">"run: SF=0; ZF=1; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1163" class="LineNr">1163 </span> <span class="Delimiter">);</span> +<span id="L1164" class="LineNr">1164 </span><span class="Delimiter">}</span> +<span id="L1165" class="LineNr">1165 </span> +<span id="L1166" class="LineNr">1166 </span><span class="Comment">//:: copy (mov)</span> +<span id="L1167" class="LineNr">1167 </span> +<span id="L1168" class="LineNr">1168 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L1169" class="LineNr">1169 </span><span class="Comment">// b8 defined earlier to copy imm32 to EAX</span> +<span id="L1170" class="LineNr">1170 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"b9"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010vm.cc.html#L11'>ECX</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L1171" class="LineNr">1171 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"ba"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010vm.cc.html#L12'>EDX</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L1172" class="LineNr">1172 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"bb"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010vm.cc.html#L13'>EBX</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L1173" class="LineNr">1173 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"bc"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010vm.cc.html#L14'>ESP</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L1174" class="LineNr">1174 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"bd"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010vm.cc.html#L15'>EBP</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L1175" class="LineNr">1175 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"be"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010vm.cc.html#L16'>ESI</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L1176" class="LineNr">1176 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"bf"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010vm.cc.html#L17'>EDI</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L1177" class="LineNr">1177 </span> +<span id="L1178" class="LineNr">1178 </span><span class="Delimiter">:(code)</span> +<span id="L1179" class="LineNr">1179 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L1179'>test_copy_imm32_to_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1180" class="LineNr">1180 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1181" class="LineNr">1181 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1182" class="LineNr">1182 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1183" class="LineNr">1183 </span> <span class="Constant">" bb 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy 0x0d0c0b0a to EBX</span> +<span id="L1184" class="LineNr">1184 </span> <span class="Delimiter">);</span> +<span id="L1185" class="LineNr">1185 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1186" class="LineNr">1186 </span> <span class="Constant">"run: copy imm32 0x0d0c0b0a to <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1187" class="LineNr">1187 </span> <span class="Delimiter">);</span> +<span id="L1188" class="LineNr">1188 </span><span class="Delimiter">}</span> +<span id="L1189" class="LineNr">1189 </span> +<span id="L1190" class="LineNr">1190 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L1191" class="LineNr">1191 </span><span class="Normal">case</span> <span class="Constant">0xb9</span>: +<span id="L1192" class="LineNr">1192 </span><span class="Normal">case</span> <span class="Constant">0xba</span>: +<span id="L1193" class="LineNr">1193 </span><span class="Normal">case</span> <span class="Constant">0xbb</span>: +<span id="L1194" class="LineNr">1194 </span><span class="Normal">case</span> <span class="Constant">0xbc</span>: +<span id="L1195" class="LineNr">1195 </span><span class="Normal">case</span> <span class="Constant">0xbd</span>: +<span id="L1196" class="LineNr">1196 </span><span class="Normal">case</span> <span class="Constant">0xbe</span>: +<span id="L1197" class="LineNr">1197 </span><span class="Normal">case</span> <span class="Constant">0xbf</span>: <span class="Delimiter">{</span> <span class="Comment">// copy imm32 to r32</span> +<span id="L1198" class="LineNr">1198 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rdest = op & <span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L1199" class="LineNr">1199 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> src = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L1200" class="LineNr">1200 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy imm32 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << src << <span class="Constant">" to "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>rdest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L1201" class="LineNr">1201 </span> Reg[rdest]<span class="Delimiter">.</span>i = src<span class="Delimiter">;</span> +<span id="L1202" class="LineNr">1202 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1203" class="LineNr">1203 </span><span class="Delimiter">}</span> +<span id="L1204" class="LineNr">1204 </span> +<span id="L1205" class="LineNr">1205 </span><span class="Comment">//:</span> +<span id="L1206" class="LineNr">1206 </span> +<span id="L1207" class="LineNr">1207 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L1208" class="LineNr">1208 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"c7"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to rm32 with subop 0 (mov)"</span><span class="Delimiter">);</span> +<span id="L1209" class="LineNr">1209 </span> +<span id="L1210" class="LineNr">1210 </span><span class="Delimiter">:(code)</span> +<span id="L1211" class="LineNr">1211 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L1211'>test_copy_imm32_to_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1212" class="LineNr">1212 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x60</span><span class="Delimiter">;</span> +<span id="L1213" class="LineNr">1213 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1214" class="LineNr">1214 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1215" class="LineNr">1215 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1216" class="LineNr">1216 </span> <span class="Constant">" c7 03 0a 0b 0c 0d </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy 0x0d0c0b0a to *EBX</span> +<span id="L1217" class="LineNr">1217 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 000 (subop) 011 (dest EBX)</span> +<span id="L1218" class="LineNr">1218 </span> <span class="Delimiter">);</span> +<span id="L1219" class="LineNr">1219 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1220" class="LineNr">1220 </span> <span class="Constant">"run: copy imm32 to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1221" class="LineNr">1221 </span> <span class="Constant">"run: effective address is 0x00000060 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1222" class="LineNr">1222 </span> <span class="Constant">"run: imm32 is 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1223" class="LineNr">1223 </span> <span class="Delimiter">);</span> +<span id="L1224" class="LineNr">1224 </span><span class="Delimiter">}</span> +<span id="L1225" class="LineNr">1225 </span> +<span id="L1226" class="LineNr">1226 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L1227" class="LineNr">1227 </span><span class="Normal">case</span> <span class="Constant">0xc7</span>: <span class="Delimiter">{</span> <span class="Comment">// copy imm32 to r32</span> +<span id="L1228" class="LineNr">1228 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L1229" class="LineNr">1229 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy imm32 to r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L1230" class="LineNr">1230 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> subop = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span class="Comment">// middle 3 'reg opcode' bits</span> +<span id="L1231" class="LineNr">1231 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>subop != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L1232" class="LineNr">1232 </span> cerr << <span class="Constant">"unrecognized subop for opcode c7: "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="Constant">" (only 0/copy currently implemented)</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L1233" class="LineNr">1233 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L1234" class="LineNr">1234 </span> <span class="Delimiter">}</span> +<span id="L1235" class="LineNr">1235 </span> <span class="Normal">int32_t</span>* dest = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L1236" class="LineNr">1236 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> src = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L1237" class="LineNr">1237 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"imm32 is 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << src << end<span class="Delimiter">();</span> +<span id="L1238" class="LineNr">1238 </span> *dest = src<span class="Delimiter">;</span> <span class="Comment">// Write multiple elements of vector<uint8_t> at once. Assumes sizeof(int) == 4 on the host as well.</span> +<span id="L1239" class="LineNr">1239 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1240" class="LineNr">1240 </span><span class="Delimiter">}</span> +<span id="L1241" class="LineNr">1241 </span> +<span id="L1242" class="LineNr">1242 </span><span class="Comment">//:: push</span> +<span id="L1243" class="LineNr">1243 </span> +<span id="L1244" class="LineNr">1244 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L1245" class="LineNr">1245 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"68"</span><span class="Delimiter">,</span> <span class="Constant">"push imm32 to stack (<a href='012elf.cc.html#L94'>push</a>)"</span><span class="Delimiter">);</span> +<span id="L1246" class="LineNr">1246 </span> +<span id="L1247" class="LineNr">1247 </span><span class="Delimiter">:(code)</span> +<span id="L1248" class="LineNr">1248 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L1248'>test_push_imm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1249" class="LineNr">1249 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><span class="Constant">0xbd000000</span><span class="Delimiter">));</span> <span class="Comment">// manually allocate memory</span> +<span id="L1250" class="LineNr">1250 </span> Reg[ESP]<span class="Delimiter">.</span>u = <span class="Constant">0xbd000014</span><span class="Delimiter">;</span> +<span id="L1251" class="LineNr">1251 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1252" class="LineNr">1252 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1253" class="LineNr">1253 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1254" class="LineNr">1254 </span> <span class="Constant">" 68 af 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// push *EAX to stack</span> +<span id="L1255" class="LineNr">1255 </span> <span class="Delimiter">);</span> +<span id="L1256" class="LineNr">1256 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1257" class="LineNr">1257 </span> <span class="Constant">"run: <a href='012elf.cc.html#L94'>push</a> imm32 0x000000af</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1258" class="LineNr">1258 </span> <span class="Constant">"run: <a href='010vm.cc.html#L14'>ESP</a> is now 0xbd000010</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1259" class="LineNr">1259 </span> <span class="Constant">"run: <a href='003trace.cc.html#L117'>contents</a> at <a href='010vm.cc.html#L14'>ESP</a>: 0x000000af</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1260" class="LineNr">1260 </span> <span class="Delimiter">);</span> +<span id="L1261" class="LineNr">1261 </span><span class="Delimiter">}</span> +<span id="L1262" class="LineNr">1262 </span> +<span id="L1263" class="LineNr">1263 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L1264" class="LineNr">1264 </span><span class="Normal">case</span> <span class="Constant">0x68</span>: <span class="Delimiter">{</span> +<span id="L1265" class="LineNr">1265 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> val = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span><a href='011run.cc.html#L433'>next32</a><span class="Delimiter">());</span> +<span id="L1266" class="LineNr">1266 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"push imm32 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << val << end<span class="Delimiter">();</span> +<span id="L1267" class="LineNr">1267 </span><span class="CommentedCode">//? cerr << "push: " << val << " => " << Reg[ESP].u << '\n';</span> +<span id="L1268" class="LineNr">1268 </span> <a href='012elf.cc.html#L94'>push</a><span class="Delimiter">(</span>val<span class="Delimiter">);</span> +<span id="L1269" class="LineNr">1269 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ESP is now 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[ESP]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L1270" class="LineNr">1270 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"contents at <a href='010vm.cc.html#L14'>ESP</a>: 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L1271" class="LineNr">1271 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1272" class="LineNr">1272 </span><span class="Delimiter">}</span> +<span id="L1273" class="LineNr">1273 </span> +<span id="L1274" class="LineNr">1274 </span><span class="Comment">//:: multiply</span> +<span id="L1275" class="LineNr">1275 </span> +<span id="L1276" class="LineNr">1276 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L1277" class="LineNr">1277 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"69"</span><span class="Delimiter">,</span> <span class="Constant">"multiply rm32 by imm32 and store result in r32 (imul)"</span><span class="Delimiter">);</span> +<span id="L1278" class="LineNr">1278 </span> +<span id="L1279" class="LineNr">1279 </span><span class="Delimiter">:(code)</span> +<span id="L1280" class="LineNr">1280 </span><span class="Normal">void</span> <a href='015immediate_addressing.cc.html#L1280'>test_multiply_imm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L1281" class="LineNr">1281 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L1282" class="LineNr">1282 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">3</span><span class="Delimiter">;</span> +<span id="L1283" class="LineNr">1283 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L1284" class="LineNr">1284 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1285" class="LineNr">1285 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L1286" class="LineNr">1286 </span> <span class="Constant">" 69 c3 04 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// EAX = EBX * 4</span> +<span id="L1287" class="LineNr">1287 </span> <span class="Comment">// ModR/M in binary: 11 (direct) 000 (dest EAX) 011 (src EBX)</span> +<span id="L1288" class="LineNr">1288 </span> <span class="Delimiter">);</span> +<span id="L1289" class="LineNr">1289 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L1290" class="LineNr">1290 </span> <span class="Constant">"run: multiply r/m32 by 0x00000004 and store result in <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1291" class="LineNr">1291 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1292" class="LineNr">1292 </span> <span class="Constant">"run: storing 0x0000000c</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L1293" class="LineNr">1293 </span> <span class="Delimiter">);</span> +<span id="L1294" class="LineNr">1294 </span><span class="Delimiter">}</span> +<span id="L1295" class="LineNr">1295 </span> +<span id="L1296" class="LineNr">1296 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L1297" class="LineNr">1297 </span><span class="Normal">case</span> <span class="Constant">0x69</span>: <span class="Delimiter">{</span> +<span id="L1298" class="LineNr">1298 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L1299" class="LineNr">1299 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rdest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L1300" class="LineNr">1300 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> val = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L1301" class="LineNr">1301 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"multiply r/m32 by 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << val << <span class="Constant">" and store result in "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>rdest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L1302" class="LineNr">1302 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* signed_arg1 = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L1303" class="LineNr">1303 </span> <span class="Normal">int32_t</span> result = *signed_arg1 * val<span class="Delimiter">;</span> +<span id="L1304" class="LineNr">1304 </span> <span class="Normal">int64_t</span> full_result = <span class="Normal">static_cast</span><<span class="Normal">int64_t</span>><span class="Delimiter">(</span>*signed_arg1<span class="Delimiter">)</span> * val<span class="Delimiter">;</span> +<span id="L1305" class="LineNr">1305 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Delimiter">(</span>result != full_result<span class="Delimiter">);</span> +<span id="L1306" class="LineNr">1306 </span> <a href='010vm.cc.html#L90'>CF</a> = <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">;</span> +<span id="L1307" class="LineNr">1307 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L1308" class="LineNr">1308 </span> Reg[rdest]<span class="Delimiter">.</span>i = result<span class="Delimiter">;</span> +<span id="L1309" class="LineNr">1309 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[rdest]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L1310" class="LineNr">1310 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L1311" class="LineNr">1311 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/016index_addressing.cc.html b/html/linux/bootstrap/016index_addressing.cc.html new file mode 100644 index 00000000..fc6d9d64 --- /dev/null +++ b/html/linux/bootstrap/016index_addressing.cc.html @@ -0,0 +1,217 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/016index_addressing.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/016index_addressing.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/016index_addressing.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: operating on memory at the address provided by some register plus optional scale and offset</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span><span class="Delimiter">:(code)</span> +<span id="L4" class="LineNr"> 4 </span><span class="Normal">void</span> <a href='016index_addressing.cc.html#L4'>test_add_r32_to_mem_at_rm32_with_sib</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L5" class="LineNr"> 5 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> +<span id="L6" class="LineNr"> 6 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L7" class="LineNr"> 7 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L10" class="LineNr"> 10 </span> <span class="Constant">" 01 1c 20 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to *EAX</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 100 (dest in SIB)</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Comment">// SIB in binary: 00 (scale 1) 100 (no index) 000 (base EAX)</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Delimiter">);</span> +<span id="L16" class="LineNr"> 16 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"run: effective address is initially 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"run: effective address is 0x00002000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Delimiter">);</span> +<span id="L22" class="LineNr"> 22 </span><span class="Delimiter">}</span> +<span id="L23" class="LineNr"> 23 </span> +<span id="L24" class="LineNr"> 24 </span><span class="Delimiter">:(before "End Mod 0 Special-cases(addr)")</span> +<span id="L25" class="LineNr"> 25 </span><span class="Normal">case</span> <span class="Constant">4</span>: <span class="Comment">// exception: mod 0b00 rm 0b100 => incoming SIB (scale-index-base) byte</span> +<span id="L26" class="LineNr"> 26 </span> addr = <a href='016index_addressing.cc.html#L29'>effective_address_from_sib</a><span class="Delimiter">(</span>mod<span class="Delimiter">);</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L28" class="LineNr"> 28 </span><span class="Delimiter">:(code)</span> +<span id="L29" class="LineNr"> 29 </span><span class="Normal">uint32_t</span> <a href='016index_addressing.cc.html#L29'>effective_address_from_sib</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> mod<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> sib = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L31" class="LineNr"> 31 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> base = sib&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Normal">uint32_t</span> addr = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>base != <a href='010vm.cc.html#L15'>EBP</a> || mod != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L34" class="LineNr"> 34 </span> addr = Reg[base]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L35" class="LineNr"> 35 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is initially 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" ("</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>base<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Delimiter">}</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L38" class="LineNr"> 38 </span> <span class="Comment">// base == EBP && mod == 0</span> +<span id="L39" class="LineNr"> 39 </span> addr = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> <span class="Comment">// ignore base</span> +<span id="L40" class="LineNr"> 40 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is initially 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" (<a href='040tests.cc.html#L82'>disp32</a>)"</span> << end<span class="Delimiter">();</span> +<span id="L41" class="LineNr"> 41 </span> <span class="Delimiter">}</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> index = <span class="Delimiter">(</span>sib>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>index == <a href='010vm.cc.html#L14'>ESP</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Comment">// ignore index and scale</span> +<span id="L45" class="LineNr"> 45 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << end<span class="Delimiter">();</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Delimiter">}</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> scale = <span class="Delimiter">(</span><span class="Constant">1</span> << <span class="Delimiter">(</span>sib>><span class="Constant">6</span><span class="Delimiter">));</span> +<span id="L49" class="LineNr"> 49 </span> addr += Reg[index]<span class="Delimiter">.</span>i*scale<span class="Delimiter">;</span> <span class="Comment">// treat index register as signed. Maybe base as well? But we'll always ensure it's non-negative.</span> +<span id="L50" class="LineNr"> 50 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" (after adding "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>index<span class="Delimiter">)</span> << <span class="Constant">"*"</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>scale<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Delimiter">}</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Identifier">return</span> addr<span class="Delimiter">;</span> +<span id="L53" class="LineNr"> 53 </span><span class="Delimiter">}</span> +<span id="L54" class="LineNr"> 54 </span> +<span id="L55" class="LineNr"> 55 </span><span class="Delimiter">:(code)</span> +<span id="L56" class="LineNr"> 56 </span><span class="Normal">void</span> <a href='016index_addressing.cc.html#L56'>test_add_r32_to_mem_at_base_r32_index_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L57" class="LineNr"> 57 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> <span class="Comment">// source</span> +<span id="L58" class="LineNr"> 58 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x1ffe</span><span class="Delimiter">;</span> <span class="Comment">// dest base</span> +<span id="L59" class="LineNr"> 59 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">0x2</span><span class="Delimiter">;</span> <span class="Comment">// dest index</span> +<span id="L60" class="LineNr"> 60 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Constant">" 01 1c 08 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to *(EAX+ECX)</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 100 (dest in SIB)</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Comment">// SIB in binary: 00 (scale 1) 001 (index ECX) 000 (base EAX)</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Delimiter">);</span> +<span id="L69" class="LineNr"> 69 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Constant">"run: effective address is initially 0x00001ffe (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Constant">"run: effective address is 0x00002000 (after adding ECX*1)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Delimiter">);</span> +<span id="L75" class="LineNr"> 75 </span><span class="Delimiter">}</span> +<span id="L76" class="LineNr"> 76 </span> +<span id="L77" class="LineNr"> 77 </span><span class="Delimiter">:(code)</span> +<span id="L78" class="LineNr"> 78 </span><span class="Normal">void</span> <a href='016index_addressing.cc.html#L78'>test_add_r32_to_mem_at_displacement_using_sib</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L79" class="LineNr"> 79 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> <span class="Comment">// source</span> +<span id="L80" class="LineNr"> 80 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Constant">" 01 1c 25 00 20 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to *0x2000</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src EBX) 100 (dest in SIB)</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Comment">// SIB in binary: 00 (scale 1) 100 (no index) 101 (not EBP but disp32)</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Delimiter">);</span> +<span id="L89" class="LineNr"> 89 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Constant">"run: effective address is initially 0x00002000 (<a href='040tests.cc.html#L82'>disp32</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Constant">"run: effective address is 0x00002000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Delimiter">);</span> +<span id="L95" class="LineNr"> 95 </span><span class="Delimiter">}</span> +<span id="L96" class="LineNr"> 96 </span> +<span id="L97" class="LineNr"> 97 </span><span class="Comment">//:</span> +<span id="L98" class="LineNr"> 98 </span> +<span id="L99" class="LineNr"> 99 </span><span class="Delimiter">:(code)</span> +<span id="L100" class="LineNr">100 </span><span class="Normal">void</span> <a href='016index_addressing.cc.html#L100'>test_add_r32_to_mem_at_base_r32_index_r32_plus_disp8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L101" class="LineNr">101 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> <span class="Comment">// source</span> +<span id="L102" class="LineNr">102 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x1ff9</span><span class="Delimiter">;</span> <span class="Comment">// dest base</span> +<span id="L103" class="LineNr">103 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">0x5</span><span class="Delimiter">;</span> <span class="Comment">// dest index</span> +<span id="L104" class="LineNr">104 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L105" class="LineNr">105 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L106" class="LineNr">106 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L107" class="LineNr">107 </span> <span class="Constant">" 01 5c 08 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to *(EAX+ECX+2)</span> +<span id="L108" class="LineNr">108 </span> <span class="Comment">// ModR/M in binary: 01 (indirect+disp8 mode) 011 (src EBX) 100 (dest in SIB)</span> +<span id="L109" class="LineNr">109 </span> <span class="Comment">// SIB in binary: 00 (scale 1) 001 (index ECX) 000 (base EAX)</span> +<span id="L110" class="LineNr">110 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L111" class="LineNr">111 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L112" class="LineNr">112 </span> <span class="Delimiter">);</span> +<span id="L113" class="LineNr">113 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L114" class="LineNr">114 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L115" class="LineNr">115 </span> <span class="Constant">"run: effective address is initially 0x00001ff9 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L116" class="LineNr">116 </span> <span class="Constant">"run: effective address is 0x00001ffe (after adding ECX*1)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L117" class="LineNr">117 </span> <span class="Constant">"run: effective address is 0x00002000 (after adding disp8)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L118" class="LineNr">118 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L119" class="LineNr">119 </span> <span class="Delimiter">);</span> +<span id="L120" class="LineNr">120 </span><span class="Delimiter">}</span> +<span id="L121" class="LineNr">121 </span> +<span id="L122" class="LineNr">122 </span><span class="Delimiter">:(before "End Mod 1 Special-cases(addr)")</span> +<span id="L123" class="LineNr">123 </span><span class="Normal">case</span> <span class="Constant">4</span>: <span class="Comment">// exception: mod 0b01 rm 0b100 => incoming SIB (scale-index-base) byte</span> +<span id="L124" class="LineNr">124 </span> addr = <a href='016index_addressing.cc.html#L29'>effective_address_from_sib</a><span class="Delimiter">(</span>mod<span class="Delimiter">);</span> +<span id="L125" class="LineNr">125 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L126" class="LineNr">126 </span> +<span id="L127" class="LineNr">127 </span><span class="Comment">//:</span> +<span id="L128" class="LineNr">128 </span> +<span id="L129" class="LineNr">129 </span><span class="Delimiter">:(code)</span> +<span id="L130" class="LineNr">130 </span><span class="Normal">void</span> <a href='016index_addressing.cc.html#L130'>test_add_r32_to_mem_at_base_r32_index_r32_plus_disp32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L131" class="LineNr">131 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x10</span><span class="Delimiter">;</span> <span class="Comment">// source</span> +<span id="L132" class="LineNr">132 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x1ff9</span><span class="Delimiter">;</span> <span class="Comment">// dest base</span> +<span id="L133" class="LineNr">133 </span> Reg[ECX]<span class="Delimiter">.</span>i = <span class="Constant">0x5</span><span class="Delimiter">;</span> <span class="Comment">// dest index</span> +<span id="L134" class="LineNr">134 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L135" class="LineNr">135 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L136" class="LineNr">136 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L137" class="LineNr">137 </span> <span class="Constant">" 01 9c 08 02 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EBX to *(EAX+ECX+2)</span> +<span id="L138" class="LineNr">138 </span> <span class="Comment">// ModR/M in binary: 10 (indirect+disp32 mode) 011 (src EBX) 100 (dest in SIB)</span> +<span id="L139" class="LineNr">139 </span> <span class="Comment">// SIB in binary: 00 (scale 1) 001 (index ECX) 000 (base EAX)</span> +<span id="L140" class="LineNr">140 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L141" class="LineNr">141 </span> <span class="Constant">"01 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1</span> +<span id="L142" class="LineNr">142 </span> <span class="Delimiter">);</span> +<span id="L143" class="LineNr">143 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L144" class="LineNr">144 </span> <span class="Constant">"run: add <a href='010vm.cc.html#L13'>EBX</a> to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L145" class="LineNr">145 </span> <span class="Constant">"run: effective address is initially 0x00001ff9 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L146" class="LineNr">146 </span> <span class="Constant">"run: effective address is 0x00001ffe (after adding ECX*1)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L147" class="LineNr">147 </span> <span class="Constant">"run: effective address is 0x00002000 (after adding <a href='040tests.cc.html#L82'>disp32</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L148" class="LineNr">148 </span> <span class="Constant">"run: storing 0x00000011</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L149" class="LineNr">149 </span> <span class="Delimiter">);</span> +<span id="L150" class="LineNr">150 </span><span class="Delimiter">}</span> +<span id="L151" class="LineNr">151 </span> +<span id="L152" class="LineNr">152 </span><span class="Delimiter">:(before "End Mod 2 Special-cases(addr)")</span> +<span id="L153" class="LineNr">153 </span><span class="Normal">case</span> <span class="Constant">4</span>: <span class="Comment">// exception: mod 0b10 rm 0b100 => incoming SIB (scale-index-base) byte</span> +<span id="L154" class="LineNr">154 </span> addr = <a href='016index_addressing.cc.html#L29'>effective_address_from_sib</a><span class="Delimiter">(</span>mod<span class="Delimiter">);</span> +<span id="L155" class="LineNr">155 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/017jump_disp8.cc.html b/html/linux/bootstrap/017jump_disp8.cc.html new file mode 100644 index 00000000..8baf96cd --- /dev/null +++ b/html/linux/bootstrap/017jump_disp8.cc.html @@ -0,0 +1,469 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/017jump_disp8.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.LineNr { } +.Constant { color: #008787; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/017jump_disp8.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/017jump_disp8.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: jump to 8-bit offset</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//:: jump</span> +<span id="L4" class="LineNr"> 4 </span> +<span id="L5" class="LineNr"> 5 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L6" class="LineNr"> 6 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"eb"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away (jmp)"</span><span class="Delimiter">);</span> +<span id="L7" class="LineNr"> 7 </span> +<span id="L8" class="LineNr"> 8 </span><span class="Delimiter">:(code)</span> +<span id="L9" class="LineNr"> 9 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L9'>test_jump_disp8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L10" class="LineNr"> 10 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Constant">" eb 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Delimiter">);</span> +<span id="L17" class="LineNr"> 17 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"run: 0x00000001 opcode: eb</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Delimiter">);</span> +<span id="L22" class="LineNr"> 22 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000003 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">}</span> +<span id="L24" class="LineNr"> 24 </span> +<span id="L25" class="LineNr"> 25 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L26" class="LineNr"> 26 </span><span class="Normal">case</span> <span class="Constant">0xeb</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp8</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L338'>next</a><span class="Delimiter">());</span> +<span id="L28" class="LineNr"> 28 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L29" class="LineNr"> 29 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L31" class="LineNr"> 31 </span><span class="Delimiter">}</span> +<span id="L32" class="LineNr"> 32 </span> +<span id="L33" class="LineNr"> 33 </span><span class="Comment">//:: jump if equal/zero</span> +<span id="L34" class="LineNr"> 34 </span> +<span id="L35" class="LineNr"> 35 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L36" class="LineNr"> 36 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"74"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if equal, if <a href='010vm.cc.html#L89'>ZF</a> is set (jcc/jz/je)"</span><span class="Delimiter">);</span> +<span id="L37" class="LineNr"> 37 </span> +<span id="L38" class="LineNr"> 38 </span><span class="Delimiter">:(code)</span> +<span id="L39" class="LineNr"> 39 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L39'>test_je_disp8_success</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L40" class="LineNr"> 40 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L41" class="LineNr"> 41 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Constant">" 74 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Delimiter">);</span> +<span id="L48" class="LineNr"> 48 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Constant">"run: 0x00000001 opcode: 74</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Delimiter">);</span> +<span id="L53" class="LineNr"> 53 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000003 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L54" class="LineNr"> 54 </span><span class="Delimiter">}</span> +<span id="L55" class="LineNr"> 55 </span> +<span id="L56" class="LineNr"> 56 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L57" class="LineNr"> 57 </span><span class="Normal">case</span> <span class="Constant">0x74</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp8 if ZF</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L338'>next</a><span class="Delimiter">());</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L89'>ZF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L60" class="LineNr"> 60 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L61" class="LineNr"> 61 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Delimiter">}</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L64" class="LineNr"> 64 </span><span class="Delimiter">}</span> +<span id="L65" class="LineNr"> 65 </span> +<span id="L66" class="LineNr"> 66 </span><span class="Delimiter">:(code)</span> +<span id="L67" class="LineNr"> 67 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L67'>test_je_disp8_fail</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L68" class="LineNr"> 68 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L69" class="LineNr"> 69 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Constant">" 74 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Delimiter">);</span> +<span id="L76" class="LineNr"> 76 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Constant">"run: 0x00000001 opcode: 74</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Constant">"run: 0x00000003 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Delimiter">);</span> +<span id="L81" class="LineNr"> 81 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: jump 5"</span><span class="Delimiter">);</span> +<span id="L82" class="LineNr"> 82 </span><span class="Delimiter">}</span> +<span id="L83" class="LineNr"> 83 </span> +<span id="L84" class="LineNr"> 84 </span><span class="Comment">//:: jump if not equal/not zero</span> +<span id="L85" class="LineNr"> 85 </span> +<span id="L86" class="LineNr"> 86 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L87" class="LineNr"> 87 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"75"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if not equal, if <a href='010vm.cc.html#L89'>ZF</a> is not set (jcc/jnz/jne)"</span><span class="Delimiter">);</span> +<span id="L88" class="LineNr"> 88 </span> +<span id="L89" class="LineNr"> 89 </span><span class="Delimiter">:(code)</span> +<span id="L90" class="LineNr"> 90 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L90'>test_jne_disp8_success</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L91" class="LineNr"> 91 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L92" class="LineNr"> 92 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Constant">" 75 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Delimiter">);</span> +<span id="L99" class="LineNr"> 99 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L100" class="LineNr">100 </span> <span class="Constant">"run: 0x00000001 opcode: 75</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L101" class="LineNr">101 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L102" class="LineNr">102 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L103" class="LineNr">103 </span> <span class="Delimiter">);</span> +<span id="L104" class="LineNr">104 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000003 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L105" class="LineNr">105 </span><span class="Delimiter">}</span> +<span id="L106" class="LineNr">106 </span> +<span id="L107" class="LineNr">107 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L108" class="LineNr">108 </span><span class="Normal">case</span> <span class="Constant">0x75</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp8 if !ZF</span> +<span id="L109" class="LineNr">109 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L338'>next</a><span class="Delimiter">());</span> +<span id="L110" class="LineNr">110 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!ZF<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L111" class="LineNr">111 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L112" class="LineNr">112 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L113" class="LineNr">113 </span> <span class="Delimiter">}</span> +<span id="L114" class="LineNr">114 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L115" class="LineNr">115 </span><span class="Delimiter">}</span> +<span id="L116" class="LineNr">116 </span> +<span id="L117" class="LineNr">117 </span><span class="Delimiter">:(code)</span> +<span id="L118" class="LineNr">118 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L118'>test_jne_disp8_fail</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L119" class="LineNr">119 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L120" class="LineNr">120 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L121" class="LineNr">121 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L122" class="LineNr">122 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L123" class="LineNr">123 </span> <span class="Constant">" 75 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L124" class="LineNr">124 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L125" class="LineNr">125 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L126" class="LineNr">126 </span> <span class="Delimiter">);</span> +<span id="L127" class="LineNr">127 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L128" class="LineNr">128 </span> <span class="Constant">"run: 0x00000001 opcode: 75</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L129" class="LineNr">129 </span> <span class="Constant">"run: 0x00000003 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L130" class="LineNr">130 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L131" class="LineNr">131 </span> <span class="Delimiter">);</span> +<span id="L132" class="LineNr">132 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: jump 5"</span><span class="Delimiter">);</span> +<span id="L133" class="LineNr">133 </span><span class="Delimiter">}</span> +<span id="L134" class="LineNr">134 </span> +<span id="L135" class="LineNr">135 </span><span class="Comment">//:: jump if greater</span> +<span id="L136" class="LineNr">136 </span> +<span id="L137" class="LineNr">137 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L138" class="LineNr">138 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"7f"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if greater, if <a href='010vm.cc.html#L89'>ZF</a> is unset and SF == <a href='010vm.cc.html#L91'>OF</a> (jcc/jg/jnle)"</span><span class="Delimiter">);</span> +<span id="L139" class="LineNr">139 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"77"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if greater (addr, float), if <a href='010vm.cc.html#L89'>ZF</a> is unset and <a href='010vm.cc.html#L90'>CF</a> is unset (jcc/ja/jnbe)"</span><span class="Delimiter">);</span> +<span id="L140" class="LineNr">140 </span> +<span id="L141" class="LineNr">141 </span><span class="Delimiter">:(code)</span> +<span id="L142" class="LineNr">142 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L142'>test_jg_disp8_success</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L143" class="LineNr">143 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L144" class="LineNr">144 </span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L145" class="LineNr">145 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L146" class="LineNr">146 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L147" class="LineNr">147 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L148" class="LineNr">148 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L149" class="LineNr">149 </span> <span class="Constant">" 7f 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L150" class="LineNr">150 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L151" class="LineNr">151 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L152" class="LineNr">152 </span> <span class="Delimiter">);</span> +<span id="L153" class="LineNr">153 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L154" class="LineNr">154 </span> <span class="Constant">"run: 0x00000001 opcode: 7f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L155" class="LineNr">155 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L156" class="LineNr">156 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L157" class="LineNr">157 </span> <span class="Delimiter">);</span> +<span id="L158" class="LineNr">158 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000003 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L159" class="LineNr">159 </span><span class="Delimiter">}</span> +<span id="L160" class="LineNr">160 </span> +<span id="L161" class="LineNr">161 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L162" class="LineNr">162 </span><span class="Normal">case</span> <span class="Constant">0x7f</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp8 if SF == OF and !ZF</span> +<span id="L163" class="LineNr">163 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L338'>next</a><span class="Delimiter">());</span> +<span id="L164" class="LineNr">164 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>SF == <a href='010vm.cc.html#L91'>OF</a> && !ZF<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L165" class="LineNr">165 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L166" class="LineNr">166 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L167" class="LineNr">167 </span> <span class="Delimiter">}</span> +<span id="L168" class="LineNr">168 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L169" class="LineNr">169 </span><span class="Delimiter">}</span> +<span id="L170" class="LineNr">170 </span><span class="Normal">case</span> <span class="Constant">0x77</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp8 if !CF and !ZF</span> +<span id="L171" class="LineNr">171 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L338'>next</a><span class="Delimiter">());</span> +<span id="L172" class="LineNr">172 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!CF && !ZF<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L173" class="LineNr">173 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L174" class="LineNr">174 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L175" class="LineNr">175 </span> <span class="Delimiter">}</span> +<span id="L176" class="LineNr">176 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L177" class="LineNr">177 </span><span class="Delimiter">}</span> +<span id="L178" class="LineNr">178 </span> +<span id="L179" class="LineNr">179 </span><span class="Delimiter">:(code)</span> +<span id="L180" class="LineNr">180 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L180'>test_jg_disp8_fail</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L181" class="LineNr">181 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L182" class="LineNr">182 </span> SF = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L183" class="LineNr">183 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L184" class="LineNr">184 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L185" class="LineNr">185 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L186" class="LineNr">186 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L187" class="LineNr">187 </span> <span class="Constant">" 7f 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L188" class="LineNr">188 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L189" class="LineNr">189 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L190" class="LineNr">190 </span> <span class="Delimiter">);</span> +<span id="L191" class="LineNr">191 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L192" class="LineNr">192 </span> <span class="Constant">"run: 0x00000001 opcode: 7f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L193" class="LineNr">193 </span> <span class="Constant">"run: 0x00000003 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L194" class="LineNr">194 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L195" class="LineNr">195 </span> <span class="Delimiter">);</span> +<span id="L196" class="LineNr">196 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: jump 5"</span><span class="Delimiter">);</span> +<span id="L197" class="LineNr">197 </span><span class="Delimiter">}</span> +<span id="L198" class="LineNr">198 </span> +<span id="L199" class="LineNr">199 </span><span class="Comment">//:: jump if greater or equal</span> +<span id="L200" class="LineNr">200 </span> +<span id="L201" class="LineNr">201 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L202" class="LineNr">202 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"7d"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if greater or equal, if SF == <a href='010vm.cc.html#L91'>OF</a> (jcc/jge/jnl)"</span><span class="Delimiter">);</span> +<span id="L203" class="LineNr">203 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"73"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if greater or equal (addr, float), if <a href='010vm.cc.html#L90'>CF</a> is unset (jcc/jae/jnb)"</span><span class="Delimiter">);</span> +<span id="L204" class="LineNr">204 </span> +<span id="L205" class="LineNr">205 </span><span class="Delimiter">:(code)</span> +<span id="L206" class="LineNr">206 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L206'>test_jge_disp8_success</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L207" class="LineNr">207 </span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L208" class="LineNr">208 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L209" class="LineNr">209 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L210" class="LineNr">210 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L211" class="LineNr">211 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L212" class="LineNr">212 </span> <span class="Constant">" 7d 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L213" class="LineNr">213 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L214" class="LineNr">214 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L215" class="LineNr">215 </span> <span class="Delimiter">);</span> +<span id="L216" class="LineNr">216 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L217" class="LineNr">217 </span> <span class="Constant">"run: 0x00000001 opcode: 7d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L218" class="LineNr">218 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L219" class="LineNr">219 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L220" class="LineNr">220 </span> <span class="Delimiter">);</span> +<span id="L221" class="LineNr">221 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000003 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L222" class="LineNr">222 </span><span class="Delimiter">}</span> +<span id="L223" class="LineNr">223 </span> +<span id="L224" class="LineNr">224 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L225" class="LineNr">225 </span><span class="Normal">case</span> <span class="Constant">0x7d</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp8 if SF == OF</span> +<span id="L226" class="LineNr">226 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L338'>next</a><span class="Delimiter">());</span> +<span id="L227" class="LineNr">227 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>SF == <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L228" class="LineNr">228 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L229" class="LineNr">229 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L230" class="LineNr">230 </span> <span class="Delimiter">}</span> +<span id="L231" class="LineNr">231 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L232" class="LineNr">232 </span><span class="Delimiter">}</span> +<span id="L233" class="LineNr">233 </span><span class="Normal">case</span> <span class="Constant">0x73</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp8 if !CF</span> +<span id="L234" class="LineNr">234 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L338'>next</a><span class="Delimiter">());</span> +<span id="L235" class="LineNr">235 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!CF<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L236" class="LineNr">236 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L237" class="LineNr">237 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L238" class="LineNr">238 </span> <span class="Delimiter">}</span> +<span id="L239" class="LineNr">239 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L240" class="LineNr">240 </span><span class="Delimiter">}</span> +<span id="L241" class="LineNr">241 </span> +<span id="L242" class="LineNr">242 </span><span class="Delimiter">:(code)</span> +<span id="L243" class="LineNr">243 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L243'>test_jge_disp8_fail</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L244" class="LineNr">244 </span> SF = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L245" class="LineNr">245 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L246" class="LineNr">246 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L247" class="LineNr">247 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L248" class="LineNr">248 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L249" class="LineNr">249 </span> <span class="Constant">" 7d 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L250" class="LineNr">250 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L251" class="LineNr">251 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L252" class="LineNr">252 </span> <span class="Delimiter">);</span> +<span id="L253" class="LineNr">253 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L254" class="LineNr">254 </span> <span class="Constant">"run: 0x00000001 opcode: 7d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L255" class="LineNr">255 </span> <span class="Constant">"run: 0x00000003 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L256" class="LineNr">256 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L257" class="LineNr">257 </span> <span class="Delimiter">);</span> +<span id="L258" class="LineNr">258 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: jump 5"</span><span class="Delimiter">);</span> +<span id="L259" class="LineNr">259 </span><span class="Delimiter">}</span> +<span id="L260" class="LineNr">260 </span> +<span id="L261" class="LineNr">261 </span><span class="Comment">//:: jump if lesser</span> +<span id="L262" class="LineNr">262 </span> +<span id="L263" class="LineNr">263 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L264" class="LineNr">264 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"7c"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if lesser, if SF != <a href='010vm.cc.html#L91'>OF</a> (jcc/jl/jnge)"</span><span class="Delimiter">);</span> +<span id="L265" class="LineNr">265 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"72"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if lesser (addr, float), if <a href='010vm.cc.html#L90'>CF</a> is set (jcc/jb/jnae)"</span><span class="Delimiter">);</span> +<span id="L266" class="LineNr">266 </span> +<span id="L267" class="LineNr">267 </span><span class="Delimiter">:(code)</span> +<span id="L268" class="LineNr">268 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L268'>test_jl_disp8_success</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L269" class="LineNr">269 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L270" class="LineNr">270 </span> SF = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L271" class="LineNr">271 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L272" class="LineNr">272 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L273" class="LineNr">273 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L274" class="LineNr">274 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L275" class="LineNr">275 </span> <span class="Constant">" 7c 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L276" class="LineNr">276 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L277" class="LineNr">277 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L278" class="LineNr">278 </span> <span class="Delimiter">);</span> +<span id="L279" class="LineNr">279 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L280" class="LineNr">280 </span> <span class="Constant">"run: 0x00000001 opcode: 7c</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L281" class="LineNr">281 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L282" class="LineNr">282 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L283" class="LineNr">283 </span> <span class="Delimiter">);</span> +<span id="L284" class="LineNr">284 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000003 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L285" class="LineNr">285 </span><span class="Delimiter">}</span> +<span id="L286" class="LineNr">286 </span> +<span id="L287" class="LineNr">287 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L288" class="LineNr">288 </span><span class="Normal">case</span> <span class="Constant">0x7c</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp8 if SF != OF</span> +<span id="L289" class="LineNr">289 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L338'>next</a><span class="Delimiter">());</span> +<span id="L290" class="LineNr">290 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>SF != <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L291" class="LineNr">291 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L292" class="LineNr">292 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L293" class="LineNr">293 </span> <span class="Delimiter">}</span> +<span id="L294" class="LineNr">294 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L295" class="LineNr">295 </span><span class="Delimiter">}</span> +<span id="L296" class="LineNr">296 </span><span class="Normal">case</span> <span class="Constant">0x72</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp8 if CF</span> +<span id="L297" class="LineNr">297 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L338'>next</a><span class="Delimiter">());</span> +<span id="L298" class="LineNr">298 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L90'>CF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L299" class="LineNr">299 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L300" class="LineNr">300 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L301" class="LineNr">301 </span> <span class="Delimiter">}</span> +<span id="L302" class="LineNr">302 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L303" class="LineNr">303 </span><span class="Delimiter">}</span> +<span id="L304" class="LineNr">304 </span> +<span id="L305" class="LineNr">305 </span><span class="Delimiter">:(code)</span> +<span id="L306" class="LineNr">306 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L306'>test_jl_disp8_fail</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L307" class="LineNr">307 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L308" class="LineNr">308 </span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L309" class="LineNr">309 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L310" class="LineNr">310 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L311" class="LineNr">311 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L312" class="LineNr">312 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L313" class="LineNr">313 </span> <span class="Constant">" 7c 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L314" class="LineNr">314 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L315" class="LineNr">315 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L316" class="LineNr">316 </span> <span class="Delimiter">);</span> +<span id="L317" class="LineNr">317 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L318" class="LineNr">318 </span> <span class="Constant">"run: 0x00000001 opcode: 7c</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L319" class="LineNr">319 </span> <span class="Constant">"run: 0x00000003 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L320" class="LineNr">320 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L321" class="LineNr">321 </span> <span class="Delimiter">);</span> +<span id="L322" class="LineNr">322 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: jump 5"</span><span class="Delimiter">);</span> +<span id="L323" class="LineNr">323 </span><span class="Delimiter">}</span> +<span id="L324" class="LineNr">324 </span> +<span id="L325" class="LineNr">325 </span><span class="Comment">//:: jump if lesser or equal</span> +<span id="L326" class="LineNr">326 </span> +<span id="L327" class="LineNr">327 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L328" class="LineNr">328 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"7e"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if lesser or equal, if <a href='010vm.cc.html#L89'>ZF</a> is set or SF != <a href='010vm.cc.html#L91'>OF</a> (jcc/jle/jng)"</span><span class="Delimiter">);</span> +<span id="L329" class="LineNr">329 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"76"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if lesser or equal (addr, float), if <a href='010vm.cc.html#L89'>ZF</a> is set or <a href='010vm.cc.html#L90'>CF</a> is set (jcc/jbe/jna)"</span><span class="Delimiter">);</span> +<span id="L330" class="LineNr">330 </span> +<span id="L331" class="LineNr">331 </span><span class="Delimiter">:(code)</span> +<span id="L332" class="LineNr">332 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L332'>test_jle_disp8_equal</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L333" class="LineNr">333 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L334" class="LineNr">334 </span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L335" class="LineNr">335 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L336" class="LineNr">336 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L337" class="LineNr">337 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L338" class="LineNr">338 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L339" class="LineNr">339 </span> <span class="Constant">" 7e 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L340" class="LineNr">340 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L341" class="LineNr">341 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L342" class="LineNr">342 </span> <span class="Delimiter">);</span> +<span id="L343" class="LineNr">343 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L344" class="LineNr">344 </span> <span class="Constant">"run: 0x00000001 opcode: 7e</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L345" class="LineNr">345 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L346" class="LineNr">346 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L347" class="LineNr">347 </span> <span class="Delimiter">);</span> +<span id="L348" class="LineNr">348 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000003 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L349" class="LineNr">349 </span><span class="Delimiter">}</span> +<span id="L350" class="LineNr">350 </span> +<span id="L351" class="LineNr">351 </span><span class="Delimiter">:(code)</span> +<span id="L352" class="LineNr">352 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L352'>test_jle_disp8_lesser</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L353" class="LineNr">353 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L354" class="LineNr">354 </span> SF = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L355" class="LineNr">355 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L356" class="LineNr">356 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L357" class="LineNr">357 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L358" class="LineNr">358 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L359" class="LineNr">359 </span> <span class="Constant">" 7e 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L360" class="LineNr">360 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L361" class="LineNr">361 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L362" class="LineNr">362 </span> <span class="Delimiter">);</span> +<span id="L363" class="LineNr">363 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L364" class="LineNr">364 </span> <span class="Constant">"run: 0x00000001 opcode: 7e</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L365" class="LineNr">365 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L366" class="LineNr">366 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L367" class="LineNr">367 </span> <span class="Delimiter">);</span> +<span id="L368" class="LineNr">368 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000003 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L369" class="LineNr">369 </span><span class="Delimiter">}</span> +<span id="L370" class="LineNr">370 </span> +<span id="L371" class="LineNr">371 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L372" class="LineNr">372 </span><span class="Normal">case</span> <span class="Constant">0x7e</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp8 if ZF or SF != OF</span> +<span id="L373" class="LineNr">373 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L338'>next</a><span class="Delimiter">());</span> +<span id="L374" class="LineNr">374 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L89'>ZF</a> || SF != <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L375" class="LineNr">375 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L376" class="LineNr">376 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L377" class="LineNr">377 </span> <span class="Delimiter">}</span> +<span id="L378" class="LineNr">378 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L379" class="LineNr">379 </span><span class="Delimiter">}</span> +<span id="L380" class="LineNr">380 </span><span class="Normal">case</span> <span class="Constant">0x76</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp8 if ZF or CF</span> +<span id="L381" class="LineNr">381 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010vm.cc.html#L338'>next</a><span class="Delimiter">());</span> +<span id="L382" class="LineNr">382 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L89'>ZF</a> || <a href='010vm.cc.html#L90'>CF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L383" class="LineNr">383 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L384" class="LineNr">384 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L385" class="LineNr">385 </span> <span class="Delimiter">}</span> +<span id="L386" class="LineNr">386 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L387" class="LineNr">387 </span><span class="Delimiter">}</span> +<span id="L388" class="LineNr">388 </span> +<span id="L389" class="LineNr">389 </span><span class="Delimiter">:(code)</span> +<span id="L390" class="LineNr">390 </span><span class="Normal">void</span> <a href='017jump_disp8.cc.html#L390'>test_jle_disp8_greater</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L391" class="LineNr">391 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L392" class="LineNr">392 </span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L393" class="LineNr">393 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L394" class="LineNr">394 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L395" class="LineNr">395 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L396" class="LineNr">396 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L397" class="LineNr">397 </span> <span class="Constant">" 7e 05 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L398" class="LineNr">398 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L399" class="LineNr">399 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L400" class="LineNr">400 </span> <span class="Delimiter">);</span> +<span id="L401" class="LineNr">401 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L402" class="LineNr">402 </span> <span class="Constant">"run: 0x00000001 opcode: 7e</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L403" class="LineNr">403 </span> <span class="Constant">"run: 0x00000003 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L404" class="LineNr">404 </span> <span class="Constant">"run: 0x00000008 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L405" class="LineNr">405 </span> <span class="Delimiter">);</span> +<span id="L406" class="LineNr">406 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: jump 5"</span><span class="Delimiter">);</span> +<span id="L407" class="LineNr">407 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/018jump_disp32.cc.html b/html/linux/bootstrap/018jump_disp32.cc.html new file mode 100644 index 00000000..991b070e --- /dev/null +++ b/html/linux/bootstrap/018jump_disp32.cc.html @@ -0,0 +1,469 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/018jump_disp32.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.LineNr { } +.Constant { color: #008787; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/018jump_disp32.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/018jump_disp32.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: jump to 32-bit offset</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//:: jump</span> +<span id="L4" class="LineNr"> 4 </span> +<span id="L5" class="LineNr"> 5 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L6" class="LineNr"> 6 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"e9"</span><span class="Delimiter">,</span> <span class="Constant">"jump <a href='040tests.cc.html#L82'>disp32</a> bytes away (jmp)"</span><span class="Delimiter">);</span> +<span id="L7" class="LineNr"> 7 </span> +<span id="L8" class="LineNr"> 8 </span><span class="Delimiter">:(code)</span> +<span id="L9" class="LineNr"> 9 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L9'>test_jump_disp32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L10" class="LineNr"> 10 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Constant">" e9 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Delimiter">);</span> +<span id="L17" class="LineNr"> 17 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"run: 0x00000001 opcode: e9</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"run: 0x0000000b opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Delimiter">);</span> +<span id="L22" class="LineNr"> 22 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000006 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">}</span> +<span id="L24" class="LineNr"> 24 </span> +<span id="L25" class="LineNr"> 25 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L26" class="LineNr"> 26 </span><span class="Normal">case</span> <span class="Constant">0xe9</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L28" class="LineNr"> 28 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> +<span id="L29" class="LineNr"> 29 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L31" class="LineNr"> 31 </span><span class="Delimiter">}</span> +<span id="L32" class="LineNr"> 32 </span> +<span id="L33" class="LineNr"> 33 </span><span class="Comment">//:: jump if equal/zero</span> +<span id="L34" class="LineNr"> 34 </span> +<span id="L35" class="LineNr"> 35 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L36" class="LineNr"> 36 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"84"</span><span class="Delimiter">,</span> <span class="Constant">"jump <a href='040tests.cc.html#L82'>disp32</a> bytes away if equal, if <a href='010vm.cc.html#L89'>ZF</a> is set (jcc/jz/je)"</span><span class="Delimiter">);</span> +<span id="L37" class="LineNr"> 37 </span> +<span id="L38" class="LineNr"> 38 </span><span class="Delimiter">:(code)</span> +<span id="L39" class="LineNr"> 39 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L39'>test_je_disp32_success</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L40" class="LineNr"> 40 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L41" class="LineNr"> 41 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Constant">" 0f 84 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Delimiter">);</span> +<span id="L48" class="LineNr"> 48 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Delimiter">);</span> +<span id="L53" class="LineNr"> 53 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000007 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L54" class="LineNr"> 54 </span><span class="Delimiter">}</span> +<span id="L55" class="LineNr"> 55 </span> +<span id="L56" class="LineNr"> 56 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L57" class="LineNr"> 57 </span><span class="Normal">case</span> <span class="Constant">0x84</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if ZF</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L89'>ZF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L60" class="LineNr"> 60 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> +<span id="L61" class="LineNr"> 61 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Delimiter">}</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L64" class="LineNr"> 64 </span><span class="Delimiter">}</span> +<span id="L65" class="LineNr"> 65 </span> +<span id="L66" class="LineNr"> 66 </span><span class="Delimiter">:(code)</span> +<span id="L67" class="LineNr"> 67 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L67'>test_je_disp32_fail</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L68" class="LineNr"> 68 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L69" class="LineNr"> 69 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Constant">" 0f 84 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Delimiter">);</span> +<span id="L76" class="LineNr"> 76 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Constant">"run: 0x00000007 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Delimiter">);</span> +<span id="L81" class="LineNr"> 81 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: jump 5"</span><span class="Delimiter">);</span> +<span id="L82" class="LineNr"> 82 </span><span class="Delimiter">}</span> +<span id="L83" class="LineNr"> 83 </span> +<span id="L84" class="LineNr"> 84 </span><span class="Comment">//:: jump if not equal/not zero</span> +<span id="L85" class="LineNr"> 85 </span> +<span id="L86" class="LineNr"> 86 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L87" class="LineNr"> 87 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"85"</span><span class="Delimiter">,</span> <span class="Constant">"jump <a href='040tests.cc.html#L82'>disp32</a> bytes away if not equal, if <a href='010vm.cc.html#L89'>ZF</a> is not set (jcc/jnz/jne)"</span><span class="Delimiter">);</span> +<span id="L88" class="LineNr"> 88 </span> +<span id="L89" class="LineNr"> 89 </span><span class="Delimiter">:(code)</span> +<span id="L90" class="LineNr"> 90 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L90'>test_jne_disp32_success</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L91" class="LineNr"> 91 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L92" class="LineNr"> 92 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Constant">" 0f 85 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Delimiter">);</span> +<span id="L99" class="LineNr"> 99 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L100" class="LineNr">100 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L101" class="LineNr">101 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L102" class="LineNr">102 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L103" class="LineNr">103 </span> <span class="Delimiter">);</span> +<span id="L104" class="LineNr">104 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000007 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L105" class="LineNr">105 </span><span class="Delimiter">}</span> +<span id="L106" class="LineNr">106 </span> +<span id="L107" class="LineNr">107 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L108" class="LineNr">108 </span><span class="Normal">case</span> <span class="Constant">0x85</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if !ZF</span> +<span id="L109" class="LineNr">109 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L110" class="LineNr">110 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!ZF<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L111" class="LineNr">111 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> +<span id="L112" class="LineNr">112 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L113" class="LineNr">113 </span> <span class="Delimiter">}</span> +<span id="L114" class="LineNr">114 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L115" class="LineNr">115 </span><span class="Delimiter">}</span> +<span id="L116" class="LineNr">116 </span> +<span id="L117" class="LineNr">117 </span><span class="Delimiter">:(code)</span> +<span id="L118" class="LineNr">118 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L118'>test_jne_disp32_fail</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L119" class="LineNr">119 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L120" class="LineNr">120 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L121" class="LineNr">121 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L122" class="LineNr">122 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L123" class="LineNr">123 </span> <span class="Constant">" 0f 85 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L124" class="LineNr">124 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L125" class="LineNr">125 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L126" class="LineNr">126 </span> <span class="Delimiter">);</span> +<span id="L127" class="LineNr">127 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L128" class="LineNr">128 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L129" class="LineNr">129 </span> <span class="Constant">"run: 0x00000007 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L130" class="LineNr">130 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L131" class="LineNr">131 </span> <span class="Delimiter">);</span> +<span id="L132" class="LineNr">132 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: jump 5"</span><span class="Delimiter">);</span> +<span id="L133" class="LineNr">133 </span><span class="Delimiter">}</span> +<span id="L134" class="LineNr">134 </span> +<span id="L135" class="LineNr">135 </span><span class="Comment">//:: jump if greater</span> +<span id="L136" class="LineNr">136 </span> +<span id="L137" class="LineNr">137 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L138" class="LineNr">138 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"8f"</span><span class="Delimiter">,</span> <span class="Constant">"jump <a href='040tests.cc.html#L82'>disp32</a> bytes away if greater, if <a href='010vm.cc.html#L89'>ZF</a> is unset and SF == <a href='010vm.cc.html#L91'>OF</a> (jcc/jg/jnle)"</span><span class="Delimiter">);</span> +<span id="L139" class="LineNr">139 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"87"</span><span class="Delimiter">,</span> <span class="Constant">"jump <a href='040tests.cc.html#L82'>disp32</a> bytes away if greater (addr, float), if <a href='010vm.cc.html#L89'>ZF</a> is unset and <a href='010vm.cc.html#L90'>CF</a> is unset (jcc/ja/jnbe)"</span><span class="Delimiter">);</span> +<span id="L140" class="LineNr">140 </span> +<span id="L141" class="LineNr">141 </span><span class="Delimiter">:(code)</span> +<span id="L142" class="LineNr">142 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L142'>test_jg_disp32_success</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L143" class="LineNr">143 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L144" class="LineNr">144 </span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L145" class="LineNr">145 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L146" class="LineNr">146 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L147" class="LineNr">147 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L148" class="LineNr">148 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L149" class="LineNr">149 </span> <span class="Constant">" 0f 8f 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L150" class="LineNr">150 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L151" class="LineNr">151 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L152" class="LineNr">152 </span> <span class="Delimiter">);</span> +<span id="L153" class="LineNr">153 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L154" class="LineNr">154 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L155" class="LineNr">155 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L156" class="LineNr">156 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L157" class="LineNr">157 </span> <span class="Delimiter">);</span> +<span id="L158" class="LineNr">158 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000007 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L159" class="LineNr">159 </span><span class="Delimiter">}</span> +<span id="L160" class="LineNr">160 </span> +<span id="L161" class="LineNr">161 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L162" class="LineNr">162 </span><span class="Normal">case</span> <span class="Constant">0x8f</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if !SF and !ZF</span> +<span id="L163" class="LineNr">163 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L164" class="LineNr">164 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!ZF && SF == <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L165" class="LineNr">165 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> +<span id="L166" class="LineNr">166 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L167" class="LineNr">167 </span> <span class="Delimiter">}</span> +<span id="L168" class="LineNr">168 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L169" class="LineNr">169 </span><span class="Delimiter">}</span> +<span id="L170" class="LineNr">170 </span><span class="Normal">case</span> <span class="Constant">0x87</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if !CF and !ZF</span> +<span id="L171" class="LineNr">171 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L172" class="LineNr">172 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!CF && !ZF<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L173" class="LineNr">173 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> +<span id="L174" class="LineNr">174 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L175" class="LineNr">175 </span> <span class="Delimiter">}</span> +<span id="L176" class="LineNr">176 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L177" class="LineNr">177 </span><span class="Delimiter">}</span> +<span id="L178" class="LineNr">178 </span> +<span id="L179" class="LineNr">179 </span><span class="Delimiter">:(code)</span> +<span id="L180" class="LineNr">180 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L180'>test_jg_disp32_fail</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L181" class="LineNr">181 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L182" class="LineNr">182 </span> SF = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L183" class="LineNr">183 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L184" class="LineNr">184 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L185" class="LineNr">185 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L186" class="LineNr">186 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L187" class="LineNr">187 </span> <span class="Constant">" 0f 8f 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L188" class="LineNr">188 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L189" class="LineNr">189 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L190" class="LineNr">190 </span> <span class="Delimiter">);</span> +<span id="L191" class="LineNr">191 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L192" class="LineNr">192 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L193" class="LineNr">193 </span> <span class="Constant">"run: 0x00000007 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L194" class="LineNr">194 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L195" class="LineNr">195 </span> <span class="Delimiter">);</span> +<span id="L196" class="LineNr">196 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: jump 5"</span><span class="Delimiter">);</span> +<span id="L197" class="LineNr">197 </span><span class="Delimiter">}</span> +<span id="L198" class="LineNr">198 </span> +<span id="L199" class="LineNr">199 </span><span class="Comment">//:: jump if greater or equal</span> +<span id="L200" class="LineNr">200 </span> +<span id="L201" class="LineNr">201 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L202" class="LineNr">202 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"8d"</span><span class="Delimiter">,</span> <span class="Constant">"jump <a href='040tests.cc.html#L82'>disp32</a> bytes away if greater or equal, if SF == <a href='010vm.cc.html#L91'>OF</a> (jcc/jge/jnl)"</span><span class="Delimiter">);</span> +<span id="L203" class="LineNr">203 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"83"</span><span class="Delimiter">,</span> <span class="Constant">"jump <a href='040tests.cc.html#L82'>disp32</a> bytes away if greater or equal (addr, float), if <a href='010vm.cc.html#L90'>CF</a> is unset (jcc/jae/jnb)"</span><span class="Delimiter">);</span> +<span id="L204" class="LineNr">204 </span> +<span id="L205" class="LineNr">205 </span><span class="Delimiter">:(code)</span> +<span id="L206" class="LineNr">206 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L206'>test_jge_disp32_success</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L207" class="LineNr">207 </span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L208" class="LineNr">208 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L209" class="LineNr">209 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L210" class="LineNr">210 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L211" class="LineNr">211 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L212" class="LineNr">212 </span> <span class="Constant">" 0f 8d 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L213" class="LineNr">213 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L214" class="LineNr">214 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L215" class="LineNr">215 </span> <span class="Delimiter">);</span> +<span id="L216" class="LineNr">216 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L217" class="LineNr">217 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L218" class="LineNr">218 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L219" class="LineNr">219 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L220" class="LineNr">220 </span> <span class="Delimiter">);</span> +<span id="L221" class="LineNr">221 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000007 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L222" class="LineNr">222 </span><span class="Delimiter">}</span> +<span id="L223" class="LineNr">223 </span> +<span id="L224" class="LineNr">224 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L225" class="LineNr">225 </span><span class="Normal">case</span> <span class="Constant">0x8d</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if !SF</span> +<span id="L226" class="LineNr">226 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L227" class="LineNr">227 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>SF == <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L228" class="LineNr">228 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> +<span id="L229" class="LineNr">229 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L230" class="LineNr">230 </span> <span class="Delimiter">}</span> +<span id="L231" class="LineNr">231 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L232" class="LineNr">232 </span><span class="Delimiter">}</span> +<span id="L233" class="LineNr">233 </span><span class="Normal">case</span> <span class="Constant">0x83</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if !CF</span> +<span id="L234" class="LineNr">234 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L235" class="LineNr">235 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!CF<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L236" class="LineNr">236 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> +<span id="L237" class="LineNr">237 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L238" class="LineNr">238 </span> <span class="Delimiter">}</span> +<span id="L239" class="LineNr">239 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L240" class="LineNr">240 </span><span class="Delimiter">}</span> +<span id="L241" class="LineNr">241 </span> +<span id="L242" class="LineNr">242 </span><span class="Delimiter">:(code)</span> +<span id="L243" class="LineNr">243 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L243'>test_jge_disp32_fail</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L244" class="LineNr">244 </span> SF = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L245" class="LineNr">245 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L246" class="LineNr">246 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L247" class="LineNr">247 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L248" class="LineNr">248 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L249" class="LineNr">249 </span> <span class="Constant">" 0f 8d 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L250" class="LineNr">250 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L251" class="LineNr">251 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L252" class="LineNr">252 </span> <span class="Delimiter">);</span> +<span id="L253" class="LineNr">253 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L254" class="LineNr">254 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L255" class="LineNr">255 </span> <span class="Constant">"run: 0x00000007 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L256" class="LineNr">256 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L257" class="LineNr">257 </span> <span class="Delimiter">);</span> +<span id="L258" class="LineNr">258 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: jump 5"</span><span class="Delimiter">);</span> +<span id="L259" class="LineNr">259 </span><span class="Delimiter">}</span> +<span id="L260" class="LineNr">260 </span> +<span id="L261" class="LineNr">261 </span><span class="Comment">//:: jump if lesser</span> +<span id="L262" class="LineNr">262 </span> +<span id="L263" class="LineNr">263 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L264" class="LineNr">264 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"8c"</span><span class="Delimiter">,</span> <span class="Constant">"jump <a href='040tests.cc.html#L82'>disp32</a> bytes away if lesser, if SF != <a href='010vm.cc.html#L91'>OF</a> (jcc/jl/jnge)"</span><span class="Delimiter">);</span> +<span id="L265" class="LineNr">265 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"82"</span><span class="Delimiter">,</span> <span class="Constant">"jump <a href='040tests.cc.html#L82'>disp32</a> bytes away if lesser (addr, float), if <a href='010vm.cc.html#L90'>CF</a> is set (jcc/jb/jnae)"</span><span class="Delimiter">);</span> +<span id="L266" class="LineNr">266 </span> +<span id="L267" class="LineNr">267 </span><span class="Delimiter">:(code)</span> +<span id="L268" class="LineNr">268 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L268'>test_jl_disp32_success</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L269" class="LineNr">269 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L270" class="LineNr">270 </span> SF = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L271" class="LineNr">271 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L272" class="LineNr">272 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L273" class="LineNr">273 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L274" class="LineNr">274 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L275" class="LineNr">275 </span> <span class="Constant">" 0f 8c 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L276" class="LineNr">276 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L277" class="LineNr">277 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L278" class="LineNr">278 </span> <span class="Delimiter">);</span> +<span id="L279" class="LineNr">279 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L280" class="LineNr">280 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L281" class="LineNr">281 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L282" class="LineNr">282 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L283" class="LineNr">283 </span> <span class="Delimiter">);</span> +<span id="L284" class="LineNr">284 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000007 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L285" class="LineNr">285 </span><span class="Delimiter">}</span> +<span id="L286" class="LineNr">286 </span> +<span id="L287" class="LineNr">287 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L288" class="LineNr">288 </span><span class="Normal">case</span> <span class="Constant">0x8c</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if SF and !ZF</span> +<span id="L289" class="LineNr">289 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L290" class="LineNr">290 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>SF != <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L291" class="LineNr">291 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> +<span id="L292" class="LineNr">292 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L293" class="LineNr">293 </span> <span class="Delimiter">}</span> +<span id="L294" class="LineNr">294 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L295" class="LineNr">295 </span><span class="Delimiter">}</span> +<span id="L296" class="LineNr">296 </span><span class="Normal">case</span> <span class="Constant">0x82</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if CF</span> +<span id="L297" class="LineNr">297 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L298" class="LineNr">298 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L90'>CF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L299" class="LineNr">299 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> +<span id="L300" class="LineNr">300 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L301" class="LineNr">301 </span> <span class="Delimiter">}</span> +<span id="L302" class="LineNr">302 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L303" class="LineNr">303 </span><span class="Delimiter">}</span> +<span id="L304" class="LineNr">304 </span> +<span id="L305" class="LineNr">305 </span><span class="Delimiter">:(code)</span> +<span id="L306" class="LineNr">306 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L306'>test_jl_disp32_fail</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L307" class="LineNr">307 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L308" class="LineNr">308 </span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L309" class="LineNr">309 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L310" class="LineNr">310 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L311" class="LineNr">311 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L312" class="LineNr">312 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L313" class="LineNr">313 </span> <span class="Constant">" 0f 8c 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L314" class="LineNr">314 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L315" class="LineNr">315 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L316" class="LineNr">316 </span> <span class="Delimiter">);</span> +<span id="L317" class="LineNr">317 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L318" class="LineNr">318 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L319" class="LineNr">319 </span> <span class="Constant">"run: 0x00000007 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L320" class="LineNr">320 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L321" class="LineNr">321 </span> <span class="Delimiter">);</span> +<span id="L322" class="LineNr">322 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: jump 5"</span><span class="Delimiter">);</span> +<span id="L323" class="LineNr">323 </span><span class="Delimiter">}</span> +<span id="L324" class="LineNr">324 </span> +<span id="L325" class="LineNr">325 </span><span class="Comment">//:: jump if lesser or equal</span> +<span id="L326" class="LineNr">326 </span> +<span id="L327" class="LineNr">327 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L328" class="LineNr">328 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"8e"</span><span class="Delimiter">,</span> <span class="Constant">"jump <a href='040tests.cc.html#L82'>disp32</a> bytes away if lesser or equal, if <a href='010vm.cc.html#L89'>ZF</a> is set or SF != <a href='010vm.cc.html#L91'>OF</a> (jcc/jle/jng)"</span><span class="Delimiter">);</span> +<span id="L329" class="LineNr">329 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"86"</span><span class="Delimiter">,</span> <span class="Constant">"jump <a href='040tests.cc.html#L82'>disp32</a> bytes away if lesser or equal (addr, float), if <a href='010vm.cc.html#L89'>ZF</a> is set or <a href='010vm.cc.html#L90'>CF</a> is set (jcc/jbe/jna)"</span><span class="Delimiter">);</span> +<span id="L330" class="LineNr">330 </span> +<span id="L331" class="LineNr">331 </span><span class="Delimiter">:(code)</span> +<span id="L332" class="LineNr">332 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L332'>test_jle_disp32_equal</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L333" class="LineNr">333 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L334" class="LineNr">334 </span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L335" class="LineNr">335 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L336" class="LineNr">336 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L337" class="LineNr">337 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L338" class="LineNr">338 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L339" class="LineNr">339 </span> <span class="Constant">" 0f 8e 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L340" class="LineNr">340 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L341" class="LineNr">341 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L342" class="LineNr">342 </span> <span class="Delimiter">);</span> +<span id="L343" class="LineNr">343 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L344" class="LineNr">344 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L345" class="LineNr">345 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L346" class="LineNr">346 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L347" class="LineNr">347 </span> <span class="Delimiter">);</span> +<span id="L348" class="LineNr">348 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000007 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L349" class="LineNr">349 </span><span class="Delimiter">}</span> +<span id="L350" class="LineNr">350 </span> +<span id="L351" class="LineNr">351 </span><span class="Delimiter">:(code)</span> +<span id="L352" class="LineNr">352 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L352'>test_jle_disp32_lesser</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L353" class="LineNr">353 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L354" class="LineNr">354 </span> SF = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L355" class="LineNr">355 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L356" class="LineNr">356 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L357" class="LineNr">357 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L358" class="LineNr">358 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L359" class="LineNr">359 </span> <span class="Constant">" 0f 8e 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L360" class="LineNr">360 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L361" class="LineNr">361 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L362" class="LineNr">362 </span> <span class="Delimiter">);</span> +<span id="L363" class="LineNr">363 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L364" class="LineNr">364 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L365" class="LineNr">365 </span> <span class="Constant">"run: jump 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L366" class="LineNr">366 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L367" class="LineNr">367 </span> <span class="Delimiter">);</span> +<span id="L368" class="LineNr">368 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000007 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L369" class="LineNr">369 </span><span class="Delimiter">}</span> +<span id="L370" class="LineNr">370 </span> +<span id="L371" class="LineNr">371 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L372" class="LineNr">372 </span><span class="Normal">case</span> <span class="Constant">0x8e</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if SF or ZF</span> +<span id="L373" class="LineNr">373 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L374" class="LineNr">374 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L89'>ZF</a> || SF != <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L375" class="LineNr">375 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> +<span id="L376" class="LineNr">376 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L377" class="LineNr">377 </span> <span class="Delimiter">}</span> +<span id="L378" class="LineNr">378 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L379" class="LineNr">379 </span><span class="Delimiter">}</span> +<span id="L380" class="LineNr">380 </span><span class="Normal">case</span> <span class="Constant">0x86</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if ZF or CF</span> +<span id="L381" class="LineNr">381 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L382" class="LineNr">382 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010vm.cc.html#L89'>ZF</a> || <a href='010vm.cc.html#L90'>CF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L383" class="LineNr">383 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> +<span id="L384" class="LineNr">384 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L385" class="LineNr">385 </span> <span class="Delimiter">}</span> +<span id="L386" class="LineNr">386 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L387" class="LineNr">387 </span><span class="Delimiter">}</span> +<span id="L388" class="LineNr">388 </span> +<span id="L389" class="LineNr">389 </span><span class="Delimiter">:(code)</span> +<span id="L390" class="LineNr">390 </span><span class="Normal">void</span> <a href='018jump_disp32.cc.html#L390'>test_jle_disp32_greater</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L391" class="LineNr">391 </span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L392" class="LineNr">392 </span> SF = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L393" class="LineNr">393 </span> <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L394" class="LineNr">394 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L395" class="LineNr">395 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L396" class="LineNr">396 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L397" class="LineNr">397 </span> <span class="Constant">" 0f 8e 05 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// skip 1 instruction</span> +<span id="L398" class="LineNr">398 </span> <span class="Constant">" 05 00 00 00 01 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L399" class="LineNr">399 </span> <span class="Constant">" 05 00 00 00 02 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L400" class="LineNr">400 </span> <span class="Delimiter">);</span> +<span id="L401" class="LineNr">401 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L402" class="LineNr">402 </span> <span class="Constant">"run: 0x00000001 opcode: 0f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L403" class="LineNr">403 </span> <span class="Constant">"run: 0x00000007 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L404" class="LineNr">404 </span> <span class="Constant">"run: 0x0000000c opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L405" class="LineNr">405 </span> <span class="Delimiter">);</span> +<span id="L406" class="LineNr">406 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: jump 5"</span><span class="Delimiter">);</span> +<span id="L407" class="LineNr">407 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/019functions.cc.html b/html/linux/bootstrap/019functions.cc.html new file mode 100644 index 00000000..4ae8357c --- /dev/null +++ b/html/linux/bootstrap/019functions.cc.html @@ -0,0 +1,185 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/019functions.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.LineNr { } +.Constant { color: #008787; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.CommentedCode { color: #8a8a8a; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/019functions.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/019functions.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//:: call</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L4" class="LineNr"> 4 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"e8"</span><span class="Delimiter">,</span> <span class="Constant">"call <a href='040tests.cc.html#L82'>disp32</a> (call)"</span><span class="Delimiter">);</span> +<span id="L5" class="LineNr"> 5 </span> +<span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(code)</span> +<span id="L7" class="LineNr"> 7 </span><span class="Normal">void</span> <a href='019functions.cc.html#L7'>test_call_disp32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L8" class="LineNr"> 8 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><span class="Constant">0xbd000000</span><span class="Delimiter">));</span> <span class="Comment">// manually allocate memory</span> +<span id="L9" class="LineNr"> 9 </span> Reg[ESP]<span class="Delimiter">.</span>u = <span class="Constant">0xbd000064</span><span class="Delimiter">;</span> +<span id="L10" class="LineNr"> 10 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Constant">" e8 a0 00 00 00 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// call function offset at 0xa0</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Comment">// next EIP is 6</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Delimiter">);</span> +<span id="L16" class="LineNr"> 16 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Constant">"run: call imm32 0x000000a0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"run: decrementing <a href='010vm.cc.html#L14'>ESP</a> to 0xbd000060</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"run: pushing value 0x00000006</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"run: jumping to 0x000000a6</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Delimiter">);</span> +<span id="L22" class="LineNr"> 22 </span><span class="Delimiter">}</span> +<span id="L23" class="LineNr"> 23 </span> +<span id="L24" class="LineNr"> 24 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L25" class="LineNr"> 25 </span><span class="Normal">case</span> <span class="Constant">0xe8</span>: <span class="Delimiter">{</span> <span class="Comment">// call disp32 relative to next EIP</span> +<span id="L26" class="LineNr"> 26 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L433'>next32</a><span class="Delimiter">();</span> +<span id="L27" class="LineNr"> 27 </span> ++Callstack_depth<span class="Delimiter">;</span> +<span id="L28" class="LineNr"> 28 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"call imm32 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << offset << end<span class="Delimiter">();</span> +<span id="L29" class="LineNr"> 29 </span><span class="CommentedCode">//? cerr << "push: EIP: " << EIP << " => " << Reg[ESP].u << '\n';</span> +<span id="L30" class="LineNr"> 30 </span> <a href='012elf.cc.html#L94'>push</a><span class="Delimiter">(</span><a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">);</span> +<span id="L31" class="LineNr"> 31 </span> <a href='010vm.cc.html#L26'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L32" class="LineNr"> 32 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L26'>EIP</a> << end<span class="Delimiter">();</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L34" class="LineNr"> 34 </span><span class="Delimiter">}</span> +<span id="L35" class="LineNr"> 35 </span> +<span id="L36" class="LineNr"> 36 </span><span class="Comment">//:</span> +<span id="L37" class="LineNr"> 37 </span> +<span id="L38" class="LineNr"> 38 </span><span class="Delimiter">:(code)</span> +<span id="L39" class="LineNr"> 39 </span><span class="Normal">void</span> <a href='019functions.cc.html#L39'>test_call_r32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L40" class="LineNr"> 40 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><span class="Constant">0xbd000000</span><span class="Delimiter">));</span> <span class="Comment">// manually allocate memory</span> +<span id="L41" class="LineNr"> 41 </span> Reg[ESP]<span class="Delimiter">.</span>u = <span class="Constant">0xbd000064</span><span class="Delimiter">;</span> +<span id="L42" class="LineNr"> 42 </span> Reg[EBX]<span class="Delimiter">.</span>u = <span class="Constant">0x000000a0</span><span class="Delimiter">;</span> +<span id="L43" class="LineNr"> 43 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Constant">" ff d3 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// call function offset at EBX</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Comment">// next EIP is 3</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Delimiter">);</span> +<span id="L49" class="LineNr"> 49 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Constant">"run: call to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Constant">"run: decrementing <a href='010vm.cc.html#L14'>ESP</a> to 0xbd000060</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Constant">"run: pushing value 0x00000003</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Constant">"run: jumping to 0x000000a0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L55" class="LineNr"> 55 </span> <span class="Delimiter">);</span> +<span id="L56" class="LineNr"> 56 </span><span class="Delimiter">}</span> +<span id="L57" class="LineNr"> 57 </span> +<span id="L58" class="LineNr"> 58 </span><span class="Delimiter">:(before "End Op ff Subops")</span> +<span id="L59" class="LineNr"> 59 </span><span class="Normal">case</span> <span class="Constant">2</span>: <span class="Delimiter">{</span> <span class="Comment">// call function pointer at r/m32</span> +<span id="L60" class="LineNr"> 60 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"call to r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* offset = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L62" class="LineNr"> 62 </span> <a href='012elf.cc.html#L94'>push</a><span class="Delimiter">(</span><a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">);</span> +<span id="L63" class="LineNr"> 63 </span> <a href='010vm.cc.html#L26'>EIP</a> = *offset<span class="Delimiter">;</span> +<span id="L64" class="LineNr"> 64 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L26'>EIP</a> << end<span class="Delimiter">();</span> +<span id="L65" class="LineNr"> 65 </span> ++Callstack_depth<span class="Delimiter">;</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L67" class="LineNr"> 67 </span><span class="Delimiter">}</span> +<span id="L68" class="LineNr"> 68 </span> +<span id="L69" class="LineNr"> 69 </span><span class="Delimiter">:(code)</span> +<span id="L70" class="LineNr"> 70 </span><span class="Normal">void</span> <a href='019functions.cc.html#L70'>test_call_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L71" class="LineNr"> 71 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><span class="Constant">0xbd000000</span><span class="Delimiter">));</span> <span class="Comment">// manually allocate memory</span> +<span id="L72" class="LineNr"> 72 </span> Reg[ESP]<span class="Delimiter">.</span>u = <span class="Constant">0xbd000064</span><span class="Delimiter">;</span> +<span id="L73" class="LineNr"> 73 </span> Reg[EBX]<span class="Delimiter">.</span>u = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L74" class="LineNr"> 74 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L76" class="LineNr"> 76 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Constant">" ff 13 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// call function offset at *EBX</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Comment">// next EIP is 3</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Constant">"a0 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0xa0</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Delimiter">);</span> +<span id="L82" class="LineNr"> 82 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Constant">"run: call to r/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L13'>EBX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Constant">"run: decrementing <a href='010vm.cc.html#L14'>ESP</a> to 0xbd000060</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Constant">"run: pushing value 0x00000003</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Constant">"run: jumping to 0x000000a0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Delimiter">);</span> +<span id="L89" class="LineNr"> 89 </span><span class="Delimiter">}</span> +<span id="L90" class="LineNr"> 90 </span> +<span id="L91" class="LineNr"> 91 </span><span class="Comment">//:: ret</span> +<span id="L92" class="LineNr"> 92 </span> +<span id="L93" class="LineNr"> 93 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L94" class="LineNr"> 94 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"c3"</span><span class="Delimiter">,</span> <span class="Constant">"return from most recent unfinished call (<a href='040tests.cc.html#L89'>ret</a>)"</span><span class="Delimiter">);</span> +<span id="L95" class="LineNr"> 95 </span> +<span id="L96" class="LineNr"> 96 </span><span class="Delimiter">:(code)</span> +<span id="L97" class="LineNr"> 97 </span><span class="Normal">void</span> <a href='019functions.cc.html#L97'>test_ret</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L98" class="LineNr"> 98 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><span class="Constant">0xbd000000</span><span class="Delimiter">));</span> <span class="Comment">// manually allocate memory</span> +<span id="L99" class="LineNr"> 99 </span> Reg[ESP]<span class="Delimiter">.</span>u = <span class="Constant">0xbd000064</span><span class="Delimiter">;</span> +<span id="L100" class="LineNr">100 </span> <a href='010vm.cc.html#L252'>write_mem_u32</a><span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L101" class="LineNr">101 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L102" class="LineNr">102 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L103" class="LineNr">103 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L104" class="LineNr">104 </span> <span class="Constant">" c3 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// return</span> +<span id="L105" class="LineNr">105 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L106" class="LineNr">106 </span> <span class="Constant">"10 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x10</span> +<span id="L107" class="LineNr">107 </span> <span class="Delimiter">);</span> +<span id="L108" class="LineNr">108 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L109" class="LineNr">109 </span> <span class="Constant">"run: return</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L110" class="LineNr">110 </span> <span class="Constant">"run: popping value 0x00000010</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L111" class="LineNr">111 </span> <span class="Constant">"run: jumping to 0x00000010</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L112" class="LineNr">112 </span> <span class="Delimiter">);</span> +<span id="L113" class="LineNr">113 </span><span class="Delimiter">}</span> +<span id="L114" class="LineNr">114 </span> +<span id="L115" class="LineNr">115 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L116" class="LineNr">116 </span><span class="Normal">case</span> <span class="Constant">0xc3</span>: <span class="Delimiter">{</span> <span class="Comment">// return from a call</span> +<span id="L117" class="LineNr">117 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"return"</span> << end<span class="Delimiter">();</span> +<span id="L118" class="LineNr">118 </span> --Callstack_depth<span class="Delimiter">;</span> +<span id="L119" class="LineNr">119 </span> <a href='010vm.cc.html#L26'>EIP</a> = <a href='013direct_addressing.cc.html#L1270'>pop</a><span class="Delimiter">();</span> +<span id="L120" class="LineNr">120 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L26'>EIP</a> << end<span class="Delimiter">();</span> +<span id="L121" class="LineNr">121 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L122" class="LineNr">122 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/020byte_addressing.cc.html b/html/linux/bootstrap/020byte_addressing.cc.html new file mode 100644 index 00000000..85c86edb --- /dev/null +++ b/html/linux/bootstrap/020byte_addressing.cc.html @@ -0,0 +1,334 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/020byte_addressing.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/020byte_addressing.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/020byte_addressing.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: SubX mostly deals with instructions operating on 32-bit operands, but we</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: still need to deal with raw bytes for strings and so on.</span> +<span id="L3" class="LineNr"> 3 </span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: Unfortunately the register encodings when dealing with bytes are a mess.</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: We need a special case for them.</span> +<span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(code)</span> +<span id="L7" class="LineNr"> 7 </span>string <a href='020byte_addressing.cc.html#L7'>rname_8bit</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Normal">case</span> <span class="Constant">0</span>: <span class="Identifier">return</span> <span class="Constant">"AL"</span><span class="Delimiter">;</span> <span class="Comment">// lowest byte of EAX</span> +<span id="L10" class="LineNr"> 10 </span> <span class="Normal">case</span> <span class="Constant">1</span>: <span class="Identifier">return</span> <span class="Constant">"CL"</span><span class="Delimiter">;</span> <span class="Comment">// lowest byte of ECX</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Normal">case</span> <span class="Constant">2</span>: <span class="Identifier">return</span> <span class="Constant">"DL"</span><span class="Delimiter">;</span> <span class="Comment">// lowest byte of EDX</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Normal">case</span> <span class="Constant">3</span>: <span class="Identifier">return</span> <span class="Constant">"BL"</span><span class="Delimiter">;</span> <span class="Comment">// lowest byte of EBX</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Normal">case</span> <span class="Constant">4</span>: <span class="Identifier">return</span> <span class="Constant">"AH"</span><span class="Delimiter">;</span> <span class="Comment">// second lowest byte of EAX</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Normal">case</span> <span class="Constant">5</span>: <span class="Identifier">return</span> <span class="Constant">"CH"</span><span class="Delimiter">;</span> <span class="Comment">// second lowest byte of ECX</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Normal">case</span> <span class="Constant">6</span>: <span class="Identifier">return</span> <span class="Constant">"DH"</span><span class="Delimiter">;</span> <span class="Comment">// second lowest byte of EDX</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Normal">case</span> <span class="Constant">7</span>: <span class="Identifier">return</span> <span class="Constant">"BH"</span><span class="Delimiter">;</span> <span class="Comment">// second lowest byte of EBX</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Normal">default</span>: <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"invalid 8-bit register "</span> << r << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Delimiter">}</span> +<span id="L19" class="LineNr"> 19 </span><span class="Delimiter">}</span> +<span id="L20" class="LineNr"> 20 </span> +<span id="L21" class="LineNr"> 21 </span><span class="Normal">uint8_t</span>* <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> modrm<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L22" class="LineNr"> 22 </span> <span class="Normal">uint8_t</span> mod = <span class="Delimiter">(</span>modrm>><span class="Constant">6</span><span class="Delimiter">);</span> +<span id="L23" class="LineNr"> 23 </span> <span class="Normal">uint8_t</span> rm = modrm & <span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod == <span class="Constant">3</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Comment">// select an 8-bit register</span> +<span id="L26" class="LineNr"> 26 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"r/m8 is "</span> << <a href='020byte_addressing.cc.html#L7'>rname_8bit</a><span class="Delimiter">(</span>rm<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Identifier">return</span> <a href='020byte_addressing.cc.html#L33'>reg_8bit</a><span class="Delimiter">(</span>rm<span class="Delimiter">);</span> +<span id="L28" class="LineNr"> 28 </span> <span class="Delimiter">}</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Comment">// the rest is as usual</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Identifier">return</span> <a href='010vm.cc.html#L192'>mem_addr_u8</a><span class="Delimiter">(</span><a href='013direct_addressing.cc.html#L116'>effective_address_number</a><span class="Delimiter">(</span>modrm<span class="Delimiter">));</span> +<span id="L31" class="LineNr"> 31 </span><span class="Delimiter">}</span> +<span id="L32" class="LineNr"> 32 </span> +<span id="L33" class="LineNr"> 33 </span><span class="Normal">uint8_t</span>* <a href='020byte_addressing.cc.html#L33'>reg_8bit</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> rm<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Normal">uint8_t</span>* result = <span class="Normal">reinterpret_cast</span><<span class="Normal">uint8_t</span>*><span class="Delimiter">(</span>&Reg[rm & <span class="Constant">0x3</span>]<span class="Delimiter">.</span>i<span class="Delimiter">);</span> <span class="Comment">// _L register</span> +<span id="L35" class="LineNr"> 35 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>rm & <span class="Constant">0x4</span><span class="Delimiter">)</span> +<span id="L36" class="LineNr"> 36 </span> ++result<span class="Delimiter">;</span> <span class="Comment">// _H register; assumes host is little-endian</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L38" class="LineNr"> 38 </span><span class="Delimiter">}</span> +<span id="L39" class="LineNr"> 39 </span> +<span id="L40" class="LineNr"> 40 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L41" class="LineNr"> 41 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"88"</span><span class="Delimiter">,</span> <span class="Constant">"copy r8 to r8/m8-at-r32"</span><span class="Delimiter">);</span> +<span id="L42" class="LineNr"> 42 </span> +<span id="L43" class="LineNr"> 43 </span><span class="Delimiter">:(code)</span> +<span id="L44" class="LineNr"> 44 </span><span class="Normal">void</span> <a href='020byte_addressing.cc.html#L44'>test_copy_r8_to_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L45" class="LineNr"> 45 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0x224488ab</span><span class="Delimiter">;</span> +<span id="L46" class="LineNr"> 46 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L47" class="LineNr"> 47 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Constant">" 88 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy BL to the byte at *EAX</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src BL) 000 (dest EAX)</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Constant">"f0 cc bb aa</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Delimiter">);</span> +<span id="L55" class="LineNr"> 55 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Constant">"run: copy BL to r8/m8-at-r32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Constant">"run: storing 0xab</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Delimiter">);</span> +<span id="L60" class="LineNr"> 60 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><span class="Constant">0xaabbccab</span><span class="Delimiter">,</span> <a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span><span class="Constant">0x2000</span><span class="Delimiter">));</span> +<span id="L61" class="LineNr"> 61 </span><span class="Delimiter">}</span> +<span id="L62" class="LineNr"> 62 </span> +<span id="L63" class="LineNr"> 63 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L64" class="LineNr"> 64 </span><span class="Normal">case</span> <span class="Constant">0x88</span>: <span class="Delimiter">{</span> <span class="Comment">// copy r8 to r/m8</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rsrc = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L67" class="LineNr"> 67 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy "</span> << <a href='020byte_addressing.cc.html#L7'>rname_8bit</a><span class="Delimiter">(</span>rsrc<span class="Delimiter">)</span> << <span class="Constant">" to r8/m8-at-r32"</span> << end<span class="Delimiter">();</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Comment">// use unsigned to zero-extend 8-bit value to 32 bits</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span>* src = <a href='020byte_addressing.cc.html#L33'>reg_8bit</a><span class="Delimiter">(</span>rsrc<span class="Delimiter">);</span> +<span id="L71" class="LineNr"> 71 </span> *dest = *src<span class="Delimiter">;</span> <span class="Comment">// Read/write multiple elements of vector<uint8_t> at once. Assumes sizeof(int) == 4 on the host as well.</span> +<span id="L72" class="LineNr"> 72 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L74" class="LineNr"> 74 </span><span class="Delimiter">}</span> +<span id="L75" class="LineNr"> 75 </span> +<span id="L76" class="LineNr"> 76 </span><span class="Comment">//:</span> +<span id="L77" class="LineNr"> 77 </span> +<span id="L78" class="LineNr"> 78 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L79" class="LineNr"> 79 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"8a"</span><span class="Delimiter">,</span> <span class="Constant">"copy r8/m8-at-r32 to r8"</span><span class="Delimiter">);</span> +<span id="L80" class="LineNr"> 80 </span> +<span id="L81" class="LineNr"> 81 </span><span class="Delimiter">:(code)</span> +<span id="L82" class="LineNr"> 82 </span><span class="Normal">void</span> <a href='020byte_addressing.cc.html#L82'>test_copy_mem_at_rm32_to_r8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L83" class="LineNr"> 83 </span> Reg[EBX]<span class="Delimiter">.</span>i = <span class="Constant">0xaabbcc0f</span><span class="Delimiter">;</span> <span class="Comment">// one nibble each of lowest byte set to all 0s and all 1s, to maximize value of this test</span> +<span id="L84" class="LineNr"> 84 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L85" class="LineNr"> 85 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Constant">" 8a 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy just the byte at *EAX to BL</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (dest EBX) 000 (src EAX)</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Constant">"ab ff ff ff</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0xab with more data in following bytes</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Delimiter">);</span> +<span id="L93" class="LineNr"> 93 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Constant">"run: copy r8/m8-at-r32 to BL</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Constant">"run: storing 0xab</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Comment">// remaining bytes of EBX are *not* cleared</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Constant">"run: <a href='010vm.cc.html#L13'>EBX</a> now contains 0xaabbccab</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L99" class="LineNr"> 99 </span> <span class="Delimiter">);</span> +<span id="L100" class="LineNr">100 </span><span class="Delimiter">}</span> +<span id="L101" class="LineNr">101 </span> +<span id="L102" class="LineNr">102 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L103" class="LineNr">103 </span><span class="Normal">case</span> <span class="Constant">0x8a</span>: <span class="Delimiter">{</span> <span class="Comment">// copy r/m8 to r8</span> +<span id="L104" class="LineNr">104 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L105" class="LineNr">105 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rdest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L106" class="LineNr">106 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy r8/m8-at-r32 to "</span> << <a href='020byte_addressing.cc.html#L7'>rname_8bit</a><span class="Delimiter">(</span>rdest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L107" class="LineNr">107 </span> <span class="Comment">// use unsigned to zero-extend 8-bit value to 32 bits</span> +<span id="L108" class="LineNr">108 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span>* src = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L109" class="LineNr">109 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L33'>reg_8bit</a><span class="Delimiter">(</span>rdest<span class="Delimiter">);</span> +<span id="L110" class="LineNr">110 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*src<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L111" class="LineNr">111 </span> *dest = *src<span class="Delimiter">;</span> <span class="Comment">// Read/write multiple elements of vector<uint8_t> at once. Assumes sizeof(int) == 4 on the host as well.</span> +<span id="L112" class="LineNr">112 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rdest_32bit = rdest & <span class="Constant">0x3</span><span class="Delimiter">;</span> +<span id="L113" class="LineNr">113 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>rdest_32bit<span class="Delimiter">)</span> << <span class="Constant">" now contains 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[rdest_32bit]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L114" class="LineNr">114 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L115" class="LineNr">115 </span><span class="Delimiter">}</span> +<span id="L116" class="LineNr">116 </span> +<span id="L117" class="LineNr">117 </span><span class="Delimiter">:(code)</span> +<span id="L118" class="LineNr">118 </span><span class="Normal">void</span> <a href='020byte_addressing.cc.html#L118'>test_cannot_copy_byte_to_ESP_EBP_ESI_EDI</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L119" class="LineNr">119 </span> Reg[ESI]<span class="Delimiter">.</span>u = <span class="Constant">0xaabbccdd</span><span class="Delimiter">;</span> +<span id="L120" class="LineNr">120 </span> Reg[EBX]<span class="Delimiter">.</span>u = <span class="Constant">0x11223344</span><span class="Delimiter">;</span> +<span id="L121" class="LineNr">121 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L122" class="LineNr">122 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L123" class="LineNr">123 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L124" class="LineNr">124 </span> <span class="Constant">" 8a f3 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy just the byte at *EBX to 8-bit register '6'</span> +<span id="L125" class="LineNr">125 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 110 (dest 8-bit 'register 6') 011 (src EBX)</span> +<span id="L126" class="LineNr">126 </span> <span class="Delimiter">);</span> +<span id="L127" class="LineNr">127 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L128" class="LineNr">128 </span> <span class="Comment">// ensure 8-bit register '6' is DH, not ESI</span> +<span id="L129" class="LineNr">129 </span> <span class="Constant">"run: copy r8/m8-at-r32 to DH</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L130" class="LineNr">130 </span> <span class="Constant">"run: storing 0x44</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L131" class="LineNr">131 </span> <span class="Delimiter">);</span> +<span id="L132" class="LineNr">132 </span> <span class="Comment">// ensure ESI is unchanged</span> +<span id="L133" class="LineNr">133 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>Reg[ESI]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Constant">0xaabbccdd</span><span class="Delimiter">);</span> +<span id="L134" class="LineNr">134 </span><span class="Delimiter">}</span> +<span id="L135" class="LineNr">135 </span> +<span id="L136" class="LineNr">136 </span><span class="Comment">//:</span> +<span id="L137" class="LineNr">137 </span> +<span id="L138" class="LineNr">138 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L139" class="LineNr">139 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"c6"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm8 to r8/m8-at-r32 with subop 0 (mov)"</span><span class="Delimiter">);</span> +<span id="L140" class="LineNr">140 </span> +<span id="L141" class="LineNr">141 </span><span class="Delimiter">:(code)</span> +<span id="L142" class="LineNr">142 </span><span class="Normal">void</span> <a href='020byte_addressing.cc.html#L142'>test_copy_imm8_to_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L143" class="LineNr">143 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L144" class="LineNr">144 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L145" class="LineNr">145 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L146" class="LineNr">146 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L147" class="LineNr">147 </span> <span class="Constant">" c6 00 dd </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy to the byte at *EAX</span> +<span id="L148" class="LineNr">148 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 000 (unused) 000 (dest EAX)</span> +<span id="L149" class="LineNr">149 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L150" class="LineNr">150 </span> <span class="Constant">"f0 cc bb aa</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L151" class="LineNr">151 </span> <span class="Delimiter">);</span> +<span id="L152" class="LineNr">152 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L153" class="LineNr">153 </span> <span class="Constant">"run: copy imm8 to r8/m8-at-r32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L154" class="LineNr">154 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L155" class="LineNr">155 </span> <span class="Constant">"run: storing 0xdd</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L156" class="LineNr">156 </span> <span class="Delimiter">);</span> +<span id="L157" class="LineNr">157 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><span class="Constant">0xaabbccdd</span><span class="Delimiter">,</span> <a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span><span class="Constant">0x2000</span><span class="Delimiter">));</span> +<span id="L158" class="LineNr">158 </span><span class="Delimiter">}</span> +<span id="L159" class="LineNr">159 </span> +<span id="L160" class="LineNr">160 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L161" class="LineNr">161 </span><span class="Normal">case</span> <span class="Constant">0xc6</span>: <span class="Delimiter">{</span> <span class="Comment">// copy imm8 to r/m8</span> +<span id="L162" class="LineNr">162 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L163" class="LineNr">163 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> src = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L164" class="LineNr">164 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy imm8 to r8/m8-at-r32"</span> << end<span class="Delimiter">();</span> +<span id="L165" class="LineNr">165 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"imm8 is 0x"</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>src<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L166" class="LineNr">166 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> subop = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span class="Comment">// middle 3 'reg opcode' bits</span> +<span id="L167" class="LineNr">167 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>subop != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L168" class="LineNr">168 </span> cerr << <span class="Constant">"unrecognized subop for opcode c6: "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="Constant">" (only 0/copy currently implemented)</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L169" class="LineNr">169 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L170" class="LineNr">170 </span> <span class="Delimiter">}</span> +<span id="L171" class="LineNr">171 </span> <span class="Comment">// use unsigned to zero-extend 8-bit value to 32 bits</span> +<span id="L172" class="LineNr">172 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L173" class="LineNr">173 </span> *dest = src<span class="Delimiter">;</span> <span class="Comment">// Write multiple elements of vector<uint8_t> at once. Assumes sizeof(int) == 4 on the host as well.</span> +<span id="L174" class="LineNr">174 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L175" class="LineNr">175 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L176" class="LineNr">176 </span><span class="Delimiter">}</span> +<span id="L177" class="LineNr">177 </span> +<span id="L178" class="LineNr">178 </span><span class="Comment">//:: set flags (setcc)</span> +<span id="L179" class="LineNr">179 </span> +<span id="L180" class="LineNr">180 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L181" class="LineNr">181 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"94"</span><span class="Delimiter">,</span> <span class="Constant">"set r8/m8-at-rm32 to 1 if equal, if <a href='010vm.cc.html#L89'>ZF</a> is set, 0 otherwise (setcc/setz/sete)"</span><span class="Delimiter">);</span> +<span id="L182" class="LineNr">182 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"95"</span><span class="Delimiter">,</span> <span class="Constant">"set r8/m8-at-rm32 to 1 if not equal, if <a href='010vm.cc.html#L89'>ZF</a> is not set, 0 otherwise (setcc/setnz/setne)"</span><span class="Delimiter">);</span> +<span id="L183" class="LineNr">183 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"9f"</span><span class="Delimiter">,</span> <span class="Constant">"set r8/m8-at-rm32 to 1 if greater, if <a href='010vm.cc.html#L89'>ZF</a> is unset and SF == <a href='010vm.cc.html#L91'>OF</a>, 0 otherwise (setcc/setg/setnle)"</span><span class="Delimiter">);</span> +<span id="L184" class="LineNr">184 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"97"</span><span class="Delimiter">,</span> <span class="Constant">"set r8/m8-at-rm32 to 1 if greater (addr, float), if <a href='010vm.cc.html#L89'>ZF</a> is unset and <a href='010vm.cc.html#L90'>CF</a> is unset, 0 otherwise (setcc/seta/setnbe)"</span><span class="Delimiter">);</span> +<span id="L185" class="LineNr">185 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"9d"</span><span class="Delimiter">,</span> <span class="Constant">"set r8/m8-at-rm32 to 1 if greater or equal, if SF == <a href='010vm.cc.html#L91'>OF</a>, 0 otherwise (setcc/setge/setnl)"</span><span class="Delimiter">);</span> +<span id="L186" class="LineNr">186 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"93"</span><span class="Delimiter">,</span> <span class="Constant">"set r8/m8-at-rm32 to 1 if greater or equal (addr, float), if <a href='010vm.cc.html#L90'>CF</a> is unset, 0 otherwise (setcc/setae/setnb)"</span><span class="Delimiter">);</span> +<span id="L187" class="LineNr">187 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"9c"</span><span class="Delimiter">,</span> <span class="Constant">"set r8/m8-at-rm32 to 1 if lesser, if SF != <a href='010vm.cc.html#L91'>OF</a>, 0 otherwise (setcc/setl/setnge)"</span><span class="Delimiter">);</span> +<span id="L188" class="LineNr">188 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"92"</span><span class="Delimiter">,</span> <span class="Constant">"set r8/m8-at-rm32 to 1 if lesser (addr, float), if <a href='010vm.cc.html#L90'>CF</a> is set, 0 otherwise (setcc/setb/setnae)"</span><span class="Delimiter">);</span> +<span id="L189" class="LineNr">189 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"9e"</span><span class="Delimiter">,</span> <span class="Constant">"set r8/m8-at-rm32 to 1 if lesser or equal, if <a href='010vm.cc.html#L89'>ZF</a> is set or SF != <a href='010vm.cc.html#L91'>OF</a>, 0 otherwise (setcc/setle/setng)"</span><span class="Delimiter">);</span> +<span id="L190" class="LineNr">190 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"96"</span><span class="Delimiter">,</span> <span class="Constant">"set r8/m8-at-rm32 to 1 if lesser or equal (addr, float), if <a href='010vm.cc.html#L89'>ZF</a> is set or <a href='010vm.cc.html#L90'>CF</a> is set, 0 otherwise (setcc/setbe/setna)"</span><span class="Delimiter">);</span> +<span id="L191" class="LineNr">191 </span> +<span id="L192" class="LineNr">192 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L193" class="LineNr">193 </span><span class="Normal">case</span> <span class="Constant">0x94</span>: <span class="Delimiter">{</span> <span class="Comment">// set r8/m8-at-rm32 if ZF</span> +<span id="L194" class="LineNr">194 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L195" class="LineNr">195 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"set r8/m8-at-rm32"</span> << end<span class="Delimiter">();</span> +<span id="L196" class="LineNr">196 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L197" class="LineNr">197 </span> *dest = <a href='010vm.cc.html#L89'>ZF</a><span class="Delimiter">;</span> +<span id="L198" class="LineNr">198 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L199" class="LineNr">199 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L200" class="LineNr">200 </span><span class="Delimiter">}</span> +<span id="L201" class="LineNr">201 </span><span class="Normal">case</span> <span class="Constant">0x95</span>: <span class="Delimiter">{</span> <span class="Comment">// set r8/m8-at-rm32 if !ZF</span> +<span id="L202" class="LineNr">202 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L203" class="LineNr">203 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"set r8/m8-at-rm32"</span> << end<span class="Delimiter">();</span> +<span id="L204" class="LineNr">204 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L205" class="LineNr">205 </span> *dest = !ZF<span class="Delimiter">;</span> +<span id="L206" class="LineNr">206 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L207" class="LineNr">207 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L208" class="LineNr">208 </span><span class="Delimiter">}</span> +<span id="L209" class="LineNr">209 </span><span class="Normal">case</span> <span class="Constant">0x9f</span>: <span class="Delimiter">{</span> <span class="Comment">// set r8/m8-at-rm32 if !SF and !ZF</span> +<span id="L210" class="LineNr">210 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L211" class="LineNr">211 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"set r8/m8-at-rm32"</span> << end<span class="Delimiter">();</span> +<span id="L212" class="LineNr">212 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L213" class="LineNr">213 </span> *dest = !ZF && SF == <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">;</span> +<span id="L214" class="LineNr">214 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L215" class="LineNr">215 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L216" class="LineNr">216 </span><span class="Delimiter">}</span> +<span id="L217" class="LineNr">217 </span><span class="Normal">case</span> <span class="Constant">0x97</span>: <span class="Delimiter">{</span> <span class="Comment">// set r8/m8-at-rm32 if !CF and !ZF</span> +<span id="L218" class="LineNr">218 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L219" class="LineNr">219 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"set r8/m8-at-rm32"</span> << end<span class="Delimiter">();</span> +<span id="L220" class="LineNr">220 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L221" class="LineNr">221 </span> *dest = <span class="Delimiter">(</span>!CF && !ZF<span class="Delimiter">);</span> +<span id="L222" class="LineNr">222 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L223" class="LineNr">223 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L224" class="LineNr">224 </span><span class="Delimiter">}</span> +<span id="L225" class="LineNr">225 </span><span class="Normal">case</span> <span class="Constant">0x9d</span>: <span class="Delimiter">{</span> <span class="Comment">// set r8/m8-at-rm32 if !SF</span> +<span id="L226" class="LineNr">226 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L227" class="LineNr">227 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"set r8/m8-at-rm32"</span> << end<span class="Delimiter">();</span> +<span id="L228" class="LineNr">228 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L229" class="LineNr">229 </span> *dest = <span class="Delimiter">(</span>SF == <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">);</span> +<span id="L230" class="LineNr">230 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L231" class="LineNr">231 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L232" class="LineNr">232 </span><span class="Delimiter">}</span> +<span id="L233" class="LineNr">233 </span><span class="Normal">case</span> <span class="Constant">0x93</span>: <span class="Delimiter">{</span> <span class="Comment">// set r8/m8-at-rm32 if !CF</span> +<span id="L234" class="LineNr">234 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L235" class="LineNr">235 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"set r8/m8-at-rm32"</span> << end<span class="Delimiter">();</span> +<span id="L236" class="LineNr">236 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L237" class="LineNr">237 </span> *dest = !CF<span class="Delimiter">;</span> +<span id="L238" class="LineNr">238 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L239" class="LineNr">239 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L240" class="LineNr">240 </span><span class="Delimiter">}</span> +<span id="L241" class="LineNr">241 </span><span class="Normal">case</span> <span class="Constant">0x9c</span>: <span class="Delimiter">{</span> <span class="Comment">// set r8/m8-at-rm32 if SF and !ZF</span> +<span id="L242" class="LineNr">242 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L243" class="LineNr">243 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"set r8/m8-at-rm32"</span> << end<span class="Delimiter">();</span> +<span id="L244" class="LineNr">244 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L245" class="LineNr">245 </span> *dest = <span class="Delimiter">(</span>SF != <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">);</span> +<span id="L246" class="LineNr">246 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<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> +<span id="L249" class="LineNr">249 </span><span class="Normal">case</span> <span class="Constant">0x92</span>: <span class="Delimiter">{</span> <span class="Comment">// set r8/m8-at-rm32 if CF</span> +<span id="L250" class="LineNr">250 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L251" class="LineNr">251 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"set r8/m8-at-rm32"</span> << end<span class="Delimiter">();</span> +<span id="L252" class="LineNr">252 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L253" class="LineNr">253 </span> *dest = <a href='010vm.cc.html#L90'>CF</a><span class="Delimiter">;</span> +<span id="L254" class="LineNr">254 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L255" class="LineNr">255 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L256" class="LineNr">256 </span><span class="Delimiter">}</span> +<span id="L257" class="LineNr">257 </span><span class="Normal">case</span> <span class="Constant">0x9e</span>: <span class="Delimiter">{</span> <span class="Comment">// set r8/m8-at-rm32 if SF or ZF</span> +<span id="L258" class="LineNr">258 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L259" class="LineNr">259 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"set r8/m8-at-rm32"</span> << end<span class="Delimiter">();</span> +<span id="L260" class="LineNr">260 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L261" class="LineNr">261 </span> *dest = <span class="Delimiter">(</span><a href='010vm.cc.html#L89'>ZF</a> || SF != <a href='010vm.cc.html#L91'>OF</a><span class="Delimiter">);</span> +<span id="L262" class="LineNr">262 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L263" class="LineNr">263 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L264" class="LineNr">264 </span><span class="Delimiter">}</span> +<span id="L265" class="LineNr">265 </span><span class="Normal">case</span> <span class="Constant">0x96</span>: <span class="Delimiter">{</span> <span class="Comment">// set r8/m8-at-rm32 if ZF or CF</span> +<span id="L266" class="LineNr">266 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L267" class="LineNr">267 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"set r8/m8-at-rm32"</span> << end<span class="Delimiter">();</span> +<span id="L268" class="LineNr">268 </span> <span class="Normal">uint8_t</span>* dest = <a href='020byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L269" class="LineNr">269 </span> *dest = <span class="Delimiter">(</span><a href='010vm.cc.html#L89'>ZF</a> || <a href='010vm.cc.html#L90'>CF</a><span class="Delimiter">);</span> +<span id="L270" class="LineNr">270 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L271" class="LineNr">271 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L272" class="LineNr">272 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/021div.cc.html b/html/linux/bootstrap/021div.cc.html new file mode 100644 index 00000000..6b735134 --- /dev/null +++ b/html/linux/bootstrap/021div.cc.html @@ -0,0 +1,100 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/021div.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.LineNr { } +.Constant { color: #008787; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/021div.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/021div.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: helper for division operations: sign-extend EAX into EDX</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L4" class="LineNr"> 4 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"99"</span><span class="Delimiter">,</span> <span class="Constant">"sign-extend <a href='010vm.cc.html#L10'>EAX</a> into <a href='010vm.cc.html#L12'>EDX</a> (cdq)"</span><span class="Delimiter">);</span> +<span id="L5" class="LineNr"> 5 </span> +<span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(code)</span> +<span id="L7" class="LineNr"> 7 </span><span class="Normal">void</span> <a href='021div.cc.html#L7'>test_cdq</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L8" class="LineNr"> 8 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">10</span><span class="Delimiter">;</span> +<span id="L9" class="LineNr"> 9 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L10" class="LineNr">10 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L11" class="LineNr">11 </span> <span class="Constant">"99</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L12" class="LineNr">12 </span> <span class="Delimiter">);</span> +<span id="L13" class="LineNr">13 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L14" class="LineNr">14 </span> <span class="Constant">"run: sign-extend <a href='010vm.cc.html#L10'>EAX</a> into <a href='010vm.cc.html#L12'>EDX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L15" class="LineNr">15 </span> <span class="Constant">"run: <a href='010vm.cc.html#L12'>EDX</a> is now 0x00000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L16" class="LineNr">16 </span> <span class="Delimiter">);</span> +<span id="L17" class="LineNr">17 </span><span class="Delimiter">}</span> +<span id="L18" class="LineNr">18 </span> +<span id="L19" class="LineNr">19 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L20" class="LineNr">20 </span><span class="Normal">case</span> <span class="Constant">0x99</span>: <span class="Delimiter">{</span> <span class="Comment">// sign-extend EAX into EDX</span> +<span id="L21" class="LineNr">21 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"sign-extend <a href='010vm.cc.html#L10'>EAX</a> into EDX"</span> << end<span class="Delimiter">();</span> +<span id="L22" class="LineNr">22 </span> Reg[EDX]<span class="Delimiter">.</span>i = <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i < <span class="Constant">0</span><span class="Delimiter">)</span> ? -<span class="Constant">1</span> : <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L23" class="LineNr">23 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"EDX is now 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[EDX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L24" class="LineNr">24 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L25" class="LineNr">25 </span><span class="Delimiter">}</span> +<span id="L26" class="LineNr">26 </span> +<span id="L27" class="LineNr">27 </span><span class="Delimiter">:(code)</span> +<span id="L28" class="LineNr">28 </span><span class="Normal">void</span> <a href='021div.cc.html#L28'>test_cdq_negative</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L29" class="LineNr">29 </span> Reg[EAX]<span class="Delimiter">.</span>i = -<span class="Constant">10</span><span class="Delimiter">;</span> +<span id="L30" class="LineNr">30 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L31" class="LineNr">31 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L32" class="LineNr">32 </span> <span class="Constant">"99</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L33" class="LineNr">33 </span> <span class="Delimiter">);</span> +<span id="L34" class="LineNr">34 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L35" class="LineNr">35 </span> <span class="Constant">"run: sign-extend <a href='010vm.cc.html#L10'>EAX</a> into <a href='010vm.cc.html#L12'>EDX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L36" class="LineNr">36 </span> <span class="Constant">"run: <a href='010vm.cc.html#L12'>EDX</a> is now 0xffffffff</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L37" class="LineNr">37 </span> <span class="Delimiter">);</span> +<span id="L38" class="LineNr">38 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/022float.cc.html b/html/linux/bootstrap/022float.cc.html new file mode 100644 index 00000000..8365cc91 --- /dev/null +++ b/html/linux/bootstrap/022float.cc.html @@ -0,0 +1,582 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/022float.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.LineNr { } +.Constant { color: #008787; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +.PreProc { color: #c000c0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/022float.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/022float.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: floating-point operations</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//:: copy</span> +<span id="L4" class="LineNr"> 4 </span> +<span id="L5" class="LineNr"> 5 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L6" class="LineNr"> 6 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"10"</span><span class="Delimiter">,</span> <span class="Constant">"copy xm32 to x32 (movss)"</span><span class="Delimiter">);</span> +<span id="L7" class="LineNr"> 7 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"11"</span><span class="Delimiter">,</span> <span class="Constant">"copy x32 to xm32 (movss)"</span><span class="Delimiter">);</span> +<span id="L8" class="LineNr"> 8 </span> +<span id="L9" class="LineNr"> 9 </span><span class="Delimiter">:(code)</span> +<span id="L10" class="LineNr"> 10 </span><span class="Normal">void</span> <a href='022float.cc.html#L10'>test_copy_x32_to_x32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L11" class="LineNr"> 11 </span> Xmm[<span class="Constant">3</span>] = <span class="Constant">0.5</span><span class="Delimiter">;</span> +<span id="L12" class="LineNr"> 12 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Constant">"f3 0f 11 d8 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy XMM3 to XMM0</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 011 (src XMM3) 000 (dest XMM0)</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Delimiter">);</span> +<span id="L18" class="LineNr"> 18 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"run: copy XMM3 to x/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"run: x/m32 is XMM0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Constant">"run: storing 0.5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L22" class="LineNr"> 22 </span> <span class="Delimiter">);</span> +<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">}</span> +<span id="L24" class="LineNr"> 24 </span> +<span id="L25" class="LineNr"> 25 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L26" class="LineNr"> 26 </span><span class="Normal">case</span> <span class="Constant">0x10</span>: <span class="Delimiter">{</span> <span class="Comment">// copy x/m32 to x32</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L28" class="LineNr"> 28 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rdest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L29" class="LineNr"> 29 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy x/m32 to "</span> << Xname[rdest] << end<span class="Delimiter">();</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Normal">float</span>* src = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L31" class="LineNr"> 31 </span> Xmm[rdest] = *src<span class="Delimiter">;</span> <span class="Comment">// Write multiple elements of vector<uint8_t> at once. Assumes sizeof(float) == 4 on the host as well.</span> +<span id="L32" class="LineNr"> 32 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << Xmm[rdest] << end<span class="Delimiter">();</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L34" class="LineNr"> 34 </span><span class="Delimiter">}</span> +<span id="L35" class="LineNr"> 35 </span><span class="Normal">case</span> <span class="Constant">0x11</span>: <span class="Delimiter">{</span> <span class="Comment">// copy x32 to x/m32</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rsrc = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L38" class="LineNr"> 38 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy "</span> << Xname[rsrc] << <span class="Constant">" to x/m32"</span> << end<span class="Delimiter">();</span> +<span id="L39" class="LineNr"> 39 </span> <span class="Normal">float</span>* dest = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L40" class="LineNr"> 40 </span> *dest = Xmm[rsrc]<span class="Delimiter">;</span> <span class="Comment">// Write multiple elements of vector<uint8_t> at once. Assumes sizeof(float) == 4 on the host as well.</span> +<span id="L41" class="LineNr"> 41 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << *dest << end<span class="Delimiter">();</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L43" class="LineNr"> 43 </span><span class="Delimiter">}</span> +<span id="L44" class="LineNr"> 44 </span> +<span id="L45" class="LineNr"> 45 </span><span class="Delimiter">:(code)</span> +<span id="L46" class="LineNr"> 46 </span><span class="Normal">void</span> <a href='022float.cc.html#L46'>test_copy_x32_to_mem_at_xm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L47" class="LineNr"> 47 </span> Xmm[<span class="Constant">3</span>] = <span class="Constant">0.5</span><span class="Delimiter">;</span> +<span id="L48" class="LineNr"> 48 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x60</span><span class="Delimiter">;</span> +<span id="L49" class="LineNr"> 49 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Constant">"f3 0f 11 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy XMM3 to *EAX</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (src XMM3) 000 (dest EAX)</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Delimiter">);</span> +<span id="L55" class="LineNr"> 55 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Constant">"run: copy XMM3 to x/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Constant">"run: effective address is 0x00000060 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Constant">"run: storing 0.5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Delimiter">);</span> +<span id="L60" class="LineNr"> 60 </span><span class="Delimiter">}</span> +<span id="L61" class="LineNr"> 61 </span> +<span id="L62" class="LineNr"> 62 </span><span class="Normal">void</span> <a href='022float.cc.html#L62'>test_copy_mem_at_xm32_to_x32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L63" class="LineNr"> 63 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L64" class="LineNr"> 64 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Constant">"f3 0f 10 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy *EAX to XMM3</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Constant">"00 00 00 3f</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x3f000000 = 0.5</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Delimiter">);</span> +<span id="L71" class="LineNr"> 71 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Constant">"run: copy x/m32 to XMM3</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Constant">"run: storing 0.5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Delimiter">);</span> +<span id="L76" class="LineNr"> 76 </span><span class="Delimiter">}</span> +<span id="L77" class="LineNr"> 77 </span> +<span id="L78" class="LineNr"> 78 </span><span class="Comment">//:: convert to floating point</span> +<span id="L79" class="LineNr"> 79 </span> +<span id="L80" class="LineNr"> 80 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L81" class="LineNr"> 81 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"2a"</span><span class="Delimiter">,</span> <span class="Constant">"convert integer to floating-point (cvtsi2ss)"</span><span class="Delimiter">);</span> +<span id="L82" class="LineNr"> 82 </span> +<span id="L83" class="LineNr"> 83 </span><span class="Delimiter">:(code)</span> +<span id="L84" class="LineNr"> 84 </span><span class="Normal">void</span> <a href='022float.cc.html#L84'>test_cvtsi2ss</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L85" class="LineNr"> 85 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">10</span><span class="Delimiter">;</span> +<span id="L86" class="LineNr"> 86 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Constant">"f3 0f 2a c0 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (XMM0) 000 (EAX)</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Delimiter">);</span> +<span id="L92" class="LineNr"> 92 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Constant">"run: convert r/m32 to XMM0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Constant">"run: r/m32 is <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Constant">"run: XMM0 is now 10</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Delimiter">);</span> +<span id="L97" class="LineNr"> 97 </span><span class="Delimiter">}</span> +<span id="L98" class="LineNr"> 98 </span> +<span id="L99" class="LineNr"> 99 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L100" class="LineNr">100 </span><span class="Normal">case</span> <span class="Constant">0x2a</span>: <span class="Delimiter">{</span> <span class="Comment">// convert integer to float</span> +<span id="L101" class="LineNr">101 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L102" class="LineNr">102 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> dest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L103" class="LineNr">103 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"convert r/m32 to "</span> << Xname[dest] << end<span class="Delimiter">();</span> +<span id="L104" class="LineNr">104 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* src = <a href='013direct_addressing.cc.html#L101'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L105" class="LineNr">105 </span> Xmm[dest] = *src<span class="Delimiter">;</span> +<span id="L106" class="LineNr">106 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Xname[dest] << <span class="Constant">" is now "</span> << Xmm[dest] << end<span class="Delimiter">();</span> +<span id="L107" class="LineNr">107 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L108" class="LineNr">108 </span><span class="Delimiter">}</span> +<span id="L109" class="LineNr">109 </span> +<span id="L110" class="LineNr">110 </span><span class="Comment">//:: convert floating point to int</span> +<span id="L111" class="LineNr">111 </span> +<span id="L112" class="LineNr">112 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L113" class="LineNr">113 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"2d"</span><span class="Delimiter">,</span> <span class="Constant">"convert floating-point to int (cvtss2si)"</span><span class="Delimiter">);</span> +<span id="L114" class="LineNr">114 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"2c"</span><span class="Delimiter">,</span> <span class="Constant">"truncate floating-point to int (cvttss2si)"</span><span class="Delimiter">);</span> +<span id="L115" class="LineNr">115 </span> +<span id="L116" class="LineNr">116 </span><span class="Delimiter">:(code)</span> +<span id="L117" class="LineNr">117 </span><span class="Normal">void</span> <a href='022float.cc.html#L117'>test_cvtss2si</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L118" class="LineNr">118 </span> Xmm[<span class="Constant">0</span>] = <span class="Constant">9.8</span><span class="Delimiter">;</span> +<span id="L119" class="LineNr">119 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L120" class="LineNr">120 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L121" class="LineNr">121 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L122" class="LineNr">122 </span> <span class="Constant">"f3 0f 2d c0 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L123" class="LineNr">123 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (EAX) 000 (XMM0)</span> +<span id="L124" class="LineNr">124 </span> <span class="Delimiter">);</span> +<span id="L125" class="LineNr">125 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L126" class="LineNr">126 </span> <span class="Constant">"run: convert x/m32 to <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L127" class="LineNr">127 </span> <span class="Constant">"run: x/m32 is XMM0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L128" class="LineNr">128 </span> <span class="Constant">"run: <a href='010vm.cc.html#L10'>EAX</a> is now 0x0000000a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L129" class="LineNr">129 </span> <span class="Delimiter">);</span> +<span id="L130" class="LineNr">130 </span><span class="Delimiter">}</span> +<span id="L131" class="LineNr">131 </span> +<span id="L132" class="LineNr">132 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L133" class="LineNr">133 </span><span class="Normal">case</span> <span class="Constant">0x2d</span>: <span class="Delimiter">{</span> <span class="Comment">// convert float to integer</span> +<span id="L134" class="LineNr">134 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L135" class="LineNr">135 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> dest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L136" class="LineNr">136 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"convert x/m32 to "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L137" class="LineNr">137 </span> <span class="Normal">const</span> <span class="Normal">float</span>* src = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L138" class="LineNr">138 </span> Reg[dest]<span class="Delimiter">.</span>i = round<span class="Delimiter">(</span>*src<span class="Delimiter">);</span> +<span id="L139" class="LineNr">139 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>dest<span class="Delimiter">)</span> << <span class="Constant">" is now 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[dest]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L140" class="LineNr">140 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L141" class="LineNr">141 </span><span class="Delimiter">}</span> +<span id="L142" class="LineNr">142 </span> +<span id="L143" class="LineNr">143 </span><span class="Delimiter">:(code)</span> +<span id="L144" class="LineNr">144 </span><span class="Normal">void</span> <a href='022float.cc.html#L144'>test_cvttss2si</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L145" class="LineNr">145 </span> Xmm[<span class="Constant">0</span>] = <span class="Constant">9.8</span><span class="Delimiter">;</span> +<span id="L146" class="LineNr">146 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L147" class="LineNr">147 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L148" class="LineNr">148 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L149" class="LineNr">149 </span> <span class="Constant">"f3 0f 2c c0 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L150" class="LineNr">150 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (EAX) 000 (XMM0)</span> +<span id="L151" class="LineNr">151 </span> <span class="Delimiter">);</span> +<span id="L152" class="LineNr">152 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L153" class="LineNr">153 </span> <span class="Constant">"run: truncate x/m32 to <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L154" class="LineNr">154 </span> <span class="Constant">"run: x/m32 is XMM0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L155" class="LineNr">155 </span> <span class="Constant">"run: <a href='010vm.cc.html#L10'>EAX</a> is now 0x00000009</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L156" class="LineNr">156 </span> <span class="Delimiter">);</span> +<span id="L157" class="LineNr">157 </span><span class="Delimiter">}</span> +<span id="L158" class="LineNr">158 </span> +<span id="L159" class="LineNr">159 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L160" class="LineNr">160 </span><span class="Normal">case</span> <span class="Constant">0x2c</span>: <span class="Delimiter">{</span> <span class="Comment">// truncate float to integer</span> +<span id="L161" class="LineNr">161 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L162" class="LineNr">162 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> dest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L163" class="LineNr">163 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"truncate x/m32 to "</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L164" class="LineNr">164 </span> <span class="Normal">const</span> <span class="Normal">float</span>* src = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L165" class="LineNr">165 </span> Reg[dest]<span class="Delimiter">.</span>i = trunc<span class="Delimiter">(</span>*src<span class="Delimiter">);</span> +<span id="L166" class="LineNr">166 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <a href='013direct_addressing.cc.html#L136'>rname</a><span class="Delimiter">(</span>dest<span class="Delimiter">)</span> << <span class="Constant">" is now 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << Reg[dest]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L167" class="LineNr">167 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L168" class="LineNr">168 </span><span class="Delimiter">}</span> +<span id="L169" class="LineNr">169 </span> +<span id="L170" class="LineNr">170 </span><span class="Comment">//:: add</span> +<span id="L171" class="LineNr">171 </span> +<span id="L172" class="LineNr">172 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L173" class="LineNr">173 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"58"</span><span class="Delimiter">,</span> <span class="Constant">"add floats (addss)"</span><span class="Delimiter">);</span> +<span id="L174" class="LineNr">174 </span> +<span id="L175" class="LineNr">175 </span><span class="Delimiter">:(code)</span> +<span id="L176" class="LineNr">176 </span><span class="Normal">void</span> <a href='022float.cc.html#L176'>test_addss</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L177" class="LineNr">177 </span> Xmm[<span class="Constant">0</span>] = <span class="Constant">3.0</span><span class="Delimiter">;</span> +<span id="L178" class="LineNr">178 </span> Xmm[<span class="Constant">1</span>] = <span class="Constant">2.0</span><span class="Delimiter">;</span> +<span id="L179" class="LineNr">179 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L180" class="LineNr">180 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L181" class="LineNr">181 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L182" class="LineNr">182 </span> <span class="Constant">"f3 0f 58 c1 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L183" class="LineNr">183 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (XMM0) 001 (XMM1)</span> +<span id="L184" class="LineNr">184 </span> <span class="Delimiter">);</span> +<span id="L185" class="LineNr">185 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L186" class="LineNr">186 </span> <span class="Constant">"run: add x/m32 to XMM0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L187" class="LineNr">187 </span> <span class="Constant">"run: x/m32 is XMM1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L188" class="LineNr">188 </span> <span class="Constant">"run: XMM0 is now 5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L189" class="LineNr">189 </span> <span class="Delimiter">);</span> +<span id="L190" class="LineNr">190 </span><span class="Delimiter">}</span> +<span id="L191" class="LineNr">191 </span> +<span id="L192" class="LineNr">192 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L193" class="LineNr">193 </span><span class="Normal">case</span> <span class="Constant">0x58</span>: <span class="Delimiter">{</span> <span class="Comment">// add x/m32 to x32</span> +<span id="L194" class="LineNr">194 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L195" class="LineNr">195 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> dest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L196" class="LineNr">196 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"add x/m32 to "</span> << Xname[dest] << end<span class="Delimiter">();</span> +<span id="L197" class="LineNr">197 </span> <span class="Normal">const</span> <span class="Normal">float</span>* src = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L198" class="LineNr">198 </span> Xmm[dest] += *src<span class="Delimiter">;</span> +<span id="L199" class="LineNr">199 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Xname[dest] << <span class="Constant">" is now "</span> << Xmm[dest] << end<span class="Delimiter">();</span> +<span id="L200" class="LineNr">200 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L201" class="LineNr">201 </span><span class="Delimiter">}</span> +<span id="L202" class="LineNr">202 </span> +<span id="L203" class="LineNr">203 </span><span class="Comment">//:: subtract</span> +<span id="L204" class="LineNr">204 </span> +<span id="L205" class="LineNr">205 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L206" class="LineNr">206 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"5c"</span><span class="Delimiter">,</span> <span class="Constant">"subtract floats (subss)"</span><span class="Delimiter">);</span> +<span id="L207" class="LineNr">207 </span> +<span id="L208" class="LineNr">208 </span><span class="Delimiter">:(code)</span> +<span id="L209" class="LineNr">209 </span><span class="Normal">void</span> <a href='022float.cc.html#L209'>test_subss</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L210" class="LineNr">210 </span> Xmm[<span class="Constant">0</span>] = <span class="Constant">3.0</span><span class="Delimiter">;</span> +<span id="L211" class="LineNr">211 </span> Xmm[<span class="Constant">1</span>] = <span class="Constant">2.0</span><span class="Delimiter">;</span> +<span id="L212" class="LineNr">212 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L213" class="LineNr">213 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L214" class="LineNr">214 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L215" class="LineNr">215 </span> <span class="Constant">"f3 0f 5c c1 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L216" class="LineNr">216 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (XMM0) 001 (XMM1)</span> +<span id="L217" class="LineNr">217 </span> <span class="Delimiter">);</span> +<span id="L218" class="LineNr">218 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L219" class="LineNr">219 </span> <span class="Constant">"run: subtract x/m32 from XMM0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L220" class="LineNr">220 </span> <span class="Constant">"run: x/m32 is XMM1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L221" class="LineNr">221 </span> <span class="Constant">"run: XMM0 is now 1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L222" class="LineNr">222 </span> <span class="Delimiter">);</span> +<span id="L223" class="LineNr">223 </span><span class="Delimiter">}</span> +<span id="L224" class="LineNr">224 </span> +<span id="L225" class="LineNr">225 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L226" class="LineNr">226 </span><span class="Normal">case</span> <span class="Constant">0x5c</span>: <span class="Delimiter">{</span> <span class="Comment">// subtract x/m32 from x32</span> +<span id="L227" class="LineNr">227 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L228" class="LineNr">228 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> dest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L229" class="LineNr">229 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subtract x/m32 from "</span> << Xname[dest] << end<span class="Delimiter">();</span> +<span id="L230" class="LineNr">230 </span> <span class="Normal">const</span> <span class="Normal">float</span>* src = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L231" class="LineNr">231 </span> Xmm[dest] -= *src<span class="Delimiter">;</span> +<span id="L232" class="LineNr">232 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Xname[dest] << <span class="Constant">" is now "</span> << Xmm[dest] << end<span class="Delimiter">();</span> +<span id="L233" class="LineNr">233 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L234" class="LineNr">234 </span><span class="Delimiter">}</span> +<span id="L235" class="LineNr">235 </span> +<span id="L236" class="LineNr">236 </span><span class="Comment">//:: multiply</span> +<span id="L237" class="LineNr">237 </span> +<span id="L238" class="LineNr">238 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L239" class="LineNr">239 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"59"</span><span class="Delimiter">,</span> <span class="Constant">"multiply floats (mulss)"</span><span class="Delimiter">);</span> +<span id="L240" class="LineNr">240 </span> +<span id="L241" class="LineNr">241 </span><span class="Delimiter">:(code)</span> +<span id="L242" class="LineNr">242 </span><span class="Normal">void</span> <a href='022float.cc.html#L242'>test_mulss</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L243" class="LineNr">243 </span> Xmm[<span class="Constant">0</span>] = <span class="Constant">3.0</span><span class="Delimiter">;</span> +<span id="L244" class="LineNr">244 </span> Xmm[<span class="Constant">1</span>] = <span class="Constant">2.0</span><span class="Delimiter">;</span> +<span id="L245" class="LineNr">245 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L246" class="LineNr">246 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L247" class="LineNr">247 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L248" class="LineNr">248 </span> <span class="Constant">"f3 0f 59 c1 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L249" class="LineNr">249 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (XMM0) 001 (XMM1)</span> +<span id="L250" class="LineNr">250 </span> <span class="Delimiter">);</span> +<span id="L251" class="LineNr">251 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L252" class="LineNr">252 </span> <span class="Constant">"run: multiply XMM0 by x/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L253" class="LineNr">253 </span> <span class="Constant">"run: x/m32 is XMM1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L254" class="LineNr">254 </span> <span class="Constant">"run: XMM0 is now 6</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L255" class="LineNr">255 </span> <span class="Delimiter">);</span> +<span id="L256" class="LineNr">256 </span><span class="Delimiter">}</span> +<span id="L257" class="LineNr">257 </span> +<span id="L258" class="LineNr">258 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L259" class="LineNr">259 </span><span class="Normal">case</span> <span class="Constant">0x59</span>: <span class="Delimiter">{</span> <span class="Comment">// multiply x32 by x/m32</span> +<span id="L260" class="LineNr">260 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L261" class="LineNr">261 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> dest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L262" class="LineNr">262 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"multiply "</span> << Xname[dest] << <span class="Constant">" by x/m32"</span> << end<span class="Delimiter">();</span> +<span id="L263" class="LineNr">263 </span> <span class="Normal">const</span> <span class="Normal">float</span>* src = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L264" class="LineNr">264 </span> Xmm[dest] *= *src<span class="Delimiter">;</span> +<span id="L265" class="LineNr">265 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Xname[dest] << <span class="Constant">" is now "</span> << Xmm[dest] << end<span class="Delimiter">();</span> +<span id="L266" class="LineNr">266 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L267" class="LineNr">267 </span><span class="Delimiter">}</span> +<span id="L268" class="LineNr">268 </span> +<span id="L269" class="LineNr">269 </span><span class="Comment">//:: divide</span> +<span id="L270" class="LineNr">270 </span> +<span id="L271" class="LineNr">271 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L272" class="LineNr">272 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"5e"</span><span class="Delimiter">,</span> <span class="Constant">"divide floats (divss)"</span><span class="Delimiter">);</span> +<span id="L273" class="LineNr">273 </span> +<span id="L274" class="LineNr">274 </span><span class="Delimiter">:(code)</span> +<span id="L275" class="LineNr">275 </span><span class="Normal">void</span> <a href='022float.cc.html#L275'>test_divss</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L276" class="LineNr">276 </span> Xmm[<span class="Constant">0</span>] = <span class="Constant">3.0</span><span class="Delimiter">;</span> +<span id="L277" class="LineNr">277 </span> Xmm[<span class="Constant">1</span>] = <span class="Constant">2.0</span><span class="Delimiter">;</span> +<span id="L278" class="LineNr">278 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L279" class="LineNr">279 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L280" class="LineNr">280 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L281" class="LineNr">281 </span> <span class="Constant">"f3 0f 5e c1 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L282" class="LineNr">282 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (XMM0) 001 (XMM1)</span> +<span id="L283" class="LineNr">283 </span> <span class="Delimiter">);</span> +<span id="L284" class="LineNr">284 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L285" class="LineNr">285 </span> <span class="Constant">"run: divide XMM0 by x/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L286" class="LineNr">286 </span> <span class="Constant">"run: x/m32 is XMM1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L287" class="LineNr">287 </span> <span class="Constant">"run: XMM0 is now 1.5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L288" class="LineNr">288 </span> <span class="Delimiter">);</span> +<span id="L289" class="LineNr">289 </span><span class="Delimiter">}</span> +<span id="L290" class="LineNr">290 </span> +<span id="L291" class="LineNr">291 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L292" class="LineNr">292 </span><span class="Normal">case</span> <span class="Constant">0x5e</span>: <span class="Delimiter">{</span> <span class="Comment">// divide x32 by x/m32</span> +<span id="L293" class="LineNr">293 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L294" class="LineNr">294 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> dest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L295" class="LineNr">295 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"divide "</span> << Xname[dest] << <span class="Constant">" by x/m32"</span> << end<span class="Delimiter">();</span> +<span id="L296" class="LineNr">296 </span> <span class="Normal">const</span> <span class="Normal">float</span>* src = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L297" class="LineNr">297 </span> Xmm[dest] /= *src<span class="Delimiter">;</span> +<span id="L298" class="LineNr">298 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Xname[dest] << <span class="Constant">" is now "</span> << Xmm[dest] << end<span class="Delimiter">();</span> +<span id="L299" class="LineNr">299 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L300" class="LineNr">300 </span><span class="Delimiter">}</span> +<span id="L301" class="LineNr">301 </span> +<span id="L302" class="LineNr">302 </span><span class="Comment">//:: min</span> +<span id="L303" class="LineNr">303 </span> +<span id="L304" class="LineNr">304 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L305" class="LineNr">305 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"5d"</span><span class="Delimiter">,</span> <span class="Constant">"minimum of two floats (minss)"</span><span class="Delimiter">);</span> +<span id="L306" class="LineNr">306 </span> +<span id="L307" class="LineNr">307 </span><span class="Delimiter">:(code)</span> +<span id="L308" class="LineNr">308 </span><span class="Normal">void</span> <a href='022float.cc.html#L308'>test_minss</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L309" class="LineNr">309 </span> Xmm[<span class="Constant">0</span>] = <span class="Constant">3.0</span><span class="Delimiter">;</span> +<span id="L310" class="LineNr">310 </span> Xmm[<span class="Constant">1</span>] = <span class="Constant">2.0</span><span class="Delimiter">;</span> +<span id="L311" class="LineNr">311 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L312" class="LineNr">312 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L313" class="LineNr">313 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L314" class="LineNr">314 </span> <span class="Constant">"f3 0f 5d c1 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L315" class="LineNr">315 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (XMM0) 001 (XMM1)</span> +<span id="L316" class="LineNr">316 </span> <span class="Delimiter">);</span> +<span id="L317" class="LineNr">317 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L318" class="LineNr">318 </span> <span class="Constant">"run: minimum of XMM0 and x/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L319" class="LineNr">319 </span> <span class="Constant">"run: x/m32 is XMM1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L320" class="LineNr">320 </span> <span class="Constant">"run: XMM0 is now 2</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L321" class="LineNr">321 </span> <span class="Delimiter">);</span> +<span id="L322" class="LineNr">322 </span><span class="Delimiter">}</span> +<span id="L323" class="LineNr">323 </span> +<span id="L324" class="LineNr">324 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L325" class="LineNr">325 </span><span class="Normal">case</span> <span class="Constant">0x5d</span>: <span class="Delimiter">{</span> <span class="Comment">// minimum of x32, x/m32</span> +<span id="L326" class="LineNr">326 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L327" class="LineNr">327 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> dest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L328" class="LineNr">328 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"minimum of "</span> << Xname[dest] << <span class="Constant">" and x/m32"</span> << end<span class="Delimiter">();</span> +<span id="L329" class="LineNr">329 </span> <span class="Normal">const</span> <span class="Normal">float</span>* src = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L330" class="LineNr">330 </span> Xmm[dest] = min<span class="Delimiter">(</span>Xmm[dest]<span class="Delimiter">,</span> *src<span class="Delimiter">);</span> +<span id="L331" class="LineNr">331 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Xname[dest] << <span class="Constant">" is now "</span> << Xmm[dest] << end<span class="Delimiter">();</span> +<span id="L332" class="LineNr">332 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L333" class="LineNr">333 </span><span class="Delimiter">}</span> +<span id="L334" class="LineNr">334 </span> +<span id="L335" class="LineNr">335 </span><span class="Comment">//:: max</span> +<span id="L336" class="LineNr">336 </span> +<span id="L337" class="LineNr">337 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L338" class="LineNr">338 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"5f"</span><span class="Delimiter">,</span> <span class="Constant">"maximum of two floats (maxss)"</span><span class="Delimiter">);</span> +<span id="L339" class="LineNr">339 </span> +<span id="L340" class="LineNr">340 </span><span class="Delimiter">:(code)</span> +<span id="L341" class="LineNr">341 </span><span class="Normal">void</span> <a href='022float.cc.html#L341'>test_maxss</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L342" class="LineNr">342 </span> Xmm[<span class="Constant">0</span>] = <span class="Constant">3.0</span><span class="Delimiter">;</span> +<span id="L343" class="LineNr">343 </span> Xmm[<span class="Constant">1</span>] = <span class="Constant">2.0</span><span class="Delimiter">;</span> +<span id="L344" class="LineNr">344 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L345" class="LineNr">345 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L346" class="LineNr">346 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L347" class="LineNr">347 </span> <span class="Constant">"f3 0f 5f c1 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L348" class="LineNr">348 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (XMM0) 001 (XMM1)</span> +<span id="L349" class="LineNr">349 </span> <span class="Delimiter">);</span> +<span id="L350" class="LineNr">350 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L351" class="LineNr">351 </span> <span class="Constant">"run: maximum of XMM0 and x/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L352" class="LineNr">352 </span> <span class="Constant">"run: x/m32 is XMM1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L353" class="LineNr">353 </span> <span class="Constant">"run: XMM0 is now 3</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L354" class="LineNr">354 </span> <span class="Delimiter">);</span> +<span id="L355" class="LineNr">355 </span><span class="Delimiter">}</span> +<span id="L356" class="LineNr">356 </span> +<span id="L357" class="LineNr">357 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L358" class="LineNr">358 </span><span class="Normal">case</span> <span class="Constant">0x5f</span>: <span class="Delimiter">{</span> <span class="Comment">// maximum of x32, x/m32</span> +<span id="L359" class="LineNr">359 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L360" class="LineNr">360 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> dest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L361" class="LineNr">361 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"maximum of "</span> << Xname[dest] << <span class="Constant">" and x/m32"</span> << end<span class="Delimiter">();</span> +<span id="L362" class="LineNr">362 </span> <span class="Normal">const</span> <span class="Normal">float</span>* src = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L363" class="LineNr">363 </span> Xmm[dest] = max<span class="Delimiter">(</span>Xmm[dest]<span class="Delimiter">,</span> *src<span class="Delimiter">);</span> +<span id="L364" class="LineNr">364 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Xname[dest] << <span class="Constant">" is now "</span> << Xmm[dest] << end<span class="Delimiter">();</span> +<span id="L365" class="LineNr">365 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L366" class="LineNr">366 </span><span class="Delimiter">}</span> +<span id="L367" class="LineNr">367 </span> +<span id="L368" class="LineNr">368 </span><span class="Comment">//:: reciprocal</span> +<span id="L369" class="LineNr">369 </span> +<span id="L370" class="LineNr">370 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L371" class="LineNr">371 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"53"</span><span class="Delimiter">,</span> <span class="Constant">"reciprocal of float (rcpss)"</span><span class="Delimiter">);</span> +<span id="L372" class="LineNr">372 </span> +<span id="L373" class="LineNr">373 </span><span class="Delimiter">:(code)</span> +<span id="L374" class="LineNr">374 </span><span class="Normal">void</span> <a href='022float.cc.html#L374'>test_rcpss</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L375" class="LineNr">375 </span> Xmm[<span class="Constant">1</span>] = <span class="Constant">2.0</span><span class="Delimiter">;</span> +<span id="L376" class="LineNr">376 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L377" class="LineNr">377 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L378" class="LineNr">378 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L379" class="LineNr">379 </span> <span class="Constant">"f3 0f 53 c1 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L380" class="LineNr">380 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (XMM0) 001 (XMM1)</span> +<span id="L381" class="LineNr">381 </span> <span class="Delimiter">);</span> +<span id="L382" class="LineNr">382 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L383" class="LineNr">383 </span> <span class="Constant">"run: reciprocal of x/m32 into XMM0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L384" class="LineNr">384 </span> <span class="Constant">"run: x/m32 is XMM1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L385" class="LineNr">385 </span> <span class="Constant">"run: XMM0 is now 0.5</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L386" class="LineNr">386 </span> <span class="Delimiter">);</span> +<span id="L387" class="LineNr">387 </span><span class="Delimiter">}</span> +<span id="L388" class="LineNr">388 </span> +<span id="L389" class="LineNr">389 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L390" class="LineNr">390 </span><span class="Normal">case</span> <span class="Constant">0x53</span>: <span class="Delimiter">{</span> <span class="Comment">// reciprocal of x/m32 into x32</span> +<span id="L391" class="LineNr">391 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L392" class="LineNr">392 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> dest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L393" class="LineNr">393 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"reciprocal of x/m32 into "</span> << Xname[dest] << end<span class="Delimiter">();</span> +<span id="L394" class="LineNr">394 </span> <span class="Normal">const</span> <span class="Normal">float</span>* src = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L395" class="LineNr">395 </span> Xmm[dest] = <span class="Constant">1.0</span> / *src<span class="Delimiter">;</span> +<span id="L396" class="LineNr">396 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Xname[dest] << <span class="Constant">" is now "</span> << Xmm[dest] << end<span class="Delimiter">();</span> +<span id="L397" class="LineNr">397 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L398" class="LineNr">398 </span><span class="Delimiter">}</span> +<span id="L399" class="LineNr">399 </span> +<span id="L400" class="LineNr">400 </span><span class="Comment">//:: square root</span> +<span id="L401" class="LineNr">401 </span> +<span id="L402" class="LineNr">402 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L403" class="LineNr">403 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"51"</span><span class="Delimiter">,</span> <span class="Constant">"square root of float (sqrtss)"</span><span class="Delimiter">);</span> +<span id="L404" class="LineNr">404 </span> +<span id="L405" class="LineNr">405 </span><span class="Delimiter">:(code)</span> +<span id="L406" class="LineNr">406 </span><span class="Normal">void</span> <a href='022float.cc.html#L406'>test_sqrtss</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L407" class="LineNr">407 </span> Xmm[<span class="Constant">1</span>] = <span class="Constant">2.0</span><span class="Delimiter">;</span> +<span id="L408" class="LineNr">408 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L409" class="LineNr">409 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L410" class="LineNr">410 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L411" class="LineNr">411 </span> <span class="Constant">"f3 0f 51 c1 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L412" class="LineNr">412 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (XMM0) 001 (XMM1)</span> +<span id="L413" class="LineNr">413 </span> <span class="Delimiter">);</span> +<span id="L414" class="LineNr">414 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L415" class="LineNr">415 </span> <span class="Constant">"run: square root of x/m32 into XMM0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L416" class="LineNr">416 </span> <span class="Constant">"run: x/m32 is XMM1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L417" class="LineNr">417 </span> <span class="Constant">"run: XMM0 is now 1.41421</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L418" class="LineNr">418 </span> <span class="Delimiter">);</span> +<span id="L419" class="LineNr">419 </span><span class="Delimiter">}</span> +<span id="L420" class="LineNr">420 </span> +<span id="L421" class="LineNr">421 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L422" class="LineNr">422 </span><span class="Normal">case</span> <span class="Constant">0x51</span>: <span class="Delimiter">{</span> <span class="Comment">// square root of x/m32 into x32</span> +<span id="L423" class="LineNr">423 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L424" class="LineNr">424 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> dest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L425" class="LineNr">425 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"square root of x/m32 into "</span> << Xname[dest] << end<span class="Delimiter">();</span> +<span id="L426" class="LineNr">426 </span> <span class="Normal">const</span> <span class="Normal">float</span>* src = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L427" class="LineNr">427 </span> Xmm[dest] = sqrt<span class="Delimiter">(</span>*src<span class="Delimiter">);</span> +<span id="L428" class="LineNr">428 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Xname[dest] << <span class="Constant">" is now "</span> << Xmm[dest] << end<span class="Delimiter">();</span> +<span id="L429" class="LineNr">429 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L430" class="LineNr">430 </span><span class="Delimiter">}</span> +<span id="L431" class="LineNr">431 </span> +<span id="L432" class="LineNr">432 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L433" class="LineNr">433 </span><span class="PreProc">#include </span><span class="Constant"><math.h></span> +<span id="L434" class="LineNr">434 </span> +<span id="L435" class="LineNr">435 </span><span class="Comment">//:: inverse square root</span> +<span id="L436" class="LineNr">436 </span> +<span id="L437" class="LineNr">437 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L438" class="LineNr">438 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"52"</span><span class="Delimiter">,</span> <span class="Constant">"inverse square root of float (rsqrtss)"</span><span class="Delimiter">);</span> +<span id="L439" class="LineNr">439 </span> +<span id="L440" class="LineNr">440 </span><span class="Delimiter">:(code)</span> +<span id="L441" class="LineNr">441 </span><span class="Normal">void</span> <a href='022float.cc.html#L441'>test_rsqrtss</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L442" class="LineNr">442 </span> Xmm[<span class="Constant">1</span>] = <span class="Constant">0.01</span><span class="Delimiter">;</span> +<span id="L443" class="LineNr">443 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L444" class="LineNr">444 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L445" class="LineNr">445 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L446" class="LineNr">446 </span> <span class="Constant">"f3 0f 52 c1 </span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L447" class="LineNr">447 </span> <span class="Comment">// ModR/M in binary: 11 (direct mode) 000 (XMM0) 001 (XMM1)</span> +<span id="L448" class="LineNr">448 </span> <span class="Delimiter">);</span> +<span id="L449" class="LineNr">449 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L450" class="LineNr">450 </span> <span class="Constant">"run: inverse square root of x/m32 into XMM0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L451" class="LineNr">451 </span> <span class="Constant">"run: x/m32 is XMM1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L452" class="LineNr">452 </span> <span class="Constant">"run: XMM0 is now 10</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L453" class="LineNr">453 </span> <span class="Delimiter">);</span> +<span id="L454" class="LineNr">454 </span><span class="Delimiter">}</span> +<span id="L455" class="LineNr">455 </span> +<span id="L456" class="LineNr">456 </span><span class="Delimiter">:(before "End Three-Byte Opcodes Starting With f3 0f")</span> +<span id="L457" class="LineNr">457 </span><span class="Normal">case</span> <span class="Constant">0x52</span>: <span class="Delimiter">{</span> <span class="Comment">// inverse square root of x/m32 into x32</span> +<span id="L458" class="LineNr">458 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L459" class="LineNr">459 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> dest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L460" class="LineNr">460 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"inverse square root of x/m32 into "</span> << Xname[dest] << end<span class="Delimiter">();</span> +<span id="L461" class="LineNr">461 </span> <span class="Normal">const</span> <span class="Normal">float</span>* src = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L462" class="LineNr">462 </span> Xmm[dest] = <span class="Constant">1.0</span> / sqrt<span class="Delimiter">(</span>*src<span class="Delimiter">);</span> +<span id="L463" class="LineNr">463 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Xname[dest] << <span class="Constant">" is now "</span> << Xmm[dest] << end<span class="Delimiter">();</span> +<span id="L464" class="LineNr">464 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L465" class="LineNr">465 </span><span class="Delimiter">}</span> +<span id="L466" class="LineNr">466 </span> +<span id="L467" class="LineNr">467 </span><span class="Delimiter">:(code)</span> +<span id="L468" class="LineNr">468 </span><span class="Normal">float</span>* <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> modrm<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L469" class="LineNr">469 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> mod = <span class="Delimiter">(</span>modrm>><span class="Constant">6</span><span class="Delimiter">);</span> +<span id="L470" class="LineNr">470 </span> <span class="Comment">// ignore middle 3 'reg opcode' bits</span> +<span id="L471" class="LineNr">471 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rm = modrm & <span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L472" class="LineNr">472 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod == <span class="Constant">3</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L473" class="LineNr">473 </span> <span class="Comment">// mod 3 is just register direct addressing</span> +<span id="L474" class="LineNr">474 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"x/m32 is "</span> << Xname[rm] << end<span class="Delimiter">();</span> +<span id="L475" class="LineNr">475 </span> <span class="Identifier">return</span> &Xmm[rm]<span class="Delimiter">;</span> +<span id="L476" class="LineNr">476 </span> <span class="Delimiter">}</span> +<span id="L477" class="LineNr">477 </span> <span class="Normal">uint32_t</span> addr = <a href='013direct_addressing.cc.html#L116'>effective_address_number</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L478" class="LineNr">478 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address contains "</span> << <a href='010vm.cc.html#L188'>read_mem_f32</a><span class="Delimiter">(</span>addr<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L479" class="LineNr">479 </span> <span class="Identifier">return</span> <a href='010vm.cc.html#L230'>mem_addr_f32</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L480" class="LineNr">480 </span><span class="Delimiter">}</span> +<span id="L481" class="LineNr">481 </span> +<span id="L482" class="LineNr">482 </span><span class="Comment">//: compare</span> +<span id="L483" class="LineNr">483 </span> +<span id="L484" class="LineNr">484 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L485" class="LineNr">485 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"2f"</span><span class="Delimiter">,</span> <span class="Constant">"compare: set <a href='010vm.cc.html#L90'>CF</a> if x32 < xm32 (comiss)"</span><span class="Delimiter">);</span> +<span id="L486" class="LineNr">486 </span> +<span id="L487" class="LineNr">487 </span><span class="Delimiter">:(code)</span> +<span id="L488" class="LineNr">488 </span><span class="Normal">void</span> <a href='022float.cc.html#L488'>test_compare_x32_with_mem_at_rm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L489" class="LineNr">489 </span> Reg[EAX]<span class="Delimiter">.</span>i = <span class="Constant">0x2000</span><span class="Delimiter">;</span> +<span id="L490" class="LineNr">490 </span> Xmm[<span class="Constant">3</span>] = <span class="Constant">0.5</span><span class="Delimiter">;</span> +<span id="L491" class="LineNr">491 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L492" class="LineNr">492 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L493" class="LineNr">493 </span> <span class="Comment">// op ModR/M SIB displacement immediate</span> +<span id="L494" class="LineNr">494 </span> <span class="Constant">" 0f 2f 18 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// compare XMM3 with *EAX</span> +<span id="L495" class="LineNr">495 </span> <span class="Comment">// ModR/M in binary: 00 (indirect mode) 011 (lhs XMM3) 000 (rhs EAX)</span> +<span id="L496" class="LineNr">496 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L497" class="LineNr">497 </span> <span class="Constant">"00 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0x00000000 = 0.0</span> +<span id="L498" class="LineNr">498 </span> <span class="Delimiter">);</span> +<span id="L499" class="LineNr">499 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L500" class="LineNr">500 </span> <span class="Constant">"run: compare XMM3 with x/m32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L501" class="LineNr">501 </span> <span class="Constant">"run: effective address is 0x00002000 (<a href='010vm.cc.html#L10'>EAX</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L502" class="LineNr">502 </span> <span class="Constant">"run: SF=0; ZF=0; CF=0; OF=0</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L503" class="LineNr">503 </span> <span class="Delimiter">);</span> +<span id="L504" class="LineNr">504 </span><span class="Delimiter">}</span> +<span id="L505" class="LineNr">505 </span> +<span id="L506" class="LineNr">506 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L507" class="LineNr">507 </span><span class="Normal">case</span> <span class="Constant">0x2f</span>: <span class="Delimiter">{</span> <span class="Comment">// set CF if x32 < x/m32</span> +<span id="L508" class="LineNr">508 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L509" class="LineNr">509 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> reg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> +<span id="L510" class="LineNr">510 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"compare "</span> << Xname[reg1] << <span class="Constant">" with x/m32"</span> << end<span class="Delimiter">();</span> +<span id="L511" class="LineNr">511 </span> <span class="Normal">const</span> <span class="Normal">float</span>* arg2 = <a href='022float.cc.html#L468'>effective_address_float</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L512" class="LineNr">512 </span> <span class="Comment">// Flag settings carefully copied from the Intel manual.</span> +<span id="L513" class="LineNr">513 </span> <span class="Comment">// See also <a href="https://stackoverflow.com/questions/7057501/x86-assembler-floating-point-compare/7057771#7057771">https://stackoverflow.com/questions/7057501/x86-assembler-floating-point-compare/7057771#7057771</a></span> +<span id="L514" class="LineNr">514 </span> SF = <a href='010vm.cc.html#L89'>ZF</a> = <a href='010vm.cc.html#L90'>CF</a> = <a href='010vm.cc.html#L91'>OF</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L515" class="LineNr">515 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Xmm[reg1] == *arg2<span class="Delimiter">)</span> <a href='010vm.cc.html#L89'>ZF</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L516" class="LineNr">516 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Xmm[reg1] < *arg2<span class="Delimiter">)</span> <a href='010vm.cc.html#L90'>CF</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L517" class="LineNr">517 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"SF="</span> << SF << <span class="Constant">"; ZF="</span> << <a href='010vm.cc.html#L89'>ZF</a> << <span class="Constant">"; CF="</span> << <a href='010vm.cc.html#L90'>CF</a> << <span class="Constant">"; OF="</span> << <a href='010vm.cc.html#L91'>OF</a> << end<span class="Delimiter">();</span> +<span id="L518" class="LineNr">518 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L519" class="LineNr">519 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/029syscalls.cc.html b/html/linux/bootstrap/029syscalls.cc.html new file mode 100644 index 00000000..75df3e81 --- /dev/null +++ b/html/linux/bootstrap/029syscalls.cc.html @@ -0,0 +1,189 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/029syscalls.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.LineNr { } +.Constant { color: #008787; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +.PreProc { color: #c000c0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/029syscalls.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/029syscalls.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L2" class="LineNr"> 2 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> <span class="Constant">"cd"</span><span class="Delimiter">,</span> <span class="Constant">"software interrupt (int)"</span><span class="Delimiter">);</span> +<span id="L3" class="LineNr"> 3 </span> +<span id="L4" class="LineNr"> 4 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L5" class="LineNr"> 5 </span><span class="Normal">case</span> <span class="Constant">0xcd</span>: <span class="Delimiter">{</span> <span class="Comment">// int imm8 (software interrupt)</span> +<span id="L6" class="LineNr"> 6 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"syscall"</span> << end<span class="Delimiter">();</span> +<span id="L7" class="LineNr"> 7 </span> <span class="Normal">uint8_t</span> code = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>code != <span class="Constant">0x80</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L9" class="LineNr"> 9 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Unimplemented interrupt code "</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << code << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L10" class="LineNr"> 10 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">" Only `int 80h` supported for now.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Delimiter">}</span> +<span id="L13" class="LineNr"> 13 </span> <a href='029syscalls.cc.html#L18'>process_int80</a><span class="Delimiter">();</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L15" class="LineNr"> 15 </span><span class="Delimiter">}</span> +<span id="L16" class="LineNr"> 16 </span> +<span id="L17" class="LineNr"> 17 </span><span class="Delimiter">:(code)</span> +<span id="L18" class="LineNr"> 18 </span><span class="Normal">void</span> <a href='029syscalls.cc.html#L18'>process_int80</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Normal">case</span> <span class="Constant">1</span>: +<span id="L21" class="LineNr"> 21 </span> exit<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">exit code</span><span class="Comment">*/</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L22" class="LineNr"> 22 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L23" class="LineNr"> 23 </span> <span class="Normal">case</span> <span class="Constant">3</span>: +<span id="L24" class="LineNr"> 24 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"read: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << Reg[ECX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << Reg[EDX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L25" class="LineNr"> 25 </span> Reg[EAX]<span class="Delimiter">.</span>i = read<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">file descriptor</span><span class="Comment">*/</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">memory buffer</span><span class="Comment">*/</span><a href='010vm.cc.html#L192'>mem_addr_u8</a><span class="Delimiter">(</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">size</span><span class="Comment">*/</span>Reg[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L26" class="LineNr"> 26 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"read: "</span> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L28" class="LineNr"> 28 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Normal">case</span> <span class="Constant">4</span>: +<span id="L30" class="LineNr"> 30 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"write: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << Reg[ECX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << Reg[EDX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L31" class="LineNr"> 31 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[ECX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010vm.cc.html#L237'>mem_addr_string</a><span class="Delimiter">(</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> Reg[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L32" class="LineNr"> 32 </span> Reg[EAX]<span class="Delimiter">.</span>i = write<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">file descriptor</span><span class="Comment">*/</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">memory buffer</span><span class="Comment">*/</span><a href='010vm.cc.html#L192'>mem_addr_u8</a><span class="Delimiter">(</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">size</span><span class="Comment">*/</span>Reg[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L33" class="LineNr"> 33 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"write: "</span> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L35" class="LineNr"> 35 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Normal">case</span> <span class="Constant">5</span>: <span class="Delimiter">{</span> +<span id="L37" class="LineNr"> 37 </span> <a href='029syscalls.cc.html#L92'>check_flags</a><span class="Delimiter">(</span><a href='010vm.cc.html#L11'>ECX</a><span class="Delimiter">);</span> +<span id="L38" class="LineNr"> 38 </span> <a href='029syscalls.cc.html#L104'>check_mode</a><span class="Delimiter">(</span><a href='010vm.cc.html#L12'>EDX</a><span class="Delimiter">);</span> +<span id="L39" class="LineNr"> 39 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"open: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << Reg[ECX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L40" class="LineNr"> 40 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L41" class="LineNr"> 41 </span> Reg[EAX]<span class="Delimiter">.</span>i = open<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">filename</span><span class="Comment">*/</span><a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">flags</span><span class="Comment">*/</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">mode</span><span class="Comment">*/</span><span class="PreProc">0</span><span class="Constant">640</span><span class="Delimiter">);</span> +<span id="L42" class="LineNr"> 42 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"open: "</span> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Delimiter">}</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Normal">case</span> <span class="Constant">6</span>: +<span id="L47" class="LineNr"> 47 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"close: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L48" class="LineNr"> 48 </span> Reg[EAX]<span class="Delimiter">.</span>i = close<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">file descriptor</span><span class="Comment">*/</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L49" class="LineNr"> 49 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"close: "</span> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Normal">case</span> <span class="Constant">8</span>: +<span id="L53" class="LineNr"> 53 </span> <a href='029syscalls.cc.html#L104'>check_mode</a><span class="Delimiter">(</span><a href='010vm.cc.html#L11'>ECX</a><span class="Delimiter">);</span> +<span id="L54" class="LineNr"> 54 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"creat: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L55" class="LineNr"> 55 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L56" class="LineNr"> 56 </span> Reg[EAX]<span class="Delimiter">.</span>i = creat<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">filename</span><span class="Comment">*/</span><a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">mode</span><span class="Comment">*/</span><span class="PreProc">0</span><span class="Constant">640</span><span class="Delimiter">);</span> +<span id="L57" class="LineNr"> 57 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"creat: "</span> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Normal">case</span> <span class="Constant">10</span>: +<span id="L61" class="LineNr"> 61 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"unlink: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L62" class="LineNr"> 62 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L63" class="LineNr"> 63 </span> Reg[EAX]<span class="Delimiter">.</span>i = unlink<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">filename</span><span class="Comment">*/</span><a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">));</span> +<span id="L64" class="LineNr"> 64 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"unlink: "</span> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Normal">case</span> <span class="Constant">38</span>: +<span id="L68" class="LineNr"> 68 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"rename: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" -> "</span> << Reg[ECX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L69" class="LineNr"> 69 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L70" class="LineNr"> 70 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[ECX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L71" class="LineNr"> 71 </span> Reg[EAX]<span class="Delimiter">.</span>i = rename<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">old filename</span><span class="Comment">*/</span><a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">new filename</span><span class="Comment">*/</span><a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">));</span> +<span id="L72" class="LineNr"> 72 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"rename: "</span> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Normal">case</span> <span class="Constant">90</span>: <span class="Comment">// mmap: allocate memory outside existing segment allocations</span> +<span id="L76" class="LineNr"> 76 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"mmap: allocate new segment"</span> << end<span class="Delimiter">();</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Comment">// Ignore most arguments for now: address hint, protection flags, sharing flags, fd, offset.</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Comment">// We only support anonymous maps.</span> +<span id="L79" class="LineNr"> 79 </span> Reg[EAX]<span class="Delimiter">.</span>u = <a href='029syscalls.cc.html#L116'>new_segment</a><span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">length</span><span class="Comment">*/</span><a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u+<span class="Constant">0x4</span><span class="Delimiter">));</span> +<span id="L80" class="LineNr"> 80 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Normal">case</span> <span class="Constant">0xa2</span>: <span class="Comment">// nanosleep</span> +<span id="L83" class="LineNr"> 83 </span> cerr << <span class="Constant">"not sleeping</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Normal">default</span>: +<span id="L86" class="LineNr"> 86 </span> <a href='003trace.cc.html#L226'>raise</a> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L26'>EIP</a> << <span class="Constant">": unimplemented syscall "</span> << Reg[EAX]<span class="Delimiter">.</span>u << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Delimiter">}</span> +<span id="L88" class="LineNr"> 88 </span><span class="Delimiter">}</span> +<span id="L89" class="LineNr"> 89 </span> +<span id="L90" class="LineNr"> 90 </span><span class="Comment">// SubX is oblivious to file permissions, directories, symbolic links, terminals, and much else besides.</span> +<span id="L91" class="LineNr"> 91 </span><span class="Comment">// Also ignoring any concurrency considerations for now.</span> +<span id="L92" class="LineNr"> 92 </span><span class="Normal">void</span> <a href='029syscalls.cc.html#L92'>check_flags</a><span class="Delimiter">(</span><span class="Normal">int</span> <a href='010vm.cc.html#L20'>reg</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Normal">uint32_t</span> flags = Reg[reg]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>flags != <span class="Delimiter">((</span>flags & O_RDONLY<span class="Delimiter">)</span> | <span class="Delimiter">(</span>flags & O_WRONLY<span class="Delimiter">)))</span> <span class="Delimiter">{</span> +<span id="L95" class="LineNr"> 95 </span> cerr << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L26'>EIP</a> << <span class="Constant">": most POSIX flags to the open() syscall are not supported. Just O_RDONLY and O_WRONLY for now. Zero concurrent access support.</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L96" class="LineNr"> 96 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Delimiter">}</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>flags & O_RDONLY<span class="Delimiter">)</span> && <span class="Delimiter">(</span>flags & O_WRONLY<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L99" class="LineNr"> 99 </span> cerr << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L26'>EIP</a> << <span class="Constant">": can't open a file for both reading and writing at once. See <a href="http://man7.org/linux/man-pages/man2/open.2.html.">http://man7.org/linux/man-pages/man2/open.2.html.</a></span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L100" class="LineNr">100 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L101" class="LineNr">101 </span> <span class="Delimiter">}</span> +<span id="L102" class="LineNr">102 </span><span class="Delimiter">}</span> +<span id="L103" class="LineNr">103 </span> +<span id="L104" class="LineNr">104 </span><span class="Normal">void</span> <a href='029syscalls.cc.html#L104'>check_mode</a><span class="Delimiter">(</span><span class="Normal">int</span> <a href='010vm.cc.html#L20'>reg</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L105" class="LineNr">105 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[reg]<span class="Delimiter">.</span>u != <span class="PreProc">0</span><span class="Constant">600</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L106" class="LineNr">106 </span> cerr << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L26'>EIP</a> << <span class="Constant">": SubX is oblivious to file permissions; register "</span> << <a href='010vm.cc.html#L20'>reg</a> << <span class="Constant">" must be 0x180.</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L107" class="LineNr">107 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L108" class="LineNr">108 </span> <span class="Delimiter">}</span> +<span id="L109" class="LineNr">109 </span><span class="Delimiter">}</span> +<span id="L110" class="LineNr">110 </span> +<span id="L111" class="LineNr">111 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L112" class="LineNr">112 </span><span class="Comment">// Very primitive/fixed/insecure mmap segments for now.</span> +<span id="L113" class="LineNr">113 </span><span class="Normal">uint32_t</span> <a href='029syscalls.cc.html#L113'>Segments_allocated_above</a> = <a href='012elf.cc.html#L151'>END_HEAP</a><span class="Delimiter">;</span> +<span id="L114" class="LineNr">114 </span><span class="Delimiter">:(code)</span> +<span id="L115" class="LineNr">115 </span><span class="Comment">// always allocate multiples of the segment size</span> +<span id="L116" class="LineNr">116 </span><span class="Normal">uint32_t</span> <a href='029syscalls.cc.html#L116'>new_segment</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> length<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L117" class="LineNr">117 </span> assert<span class="Delimiter">(</span>length > <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L118" class="LineNr">118 </span> <span class="Normal">uint32_t</span> result = <span class="Delimiter">(</span><a href='029syscalls.cc.html#L113'>Segments_allocated_above</a> - length<span class="Delimiter">)</span> & <span class="Constant">0xff000000</span><span class="Delimiter">;</span> <span class="Comment">// same number of zeroes as SEGMENT_ALIGNMENT</span> +<span id="L119" class="LineNr">119 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result <= <a href='012elf.cc.html#L150'>START_HEAP</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L120" class="LineNr">120 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"Allocated too many segments; the VM ran out of memory. "</span> +<span id="L121" class="LineNr">121 </span> << <span class="Constant">"Maybe <a href='010vm.cc.html#L98'>SEGMENT_ALIGNMENT</a> can be smaller?</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> +<span id="L122" class="LineNr">122 </span> <span class="Delimiter">}</span> +<span id="L123" class="LineNr">123 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span>result<span class="Delimiter">,</span> result+length<span class="Delimiter">));</span> +<span id="L124" class="LineNr">124 </span> <a href='029syscalls.cc.html#L113'>Segments_allocated_above</a> = result<span class="Delimiter">;</span> +<span id="L125" class="LineNr">125 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L126" class="LineNr">126 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/030translate.cc.html b/html/linux/bootstrap/030translate.cc.html new file mode 100644 index 00000000..c63a7fa8 --- /dev/null +++ b/html/linux/bootstrap/030translate.cc.html @@ -0,0 +1,270 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/030translate.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.SalientComment { color: #0000af; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +.PreProc { color: #c000c0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/030translate.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/030translate.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: After that lengthy prelude to define an x86 emulator, we are now ready to</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: start translating SubX notation.</span> +<span id="L3" class="LineNr"> 3 </span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: Translator workflow: read 'source' file. Run a series of transforms on it,</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: each passing through what it doesn't understand. The final program should</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment">//: be just machine code, suitable to emulate, or to write to an ELF binary.</span> +<span id="L7" class="LineNr"> 7 </span> +<span id="L8" class="LineNr"> 8 </span><span class="Delimiter">:(before "End Main")</span> +<span id="L9" class="LineNr"> 9 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L98'>is_equal</a><span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"translate"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L10" class="LineNr"> 10 </span> <span class="Comment">// Outside of tests, traces must be explicitly requested.</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L446'>Trace_file</a><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> <a href='003trace.cc.html#L72'>Trace_stream</a> = <span class="Normal">new</span> trace_stream<span class="Delimiter">;</span> +<span id="L12" class="LineNr"> 12 </span> <a href='000organization.cc.html#L150'>reset</a><span class="Delimiter">();</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Comment">// Begin bootstrap translate</span> +<span id="L14" class="LineNr"> 14 </span> program p<span class="Delimiter">;</span> +<span id="L15" class="LineNr"> 15 </span> string output_filename<span class="Delimiter">;</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Comment">/*</span><span class="Comment">skip 'bootstrap translate'</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">;</span> i < argc<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L98'>is_equal</a><span class="Delimiter">(</span>argv[i]<span class="Delimiter">,</span> <span class="Constant">"-o"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L18" class="LineNr"> 18 </span> ++i<span class="Delimiter">;</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i >= argc<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L20" class="LineNr"> 20 </span> <a href='030translate.cc.html#L65'>print_translate_usage</a><span class="Delimiter">();</span> +<span id="L21" class="LineNr"> 21 </span> cerr << <span class="Constant">"'-o' must be followed by a filename to write results to</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L22" class="LineNr"> 22 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L23" class="LineNr"> 23 </span> <span class="Delimiter">}</span> +<span id="L24" class="LineNr"> 24 </span> output_filename = argv[i]<span class="Delimiter">;</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Delimiter">}</span> +<span id="L26" class="LineNr"> 26 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L27" class="LineNr"> 27 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << argv[i] << end<span class="Delimiter">();</span> +<span id="L28" class="LineNr"> 28 </span> ifstream fin<span class="Delimiter">(</span>argv[i]<span class="Delimiter">);</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!fin<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L30" class="LineNr"> 30 </span> cerr << <span class="Constant">"could not open "</span> << argv[i] << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L31" class="LineNr"> 31 </span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Delimiter">}</span> +<span id="L33" class="LineNr"> 33 </span> parse<span class="Delimiter">(</span>fin<span class="Delimiter">,</span> p<span class="Delimiter">);</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L35" class="LineNr"> 35 </span> <span class="Delimiter">}</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Delimiter">}</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L38" class="LineNr"> 38 </span> <a href='030translate.cc.html#L65'>print_translate_usage</a><span class="Delimiter">();</span> +<span id="L39" class="LineNr"> 39 </span> cerr << <span class="Constant">"nothing to do; must provide at least one file to read</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L40" class="LineNr"> 40 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L41" class="LineNr"> 41 </span> <span class="Delimiter">}</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>output_filename<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L43" class="LineNr"> 43 </span> <a href='030translate.cc.html#L65'>print_translate_usage</a><span class="Delimiter">();</span> +<span id="L44" class="LineNr"> 44 </span> cerr << <span class="Constant">"must provide a filename to write to using '-o'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L45" class="LineNr"> 45 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Delimiter">}</span> +<span id="L47" class="LineNr"> 47 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"begin"</span> << end<span class="Delimiter">();</span> +<span id="L48" class="LineNr"> 48 </span> transform<span class="Delimiter">(</span>p<span class="Delimiter">);</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L50" class="LineNr"> 50 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">"translate"</span><span class="Delimiter">)</span> << <span class="Constant">"begin"</span> << end<span class="Delimiter">();</span> +<span id="L51" class="LineNr"> 51 </span> save_elf<span class="Delimiter">(</span>p<span class="Delimiter">,</span> output_filename<span class="Delimiter">);</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L53" class="LineNr"> 53 </span> unlink<span class="Delimiter">(</span>output_filename<span class="Delimiter">.</span>c_str<span class="Delimiter">());</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L55" class="LineNr"> 55 </span> <span class="Delimiter">}</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Comment">// End bootstrap translate</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L58" class="LineNr"> 58 </span><span class="Delimiter">}</span> +<span id="L59" class="LineNr"> 59 </span> +<span id="L60" class="LineNr"> 60 </span><span class="Delimiter">:(code)</span> +<span id="L61" class="LineNr"> 61 </span><span class="Normal">void</span> transform<span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Comment">// End transform(program& p)</span> +<span id="L63" class="LineNr"> 63 </span><span class="Delimiter">}</span> +<span id="L64" class="LineNr"> 64 </span> +<span id="L65" class="LineNr"> 65 </span><span class="Normal">void</span> <a href='030translate.cc.html#L65'>print_translate_usage</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L66" class="LineNr"> 66 </span> cerr << <span class="Constant">"Usage: bootstrap translate file1 file2 ... -o output</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L67" class="LineNr"> 67 </span><span class="Delimiter">}</span> +<span id="L68" class="LineNr"> 68 </span> +<span id="L69" class="LineNr"> 69 </span><span class="Comment">// write out a program to a bare-bones ELF file</span> +<span id="L70" class="LineNr"> 70 </span><span class="Normal">void</span> save_elf<span class="Delimiter">(</span><span class="Normal">const</span> program& p<span class="Delimiter">,</span> <span class="Normal">const</span> string& filename<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L71" class="LineNr"> 71 </span> ofstream out<span class="Delimiter">(</span>filename<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> ios::binary<span class="Delimiter">);</span> +<span id="L72" class="LineNr"> 72 </span> save_elf<span class="Delimiter">(</span>p<span class="Delimiter">,</span> out<span class="Delimiter">);</span> +<span id="L73" class="LineNr"> 73 </span> out<span class="Delimiter">.</span>close<span class="Delimiter">();</span> +<span id="L74" class="LineNr"> 74 </span><span class="Delimiter">}</span> +<span id="L75" class="LineNr"> 75 </span> +<span id="L76" class="LineNr"> 76 </span><span class="Normal">void</span> save_elf<span class="Delimiter">(</span><span class="Normal">const</span> program& p<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Comment">// validation: stay consistent with the self-hosted translator</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L105'>entry</a> == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L79" class="LineNr"> 79 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"no 'Entry' label found</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Delimiter">}</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>find<span class="Delimiter">(</span>p<span class="Delimiter">,</span> <span class="Constant">"data"</span><span class="Delimiter">)</span> == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L83" class="LineNr"> 83 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"must include a 'data' segment</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Delimiter">}</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Comment">// processing</span> +<span id="L87" class="LineNr"> 87 </span> <a href='030translate.cc.html#L92'>write_elf_header</a><span class="Delimiter">(</span>out<span class="Delimiter">,</span> p<span class="Delimiter">);</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> +<span id="L89" class="LineNr"> 89 </span> <a href='030translate.cc.html#L188'>write_segment</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> out<span class="Delimiter">);</span> +<span id="L90" class="LineNr"> 90 </span><span class="Delimiter">}</span> +<span id="L91" class="LineNr"> 91 </span> +<span id="L92" class="LineNr"> 92 </span><span class="Normal">void</span> <a href='030translate.cc.html#L92'>write_elf_header</a><span class="Delimiter">(</span>ostream& out<span class="Delimiter">,</span> <span class="Normal">const</span> program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Normal">char</span> c = <span class="cSpecial">'\0'</span><span class="Delimiter">;</span> +<span id="L94" class="LineNr"> 94 </span><span class="PreProc">#define O(X) c = (X)</span><span class="Delimiter">;</span><span class="PreProc"> out</span><span class="Delimiter">.</span><span class="PreProc">write(&c</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Normal">sizeof</span><span class="PreProc">(c))</span> +<span id="L95" class="LineNr"> 95 </span><span class="Comment">// host is required to be little-endian</span> +<span id="L96" class="LineNr"> 96 </span><span class="PreProc">#define emit(X) out</span><span class="Delimiter">.</span><span class="PreProc">write(</span><span class="Normal">reinterpret_cast</span><span class="PreProc"><</span><span class="Normal">const</span><span class="PreProc"> </span><span class="Normal">char</span><span class="PreProc">*>(&X)</span><span class="Delimiter">,</span><span class="PreProc"> </span><span class="Normal">sizeof</span><span class="PreProc">(X))</span> +<span id="L97" class="LineNr"> 97 </span> <span class="SalientComment">//// ehdr</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Comment">// e_ident</span> +<span id="L99" class="LineNr"> 99 </span> O<span class="Delimiter">(</span><span class="Constant">0x7f</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">E</span><span class="Comment">*/</span><span class="Constant">0x45</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">L</span><span class="Comment">*/</span><span class="Constant">0x4c</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">F</span><span class="Comment">*/</span><span class="Constant">0x46</span><span class="Delimiter">);</span> +<span id="L100" class="LineNr">100 </span> O<span class="Delimiter">(</span><span class="Constant">0x1</span><span class="Delimiter">);</span> <span class="Comment">// 32-bit format</span> +<span id="L101" class="LineNr">101 </span> O<span class="Delimiter">(</span><span class="Constant">0x1</span><span class="Delimiter">);</span> <span class="Comment">// little-endian</span> +<span id="L102" class="LineNr">102 </span> O<span class="Delimiter">(</span><span class="Constant">0x1</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Constant">0x0</span><span class="Delimiter">);</span> +<span id="L103" class="LineNr">103 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Constant">8</span><span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> O<span class="Delimiter">(</span><span class="Constant">0x0</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> +<span id="L104" class="LineNr">104 </span> <span class="Comment">// e_type</span> +<span id="L105" class="LineNr">105 </span> O<span class="Delimiter">(</span><span class="Constant">0x02</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L106" class="LineNr">106 </span> <span class="Comment">// e_machine</span> +<span id="L107" class="LineNr">107 </span> O<span class="Delimiter">(</span><span class="Constant">0x03</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L108" class="LineNr">108 </span> <span class="Comment">// e_version</span> +<span id="L109" class="LineNr">109 </span> O<span class="Delimiter">(</span><span class="Constant">0x01</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L110" class="LineNr">110 </span> <span class="Comment">// e_entry</span> +<span id="L111" class="LineNr">111 </span> <span class="Normal">uint32_t</span> e_entry = p<span class="Delimiter">.</span><a href='011run.cc.html#L105'>entry</a><span class="Delimiter">;</span> +<span id="L112" class="LineNr">112 </span> <span class="Comment">// Override e_entry</span> +<span id="L113" class="LineNr">113 </span> emit<span class="Delimiter">(</span>e_entry<span class="Delimiter">);</span> +<span id="L114" class="LineNr">114 </span> <span class="Comment">// e_phoff -- immediately after ELF header</span> +<span id="L115" class="LineNr">115 </span> <span class="Normal">uint32_t</span> e_phoff = <span class="Constant">0x34</span><span class="Delimiter">;</span> +<span id="L116" class="LineNr">116 </span> emit<span class="Delimiter">(</span>e_phoff<span class="Delimiter">);</span> +<span id="L117" class="LineNr">117 </span> <span class="Comment">// e_shoff; unused</span> +<span id="L118" class="LineNr">118 </span> <span class="Normal">uint32_t</span> dummy32 = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L119" class="LineNr">119 </span> emit<span class="Delimiter">(</span>dummy32<span class="Delimiter">);</span> +<span id="L120" class="LineNr">120 </span> <span class="Comment">// e_flags; unused</span> +<span id="L121" class="LineNr">121 </span> emit<span class="Delimiter">(</span>dummy32<span class="Delimiter">);</span> +<span id="L122" class="LineNr">122 </span> <span class="Comment">// e_ehsize</span> +<span id="L123" class="LineNr">123 </span> <span class="Normal">uint16_t</span> e_ehsize = <span class="Constant">0x34</span><span class="Delimiter">;</span> +<span id="L124" class="LineNr">124 </span> emit<span class="Delimiter">(</span>e_ehsize<span class="Delimiter">);</span> +<span id="L125" class="LineNr">125 </span> <span class="Comment">// e_phentsize</span> +<span id="L126" class="LineNr">126 </span> <span class="Normal">uint16_t</span> e_phentsize = <span class="Constant">0x20</span><span class="Delimiter">;</span> +<span id="L127" class="LineNr">127 </span> emit<span class="Delimiter">(</span>e_phentsize<span class="Delimiter">);</span> +<span id="L128" class="LineNr">128 </span> <span class="Comment">// e_phnum</span> +<span id="L129" class="LineNr">129 </span> <span class="Normal">uint16_t</span> e_phnum = <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">);</span> +<span id="L130" class="LineNr">130 </span> emit<span class="Delimiter">(</span>e_phnum<span class="Delimiter">);</span> +<span id="L131" class="LineNr">131 </span> <span class="Comment">// e_shentsize</span> +<span id="L132" class="LineNr">132 </span> <span class="Normal">uint16_t</span> dummy16 = <span class="Constant">0x0</span><span class="Delimiter">;</span> +<span id="L133" class="LineNr">133 </span> emit<span class="Delimiter">(</span>dummy16<span class="Delimiter">);</span> +<span id="L134" class="LineNr">134 </span> <span class="Comment">// e_shnum</span> +<span id="L135" class="LineNr">135 </span> emit<span class="Delimiter">(</span>dummy16<span class="Delimiter">);</span> +<span id="L136" class="LineNr">136 </span> <span class="Comment">// e_shstrndx</span> +<span id="L137" class="LineNr">137 </span> emit<span class="Delimiter">(</span>dummy16<span class="Delimiter">);</span> +<span id="L138" class="LineNr">138 </span> +<span id="L139" class="LineNr">139 </span> <span class="Normal">uint32_t</span> p_offset = <span class="Comment">/*</span><span class="Comment">size of ehdr</span><span class="Comment">*/</span><span class="Constant">0x34</span> + <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">)</span>*<span class="Constant">0x20</span><span class="Comment">/*</span><span class="Comment">size of each phdr</span><span class="Comment">*/</span><span class="Delimiter">;</span> +<span id="L140" class="LineNr">140 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L141" class="LineNr">141 </span> <span class="Normal">const</span> segment& curr = p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L142" class="LineNr">142 </span> <span class="SalientComment">//// phdr</span> +<span id="L143" class="LineNr">143 </span> <span class="Comment">// p_type</span> +<span id="L144" class="LineNr">144 </span> <span class="Normal">uint32_t</span> p_type = <span class="Constant">0x1</span><span class="Delimiter">;</span> +<span id="L145" class="LineNr">145 </span> emit<span class="Delimiter">(</span>p_type<span class="Delimiter">);</span> +<span id="L146" class="LineNr">146 </span> <span class="Comment">// p_offset</span> +<span id="L147" class="LineNr">147 </span> emit<span class="Delimiter">(</span>p_offset<span class="Delimiter">);</span> +<span id="L148" class="LineNr">148 </span> <span class="Comment">// p_vaddr</span> +<span id="L149" class="LineNr">149 </span> <span class="Normal">uint32_t</span> p_start = curr<span class="Delimiter">.</span>start<span class="Delimiter">;</span> +<span id="L150" class="LineNr">150 </span> emit<span class="Delimiter">(</span>p_start<span class="Delimiter">);</span> +<span id="L151" class="LineNr">151 </span> <span class="Comment">// p_paddr</span> +<span id="L152" class="LineNr">152 </span> emit<span class="Delimiter">(</span>p_start<span class="Delimiter">);</span> +<span id="L153" class="LineNr">153 </span> <span class="Comment">// p_filesz</span> +<span id="L154" class="LineNr">154 </span> <span class="Normal">uint32_t</span> size = <a href='030translate.cc.html#L198'>num_words</a><span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L155" class="LineNr">155 </span> assert<span class="Delimiter">(</span>p_offset + size < <a href='010vm.cc.html#L98'>SEGMENT_ALIGNMENT</a><span class="Delimiter">);</span> +<span id="L156" class="LineNr">156 </span> emit<span class="Delimiter">(</span>size<span class="Delimiter">);</span> +<span id="L157" class="LineNr">157 </span> <span class="Comment">// p_memsz</span> +<span id="L158" class="LineNr">158 </span> emit<span class="Delimiter">(</span>size<span class="Delimiter">);</span> +<span id="L159" class="LineNr">159 </span> <span class="Comment">// p_flags</span> +<span id="L160" class="LineNr">160 </span> <span class="Normal">uint32_t</span> p_flags = <span class="Delimiter">(</span>curr<span class="Delimiter">.</span><a href='011run.cc.html#L111'>name</a> == <span class="Constant">"code"</span><span class="Delimiter">)</span> ? <span class="Comment">/*</span><span class="Comment">r-x</span><span class="Comment">*/</span><span class="Constant">0x5</span> : <span class="Comment">/*</span><span class="Comment">rw-</span><span class="Comment">*/</span><span class="Constant">0x6</span><span class="Delimiter">;</span> +<span id="L161" class="LineNr">161 </span> emit<span class="Delimiter">(</span>p_flags<span class="Delimiter">);</span> +<span id="L162" class="LineNr">162 </span> +<span id="L163" class="LineNr">163 </span> <span class="Comment">// p_align</span> +<span id="L164" class="LineNr">164 </span> <span class="Comment">// "As the system creates or augments a process image, it logically copies</span> +<span id="L165" class="LineNr">165 </span> <span class="Comment">// a file's segment to a virtual memory segment. When—and if— the system</span> +<span id="L166" class="LineNr">166 </span> <span class="Comment">// physically reads the file depends on the program's execution behavior,</span> +<span id="L167" class="LineNr">167 </span> <span class="Comment">// system load, and so on. A process does not require a physical page</span> +<span id="L168" class="LineNr">168 </span> <span class="Comment">// unless it references the logical page during execution, and processes</span> +<span id="L169" class="LineNr">169 </span> <span class="Comment">// commonly leave many pages unreferenced. Therefore delaying physical</span> +<span id="L170" class="LineNr">170 </span> <span class="Comment">// reads frequently obviates them, improving system performance. To obtain</span> +<span id="L171" class="LineNr">171 </span> <span class="Comment">// this efficiency in practice, executable and shared object files must</span> +<span id="L172" class="LineNr">172 </span> <span class="Comment">// have segment images whose file offsets and virtual addresses are</span> +<span id="L173" class="LineNr">173 </span> <span class="Comment">// congruent, modulo the page size." -- <a href="http://refspecs.linuxbase.org/elf/elf.pdf">http://refspecs.linuxbase.org/elf/elf.pdf</a> (page 95)</span> +<span id="L174" class="LineNr">174 </span> <span class="Normal">uint32_t</span> p_align = <span class="Constant">0x1000</span><span class="Delimiter">;</span> <span class="Comment">// default page size on linux</span> +<span id="L175" class="LineNr">175 </span> emit<span class="Delimiter">(</span>p_align<span class="Delimiter">);</span> +<span id="L176" class="LineNr">176 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p_offset % p_align != p_start % p_align<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L177" class="LineNr">177 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"segment starting at 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << p_start << <span class="Constant">" is improperly aligned; alignment for p_offset "</span> << p_offset << <span class="Constant">" should be "</span> << <span class="Delimiter">(</span>p_offset % p_align<span class="Delimiter">)</span> << <span class="Constant">" but is "</span> << <span class="Delimiter">(</span>p_start % p_align<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L178" class="LineNr">178 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L179" class="LineNr">179 </span> <span class="Delimiter">}</span> +<span id="L180" class="LineNr">180 </span> +<span id="L181" class="LineNr">181 </span> <span class="Comment">// prepare for next segment</span> +<span id="L182" class="LineNr">182 </span> p_offset += size<span class="Delimiter">;</span> +<span id="L183" class="LineNr">183 </span> <span class="Delimiter">}</span> +<span id="L184" class="LineNr">184 </span><span class="PreProc">#undef O</span> +<span id="L185" class="LineNr">185 </span><span class="PreProc">#undef emit</span> +<span id="L186" class="LineNr">186 </span><span class="Delimiter">}</span> +<span id="L187" class="LineNr">187 </span> +<span id="L188" class="LineNr">188 </span><span class="Normal">void</span> <a href='030translate.cc.html#L188'>write_segment</a><span class="Delimiter">(</span><span class="Normal">const</span> segment& s<span class="Delimiter">,</span> ostream& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L189" class="LineNr">189 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L190" class="LineNr">190 </span> <span class="Normal">const</span> vector<word>& w = s<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">;</span> +<span id="L191" class="LineNr">191 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>w<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L192" class="LineNr">192 </span> <span class="Normal">uint8_t</span> x = <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">).</span>data<span class="Delimiter">);</span> <span class="Comment">// we're done with metadata by this point</span> +<span id="L193" class="LineNr">193 </span> out<span class="Delimiter">.</span>write<span class="Delimiter">(</span><span class="Normal">reinterpret_cast</span><<span class="Normal">const</span> <span class="Normal">char</span>*><span class="Delimiter">(</span>&x<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">sizeof(byte)</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L194" class="LineNr">194 </span> <span class="Delimiter">}</span> +<span id="L195" class="LineNr">195 </span> <span class="Delimiter">}</span> +<span id="L196" class="LineNr">196 </span><span class="Delimiter">}</span> +<span id="L197" class="LineNr">197 </span> +<span id="L198" class="LineNr">198 </span><span class="Normal">uint32_t</span> <a href='030translate.cc.html#L198'>num_words</a><span class="Delimiter">(</span><span class="Normal">const</span> segment& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L199" class="LineNr">199 </span> <span class="Normal">uint32_t</span> sum = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L200" class="LineNr">200 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L201" class="LineNr">201 </span> sum += <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> +<span id="L202" class="LineNr">202 </span> <span class="Identifier">return</span> sum<span class="Delimiter">;</span> +<span id="L203" class="LineNr">203 </span><span class="Delimiter">}</span> +<span id="L204" class="LineNr">204 </span> +<span id="L205" class="LineNr">205 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L206" class="LineNr">206 </span><span class="Normal">using</span> std::ios<span class="Delimiter">;</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/031transforms.cc.html b/html/linux/bootstrap/031transforms.cc.html new file mode 100644 index 00000000..4d5b3ff4 --- /dev/null +++ b/html/linux/bootstrap/031transforms.cc.html @@ -0,0 +1,72 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/031transforms.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.LineNr { } +.Constant { color: #008787; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/031transforms.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/031transforms.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L2" class="LineNr"> 2 </span><span class="Normal">typedef</span> <span class="Normal">void</span> <span class="Delimiter">(</span>*transform_fn<span class="Delimiter">)(</span>program&<span class="Delimiter">);</span> +<span id="L3" class="LineNr"> 3 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L4" class="LineNr"> 4 </span>vector<transform_fn> <a href='031transforms.cc.html#L4'>Transform</a><span class="Delimiter">;</span> +<span id="L5" class="LineNr"> 5 </span> +<span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(before "End transform(program& p)")</span> +<span id="L7" class="LineNr"> 7 </span><span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> t = <span class="Constant">0</span><span class="Delimiter">;</span> t < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span><a href='031transforms.cc.html#L4'>Transform</a><span class="Delimiter">);</span> ++t<span class="Delimiter">)</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Delimiter">(</span>*Transform<span class="Delimiter">.</span>at<span class="Delimiter">(</span>t<span class="Delimiter">))(</span>p<span class="Delimiter">);</span> +<span id="L9" class="LineNr"> 9 </span> +<span id="L10" class="LineNr">10 </span><span class="Delimiter">:(before "End One-time Setup")</span> +<span id="L11" class="LineNr">11 </span><span class="Comment">// Begin Transforms</span> +<span id="L12" class="LineNr">12 </span><span class="Comment">// End Transforms</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/032operands.cc.html b/html/linux/bootstrap/032operands.cc.html new file mode 100644 index 00000000..b4d9f1ff --- /dev/null +++ b/html/linux/bootstrap/032operands.cc.html @@ -0,0 +1,703 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/032operands.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.LineNr { } +.Constant { color: #008787; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/032operands.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/032operands.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: Metadata for fields of an x86 instruction.</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//:</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: The x86 instruction set is variable-length, and how a byte is interpreted</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: affects later instruction boundaries. A lot of the pain in programming</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: machine code stems from computer and programmer going out of sync on what</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment">//: a byte means. The miscommunication is usually not immediately caught, and</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment">//: metastasizes at runtime into kilobytes of misinterpreted instructions.</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment">//:</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment">//: To mitigate these issues, we'll start programming in terms of logical</span> +<span id="L10" class="LineNr"> 10 </span><span class="Comment">//: arguments rather than physical bytes. Some arguments are smaller than a</span> +<span id="L11" class="LineNr"> 11 </span><span class="Comment">//: byte, and others may consist of multiple bytes. This layer will correctly</span> +<span id="L12" class="LineNr"> 12 </span><span class="Comment">//: pack and order the bytes corresponding to the arguments in an instruction.</span> +<span id="L13" class="LineNr"> 13 </span> +<span id="L14" class="LineNr"> 14 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Texts")</span> +<span id="L15" class="LineNr"> 15 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"instructions"</span><span class="Delimiter">,</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Constant">"Each x86 instruction consists of an instruction or opcode and some number</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Constant">"of arguments.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"Each argument has a type. An instruction won't have more than one argument of</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"any type.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"Each instruction has some set of allowed argument types. It'll reject others.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Constant">"The complete list of argument types: mod, subop, r32 (integer register),</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L22" class="LineNr"> 22 </span> <span class="Constant">"rm32 (integer register or memory), x32 (floating point register),</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L23" class="LineNr"> 23 </span> <span class="Constant">"xm32 (floating point register or memory), scale, index, base, disp8, disp16,</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Constant">"disp32,imm8,imm32.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Constant">"Each of these has its own help page. Try reading 'bootstrap help mod' next.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L26" class="LineNr"> 26 </span><span class="Delimiter">);</span> +<span id="L27" class="LineNr"> 27 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Contents")</span> +<span id="L28" class="LineNr"> 28 </span>cerr << <span class="Constant">" instructions</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L29" class="LineNr"> 29 </span> +<span id="L30" class="LineNr"> 30 </span><span class="Delimiter">:(before "Running Test Program")</span> +<span id="L31" class="LineNr"> 31 </span>transform<span class="Delimiter">(</span>p<span class="Delimiter">);</span> +<span id="L32" class="LineNr"> 32 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L33" class="LineNr"> 33 </span> +<span id="L34" class="LineNr"> 34 </span><span class="Delimiter">:(code)</span> +<span id="L35" class="LineNr"> 35 </span><span class="Normal">void</span> <a href='032operands.cc.html#L35'>test_pack_immediate_constants</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L36" class="LineNr"> 36 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L38" class="LineNr"> 38 </span> <span class="Constant">"bb 0x2a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L39" class="LineNr"> 39 </span> <span class="Delimiter">);</span> +<span id="L40" class="LineNr"> 40 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L41" class="LineNr"> 41 </span> <span class="Constant">"transform: packing instruction 'bb 0x2a/imm32'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Constant">"transform: instruction after packing: 'bb 2a 00 00 00'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Constant">"run: copy imm32 0x0000002a to <a href='010vm.cc.html#L13'>EBX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Delimiter">);</span> +<span id="L45" class="LineNr"> 45 </span><span class="Delimiter">}</span> +<span id="L46" class="LineNr"> 46 </span> +<span id="L47" class="LineNr"> 47 </span><span class="Comment">//: complete set of valid argument types</span> +<span id="L48" class="LineNr"> 48 </span> +<span id="L49" class="LineNr"> 49 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L50" class="LineNr"> 50 </span>set<string> <a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">;</span> +<span id="L51" class="LineNr"> 51 </span><span class="Delimiter">:(before "End One-time Setup")</span> +<span id="L52" class="LineNr"> 52 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"subop"</span><span class="Delimiter">);</span> +<span id="L53" class="LineNr"> 53 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"mod"</span><span class="Delimiter">);</span> +<span id="L54" class="LineNr"> 54 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"rm32"</span><span class="Delimiter">);</span> +<span id="L55" class="LineNr"> 55 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"xm32"</span><span class="Delimiter">);</span> +<span id="L56" class="LineNr"> 56 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"base"</span><span class="Delimiter">);</span> +<span id="L57" class="LineNr"> 57 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"index"</span><span class="Delimiter">);</span> +<span id="L58" class="LineNr"> 58 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"scale"</span><span class="Delimiter">);</span> +<span id="L59" class="LineNr"> 59 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"r32"</span><span class="Delimiter">);</span> +<span id="L60" class="LineNr"> 60 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"x32"</span><span class="Delimiter">);</span> +<span id="L61" class="LineNr"> 61 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"disp8"</span><span class="Delimiter">);</span> +<span id="L62" class="LineNr"> 62 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"disp16"</span><span class="Delimiter">);</span> +<span id="L63" class="LineNr"> 63 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"disp32"</span><span class="Delimiter">);</span> +<span id="L64" class="LineNr"> 64 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"imm8"</span><span class="Delimiter">);</span> +<span id="L65" class="LineNr"> 65 </span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"imm32"</span><span class="Delimiter">);</span> +<span id="L66" class="LineNr"> 66 </span> +<span id="L67" class="LineNr"> 67 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Texts")</span> +<span id="L68" class="LineNr"> 68 </span><a href='032operands.cc.html#L70'>init_argument_type_help</a><span class="Delimiter">();</span> +<span id="L69" class="LineNr"> 69 </span><span class="Delimiter">:(code)</span> +<span id="L70" class="LineNr"> 70 </span><span class="Normal">void</span> <a href='032operands.cc.html#L70'>init_argument_type_help</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L71" class="LineNr"> 71 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">,</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Constant">"2-bit argument controlling the _addressing mode_ of many instructions,</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">"to determine how to compute the _effective address_ to look up memory at</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Constant">"based on the 'rm32' argument and potentially others.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L76" class="LineNr"> 76 </span> <span class="Constant">"If mod = 3, just operate on the <a href='003trace.cc.html#L117'>contents</a> of the register specified by rm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Constant">" (direct mode).</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Constant">"If mod = 2, effective address is usually* rm32 + <a href='040tests.cc.html#L82'>disp32</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Constant">" (indirect mode with displacement).</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Constant">"If mod = 1, effective address is usually* rm32 + disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Constant">" (indirect mode with displacement).</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Constant">"If mod = 0, effective address is usually* rm32 (indirect mode).</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Constant">"(* - The exception is when rm32 is '4'. Register 4 is the stack pointer (<a href='010vm.cc.html#L14'>ESP</a>).</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Constant">" Using it as an address gets more involved. For more details,</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Constant">" try reading the help pages for 'base', 'index' and 'scale'.)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Constant">"For complete details, spend some time with two tables in the IA-32 software</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Constant">"developer's manual that are also included in this repo:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Constant">" - modrm.pdf: volume 2, table 2-2, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the ModR/M byte.</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Constant">" - sib.pdf: volume 2, table 2-3, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the SIB byte.</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Delimiter">);</span> +<span id="L92" class="LineNr"> 92 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"subop"</span><span class="Delimiter">,</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Constant">"Additional 3-bit argument for determining the instruction when the opcode</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Constant">"is 81, 8f, d3, f7 or ff.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Constant">"Can't coexist with argument of type 'r32' in a single instruction, because</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Constant">"the two use the same bits.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Delimiter">);</span> +<span id="L98" class="LineNr"> 98 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"r32"</span><span class="Delimiter">,</span> +<span id="L99" class="LineNr"> 99 </span> <span class="Constant">"3-bit argument specifying an integer register argument used directly,</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L100" class="LineNr">100 </span> <span class="Constant">"without any further addressing modes.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L101" class="LineNr">101 </span> <span class="Delimiter">);</span> +<span id="L102" class="LineNr">102 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"x32"</span><span class="Delimiter">,</span> +<span id="L103" class="LineNr">103 </span> <span class="Constant">"3-bit argument specifying a floating-point register argument used directly,</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L104" class="LineNr">104 </span> <span class="Constant">"without any further addressing modes.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L105" class="LineNr">105 </span> <span class="Delimiter">);</span> +<span id="L106" class="LineNr">106 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">,</span> +<span id="L107" class="LineNr">107 </span> <span class="Constant">"32-bit value in an integer register or memory. The precise details of its</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L108" class="LineNr">108 </span> <span class="Constant">"construction depend on the eponymous 3-bit 'rm32' argument, the 'mod' argument,</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L109" class="LineNr">109 </span> <span class="Constant">"and also potentially the 'SIB' arguments ('scale', 'index' and 'base')</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L110" class="LineNr">110 </span> <span class="Constant">"and a displacement ('disp8' or 'disp32').</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L111" class="LineNr">111 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L112" class="LineNr">112 </span> <span class="Constant">"For complete details, spend some time with two tables in the IA-32 software</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L113" class="LineNr">113 </span> <span class="Constant">"developer's manual that are also included in this repo:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L114" class="LineNr">114 </span> <span class="Constant">" - modrm.pdf: volume 2, table 2-2, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the ModR/M byte.</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L115" class="LineNr">115 </span> <span class="Constant">" - sib.pdf: volume 2, table 2-3, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the SIB byte.</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L116" class="LineNr">116 </span> <span class="Delimiter">);</span> +<span id="L117" class="LineNr">117 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"xm32"</span><span class="Delimiter">,</span> +<span id="L118" class="LineNr">118 </span> <span class="Constant">"32-bit value in a floating-point register or memory. The precise details of its</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L119" class="LineNr">119 </span> <span class="Constant">"construction depend on the eponymous 3-bit 'xm32' argument, the 'mod' argument,</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L120" class="LineNr">120 </span> <span class="Constant">"and also potentially the 'SIB' arguments ('scale', 'index' and 'base')</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L121" class="LineNr">121 </span> <span class="Constant">"and a displacement ('disp8' or 'disp32').</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L122" class="LineNr">122 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L123" class="LineNr">123 </span> <span class="Constant">"For complete details, spend some time with two tables in the IA-32 software</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L124" class="LineNr">124 </span> <span class="Constant">"developer's manual that are also included in this repo:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L125" class="LineNr">125 </span> <span class="Constant">" - modrm.pdf: volume 2, table 2-2, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the ModR/M byte.</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L126" class="LineNr">126 </span> <span class="Constant">" - sib.pdf: volume 2, table 2-3, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the SIB byte.</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L127" class="LineNr">127 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L128" class="LineNr">128 </span> <span class="Constant">"One subtlety here: while /xm32 refers to floating-point registers in direct mode</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L129" class="LineNr">129 </span> <span class="Constant">"(when /mod is 3), other addressing modes to construct memory addresses use integer registers</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L130" class="LineNr">130 </span> <span class="Constant">"(just like /rm32). Other than direct mode, its behavior is identical to /rm32.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L131" class="LineNr">131 </span> <span class="Delimiter">);</span> +<span id="L132" class="LineNr">132 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">,</span> +<span id="L133" class="LineNr">133 </span> <span class="Constant">"Additional 3-bit argument (when 'rm32' is 4, unless 'mod' is 3) specifying the</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L134" class="LineNr">134 </span> <span class="Constant">"register containing an address to look up.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L135" class="LineNr">135 </span> <span class="Constant">"This address may be further modified by 'index' and 'scale' arguments.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L136" class="LineNr">136 </span> <span class="Constant">" effective address = base + index*scale + displacement (disp8 or <a href='040tests.cc.html#L82'>disp32</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L137" class="LineNr">137 </span> <span class="Constant">"For complete details, spend some time with the IA-32 software developer's manual,</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L138" class="LineNr">138 </span> <span class="Constant">"volume 2, table 2-3, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the SIB byte</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L139" class="LineNr">139 </span> <span class="Constant">"It is included in this repository as 'sib.pdf'.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L140" class="LineNr">140 </span> <span class="Delimiter">);</span> +<span id="L141" class="LineNr">141 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">,</span> +<span id="L142" class="LineNr">142 </span> <span class="Constant">"Optional 3-bit argument (when 'rm32' is 4 unless 'mod' is 3) that can be added to</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L143" class="LineNr">143 </span> <span class="Constant">"the 'base' argument to compute the 'effective address' at which to look up memory.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L144" class="LineNr">144 </span> <span class="Constant">" effective address = base + index*scale + displacement (disp8 or <a href='040tests.cc.html#L82'>disp32</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L145" class="LineNr">145 </span> <span class="Constant">"For complete details, spend some time with the IA-32 software developer's manual,</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L146" class="LineNr">146 </span> <span class="Constant">"volume 2, table 2-3, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the SIB byte</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L147" class="LineNr">147 </span> <span class="Constant">"It is included in this repository as 'sib.pdf'.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L148" class="LineNr">148 </span> <span class="Delimiter">);</span> +<span id="L149" class="LineNr">149 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"scale"</span><span class="Delimiter">,</span> +<span id="L150" class="LineNr">150 </span> <span class="Constant">"Optional 2-bit argument (when 'rm32' is 4 unless 'mod' is 3) that encodes a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L151" class="LineNr">151 </span> <span class="Constant">"power of 2 to be multiplied to the 'index' argument before adding the result to</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L152" class="LineNr">152 </span> <span class="Constant">"the 'base' argument to compute the _effective address_ to operate on.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L153" class="LineNr">153 </span> <span class="Constant">" effective address = base + index * scale + displacement (disp8 or <a href='040tests.cc.html#L82'>disp32</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L154" class="LineNr">154 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L155" class="LineNr">155 </span> <span class="Constant">"When scale is 0, use index unmodified.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L156" class="LineNr">156 </span> <span class="Constant">"When scale is 1, multiply index by 2.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L157" class="LineNr">157 </span> <span class="Constant">"When scale is 2, multiply index by 4.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L158" class="LineNr">158 </span> <span class="Constant">"When scale is 3, multiply index by 8.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L159" class="LineNr">159 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L160" class="LineNr">160 </span> <span class="Constant">"For complete details, spend some time with the IA-32 software developer's manual,</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L161" class="LineNr">161 </span> <span class="Constant">"volume 2, table 2-3, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the SIB byte</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L162" class="LineNr">162 </span> <span class="Constant">"It is included in this repository as 'sib.pdf'.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L163" class="LineNr">163 </span> <span class="Delimiter">);</span> +<span id="L164" class="LineNr">164 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"disp8"</span><span class="Delimiter">,</span> +<span id="L165" class="LineNr">165 </span> <span class="Constant">"8-bit value to be added in many instructions.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L166" class="LineNr">166 </span> <span class="Delimiter">);</span> +<span id="L167" class="LineNr">167 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">,</span> +<span id="L168" class="LineNr">168 </span> <span class="Constant">"16-bit value to be added in many instructions.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L169" class="LineNr">169 </span> <span class="Constant">"Currently not used in any SubX instructions.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L170" class="LineNr">170 </span> <span class="Delimiter">);</span> +<span id="L171" class="LineNr">171 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">,</span> +<span id="L172" class="LineNr">172 </span> <span class="Constant">"32-bit value to be added in many instructions.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L173" class="LineNr">173 </span> <span class="Delimiter">);</span> +<span id="L174" class="LineNr">174 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"imm8"</span><span class="Delimiter">,</span> +<span id="L175" class="LineNr">175 </span> <span class="Constant">"8-bit value for many instructions.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L176" class="LineNr">176 </span> <span class="Delimiter">);</span> +<span id="L177" class="LineNr">177 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">,</span> +<span id="L178" class="LineNr">178 </span> <span class="Constant">"32-bit value for many instructions.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L179" class="LineNr">179 </span> <span class="Delimiter">);</span> +<span id="L180" class="LineNr">180 </span><span class="Delimiter">}</span> +<span id="L181" class="LineNr">181 </span> +<span id="L182" class="LineNr">182 </span><span class="Comment">//:: transform packing arguments into bytes in the right order</span> +<span id="L183" class="LineNr">183 </span> +<span id="L184" class="LineNr">184 </span><span class="Delimiter">:(after "Begin Transforms")</span> +<span id="L185" class="LineNr">185 </span><a href='031transforms.cc.html#L4'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pack_arguments<span class="Delimiter">);</span> +<span id="L186" class="LineNr">186 </span> +<span id="L187" class="LineNr">187 </span><span class="Delimiter">:(code)</span> +<span id="L188" class="LineNr">188 </span><span class="Normal">void</span> pack_arguments<span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L189" class="LineNr">189 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L190" class="LineNr">190 </span> segment& code = *find<span class="Delimiter">(</span>p<span class="Delimiter">,</span> <span class="Constant">"code"</span><span class="Delimiter">);</span> +<span id="L191" class="LineNr">191 </span> <span class="Comment">// Pack Operands(segment code)</span> +<span id="L192" class="LineNr">192 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"-- pack arguments"</span> << end<span class="Delimiter">();</span> +<span id="L193" class="LineNr">193 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L194" class="LineNr">194 </span> line& inst = code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L195" class="LineNr">195 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='032operands.cc.html#L531'>all_hex_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L196" class="LineNr">196 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"packing instruction '"</span> << to_string<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">with metadata</span><span class="Comment">*/</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> +<span id="L197" class="LineNr">197 </span> pack_arguments<span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L198" class="LineNr">198 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction after packing: '"</span> << to_string<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">without metadata</span><span class="Comment">*/</span>inst<span class="Delimiter">.</span>words<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> +<span id="L199" class="LineNr">199 </span> <span class="Delimiter">}</span> +<span id="L200" class="LineNr">200 </span><span class="Delimiter">}</span> +<span id="L201" class="LineNr">201 </span> +<span id="L202" class="LineNr">202 </span><span class="Normal">void</span> pack_arguments<span class="Delimiter">(</span>line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L203" class="LineNr">203 </span> <a href='011run.cc.html#L121'>line</a> new_inst<span class="Delimiter">;</span> +<span id="L204" class="LineNr">204 </span> <a href='032operands.cc.html#L212'>add_opcodes</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> new_inst<span class="Delimiter">);</span> +<span id="L205" class="LineNr">205 </span> <a href='032operands.cc.html#L222'>add_modrm_byte</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> new_inst<span class="Delimiter">);</span> +<span id="L206" class="LineNr">206 </span> <a href='032operands.cc.html#L256'>add_sib_byte</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> new_inst<span class="Delimiter">);</span> +<span id="L207" class="LineNr">207 </span> <a href='032operands.cc.html#L278'>add_disp_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> new_inst<span class="Delimiter">);</span> +<span id="L208" class="LineNr">208 </span> <a href='032operands.cc.html#L290'>add_imm_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> new_inst<span class="Delimiter">);</span> +<span id="L209" class="LineNr">209 </span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>swap<span class="Delimiter">(</span>new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> +<span id="L210" class="LineNr">210 </span><span class="Delimiter">}</span> +<span id="L211" class="LineNr">211 </span> +<span id="L212" class="LineNr">212 </span><span class="Normal">void</span> <a href='032operands.cc.html#L212'>add_opcodes</a><span class="Delimiter">(</span><span class="Normal">const</span> line& in<span class="Delimiter">,</span> line& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L213" class="LineNr">213 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> +<span id="L214" class="LineNr">214 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"0f"</span> || in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"f2"</span> || in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"f3"</span><span class="Delimiter">)</span> +<span id="L215" class="LineNr">215 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">));</span> +<span id="L216" class="LineNr">216 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"f3"</span> && in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>data == <span class="Constant">"0f"</span><span class="Delimiter">)</span> +<span id="L217" class="LineNr">217 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">));</span> +<span id="L218" class="LineNr">218 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"f2"</span> && in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>data == <span class="Constant">"0f"</span><span class="Delimiter">)</span> +<span id="L219" class="LineNr">219 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">));</span> +<span id="L220" class="LineNr">220 </span><span class="Delimiter">}</span> +<span id="L221" class="LineNr">221 </span> +<span id="L222" class="LineNr">222 </span><span class="Normal">void</span> <a href='032operands.cc.html#L222'>add_modrm_byte</a><span class="Delimiter">(</span><span class="Normal">const</span> line& in<span class="Delimiter">,</span> line& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L223" class="LineNr">223 </span> <span class="Normal">uint8_t</span> mod=<span class="Constant">0</span><span class="Delimiter">,</span> reg_subop=<span class="Constant">0</span><span class="Delimiter">,</span> rm32=<span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L224" class="LineNr">224 </span> <span class="Normal">bool</span> emit = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L225" class="LineNr">225 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L226" class="LineNr">226 </span> <span class="Normal">const</span> word& curr = in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L227" class="LineNr">227 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L228" class="LineNr">228 </span> mod = <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L229" class="LineNr">229 </span> emit = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L230" class="LineNr">230 </span> <span class="Delimiter">}</span> +<span id="L231" class="LineNr">231 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L232" class="LineNr">232 </span> rm32 = <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L233" class="LineNr">233 </span> emit = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L234" class="LineNr">234 </span> <span class="Delimiter">}</span> +<span id="L235" class="LineNr">235 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"r32"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L236" class="LineNr">236 </span> reg_subop = <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L237" class="LineNr">237 </span> emit = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L238" class="LineNr">238 </span> <span class="Delimiter">}</span> +<span id="L239" class="LineNr">239 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"xm32"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L240" class="LineNr">240 </span> rm32 = <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L241" class="LineNr">241 </span> emit = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L242" class="LineNr">242 </span> <span class="Delimiter">}</span> +<span id="L243" class="LineNr">243 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"x32"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L244" class="LineNr">244 </span> reg_subop = <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L245" class="LineNr">245 </span> emit = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L246" class="LineNr">246 </span> <span class="Delimiter">}</span> +<span id="L247" class="LineNr">247 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"subop"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L248" class="LineNr">248 </span> reg_subop = <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L249" class="LineNr">249 </span> emit = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L250" class="LineNr">250 </span> <span class="Delimiter">}</span> +<span id="L251" class="LineNr">251 </span> <span class="Delimiter">}</span> +<span id="L252" class="LineNr">252 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>emit<span class="Delimiter">)</span> +<span id="L253" class="LineNr">253 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='032operands.cc.html#L320'>hex_byte_text</a><span class="Delimiter">((</span>mod << <span class="Constant">6</span><span class="Delimiter">)</span> | <span class="Delimiter">(</span>reg_subop << <span class="Constant">3</span><span class="Delimiter">)</span> | rm32<span class="Delimiter">));</span> +<span id="L254" class="LineNr">254 </span><span class="Delimiter">}</span> +<span id="L255" class="LineNr">255 </span> +<span id="L256" class="LineNr">256 </span><span class="Normal">void</span> <a href='032operands.cc.html#L256'>add_sib_byte</a><span class="Delimiter">(</span><span class="Normal">const</span> line& in<span class="Delimiter">,</span> line& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L257" class="LineNr">257 </span> <span class="Normal">uint8_t</span> scale=<span class="Constant">0</span><span class="Delimiter">,</span> index=<span class="Constant">0</span><span class="Delimiter">,</span> base=<span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L258" class="LineNr">258 </span> <span class="Normal">bool</span> emit = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L259" class="LineNr">259 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L260" class="LineNr">260 </span> <span class="Normal">const</span> word& curr = in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L261" class="LineNr">261 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"scale"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L262" class="LineNr">262 </span> scale = <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L263" class="LineNr">263 </span> emit = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L264" class="LineNr">264 </span> <span class="Delimiter">}</span> +<span id="L265" class="LineNr">265 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L266" class="LineNr">266 </span> index = <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L267" class="LineNr">267 </span> emit = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L268" class="LineNr">268 </span> <span class="Delimiter">}</span> +<span id="L269" class="LineNr">269 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L270" class="LineNr">270 </span> base = <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L271" class="LineNr">271 </span> emit = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L272" class="LineNr">272 </span> <span class="Delimiter">}</span> +<span id="L273" class="LineNr">273 </span> <span class="Delimiter">}</span> +<span id="L274" class="LineNr">274 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>emit<span class="Delimiter">)</span> +<span id="L275" class="LineNr">275 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='032operands.cc.html#L320'>hex_byte_text</a><span class="Delimiter">((</span>scale << <span class="Constant">6</span><span class="Delimiter">)</span> | <span class="Delimiter">(</span>index << <span class="Constant">3</span><span class="Delimiter">)</span> | base<span class="Delimiter">));</span> +<span id="L276" class="LineNr">276 </span><span class="Delimiter">}</span> +<span id="L277" class="LineNr">277 </span> +<span id="L278" class="LineNr">278 </span><span class="Normal">void</span> <a href='032operands.cc.html#L278'>add_disp_bytes</a><span class="Delimiter">(</span><span class="Normal">const</span> line& in<span class="Delimiter">,</span> line& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L279" class="LineNr">279 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L280" class="LineNr">280 </span> <span class="Normal">const</span> word& curr = in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L281" class="LineNr">281 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp8"</span><span class="Delimiter">))</span> +<span id="L282" class="LineNr">282 </span> emit_hex_bytes<span class="Delimiter">(</span>out<span class="Delimiter">,</span> curr<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L283" class="LineNr">283 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">))</span> +<span id="L284" class="LineNr">284 </span> emit_hex_bytes<span class="Delimiter">(</span>out<span class="Delimiter">,</span> curr<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L285" class="LineNr">285 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">))</span> +<span id="L286" class="LineNr">286 </span> emit_hex_bytes<span class="Delimiter">(</span>out<span class="Delimiter">,</span> curr<span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L287" class="LineNr">287 </span> <span class="Delimiter">}</span> +<span id="L288" class="LineNr">288 </span><span class="Delimiter">}</span> +<span id="L289" class="LineNr">289 </span> +<span id="L290" class="LineNr">290 </span><span class="Normal">void</span> <a href='032operands.cc.html#L290'>add_imm_bytes</a><span class="Delimiter">(</span><span class="Normal">const</span> line& in<span class="Delimiter">,</span> line& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L291" class="LineNr">291 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L292" class="LineNr">292 </span> <span class="Normal">const</span> word& curr = in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L293" class="LineNr">293 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"imm8"</span><span class="Delimiter">))</span> +<span id="L294" class="LineNr">294 </span> emit_hex_bytes<span class="Delimiter">(</span>out<span class="Delimiter">,</span> curr<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L295" class="LineNr">295 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">))</span> +<span id="L296" class="LineNr">296 </span> emit_hex_bytes<span class="Delimiter">(</span>out<span class="Delimiter">,</span> curr<span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L297" class="LineNr">297 </span> <span class="Delimiter">}</span> +<span id="L298" class="LineNr">298 </span><span class="Delimiter">}</span> +<span id="L299" class="LineNr">299 </span> +<span id="L300" class="LineNr">300 </span><span class="Normal">void</span> emit_hex_bytes<span class="Delimiter">(</span>line& out<span class="Delimiter">,</span> <span class="Normal">const</span> word& w<span class="Delimiter">,</span> <span class="Normal">int</span> num<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L301" class="LineNr">301 </span> assert<span class="Delimiter">(</span>num <= <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L302" class="LineNr">302 </span> <span class="Normal">bool</span> is_number = <a href='032operands.cc.html#L591'>looks_like_hex_int</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L303" class="LineNr">303 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>num == <span class="Constant">1</span> || !is_number<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L304" class="LineNr">304 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>w<span class="Delimiter">);</span> <span class="Comment">// preserve existing metadata</span> +<span id="L305" class="LineNr">305 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_number<span class="Delimiter">)</span> +<span id="L306" class="LineNr">306 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>data = <a href='032operands.cc.html#L327'>hex_byte_to_string</a><span class="Delimiter">(</span><a href='032operands.cc.html#L608'>parse_int</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>data<span class="Delimiter">));</span> +<span id="L307" class="LineNr">307 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L308" class="LineNr">308 </span> <span class="Delimiter">}</span> +<span id="L309" class="LineNr">309 </span> emit_hex_bytes<span class="Delimiter">(</span>out<span class="Delimiter">,</span> <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span><a href='032operands.cc.html#L608'>parse_int</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>data<span class="Delimiter">)),</span> num<span class="Delimiter">);</span> +<span id="L310" class="LineNr">310 </span><span class="Delimiter">}</span> +<span id="L311" class="LineNr">311 </span> +<span id="L312" class="LineNr">312 </span><span class="Normal">void</span> emit_hex_bytes<span class="Delimiter">(</span>line& out<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> val<span class="Delimiter">,</span> <span class="Normal">int</span> num<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L313" class="LineNr">313 </span> assert<span class="Delimiter">(</span>num <= <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L314" class="LineNr">314 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < num<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L315" class="LineNr">315 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='032operands.cc.html#L320'>hex_byte_text</a><span class="Delimiter">(</span>val & <span class="Constant">0xff</span><span class="Delimiter">));</span> +<span id="L316" class="LineNr">316 </span> val = val >> <span class="Constant">8</span><span class="Delimiter">;</span> +<span id="L317" class="LineNr">317 </span> <span class="Delimiter">}</span> +<span id="L318" class="LineNr">318 </span><span class="Delimiter">}</span> +<span id="L319" class="LineNr">319 </span> +<span id="L320" class="LineNr">320 </span><a href='011run.cc.html#L127'>word</a> <a href='032operands.cc.html#L320'>hex_byte_text</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L321" class="LineNr">321 </span> <a href='011run.cc.html#L127'>word</a> result<span class="Delimiter">;</span> +<span id="L322" class="LineNr">322 </span> result<span class="Delimiter">.</span>data = <a href='032operands.cc.html#L327'>hex_byte_to_string</a><span class="Delimiter">(</span>val<span class="Delimiter">);</span> +<span id="L323" class="LineNr">323 </span> result<span class="Delimiter">.</span>original = result<span class="Delimiter">.</span>data+<span class="Constant">"/auto"</span><span class="Delimiter">;</span> +<span id="L324" class="LineNr">324 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L325" class="LineNr">325 </span><span class="Delimiter">}</span> +<span id="L326" class="LineNr">326 </span> +<span id="L327" class="LineNr">327 </span>string <a href='032operands.cc.html#L327'>hex_byte_to_string</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L328" class="LineNr">328 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L329" class="LineNr">329 </span> <span class="Comment">// uint8_t prints without padding, but int8_t will expand to 32 bits again</span> +<span id="L330" class="LineNr">330 </span> out << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>val<span class="Delimiter">);</span> +<span id="L331" class="LineNr">331 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L332" class="LineNr">332 </span><span class="Delimiter">}</span> +<span id="L333" class="LineNr">333 </span> +<span id="L334" class="LineNr">334 </span>string to_string<span class="Delimiter">(</span><span class="Normal">const</span> vector<word>& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L335" class="LineNr">335 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L336" class="LineNr">336 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L337" class="LineNr">337 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> +<span id="L338" class="LineNr">338 </span> out << in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>data<span class="Delimiter">;</span> +<span id="L339" class="LineNr">339 </span> <span class="Delimiter">}</span> +<span id="L340" class="LineNr">340 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L341" class="LineNr">341 </span><span class="Delimiter">}</span> +<span id="L342" class="LineNr">342 </span> +<span id="L343" class="LineNr">343 </span><span class="Delimiter">:(before "End Unit Tests")</span> +<span id="L344" class="LineNr">344 </span><span class="Normal">void</span> <a href='032operands.cc.html#L344'>test_preserve_metadata_when_emitting_single_byte</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L345" class="LineNr">345 </span> <a href='011run.cc.html#L127'>word</a> in<span class="Delimiter">;</span> +<span id="L346" class="LineNr">346 </span> in<span class="Delimiter">.</span>data = <span class="Constant">"f0"</span><span class="Delimiter">;</span> +<span id="L347" class="LineNr">347 </span> in<span class="Delimiter">.</span>original = <span class="Constant">"f0/foo"</span><span class="Delimiter">;</span> +<span id="L348" class="LineNr">348 </span> <a href='011run.cc.html#L121'>line</a> out<span class="Delimiter">;</span> +<span id="L349" class="LineNr">349 </span> emit_hex_bytes<span class="Delimiter">(</span>out<span class="Delimiter">,</span> in<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L350" class="LineNr">350 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>out<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data<span class="Delimiter">,</span> <span class="Constant">"f0"</span><span class="Delimiter">);</span> +<span id="L351" class="LineNr">351 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>out<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original<span class="Delimiter">,</span> <span class="Constant">"f0/foo"</span><span class="Delimiter">);</span> +<span id="L352" class="LineNr">352 </span><span class="Delimiter">}</span> +<span id="L353" class="LineNr">353 </span> +<span id="L354" class="LineNr">354 </span><span class="Delimiter">:(code)</span> +<span id="L355" class="LineNr">355 </span><span class="Normal">void</span> <a href='032operands.cc.html#L355'>test_pack_disp8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L356" class="LineNr">356 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L357" class="LineNr">357 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L358" class="LineNr">358 </span> <span class="Constant">"74 2/disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// jump 2 bytes away if ZF is set</span> +<span id="L359" class="LineNr">359 </span> <span class="Delimiter">);</span> +<span id="L360" class="LineNr">360 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L361" class="LineNr">361 </span> <span class="Constant">"transform: packing instruction '74 2/disp8'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L362" class="LineNr">362 </span> <span class="Constant">"transform: instruction after packing: '74 02'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L363" class="LineNr">363 </span> <span class="Delimiter">);</span> +<span id="L364" class="LineNr">364 </span><span class="Delimiter">}</span> +<span id="L365" class="LineNr">365 </span> +<span id="L366" class="LineNr">366 </span><span class="Normal">void</span> <a href='032operands.cc.html#L366'>test_pack_disp8_negative</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L367" class="LineNr">367 </span> transform<span class="Delimiter">(</span> +<span id="L368" class="LineNr">368 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L369" class="LineNr">369 </span> <span class="Comment">// running this will cause an infinite loop</span> +<span id="L370" class="LineNr">370 </span> <span class="Constant">"74 -1/disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// jump 1 byte before if ZF is set</span> +<span id="L371" class="LineNr">371 </span> <span class="Delimiter">);</span> +<span id="L372" class="LineNr">372 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L373" class="LineNr">373 </span> <span class="Constant">"transform: packing instruction '74 -1/disp8'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L374" class="LineNr">374 </span> <span class="Constant">"transform: instruction after packing: '74 ff'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L375" class="LineNr">375 </span> <span class="Delimiter">);</span> +<span id="L376" class="LineNr">376 </span><span class="Delimiter">}</span> +<span id="L377" class="LineNr">377 </span> +<span id="L378" class="LineNr">378 </span><span class="Normal">void</span> <a href='032operands.cc.html#L378'>test_pack_rm32_direct</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L379" class="LineNr">379 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L380" class="LineNr">380 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L381" class="LineNr">381 </span> <span class="Comment">// instruction effective address operand displacement immediate\n"</span> +<span id="L382" class="LineNr">382 </span> <span class="Comment">// op subop mod rm32 base index scale r32\n"</span> +<span id="L383" class="LineNr">383 </span> <span class="Comment">// 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes\n"</span> +<span id="L384" class="LineNr">384 </span> <span class="Constant">" 01 3/mod/direct 3/rm32/ebx 0/r32/eax </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EAX to EBX</span> +<span id="L385" class="LineNr">385 </span> <span class="Delimiter">);</span> +<span id="L386" class="LineNr">386 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L387" class="LineNr">387 </span> <span class="Constant">"transform: packing instruction '01 3/mod/direct 3/rm32/ebx 0/r32/eax'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L388" class="LineNr">388 </span> <span class="Constant">"transform: instruction after packing: '01 c3'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L389" class="LineNr">389 </span> <span class="Delimiter">);</span> +<span id="L390" class="LineNr">390 </span><span class="Delimiter">}</span> +<span id="L391" class="LineNr">391 </span> +<span id="L392" class="LineNr">392 </span><span class="Normal">void</span> <a href='032operands.cc.html#L392'>test_pack_rm32_indirect</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L393" class="LineNr">393 </span> transform<span class="Delimiter">(</span> +<span id="L394" class="LineNr">394 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L395" class="LineNr">395 </span> <span class="Comment">// instruction effective address operand displacement immediate\n"</span> +<span id="L396" class="LineNr">396 </span> <span class="Comment">// op subop mod rm32 base index scale r32\n"</span> +<span id="L397" class="LineNr">397 </span> <span class="Comment">// 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes\n"</span> +<span id="L398" class="LineNr">398 </span> <span class="Constant">" 01 0/mod/indirect 3/rm32/ebx 0/r32/eax </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add EAX to *EBX</span> +<span id="L399" class="LineNr">399 </span> <span class="Delimiter">);</span> +<span id="L400" class="LineNr">400 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L401" class="LineNr">401 </span> <span class="Constant">"transform: packing instruction '01 0/mod/indirect 3/rm32/ebx 0/r32/eax'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L402" class="LineNr">402 </span> <span class="Constant">"transform: instruction after packing: '01 03'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L403" class="LineNr">403 </span> <span class="Delimiter">);</span> +<span id="L404" class="LineNr">404 </span><span class="Delimiter">}</span> +<span id="L405" class="LineNr">405 </span> +<span id="L406" class="LineNr">406 </span><span class="Normal">void</span> <a href='032operands.cc.html#L406'>test_pack_x32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L407" class="LineNr">407 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L408" class="LineNr">408 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L409" class="LineNr">409 </span> <span class="Comment">// instruction effective address operand displacement immediate\n"</span> +<span id="L410" class="LineNr">410 </span> <span class="Comment">// op subop mod rm32 base index scale r32\n"</span> +<span id="L411" class="LineNr">411 </span> <span class="Comment">// 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes\n"</span> +<span id="L412" class="LineNr">412 </span> <span class="Constant">" f3 0f 2a 3/mod/direct 3/rm32/ebx 1/x32 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// convert EBX to XMM1</span> +<span id="L413" class="LineNr">413 </span> <span class="Delimiter">);</span> +<span id="L414" class="LineNr">414 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L415" class="LineNr">415 </span> <span class="Constant">"transform: packing instruction 'f3 0f 2a 3/mod/direct 3/rm32/ebx 1/x32'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L416" class="LineNr">416 </span> <span class="Constant">"transform: instruction after packing: 'f3 0f 2a cb'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L417" class="LineNr">417 </span> <span class="Delimiter">);</span> +<span id="L418" class="LineNr">418 </span><span class="Delimiter">}</span> +<span id="L419" class="LineNr">419 </span> +<span id="L420" class="LineNr">420 </span><span class="Normal">void</span> <a href='032operands.cc.html#L420'>test_pack_xm32_direct</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L421" class="LineNr">421 </span> transform<span class="Delimiter">(</span> +<span id="L422" class="LineNr">422 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L423" class="LineNr">423 </span> <span class="Comment">// instruction effective address operand displacement immediate\n"</span> +<span id="L424" class="LineNr">424 </span> <span class="Comment">// op subop mod rm32 base index scale r32\n"</span> +<span id="L425" class="LineNr">425 </span> <span class="Comment">// 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes\n"</span> +<span id="L426" class="LineNr">426 </span> <span class="Constant">" f3 0f 5e 3/mod/direct 3/xm32 1/x32 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// divide XMM1 by XMM3</span> +<span id="L427" class="LineNr">427 </span> <span class="Delimiter">);</span> +<span id="L428" class="LineNr">428 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L429" class="LineNr">429 </span> <span class="Constant">"transform: packing instruction 'f3 0f 5e 3/mod/direct 3/xm32 1/x32'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L430" class="LineNr">430 </span> <span class="Constant">"transform: instruction after packing: 'f3 0f 5e cb'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L431" class="LineNr">431 </span> <span class="Delimiter">);</span> +<span id="L432" class="LineNr">432 </span><span class="Delimiter">}</span> +<span id="L433" class="LineNr">433 </span> +<span id="L434" class="LineNr">434 </span><span class="Normal">void</span> <a href='032operands.cc.html#L434'>test_pack_xm32_indirect</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L435" class="LineNr">435 </span> transform<span class="Delimiter">(</span> +<span id="L436" class="LineNr">436 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L437" class="LineNr">437 </span> <span class="Comment">// instruction effective address operand displacement immediate\n"</span> +<span id="L438" class="LineNr">438 </span> <span class="Comment">// op subop mod rm32 base index scale r32\n"</span> +<span id="L439" class="LineNr">439 </span> <span class="Comment">// 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes\n"</span> +<span id="L440" class="LineNr">440 </span> <span class="Constant">" f3 0f 5e 0/mod/indirect 3/rm32/ebx 1/x32 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// divide XMM1 by *EBX</span> +<span id="L441" class="LineNr">441 </span> <span class="Delimiter">);</span> +<span id="L442" class="LineNr">442 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L443" class="LineNr">443 </span> <span class="Constant">"transform: packing instruction 'f3 0f 5e 0/mod/indirect 3/rm32/ebx 1/x32'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L444" class="LineNr">444 </span> <span class="Constant">"transform: instruction after packing: 'f3 0f 5e 0b'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L445" class="LineNr">445 </span> <span class="Delimiter">);</span> +<span id="L446" class="LineNr">446 </span><span class="Delimiter">}</span> +<span id="L447" class="LineNr">447 </span> +<span id="L448" class="LineNr">448 </span><span class="Comment">//: helper for scenario</span> +<span id="L449" class="LineNr">449 </span><span class="Normal">void</span> transform<span class="Delimiter">(</span><span class="Normal">const</span> string& text_bytes<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L450" class="LineNr">450 </span> program p<span class="Delimiter">;</span> +<span id="L451" class="LineNr">451 </span> istringstream in<span class="Delimiter">(</span>text_bytes<span class="Delimiter">);</span> +<span id="L452" class="LineNr">452 </span> parse<span class="Delimiter">(</span>in<span class="Delimiter">,</span> p<span class="Delimiter">);</span> +<span id="L453" class="LineNr">453 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L454" class="LineNr">454 </span> transform<span class="Delimiter">(</span>p<span class="Delimiter">);</span> +<span id="L455" class="LineNr">455 </span><span class="Delimiter">}</span> +<span id="L456" class="LineNr">456 </span> +<span id="L457" class="LineNr">457 </span><span class="Normal">void</span> <a href='032operands.cc.html#L457'>test_pack_modrm_imm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L458" class="LineNr">458 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L459" class="LineNr">459 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L460" class="LineNr">460 </span> <span class="Comment">// instruction effective address operand displacement immediate\n"</span> +<span id="L461" class="LineNr">461 </span> <span class="Comment">// op subop mod rm32 base index scale r32\n"</span> +<span id="L462" class="LineNr">462 </span> <span class="Comment">// 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes\n"</span> +<span id="L463" class="LineNr">463 </span> <span class="Constant">" 81 0/add/subop 3/mod/direct 3/rm32/ebx 1/imm32 </span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add 1 to EBX</span> +<span id="L464" class="LineNr">464 </span> <span class="Delimiter">);</span> +<span id="L465" class="LineNr">465 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L466" class="LineNr">466 </span> <span class="Constant">"transform: packing instruction '81 0/add/subop 3/mod/direct 3/rm32/ebx 1/imm32'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L467" class="LineNr">467 </span> <span class="Constant">"transform: instruction after packing: '81 c3 01 00 00 00'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L468" class="LineNr">468 </span> <span class="Delimiter">);</span> +<span id="L469" class="LineNr">469 </span><span class="Delimiter">}</span> +<span id="L470" class="LineNr">470 </span> +<span id="L471" class="LineNr">471 </span><span class="Normal">void</span> <a href='032operands.cc.html#L471'>test_pack_imm32_large</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L472" class="LineNr">472 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L473" class="LineNr">473 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L474" class="LineNr">474 </span> <span class="Constant">"b9 0x080490a7/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L475" class="LineNr">475 </span> <span class="Delimiter">);</span> +<span id="L476" class="LineNr">476 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L477" class="LineNr">477 </span> <span class="Constant">"transform: packing instruction 'b9 0x080490a7/imm32'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L478" class="LineNr">478 </span> <span class="Constant">"transform: instruction after packing: 'b9 a7 90 04 08'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L479" class="LineNr">479 </span> <span class="Delimiter">);</span> +<span id="L480" class="LineNr">480 </span><span class="Delimiter">}</span> +<span id="L481" class="LineNr">481 </span> +<span id="L482" class="LineNr">482 </span><span class="Normal">void</span> <a href='032operands.cc.html#L482'>test_pack_immediate_constants_hex</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L483" class="LineNr">483 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L484" class="LineNr">484 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L485" class="LineNr">485 </span> <span class="Constant">"b9 0x2a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L486" class="LineNr">486 </span> <span class="Delimiter">);</span> +<span id="L487" class="LineNr">487 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L488" class="LineNr">488 </span> <span class="Constant">"transform: packing instruction 'b9 0x2a/imm32'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L489" class="LineNr">489 </span> <span class="Constant">"transform: instruction after packing: 'b9 2a 00 00 00'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L490" class="LineNr">490 </span> <span class="Constant">"run: copy imm32 0x0000002a to <a href='010vm.cc.html#L11'>ECX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L491" class="LineNr">491 </span> <span class="Delimiter">);</span> +<span id="L492" class="LineNr">492 </span><span class="Delimiter">}</span> +<span id="L493" class="LineNr">493 </span> +<span id="L494" class="LineNr">494 </span><span class="Normal">void</span> <a href='032operands.cc.html#L494'>test_pack_silently_ignores_non_hex</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L495" class="LineNr">495 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L496" class="LineNr">496 </span> transform<span class="Delimiter">(</span> +<span id="L497" class="LineNr">497 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L498" class="LineNr">498 </span> <span class="Constant">"b9 foo/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L499" class="LineNr">499 </span> <span class="Delimiter">);</span> +<span id="L500" class="LineNr">500 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L501" class="LineNr">501 </span> <span class="Constant">"transform: packing instruction 'b9 foo/imm32'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L502" class="LineNr">502 </span> <span class="Comment">// no change (we're just not printing metadata to the trace)</span> +<span id="L503" class="LineNr">503 </span> <span class="Constant">"transform: instruction after packing: 'b9 foo'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L504" class="LineNr">504 </span> <span class="Delimiter">);</span> +<span id="L505" class="LineNr">505 </span><span class="Delimiter">}</span> +<span id="L506" class="LineNr">506 </span> +<span id="L507" class="LineNr">507 </span><span class="Normal">void</span> <a href='032operands.cc.html#L507'>test_pack_flags_bad_hex</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L508" class="LineNr">508 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L509" class="LineNr">509 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L510" class="LineNr">510 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L511" class="LineNr">511 </span> <span class="Constant">"b9 0xfoo/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L512" class="LineNr">512 </span> <span class="Delimiter">);</span> +<span id="L513" class="LineNr">513 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L514" class="LineNr">514 </span> <span class="Constant">"error: not a number: 0xfoo</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L515" class="LineNr">515 </span> <span class="Delimiter">);</span> +<span id="L516" class="LineNr">516 </span><span class="Delimiter">}</span> +<span id="L517" class="LineNr">517 </span> +<span id="L518" class="LineNr">518 </span><span class="Normal">void</span> <a href='032operands.cc.html#L518'>test_pack_flags_uppercase_hex</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L519" class="LineNr">519 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L520" class="LineNr">520 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L521" class="LineNr">521 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L522" class="LineNr">522 </span> <span class="Constant">"b9 0xAb/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L523" class="LineNr">523 </span> <span class="Delimiter">);</span> +<span id="L524" class="LineNr">524 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L525" class="LineNr">525 </span> <span class="Constant">"error: uppercase hex not allowed: 0xAb</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L526" class="LineNr">526 </span> <span class="Delimiter">);</span> +<span id="L527" class="LineNr">527 </span><span class="Delimiter">}</span> +<span id="L528" class="LineNr">528 </span> +<span id="L529" class="LineNr">529 </span><span class="Comment">//:: helpers</span> +<span id="L530" class="LineNr">530 </span> +<span id="L531" class="LineNr">531 </span><span class="Normal">bool</span> <a href='032operands.cc.html#L531'>all_hex_bytes</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L532" class="LineNr">532 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L533" class="LineNr">533 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_hex_byte<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> +<span id="L534" class="LineNr">534 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L535" class="LineNr">535 </span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L536" class="LineNr">536 </span><span class="Delimiter">}</span> +<span id="L537" class="LineNr">537 </span> +<span id="L538" class="LineNr">538 </span><span class="Normal">bool</span> <a href='032operands.cc.html#L538'>is_hex_byte</a><span class="Delimiter">(</span><span class="Normal">const</span> word& curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L539" class="LineNr">539 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='032operands.cc.html#L548'>contains_any_argument_metadata</a><span class="Delimiter">(</span>curr<span class="Delimiter">))</span> +<span id="L540" class="LineNr">540 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L541" class="LineNr">541 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">)</span> != <span class="Constant">2</span><span class="Delimiter">)</span> +<span id="L542" class="LineNr">542 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L543" class="LineNr">543 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789abcdef"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> +<span id="L544" class="LineNr">544 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L545" class="LineNr">545 </span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L546" class="LineNr">546 </span><span class="Delimiter">}</span> +<span id="L547" class="LineNr">547 </span> +<span id="L548" class="LineNr">548 </span><span class="Normal">bool</span> <a href='032operands.cc.html#L548'>contains_any_argument_metadata</a><span class="Delimiter">(</span><span class="Normal">const</span> word& <a href='011run.cc.html#L127'>word</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L549" class="LineNr">549 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span><a href='011run.cc.html#L127'>word</a><span class="Delimiter">.</span>metadata<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L550" class="LineNr">550 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>find<span class="Delimiter">(</span><a href='011run.cc.html#L127'>word</a><span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> != <a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>end<span class="Delimiter">())</span> +<span id="L551" class="LineNr">551 </span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L552" class="LineNr">552 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L553" class="LineNr">553 </span><span class="Delimiter">}</span> +<span id="L554" class="LineNr">554 </span> +<span id="L555" class="LineNr">555 </span><span class="Normal">bool</span> has_argument_metadata<span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> string& m<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L556" class="LineNr">556 </span> <span class="Normal">bool</span> result = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L557" class="LineNr">557 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L558" class="LineNr">558 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_argument_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> m<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L559" class="LineNr">559 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L560" class="LineNr">560 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"' has conflicting "</span> << m << <span class="Constant">" arguments</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L561" class="LineNr">561 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L562" class="LineNr">562 </span> <span class="Delimiter">}</span> +<span id="L563" class="LineNr">563 </span> result = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L564" class="LineNr">564 </span> <span class="Delimiter">}</span> +<span id="L565" class="LineNr">565 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L566" class="LineNr">566 </span><span class="Delimiter">}</span> +<span id="L567" class="LineNr">567 </span> +<span id="L568" class="LineNr">568 </span><span class="Normal">bool</span> has_argument_metadata<span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">,</span> <span class="Normal">const</span> string& m<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L569" class="LineNr">569 </span> <span class="Normal">bool</span> result = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L570" class="LineNr">570 </span> <span class="Normal">bool</span> metadata_found = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L571" class="LineNr">571 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>metadata<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L572" class="LineNr">572 </span> <span class="Normal">const</span> string& curr = w<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L573" class="LineNr">573 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>find<span class="Delimiter">(</span>curr<span class="Delimiter">)</span> == <a href='032operands.cc.html#L50'>Instruction_arguments</a><span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// ignore unrecognized metadata</span> +<span id="L574" class="LineNr">574 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>metadata_found<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L575" class="LineNr">575 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << w<span class="Delimiter">.</span>original << <span class="Constant">"' has conflicting argument types; it should have only one</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L576" class="LineNr">576 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L577" class="LineNr">577 </span> <span class="Delimiter">}</span> +<span id="L578" class="LineNr">578 </span> metadata_found = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L579" class="LineNr">579 </span> result = <span class="Delimiter">(</span>curr == m<span class="Delimiter">);</span> +<span id="L580" class="LineNr">580 </span> <span class="Delimiter">}</span> +<span id="L581" class="LineNr">581 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L582" class="LineNr">582 </span><span class="Delimiter">}</span> +<span id="L583" class="LineNr">583 </span> +<span id="L584" class="LineNr">584 </span><a href='011run.cc.html#L127'>word</a> metadata<span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> string& m<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L585" class="LineNr">585 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L586" class="LineNr">586 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> m<span class="Delimiter">))</span> +<span id="L587" class="LineNr">587 </span> <span class="Identifier">return</span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L588" class="LineNr">588 </span> assert<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span> +<span id="L589" class="LineNr">589 </span><span class="Delimiter">}</span> +<span id="L590" class="LineNr">590 </span> +<span id="L591" class="LineNr">591 </span><span class="Normal">bool</span> <a href='032operands.cc.html#L591'>looks_like_hex_int</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L592" class="LineNr">592 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>s<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L593" class="LineNr">593 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">'-'</span> || s<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">'+'</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L594" class="LineNr">594 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>isdigit<span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// includes '0x' prefix</span> +<span id="L595" class="LineNr">595 </span> <span class="Comment">// End looks_like_hex_int(s) Detectors</span> +<span id="L596" class="LineNr">596 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L597" class="LineNr">597 </span><span class="Delimiter">}</span> +<span id="L598" class="LineNr">598 </span> +<span id="L599" class="LineNr">599 </span>string to_string<span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L600" class="LineNr">600 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L601" class="LineNr">601 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L602" class="LineNr">602 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> +<span id="L603" class="LineNr">603 </span> out << inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original<span class="Delimiter">;</span> +<span id="L604" class="LineNr">604 </span> <span class="Delimiter">}</span> +<span id="L605" class="LineNr">605 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L606" class="LineNr">606 </span><span class="Delimiter">}</span> +<span id="L607" class="LineNr">607 </span> +<span id="L608" class="LineNr">608 </span><span class="Normal">int32_t</span> <a href='032operands.cc.html#L608'>parse_int</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L609" class="LineNr">609 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>s<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L610" class="LineNr">610 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='011run.cc.html#L449'>contains_uppercase</a><span class="Delimiter">(</span>s<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L611" class="LineNr">611 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"uppercase hex not allowed: "</span> << s << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L612" class="LineNr">612 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L613" class="LineNr">613 </span> <span class="Delimiter">}</span> +<span id="L614" class="LineNr">614 </span> istringstream in<span class="Delimiter">(</span>s<span class="Delimiter">);</span> +<span id="L615" class="LineNr">615 </span> in >> std::hex<span class="Delimiter">;</span> +<span id="L616" class="LineNr">616 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">'-'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L617" class="LineNr">617 </span> <span class="Normal">int32_t</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L618" class="LineNr">618 </span> in >> result<span class="Delimiter">;</span> +<span id="L619" class="LineNr">619 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!in || !in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L620" class="LineNr">620 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"not a number: "</span> << s << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L621" class="LineNr">621 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L622" class="LineNr">622 </span> <span class="Delimiter">}</span> +<span id="L623" class="LineNr">623 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L624" class="LineNr">624 </span> <span class="Delimiter">}</span> +<span id="L625" class="LineNr">625 </span> <span class="Normal">uint32_t</span> uresult = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L626" class="LineNr">626 </span> in >> uresult<span class="Delimiter">;</span> +<span id="L627" class="LineNr">627 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!in || !in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L628" class="LineNr">628 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"not a number: "</span> << s << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L629" class="LineNr">629 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L630" class="LineNr">630 </span> <span class="Delimiter">}</span> +<span id="L631" class="LineNr">631 </span> <span class="Identifier">return</span> <span class="Normal">static_cast</span><<span class="Normal">int32_t</span>><span class="Delimiter">(</span>uresult<span class="Delimiter">);</span> +<span id="L632" class="LineNr">632 </span><span class="Delimiter">}</span> +<span id="L633" class="LineNr">633 </span><span class="Delimiter">:(before "End Unit Tests")</span> +<span id="L634" class="LineNr">634 </span><span class="Normal">void</span> <a href='032operands.cc.html#L634'>test_parse_int</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L635" class="LineNr">635 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> <a href='032operands.cc.html#L608'>parse_int</a><span class="Delimiter">(</span><span class="Constant">"0"</span><span class="Delimiter">));</span> +<span id="L636" class="LineNr">636 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> <a href='032operands.cc.html#L608'>parse_int</a><span class="Delimiter">(</span><span class="Constant">"0x0"</span><span class="Delimiter">));</span> +<span id="L637" class="LineNr">637 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> <a href='032operands.cc.html#L608'>parse_int</a><span class="Delimiter">(</span><span class="Constant">"0x0"</span><span class="Delimiter">));</span> +<span id="L638" class="LineNr">638 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><span class="Constant">16</span><span class="Delimiter">,</span> <a href='032operands.cc.html#L608'>parse_int</a><span class="Delimiter">(</span><span class="Constant">"10"</span><span class="Delimiter">));</span> <span class="Comment">// hex always</span> +<span id="L639" class="LineNr">639 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>-<span class="Constant">1</span><span class="Delimiter">,</span> <a href='032operands.cc.html#L608'>parse_int</a><span class="Delimiter">(</span><span class="Constant">"-1"</span><span class="Delimiter">));</span> +<span id="L640" class="LineNr">640 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>-<span class="Constant">1</span><span class="Delimiter">,</span> <a href='032operands.cc.html#L608'>parse_int</a><span class="Delimiter">(</span><span class="Constant">"0xffffffff"</span><span class="Delimiter">));</span> +<span id="L641" class="LineNr">641 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/033check_operands.cc.html b/html/linux/bootstrap/033check_operands.cc.html new file mode 100644 index 00000000..addf3048 --- /dev/null +++ b/html/linux/bootstrap/033check_operands.cc.html @@ -0,0 +1,851 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/033check_operands.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.SalientComment { color: #0000af; } +.Delimiter { color: #c000c0; } +.Comment { color: #005faf; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.CommentedCode { color: #8a8a8a; } +.Identifier { color: #af5f00; } +.PreProc { color: #c000c0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/033check_operands.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/033check_operands.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: Since we're tagging arguments with their types, let's start checking these</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: argument types for each instruction.</span> +<span id="L3" class="LineNr"> 3 </span> +<span id="L4" class="LineNr"> 4 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L4'>test_check_missing_imm8_argument</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L5" class="LineNr"> 5 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L6" class="LineNr"> 6 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L7" class="LineNr"> 7 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Constant">"cd</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// interrupt ??</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Delimiter">);</span> +<span id="L10" class="LineNr"> 10 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Constant">"error: 'cd' (software interrupt): missing imm8 argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Delimiter">);</span> +<span id="L13" class="LineNr"> 13 </span><span class="Delimiter">}</span> +<span id="L14" class="LineNr"> 14 </span> +<span id="L15" class="LineNr"> 15 </span><span class="Delimiter">:(before "Pack Operands(segment code)")</span> +<span id="L16" class="LineNr"> 16 </span>check_arguments<span class="Delimiter">(</span>code<span class="Delimiter">);</span> +<span id="L17" class="LineNr"> 17 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L18" class="LineNr"> 18 </span> +<span id="L19" class="LineNr"> 19 </span><span class="Delimiter">:(code)</span> +<span id="L20" class="LineNr"> 20 </span><span class="Normal">void</span> check_arguments<span class="Delimiter">(</span><span class="Normal">const</span> segment& code<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L21" class="LineNr"> 21 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"-- check arguments"</span> << end<span class="Delimiter">();</span> +<span id="L22" class="LineNr"> 22 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L23" class="LineNr"> 23 </span> check_arguments<span class="Delimiter">(</span>code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// stop at the first mal-formed instruction</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Delimiter">}</span> +<span id="L26" class="LineNr"> 26 </span><span class="Delimiter">}</span> +<span id="L27" class="LineNr"> 27 </span> +<span id="L28" class="LineNr"> 28 </span><span class="Normal">void</span> check_arguments<span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L29" class="LineNr"> 29 </span> <a href='011run.cc.html#L127'>word</a> op = <a href='033check_operands.cc.html#L41'>preprocess_op</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>op<span class="Delimiter">.</span>data == <span class="Constant">"0f"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L31" class="LineNr"> 31 </span> check_arguments_0f<span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Delimiter">}</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>op<span class="Delimiter">.</span>data == <span class="Constant">"f3"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L35" class="LineNr"> 35 </span> check_arguments_f3<span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Delimiter">}</span> +<span id="L38" class="LineNr"> 38 </span> check_arguments<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L39" class="LineNr"> 39 </span><span class="Delimiter">}</span> +<span id="L40" class="LineNr"> 40 </span> +<span id="L41" class="LineNr"> 41 </span><a href='011run.cc.html#L127'>word</a> <a href='033check_operands.cc.html#L41'>preprocess_op</a><span class="Delimiter">(</span><a href='011run.cc.html#L127'>word</a><span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L42" class="LineNr"> 42 </span> op<span class="Delimiter">.</span>data = <a href='033check_operands.cc.html#L774'>tolower</a><span class="Delimiter">(</span>op<span class="Delimiter">.</span>data<span class="Delimiter">.</span>c_str<span class="Delimiter">());</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Comment">// opcodes can't be negative</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L104'>starts_with</a><span class="Delimiter">(</span>op<span class="Delimiter">.</span>data<span class="Delimiter">,</span> <span class="Constant">"0x"</span><span class="Delimiter">))</span> +<span id="L45" class="LineNr"> 45 </span> op<span class="Delimiter">.</span>data = op<span class="Delimiter">.</span>data<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>op<span class="Delimiter">.</span>data<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</span> +<span id="L47" class="LineNr"> 47 </span> op<span class="Delimiter">.</span>data = string<span class="Delimiter">(</span><span class="Constant">"0"</span><span class="Delimiter">)</span>+op<span class="Delimiter">.</span>data<span class="Delimiter">;</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Identifier">return</span> op<span class="Delimiter">;</span> +<span id="L49" class="LineNr"> 49 </span><span class="Delimiter">}</span> +<span id="L50" class="LineNr"> 50 </span> +<span id="L51" class="LineNr"> 51 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L51'>test_preprocess_op</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L52" class="LineNr"> 52 </span> <a href='011run.cc.html#L127'>word</a> w1<span class="Delimiter">;</span> w1<span class="Delimiter">.</span>data = <span class="Constant">"0xf"</span><span class="Delimiter">;</span> +<span id="L53" class="LineNr"> 53 </span> <a href='011run.cc.html#L127'>word</a> w2<span class="Delimiter">;</span> w2<span class="Delimiter">.</span>data = <span class="Constant">"0f"</span><span class="Delimiter">;</span> +<span id="L54" class="LineNr"> 54 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L41'>preprocess_op</a><span class="Delimiter">(</span>w1<span class="Delimiter">).</span>data<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L41'>preprocess_op</a><span class="Delimiter">(</span>w2<span class="Delimiter">).</span>data<span class="Delimiter">);</span> +<span id="L55" class="LineNr"> 55 </span><span class="Delimiter">}</span> +<span id="L56" class="LineNr"> 56 </span> +<span id="L57" class="LineNr"> 57 </span><span class="Comment">//: To check the arguments for an opcode, we'll track the permitted arguments</span> +<span id="L58" class="LineNr"> 58 </span><span class="Comment">//: for each supported opcode in a bitvector. That way we can often compute the</span> +<span id="L59" class="LineNr"> 59 </span><span class="Comment">//: 'received' argument bitvector for each instruction's arguments and compare</span> +<span id="L60" class="LineNr"> 60 </span><span class="Comment">//: it with the 'expected' bitvector.</span> +<span id="L61" class="LineNr"> 61 </span><span class="Comment">//:</span> +<span id="L62" class="LineNr"> 62 </span><span class="Comment">//: The 'expected' and 'received' bitvectors can be different; the MODRM bit</span> +<span id="L63" class="LineNr"> 63 </span><span class="Comment">//: in the 'expected' bitvector maps to multiple 'received' argument types in</span> +<span id="L64" class="LineNr"> 64 </span><span class="Comment">//: an instruction. We deal in expected bitvectors throughout.</span> +<span id="L65" class="LineNr"> 65 </span> +<span id="L66" class="LineNr"> 66 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L67" class="LineNr"> 67 </span><span class="Normal">enum</span> <a href='033check_operands.cc.html#L67'>expected_argument_type</a> <span class="Delimiter">{</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Comment">// start from the least significant bit</span> +<span id="L69" class="LineNr"> 69 </span> <a href='033check_operands.cc.html#L69'>MODRM</a><span class="Delimiter">,</span> <span class="Comment">// more complex, may also involve disp8 or disp32</span> +<span id="L70" class="LineNr"> 70 </span> <a href='033check_operands.cc.html#L70'>SUBOP</a><span class="Delimiter">,</span> +<span id="L71" class="LineNr"> 71 </span> <a href='033check_operands.cc.html#L71'>DISP8</a><span class="Delimiter">,</span> +<span id="L72" class="LineNr"> 72 </span> <a href='033check_operands.cc.html#L72'>DISP16</a><span class="Delimiter">,</span> +<span id="L73" class="LineNr"> 73 </span> <a href='033check_operands.cc.html#L73'>DISP32</a><span class="Delimiter">,</span> +<span id="L74" class="LineNr"> 74 </span> <a href='033check_operands.cc.html#L74'>IMM8</a><span class="Delimiter">,</span> +<span id="L75" class="LineNr"> 75 </span> <a href='033check_operands.cc.html#L75'>IMM32</a><span class="Delimiter">,</span> +<span id="L76" class="LineNr"> 76 </span> <a href='033check_operands.cc.html#L76'>NUM_OPERAND_TYPES</a> +<span id="L77" class="LineNr"> 77 </span><span class="Delimiter">};</span> +<span id="L78" class="LineNr"> 78 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L79" class="LineNr"> 79 </span>vector<string> <a href='033check_operands.cc.html#L79'>Operand_type_name</a><span class="Delimiter">;</span> +<span id="L80" class="LineNr"> 80 </span>map<string<span class="Delimiter">,</span> expected_argument_type> <a href='033check_operands.cc.html#L80'>Operand_type</a><span class="Delimiter">;</span> +<span id="L81" class="LineNr"> 81 </span><span class="Delimiter">:(before "End One-time Setup")</span> +<span id="L82" class="LineNr"> 82 </span><a href='033check_operands.cc.html#L84'>init_op_types</a><span class="Delimiter">();</span> +<span id="L83" class="LineNr"> 83 </span><span class="Delimiter">:(code)</span> +<span id="L84" class="LineNr"> 84 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L84'>init_op_types</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L85" class="LineNr"> 85 </span> assert<span class="Delimiter">(</span><a href='033check_operands.cc.html#L76'>NUM_OPERAND_TYPES</a> <= <span class="Comment">/*</span><span class="Comment">bits in a uint8_t</span><span class="Comment">*/</span><span class="Constant">8</span><span class="Delimiter">);</span> +<span id="L86" class="LineNr"> 86 </span> <a href='033check_operands.cc.html#L79'>Operand_type_name</a><span class="Delimiter">.</span>resize<span class="Delimiter">(</span><a href='033check_operands.cc.html#L76'>NUM_OPERAND_TYPES</a><span class="Delimiter">);</span> +<span id="L87" class="LineNr"> 87 </span> <span class="PreProc">#define DEF(type) Operand_type_name</span><span class="Delimiter">.</span><span class="PreProc">at(type) = tolower(#type)</span><span class="Delimiter">,</span><span class="PreProc"> put(Operand_type</span><span class="Delimiter">,</span><span class="PreProc"> tolower(#type)</span><span class="Delimiter">,</span><span class="PreProc"> type)</span><span class="Delimiter">;</span> +<span id="L88" class="LineNr"> 88 </span> DEF<span class="Delimiter">(</span><a href='033check_operands.cc.html#L69'>MODRM</a><span class="Delimiter">);</span> +<span id="L89" class="LineNr"> 89 </span> DEF<span class="Delimiter">(</span><a href='033check_operands.cc.html#L70'>SUBOP</a><span class="Delimiter">);</span> +<span id="L90" class="LineNr"> 90 </span> DEF<span class="Delimiter">(</span><a href='033check_operands.cc.html#L71'>DISP8</a><span class="Delimiter">);</span> +<span id="L91" class="LineNr"> 91 </span> DEF<span class="Delimiter">(</span><a href='033check_operands.cc.html#L72'>DISP16</a><span class="Delimiter">);</span> +<span id="L92" class="LineNr"> 92 </span> DEF<span class="Delimiter">(</span><a href='033check_operands.cc.html#L73'>DISP32</a><span class="Delimiter">);</span> +<span id="L93" class="LineNr"> 93 </span> DEF<span class="Delimiter">(</span><a href='033check_operands.cc.html#L74'>IMM8</a><span class="Delimiter">);</span> +<span id="L94" class="LineNr"> 94 </span> DEF<span class="Delimiter">(</span><a href='033check_operands.cc.html#L75'>IMM32</a><span class="Delimiter">);</span> +<span id="L95" class="LineNr"> 95 </span> <span class="PreProc">#undef DEF</span> +<span id="L96" class="LineNr"> 96 </span><span class="Delimiter">}</span> +<span id="L97" class="LineNr"> 97 </span> +<span id="L98" class="LineNr"> 98 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L99" class="LineNr"> 99 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">bitvector</span><span class="Comment">*/</span><span class="Normal">uint8_t</span>> <a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">;</span> +<span id="L100" class="LineNr">100 </span><span class="Normal">const</span> <span class="Normal">uint8_t</span> <a href='033check_operands.cc.html#L100'>INVALID_OPERANDS</a> = <span class="Constant">0xff</span><span class="Delimiter">;</span> <span class="Comment">// no instruction uses all the argument types</span> +<span id="L101" class="LineNr">101 </span><span class="Delimiter">:(before "End One-time Setup")</span> +<span id="L102" class="LineNr">102 </span><a href='033check_operands.cc.html#L104'>init_permitted_arguments</a><span class="Delimiter">();</span> +<span id="L103" class="LineNr">103 </span><span class="Delimiter">:(code)</span> +<span id="L104" class="LineNr">104 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L104'>init_permitted_arguments</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L105" class="LineNr">105 </span> <span class="SalientComment">//// Class A: just op, no arguments</span> +<span id="L106" class="LineNr">106 </span> <span class="Comment">// halt</span> +<span id="L107" class="LineNr">107 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"f4"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L108" class="LineNr">108 </span> <span class="Comment">// inc</span> +<span id="L109" class="LineNr">109 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"40"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L110" class="LineNr">110 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"41"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L111" class="LineNr">111 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"42"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L112" class="LineNr">112 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"43"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L113" class="LineNr">113 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"44"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L114" class="LineNr">114 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"45"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L115" class="LineNr">115 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"46"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L116" class="LineNr">116 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"47"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L117" class="LineNr">117 </span> <span class="Comment">// dec</span> +<span id="L118" class="LineNr">118 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"48"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L119" class="LineNr">119 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"49"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L120" class="LineNr">120 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"4a"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L121" class="LineNr">121 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"4b"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L122" class="LineNr">122 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"4c"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L123" class="LineNr">123 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"4d"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L124" class="LineNr">124 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"4e"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L125" class="LineNr">125 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"4f"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L126" class="LineNr">126 </span> <span class="Comment">// push</span> +<span id="L127" class="LineNr">127 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"50"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L128" class="LineNr">128 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"51"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L129" class="LineNr">129 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"52"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L130" class="LineNr">130 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"53"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L131" class="LineNr">131 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"54"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L132" class="LineNr">132 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"55"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L133" class="LineNr">133 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"56"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L134" class="LineNr">134 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"57"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L135" class="LineNr">135 </span> <span class="Comment">// pop</span> +<span id="L136" class="LineNr">136 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"58"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L137" class="LineNr">137 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"59"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L138" class="LineNr">138 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"5a"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L139" class="LineNr">139 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"5b"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L140" class="LineNr">140 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"5c"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L141" class="LineNr">141 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"5d"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L142" class="LineNr">142 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"5e"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L143" class="LineNr">143 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"5f"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L144" class="LineNr">144 </span> <span class="Comment">// sign-extend EAX into EDX</span> +<span id="L145" class="LineNr">145 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"99"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L146" class="LineNr">146 </span> <span class="Comment">// return</span> +<span id="L147" class="LineNr">147 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"c3"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L148" class="LineNr">148 </span> +<span id="L149" class="LineNr">149 </span> <span class="SalientComment">//// Class B: just op and disp8</span> +<span id="L150" class="LineNr">150 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L151" class="LineNr">151 </span> <span class="Comment">// 0 0 0 |0 1 0 0</span> +<span id="L152" class="LineNr">152 </span> +<span id="L153" class="LineNr">153 </span> <span class="Comment">// jump</span> +<span id="L154" class="LineNr">154 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"eb"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L155" class="LineNr">155 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"72"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L156" class="LineNr">156 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"73"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L157" class="LineNr">157 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"74"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L158" class="LineNr">158 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"75"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L159" class="LineNr">159 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"76"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L160" class="LineNr">160 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"77"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L161" class="LineNr">161 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"7c"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L162" class="LineNr">162 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"7d"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L163" class="LineNr">163 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"7e"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L164" class="LineNr">164 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"7f"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L165" class="LineNr">165 </span> +<span id="L166" class="LineNr">166 </span> <span class="SalientComment">//// Class D: just op and disp32</span> +<span id="L167" class="LineNr">167 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L168" class="LineNr">168 </span> <span class="Comment">// 0 0 1 |0 0 0 0</span> +<span id="L169" class="LineNr">169 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"e8"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> <span class="Comment">// call</span> +<span id="L170" class="LineNr">170 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"e9"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> <span class="Comment">// jump</span> +<span id="L171" class="LineNr">171 </span> +<span id="L172" class="LineNr">172 </span> <span class="SalientComment">//// Class E: just op and imm8</span> +<span id="L173" class="LineNr">173 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L174" class="LineNr">174 </span> <span class="Comment">// 0 1 0 |0 0 0 0</span> +<span id="L175" class="LineNr">175 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"cd"</span><span class="Delimiter">,</span> <span class="Constant">0x20</span><span class="Delimiter">);</span> <span class="Comment">// software interrupt</span> +<span id="L176" class="LineNr">176 </span> +<span id="L177" class="LineNr">177 </span> <span class="SalientComment">//// Class F: just op and imm32</span> +<span id="L178" class="LineNr">178 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L179" class="LineNr">179 </span> <span class="Comment">// 1 0 0 |0 0 0 0</span> +<span id="L180" class="LineNr">180 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"05"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// add</span> +<span id="L181" class="LineNr">181 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"2d"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// subtract</span> +<span id="L182" class="LineNr">182 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"25"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// and</span> +<span id="L183" class="LineNr">183 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"0d"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// or</span> +<span id="L184" class="LineNr">184 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"35"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// xor</span> +<span id="L185" class="LineNr">185 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"3d"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// compare</span> +<span id="L186" class="LineNr">186 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"68"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// push</span> +<span id="L187" class="LineNr">187 </span> <span class="Comment">// copy</span> +<span id="L188" class="LineNr">188 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"b8"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L189" class="LineNr">189 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"b9"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L190" class="LineNr">190 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"ba"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L191" class="LineNr">191 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"bb"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L192" class="LineNr">192 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"bc"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L193" class="LineNr">193 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"bd"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L194" class="LineNr">194 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"be"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L195" class="LineNr">195 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"bf"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L196" class="LineNr">196 </span> +<span id="L197" class="LineNr">197 </span> <span class="SalientComment">//// Class M: using ModR/M byte</span> +<span id="L198" class="LineNr">198 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L199" class="LineNr">199 </span> <span class="Comment">// 0 0 0 |0 0 0 1</span> +<span id="L200" class="LineNr">200 </span> +<span id="L201" class="LineNr">201 </span> <span class="Comment">// add</span> +<span id="L202" class="LineNr">202 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"01"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L203" class="LineNr">203 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"03"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L204" class="LineNr">204 </span> <span class="Comment">// subtract</span> +<span id="L205" class="LineNr">205 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"29"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L206" class="LineNr">206 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"2b"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L207" class="LineNr">207 </span> <span class="Comment">// and</span> +<span id="L208" class="LineNr">208 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"21"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L209" class="LineNr">209 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"23"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L210" class="LineNr">210 </span> <span class="Comment">// or</span> +<span id="L211" class="LineNr">211 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"09"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L212" class="LineNr">212 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"0b"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L213" class="LineNr">213 </span> <span class="Comment">// xor</span> +<span id="L214" class="LineNr">214 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"31"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L215" class="LineNr">215 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"33"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L216" class="LineNr">216 </span> <span class="Comment">// compare</span> +<span id="L217" class="LineNr">217 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"39"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L218" class="LineNr">218 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"3b"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L219" class="LineNr">219 </span> <span class="Comment">// copy</span> +<span id="L220" class="LineNr">220 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"88"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L221" class="LineNr">221 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"89"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L222" class="LineNr">222 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"8a"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L223" class="LineNr">223 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"8b"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L224" class="LineNr">224 </span> <span class="Comment">// swap</span> +<span id="L225" class="LineNr">225 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"87"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L226" class="LineNr">226 </span> <span class="Comment">// copy address (lea)</span> +<span id="L227" class="LineNr">227 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"8d"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L228" class="LineNr">228 </span> +<span id="L229" class="LineNr">229 </span> <span class="SalientComment">//// Class N: op, ModR/M and subop (not r32)</span> +<span id="L230" class="LineNr">230 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L231" class="LineNr">231 </span> <span class="Comment">// 0 0 0 |0 0 1 1</span> +<span id="L232" class="LineNr">232 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"8f"</span><span class="Delimiter">,</span> <span class="Constant">0x03</span><span class="Delimiter">);</span> <span class="Comment">// pop</span> +<span id="L233" class="LineNr">233 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"d3"</span><span class="Delimiter">,</span> <span class="Constant">0x03</span><span class="Delimiter">);</span> <span class="Comment">// shift</span> +<span id="L234" class="LineNr">234 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"f7"</span><span class="Delimiter">,</span> <span class="Constant">0x03</span><span class="Delimiter">);</span> <span class="Comment">// test/not/mul/div</span> +<span id="L235" class="LineNr">235 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"ff"</span><span class="Delimiter">,</span> <span class="Constant">0x03</span><span class="Delimiter">);</span> <span class="Comment">// jump/push/call</span> +<span id="L236" class="LineNr">236 </span> +<span id="L237" class="LineNr">237 </span> <span class="SalientComment">//// Class O: op, ModR/M, subop (not r32) and imm8</span> +<span id="L238" class="LineNr">238 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L239" class="LineNr">239 </span> <span class="Comment">// 0 1 0 |0 0 1 1</span> +<span id="L240" class="LineNr">240 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"c1"</span><span class="Delimiter">,</span> <span class="Constant">0x23</span><span class="Delimiter">);</span> <span class="Comment">// combine</span> +<span id="L241" class="LineNr">241 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"c6"</span><span class="Delimiter">,</span> <span class="Constant">0x23</span><span class="Delimiter">);</span> <span class="Comment">// copy</span> +<span id="L242" class="LineNr">242 </span> +<span id="L243" class="LineNr">243 </span> <span class="SalientComment">//// Class P: op, ModR/M, subop (not r32) and imm32</span> +<span id="L244" class="LineNr">244 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L245" class="LineNr">245 </span> <span class="Comment">// 1 0 0 |0 0 1 1</span> +<span id="L246" class="LineNr">246 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"81"</span><span class="Delimiter">,</span> <span class="Constant">0x43</span><span class="Delimiter">);</span> <span class="Comment">// combine</span> +<span id="L247" class="LineNr">247 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"c7"</span><span class="Delimiter">,</span> <span class="Constant">0x43</span><span class="Delimiter">);</span> <span class="Comment">// copy</span> +<span id="L248" class="LineNr">248 </span> +<span id="L249" class="LineNr">249 </span> <span class="SalientComment">//// Class Q: op, ModR/M and imm32</span> +<span id="L250" class="LineNr">250 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L251" class="LineNr">251 </span> <span class="Comment">// 1 0 0 |0 0 0 1</span> +<span id="L252" class="LineNr">252 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> <span class="Constant">"69"</span><span class="Delimiter">,</span> <span class="Constant">0x41</span><span class="Delimiter">);</span> <span class="Comment">// multiply</span> +<span id="L253" class="LineNr">253 </span> +<span id="L254" class="LineNr">254 </span> <span class="Comment">// End Init Permitted Operands</span> +<span id="L255" class="LineNr">255 </span><span class="Delimiter">}</span> +<span id="L256" class="LineNr">256 </span> +<span id="L257" class="LineNr">257 </span><span class="PreProc">#define HAS(bitvector</span><span class="Delimiter">,</span><span class="PreProc"> bit) ((bitvector) & (</span><span class="Constant">1</span><span class="PreProc"> << (bit)))</span> +<span id="L258" class="LineNr">258 </span><span class="PreProc">#define SET(bitvector</span><span class="Delimiter">,</span><span class="PreProc"> bit) ((bitvector) | (</span><span class="Constant">1</span><span class="PreProc"> << (bit)))</span> +<span id="L259" class="LineNr">259 </span><span class="PreProc">#define CLEAR(bitvector</span><span class="Delimiter">,</span><span class="PreProc"> bit) ((bitvector) & (~(</span><span class="Constant">1</span><span class="PreProc"> << (bit))))</span> +<span id="L260" class="LineNr">260 </span> +<span id="L261" class="LineNr">261 </span><span class="Normal">void</span> check_arguments<span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L262" class="LineNr">262 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_hex_byte<span class="Delimiter">(</span>op<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L263" class="LineNr">263 </span> <span class="Normal">uint8_t</span> expected_bitvector = get<span class="Delimiter">(</span><a href='033check_operands.cc.html#L99'>Permitted_arguments</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L264" class="LineNr">264 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>HAS<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L69'>MODRM</a><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L265" class="LineNr">265 </span> <a href='033check_operands.cc.html#L377'>check_arguments_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L266" class="LineNr">266 </span> <a href='033check_operands.cc.html#L412'>compare_bitvector_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> expected_bitvector<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L293'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">));</span> +<span id="L267" class="LineNr">267 </span> <span class="Delimiter">}</span> +<span id="L268" class="LineNr">268 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L269" class="LineNr">269 </span> <a href='033check_operands.cc.html#L275'>compare_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> expected_bitvector<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L293'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">));</span> +<span id="L270" class="LineNr">270 </span> <span class="Delimiter">}</span> +<span id="L271" class="LineNr">271 </span><span class="Delimiter">}</span> +<span id="L272" class="LineNr">272 </span> +<span id="L273" class="LineNr">273 </span><span class="Comment">//: Many instructions can be checked just by comparing bitvectors.</span> +<span id="L274" class="LineNr">274 </span> +<span id="L275" class="LineNr">275 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L275'>compare_bitvector</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">uint8_t</span> expected<span class="Delimiter">,</span> <span class="Normal">const</span> string& maybe_op_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L276" class="LineNr">276 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='032operands.cc.html#L531'>all_hex_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">)</span> && <a href='033check_operands.cc.html#L311'>has_arguments</a><span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// deliberately programming in raw hex; we'll raise a warning elsewhere</span> +<span id="L277" class="LineNr">277 </span> <span class="Normal">uint8_t</span> bitvector = <a href='033check_operands.cc.html#L301'>compute_expected_argument_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L278" class="LineNr">278 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// duplicate argument type</span> +<span id="L279" class="LineNr">279 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>bitvector == expected<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// all good with this instruction</span> +<span id="L280" class="LineNr">280 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='033check_operands.cc.html#L76'>NUM_OPERAND_TYPES</a><span class="Delimiter">;</span> ++i<span class="Delimiter">,</span> bitvector >>= <span class="Constant">1</span><span class="Delimiter">,</span> expected >>= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L281" class="LineNr">281 </span><span class="CommentedCode">//? cerr << "comparing " << HEXBYTE << NUM(bitvector) << " with " << NUM(expected) << '\n';</span> +<span id="L282" class="LineNr">282 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> == <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// all good with this argument</span> +<span id="L283" class="LineNr">283 </span> <span class="Normal">const</span> string& optype = <a href='033check_operands.cc.html#L79'>Operand_type_name</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L284" class="LineNr">284 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> > <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> +<span id="L285" class="LineNr">285 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << maybe_op_name << <span class="Constant">": unexpected "</span> << optype << <span class="Constant">" argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L286" class="LineNr">286 </span> <span class="Normal">else</span> +<span id="L287" class="LineNr">287 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << maybe_op_name << <span class="Constant">": missing "</span> << optype << <span class="Constant">" argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L288" class="LineNr">288 </span> <span class="Comment">// continue giving all errors for a single instruction</span> +<span id="L289" class="LineNr">289 </span> <span class="Delimiter">}</span> +<span id="L290" class="LineNr">290 </span> <span class="Comment">// ignore settings in any unused bits</span> +<span id="L291" class="LineNr">291 </span><span class="Delimiter">}</span> +<span id="L292" class="LineNr">292 </span> +<span id="L293" class="LineNr">293 </span>string <a href='033check_operands.cc.html#L293'>maybe_name</a><span class="Delimiter">(</span><span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L294" class="LineNr">294 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_hex_byte<span class="Delimiter">(</span>op<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L295" class="LineNr">295 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L296" class="LineNr">296 </span> <span class="Comment">// strip stuff in parens from the name</span> +<span id="L297" class="LineNr">297 </span> <span class="Normal">const</span> string& s = get<span class="Delimiter">(</span><a href='010vm.cc.html#L355'>Name</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L298" class="LineNr">298 </span> <span class="Identifier">return</span> <span class="Constant">" ("</span>+s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">" ("</span><span class="Delimiter">))</span>+<span class="Constant">')'</span><span class="Delimiter">;</span> +<span id="L299" class="LineNr">299 </span><span class="Delimiter">}</span> +<span id="L300" class="LineNr">300 </span> +<span id="L301" class="LineNr">301 </span><span class="Normal">uint32_t</span> <a href='033check_operands.cc.html#L301'>compute_expected_argument_bitvector</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L302" class="LineNr">302 </span> set<string> arguments_found<span class="Delimiter">;</span> +<span id="L303" class="LineNr">303 </span> <span class="Normal">uint32_t</span> bitvector = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L304" class="LineNr">304 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Comment">/*</span><span class="Comment">skip op</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L305" class="LineNr">305 </span> bitvector = bitvector | <a href='033check_operands.cc.html#L328'>expected_bit_for_received_argument</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> arguments_found<span class="Delimiter">,</span> inst<span class="Delimiter">);</span> +<span id="L306" class="LineNr">306 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span> <a href='033check_operands.cc.html#L100'>INVALID_OPERANDS</a><span class="Delimiter">;</span> <span class="Comment">// duplicate argument type</span> +<span id="L307" class="LineNr">307 </span> <span class="Delimiter">}</span> +<span id="L308" class="LineNr">308 </span> <span class="Identifier">return</span> bitvector<span class="Delimiter">;</span> +<span id="L309" class="LineNr">309 </span><span class="Delimiter">}</span> +<span id="L310" class="LineNr">310 </span> +<span id="L311" class="LineNr">311 </span><span class="Normal">bool</span> <a href='033check_operands.cc.html#L311'>has_arguments</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L312" class="LineNr">312 </span> <span class="Identifier">return</span> <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">)</span> > <a href='033check_operands.cc.html#L315'>first_argument</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L313" class="LineNr">313 </span><span class="Delimiter">}</span> +<span id="L314" class="LineNr">314 </span> +<span id="L315" class="LineNr">315 </span><span class="Normal">int</span> <a href='033check_operands.cc.html#L315'>first_argument</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L316" class="LineNr">316 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"0f"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L317" class="LineNr">317 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"f2"</span> || inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"f3"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L318" class="LineNr">318 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>data == <span class="Constant">"0f"</span><span class="Delimiter">)</span> +<span id="L319" class="LineNr">319 </span> <span class="Identifier">return</span> <span class="Constant">3</span><span class="Delimiter">;</span> +<span id="L320" class="LineNr">320 </span> <span class="Normal">else</span> +<span id="L321" class="LineNr">321 </span> <span class="Identifier">return</span> <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L322" class="LineNr">322 </span> <span class="Delimiter">}</span> +<span id="L323" class="LineNr">323 </span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L324" class="LineNr">324 </span><span class="Delimiter">}</span> +<span id="L325" class="LineNr">325 </span> +<span id="L326" class="LineNr">326 </span><span class="Comment">// Scan the metadata of 'w' and return the expected bit corresponding to any argument type.</span> +<span id="L327" class="LineNr">327 </span><span class="Comment">// Also raise an error if metadata contains multiple argument types.</span> +<span id="L328" class="LineNr">328 </span><span class="Normal">uint32_t</span> <a href='033check_operands.cc.html#L328'>expected_bit_for_received_argument</a><span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">,</span> set<string>& instruction_arguments<span class="Delimiter">,</span> <span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L329" class="LineNr">329 </span> <span class="Normal">uint32_t</span> bv = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L330" class="LineNr">330 </span> <span class="Normal">bool</span> found = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L331" class="LineNr">331 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>metadata<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L332" class="LineNr">332 </span> string<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> curr = w<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L333" class="LineNr">333 </span> string expected_metadata = curr<span class="Delimiter">;</span> +<span id="L334" class="LineNr">334 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr == <span class="Constant">"mod"</span> || curr == <span class="Constant">"rm32"</span> || curr == <span class="Constant">"r32"</span> || curr == <span class="Constant">"xm32"</span> || curr == <span class="Constant">"x32"</span> || curr == <span class="Constant">"scale"</span> || curr == <span class="Constant">"index"</span> || curr == <span class="Constant">"base"</span><span class="Delimiter">)</span> +<span id="L335" class="LineNr">335 </span> expected_metadata = <span class="Constant">"modrm"</span><span class="Delimiter">;</span> +<span id="L336" class="LineNr">336 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><a href='033check_operands.cc.html#L80'>Operand_type</a><span class="Delimiter">,</span> curr<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// ignore unrecognized metadata</span> +<span id="L337" class="LineNr">337 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>found<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L338" class="LineNr">338 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << w<span class="Delimiter">.</span>original << <span class="Constant">"' has conflicting argument types; it should have only one</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L339" class="LineNr">339 </span> <span class="Identifier">return</span> <a href='033check_operands.cc.html#L100'>INVALID_OPERANDS</a><span class="Delimiter">;</span> +<span id="L340" class="LineNr">340 </span> <span class="Delimiter">}</span> +<span id="L341" class="LineNr">341 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>instruction_arguments<span class="Delimiter">.</span>find<span class="Delimiter">(</span>curr<span class="Delimiter">)</span> != instruction_arguments<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L342" class="LineNr">342 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': duplicate "</span> << curr << <span class="Constant">" argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L343" class="LineNr">343 </span> <span class="Identifier">return</span> <a href='033check_operands.cc.html#L100'>INVALID_OPERANDS</a><span class="Delimiter">;</span> +<span id="L344" class="LineNr">344 </span> <span class="Delimiter">}</span> +<span id="L345" class="LineNr">345 </span> instruction_arguments<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L346" class="LineNr">346 </span> bv = <span class="Delimiter">(</span><span class="Constant">1</span> << get<span class="Delimiter">(</span><a href='033check_operands.cc.html#L80'>Operand_type</a><span class="Delimiter">,</span> expected_metadata<span class="Delimiter">));</span> +<span id="L347" class="LineNr">347 </span> found = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L348" class="LineNr">348 </span> <span class="Delimiter">}</span> +<span id="L349" class="LineNr">349 </span> <span class="Identifier">return</span> bv<span class="Delimiter">;</span> +<span id="L350" class="LineNr">350 </span><span class="Delimiter">}</span> +<span id="L351" class="LineNr">351 </span> +<span id="L352" class="LineNr">352 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L352'>test_conflicting_argument_type</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L353" class="LineNr">353 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L354" class="LineNr">354 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L355" class="LineNr">355 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L356" class="LineNr">356 </span> <span class="Constant">"cd/software-interrupt 80/imm8/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L357" class="LineNr">357 </span> <span class="Delimiter">);</span> +<span id="L358" class="LineNr">358 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L359" class="LineNr">359 </span> <span class="Constant">"error: '80/imm8/imm32' has conflicting argument types; it should have only one</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L360" class="LineNr">360 </span> <span class="Delimiter">);</span> +<span id="L361" class="LineNr">361 </span><span class="Delimiter">}</span> +<span id="L362" class="LineNr">362 </span> +<span id="L363" class="LineNr">363 </span><span class="Comment">//: Instructions computing effective addresses have more complex rules, so</span> +<span id="L364" class="LineNr">364 </span><span class="Comment">//: we'll hard-code a common set of instruction-decoding rules.</span> +<span id="L365" class="LineNr">365 </span> +<span id="L366" class="LineNr">366 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L366'>test_check_missing_mod_argument</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L367" class="LineNr">367 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L368" class="LineNr">368 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L369" class="LineNr">369 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L370" class="LineNr">370 </span> <span class="Constant">"81 0/add/subop 3/rm32/ebx 1/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L371" class="LineNr">371 </span> <span class="Delimiter">);</span> +<span id="L372" class="LineNr">372 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L373" class="LineNr">373 </span> <span class="Constant">"error: '81 0/add/subop 3/rm32/ebx 1/imm32' (combine rm32 with imm32 based on subop): missing mod argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L374" class="LineNr">374 </span> <span class="Delimiter">);</span> +<span id="L375" class="LineNr">375 </span><span class="Delimiter">}</span> +<span id="L376" class="LineNr">376 </span> +<span id="L377" class="LineNr">377 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L377'>check_arguments_modrm</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L378" class="LineNr">378 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='032operands.cc.html#L531'>all_hex_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// deliberately programming in raw hex; we'll raise a warning elsewhere</span> +<span id="L379" class="LineNr">379 </span> <a href='033check_operands.cc.html#L446'>check_argument_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L380" class="LineNr">380 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_argument_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">)</span> && !has_argument_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"xm32"</span><span class="Delimiter">))</span> +<span id="L381" class="LineNr">381 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='033check_operands.cc.html#L293'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": missing rm32 (or xm32) argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L382" class="LineNr">382 </span> <span class="Comment">// no check for r32; some instructions don't use it; just assume it's 0 if missing</span> +<span id="L383" class="LineNr">383 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>op<span class="Delimiter">.</span>data == <span class="Constant">"81"</span> || op<span class="Delimiter">.</span>data == <span class="Constant">"8f"</span> || op<span class="Delimiter">.</span>data == <span class="Constant">"f7"</span> || op<span class="Delimiter">.</span>data == <span class="Constant">"ff"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// keep sync'd with 'help subop'</span> +<span id="L384" class="LineNr">384 </span> <a href='033check_operands.cc.html#L446'>check_argument_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"subop"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L385" class="LineNr">385 </span> <a href='033check_operands.cc.html#L451'>check_argument_metadata_absent</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"r32"</span><span class="Delimiter">,</span> op<span class="Delimiter">,</span> <span class="Constant">"should be replaced by subop"</span><span class="Delimiter">);</span> +<span id="L386" class="LineNr">386 </span> <a href='033check_operands.cc.html#L451'>check_argument_metadata_absent</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"x32"</span><span class="Delimiter">,</span> op<span class="Delimiter">,</span> <span class="Constant">"should be replaced by subop"</span><span class="Delimiter">);</span> +<span id="L387" class="LineNr">387 </span> <span class="Delimiter">}</span> +<span id="L388" class="LineNr">388 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L389" class="LineNr">389 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='033check_operands.cc.html#L403'>metadata_m32</a><span class="Delimiter">(</span>inst<span class="Delimiter">).</span>data != <span class="Constant">"4"</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L390" class="LineNr">390 </span> <span class="Comment">// SIB byte checks</span> +<span id="L391" class="LineNr">391 </span> <span class="Normal">uint8_t</span> mod = <a href='011run.cc.html#L288'>hex_byte</a><span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">).</span>data<span class="Delimiter">);</span> +<span id="L392" class="LineNr">392 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod != <span class="Comment">/*</span><span class="Comment">direct</span><span class="Comment">*/</span><span class="Constant">3</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L393" class="LineNr">393 </span> <a href='033check_operands.cc.html#L446'>check_argument_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L394" class="LineNr">394 </span> <a href='033check_operands.cc.html#L446'>check_argument_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> <span class="Comment">// otherwise why go to SIB?</span> +<span id="L395" class="LineNr">395 </span> <span class="Delimiter">}</span> +<span id="L396" class="LineNr">396 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L397" class="LineNr">397 </span> <a href='033check_operands.cc.html#L451'>check_argument_metadata_absent</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">,</span> op<span class="Delimiter">,</span> <span class="Constant">"direct mode"</span><span class="Delimiter">);</span> +<span id="L398" class="LineNr">398 </span> <a href='033check_operands.cc.html#L451'>check_argument_metadata_absent</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">,</span> op<span class="Delimiter">,</span> <span class="Constant">"direct mode"</span><span class="Delimiter">);</span> +<span id="L399" class="LineNr">399 </span> <span class="Delimiter">}</span> +<span id="L400" class="LineNr">400 </span> <span class="Comment">// no check for scale; 0 (2**0 = 1) by default</span> +<span id="L401" class="LineNr">401 </span><span class="Delimiter">}</span> +<span id="L402" class="LineNr">402 </span> +<span id="L403" class="LineNr">403 </span><a href='011run.cc.html#L127'>word</a> <a href='033check_operands.cc.html#L403'>metadata_m32</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L404" class="LineNr">404 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L405" class="LineNr">405 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> <span class="Constant">"rm32"</span><span class="Delimiter">)</span> || has_argument_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> <span class="Constant">"xm32"</span><span class="Delimiter">))</span> +<span id="L406" class="LineNr">406 </span> <span class="Identifier">return</span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L407" class="LineNr">407 </span> assert<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span> +<span id="L408" class="LineNr">408 </span><span class="Delimiter">}</span> +<span id="L409" class="LineNr">409 </span> +<span id="L410" class="LineNr">410 </span><span class="Comment">// same as compare_bitvector, with one additional exception for modrm-based</span> +<span id="L411" class="LineNr">411 </span><span class="Comment">// instructions: they may use an extra displacement on occasion</span> +<span id="L412" class="LineNr">412 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L412'>compare_bitvector_modrm</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">uint8_t</span> expected<span class="Delimiter">,</span> <span class="Normal">const</span> string& maybe_op_name<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L413" class="LineNr">413 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='032operands.cc.html#L531'>all_hex_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">)</span> && <a href='033check_operands.cc.html#L311'>has_arguments</a><span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// deliberately programming in raw hex; we'll raise a warning elsewhere</span> +<span id="L414" class="LineNr">414 </span> <span class="Normal">uint8_t</span> bitvector = <a href='033check_operands.cc.html#L301'>compute_expected_argument_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L415" class="LineNr">415 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// duplicate argument type</span> +<span id="L416" class="LineNr">416 </span> <span class="Comment">// update 'expected' bitvector for the additional exception</span> +<span id="L417" class="LineNr">417 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L418" class="LineNr">418 </span> <span class="Normal">int32_t</span> mod = <a href='032operands.cc.html#L608'>parse_int</a><span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">).</span>data<span class="Delimiter">);</span> +<span id="L419" class="LineNr">419 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>mod<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L420" class="LineNr">420 </span> <span class="Normal">case</span> <span class="Constant">0</span>: +<span id="L421" class="LineNr">421 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">)</span> && <a href='032operands.cc.html#L608'>parse_int</a><span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">).</span>data<span class="Delimiter">)</span> == <span class="Constant">5</span><span class="Delimiter">)</span> +<span id="L422" class="LineNr">422 </span> expected |= <span class="Delimiter">(</span><span class="Constant">1</span><<DISP32<span class="Delimiter">);</span> +<span id="L423" class="LineNr">423 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L424" class="LineNr">424 </span> <span class="Normal">case</span> <span class="Constant">1</span>: +<span id="L425" class="LineNr">425 </span> expected |= <span class="Delimiter">(</span><span class="Constant">1</span><<DISP8<span class="Delimiter">);</span> +<span id="L426" class="LineNr">426 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L427" class="LineNr">427 </span> <span class="Normal">case</span> <span class="Constant">2</span>: +<span id="L428" class="LineNr">428 </span> expected |= <span class="Delimiter">(</span><span class="Constant">1</span><<DISP32<span class="Delimiter">);</span> +<span id="L429" class="LineNr">429 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L430" class="LineNr">430 </span> <span class="Delimiter">}</span> +<span id="L431" class="LineNr">431 </span> <span class="Delimiter">}</span> +<span id="L432" class="LineNr">432 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>bitvector == expected<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// all good with this instruction</span> +<span id="L433" class="LineNr">433 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='033check_operands.cc.html#L76'>NUM_OPERAND_TYPES</a><span class="Delimiter">;</span> ++i<span class="Delimiter">,</span> bitvector >>= <span class="Constant">1</span><span class="Delimiter">,</span> expected >>= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L434" class="LineNr">434 </span><span class="CommentedCode">//? cerr << "comparing for modrm " << HEXBYTE << NUM(bitvector) << " with " << NUM(expected) << '\n';</span> +<span id="L435" class="LineNr">435 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> == <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// all good with this argument</span> +<span id="L436" class="LineNr">436 </span> <span class="Normal">const</span> string& optype = <a href='033check_operands.cc.html#L79'>Operand_type_name</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L437" class="LineNr">437 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> > <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> +<span id="L438" class="LineNr">438 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << maybe_op_name << <span class="Constant">": unexpected "</span> << optype << <span class="Constant">" argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L439" class="LineNr">439 </span> <span class="Normal">else</span> +<span id="L440" class="LineNr">440 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << maybe_op_name << <span class="Constant">": missing "</span> << optype << <span class="Constant">" argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L441" class="LineNr">441 </span> <span class="Comment">// continue giving all errors for a single instruction</span> +<span id="L442" class="LineNr">442 </span> <span class="Delimiter">}</span> +<span id="L443" class="LineNr">443 </span> <span class="Comment">// ignore settings in any unused bits</span> +<span id="L444" class="LineNr">444 </span><span class="Delimiter">}</span> +<span id="L445" class="LineNr">445 </span> +<span id="L446" class="LineNr">446 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L446'>check_argument_metadata_present</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> string& type<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L447" class="LineNr">447 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_argument_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> type<span class="Delimiter">))</span> +<span id="L448" class="LineNr">448 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='033check_operands.cc.html#L293'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": missing "</span> << type << <span class="Constant">" argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L449" class="LineNr">449 </span><span class="Delimiter">}</span> +<span id="L450" class="LineNr">450 </span> +<span id="L451" class="LineNr">451 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L451'>check_argument_metadata_absent</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> string& type<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">,</span> <span class="Normal">const</span> string& msg<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L452" class="LineNr">452 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> type<span class="Delimiter">))</span> +<span id="L453" class="LineNr">453 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='033check_operands.cc.html#L293'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << type << <span class="Constant">" argument ("</span> << msg << <span class="Constant">")</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L454" class="LineNr">454 </span><span class="Delimiter">}</span> +<span id="L455" class="LineNr">455 </span> +<span id="L456" class="LineNr">456 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L456'>test_modrm_with_displacement</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L457" class="LineNr">457 </span> Reg[EAX]<span class="Delimiter">.</span>u = <span class="Constant">0x1</span><span class="Delimiter">;</span> +<span id="L458" class="LineNr">458 </span> transform<span class="Delimiter">(</span> +<span id="L459" class="LineNr">459 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L460" class="LineNr">460 </span> <span class="Comment">// just avoid null pointer</span> +<span id="L461" class="LineNr">461 </span> <span class="Constant">"8b/copy 1/mod/lookup+disp8 0/rm32/EAX 2/r32/EDX 4/disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// copy *(EAX+4) to EDX</span> +<span id="L462" class="LineNr">462 </span> <span class="Delimiter">);</span> +<span id="L463" class="LineNr">463 </span> <a href='003trace.cc.html#L294'>CHECK_TRACE_COUNT</a><span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L464" class="LineNr">464 </span><span class="Delimiter">}</span> +<span id="L465" class="LineNr">465 </span> +<span id="L466" class="LineNr">466 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L466'>test_check_missing_disp8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L467" class="LineNr">467 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L468" class="LineNr">468 </span> transform<span class="Delimiter">(</span> +<span id="L469" class="LineNr">469 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L470" class="LineNr">470 </span> <span class="Constant">"89/copy 1/mod/lookup+disp8 0/rm32/EAX 1/r32/ECX</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// missing disp8</span> +<span id="L471" class="LineNr">471 </span> <span class="Delimiter">);</span> +<span id="L472" class="LineNr">472 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L473" class="LineNr">473 </span> <span class="Constant">"error: '89/copy 1/mod/lookup+disp8 0/rm32/EAX 1/r32/ECX' (copy r32 to rm32): missing disp8 argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L474" class="LineNr">474 </span> <span class="Delimiter">);</span> +<span id="L475" class="LineNr">475 </span><span class="Delimiter">}</span> +<span id="L476" class="LineNr">476 </span> +<span id="L477" class="LineNr">477 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L477'>test_check_missing_disp32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L478" class="LineNr">478 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L479" class="LineNr">479 </span> transform<span class="Delimiter">(</span> +<span id="L480" class="LineNr">480 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L481" class="LineNr">481 </span> <span class="Constant">"8b/copy 0/mod/indirect 5/rm32/.disp32 2/r32/EDX</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// missing disp32</span> +<span id="L482" class="LineNr">482 </span> <span class="Delimiter">);</span> +<span id="L483" class="LineNr">483 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L484" class="LineNr">484 </span> <span class="Constant">"error: '8b/copy 0/mod/indirect 5/rm32/.disp32 2/r32/EDX' (copy rm32 to r32): missing <a href='040tests.cc.html#L82'>disp32</a> argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L485" class="LineNr">485 </span> <span class="Delimiter">);</span> +<span id="L486" class="LineNr">486 </span><span class="Delimiter">}</span> +<span id="L487" class="LineNr">487 </span> +<span id="L488" class="LineNr">488 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L488'>test_conflicting_arguments_in_modrm_instruction</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L489" class="LineNr">489 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L490" class="LineNr">490 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L491" class="LineNr">491 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L492" class="LineNr">492 </span> <span class="Constant">"01/add 0/mod 3/mod</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L493" class="LineNr">493 </span> <span class="Delimiter">);</span> +<span id="L494" class="LineNr">494 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L495" class="LineNr">495 </span> <span class="Constant">"error: '01/add 0/mod 3/mod' has conflicting mod arguments</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L496" class="LineNr">496 </span> <span class="Delimiter">);</span> +<span id="L497" class="LineNr">497 </span><span class="Delimiter">}</span> +<span id="L498" class="LineNr">498 </span> +<span id="L499" class="LineNr">499 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L499'>test_conflicting_argument_type_modrm</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L500" class="LineNr">500 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L501" class="LineNr">501 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L502" class="LineNr">502 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L503" class="LineNr">503 </span> <span class="Constant">"01/add 0/mod 3/rm32/r32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L504" class="LineNr">504 </span> <span class="Delimiter">);</span> +<span id="L505" class="LineNr">505 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L506" class="LineNr">506 </span> <span class="Constant">"error: '3/rm32/r32' has conflicting argument types; it should have only one</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L507" class="LineNr">507 </span> <span class="Delimiter">);</span> +<span id="L508" class="LineNr">508 </span><span class="Delimiter">}</span> +<span id="L509" class="LineNr">509 </span> +<span id="L510" class="LineNr">510 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L510'>test_check_missing_rm32_argument</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L511" class="LineNr">511 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L512" class="LineNr">512 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L513" class="LineNr">513 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L514" class="LineNr">514 </span> <span class="Constant">"81 0/add/subop 0/mod 1/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L515" class="LineNr">515 </span> <span class="Delimiter">);</span> +<span id="L516" class="LineNr">516 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L517" class="LineNr">517 </span> <span class="Constant">"error: '81 0/add/subop 0/mod 1/imm32' (combine rm32 with imm32 based on subop): missing rm32 (or xm32) argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L518" class="LineNr">518 </span> <span class="Delimiter">);</span> +<span id="L519" class="LineNr">519 </span><span class="Delimiter">}</span> +<span id="L520" class="LineNr">520 </span> +<span id="L521" class="LineNr">521 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L521'>test_check_missing_subop_argument</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L522" class="LineNr">522 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L523" class="LineNr">523 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L524" class="LineNr">524 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L525" class="LineNr">525 </span> <span class="Constant">"81 0/mod 3/rm32/ebx 1/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L526" class="LineNr">526 </span> <span class="Delimiter">);</span> +<span id="L527" class="LineNr">527 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L528" class="LineNr">528 </span> <span class="Constant">"error: '81 0/mod 3/rm32/ebx 1/imm32' (combine rm32 with imm32 based on subop): missing subop argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L529" class="LineNr">529 </span> <span class="Delimiter">);</span> +<span id="L530" class="LineNr">530 </span><span class="Delimiter">}</span> +<span id="L531" class="LineNr">531 </span> +<span id="L532" class="LineNr">532 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L532'>test_check_missing_base_argument</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L533" class="LineNr">533 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L534" class="LineNr">534 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L535" class="LineNr">535 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L536" class="LineNr">536 </span> <span class="Constant">"81 0/add/subop 0/mod/indirect 4/rm32/use-sib 1/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L537" class="LineNr">537 </span> <span class="Delimiter">);</span> +<span id="L538" class="LineNr">538 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L539" class="LineNr">539 </span> <span class="Constant">"error: '81 0/add/subop 0/mod/indirect 4/rm32/use-sib 1/imm32' (combine rm32 with imm32 based on subop): missing base argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L540" class="LineNr">540 </span> <span class="Delimiter">);</span> +<span id="L541" class="LineNr">541 </span><span class="Delimiter">}</span> +<span id="L542" class="LineNr">542 </span> +<span id="L543" class="LineNr">543 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L543'>test_check_missing_index_argument</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L544" class="LineNr">544 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L545" class="LineNr">545 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L546" class="LineNr">546 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L547" class="LineNr">547 </span> <span class="Constant">"81 0/add/subop 0/mod/indirect 4/rm32/use-sib 0/base 1/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L548" class="LineNr">548 </span> <span class="Delimiter">);</span> +<span id="L549" class="LineNr">549 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L550" class="LineNr">550 </span> <span class="Constant">"error: '81 0/add/subop 0/mod/indirect 4/rm32/use-sib 0/base 1/imm32' (combine rm32 with imm32 based on subop): missing index argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L551" class="LineNr">551 </span> <span class="Delimiter">);</span> +<span id="L552" class="LineNr">552 </span><span class="Delimiter">}</span> +<span id="L553" class="LineNr">553 </span> +<span id="L554" class="LineNr">554 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L554'>test_check_missing_base_argument_2</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L555" class="LineNr">555 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L556" class="LineNr">556 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L557" class="LineNr">557 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L558" class="LineNr">558 </span> <span class="Constant">"81 0/add/subop 0/mod/indirect 4/rm32/use-sib 2/index 3/scale 1/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L559" class="LineNr">559 </span> <span class="Delimiter">);</span> +<span id="L560" class="LineNr">560 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L561" class="LineNr">561 </span> <span class="Constant">"error: '81 0/add/subop 0/mod/indirect 4/rm32/use-sib 2/index 3/scale 1/imm32' (combine rm32 with imm32 based on subop): missing base argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L562" class="LineNr">562 </span> <span class="Delimiter">);</span> +<span id="L563" class="LineNr">563 </span><span class="Delimiter">}</span> +<span id="L564" class="LineNr">564 </span> +<span id="L565" class="LineNr">565 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L565'>test_check_extra_displacement</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L566" class="LineNr">566 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L567" class="LineNr">567 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L568" class="LineNr">568 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L569" class="LineNr">569 </span> <span class="Constant">"89/copy 0/mod/indirect 0/rm32/EAX 1/r32/ECX 4/disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L570" class="LineNr">570 </span> <span class="Delimiter">);</span> +<span id="L571" class="LineNr">571 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L572" class="LineNr">572 </span> <span class="Constant">"error: '89/copy 0/mod/indirect 0/rm32/EAX 1/r32/ECX 4/disp8' (copy r32 to rm32): unexpected disp8 argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L573" class="LineNr">573 </span> <span class="Delimiter">);</span> +<span id="L574" class="LineNr">574 </span><span class="Delimiter">}</span> +<span id="L575" class="LineNr">575 </span> +<span id="L576" class="LineNr">576 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L576'>test_check_duplicate_argument</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L577" class="LineNr">577 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L578" class="LineNr">578 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L579" class="LineNr">579 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L580" class="LineNr">580 </span> <span class="Constant">"89/copy 0/mod/indirect 0/rm32/EAX 1/r32/ECX 1/r32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L581" class="LineNr">581 </span> <span class="Delimiter">);</span> +<span id="L582" class="LineNr">582 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L583" class="LineNr">583 </span> <span class="Constant">"error: '89/copy 0/mod/indirect 0/rm32/EAX 1/r32/ECX 1/r32': duplicate r32 argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L584" class="LineNr">584 </span> <span class="Delimiter">);</span> +<span id="L585" class="LineNr">585 </span><span class="Delimiter">}</span> +<span id="L586" class="LineNr">586 </span> +<span id="L587" class="LineNr">587 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L587'>test_check_base_argument_not_needed_in_direct_mode</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L588" class="LineNr">588 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L589" class="LineNr">589 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L590" class="LineNr">590 </span> <span class="Constant">"81 0/add/subop 3/mod/indirect 4/rm32/use-sib 1/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L591" class="LineNr">591 </span> <span class="Delimiter">);</span> +<span id="L592" class="LineNr">592 </span> <a href='003trace.cc.html#L294'>CHECK_TRACE_COUNT</a><span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L593" class="LineNr">593 </span><span class="Delimiter">}</span> +<span id="L594" class="LineNr">594 </span> +<span id="L595" class="LineNr">595 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L595'>test_extra_modrm</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L596" class="LineNr">596 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L597" class="LineNr">597 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L598" class="LineNr">598 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L599" class="LineNr">599 </span> <span class="Constant">"59/pop-to-ECX 3/mod/direct 1/rm32/ECX 4/r32/ESP</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L600" class="LineNr">600 </span> <span class="Delimiter">);</span> +<span id="L601" class="LineNr">601 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L602" class="LineNr">602 </span> <span class="Constant">"error: '59/pop-to-ECX 3/mod/direct 1/rm32/ECX 4/r32/ESP' (<a href='013direct_addressing.cc.html#L1270'>pop</a> top of stack to <a href='010vm.cc.html#L11'>ECX</a>): unexpected modrm argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L603" class="LineNr">603 </span> <span class="Delimiter">);</span> +<span id="L604" class="LineNr">604 </span><span class="Delimiter">}</span> +<span id="L605" class="LineNr">605 </span> +<span id="L606" class="LineNr">606 </span><span class="Comment">//:: similarly handle multi-byte opcodes</span> +<span id="L607" class="LineNr">607 </span> +<span id="L608" class="LineNr">608 </span><span class="Normal">void</span> check_arguments_0f<span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L609" class="LineNr">609 </span> assert<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"0f"</span><span class="Delimiter">);</span> +<span id="L610" class="LineNr">610 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L611" class="LineNr">611 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"opcode '0f' requires a second opcode</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L612" class="LineNr">612 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L613" class="LineNr">613 </span> <span class="Delimiter">}</span> +<span id="L614" class="LineNr">614 </span> <a href='011run.cc.html#L127'>word</a> op = <a href='033check_operands.cc.html#L41'>preprocess_op</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">));</span> +<span id="L615" class="LineNr">615 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L616" class="LineNr">616 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"unknown 2-byte opcode '0f "</span> << op<span class="Delimiter">.</span>data << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L617" class="LineNr">617 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L618" class="LineNr">618 </span> <span class="Delimiter">}</span> +<span id="L619" class="LineNr">619 </span> check_arguments_0f<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L620" class="LineNr">620 </span><span class="Delimiter">}</span> +<span id="L621" class="LineNr">621 </span> +<span id="L622" class="LineNr">622 </span><span class="Normal">void</span> check_arguments_f3<span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L623" class="LineNr">623 </span> assert<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"f3"</span><span class="Delimiter">);</span> +<span id="L624" class="LineNr">624 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L625" class="LineNr">625 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"opcode 'f3' requires a second opcode</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L626" class="LineNr">626 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L627" class="LineNr">627 </span> <span class="Delimiter">}</span> +<span id="L628" class="LineNr">628 </span> <a href='011run.cc.html#L127'>word</a> op = <a href='033check_operands.cc.html#L41'>preprocess_op</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">));</span> +<span id="L629" class="LineNr">629 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>op<span class="Delimiter">.</span>data == <span class="Constant">"0f"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L630" class="LineNr">630 </span> <a href='011run.cc.html#L127'>word</a> op2 = <a href='033check_operands.cc.html#L41'>preprocess_op</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">));</span> +<span id="L631" class="LineNr">631 </span> <a href='033check_operands.cc.html#L739'>check_arguments_f3_0f</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op2<span class="Delimiter">);</span> +<span id="L632" class="LineNr">632 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L633" class="LineNr">633 </span> <span class="Delimiter">}</span> +<span id="L634" class="LineNr">634 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><a href='010vm.cc.html#L357'>Name_f3</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L635" class="LineNr">635 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"unknown 2-byte opcode 'f3 "</span> << op<span class="Delimiter">.</span>data << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L636" class="LineNr">636 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L637" class="LineNr">637 </span> <span class="Delimiter">}</span> +<span id="L638" class="LineNr">638 </span> check_arguments_f3<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L639" class="LineNr">639 </span><span class="Delimiter">}</span> +<span id="L640" class="LineNr">640 </span> +<span id="L641" class="LineNr">641 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L641'>test_check_missing_disp32_argument</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L642" class="LineNr">642 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L643" class="LineNr">643 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L644" class="LineNr">644 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L645" class="LineNr">645 </span> <span class="Constant">" 0f 84 # jmp if ZF to ??</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L646" class="LineNr">646 </span> <span class="Delimiter">);</span> +<span id="L647" class="LineNr">647 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L648" class="LineNr">648 </span> <span class="Constant">"error: '0f 84' (jump <a href='040tests.cc.html#L82'>disp32</a> bytes away if equal, if <a href='010vm.cc.html#L89'>ZF</a> is set): missing <a href='040tests.cc.html#L82'>disp32</a> argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L649" class="LineNr">649 </span> <span class="Delimiter">);</span> +<span id="L650" class="LineNr">650 </span><span class="Delimiter">}</span> +<span id="L651" class="LineNr">651 </span> +<span id="L652" class="LineNr">652 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L652'>test_0f_opcode_with_modrm</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L653" class="LineNr">653 </span> transform<span class="Delimiter">(</span> +<span id="L654" class="LineNr">654 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L655" class="LineNr">655 </span> <span class="Constant">"0f af/multiply 2/mod/*+disp32 5/rm32/ebp 8/disp32 0/r32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L656" class="LineNr">656 </span> <span class="Delimiter">);</span> +<span id="L657" class="LineNr">657 </span> <a href='003trace.cc.html#L304'>CHECK_TRACE_DOESNT_CONTAIN_ERRORS</a><span class="Delimiter">();</span> +<span id="L658" class="LineNr">658 </span><span class="Delimiter">}</span> +<span id="L659" class="LineNr">659 </span> +<span id="L660" class="LineNr">660 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L661" class="LineNr">661 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">bitvector</span><span class="Comment">*/</span><span class="Normal">uint8_t</span>> <a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">;</span> +<span id="L662" class="LineNr">662 </span><span class="Delimiter">:(before "End Init Permitted Operands")</span> +<span id="L663" class="LineNr">663 </span><span class="SalientComment">//// Class D: just op and disp32</span> +<span id="L664" class="LineNr">664 </span><span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L665" class="LineNr">665 </span><span class="Comment">// 0 0 1 |0 0 0 0</span> +<span id="L666" class="LineNr">666 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"82"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L667" class="LineNr">667 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"83"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L668" class="LineNr">668 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"84"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L669" class="LineNr">669 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"85"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L670" class="LineNr">670 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"86"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L671" class="LineNr">671 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"87"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L672" class="LineNr">672 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"8c"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L673" class="LineNr">673 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"8d"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L674" class="LineNr">674 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"8e"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L675" class="LineNr">675 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"8f"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L676" class="LineNr">676 </span> +<span id="L677" class="LineNr">677 </span><span class="SalientComment">//// Class M: using ModR/M byte</span> +<span id="L678" class="LineNr">678 </span><span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L679" class="LineNr">679 </span><span class="Comment">// 0 0 0 |0 0 0 1</span> +<span id="L680" class="LineNr">680 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"2f"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// compare floats</span> +<span id="L681" class="LineNr">681 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"af"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// multiply ints</span> +<span id="L682" class="LineNr">682 </span><span class="Comment">// setcc</span> +<span id="L683" class="LineNr">683 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"92"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L684" class="LineNr">684 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"93"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L685" class="LineNr">685 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"94"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L686" class="LineNr">686 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"95"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L687" class="LineNr">687 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"96"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L688" class="LineNr">688 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"97"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L689" class="LineNr">689 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"9c"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L690" class="LineNr">690 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"9d"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L691" class="LineNr">691 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"9e"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L692" class="LineNr">692 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> <span class="Constant">"9f"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L693" class="LineNr">693 </span> +<span id="L694" class="LineNr">694 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L695" class="LineNr">695 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">bitvector</span><span class="Comment">*/</span><span class="Normal">uint8_t</span>> <a href='033check_operands.cc.html#L695'>Permitted_arguments_f3</a><span class="Delimiter">;</span> +<span id="L696" class="LineNr">696 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">bitvector</span><span class="Comment">*/</span><span class="Normal">uint8_t</span>> <a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">;</span> +<span id="L697" class="LineNr">697 </span><span class="Delimiter">:(before "End Init Permitted Operands")</span> +<span id="L698" class="LineNr">698 </span><span class="SalientComment">//// Class M: using ModR/M byte</span> +<span id="L699" class="LineNr">699 </span><span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L700" class="LineNr">700 </span><span class="Comment">// 0 0 0 |0 0 0 1</span> +<span id="L701" class="LineNr">701 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"10"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// copy xm32 to x32</span> +<span id="L702" class="LineNr">702 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"11"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// copy x32 to xm32</span> +<span id="L703" class="LineNr">703 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"2a"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// convert-to-float</span> +<span id="L704" class="LineNr">704 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"2c"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// truncate-to-int</span> +<span id="L705" class="LineNr">705 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"2d"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// convert-to-int</span> +<span id="L706" class="LineNr">706 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"51"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// square root</span> +<span id="L707" class="LineNr">707 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"52"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// inverse square root</span> +<span id="L708" class="LineNr">708 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"53"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// reciprocal</span> +<span id="L709" class="LineNr">709 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"58"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// add floats</span> +<span id="L710" class="LineNr">710 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"59"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// multiply floats</span> +<span id="L711" class="LineNr">711 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"5c"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// subtract floats</span> +<span id="L712" class="LineNr">712 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"5d"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// minimum of floats</span> +<span id="L713" class="LineNr">713 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"5e"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// divide floats</span> +<span id="L714" class="LineNr">714 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> <span class="Constant">"5f"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Comment">// maximum of floats</span> +<span id="L715" class="LineNr">715 </span> +<span id="L716" class="LineNr">716 </span><span class="Delimiter">:(code)</span> +<span id="L717" class="LineNr">717 </span><span class="Normal">void</span> check_arguments_0f<span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L718" class="LineNr">718 </span> <span class="Normal">uint8_t</span> expected_bitvector = get<span class="Delimiter">(</span><a href='033check_operands.cc.html#L661'>Permitted_arguments_0f</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L719" class="LineNr">719 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>HAS<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L69'>MODRM</a><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L720" class="LineNr">720 </span> <a href='033check_operands.cc.html#L377'>check_arguments_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L721" class="LineNr">721 </span> <a href='033check_operands.cc.html#L412'>compare_bitvector_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> expected_bitvector<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L750'>maybe_name_0f</a><span class="Delimiter">(</span>op<span class="Delimiter">));</span> +<span id="L722" class="LineNr">722 </span> <span class="Delimiter">}</span> +<span id="L723" class="LineNr">723 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L724" class="LineNr">724 </span> <a href='033check_operands.cc.html#L275'>compare_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> CLEAR<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L69'>MODRM</a><span class="Delimiter">),</span> <a href='033check_operands.cc.html#L750'>maybe_name_0f</a><span class="Delimiter">(</span>op<span class="Delimiter">));</span> +<span id="L725" class="LineNr">725 </span> <span class="Delimiter">}</span> +<span id="L726" class="LineNr">726 </span><span class="Delimiter">}</span> +<span id="L727" class="LineNr">727 </span> +<span id="L728" class="LineNr">728 </span><span class="Normal">void</span> check_arguments_f3<span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L729" class="LineNr">729 </span> <span class="Normal">uint8_t</span> expected_bitvector = get<span class="Delimiter">(</span><a href='033check_operands.cc.html#L695'>Permitted_arguments_f3</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L730" class="LineNr">730 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>HAS<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L69'>MODRM</a><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L731" class="LineNr">731 </span> <a href='033check_operands.cc.html#L377'>check_arguments_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L732" class="LineNr">732 </span> <a href='033check_operands.cc.html#L412'>compare_bitvector_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> expected_bitvector<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L758'>maybe_name_f3</a><span class="Delimiter">(</span>op<span class="Delimiter">));</span> +<span id="L733" class="LineNr">733 </span> <span class="Delimiter">}</span> +<span id="L734" class="LineNr">734 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L735" class="LineNr">735 </span> <a href='033check_operands.cc.html#L275'>compare_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> CLEAR<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L69'>MODRM</a><span class="Delimiter">),</span> <a href='033check_operands.cc.html#L758'>maybe_name_f3</a><span class="Delimiter">(</span>op<span class="Delimiter">));</span> +<span id="L736" class="LineNr">736 </span> <span class="Delimiter">}</span> +<span id="L737" class="LineNr">737 </span><span class="Delimiter">}</span> +<span id="L738" class="LineNr">738 </span> +<span id="L739" class="LineNr">739 </span><span class="Normal">void</span> <a href='033check_operands.cc.html#L739'>check_arguments_f3_0f</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L740" class="LineNr">740 </span> <span class="Normal">uint8_t</span> expected_bitvector = get<span class="Delimiter">(</span><a href='033check_operands.cc.html#L696'>Permitted_arguments_f3_0f</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L741" class="LineNr">741 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>HAS<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L69'>MODRM</a><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L742" class="LineNr">742 </span> <a href='033check_operands.cc.html#L377'>check_arguments_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L743" class="LineNr">743 </span> <a href='033check_operands.cc.html#L412'>compare_bitvector_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> expected_bitvector<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L766'>maybe_name_f3_0f</a><span class="Delimiter">(</span>op<span class="Delimiter">));</span> +<span id="L744" class="LineNr">744 </span> <span class="Delimiter">}</span> +<span id="L745" class="LineNr">745 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L746" class="LineNr">746 </span> <a href='033check_operands.cc.html#L275'>compare_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> CLEAR<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='033check_operands.cc.html#L69'>MODRM</a><span class="Delimiter">),</span> <a href='033check_operands.cc.html#L766'>maybe_name_f3_0f</a><span class="Delimiter">(</span>op<span class="Delimiter">));</span> +<span id="L747" class="LineNr">747 </span> <span class="Delimiter">}</span> +<span id="L748" class="LineNr">748 </span><span class="Delimiter">}</span> +<span id="L749" class="LineNr">749 </span> +<span id="L750" class="LineNr">750 </span>string <a href='033check_operands.cc.html#L750'>maybe_name_0f</a><span class="Delimiter">(</span><span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L751" class="LineNr">751 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_hex_byte<span class="Delimiter">(</span>op<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L752" class="LineNr">752 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L753" class="LineNr">753 </span> <span class="Comment">// strip stuff in parens from the name</span> +<span id="L754" class="LineNr">754 </span> <span class="Normal">const</span> string& s = get<span class="Delimiter">(</span><a href='010vm.cc.html#L356'>Name_0f</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L755" class="LineNr">755 </span> <span class="Identifier">return</span> <span class="Constant">" ("</span>+s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">" ("</span><span class="Delimiter">))</span>+<span class="Constant">')'</span><span class="Delimiter">;</span> +<span id="L756" class="LineNr">756 </span><span class="Delimiter">}</span> +<span id="L757" class="LineNr">757 </span> +<span id="L758" class="LineNr">758 </span>string <a href='033check_operands.cc.html#L758'>maybe_name_f3</a><span class="Delimiter">(</span><span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L759" class="LineNr">759 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_hex_byte<span class="Delimiter">(</span>op<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L760" class="LineNr">760 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><a href='010vm.cc.html#L357'>Name_f3</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L761" class="LineNr">761 </span> <span class="Comment">// strip stuff in parens from the name</span> +<span id="L762" class="LineNr">762 </span> <span class="Normal">const</span> string& s = get<span class="Delimiter">(</span><a href='010vm.cc.html#L357'>Name_f3</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L763" class="LineNr">763 </span> <span class="Identifier">return</span> <span class="Constant">" ("</span>+s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">" ("</span><span class="Delimiter">))</span>+<span class="Constant">')'</span><span class="Delimiter">;</span> +<span id="L764" class="LineNr">764 </span><span class="Delimiter">}</span> +<span id="L765" class="LineNr">765 </span> +<span id="L766" class="LineNr">766 </span>string <a href='033check_operands.cc.html#L766'>maybe_name_f3_0f</a><span class="Delimiter">(</span><span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L767" class="LineNr">767 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_hex_byte<span class="Delimiter">(</span>op<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L768" class="LineNr">768 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L769" class="LineNr">769 </span> <span class="Comment">// strip stuff in parens from the name</span> +<span id="L770" class="LineNr">770 </span> <span class="Normal">const</span> string& s = get<span class="Delimiter">(</span><a href='010vm.cc.html#L358'>Name_f3_0f</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L771" class="LineNr">771 </span> <span class="Identifier">return</span> <span class="Constant">" ("</span>+s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">" ("</span><span class="Delimiter">))</span>+<span class="Constant">')'</span><span class="Delimiter">;</span> +<span id="L772" class="LineNr">772 </span><span class="Delimiter">}</span> +<span id="L773" class="LineNr">773 </span> +<span id="L774" class="LineNr">774 </span>string <a href='033check_operands.cc.html#L774'>tolower</a><span class="Delimiter">(</span><span class="Normal">const</span> <span class="Normal">char</span>* s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L775" class="LineNr">775 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L776" class="LineNr">776 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">nada</span><span class="Comment">*/</span><span class="Delimiter">;</span> *s<span class="Delimiter">;</span> ++s<span class="Delimiter">)</span> +<span id="L777" class="LineNr">777 </span> out << <span class="Normal">static_cast</span><<span class="Normal">char</span>><span class="Delimiter">(</span><a href='033check_operands.cc.html#L774'>tolower</a><span class="Delimiter">(</span>*s<span class="Delimiter">));</span> +<span id="L778" class="LineNr">778 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L779" class="LineNr">779 </span><span class="Delimiter">}</span> +<span id="L780" class="LineNr">780 </span> +<span id="L781" class="LineNr">781 </span><span class="PreProc">#undef HAS</span> +<span id="L782" class="LineNr">782 </span><span class="PreProc">#undef SET</span> +<span id="L783" class="LineNr">783 </span><span class="PreProc">#undef CLEAR</span> +<span id="L784" class="LineNr">784 </span> +<span id="L785" class="LineNr">785 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L786" class="LineNr">786 </span><span class="PreProc">#include</span><span class="Constant"><cctype></span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/034check_operand_bounds.cc.html b/html/linux/bootstrap/034check_operand_bounds.cc.html new file mode 100644 index 00000000..11670f19 --- /dev/null +++ b/html/linux/bootstrap/034check_operand_bounds.cc.html @@ -0,0 +1,205 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/034check_operand_bounds.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.Delimiter { color: #c000c0; } +.Comment { color: #005faf; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/034check_operand_bounds.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/034check_operand_bounds.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//:: Check that the different arguments of an instruction aren't too large for their bitfields.</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span><span class="Normal">void</span> <a href='034check_operand_bounds.cc.html#L3'>test_check_bitfield_sizes</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L4" class="LineNr"> 4 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L5" class="LineNr"> 5 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L6" class="LineNr"> 6 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L7" class="LineNr"> 7 </span> <span class="Constant">"01/add 4/mod 3/rm32 1/r32</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add ECX to EBX</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Delimiter">);</span> +<span id="L9" class="LineNr"> 9 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L10" class="LineNr"> 10 </span> <span class="Constant">"error: '4/mod' too large to fit in bitfield mod</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Delimiter">);</span> +<span id="L12" class="LineNr"> 12 </span><span class="Delimiter">}</span> +<span id="L13" class="LineNr"> 13 </span> +<span id="L14" class="LineNr"> 14 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L15" class="LineNr"> 15 </span>map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>> <a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">;</span> +<span id="L16" class="LineNr"> 16 </span><span class="Delimiter">:(before "End One-time Setup")</span> +<span id="L17" class="LineNr"> 17 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"subop"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L18" class="LineNr"> 18 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L19" class="LineNr"> 19 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L20" class="LineNr"> 20 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L21" class="LineNr"> 21 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L22" class="LineNr"> 22 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"scale"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L23" class="LineNr"> 23 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"r32"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L24" class="LineNr"> 24 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"disp8"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">8</span><span class="Delimiter">);</span> +<span id="L25" class="LineNr"> 25 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">16</span><span class="Delimiter">);</span> +<span id="L26" class="LineNr"> 26 </span><span class="Comment">// no bound needed for disp32</span> +<span id="L27" class="LineNr"> 27 </span><a href='001help.cc.html#L237'>put_new</a><span class="Delimiter">(</span><a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"imm8"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">8</span><span class="Delimiter">);</span> +<span id="L28" class="LineNr"> 28 </span><span class="Comment">// no bound needed for imm32</span> +<span id="L29" class="LineNr"> 29 </span> +<span id="L30" class="LineNr"> 30 </span><span class="Delimiter">:(before "Pack Operands(segment code)")</span> +<span id="L31" class="LineNr"> 31 </span>check_argument_bounds<span class="Delimiter">(</span>code<span class="Delimiter">);</span> +<span id="L32" class="LineNr"> 32 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L33" class="LineNr"> 33 </span><span class="Delimiter">:(code)</span> +<span id="L34" class="LineNr"> 34 </span><span class="Normal">void</span> check_argument_bounds<span class="Delimiter">(</span><span class="Normal">const</span> segment& code<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L35" class="LineNr"> 35 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"-- check argument bounds"</span> << end<span class="Delimiter">();</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Normal">const</span> line& inst = code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L38" class="LineNr"> 38 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <a href='033check_operands.cc.html#L315'>first_argument</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> +<span id="L39" class="LineNr"> 39 </span> check_argument_bounds<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">));</span> +<span id="L40" class="LineNr"> 40 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// stop at the first mal-formed instruction</span> +<span id="L41" class="LineNr"> 41 </span> <span class="Delimiter">}</span> +<span id="L42" class="LineNr"> 42 </span><span class="Delimiter">}</span> +<span id="L43" class="LineNr"> 43 </span> +<span id="L44" class="LineNr"> 44 </span><span class="Normal">void</span> check_argument_bounds<span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>>::iterator p = <a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='034check_operand_bounds.cc.html#L15'>Operand_bound</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_argument_metadata<span class="Delimiter">(</span>w<span class="Delimiter">,</span> p<span class="Delimiter">-></span>first<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!looks_like_hex_int<span class="Delimiter">(</span>w<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// later transforms are on their own to do their own bounds checking</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Normal">int32_t</span> x = <a href='032operands.cc.html#L608'>parse_int</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>x >= <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">-></span>first == <span class="Constant">"disp8"</span> || p<span class="Delimiter">-></span>first == <span class="Constant">"disp16"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>x<span class="Delimiter">)</span> >= p<span class="Delimiter">-></span>second/<span class="Constant">2</span><span class="Delimiter">)</span> +<span id="L52" class="LineNr"> 52 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << w<span class="Delimiter">.</span>original << <span class="Constant">"' too large to fit in signed bitfield "</span> << p<span class="Delimiter">-></span>first << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Delimiter">}</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L55" class="LineNr"> 55 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>x<span class="Delimiter">)</span> >= p<span class="Delimiter">-></span>second<span class="Delimiter">)</span> +<span id="L56" class="LineNr"> 56 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << w<span class="Delimiter">.</span>original << <span class="Constant">"' too large to fit in bitfield "</span> << p<span class="Delimiter">-></span>first << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Delimiter">}</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Delimiter">}</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Comment">// hacky? assuming bound is a power of 2</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>x < -<span class="Constant">1</span>*<span class="Normal">static_cast</span><<span class="Normal">int32_t</span>><span class="Delimiter">(</span>p<span class="Delimiter">-></span>second/<span class="Constant">2</span><span class="Delimiter">))</span> +<span id="L62" class="LineNr"> 62 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << w<span class="Delimiter">.</span>original << <span class="Constant">"' too large to fit in bitfield "</span> << p<span class="Delimiter">-></span>first << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Delimiter">}</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Delimiter">}</span> +<span id="L65" class="LineNr"> 65 </span><span class="Delimiter">}</span> +<span id="L66" class="LineNr"> 66 </span> +<span id="L67" class="LineNr"> 67 </span><span class="Normal">void</span> <a href='034check_operand_bounds.cc.html#L67'>test_check_bitfield_sizes_for_imm8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L68" class="LineNr"> 68 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Constant">"c1/shift 4/subop/left 3/mod/direct 1/rm32/ECX 0xff/imm8"</span> <span class="Comment">// shift EBX left</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Delimiter">);</span> +<span id="L72" class="LineNr"> 72 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!trace_contains_errors<span class="Delimiter">());</span> +<span id="L73" class="LineNr"> 73 </span><span class="Delimiter">}</span> +<span id="L74" class="LineNr"> 74 </span> +<span id="L75" class="LineNr"> 75 </span><span class="Normal">void</span> <a href='034check_operand_bounds.cc.html#L75'>test_check_bitfield_sizes_for_imm8_error</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L76" class="LineNr"> 76 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L77" class="LineNr"> 77 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Constant">"c1/shift 4/subop/left 3/mod/direct 1/rm32/ECX 0x100/imm8"</span> <span class="Comment">// shift EBX left</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Delimiter">);</span> +<span id="L81" class="LineNr"> 81 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Constant">"error: '0x100/imm8' too large to fit in bitfield imm8</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Delimiter">);</span> +<span id="L84" class="LineNr"> 84 </span><span class="Delimiter">}</span> +<span id="L85" class="LineNr"> 85 </span> +<span id="L86" class="LineNr"> 86 </span><span class="Normal">void</span> <a href='034check_operand_bounds.cc.html#L86'>test_check_bitfield_sizes_for_negative_imm8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L87" class="LineNr"> 87 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Constant">"c1/shift 4/subop/left 3/mod/direct 1/rm32/ECX -0x80/imm8"</span> <span class="Comment">// shift EBX left</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Delimiter">);</span> +<span id="L91" class="LineNr"> 91 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!trace_contains_errors<span class="Delimiter">());</span> +<span id="L92" class="LineNr"> 92 </span><span class="Delimiter">}</span> +<span id="L93" class="LineNr"> 93 </span> +<span id="L94" class="LineNr"> 94 </span><span class="Normal">void</span> <a href='034check_operand_bounds.cc.html#L94'>test_check_bitfield_sizes_for_negative_imm8_error</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L95" class="LineNr"> 95 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L96" class="LineNr"> 96 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Constant">"c1/shift 4/subop/left 3/mod/direct 1/rm32/ECX -0x81/imm8"</span> <span class="Comment">// shift EBX left</span> +<span id="L99" class="LineNr"> 99 </span> <span class="Delimiter">);</span> +<span id="L100" class="LineNr">100 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L101" class="LineNr">101 </span> <span class="Constant">"error: '-0x81/imm8' too large to fit in bitfield imm8</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L102" class="LineNr">102 </span> <span class="Delimiter">);</span> +<span id="L103" class="LineNr">103 </span><span class="Delimiter">}</span> +<span id="L104" class="LineNr">104 </span> +<span id="L105" class="LineNr">105 </span><span class="Normal">void</span> <a href='034check_operand_bounds.cc.html#L105'>test_check_bitfield_sizes_for_disp8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L106" class="LineNr">106 </span> <span class="Comment">// not bothering to run</span> +<span id="L107" class="LineNr">107 </span> transform<span class="Delimiter">(</span> +<span id="L108" class="LineNr">108 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L109" class="LineNr">109 </span> <span class="Constant">"01/add 1/mod/*+disp8 3/rm32 1/r32 0x7f/disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add ECX to *(EBX+0x7f)</span> +<span id="L110" class="LineNr">110 </span> <span class="Delimiter">);</span> +<span id="L111" class="LineNr">111 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!trace_contains_errors<span class="Delimiter">());</span> +<span id="L112" class="LineNr">112 </span><span class="Delimiter">}</span> +<span id="L113" class="LineNr">113 </span> +<span id="L114" class="LineNr">114 </span><span class="Normal">void</span> <a href='034check_operand_bounds.cc.html#L114'>test_check_bitfield_sizes_for_disp8_error</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L115" class="LineNr">115 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L116" class="LineNr">116 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L117" class="LineNr">117 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L118" class="LineNr">118 </span> <span class="Constant">"01/add 1/mod/*+disp8 3/rm32 1/r32 0x80/disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add ECX to *(EBX+0x80)</span> +<span id="L119" class="LineNr">119 </span> <span class="Delimiter">);</span> +<span id="L120" class="LineNr">120 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L121" class="LineNr">121 </span> <span class="Constant">"error: '0x80/disp8' too large to fit in signed bitfield disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L122" class="LineNr">122 </span> <span class="Delimiter">);</span> +<span id="L123" class="LineNr">123 </span><span class="Delimiter">}</span> +<span id="L124" class="LineNr">124 </span> +<span id="L125" class="LineNr">125 </span><span class="Normal">void</span> <a href='034check_operand_bounds.cc.html#L125'>test_check_bitfield_sizes_for_negative_disp8</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L126" class="LineNr">126 </span> <span class="Comment">// not bothering to run</span> +<span id="L127" class="LineNr">127 </span> transform<span class="Delimiter">(</span> +<span id="L128" class="LineNr">128 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L129" class="LineNr">129 </span> <span class="Constant">"01/add 1/mod/*+disp8 3/rm32 1/r32 -0x80/disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add ECX to *(EBX-0x80)</span> +<span id="L130" class="LineNr">130 </span> <span class="Delimiter">);</span> +<span id="L131" class="LineNr">131 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!trace_contains_errors<span class="Delimiter">());</span> +<span id="L132" class="LineNr">132 </span><span class="Delimiter">}</span> +<span id="L133" class="LineNr">133 </span> +<span id="L134" class="LineNr">134 </span><span class="Normal">void</span> <a href='034check_operand_bounds.cc.html#L134'>test_check_bitfield_sizes_for_negative_disp8_error</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L135" class="LineNr">135 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L136" class="LineNr">136 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L137" class="LineNr">137 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L138" class="LineNr">138 </span> <span class="Constant">"01/add 1/mod/*+disp8 3/rm32 1/r32 -0x81/disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// add ECX to *(EBX-0x81)</span> +<span id="L139" class="LineNr">139 </span> <span class="Delimiter">);</span> +<span id="L140" class="LineNr">140 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L141" class="LineNr">141 </span> <span class="Constant">"error: '-0x81/disp8' too large to fit in bitfield disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L142" class="LineNr">142 </span> <span class="Delimiter">);</span> +<span id="L143" class="LineNr">143 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/035compute_segment_address.cc.html b/html/linux/bootstrap/035compute_segment_address.cc.html new file mode 100644 index 00000000..a71afcf6 --- /dev/null +++ b/html/linux/bootstrap/035compute_segment_address.cc.html @@ -0,0 +1,148 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/035compute_segment_address.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.Delimiter { color: #c000c0; } +.Comment { color: #005faf; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/035compute_segment_address.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/035compute_segment_address.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: ELF binaries have finicky rules about the precise alignment each segment</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: should start at. They depend on the amount of code in a program.</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: We shouldn't expect people to adjust segment addresses everytime they make</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: a change to their programs.</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: Let's start taking the given segment addresses as guidelines, and adjust</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment">//: them as necessary.</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment">//: This gives up a measure of control in placing code and data.</span> +<span id="L8" class="LineNr"> 8 </span> +<span id="L9" class="LineNr"> 9 </span><span class="Normal">void</span> <a href='035compute_segment_address.cc.html#L9'>test_segment_name</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L10" class="LineNr">10 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L11" class="LineNr">11 </span> <span class="Constant">"== code 0x09000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L12" class="LineNr">12 </span> <span class="Constant">"05/add-to-EAX 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L13" class="LineNr">13 </span> <span class="Comment">// code starts at 0x09000000 + p_offset, which is 0x54 for a single-segment binary</span> +<span id="L14" class="LineNr">14 </span> <span class="Delimiter">);</span> +<span id="L15" class="LineNr">15 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L16" class="LineNr">16 </span> <span class="Constant">"load: 0x09000054 -> 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L17" class="LineNr">17 </span> <span class="Constant">"load: 0x09000055 -> 0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L18" class="LineNr">18 </span> <span class="Constant">"load: 0x09000056 -> 0b</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L19" class="LineNr">19 </span> <span class="Constant">"load: 0x09000057 -> 0c</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L20" class="LineNr">20 </span> <span class="Constant">"load: 0x09000058 -> 0d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L21" class="LineNr">21 </span> <span class="Constant">"run: add imm32 0x0d0c0b0a to <a href='010vm.cc.html#L10'>EAX</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L22" class="LineNr">22 </span> <span class="Constant">"run: storing 0x0d0c0b0a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L23" class="LineNr">23 </span> <span class="Delimiter">);</span> +<span id="L24" class="LineNr">24 </span><span class="Delimiter">}</span> +<span id="L25" class="LineNr">25 </span> +<span id="L26" class="LineNr">26 </span><span class="Comment">//: compute segment address</span> +<span id="L27" class="LineNr">27 </span> +<span id="L28" class="LineNr">28 </span><span class="Delimiter">:(before "End Transforms")</span> +<span id="L29" class="LineNr">29 </span><a href='031transforms.cc.html#L4'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='035compute_segment_address.cc.html#L32'>compute_segment_starts</a><span class="Delimiter">);</span> +<span id="L30" class="LineNr">30 </span> +<span id="L31" class="LineNr">31 </span><span class="Delimiter">:(code)</span> +<span id="L32" class="LineNr">32 </span><span class="Normal">void</span> <a href='035compute_segment_address.cc.html#L32'>compute_segment_starts</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L33" class="LineNr">33 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"-- compute segment addresses"</span> << end<span class="Delimiter">();</span> +<span id="L34" class="LineNr">34 </span> <span class="Normal">uint32_t</span> p_offset = <span class="Comment">/*</span><span class="Comment">size of ehdr</span><span class="Comment">*/</span><span class="Constant">0x34</span> + <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">)</span>*<span class="Constant">0x20</span><span class="Comment">/*</span><span class="Comment">size of each phdr</span><span class="Comment">*/</span><span class="Delimiter">;</span> +<span id="L35" class="LineNr">35 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L36" class="LineNr">36 </span> segment& curr = p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L37" class="LineNr">37 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start >= <span class="Constant">0x08000000</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L38" class="LineNr">38 </span> <span class="Comment">// valid address for user space, so assume we're creating a real ELF binary, not just running a test</span> +<span id="L39" class="LineNr">39 </span> curr<span class="Delimiter">.</span>start &= <span class="Constant">0xfffff000</span><span class="Delimiter">;</span> <span class="Comment">// same number of zeros as the p_align used when emitting the ELF binary</span> +<span id="L40" class="LineNr">40 </span> curr<span class="Delimiter">.</span>start |= <span class="Delimiter">(</span>p_offset & <span class="Constant">0xfff</span><span class="Delimiter">);</span> +<span id="L41" class="LineNr">41 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"segment "</span> << i << <span class="Constant">" begins at address 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << curr<span class="Delimiter">.</span>start << end<span class="Delimiter">();</span> +<span id="L42" class="LineNr">42 </span> <span class="Delimiter">}</span> +<span id="L43" class="LineNr">43 </span> p_offset += size_of<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L44" class="LineNr">44 </span> assert<span class="Delimiter">(</span>p_offset < <a href='010vm.cc.html#L98'>SEGMENT_ALIGNMENT</a><span class="Delimiter">);</span> <span class="Comment">// for now we get less and less available space in each successive segment</span> +<span id="L45" class="LineNr">45 </span> <span class="Delimiter">}</span> +<span id="L46" class="LineNr">46 </span><span class="Delimiter">}</span> +<span id="L47" class="LineNr">47 </span> +<span id="L48" class="LineNr">48 </span><span class="Normal">uint32_t</span> size_of<span class="Delimiter">(</span><span class="Normal">const</span> segment& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L49" class="LineNr">49 </span> <span class="Normal">uint32_t</span> sum = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L50" class="LineNr">50 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L51" class="LineNr">51 </span> sum += <a href='035compute_segment_address.cc.html#L56'>num_bytes</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> +<span id="L52" class="LineNr">52 </span> <span class="Identifier">return</span> sum<span class="Delimiter">;</span> +<span id="L53" class="LineNr">53 </span><span class="Delimiter">}</span> +<span id="L54" class="LineNr">54 </span> +<span id="L55" class="LineNr">55 </span><span class="Comment">// Assumes all bitfields are packed.</span> +<span id="L56" class="LineNr">56 </span><span class="Normal">uint32_t</span> <a href='035compute_segment_address.cc.html#L56'>num_bytes</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L57" class="LineNr">57 </span> <span class="Normal">uint32_t</span> sum = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L58" class="LineNr">58 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L59" class="LineNr">59 </span> sum += size_of<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> +<span id="L60" class="LineNr">60 </span> <span class="Identifier">return</span> sum<span class="Delimiter">;</span> +<span id="L61" class="LineNr">61 </span><span class="Delimiter">}</span> +<span id="L62" class="LineNr">62 </span> +<span id="L63" class="LineNr">63 </span><span class="Normal">int</span> size_of<span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L64" class="LineNr">64 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>w<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">)</span> || has_argument_metadata<span class="Delimiter">(</span>w<span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">))</span> +<span id="L65" class="LineNr">65 </span> <span class="Identifier">return</span> <span class="Constant">4</span><span class="Delimiter">;</span> +<span id="L66" class="LineNr">66 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>w<span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">))</span> +<span id="L67" class="LineNr">67 </span> <span class="Identifier">return</span> <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L68" class="LineNr">68 </span> <span class="Comment">// End size_of(word w) Special-cases</span> +<span id="L69" class="LineNr">69 </span> <span class="Normal">else</span> +<span id="L70" class="LineNr">70 </span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L71" class="LineNr">71 </span><span class="Delimiter">}</span> +<span id="L72" class="LineNr">72 </span> +<span id="L73" class="LineNr">73 </span><span class="Comment">//: Dependencies:</span> +<span id="L74" class="LineNr">74 </span><span class="Comment">//: - We'd like to compute segment addresses before setting up global variables,</span> +<span id="L75" class="LineNr">75 </span><span class="Comment">//: because computing addresses for global variables requires knowing where</span> +<span id="L76" class="LineNr">76 </span><span class="Comment">//: the data segment starts.</span> +<span id="L77" class="LineNr">77 </span><span class="Comment">//: - We'd like to finish expanding labels before computing segment addresses,</span> +<span id="L78" class="LineNr">78 </span><span class="Comment">//: because it would make computing the sizes of segments more self-contained</span> +<span id="L79" class="LineNr">79 </span><span class="Comment">//: (num_bytes).</span> +<span id="L80" class="LineNr">80 </span><span class="Comment">//:</span> +<span id="L81" class="LineNr">81 </span><span class="Comment">//: Decision: compute segment addresses before expanding labels, by being</span> +<span id="L82" class="LineNr">82 </span><span class="Comment">//: aware in this layer of certain argument types that will eventually occupy</span> +<span id="L83" class="LineNr">83 </span><span class="Comment">//: multiple bytes.</span> +<span id="L84" class="LineNr">84 </span><span class="Comment">//:</span> +<span id="L85" class="LineNr">85 </span><span class="Comment">//: The layer to expand labels later hooks into num_bytes() to teach this</span> +<span id="L86" class="LineNr">86 </span><span class="Comment">//: layer that labels occupy zero space in the binary.</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/036labels.cc.html b/html/linux/bootstrap/036labels.cc.html new file mode 100644 index 00000000..2068cf7c --- /dev/null +++ b/html/linux/bootstrap/036labels.cc.html @@ -0,0 +1,491 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/036labels.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.Delimiter { color: #c000c0; } +.Comment { color: #005faf; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/036labels.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/036labels.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: Labels are defined by ending names with a ':'. This layer will compute</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: displacements for labels, and compute the offset for instructions using them.</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//:</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: We won't check this, but our convention will be that jump targets will</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: start with a '$', while functions will not. Function names will never be</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment">//: jumped to, and jump targets will never be called.</span> +<span id="L7" class="LineNr"> 7 </span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment">//: We're introducing non-number names for the first time, so it's worth</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment">//: laying down some ground rules all transforms will follow, so things don't</span> +<span id="L10" class="LineNr"> 10 </span><span class="Comment">//: get too confusing:</span> +<span id="L11" class="LineNr"> 11 </span><span class="Comment">//: - if it starts with a digit, it's treated as a number. If it can't be</span> +<span id="L12" class="LineNr"> 12 </span><span class="Comment">//: parsed as hex it will raise an error.</span> +<span id="L13" class="LineNr"> 13 </span><span class="Comment">//: - if it starts with '-' it's treated as a number.</span> +<span id="L14" class="LineNr"> 14 </span><span class="Comment">//: - if it starts with '0x' it's treated as a number.</span> +<span id="L15" class="LineNr"> 15 </span><span class="Comment">//: - if it's two characters long, it can't be a name. Either it's a hex</span> +<span id="L16" class="LineNr"> 16 </span><span class="Comment">//: byte, or it raises an error.</span> +<span id="L17" class="LineNr"> 17 </span><span class="Comment">//: That's it. Names can start with any non-digit that isn't a dash. They can</span> +<span id="L18" class="LineNr"> 18 </span><span class="Comment">//: be a single character long. 'a' is not a hex number, it's a variable.</span> +<span id="L19" class="LineNr"> 19 </span><span class="Comment">//: Later layers may add more conventions partitioning the space of names. But</span> +<span id="L20" class="LineNr"> 20 </span><span class="Comment">//: the above rules will remain inviolate.</span> +<span id="L21" class="LineNr"> 21 </span> +<span id="L22" class="LineNr"> 22 </span><span class="Comment">//: One special label is 'Entry', the address to start running the program at.</span> +<span id="L23" class="LineNr"> 23 </span><span class="Comment">//: It can be non-unique; the last declaration overrides earlier ones.</span> +<span id="L24" class="LineNr"> 24 </span><span class="Comment">//: It must exist in a program. Otherwise we don't know where to start running</span> +<span id="L25" class="LineNr"> 25 </span><span class="Comment">//: programs.</span> +<span id="L26" class="LineNr"> 26 </span> +<span id="L27" class="LineNr"> 27 </span><span class="Normal">void</span> <a href='036labels.cc.html#L27'>test_Entry_label</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L28" class="LineNr"> 28 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Constant">"05 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L31" class="LineNr"> 31 </span> <span class="Constant">"Entry:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Constant">"05 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Delimiter">);</span> +<span id="L34" class="LineNr"> 34 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L35" class="LineNr"> 35 </span> <span class="Constant">"run: 0x00000006 opcode: 05</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Delimiter">);</span> +<span id="L37" class="LineNr"> 37 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"run: 0x00000001 opcode: 05"</span><span class="Delimiter">);</span> +<span id="L38" class="LineNr"> 38 </span><span class="Delimiter">}</span> +<span id="L39" class="LineNr"> 39 </span> +<span id="L40" class="LineNr"> 40 </span><span class="Delimiter">:(before "End <a href='032operands.cc.html#L591'>looks_like_hex_int</a>(s) Detectors")</span> +<span id="L41" class="LineNr"> 41 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">)</span> == <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L42" class="LineNr"> 42 </span> +<span id="L43" class="LineNr"> 43 </span><span class="Delimiter">:(code)</span> +<span id="L44" class="LineNr"> 44 </span><span class="Normal">void</span> <a href='036labels.cc.html#L44'>test_pack_immediate_ignores_single_byte_nondigit_argument</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L45" class="LineNr"> 45 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L46" class="LineNr"> 46 </span> transform<span class="Delimiter">(</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Constant">"b9/copy a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Delimiter">);</span> +<span id="L50" class="LineNr"> 50 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Constant">"transform: packing instruction 'b9/copy a/imm32'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Comment">// no change (we're just not printing metadata to the trace)</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Constant">"transform: instruction after packing: 'b9 a'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Delimiter">);</span> +<span id="L55" class="LineNr"> 55 </span><span class="Delimiter">}</span> +<span id="L56" class="LineNr"> 56 </span> +<span id="L57" class="LineNr"> 57 </span><span class="Normal">void</span> <a href='036labels.cc.html#L57'>test_pack_immediate_ignores_3_hex_digit_argument</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L58" class="LineNr"> 58 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L59" class="LineNr"> 59 </span> transform<span class="Delimiter">(</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Constant">"b9/copy aaa/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Delimiter">);</span> +<span id="L63" class="LineNr"> 63 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Constant">"transform: packing instruction 'b9/copy aaa/imm32'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Comment">// no change (we're just not printing metadata to the trace)</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Constant">"transform: instruction after packing: 'b9 aaa'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Delimiter">);</span> +<span id="L68" class="LineNr"> 68 </span><span class="Delimiter">}</span> +<span id="L69" class="LineNr"> 69 </span> +<span id="L70" class="LineNr"> 70 </span><span class="Normal">void</span> <a href='036labels.cc.html#L70'>test_pack_immediate_ignores_non_hex_argument</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L71" class="LineNr"> 71 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L72" class="LineNr"> 72 </span> transform<span class="Delimiter">(</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Constant">"b9/copy xxx/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Delimiter">);</span> +<span id="L76" class="LineNr"> 76 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Constant">"transform: packing instruction 'b9/copy xxx/imm32'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Comment">// no change (we're just not printing metadata to the trace)</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Constant">"transform: instruction after packing: 'b9 xxx'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Delimiter">);</span> +<span id="L81" class="LineNr"> 81 </span><span class="Delimiter">}</span> +<span id="L82" class="LineNr"> 82 </span> +<span id="L83" class="LineNr"> 83 </span><span class="Comment">//: a helper we'll find handy later</span> +<span id="L84" class="LineNr"> 84 </span><span class="Normal">void</span> <a href='036labels.cc.html#L84'>check_valid_name</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>s<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L86" class="LineNr"> 86 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"empty name!</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Delimiter">}</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">'-'</span><span class="Delimiter">)</span> +<span id="L90" class="LineNr"> 90 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << s << <span class="Constant">"' starts with '-', which can be confused with a negative number; use a different <a href='011run.cc.html#L111'>name</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">)</span> == <span class="Constant">"0x"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L92" class="LineNr"> 92 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << s << <span class="Constant">"' looks like a hex number; use a different <a href='011run.cc.html#L111'>name</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Delimiter">}</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>isdigit<span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> +<span id="L96" class="LineNr"> 96 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << s << <span class="Constant">"' starts with a digit, and so can be confused with a number; use a different name.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">)</span> == <span class="Constant">2</span><span class="Delimiter">)</span> +<span id="L98" class="LineNr"> 98 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << s << <span class="Constant">"' is two characters long, which can look like raw hex bytes at a glance; use a different <a href='011run.cc.html#L111'>name</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L99" class="LineNr"> 99 </span><span class="Delimiter">}</span> +<span id="L100" class="LineNr">100 </span> +<span id="L101" class="LineNr">101 </span><span class="Comment">//: Now that that's done, let's start using names as labels.</span> +<span id="L102" class="LineNr">102 </span> +<span id="L103" class="LineNr">103 </span><span class="Normal">void</span> <a href='036labels.cc.html#L103'>test_map_label</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L104" class="LineNr">104 </span> transform<span class="Delimiter">(</span> +<span id="L105" class="LineNr">105 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L106" class="LineNr">106 </span> <span class="Constant">"loop:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L107" class="LineNr">107 </span> <span class="Constant">" 05 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L108" class="LineNr">108 </span> <span class="Delimiter">);</span> +<span id="L109" class="LineNr">109 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L110" class="LineNr">110 </span> <span class="Constant">"transform: label 'loop' is at address 1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L111" class="LineNr">111 </span> <span class="Delimiter">);</span> +<span id="L112" class="LineNr">112 </span><span class="Delimiter">}</span> +<span id="L113" class="LineNr">113 </span> +<span id="L114" class="LineNr">114 </span><span class="Delimiter">:(before "End Transforms")</span> +<span id="L115" class="LineNr">115 </span><a href='031transforms.cc.html#L4'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='036labels.cc.html#L117'>rewrite_labels</a><span class="Delimiter">);</span> +<span id="L116" class="LineNr">116 </span><span class="Delimiter">:(code)</span> +<span id="L117" class="LineNr">117 </span><span class="Normal">void</span> <a href='036labels.cc.html#L117'>rewrite_labels</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L118" class="LineNr">118 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"-- rewrite labels"</span> << end<span class="Delimiter">();</span> +<span id="L119" class="LineNr">119 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L120" class="LineNr">120 </span> segment& code = *find<span class="Delimiter">(</span>p<span class="Delimiter">,</span> <span class="Constant">"code"</span><span class="Delimiter">);</span> +<span id="L121" class="LineNr">121 </span> map<string<span class="Delimiter">,</span> <span class="Normal">int32_t</span>> byte_index<span class="Delimiter">;</span> <span class="Comment">// values are unsigned, but we're going to do subtractions on them so they need to fit in 31 bits</span> +<span id="L122" class="LineNr">122 </span> <a href='036labels.cc.html#L131'>compute_byte_indices_for_labels</a><span class="Delimiter">(</span>code<span class="Delimiter">,</span> byte_index<span class="Delimiter">);</span> +<span id="L123" class="LineNr">123 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L124" class="LineNr">124 </span> <a href='036labels.cc.html#L205'>drop_labels</a><span class="Delimiter">(</span>code<span class="Delimiter">);</span> +<span id="L125" class="LineNr">125 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L126" class="LineNr">126 </span> <a href='036labels.cc.html#L217'>replace_labels_with_displacements</a><span class="Delimiter">(</span>code<span class="Delimiter">,</span> byte_index<span class="Delimiter">);</span> +<span id="L127" class="LineNr">127 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L231'>contains_key</a><span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> <span class="Constant">"Entry"</span><span class="Delimiter">))</span> +<span id="L128" class="LineNr">128 </span> p<span class="Delimiter">.</span><a href='011run.cc.html#L105'>entry</a> = code<span class="Delimiter">.</span>start + get<span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> <span class="Constant">"Entry"</span><span class="Delimiter">);</span> +<span id="L129" class="LineNr">129 </span><span class="Delimiter">}</span> +<span id="L130" class="LineNr">130 </span> +<span id="L131" class="LineNr">131 </span><span class="Normal">void</span> <a href='036labels.cc.html#L131'>compute_byte_indices_for_labels</a><span class="Delimiter">(</span><span class="Normal">const</span> segment& code<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> <span class="Normal">int32_t</span>>& byte_index<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L132" class="LineNr">132 </span> <span class="Normal">int</span> current_byte = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L133" class="LineNr">133 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L134" class="LineNr">134 </span> <span class="Normal">const</span> line& inst = code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L135" class="LineNr">135 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='036labels.cc.html#L184'>Source_lines_file</a><span class="Delimiter">.</span>is_open<span class="Delimiter">()</span> && !inst<span class="Delimiter">.</span>original<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && <span class="Comment">/*</span><span class="Comment">not a label</span><span class="Comment">*/</span> *inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> != <span class="Constant">':'</span><span class="Delimiter">)</span> +<span id="L136" class="LineNr">136 </span> <a href='036labels.cc.html#L184'>Source_lines_file</a> << <span class="Constant">"0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <span class="Delimiter">(</span>code<span class="Delimiter">.</span>start + current_byte<span class="Delimiter">)</span> << <span class="Constant">' '</span> << inst<span class="Delimiter">.</span>original << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L137" class="LineNr">137 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L138" class="LineNr">138 </span> <span class="Normal">const</span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L139" class="LineNr">139 </span> <span class="Comment">// hack: if we have any argument metadata left after previous transforms,</span> +<span id="L140" class="LineNr">140 </span> <span class="Comment">// deduce its size</span> +<span id="L141" class="LineNr">141 </span> <span class="Comment">// Maybe we should just move this transform to before instruction</span> +<span id="L142" class="LineNr">142 </span> <span class="Comment">// packing, and deduce the size of *all* arguments. But then we'll also</span> +<span id="L143" class="LineNr">143 </span> <span class="Comment">// have to deal with bitfields.</span> +<span id="L144" class="LineNr">144 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">)</span> || has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L145" class="LineNr">145 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> == <span class="Constant">':'</span><span class="Delimiter">)</span> +<span id="L146" class="LineNr">146 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': don't use ':' when jumping to labels</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L147" class="LineNr">147 </span> current_byte += <span class="Constant">4</span><span class="Delimiter">;</span> +<span id="L148" class="LineNr">148 </span> <span class="Delimiter">}</span> +<span id="L149" class="LineNr">149 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L150" class="LineNr">150 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> == <span class="Constant">':'</span><span class="Delimiter">)</span> +<span id="L151" class="LineNr">151 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': don't use ':' when jumping to labels</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L152" class="LineNr">152 </span> current_byte += <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L153" class="LineNr">153 </span> <span class="Delimiter">}</span> +<span id="L154" class="LineNr">154 </span> <span class="Comment">// automatically handle /disp8 and /imm8 here</span> +<span id="L155" class="LineNr">155 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> != <span class="Constant">':'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L156" class="LineNr">156 </span> ++current_byte<span class="Delimiter">;</span> +<span id="L157" class="LineNr">157 </span> <span class="Delimiter">}</span> +<span id="L158" class="LineNr">158 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L159" class="LineNr">159 </span> string label = <a href='036labels.cc.html#L276'>drop_last</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L160" class="LineNr">160 </span> <span class="Comment">// ensure labels look sufficiently different from raw hex</span> +<span id="L161" class="LineNr">161 </span> <a href='036labels.cc.html#L84'>check_valid_name</a><span class="Delimiter">(</span>label<span class="Delimiter">);</span> +<span id="L162" class="LineNr">162 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L163" class="LineNr">163 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='032operands.cc.html#L548'>contains_any_argument_metadata</a><span class="Delimiter">(</span>curr<span class="Delimiter">))</span> +<span id="L164" class="LineNr">164 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': label definition (':') not allowed in argument</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L165" class="LineNr">165 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>j > <span class="Constant">0</span><span class="Delimiter">)</span> +<span id="L166" class="LineNr">166 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': labels can only be the first <a href='011run.cc.html#L127'>word</a> in a line.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L167" class="LineNr">167 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='036labels.cc.html#L183'>Labels_file</a><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> +<span id="L168" class="LineNr">168 </span> <a href='036labels.cc.html#L183'>Labels_file</a> << <span class="Constant">"0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <span class="Delimiter">(</span>code<span class="Delimiter">.</span>start + current_byte<span class="Delimiter">)</span> << <span class="Constant">' '</span> << label << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L169" class="LineNr">169 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L231'>contains_key</a><span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> label<span class="Delimiter">)</span> && label != <span class="Constant">"Entry"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L170" class="LineNr">170 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"duplicate label '"</span> << label << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L171" class="LineNr">171 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L172" class="LineNr">172 </span> <span class="Delimiter">}</span> +<span id="L173" class="LineNr">173 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> label<span class="Delimiter">,</span> current_byte<span class="Delimiter">);</span> +<span id="L174" class="LineNr">174 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"label '"</span> << label << <span class="Constant">"' is at address "</span> << <span class="Delimiter">(</span>current_byte+code<span class="Delimiter">.</span>start<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L175" class="LineNr">175 </span> <span class="Comment">// no modifying current_byte; label definitions won't be in the final binary</span> +<span id="L176" class="LineNr">176 </span> <span class="Delimiter">}</span> +<span id="L177" class="LineNr">177 </span> <span class="Delimiter">}</span> +<span id="L178" class="LineNr">178 </span> <span class="Delimiter">}</span> +<span id="L179" class="LineNr">179 </span><span class="Delimiter">}</span> +<span id="L180" class="LineNr">180 </span> +<span id="L181" class="LineNr">181 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L182" class="LineNr">182 </span><span class="Normal">bool</span> <a href='036labels.cc.html#L182'>Dump_debug_info</a> = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// currently used only by 'bootstrap translate'</span> +<span id="L183" class="LineNr">183 </span>ofstream <a href='036labels.cc.html#L183'>Labels_file</a><span class="Delimiter">;</span> +<span id="L184" class="LineNr">184 </span>ofstream <a href='036labels.cc.html#L184'>Source_lines_file</a><span class="Delimiter">;</span> +<span id="L185" class="LineNr">185 </span><span class="Delimiter">:(before "End Commandline Options")</span> +<span id="L186" class="LineNr">186 </span><span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L98'>is_equal</a><span class="Delimiter">(</span>*arg<span class="Delimiter">,</span> <span class="Constant">"--debug"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L187" class="LineNr">187 </span> <a href='036labels.cc.html#L182'>Dump_debug_info</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L188" class="LineNr">188 </span> <span class="Comment">// End --debug Settings</span> +<span id="L189" class="LineNr">189 </span><span class="Delimiter">}</span> +<span id="L190" class="LineNr">190 </span><span class="Comment">//: wait to open "labels" for writing until we're sure we aren't trying to read it</span> +<span id="L191" class="LineNr">191 </span><span class="Delimiter">:(after "Begin bootstrap translate")</span> +<span id="L192" class="LineNr">192 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='036labels.cc.html#L182'>Dump_debug_info</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L193" class="LineNr">193 </span> cerr << <span class="Constant">"saving address->label information to 'labels'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L194" class="LineNr">194 </span> <a href='036labels.cc.html#L183'>Labels_file</a><span class="Delimiter">.</span>open<span class="Delimiter">(</span><span class="Constant">"labels"</span><span class="Delimiter">);</span> +<span id="L195" class="LineNr">195 </span> cerr << <span class="Constant">"saving address->source information to 'source_lines'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L196" class="LineNr">196 </span> <a href='036labels.cc.html#L184'>Source_lines_file</a><span class="Delimiter">.</span>open<span class="Delimiter">(</span><span class="Constant">"source_lines"</span><span class="Delimiter">);</span> +<span id="L197" class="LineNr">197 </span><span class="Delimiter">}</span> +<span id="L198" class="LineNr">198 </span><span class="Delimiter">:(before "End bootstrap translate")</span> +<span id="L199" class="LineNr">199 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='036labels.cc.html#L182'>Dump_debug_info</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L200" class="LineNr">200 </span> <a href='036labels.cc.html#L183'>Labels_file</a><span class="Delimiter">.</span>close<span class="Delimiter">();</span> +<span id="L201" class="LineNr">201 </span> <a href='036labels.cc.html#L184'>Source_lines_file</a><span class="Delimiter">.</span>close<span class="Delimiter">();</span> +<span id="L202" class="LineNr">202 </span><span class="Delimiter">}</span> +<span id="L203" class="LineNr">203 </span> +<span id="L204" class="LineNr">204 </span><span class="Delimiter">:(code)</span> +<span id="L205" class="LineNr">205 </span><span class="Normal">void</span> <a href='036labels.cc.html#L205'>drop_labels</a><span class="Delimiter">(</span>segment& code<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L206" class="LineNr">206 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L207" class="LineNr">207 </span> line& inst = code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L208" class="LineNr">208 </span> vector<word>::iterator new_end = remove_if<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <a href='036labels.cc.html#L213'>is_label</a><span class="Delimiter">);</span> +<span id="L209" class="LineNr">209 </span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>erase<span class="Delimiter">(</span>new_end<span class="Delimiter">,</span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L210" class="LineNr">210 </span> <span class="Delimiter">}</span> +<span id="L211" class="LineNr">211 </span><span class="Delimiter">}</span> +<span id="L212" class="LineNr">212 </span> +<span id="L213" class="LineNr">213 </span><span class="Normal">bool</span> <a href='036labels.cc.html#L213'>is_label</a><span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L214" class="LineNr">214 </span> <span class="Identifier">return</span> *w<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> == <span class="Constant">':'</span><span class="Delimiter">;</span> +<span id="L215" class="LineNr">215 </span><span class="Delimiter">}</span> +<span id="L216" class="LineNr">216 </span> +<span id="L217" class="LineNr">217 </span><span class="Normal">void</span> <a href='036labels.cc.html#L217'>replace_labels_with_displacements</a><span class="Delimiter">(</span>segment& code<span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">int32_t</span>>& byte_index<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L218" class="LineNr">218 </span> <span class="Normal">int32_t</span> byte_index_next_instruction_starts_at = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L219" class="LineNr">219 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L220" class="LineNr">220 </span> line& inst = code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L221" class="LineNr">221 </span> byte_index_next_instruction_starts_at += <a href='035compute_segment_address.cc.html#L56'>num_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L222" class="LineNr">222 </span> <a href='011run.cc.html#L121'>line</a> new_inst<span class="Delimiter">;</span> +<span id="L223" class="LineNr">223 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L224" class="LineNr">224 </span> <span class="Normal">const</span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L225" class="LineNr">225 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L231'>contains_key</a><span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L226" class="LineNr">226 </span> <span class="Normal">int32_t</span> displacement = <span class="Normal">static_cast</span><<span class="Normal">int32_t</span>><span class="Delimiter">(</span>get<span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> - byte_index_next_instruction_starts_at<span class="Delimiter">;</span> +<span id="L227" class="LineNr">227 </span> <span class="Normal">int32_t</span> absolute_address = code<span class="Delimiter">.</span>start + get<span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L228" class="LineNr">228 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp8"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L229" class="LineNr">229 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>displacement > <span class="Constant">0x7f</span> || displacement < -<span class="Constant">0x7f</span><span class="Delimiter">)</span> +<span id="L230" class="LineNr">230 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': label too far away for displacement "</span> << std::hex << displacement << <span class="Constant">" to fit in 8 signed bits</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L231" class="LineNr">231 </span> <span class="Normal">else</span> +<span id="L232" class="LineNr">232 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> displacement<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L233" class="LineNr">233 </span> <span class="Delimiter">}</span> +<span id="L234" class="LineNr">234 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L235" class="LineNr">235 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>displacement > <span class="Constant">0x7fff</span> || displacement < -<span class="Constant">0x7fff</span><span class="Delimiter">)</span> +<span id="L236" class="LineNr">236 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': label too far away for displacement "</span> << std::hex << displacement << <span class="Constant">" to fit in 16 signed bits</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L237" class="LineNr">237 </span> <span class="Normal">else</span> +<span id="L238" class="LineNr">238 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> displacement<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L239" class="LineNr">239 </span> <span class="Delimiter">}</span> +<span id="L240" class="LineNr">240 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L241" class="LineNr">241 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='036labels.cc.html#L258'>is_far_jump_or_call</a><span class="Delimiter">(</span>new_inst<span class="Delimiter">))</span> +<span id="L242" class="LineNr">242 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> displacement<span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L243" class="LineNr">243 </span> <span class="Normal">else</span> +<span id="L244" class="LineNr">244 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> absolute_address<span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L245" class="LineNr">245 </span> <span class="Delimiter">}</span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L246" class="LineNr">246 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> absolute_address<span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L247" class="LineNr">247 </span> <span class="Delimiter">}</span> +<span id="L248" class="LineNr">248 </span> <span class="Delimiter">}</span> +<span id="L249" class="LineNr">249 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L250" class="LineNr">250 </span> new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L251" class="LineNr">251 </span> <span class="Delimiter">}</span> +<span id="L252" class="LineNr">252 </span> <span class="Delimiter">}</span> +<span id="L253" class="LineNr">253 </span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>swap<span class="Delimiter">(</span>new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> +<span id="L254" class="LineNr">254 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction after transform: '"</span> << data_to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> +<span id="L255" class="LineNr">255 </span> <span class="Delimiter">}</span> +<span id="L256" class="LineNr">256 </span><span class="Delimiter">}</span> +<span id="L257" class="LineNr">257 </span> +<span id="L258" class="LineNr">258 </span><span class="Normal">bool</span> <a href='036labels.cc.html#L258'>is_far_jump_or_call</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L259" class="LineNr">259 </span> string first_opcode = inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data<span class="Delimiter">;</span> +<span id="L260" class="LineNr">260 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>first_opcode == <span class="Constant">"e8"</span> || first_opcode == <span class="Constant">"e9"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L261" class="LineNr">261 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">)</span> < <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L262" class="LineNr">262 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>first_opcode != <span class="Constant">"0f"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L263" class="LineNr">263 </span> string second_opcode = inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>data<span class="Delimiter">;</span> +<span id="L264" class="LineNr">264 </span> <span class="Identifier">return</span> <a href='001help.cc.html#L104'>starts_with</a><span class="Delimiter">(</span>second_opcode<span class="Delimiter">,</span> <span class="Constant">"8"</span><span class="Delimiter">);</span> +<span id="L265" class="LineNr">265 </span><span class="Delimiter">}</span> +<span id="L266" class="LineNr">266 </span> +<span id="L267" class="LineNr">267 </span>string <a href='036labels.cc.html#L267'>data_to_string</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L268" class="LineNr">268 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L269" class="LineNr">269 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L270" class="LineNr">270 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> +<span id="L271" class="LineNr">271 </span> out << inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>data<span class="Delimiter">;</span> +<span id="L272" class="LineNr">272 </span> <span class="Delimiter">}</span> +<span id="L273" class="LineNr">273 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L274" class="LineNr">274 </span><span class="Delimiter">}</span> +<span id="L275" class="LineNr">275 </span> +<span id="L276" class="LineNr">276 </span>string <a href='036labels.cc.html#L276'>drop_last</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L277" class="LineNr">277 </span> <span class="Identifier">return</span> string<span class="Delimiter">(</span>s<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> --s<span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L278" class="LineNr">278 </span><span class="Delimiter">}</span> +<span id="L279" class="LineNr">279 </span> +<span id="L280" class="LineNr">280 </span><span class="Comment">//: Label definitions must be the first word on a line. No jumping inside</span> +<span id="L281" class="LineNr">281 </span><span class="Comment">//: instructions.</span> +<span id="L282" class="LineNr">282 </span><span class="Comment">//: They should also be the only word on a line.</span> +<span id="L283" class="LineNr">283 </span><span class="Comment">//: However, you can absolutely have multiple labels map to the same address,</span> +<span id="L284" class="LineNr">284 </span><span class="Comment">//: as long as they're on separate lines.</span> +<span id="L285" class="LineNr">285 </span> +<span id="L286" class="LineNr">286 </span><span class="Normal">void</span> <a href='036labels.cc.html#L286'>test_multiple_labels_at</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L287" class="LineNr">287 </span> transform<span class="Delimiter">(</span> +<span id="L288" class="LineNr">288 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L289" class="LineNr">289 </span> <span class="Comment">// address 1</span> +<span id="L290" class="LineNr">290 </span> <span class="Constant">"loop:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L291" class="LineNr">291 </span> <span class="Constant">" $loop2:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L292" class="LineNr">292 </span> <span class="Comment">// address 1 (labels take up no space)</span> +<span id="L293" class="LineNr">293 </span> <span class="Constant">" 05 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L294" class="LineNr">294 </span> <span class="Comment">// address 6</span> +<span id="L295" class="LineNr">295 </span> <span class="Constant">" eb $loop2/disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L296" class="LineNr">296 </span> <span class="Comment">// address 8</span> +<span id="L297" class="LineNr">297 </span> <span class="Constant">" eb $loop3/disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L298" class="LineNr">298 </span> <span class="Comment">// address 0xa</span> +<span id="L299" class="LineNr">299 </span> <span class="Constant">" $loop3:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L300" class="LineNr">300 </span> <span class="Delimiter">);</span> +<span id="L301" class="LineNr">301 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L302" class="LineNr">302 </span> <span class="Constant">"transform: label 'loop' is at address 1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L303" class="LineNr">303 </span> <span class="Constant">"transform: label '$loop2' is at address 1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L304" class="LineNr">304 </span> <span class="Constant">"transform: label '$loop3' is at address a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L305" class="LineNr">305 </span> <span class="Comment">// first jump is to -7</span> +<span id="L306" class="LineNr">306 </span> <span class="Constant">"transform: instruction after transform: 'eb f9'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L307" class="LineNr">307 </span> <span class="Comment">// second jump is to 0 (fall through)</span> +<span id="L308" class="LineNr">308 </span> <span class="Constant">"transform: instruction after transform: 'eb 00'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L309" class="LineNr">309 </span> <span class="Delimiter">);</span> +<span id="L310" class="LineNr">310 </span><span class="Delimiter">}</span> +<span id="L311" class="LineNr">311 </span> +<span id="L312" class="LineNr">312 </span><span class="Normal">void</span> <a href='036labels.cc.html#L312'>test_loading_label_as_imm32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L313" class="LineNr">313 </span> transform<span class="Delimiter">(</span> +<span id="L314" class="LineNr">314 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L315" class="LineNr">315 </span> <span class="Constant">"label:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L316" class="LineNr">316 </span> <span class="Constant">" be/copy-to-ESI label/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L317" class="LineNr">317 </span> <span class="Delimiter">);</span> +<span id="L318" class="LineNr">318 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L319" class="LineNr">319 </span> <span class="Constant">"transform: label 'label' is at address 1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L320" class="LineNr">320 </span> <span class="Constant">"transform: instruction after transform: 'be 01 00 00 00'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L321" class="LineNr">321 </span> <span class="Delimiter">);</span> +<span id="L322" class="LineNr">322 </span><span class="Delimiter">}</span> +<span id="L323" class="LineNr">323 </span> +<span id="L324" class="LineNr">324 </span><span class="Normal">void</span> <a href='036labels.cc.html#L324'>test_duplicate_label</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L325" class="LineNr">325 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L326" class="LineNr">326 </span> transform<span class="Delimiter">(</span> +<span id="L327" class="LineNr">327 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L328" class="LineNr">328 </span> <span class="Constant">"loop:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L329" class="LineNr">329 </span> <span class="Constant">"loop:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L330" class="LineNr">330 </span> <span class="Constant">" 05 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L331" class="LineNr">331 </span> <span class="Delimiter">);</span> +<span id="L332" class="LineNr">332 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L333" class="LineNr">333 </span> <span class="Constant">"error: duplicate label 'loop'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L334" class="LineNr">334 </span> <span class="Delimiter">);</span> +<span id="L335" class="LineNr">335 </span><span class="Delimiter">}</span> +<span id="L336" class="LineNr">336 </span> +<span id="L337" class="LineNr">337 </span><span class="Normal">void</span> <a href='036labels.cc.html#L337'>test_label_too_short</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L338" class="LineNr">338 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L339" class="LineNr">339 </span> transform<span class="Delimiter">(</span> +<span id="L340" class="LineNr">340 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L341" class="LineNr">341 </span> <span class="Constant">"xz:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L342" class="LineNr">342 </span> <span class="Constant">" 05 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L343" class="LineNr">343 </span> <span class="Delimiter">);</span> +<span id="L344" class="LineNr">344 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L345" class="LineNr">345 </span> <span class="Constant">"error: 'xz' is two characters long, which can look like raw hex bytes at a glance; use a different <a href='011run.cc.html#L111'>name</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L346" class="LineNr">346 </span> <span class="Delimiter">);</span> +<span id="L347" class="LineNr">347 </span><span class="Delimiter">}</span> +<span id="L348" class="LineNr">348 </span> +<span id="L349" class="LineNr">349 </span><span class="Normal">void</span> <a href='036labels.cc.html#L349'>test_label_hex</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L350" class="LineNr">350 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L351" class="LineNr">351 </span> transform<span class="Delimiter">(</span> +<span id="L352" class="LineNr">352 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L353" class="LineNr">353 </span> <span class="Constant">"0xab:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L354" class="LineNr">354 </span> <span class="Constant">" 05 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L355" class="LineNr">355 </span> <span class="Delimiter">);</span> +<span id="L356" class="LineNr">356 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L357" class="LineNr">357 </span> <span class="Constant">"error: '0xab' looks like a hex number; use a different <a href='011run.cc.html#L111'>name</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L358" class="LineNr">358 </span> <span class="Delimiter">);</span> +<span id="L359" class="LineNr">359 </span><span class="Delimiter">}</span> +<span id="L360" class="LineNr">360 </span> +<span id="L361" class="LineNr">361 </span><span class="Normal">void</span> <a href='036labels.cc.html#L361'>test_label_negative_hex</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L362" class="LineNr">362 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L363" class="LineNr">363 </span> transform<span class="Delimiter">(</span> +<span id="L364" class="LineNr">364 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L365" class="LineNr">365 </span> <span class="Constant">"-a:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L366" class="LineNr">366 </span> <span class="Constant">" 05 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L367" class="LineNr">367 </span> <span class="Delimiter">);</span> +<span id="L368" class="LineNr">368 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L369" class="LineNr">369 </span> <span class="Constant">"error: '-a' starts with '-', which can be confused with a negative number; use a different <a href='011run.cc.html#L111'>name</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L370" class="LineNr">370 </span> <span class="Delimiter">);</span> +<span id="L371" class="LineNr">371 </span><span class="Delimiter">}</span> +<span id="L372" class="LineNr">372 </span> +<span id="L373" class="LineNr">373 </span><span class="Comment">//: As said up top, the 'Entry' label is special.</span> +<span id="L374" class="LineNr">374 </span><span class="Comment">//: It can be non-unique; the last declaration overrides earlier ones.</span> +<span id="L375" class="LineNr">375 </span><span class="Comment">//: It must exist in a program. Otherwise we don't know where to start running</span> +<span id="L376" class="LineNr">376 </span><span class="Comment">//: programs.</span> +<span id="L377" class="LineNr">377 </span> +<span id="L378" class="LineNr">378 </span><span class="Normal">void</span> <a href='036labels.cc.html#L378'>test_duplicate_Entry_label</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L379" class="LineNr">379 </span> transform<span class="Delimiter">(</span> +<span id="L380" class="LineNr">380 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L381" class="LineNr">381 </span> <span class="Constant">"Entry:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L382" class="LineNr">382 </span> <span class="Constant">"Entry:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L383" class="LineNr">383 </span> <span class="Constant">" 05 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L384" class="LineNr">384 </span> <span class="Delimiter">);</span> +<span id="L385" class="LineNr">385 </span> <a href='003trace.cc.html#L304'>CHECK_TRACE_DOESNT_CONTAIN_ERRORS</a><span class="Delimiter">();</span> +<span id="L386" class="LineNr">386 </span><span class="Delimiter">}</span> +<span id="L387" class="LineNr">387 </span> +<span id="L388" class="LineNr">388 </span><span class="Comment">// This test could do with some refactoring.</span> +<span id="L389" class="LineNr">389 </span><span class="Comment">// We're duplicating the flow inside `bootstrap translate`, but without</span> +<span id="L390" class="LineNr">390 </span><span class="Comment">// reading/writing files.</span> +<span id="L391" class="LineNr">391 </span><span class="Comment">// We can't just use run(string) because most of our tests allow programs</span> +<span id="L392" class="LineNr">392 </span><span class="Comment">// without 'Entry' labels, as a convenience.</span> +<span id="L393" class="LineNr">393 </span><span class="Normal">void</span> <a href='036labels.cc.html#L393'>test_programs_without_Entry_label</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L394" class="LineNr">394 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L395" class="LineNr">395 </span> program p<span class="Delimiter">;</span> +<span id="L396" class="LineNr">396 </span> istringstream in<span class="Delimiter">(</span> +<span id="L397" class="LineNr">397 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L398" class="LineNr">398 </span> <span class="Constant">"05 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L399" class="LineNr">399 </span> <span class="Constant">"05 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L400" class="LineNr">400 </span> <span class="Delimiter">);</span> +<span id="L401" class="LineNr">401 </span> parse<span class="Delimiter">(</span>in<span class="Delimiter">,</span> p<span class="Delimiter">);</span> +<span id="L402" class="LineNr">402 </span> transform<span class="Delimiter">(</span>p<span class="Delimiter">);</span> +<span id="L403" class="LineNr">403 </span> ostringstream dummy<span class="Delimiter">;</span> +<span id="L404" class="LineNr">404 </span> save_elf<span class="Delimiter">(</span>p<span class="Delimiter">,</span> dummy<span class="Delimiter">);</span> +<span id="L405" class="LineNr">405 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L406" class="LineNr">406 </span> <span class="Constant">"error: no 'Entry' label found</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L407" class="LineNr">407 </span> <span class="Delimiter">);</span> +<span id="L408" class="LineNr">408 </span><span class="Delimiter">}</span> +<span id="L409" class="LineNr">409 </span> +<span id="L410" class="LineNr">410 </span><span class="Comment">//: now that we have labels, we need to adjust segment size computation to</span> +<span id="L411" class="LineNr">411 </span><span class="Comment">//: ignore them.</span> +<span id="L412" class="LineNr">412 </span> +<span id="L413" class="LineNr">413 </span><span class="Normal">void</span> <a href='036labels.cc.html#L413'>test_segment_size_ignores_labels</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L414" class="LineNr">414 </span> transform<span class="Delimiter">(</span> +<span id="L415" class="LineNr">415 </span> <span class="Constant">"== code 0x09000074</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L416" class="LineNr">416 </span> <span class="Constant">" 05/add 0x0d0c0b0a/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 5 bytes</span> +<span id="L417" class="LineNr">417 </span> <span class="Constant">"foo:</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 0 bytes</span> +<span id="L418" class="LineNr">418 </span> <span class="Constant">"== data 0x0a000000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L419" class="LineNr">419 </span> <span class="Constant">"bar:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L420" class="LineNr">420 </span> <span class="Constant">" 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L421" class="LineNr">421 </span> <span class="Delimiter">);</span> +<span id="L422" class="LineNr">422 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L423" class="LineNr">423 </span> <span class="Constant">"transform: segment 1 begins at address 0x0a000079</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L424" class="LineNr">424 </span> <span class="Delimiter">);</span> +<span id="L425" class="LineNr">425 </span><span class="Delimiter">}</span> +<span id="L426" class="LineNr">426 </span> +<span id="L427" class="LineNr">427 </span><span class="Delimiter">:(before "End size_of(<a href='011run.cc.html#L127'>word</a> w) Special-cases")</span> +<span id="L428" class="LineNr">428 </span><span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='036labels.cc.html#L213'>is_label</a><span class="Delimiter">(</span>w<span class="Delimiter">))</span> +<span id="L429" class="LineNr">429 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/037global_variables.cc.html b/html/linux/bootstrap/037global_variables.cc.html new file mode 100644 index 00000000..ea37783f --- /dev/null +++ b/html/linux/bootstrap/037global_variables.cc.html @@ -0,0 +1,368 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/037global_variables.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.CommentedCode { color: #8a8a8a; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/037global_variables.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/037global_variables.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: Global variables.</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//:</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: Global variables are just labels in the data segment.</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: However, they can only be used in imm32 and not disp32 arguments. And they</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: can't be used with jump and call instructions.</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment">//:</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment">//: This layer has much the same structure as rewriting labels.</span> +<span id="L8" class="LineNr"> 8 </span> +<span id="L9" class="LineNr"> 9 </span><span class="Delimiter">:(code)</span> +<span id="L10" class="LineNr"> 10 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L10'>test_global_variable</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L11" class="LineNr"> 11 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Constant">"b9 x/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Constant">"x:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Constant">" 00 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Delimiter">);</span> +<span id="L18" class="LineNr"> 18 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"transform: global variable 'x' is at address 0x00002000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Delimiter">);</span> +<span id="L21" class="LineNr"> 21 </span><span class="Delimiter">}</span> +<span id="L22" class="LineNr"> 22 </span> +<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">:(before "End Transforms")</span> +<span id="L24" class="LineNr"> 24 </span><a href='031transforms.cc.html#L4'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='037global_variables.cc.html#L26'>rewrite_global_variables</a><span class="Delimiter">);</span> +<span id="L25" class="LineNr"> 25 </span><span class="Delimiter">:(code)</span> +<span id="L26" class="LineNr"> 26 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L26'>rewrite_global_variables</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L27" class="LineNr"> 27 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"-- rewrite global variables"</span> << end<span class="Delimiter">();</span> +<span id="L28" class="LineNr"> 28 </span> <span class="Comment">// Begin rewrite_global_variables</span> +<span id="L29" class="LineNr"> 29 </span> map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>> address<span class="Delimiter">;</span> +<span id="L30" class="LineNr"> 30 </span> compute_addresses_for_global_variables<span class="Delimiter">(</span>p<span class="Delimiter">,</span> address<span class="Delimiter">);</span> +<span id="L31" class="LineNr"> 31 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L32" class="LineNr"> 32 </span> <a href='037global_variables.cc.html#L73'>drop_global_variables</a><span class="Delimiter">(</span>p<span class="Delimiter">);</span> +<span id="L33" class="LineNr"> 33 </span> <a href='037global_variables.cc.html#L80'>replace_global_variables_with_addresses</a><span class="Delimiter">(</span>p<span class="Delimiter">,</span> address<span class="Delimiter">);</span> +<span id="L34" class="LineNr"> 34 </span><span class="Delimiter">}</span> +<span id="L35" class="LineNr"> 35 </span> +<span id="L36" class="LineNr"> 36 </span><span class="Normal">void</span> compute_addresses_for_global_variables<span class="Delimiter">(</span><span class="Normal">const</span> program& p<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>>& address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L38" class="LineNr"> 38 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='011run.cc.html#L111'>name</a> != <span class="Constant">"code"</span><span class="Delimiter">)</span> +<span id="L39" class="LineNr"> 39 </span> compute_addresses_for_global_variables<span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> address<span class="Delimiter">);</span> +<span id="L40" class="LineNr"> 40 </span> <span class="Delimiter">}</span> +<span id="L41" class="LineNr"> 41 </span><span class="Delimiter">}</span> +<span id="L42" class="LineNr"> 42 </span> +<span id="L43" class="LineNr"> 43 </span><span class="Normal">void</span> compute_addresses_for_global_variables<span class="Delimiter">(</span><span class="Normal">const</span> segment& s<span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>>& address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Normal">int</span> current_address = s<span class="Delimiter">.</span>start<span class="Delimiter">;</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Normal">const</span> line& inst = s<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Normal">const</span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> != <span class="Constant">':'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L50" class="LineNr"> 50 </span> current_address += size_of<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Delimiter">}</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L53" class="LineNr"> 53 </span> string variable = <a href='036labels.cc.html#L276'>drop_last</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Comment">// ensure variables look sufficiently different from raw hex</span> +<span id="L55" class="LineNr"> 55 </span> <a href='036labels.cc.html#L84'>check_valid_name</a><span class="Delimiter">(</span>variable<span class="Delimiter">);</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L262'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>j > <span class="Constant">0</span><span class="Delimiter">)</span> +<span id="L58" class="LineNr"> 58 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': global variable names can only be the first <a href='011run.cc.html#L127'>word</a> in a line.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='036labels.cc.html#L183'>Labels_file</a><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> +<span id="L60" class="LineNr"> 60 </span> <a href='036labels.cc.html#L183'>Labels_file</a> << <span class="Constant">"0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << current_address << <span class="Constant">' '</span> << variable << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L231'>contains_key</a><span class="Delimiter">(</span>address<span class="Delimiter">,</span> variable<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L62" class="LineNr"> 62 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"duplicate global '"</span> << variable << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Delimiter">}</span> +<span id="L65" class="LineNr"> 65 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span>address<span class="Delimiter">,</span> variable<span class="Delimiter">,</span> current_address<span class="Delimiter">);</span> +<span id="L66" class="LineNr"> 66 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"global variable '"</span> << variable << <span class="Constant">"' is at address 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << current_address << end<span class="Delimiter">();</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Comment">// no modifying current_address; global variable definitions won't be in the final binary</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Delimiter">}</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Delimiter">}</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Delimiter">}</span> +<span id="L71" class="LineNr"> 71 </span><span class="Delimiter">}</span> +<span id="L72" class="LineNr"> 72 </span> +<span id="L73" class="LineNr"> 73 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L73'>drop_global_variables</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='011run.cc.html#L111'>name</a> != <span class="Constant">"code"</span><span class="Delimiter">)</span> +<span id="L76" class="LineNr"> 76 </span> <a href='036labels.cc.html#L205'>drop_labels</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Delimiter">}</span> +<span id="L78" class="LineNr"> 78 </span><span class="Delimiter">}</span> +<span id="L79" class="LineNr"> 79 </span> +<span id="L80" class="LineNr"> 80 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L80'>replace_global_variables_with_addresses</a><span class="Delimiter">(</span>program& p<span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>>& address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L83" class="LineNr"> 83 </span> segment& curr = p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span><a href='011run.cc.html#L111'>name</a> == <span class="Constant">"code"</span><span class="Delimiter">)</span> +<span id="L85" class="LineNr"> 85 </span> <a href='037global_variables.cc.html#L91'>replace_global_variables_in_code_segment</a><span class="Delimiter">(</span>curr<span class="Delimiter">,</span> address<span class="Delimiter">);</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Normal">else</span> +<span id="L87" class="LineNr"> 87 </span> <a href='037global_variables.cc.html#L114'>replace_global_variables_in_data_segment</a><span class="Delimiter">(</span>curr<span class="Delimiter">,</span> address<span class="Delimiter">);</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Delimiter">}</span> +<span id="L89" class="LineNr"> 89 </span><span class="Delimiter">}</span> +<span id="L90" class="LineNr"> 90 </span> +<span id="L91" class="LineNr"> 91 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L91'>replace_global_variables_in_code_segment</a><span class="Delimiter">(</span>segment& code<span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>>& address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L93" class="LineNr"> 93 </span> line& inst = code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L94" class="LineNr"> 94 </span> <a href='011run.cc.html#L121'>line</a> new_inst<span class="Delimiter">;</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Normal">const</span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>address<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!looks_like_hex_int<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> +<span id="L99" class="LineNr"> 99 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"missing reference to global '"</span> << curr<span class="Delimiter">.</span>data << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L100" class="LineNr">100 </span> new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L101" class="LineNr">101 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L102" class="LineNr">102 </span> <span class="Delimiter">}</span> +<span id="L103" class="LineNr">103 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!valid_use_of_global_variable<span class="Delimiter">(</span>curr<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L104" class="LineNr">104 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': can't refer to global variable '"</span> << curr<span class="Delimiter">.</span>data << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L105" class="LineNr">105 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L106" class="LineNr">106 </span> <span class="Delimiter">}</span> +<span id="L107" class="LineNr">107 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>address<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">),</span> <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L108" class="LineNr">108 </span> <span class="Delimiter">}</span> +<span id="L109" class="LineNr">109 </span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>swap<span class="Delimiter">(</span>new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> +<span id="L110" class="LineNr">110 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction after transform: '"</span> << data_to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> +<span id="L111" class="LineNr">111 </span> <span class="Delimiter">}</span> +<span id="L112" class="LineNr">112 </span><span class="Delimiter">}</span> +<span id="L113" class="LineNr">113 </span> +<span id="L114" class="LineNr">114 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L114'>replace_global_variables_in_data_segment</a><span class="Delimiter">(</span>segment& data<span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>>& address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L115" class="LineNr">115 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>data<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L116" class="LineNr">116 </span> line& l = data<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L117" class="LineNr">117 </span> <a href='011run.cc.html#L121'>line</a> new_l<span class="Delimiter">;</span> +<span id="L118" class="LineNr">118 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>l<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L119" class="LineNr">119 </span> <span class="Normal">const</span> word& curr = l<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L120" class="LineNr">120 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>address<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L121" class="LineNr">121 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='032operands.cc.html#L591'>looks_like_hex_int</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L122" class="LineNr">122 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">))</span> +<span id="L123" class="LineNr">123 </span> emit_hex_bytes<span class="Delimiter">(</span>new_l<span class="Delimiter">,</span> curr<span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L124" class="LineNr">124 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"imm16"</span><span class="Delimiter">))</span> +<span id="L125" class="LineNr">125 </span> emit_hex_bytes<span class="Delimiter">(</span>new_l<span class="Delimiter">,</span> curr<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L126" class="LineNr">126 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"imm8"</span><span class="Delimiter">))</span> +<span id="L127" class="LineNr">127 </span> emit_hex_bytes<span class="Delimiter">(</span>new_l<span class="Delimiter">,</span> curr<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L128" class="LineNr">128 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp8"</span><span class="Delimiter">))</span> +<span id="L129" class="LineNr">129 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"can't use /disp8 in a non-code segment</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L130" class="LineNr">130 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">))</span> +<span id="L131" class="LineNr">131 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"can't use /disp16 in a non-code segment</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L132" class="LineNr">132 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">))</span> +<span id="L133" class="LineNr">133 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"can't use /disp32 in a non-code segment</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L134" class="LineNr">134 </span> <span class="Normal">else</span> +<span id="L135" class="LineNr">135 </span> new_l<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L136" class="LineNr">136 </span> <span class="Delimiter">}</span> +<span id="L137" class="LineNr">137 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L138" class="LineNr">138 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"missing reference to global '"</span> << curr<span class="Delimiter">.</span>data << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L139" class="LineNr">139 </span> new_l<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L140" class="LineNr">140 </span> <span class="Delimiter">}</span> +<span id="L141" class="LineNr">141 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L142" class="LineNr">142 </span> <span class="Delimiter">}</span> +<span id="L143" class="LineNr">143 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << curr<span class="Delimiter">.</span>data << <span class="Constant">" maps to "</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << get<span class="Delimiter">(</span>address<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L144" class="LineNr">144 </span> emit_hex_bytes<span class="Delimiter">(</span>new_l<span class="Delimiter">,</span> get<span class="Delimiter">(</span>address<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">),</span> <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L145" class="LineNr">145 </span> <span class="Delimiter">}</span> +<span id="L146" class="LineNr">146 </span> l<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>swap<span class="Delimiter">(</span>new_l<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> +<span id="L147" class="LineNr">147 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"after transform: '"</span> << data_to_string<span class="Delimiter">(</span>l<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> +<span id="L148" class="LineNr">148 </span> <span class="Delimiter">}</span> +<span id="L149" class="LineNr">149 </span><span class="Delimiter">}</span> +<span id="L150" class="LineNr">150 </span> +<span id="L151" class="LineNr">151 </span><span class="Normal">bool</span> <a href='037global_variables.cc.html#L151'>valid_use_of_global_variable</a><span class="Delimiter">(</span><span class="Normal">const</span> word& curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L152" class="LineNr">152 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L153" class="LineNr">153 </span> <span class="Comment">// End Valid Uses Of Global Variable(curr)</span> +<span id="L154" class="LineNr">154 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L155" class="LineNr">155 </span><span class="Delimiter">}</span> +<span id="L156" class="LineNr">156 </span> +<span id="L157" class="LineNr">157 </span><span class="Comment">//:: a more complex sanity check for how we use global variables</span> +<span id="L158" class="LineNr">158 </span><span class="Comment">//: requires first saving some data early before we pack arguments</span> +<span id="L159" class="LineNr">159 </span> +<span id="L160" class="LineNr">160 </span><span class="Delimiter">:(after "Begin Transforms")</span> +<span id="L161" class="LineNr">161 </span><a href='031transforms.cc.html#L4'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='037global_variables.cc.html#L163'>correlate_disp32_with_mod</a><span class="Delimiter">);</span> +<span id="L162" class="LineNr">162 </span><span class="Delimiter">:(code)</span> +<span id="L163" class="LineNr">163 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L163'>correlate_disp32_with_mod</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L164" class="LineNr">164 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L165" class="LineNr">165 </span> segment& code = *find<span class="Delimiter">(</span>p<span class="Delimiter">,</span> <span class="Constant">"code"</span><span class="Delimiter">);</span> +<span id="L166" class="LineNr">166 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L167" class="LineNr">167 </span> line& inst = code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L168" class="LineNr">168 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L169" class="LineNr">169 </span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L170" class="LineNr">170 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">)</span> +<span id="L171" class="LineNr">171 </span> && has_argument_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">))</span> +<span id="L172" class="LineNr">172 </span> curr<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"has_mod"</span><span class="Delimiter">);</span> +<span id="L173" class="LineNr">173 </span> <span class="Delimiter">}</span> +<span id="L174" class="LineNr">174 </span> <span class="Delimiter">}</span> +<span id="L175" class="LineNr">175 </span><span class="Delimiter">}</span> +<span id="L176" class="LineNr">176 </span> +<span id="L177" class="LineNr">177 </span><span class="Delimiter">:(before "End Valid Uses Of Global Variable(curr)")</span> +<span id="L178" class="LineNr">178 </span><span class="Normal">if</span> <span class="Delimiter">(</span>has_argument_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">))</span> +<span id="L179" class="LineNr">179 </span> <span class="Identifier">return</span> <a href='037global_variables.cc.html#L184'>has_metadata</a><span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"has_mod"</span><span class="Delimiter">);</span> +<span id="L180" class="LineNr">180 </span><span class="Comment">// todo: more sophisticated check, to ensure we don't use global variable</span> +<span id="L181" class="LineNr">181 </span><span class="Comment">// addresses as a real displacement added to other arguments.</span> +<span id="L182" class="LineNr">182 </span> +<span id="L183" class="LineNr">183 </span><span class="Delimiter">:(code)</span> +<span id="L184" class="LineNr">184 </span><span class="Normal">bool</span> <a href='037global_variables.cc.html#L184'>has_metadata</a><span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">,</span> <span class="Normal">const</span> string& m<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L185" class="LineNr">185 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>metadata<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L186" class="LineNr">186 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>w<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == m<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L187" class="LineNr">187 </span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L188" class="LineNr">188 </span><span class="Delimiter">}</span> +<span id="L189" class="LineNr">189 </span> +<span id="L190" class="LineNr">190 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L190'>test_global_variable_disallowed_in_jump</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L191" class="LineNr">191 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L192" class="LineNr">192 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L193" class="LineNr">193 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L194" class="LineNr">194 </span> <span class="Constant">"eb/jump x/disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L195" class="LineNr">195 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L196" class="LineNr">196 </span> <span class="Constant">"x:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L197" class="LineNr">197 </span> <span class="Constant">" 00 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L198" class="LineNr">198 </span> <span class="Delimiter">);</span> +<span id="L199" class="LineNr">199 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L200" class="LineNr">200 </span> <span class="Constant">"error: 'eb/jump x/disp8': can't refer to global variable 'x'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L201" class="LineNr">201 </span> <span class="Comment">// sub-optimal error message; should be</span> +<span id="L202" class="LineNr">202 </span><span class="CommentedCode">//? "error: can't jump to data (variable 'x')\n"</span> +<span id="L203" class="LineNr">203 </span> <span class="Delimiter">);</span> +<span id="L204" class="LineNr">204 </span><span class="Delimiter">}</span> +<span id="L205" class="LineNr">205 </span> +<span id="L206" class="LineNr">206 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L206'>test_global_variable_disallowed_in_call</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L207" class="LineNr">207 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L208" class="LineNr">208 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L209" class="LineNr">209 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L210" class="LineNr">210 </span> <span class="Constant">"e8/call x/disp32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L211" class="LineNr">211 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L212" class="LineNr">212 </span> <span class="Constant">"x:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L213" class="LineNr">213 </span> <span class="Constant">" 00 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L214" class="LineNr">214 </span> <span class="Delimiter">);</span> +<span id="L215" class="LineNr">215 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L216" class="LineNr">216 </span> <span class="Constant">"error: 'e8/call x/disp32': can't refer to global variable 'x'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L217" class="LineNr">217 </span> <span class="Comment">// sub-optimal error message; should be</span> +<span id="L218" class="LineNr">218 </span><span class="CommentedCode">//? "error: can't call to the data segment ('x')\n"</span> +<span id="L219" class="LineNr">219 </span> <span class="Delimiter">);</span> +<span id="L220" class="LineNr">220 </span><span class="Delimiter">}</span> +<span id="L221" class="LineNr">221 </span> +<span id="L222" class="LineNr">222 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L222'>test_global_variable_in_data_segment</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L223" class="LineNr">223 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L224" class="LineNr">224 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L225" class="LineNr">225 </span> <span class="Constant">"b9 x/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L226" class="LineNr">226 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L227" class="LineNr">227 </span> <span class="Constant">"x:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L228" class="LineNr">228 </span> <span class="Constant">" y/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L229" class="LineNr">229 </span> <span class="Constant">"y:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L230" class="LineNr">230 </span> <span class="Constant">" 00 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L231" class="LineNr">231 </span> <span class="Delimiter">);</span> +<span id="L232" class="LineNr">232 </span> <span class="Comment">// check that we loaded 'x' with the address of 'y'</span> +<span id="L233" class="LineNr">233 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L234" class="LineNr">234 </span> <span class="Constant">"load: 0x00002000 -> 04</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L235" class="LineNr">235 </span> <span class="Constant">"load: 0x00002001 -> 20</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L236" class="LineNr">236 </span> <span class="Constant">"load: 0x00002002 -> 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L237" class="LineNr">237 </span> <span class="Constant">"load: 0x00002003 -> 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L238" class="LineNr">238 </span> <span class="Delimiter">);</span> +<span id="L239" class="LineNr">239 </span> <a href='003trace.cc.html#L294'>CHECK_TRACE_COUNT</a><span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L240" class="LineNr">240 </span><span class="Delimiter">}</span> +<span id="L241" class="LineNr">241 </span> +<span id="L242" class="LineNr">242 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L242'>test_raw_number_with_imm32_in_data_segment</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L243" class="LineNr">243 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L244" class="LineNr">244 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L245" class="LineNr">245 </span> <span class="Constant">"b9 x/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L246" class="LineNr">246 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L247" class="LineNr">247 </span> <span class="Constant">"x:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L248" class="LineNr">248 </span> <span class="Constant">" 1/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L249" class="LineNr">249 </span> <span class="Delimiter">);</span> +<span id="L250" class="LineNr">250 </span> <span class="Comment">// check that we loaded 'x' with the address of 1</span> +<span id="L251" class="LineNr">251 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L252" class="LineNr">252 </span> <span class="Constant">"load: 0x00002000 -> 01</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L253" class="LineNr">253 </span> <span class="Constant">"load: 0x00002001 -> 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L254" class="LineNr">254 </span> <span class="Constant">"load: 0x00002002 -> 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L255" class="LineNr">255 </span> <span class="Constant">"load: 0x00002003 -> 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L256" class="LineNr">256 </span> <span class="Delimiter">);</span> +<span id="L257" class="LineNr">257 </span> <a href='003trace.cc.html#L294'>CHECK_TRACE_COUNT</a><span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L258" class="LineNr">258 </span><span class="Delimiter">}</span> +<span id="L259" class="LineNr">259 </span> +<span id="L260" class="LineNr">260 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L260'>test_duplicate_global_variable</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L261" class="LineNr">261 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L262" class="LineNr">262 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L263" class="LineNr">263 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L264" class="LineNr">264 </span> <span class="Constant">"40/increment-EAX</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L265" class="LineNr">265 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L266" class="LineNr">266 </span> <span class="Constant">"x:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L267" class="LineNr">267 </span> <span class="Constant">"x:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L268" class="LineNr">268 </span> <span class="Constant">" 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L269" class="LineNr">269 </span> <span class="Delimiter">);</span> +<span id="L270" class="LineNr">270 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L271" class="LineNr">271 </span> <span class="Constant">"error: duplicate global 'x'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L272" class="LineNr">272 </span> <span class="Delimiter">);</span> +<span id="L273" class="LineNr">273 </span><span class="Delimiter">}</span> +<span id="L274" class="LineNr">274 </span> +<span id="L275" class="LineNr">275 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L275'>test_global_variable_disp32_with_modrm</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L276" class="LineNr">276 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L277" class="LineNr">277 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L278" class="LineNr">278 </span> <span class="Constant">"8b/copy 0/mod/indirect 5/rm32/.disp32 2/r32/EDX x/disp32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L279" class="LineNr">279 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L280" class="LineNr">280 </span> <span class="Constant">"x:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L281" class="LineNr">281 </span> <span class="Constant">" 00 00 00 00</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L282" class="LineNr">282 </span> <span class="Delimiter">);</span> +<span id="L283" class="LineNr">283 </span> <a href='003trace.cc.html#L294'>CHECK_TRACE_COUNT</a><span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L284" class="LineNr">284 </span><span class="Delimiter">}</span> +<span id="L285" class="LineNr">285 </span> +<span id="L286" class="LineNr">286 </span><span class="Normal">void</span> <a href='037global_variables.cc.html#L286'>test_global_variable_disp32_with_call</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L287" class="LineNr">287 </span> transform<span class="Delimiter">(</span> +<span id="L288" class="LineNr">288 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L289" class="LineNr">289 </span> <span class="Constant">"foo:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L290" class="LineNr">290 </span> <span class="Constant">" e8/call bar/disp32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L291" class="LineNr">291 </span> <span class="Constant">"bar:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L292" class="LineNr">292 </span> <span class="Delimiter">);</span> +<span id="L293" class="LineNr">293 </span> <a href='003trace.cc.html#L294'>CHECK_TRACE_COUNT</a><span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L294" class="LineNr">294 </span><span class="Delimiter">}</span> +<span id="L295" class="LineNr">295 </span> +<span id="L296" class="LineNr">296 </span>string <a href='037global_variables.cc.html#L296'>to_full_string</a><span class="Delimiter">(</span><span class="Normal">const</span> line& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L297" class="LineNr">297 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L298" class="LineNr">298 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L299" class="LineNr">299 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> +<span id="L300" class="LineNr">300 </span> out << in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>data<span class="Delimiter">;</span> +<span id="L301" class="LineNr">301 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>metadata<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> +<span id="L302" class="LineNr">302 </span> out << <span class="Constant">'/'</span> << in<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L303" class="LineNr">303 </span> <span class="Delimiter">}</span> +<span id="L304" class="LineNr">304 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L305" class="LineNr">305 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/038literal_strings.cc.html b/html/linux/bootstrap/038literal_strings.cc.html new file mode 100644 index 00000000..7b6d34f0 --- /dev/null +++ b/html/linux/bootstrap/038literal_strings.cc.html @@ -0,0 +1,425 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/038literal_strings.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.Delimiter { color: #c000c0; } +.Comment { color: #005faf; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.CommentedCode { color: #8a8a8a; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/038literal_strings.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/038literal_strings.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: Allow instructions to mention literals directly.</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//:</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: This layer will transparently move them to the global segment (assumed to</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: always be the second segment).</span> +<span id="L5" class="LineNr"> 5 </span> +<span id="L6" class="LineNr"> 6 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L6'>test_transform_literal_string</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L7" class="LineNr"> 7 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Constant">"b8/copy </span><span class="cSpecial">\"</span><span class="Constant">test</span><span class="cSpecial">\"</span><span class="Constant">/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L10" class="LineNr"> 10 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// need an empty segment</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Delimiter">);</span> +<span id="L12" class="LineNr"> 12 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Constant">"transform: -- move literal strings to data segment</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Constant">"transform: adding global variable '__subx_global_1' containing </span><span class="cSpecial">\"</span><span class="Constant">test</span><span class="cSpecial">\"\n</span><span class="Constant">"</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Constant">"transform: <a href='011run.cc.html#L121'>line</a> after transform: 'b8 __subx_global_1'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Delimiter">);</span> +<span id="L17" class="LineNr"> 17 </span><span class="Delimiter">}</span> +<span id="L18" class="LineNr"> 18 </span> +<span id="L19" class="LineNr"> 19 </span><span class="Comment">//: We don't rely on any transforms running in previous layers, but this layer</span> +<span id="L20" class="LineNr"> 20 </span><span class="Comment">//: knows about labels and global variables and will emit them for previous</span> +<span id="L21" class="LineNr"> 21 </span><span class="Comment">//: layers to transform.</span> +<span id="L22" class="LineNr"> 22 </span><span class="Delimiter">:(after "Begin Transforms")</span> +<span id="L23" class="LineNr"> 23 </span><a href='031transforms.cc.html#L4'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='038literal_strings.cc.html#L30'>transform_literal_strings</a><span class="Delimiter">);</span> +<span id="L24" class="LineNr"> 24 </span> +<span id="L25" class="LineNr"> 25 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L26" class="LineNr"> 26 </span><span class="Normal">int</span> Next_auto_global = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L27" class="LineNr"> 27 </span><span class="Delimiter">:(before "End Reset")</span> +<span id="L28" class="LineNr"> 28 </span>Next_auto_global = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L29" class="LineNr"> 29 </span><span class="Delimiter">:(code)</span> +<span id="L30" class="LineNr"> 30 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L30'>transform_literal_strings</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L31" class="LineNr"> 31 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"-- move literal strings to data segment"</span> << end<span class="Delimiter">();</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L33" class="LineNr"> 33 </span> vector<line> new_lines<span class="Delimiter">;</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> s = <span class="Constant">0</span><span class="Delimiter">;</span> s < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">);</span> ++s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L35" class="LineNr"> 35 </span> segment& seg = p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>s<span class="Delimiter">);</span> +<span id="L36" class="LineNr"> 36 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"segment '"</span> << seg<span class="Delimiter">.</span>name << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>seg<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L38" class="LineNr"> 38 </span><span class="CommentedCode">//? cerr << seg.name << '/' << i << '\n';</span> +<span id="L39" class="LineNr"> 39 </span> line& <a href='011run.cc.html#L121'>line</a> = seg<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L40" class="LineNr"> 40 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span><a href='011run.cc.html#L121'>line</a><span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L41" class="LineNr"> 41 </span> word& curr = <a href='011run.cc.html#L121'>line</a><span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != <span class="Constant">'"'</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L43" class="LineNr"> 43 </span> ostringstream global_name<span class="Delimiter">;</span> +<span id="L44" class="LineNr"> 44 </span> global_name << <span class="Constant">"__subx_global_"</span> << Next_auto_global<span class="Delimiter">;</span> +<span id="L45" class="LineNr"> 45 </span> ++Next_auto_global<span class="Delimiter">;</span> +<span id="L46" class="LineNr"> 46 </span> <a href='038literal_strings.cc.html#L57'>add_global_to_data_segment</a><span class="Delimiter">(</span>global_name<span class="Delimiter">.</span>str<span class="Delimiter">(),</span> curr<span class="Delimiter">,</span> new_lines<span class="Delimiter">);</span> +<span id="L47" class="LineNr"> 47 </span> curr<span class="Delimiter">.</span>data = global_name<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Delimiter">}</span> +<span id="L49" class="LineNr"> 49 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"line after transform: '"</span> << data_to_string<span class="Delimiter">(</span>line<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Delimiter">}</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Delimiter">}</span> +<span id="L52" class="LineNr"> 52 </span> segment* data = find<span class="Delimiter">(</span>p<span class="Delimiter">,</span> <span class="Constant">"data"</span><span class="Delimiter">);</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>data<span class="Delimiter">)</span> +<span id="L54" class="LineNr"> 54 </span> data<span class="Delimiter">-></span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span>data<span class="Delimiter">-></span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>end<span class="Delimiter">(),</span> new_lines<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> new_lines<span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L55" class="LineNr"> 55 </span><span class="Delimiter">}</span> +<span id="L56" class="LineNr"> 56 </span> +<span id="L57" class="LineNr"> 57 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L57'>add_global_to_data_segment</a><span class="Delimiter">(</span><span class="Normal">const</span> string& <a href='011run.cc.html#L111'>name</a><span class="Delimiter">,</span> <span class="Normal">const</span> word& value<span class="Delimiter">,</span> vector<line>& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L58" class="LineNr"> 58 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"adding global variable '"</span> << name << <span class="Constant">"' containing "</span> << value<span class="Delimiter">.</span>data << end<span class="Delimiter">();</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Comment">// emit label</span> +<span id="L60" class="LineNr"> 60 </span> out<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>label<span class="Delimiter">(</span><a href='011run.cc.html#L111'>name</a><span class="Delimiter">));</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Comment">// emit size for size-prefixed array</span> +<span id="L62" class="LineNr"> 62 </span> out<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='011run.cc.html#L121'>line</a><span class="Delimiter">());</span> +<span id="L63" class="LineNr"> 63 </span> emit_hex_bytes<span class="Delimiter">(</span>out<span class="Delimiter">.</span>back<span class="Delimiter">(),</span> <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>value<span class="Delimiter">.</span>data<span class="Delimiter">)</span>-<span class="Comment">/*</span><span class="Comment">skip quotes</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">4</span><span class="Comment">/*</span><span class="Comment">bytes</span><span class="Comment">*/</span><span class="Delimiter">);</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Comment">// emit data byte by byte</span> +<span id="L65" class="LineNr"> 65 </span> out<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='011run.cc.html#L121'>line</a><span class="Delimiter">());</span> +<span id="L66" class="LineNr"> 66 </span> line& curr = out<span class="Delimiter">.</span>back<span class="Delimiter">();</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Comment">/*</span><span class="Comment">skip start quote</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>value<span class="Delimiter">.</span>data<span class="Delimiter">)</span>-<span class="Comment">/*</span><span class="Comment">skip end quote</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Normal">char</span> c = value<span class="Delimiter">.</span>data<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L69" class="LineNr"> 69 </span> curr<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='011run.cc.html#L127'>word</a><span class="Delimiter">());</span> +<span id="L70" class="LineNr"> 70 </span> curr<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>data = <a href='032operands.cc.html#L327'>hex_byte_to_string</a><span class="Delimiter">(</span>c<span class="Delimiter">);</span> +<span id="L71" class="LineNr"> 71 </span> curr<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>string<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">,</span> c<span class="Delimiter">));</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Delimiter">}</span> +<span id="L73" class="LineNr"> 73 </span><span class="Delimiter">}</span> +<span id="L74" class="LineNr"> 74 </span> +<span id="L75" class="LineNr"> 75 </span><span class="Comment">//: Within strings, whitespace is significant. So we need to redo our instruction</span> +<span id="L76" class="LineNr"> 76 </span><span class="Comment">//: parsing.</span> +<span id="L77" class="LineNr"> 77 </span> +<span id="L78" class="LineNr"> 78 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L78'>test_instruction_with_string_literal</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L79" class="LineNr"> 79 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Constant">"a </span><span class="cSpecial">\"</span><span class="Constant">abc def</span><span class="cSpecial">\"</span><span class="Constant"> z</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// two spaces inside string</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Delimiter">);</span> +<span id="L82" class="LineNr"> 82 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: </span><span class="cSpecial">\"</span><span class="Constant">abc def</span><span class="cSpecial">\"\n</span><span class="Constant">"</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: z</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Delimiter">);</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Comment">// no other words</span> +<span id="L88" class="LineNr"> 88 </span> <a href='003trace.cc.html#L294'>CHECK_TRACE_COUNT</a><span class="Delimiter">(</span><span class="Constant">"parse2"</span><span class="Delimiter">,</span> <span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L89" class="LineNr"> 89 </span><span class="Delimiter">}</span> +<span id="L90" class="LineNr"> 90 </span> +<span id="L91" class="LineNr"> 91 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L91'>test_string_literal_in_data_segment</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L92" class="LineNr"> 92 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Constant">"b8/copy X/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Constant">"X:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">test</span><span class="cSpecial">\"</span><span class="Constant">/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Delimiter">);</span> +<span id="L99" class="LineNr"> 99 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L100" class="LineNr">100 </span> <span class="Constant">"transform: -- move literal strings to data segment</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L101" class="LineNr">101 </span> <span class="Constant">"transform: adding global variable '__subx_global_1' containing </span><span class="cSpecial">\"</span><span class="Constant">test</span><span class="cSpecial">\"\n</span><span class="Constant">"</span> +<span id="L102" class="LineNr">102 </span> <span class="Constant">"transform: <a href='011run.cc.html#L121'>line</a> after transform: '__subx_global_1'</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L103" class="LineNr">103 </span> <span class="Delimiter">);</span> +<span id="L104" class="LineNr">104 </span><span class="Delimiter">}</span> +<span id="L105" class="LineNr">105 </span> +<span id="L106" class="LineNr">106 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L106'>test_string_literal_with_missing_quote</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L107" class="LineNr">107 </span> Hide_errors = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L108" class="LineNr">108 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L109" class="LineNr">109 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L110" class="LineNr">110 </span> <span class="Constant">"b8/copy </span><span class="cSpecial">\"</span><span class="Constant">test/imm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L111" class="LineNr">111 </span> <span class="Constant">"== data 0x2000</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L112" class="LineNr">112 </span> <span class="Delimiter">);</span> +<span id="L113" class="LineNr">113 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L114" class="LineNr">114 </span> <span class="Constant">"error: unclosed string in: b8/copy </span><span class="cSpecial">\"</span><span class="Constant">test/imm32"</span> +<span id="L115" class="LineNr">115 </span> <span class="Delimiter">);</span> +<span id="L116" class="LineNr">116 </span><span class="Delimiter">}</span> +<span id="L117" class="LineNr">117 </span> +<span id="L118" class="LineNr">118 </span><span class="Delimiter">:(before "End Line Parsing Special-cases(line_data -> l)")</span> +<span id="L119" class="LineNr">119 </span><span class="Normal">if</span> <span class="Delimiter">(</span>line_data<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">'"'</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// can cause false-positives, but we can handle them</span> +<span id="L120" class="LineNr">120 </span> parse_instruction_character_by_character<span class="Delimiter">(</span>line_data<span class="Delimiter">,</span> l<span class="Delimiter">);</span> +<span id="L121" class="LineNr">121 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L122" class="LineNr">122 </span><span class="Delimiter">}</span> +<span id="L123" class="LineNr">123 </span> +<span id="L124" class="LineNr">124 </span><span class="Delimiter">:(code)</span> +<span id="L125" class="LineNr">125 </span><span class="Normal">void</span> parse_instruction_character_by_character<span class="Delimiter">(</span><span class="Normal">const</span> string& line_data<span class="Delimiter">,</span> vector<line>& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L126" class="LineNr">126 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>line_data<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="cSpecial">'\n'</span><span class="Delimiter">)</span> != string::npos && line_data<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="cSpecial">'\n'</span><span class="Delimiter">)</span> != line_data<span class="Delimiter">.</span>size<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L127" class="LineNr">127 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"parse_instruction_character_by_character: should receive only a single <a href='011run.cc.html#L121'>line</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L128" class="LineNr">128 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L129" class="LineNr">129 </span> <span class="Delimiter">}</span> +<span id="L130" class="LineNr">130 </span> <span class="Comment">// parse literals</span> +<span id="L131" class="LineNr">131 </span> istringstream in<span class="Delimiter">(</span>line_data<span class="Delimiter">);</span> +<span id="L132" class="LineNr">132 </span> in >> std::noskipws<span class="Delimiter">;</span> +<span id="L133" class="LineNr">133 </span> <a href='011run.cc.html#L121'>line</a> result<span class="Delimiter">;</span> +<span id="L134" class="LineNr">134 </span> result<span class="Delimiter">.</span>original = line_data<span class="Delimiter">;</span> +<span id="L135" class="LineNr">135 </span> <span class="Comment">// add tokens (words or strings) one by one</span> +<span id="L136" class="LineNr">136 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L249'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L137" class="LineNr">137 </span> <a href='038literal_strings.cc.html#L205'>skip_whitespace</a><span class="Delimiter">(</span>in<span class="Delimiter">);</span> +<span id="L138" class="LineNr">138 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L139" class="LineNr">139 </span> <span class="Normal">char</span> c = in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> +<span id="L140" class="LineNr">140 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// comment; drop rest of line</span> +<span id="L141" class="LineNr">141 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">':'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// line metadata; skip for now</span> +<span id="L142" class="LineNr">142 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'.'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L143" class="LineNr">143 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// comment token at end of line</span> +<span id="L144" class="LineNr">144 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> +<span id="L145" class="LineNr">145 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// '.' followed by space is comment token; skip</span> +<span id="L146" class="LineNr">146 </span> <span class="Delimiter">}</span> +<span id="L147" class="LineNr">147 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='011run.cc.html#L127'>word</a><span class="Delimiter">());</span> +<span id="L148" class="LineNr">148 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'"'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L149" class="LineNr">149 </span> <span class="Comment">// string literal; slurp everything between quotes into data</span> +<span id="L150" class="LineNr">150 </span> ostringstream d<span class="Delimiter">;</span> +<span id="L151" class="LineNr">151 </span> d << c<span class="Delimiter">;</span> +<span id="L152" class="LineNr">152 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L153" class="LineNr">153 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L154" class="LineNr">154 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"unclosed string in: "</span> << line_data << end<span class="Delimiter">();</span> +<span id="L155" class="LineNr">155 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L156" class="LineNr">156 </span> <span class="Delimiter">}</span> +<span id="L157" class="LineNr">157 </span> in >> c<span class="Delimiter">;</span> +<span id="L158" class="LineNr">158 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="cSpecial">'\\'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L159" class="LineNr">159 </span> in >> c<span class="Delimiter">;</span> +<span id="L160" class="LineNr">160 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'n'</span><span class="Delimiter">)</span> d << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L161" class="LineNr">161 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'"'</span><span class="Delimiter">)</span> d << <span class="Constant">'"'</span><span class="Delimiter">;</span> +<span id="L162" class="LineNr">162 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="cSpecial">'\\'</span><span class="Delimiter">)</span> d << <span class="cSpecial">'\\'</span><span class="Delimiter">;</span> +<span id="L163" class="LineNr">163 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L164" class="LineNr">164 </span> <a href='003trace.cc.html#L226'>raise</a> << <span class="Constant">"parse_instruction_character_by_character: unknown escape sequence '</span><span class="cSpecial">\\</span><span class="Constant">"</span> << c << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L165" class="LineNr">165 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L166" class="LineNr">166 </span> <span class="Delimiter">}</span> +<span id="L167" class="LineNr">167 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L168" class="LineNr">168 </span> <span class="Delimiter">}</span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L169" class="LineNr">169 </span> d << c<span class="Delimiter">;</span> +<span id="L170" class="LineNr">170 </span> <span class="Delimiter">}</span> +<span id="L171" class="LineNr">171 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'"'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L172" class="LineNr">172 </span> <span class="Delimiter">}</span> +<span id="L173" class="LineNr">173 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>data = d<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L174" class="LineNr">174 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>original = d<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L175" class="LineNr">175 </span> <span class="Comment">// slurp metadata</span> +<span id="L176" class="LineNr">176 </span> ostringstream m<span class="Delimiter">;</span> +<span id="L177" class="LineNr">177 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>!isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">())</span> && <a href='001help.cc.html#L249'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// peek can sometimes trigger eof(), so do it first</span> +<span id="L178" class="LineNr">178 </span> in >> c<span class="Delimiter">;</span> +<span id="L179" class="LineNr">179 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'/'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L180" class="LineNr">180 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!m<span class="Delimiter">.</span>str<span class="Delimiter">().</span>empty<span class="Delimiter">())</span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>m<span class="Delimiter">.</span>str<span class="Delimiter">());</span> +<span id="L181" class="LineNr">181 </span> m<span class="Delimiter">.</span>str<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L182" class="LineNr">182 </span> <span class="Delimiter">}</span> +<span id="L183" class="LineNr">183 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L184" class="LineNr">184 </span> m << c<span class="Delimiter">;</span> +<span id="L185" class="LineNr">185 </span> <span class="Delimiter">}</span> +<span id="L186" class="LineNr">186 </span> <span class="Delimiter">}</span> +<span id="L187" class="LineNr">187 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!m<span class="Delimiter">.</span>str<span class="Delimiter">().</span>empty<span class="Delimiter">())</span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>m<span class="Delimiter">.</span>str<span class="Delimiter">());</span> +<span id="L188" class="LineNr">188 </span> <span class="Delimiter">}</span> +<span id="L189" class="LineNr">189 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L190" class="LineNr">190 </span> <span class="Comment">// not a string literal; slurp all characters until whitespace</span> +<span id="L191" class="LineNr">191 </span> ostringstream w<span class="Delimiter">;</span> +<span id="L192" class="LineNr">192 </span> w << c<span class="Delimiter">;</span> +<span id="L193" class="LineNr">193 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>!isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">())</span> && <a href='001help.cc.html#L249'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// peek can sometimes trigger eof(), so do it first</span> +<span id="L194" class="LineNr">194 </span> in >> c<span class="Delimiter">;</span> +<span id="L195" class="LineNr">195 </span> w << c<span class="Delimiter">;</span> +<span id="L196" class="LineNr">196 </span> <span class="Delimiter">}</span> +<span id="L197" class="LineNr">197 </span> <a href='011run.cc.html#L209'>parse_word</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>str<span class="Delimiter">(),</span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">());</span> +<span id="L198" class="LineNr">198 </span> <span class="Delimiter">}</span> +<span id="L199" class="LineNr">199 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse2"</span><span class="Delimiter">)</span> << <span class="Constant">"word: "</span> << to_string<span class="Delimiter">(</span>result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">())</span> << end<span class="Delimiter">();</span> +<span id="L200" class="LineNr">200 </span> <span class="Delimiter">}</span> +<span id="L201" class="LineNr">201 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> +<span id="L202" class="LineNr">202 </span> out<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>result<span class="Delimiter">);</span> +<span id="L203" class="LineNr">203 </span><span class="Delimiter">}</span> +<span id="L204" class="LineNr">204 </span> +<span id="L205" class="LineNr">205 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L205'>skip_whitespace</a><span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L206" class="LineNr">206 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L249'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">)</span> && isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> <span class="Delimiter">{</span> +<span id="L207" class="LineNr">207 </span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> +<span id="L208" class="LineNr">208 </span> <span class="Delimiter">}</span> +<span id="L209" class="LineNr">209 </span><span class="Delimiter">}</span> +<span id="L210" class="LineNr">210 </span> +<span id="L211" class="LineNr">211 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L211'>skip_comment</a><span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L212" class="LineNr">212 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L249'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">)</span> && in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L213" class="LineNr">213 </span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> +<span id="L214" class="LineNr">214 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L249'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">)</span> && in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> +<span id="L215" class="LineNr">215 </span> <span class="Delimiter">}</span> +<span id="L216" class="LineNr">216 </span><span class="Delimiter">}</span> +<span id="L217" class="LineNr">217 </span> +<span id="L218" class="LineNr">218 </span><a href='011run.cc.html#L121'>line</a> label<span class="Delimiter">(</span>string s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L219" class="LineNr">219 </span> <a href='011run.cc.html#L121'>line</a> result<span class="Delimiter">;</span> +<span id="L220" class="LineNr">220 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='011run.cc.html#L127'>word</a><span class="Delimiter">());</span> +<span id="L221" class="LineNr">221 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>data = <span class="Delimiter">(</span>s+<span class="Constant">":"</span><span class="Delimiter">);</span> +<span id="L222" class="LineNr">222 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L223" class="LineNr">223 </span><span class="Delimiter">}</span> +<span id="L224" class="LineNr">224 </span> +<span id="L225" class="LineNr">225 </span><span class="Comment">// helper for tests</span> +<span id="L226" class="LineNr">226 </span><span class="Normal">void</span> parse_instruction_character_by_character<span class="Delimiter">(</span><span class="Normal">const</span> string& line_data<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L227" class="LineNr">227 </span> vector<line> out<span class="Delimiter">;</span> +<span id="L228" class="LineNr">228 </span> parse_instruction_character_by_character<span class="Delimiter">(</span>line_data<span class="Delimiter">,</span> out<span class="Delimiter">);</span> +<span id="L229" class="LineNr">229 </span><span class="Delimiter">}</span> +<span id="L230" class="LineNr">230 </span> +<span id="L231" class="LineNr">231 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L231'>test_parse2_comment_token_in_middle</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L232" class="LineNr">232 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L233" class="LineNr">233 </span> <span class="Constant">"a . z</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L234" class="LineNr">234 </span> <span class="Delimiter">);</span> +<span id="L235" class="LineNr">235 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L236" class="LineNr">236 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L237" class="LineNr">237 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: z</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L238" class="LineNr">238 </span> <span class="Delimiter">);</span> +<span id="L239" class="LineNr">239 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: ."</span><span class="Delimiter">);</span> +<span id="L240" class="LineNr">240 </span> <span class="Comment">// no other words</span> +<span id="L241" class="LineNr">241 </span> <a href='003trace.cc.html#L294'>CHECK_TRACE_COUNT</a><span class="Delimiter">(</span><span class="Constant">"parse2"</span><span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L242" class="LineNr">242 </span><span class="Delimiter">}</span> +<span id="L243" class="LineNr">243 </span> +<span id="L244" class="LineNr">244 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L244'>test_parse2_word_starting_with_dot</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L245" class="LineNr">245 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L246" class="LineNr">246 </span> <span class="Constant">"a .b c</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L247" class="LineNr">247 </span> <span class="Delimiter">);</span> +<span id="L248" class="LineNr">248 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L249" class="LineNr">249 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L250" class="LineNr">250 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: .b</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L251" class="LineNr">251 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: c</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L252" class="LineNr">252 </span> <span class="Delimiter">);</span> +<span id="L253" class="LineNr">253 </span><span class="Delimiter">}</span> +<span id="L254" class="LineNr">254 </span> +<span id="L255" class="LineNr">255 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L255'>test_parse2_comment_token_at_start</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L256" class="LineNr">256 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L257" class="LineNr">257 </span> <span class="Constant">". a b</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L258" class="LineNr">258 </span> <span class="Delimiter">);</span> +<span id="L259" class="LineNr">259 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L260" class="LineNr">260 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L261" class="LineNr">261 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: b</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L262" class="LineNr">262 </span> <span class="Delimiter">);</span> +<span id="L263" class="LineNr">263 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: ."</span><span class="Delimiter">);</span> +<span id="L264" class="LineNr">264 </span><span class="Delimiter">}</span> +<span id="L265" class="LineNr">265 </span> +<span id="L266" class="LineNr">266 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L266'>test_parse2_comment_token_at_end</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L267" class="LineNr">267 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L268" class="LineNr">268 </span> <span class="Constant">"a b .</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L269" class="LineNr">269 </span> <span class="Delimiter">);</span> +<span id="L270" class="LineNr">270 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L271" class="LineNr">271 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L272" class="LineNr">272 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: b</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L273" class="LineNr">273 </span> <span class="Delimiter">);</span> +<span id="L274" class="LineNr">274 </span> <a href='003trace.cc.html#L292'>CHECK_TRACE_DOESNT_CONTAIN</a><span class="Delimiter">(</span><span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: ."</span><span class="Delimiter">);</span> +<span id="L275" class="LineNr">275 </span><span class="Delimiter">}</span> +<span id="L276" class="LineNr">276 </span> +<span id="L277" class="LineNr">277 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L277'>test_parse2_word_starting_with_dot_at_start</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L278" class="LineNr">278 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L279" class="LineNr">279 </span> <span class="Constant">".a b c</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L280" class="LineNr">280 </span> <span class="Delimiter">);</span> +<span id="L281" class="LineNr">281 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L282" class="LineNr">282 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: .a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L283" class="LineNr">283 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: b</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L284" class="LineNr">284 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: c</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L285" class="LineNr">285 </span> <span class="Delimiter">);</span> +<span id="L286" class="LineNr">286 </span><span class="Delimiter">}</span> +<span id="L287" class="LineNr">287 </span> +<span id="L288" class="LineNr">288 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L288'>test_parse2_metadata</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L289" class="LineNr">289 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L290" class="LineNr">290 </span> <span class="Constant">".a b/c d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L291" class="LineNr">291 </span> <span class="Delimiter">);</span> +<span id="L292" class="LineNr">292 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L293" class="LineNr">293 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: .a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L294" class="LineNr">294 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: b /c</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L295" class="LineNr">295 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: d</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L296" class="LineNr">296 </span> <span class="Delimiter">);</span> +<span id="L297" class="LineNr">297 </span><span class="Delimiter">}</span> +<span id="L298" class="LineNr">298 </span> +<span id="L299" class="LineNr">299 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L299'>test_parse2_string_with_metadata</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L300" class="LineNr">300 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L301" class="LineNr">301 </span> <span class="Constant">"a </span><span class="cSpecial">\"</span><span class="Constant">bc def</span><span class="cSpecial">\"</span><span class="Constant">/disp32 g</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L302" class="LineNr">302 </span> <span class="Delimiter">);</span> +<span id="L303" class="LineNr">303 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L304" class="LineNr">304 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L305" class="LineNr">305 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: </span><span class="cSpecial">\"</span><span class="Constant">bc def</span><span class="cSpecial">\"</span><span class="Constant"> /disp32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L306" class="LineNr">306 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: g</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L307" class="LineNr">307 </span> <span class="Delimiter">);</span> +<span id="L308" class="LineNr">308 </span><span class="Delimiter">}</span> +<span id="L309" class="LineNr">309 </span> +<span id="L310" class="LineNr">310 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L310'>test_parse2_string_with_metadata_at_end</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L311" class="LineNr">311 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L312" class="LineNr">312 </span> <span class="Constant">"a </span><span class="cSpecial">\"</span><span class="Constant">bc def</span><span class="cSpecial">\"</span><span class="Constant">/disp32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L313" class="LineNr">313 </span> <span class="Delimiter">);</span> +<span id="L314" class="LineNr">314 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L315" class="LineNr">315 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: a</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L316" class="LineNr">316 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: </span><span class="cSpecial">\"</span><span class="Constant">bc def</span><span class="cSpecial">\"</span><span class="Constant"> /disp32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L317" class="LineNr">317 </span> <span class="Delimiter">);</span> +<span id="L318" class="LineNr">318 </span><span class="Delimiter">}</span> +<span id="L319" class="LineNr">319 </span> +<span id="L320" class="LineNr">320 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L320'>test_parse2_string_with_metadata_at_end_of_line_without_newline</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L321" class="LineNr">321 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L322" class="LineNr">322 </span> <span class="Constant">"68/push </span><span class="cSpecial">\"</span><span class="Constant">test</span><span class="cSpecial">\"</span><span class="Constant">/f"</span> <span class="Comment">// no newline, which is how calls from parse() will look</span> +<span id="L323" class="LineNr">323 </span> <span class="Delimiter">);</span> +<span id="L324" class="LineNr">324 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L325" class="LineNr">325 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: 68 /push</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L326" class="LineNr">326 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: </span><span class="cSpecial">\"</span><span class="Constant">test</span><span class="cSpecial">\"</span><span class="Constant"> /f</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L327" class="LineNr">327 </span> <span class="Delimiter">);</span> +<span id="L328" class="LineNr">328 </span><span class="Delimiter">}</span> +<span id="L329" class="LineNr">329 </span> +<span id="L330" class="LineNr">330 </span><span class="Comment">//: Make sure slashes inside strings don't trigger adding stuff from inside the</span> +<span id="L331" class="LineNr">331 </span><span class="Comment">//: string to metadata.</span> +<span id="L332" class="LineNr">332 </span> +<span id="L333" class="LineNr">333 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L333'>test_parse2_string_containing_slashes</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L334" class="LineNr">334 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L335" class="LineNr">335 </span> <span class="Constant">"a </span><span class="cSpecial">\"</span><span class="Constant">bc/def</span><span class="cSpecial">\"</span><span class="Constant">/disp32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L336" class="LineNr">336 </span> <span class="Delimiter">);</span> +<span id="L337" class="LineNr">337 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L338" class="LineNr">338 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: </span><span class="cSpecial">\"</span><span class="Constant">bc/def</span><span class="cSpecial">\"</span><span class="Constant"> /disp32</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L339" class="LineNr">339 </span> <span class="Delimiter">);</span> +<span id="L340" class="LineNr">340 </span><span class="Delimiter">}</span> +<span id="L341" class="LineNr">341 </span> +<span id="L342" class="LineNr">342 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L342'>test_instruction_with_string_literal_with_escaped_quote</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L343" class="LineNr">343 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L344" class="LineNr">344 </span> <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">a</span><span class="cSpecial">\\\"</span><span class="Constant">b</span><span class="cSpecial">\"\n</span><span class="Constant">"</span> <span class="Comment">// escaped quote inside string</span> +<span id="L345" class="LineNr">345 </span> <span class="Delimiter">);</span> +<span id="L346" class="LineNr">346 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L347" class="LineNr">347 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: </span><span class="cSpecial">\"</span><span class="Constant">a</span><span class="cSpecial">\"</span><span class="Constant">b</span><span class="cSpecial">\"\n</span><span class="Constant">"</span> +<span id="L348" class="LineNr">348 </span> <span class="Delimiter">);</span> +<span id="L349" class="LineNr">349 </span> <span class="Comment">// no other words</span> +<span id="L350" class="LineNr">350 </span> <a href='003trace.cc.html#L294'>CHECK_TRACE_COUNT</a><span class="Delimiter">(</span><span class="Constant">"parse2"</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L351" class="LineNr">351 </span><span class="Delimiter">}</span> +<span id="L352" class="LineNr">352 </span> +<span id="L353" class="LineNr">353 </span><span class="Normal">void</span> <a href='038literal_strings.cc.html#L353'>test_instruction_with_string_literal_with_escaped_backslash</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L354" class="LineNr">354 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L355" class="LineNr">355 </span> <span class="Constant">"</span><span class="cSpecial">\"</span><span class="Constant">a</span><span class="cSpecial">\\\\</span><span class="Constant">b</span><span class="cSpecial">\"\n</span><span class="Constant">"</span> <span class="Comment">// escaped backslash inside string</span> +<span id="L356" class="LineNr">356 </span> <span class="Delimiter">);</span> +<span id="L357" class="LineNr">357 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L358" class="LineNr">358 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L127'>word</a>: </span><span class="cSpecial">\"</span><span class="Constant">a</span><span class="cSpecial">\\</span><span class="Constant">b</span><span class="cSpecial">\"\n</span><span class="Constant">"</span> +<span id="L359" class="LineNr">359 </span> <span class="Delimiter">);</span> +<span id="L360" class="LineNr">360 </span> <span class="Comment">// no other words</span> +<span id="L361" class="LineNr">361 </span> <a href='003trace.cc.html#L294'>CHECK_TRACE_COUNT</a><span class="Delimiter">(</span><span class="Constant">"parse2"</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L362" class="LineNr">362 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/039debug.cc.html b/html/linux/bootstrap/039debug.cc.html new file mode 100644 index 00000000..6df286a0 --- /dev/null +++ b/html/linux/bootstrap/039debug.cc.html @@ -0,0 +1,237 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/039debug.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.Todo { color: #000000; background-color: #ffff00; padding-bottom: 1px; } +.LineNr { } +.Constant { color: #008787; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/039debug.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/039debug.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//:: Some helpers for debugging.</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: Load the 'map' file generated during 'bootstrap --debug translate' when running</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: 'bootstrap --trace run'.</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: (It'll only affect the trace.)</span> +<span id="L6" class="LineNr"> 6 </span> +<span id="L7" class="LineNr"> 7 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L8" class="LineNr"> 8 </span>map<<span class="Comment">/*</span><span class="Comment">address</span><span class="Comment">*/</span><span class="Normal">uint32_t</span><span class="Delimiter">,</span> string> <a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">;</span> <span class="Comment">// used only by 'bootstrap run'</span> +<span id="L9" class="LineNr"> 9 </span>map<<span class="Comment">/*</span><span class="Comment">address</span><span class="Comment">*/</span><span class="Normal">uint32_t</span><span class="Delimiter">,</span> string> <a href='039debug.cc.html#L9'>Source_line</a><span class="Delimiter">;</span> <span class="Comment">// used only by 'bootstrap run'</span> +<span id="L10" class="LineNr"> 10 </span><span class="Delimiter">:(before "End --trace Settings")</span> +<span id="L11" class="LineNr"> 11 </span><a href='039debug.cc.html#L14'>load_labels</a><span class="Delimiter">();</span> +<span id="L12" class="LineNr"> 12 </span><a href='039debug.cc.html#L27'>load_source_lines</a><span class="Delimiter">();</span> +<span id="L13" class="LineNr"> 13 </span><span class="Delimiter">:(code)</span> +<span id="L14" class="LineNr"> 14 </span><span class="Normal">void</span> <a href='039debug.cc.html#L14'>load_labels</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L15" class="LineNr"> 15 </span> ifstream fin<span class="Delimiter">(</span><span class="Constant">"labels"</span><span class="Delimiter">);</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>fin<span class="Delimiter">.</span>fail<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L17" class="LineNr"> 17 </span> fin >> std::hex<span class="Delimiter">;</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L249'>has_data</a><span class="Delimiter">(</span>fin<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Normal">uint32_t</span> addr = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L20" class="LineNr"> 20 </span> fin >> addr<span class="Delimiter">;</span> +<span id="L21" class="LineNr"> 21 </span> string <a href='011run.cc.html#L111'>name</a><span class="Delimiter">;</span> +<span id="L22" class="LineNr"> 22 </span> fin >> <a href='011run.cc.html#L111'>name</a><span class="Delimiter">;</span> +<span id="L23" class="LineNr"> 23 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">,</span> addr<span class="Delimiter">,</span> <a href='011run.cc.html#L111'>name</a><span class="Delimiter">);</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Delimiter">}</span> +<span id="L25" class="LineNr"> 25 </span><span class="Delimiter">}</span> +<span id="L26" class="LineNr"> 26 </span> +<span id="L27" class="LineNr"> 27 </span><span class="Normal">void</span> <a href='039debug.cc.html#L27'>load_source_lines</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L28" class="LineNr"> 28 </span> ifstream fin<span class="Delimiter">(</span><span class="Constant">"source_lines"</span><span class="Delimiter">);</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>fin<span class="Delimiter">.</span>fail<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L30" class="LineNr"> 30 </span> fin >> std::hex<span class="Delimiter">;</span> +<span id="L31" class="LineNr"> 31 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L249'>has_data</a><span class="Delimiter">(</span>fin<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Normal">uint32_t</span> addr = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L33" class="LineNr"> 33 </span> fin >> addr<span class="Delimiter">;</span> +<span id="L34" class="LineNr"> 34 </span> string <a href='011run.cc.html#L121'>line</a><span class="Delimiter">;</span> +<span id="L35" class="LineNr"> 35 </span> getline<span class="Delimiter">(</span>fin<span class="Delimiter">,</span> <a href='011run.cc.html#L121'>line</a><span class="Delimiter">);</span> +<span id="L36" class="LineNr"> 36 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='039debug.cc.html#L9'>Source_line</a><span class="Delimiter">,</span> addr<span class="Delimiter">,</span> <a href='039debug.cc.html#L139'>hacky_squeeze_out_whitespace</a><span class="Delimiter">(</span><a href='011run.cc.html#L121'>line</a><span class="Delimiter">));</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Delimiter">}</span> +<span id="L38" class="LineNr"> 38 </span><span class="Delimiter">}</span> +<span id="L39" class="LineNr"> 39 </span> +<span id="L40" class="LineNr"> 40 </span><span class="Delimiter">:(after "Run One Instruction")</span> +<span id="L41" class="LineNr"> 41 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L231'>contains_key</a><span class="Delimiter">(</span><a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">,</span> <a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">))</span> +<span id="L42" class="LineNr"> 42 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"== label "</span> << get<span class="Delimiter">(</span><a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">,</span> <a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L43" class="LineNr"> 43 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L231'>contains_key</a><span class="Delimiter">(</span><a href='039debug.cc.html#L9'>Source_line</a><span class="Delimiter">,</span> <a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">))</span> +<span id="L44" class="LineNr"> 44 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"inst: "</span> << get<span class="Delimiter">(</span><a href='039debug.cc.html#L9'>Source_line</a><span class="Delimiter">,</span> <a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L45" class="LineNr"> 45 </span><span class="Normal">else</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Comment">// no source line info; do what you can</span> +<span id="L47" class="LineNr"> 47 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"inst: "</span> << <a href='039debug.cc.html#L50'>debug_info</a><span class="Delimiter">(</span><a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L48" class="LineNr"> 48 </span> +<span id="L49" class="LineNr"> 49 </span><span class="Delimiter">:(code)</span> +<span id="L50" class="LineNr"> 50 </span>string <a href='039debug.cc.html#L50'>debug_info</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> inst_address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Normal">uint8_t</span> op = <a href='010vm.cc.html#L174'>read_mem_u8</a><span class="Delimiter">(</span>inst_address<span class="Delimiter">);</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>op != <span class="Constant">0xe8</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L53" class="LineNr"> 53 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L54" class="LineNr"> 54 </span> out << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span>op<span class="Delimiter">);</span> +<span id="L55" class="LineNr"> 55 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Delimiter">}</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Normal">int32_t</span> offset = <a href='010vm.cc.html#L185'>read_mem_i32</a><span class="Delimiter">(</span>inst_address+<span class="Comment">/*</span><span class="Comment">skip op</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Normal">uint32_t</span> next_eip = inst_address+<span class="Comment">/*</span><span class="Comment">inst length</span><span class="Comment">*/</span><span class="Constant">5</span>+offset<span class="Delimiter">;</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L231'>contains_key</a><span class="Delimiter">(</span><a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">,</span> next_eip<span class="Delimiter">))</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Identifier">return</span> <span class="Constant">"e8/call "</span>+get<span class="Delimiter">(</span><a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">,</span> next_eip<span class="Delimiter">);</span> +<span id="L61" class="LineNr"> 61 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L62" class="LineNr"> 62 </span> out << <span class="Constant">"e8/call 0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << next_eip<span class="Delimiter">;</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L64" class="LineNr"> 64 </span><span class="Delimiter">}</span> +<span id="L65" class="LineNr"> 65 </span> +<span id="L66" class="LineNr"> 66 </span><span class="Comment">//: If a label starts with '$watch-', make a note of the effective address</span> +<span id="L67" class="LineNr"> 67 </span><span class="Comment">//: computed by the next instruction. Start dumping out its contents to the</span> +<span id="L68" class="LineNr"> 68 </span><span class="Comment">//: trace after every subsequent instruction.</span> +<span id="L69" class="LineNr"> 69 </span> +<span id="L70" class="LineNr"> 70 </span><span class="Delimiter">:(after "Run One Instruction")</span> +<span id="L71" class="LineNr"> 71 </span><a href='039debug.cc.html#L77'>dump_watch_points</a><span class="Delimiter">();</span> +<span id="L72" class="LineNr"> 72 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L73" class="LineNr"> 73 </span>map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>> <a href='039debug.cc.html#L73'>Watch_points</a><span class="Delimiter">;</span> +<span id="L74" class="LineNr"> 74 </span><span class="Delimiter">:(before "End Reset")</span> +<span id="L75" class="LineNr"> 75 </span><a href='039debug.cc.html#L73'>Watch_points</a><span class="Delimiter">.</span>clear<span class="Delimiter">();</span> +<span id="L76" class="LineNr"> 76 </span><span class="Delimiter">:(code)</span> +<span id="L77" class="LineNr"> 77 </span><span class="Normal">void</span> <a href='039debug.cc.html#L77'>dump_watch_points</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='039debug.cc.html#L73'>Watch_points</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L79" class="LineNr"> 79 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth<span class="Delimiter">,</span> <span class="Constant">"dbg"</span><span class="Delimiter">)</span> << <span class="Constant">"watch points:"</span> << end<span class="Delimiter">();</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>>::iterator p = <a href='039debug.cc.html#L73'>Watch_points</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='039debug.cc.html#L73'>Watch_points</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> +<span id="L81" class="LineNr"> 81 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span>Callstack_depth<span class="Delimiter">,</span> <span class="Constant">"dbg"</span><span class="Delimiter">)</span> << <span class="Constant">" "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << p<span class="Delimiter">-></span>second << <span class="Constant">" -> "</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span>p<span class="Delimiter">-></span>second<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L82" class="LineNr"> 82 </span><span class="Delimiter">}</span> +<span id="L83" class="LineNr"> 83 </span> +<span id="L84" class="LineNr"> 84 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L85" class="LineNr"> 85 </span>string Watch_this_effective_address<span class="Delimiter">;</span> +<span id="L86" class="LineNr"> 86 </span><span class="Delimiter">:(after "Run One Instruction")</span> +<span id="L87" class="LineNr"> 87 </span>Watch_this_effective_address = <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L88" class="LineNr"> 88 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L231'>contains_key</a><span class="Delimiter">(</span><a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">,</span> <a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">)</span> && <a href='001help.cc.html#L104'>starts_with</a><span class="Delimiter">(</span>get<span class="Delimiter">(</span><a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">,</span> <a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">),</span> <span class="Constant">"$watch-"</span><span class="Delimiter">))</span> +<span id="L89" class="LineNr"> 89 </span> Watch_this_effective_address = get<span class="Delimiter">(</span><a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">,</span> <a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">);</span> +<span id="L90" class="LineNr"> 90 </span><span class="Delimiter">:(after "Found <a href='013direct_addressing.cc.html#L101'>effective_address</a>(addr)")</span> +<span id="L91" class="LineNr"> 91 </span><span class="Normal">if</span> <span class="Delimiter">(</span>!Watch_this_effective_address<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L92" class="LineNr"> 92 </span> <a href='003trace.cc.html#L439'>dbg</a> << <span class="Constant">"now watching "</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">" for "</span> << Watch_this_effective_address << end<span class="Delimiter">();</span> +<span id="L93" class="LineNr"> 93 </span> <a href='001help.cc.html#L227'>put</a><span class="Delimiter">(</span><a href='039debug.cc.html#L73'>Watch_points</a><span class="Delimiter">,</span> Watch_this_effective_address<span class="Delimiter">,</span> addr<span class="Delimiter">);</span> +<span id="L94" class="LineNr"> 94 </span><span class="Delimiter">}</span> +<span id="L95" class="LineNr"> 95 </span> +<span id="L96" class="LineNr"> 96 </span><span class="Comment">//: If a label starts with '$dump-stack', dump out to the trace n bytes on</span> +<span id="L97" class="LineNr"> 97 </span><span class="Comment">//: either side of ESP.</span> +<span id="L98" class="LineNr"> 98 </span> +<span id="L99" class="LineNr"> 99 </span><span class="Delimiter">:(after "Run One Instruction")</span> +<span id="L100" class="LineNr">100 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L231'>contains_key</a><span class="Delimiter">(</span><a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">,</span> <a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">)</span> && <a href='001help.cc.html#L104'>starts_with</a><span class="Delimiter">(</span>get<span class="Delimiter">(</span><a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">,</span> <a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">),</span> <span class="Constant">"$dump-stack"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L101" class="LineNr">101 </span> dump_stack<span class="Delimiter">(</span><span class="Constant">64</span><span class="Delimiter">);</span> +<span id="L102" class="LineNr">102 </span><span class="Delimiter">}</span> +<span id="L103" class="LineNr">103 </span><span class="Delimiter">:(code)</span> +<span id="L104" class="LineNr">104 </span><span class="Normal">void</span> dump_stack<span class="Delimiter">(</span><span class="Normal">int</span> n<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L105" class="LineNr">105 </span> <span class="Normal">uint32_t</span> stack_pointer = Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L106" class="LineNr">106 </span> <span class="Normal">uint32_t</span> start = <span class="Delimiter">((</span>stack_pointer-n<span class="Delimiter">)</span>&<span class="Constant">0xfffffff0</span><span class="Delimiter">);</span> +<span id="L107" class="LineNr">107 </span> <a href='003trace.cc.html#L439'>dbg</a> << <span class="Constant">"stack:"</span> << end<span class="Delimiter">();</span> +<span id="L108" class="LineNr">108 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr = start<span class="Delimiter">;</span> addr < start+n*<span class="Constant">2</span><span class="Delimiter">;</span> addr+=<span class="Constant">16</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L109" class="LineNr">109 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>addr >= <a href='012elf.cc.html#L153'>AFTER_STACK</a><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L110" class="LineNr">110 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L111" class="LineNr">111 </span> out << <a href='010vm.cc.html#L408'>HEXWORD</a> << addr << <span class="Constant">":"</span><span class="Delimiter">;</span> +<span id="L112" class="LineNr">112 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Constant">16</span><span class="Delimiter">;</span> i+=<span class="Constant">4</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L113" class="LineNr">113 </span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> +<span id="L114" class="LineNr">114 </span> out << <span class="Delimiter">((</span>addr+i == stack_pointer<span class="Delimiter">)</span> ? <span class="Constant">'['</span> : <span class="Constant">' '</span><span class="Delimiter">);</span> +<span id="L115" class="LineNr">115 </span> out << <a href='010vm.cc.html#L408'>HEXWORD</a> << <a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span>addr+i<span class="Delimiter">);</span> +<span id="L116" class="LineNr">116 </span> out << <span class="Delimiter">((</span>addr+i == stack_pointer<span class="Delimiter">)</span> ? <span class="Constant">']'</span> : <span class="Constant">' '</span><span class="Delimiter">);</span> +<span id="L117" class="LineNr">117 </span> <span class="Delimiter">}</span> +<span id="L118" class="LineNr">118 </span> <a href='003trace.cc.html#L439'>dbg</a> << out<span class="Delimiter">.</span>str<span class="Delimiter">()</span> << end<span class="Delimiter">();</span> +<span id="L119" class="LineNr">119 </span> <span class="Delimiter">}</span> +<span id="L120" class="LineNr">120 </span><span class="Delimiter">}</span> +<span id="L121" class="LineNr">121 </span> +<span id="L122" class="LineNr">122 </span><span class="Comment">//: Special label that dumps regions of memory.</span> +<span id="L123" class="LineNr">123 </span><span class="Comment">//: Not a general mechanism; by the time you get here you're willing to hack</span> +<span id="L124" class="LineNr">124 </span><span class="Comment">//: on the emulator.</span> +<span id="L125" class="LineNr">125 </span><span class="Delimiter">:(after "Run One Instruction")</span> +<span id="L126" class="LineNr">126 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L231'>contains_key</a><span class="Delimiter">(</span><a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">,</span> <a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">)</span> && get<span class="Delimiter">(</span><a href='039debug.cc.html#L8'>Symbol_name</a><span class="Delimiter">,</span> <a href='010vm.cc.html#L26'>EIP</a><span class="Delimiter">)</span> == <span class="Constant">"$dump-stream-at-EAX"</span><span class="Delimiter">)</span> +<span id="L127" class="LineNr">127 </span> <a href='039debug.cc.html#L129'>dump_stream_at</a><span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L128" class="LineNr">128 </span><span class="Delimiter">:(code)</span> +<span id="L129" class="LineNr">129 </span><span class="Normal">void</span> <a href='039debug.cc.html#L129'>dump_stream_at</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> stream_start<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L130" class="LineNr">130 </span> <span class="Normal">int32_t</span> stream_length = <a href='010vm.cc.html#L185'>read_mem_i32</a><span class="Delimiter">(</span>stream_start + <span class="Constant">8</span><span class="Delimiter">);</span> +<span id="L131" class="LineNr">131 </span> <a href='003trace.cc.html#L439'>dbg</a> << <span class="Constant">"stream length: "</span> << std::dec << stream_length << end<span class="Delimiter">();</span> +<span id="L132" class="LineNr">132 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < stream_length + <span class="Constant">12</span><span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> +<span id="L133" class="LineNr">133 </span> <a href='003trace.cc.html#L439'>dbg</a> << <span class="Constant">"0x"</span> << <a href='010vm.cc.html#L408'>HEXWORD</a> << <span class="Delimiter">(</span>stream_start+i<span class="Delimiter">)</span> << <span class="Constant">": "</span> << <a href='010vm.cc.html#L407'>HEXBYTE</a> << <a href='010vm.cc.html#L410'>NUM</a><span class="Delimiter">(</span><a href='010vm.cc.html#L174'>read_mem_u8</a><span class="Delimiter">(</span>stream_start+i<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> +<span id="L134" class="LineNr">134 </span><span class="Delimiter">}</span> +<span id="L135" class="LineNr">135 </span> +<span id="L136" class="LineNr">136 </span><span class="Comment">//: helpers</span> +<span id="L137" class="LineNr">137 </span> +<span id="L138" class="LineNr">138 </span><span class="Delimiter">:(code)</span> +<span id="L139" class="LineNr">139 </span>string <a href='039debug.cc.html#L139'>hacky_squeeze_out_whitespace</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L140" class="LineNr">140 </span> <span class="Comment">// strip whitespace at start</span> +<span id="L141" class="LineNr">141 </span> string::const_iterator first = s<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> +<span id="L142" class="LineNr">142 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>first != s<span class="Delimiter">.</span>end<span class="Delimiter">()</span> && isspace<span class="Delimiter">(</span>*first<span class="Delimiter">))</span> +<span id="L143" class="LineNr">143 </span> ++first<span class="Delimiter">;</span> +<span id="L144" class="LineNr">144 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>first == s<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L145" class="LineNr">145 </span> +<span id="L146" class="LineNr">146 </span> <span class="Comment">// strip whitespace at end</span> +<span id="L147" class="LineNr">147 </span> string::const_iterator last = --s<span class="Delimiter">.</span>end<span class="Delimiter">();</span> +<span id="L148" class="LineNr">148 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>last != s<span class="Delimiter">.</span>begin<span class="Delimiter">()</span> && isspace<span class="Delimiter">(</span>*last<span class="Delimiter">))</span> +<span id="L149" class="LineNr">149 </span> --last<span class="Delimiter">;</span> +<span id="L150" class="LineNr">150 </span> ++last<span class="Delimiter">;</span> +<span id="L151" class="LineNr">151 </span> +<span id="L152" class="LineNr">152 </span> <span class="Comment">// replace runs of spaces/dots with single space until comment or string</span> +<span id="L153" class="LineNr">153 </span> <span class="Comment">// </span><span class="Todo">TODO</span><span class="Comment">:</span> +<span id="L154" class="LineNr">154 </span> <span class="Comment">// leave alone dots not surrounded by whitespace</span> +<span id="L155" class="LineNr">155 </span> <span class="Comment">// leave alone '#' within word</span> +<span id="L156" class="LineNr">156 </span> <span class="Comment">// leave alone '"' within word</span> +<span id="L157" class="LineNr">157 </span> <span class="Comment">// squeeze spaces after end of string</span> +<span id="L158" class="LineNr">158 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L159" class="LineNr">159 </span> <span class="Normal">bool</span> previous_was_space = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L160" class="LineNr">160 </span> <span class="Normal">bool</span> in_comment_or_string = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L161" class="LineNr">161 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>string::const_iterator curr = first<span class="Delimiter">;</span> curr != last<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L162" class="LineNr">162 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>in_comment_or_string<span class="Delimiter">)</span> +<span id="L163" class="LineNr">163 </span> out << *curr<span class="Delimiter">;</span> +<span id="L164" class="LineNr">164 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>*curr<span class="Delimiter">)</span> || *curr == <span class="Constant">'.'</span><span class="Delimiter">)</span> +<span id="L165" class="LineNr">165 </span> previous_was_space = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L166" class="LineNr">166 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L167" class="LineNr">167 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>previous_was_space<span class="Delimiter">)</span> +<span id="L168" class="LineNr">168 </span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> +<span id="L169" class="LineNr">169 </span> out << *curr<span class="Delimiter">;</span> +<span id="L170" class="LineNr">170 </span> previous_was_space = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L171" class="LineNr">171 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*curr == <span class="Constant">'#'</span> || *curr == <span class="Constant">'"'</span><span class="Delimiter">)</span> in_comment_or_string = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L172" class="LineNr">172 </span> <span class="Delimiter">}</span> +<span id="L173" class="LineNr">173 </span> <span class="Delimiter">}</span> +<span id="L174" class="LineNr">174 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L175" class="LineNr">175 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/linux/bootstrap/040tests.cc.html b/html/linux/bootstrap/040tests.cc.html new file mode 100644 index 00000000..a229a522 --- /dev/null +++ b/html/linux/bootstrap/040tests.cc.html @@ -0,0 +1,157 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - linux/bootstrap/040tests.cc</title> +<meta name="Generator" content="Vim/8.1"> +<meta name="plugin-version" content="vim8.1_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal-light"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #c6c6c6; } +body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; } +a { color:inherit; } +* { font-size:12pt; font-size: 1em; } +.cSpecial { color: #008000; } +.LineNr { } +.Constant { color: #008787; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Comment { color: #005faf; } +.Delimiter { color: #c000c0; } +.Identifier { color: #af5f00; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + var lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<a href='https://github.com/akkartik/mu/blob/main/linux/bootstrap/040tests.cc'>https://github.com/akkartik/mu/blob/main/linux/bootstrap/040tests.cc</a> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: Automatically aggregate functions starting with 'test-' into a test suite</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: called 'run-tests'. Running this function will run all tests.</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//:</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//: This is actually SubX's first (trivial) compiler. We generate all the code</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: needed for the 'run-tests' function.</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment">//:</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment">//: By convention, temporary functions needed by tests will start with</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment">//: '_test-'.</span> +<span id="L9" class="LineNr"> 9 </span> +<span id="L10" class="LineNr">10 </span><span class="Comment">//: We don't rely on any transforms running in previous layers, but this layer</span> +<span id="L11" class="LineNr">11 </span><span class="Comment">//: knows about labels and will emit labels for previous layers to transform.</span> +<span id="L12" class="LineNr">12 </span><span class="Delimiter">:(after "Begin Transforms")</span> +<span id="L13" class="LineNr">13 </span><a href='031transforms.cc.html#L4'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='040tests.cc.html#L34'>create_test_function</a><span class="Delimiter">);</span> +<span id="L14" class="LineNr">14 </span> +<span id="L15" class="LineNr">15 </span><span class="Delimiter">:(code)</span> +<span id="L16" class="LineNr">16 </span><span class="Normal">void</span> <a href='040tests.cc.html#L16'>test_run_test</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L17" class="LineNr">17 </span> <a href='010vm.cc.html#L163'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><span class="Constant">0xbd000000</span><span class="Delimiter">));</span> <span class="Comment">// manually allocate memory</span> +<span id="L18" class="LineNr">18 </span> Reg[ESP]<span class="Delimiter">.</span>u = <span class="Constant">0xbd000100</span><span class="Delimiter">;</span> +<span id="L19" class="LineNr">19 </span> <a href='011run.cc.html#L82'>run</a><span class="Delimiter">(</span> +<span id="L20" class="LineNr">20 </span> <span class="Constant">"== code 0x1</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// code segment</span> +<span id="L21" class="LineNr">21 </span> <span class="Constant">"main:</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L22" class="LineNr">22 </span> <span class="Constant">" e8/call run-tests/disp32</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 5 bytes</span> +<span id="L23" class="LineNr">23 </span> <span class="Constant">" f4/halt</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// 1 byte</span> +<span id="L24" class="LineNr">24 </span> <span class="Constant">"test-foo:</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// offset 7</span> +<span id="L25" class="LineNr">25 </span> <span class="Constant">" 01 d8</span><span class="cSpecial">\n</span><span class="Constant">"</span> <span class="Comment">// just some unique instruction: add EBX to EAX</span> +<span id="L26" class="LineNr">26 </span> <span class="Constant">" c3/return</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L27" class="LineNr">27 </span> <span class="Delimiter">);</span> +<span id="L28" class="LineNr">28 </span> <span class="Comment">// check that code in test-foo ran (implicitly called by run-tests)</span> +<span id="L29" class="LineNr">29 </span> <a href='003trace.cc.html#L290'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L30" class="LineNr">30 </span> <span class="Constant">"run: 0x00000007 opcode: 01</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L31" class="LineNr">31 </span> <span class="Delimiter">);</span> +<span id="L32" class="LineNr">32 </span><span class="Delimiter">}</span> +<span id="L33" class="LineNr">33 </span> +<span id="L34" class="LineNr">34 </span><span class="Normal">void</span> <a href='040tests.cc.html#L34'>create_test_function</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L35" class="LineNr">35 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L106'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L36" class="LineNr">36 </span> segment& code = *find<span class="Delimiter">(</span>p<span class="Delimiter">,</span> <span class="Constant">"code"</span><span class="Delimiter">);</span> +<span id="L37" class="LineNr">37 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"-- create 'run-tests'"</span> << end<span class="Delimiter">();</span> +<span id="L38" class="LineNr">38 </span> vector<line> new_insts<span class="Delimiter">;</span> +<span id="L39" class="LineNr">39 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L40" class="LineNr">40 </span> line& inst = code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L41" class="LineNr">41 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L42" class="LineNr">42 </span> <span class="Normal">const</span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L43" class="LineNr">43 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> != <span class="Constant">':'</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// not a label</span> +<span id="L44" class="LineNr">44 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!starts_with<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">,</span> <span class="Constant">"test-"</span><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L45" class="LineNr">45 </span> string fn = <a href='036labels.cc.html#L276'>drop_last</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L46" class="LineNr">46 </span> new_insts<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>call<span class="Delimiter">(</span>fn<span class="Delimiter">));</span> +<span id="L47" class="LineNr">47 </span> <span class="Delimiter">}</span> +<span id="L48" class="LineNr">48 </span> <span class="Delimiter">}</span> +<span id="L49" class="LineNr">49 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>new_insts<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// no tests found</span> +<span id="L50" class="LineNr">50 </span> code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>label<span class="Delimiter">(</span><span class="Constant">"run-tests"</span><span class="Delimiter">));</span> +<span id="L51" class="LineNr">51 </span> code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span>code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>end<span class="Delimiter">(),</span> new_insts<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> new_insts<span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L52" class="LineNr">52 </span> code<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='040tests.cc.html#L89'>ret</a><span class="Delimiter">());</span> +<span id="L53" class="LineNr">53 </span><span class="Delimiter">}</span> +<span id="L54" class="LineNr">54 </span> +<span id="L55" class="LineNr">55 </span>string to_string<span class="Delimiter">(</span><span class="Normal">const</span> segment& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L56" class="LineNr">56 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L57" class="LineNr">57 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L58" class="LineNr">58 </span> <span class="Normal">const</span> line& l = s<span class="Delimiter">.</span><a href='011run.cc.html#L113'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L59" class="LineNr">59 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L168'>SIZE</a><span class="Delimiter">(</span>l<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L60" class="LineNr">60 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>j > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> +<span id="L61" class="LineNr">61 </span> out << to_string<span class="Delimiter">(</span>l<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">));</span> +<span id="L62" class="LineNr">62 </span> <span class="Delimiter">}</span> +<span id="L63" class="LineNr">63 </span> out << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L64" class="LineNr">64 </span> <span class="Delimiter">}</span> +<span id="L65" class="LineNr">65 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L66" class="LineNr">66 </span><span class="Delimiter">}</span> +<span id="L67" class="LineNr">67 </span> +<span id="L68" class="LineNr">68 </span><a href='011run.cc.html#L121'>line</a> call<span class="Delimiter">(</span>string s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L69" class="LineNr">69 </span> <a href='011run.cc.html#L121'>line</a> result<span class="Delimiter">;</span> +<span id="L70" class="LineNr">70 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>call<span class="Delimiter">());</span> +<span id="L71" class="LineNr">71 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='040tests.cc.html#L82'>disp32</a><span class="Delimiter">(</span>s<span class="Delimiter">));</span> +<span id="L72" class="LineNr">72 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L73" class="LineNr">73 </span><span class="Delimiter">}</span> +<span id="L74" class="LineNr">74 </span> +<span id="L75" class="LineNr">75 </span><a href='011run.cc.html#L127'>word</a> call<span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L76" class="LineNr">76 </span> <a href='011run.cc.html#L127'>word</a> result<span class="Delimiter">;</span> +<span id="L77" class="LineNr">77 </span> result<span class="Delimiter">.</span>data = <span class="Constant">"e8"</span><span class="Delimiter">;</span> +<span id="L78" class="LineNr">78 </span> result<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"call"</span><span class="Delimiter">);</span> +<span id="L79" class="LineNr">79 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L80" class="LineNr">80 </span><span class="Delimiter">}</span> +<span id="L81" class="LineNr">81 </span> +<span id="L82" class="LineNr">82 </span><a href='011run.cc.html#L127'>word</a> <a href='040tests.cc.html#L82'>disp32</a><span class="Delimiter">(</span>string s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L83" class="LineNr">83 </span> <a href='011run.cc.html#L127'>word</a> result<span class="Delimiter">;</span> +<span id="L84" class="LineNr">84 </span> result<span class="Delimiter">.</span>data = s<span class="Delimiter">;</span> +<span id="L85" class="LineNr">85 </span> result<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"disp32"</span><span class="Delimiter">);</span> +<span id="L86" class="LineNr">86 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L87" class="LineNr">87 </span><span class="Delimiter">}</span> +<span id="L88" class="LineNr">88 </span> +<span id="L89" class="LineNr">89 </span><a href='011run.cc.html#L121'>line</a> <a href='040tests.cc.html#L89'>ret</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L90" class="LineNr">90 </span> <a href='011run.cc.html#L121'>line</a> result<span class="Delimiter">;</span> +<span id="L91" class="LineNr">91 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='011run.cc.html#L127'>word</a><span class="Delimiter">());</span> +<span id="L92" class="LineNr">92 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>data = <span class="Constant">"c3"</span><span class="Delimiter">;</span> +<span id="L93" class="LineNr">93 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L122'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"return"</span><span class="Delimiter">);</span> +<span id="L94" class="LineNr">94 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L95" class="LineNr">95 </span><span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> |