Chinaunix

标题: 这段汇编怎么ld过不了? [打印本页]

作者: yylogo    时间: 2010-08-01 11:41
标题: 这段汇编怎么ld过不了?
本帖最后由 yylogo 于 2010-08-01 14:58 编辑

这段汇编怎么ld过不了?
  1. BOOTSEG        = 0x07C0
  2. SYSSEG        = 0x0000
  3. SYSLEN        = 17
  4. .code16
  5. .text
  6. .global _start
  7. _start:
  8.         movw $BOOTSEG, %ax
  9.         movw %ax, %cs
  10.         movw %ax, %ds
  11.         movw %ax, %ss
  12.         movw $0x400, %sp
  13. load_system:
  14.         movw $0x0000, %dx
  15.         movw $0x0002, %cx
  16.         movw $SYSSEG, %ax
  17.         movw %es, %ax
  18.         xor %bx, %bx
  19.         movw $0x200+SYSLEN, %ax
  20.         int $0x13
  21.         jnc ok_lode
  22. die:        jmp die

  23. ok_lode:
  24.         lidt idt_48
  25.         lgdt gdt_48
  26.         iret

  27. .data
  28. idt_48:        .word        0, 0, 0
  29. gdt:        .word        0, 0, 0, 0

  30.         .word        0x07FF
  31.         .word        0x0000
  32.         .word        0x9A00
  33.         .word        0x00C0

  34.         .word        0x07FF
  35.         .word        0x0000
  36.         .word        0x9200
  37.         .word        0x00C0

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

  39. .org 510
  40.         .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


     没用额..
代码如下:
  1. BOOTSEG        = 0x07C0
  2. SYSSEG        = 0x0000
  3. SYSLEN        = 17
  4. .code16
  5. .text
  6. .global _start, load_system, die, ok_lode, idt_48, gdt_48, gdt
  7. _start:
  8.         movw $BOOTSEG, %ax
  9.         movw %ax, %cs
  10.         movw %ax, %ds
  11.         movw %ax, %ss
  12.         movw $0x400, %sp
  13. load_system:
  14.         movw $0x0000, %dx
  15.         movw $0x0002, %cx
  16.         movw $SYSSEG, %ax
  17.         movw %es, %ax
  18.         xor %bx, %bx
  19.         movw $0x200+SYSLEN, %ax
  20.         int $0x13
  21.         jnc ok_lode
  22. die:        jmp die

  23. ok_lode:
  24.         lidt idt_48
  25.         lgdt gdt_48
  26.         iret

  27. .data
  28. idt_48:        .word        0, 0, 0
  29. gdt:        .word        0, 0, 0, 0

  30.         .word        0x07FF
  31.         .word        0x0000
  32.         .word        0x9A00
  33.         .word        0x00C0

  34.         .word        0x07FF
  35.         .word        0x0000
  36.         .word        0x9200
  37.         .word        0x00C0

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

  39. .org 510
  40.         .word        0xAA55
复制代码
提示如下:
yylogo@ubuntu:~$ as boot.s -o boot.o
yylogo@ubuntu:~$ ld boot.o -o boot
boot.o: In function `ok_lode':
(.text+0x2: 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/darklighting ... 054dd1fc1f1065.html

有篇文章Making plain binary files using a C compiler不错
这里有中文版http://www.mlxos.org/docs.html
作者: qsnqss    时间: 2010-08-26 11:31
链接时,加个参数-Ttext=0x00




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2