OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [testsuite/] [gdb.base/] [call-rt-st.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.