28 July 2013, 18:28 | #1 |
Registered User
Join Date: Apr 2013
Location: Mallorca
Posts: 762
|
Mixed 68k / PPC code on VBCC.
Hello. This is my first post.
So far I've been testing some 68k C code that sends data (array with integers) to a PPC C code function and returns the result: Compiled each object file with their respective cpu directives and then linked both finally as 68k code. It works. The problem I face is when my data is based arround float point: The PPC code needs the link library -lm to work correctly, but at linking time I can only use 68k link libraries. Being a half begginer coder I don't know if it is possible such a thing, or if I need some kind of stub (fd,etc) with mixed math code from both cpu's. Any idea? "2013 and playing with my old Commodore A 1200-40/PPC " Last edited by Cowcat; 28 July 2013 at 19:47. |
28 July 2013, 18:30 | #2 |
BlizzardPPC'less
|
I don't know the answers to your coding questions, but I'm always after members to join our Blizzard PPC club
Welcome to EAB |
28 July 2013, 19:46 | #3 |
Registered User
Join Date: Apr 2013
Location: Mallorca
Posts: 762
|
Thanks!
|
29 July 2013, 10:38 | #4 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,537
|
Quote:
You have to resolve all PPC symbol references, before doing the final linking step with the 68k startup code, objects and libraries. So you may try the following with all the PPC objects (from memory, assuming WarpOS EHF object file format): Code:
vlink -bamigaehf -r -o ppc.o ppcobj1.o ppcobj2.o ... -Lvlibwos: -lm In the final linking step you just link with ppc.o. |
|
29 July 2013, 12:40 | #5 |
Registered User
Join Date: Apr 2013
Location: Mallorca
Posts: 762
|
Thanks a lot phx. It's a warpos object. I tried something like that but the result it's a warpos exception. I'll post code later.
|
29 July 2013, 15:55 | #6 |
Registered User
Join Date: Apr 2013
Location: Mallorca
Posts: 762
|
code1.c
#include <stdio.h> #ifdef __VBCC__ #pragma amiga-align #endif #include <proto/exec.h> #include <powerpc/powerpc.h> #include <proto/powerpc.h> #ifdef __VBCC__ #pragma default-align #endif #include "st.h" extern void PPC_add(); int i; vertex v[] = { {-0.5,-0.5, 1.0}, {-0.5, 0.5, 1.0}, { 0.5,-0.5, 1.0}, { 0.5, 0.5, 1.0} }; int main() { struct PPCArgs pa; pa.PP_Code =(ULONG *)&PPC_add; pa.PP_Offset = 0; pa.PP_Flags = PPF_LINEAR; pa.PP_Stack = 0; pa.PP_StackSize=0; pa.PP_Regs[0]=(ULONG) &v; printf("Going PPC\n"); RunPPC(&pa); for(i=0;i<4;i++){ printf("Result X %f\n",v[i].x); printf("Result Y %f\n",v[i].y); printf("Result Z %f\n",v[i].z); printf("\n"); } return(0); } ############################################## code2.c #include <math.h> #include "st.h" void PPC_add (__reg("r3") vertex *p) { int i; for(i=0;i<4;i++){ p[i].x = p[i].x +0.5; p[i].y = p[i].y +0.5; p[i].z = p[i].z +0.5; } } ########################## st.h typedef struct{ float x,y,z; }vertex; Then.... vc +aos68k -c99 -c code1.c vc +warpos -c99 -c code2.c vlink -bamigaehf -r -o ppc.o code2.o -Lvlibwos: -lm vc +aos68k -o crap code1.o ppc.o -lamiga -lmieee -lauto Something is wrong in my code (crap) : Results are weird (sometimes same original values, others unexpected float values)....... Same happens without linking ppc object with -lm. No problem if I modify array and code to work only with integers. Last edited by Cowcat; 29 July 2013 at 16:03. |
31 July 2013, 11:02 | #7 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,537
|
I guess your problem is that the TOC pointer in r2 is not initialized for the PPC code, so static data references will access random memory locations.
The TOC pointer in r2 is the same as the small data pointer in a4 for the M68k. You either have to pass it via PP_Regs (from LinkerDB symbol) or use the attribute __saveds for PPC_add(), so the function will restore the TOC register itself. I would recommend Code:
__saveds void PPC_add (__reg("r3") vertex *p) { When it still doesn't work then I need some time to reproduce it on a real WarpOS environment at home. BTW, those #ifdefs are not needed, because by definition a #pragma directive must be ignored by the compiler, when it is unknown. Quote:
Quote:
But now, when using __saveds, you have to link with the WarpOS -lvc here, to resolve a reference to the __setr2 function, which restores the TOC pointer. |
||
31 July 2013, 12:48 | #8 |
Registered User
Join Date: Apr 2013
Location: Mallorca
Posts: 762
|
Awesome. My initial thought about linking m.lib, was that compiling for only warpos a similiar code, and without linking that lib, the printf output is a "%f" string (??) More brain storming, thank you again.
|
31 July 2013, 13:00 | #9 |
Registered User
Join Date: Apr 2013
Location: Mallorca
Posts: 762
|
Perfect. It works (__saveds & linking -lvc ) !!! ,)
|
31 July 2013, 17:09 | #10 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,537
|
Quote:
Quote:
|
||
01 August 2013, 16:01 | #11 |
Registered User
Join Date: Apr 2013
Location: Mallorca
Posts: 762
|
I owe you two beers.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
68k & 060 friendly code... | korruptor | Coders. Tutorials | 5 | 05 February 2011 15:46 |
68K/PPC context switching? | RedskullDC | support.Hardware | 1 | 08 December 2008 11:44 |
VBCC 0.8j for Windows | hitchhikr | Coders. General | 11 | 09 October 2008 00:58 |
Any interested in buying NEW PPC and 68K accelerators for A1200? | keropi | MarketPlace | 8 | 23 February 2005 00:20 |
Aweb: New APL 3.5Beta AOS4 PPC code + Milestone: KHTML porting started | Paul | News | 0 | 05 November 2004 11:21 |
|
|