<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>G33K @ Work &#187; OSDev</title>
	<atom:link href="http://www.geekatwork.de/category/osdev/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.geekatwork.de</link>
	<description>Basteleien eines Geeks</description>
	<lastBuildDate>Mon, 12 Jul 2010 08:38:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>OS Development Demo Code</title>
		<link>http://www.geekatwork.de/2010/07/12/os-development-demo-code/</link>
		<comments>http://www.geekatwork.de/2010/07/12/os-development-demo-code/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 08:36:14 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[OSDev]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[interrupts]]></category>
		<category><![CDATA[low level]]></category>
		<category><![CDATA[pic]]></category>
		<category><![CDATA[pit]]></category>
		<category><![CDATA[sigint]]></category>
		<category><![CDATA[x86]]></category>

		<guid isPermaLink="false">https://www.geekatwork.de/?p=274</guid>
		<description><![CDATA[A while ago, I wrote some demo code to demonstrate vari [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago, I wrote some demo code to demonstrate various things you need to do to write your own operating system.<br />
In May 2010 I held a lecture and workshop about this code and the concepts at <a href="http://events.ccc.de/sigint/2010/wiki/Hauptseite" target="_blank">SigInt conference in Cologne</a>, Germany.</p>
<p>I just thought that this code may be interesting to other people who did not attend this conference.<span id="more-274"></span></p>
<p><a href="http://github.com/G33KatWork/SigInt10OSWorkshop" target="_blank">The demo code</a> includes mainly x86 specific stuff and it is truly demo code, so don&#8217;t just copy it into another project. Even if it works at first sight, it it is highly likely to break sooner or later <img src='http://www.geekatwork.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The code contains samples for:</p>
<ul>
<li>A small &#8220;Hello World&#8221; bootsector in realmode</li>
<li>A sample how to enable the A20 gate. This works at least in QEMU</li>
<li>Loading a barebone-kernel written in C by GRUB</li>
<li>Switching to protected mode and writing to the textmode framebuffer</li>
<li>Handling interrupts in protected mode using the old PIC</li>
<li>Configuring and using the old PIT (Timer)</li>
<li>Switching to longmode (64 Bit)</li>
<li>A multitasking demo how to do context switching</li>
</ul>
<p>The first two samples are completely written in Assembly and are loaded directly by the BIOS from a floppy drive. All other samples are mainly written in C spiced with some Assembly and are loaded from a FAT formatted floppy disk by a GRUB bootloader.</p>
<p>For those of you who speak german, here are the slides of the conference:<br />
<a href="http://events.ccc.de/sigint/2010/wiki/Fahrplan/events/3889.de.html" target="_blank">Talk</a><br />
<a href="http://events.ccc.de/sigint/2010/wiki/Fahrplan/events/3890.de.html" target="_blank">Workshop </a></p>
<p>If you do anything with this demo code, I would appreciate to hear about your project or experiences. Also, If there are specific questions or problems about/with this code which are not easily resolvable by Googling and using your brain, feel free to ask in the comments. <img src='http://www.geekatwork.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://www.geekatwork.de/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekatwork.de/2010/07/12/os-development-demo-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dumping the VMware BIOS</title>
		<link>http://www.geekatwork.de/2010/05/27/dumping-the-vmware-bios-2/</link>
		<comments>http://www.geekatwork.de/2010/05/27/dumping-the-vmware-bios-2/#comments</comments>
		<pubDate>Thu, 27 May 2010 00:48:18 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[OSDev]]></category>
		<category><![CDATA[BIOS]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[dumping]]></category>
		<category><![CDATA[extracting]]></category>
		<category><![CDATA[MacOS]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[VMware]]></category>

		<guid isPermaLink="false">http://www.geekatwork.de/?p=228</guid>
		<description><![CDATA[Sometimes, even if you don't want to install a pirated  [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, even if you don&#8217;t want to install a pirated Windows version, you may want to dump and modify the BIOS of a computer.<br />
Especially if you are developing some kind of an ACPI subsystem for your <a href="projekte/geexos/">own small operating system kernel</a>.</p>
<p>Doing this with real hardware is kinda risky and complex.<br />
But what about virtual machines like VMware? They have a BIOS, but how can we get our hands on it?<span id="more-228"></span><br />
As I&#8217;m using Mac OS X for all my daily work, I&#8217;m using VMware Fusion as a virtualization program.</p>
<p>The BIOS seems to be hidden inside the virtual machine monitor executable itself.<br />
To make our lifes easier, we are going to extract only the x86_64 part out of the universal binary with the following command:</p>
<pre class="brush:shell">lipo /Libary/Application\ Support/VMware\ Fusion/vmware-vmx -thin x86_64 -output /Users/user/Desktop/vm64</pre>
<p>Now, we have a Mach-O file with only one architecture, which is x86_64.<br />
It doesn&#8217;t matter if you are dumping the BIOS out of the i386 or x86_64 version of the binary. It should be the same for both architectures.</p>
<p>After that, we can extract the appropriate section in the Mach-O file which contains the BIOS itself:</p>
<pre class="brush:shell">segedit /Users/user/Desktop/vm64 -extract __VMWARE bios440 /Users/user/Desktop/bios440.rom</pre>
<p>And here, you go: bios440.rom contains your VMware BIOS.</p>
<p>After you modified it to your wishes, you can use a handy VMware feature which lets you specify a custom BIOS for a virtual machine inside its vmx-file.<br />
Just add this line to the vmx-file of the machine you want a custom BIOS for and place the rom file in the proper folder:</p>
<pre>bios440.filename = "bios.rom"</pre>
<p>Happy BIOS modding!</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = 'G33KatWork';
var flattr_url = 'http://www.geekatwork.de';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'G33K @ Work';
var flattr_dsc = 'Basteleien eines Geeks';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://www.geekatwork.de/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekatwork.de/2010/05/27/dumping-the-vmware-bios-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Systemprogrammierung</title>
		<link>http://www.geekatwork.de/2010/01/03/systemprogrammierung/</link>
		<comments>http://www.geekatwork.de/2010/01/03/systemprogrammierung/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 00:08:14 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[OSDev]]></category>
		<category><![CDATA[The usual rants]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Virtualisierung]]></category>

		<guid isPermaLink="false">http://www.geekatwork.de/?p=81</guid>
		<description><![CDATA[Mein momentanes Interessenfeld bezieht sich ja sehr sta [...]]]></description>
			<content:encoded><![CDATA[<p>Mein momentanes Interessenfeld bezieht sich ja sehr stark auf alles, was mit System- und Hardwarenaher Programmierung zu tun hat.<br />
Da ich auf der Zugfahrt zum <a href="http://events.ccc.de/congress/2009" target="_blank">26c3</a> nicht besonders viel zu tun hatte und die AMD und Intel Dokumentationen auf meinem Rechner hatte, habe ich mal angefangen mich um die <a href="http://de.wikipedia.org/wiki/Virtualisierung_%28Informatik%29" target="_blank">Virtualisierungsfunktionen</a>, die diese beiden Hersteller da so in ihre Prozessoren verpflanzen, zu kümmern.<span id="more-81"></span></p>
<p>Nachdem ich dann auch irgendwann mal raushatte, wie ich das vierstufige (!) Paging mit 4KB großen Pages beim Booten zusammenbauen konnte, um so einen Prozessor in den <a href="http://de.wikipedia.org/wiki/AMD64#Betriebsmodi" target="_blank">Long Mode</a> zu bekommen, hab ich mich mal an die Virtualisierung machen wollen.<br />
Zu diesem Zeitpunkt saß ich allerdings schon im Hackcenter.</p>
<p>Wie ich dann, mal wieder, feststellen musste, hat so ein Low Level Zeug einen unglaublichen Rattenschwanz, den man immer wieder hinter sich herzieht. In diesem konrekten Fall brauchte ich also ein vernünftiges <a href="http://de.wikipedia.org/wiki/Interrupt" target="_blank">Interrupthandling</a>. Ist ja schnell implementiert, dachte ich mir und kopier mir meinen Code aus meinen anderen <a href="http://www.geekatwork.de/projekte/geexos/" target="_self">Projekten</a> fröhlich zusammen.</p>
<p>Interrupts konnte ich dann handlen. Problem war jetzt nur, dass 2 Instruktionen nach dem Aktivieren der Interrupts sofort der Interrupt #8 auftrat, was nach Dokumentation ein Double Fault gewesen sein müsste. Dieser tritt aber nur nach einer fatalen, vorhergegangenen Exception auf, wovon ich aber nichts mitbekommen habe. Wieso fliegt da also ein Double Fault? Nichtmal die 2 Instruktionen, die nach dem setzen des Interrupt Enable Flags ausgeführt wurden konnten einen solchen Interrupt auslösen, weil es Sprünge zu sich selbst waren, um die CPU in einer Endlosschleife zu halten.</p>
<p>Kommen wir zurück zum Rattenschwanz: Nachdem ich dann die Interrupt Handler und die Verwaltung der IDT hatte, habe ich noch Routinen zur Verwaltung der <a href="http://de.wikipedia.org/wiki/Global_Descriptor_Table" target="_blank">GDT</a> implementiert. Es funktionierte immernoch nicht, was allerdings zu erwarten war, da es mehr eine Verzweifelungstat war als ein richtiger Lösungsansatz. Wir sind zu diesem Zeitpunkt bei Tag 3 des Kongresses.<br />
Allerdings war das ja auch nicht das Einzige, was ich da gemacht habe. Gab ja noch Vorträge.</p>
<p>Danach gings ans Debuggen. Ich habe VMware probiert, um zu sehen, was das Ding sagt. Wie erwartet: nichts. Es fehlen einfach die Debuggingmöglichkeiten unter Mac OS mit VMware.<br />
Dann gibts noch Qemu, an den man einen GDB klemmen kann. Gesagt getan. Nach wie vor nichts gefunden.<br />
Als letztes bin ich mit dem integrierten Debugger in Bochs dem Kram zu Leibe gerückt, mit dem man seinen Code auf Assemblerebene Debuggen konnte. Auch hier habe ich wieder nichts gefunden.</p>
<p>Was war das Ende vom Lied? Es gibt einen extra Chip auf x86 Systemem, der externe Interrupts handlet. Früher war das der <a href="http://de.wikipedia.org/wiki/Programmable_Interrupt_Controller" target="_blank">PIC (Programmable Interrupt Controller)</a> und heute ist es der <a href="http://de.wikipedia.org/wiki/APIC" target="_blank">APIC (Advanced Programmable Interrupt Controller)</a>, der auch Mehrprozessorsysteme ohne Gefrickel unterstützt.<br />
Diese Chips kann man so konfigurieren, dass jeder externe Interrupt (Tastatur, Floppy, Timer etc) auf einen der 256 Interrupts der CPU gemappt werden kann.</p>
<p>Irgendein Stück Software vor meinem Kernel hat genau das anscheinend mit dem Timerinterrupt gemacht und ihn auf Interrupt #8 gelegt.<br />
Das würde dann auch erklären, warum bei einem Double Fault eigentlich ein Errorcode auf den Stack gepusht werden sollte, was bei mir aber nie passiert ist. Es war schlicht und ergreifend kein Double Fault.</p>
<p>Also hab ich dann doch, entgegen meiner vorherigen &#8220;Brauchste eh nich&#8221;-Meinung, auch noch Code hinzugefügt, der den PIC (eigentlich sind es 2 PICs) entsprechend konfiguriert und die 16 Interrupts, die er verwalten kann, hinter die Exceptions mappt.</p>
<p>Was ist? Es funktioniert endlich.</p>
<p>Und so kann man sich wunderschön auf die Fresse legen und Zeit verbraten.<br />
Ich will nicht sagen ich hab nichts gelernt, genervt hat es aber doch schon ziemlich. Gedauert hat der ganze Prozess jetzt 6 Tage. Und ich hab immernoch keinen virtualisierten Code laufen.</p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://www.geekatwork.de/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekatwork.de/2010/01/03/systemprogrammierung/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
