16bit program

Programming, for all ages and all languages.
Post Reply
zztrh
Posts: 2
Joined: Sun May 09, 2010 10:15 pm

16bit program

Post 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
Last edited by zztrh on Mon May 10, 2010 7:51 am, edited 3 times in total.
TylerH
Member
Member
Posts: 285
Joined: Tue Apr 13, 2010 8:00 pm
Contact:

Re: 16bit program

Post 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.
zztrh
Posts: 2
Joined: Sun May 09, 2010 10:15 pm

Re: 16bit program

Post 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: 16bit program

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply