1*702941cdSRichard Lowe /* 2*702941cdSRichard Lowe * This file and its contents are supplied under the terms of the 3*702941cdSRichard Lowe * Common Development and Distribution License ("CDDL"), version 1.0. 4*702941cdSRichard Lowe * You may only use this file in accordance with the terms of version 5*702941cdSRichard Lowe * 1.0 of the CDDL. 6*702941cdSRichard Lowe * 7*702941cdSRichard Lowe * A full copy of the text of the CDDL should have accompanied this 8*702941cdSRichard Lowe * source. A copy of the CDDL is also available via the Internet at 9*702941cdSRichard Lowe * http://www.illumos.org/license/CDDL. 10*702941cdSRichard Lowe */ 11*702941cdSRichard Lowe 12*702941cdSRichard Lowe /* 13*702941cdSRichard Lowe * Copyright 2012, Richard Lowe. 14*702941cdSRichard Lowe */ 15*702941cdSRichard Lowe 16*702941cdSRichard Lowe #include <stdio.h> 17*702941cdSRichard Lowe #include <sys/types.h> 18*702941cdSRichard Lowe #include <saveargs.h> 19*702941cdSRichard Lowe 20*702941cdSRichard Lowe #define DEF_TEST(name) \ 21*702941cdSRichard Lowe extern uint8_t name[]; \ 22*702941cdSRichard Lowe extern int name##_end 23*702941cdSRichard Lowe 24*702941cdSRichard Lowe #define SIZE_OF(name) ((caddr_t)&name##_end - (caddr_t)&name) 25*702941cdSRichard Lowe 26*702941cdSRichard Lowe #define TEST_GOOD(name, argc) \ 27*702941cdSRichard Lowe if (saveargs_has_args(name, SIZE_OF(name), argc, 0) == \ 28*702941cdSRichard Lowe SAVEARGS_TRAD_ARGS) \ 29*702941cdSRichard Lowe printf("Pass: %s\n", #name); \ 30*702941cdSRichard Lowe else \ 31*702941cdSRichard Lowe printf("FAIL: %s\n", #name); 32*702941cdSRichard Lowe 33*702941cdSRichard Lowe #define TEST_GOOD_STRUCT(name, argc) \ 34*702941cdSRichard Lowe if (saveargs_has_args(name, SIZE_OF(name), argc, 1) == \ 35*702941cdSRichard Lowe SAVEARGS_STRUCT_ARGS) \ 36*702941cdSRichard Lowe printf("Pass: %s\n", #name); \ 37*702941cdSRichard Lowe else \ 38*702941cdSRichard Lowe printf("FAIL: %s\n", #name); 39*702941cdSRichard Lowe 40*702941cdSRichard Lowe /* 41*702941cdSRichard Lowe * GCC deals with structures differently, so TRAD args is actually correct for 42*702941cdSRichard Lowe * this 43*702941cdSRichard Lowe */ 44*702941cdSRichard Lowe #define TEST_GOOD_GSTRUCT(name, argc) \ 45*702941cdSRichard Lowe if (saveargs_has_args(name, SIZE_OF(name), argc, 1) == \ 46*702941cdSRichard Lowe SAVEARGS_TRAD_ARGS) \ 47*702941cdSRichard Lowe printf("Pass: %s\n", #name); \ 48*702941cdSRichard Lowe else \ 49*702941cdSRichard Lowe printf("FAIL: %s\n", #name); 50*702941cdSRichard Lowe 51*702941cdSRichard Lowe #define TEST_BAD(name, argc) \ 52*702941cdSRichard Lowe if (saveargs_has_args(name, SIZE_OF(name), argc, 0) == \ 53*702941cdSRichard Lowe SAVEARGS_NO_ARGS) \ 54*702941cdSRichard Lowe printf("Pass: %s\n", #name); \ 55*702941cdSRichard Lowe else \ 56*702941cdSRichard Lowe printf("FAIL: %s\n", #name); 57*702941cdSRichard Lowe 58*702941cdSRichard Lowe #define TEST_BAD_STRUCT(name, argc) \ 59*702941cdSRichard Lowe if (saveargs_has_args(name, SIZE_OF(name), argc, 1) == \ 60*702941cdSRichard Lowe SAVEARGS_NO_ARGS) \ 61*702941cdSRichard Lowe printf("Pass: %s\n", #name); \ 62*702941cdSRichard Lowe else \ 63*702941cdSRichard Lowe printf("FAIL: %s\n", #name); 64*702941cdSRichard Lowe 65*702941cdSRichard Lowe #define TEST_BAD_GSTRUCT(name, argc) \ 66*702941cdSRichard Lowe if (saveargs_has_args(name, SIZE_OF(name), argc, 1) == \ 67*702941cdSRichard Lowe SAVEARGS_NO_ARGS) \ 68*702941cdSRichard Lowe printf("Pass: %s\n", #name); \ 69*702941cdSRichard Lowe else \ 70*702941cdSRichard Lowe printf("FAIL: %s\n", #name); 71*702941cdSRichard Lowe 72*702941cdSRichard Lowe DEF_TEST(gcc_mov_align); 73*702941cdSRichard Lowe DEF_TEST(gcc_mov_basic); 74*702941cdSRichard Lowe DEF_TEST(gcc_mov_noorder); 75*702941cdSRichard Lowe DEF_TEST(gcc_mov_struct_noorder); 76*702941cdSRichard Lowe DEF_TEST(gcc_mov_big_struct_ret); 77*702941cdSRichard Lowe DEF_TEST(gcc_mov_big_struct_ret_and_spill); 78*702941cdSRichard Lowe DEF_TEST(gcc_mov_small_struct_ret); 79*702941cdSRichard Lowe DEF_TEST(gcc_mov_small_struct_ret_and_spill); 80*702941cdSRichard Lowe DEF_TEST(gcc_mov_stack_spill); 81*702941cdSRichard Lowe 82*702941cdSRichard Lowe DEF_TEST(gcc_push_align); 83*702941cdSRichard Lowe DEF_TEST(gcc_push_basic); 84*702941cdSRichard Lowe DEF_TEST(gcc_push_noorder); 85*702941cdSRichard Lowe DEF_TEST(gcc_push_struct_noorder); 86*702941cdSRichard Lowe DEF_TEST(gcc_push_big_struct_ret); 87*702941cdSRichard Lowe DEF_TEST(gcc_push_big_struct_ret_and_spill); 88*702941cdSRichard Lowe DEF_TEST(gcc_push_small_struct_ret); 89*702941cdSRichard Lowe DEF_TEST(gcc_push_small_struct_ret_and_spill); 90*702941cdSRichard Lowe DEF_TEST(gcc_push_stack_spill); 91*702941cdSRichard Lowe 92*702941cdSRichard Lowe DEF_TEST(ss_mov_align); 93*702941cdSRichard Lowe DEF_TEST(ss_mov_basic); 94*702941cdSRichard Lowe DEF_TEST(ss_mov_big_struct_ret); 95*702941cdSRichard Lowe DEF_TEST(ss_mov_big_struct_ret_and_spill); 96*702941cdSRichard Lowe DEF_TEST(ss_mov_small_struct_ret); 97*702941cdSRichard Lowe DEF_TEST(ss_mov_small_struct_ret_and_spill); 98*702941cdSRichard Lowe DEF_TEST(ss_mov_stack_spill); 99*702941cdSRichard Lowe 100*702941cdSRichard Lowe DEF_TEST(dtrace_instrumented); 101*702941cdSRichard Lowe DEF_TEST(kmem_alloc); 102*702941cdSRichard Lowe DEF_TEST(uts_kill); 103*702941cdSRichard Lowe DEF_TEST(av1394_ic_bitreverse); 104*702941cdSRichard Lowe 105*702941cdSRichard Lowe DEF_TEST(small_struct_ret_w_float); 106*702941cdSRichard Lowe DEF_TEST(big_struct_ret_w_float); 107*702941cdSRichard Lowe 108*702941cdSRichard Lowe DEF_TEST(interleaved_argument_saves); 109*702941cdSRichard Lowe DEF_TEST(jmp_table); 110*702941cdSRichard Lowe 111*702941cdSRichard Lowe /* 112*702941cdSRichard Lowe * Functions which should not match 113*702941cdSRichard Lowe * 114*702941cdSRichard Lowe * no_fp -- valid save-args sequence with no saved FP 115*702941cdSRichard Lowe * big_struct_arg_by_value -- function with big struct passed by value 116*702941cdSRichard Lowe * small_struct_arg_by_value -- function with small struct passed by value 117*702941cdSRichard Lowe */ 118*702941cdSRichard Lowe DEF_TEST(no_fp); 119*702941cdSRichard Lowe DEF_TEST(big_struct_arg_by_value); 120*702941cdSRichard Lowe DEF_TEST(small_struct_arg_by_value); 121*702941cdSRichard Lowe 122*702941cdSRichard Lowe int 123*702941cdSRichard Lowe main(int argc, char **argv) 124*702941cdSRichard Lowe { 125*702941cdSRichard Lowe TEST_GOOD(kmem_alloc, 2); 126*702941cdSRichard Lowe TEST_GOOD(uts_kill, 2); 127*702941cdSRichard Lowe TEST_GOOD(av1394_ic_bitreverse, 1); 128*702941cdSRichard Lowe TEST_GOOD(dtrace_instrumented, 4); 129*702941cdSRichard Lowe TEST_GOOD_GSTRUCT(big_struct_ret_w_float, 1); 130*702941cdSRichard Lowe TEST_BAD(no_fp, 5); 131*702941cdSRichard Lowe 132*702941cdSRichard Lowe TEST_GOOD(gcc_mov_align, 5); 133*702941cdSRichard Lowe TEST_GOOD(gcc_push_align, 5); 134*702941cdSRichard Lowe TEST_GOOD(ss_mov_align, 5); 135*702941cdSRichard Lowe 136*702941cdSRichard Lowe TEST_GOOD(gcc_mov_basic, 4); 137*702941cdSRichard Lowe TEST_GOOD(gcc_push_basic, 4); 138*702941cdSRichard Lowe TEST_GOOD(ss_mov_basic, 4); 139*702941cdSRichard Lowe 140*702941cdSRichard Lowe TEST_GOOD(gcc_mov_noorder, 4); 141*702941cdSRichard Lowe TEST_GOOD(gcc_push_noorder, 4); 142*702941cdSRichard Lowe 143*702941cdSRichard Lowe TEST_GOOD_GSTRUCT(gcc_mov_big_struct_ret, 4); 144*702941cdSRichard Lowe TEST_GOOD_GSTRUCT(gcc_push_big_struct_ret, 4); 145*702941cdSRichard Lowe TEST_GOOD_STRUCT(ss_mov_big_struct_ret, 4); 146*702941cdSRichard Lowe 147*702941cdSRichard Lowe TEST_GOOD_GSTRUCT(gcc_mov_struct_noorder, 4); 148*702941cdSRichard Lowe TEST_GOOD_GSTRUCT(gcc_push_struct_noorder, 4); 149*702941cdSRichard Lowe 150*702941cdSRichard Lowe TEST_GOOD_GSTRUCT(gcc_mov_big_struct_ret_and_spill, 8); 151*702941cdSRichard Lowe TEST_GOOD_GSTRUCT(gcc_push_big_struct_ret_and_spill, 8); 152*702941cdSRichard Lowe TEST_GOOD_STRUCT(ss_mov_big_struct_ret_and_spill, 8); 153*702941cdSRichard Lowe 154*702941cdSRichard Lowe TEST_GOOD(gcc_mov_small_struct_ret, 4); 155*702941cdSRichard Lowe TEST_GOOD(gcc_push_small_struct_ret, 4); 156*702941cdSRichard Lowe TEST_GOOD(ss_mov_small_struct_ret, 4); 157*702941cdSRichard Lowe 158*702941cdSRichard Lowe TEST_GOOD(gcc_mov_small_struct_ret_and_spill, 8); 159*702941cdSRichard Lowe TEST_GOOD(gcc_push_small_struct_ret_and_spill, 8); 160*702941cdSRichard Lowe TEST_GOOD(ss_mov_small_struct_ret_and_spill, 8); 161*702941cdSRichard Lowe 162*702941cdSRichard Lowe TEST_GOOD(gcc_mov_stack_spill, 8); 163*702941cdSRichard Lowe TEST_GOOD(gcc_push_stack_spill, 8); 164*702941cdSRichard Lowe TEST_GOOD(ss_mov_stack_spill, 8); 165*702941cdSRichard Lowe 166*702941cdSRichard Lowe TEST_BAD(big_struct_arg_by_value, 2); 167*702941cdSRichard Lowe TEST_BAD(small_struct_arg_by_value, 2); 168*702941cdSRichard Lowe 169*702941cdSRichard Lowe TEST_BAD(small_struct_ret_w_float, 1); 170*702941cdSRichard Lowe 171*702941cdSRichard Lowe TEST_GOOD(interleaved_argument_saves, 4); 172*702941cdSRichard Lowe TEST_BAD(jmp_table, 1); 173*702941cdSRichard Lowe 174*702941cdSRichard Lowe return (0); 175*702941cdSRichard Lowe } 176