15 May 2020, 21:20 | #1 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
Running c code from Amos
I'm a member from the Demogroup void. We have a challenge. Our
coders use Amos, C and assembler. We want to make demos together but nobody wants to change its language preference. So I told myself that it has to be possible to merge code from all those three languages into one executable. On the lowest level everything is machine code after all. After some research I discovered that Amos has commands to embedd binary files. With the method PLIST a binary can be loaded into memory. This code can get executed using the Call method. There is a caveat however. Amos only loads the first hunk. All others are ignored. I'm using gcc and do a crosscompile for the c code. I do not have full control over the hunks there. How can I workaround this? |
15 May 2020, 22:08 | #2 |
Registered User
Join Date: Apr 2013
Location: Mallorca
Posts: 758
|
We use vlink to manipulate objects before link time (to embed 68k code with gcc ppc code, for example). Phx knows about hunks.
Other than that, cut paste hex code from output object to be read as an array..... |
16 May 2020, 12:14 | #3 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Quote:
Cowcat already mentioned vlink, which might be the solution here. I have some options for merging code sections, all data and bss sections for small-data, and merging all sections of the same type. Adding another option for merging all sections was a matter of 5 minutes. Tomorrow's vlink snapshot at http://sun.hasenbraten.de/vlink/index.php?view=source can do that with the new -mall option. I don't know if your C developers have the knowledge to replace the GNU-linker with vlink to generate an executable. But vlink also works directly on executables and can convert them (while emitting some warnings). For example: vlink -bamigahunk -mall -o newexe oldexe. Or does PLIST need an object file? I have no experience with Amos at all. Is there even an Amos compiler which can create object files from your Amos source? |
||
16 May 2020, 18:18 | #4 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
Thanks so much for this phx! This vlink version should make this a piece of cake. Will let you know how it goes.
|
16 May 2020, 19:04 | #5 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
Didn't touch AMOS for decades myself. :-)
I'd say PLOAD needs an executable. Thats what the Manual says. The PLOAD command reserves a memory bank and loads some machine code into it from disc. Specify thefilename that contains the machine code file on disc, followed by the number of a new memory bank to be reservedfor the program. If the bank number is negative, the number will be multiplied by -1, and the bank will be allocatedusing Chip memory.Once machine code is loaded in this way, it is installed as a permanent memory bank, so whenever the currentprogram is saved, the machine code is stored too. Also note that the machine code file can be saved onto disc as astandard ".Abk" file, then loaded directly into AMOS Professional Basic. After PLOAD has performed its work, the memory bank can be executed immediately! I do not think that its possible to create an object file with Amos compiler. But this way it should not be neccesary. If I understand it correctly I can just compile it and the binary will be embedded in it. |
16 May 2020, 22:14 | #6 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
|
18 May 2020, 21:10 | #7 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
You can also load a executable inside a Procedure. Amos procedures do accept parameters. Same rules apply otherwise as for PLOAD.
New version of vlink works fine. It gives me a working executable with only one section. Amos Integration dies not work yet. Have to find out why. |
24 May 2020, 09:32 | #8 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
It looks like Amos doesnt to relocation. This makes it hard to use for my purpose. I'd need to write everything PC relative. Which is difficult to do in C for a bigger chunk of code.
|
24 May 2020, 09:40 | #9 | |
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
|
Quote:
A long time ago I solved a similar problem by writing an AMOSPro extension which could load code modules (using LoadSeg() so with full relocation). My modules contained a header which the extension used to locate variables and procedures. I released the extension here: http://aminet.net/package/dev/amos/GameSupport a long time ago - if you think it might help with your project I'll see if I can find an example code module, too. |
|
24 May 2020, 10:02 | #10 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
This sounds interesting! I've seen the loadseg function. My issue is that we need this
for an intro. Which means we are limited to one file. So we'd need to "run loadseg" for a block in memory instead of a file. Not sure this would be possible. |
24 May 2020, 10:15 | #11 | |
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
|
Quote:
Yeah that does make things a lot trickier. If the OS is still alive, one brute-force, ugly method might be to save the executable back out to RAM: and LoadSeg() it from there. What's the problem with PC-relative code from C, though? Which compiler are you using? |
|
24 May 2020, 10:23 | #12 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
I'm using gcc. Found some compile options like fpic, fpie and mpcrel. Either they don't do anything or cause compiler or linker errors.
|
24 May 2020, 11:25 | #13 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
Basically what I need is something like this http://www.whdload.de/docs/autodoc.h...sload_Relocate
|
24 May 2020, 11:50 | #14 | |
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
|
Quote:
I've just tried -mpcrel with m68k-elf-gcc and it does indeed seem to generate PC-relative code. What errors are you seeing with that option? What exactly are you trying to do within the C code? Any OS calls? Are you linking with or without startup code / std C library? Are you using a linkscript? |
|
24 May 2020, 12:05 | #15 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
Compilation with mpcrel works. The result isn't what I need unfortunately. First instruction is 4E F9 00 00 00 06 (jmp $6). Without relocation this jumps to address 06 and of course crashes.
|
24 May 2020, 12:15 | #16 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,502
|
One solution (or a hack) would be to add small routine at the beginning of executable that does the relocation in-place.
I used this method to create pfs3aio "custom" version that is made for crappy HD controllers that expect no relocations in RDB embedded filesystems. It is basically original executable embedded in another executable. |
24 May 2020, 12:23 | #17 | |
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
|
Quote:
But where does that jmp $6 come from? Is that from your code, or is it startup / library code? If the latter, have you tried linking without startup / c library? |
|
24 May 2020, 13:33 | #18 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
Hi Tony. Thanks for the hint. Found the source on https://github.com/tonioni/pfs3aio. Where in the source would I find the code I'm interested in?
|
24 May 2020, 18:07 | #19 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,502
|
It is not part of pfs3aio. But it is extremely simple: (pfs3aio is normal executable, must only have 1 hunk)
Code:
start move.l 4.w,a6 jsr -$0084(a6) lea DriverStart+$1c(pc),a0 move.l (a0)+,d0 ;hunk size move.l a0,a1 addq.l #2,d0 lsl.l #2,d0 add.l d0,a0 move.l a1,d1 tst.l (a0) bmi.s relocend moveq #-1,d0 move.l d0,(a0)+ reloc move.l (a0)+,d0 beq.s relocend add.l d1,0(a1,d0.l) bra.s reloc cmp.w #36,20(a6) bcs.s relocend jsr -$27c(a6) relocend jsr -$008a(a6) jmp (a1) DriverStart incbin "l:pfs3aio/pfs3aio" DriverEnd end |
24 May 2020, 21:43 | #20 |
Registered User
Join Date: Mar 2016
Location: Thun / Switzerland
Posts: 57
|
Thanks Tony. I think this code should make it straight forward for me to write my own relocation routine.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
develop AMOS code in PC/Mac | slademania | Coders. AMOS | 6 | 29 November 2019 22:36 |
Is there any way of modularize AMOS code? | darkhog | Coders. AMOS | 9 | 04 April 2017 23:54 |
AMOS (Editor) Source Code | SparkyNZ | request.Apps | 4 | 25 March 2017 00:49 |
Trying to get Amos 3D running on my 600 | Johan Walfridso | support.Apps | 4 | 13 March 2009 23:26 |
Running AMOS from HDD? | Fackamato | support.Apps | 11 | 15 November 2004 21:27 |
|
|