<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Matteus Silva on Medium]]></title>
        <description><![CDATA[Stories by Matteus Silva on Medium]]></description>
        <link>https://medium.com/@silvamatteus?source=rss-8fa13bc28467------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HIKT6zP0KrZzMW9TtymRZA.jpeg</url>
            <title>Stories by Matteus Silva on Medium</title>
            <link>https://medium.com/@silvamatteus?source=rss-8fa13bc28467------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 01:43:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@silvamatteus/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Adding New System Calls to xv6]]></title>
            <link>https://medium.com/@silvamatteus/adding-new-system-calls-to-xv6-217b7daefbe1?source=rss-8fa13bc28467------2</link>
            <guid isPermaLink="false">https://medium.com/p/217b7daefbe1</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Matteus Silva]]></dc:creator>
            <pubDate>Thu, 19 Apr 2018 12:27:45 GMT</pubDate>
            <atom:updated>2018-04-19T12:27:45.790Z</atom:updated>
            <content:encoded><![CDATA[<h4>A direct approach</h4><p>Hi! what’s up?</p><p>It’s my second text about xv6 or <em>how to add some stuff to xv6</em>. To understand why I’m doing this, read <a href="https://medium.com/@silvamatteus/adding-user-programs-to-xv6-ba9896605942">the first post</a>.</p><p>In my first contact with xv6, after compiling and running, I missed a command to shut down the virtual machine. So the first program I tried to write to xv6 was the <em>shutdown</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XTWGDHjMWdjsMyAd5cjINA.jpeg" /><figcaption>Function written on a paper.</figcaption></figure><p>I thought about it for a while. My program, following the pattern of other programs in xv6, should be something like that function written on a paper.</p><p>Searching about ways to shut down in QEMU, I found <a href="https://wiki.osdev.org/Shutdown">this site</a> and I found that is necessary to send a special signal to QEMU.</p><p>The problem is that an user program can not access the hardware directly. I needed something that offered me a interface to talk the hardware I want to shut down.</p><p>According to <a href="https://en.wikipedia.org/wiki/System_call">Wikipedia</a>, a <strong>system call</strong> is the programmatic way in which a <strong>computer program</strong> requests a service from the <strong>kernel</strong> of the operating system it is executing on. I needed the kernel. I needed a system call.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*-8IpF_frVKgc6RfFL3qI0w.png" /><figcaption>The syscalls that existed at that moment in my fork of xv6.</figcaption></figure><p>Well, I looked for a system call in xv6 to help me to shut down the machine and I found nothing.</p><p>It was time to write my first system call.</p><p>I figured out what things to add in xv6 and in what files to add these things to write my syscall and make it available for user programs.</p><p>Here are the steps to add a shutdown in xv6 (running into QEMU emulator version 2.5.0).</p><h4>Create <em>shutdown.c</em></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79d8e599ab9de3a25ae7d27dbb016ea9/href">https://medium.com/media/79d8e599ab9de3a25ae7d27dbb016ea9/href</a></iframe><p>The program shutdown will call the system call <em>halt.</em></p><h4>Create the system call halt</h4><p>The system call halt must be implemented in <em>sysproc.c </em>and uses the documentation provided in <a href="https://wiki.osdev.org/Shutdown">https://wiki.osdev.org/Shutdown</a> to send a special signal to QEMU.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ece466ac19609cf6acfd671c9216447/href">https://medium.com/media/7ece466ac19609cf6acfd671c9216447/href</a></iframe><p>Add <strong><em>SYSCALL(halt)</em></strong><em> </em>to the end of the file <em>usys.S.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*wGudszxJi-Qy5q-9H1vN9A.png" /></figure><p>Add a new number for the syscall in <em>syscall.h</em> by adding <strong><em>#define SYS_halt 22 </em></strong>to the end of the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*tUshmEMl89XYtKyxxoj_1Q.png" /></figure><p>Add the following to <em>syscall.c.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*zhLVlL2ScgP9Xh0tO_7uQQ.png" /></figure><p>At least, expose the new system call to user programs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*NByM5E_JrZj98PQ3UWLQaA.png" /></figure><p>For the <em>shutdown</em> work, find the definition of <strong>QEMUOPTS </strong>in the Makefile and add <strong>-device isa-debug-exit,iobase=0xf4,iosize=0x04<em> </em></strong>to the line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*4bZv33LI04GVx-lJsmTDeQ.png" /></figure><p>That’s it! The system call halt is now available for our <em>shutdown</em> program. To know how to add the user program with xv6, see <a href="https://medium.com/@silvamatteus/adding-user-programs-to-xv6-ba9896605942">this post</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=217b7daefbe1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding user programs to xv6]]></title>
            <link>https://medium.com/@silvamatteus/adding-user-programs-to-xv6-ba9896605942?source=rss-8fa13bc28467------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba9896605942</guid>
            <category><![CDATA[xv6]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[teaching]]></category>
            <category><![CDATA[linux-kernel]]></category>
            <dc:creator><![CDATA[Matteus Silva]]></dc:creator>
            <pubDate>Wed, 18 Apr 2018 18:39:31 GMT</pubDate>
            <atom:updated>2018-04-18T18:39:31.743Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello guys!</p><p><strong><em>To my classmates</em></strong><em>: We are working with </em><a href="https://github.com/mit-pdos/xv6-public"><em>xv6</em></a><em> to learn how some important concepts can be implemented in practice. In this sense, I’ll share with you some tips in the Medium platform throughout the next weeks.</em></p><p>Let’s add the <em>clear.c </em>to our xv6. It’s quite simple.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51e3c5a6964dc79f463ed1a16520a0d2/href">https://medium.com/media/51e3c5a6964dc79f463ed1a16520a0d2/href</a></iframe><p>The code has been <strong>intentionally</strong> garbled. Ignore the code quality =P</p><p>To add this program, we need to modify the Makefile and put the <em>clear.c</em> into the xv6 main directory.</p><p>In Makefile, look for UPROG and add <em>_clear\ </em>as in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*pO8_TG2w2O2r08LofQcubg.png" /></figure><p>Still in the Makefile, look for EXTRA and add <em>clear.c</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*GnuJVLOT1lz50z7darSDSQ.png" /></figure><p>That’s it! Now, after building and running xv6 with the command <em>make qemu</em>, we can call the program <em>clear</em> typing clear in sh.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba9896605942" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>