<?xml version="1.0"?>
<!-- name="generator" content="blosxom/2.0" -->
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">
  <channel>
    <title>Hans-Georg Eßer: ULIX   </title>
    <link>http://privat.hgesser.com/ulix/index.cgi</link>
    <description>Blogging the Implementation of ULIX</description>
    <language>en</language>

  <item>
    <title>Bug fix :)</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2012/05/19#2012-05-19</link>
    <description>
I found a bug in memory management that came into being after
including code for creating new address spaces: When there is
more than one address space, we have (identical) copies of
the page directory's mapping for c0000000..ffffffff -- so when
an entry in that area is modifed (i.e. a new page table is
created and linked from that page directory)
it must also be modified in
all existing copies... Took me quite a while to find it, but
now the code is OK :) Memory setup works for processes (as
long as no more than 4 MB are requested; can be fixed easily),
so the system is ready for process creation.</description>
  </item>
  <item>
    <title>Ulix has address spaces</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2012/04/05#2012-04-05</link>
    <description>
Another step on the way to proper process management: Ulix now has address
spaces which can be switched on. So there is &quot;process-private&quot; memory
(however: no process yet). &lt;br&gt;

To do: more work on address spaces (there are some bugs in there); integrate
address spaces + usermode switch + process table (not defined yet). For
starters, only cooperative scheduling.</description>
  </item>
  <item>
    <title>User mode stuff: side project</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2012/04/02#2012-04-02</link>
    <description>
Since I'm giving the lecture &quot;System Level Programming&quot; at Nuernberg Univ. of Applied Sciences,
I use the practical coursework to develop some user mode tools for Ulix. Currently I'm working
on a simple shell. So far it can evaluate parameters and launch processes (assuming there are
working fork() and exec() functions). &lt;br&gt;
fork() should not be a problem at all (once I have a process table), exec() can't be done properly
yet since there is no filesystem code at all. However, exec() could load a binary from RAM. I had
already experimented with precompiled programs stored in the Ulix code as byte arrays.</description>
  </item>
  <item>
    <title>Update: Development goes on, Moved to Erlangen</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2012/01/12#2012-01-12</link>
    <description>
I've moved to Erlangen (where research and Ulix development are done), so
now I'm closer to the project, and things will continue faster this year.
Keep watching for new features :)
</description>
  </item>
  <item>
    <title>User Mode</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2011/08/21#2011-08-21</link>
    <description>
Ulix can now switch to user mode and execute simple code. Since we have no syscalls
yet, it cannot do much in user mode. So the next step is to set up syscalls
for &quot;print character&quot; and &quot;read character&quot; -- then I can convert the current
simple shell into a user mode shell. This is not yet a process, it is just code
being executed with privilege level 3 (in ring 3) instead of the kernel's own
privilege level 0 (ring 0). However, it's nice to have it, because the transition
from kernel to user mode requires weird code and a TSS (Task State Segment).
</description>
  </item>
  <item>
    <title>Ulix has simple kmalloc() and kfree() functions</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2011/08/19#2011-08-19</link>
    <description>
A first implementation of &lt;tt&gt;kmalloc&lt;/tt&gt; and &lt;tt&gt;kfree&lt;/tt&gt; is now available.
It always starts with a fresh page, so it is quite wasteful. Also, it does not
check, whether contiguous pages are allocated by &lt;tt&gt;request_new_page&lt;/tt&gt; -- but
the code for that function has been prepared so that (in the future) it will
be able to guarantee a contiguous area.
&lt;br&gt;

The way new page tables are entered into the system has changed: I no longer
allocate pages for them, only frames. They do not need to have virtual
addresses because they are always referenced via their physical addresses.
</description>
  </item>
  <item>
    <title>Remembering: there's a thing called scope</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2011/08/18#2011-08-17</link>
    <description>
Back to &quot;Learning C 101&quot;: Assume you create a new page table, and you do that
within a function. That page table is supposed to stay around (even
though it's never explicitly accessed outside the function, however it's 
being pointed to.)
Sometimes the code works, sometimes not. You spend half a day on searching
for the errors in the paging calculations... Perhaps something's wrong with
the physical addresses? But not always? The code looks like this:

&lt;pre&gt;
void create_new_table() {
  page_table pt;
  ... (&lt;i&gt;fill pt with data&lt;/i&gt;)
  ... (&lt;i&gt;enter &amp;amp;pt in global page directory&lt;/i&gt;)
  return;
}
&lt;/pre&gt;

Then, suddenly, at 4:00 a.m. in the morning, you realize that this way
&lt;tt&gt;return&lt;/tt&gt; is an implicit &lt;tt&gt;forget about pt&lt;/tt&gt;. D'oh.
&lt;br&gt;
In related news, moving the &lt;tt&gt;pt&lt;/tt&gt; declaration outside the function solved
my problem, and now Ulix can reserve new pages (and correctly update the
page tables) until it runs out of physical frames :)
Yes, there's still the issue of paging out memory to disk. Which would
require disk access. Which is a topic for later.
</description>
  </item>
  <item>
    <title>v0.04: Memory Allocation: Get Frame, Get Page, Update Page Tables</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2011/08/17#2011-08-v0.04</link>
    <description>
&lt;a href=&quot;/ulix/pics/ulix-0.04.png&quot;&gt;&lt;img src=&quot;/ulix/pics/ulix-0.04_s.png&quot; align=&quot;right&quot; border=&quot;0&quot;&gt;&lt;/a&gt;
OK, the memory system is slowly becoming useful. There's now a bitmap that keeps
track of used/free frames in RAM, and there's a function which requests a new
page (first getting a frame, then updating the page table and eventually creating
a new page table when the old one is full). Next up is some kind of kmalloc()... &lt;br&gt;
Some other things I found out: It's sometimes helpful to use the graphical
debug frontend of Bochs. And: There's a free (LGPL-licensed), simple printf() implementation
(Georges Menie, 2002) which does not depend on the existence of any libraries:
all it needs is a way to put a single character on the console (and I have a
putch() already).

&lt;p&gt;
&lt;b&gt;Resources used:&lt;/b&gt; &lt;br&gt;
printf, by Georges Menie, &lt;a href=&quot;http://www.menie.org/georges/embedded/&quot; class=&quot;extern&quot;&gt;http://www.menie.org/georges/embedded/&lt;/a&gt;
</description>
  </item>
  <item>
    <title>Debugging the Kernel with Bochs</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2011/08/14#2011-08-14b</link>
    <description>
Debugging the Ulix kernel requires use of some tools: I use
Bochs (a fresh compile with the configure options
&lt;tt&gt;--enable-debugger&lt;/tt&gt; and &lt;tt&gt;--enable-disasm&lt;/tt&gt;).
Compared to a standard configuration of Bochs, I do a few
things differently via the config file (bochsrc.txt):

&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;port_e9_hack: enabled=1&lt;/tt&gt; lets me use a special
  &lt;tt&gt;outb()&lt;/tt&gt; command to write to the 
  terminal from which Bochs was started -- helpful when video
  is not yet setup
&lt;li&gt;&lt;tt&gt;magic_break: enabled=1&lt;/tt&gt; allows me to insert
  the useless assembler statement &lt;tt&gt;xchg bx,bx&lt;/tt&gt; anywhere
  in the code and have execution stop at that point (without
  having to set the breakpoint manually inside Bochs)
&lt;li&gt;&lt;tt&gt;debug_symbols: file=ulix.sym&lt;/tt&gt; makes Bochs read
  a symbol table at startup so it can output addresses
  relative to the start of some function. However no tool
  immediately produces the symbol table in a format that
  Bochs can read. I use the following command to create a 
  fitting table:
&lt;pre&gt;
objdump -D ulix.bin | grep -e '^[^ ]* &amp;lt;' | sed -e 's/&amp;lt;//' -e 's/&amp;gt;://' &amp;gt; ulix.sym
&lt;/pre&gt;
  (This works only for ELF binaries.)
&lt;/ul&gt;

All of that together makes debugging the kernel a bit easier:
Bochs can show information about registers, the GDT, TSS and
many more interesting things.
&lt;p&gt;

&lt;b&gt;Resources used:&lt;/b&gt;&lt;br&gt;
Bochs, &lt;a href=&quot;http://bochs.sourceforge.net/&quot; class=&quot;extern&quot;&gt;http://bochs.sourceforge.net/&lt;/a&gt;</description>
  </item>
  <item>
    <title>Preparations for User Mode</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2011/08/13#2011-08-14</link>
    <description>
In order to create user mode processes (without implementing a program
loader right now) I compile simple C programs (with a main() function)
to object files and link them with a ld linker script with
&lt;tt&gt;OUTPUT_FORMAT&lt;/tt&gt; set to &lt;tt&gt;binary&lt;/tt&gt;, creating a &lt;tt&gt;.com&lt;/tt&gt;
file. (I use this ending in memory of simple DOS programs and because
yesterday the original IBM PC turned 30 years.)

Then comes some Unix
shell script magic which pipes the binary through hexdump, fmt, and sed
in order to create a char array declaration like this:

&lt;pre&gt;
static char procbin[] __attribute__ ((aligned (4096))) = {
0x83, 0xec, 0x10, 0xc7, 0x44, 0x24, 0x0c, 0x00, 0x00, 0x00,
0x00, 0xc7, 0x44, 0x24, 0x08, 0x01, 0x00, 0x00, 0x00, 0xeb,
0x10, 0x8b, 0x44, 0x24, 0x08, 0x01, 0x44, 0x24, 0x0c, 0xff,
0x44, 0x24, 0x0c, 0xff, 0x44, 0x24, 0x08, 0x83, 0x7c, 0x24,
0x08, 0x09, 0x7e, 0xe9, 0xb8, 0xcd, 0xab, 0x00, 0x00, 0xcd,
0x80, 0x8b, 0x44, 0x24, 0x0c, 0x83, 0xc4, 0x10, 0xc3, 0x00
};
&lt;/pre&gt;

That can be pasted into the Ulix source code and will create a page-aligned
block holding the program. This is then mapped to page 0, and user mode is
entered with an IRET to address 0: The program starts.
&lt;br&gt;
In order to check what code has been produced by the compiler, I use
the disassembler udis86.
&lt;p&gt;

&lt;b&gt;Resources used:&lt;/b&gt; &lt;br&gt;
udis86 disassembler library with udcli client,
&lt;a href=&quot;http://udis86.sourceforge.net/&quot; class=&quot;extern&quot;&gt;http://udis86.sourceforge.net/&lt;/a&gt;
</description>
  </item>
  <item>
    <title>Physical RAM mapped, hexdump</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2011/08/13#2011-08-13</link>
    <description>
I've done some preparations for user mode: physical RAM (I assume 64 MByte RAM)
is now mapped to 0xD000.0000-0xD3FF.FFFF. That's helpful when I know the
physical address of some data, but not the virtual one. I noticed that it's
easy to forget that page directory entries need to point to physical
addresses, not virtual ones. I kept wondering why I got segfaults :) &lt;br&gt;
There is now a &quot;frame list&quot; (actually just a bitmap). It can be asked for
the status of any frame (im RAM), and for each frame the status can be set
to free or used. &lt;br&gt;
Another new function is hexdump() which displays (virtual) memory contents in
the same format as the shell command hexdump does for text files. It was fun
to compare its output with the output of 'hexdump ulix.bin'. My temporary
shell (the hard-coded main loop for now) cannot yet parse arguments to
commands, so hexdump will display contents of three memory areas selected in
the code; in a future version it will accept start and end addresses and
show the memory region's contents.
</description>
  </item>
  <item>
    <title>v0.03: Paging with Higher Half Kernel</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2011/08/12#2011-08-v0.03</link>
    <description>
&lt;a href=&quot;/ulix/pics/ulix-0.03.png&quot;&gt;&lt;img src=&quot;/ulix/pics/ulix-0.03_s.png&quot; align=&quot;right&quot; border=&quot;0&quot;&gt;&lt;/a&gt;
It works: now the kernel uses virtual addresses starting at 0xC0000000 (the last of four
gigabytes). This is a preparation for allowing user mode code (processes) to run in the
lower 3 GBytes. It took me all a whole day to get this to work because my original code
did not setup enough page -&gt; frame mappings; it mapped some virtual memory to [0..1MB], but
the system was loaded to [1MB..2MB], so after enabling paging nothing useful was found... &lt;br&gt;
Now the next step will be user mode. For a starter I will just try to switch to user
mode and back; there's some meddling with the stack involved because Intel CPUs have
only one instruction that can be used to enter user mode: IRET (return from interrupt)
which finds the next instruction pointer on the stack. This will later turn into the
init process from which all other processes will be forked. &lt;br&gt;
Another thing to think of now is memory allocation. When I start handling processes I will
need a list of free page frames, so the physical memory should be identified in the
beginning. There's a lot of untested frame allocation code in Felix Freiling's non-Intel Ulix,
so I'll look how that works on an Intel chip.
&lt;p&gt;
&lt;b&gt;Resources used:&lt;/b&gt; &lt;br&gt;
Higher Half With GDT, &lt;a href=&quot;http://wiki.osdev.org/Higher_Half_With_GDT&quot; class=&quot;extern&quot;&gt;http://wiki.osdev.org/Higher_Half_With_GDT&lt;/a&gt;
</description>
  </item>
  <item>
    <title>Working on the GDT trick</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2011/08/11#2011-08-WIP-gdt-trick</link>
    <description>
In order to make the kernel use (virtual) high memory addresses (0xC000.0000 to 0xFFFF.FFFF),
some extra work is necessary. I am porting the GDT trick over to the current code which
uses a special GDT that linearly remaps memory by supplying a relocation offset as part
of a segment description.
&lt;p&gt;
&lt;b&gt;Resources used:&lt;/b&gt; &lt;br&gt;
Higher Half With GDT, &lt;a href=&quot;http://wiki.osdev.org/Higher_Half_With_GDT&quot; class=&quot;extern&quot;&gt;http://wiki.osdev.org/Higher_Half_With_GDT&lt;/a&gt;
</description>
  </item>
  <item>
    <title>v0.02: Booting, Paging</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2011/08/01#2011-08-v0.02</link>
    <description>
I started with OS code from Bran's OS tutorial and imported this code (slightly modified)
into the tex/noweb sources. Shell scripts can create either a PDF file of the documentation
or a bootable floppy image with the kernel on it. The kernel loads low in RAM and starts
paging. It uses identity mapping for the first MB of RAM.
&lt;p&gt;
&lt;b&gt;Resources used:&lt;/b&gt; &lt;br&gt;
Bran's Kernel Development Tutorial, &lt;a href=&quot;http://www.osdever.net/tutorials/view/brans-kernel-development-tutorial&quot; class=&quot;extern&quot;&gt;http://www.osdever.net/tutorials/view/brans-kernel-development-tutorial&lt;/a&gt; &lt;br&gt;
GCC Cross Compiler, &lt;a href=&quot;http://www.fanofblitzbasic.de/prettyos/PrettyOSMacOSX.pdf&quot; class=&quot;extern&quot;&gt;http://www.fanofblitzbasic.de/prettyos/PrettyOSMacOSX.pdf&lt;/a&gt; &lt;br&gt;
All in one boot disk: &lt;a href=&quot;http://rescup.winbuilder.net/bootdisk/&quot; class=&quot;extern&quot;&gt;http://rescup.winbuilder.net/bootdisk/&lt;/a&gt; &lt;br&gt;
Qemu: &lt;a href=&quot;http://wiki.qemu.org/&quot; class=&quot;extern&quot;&gt;http://wiki.qemu.org/&lt;/a&gt; &lt;br&gt;
Bochs: &lt;a href=&quot;http://bochs.sourceforge.net/&quot; class=&quot;extern&quot;&gt;http://bochs.sourceforge.net/&lt;/a&gt; &lt;br&gt;
Noweb: &lt;a href=&quot;http://www.cs.tufts.edu/~nr/noweb/&quot; class=&quot;extern&quot;&gt;http://www.cs.tufts.edu/~nr/noweb/&lt;/a&gt; &lt;br&gt;
mtools (for copying the kernel binary to the floppy image):
&lt;a href=&quot;http://www.gnu.org/s/mtools/&quot; class=&quot;extern&quot;&gt;http://www.gnu.org/s/mtools/&lt;/a&gt; &lt;br&gt;
Ulix noweb sources (Felix Freiling, unpublished)
</description>
  </item>
  <item>
    <title>Ulix v0.01 - it begins</title>
    <link>http://privat.hgesser.com/ulix/index.cgi/2011/07/01#2011-07-v0.01</link>
    <description>
So here's the beginning of my ULIX blog, and also the beginning of my Ulix-i386
development. I base my work on Felix Freiling's &quot;The Design and Implementation of
the ULIX Operating System&quot;, an unfinished literate programming document from which
parts of an OS theory book (in LaTeX) and parts of a kernel (in C and assembler)
can be extracted using the noweb tools (noweave, notangle).&lt;p&gt;

The original code from this document is intended to run on a virtual machine
(the ULIX hardware) which is also described in that text and for which parts of
a tool chain (emulator, gcc port, assembler) had been created by other
students. However, I am implementing Ulix for the i386 architecture. So some
of the original code will remain, and some must go.&lt;p&gt;

In this blog I will keep you updated on my progress.
</description>
  </item>
  </channel>
</rss>
