Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2022-02

Questions about cross-compiling (z80)

16 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

BogDan

Hello,

According to https://wiki.freepascal.org/Z80 fpc is able to compile pascal code for z80. Sadly I'm a newbie on fpc, therefore I have a few questions:

1. I changed a bit the build script from https://wiki.freepascal.org/Z80#Building and I managed to build fpc, and when I built a simple hello world file, the resulted tzx file seems wrong: ./ppcrossz80 -n -Tzxspectrum -PZ80 -Fu/path/to/fpc/lib/fpc/3.3.1/units/z80-zxspectrum/rtl -viwn -CX -XX test.pas

$ cat test.tzx
:105CF800314CEA0188E0214DE6373FED423E000293
:105D0800032BBD20FABC20F7FD2288E0F31100FE2A
:105D180021FDFD7AED477D121C20FC141236C321AB
....

It seems is an IHX format not tzx
Also the result for a simple hello world is way too big (over 20k) ! I assume that I'm passing wrong params to ppcrossz80. What params should I use? Where I can find more info on this matter?

2. Is it possible to add z80 cross compilation target to FP IDE? The FP IDe shows me a few targets, but z80 is not there.

Cheers,
BogDan.

Sven Barth
to BogDan

BogDan via fpc-devel schrieb am Fr., 11.
Feb. 2022, 11:09:

Show quoted text 24 lines
Hello, According to https://wiki.freepascal.org/Z80 fpc is able to compile pascal code for z80. Sadly I'm a newbie on fpc, therefore I have a few questions: 1. I changed a bit the build script from https://wiki.freepascal.org/Z80#Building and I managed to build fpc, and when I built a simple hello world file, the resulted tzx file seems wrong: ./ppcrossz80 -n -Tzxspectrum -PZ80 -Fu/path/to/fpc/lib/fpc/3.3.1/units/z80-zxspectrum/rtl -viwn -CX -XX test.pas $ cat test.tzx :105CF800314CEA0188E0214DE6373FED423E000293 :105D0800032BBD20FABC20F7FD2288E0F31100FE2A :105D180021FDFD7AED477D121C20FC141236C321AB .... It seems is an IHX format not tzx Also the result for a simple hello world is way too big (over 20k) ! I assume that I'm passing wrong params to ppcrossz80. What params should I use? Where I can find more info on this matter?

You need to make sure that the ihxutil built in
utils/ihxutil/<hostcpu>-<hostos>/ is available in PATH, so that the compiler will do the conversion.

2. Is it possible to add z80 cross compilation target to FP IDE? The FP IDe shows me a few targets, but z80 is not there.

The text mode IDE can only ever compile for one CPU platform, so you need to build it for Z80. Though I don't know right now whether this is enabled.

Regards,
Sven

Tomas Hajny
to Sven Barth
Sven Barth wrote
BogDan via fpc-devel schrieb am Fr., 11. Feb. 2022, 11:09:

.
.

Show quoted text 8 lines
> It seems is an IHX format not tzx > Also the result for a simple hello world is way too big (over 20k) ! > I assume that I'm passing wrong params to ppcrossz80. What params > should I use? Where I can find more info on this matter? You need to make sure that the ihxutil built in utils/ihxutil/<hostcpu>-<hostos>/ is available in PATH, so that the compiler will do the conversion.

@Sven: Sorry for a silly question, but shouldn't the compiler emit some error message if the tool isn't available?

Show quoted text 6 lines
> 2. Is it possible to add z80 cross compilation target to FP IDE? The > FP IDe shows me a few targets, but z80 is not there. The text mode IDE can only ever compile for one CPU platform, so you need to build it for Z80. Though I don't know right now whether this is enabled.

Just for clarification of the original poster - Sven means building the IDE for _compilation_ for Z80 (not that the IDE should run on Z80). Nevertheless, even that isn't supported right now at the moment - as of now, there's support only for x86 and m68k architectures within this IDE. It might be possible to add support for other targets as well, but it would require some effort.

Tomas

Sven Barth
to Tomas Hajny

Tomas Hajny via fpc-devel schrieb am Fr.,
11. Feb. 2022, 17:24:

Show quoted text 18 lines
On 2022-02-11 14:14, Sven Barth via fpc-devel wrote: > BogDan via fpc-devel schrieb am Fr., > 11. Feb. 2022, 11:09: . . >> It seems is an IHX format not tzx >> Also the result for a simple hello world is way too big (over 20k) ! >> I assume that I'm passing wrong params to ppcrossz80. What params >> should I use? Where I can find more info on this matter? > > You need to make sure that the ihxutil built in > utils/ihxutil/<hostcpu>-<hostos>/ is available in PATH, so that the > compiler will do the conversion. @Sven: Sorry for a silly question, but shouldn't the compiler emit some error message if the tool isn't available?

It wasn't me who implemented it. But at least a warning or note might be good, cause the output *is* usable after all.

Regards,
Sven

Florian Klämpfl
to BogDan: Thanks a lot for your quick reply. Adding ihxutil to path fixed the problem. But the…
BogDan wrote 7 lines
Hi, Thanks a lot for your quick reply. Adding ihxutil to path fixed the problem. But the size problem is stil there, a simple 2 lines of code "begin; end."  generates over 32k of code. That code should not generate more than 8 bytes of code.

- no smartlinking?
- any high level language comes with some overhead
- begin end. is simply a bad tests. Getting rid of code any useful program needs makes little sense.
- Z80 rtl is probably not optimized for size yet.

E.g. on avrtiny, the smallest program is 94 bytes, most space taken by the interrupt vector table and flash to ram copying routines any program needs anyways, but in this case a lot of optimization has been spent in the compiler which Z80 didn't receive yet.

Show quoted text 50 lines
Are there any flags that I need to use to make the code smaller? Cheers, BogDan. On Friday, February 11, 2022, 03:14:46 PM GMT+2, Sven Barth via fpc-devel wrote: BogDan via fpc-devel schrieb am Fr., 11. Feb. 2022, 11:09: > Hello, > > According to https://wiki.freepascal.org/Z80 fpc is able to compile pascal code for z80. > Sadly I'm a newbie on fpc, therefore I have a few questions: > > 1. I changed a bit the build script from https://wiki.freepascal.org/Z80#Building and I managed to build fpc, and when I built a simple hello world file, the resulted tzx file seems wrong: >  ./ppcrossz80 -n -Tzxspectrum -PZ80 -Fu/path/to/fpc/lib/fpc/3.3.1/units/z80-zxspectrum/rtl -viwn -CX -XX test.pas > > $ cat test.tzx > :105CF800314CEA0188E0214DE6373FED423E000293 > :105D0800032BBD20FABC20F7FD2288E0F31100FE2A > :105D180021FDFD7AED477D121C20FC141236C321AB > .... > > It seems is an IHX format not tzx > Also the result for a simple hello world is way too big (over 20k) ! > I assume that I'm passing wrong params to ppcrossz80. What params should I use? Where I can find more info on this matter? You need to make sure that the ihxutil built in utils/ihxutil/<hostcpu>-<hostos>/ is available in PATH, so that the compiler will do the conversion. > > 2. Is it possible to add z80 cross compilation target to FP IDE? The FP IDe shows me a few targets, but z80 is not there. > The text mode IDE can only ever compile for one CPU platform, so you need to build it for Z80. Though I don't know right now whether this is enabled. Regards, Sven > _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel _______________________________________________ fpc-devel maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
BogDan
to Sven Barth: BogDan via fpc-devel schrieb am Fr., 11. Feb. 2022, 11:09: You need to make sure that…

Hi,

Thanks a lot for your quick reply.

Adding ihxutil to path fixed the problem.
But the size problem is stil there, a simple 2 lines of code "begin; end."  generates over 32k of code. That code should not generate more than 8 bytes of code. Are there any flags that I need to use to make the code smaller?

Cheers,
BogDan.

On Friday, February 11, 2022, 03:14:46 PM GMT+2, Sven Barth via fpc-devel wrote:

BogDan via fpc-devel schrieb am Fr., 11. Feb. 2022, 11:09:

Show quoted text 17 lines
Hello, According to https://wiki.freepascal.org/Z80 fpc is able to compile pascal code for z80. Sadly I'm a newbie on fpc, therefore I have a few questions: 1. I changed a bit the build script from https://wiki.freepascal.org/Z80#Building and I managed to build fpc, and when I built a simple hello world file, the resulted tzx file seems wrong:  ./ppcrossz80 -n -Tzxspectrum -PZ80 -Fu/path/to/fpc/lib/fpc/3.3.1/units/z80-zxspectrum/rtl -viwn -CX -XX test.pas $ cat test.tzx :105CF800314CEA0188E0214DE6373FED423E000293 :105D0800032BBD20FABC20F7FD2288E0F31100FE2A :105D180021FDFD7AED477D121C20FC141236C321AB .... It seems is an IHX format not tzx Also the result for a simple hello world is way too big (over 20k) ! I assume that I'm passing wrong params to ppcrossz80. What params should I use? Where I can find more info on this matter?

You need to make sure that the ihxutil built in utils/ihxutil/<hostcpu>-<hostos>/ is available in PATH, so that the compiler will do the conversion. 

   2. Is it possible to add z80 cross compilation target to FP IDE? The FP IDe shows me a few targets, but z80 is not there.

The text mode IDE can only ever compile for one CPU platform, so you need to build it for Z80. Though I don't know right now whether this is enabled. 

Regards, 
Sven 

  
Sven Barth
to BogDan

BogDan schrieb am Fr., 11. Feb. 2022, 22:20:

Show quoted text 11 lines
Hi, Thanks a lot for your quick reply. Adding ihxutil to path fixed the problem. But the size problem is stil there, a simple 2 lines of code "begin; end." generates over 32k of code. That code should not generate more than 8 bytes of code. Are there any flags that I need to use to make the code smaller?

The System unit initialization is larger than 8 Byte. A program does not begin with "begin".

Regards,
Sven

Pierre Muller
to BogDan: Thanks a lot for your quick reply. Adding ihxutil to path fixed the problem. But the…
> 2. Is it possible to add z80 cross compilation target to FP IDE? The FP IDe shows me a few targets, but z80 is not there. > The text mode IDE can only ever compile for one CPU platform, so you need to build it for Z80. Though I don't know right now whether this is enabled.

I just added basic support for a few more CPUs: riscv32, riscv64, wasm32, xtensa and z80.

You can generate them in newest trunk by moving to packages/ide directory and issuing a:

make all_targets OPT="XXXX"
with XXXX being you usual OPT.

Or you can simply use:
make z80 OPT="XXXX"
followed by
make z80_install OPT="XXXX"

This should add z80-fp executable in the same location as your latest trunk compiler...

Most CPUs do not have CPU specific options encoded inside the IDE sources, thus you might need to add the options you want to use to the
Please report if you discover any problems.

Pierre

BogDan
to Pierre Muller

Hi,

Wow, thanks a lot Pierre!
Now I can use fp ide to build stuff for zx spectrum.

Cheers,
BogDan.

Pierre Muller wrote
> 2. Is it possible to add z80 cross compilation target to FP IDE? The FP IDe shows me a few targets, but z80 is not there. > The text mode IDE can only ever compile for one CPU platform, so you need to build it for Z80. Though I don't know right now whether this is enabled.

  I just added basic support for a few more CPUs: riscv32, riscv64, wasm32, xtensa and z80.

  You can generate them in newest trunk by moving to packages/ide directory and issuing a:

make all_targets OPT="XXXX"
with XXXX being you usual OPT.

Or you can simply use:
make z80 OPT="XXXX"
followed by
make z80_install OPT="XXXX"

  This should add z80-fp executable in the same location as your latest trunk compiler...

  Most CPUs do not have CPU specific options encoded inside the IDE sources, thus you might need to add the options you want to use to the
  Please report if you discover any problems.

  Pierre

BogDan
to Florian Klämpfl: - no smartlinking? - any high level language comes with some overhead - begin end. is…

Hey,

zx spectrum has ~41k or ram available for apps (it has 48k in total but ~7k are needed for screen). If RTL needs has over 32k it will not be too much left for the application itself. IMHO the z80 port RTL should have at least two implementations:
- bare-metal which implement all the needed stuff
- zx-spectrum which should use the existing routines/data from spectrum rom (see https://skoolkid.github.io/rom  or http://www.primrosebank.net/computers/zxspectrum/docs/CompleteSpectrumROMDisassemblyThe.pdf )

Also, everything that is not used by the application it should be stripped by the linker (if it has one). Again I'd like to highlight that I'm new to fpc, last time I used pascal it was over 20 years ago :) .

This means, IMHO an empty application (begin;end.) should not produce more than a few bytes of code.

Cheers,
BogDan.

P.S. Sorry for top posting, yahoo email is so difficult to be used with maillists

On Friday, February 11, 2022, 11:38:21 PM GMT+2, Florian Klämpfl via fpc-devel wrote:

BogDan wrote 7 lines
Hi, Thanks a lot for your quick reply. Adding ihxutil to path fixed the problem. But the size problem is stil there, a simple 2 lines of code "begin; end."  generates over 32k of code. That code should not generate more than 8 bytes of code.

- no smartlinking?
- any high level language comes with some overhead
- begin end. is simply a bad tests. Getting rid of code any useful program needs makes little sense.
- Z80 rtl is probably not optimized for size yet.

E.g. on avrtiny, the smallest program is 94 bytes, most space taken by the interrupt vector table and flash to ram copying routines any program needs anyways, but in this case a lot of optimization has been spent in the compiler which Z80 didn't receive yet.

Show quoted text 50 lines
Are there any flags that I need to use to make the code smaller? Cheers, BogDan. On Friday, February 11, 2022, 03:14:46 PM GMT+2, Sven Barth via fpc-devel wrote: BogDan via fpc-devel schrieb am Fr., 11. Feb. 2022, 11:09: > Hello, > > According to https://wiki.freepascal.org/Z80 fpc is able to compile pascal code for z80. > Sadly I'm a newbie on fpc, therefore I have a few questions: > > 1. I changed a bit the build script from https://wiki.freepascal.org/Z80#Building and I managed to build fpc, and when I built a simple hello world file, the resulted tzx file seems wrong: >   ./ppcrossz80 -n -Tzxspectrum -PZ80 -Fu/path/to/fpc/lib/fpc/3.3.1/units/z80-zxspectrum/rtl -viwn -CX -XX test.pas > > $ cat test.tzx > :105CF800314CEA0188E0214DE6373FED423E000293 > :105D0800032BBD20FABC20F7FD2288E0F31100FE2A > :105D180021FDFD7AED477D121C20FC141236C321AB > .... > > It seems is an IHX format not tzx > Also the result for a simple hello world is way too big (over 20k) ! > I assume that I'm passing wrong params to ppcrossz80. What params should I use? Where I can find more info on this matter? You need to make sure that the ihxutil built in utils/ihxutil/<hostcpu>-<hostos>/ is available in PATH, so that the compiler will do the conversion. >    > 2. Is it possible to add z80 cross compilation target to FP IDE? The FP IDe shows me a few targets, but z80 is not there. > The text mode IDE can only ever compile for one CPU platform, so you need to build it for Z80. Though I don't know right now whether this is enabled. Regards, Sven >    _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Sven Barth
to BogDan

BogDan via fpc-devel schrieb am Sa., 12.
Feb. 2022, 10:18:

Also, everything that is not used by the application it should be stripped by the linker (if it has one). Again I'd like to highlight that I'm new to fpc, last time I used pascal it was over 20 years ago :) .

The linker can only remove stuff that isn't used. And due to the cross platform nature of FPC manager approaches are used to make the easier maintainable which also results in a negative impact there.

But anyway: did you build FPC and the RTL with the -CX option and compile your application with -XX?

Regards,
Sven

Florian Klämpfl
to BogDan: zx spectrum has ~41k or ram available for apps (it has 48k in total but ~7k are needed…
BogDan wrote 7 lines
Hey, zx spectrum has ~41k or ram available for apps (it has 48k in total but ~7k are needed for screen). If RTL needs has over 32k it will not be too much left for the application itself. IMHO the z80 port RTL should have at least two implementations: - bare-metal which implement all the needed stuff - zx-spectrum which should use the existing routines/data from spectrum rom (see https://skoolkid.github.io/rom  or http://www.primrosebank.net/computers/zxspectrum/docs/CompleteSpectrumROMDisassemblyThe.pdf )

Indeed, so somebody just has to provide a patch for this :)

BogDan
to Sven Barth: BogDan via fpc-devel schrieb am Sa., 12. Feb. 2022, 10:18: The linker can only remove…

Hi,

On Saturday, February 12, 2022, 11:23:40 AM GMT+2, Sven Barth wrote:

BogDan via fpc-devel schrieb am Sa., 12. Feb. 2022, 10:18:

Also, everything that is not used by the application it should be stripped by the linker (if it has one). Again I'd like to highlight that I'm new to fpc, last time I used pascal it was over 20 years ago :) .

The linker can only remove stuff that isn't used. And due to the cross platform nature of FPC manager approaches are used to make the easier maintainable which also results in a negative impact there. 

But anyway: did you build FPC and the RTL with the -CX option and compile your application with -XX? 

Regards, 
Sven 

  

I'm compiling my app with -CX -XX flags.
I just tried to buld fpc and RTL with -CX but it fails with the followings: ...
make[3]: Entering directory '/home/taipan/work/z80/fpc/rtl/zxspectrum' /bin/mkdir -p /home/taipan/work/z80/fpc/rtl/units/z80-zxspectrum /home/taipan/work/z80/fpc/compiler/ppcrossz80 -Tzxspectrum -Pz80 -Ur -Xs -O2 -n -Fi../inc -Fi../z80 -FE. -FU/home/taipan/work/z80/fpc/rtl/units/z80-zxspectrum -Fl/usr/lib/gcc/x86_64-linux-gnu/11 -dz 80 -dRELEASE -O-1  -Us -Sg system.pp
genmath.inc(366,16) Fatal: Code segment too large
Fatal: Compilation aborted

BogDan.

Sven Barth
to BogDan

BogDan schrieb am Sa., 12. Feb. 2022, 13:23:

Show quoted text 38 lines
Hi, On Saturday, February 12, 2022, 11:23:40 AM GMT+2, Sven Barth < > wrote: BogDan via fpc-devel schrieb am Sa., 12. Feb. 2022, 10:18: > Also, everything that is not used by the application it should be stripped by the linker (if it has one). Again I'd like to highlight that I'm new to fpc, last time I used pascal it was over 20 years ago :) . The linker can only remove stuff that isn't used. And due to the cross platform nature of FPC manager approaches are used to make the easier maintainable which also results in a negative impact there. But anyway: did you build FPC and the RTL with the -CX option and compile your application with -XX? Regards, Sven > I'm compiling my app with -CX -XX flags. I just tried to buld fpc and RTL with -CX but it fails with the followings: ... make[3]: Entering directory '/home/taipan/work/z80/fpc/rtl/zxspectrum' /bin/mkdir -p /home/taipan/work/z80/fpc/rtl/units/z80-zxspectrum /home/taipan/work/z80/fpc/compiler/ppcrossz80 -Tzxspectrum -Pz80 -Ur -Xs -O2 -n -Fi../inc -Fi../z80 -FE. -FU/home/taipan/work/z80/fpc/rtl/units/z80-zxspectrum -Fl/usr/lib/gcc/x86_64-linux-gnu/11 -dz 80 -dRELEASE -O-1 -Us -Sg system.pp genmath.inc(366,16) Fatal: Code segment too large Fatal: Compilation aborted

I don't see -CX listed there.

Regards,
Sven

BogDan
to Sven Barth

Hi,

On Saturday, February 12, 2022, 06:08:22 PM GMT+2, Sven Barth wrote:

BogDan schrieb am Sa., 12. Feb. 2022, 13:23:

Show quoted text 28 lines
Hi, On Saturday, February 12, 2022, 11:23:40 AM GMT+2, Sven Barth wrote: BogDan via fpc-devel schrieb am Sa., 12. Feb. 2022, 10:18: > Also, everything that is not used by the application it should be stripped by the linker (if it has one). Again I'd like to highlight that I'm new to fpc, last time I used pascal it was over 20 years ago :) . The linker can only remove stuff that isn't used. And due to the cross platform nature of FPC manager approaches are used to make the easier maintainable which also results in a negative impact there.  But anyway: did you build FPC and the RTL with the -CX option and compile your application with -XX?  Regards,  Sven  >   I'm compiling my app with -CX -XX flags. I just tried to buld fpc and RTL with -CX but it fails with the followings: ... make[3]: Entering directory '/home/taipan/work/z80/fpc/rtl/zxspectrum' /bin/mkdir -p /home/taipan/work/z80/fpc/rtl/units/z80-zxspectrum /home/taipan/work/z80/fpc/compiler/ppcrossz80 -Tzxspectrum -Pz80 -Ur -Xs -O2 -n -Fi../inc -Fi../z80 -FE. -FU/home/taipan/work/z80/fpc/rtl/units/z80-zxspectrum -Fl/usr/lib/gcc/x86_64-linux-gnu/11 -dz 80 -dRELEASE -O-1  -Us -Sg system.pp genmath.inc(366,16) Fatal: Code segment too large Fatal: Compilation aborted

I don't see -CX listed there. 

My bad, I did wrong changes to the build script.
Anyway, I double checked that the rtl is built with -CX -XX but the final size is still over 32k. Can someone else check if a simple "begin;end." test strips the rtl ?

Cheers,
BogDan.

Nikolay Nikolov
to Sven Barth: Tomas Hajny via fpc-devel schrieb am Fr., 11. Feb. 2022, 17:24: It wasn't me who…
Sven Barth wrote 27 lines
Tomas Hajny via fpc-devel schrieb am Fr., 11. Feb. 2022, 17:24: On 2022-02-11 14:14, Sven Barth via fpc-devel wrote: > BogDan via fpc-devel schrieb am Fr., > 11. Feb. 2022, 11:09:   .   . >> It seems is an IHX format not tzx >> Also the result for a simple hello world is way too big (over 20k) ! >> I assume that I'm passing wrong params to ppcrossz80. What params >> should I use? Where I can find more info on this matter? > > You need to make sure that the ihxutil built in > utils/ihxutil/<hostcpu>-<hostos>/ is available in PATH, so that the > compiler will do the conversion. @Sven: Sorry for a silly question, but shouldn't the compiler emit some error message if the tool isn't available? It wasn't me who implemented it. But at least a warning or note might be good, cause the output *is* usable after all.

Added an error in:

https://gitlab.com/freepascal.org/fpc/source/-/commit/3c91a7c01ea16f5fc9239b21636d4127faacaf31

The error looks like this:

Free Pascal Compiler version 3.3.1 [2022/02/13] for z80 Copyright (c) 1993-2022 by Florian Klaempfl and others Target OS: ZX Spectrum
Compiling hello.pas
Linking hello.tzx
hello.pas(4,1) Error: Util ihxutil not found, switching to external linking hello.pas(4,1) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted

Additionally, there's an extra message that the tool is being used, when you compile with -vt and the tool is found.

Nikolay

Show quoted text 7 lines
Regards, Sven _______________________________________________ fpc-devel maillist https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel