Startup code for new target?

Discussion about other targets
Post Reply
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

Startup code for new target?

Post by WORP3 »

I've compiled a little test program to hopefully getting started on my new target. For now it's just a basic z80 with 64K ram, no specific rom or compatible peripherals. Code and Data are in the same address space. After compiling using the command below, i'm seeing quite a large startup code present inside the binary. As I would like to customize this code a bit I was wondering where this code is located and how to alter this?

zcc +z80 -v -O3 -startup=0 -clib=new --list test.c --no-crt -o test -lm -create-app

So is it possible to alter the startup code using a z80 project or would it be a better solution to create a new target for my platform?

Thanks in advance.
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Startup code for new target?

Post by jorgegv »

Try changing -startup=31 for minimal footprint
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

Re: Startup code for new target?

Post by WORP3 »

jorgegv wrote: Fri Dec 30, 2022 2:01 pm Try changing -startup=31 for minimal footprint
Ohh wow using te startup=31 will remove all the startcode, that's a bit more then I would have expected :lol:
But maybe not so bad at all, at least I can now work from a clean start without some startup code I don't need. The only problem is off-coarse that I also don't have a starting point anymore (See test code below) or no JP to main function. I could add some inline instructions but is there a way to add a JP to main()?

Code: Select all

//#include <z80.h>
	__asm
		DI
		IM		1
		LD		SP,0FFFFh
	__endasm

void z80_outp(unsigned char Port, unsigned char Data)
{
	__asm
		POP		AF		
		POP		HL		
		POP		BC		
		PUSH	AF		
		OUT		(C),L
	__endasm
}

int main()
{
	z80_outp(0xd8,0x0e);
	
	return 0;
}
Will turn into:

Code: Select all

;Addr	Hexa	  ASCII	Z80 Mnemonic			Comments

T0000h	F3......  ๓...	DI			
T0001h	ED56....  ํV..	IM	1		
T0003h	31FFFF..  1.	LD	SP,0FFFFh	
T0006h	F1......  ๑...	POP	AF		
T0007h	E1......  แ...	POP	HL		
T0008h	C1......  ม...	POP	BC		
T0009h	F5......  ๕...	PUSH	AF		
T000Ah	ED69....  ํi..	OUT	(C),L			; 
T000Ch	C9......  ษ...	RET				

T000Dh	21D800..  !ุ..	LD	HL,000D8h	
T0010h	E5......  ๅ...	PUSH	HL		
T0011h	2E0E....  ....	LD	L,00Eh		
T0013h	E5......  ๅ...	PUSH	HL		
T0014h	CD0600..  อ...	CALL	T0006H		
T0017h	C1......  ม...	POP	BC		
T0018h	C1......  ม...	POP	BC		
T0019h	210000..  !...	LD	HL,00000h	
T001Ch	C9......  ษ...	RET				
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Startup code for new target?

Post by jorgegv »

You can remove the --no-crt and use just -startup=31
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

Re: Startup code for new target?

Post by WORP3 »

jorgegv wrote: Fri Dec 30, 2022 10:20 pm You can remove the --no-crt and use just -startup=31
Thanks for your message, because of this I re-tested the effect of this and found out that the last time I've tested with this operand the reason nothing seems to change was because the compiler isn't generating a new .bin file anymore. So the disassembler kept looking at a old file :/

But knowing this it seems that using the --no-crt or startup=31 are actually doing the same thing.

Why doesn't the output of files change between startup=0 or startup=31?
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

Re: Startup code for new target?

Post by WORP3 »

Now knowing that it's possible to just place the crt0.asm file directly beside your source files and use the following command to tel z88dk to use it:

Code: Select all

zcc +z80 -crt0=crt0.asm program.c
Is it then also possible to copy the "Z80_CRT_0.ASM.M4" file out of the "Z88dk\libsrc\_DEVELOPMENT\target\z80\startup" folder and use it as the crt0.asm file inside my project directory? I presume that this (if not altered) will generate the same code then using the "zcc +z80 -v -O3 -startup=0 -clib=new program.c" command?

Any thoughts?
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

Re: Startup code for new target?

Post by WORP3 »

I've got the custom CRT working. In the end it became clear to me that with the amount of customization that is possible, it was better for compatibility sake, to switch back to using the default z80 target. Got all special stuff tailored using pragma's now. A lot of searching but in the end it is working now.

The overall reason that the CPU got stuck inside the CRT was because I've got my assembly interrupt code defined inside the code_crt_init section which isn't allowed but I didn't know that it automatically was executing code inside this section :(
Post Reply