免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3366 | 回复: 6
打印 上一主题 下一主题

这段汇编怎么ld过不了? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-01 11:41 |只看该作者 |倒序浏览
本帖最后由 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

复制代码

论坛徽章:
1
天蝎座
日期:2013-10-23 21:11:03
2 [报告]
发表于 2010-08-01 13:52 |只看该作者
把出错信息贴一下

论坛徽章:
0
3 [报告]
发表于 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'

论坛徽章:
1
天蝎座
日期:2013-10-23 21:11:03
4 [报告]
发表于 2010-08-01 17:23 |只看该作者
用ld解析的符号需要用.global声明
你把29行的.data去掉或者用.global把那些label声明一下试试

论坛徽章:
0
5 [报告]
发表于 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

论坛徽章:
1
天蝎座
日期:2013-10-23 21:11:03
6 [报告]
发表于 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

论坛徽章:
0
7 [报告]
发表于 2010-08-26 11:31 |只看该作者
链接时,加个参数-Ttext=0x00
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP