flat assembler
Message board for the users of flat assembler.

Index > OS Construction > File formats

Author
Thread Post new topic Reply to topic
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 12 Aug 2005, 21:59
Pardon me if this sounds newbish, because I am a n00b at OS development, and other than flat binary I do not understand any of the other file formats (ELF, COFF, PE, etc.), which I will be sending to the linker ld along with a DJGPP program.

I'm finally going to get started writing my kernel, but now a new problem comes up. All the tutorials I see use NASM and DJGPP, and I want to use FASM (of course) and DJGPP. Since I don't know a whole lot about PE, COFF, or ELF, I'm unable to convert this NASM code:
Code:
; Note: Semicolens are comments in Assembly (ASM)

[bits 32] ;Make our OS 32bit

SECTION .text

EXTERN _c_main ;Reference to our main function in the c code.
;Note that our function in C starts with an underscore (_)
;This is because when we compile our C file, functions are started with
;underscores. This is not so for ASM files though.

start:
call _c_main ;This calls our main function in the C file
jmp $ ;Freezes the computer because theres nowhere else to go!
    

to FASM. I will of course be linking with the C program (compiled in DJGPP) which will contain the function c_main (which apparently becomes _c_main when compiled by DJGPP and other gcc variants) using ld.
So what is the FASM equivalent of this code? Do I need an "org 0x10000" somewhere, or do I simply tell ld where to originate from?

I will probably be using either COFF or ELF (but ld will convert to plain binary for me). Which should I use, or does it matter?

Feel free to flame me if I'm asking stupid questions, or being newbish in general. I won't mind. Smile

_________________
FASM Rules!
OS Dev is fun!
Pepsi tastes nasty!
Some ants toot!
It's over!
Post 12 Aug 2005, 21:59
View user's profile Send private message AIM Address Reply with quote
DataHunter2009



Joined: 10 Jun 2005
Posts: 144
DataHunter2009 13 Aug 2005, 01:52
I used to use an example like the one you posted there. I found it later on converted to FASM around here somewhere. I don't have the link anymore. I'm sure someone would post it though.

As for the file formats, I had to use ELF one time for a kernel, but I never really read up on what ELF was.
Post 13 Aug 2005, 01:52
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 13 Aug 2005, 10:59
With ld you will probably prefer ELF, though it supports COFF, too.
You above sample converted to fasm looks like:
Code:
FORMAT ELF

SECTION '.text' EXECUTABLE

EXTRN _c_main

start:
call _c_main
jmp $    

or this way for COFF format:
Code:
FORMAT COFF

SECTION '.text' CODE

EXTRN _c_main

start:
call _c_main
jmp $    
Post 13 Aug 2005, 10:59
View user's profile Send private message Visit poster's website Reply with quote
DataHunter2009



Joined: 10 Jun 2005
Posts: 144
DataHunter2009 13 Aug 2005, 13:06
What exactly is the difference between ELF and COFF? I really only see one difference in code. Are there speed issues aswell?
Post 13 Aug 2005, 13:06
View user's profile Send private message Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade 13 Aug 2005, 21:43
The only difference between ELF and COFF is the file header. IF one has a smaller header, then it might be faster to run, as theres less data to parse, but thats a tiny difference, if any. Just make sure your kernel doesnt suck, and it'll run fine Wink

Anyway, you have no need to stick to these file formats if your making your own OS. the only reason you'd stick to these is if you wanted to make it able to run other OS's programs on your OS. ie: ReactOS allows you to run windows programs on it. therefore would have to use the coff format (or that other windows one)
Post 13 Aug 2005, 21:43
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 13 Aug 2005, 23:44
But I guess he wants to use the object format to link the assembly code with C code into the simple flat binary for the OS. In this aspect it actually doesn't matter whether you use ELF or COFF, since ld supports both.
Post 13 Aug 2005, 23:44
View user's profile Send private message Visit poster's website Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 14 Aug 2005, 18:07
I will use ELF (I was planning to use that anyways, unless someone recommended I do otherwise).

Thanks! I see ELF and COFF look pretty much the same in FASM, except that with ELF you type "format elf" and with COFF you type "format coff". I see use32 is not included in the code, which I assume is because both ELF and COFF support 32 bits only (except ELF64).

Maybe I shouldn't say file formats. What I meant is "how to make a ELF/COFF object in FASM?" which has been answered sufficiently. Thanks!

Maybe someone should write a simple tutorial for using FASM in conjunction with DJGPP (or any other language for that matter). Also one on converting NASM code to FASM. This would be useful for newbies like me (in OS development or for other things).
Post 14 Aug 2005, 18:07
View user's profile Send private message AIM Address Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 14 Aug 2005, 20:44
I guess I forgot to mention I'm using the DOS ld, from the DJGPP binutils. When I tried to link the C object (kernel_c.o) with the assembly object (kernel.o) it didn't recognize the format. Should I switch to COFF, or does anyone know how to use ELF files with this port of ld? Here's the commandline I use:
Code:
ld -Ttext 0xFF800000 --oformat binary -o kernel.sys kernel.o kernel_c.o
    

The kernel loads to 0x10000 physical memory (it's in protected mode). When I made a plain binary file with just FASM, I started it with "org 0x10000". How do I do this with ld? Should I change "0xFF800000" to "0x10000" or what? Sorry, if this is really newbish, but I've never had any use for this sort of thing before; I used to program in only assembly, but I want to write my kernel in C and assembly, now!

Looking at man pages weren't much help, they are too technical and don't make much sense.

If it helps any, these are the tutorials I'm looking at:

http://www.pscode.com/vb/scripts/ShowCode.asp txtCodeId=4513&lngWId=3

http://www.osdever.net/bkerndev/Docs/basickernel.htm

Thanks, and sorry if I sound newbish!

_________________
FASM Rules!
OS Dev is fun!
Pepsi tastes nasty!
Some ants toot!
It's over!
Post 14 Aug 2005, 20:44
View user's profile Send private message AIM Address Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 16 Aug 2005, 14:49
After much trial and error, I discovered that ld from the DJGPP binutils for DOS expects MS COFF rather than ELF or COFF.

So I changed "format ELF" to "format MS COFF" and it worked just fine.

_________________
FASM Rules!
OS Dev is fun!
Pepsi tastes nasty!
Some ants toot!
It's over!
Post 16 Aug 2005, 14:49
View user's profile Send private message AIM Address Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 16 Aug 2005, 15:02
You might want to have a look at http://www.mingw.org/ instead of djgpp, at least if you're developing under windows. Or you could use the (free) MS VC2003 toolkit and have your kernel in PE format.

There isn't much reason to use a binary format kernel... "proper" formats allow things like per-section protection, and a this will work until I write it properly "loader" for PE executables is something like 5 assembly instructions more than a flat binary loader...
Post 16 Aug 2005, 15:02
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.