about summary refs log blame commit diff stats
path: root/html/linux/000init.subx.html
blob: 1914303f7f4d31ff965284508063b189c651d698 (plain) (tree)
1
2
3
4
5
6
7
8
9








                                                                                                               
                                                 

                       

                                                                                                 





































































































































                                                                                                                                                                                                                                                                                          
<!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/000init.subx</title>
<meta name="Generator" content="Vim/8.1">
<meta name="plugin-version" content="vim8.1_v1">
<meta name="syntax" content="none">
<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: #ffffd7; }
body { font-size:12pt; font-family: monospace; color: #000000; background-color: #ffffd7; }
a { color:inherit; }
* { font-size:12pt; font-size: 1em; }
.subxComment { color: #005faf; }
.LineNr { }
.subxFunction { color: #af5f00; text-decoration: underline; }
-->
</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/000init.subx'>https://github.com/akkartik/mu/blob/main/linux/000init.subx</a>
<pre id='vimCodeElement'>
<span id="L1" class="LineNr"> 1 </span><span class="subxComment"># Some OS-specific preliminaries for Linux.</span>
<span id="L2" class="LineNr"> 2 </span>
<span id="L3" class="LineNr"> 3 </span><span class="subxComment"># Memory layout</span>
<span id="L4" class="LineNr"> 4 </span><span class="subxComment">#</span>
<span id="L5" class="LineNr"> 5 </span><span class="subxComment">#          0 - 0x08047ffff - reserved for the kernel</span>
<span id="L6" class="LineNr"> 6 </span><span class="subxComment"># 0x08048000 - 0xbffffffff - available for user programs</span>
<span id="L7" class="LineNr"> 7 </span><span class="subxComment"># 0xc0000000 - 0xfffffffff - reserved for the kernel</span>
<span id="L8" class="LineNr"> 8 </span>== code 0x09000000
<span id="L9" class="LineNr"> 9 </span>== data 0x0a000000
<span id="L10" class="LineNr">10 </span>
<span id="L11" class="LineNr">11 </span><span class="subxComment"># Syscalls</span>
<span id="L12" class="LineNr">12 </span><span class="subxComment">#</span>
<span id="L13" class="LineNr">13 </span><span class="subxComment"># We don't have libc, so we need to know Linux's precise syscall layout.</span>
<span id="L14" class="LineNr">14 </span><span class="subxComment"># These are not real functions. Pass arguments in specific registers.</span>
<span id="L15" class="LineNr">15 </span>== code
<span id="L16" class="LineNr">16 </span>
<span id="L17" class="LineNr">17 </span><span class="subxComment"># <a href="http://man7.org/linux/man-pages/man2/exit.2.html">http://man7.org/linux/man-pages/man2/exit.2.html</a></span>
<span id="L18" class="LineNr">18 </span><span class="subxFunction">syscall_exit</span>:  <span class="subxComment"># status/ebx: int</span>
<span id="L19" class="LineNr">19 </span>    b8/copy-to-eax 1/imm32
<span id="L20" class="LineNr">20 </span>    cd/syscall 0x80/imm8
<span id="L21" class="LineNr">21 </span>
<span id="L22" class="LineNr">22 </span><span class="subxComment"># <a href="http://man7.org/linux/man-pages/man2/read.2.html">http://man7.org/linux/man-pages/man2/read.2.html</a></span>
<span id="L23" class="LineNr">23 </span><span class="subxFunction">syscall_read</span>:  <span class="subxComment"># fd/ebx: int, buf/ecx: addr, size/edx: int -&gt; nbytes-or-error/eax: int</span>
<span id="L24" class="LineNr">24 </span>    b8/copy-to-eax 3/imm32
<span id="L25" class="LineNr">25 </span>    cd/syscall 0x80/imm8
<span id="L26" class="LineNr">26 </span>    c3/return
<span id="L27" class="LineNr">27 </span>
<span id="L28" class="LineNr">28 </span><span class="subxComment"># <a href="http://man7.org/linux/man-pages/man2/write.2.html">http://man7.org/linux/man-pages/man2/write.2.html</a></span>
<span id="L29" class="LineNr">29 </span><span class="subxFunction">syscall_write</span>:  <span class="subxComment"># fd/ebx: int, buf/ecx: addr, size/edx: int -&gt; nbytes-or-error/eax: int</span>
<span id="L30" class="LineNr">30 </span>    b8/copy-to-eax 4/imm32
<span id="L31" class="LineNr">31 </span>    cd/syscall 0x80/imm8
<span id="L32" class="LineNr">32 </span>    c3/return
<span id="L33" class="LineNr">33 </span>
<span id="L34" class="LineNr">34 </span><span class="subxComment"># <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 id="L35" class="LineNr">35 </span><span class="subxFunction">syscall_open</span>:  <span class="subxComment"># filename/ebx: (addr kernel-string), flags/ecx: int, dummy=0x180/edx -&gt; fd-or-error/eax: int</span>
<span id="L36" class="LineNr">36 </span>    b8/copy-to-eax 5/imm32
<span id="L37" class="LineNr">37 </span>    cd/syscall 0x80/imm8
<span id="L38" class="LineNr">38 </span>    c3/return
<span id="L39" class="LineNr">39 </span>
<span id="L40" class="LineNr">40 </span><span class="subxComment"># <a href="http://man7.org/linux/man-pages/man2/close.2.html">http://man7.org/linux/man-pages/man2/close.2.html</a></span>
<span id="L41" class="LineNr">41 </span><span class="subxFunction">syscall_close</span>:  <span class="subxComment"># fd/ebx: int -&gt; status/eax</span>
<span id="L42" class="LineNr">42 </span>    b8/copy-to-eax 6/imm32
<span id="L43" class="LineNr">43 </span>    cd/syscall 0x80/imm8
<span id="L44" class="LineNr">44 </span>    c3/return
<span id="L45" class="LineNr">45 </span>
<span id="L46" class="LineNr">46 </span><span class="subxComment"># <a href="http://man7.org/linux/man-pages/man2/lseek.2.html">http://man7.org/linux/man-pages/man2/lseek.2.html</a></span>
<span id="L47" class="LineNr">47 </span><span class="subxFunction">syscall_lseek</span>:  <span class="subxComment"># fd/ebx: int, offset/ecx: int, whence/edx: int</span>
<span id="L48" class="LineNr">48 </span>    b8/copy-to-eax 0x13/imm32
<span id="L49" class="LineNr">49 </span>    cd/syscall 0x80/imm8
<span id="L50" class="LineNr">50 </span>    c3/return
<span id="L51" class="LineNr">51 </span>
<span id="L52" class="LineNr">52 </span><span class="subxComment"># <a href="http://man7.org/linux/man-pages/man2/creat.2.html">http://man7.org/linux/man-pages/man2/creat.2.html</a></span>
<span id="L53" class="LineNr">53 </span><span class="subxFunction">syscall_creat</span>:  <span class="subxComment"># filename/ebx: (addr kernel-string) -&gt; fd-or-error/eax: int</span>
<span id="L54" class="LineNr">54 </span>    b8/copy-to-eax 8/imm32
<span id="L55" class="LineNr">55 </span>    cd/syscall 0x80/imm8
<span id="L56" class="LineNr">56 </span>    c3/return
<span id="L57" class="LineNr">57 </span>
<span id="L58" class="LineNr">58 </span><span class="subxComment"># <a href="http://man7.org/linux/man-pages/man2/unlink.2.html">http://man7.org/linux/man-pages/man2/unlink.2.html</a></span>
<span id="L59" class="LineNr">59 </span><span class="subxFunction">syscall_unlink</span>:  <span class="subxComment"># filename/ebx: (addr kernel-string) -&gt; status/eax: int</span>
<span id="L60" class="LineNr">60 </span>    b8/copy-to-eax 0xa/imm32
<span id="L61" class="LineNr">61 </span>    cd/syscall 0x80/imm8
<span id="L62" class="LineNr">62 </span>    c3/return
<span id="L63" class="LineNr">63 </span>
<span id="L64" class="LineNr">64 </span><span class="subxComment"># <a href="http://man7.org/linux/man-pages/man2/rename.2.html">http://man7.org/linux/man-pages/man2/rename.2.html</a></span>
<span id="L65" class="LineNr">65 </span><span class="subxFunction">syscall_rename</span>:  <span class="subxComment"># source/ebx: (addr kernel-string), dest/ecx: (addr kernel-string) -&gt; status/eax: int</span>
<span id="L66" class="LineNr">66 </span>    b8/copy-to-eax 0x26/imm32
<span id="L67" class="LineNr">67 </span>    cd/syscall 0x80/imm8
<span id="L68" class="LineNr">68 </span>    c3/return
<span id="L69" class="LineNr">69 </span>
<span id="L70" class="LineNr">70 </span><span class="subxComment"># <a href="https://github.com/torvalds/linux/blob/fa121bb3fed6313b1f0af23952301e06cf6d32ed/mm/nommu.c#L1352">https://github.com/torvalds/linux/blob/fa121bb3fed6313b1f0af23952301e06cf6d32ed/mm/nommu.c#L1352</a></span>
<span id="L71" class="LineNr">71 </span><span class="subxFunction">syscall_mmap</span>:  <span class="subxComment"># arg/ebx: (addr mmap_arg_struct) -&gt; status/eax: int</span>
<span id="L72" class="LineNr">72 </span>    <span class="subxComment"># the important thing: ebx+4 contains the 32-bit size to be allocated</span>
<span id="L73" class="LineNr">73 </span>    b8/copy-to-eax 0x5a/imm32
<span id="L74" class="LineNr">74 </span>    cd/syscall 0x80/imm8
<span id="L75" class="LineNr">75 </span>    c3/return
<span id="L76" class="LineNr">76 </span>
<span id="L77" class="LineNr">77 </span><span class="subxFunction">syscall_ioctl</span>:  <span class="subxComment"># fd/ebx: int, cmd/ecx: int, arg/edx: (addr _)</span>
<span id="L78" class="LineNr">78 </span>    b8/copy-to-eax 0x36/imm32
<span id="L79" class="LineNr">79 </span>    cd/syscall 0x80/imm8
<span id="L80" class="LineNr">80 </span>    c3/return
<span id="L81" class="LineNr">81 </span>
<span id="L82" class="LineNr">82 </span><span class="subxFunction">syscall_nanosleep</span>:  <span class="subxComment"># req/ebx: (addr timespec)</span>
<span id="L83" class="LineNr">83 </span>    b8/copy-to-eax 0xa2/imm32  <span class="subxComment"># 162</span>
<span id="L84" class="LineNr">84 </span>    cd/syscall 0x80/imm8
<span id="L85" class="LineNr">85 </span>    c3/return
<span id="L86" class="LineNr">86 </span>
<span id="L87" class="LineNr">87 </span><span class="subxFunction">syscall_clock_gettime</span>:  <span class="subxComment"># clock/ebx: int, out/ecx: (addr timespec)</span>
<span id="L88" class="LineNr">88 </span>    b8/copy-to-eax 0x109/imm32  <span class="subxComment"># 265</span>
<span id="L89" class="LineNr">89 </span>    cd/syscall 0x80/imm8
<span id="L90" class="LineNr">90 </span>    c3/return
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->