Page 1 of 1

16bit program

Posted: Sun May 09, 2010 10:26 pm
by zztrh
first,i am sorry i know only a littleenglish.

souce code:
boot.s

Code: Select all

.code16
  4 
  5 .global _start
  6 
  7 .text
  8 
  9 _start:
 10     jmp $0x7c0  ,$go
 11 
 12 go:
 13 movw %cs , %ax
 14 movw %ax , %ds
 15 movw %ax , %es
 16 
 17 movw %ax    ,   %ss
 18 
 19 movw $0x8000    ,%sp
 20 
 21 call _loadDisk
22 .org 1024*1024       #error   more than 1M
***************************************************************************************
loadfile.s

Code: Select all

.code16

.global _loadDisk

.text
_loadDisk:
      nop
     ret
Makefile

Code: Select all

all:boot
  2 
  3 boot:boot.s loadfile.s
  4     as -o boot.o boot.s  
  5     as -o loadfile.o loadfile.s
  6     ld   -s -o boot   boot.o loadfile.o  --oformat=binary -Ttext 0x0 
error:
as -o boot.o boot.s
as -o loadfile.o loadfile.s
ld -s -o boot boot.o loadfile.o --oformat=binary -Ttext 0x0
boot.o: In function `go':
(.text+0x11): relocation truncated to fit: R_386_PC16 against `_loadDisk'
make: *** [boot] Error 1

Re: 16bit program

Posted: Sun May 09, 2010 11:34 pm
by TylerH
Put code tags around your code.

What about it, what is your question? I think it should be "org 0" since you're using 7c0h as your segment.

Re: 16bit program

Posted: Mon May 10, 2010 12:11 am
by zztrh
zztrh@ubuntu:~/Test/asm/minos/boot$ make
as -o boot.o boot.s
as -o loadfile.o loadfile.s
ld -s -o boot boot.o loadfile.o --oformat=binary -Ttext 0x0
boot.o: In function `go':
(.text+0x11): relocation truncated to fit: R_386_PC16 against `_loadDisk'
make: *** [boot] Error 1

Re: 16bit program

Posted: Mon May 10, 2010 2:03 am
by Combuster
It is really tricky to make binutils do all those things it isn't really designed to do: 16-bit code, fixed location, fixed code order, bits at various fixed locations, and in this case, building for a different platform (it is not a crosscompiling toolchain!)

Use YASM/NASM and have it emit a binary directly if you want things to work without having to deal with the above mentioned problems.

Otherwise you should read through the documents on ELF, ld, as, and linker scripts, the Intel manuals about 16-bit addressing modes, and really know how linking is performed before attempting things the hacky way. At any rate, you should find out what "relocation truncated" is about before attempting things this way again.