S100 - hello world not working.

Discussion about other targets
Post Reply
jacotton
Member
Posts: 89
Joined: Fri Nov 24, 2017 1:35 am

S100 - hello world not working.

Post by jacotton »

I am trying to expand my make file targets to include S100 buss machines. No joy.
The machine is S100 with 8080 or z80 at 2mhz to 8mhz. Has about 46k of ram, and is running
cp/m 3. The system boots cp/m no problem. I'd expect this to just work.

I think the bug is in printf (only functions present) but it seem obscure to me.
I added the the CONSOLE# stuff to see if that would shake things loose.

I am certain that its a link option but my FOO is a bit lacking.


Here is my test program.
#include <stdio.h>

void main()
{
printf("Hello World\n");
}

Here is my make file
CFLAGS = +cpm -Wall -DOLD
LINKOP = +cpm -clib=8080 -create-app --generic-console -m -pragma-define:CONSOLE_COLUMNS=64 -pragma-define:CONSOLE_ROWS=16
DESTDIR = ~/HostFileBdos/c/
DESTDIR1 = /var/www/html
SUM = sum
CP = cp
INDENT = indent -kr
SUDO = sudo

# define SNAP to null when debugging is done.
SNAP =
#SNAP = snaplib.o

all: test

test: test.o
zcc $(LINKOP) test.o

test.o: hello.c
zcc $(CFLAGS) -c hello.c -o test.o

clean:
$(RM) *.o *.err *.lis *.def *.lst *.sym *.exe *.COM *.map find

just:
$(INDENT) find.c
$(INDENT) mygetopt.c

scope:
cscope

install:
$(SUDO) $(CP) ./*.COM $(DESTDIR1)/.

check:
$(SUM) *.COM
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: S100 - hello world not working.

Post by dom »

That is odd, it should "just work".

I'm not sure what permutations you've tried, but if you just do: zcc +cpm -clib=8080 hello.c -create-app does that work?

Either way, could you create a GitHub issue with the generated binaries and the .map file and I'll take a look.
jacotton
Member
Posts: 89
Joined: Fri Nov 24, 2017 1:35 am

Re: S100 - hello world not working.

Post by jacotton »

Here is my test repo. https://github.com/jayacotton/hello

I removed all the generic console stuff and pulled out the clib flag.

In this build, the machine is hanging.


Here is an output from the test run.

CP/M V3.0 Loader
Copyright (C) 1982, Digital Research

BIOS3 SPR BD00 0A00
BDOS3 SPR 9C00 2100

39K TPA


CP/M VERSION 3.0 (NON-BANKED) (John Monahan 03/16/2011)
Modified by David Fry and David Mehaffy (aka Yoda) 6/21/2014
A: & B: = IDE CF Memory Disk
A>test
jacotton
Member
Posts: 89
Joined: Fri Nov 24, 2017 1:35 am

Re: S100 - hello world not working.

Post by jacotton »

Debugging with SID.

G100,237 (237 is the entry point for main).
It does not get to main. Seems to hang up in the init code.
Single stepping the h/w I see address's off the end of the code. Its wondering around
0x1bxx range. This looks like its off the end of the program. _tail is $1abf

Also, it looks like the code tried to write something, but just got junk bytes...
A>sid test.com
SID Version 3.0
NEXT MSZE PC END
1B00 1B00 0100 80FF
#g100,237
�ý


I think I'm chasing 2 bugs here.

1. why does it not print hello world
2. why are we off in the weeds WRT single stepping the h/w.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: S100 - hello world not working.

Post by dom »

Thanks for that, I get the feeling that this isn't really a problem with printf, but more likely a machine setup issue.

I spot this comment: "Has about 46k of ram" which gets to thinking about the stack pointer - by default we don't change the stack pointer on entry so I'm wondering if on this hardware it's ending up defaulting to somewhere which is overflowing - which could explain us executing off into space.

It might be worth adding -pragma-define:REGISTER_SP=16384 to place the stack somewhere which we know is RAM and there's sufficient space to see if that is the problem.
jacotton
Member
Posts: 89
Joined: Fri Nov 24, 2017 1:35 am

Re: S100 - hello world not working.

Post by jacotton »

Stack.... I'll try the pragma.
jacotton
Member
Posts: 89
Joined: Fri Nov 24, 2017 1:35 am

Re: S100 - hello world not working.

Post by jacotton »

Here is my pragma file
#pragma output REGISTER_SP = 0x8000
#pragma output USING_amalloc
#pragma printf "%x %s %02d %c %u"
#pragma scanf "%x %s %02d %c %u"

and the altered make file
CFLAGS = +cpm -Wall -DOLD --list --c-code-in-asm -pragma-include:zpragma.inc
LINKOP = +cpm -create-app -m --list --c-code-in-asm -pragma-include:zpragma.inc

No joy yet.

Updated github.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: S100 - hello world not working.

Post by dom »

It's was worth a shot.

I have to admit most of the testing I've been doing is on CP/M 2.2 rather than 3 so I wonder if we're doing something in the crt0 that isn't right. Let me try to find a version of 3 running somewhere and try it out.
jacotton
Member
Posts: 89
Joined: Fri Nov 24, 2017 1:35 am

Re: S100 - hello world not working.

Post by jacotton »

I have not noticed a problem on the rc2014, switching between 2.2 and 3.0 with the same binary.

I am becoming convinced that there is a problem WRT crt0, but not convinced that its crt0 itself.

Another touch point. I have a program (myget.com) from my inettools repo, that was built some time ago on a previous version
of z88dk. It runs. The newer version does not. Sorry for not bringing that up sooner. I just remembered.

The point now is that older code seems o.k. but new builds do not.

So, with that, are we looking for a delta to crt0 and friends? Do note that, these programs run on the rc2014. Also there
has been some activity WRT z180 code path. That should not be an issue here, but CPU is a Z80, but perhaps a branch
is taken by mistake, or perhaps the CPU type probe is getting it wrong ?
jacotton
Member
Posts: 89
Joined: Fri Nov 24, 2017 1:35 am

Re: S100 - hello world not working.

Post by jacotton »

I think I have a handle on the bug. It's not a z88dk bug.
Looks like the binary is getting corrupted during download.

Sorry for the fire drill.
tnx
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: S100 - hello world not working.

Post by dom »

Oh thank goodness!

Given that you said it was working on the rc2014 it was a bit of a head scratcher.

Does the download problem clear up the other issue as well?
jacotton
Member
Posts: 89
Joined: Fri Nov 24, 2017 1:35 am

Re: S100 - hello world not working.

Post by jacotton »

Yes. I now have a working "Hello World!"

How I figured this out. I used z88dk-dis of the test.com program and compared the listing with what was in memory,
and did trace steps with ddtz. Looked good until it just ran off the rails. After several rounds of that, the light came
on, and is said, 'you know, the binary is busted' .

The sad part is, I found and fixed this before, and just could not accept that I was tracking the same bug again.
So soon old, so late wise.

tnx for your help with this.
Post Reply