aboutsummaryrefslogtreecommitdiff
path: root/modules/objfmts/macho/tests/nasm64/machotest64.c
blob: c0f1e3c42eefd85a604ed65f2f42b2ecd6f9c9bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * test source file for assembling to Mach-O 
 * copied from cofftest.c, adapted to current limitations 
 * in Mach-O module
 * build with (under OSX Tiger/Leopard, for example):
 *    yasm -f macho -m amd64 machotest64.asm
 *    gcc -m64 -o machotest64 machotest64.c machotest64.o
 */

#include <stdio.h>

extern long lrotate(long, long);
extern void greet(void);
extern long readgreet(void);
extern char asmstr[];
extern void *selfptr;
extern void *textptr;
extern int integer, commvar;
extern char *getstr(void);

int main(void) {

    printf("Testing lrotate: should get 0x0000000000400000, 0x0000000000000001\n");
    printf("lrotate(0x00040000, 4 ) = 0x%016lx\n", lrotate(0x40000,4));
    printf("lrotate(0x00040000, 46) = 0x%016lx\n", lrotate(0x40000,46));

    printf("This string should read `hello, world': `%s'\n", asmstr);
    {
        long a,b;
        a = (long)asmstr;
        b = (long)getstr();
        printf("The pointers %lx and %lx should be equal\n",a,b);
    }
   printf("This string should read `hello, world': `%s'\n", getstr());

    printf("The integers here should be 1234, 1235 and 4321:\n");
    integer = 1234;
    commvar = 4321;
    greet();
    printf("The absolute addressing to the asm-local integer should yield in 1235:\n%ld\n",readgreet());

    printf("These pointers should be equal: %p and %p\n",
           &greet, textptr);

    printf("So should these: %p and %p\n", selfptr, &selfptr);
}

/*
  there is no support for dynamically linkable objects in current
  mach-o module. Therefore put "printf" statement here and redirect 
  the asm call to druck()
*/
void druck( char *string, int a, int b, int c )
{
 printf(string,a,b,c);
}