Skip to content

chillancezen/ZeldaOS

Repository files navigation

ZeldaOS

Written in C&inline assembly from scratch, ZeldaOS is an unix-like 32bit monolithic kernel which is designed to comform to POSIX.1 interface. At present, it's only able to run on any x86 and x86_64 processors. The name Zelda is from Nintendo video game: The Legend of Zelda asciicast

How to Build The Project ?

To build the project, we need a 64bit Linux host (I used a CentOS 7.3) and GCC suite(my GCC version is 4.8.5, other versioned gcc are supposed to work), in order to package a bootable ISO image, I also install rpm package: #yum install -y xorriso. the compilation tools will automatically generate 32bit elf objects with Makefile and Linker script

To build the image and ISO image(imagine the project top directory is /root/ZeldaOS/):

#ZELDA=/root/ZeldaOS/ make runtime_install
#ZELDA=/root/ZeldaOS/ make app_install
#ZELDA=/root/ZeldaOS/ make drive
#ZELDA=/root/ZeldaOS/ make

To clean the built objects:

#ZELDA=/root/ZeldaOS/ make runtime_clean
#ZELDA=/root/ZeldaOS/ make app_clean
#ZELDA=/root/ZeldaOS/ make clean

How to Launch the OS/kernel ?

There are two ways to launch the ZeldaOS:

(a) Launch ZeldaOS via the Zelda.bin raw kernel image.

this is the most usual way I did when I was debuging the code. you need to install qemu software beforehand, a typical command is given like:

#/usr/bin/qemu-system-x86_64 -serial tcp::4444,server -m 3024 -kernel Zelda.bin \
-monitor null -nographic -vnc :100 -netdev tap,id=demonet0,ifname=demotap0,script=no,downscript=no \
-device virtio-net-pci,netdev=demonet0,mac=52:53:54:55:56:00 \
-netdev tap,id=demonet1,ifname=demotap1,script=no,downscript=no \
-device virtio-net-pci,netdev=demonet1 -gdb tcp::5070

you can specify more different -serial parameter(qemu mannual) to observe the output or input. right here you can use the shell by telnet to local qemu serial endpoint:

#telnet localhost 4444
....(omitted)
Welcome to ZeldaOS Version 0.1
Copyright (c) 2018 Jie Zheng [at] VMware

[Link@Hyrule.kingdom /home/zelda]# uname
sysname  : ZeldaOS
nodename : Hyrule
release  : The Brave
version  : 0.1
machine  : i686
domain   : kingdom
[Link@Hyrule.kingdom /home/zelda]#
[Link@Hyrule.kingdom /home/zelda]# ps
    0 PL0:0x1060f6   kernel_idle_task          running                   /
    1 PL3:0x40000c27 /usr/bin/userland_init    interruptible             /
    2 PL0:0x104664   wq:ethernet_rx            interruptible             /
    3 PL3:0x400013c8 /usr/bin/shelld           interruptible             /home/zelda
    4 PL3:0x400013c8 /usr/bin/shelld           interruptible             /home/zelda
    5 PL3:0x400013c8 /usr/bin/shelld           interruptible             /home/zelda
    6 PL3:0x400013c8 /usr/bin/shelld           interruptible             /home/zelda
    7 PL3:0x400013c8 /usr/bin/shelld           interruptible             /home/zelda
    8 PL3:0x400013c8 /usr/bin/shelld           interruptible             /home/zelda
    9 PL3:0x400013c8 /usr/bin/shelld           interruptible             /home/zelda
   10 PL3:0x40000b24 ps                        running                   /home/zelda
[Link@Hyrule.kingdom /dev]# ls -la ./ ./net
./:
FILE_TYPE_MARK        0        .
FILE_TYPE_REGULAR     0        serial0
FILE_TYPE_REGULAR     2000     ptm0
FILE_TYPE_REGULAR     2000     ptm1
FILE_TYPE_REGULAR     2000     ptm2
FILE_TYPE_REGULAR     2000     ptm3
FILE_TYPE_REGULAR     2000     ptm4
FILE_TYPE_REGULAR     2000     ptm5
FILE_TYPE_REGULAR     0        console
FILE_TYPE_DIR         0        net

./net:
FILE_TYPE_MARK        0        .
FILE_TYPE_REGULAR     0        Ethernet:0:3.0
FILE_TYPE_REGULAR     0        Ethernet:0:4.0
[Link@Hyrule.kingdom /usr/var]# tinyvm primes.vm
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
[Link@Hyrule.kingdom /home/zelda]# dummy
0: Hello World
1: Hello World
^X
[keyboard interrupted]
[Link@Hyrule.kingdom /home/zelda]#

(b) Launch ZeldaOS via the Zelda.iso bootable image or hard drive.

In this case the kernel is booted by GRUB multiboot. you can burn the Zelda.iso into a udisk drive or hard drive from which you can boot the kernel. we have the splash window when the kernel boots(grub draws it): image_of_splash

When the kernel is fully ready, the default console (which you can navigate to by Alt+F1) is displayed, there are other 6 consoles initiated by /usr/bin/userland_init, you can switch the console by Alt+F2 ... Alt+F7, you will observe console as below:

image_of_console0

Feature inventory

Archeticture Features:
  • x86
  • PIC, APIC will be supported in ZeldaOS.x86_64.
  • interrupt management.
  • x86_64 64bit support.
  • Symmetric multiprocessing (SMP).
  • SSE/AVX context save and restore
  • hypervisor to lauch a VM with Intel VT-x(VMX)
memory Features:
  • physical memory management.
  • 4K paging(No 3G barrier break) for both kernel and PL3 tasks.
  • Virtual Memory Area(VMA) management(per-task VMAs and kernel VMAs).
  • paging fault handling, including page non-presence and page permission fault.
  • kernel memory allocator.
Kernel Features:
  • multitasking (PL0 tasks and PL3 tasks).
  • task signal framework.
  • Elf32 executable loading.
  • task exception detection(e.g. illegal instruction, #GP, paging permission violation).
  • Wait queue.
  • Timer.
  • bottom half schedule.
  • kernel panic.
Filesystem Features:
  • Virtual File System (VFS).
  • zeldafs as initramfs in Linux.
  • memfs as tmpfs in Linux.
  • devfs to expose kernel runtime data to userland.
Network Features:
  • net packets management.
  • Ethernet device interface.
  • L2 multi-bridging(VLAN+MAC learning).
  • L3 multi-routing(ARP, ICMP).
  • overlay support(vxlan).
  • userland networking extension(LWIP).
Device Features:
  • Legacy virtio-net ethernet device driver(with revisionid == 0).
  • vmxnet3 ethernet device support.
  • PS/2 keyboard management.
  • Programmable Interval Timer(PIT) management.
  • serial port input/output management and serial console.
  • ATA/IDE drive management.
  • Lower level Text mode video buffer management.
  • pseudo terminal console management.
Miscellaneous Features:

About

32bit OS/kernel built from scratch with POSIX.1 compliance

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages