Basic boot loader using GAS
Posted: Sun Sep 29, 2013 3:29 pm
Hey,
I am working to get a very basic(hello-world thing) boot-loader running; I read some examples online, followed their steps and got it working.
Using, then copy it to a floppy and use qemu to load it.
What I am trying to do now is simply re-do that but using GAS (my brain's convinced me I am more familiar with AT&T syntax, somehow).
So here's my code, I added some comments as I was trying to understand each step.
Please let me know if these indicate any problem with my understanding of what's going on:
Next, I assembled it with as; that produces an ELF so I used binary and then copied it using and loaded it with ; it complained that the floppy is not bootable.
In what step have I erred here? Any tips where I should be looking for the error?
I used hexdump to compare the binary outputs of both my NASM and GAS attempts, they seem to differ but I am not sure why; is it something related to the instruction?
Another question:
The same assembly in nasm syntax worked; how did it work properly when I didn't set the stack segment, considering that I have used the call and the ret instructions? Am I missing something here?
Thanks,
I am working to get a very basic(hello-world thing) boot-loader running; I read some examples online, followed their steps and got it working.
Using
Code: Select all
nasm -f bin
What I am trying to do now is simply re-do that but using GAS (my brain's convinced me I am more familiar with AT&T syntax, somehow).
So here's my code, I added some comments as I was trying to understand each step.
Please let me know if these indicate any problem with my understanding of what's going on:
Code: Select all
.code16 # 16-bit assembly
.org 0x7C00 # We MUST be loaded here
# L0 is loop-begining and L1 is loop exit
# BIOS INT 10H: (Video)
# AH: 0EH (the type of the printing - here Teletype)
# AL: The character I will print
# BH: 00H (The video page number)
# BL: 02H (Color of the text - 0/black back , 2/green front)
movw $my_hello, %si #Put the &my_hello[0] in the %si
call print_string
jmp . #Jump to self - loop forever
print_string:
L0:
movb (%si), %al #Move the character to AL for printing
cmpb $0, %al #Did we reach the \0 terminator?
je L1 #Yes? Jump to end
call print_char #No? Print the character
inc %si #Increment to the next character
jmp L0 #Repeat
L1:
ret
print_char:
#CAREFUL: I am assuming the char is in the AL already
movb $0x0E, %ah #Teletype
movb $0x00, %bh #Page No: 0
movb $0x02, %bl #black|green
int $0x10 #Calling the bios
ret
#My Data
my_hello:
.asciz "Hello, world!"
.org .+510, 0 #Move the location counter to current+510
#and pad in between with 0s
.word 0xAA55 #end with the bootloader marker
Code: Select all
objcopy -O
Code: Select all
dd
Code: Select all
qemu-system-i386
In what step have I erred here? Any tips where I should be looking for the error?
I used hexdump to compare the binary outputs of both my NASM and GAS attempts, they seem to differ but I am not sure why; is it something related to the
Code: Select all
.org
Another question:
The same assembly in nasm syntax worked; how did it work properly when I didn't set the stack segment, considering that I have used the call and the ret instructions? Am I missing something here?
Thanks,