Page 1 of 1

Hello world bootloader

Posted: Wed Jan 18, 2006 3:06 pm
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

Re:Hello world bootloader

Posted: Wed Jan 18, 2006 3:51 pm
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.

Re:Hello world bootloader

Posted: Thu Jan 19, 2006 3:53 am
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.