Skip to content

Static Variables

I have now made a change to get rid of some fixed variable arrays. Previously the task table was a fixed array of limited size, as was the table of standard message ports. I have now changed these to dynamically allocated linked lists; this gives these items the ability to grow unlimited (except by memory constraints).

As always, making these changes brought to light a couple of unnoticed bugs which had been causing system instability and also a horrendous memory leak in the kernel. These have now been corrected, leading to more stability. The memory allocation routine has also been improved and simplified. Previously I kept a record, in struct MemStruct, of the pid that allocated memory. The intention was to allow the kernel to automatically deallocate any unused memory once a process ends. On reflection this was not a particularly good idea. As the kernel allocates and deallocates all memory on its heap it seemed better to just make sure it didn’t leave any unused memory allocated (which I think I have managed so far). As for user memory, that is deallocated automatically when the pages are released by the DummyTask process.

I haven’t managed to crash the system with simple tests since making these changes, but I’m sure there are many bugs left lurking.

The source code download on my website now reflects these changes (and all previous ones mentioned), but I have yet to update the documentation and listings; I’ll do this in due course.

Growing the Stack

For a long time I have meant to look at code to detect stack underflow and grow the stack accordingly, but never got round to it. This was brought to a head when writing the disk buffering code; I was getting some unexplained errors that turned out to be stack underflows due to excessively recursive function calls (which I solved separately).

I’ve always thought this would be quite hard but I had a look, and it turned out to be very easy. I’ve now added code that will detect an underflow of the user stack (which is the only one that we don’t have tight control of) and allocate a new page if needed. I haven’t yet incorporated it in the code on the web, but for those interested, here is the revised page fault handler (where all the work is done).

You will need to make one more change for this code to work. Currently the user stack is located at the page starting 0xA00000. The page immediately before that is actually part of the kernel stack address space and is not accessible by user programs. So UserStack needs to be changed in “memory.h” and “memory.inc”. I’ve made it 0xBFF000; that gives quite a few available pages for the user stack; if it grows bigger than this there’s probably something wrong. (But you can set aside as much of the virtual address space as you like.)

Disk Buffering

I took a little time out from writing an editor to implement a fairly simple method of buffering disk access. Obviously this is desirable as direct access to the hard disk is much slower than memory access.

Previously, whenever a sector was required the OS just loaded it from the disk. Now the sector is put into a buffer which is managed by a binary tree. When the OS requires a sector it first checks this tree to see if the sector is already in it. If so it returns a pointer to the existing buffer; otherwise it loads the sector and adds it to the tree.

In the current implementation the buffer is never freed. That’s not such a problem as the disk is small, it has very little data on it, and the system never runs for very long anyway. In due course I will implement flushing of old buffers from the tree. Not only is this necessary for memory reasons, but at some stage the tree will become so large that it is less efficient than reading direct from the disk. I’ll probably use a “least recently used” algorithm.

When the buffer is written to it is marked as dirty. At crucial points the OS checks for dirty buffers and writes them to disk. All of this code is to be found in filesystem.c (plus btree.c, which contains routines to manage the binary tree).

Work on the editor progresses. It’s doing quite well now but still has a few bugs.

Whilst working on these two points a few bugs have arisen, which have now been corrected. (One of these involves a slight change to the format of executable files in “tasks”.) The download, and the source listings, now contain all of these changes.

Unlink Fixed

Working again. Back to the editor.

Unlink Broken

In working on the text editor I notice that the unlink system call, to delete a file, appears to be broken. It was working fine a while ago so I’ve obviously changed something. Ho hum – one step forward, two steps back.

As an aside, I’ve been thinking about the best way to publish patches for minor problems like this. I could make the svn archive open for public read access, or just post the updated files in links here or in a Downloads directory. Alternatively I can create a new tar.gz of the whole source code every time.

Any preferences?

Updates to System

It seems like ages since I added anything to the website. Not surprising, as it is ages. But I have been working, on and off, on the system and have now made what I think are significant improvements, and have improved the stability considerable, so I present them for your entertainment.

Those of you who have looked at IanOS in the past will notice:

1. I have now adopted the standard UNIX/Linux system calls, with just one or two of my own. The hope is that one day – in the far, far distant future – I may get to the stage of porting software from Linux.

2. The console task now supports multiple consoles. Sounds easy but it involved a lot of work.

3. I’ve written a few more user programs, and I’m in the process of writing a simple text editor. This will, I think, be the first really useful program. One day I’d like to produce, or port, an assembler and C compiler so that the system could compile itself. Well, we can all dream.

4. The filesystem has been improved considerably with working support for directories, files that use more than one disk cluster, etc. It’s still a bit rough but I’m getting there.

All round, the system is more stable, more versatile and, I hope, better commented and documented. I’m aware that there is room for improvement in the documentation and I am looking into this.

As I work on the system further I’ll try hard to keep this blog updated. But, don’t forget, it’s all just a fun project and sometimes I have other things that attract my interest. So bear with me if I sometimes neglect this little project.

Enjoy!

Ian.

Latest Version Uploaded

I’ve now updated the documentation and uploaded the latest version which includes all the changes mentioned here to date. Let me know if you spot any problems or bad links.