C os programming

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
SpiglerG

C os programming

Post by SpiglerG »

I have installed djgpp and nasmw. i'm using windows, but i have a linux partition too.
I programmed a simple assembly written operating system(http://www.ados.asmhackers.net) and now i want to evolve it to protected mode and c.
I tryed some example operating system written in c, but i can't compile them.
Could someone tell me all the operations i need to program it: the command prompt lines to write, the needed files and all the other things i need?

*modify* i tryied djgpp, but i think i will use dev-cpp(its gcc based).
AR

Re:C os programming

Post by AR »

MinGW32 (Dev-C++'s compiler) is not particularly good for OS Dev unless you want everything to be a PE binary.

I suggest you read the Wiki because this stuff is already covered in there. See the Barebones example as well
SpiglerG

Re:C os programming

Post by SpiglerG »

I don't use grub.
I use a fat12 bootloader.
I tryied the methods described, but it doesn't work.
SpiglerG

Re:C os programming

Post by SpiglerG »

I can use linux's gcc or windows' cygwin, too. I have red hat linux installed on my computer.
Now, i need all the steps i need to do to program a simple, 32bit c mixed asm operating system. i need only a compilable template, so i can modify it as i would.
AR

Re:C os programming

Post by AR »

That is not possible, without knowing what interface whatever bootloader you use provides there is no way to demonstrate a starting template
SpiglerG

Re:C os programming

Post by SpiglerG »

You can show me a protected mode bootloader too. my bootloader is in real mode.
oswizard

Re:C os programming

Post by oswizard »

What I have in my OS is a three-stage boot loader, all written in assembler.

The first part is FAT-aware, and all it does is load the second stage off the disk.

The second stage is also FAT-aware, and it loads the kernel image, a third stage, and any device drivers into memory by using unreal mode and BIOS interrupts. It then enables protected mode and jumps to the third stage.

The third stage enables paging and jumps to the kernel. On the x64 version of my OS, it also enables long mode.

You could probably do it in two stages, both in assembler. Keep your first stage, and instead of it loading the OS directly, have it load a small file that just loads the next stage (the C kernel), enters protected mode, and then jumps to the C code. It would be extremely complicated, if impossible, to try to write the boot loader in C. I don't want to just give away the source code to mine, as it is probably more complex than you need.

Besides, it would have been difficult for me to write the rest of my OS if I didn't have a solid understanding of what happens at boot time. IMHO, that's the best thing about not using GRUB, and I think you made a good choice not to use it. It may take quite a bit of work, but you get to see what really goes on. (Please - let's not start a GRUB vs. Custom war here. Everyone has their own views that are not going to change because of what anyone else says)

Good luck,
Mike
SpiglerG

Re:C os programming

Post by SpiglerG »

As i said, i've programmed an os first than this i want to program.
It has the bootloader, wich load directly the kernel into the memory off the floppy. I know that most protected mode os have another file, to activate the drivers and the protected mode, then the kernel.
My current os doesn't use protected mode, but maybe i need to transform it to protected mode, first, and then write the call _main to jump to the c program to evolve the os.
Maybe, i need to wait and jump to protected mode before use c to develop the os.
So, if anyone can help me to use protected mode for an asm kernel, please post tips.
SpiglerG

Re:C os programming

Post by SpiglerG »

Ok. when i was planning a protected mode boot loader for my current os, i re-tryied to build a simple c kernel(basic printf and clrscr functions) with djgpp, and it worked!
Tomorrow i'll write the bootloader and test the kernel.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:C os programming

Post by Pype.Clicker »

SpiglerG wrote: As i said, i've programmed an os first than this i want to program.
It has the bootloader, wich load directly the kernel into the memory off the floppy. I know that most protected mode os have another file, to activate the drivers and the protected mode, then the kernel.
My current os doesn't use protected mode, but maybe i need to transform it to protected mode, first, and then write the call _main to jump to the c program to evolve the os.
Maybe, i need to wait and jump to protected mode before use c to develop the os.
So, if anyone can help me to use protected mode for an asm kernel, please post tips.
expect troubles while loading djgpp-generated code in real mode. See this thread if you still wonder why.
SpiglerG

Re:C os programming

Post by SpiglerG »

I have a problem.
I compiled the c kernel without errors and linked it to the loader, too.
I want to try 2 different things: 32bit real mode and 32bit protected mode, but they don't work.
Later i'll post my code here(half an hour).
SpiglerG

Re:C os programming

Post by SpiglerG »

The code is attached.
AR

Re:C os programming

Post by AR »

SpiglerG wrote:... 32bit real mode ...
what? There's no such thing. You only have:
  • Real mode (16bit 8086 legacy)
  • 16bit protected mode
  • 32bit protected mode
  • (AMD64) 64bit long mode
  • (AMD64) 32/16bit compatibility long mode
SpiglerG

Re:C os programming

Post by SpiglerG »

Ok. thanks. i didn't know.

so, could you help me? i need someone to correct and update the code in the .zip i posted. i know a simple method to switch to protected mode and load a gdt, but if someone could post some code, i'll be very happy.
beyondsociety

Re:C os programming

Post by beyondsociety »

I compiled the c kernel without errors and linked it to the loader, too. I want to try 2 different things: 32bit real mode and 32bit protected mode, but they don't work.
Later i'll post my code here(half an hour).
There is no such thing as 32bit real mode. Are you thinking of unreal mode? unreal mode = code and stack are 16-bit, so code and stack segments cant be larger than 64kb. However data segments can cover the entire 4GB of address space, so you can use the 32bit registers to access data anywhere in memory.

There's also (16bit) real mode, 16bit protected mode, and 32 bit protected mode.

Hope this helps.
Post Reply