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
57
58
59
60
61
62
63
64
65
66
67
68
|
#include <stdio.h>
#include <string.h>
#include <libmcpu.h>
#include "../utils/mcpu-asm.h"
#define CHECK(c,m) do{if(!(c)){fprintf(stderr,"FAIL: %s\n",m);return 1;}}while(0)
static const char src[]=
".text\n"
" ADJSP -16\n"
" LEASP r64@0x00000, 0\n"
" LDI r64@0x00100, 11\n"
" LDI r64@0x00108, 22\n"
" ADJSP -32\n"
" STSP 0, r64@0x00000\n"
" STSP 8, r128@0x00100\n"
" CALL copy_pair\n"
" ADJSP 32\n"
" LDSP r128@0x00200, 0\n"
" IADD r64@0x00210, r64@0x00200, r64@0x00208\n"
" LEASP r64@0x00008, 0\n"
" ADJSP -16\n"
" STSP 0, r64@0x00008\n"
" CALL first_field\n"
" ADJSP 16\n"
" ADJSP 16\n"
" HALT\n"
"copy_pair:\n"
" LDSP r64@0x00300, 8\n"
" LDSP r128@0x00310, 16\n"
" STOREP r64@0x00300, r128@0x00310\n"
" RET\n"
"first_field:\n"
" LDSP r64@0x00400, 8\n"
" LOADP r64@0x7fff8, r64@0x00400\n"
" RET\n";
static int
eq64( unsigned address, const char *text )
{
mpu_int64_t x;
iatoi( ( mpu_int * ) x, (__mpu_char8_t *)text, NB_I64 );
return( !memcmp( __cpu_reg_ptr( 64, address ), x, NB_I64 ) );
}
int
main( void )
{
cpu_asm_image im;
char err[256];
__cpu_init();
CHECK( cpu_assemble_text( src, &im, err, sizeof( err ) ) == 0, err );
CHECK( __cpu_program_set( im.code, im.code_size ) == 0, "program set" );
CHECK( __cpu_stack_alloc( 512 ) == 0, "stack alloc" );
CHECK( __cpu_run() == CPU_EXEC_SUCCESS, "aggregate ABI program run" );
CHECK( __cpu_sp == 512, "caller released local object and all arguments" );
CHECK( eq64( 0x00200, "11" ), "aggregate return first field" );
CHECK( eq64( 0x00208, "22" ), "aggregate return second field" );
CHECK( eq64( 0x00210, "33" ), "aggregate return object preserved" );
CHECK( eq64( 0x7fff8, "11" ), "pointer argument and scalar return" );
cpu_asm_image_free( &im );
__cpu_free_context();
puts( "libcpu aggregate CALL ABI regression: PASS" );
return( 0 );
}
|