* Why can not GNU linker translate relocatable symbol address to absolute address?
@ 2021-10-03 6:18 戴 志勇
0 siblings, 0 replies; only message in thread
From: 戴 志勇 @ 2021-10-03 6:18 UTC (permalink / raw)
To: cygwin
Hi:
I have a problem that the gnu assembler and linker can not relocate symbols address in 16 bit real mode of x86 architecture. Below is the code:
# file: boot.asm
.code16
.text
.global _start
_start:
# initialize
movw %cs, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movw $base, %sp
# clear screen
movw $0x0600, %ax
movw $0x0700, %bx
movw $0, %cx
movw $0x184f, %dx
int $0x10
# set focus
movw $0x200, %ax
movw $0x0, %bx
movw $0x0, %dx
int $0x10
# display on screen: Starting boot
movw $0x1301, %ax
movw $0x000f, %bx
movw $0x0, %dx
movw $msg_len, %cx
pushw %ax
movw %ds, %ax
movw %ax, %es
popw %ax
movw msg, %bp # Assign msg address to %bp, But cannot
# translate relocation address to
# absolute address. I must use:
# movw $msg_addr, %bp
int $0x10
# reset disk
xorb %ah, %ah
xorb %dl, %dl
int $0x13
hlt
msg: .ascii "Starting Boot"
msg_len = . - msg
base = 0x7c00
msg_addr = msg + 0x7c00
.org 510
.word 0xaa55
# file: end
Assembling the file boot.asm in Cygwin shell:
as -o boot.o bootloader5.asm --warn --32 && ld -r -Ttext 0x7c00 -e _start -s -o boot.tmp boot.o -m i386pe && objdump -m i8086 -D boot.tmp
Below is output:
boot.tmp: file format pe-i386
Disassembly of section .text:
00007c00 <_main>:
7c00: 8c c8 mov %cs,%ax
7c02: 8e d8 mov %ax,%ds
7c04: 8e c0 mov %ax,%es
7c06: 8e d0 mov %ax,%ss
7c08: bc 00 7c mov $0x7c00,%sp
7c0b: b8 00 06 mov $0x600,%ax
7c0e: bb 00 07 mov $0x700,%bx
7c11: b9 00 00 mov $0x0,%cx
7c14: ba 4f 18 mov $0x184f,%dx
7c17: cd 10 int $0x10
7c19: b8 00 02 mov $0x200,%ax
7c1c: bb 00 00 mov $0x0,%bx
7c1f: ba 00 00 mov $0x0,%dx
7c22: cd 10 int $0x10
7c24: b8 01 13 mov $0x1301,%ax
7c27: bb 0f 00 mov $0xf,%bx
7c2a: ba 00 00 mov $0x0,%dx
7c2d: b9 0d 00 mov $0xd,%cx
7c30: 50 push %ax
7c31: 8c d8 mov %ds,%ax
7c33: 8e c0 mov %ax,%es
7c35: 58 pop %ax
7c36: 8b 2e 43 00 mov 0x43,%bp # Here is problem: msg address is not absolute address
7c3a: cd 10 int $0x10
7c3c: 30 e4 xor %ah,%ah
7c3e: 30 d2 xor %dl,%dl
7c40: cd 13 int $0x13
7c42: f4 hlt
7c43: 53 push %bx
7c44: 74 61 je 7ca7 <_main+0xa7>
7c46: 72 74 jb 7cbc <_main+0xbc>
7c48: 69 6e 67 20 42 imul $0x4220,0x67(%bp),%bp
7c4d: 6f outsw %ds:(%si),(%dx)
7c4e: 6f outsw %ds:(%si),(%dx)
7c4f: 74 00 je 7c51 <_main+0x51>
...
7dfd: 00 55 aa add %dl,-0x56(%di)
As you can see, address 0x7c36 is disassembly of: movw msg, %bp. But the absolute address of msg is not 0x7c43. Is there a mistake in my command options ? Thanks!
Best wishes to you!
Zhiyong Dai
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-03 6:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-03 6:18 Why can not GNU linker translate relocatable symbol address to absolute address? 戴 志勇
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).