[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cinvoke-svn] r90 - in trunk/cinvoke: lib lib/arch test
From: |
will |
Subject: |
[cinvoke-svn] r90 - in trunk/cinvoke: lib lib/arch test |
Date: |
13 Jul 2006 02:02:10 -0400 |
Author: will
Date: 2006-07-13 02:02:07 -0400 (Thu, 13 Jul 2006)
New Revision: 90
Modified:
trunk/cinvoke/lib/arch/cl_x86_win.h
trunk/cinvoke/lib/arch/empty_empty_empty.c
trunk/cinvoke/lib/arch/empty_empty_empty.h
trunk/cinvoke/lib/arch/gcc_ppc_osx.c
trunk/cinvoke/lib/arch/gcc_ppc_osx.h
trunk/cinvoke/lib/arch/gcc_x64_unix.h
trunk/cinvoke/lib/arch/gcc_x86_unix.h
trunk/cinvoke/lib/cinvoke.c
trunk/cinvoke/test/runtests.c
Log:
working on ppc
Modified: trunk/cinvoke/lib/arch/cl_x86_win.h
===================================================================
--- trunk/cinvoke/lib/arch/cl_x86_win.h 2006-07-13 03:35:19 UTC (rev 89)
+++ trunk/cinvoke/lib/arch/cl_x86_win.h 2006-07-13 06:02:07 UTC (rev 90)
@@ -104,7 +104,7 @@
#define ARCH_STACK_GROWS_DOWN 1
-#define ARCH_STACK_TOPSKIP 0
+#define ARCH_STACK_SKIPTOP 0
#define ARCH_REGPARMS_IN_STACKSIZE 0
Modified: trunk/cinvoke/lib/arch/empty_empty_empty.c
===================================================================
--- trunk/cinvoke/lib/arch/empty_empty_empty.c 2006-07-13 03:35:19 UTC (rev 89)
+++ trunk/cinvoke/lib/arch/empty_empty_empty.c 2006-07-13 06:02:07 UTC (rev 90)
@@ -226,11 +226,6 @@
// in structures, but Microsoft cl aligns them on an 8-byte
// boundary. If you do not set structalign_out, then
// it is implcitly assumed to be 1.
-
-// Incidentally, the best way to determine these values
-// (and just about everything else in this file and the header)
-// is not by consulting docs but by writing test programs, and
-// using your C compiler to dump them to assembly.
void arch_size_char(int *stacksize_out, int *structsize_out,
int *structalign_out) {
*stacksize_out = 4;
Modified: trunk/cinvoke/lib/arch/empty_empty_empty.h
===================================================================
--- trunk/cinvoke/lib/arch/empty_empty_empty.h 2006-07-13 03:35:19 UTC (rev 89)
+++ trunk/cinvoke/lib/arch/empty_empty_empty.h 2006-07-13 06:02:07 UTC (rev 90)
@@ -175,7 +175,7 @@
// set this to a value other than 0, you must allocate additional
// space in ARCH_PUT_STACK_BYTES (and de-allocate additional space in
// ARCH_REMOVE_STACK_BYTES!).
-#define ARCH_STACK_TOPSKIP 0
+#define ARCH_STACK_SKIPTOP 0
// TODO: Set this to 1 if args being passed in registers are
// still allocated space on the stack, despite not being copied
Modified: trunk/cinvoke/lib/arch/gcc_ppc_osx.c
===================================================================
--- trunk/cinvoke/lib/arch/gcc_ppc_osx.c 2006-07-13 03:35:19 UTC (rev 89)
+++ trunk/cinvoke/lib/arch/gcc_ppc_osx.c 2006-07-13 06:02:07 UTC (rev 90)
@@ -78,41 +78,119 @@
return CINV_SUCCESS;
}
-// XXX fix bug here where long long straddles registers and stack by
-// copying last integer register to stack if neccessary
+int isflt(cinv_type_t t) {
+ return (t == CINV_T_FLOAT) || (t == CINV_T_DOUBLE);
+}
+
const static int LEN = 4096;
char *arch_callback_stub(void *functionp, void *param,
short stacksize, cinv_callconv_t cc, cinv_type_t types[], int
numparams) {
+ short functionphi = ((int)functionp >> 16);
+ short functionplo = ((int)functionp & 0xFFFF);
+ short paramhi = ((int)param >> 16);
+ short paramlo = ((int)param & 0xFFFF);
+
+ int needscopy = 0, i, numints = 0;
+
+ for (i = 0; i < numparams; i++) {
+ if (isflt(types[i])) {
+ if (types[i] == CINV_T_FLOAT)
+ numints++;
+ else
+ numints += 2;
+ } else {
+ if (types[i] == CINV_T_EXTRALONG)
+ numints += 2;
+ else
+ numints ++;
+ }
+
+ if (numints == 9 && types[i] == CINV_T_EXTRALONG) {
+ needscopy = 1;
+ break;
+ }
+ }
+
char *ret = mmap(0, LEN, PROT_EXEC|PROT_READ|PROT_WRITE,
MAP_ANON|MAP_PRIVATE, -1, 0);
if (ret == MAP_FAILED)
return NULL;
- //void f() {
- // __asm("movq %%rdi, %%r11" ::: "%r11");
- // ((void (*)(void *))0xAAAAAAAAAAAAAAAA)(
- // (void *)0xBBBBBBBBBBBBBBBB);
- //}
- memcpy(ret,
- "\x55\x48\x89\xe5\x49\x89\xfb\x48\xb8"
- "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
- "\x48\xbf\xbb\xbb\xbb\xbb\xbb\xbb\xbb\xbb"
- "\xff\xd0\xc9\xc3",
- 31);
+ if (!needscopy) {
+ //void f() {
+ // __asm("mr r2, r3" ::: "r2");
+ // ((void (*)(void *))0xAAAABBBB)((void *)0xCCCCDDDD);
+ //}
+ memcpy(ret,
+ "\x7c\x08\x02\xa6\xbf\xc1\xff\xf8"
+ "\x90\x01\x00\x08\x94\x21\xff\xb0"
+ "\x7c\x3e\x0b\x78\x7c\x62\x1b\x78"
+ "\x3c\x00\xaa\xaa\x60\x00\xbb\xbb"
+ "\x3c\x60\xcc\xcc\x60\x63\xdd\xdd"
+ "\x7c\x0c\x03\x78\x7d\x89\x03\xa6"
+ "\x4e\x80\x04\x21\x80\x21\x00\x00"
+ "\x80\x01\x00\x08\x7c\x08\x03\xa6"
+ "\xbb\xc1\xff\xf8\x4e\x80\x00\x20",
+ 72);
- memcpy(ret + 9, &functionp, 8);
- memcpy(ret + 19, ¶m, 8);
+ memcpy(ret + 26, &functionphi, 2);
+ memcpy(ret + 30, &functionplo, 2);
+ memcpy(ret + 34, ¶mhi, 2);
+ memcpy(ret + 38, ¶mlo, 2);
+ } else {
+ short offset = 80 + ARCH_STACK_SKIPTOP + (7 * 4);
+ offset &= 0x7FF;
+
+ //void f2() {
+ // __asm("lwz r10 3822(r1)"); // 0xEEE
+ // __asm("mr r2, r3" ::: "r2");
+ // ((void (*)(void *))0xAAAABBBB)((void *)0xCCCCDDDD);
+ //}
+ memcpy(ret,
+ "\x7c\x08\x02\xa6\xbf\xc1\xff\xf8"
+ "\x90\x01\x00\x08\x94\x21\xff\xb0"
+ "\x7c\x3e\x0b\x78\x91\x41\x0e\xee"
+ "\x7c\x62\x1b\x78\x3c\x00\xaa\xaa"
+ "\x60\x00\xbb\xbb\x3c\x60\xcc\xcc"
+ "\x60\x63\xdd\xdd\x7c\x0c\x03\x78"
+ "\x7d\x89\x03\xa6\x4e\x80\x04\x21"
+ "\x80\x21\x00\x00\x80\x01\x00\x08"
+ "\x7c\x08\x03\xa6\xbb\xc1\xff\xf8"
+ "\x4e\x80\x00\x20",
+ 76);
+
+ memcpy(ret + 22, &offset, 2);
+ memcpy(ret + 30, &functionphi, 2);
+ memcpy(ret + 34, &functionplo, 2);
+ memcpy(ret + 38, ¶mhi, 2);
+ memcpy(ret + 42, ¶mlo, 2);
+ }
+ // the following block is a ppc oddity which is neccessary due to
+ // the instruction cache and data cache not being linked. in
+ // order to modify and execute code on ppc we have to flush it out
+ // of the data cache, then invalidate the instruction cache. this
+ // will ensure that when the code is executed it is running our fresh
+ // copy from memory. Much praise to H D Moore for pointing this out @
+ // http://www.uninformed.org/?v=1&a=1&t=pdf.
+ int *c = (int *)ret;
+ for (i = 0; i < 76; i++) {
+ __asm("lwz r2, %0" :: "m" (c) : "r2");
+ __asm("dcbf 0, r2");
+ __asm("sync");
+ __asm("icbi 0, r2");
+ __asm("isync");
+ c++;
+ }
+
+
return ret;
}
void arch_free_stub(char *stub) {
munmap(stub, LEN);
}
-int isflt(cinv_type_t t) {
- return (t == CINV_T_FLOAT) || (t == CINV_T_DOUBLE);
-}
int arch_is_register_parm(cinv_callconv_t callingconvention, int index,
int num_params, cinv_type_t types[]) {
int numints = 0, numflts = 0;
@@ -159,13 +237,13 @@
else if (type == CINV_T_INT)
*(toset[index]) = *(int *)p;
else if (type == CINV_T_LONG)
- *(toset[index]) = *(long *)p;
+ *(toset[index]) = (int)*(long *)p;
else if (type == CINV_T_EXTRALONG) {
- *(toset[index]) = ((*(long long *)p) >> 32);
+ *(toset[index]) = (int)((*(long long *)p) >> 32);
if (index < 7)
- *(toset[index + 1]) = ((*(long long *)p) & 0xFFFFFFFF);
+ *(toset[index + 1]) = (int)((*(long long *)p) &
0xFFFFFFFF);
} else
- *(toset[index]) = (long)*(void **)p;
+ *(toset[index]) = (int)*(void **)p;
}
void arch_set_register_parms(ArchRegParms *regparms,
@@ -223,9 +301,10 @@
else if (type == CINV_T_LONG)
*(long *)po = *toget[index];
else if (type == CINV_T_EXTRALONG) {
- *(long long *)po = ((long long)*toget[index]) << 32;
- if (index < 7)
+ if (index < 7) {
+ *(long long *)po = ((long long)*toget[index]) << 32;
*(long long *)po |= *toget[index + 1];
+ }
} else
*(void* *)po = (void *)*toget[index];
}
Modified: trunk/cinvoke/lib/arch/gcc_ppc_osx.h
===================================================================
--- trunk/cinvoke/lib/arch/gcc_ppc_osx.h 2006-07-13 03:35:19 UTC (rev 89)
+++ trunk/cinvoke/lib/arch/gcc_ppc_osx.h 2006-07-13 06:02:07 UTC (rev 90)
@@ -83,7 +83,7 @@
// macros
/////////////////////////////////////
#define ARCH_SAVE_REGPARMS(regparms) \
- __asm__("stw r3, %0\n \
+ __asm__("stw r2, %0\n \
stw r4, %1\n \
stw r5, %2\n \
stw r6, %3\n \
@@ -191,7 +191,7 @@
#define ARCH_SET_RETURN(archvalue) \
__asm__("lwz r3, %0\n \
lwz r4, %1\n \
- lfs f1, %2\n" :: \
+ lfd f1, %2\n" :: \
"m" ((archvalue).ivallo), \
"m" ((archvalue).ivalhi), \
"m" ((archvalue).dval) : \
@@ -219,15 +219,15 @@
__asm__("stw r1, %0" : "=m" (sp));
#define ARCH_GET_FRAME_PTR(fp) \
-;/* __asm__("movq %%rbp, %0" : "=m" (fp));*/
+ __asm__("stw r30, %0" : "=m" (fp));
-#define ARCH_CALLBACK_ARG_OFFSET (32)
+#define ARCH_CALLBACK_ARG_OFFSET (392)
#define ARCH_BIG_ENDIAN 1
#define ARCH_STACK_GROWS_DOWN 1
-#define ARCH_STACK_TOPSKIP 24
+#define ARCH_STACK_SKIPTOP 24
#define ARCH_REGPARMS_IN_STACKSIZE 1
Modified: trunk/cinvoke/lib/arch/gcc_x64_unix.h
===================================================================
--- trunk/cinvoke/lib/arch/gcc_x64_unix.h 2006-07-13 03:35:19 UTC (rev 89)
+++ trunk/cinvoke/lib/arch/gcc_x64_unix.h 2006-07-13 06:02:07 UTC (rev 90)
@@ -179,7 +179,7 @@
#define ARCH_STACK_GROWS_DOWN 1
-#define ARCH_STACK_TOPSKIP 0
+#define ARCH_STACK_SKIPTOP 0
#define ARCH_REGPARMS_IN_STACKSIZE 0
Modified: trunk/cinvoke/lib/arch/gcc_x86_unix.h
===================================================================
--- trunk/cinvoke/lib/arch/gcc_x86_unix.h 2006-07-13 03:35:19 UTC (rev 89)
+++ trunk/cinvoke/lib/arch/gcc_x86_unix.h 2006-07-13 06:02:07 UTC (rev 90)
@@ -99,7 +99,7 @@
#define ARCH_STACK_GROWS_DOWN 1
-#define ARCH_STACK_TOPSKIP 0
+#define ARCH_STACK_SKIPTOP 0
#define ARCH_REGPARMS_IN_STACKSIZE 0
Modified: trunk/cinvoke/lib/cinvoke.c
===================================================================
--- trunk/cinvoke/lib/cinvoke.c 2006-07-13 03:35:19 UTC (rev 89)
+++ trunk/cinvoke/lib/cinvoke.c 2006-07-13 06:02:07 UTC (rev 90)
@@ -456,22 +456,12 @@
return;
}
-#if ARCH_STACK_SKIPTOP
- numbytes += ARCH_STACK_SKIPTOP;
- #if ARCH_STACK_GROWS_DOWN
- frameptr += ARCH_STACK_SKIPTOP;
- #else
- frameptr -= ARCH_STACK_SKIPTOP;
- #endif
-#endif
-
#if ARCH_REGPARMS_IN_STACKSIZE
if (cb->prototype->regparms[i]) {
- numbytes += stacksize;
#if ARCH_STACK_GROWS_DOWN
- stackptr += stacksize;
+ frameptr += stacksize;
#else
- stackptr -= stacksize;
+ frameptr -= stacksize;
#endif
continue;
}
Modified: trunk/cinvoke/test/runtests.c
===================================================================
--- trunk/cinvoke/test/runtests.c 2006-07-13 03:35:19 UTC (rev 89)
+++ trunk/cinvoke/test/runtests.c 2006-07-13 06:02:07 UTC (rev 90)
@@ -255,7 +255,7 @@
printf("struct = %c %d %d %f %c\n", c1, i1, s1,
d1, c2);
return 0;
- }
+ }
}
printf("test8\n");
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cinvoke-svn] r90 - in trunk/cinvoke: lib lib/arch test,
will <=