QL / PASCAL

Anything QL Software or Programming Related.
User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: QL / PASCAL

Post by NormanDunbar »

Chain-Q wrote:@pjw
Something tells me the bar wasn't set too high, but hey. :D Any victory is a victory! :ugeek: Anyway, as said earlier, now documented.
Hmm, it's obviously me doing something wrong, but this code gives compilation errors:

Code: Select all

{ Program to demonstrate the Reset function. }

program FPC_RESET;
    
Var 
    f : text;
    l : array[0..255] of char;

begin
    Assign (f,'ram1_test.txt');
    Reset (f);            { file is opened for read }
    Readln(f, l);
    Writeln (l);
    Close (f);
end.
The error is:

Code: Select all

$ fpc-ql -Tsinclairql reset.pp
system.o: In "SYSTEM_$$_SYSINITQDOS":
Error 21: system.o (.text.n_system_$$_sysinitqdos+0x56): Reference to undefined symbol __fpc_program_name.
Warning 22: Attributes of section .text were changed from r-x- in Linker Script <link1340.res> to rwx- in reset.o.
reset.pp(10,30) Error: Error while linking
reset.pp(10,30) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
It doesn't look happy with the new program name stuff. I get the same error if I omit the "program" line, as is permitted with FPC.

I have done the following:
  • svn update;
  • rebuilt the cross compiler -- just in case;
  • rebuilt the rtl;
  • Added program to the source code;
  • Compiled with "fpc-ql -Tsinclairql reset.pp"
I have not touched the units.

What have I missed please?


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
Chain-Q
Chuggy Microdrive
Posts: 62
Joined: Mon Nov 16, 2020 1:10 pm
Location: Berlin, DE, EU
Contact:

Re: QL / PASCAL

Post by Chain-Q »

@NormanDunbar

Rebuilding the crosscompiler is certainly needed, in fact this is exactly the error you should get if you use a too old compiler with the current RTL. __fpc_program_name is the symbol the compiler should generate. Omitting the program keyword doesn't change it, the compiler will still use some default anyway, I think it is "Program" or something. BTW, your example builds just fine for me (and I have no more local compiler changes now, so current SVN trunk state).

But in case you're sure you're using the right compiler, can you build with -al, then upload the .s file somewhere?

Edit:A stupid idea maybe, but are you sure you updated to latest SVN on the whole tree, before rebuilding the compiler? SVN is not like git, it will only update the directory you're executing the update from. So for a full update you have to update from trunk root, not from rtl/sinclairql. Sorry if that's not the problem, but I was running into this exact thing myself, that I thought I've updated, and I haven't, so I thought I'd share it maybe.


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: QL / PASCAL

Post by NormanDunbar »

Problem solved. It was a PICNIC. (Problem In Chair, Not In Computer)!

I had indeed rebuilt the cross compiler, but the version number changed from 3..2.0 to 3.3.1. Once I sorted that out, everything was fine and the code compiles quite happily.

The default jobname, if no Program line is present appears to be "Program", otherwise it takes the job name from the Program line. Very nice, thanks.

Thanks also for the tip about SVN. I had used it for years before git took over the world, and yes, I was in the top level directory when I updated. No problems on that score. :)

In case anyone (else) is interested, I'm documenting all the steps and stages to go through to get a cross compiler up and running on Linux. I don't run Windows so I would appreciate someone taking my document and letting me know the changes required for Windows -- at some point after I've completed the Linux version.

EDIT: I decided to append my "work in progress" document, as it may already prove useful.
EDIT2: I have removed the attachment as it is no longer a work in progress, and the "final" version is online at https://github.com/NormanDunbar/FPC-Cro ... ses/latest for anyone interested.




Cheers,
Norm.
Attachments
QlCrossCompiler.pdf
(327.4 KiB) Downloaded 67 times


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
Chain-Q
Chuggy Microdrive
Posts: 62
Joined: Mon Nov 16, 2020 1:10 pm
Location: Berlin, DE, EU
Contact:

Re: QL / PASCAL

Post by Chain-Q »

@NormanDunbar

Glad that your PICNIC went well. :D And that's a quite nice document you've got there. It really extends on a lot of details for beginners, which I did not want to include into the wiki. But if you find some final location for it somewhere, I'll gladly link it from the FPC Wiki page.

In other news, I had some overnight fun with stack pointers, so now the QL port sports working stacktraces, and even stack checking. This later is optional, enable it with $S+ directive, or -Ct compiler command line argument, but it's a debug feature, not to be included in production software due to its performance implications and because it really isn't a silver bullet: there are scenarios where the program could still overflow its stack. But I'm sure it's helpful to debug some cases anyway. Note the stack checking code works with 5% (or max. 16KiB) of stack space safety margin, so the RTE 202 will occur before the stack has actually overflown, unless you have a function which uses more stack than the safety margin.
Screenshot 2021-04-14 at 06.11.05.png
Only one is visible on the screenshot, but in the stack traces two different kind of lines are possible. "Offs" lines, they show the offset from the code start within the binary. And "Addr" lines, which would be absolute addresses, in case some stack call offset is outside the binary's code range, and they're somewhere else in memory. The offsets are really useful if you use the -Xm compiler argument. Then FPC tells vlink to generate a human readable linker .map file. Using the map file, the offsets can be turned into function names with relative ease, when debugging.

There would be a lot more possibilities down this line, but I'm not sure how many of them are feasible on QL. Anyway, it's a start.


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: QL / PASCAL

Post by NormanDunbar »

Chain-Q wrote:Glad that your PICNIC went well. :D And that's a quite nice document you've got there. It really extends on a lot of details for beginners, which I did not want to include into the wiki. But if you find some final location for it somewhere, I'll gladly link it from the FPC Wiki page.
Thanks, and yes, the PICNIC did go well. :D (Silly me!)

The document will be available on my GitHub releases area as will the LyX/LaTeX source "soon". Anyone can have it, so feel free to link to it -- when I post the link. I'll be intending to keep it up to date too. Corrections etc are all welcome.

The stack stuff looks very interesting. I might have to have a play there later.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: QL / PASCAL

Post by tofro »

After fighting a bit with wierdness in the install files and eventually building my own private version of the native compiler, I have finally managed to build both the m68k cross-compiler and the system unit on a Raspberry Pi 400 (why there? well, because you can!).

You guys may expect one or the other dubious patch once my family obligations allow more "free" Pascal time ;)


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: QL / PASCAL

Post by NormanDunbar »

tofro wrote:I have finally managed to build both the m68k cross-compiler and the system unit on a Raspberry Pi 400
Just out of interest, did you use my document? If so, how did you find it? Happy for a major slagging off, or indeed, praise. Anything that will help.


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: QL / PASCAL

Post by tofro »

Norman, yes I did read your document (but only found it after I was already done with the cross-compiler ;) ). It's very nice and much more detailed than I would have expected. Good thing we have something that explains things on a detail level, thanks!!

I actually worked from the doc found on the FPC wiki. That sortof covered my base, as I have built FPC before on x86 Linux.

This didn't help me with the problems I encountered on the RPi 400 which were somewhat outside the FPC domain, but rather with the Raspian distribution: This contains a pretty old compiler (3.04) that is apparently not able to build current FPC (it actively refuses with a message). Then I was searching half of the internet for a more or less current 3.2 binary. I found some 3.2 tar packages, but somehow they did contain - the 3.04 compiler binary - drat!. So ended up compiling the ARM compiler first with an x86 cross compiler (that I had to build first) on yet another Linux box, then I eventually had a compiler that could build the ARM cross compiler - from there, everything else went smoothly.

At least some proof the FPC package is really portable ;)
Last edited by tofro on Wed Apr 14, 2021 6:04 pm, edited 1 time in total.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: QL / PASCAL

Post by NormanDunbar »

Ok, thanks ToFro, that was useful.

Mind you, it does your head in creating compilers to compile a compiler to compile a compiler that you need to use!


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: QL / PASCAL

Post by NormanDunbar »

Second attempt:

A quick fix for today. The existing MT_INF in qdos.inc has the system variables address coming back via a pchar and the ASCII version via a plongint. They are the wrong way around. Patch 6 fixes the problem. However, you will need the latest source code so do an svn update first.

EDIT: 17 April 2021: I'm informed that there's work to be done with mt_inf and that the parameters may not be incorrect after all, so I've removed patch 6 from this posting for now. If you have already applied it, then:

Code: Select all

cd ~/SourceCode/fpc/rtl/sinclairql
svn revert qdos.inc
Will get things back to how they were. You can then rebuild the RTL and reinstall it as per usual.

I was going to post some really bad Pascal code, but the Forum ate my first reply with a 403 Forbidden error.

Cheers,
Norm.
Attachments
FPC.patch.6.zip
(537 Bytes) Downloaded 48 times


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Post Reply