Cross compiled executables, the XTcc record and Dataspace.

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

Cross compiled executables, the XTcc record and Dataspace.

Post by NormanDunbar »

As mentioned elsewhere, I'm playing with the xtc68 C compiler, on Linux, to generate executables for QDOSMSQ. It works quite well, so far.

I did need a quick utility to convert the non-executable on QDOSMSQ, to an executable with the correct data space, as taken from the 'XTcc' header at the end of the compiled file. To this end, I quickly knocked up the following:

Code: Select all

1000 REMark A program to extract the XTcc record from the end of a
1010 REMark Cross-compiled executable file and set the dataspace to
1020 REMark the correct value.
1030 :
1040 REMark Norman Dunbar
1050 REMark 30th October 2018.
1060 :
1070 REMark Uses DJToolkit
1080 :
1085 CLS
2000 REPeat file_loop
2010   PRINT #1
2020   INPUT #1, 'Enter the cross-compiled filename please, ENTER to quit: '; f$
2030   IF f$ = '' THEN EXIT file_loop: END IF
2040   IF FILE_TYPE(f$) = 1 THEN
2050     PRINT #1,f$; ' is already an executable file, with dataspace set to ';
2060     PRINT #1,FILE_DATASPACE(f$)
2070     NEXT file_loop
2080   END IF
2090   :
2100   size = FILE_LENGTH(f$)
2110   IF size < 0 THEN
2120     PRINT #1,'Error '; size; ' reading file size for '; f$
2130     NEXT file_loop
2140   END IF
2150   :
2160   addr = RESERVE_HEAP(size)
2170   IF addr < 0 THEN
2180     PRINT #1, 'Error '; addr; ' allocating memory for '; f$
2190     NEXT file_loop
2200   END IF
2210   :
2220   LBYTES f$,addr
2230   xtcc = SEARCH_I(addr + size - 8, 4, 'XTcc')
2240   IF xtcc = 0 THEN
2250     PRINT #1, f$; ' has no XTcc record present. Cannot continue.'
2260     RELEASE_HEAP(addr)
2270     NEXT file_loop
2280   END IF
2290   :
2300   dspace = PEEK_L(xtcc + 4)
2310   PRINT #1, 'XTcc record found. Dataspace is '; dspace
2320   IF dspace < 512 THEN
2330     PRINT #1, 'Dataspace seems a tad small at '; dspace
2340     PRINT #1, 'You might need to increase it. '
2350   END IF
2360   :
2370   SEXEC_O f$, addr, size, dspace
2380   PRINT f$; ' resaved as executable file, with dataspace set to '; dspace; '.'
2390   RELEASE_HEAP(addr)
2400   PRINT 'Press any key to continue....'
2410 END REPeat file_loop
This requires DJToolkit but that's easily available from Dilwyn at http://www.dilwyn.me.uk/tk/djtk.zip.

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: Cross compiled executables, the XTcc record and Dataspace.

Post by NormanDunbar »

Regarding the above listing, there will be an article an this very subject in the next, somewhat exciting, instalment of the somewhat irregular Assembly Language eComic.

Watch out for that, coming soon. (For certain values of "soon" that is!) ;)


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.
Post Reply