1 /*
2 * test source file for assembling to Mach-O
3 * copied from cofftest.c, adapted to current limitations
4 * in Mach-O module
5 * build with (under OSX Tiger/Leopard, for example):
6 * yasm -f macho -m amd64 machotest64.asm
7 * gcc -m64 -o machotest64 machotest64.c machotest64.o
8 */
9
10 #include <stdio.h>
11
12 extern long lrotate(long, long);
13 extern void greet(void);
14 extern long readgreet(void);
15 extern char asmstr[];
16 extern void *selfptr;
17 extern void *textptr;
18 extern int integer, commvar;
19 extern char *getstr(void);
20
main(void)21 int main(void) {
22
23 printf("Testing lrotate: should get 0x0000000000400000, 0x0000000000000001\n");
24 printf("lrotate(0x00040000, 4 ) = 0x%016lx\n", lrotate(0x40000,4));
25 printf("lrotate(0x00040000, 46) = 0x%016lx\n", lrotate(0x40000,46));
26
27 printf("This string should read `hello, world': `%s'\n", asmstr);
28 {
29 long a,b;
30 a = (long)asmstr;
31 b = (long)getstr();
32 printf("The pointers %lx and %lx should be equal\n",a,b);
33 }
34 printf("This string should read `hello, world': `%s'\n", getstr());
35
36 printf("The integers here should be 1234, 1235 and 4321:\n");
37 integer = 1234;
38 commvar = 4321;
39 greet();
40 printf("The absolute addressing to the asm-local integer should yield in 1235:\n%ld\n",readgreet());
41
42 printf("These pointers should be equal: %p and %p\n",
43 &greet, textptr);
44
45 printf("So should these: %p and %p\n", selfptr, &selfptr);
46 }
47
48 /*
49 there is no support for dynamically linkable objects in current
50 mach-o module. Therefore put "printf" statement here and redirect
51 the asm call to druck()
52 */
druck(char * string,int a,int b,int c)53 void druck( char *string, int a, int b, int c )
54 {
55 printf(string,a,b,c);
56 }
57