Steps to build an OS, am I doing it right?

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.
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Steps to build an OS, am I doing it right?

Post by Kevin »

rdos wrote:Putting the OS at raw sectors is also possible, although a little awkward.
Indeed. In my experience, one of the most common mistakes that newbies make with their quick hack that they call a boot loader is that they load only n sectors and don't notice when the kernel grows to n+1 sectors. To fix it, some even just increase it to m sectors and come back asking for help when the kernel reaches m+1 sectors...
A custom boot-loader definitely doesn't need to know file formats, unless the OS creator never heard binary file formats.
Using ELF for the kernel has its advantages. Debug information, symbols available at runtime, stuff like this. Yes, I guess you can work around it. But... why not just use a file format that provides it from the start?
Developer of tyndur - community OS of Lowlevel (German)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Steps to build an OS, am I doing it right?

Post by Combuster »

rdos wrote:A custom boot-loader definitely doesn't need to know file formats, unless the OS creator never heard binary file formats.
A flat file is still a format. The only difference is that the headers you "got rid of" are now magic numbers in the bootloader code.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: Steps to build an OS, am I doing it right?

Post by Yoda »

Flat binary format is inevitable somwhere as intermediate step between ELF and first stage boot loader.
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
rdos
Member
Member
Posts: 3306
Joined: Wed Oct 01, 2008 1:55 pm

Re: Steps to build an OS, am I doing it right?

Post by rdos »

Kevin wrote:Using ELF for the kernel has its advantages. Debug information, symbols available at runtime, stuff like this. Yes, I guess you can work around it. But... why not just use a file format that provides it from the start?
Yes, but it is better to have the symbols in a separate file rather than in the kernel image itself.
rdos
Member
Member
Posts: 3306
Joined: Wed Oct 01, 2008 1:55 pm

Re: Steps to build an OS, am I doing it right?

Post by rdos »

Yoda wrote:Flat binary format is inevitable somwhere as intermediate step between ELF and first stage boot loader.
It depends how we define "flat binary". If you also include a real-mode loader, you are right. If you mean a 32/64 bit flat binary, no. That is not necessary. It is not even necessary to have kernel in ELF or PE. There are alternatives (including own header definitions which I use).
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Steps to build an OS, am I doing it right?

Post by Kevin »

rdos wrote:Yes, but it is better to have the symbols in a separate file rather than in the kernel image itself.
For using them with an external debugger, like wih a gdb stub, probably a matter of taste (and for those using floppies, potentially of disk image size).

For actually using them in the kernel at runtime, like for backtraces or loading modules, I can't see why having them in a separate file would be a good idea.
Developer of tyndur - community OS of Lowlevel (German)
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Steps to build an OS, am I doing it right?

Post by bluemoon »

rdos wrote:Yes, but it is better to have the symbols in a separate file rather than in the kernel image itself.
I suppose you know that the symbols & debug info can be strip into another file.

I do this to my kernel binary (ELF32/ELF64)

Code: Select all

$(KERNEL_BIN): $(KERNEL_TMP) $(KERNEL_OBJ) $(KERNEL_USELIB) Makefile
	@echo [LINK] $@
	@$(LD) $(LDFLAGS) -Tarch/$(ARCH)/kernel.ld -o $@ $(KERNEL_OBJ) $(KERNEL_USELIB)
	@$(OBJCOPY) --only-keep-debug $@ $(KERNEL_SYM)
	@$(OBJCOPY) --strip-debug --strip-unneeded $@
FallenAvatar
Member
Member
Posts: 283
Joined: Mon Jan 03, 2011 6:58 pm

Re: Steps to build an OS, am I doing it right?

Post by FallenAvatar »

bluemoon wrote:
rdos wrote:Yes, but it is better to have the symbols in a separate file rather than in the kernel image itself.
I suppose you know that the symbols & debug info can be strip into another file.
I can't believe I am saying this, but I agree with rdos (Hell froze over? haha)

This has been a default/feature/whatever of microsoft compiliers/linkers for a while. They use a seperate file (*.pdb) that contains the debug info. This has some advantages, if your kernel code has all of 1-3 extra lines of code, its easy to ignore missing debug info, and then just delete them from releases. This CAN be easier to maintain (but is not be default). It also has the advantage of giving you, the developer, a realistic idea of the size of a binary file (ie. without debugging info) And this plays nice with both local and remote debugging techniques.

However, this does require extra code to load the debug info when it is present, and may not be feasible in early stages of development.

So, both ways work, both ways make "sense" and both ways have pros/cons. This really comes down to personal preference/experience.

- Monk
Kirk
Posts: 5
Joined: Wed Nov 07, 2012 12:32 pm

Re: Steps to build an OS, am I doing it right?

Post by Kirk »

I think the OP hasn't grasped the very basics. Read James's tutorials:

http://www.jamesmolloy.co.uk/index.html
Post Reply