OSDev.org

The Place to Start for Operating System Developers
It is currently Thu May 09, 2024 7:25 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: ASM and C in a Bootloader
PostPosted: Sun Jun 01, 2008 9:29 am 
Offline
Member
Member
User avatar

Joined: Tue May 27, 2008 2:42 am
Posts: 26
Location: Great Yarmouth, Norfolk, United Kingdom
Hi guys, I'm back with another question. And here it is:

Is it possible to use Assembly and C in a bootloader? If so, please tell me how. I tried the wiki but I couldn't seem to pick anything up from it.

Thanks,
Ollie. :D :D


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 01, 2008 10:04 am 
Offline
Member
Member

Joined: Mon Mar 24, 2008 1:46 pm
Posts: 98
for a boot sector i think you can only use asm

but for a bootloader something like grub, you can use anything you want really.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 01, 2008 10:06 am 
Offline
Member
Member
User avatar

Joined: Tue May 27, 2008 2:42 am
Posts: 26
Location: Great Yarmouth, Norfolk, United Kingdom
itisiuk wrote:
for a boot sector i think you can only use asm

but for a bootloader something like grub, you can use anything you want really.


Ok thanks, I'll write my bootsector in ASM. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 01, 2008 10:28 am 
Offline
Member
Member
User avatar

Joined: Tue Feb 20, 2007 3:00 pm
Posts: 672
Location: London UK
Its possible to put C in a boot sector, its just really hard and stupid...
Jules


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 01, 2008 10:31 am 
Offline
Member
Member

Joined: Tue May 06, 2008 9:32 am
Posts: 87
Location: The Netherlands
The first part of your bootloader will be 16-bit code. It's possible to create 16-bit code with C (I have seen people doing it in Borland C 2.0) but there are a limited number of compilers and I don't know a free one (free as in free speech, not free beer).

With free compilers like GCC you can make 32-bit code. I wrote the 16-bit parts in assembly, after switch to a protected mode 32-bit codesegment you can use code written in C.

There are some complications: In the bootloader you need to call the BIOS for loading disksectors. You have to choose between writing the routines for loading files in memory in 16-bit realmode (when the memory is full you can switch to protected mode to move the read files to a higher part in memory) or in 32-bit protectedmode (for sector reading you temporary switch back to realmode). If you choose 32-bit you can write everything in C, but you have to write some assembly routines switching to realmode and reading sectors.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 01, 2008 10:57 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 11:33 pm
Posts: 3882
Location: Eindhoven
There is BCC, Bruce's C Compiler. That is a 16-bit compiler but it is a bit awkward to use as it doesn't do C89, let alone any variant after that.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 6:44 am 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 9:29 pm
Posts: 2426
Location: Canada
Candy wrote:
There is BCC, Bruce's C Compiler. That is a 16-bit compiler but it is a bit awkward to use as it doesn't do C89, let alone any variant after that.
I know, K&R with some ANSI tacked on... using the -ansi argument might make it less-awkward. :lol:

EDIT: http://tack.sourceforge.net/ seems to have 8086 support, this was the C compiler used by Minix once upon a time, BSD licenced now.

"The ACK contains compilers for ANSI C, K&R C, Pascal, Modula-2, Occam 1, and a primitive Basic."

_________________
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 8:59 am 
Offline

Joined: Tue Feb 26, 2008 3:43 am
Posts: 22
Location: The Netherlands
Actually, using GAS's '.code16gcc' directive, GCC can be used to write C code for a 16 bit code segment.
GAS will add the necessary address/operand override prefixes to the 32 bit instructions generated by GCC.

Just make sure you stay within your data segment limits. ;)
For a real life example of 16 bit c code, examine the linux boot code. (arch\x86\boot)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 10:08 am 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 775
Location: London, UK
AFAIK OpenWatcom at least used to support compiling to 16-bit code with some extensions to allow supporting segments.

Regards,
John.

_________________
Tysos | rpi-boot


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 22 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