Hello world bootloader

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.
Post Reply
N3m

Hello world bootloader

Post by N3m »

Hi, i read this tutorial: http://www.osdever.net/tutorials/hello_ ... ?the_id=85
and tried to convert the sample code, from intel to AT&T syntax.

But my putsrc procedure didn't work. can someone help me?

Code: Select all

.code16               # 16 bit code generation        
.text

.global _start

_start:
   jmpl   $0x07C0, $start2   # Normalize the start address

start2:

   movw $0x0000, %ax      # Setup the Data Segment Register
   movw %ax, %ds         # ( 'movw $0x0000, %ds' will NOT work due to limitations on the CPU )
   
   movw $helloworld, %si
   call putstr
   
loop:

   jmp loop         # Put it into a coninuous loop to stop it running off into
               #  the memory running any junk it may find there.

putstr:               
   # Setup registers for interrupt call
   movb $0x0E, %ah         # Function to display a character on the screen ( teletype )
   movb $0x00, %bh         # Page number
   movb $0x07, %bl         # Text attribute ( 0x07 = White text, black background ) 
   
   putstr.nc:         # Label to loop arround for the next char
      lodsb

      orb %al,%al      # Check for end of string
      jz putstr.ret

      int $0x10      # Run the BIOS video interrupt
   
      jmp putstr.nc      # Next character
      
   putstr.ret:
      ret



helloworld:
   .asciz "Hello World!"


   
.org 510,0            
.word 0xAA55                       # Boot signature
seph

Re:Hello world bootloader

Post by seph »

try

Code: Select all

cmp         $0, %al
je        putstr.ret
instead of

Code: Select all

 orb        %al, %al

also, shouldn't it be ascii not asciz?
edit:
No, it shouldn't. Sorry.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Hello world bootloader

Post by Pype.Clicker »

Code: Select all

   movw $0x0000, %ax      # Setup the Data Segment Register
   movw %ax, %ds         # ( 'movw $0x0000, %ds' will NOT work due to limitations on the CPU )
so you assume cs = 7c0 and ds = 0000 ? sorry, but your assembler will not understand this. You should have cs = ds and your first byte of code loaded at offset 0 in that section.

If cs = ds = 0000 is what you want, then you'll need the 'gas' equivalent of "org 0x7c00" in your code.
Post Reply