* [z80-coff-ld] how can I use ld for creating an exe from z80-coff-as ?
@ 2012-02-21 21:10 jseb
2012-02-21 21:52 ` Alan Modra
0 siblings, 1 reply; 4+ messages in thread
From: jseb @ 2012-02-21 21:10 UTC (permalink / raw)
To: binutils
Hello,
I've compiled this source file, using z80-coff-as.
~/z80-coff-as -als hello_world.asm -o hello_world.out
GAS LISTING hello_world.asm page 1
1 0000 FE db $fe
2 0001 00C0 1AC0 dw debut,fin,debut
2 00C0
3
4 0007 0000 0000 ORG $C000
4 0000 0000
4 0000 0000
4 0000 0000
4 0000 0000
5
6 debut:
7 c000 210D C0 LD HL,LABEL
8 c003 7E AFF: LD A,(HL)
9 c004 23 INC HL
10 c005 A7 AND A
11 c006 C8 RET Z
12 c007 CDA2 00 CALL $A2 ; HFDA4 ;CHPUT
13 c00a 18F7 JR AFF
14 c00c C9 RET
15 c00d 5465 7374 LABEL: DEFB "Test chput",13,10,0
15 2063 6870
15 7574 0D0A
15 00
16 fin:
17 END
GAS LISTING hello_world.asm page 2
DEFINED SYMBOLS
*ABS*:0000000000000000 fake
hello_world.asm:6 .text:000000000000c000 debut
hello_world.asm:16 .text:000000000000c01a fin
hello_world.asm:15 .text:000000000000c00d LABEL
hello_world.asm:8 .text:000000000000c003 AFF
NO UNDEFINED SYMBOLS
So, it gives me a COFF object files, and i don't want all those
sections, as it's for using inside an 8 bit emulator (target is MSX
machine).
I had success using «coff-z80-objcopy» with binary output, but i'd
rather like using the linker instead.
I tried with:
~/test$ z80-coff-ld.bfd hello_world.out -o hello_world.msx
~/test$ hexdump hello_world.msx -C
00000000 fe 00 c1 1b c1 00 c1 00 00 00 00 00 00 00 00 00
|................|
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|................|
*
0000c000 21 0d c1 7e 23 a7 c8 cd a2 00 18 f7 c9 48 65 6c
|!..~#........Hel|
0000c010 6c 6f 20 57 6f 72 6c 64 0d 0a 00
|lo World...|
As you can see, the first bytes show that the origin is now 0xc100 ,
instead of 0xc000.
I guess it's because ld adds 0x100h (old .com startup) to my .org setting.
Another problem is i don't want all those fillers, between stub (the
first seven bytes) and the start of my code section (at 0xc000).
I want to get this instead:
00000000 fe 00 c0 1b c0 00 c0 21 0d c0 7e 23 a7 c8 cd a2
|.......!..~#....|
00000010 00 18 f7 c9 48 65 6c 6c 6f 20 57 6f 72 6c 64 0d
|....Hello World.|
00000020 0a 00
I tried to set up a little ld script, for using with «-T» flag of ld,
but all i got is the return of «COFF» sections…
SECTIONS
{
. = 0xC000;
.text : { *(.text) }
}
I've made extensive search on the web, on this list, and on dedicated
emulators list, but didn't find anything about this problem.
If someone can helpÂ… thank you.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [z80-coff-ld] how can I use ld for creating an exe from z80-coff-as ?
2012-02-21 21:10 [z80-coff-ld] how can I use ld for creating an exe from z80-coff-as ? jseb
@ 2012-02-21 21:52 ` Alan Modra
2012-02-23 14:48 ` jseb
2012-08-09 10:16 ` Chris Smith
0 siblings, 2 replies; 4+ messages in thread
From: Alan Modra @ 2012-02-21 21:52 UTC (permalink / raw)
To: jseb; +Cc: binutils
On Tue, Feb 21, 2012 at 10:06:41PM +0100, jseb wrote:
> ... to my .org setting.
.org doesn't do what you think it does. gas isn't an absolute
assembler, but instead produces relocatable object files. .org just
adds space to make the offset from the start of the current section
equal to its argument.
You're on the right track in your use of a linker script to set the
start of your code. Just leave out the .org in the assembly code.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [z80-coff-ld] how can I use ld for creating an exe from z80-coff-as ?
2012-02-21 21:52 ` Alan Modra
@ 2012-02-23 14:48 ` jseb
2012-08-09 10:16 ` Chris Smith
1 sibling, 0 replies; 4+ messages in thread
From: jseb @ 2012-02-23 14:48 UTC (permalink / raw)
To: binutils
> .org doesn't do what you think it does. gas isn't an absolute
> assembler, but instead produces relocatable object files. .org just
> adds space to make the offset from the start of the current section
> equal to its argument.
Ok, i did what you've said, and deleted .org argument in source file.
I've also named sections, with :
«.stub» for the header.
«.mycode» for the real code, which should be loaded at 0xC000
1 .section .stub
2 0000 FE db $fe
3 0001 0000 1B00 dw debut,fin,debut
3 0000
4
5 ; don't use .ORG directive
6 ; .ORG $C000
7
8 .section .mycode
9 ;
10 debut:
11 0000 210D 00 LD HL,LABEL
12 0003 7E AFF: LD A,(HL)
13 0004 23 INC HL
14 0005 A7 AND A
15 0006 C8 RET Z
16 0007 CDA2 00 CALL $A2 ; HFDA4 ;CHPUT
17 ;
18 000a 18F7 JR AFF
19 000c C9 RET
20 000d 4865 6C6C LABEL: DEFB "Hello World",13,10,0
20 6F20 576F
20 726C 640D
20 0A00
21 fin:
22 END
And then, i've written this script:
OUTPUT_FORMAT(binary)
SECTIONS
{
.stub 0xC000 - 7 : { *(.stub) }
.code : { *(.mycode) }
}
Using this, i got correct output, working in emulator
00000000 fe 00 c0 1b c0 00 c0 21 0d c0 7e 23 a7 c8 cd a2
|.......!..~#....|
00000010 00 18 f7 c9 48 65 6c 6c 6f 20 57 6f 72 6c 64 0d
|....Hello World.|
00000020 0a 00
You see the stub at the beginning:
FE (magic)
00C0 (start adress of code: 0xC000)
1BC0 (end address: 0xC0B1)
00C0 (entry point, same as start)
And then,code following with correct relocation for execution at 0xC000.
The ld script is not very nice (the magic number «7»), but i couldn't
manage to do better.
I you have a suggestion, it will be welcome.
Thank you for helping.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [z80-coff-ld] how can I use ld for creating an exe from z80-coff-as ?
2012-02-21 21:52 ` Alan Modra
2012-02-23 14:48 ` jseb
@ 2012-08-09 10:16 ` Chris Smith
1 sibling, 0 replies; 4+ messages in thread
From: Chris Smith @ 2012-08-09 10:16 UTC (permalink / raw)
To: jseb, binutils
Hi Jseb.
I do a lot of complicated Z80 development using binutils, and have set
up a z80 specific makefile that sorts this all out. I include this
makefile in all my project makefiles to provide all the functionality
I need. I also have a platform specific linker script that defines
useful memory regions that I use. I can then target code to the memory
regions/segments as necessary.
Extracting the final linked binary is done through objcopy, with
listing dumps and map output done through objdump. It does what you
expect, and works beautifully for me at least.
Happy to share this base makefile and linker scripts with you, with
some examples (been meaning to write it all up and publish on my
website....)
Chris
On 21 February 2012 21:52, Alan Modra <amodra@gmail.com> wrote:
>
> On Tue, Feb 21, 2012 at 10:06:41PM +0100, jseb wrote:
> > ... to my .org setting.
>
> .org doesn't do what you think it does. gas isn't an absolute
> assembler, but instead produces relocatable object files. .org just
> adds space to make the offset from the start of the current section
> equal to its argument.
>
> You're on the right track in your use of a linker script to set the
> start of your code. Just leave out the .org in the assembly code.
>
> --
> Alan Modra
> Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-08-09 10:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-21 21:10 [z80-coff-ld] how can I use ld for creating an exe from z80-coff-as ? jseb
2012-02-21 21:52 ` Alan Modra
2012-02-23 14:48 ` jseb
2012-08-09 10:16 ` Chris Smith
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).