GNU GAS: Label is not relatively referenced

后端 未结 1 392
天涯浪人
天涯浪人 2021-01-24 13:16

I am writing a little bootsector for learning purpose.

Here is boot.S

.code16
.text
    movw    $0xB800, %ax    /* 0xB000 is the text screen video memory         


        
相关标签:
1条回答
  • 2021-01-24 13:44

    Of course it is possible to relocate strings.

    First of all, your -Ttext 0x7C00 is correct. Do not change it. At the beginning of your bootloader you should zero the segment registers (%ds, %es, %fs, %gs and %ss):

    mov $0, %ax         // xor %ax, %ax would be more space efficient
    mov %ax, %ds
    mov %ax, %es
    mov %ax, %fs
    mov %ax, %gs
    mov %ax, %ss
    

    Next, you should set up a stack. Read: osdev wiki about stacks

    Now to your question: It is usual to address strings using segmentation in the form of %ds:%si. When relocating the bootloader, just change %ds properly.
    Assuming you call your string label:

    mov $label, %si     // Always prefix a label address with a $
    

    You can get a character from a string using the lodsb instruction (LOaD String Byte, which automatically increments %si for you:

    lodsb               // Character is stored in `%al` now
    

    Another recommendation is not to address the video memory manually. Use BIOS Interrupt 0x10.

    Good luck with your bootloader!

    0 讨论(0)
提交回复
热议问题