yylogo 发表于 2010-08-01 11:41

这段汇编怎么ld过不了?

本帖最后由 yylogo 于 2010-08-01 14:58 编辑

这段汇编怎么ld过不了?BOOTSEG        = 0x07C0
SYSSEG        = 0x0000
SYSLEN        = 17
.code16
.text
.global _start
_start:
        movw $BOOTSEG, %ax
        movw %ax, %cs
        movw %ax, %ds
        movw %ax, %ss
        movw $0x400, %sp
load_system:
        movw $0x0000, %dx
        movw $0x0002, %cx
        movw $SYSSEG, %ax
        movw %es, %ax
        xor %bx, %bx
        movw $0x200+SYSLEN, %ax
        int $0x13
        jnc ok_lode
die:        jmp die

ok_lode:
        lidt idt_48
        lgdt gdt_48
        iret

.data
idt_48:        .word        0, 0, 0
gdt:        .word        0, 0, 0, 0

        .word        0x07FF
        .word        0x0000
        .word        0x9A00
        .word        0x00C0

        .word        0x07FF
        .word        0x0000
        .word        0x9200
        .word        0x00C0

gdt_48:        .word        0x7ff, 0x07c0+gdt, 0

.org 510
        .word        0xAA55

openspace 发表于 2010-08-01 13:52

把出错信息贴一下

yylogo 发表于 2010-08-01 15:02

回复 2# openspace


    yylogo@ubuntu:~$ as boot.s -o boot.o
yylogo@ubuntu:~$ ld boot.o -o boot
boot.o: In function `ok_lode':
(.text+0x25): relocation truncated to fit: R_X86_64_16 against `.data'
boot.o: In function `ok_lode':
(.text+0x2a): relocation truncated to fit: R_X86_64_16 against `.data'
boot.o: In function `gdt_48':
(.data+0x20): relocation truncated to fit: R_X86_64_16 against `.data'

openspace 发表于 2010-08-01 17:23

用ld解析的符号需要用.global声明
你把29行的.data去掉或者用.global把那些label声明一下试试

yylogo 发表于 2010-08-02 09:46

本帖最后由 yylogo 于 2010-08-02 09:48 编辑

回复 4# openspace


   没用额..
代码如下:BOOTSEG      = 0x07C0
SYSSEG      = 0x0000
SYSLEN      = 17
.code16
.text
.global _start, load_system, die, ok_lode, idt_48, gdt_48, gdt
_start:
      movw $BOOTSEG, %ax
      movw %ax, %cs
      movw %ax, %ds
      movw %ax, %ss
      movw $0x400, %sp
load_system:
      movw $0x0000, %dx
      movw $0x0002, %cx
      movw $SYSSEG, %ax
      movw %es, %ax
      xor %bx, %bx
      movw $0x200+SYSLEN, %ax
      int $0x13
      jnc ok_lode
die:      jmp die

ok_lode:
      lidt idt_48
      lgdt gdt_48
      iret

.data
idt_48:      .word      0, 0, 0
gdt:      .word      0, 0, 0, 0

      .word      0x07FF
      .word      0x0000
      .word      0x9A00
      .word      0x00C0

      .word      0x07FF
      .word      0x0000
      .word      0x9200
      .word      0x00C0

gdt_48:      .word      0x7ff, 0x07c0+gdt, 0

.org 510
      .word      0xAA55
提示如下:
yylogo@ubuntu:~$ as boot.s -o boot.o
yylogo@ubuntu:~$ ld boot.o -o boot
boot.o: In function `ok_lode':
(.text+0x28): relocation truncated to fit: R_X86_64_16 against symbol `idt_48' d
efined in .data section in boot.o
boot.o: In function `ok_lode':
(.text+0x2d): relocation truncated to fit: R_X86_64_16 against symbol `gdt_48' d
efined in .data section in boot.o
boot.o: In function `gdt_48':
(.data+0x20): relocation truncated to fit: R_X86_64_16 against symbol `gdt' defi
ned in .data section in boot.o

openspace 发表于 2010-08-02 11:20

回复 5# yylogo

http://hi.baidu.com/darklightingx/blog/item/c218ee8bdf054dd1fc1f1065.html

有篇文章Making plain binary files using a C compiler不错
这里有中文版http://www.mlxos.org/docs.html

qsnqss 发表于 2010-08-26 11:31

链接时,加个参数-Ttext=0x00
页: [1]
查看完整版本: 这段汇编怎么ld过不了?