OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 12:12 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 52 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: C os programming
PostPosted: Mon Aug 15, 2005 4:19 am 
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).


Top
  
 
 Post subject: Re:C os programming
PostPosted: Mon Aug 15, 2005 6:28 am 
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


Top
  
 
 Post subject: Re:C os programming
PostPosted: Mon Aug 15, 2005 6:34 am 
I don't use grub.
I use a fat12 bootloader.
I tryied the methods described, but it doesn't work.


Top
  
 
 Post subject: Re:C os programming
PostPosted: Mon Aug 15, 2005 6:40 am 
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.


Top
  
 
 Post subject: Re:C os programming
PostPosted: Mon Aug 15, 2005 6:45 am 
That is not possible, without knowing what interface whatever bootloader you use provides there is no way to demonstrate a starting template


Top
  
 
 Post subject: Re:C os programming
PostPosted: Mon Aug 15, 2005 6:49 am 
You can show me a protected mode bootloader too. my bootloader is in real mode.


Top
  
 
 Post subject: Re:C os programming
PostPosted: Mon Aug 15, 2005 8:00 am 
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


Top
  
 
 Post subject: Re:C os programming
PostPosted: Mon Aug 15, 2005 8:08 am 
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.


Top
  
 
 Post subject: Re:C os programming
PostPosted: Mon Aug 15, 2005 11:15 am 
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.


Top
  
 
 Post subject: Re:C os programming
PostPosted: Tue Aug 16, 2005 2:32 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
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.

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:C os programming
PostPosted: Wed Aug 17, 2005 4:58 am 
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).


Top
  
 
 Post subject: Re:C os programming
PostPosted: Wed Aug 17, 2005 5:28 am 
The code is attached.


Top
  
 
 Post subject: Re:C os programming
PostPosted: Wed Aug 17, 2005 5:33 am 
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


Top
  
 
 Post subject: Re:C os programming
PostPosted: Wed Aug 17, 2005 5:36 am 
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.


Top
  
 
 Post subject: Re:C os programming
PostPosted: Wed Aug 17, 2005 5:39 am 
Quote:
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.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 52 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 91 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group