Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Boot sector with GNU as

403 views
Skip to first unread message

Varghese Mathew

unread,
Mar 12, 2008, 6:20:30 AM3/12/08
to

If I have my bootloader (or some program to run at system boot, for that
matter) written in AT&T style assembly, targeted for the i386 based IBM-PC,
then how do I assemble the same and put it into the bootsector of
/dev/fd0 ?

I would like to use GNU 'as' and do this from a GNU/linux box.

Can someone give me a quick intro / some good pointer for the same ?

Thanks in advance
Varghese

bj7lewis

unread,
Mar 12, 2008, 9:23:39 AM3/12/08
to
> If I have my bootloader (or some program to run at system boot, for that
Grub Is a boot loader I use to start out with... Check out
"http://www.gnu.org/software/grub/"...

> I would like to use GNU 'as' and do this from a GNU/linux box.

ASM coding style doesn't matter to the CPU just that machine language code +
your bootsector data + any padding must fit in 512 bytes with the boot sign
'55 AA' hex value.

For linux you can use "dd" cmd. I use windows so you need to check out
"http://www.osdever.net/tutorials/hello_btldr.php" under "Installing a boot
loader" heading...


bj7lewis

unread,
Mar 12, 2008, 10:10:44 AM3/12/08
to
> ... must fit in 512 bytes with the boot sign '55 AA' hex value.
My bad - that should read "... boot sig '55 AA' hex value at placed at
offset 0x1fe..."


Varghese Mathew

unread,
Mar 12, 2008, 1:34:29 PM3/12/08
to
Oops, I should have made it clearer..

How do I get GNU as to assemble in native code without all elf/whatever
headers etc in so that I can put the code into the boot sector.

I couldn't figure out the options..

-Varghese

Varghese Mathew

unread,
Mar 12, 2008, 3:36:21 PM3/12/08
to

Jordi Sanfeliu

unread,
Mar 12, 2008, 4:51:21 PM3/12/08
to
On 12 Març, 18:34, Varghese Mathew <varghese85-does-not-ex...@no-spam-

please.org> wrote:
> Oops, I should have made it clearer..
>
> How do I get GNU as to assemble in native code without all elf/whatever
> headers etc in so that I can put the code into the boot sector.
>

You can generate your code using GAS (keeping in mind you must use
16bit code), and once compiled you can convert it to a raw data using:

objcopy -b binary boot finalboot

See the GRUB source code as it's a clear example of what you want to
do.

bj7lewis

unread,
Mar 12, 2008, 5:04:07 PM3/12/08
to
> How do I get GNU as to assemble in native code without all elf/whatever
> headers etc in so that I can put the code into the boot sector.
I sorry - I first started out with nasm to build my bootsect and loader it
generate raw COM files from the get go. Now I use grub cause it loades elf
kernels which is now what I am using and dropped the bootsect and loader
steps...


Varghese Mathew

unread,
Mar 12, 2008, 11:56:44 PM3/12/08
to

Have you used grub2 (grub 1.* versions) ?

The Grub Manual gives info on Grub .97 which they now call Grub Legacy.
That version seems to be easy to me.. build the stage1 and stage2..
and then create the boot device..

How different is using Grub 2?
Have you or any one else found any good doc for Grub 2?

Varghese Mathew

unread,
Mar 12, 2008, 11:57:54 PM3/12/08
to

Thanks. I haven't looked into GRUB sources.. Too many things on my
plate.. Hope to do that someday..

bj7lewis

unread,
Mar 13, 2008, 8:52:45 AM3/13/08
to
> The Grub Manual gives info on Grub .97 which they now call Grub Legacy.
> That version seems to be easy to me.. build the stage1 and stage2..
> and then create the boot device..
Good - Grub is a great step in starting out...

I haven't had much time to get back to that core programming level because I
am still just starting out until an OS class at my university is offered.
Some time ago I decided to learn some of OS stuff at a higher programming
level letting Windows do some of the work virtually like I can learn to
build a virtual FAT filesystem and other subsystems. Then one day from
strach get back to core level using Grub 2 or higher.


Rod Pemberton

unread,
Mar 13, 2008, 10:46:10 PM3/13/08
to

"Varghese Mathew" <varghese85-d...@no-spam-please.org> wrote in
message news:fr94al$e4r$1...@aioe.org...

> Oops, I should have made it clearer..
>
> How do I get GNU as to assemble in native code without all elf/whatever
> headers etc in so that I can put the code into the boot sector.
>
> I couldn't figure out the options..
>

I'm not finding much on bootloaders in GAS (Gnu AS). It might be easier to
learn how to code a bootloader NASM, and port to GAS.

Links for creating various formats:
http://www.yeyan.cn/Programming/gcc-ld-compile-binary-formats.aspx
http://devpit.org/wiki/Compiler_Options_for_Creating_Odd_Binaries

The dd command, for *nix, is used to install the bootsector, once compiled.
Typically, something like so:
dd if=mbr of=/dev/hda bs=512 count=1

These two on GAS bootloaders may help. One is in Italian... The second
also shows commands on how to compile.
http://packz.noblogs.org/post/2007/11/18/creare-un-bootloader
http://www.in-nomine.org/~asmodai/booting-documentation.txt

You may want to learn about GAS directives: .code16, .fill, etc. here:
http://www.gnu.org/software/binutils/manual/gas-2.9.1/html_mono/as.html#SEC67
http://www.gnu.org/software/binutils/manual/gas-2.9.1/html_mono/as.html#SEC205

The .fill directive is the GAS version of NASM's times. It'll be used to
fill upto 510th byte prior to 0xAA55.


RP

Rod Pemberton

unread,
Mar 14, 2008, 3:34:23 AM3/14/08
to

"Rod Pemberton" <do_no...@nohavenot.cmm> wrote in message
news:frcot6$ul3$1...@aioe.org...

It seems some GAS bootloaders use .org instead of .fill:
http://www.osdev.org/osfaq2/index.php/GasAllInOne

Giese's recommendations on bootloaders:
http://my.execpc.com/CE/AC/geezer/osd/boot/


RP

Varghese Mathew

unread,
Apr 29, 2008, 1:10:12 AM4/29/08
to
Sorry to bring up this rather old one.

Recently came across this public domain GPL licensed book
Bartlett, Jonathan - Programming from the Ground up
http://programminggroundup.blogspot.com/2007/01/programming-from-ground-up.html
http://savannah.nongnu.org/projects/pgubook/

This book teaches x86 assembly on Linux platforms using the GNU toolset
including GNU as.

FYI, if anyone else is interested in the ATT/gas way of doing assembly.

/varghese

0 new messages