程序天空

系统程序开发
posts - 52, comments - 34, trackbacks - 1, articles - 28

the@womble.co.uk:Writing an operating system PART 2

Posted on Thursday, November 25, 2004 11:04 AM #操作系统
Free2Code » articles » Other » Writing an operating system PART 2

Writing an operating system PART 2

By: the@womble.co.uk
More at: http://www.groovyweb.cjb.net http://wwww.axion-network.net

How to write an operating system, part 2

In part one, assembly language was very briefly covered, and the practical way an os works was covered. Now we say good bye to assembly language (for a short time) and say hello to friendly c programming. Also, this tutorial is alot shorter, as the hardest stuff was covered in the first tutorials, but there is alot of sourcecode to add to and learn from.

Tools:

http://www.geocities.com/groovyos/tutor.zip
MinitOS by competer_uk@yahoo.co.uk and then I hacked on the shell and some bits
Includes source, nasm (assembler), tcc (c compiler)

Open the zip file, and run make.bat (sorry Linux lovers, the zip file is designed for dos. The assembly doesn't need to be changed, but you'll have to change the c a bit. E-mail me for how)
Now restart and be amazed. The commands are:
run -After typing this type LOADME COM (two spaces between loadme and com) and enjoy a funky screensavers. Which then crahses
restart -An amazing exclusive feature of minitos

boot.asm can be ignored, it does nothing new. It includes certain text at the top to day the disk is in FAT 12 format, and then loads SYSTEM.COM

Why can't I use stdio.h
There is a great explanation at http://www.execpc.com/~geezer/osd/libc/index.htm
Basically, they need to be ported. When I was trying to work out what, Chris Benesch said "To do printf, you dont need assembly. You can include and use a va_list. " -This works for gcc. I think. i'm very new to c, so you can probably find far easier ways to write an os, but in this os as the functions are done in assembly you will learn alot.

Using asm functions from c
System.asm and system.c aren't separate programs, they are built then linked, so it is as if they are the same program.
System.asm is made up of functions that are used by c.

When tcc calls a function, it puts the text sent at bp+4. It then looks for the output in ax and dx. Tcc (unlike gcc) cuts off the first character of the function name, which is why _setvalue in asm becomes setvalue in c. To declare an asm function use the following code: GLOBAL _setvalue and then the following in the c file: extern setvalue();
The following pointless function I wrote to set a value in c:

That's about all you need to do to use asm in your os. The most can be learnt from looking at the source code.
Try adding another function that allows you to multiply or something.

Well that's it.

For updates of the os, check out http://www.groovyweb.uklinux.net/index.php?page_name=groovyos and if you add anything, e-mail me at the@womble.co.uk and I'll be really greatful. 256 colour mode we don`t need to use numbers higher than 255(0-255 = 256) so a char data

Post Comment

Title  
Name  
Url
Comment   
Protected by Clearscreen.SharpHIPEnter the code you see: