booting to a C file.

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.
Post Reply
vbbrett

booting to a C file.

Post by vbbrett »

I have used assembly in 16 bit mode and have pretty much mastered that. The problem is that I would like to move to 32 bit mode and enable the A20 along with all the other little things. I'm not entirely sure HOW to do this, or WHAT to do to accomplish this. I want to then execute a C file(which I know can be done under a binary format). Any help, or ideas, would be helpful at this point.

It's great to be able to boot a floppy and see some text, but it isn't really ,ummmmm, real. I would like to see more.

Another thing, I'd much rather I read something telling me how to do it, than have someone copy code for me. In my mind the OS isn't really mine, but someone elses endeavours. So, any thoughts, ect, about HOW to do this, WHAT to do, Anthing. Thanks,
vbbrett
Slasher

Re:booting to a C file.

Post by Slasher »

hi, as you know 16 bit asm well you are ahead of the game. The next thing is to get you hands on the intel x86 manuals, some protected mode tutorials and a simple C kernel tutorial.
check this post
http://www.mega-tokyo.com/forum/index.p ... eadid=3254
and then
www.osdev.net.
All you need is there.
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:booting to a C file.

Post by Pype.Clicker »

be prepared: writing pmode switch code from scratch (even for someone who mastered ASM) is probably the trickiest thing ever, because there are soooo many little thing you will hardly think of when looking for docs. This is probably one of the area where you will eventually have to get a look at someone else's job ... or make fixes during years each time you move to a new platform :-/

I don't really recommend the tutorials of Alexei F. because they're requiring a 16 bits C compiler -- something that becomes hard to find nowadays.

Probably TRAN's pmode tutorial on http://www.nondot.org/sabre/os/articles/ProtectedMode/ is the best i've found, but it's targetted as a dos extender, so there will probably be lot of things that will be of no use for you :(
Slasher

Re:booting to a C file.

Post by Slasher »

But with Alexei F.'s tutotials the ASM parts are valid. He just has to use a 32 bits compiler of his choice (C,Pascal etc) where Alexi used the 16 bits C compiler.
vbbrett

Re:booting to a C file.

Post by vbbrett »

Okay, so, I'm going to use someone elses code. The best I could find was John Fine's stuff, but his boot sector didn't work. Here's the link to his page: http://my.execpc.com/~geezer/johnfine/
The download is named bootp02.zip. I compiled all that and burned it to a floppy, Just like he said at the end of the code in the .Asm file. Still, It just beeps, like he said it would if it encountered an error. So, what would like?
I would like you to recommend some type of bootstrap that will execute a binary off my hard disk, just like this one. If you can get one of Johns bootsectors to work, tell me how. I've looked and it seems that there really isn't any FULLY working one around. I'd like to basically setup all the tables(gdt,ect) permanently(not temporarily) and go into Pmode, then boot the kernel. How this is accomplished, I still can't get it through my head, I do not know. So, I figure, if I can get to coding a C file I should be able to do everthing else from there, and easier than in NASM. Any suggestions,thoughts,help,anything, would be useful right now.
thank you again,
vbbrett
Curufir

Re:booting to a C file.

Post by Curufir »

Are you actually using it properly?

I ask this because it's unusual to find many people having an active FAT16 partition lying around their hardrive.

As for suggestions I'd have to go along with the words of ye olde sage Tim Robinson :) in this instance. Use GRUB and forget about writing bootloaders until you have something worth loading.
vbbrett

Re:booting to a C file.

Post by vbbrett »

Yeah, I believe that I agree with that comment. Yes, I will just build something worth booting. So, I've got DJGPP. Now, I know C, but not this type of C. Because when I compile and link, it doesn't like my style. So, How do you compile and link correctly a .c file into a flat binary? Oh, and, can someone give me some pointers, or commented code, on how to write a simple 32bit app to print "Hello World" by writing to the video memory?
vbbrett
Tim

Re:booting to a C file.

Post by Tim »

vbbrett wrote: Yeah, I believe that I agree with that comment. Yes, I will just build something worth booting. So, I've got DJGPP. Now, I know C, but not this type of C. Because when I compile and link, it doesn't like my style.
:) I've got a picture in my head of a compiler error message: "kernel.c(3): I don't like your style!"
So, How do you compile and link correctly a .c file into a flat binary? Oh, and, can someone give me some pointers, or commented code, on how to write a simple 32bit app to print "Hello World" by writing to the video memory?
You don't have to link to binary if you're using GRUB. It's easiest to use ELF. There is a sample C kernel in the GRUB source code package which demonstrates an assembly-language stub, a simple printf, and some code to dump the multiboot info structure to the screen.

PS: I recommend getting a compiler other than DJGPP. Cygwin and Mingw are both more recent and have more features. DJGPP has traditionally been a bit unreliable under Windows, whereas Cygwin and Mingw are native Win32 ports of gcc and binutils (and lots more). Besides, Cygwin supports ELF out of the box, whereas I believe you have to download a patch to get DJGPP to emit ELF.
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:booting to a C file.

Post by Pype.Clicker »

@Tim: I can remember of people on this board that had hard time trying to boot an ELF kernel with GRUB ... do you have a step-by-step tutorials in your carddeck ? or is it so simple that "cp kernel.elf /floppy/kernel" and then "root fd(0) ; kernel /kernel/kernel.elf" does the trick ?
Tim

Re:booting to a C file.

Post by Tim »

Yes, assuming you've got a pre-built GRUB floppy, i.e. one that's formatted for FAT or Minix, has stage1 in the boot sector, and has stage2 as a file somewhere.

I think df posted one of those. If you follow the instructions in the GRUB tutorial on www.osdever.net you shouldn't find it too hard. (I'd post a URL, but www.osdever.net is down at the moment.)
Post Reply