z88dk calling conventions on return value?

Other misc things
Post Reply
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

z88dk calling conventions on return value?

Post by WORP3 »

Sorry for the amount of questions lately, but the amount contra-dictionary information on the web keeps me kind of in the dark. It's not that i'm lazy in trying to search for an answer ;)

On the following site (Also seen on multiple other sites) they are saying that in case of a 8 bit return value, the value will be parsed back in register L.

https://www.z88dk.org/wiki/doku.php?id= ... y_language

Code: Select all

The rules are exactly the same as for the return value already discussed. A subset of DEHL holds the parameter value ([b]L for an 8-bit value[/b], HL for a 16-bit value, DEHL for a 32-bit value).
For some reason the compiler seems the handle the full 16 bits HL register as a return value. I see no difference between a standard or fastcall function. Also using a char or unsigned char in the definition isn't doing anything.

Code: Select all

T00F0h	CD1702..  Í...	CALL	T0217H		
T00F3h	7C......  |...	LD	A,H		
T00F4h	B5......  µ...	OR	L		
T00F5h	CAF000..  Êð..	JP	Z,T00F0H
Using the following cmd:

Code: Select all

zcc +z80 -vn -O3 -clib=new --list @ProjectFiles.lst -o test -lm -create-app -pragma-include:zpragma.inc
Is z88dk always using a 16 bits value for it's return parameter or do I overlook something?
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: z88dk calling conventions on return value?

Post by dom »

There's a lot of misinformation out there unfortunately. For reference, the maintained documentation page for calling conventions is this one: https://github.com/z88dk/z88dk/wiki/CallingConventions

Remember that there's two different compilers (and I note that you're switching between them) and they have two different default calling conventions. sccz80 defaults to __smallc and sdcc to __z88dk_sdccdecl

Hopefully that explains the behaviour you're seeing.
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

Re: z88dk calling conventions on return value?

Post by WORP3 »

Thanks again for the answer dom, really appreciated.
This is probably going to sound really dumb, I was actually thinking that the selection of the compiler self was done by the zcc command. As it seems this is only the front-end which is actually calling the compiler...
I've added the compiler parameter and you where right, now it's only looking at the lower 8 bits part or L register.

Code: Select all

zcc +z80 -vn -compiler=sdcc -O3 -clib=new --list @ProjectFiles.lst -o test -lm -create-app -pragma-include:zpragma.inc

Code: Select all

T00EBh	CD0C02..  Í...	CALL	T020CH		
T00EEh	7D......  }...	LD	A,L		
T00EFh	B7......  ·...	OR	A		
T00F0h	28F9....  (ù..	JR	Z,0F9h			; Jump to 000EBH
Just one more question, are there any problems using one of the two compilers in combination with the "new" clib?
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: z88dk calling conventions on return value?

Post by dom »

Just one more question, are there any problems using one of the two compilers in combination with the "new" clib?
Newlib has separate libraries for each compiler:

* new = sccz80
* sdcc_ix = sdcc
* sdcc_iy = sdcc (reserving iy?)

And selecting the library automatically switches the compiler.

Selecting -clib=new -compiler=sdcc is going to result in a broken binary (if it even links).

Classic just has one library, so the -compiler= option is used to switch the compiler round.
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

Re: z88dk calling conventions on return value?

Post by WORP3 »

* new = sccz80
* sdcc_ix = sdcc
* sdcc_iy = sdcc (reserving iy?)

Selecting -clib=new -compiler=sdcc is going to result in a broken binary (if it even links).
It links without any complains or warnings (Even with a -v instead of -vn). So it's better to select sdcc_ix or remove the parameter from the command line?
Maybe also a dumb question but is there somewhere a list of what kind of functions is present inside these clib's? I presume that there are al of the glue functions that are actually doing the math and comparing stuff, is this correct?
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

Re: z88dk calling conventions on return value?

Post by WORP3 »

Why is this compiler complaining "overflow in implicit constant conversion" over the following:

Code: Select all

OutP(((PARA_IO_DEBUG_H<<8)|1));
Definitions:

Code: Select all

#define PARA_IO_DEBUG_H	0xFD
void OutP(unsigned int RegData)__z88dk_fastcall;
Type casting this will get rid of the warning but still strange as it's the same as the function prototype.

Code: Select all

OutP((unsigned int)((PARA_IO_DEBUG_H<<8)|1));
I'm also getting "unreachable code" during compiling, is there a way to suppress this? I know it's correct as the end of my main looks like this but this is deliberate.

Code: Select all

while(1)
{
 some code
}
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

Re: z88dk calling conventions on return value?

Post by WORP3 »

"unreachable code" is solved, so forget about that question please ;)
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: z88dk calling conventions on return value?

Post by dom »

Maybe also a dumb question but is there somewhere a list of what kind of functions is present inside these clib's? I presume that there are al of the glue functions that are actually doing the math and comparing stuff, is this correct?
There's the compiler support routines (so multiplication etc) + the common bits of the standard library.

Code: Select all

z88dk-z80nm sdcc_ix/z80.lib | grep " G "  
Will show you the exported symbols
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: z88dk calling conventions on return value?

Post by dom »

WORP3 wrote: Sat Mar 11, 2023 5:13 pm Why is this compiler complaining "overflow in implicit constant conversion" over the following:
This is probably this issue: https://sourceforge.net/p/sdcc/bugs/2733/
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

Re: z88dk calling conventions on return value?

Post by WORP3 »

Thanks for the answers again!

Looks like that issue indeed, although an additional typecast will prevent the warning :)
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

Re: z88dk calling conventions on return value?

Post by WORP3 »

At least the program is running now and compiling without any further warnings, so happy for now :) Now going to start in adding all of the additional code.
Post Reply