diff options
Diffstat (limited to 'html/034compute_segment_address.cc.html')
-rw-r--r-- | html/034compute_segment_address.cc.html | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/html/034compute_segment_address.cc.html b/html/034compute_segment_address.cc.html index f761044d..2b105f9b 100644 --- a/html/034compute_segment_address.cc.html +++ b/html/034compute_segment_address.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - subx/034compute_segment_address.cc</title> +<title>Mu - 034compute_segment_address.cc</title> <meta name="Generator" content="Vim/8.1"> <meta name="plugin-version" content="vim8.1_v1"> <meta name="syntax" content="cpp"> @@ -54,7 +54,7 @@ if ('onhashchange' in window) { </script> </head> <body onload='JumpToLine();'> -<a href='https://github.com/akkartik/mu/blob/master/subx/034compute_segment_address.cc'>https://github.com/akkartik/mu/blob/master/subx/034compute_segment_address.cc</a> +<a href='https://github.com/akkartik/mu/blob/master/034compute_segment_address.cc'>https://github.com/akkartik/mu/blob/master/034compute_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> @@ -65,7 +65,7 @@ if ('onhashchange' in window) { <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='034compute_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#L85'>run</a><span class="Delimiter">(</span> +<span id="L10" class="LineNr">10 </span> <a href='011run.cc.html#L83'>run</a><span class="Delimiter">(</span> <span id="L11" class="LineNr">11 </span> <span class="Constant">"== code 0x09000000\n"</span> <span id="L12" class="LineNr">12 </span> <span class="Constant">"05/add-to-EAX 0x0d0c0b0a/imm32\n"</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> @@ -84,19 +84,19 @@ if ('onhashchange' in window) { <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 Level-2 Transforms")</span> -<span id="L29" class="LineNr">29 </span><span class="Special"><a href='011run.cc.html#L250'>Transform</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='034compute_segment_address.cc.html#L32'>compute_segment_starts</a><span class="Delimiter">);</span> +<span id="L29" class="LineNr">29 </span><span class="Special"><a href='011run.cc.html#L252'>Transform</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='034compute_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='034compute_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#L165'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L102'>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#L102'>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#L102'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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#L164'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L107'>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#L107'>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#L107'>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='010---vm.cc.html#L409'>HEXWORD</a> << curr<span class="Delimiter">.</span>start << end<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='010---vm.cc.html#L398'>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='010---vm.cc.html#L92'>SEGMENT_ALIGNMENT</a><span class="Delimiter">);</span> <span class="Comment">// for now we get less and less available space in each successive segment</span> @@ -105,16 +105,16 @@ if ('onhashchange' in window) { <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#L165'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L112'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> -<span id="L51" class="LineNr">51 </span> sum += <a href='034compute_segment_address.cc.html#L56'>num_bytes</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L112'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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#L164'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L114'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L51" class="LineNr">51 </span> sum += <a href='034compute_segment_address.cc.html#L56'>num_bytes</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L114'>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='034compute_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#L165'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L121'>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#L121'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<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#L164'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L123'>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#L123'>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> |