z88dk forums

z80 Development Kit

You are not logged in.

#1 2020-05-18 19:44:45

jacotton
Member
Registered: 2017-11-24
Posts: 26

CP/M 3 stack issues.

Have not yet got to the bottom of this issue, but I thought it would be good to ask here first.

CP/M 3.
z88dk
zcc - Frontend for the z88dk Cross-C Compiler - v16128-c78bc0271-20200306

My inettools-z80 code pile, pick one.

Here is the issue we are seeing.

When a submit script is 'submited' and that script has any of my inettools in it,
then the submit program go's bonkers and we start getting crash codes.

The supposition is that the inettools (being large) are pushing the stack up into
the submit program space.

Is there a way to adjust the program stack at build time to account for this
kind of issue?  It seems like the kind of thing that would be available in z88dk
but I have not found a way to do it yet.

Offline

 

#2 2020-05-18 19:55:34

jacotton
Member
Registered: 2017-11-24
Posts: 26

Re: CP/M 3 stack issues.

Does this kind of thing apply to the general case ?
#pragma output STACKPTR=49152

Offline

 

#3 2020-05-18 20:06:51

jacotton
Member
Registered: 2017-11-24
Posts: 26

Re: CP/M 3 stack issues.

Looking like I found the solution.

I will hold this open to see if there are any better ways to handle this.

Offline

 

#4 2020-05-19 07:28:06

stefano
Administrator
Registered: 2007-07-16
Posts: 1581

Re: CP/M 3 stack issues.

It it the right way to address the problem.
An option to relocate the stack could be possible only if we find an universal and reliable way to determine the TPA size.

Offline

 

#5 2020-05-23 03:45:07

jacotton
Member
Registered: 2017-11-24
Posts: 26

Re: CP/M 3 stack issues.

I'm not seeing what I expect to get.

This program "ifconfig"  Has a pragma to set the stack 0x9000.
But this never seems to produce the desired results.
Perhaps I am not using it correctly.

Here is a hunk of the make file.

ifconfig: addrprint.o w5500.o dhcp.o spi.o socket.o ethernet.o dns.o
        zcc +cpm -m -create-app -oifconfig -Wunused addrprint.o w5500.o dhcp.o spi.o socket.o ethernet.o dns.o


Here is a hunk of the code.
#pragma output REGISTER_SP = 0x9000
void main()
{
printf("Stack 0x%04x\n",get_sp());

The stack is reporting at 0xf1b2. ?? way up there.

So, the problem is that a: its not 9000 and b: its mapped to middle of CPM3
RESBDOS3 SPR  F100  0600
This seems to allow "ifconfig" to poke holes in the FCB of RESBDOS3, and it then
renders the system unstable.

Here is the stack reporting code I put in ifconfig.
unsigned int get_sp()
{
#asm
ld hl,0
add hl,sp
ret
#endasm
return 0;
}

printf("Stack 0x%04x\n",get_sp());
output.
A>ifconfig
Stack 0xf1b2
Shift Register SPI Wiznet v1.0
Stack 0xf1b2
inet 192.168.0.172 Stack 0xf1b2
netmask 255.255.255.0
Stack 0xf1b2
Stack 0xf1b2
dns server 192.168.0.1
ether 98.76.b6.11.00.c3

Offline

 

#6 2020-05-23 13:46:24

dom
Administrator
Registered: 2007-07-15
Posts: 1446
Website

Re: CP/M 3 stack issues.

I think I know what's going on, it's a bit annoying, but we've run into it before so there's a way around it.

The results of the pragmas are written the zcc_opt.def which is cleaned on every invocation of zcc. So if you're using a makefile then it gets wiped all the time. However if the compilation is all in one step then it works just fine.

The solution is to put all the pragmas into a separate file (say zpragma.inc) and include that file at the linking stage with the option:  -pragma-include:zpragma.inc

Offline

 

#7 2020-05-23 16:33:45

jacotton
Member
Registered: 2017-11-24
Posts: 26

Re: CP/M 3 stack issues.

I think that you hit the root cause of the problem.  But, in order to get it to work I had to compile the entire program in one bite. 

This command worked.
zcc +cpm -create-app -oifconfig addrprint.c w5500.c dhcp.c spi.c socket.c ethernet.c dns.c

This one did not.
zcc +cpm -m -create-app -oifconfig -Wunused -pramga-include:zpragma.inc addrprint.o w5500.o dhcp.o spi.o socket.o ethernet.o dns.o

Here is the include file contents.
IF !DEFINED_REGISTER_SP
    defc    DEFINED_REGISTER_SP  = 1
    defc REGISTER_SP  = 0x9000
    IFNDEF REGISTER_SP
    ENDIF
ENDIF

I have some doubt about this file, seems like it might be incorrect.

Offline

 

#8 2020-05-23 17:12:50

dom
Administrator
Registered: 2007-07-15
Posts: 1446
Website

Re: CP/M 3 stack issues.

The zpragma.inc should just contain pragmas:

#pragma output REGISTER_SP = 0x9000

In the same format as you were putting into the source files.

Offline

 

#9 2020-05-24 05:02:04

jacotton
Member
Registered: 2017-11-24
Posts: 26

Re: CP/M 3 stack issues.

Still not there.

Here is a log of the build, with a make file.

jay@jay-Ultra-27:~/projects/inettools-z80$ make ifconfig
zcc +cpm --list --c-code-in-asm  -Wall -pragma-include:zpragma.inc  -c  addrprint.c
zcc +cpm --list --c-code-in-asm  -Wall -pragma-include:zpragma.inc -c  w5500.c
zcc +cpm --list --c-code-in-asm  -Wall -pragma-include:zpragma.inc   -c  dhcp.c
zcc +cpm --list --c-code-in-asm  -Wall -pragma-include:zpragma.inc  -c  spi.c
zcc +cpm --list --c-code-in-asm  -Wall -pragma-include:zpragma.inc   -c  socket.c
zcc +cpm --list --c-code-in-asm  -Wall -pragma-include:zpragma.inc   -c  ethernet.c
zcc +cpm --list --c-code-in-asm  -Wall -pragma-include:zpragma.inc   -c  dns.c
zcc +cpm -m -create-app -oifconfig -Wunused -pramga-include:zpragma.inc addrprint.o w5500.o dhcp.o spi.o socket.o ethernet.o dns.o
cp IFCONFIG.COM ~/HostFileBdos/c/ifconfig.com

Here is the pragma file.

cat zpragma.inc
#pragma output REGISTER_SP = 0x9000

Here is the result of the build.

A>ifconfig
Stack 0xf1b2
Shift Register SPI Wiznet v1.0
Stack 0xf1b2
inet 192.168.0.172 Stack 0xf1b2
netmask 255.255.255.0
Stack 0xf1b2
Stack 0xf1b2
dns server 192.168.0.1
ether 98.76.b6.11.00.c3

Note that the stack address is still at f1b2.

Now this command will produce the correct output.

zcc +cpm -create-app -oifconfig addrprint.c w5500.c dhcp.c spi.c socket.c ethernet.c dns.c

Where the pragma is in the file addrprint.c

A>ifconfig
Stack 0x8fb4
Shift Register SPI Wiznet v1.0
Stack 0x8fb4
inet 192.168.0.172 Stack 0x8fb4
netmask 255.255.255.0
Stack 0x8fb4
Stack 0x8fb4
dns server 192.168.0.1
ether 98.76.b6.11.00.c3


Is there a tool/method to check the .COM file for the stack address ?
Looking at the .map file, nothing of interest there.

The zcc_opt.def file is null for the make file build case.  Is that expected ?

Offline

 

#10 2020-05-24 05:09:08

jacotton
Member
Registered: 2017-11-24
Posts: 26

Re: CP/M 3 stack issues.

I modified the Makefile to print out the zcc_opt.def file after each segment of code is compiled.  It looks correct i.e.  each module has a
IF !DEFINED_REGISTER_SP
    defc    DEFINED_REGISTER_SP  = 1
    defc REGISTER_SP  = 0x9000
    IFNDEF REGISTER_SP
    ENDIF
ENDIF
In it.
However the last step, the link phase the zcc_opt.def file is void.

Offline

 

#11 2020-05-24 05:17:05

jacotton
Member
Registered: 2017-11-24
Posts: 26

Re: CP/M 3 stack issues.

O.k I found the correct combination.  This command will build the correct (desired) stack pointer value.
Note that what I did was to compile the .c file that holds the 'main' entry point and the rest are all object files.

zcc +cpm -m -create-app -oifconfig -Wunused -pragma-include:zpragma.inc addrprint.c w5500.o dhcp.o spi.o socket.o ethernet.o dns.o

I can make this work for my environment and it will clear up a few problems.

Offline

 

#12 2020-05-24 12:02:50

dom
Administrator
Registered: 2007-07-15
Posts: 1446
Website

Re: CP/M 3 stack issues.

The only reason why I can see that it didn't work would be the typo in -pragma-include=zpragma.inc you had -pramga.

I've just tried it out with:

Code:

OBJS = main.o func.o


all: program.com

program.com: $(OBJS)
        zcc +cpm -v $(OBJS) -o $@ -pragma-include=zpragma.inc

%.o: %.c
        zcc +cpm -c $^ -o $@

clean:
        $(RM) $(OBJS) program.com

Code:

extern void func();

int main() {
        func();
}

Code:

#include <stdio.h>

void func() {
        printf("In func\n");
}

Code:

#pragma define REGISTER_SP = 0x9000

Disassembling program.com gives:

Code:

                    ld      hl,$0000                        ;[0136] 21 00 00
                    add     hl,sp                           ;[0139] 39
                    ld      ($01ed),hl                      ;[013a] 22 ed 01
                    ld      sp,$9000                        ;[013d] 31 00 90
                    ld      hl,$ffc0                        ;[0140] 21 c0 ff
                    add     hl,sp                           ;[0143] 39

So we can see the pragma is picked up correctly.

Offline

 

#13 2020-05-24 17:52:06

jacotton
Member
Registered: 2017-11-24
Posts: 26

Re: CP/M 3 stack issues.

The changes made, seem to be a fix for the problem I was working...    tnx for all the help.

Offline

 

#14 2020-05-27 10:33:06

dom
Administrator
Registered: 2007-07-15
Posts: 1446
Website

Re: CP/M 3 stack issues.

In case someone in the future stumbles upon this thread due to having the same issues, I've written it up on the wiki: https://github.com/z88dk/z88dk/wiki/Com … plications

I've also written a Makefile (https://github.com/z88dk/z88dk/blob/mas … d/Makefile) that assumes a (hopefully uncontroversial) project structure and permits incremental builds for multiple z88dk targets.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson