How to find the variable in the AT & T assembly?

I am writing bootstrap using assembly (in AT & T and gnu / gas syntax). A small program is assembled and linked, and then copied to the first sector of the virtual disk. The BIOS will load it in 0000:7c00, and there is a problem. When you start it call hellowill be transferred from call 0010to call 7c10. But movw $message, %asdoes not move. axstill 0026, not 7c26. As a result, I can not do Hello Worldon the screen. Instead, some random data will be displayed on the screen 0000:0026.

How can I do it right at boot time? Should I change the asm source code with some directives? Or do I need to change the script link?

Thank!

.text
.global     _start
.code16

_start:
movw    %cs, %ax
movw    %ax, %ds
movw    %ax, %es
call    hello
jmp     .

.org    0x10

hello:
movw    $message, %ax
movw    %ax, %bp
movw    $13, %cx
movw    $0x1301, %ax
movw    $0x000c, %bx
movb    $0, %dl
int     $0x10
ret

message:    
.ascii  "Hello, World!"

.org    0x01fe
.byte   0x55
.byte   0xaa

I use the following build and link scripts

as -o boot.o boot.s  
    //generate object code

ld -Ttext 0x0 -e _start -s -o boot.out boot.o  
    //relocate .text to 0x0
    //entry is _start

objcopy -O binary -j .text boot.out boot
    //copy .text section to boot

vboxmanage convertfromraw boot boot.vdi --format VDI
    //create vdi for virtual box
+5
1

, , .

:

as boot.s -c -o boot.o
ld --oformat binary --Ttext 0x7C00 -o boot.bin boot.o

, , , --Ttext 0x7C00 ld, .

:

.text
.global     _start
.code16

_start:
jmp stage1_start

...

stage1_start:

<your bootloader here>

, , BIOS , 2 ( ) .

, as, :

. = _start + 0x0200 - 2
.short 0x0AA55

. - . , ( ld, as).

, !

+1

All Articles