NAOS
Table of contents
- About
- Open topics
- History
- Configuration information
- Building the GCC based NAOS tool chain
- Building NAOS
- Preparing the NAOS disk image
- Setting up NAOS with BOCHS
- Setting up NAOS with GRUB
- Setting up NAOS with VIRTUALBOX
- Credits
1. About
NAOS is the abbreviation for Not Yet Another Operating System.
NAOS is a low scaled embedded operating system, currently running on the intel x86 platform. NAOS is to be intended for private study and learning purposes. It comes without any warranty. This document deals with operating system programming basics, using GNU/Linux and the GNU GCC tools. It addresses the developer who is familiar with the principles of the programming languages C and assembler.
Currently version V1.0.2 is released (Prevent the line breaks from Unix/Windows-conversion while extracting the archive!).
2. Open topics
- NEWLIB compiles and links. Testing.
- Adjust stack size dynamically.
- DMI support.
- Ethernet support.
- APIC support.
- NAOS API.
- More documentation.
3. History
V1.0.2, released on 29.07.2009. Changes:
- UART port support added.
- HTML documentation.
V1.0.1, released on 03.06.2009. Changes:
- NEWLIB support added.
- CLI commands 'reboot' and 'display' work.
V1.0.0, released on 05.04.2009. Changes:
- NAOS boots from grub.
- VGA works.
- Timer works.
- Exceptions work.
- Interrupts work.
4. Configuration information
The following tools have been used building NAOS:
- Debian / GNU Linux 4.0 (Etch) with
- GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)
- GCC 3.4.6 (Debian 3.4.6-5)
- BINUTILS 2.17
- GMP 2.4.2
- MPFR 2.4.0
- NAOS-GCC 4.3.3
- NAOS-BINUTILS 2.19
- NASM version 0.98.38 compiled on May 17 2005
- BOCHS 2.3.7, built from CVS snapshot on June 3, 2008
- SUN VIRTUALBOX V2.2.4 r47978
- For Microsoft Windows XP SP2: com0com V2.2.1.0
- NEWLIB 1.17.0
5. Building the GCC based NAOS tool chain
If you not only want to boot and execute the NAOS kernel as a binary but also want to build NAOS yourself from source, you first have to compile a NAOS tool chain.
- Install the necessary GCC software on your development system. This software depends on your system's preconditions: If you use Debian, you will need some packages like gcc core and libc. If you use WIN32 in combination with MinGW or CYGWIN, you will need packages like libiconv, TEX and several others. These preconditions are not the subject of this article.
- Build and install the gmp library for your development system:
$USER at $HOME/naos-tools/gmp>./configure
$USER at $HOME/naos-tools/gmp>make
$ROOT at $HOME/naos-tools/gmp>make install
- Build and install the mpfr library for your development system:
$USER at $HOME/naos-tools/mpfr>./configure
$USER at $HOME/naos-tools/mpfr>make
$ROOT at $HOME/naos-tools/mpfr>make install
- Build and install the binutils for your target system. Follow the GNU recommendations and build in an extra directory:
$USER at $HOME/naos-tools/binutils-build>../binutils-src/configure \
--target=i586-elf \
--program-prefix=naos-
$USER at $HOME/naos-tools/binutils-build>make
$ROOT at $HOME/naos-tools/binutils-build>make install
- Build and install the GNU c compiler for your target system. Follow the GNU recommendations and build in an extra directory:
$USER at $HOME/naos-tools/gcc-build>../gcc-src/configure \
--target=i586-elf \
--program-prefix=naos- \
--disable-nls \
--disable-shared \
--disable-multilib \
--disable-libssp \
--without-headers \
--enable-languages=c
$USER at $HOME/naos-tools/gcc-build>make
$ROOT at $HOME/naos-tools/gcc-build>make install
- Build and install the newlib c library for your target system:
$USER at $HOME/naos-tools/newlib>./configure
$USER at $HOME/naos-tools/newlib>make
$ROOT at $HOME/naos-tools/newlib>ln -s /usr/local/bin/naos-ranlib /usr/local/bin/i586-elf-ranlib
$ROOT at $HOME/naos-tools/newlib>make install
After these steps you should have:
- Binary tools like naos-ld at /usr/local/bin/
- The c compiler naos-gcc at /usr/local/bin/
- The c library libc.a at /usr/local/i586-elf/lib/
The NAOS build script b.sh depends on these preconditions!
If you have difficulties building the NAOS tool chain, read the GCC documentation or contact me here!
6. Building NAOS
The GCC based NAOS tool chain is needed for building.
- Run b.sh with user privileges.
The script compiles and links the NAOS kernel in boot/kernel.bin.
7. Preparing the NAOS disk image
In order to run NAOS in an emulator like BOCHS or VIRTUALBOX, you have to use a bootable disk image with a boot loader and the binary NAOS kernel file. The file boot/naos.img is such a disk image ready to use. It contains the GRUB boot loader and the current version of the NAOS kernel.
The file boot/naos.img was created with the BOCHS tool bximage. The transfer of the binary NAOS kernel file boot/kernel.bin into the disk image file boot/naos.img may be done with the script p.sh, run with root priviledges. Unlike the build script b.sh, the transfer script p.sh will only work with GNU/Linux; I currently have no tool for this using Microsoft Windows.
8. Setting up NAOS with BOCHS
For only booting and executing the NAOS kernel image, the GCC based NAOS tool chain is not needed.
- If you accomplished changes to the source code, build a new NAOS kernel with the script b.sh with user priviledges, then run p.sh with root privileges to transfer the NAOS kernel to the floppy disk image boot/naos.img.
- For UART support,
- open a terminal (e.g. konsole or xterm).
- Detect the device, your terminal is mapped on with the command '
tty
'.
On my system, it's /dev/pty/1
.
- Let your terminal sleep with the command '
sleep 1000000
'.
- Enter your terminal's device in the BOCHS configuration file boot/bochsrc.txt
com1: enabled=1, mode=term, dev=/dev/pts/1
During the boot process, NAOS will detect BOCHS' COM port emulation, print out a welcome message and start a CLI session. You can then use the serial terminal as a CLI terminal.
- Run BOCHS from the directory boot:
$USER at $HOME/naos/boot> bochs -f bochsrc.txt -q
9. Setting up NAOS with GRUB
For only booting and executing the NAOS kernel image, the GCC based NAOS tool chain is not needed.
- Transfer the NAOS kernel into your boot directory, e.g.:
$ROOT at $HOME/naos/boot>cp ./kernel.bin /boot
- Create a NAOS entry within your GRUB menu /boot/grub/menu.lst, e.g.:
[...]
title NAOS 1.0.1
root (hd0,5)
kernel /boot/kernel.bin
[...]
- Reboot your system and choose NAOS from the GRUB menu.
10. Setting up NAOS with VIRTUALBOX
For only booting and executing the NAOS kernel image, the GCC based NAOS tool chain is not needed.
So you've decided to prefer VIRTUALBOX. Perhaps even together with M$ Windows.
Mh.
Okay, that means you have to set up some preconditions and accept some issues coming with VIRTUALBOX.
- If you accomplished changes to the source code, build a new NAOS kernel with the script b.sh with user priviledges, then run p.sh with root privileges to transfer the NAOS kernel to the floppy disk image boot/naos.img.
- Run VIRTUALBOX from the menu.
On my system, I find it in the K-menu at System -> Sun Virtual Box.
- Create a virtual machine within VIRTUALBOX
- without harddisk,
- booting from floppy and
- add the NAOS floppy image naos.img to the virtual machine.
For UART support with GNU/Linux,
- open a terminal (e.g. konsole or xterm).
- Detect the device, your terminal is mapped on with the command '
tty
'.
On my system, it's /dev/pty/1
.
- Let your terminal sleep with the command '
sleep 1000000
'.
- Enter your terminal's device as your COM port's port / file path in VIRTUALBOX.
For UART support with M$ Windows, things get a little bit more difficult, because you can't simply connect the Windows Hyper Terminal to the VIRTUALBOX's serial emulation.
You have to create two new virtual COM ports, connected with each other.
With the first port, VIRTUALBOX may be connected; with the second port, the Windows Hyper Terminal may be connected.
This may be done for example with com0com. If you prefer another tool, you may try out yourself.
- Get com0com from sourceforge.
com0com will set up two new virtual COM ports.
- Execute setupc.exe from the C:\Programs\com0com directory and enter '
install - -
' for installing 2 new mirrored pseudo COM ports.
On my system, I had to install drivers for the new ports in the Windows device manager to finish the procedure completely.
- In VIRTUALBOX, change the virtual machine settings:
Serial interface, port1 tab
- Choose COM1 as port number
- host interface as port mode
- Enter the com0com port's device name '
\\.\CNCB1
' as Port/File Path
- Open the a hyper terminal from the Windows accessories and create a new serial connection on com0com port CNCA1.
- Choose 38400 as baud rate.
During the boot process, NAOS will detect VIRTUALBOX' COM port emulation, print out a welcome message and start a CLI session. You can then use the serial terminal as a CLI terminal.
- Boot your NAOS image within VIRTUALBOX.
On reboot, there are some issues with VIRTUALBOX. Currently NAOS behaves like FreeDOS and crashes the emulator on reboot. See bug #1600 for details.
- On Windows this means, VIRTUALBOX crashes with an exception.
- On Linux this means, VIRTUALBOX crashes and simply closes the virtual machine window.
- On a real hardware this does not occur.
Perhaps this will be fixed later. Just boot again from the scratch instead of rebooting.
11. Credits
The NAOS basics have been deeply inspired by Bran's kernel development tutorial and the guys at OSDev.org.
Further, the tools and some hardware specific code snippets came from the GNU/Linux community.
The UART routines are based upon The Serial Port rel. 14, part 1/3 from Chris Blum and the wikibook about Serial Programming/8250 UART Programming.