Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: Stryker on 15 November 2002, 06:42

Title: Operating System Development
Post by: Stryker on 15 November 2002, 06:42
I'm working on making an operating system. I've gotten quite a bit done but I haven't actually gotten it to boot. I do not want to use anything written by anyone else, no grub, lilo, or kernel. But what I do need is a c++ compiler that will compile things in machine code, rather than a .com, .exe, or linux executable. When I compile it with linux it will only work in linux, when it's compiled in windoze it only runs in windoze. I've considered learning ASM but I am having trouble finding a good tutorial anywhere. Does anyone know of a c++ compiler that will compile for a x86 machine without any non-bios interrupts?
Title: Operating System Development
Post by: The Auditor on 15 November 2002, 07:43
To my knowledge, you will only be able to get it to run under one or the other.
its a thing about C++.

The HUO (Hackers Unlimited Organization, see profile) is working on an OS, BSD, or possibly Darwin based..
i woulod advise the learning of ASM, it will only benefit you.

The Auditor

[ November 14, 2002: Message edited by: The Auditor ]

Title: Operating System Development
Post by: Stryker on 15 November 2002, 08:22
quote:
Originally posted by The Auditor:
To my knowledge, you will only be able to get it to run under one or the other.
its a thing about C++.

The HUO (Hackers Unlimited Organization, see profile) is working on an OS, BSD, or possibly Darwin based..
i woulod advise the learning of ASM, it will only benefit you.

The Auditor

[ November 14, 2002: Message edited by: The Auditor ]



Well i'm not really looking for it to run in both, but rather neither. I'm looking to have it compile into a standalone program, one that doesn't require an OS. I've gotten one to work but it was made with ASM all i know is enableing the mouse and changing screen modes. Is there any compiler that will compile and use bios interrupts instead of dos or any linux, bsd, or any other one? I don't care if it's C/C++ anymore, i would rather have something a bit easier than ASM, i can't find anything good for learning ASM.
Title: Operating System Development
Post by: The Auditor on 15 November 2002, 08:42
Ahh i see what you mean now.. I apologise.

Hmm, I don't know what to suggest..
I'll have a word with the programmers with HUO and my mate AIDeveloper..
see what they think..

It should, beyond all reasonable doubt, be possible... but im not certain how one would do it, soo.. Ill find out and post as soon as i know..

Sorry about the confusion.

The Auditor
Title: Operating System Development
Post by: Kintaro on 15 November 2002, 08:58
You will have to write your own libarys or modify the orignal ones to work, its hard work but can be done, its easy to work with the GeekOS Kernel. But if you want to make an Arrogance OS then do what your doing. Im also working on a simlar thing based around networking, its currently 37 flowcharts and things.
Title: Operating System Development
Post by: voidmain on 15 November 2002, 21:41
Well, the easiest way if you want to do it in C++ is to first compile your program statically (g++ -static -o file file.cpp). Then strip it (strip file). Then make sure it's small enough to fit on a floppy. Then look over this:

http://www.groovyweb.uklinux.net/index.php?page_name=os%20newbie%20tutorial (http://www.groovyweb.uklinux.net/index.php?page_name=os%20newbie%20tutorial)

Or similar links. You will find boot loader souce code in GRUB, you can rewrite it if you want but you are probably going to have to do that part in assembly.

Obviously if you write your entire program in assembly you don't need a boot loader. Just dd it to disk like you can with the Linux kernel (actually there is only a small amount of assembly in Linux kernel, most of it is C):

# dd if=program of=/dev/fd0

Yer not workin' on a virus are ya? The last time I did such a task was using Borland TASM about 12 or 14 years ago so I don't think I'll be much more help (if I've been any at all here). But please share your code and instructions when you get it sorted. I could use an updated refresher.

[ November 15, 2002: Message edited by: void main ]

Title: Operating System Development
Post by: beltorak0 on 15 November 2002, 10:08
I used to do a heavy amount of assembly programming.  If you want to start from scratch, i suggest going there.  Of course assembly is terse; remember that it is only half a step removed from machine code: one instruction line equals one machine code instruction (unless you write some macros).  If you decide to go with assembly, get ralph brown's interrupt list .txt.

a ".com" is pure machine code.  Dos prefizes it with a "program segment prefix" which holds (the pointers to) important data; like the emegency failure routine, command line arguments, up to 2 supplied files, current environment, etc etc etc.  it is 100 bytes long (.RADIX 16).  In any event, the CS:IP (code segment & instruction pointer) points to byte 0 of the file.  There is no imposed header, like in ELF or .exe files.  They are a bit more complex in the setup, but machine code is machine code; and all memory is laid out linearly -- otherwise there would be no such thing as a buffer overflow attack.  I can't think of any online tutorials that would do better than printed resources; check out your local barnes and noble.

Creating your own OS is extreemly ... involved.  Most likely it will not run stand alone for a few incarnations -- remember that even linux required minix in order to work when it was being created.  

[never mind, thanks void main];

I am probably telling you what you already know, so i will just shut up now.  happy hacking   ;)  

-t.

[ November 15, 2002: Message edited by: beltorak0 ]

Title: Operating System Development
Post by: voidmain on 15 November 2002, 10:27
beltorak. I also started a big long message about OS design, writing your own compiler, kernel, device drivers etc, then I realized he just wants to be able to boot a simple program from a floppy without an OS or boot loader (for now anyway). You put him on the right track. And it prompted me to pull out a few old books from my wall. I know I learned how to do it long ago from one of them.

Let's see what I got here... Mastering Turbo Assembler by Tom Swan, 1989, Peter Norton's Assembly Language Book for the IBM PC 1989. I also have several DOS/BIOS interrupt books. Oh and a couple of my personal favorites "Tricks of the MS-DOS Masters" circa 1988 and if you want to learn how to manually repair a FAT table and fix those cross linked clusters using DEBUG there's Peter Norton's Hard Disk companion 1988. Should be good bathroom readin'!

[edit]
Just got back from the bathroom. Couldn't find the  COM examples for loading directly off of disk that I was looking for. Maybe I picked that up in a Byte magazine or something. Damn mind is going!!
[/edit]

[ November 15, 2002: Message edited by: void main ]

Title: Operating System Development
Post by: voidmain on 15 November 2002, 11:49
Ahh, this looks like just what you need:
http://linux.oreillynet.com/pub/a/linux/excerpts/linux_kernel/how_computer_boots.html (http://linux.oreillynet.com/pub/a/linux/excerpts/linux_kernel/how_computer_boots.html)

It would be best to understand how an existing OS boots in order to write your own (if you don't already know). The nice thing about Linux is all of the source is there for you to learn from.

And some Linux assembly tutorials and information:
http://linuxassembly.org/ (http://linuxassembly.org/)

[ November 15, 2002: Message edited by: void main ]

Title: Operating System Development
Post by: Kintaro on 15 November 2002, 13:50
Yeah, even i could do that stuff, i've read on general computer science. 86 based cpu's are really shitty to machine code. m68k's are easy though...
Title: Operating System Development
Post by: Stryker on 16 November 2002, 02:41
Well what I was thinking of doing was something like...

Make a .com file that doesn't use dos interrupts.

Make a small assembly program that will go to a certain byte on a disk and start executing there.

use debug to put it on the floppy disk

add the signature with e 2fe aa 55

write the assembly goodie to the disk, use debug to move the .com file to the place i specified in the assembly program.

But the thing is I don't know how to compile a .com file that doesn't use dos interrupts. I'll be back in a while, going to check out those links.
Title: Operating System Development
Post by: voidmain on 16 November 2002, 04:54
Believe it or not, it's not as hard as you are making it. If you make the right kind of COM file in assembly all you have to do is write it to the floppy starting at the first sector (the hardware automatically loads and executes the first sector on disk). You can write your program to raw floppy using debug, but it's easier to use "dd" or "rawrite".

Now since it only automatically loads and executes the first sector of the floppy (512 bytes) if your program is bigger than that you may have to call a BIOS interrupt to load the 2nd through ?? sectors into memory and jump to that memory location to continue execution. But I can't remember if the programs I used to write were small enough to fit entirely on the first sector. The helloworld.asm example on that linuxassembly site I linked to you was only around 400 bytes when assembled.

And by the way, you don't "compile" a *.com file. You compile source into object code using a compiler (could be C, C++, Pascal, etc). You "assemble" assembly code into object code. And in both cases you use the linker to create the executable file from the object code (weather it be *.COM, *.EXE, a.out, elf, etc). But you probably already know this....
Title: Operating System Development
Post by: Stryker on 16 November 2002, 05:04
quote:
Originally posted by void main:
Believe it or not, it's not as hard as you are making it. If you make the right kind of COM file in assembly all you have to do is write it to the floppy starting at the first sector (the hardware automatically loads and executes the first sector on disk). You can write your program to raw floppy using debug, but it's easier to use "dd" or "rawrite".

Now since it only automatically loads and executes the first sector of the floppy (512 bytes) if your program is bigger than that you may have to call a BIOS interrupt to load the 2nd through ?? sectors into memory and jump to that memory location to continue execution. But I can't remember if the programs I used to write were small enough to fit entirely on the first sector. The helloworld.asm example on that linuxassembly site I linked to you was only around 400 bytes when assembled.

And by the way, you don't "compile" a *.com file. You compile source into object code using a compiler (could be C, C++, Pascal, etc). You "assemble" assembly code into object code. And in both cases you use the linker to create the executable file from the object code (weather it be *.COM, *.EXE, a.out, elf, etc). But you probably already know this....



Well I wasn't going for vocabulary, i just try to get my point across. i used to make programs with quickbasic (is it the good old days, or is it the undeducated days?) to make those .com files, anyone know if it uses dos interrupts? i made some pretty cool graphics programs, there would be an interesting operating system. i'll give it a shot.
Title: Operating System Development
Post by: Kintaro on 16 November 2002, 05:26
You could just make a bootable MS-DOS and have your program start in autoexec and use a Hex editor so it says "Starting StrykerOS" instead of "Starting Windows 95" or whatever it used to say!
Title: Operating System Development
Post by: Stryker on 16 November 2002, 05:49
quote:
Originally posted by Ex Eleven / b0b 2.1:
You could just make a bootable MS-DOS and have your program start in autoexec and use a Hex editor so it says "Starting StrykerOS" instead of "Starting Windows 95" or whatever it used to say!


What? and live with the guilt of using microsoft products? i suppose i could, i've done it before, it's just that... isn't that basicly what microsoft did. bought dos from some guys and changed the banner?
Title: Operating System Development
Post by: Kintaro on 16 November 2002, 06:02
Actually use Freedos its opensource!
Title: Operating System Development
Post by: voidmain on 16 November 2002, 06:08
quote:
Originally posted by Stryker:
i used to make programs with quickbasic (is it the good old days, or is it the undeducated days?) to make those .com files, anyone know if it uses dos interrupts? i made some pretty cool graphics programs, there would be an interesting operating system. i'll give it a shot.


That depends on if you call DOS interrupts in your assembly program or not. In assembly it's not going to use *anything* you do not write. If you call a DOS interrupt your program will use DOS interrupts. If you call a BIOS interrupt your program will use BIOS interrupts. And I can guarantee you that if you write your assembly program in Linux it will not contain DOS interrupts. Remember, it's one line of code for one processor instruction. You certainly will not be able to create a program like this in quickbasic.    (http://smile.gif)  

Maybe you are not ready for this. You might try something like X11 said and use a boot disk using a boot loader of another OS (doesn't have to be Microsoft). Then you can write your program in C or C++ and have it autoload when you boot the floppy. You could use FreeDOS and stick with that crappy DOS/WIN type of environment or you could use Linux or FreeBSD to create programs and your disk.

[ November 15, 2002: Message edited by: void main ]

Title: Operating System Development
Post by: voidmain on 16 November 2002, 12:32
Found a couple of interesting links. The Win95 boot sector assembly code (reverse engineered, comments are great!):
http://www.singlix.com/trdos/win95_boot_sector.asm (http://www.singlix.com/trdos/win95_boot_sector.asm)

Linux 2.0 boot sector code:
http://www.singlix.com/trdos/Linux%202_0%20Boot%20Sector.html (http://www.singlix.com/trdos/Linux%202_0%20Boot%20Sector.html)

But this one might be the mother link which tells you how to use GCC (C) to make plain binary executable code that can be booted directly from a boot sector:
http://www.nondot.org/~sabre/os/articles/TheBootProcess/ (http://www.nondot.org/~sabre/os/articles/TheBootProcess/)

In effect allowing you to boot your code without the help of any other code from any other vendor (not counting the code within your hardware). I think this is what you were asking to do in the first place.

And if you want to look at the boot sector source on your currect kernel, if you have the kernel source installed you will find it here:

/usr/src/linux*/arch/i386/boot/bootsect.S

*.S files contain assembly code that must be preprocessed. I just looked at the Makefile and here are the commands that you would use to turn that source into a binary executable boot sector that can be written to the first sector of a floppy or hard disk partition:

Code: [Select]

You should now find a file called "bootsect" which is exactly 512 bytes long and can be written to floppy with "dd if=bootsect of=/dev/fd0". Of course by itself it won't do much, probably just hang your system.

You might want to look at the comments within the other *.S files that are located in the same directory. There are only a few small files that are responsible for loading/running the kernel. You will need to know a little assembly in any case. Fortunately it doesn't take much.

[ November 16, 2002: Message edited by: void main ]

Title: Operating System Development
Post by: Kintaro on 16 November 2002, 13:32
Basically this boot sector code is 32 bit extension for a 16 bit patch to
an 8 bit boot sector originally coded for a 4 bit microprocessor, written
by a 2 bit company, that can't stand 1 bit of competition.


How would i go about compiling this is tasm?
Title: Operating System Development
Post by: voidmain on 16 November 2002, 13:53
You wouldn't compile it. But you might assemble it.  (http://smile.gif)
Title: Operating System Development
Post by: Kintaro on 16 November 2002, 13:59
Oh yeah, thats what i ment
Title: Operating System Development
Post by: voidmain on 16 November 2002, 14:11
The instructions are right in the source between the 2 bit company and the top of the file:

C:> tasm win95 /m
C:> tlink win95,win95.bin /t
Title: Operating System Development
Post by: Kintaro on 16 November 2002, 14:49
Sorry i ment nasm, the one that comes with Red-Hat
Title: Operating System Development
Post by: voidmain on 16 November 2002, 23:43
You would have to do a little rewriting to assemble it with "nasm". This code is written in TASM format.  Look over that other link with nasm bootstrap examples. It shouldn't take much to convert it to nasm format:

http://www.nondot.org/sabre/os/files/Booting/nasmBoot.txt (http://www.nondot.org/sabre/os/files/Booting/nasmBoot.txt)