This site is very simplistic. I just want to show off what I've been
working on lately. It's a very minimalist operating system. I wrote it
in High
Level Assembly. A couple of years back when I tried to get my
head around assembly programming, I discovered HLA on the web and was
intrigued by its advertised ease of entry into an understanding about
how the machine works inside. But after learning assembly I wasn't
happy, because everything I wrote was still dependent on the OS I was
running on, so I sort of knew
what my programs did in machine terms, but not how the multitasking and
all the hardware stuff was made to get going.
I found it was time to learn about operating systems. But not just from
a theoretical point (I did have that in the college). After a little
bit more research I found out about Minix.
I got myself a copy of the
Minix Book, which turnt out to be an excellent investment.
When it
came to actually writing some code on my own, I recalled HLA and was
curious whether it would actually be possible to code an OS in it. On
the HLA newsgroup I was told it was possible, the only catch being that
you can't use HLA to write 16-bit code. So you would indeed need some
other compiler to code the very first few instructions of your would-be
OS in to make your machine switch into protected mode, but from there
on, HLA is all you need. I personally love HLA because it gives me the
power to write "real assembly" whenever I see fit, but also to express
myself on a higher level, with control structures, structs, and the
likes.
But getting back to my OS, what I've got going for the moment is the
following:
- machine starts and reads first 512 bytes from disk
- machine reads rest of the kernel from disk
- machine uses BIOS to retrieve memory map
- machine switches over to protected mode
- machine sets up clock and keyboard interrupts
- machine sets up rudimentary multitasking
- machine sets up 3 simple commands: cls, say, and uptime
Below I will provide the source plus the compiled "kernel". If you want
to compile the kernel yourself, you will need to install NASM
and HLA
on your Linux box. Then uncompress the files into a folder of your
choice and type:
make bootdisk.bin
You will need to copy the content of this file to the very start of a
floppy disk. You can then restart your machine from this floppy into
the kernel. Alternatively, you can start the emulator of your choice
(Bochs, qemu, VirtualBox, and the likes) and provide bootdisk.bin as a
virtual floppy to boot from.
A few words about the multitasking: I don't as of yet have any
meaningful tasks. So all I did was write two very simple tasks that
just increment a register in a tight loop, over and over again. They
look like this:
procedure task1;
begin task1;
forever
cli;
putstring("1");
sti;
endfor;
endfor;
end task1;
procedure task2;
begin task2;
forever
cli;
putstring("2");
sti;
endfor;
end task2;
The multitasking functionality is however still very
rudimentary. The user cannot launch new processes as of yet. But the
most fundamental functions and mechanisms to for this exists already.
Take the following function call (it's commented out in main.hla):
createProcess(0,50,&task1,$14700,$14700,NO_BASE,0,$b8000,$110000,$fffff,$fffff,0,$fffff,$1,$ffff0);
This will create a new process in the process table with:
- privilege 0
- a quantum of 50 clockticks
- a starting address equal to &task1
- a code segment (where the cs register points) that starts at absolute memory offset $14700 and has a limit of $fffff (page-granular)
- a data segment (where the ds register points) that starts at absolute memory offset $14700 and has a limit of $fffff (page-granular)
- an empty (zeroed-out) es register
- a data segment (where the fs register points) that starts at absolute memory offset 0 and has a limit of $fffff (page-granular)
- a data segment (where the gs register points) that starts at absolute memory offset $b8000 and has a limit of $1 (page-granular)
- a stack segment (where the ss register points) that starts at absolute memory offset $110000 and has a limit of $ffff0 (page-granular)
This function returns the index into pproctab for the new process in eax. You can then enqueue this new process with:
enqueue(pproctab[eax], 5, FRONT);
The
above call would enqueue the process at the front of scheduling queue 5
(There exists a maximum of NO_SCHEDQUEUES scheduling queues).
If you uncommend the four lines down the bottom of main.hla you can see how the two processes are created and run.
I will also shortly describe the commands that I've implemented so
far:
- cls
- say
- will repeat what you tell it to (e.g. "say something")
- uptime
- will display the hours, minutes and seconds passed since
sytem startup
I will also include a precompiled version of bootdisk.bin, in case you
want to see it roll but can't compile the source.
Click here to learn more about the source.
Download here:
MyOS.zip
bootdisk.bin
I have also written some basic documentation about the source code. Please click here.
mail to: webmaster {at} com-eu-nication.eu