2 * Copyright (c) 2004 Greg Parker. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY GREG PARKER ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #define swap32(n) ( ((((unsigned long) (n)) << 24) & 0xFF000000) | \
31 ((((unsigned long) (n)) << 8) & 0x00FF0000) | \
32 ((((unsigned long) (n)) >> 8) & 0x0000FF00) | \
33 ((((unsigned long) (n)) >> 24) & 0x000000FF) )
36 void print(char *format, ...)
38 RectangleType r, empty;
42 va_start(args, format);
43 StrVPrintF(buf, format, args);
50 WinScrollRectangle(&r, winDown, 12, &empty);
51 WinEraseRectangle(&empty, 0);
53 WinDrawChars(buf, StrLen(buf), 1, 1);
56 static MemHandle armH = NULL;
58 PealModule *load(void)
61 armH = DmGetResource('armc', 1000);
65 return PealLoad(MemHandleLock(armH));
67 return PealLoadFromResources('armc', 1000);
71 void unload(PealModule *m)
75 MemHandleUnlock(armH);
76 DmReleaseResource(armH);
81 uint32_t callback(void)
87 void test(PealModule *m)
89 void *GetCallCount_arm;
90 void *SetFunctionPointer_arm;
91 void *CallFunctionPointer_arm;
94 uint32_t *CallCount_arm;
99 // Call an ARM function that uses global data
100 GetCallCount_arm = PealLookupSymbol(m, "GetCallCount");
102 result = PealCall(m, GetCallCount_arm, NULL);
103 print("CallCount(): %lu", result);
104 result = PealCall(m, GetCallCount_arm, NULL);
105 print("CallCount(): %lu", result);
106 result = PealCall(m, GetCallCount_arm, NULL);
107 print("CallCount(): %lu", result);
109 // Read an ARM variable directly
110 CallCount_arm = (uint32_t *)PealLookupSymbol(m, "CallCount");
111 print("CallCount variable is %lu", swap32(*CallCount_arm));
113 // Call an ARM function that uses function pointers and global data
114 SetFunctionPointer_arm = PealLookupSymbol(m, "SetFunctionPointer");
115 CallFunctionPointer_arm = PealLookupSymbol(m, "CallFunctionPointer");
117 PealCall(m, SetFunctionPointer_arm, (void *)1);
119 str = (char *)PealCall(m, CallFunctionPointer_arm, NULL);
120 print("CallFunctionPointer (fn 1): '%s'", str);
122 PealCall(m, SetFunctionPointer_arm, (void *)0);
124 str = (char *)PealCall(m, CallFunctionPointer_arm, NULL);
125 print("CallFunctionPointer (fn 0): '%s'", str);
126 str = (char *)PealCall(m, CallFunctionPointer_arm, NULL);
127 print("CallFunctionPointer (fn 0): '%s'", str);
129 // Set an ARM variable
130 Callback_arm = (void **)PealLookupSymbol(m, "Callback_m68k");
131 *Callback_arm = (void *)swap32(&callback);
133 // Call an ARM function that calls back into m68k
134 Call68K_arm = PealLookupSymbol(m, "Call68K");
135 result = PealCall(m, Call68K_arm, NULL);
136 print("m68k callback return %lu", result);
138 // Read an ARM variable directly
139 CallCount_arm = PealLookupSymbol(m, "CallCount");
140 print("CallCount variable is %lu", swap32(*CallCount_arm));
144 UInt32 PilotMain(UInt16 cmd, void *cmdPBP, UInt16 launchFlags)
148 // we don't handle search et al.
149 if (cmd != sysAppLaunchCmdNormalLaunch) return 0;
155 print("Quitting in 10 seconds.");
156 SysTaskDelay(10*SysTicksPerSecond());