call-rt-st.c revision 1.6
1#include <stdio.h> 2#include <stdlib.h> 3#include <string.h> 4 5#include "../lib/unbuffer_output.c" 6 7/************************************************************************** 8 * TESTS : 9 * function returning large structures, which go on the stack 10 * functions returning varied sized structs which go on in the registers. 11 ***************************************************************************/ 12 13 14/* A large structure (> 64 bits) used to test passing large structures as 15 * parameters 16 */ 17 18struct array_rep_info_t { 19 int next_index[10]; 20 int values[10]; 21 int head; 22}; 23 24/***************************************************************************** 25 * Small structures ( <= 64 bits). These are used to test passing small 26 * structures as parameters and test argument size promotion. 27 *****************************************************************************/ 28 29 /* 64 bits 30 */ 31struct small_rep_info_t { 32 int value; 33 int head; 34}; 35 36/* 6 bits : really fits in 8 bits and is promoted to 8 bits 37 */ 38struct bit_flags_char_t { 39 unsigned char alpha :1; 40 unsigned char beta :1; 41 unsigned char gamma :1; 42 unsigned char delta :1; 43 unsigned char epsilon :1; 44 unsigned char omega :1; 45}; 46 47/* 6 bits : really fits in 8 bits and is promoted to 16 bits 48 */ 49struct bit_flags_short_t { 50 unsigned short alpha :1; 51 unsigned short beta :1; 52 unsigned short gamma :1; 53 unsigned short delta :1; 54 unsigned short epsilon :1; 55 unsigned short omega :1; 56}; 57 58/* 6 bits : really fits in 8 bits and is promoted to 32 bits 59 */ 60struct bit_flags_t { 61 unsigned alpha :1; 62 unsigned beta :1; 63 unsigned gamma :1; 64 unsigned delta :1; 65 unsigned epsilon :1; 66 unsigned omega :1; 67}; 68 69/* 22 bits : really fits in 40 bits and is promoted to 64 bits 70 */ 71struct bit_flags_combo_t { 72 unsigned alpha :1; 73 unsigned beta :1; 74 char ch1; 75 unsigned gamma :1; 76 unsigned delta :1; 77 char ch2; 78 unsigned epsilon :1; 79 unsigned omega :1; 80}; 81 82/* 64 bits 83 */ 84struct one_double_t { 85 double double1; 86}; 87 88/* 64 bits 89 */ 90struct two_floats_t { 91 float float1; 92 float float2; 93}; 94 95 96/* 24 bits : promoted to 32 bits 97 */ 98struct three_char_t { 99 char ch1; 100 char ch2; 101 char ch3; 102}; 103 104/* 40 bits : promoted to 64 bits 105 */ 106struct five_char_t { 107 char ch1; 108 char ch2; 109 char ch3; 110 char ch4; 111 char ch5; 112}; 113 114/* 40 bits : promoted to 64 bits 115 */ 116struct int_char_combo_t { 117 int int1; 118 char ch1; 119}; 120 121 122/***************************************************************** 123 * LOOP_COUNT : 124 * A do nothing function. Used to provide a point at which calls can be made. 125 *****************************************************************/ 126void loop_count () { 127 128 int index; 129 130 for (index=0; index<4; index++); /* -break1- */ 131} 132 133/***************************************************************** 134 * INIT_BIT_FLAGS_CHAR : 135 * Initializes a bit_flags_char_t structure. Can call this function see 136 * the call command behavior when integer arguments do not fit into 137 * registers and must be placed on the stack. 138 * OUT struct bit_flags_char_t *bit_flags -- structure to be filled 139 * IN unsigned a -- 0 or 1 140 * IN unsigned b -- 0 or 1 141 * IN unsigned g -- 0 or 1 142 * IN unsigned d -- 0 or 1 143 * IN unsigned e -- 0 or 1 144 * IN unsigned o -- 0 or 1 145 *****************************************************************/ 146void init_bit_flags_char ( 147struct bit_flags_char_t *bit_flags, 148unsigned a, 149unsigned b, 150unsigned g, 151unsigned d, 152unsigned e, 153unsigned o) 154{ 155 156 bit_flags->alpha = a; 157 bit_flags->beta = b; 158 bit_flags->gamma = g; 159 bit_flags->delta = d; 160 bit_flags->epsilon = e; 161 bit_flags->omega = o; 162} 163 164/***************************************************************** 165 * INIT_BIT_FLAGS_SHORT : 166 * Initializes a bit_flags_short_t structure. Can call this function see 167 * the call command behavior when integer arguments do not fit into 168 * registers and must be placed on the stack. 169 * OUT struct bit_flags_short_t *bit_flags -- structure to be filled 170 * IN unsigned a -- 0 or 1 171 * IN unsigned b -- 0 or 1 172 * IN unsigned g -- 0 or 1 173 * IN unsigned d -- 0 or 1 174 * IN unsigned e -- 0 or 1 175 * IN unsigned o -- 0 or 1 176 *****************************************************************/ 177void init_bit_flags_short ( 178struct bit_flags_short_t *bit_flags, 179unsigned a, 180unsigned b, 181unsigned g, 182unsigned d, 183unsigned e, 184unsigned o) 185{ 186 187 bit_flags->alpha = a; 188 bit_flags->beta = b; 189 bit_flags->gamma = g; 190 bit_flags->delta = d; 191 bit_flags->epsilon = e; 192 bit_flags->omega = o; 193} 194 195/***************************************************************** 196 * INIT_BIT_FLAGS : 197 * Initializes a bit_flags_t structure. Can call this function see 198 * the call command behavior when integer arguments do not fit into 199 * registers and must be placed on the stack. 200 * OUT struct bit_flags_t *bit_flags -- structure to be filled 201 * IN unsigned a -- 0 or 1 202 * IN unsigned b -- 0 or 1 203 * IN unsigned g -- 0 or 1 204 * IN unsigned d -- 0 or 1 205 * IN unsigned e -- 0 or 1 206 * IN unsigned o -- 0 or 1 207 *****************************************************************/ 208void init_bit_flags ( 209struct bit_flags_t *bit_flags, 210unsigned a, 211unsigned b, 212unsigned g, 213unsigned d, 214unsigned e, 215unsigned o) 216{ 217 218 bit_flags->alpha = a; 219 bit_flags->beta = b; 220 bit_flags->gamma = g; 221 bit_flags->delta = d; 222 bit_flags->epsilon = e; 223 bit_flags->omega = o; 224} 225 226/***************************************************************** 227 * INIT_BIT_FLAGS_COMBO : 228 * Initializes a bit_flags_combo_t structure. Can call this function 229 * to see the call command behavior when integer and character arguments 230 * do not fit into registers and must be placed on the stack. 231 * OUT struct bit_flags_combo_t *bit_flags_combo -- structure to fill 232 * IN unsigned a -- 0 or 1 233 * IN unsigned b -- 0 or 1 234 * IN char ch1 235 * IN unsigned g -- 0 or 1 236 * IN unsigned d -- 0 or 1 237 * IN char ch2 238 * IN unsigned e -- 0 or 1 239 * IN unsigned o -- 0 or 1 240 *****************************************************************/ 241void init_bit_flags_combo ( 242struct bit_flags_combo_t *bit_flags_combo, 243unsigned a, 244unsigned b, 245char ch1, 246unsigned g, 247unsigned d, 248char ch2, 249unsigned e, 250unsigned o) 251{ 252 253 bit_flags_combo->alpha = a; 254 bit_flags_combo->beta = b; 255 bit_flags_combo->ch1 = ch1; 256 bit_flags_combo->gamma = g; 257 bit_flags_combo->delta = d; 258 bit_flags_combo->ch2 = ch2; 259 bit_flags_combo->epsilon = e; 260 bit_flags_combo->omega = o; 261} 262 263 264/***************************************************************** 265 * INIT_ONE_DOUBLE : 266 * OUT struct one_double_t *one_double -- structure to fill 267 * IN double init_val 268 *****************************************************************/ 269void init_one_double ( struct one_double_t *one_double, double init_val) 270{ 271 272 one_double->double1 = init_val; 273} 274 275/***************************************************************** 276 * INIT_TWO_FLOATS : 277 * OUT struct two_floats_t *two_floats -- structure to be filled 278 * IN float init_val1 279 * IN float init_val2 280 *****************************************************************/ 281void init_two_floats ( 282 struct two_floats_t *two_floats, 283 float init_val1, 284 float init_val2) 285{ 286 287 two_floats->float1 = init_val1; 288 two_floats->float2 = init_val2; 289} 290 291/***************************************************************** 292 * INIT_THREE_CHARS : 293 * OUT struct three_char_t *three_char -- structure to be filled 294 * IN char init_val1 295 * IN char init_val2 296 * IN char init_val3 297 *****************************************************************/ 298void init_three_chars ( 299struct three_char_t *three_char, 300char init_val1, 301char init_val2, 302char init_val3) 303{ 304 305 three_char->ch1 = init_val1; 306 three_char->ch2 = init_val2; 307 three_char->ch3 = init_val3; 308} 309 310/***************************************************************** 311 * INIT_FIVE_CHARS : 312 * OUT struct five_char_t *five_char -- structure to be filled 313 * IN char init_val1 314 * IN char init_val2 315 * IN char init_val3 316 * IN char init_val4 317 * IN char init_val5 318 *****************************************************************/ 319void init_five_chars ( 320struct five_char_t *five_char, 321char init_val1, 322char init_val2, 323char init_val3, 324char init_val4, 325char init_val5) 326{ 327 328 five_char->ch1 = init_val1; 329 five_char->ch2 = init_val2; 330 five_char->ch3 = init_val3; 331 five_char->ch4 = init_val4; 332 five_char->ch5 = init_val5; 333} 334 335/***************************************************************** 336 * INIT_INT_CHAR_COMBO : 337 * OUT struct int_char_combo_t *combo -- structure to be filled 338 * IN int init_val1 339 * IN char init_val2 340 *****************************************************************/ 341void init_int_char_combo ( 342struct int_char_combo_t *combo, 343int init_val1, 344char init_val2) 345{ 346 347 combo->int1 = init_val1; 348 combo->ch1 = init_val2; 349} 350 351/***************************************************************** 352 * INIT_STRUCT_REP : 353 * OUT struct small_rep_into_t *small_struct -- structure to be filled 354 * IN int seed 355 *****************************************************************/ 356void init_struct_rep( 357 struct small_rep_info_t *small_struct, 358 int seed) 359{ 360 361 small_struct->value = 2 + (seed*2); 362 small_struct->head = 0; 363} 364 365/***************************************************************** 366 * PRINT_BIT_FLAGS_CHAR : 367 * IN struct bit_flags_char_t bit_flags 368 ****************************************************************/ 369struct bit_flags_char_t print_bit_flags_char (struct bit_flags_char_t bit_flags) 370{ 371 372 if (bit_flags.alpha) printf("alpha\n"); 373 if (bit_flags.beta) printf("beta\n"); 374 if (bit_flags.gamma) printf("gamma\n"); 375 if (bit_flags.delta) printf("delta\n"); 376 if (bit_flags.epsilon) printf("epsilon\n"); 377 if (bit_flags.omega) printf("omega\n"); 378 return bit_flags; 379 380} 381 382/***************************************************************** 383 * PRINT_BIT_FLAGS_SHORT : 384 * IN struct bit_flags_short_t bit_flags 385 ****************************************************************/ 386struct bit_flags_short_t print_bit_flags_short (struct bit_flags_short_t bit_flags) 387{ 388 389 if (bit_flags.alpha) printf("alpha\n"); 390 if (bit_flags.beta) printf("beta\n"); 391 if (bit_flags.gamma) printf("gamma\n"); 392 if (bit_flags.delta) printf("delta\n"); 393 if (bit_flags.epsilon) printf("epsilon\n"); 394 if (bit_flags.omega) printf("omega\n"); 395 return bit_flags; 396 397} 398 399/***************************************************************** 400 * PRINT_BIT_FLAGS : 401 * IN struct bit_flags_t bit_flags 402 ****************************************************************/ 403struct bit_flags_t print_bit_flags (struct bit_flags_t bit_flags) 404{ 405 406 if (bit_flags.alpha) printf("alpha\n"); 407 if (bit_flags.beta) printf("beta\n"); 408 if (bit_flags.gamma) printf("gamma\n"); 409 if (bit_flags.delta) printf("delta\n"); 410 if (bit_flags.epsilon) printf("epsilon\n"); 411 if (bit_flags.omega) printf("omega\n"); 412 return bit_flags; 413 414} 415 416/***************************************************************** 417 * PRINT_BIT_FLAGS_COMBO : 418 * IN struct bit_flags_combo_t bit_flags_combo 419 ****************************************************************/ 420struct bit_flags_combo_t print_bit_flags_combo (struct bit_flags_combo_t bit_flags_combo) 421{ 422 423 if (bit_flags_combo.alpha) printf("alpha\n"); 424 if (bit_flags_combo.beta) printf("beta\n"); 425 if (bit_flags_combo.gamma) printf("gamma\n"); 426 if (bit_flags_combo.delta) printf("delta\n"); 427 if (bit_flags_combo.epsilon) printf("epsilon\n"); 428 if (bit_flags_combo.omega) printf("omega\n"); 429 printf("ch1: %c\tch2: %c\n", bit_flags_combo.ch1, bit_flags_combo.ch2); 430 return bit_flags_combo; 431 432} 433 434/***************************************************************** 435 * PRINT_ONE_DOUBLE : 436 * IN struct one_double_t one_double 437 ****************************************************************/ 438struct one_double_t print_one_double (struct one_double_t one_double) 439{ 440 441 printf("Contents of one_double_t: \n\n"); 442 printf("%f\n", one_double.double1); 443 return one_double; 444 445} 446 447/***************************************************************** 448 * PRINT_TWO_FLOATS : 449 * IN struct two_floats_t two_floats 450 ****************************************************************/ 451struct two_floats_t print_two_floats (struct two_floats_t two_floats) 452{ 453 454 printf("Contents of two_floats_t: \n\n"); 455 printf("%f\t%f\n", two_floats.float1, two_floats.float2); 456 return two_floats; 457 458} 459 460/***************************************************************** 461 * PRINT_THREE_CHARS : 462 * IN struct three_char_t three_char 463 ****************************************************************/ 464struct three_char_t print_three_chars (struct three_char_t three_char) 465{ 466 467 printf("Contents of three_char_t: \n\n"); 468 printf("%c\t%c\t%c\n", three_char.ch1, three_char.ch2, three_char.ch3); 469 return three_char; 470 471} 472 473/***************************************************************** 474 * PRINT_FIVE_CHARS : 475 * IN struct five_char_t five_char 476 ****************************************************************/ 477struct five_char_t print_five_chars (struct five_char_t five_char) 478{ 479 480 printf("Contents of five_char_t: \n\n"); 481 printf("%c\t%c\t%c\t%c\t%c\n", five_char.ch1, five_char.ch2, 482 five_char.ch3, five_char.ch4, 483 five_char.ch5); 484 return five_char; 485 486} 487 488/***************************************************************** 489 * PRINT_INT_CHAR_COMBO : 490 * IN struct int_char_combo_t int_char_combo 491 ****************************************************************/ 492struct int_char_combo_t print_int_char_combo (struct int_char_combo_t int_char_combo) 493{ 494 495 printf("Contents of int_char_combo_t: \n\n"); 496 printf("%d\t%c\n", int_char_combo.int1, int_char_combo.ch1); 497 return int_char_combo; 498 499} 500 501/***************************************************************** 502 * PRINT_STRUCT_REP : 503 ****************************************************************/ 504struct small_rep_info_t print_struct_rep(struct small_rep_info_t struct1) 505{ 506 507 printf("Contents of struct1: \n\n"); 508 printf("%10d%10d\n", struct1.value, struct1.head); 509 struct1.value =+5; 510 511 return struct1; 512 513 514} 515 516 517struct array_rep_info_t print_one_large_struct(struct array_rep_info_t linked_list1) 518{ 519 520 521 printf("%10d%10d\n", linked_list1.values[0], 522 linked_list1.next_index[0]); 523 524 return linked_list1; 525 526} 527 528/***************************************************************** 529 * INIT_ARRAY_REP : 530 * IN struct array_rep_info_t *linked_list 531 * IN int seed 532 ****************************************************************/ 533void init_array_rep(struct array_rep_info_t *linked_list, int seed) 534{ 535 536 int index; 537 538 for (index = 0; index < 10; index++) { 539 540 linked_list->values[index] = (2*index) + (seed*2); 541 linked_list->next_index[index] = index + 1; 542 } 543 linked_list->head = 0; 544} 545 546 547int main () { 548 549 /* variables for large structure testing 550 */ 551 int number = 10; 552 struct array_rep_info_t *list1; 553 554 /* variables for testing a small structures and a very long argument list 555 */ 556 struct small_rep_info_t *struct1; 557 struct bit_flags_char_t *cflags; 558 struct bit_flags_short_t *sflags; 559 struct bit_flags_t *flags; 560 struct bit_flags_combo_t *flags_combo; 561 struct three_char_t *three_char; 562 struct five_char_t *five_char; 563 struct int_char_combo_t *int_char_combo; 564 struct one_double_t *d1; 565 struct two_floats_t *f3; 566 567 gdb_unbuffer_output (); 568 569 /* Allocate space for large structures 570 */ 571 list1 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t)); 572 573 /* Initialize large structures 574 */ 575 init_array_rep(list1, 2); 576 577 /* Print large structures 578 */ 579 print_one_large_struct(*list1); 580 581 /* Allocate space for small structures 582 */ 583 struct1 = (struct small_rep_info_t *)malloc(sizeof(struct small_rep_info_t)); 584 cflags = (struct bit_flags_char_t *)malloc(sizeof(struct bit_flags_char_t)); 585 sflags = (struct bit_flags_short_t *)malloc(sizeof(struct bit_flags_short_t)); 586 flags = (struct bit_flags_t *)malloc(sizeof(struct bit_flags_t)); 587 flags_combo = (struct bit_flags_combo_t *)malloc(sizeof(struct bit_flags_combo_t)); 588 three_char = (struct three_char_t *)malloc(sizeof(struct three_char_t)); 589 five_char = (struct five_char_t *)malloc(sizeof(struct five_char_t)); 590 int_char_combo = (struct int_char_combo_t *)malloc(sizeof(struct int_char_combo_t)); 591 592 d1 = (struct one_double_t *)malloc(sizeof(struct one_double_t)); 593 f3 = (struct two_floats_t *)malloc(sizeof(struct two_floats_t)); 594 595 /* Initialize small structures 596 */ 597 init_one_double ( d1, 1.11111); 598 init_two_floats ( f3, -2.345, 1.0); 599 init_bit_flags_char(cflags, (unsigned)1, (unsigned)0, (unsigned)1, 600 (unsigned)0, (unsigned)1, (unsigned)0 ); 601 init_bit_flags_short(sflags, (unsigned)1, (unsigned)0, (unsigned)1, 602 (unsigned)0, (unsigned)1, (unsigned)0 ); 603 init_bit_flags(flags, (unsigned)1, (unsigned)0, (unsigned)1, 604 (unsigned)0, (unsigned)1, (unsigned)0 ); 605 init_bit_flags_combo(flags_combo, (unsigned)1, (unsigned)0, 'y', 606 (unsigned)1, (unsigned)0, 'n', 607 (unsigned)1, (unsigned)0 ); 608 init_three_chars(three_char, 'x', 'y', 'z'); 609 init_five_chars(five_char, 'h', 'e', 'l', 'l', 'o'); 610 init_int_char_combo(int_char_combo, 13, '!'); 611 init_struct_rep(struct1, 10); 612 613 614 /* Print small structures 615 */ 616 print_one_double(*d1); 617 print_two_floats(*f3); 618 print_bit_flags_char(*cflags); 619 print_bit_flags_short(*sflags); 620 print_bit_flags(*flags); 621 print_bit_flags_combo(*flags_combo); 622 print_three_chars(*three_char); 623 print_five_chars(*five_char); 624 print_int_char_combo(*int_char_combo); 625 print_struct_rep(*struct1); 626 627 loop_count(); /* -finish2- */ 628 629 return 0; /* -finish1- */ 630} 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646