-
Notifications
You must be signed in to change notification settings - Fork 43
/
sim-config.c
1696 lines (1380 loc) · 46.6 KB
/
sim-config.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* sim-config.c -- Simulator configuration
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
Copyright (C) 2008 Embecosm Limited
Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
This file is part of OpenRISC 1000 Architectural Simulator.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>. */
/* This program is commented throughout in a fashion suitable for processing
with Doxygen. */
/* Simulator configuration. Eventually this one will be a lot bigger. Updated
to use argtable2 for argument parsing. */
/* Autoconf and/or portability configuration */
#include "config.h"
#include "port.h"
/* System includes */
#include <stdlib.h>
/* Package includes */
#include "sim-config.h"
#include "vapi.h"
#include "cuc.h"
#include "cpu-config.h"
#include "memory.h"
#include "dmmu.h"
#include "immu.h"
#include "dcache-model.h"
#include "icache-model.h"
#include "pic.h"
#include "pm.h"
#include "pcu.h"
#include "branch-predict.h"
#include "debug-unit.h"
#include "mc.h"
#include "16450.h"
#include "dma.h"
#include "eth.h"
#include "gpio.h"
#include "vga.h"
#include "fb.h"
#include "ps2kbd.h"
#include "atahost.h"
#include "generic.h"
#include "execute.h"
#include "spr-defs.h"
#include "debug.h"
#include "jtag.h"
#include "misc.h"
#include "argtable2.h"
#include "cfi_flash.h"
/*! A structure used to represent possible parameters in a section. */
struct config_param
{
char *name; /* param name */
enum param_t type; /* param type */
void (*func) (union param_val val, /* Setter function */
void *dat);
struct config_param *next; /* Next param in list */
}; /* struct config_param */
/*! Config file line count */
static int line_number;
/*! The global configuration data structure */
struct config config;
/*! The global runtime status data structure */
struct runtime runtime;
/*! Master list of sections it is possible to configure. */
static struct config_section *section_master_list = NULL;
/* -------------------------------------------------------------------------- */
/*!Register a parameter for a section
Add a new parameter to the list of parameters that may be set for a given
section.
@param[in] sec The section containing the parameter.
@param[in] param Name of the parameter
@param[in] type Type of the parameter
@param[in] param_cb Call back function to set this parameter. */
/* -------------------------------------------------------------------------- */
void
reg_config_param (struct config_section *sec,
const char *param,
enum param_t type,
void (*param_cb) (union param_val,
void *))
{
struct config_param *new = malloc (sizeof (struct config_param));
if (!new)
{
fprintf (stderr, "ERROR: Out-of-memory allocating parameter: exiting,\n");
exit (1);
}
if (!(new->name = strdup (param)))
{
fprintf (stderr, "ERROR: Out-of-memory allocating parameter name: "
"exiting,\n");
exit (1);
}
/* Set up the parameter */
new->func = param_cb;
new->type = type;
/* Insert on head of list */
new->next = sec->params;
sec->params = new;
} /* reg_config_param () */
/* -------------------------------------------------------------------------- */
/*!Register a new section.
Add a new section to the list of sections that may be found in a config
file.
@param[in] section The name of the new section.
@param[in] sec_start Function to call at start of section configuration
(or NULL if none)
@param[in] sec_end Function to call at end of section configuration
(or NULL if none). Returns pointer to an arbitrary
data structure.
@return A pointer to the section data structure for the new section. */
/* -------------------------------------------------------------------------- */
struct config_section *
reg_config_sec (const char *section,
void *(*sec_start) (void),
void (*sec_end) (void *))
{
struct config_section *new = malloc (sizeof (struct config_section));
if (!new)
{
fprintf (stderr, "ERROR: Out-of-memory allocating section: exiting,\n");
exit (1);
}
if (!(new->name = strdup (section)))
{
fprintf (stderr, "ERROR: Out-of-memory allocating section name: "
"exiting,\n");
exit (1);
}
/* Set up the section */
new->next = section_master_list;
new->sec_start = sec_start;
new->sec_end = sec_end;
new->params = NULL;
/* Insert the section */
section_master_list = new;
return new;
} /* reg_config_sec () */
/* -------------------------------------------------------------------------- */
/*!Look up a section
Given a section name, return the data structure describing that section.
@param[in] name The section to look for.
@return A pointer to the section config data structure, or NULL if the
section is not found */
/* -------------------------------------------------------------------------- */
static struct config_section *
lookup_section (char *name)
{
struct config_section *cur = NULL;
for (cur = section_master_list; NULL != cur; cur = cur->next)
{
if (strcmp (cur->name, name) == 0)
{
break;
}
}
return cur;
} /* lookup_section () */
/* -------------------------------------------------------------------------- */
/*!Look up a parameter for a section
Given a parameter name and a section data structure, return the data
structure describing that parameter
@param[in] name The parameter to look for.
@param[in] sec The section containing the parameter.
@return A pointer to the parameter config data structure, or NULL if the
parameter is not found */
/* -------------------------------------------------------------------------- */
static struct config_param *
lookup_param (char *name,
struct config_section *sec)
{
struct config_param *param = NULL;
for (param = sec->params; NULL != param; param = param->next)
{
if (strcmp (param->name, name) == 0)
{
break;
}
}
return param;
} /* lookup_param () */
/* -------------------------------------------------------------------------- */
/*!Set default configuration parameters for fixed components
These values are held in the global config variable. Parameter orders
match the order in the corresponding section registration function and
documentation.
Also set some starting values for runtime elements. */
/* -------------------------------------------------------------------------- */
void
init_defconfig ()
{
int set_bits; /* Temporaries for computing bit fields */
int way_bits;
memset (&config, 0, sizeof (config));
/* External linkage disabled here. */
config.ext.class_ptr = NULL;
config.ext.read_up = NULL;
config.ext.write_up = NULL;
/* Sim */
config.sim.is_library = 0; /* Not library operation */
config.sim.verbose = 0;
config.sim.debug = 0;
config.sim.profile = 0;
config.sim.prof_fn = strdup ("sim.profile");
config.sim.mprofile = 0;
config.sim.mprof_fn = strdup ("sim.mprofile");
config.sim.history = 0;
config.sim.exe_log = 0;
config.sim.exe_log_type = EXE_LOG_HARDWARE;
config.sim.exe_log_start = 0;
config.sim.exe_log_end = 0;
config.sim.exe_log_marker = 0;
config.sim.exe_log_fn = strdup ("executed.log");
config.sim.exe_bin_insn_log = 0;
config.sim.exe_bin_insn_log_fn = strdup ("exe-insn.bin");
config.sim.clkcycle_ps = 4000; /* 4000 for 4ns (250MHz) */
/* Debug */
config.debug.jtagcycle_ps = 40000; /* 40000 for 40ns (25MHz) */
/* VAPI */
config.vapi.enabled = 0;
config.vapi.server_port = 50000;
config.vapi.log_enabled = 0;
config.vapi.hide_device_id = 0;
config.vapi.vapi_fn = strdup ("vapi.log");
/* CUC */
config.cuc.calling_convention = 1;
config.cuc.enable_bursts = 1;
config.cuc.no_multicycle = 1;
config.cuc.memory_order = MO_STRONG;
config.cuc.timings_fn = strdup ("virtex.tim");
/* CPU */
cpu_state.sprs[SPR_VR] = 0;
cpu_state.sprs[SPR_UPR] = SPR_UPR_UP | SPR_UPR_TTP;
cpu_state.sprs[SPR_SR] = SPR_SR_FO | SPR_SR_SM;
#ifndef OR32_NODELAY
cpu_state.sprs[SPR_CPUCFGR] = SPR_CPUCFGR_OB32S;
#else
cpu_state.sprs[SPR_CPUCFGR] = SPR_CPUCFGR_OB32S | SPR_CPUCFGR_ND;
#endif
config.cpu.superscalar = 0;
config.cpu.hazards = 0;
config.cpu.dependstats = 0;
config.cpu.sbuf_len = 0;
config.cpu.hardfloat = 0;
/* Data cache (IC is set dynamically). Also set relevant SPR bits */
config.dc.enabled = 0;
config.dc.nsets = 1;
config.dc.nways = 1;
config.dc.blocksize = 1;
config.dc.ustates = 2;
config.dc.load_hitdelay = 2;
config.dc.load_missdelay = 2;
config.dc.store_hitdelay = 0;
config.dc.store_missdelay = 0;
if (config.dc.enabled)
{
cpu_state.sprs[SPR_UPR] |= SPR_UPR_DCP;
}
else
{
cpu_state.sprs[SPR_UPR] &= ~SPR_UPR_DCP;
}
set_bits = log2_int (config.dc.nsets);
cpu_state.sprs[SPR_DCCFGR] &= ~SPR_DCCFGR_NCS;
cpu_state.sprs[SPR_DCCFGR] |= set_bits << SPR_DCCFGR_NCS_OFF;
way_bits = log2_int (config.dc.nways);
cpu_state.sprs[SPR_DCCFGR] &= ~SPR_DCCFGR_NCW;
cpu_state.sprs[SPR_DCCFGR] |= way_bits << SPR_DCCFGR_NCW_OFF;
if (MIN_DC_BLOCK_SIZE == config.dc.blocksize)
{
cpu_state.sprs[SPR_DCCFGR] &= ~SPR_DCCFGR_CBS;
}
else
{
cpu_state.sprs[SPR_DCCFGR] |= SPR_DCCFGR_CBS;
}
/* Power management */
config.pm.enabled = 0;
if (config.pm.enabled)
{
cpu_state.sprs[SPR_UPR] |= SPR_UPR_PMP;
}
else
{
cpu_state.sprs[SPR_UPR] &= ~SPR_UPR_PMP;
}
/* Programmable Interrupt Controller */
config.pic.enabled = 0;
config.pic.edge_trigger = 1;
config.pic.use_nmi = 1;
if (config.pic.enabled)
{
cpu_state.sprs[SPR_UPR] |= SPR_UPR_PICP;
}
else
{
cpu_state.sprs[SPR_UPR] &= ~SPR_UPR_PICP;
}
/* Performance Counters Unit */
config.pcu.enabled = 0;
/* Branch Prediction */
config.bpb.enabled = 0;
config.bpb.btic = 0;
config.bpb.sbp_bnf_fwd = 0;
config.bpb.sbp_bf_fwd = 0;
config.bpb.missdelay = 0;
config.bpb.hitdelay = 0;
/* Debug */
config.debug.enabled = 0;
config.debug.rsp_enabled = 0;
config.debug.rsp_port = 51000;
config.debug.vapi_id = 0;
cpu_state.sprs[SPR_DCFGR] = SPR_DCFGR_WPCI |
MATCHPOINTS_TO_NDP (MAX_MATCHPOINTS);
if (config.debug.enabled)
{
cpu_state.sprs[SPR_UPR] |= SPR_UPR_DUP;
}
else
{
cpu_state.sprs[SPR_UPR] &= ~SPR_UPR_DUP;
}
/* Configure runtime */
memset (&runtime, 0, sizeof (runtime));
/* Sim */
runtime.sim.fexe_log = NULL;
runtime.sim.iprompt = 0;
runtime.sim.fprof = NULL;
runtime.sim.fmprof = NULL;
runtime.sim.fout = stdout;
/* Debug */
runtime.debug.instr = JI_UNDEFINED;
runtime.debug.mod_id = JM_UNDEFINED;
runtime.debug.write_defined_p = 0; /* No WRITE_COMMAND yet */
/* NPC state. Set to 1 when NPC is changed while the processor is stalled. */
cpu_state.npc_not_valid = 0;
/* VAPI */
runtime.vapi.vapi_file = NULL;
runtime.vapi.enabled = 0;
} /* init_defconfig() */
/* -------------------------------------------------------------------------- */
/*!Set a configuration parameter.
We have a string representing the value, and a data structure representing
the particular parameter. Break out the value and call the setter function
to set its value in the section.
The value text is guaranteed to have no leading or trailing whitespace.
@param[in] cur_section Spec of the section currently being configured.
@param[in] param Spec of the parameter we are setting.
@param[in] val_text The parameter value text */
/* -------------------------------------------------------------------------- */
static void
set_config_param (struct config_section *cur_section,
struct config_param *param,
char *val_text)
{
union param_val val;
/* Break out the different parameter types */
switch (param->type)
{
case PARAMT_NONE:
break;
case PARAMT_INT:
val.int_val = strtol (val_text, NULL, 0);
break;
case PARAMT_LONGLONG:
val.longlong_val = strtoll (val_text, NULL, 0);
break;
case PARAMT_ADDR:
val.addr_val = strtoul (val_text, NULL, 0);
break;
case PARAMT_WORD:
case PARAMT_STR:
/* Word and string are the same thing by now. */
val.str_val = val_text;
break;
}
/* Call the setter function */
param->func (val, cur_section->dat);
} /* set_config_param () */
/* -------------------------------------------------------------------------- */
/*!Scan the next word, skipping any preceding space.
A word is anything that is not white space, except where the white space is
within quotation marks. Return the number of newlines we have to skip.
@param[in] f The file handle to read from
@param[in] word A buffer in which to store the word.
@return The text of the next entity or NULL at end of file. Note strings
have their quotation marks removed. */
/* -------------------------------------------------------------------------- */
static char *
next_word (FILE *f,
char word[])
{
int c;
int i;
/* Skip the whitespace */
do
{
c = fgetc (f);
line_number += ('\n' == c) ? 1: 0;
}
while ((EOF != c) && isspace (c));
/* Get the word> Special treatment if it is a string. */
if ('"' == c)
{
/* We have a string. Skip the opening quote. */
c = fgetc (f);
for (i = 0; i < (STR_SIZE - 1); i++)
{
if ('"' == c)
{
c = fgetc (f); /* So ungetc works */
break; /* End of the string */
}
else if ('\n' == c)
{
line_number++;
}
else if (EOF == c)
{
fprintf (stderr, "ERROR: EOF in middle of string: exiting.\n");
exit (1);
}
word[i] = c;
c = fgetc (f);
}
/* Skip the closing quote */
c = fgetc (f);
}
else
{
/* We have a space delimited word */
for (i = 0; i < (STR_SIZE - 1); i++)
{
if ((EOF == c) || isspace (c))
{
break; /* End of the word */
}
word[i] = c;
c = fgetc (f);
}
}
word[i] = '\0'; /* Terminate the word */
if ((STR_SIZE - 1) == i)
{
word[10]= '\0';
fprintf (stderr,
"ERROR: Symbol beginning %s on line %d too long: exiting.\n",
word, line_number);
exit (1);
}
ungetc (c, f); /* Ready for next time */
return (0 == i) ? NULL : word;
} /* next_word () */
/* -------------------------------------------------------------------------- */
/*!Read the next lexeme from the a config file.
At this stage we are just breaking things out into space delimited
entities, stripping out comments.
@param[in] f The file handle to read from
@param[in] lexeme A buffer in which to store the lexeme.
@return The text of the next entity or NULL at end of file. */
/* -------------------------------------------------------------------------- */
static char *
next_lexeme (FILE *f,
char lexeme[])
{
if (NULL == next_word (f, lexeme))
{
return NULL;
}
/* Skip any comments */
while (0 ==strncmp (lexeme, "/*", 2))
{
/* Look for the closing '*' and '/'. */
char c0 = '\0';
char c1 = '\0';
while (('*' != c0) || ('/' != c1))
{
c0 = c1;
c1 = fgetc (f);
line_number += ('\n' == c1) ? 1 : 0;
/* We assume if we hit EOF we have a serious problem and die. */
if (feof (f))
{
fprintf (stderr, "ERROR: Comment reached EOF.\n");
exit (1);
}
}
/* Get the next lexeme */
if (NULL == next_word (f, lexeme))
{
return NULL;
}
}
return lexeme;
} /* next_lexeme () */
/* -------------------------------------------------------------------------- */
/*!Read configuration from a script file.
The syntax of script file is:
[section x
[param [=] value]+
end]*
Example:
section mc
enabled = 1
POC = 0x47892344
end
The config file is searched for first in the local directory, then in
${HOME}/.or1ksim, then (for backwards compatibility) in ${HOME}/.or1ksim.
If the file is not found, then a rude message is printed. The system will
just use default values.
@param[in] filename The configuration file to use. */
/* -------------------------------------------------------------------------- */
static void
read_script_file (const char *filename)
{
FILE *f;
char *home = getenv ("HOME");
char ctmp1[STR_SIZE];
char ctmp2[STR_SIZE];
char *dir;
/* Attempt to open the config file. If we fail, give up with a rude
message. */
sprintf (ctmp1, "%s/.or1ksim/%s", home, filename);
sprintf (ctmp2, "%s/.or1k/%s", home, filename);
if (NULL != (f = fopen (filename, "r")))
{
dir = ".";
}
else if (home && (NULL != (f = fopen (ctmp1, "r"))))
{
dir = ctmp1;
}
else if (home && (NULL != (f = fopen (ctmp2, "r"))))
{
dir = ctmp2;
}
else
{
fprintf (stderr, "Warning: Failed to open script file \"%s\". Ignored.\n",
filename);
return;
}
/* Log the config file we have just opened if required. */
if (config.sim.verbose)
{
PRINTF ("Reading script file from \"%s/%s\"...\n", dir, filename);
}
/* Process the config file. */
char lexeme[STR_SIZE]; /* Next entity from the input */
int in_section_p = 0; /* Are we processing a section */
struct config_section *cur_section = NULL; /* Section being processed */
line_number = 1;
while (NULL != next_lexeme (f, lexeme))
{
/* Get the next symbol. Four possibilities.
1. It's "section". Only if we are not currently in a section. Process
the start of a section.
2. It's "end". Only if we are currently in a section. Process the end
of a section.
3. Anything else while we are in a section. Assume it is a parameter
for the current section.
4. Anything else. An error.
*/
if (!in_section_p && (0 == strcmp (lexeme, "section")))
{
/* We have the start of a section */
if (NULL == next_lexeme (f, lexeme))
{
fprintf (stderr, "ERROR: %s/%s: Section name required at line "
"%d. Exiting\n", dir, filename, line_number);
exit (1);
}
cur_section = lookup_section (lexeme);
if (NULL != cur_section)
{
/* Valid section, run its startup code, with any data saved. */
cur_section->dat = NULL;
if (cur_section->sec_start)
{
cur_section->dat = cur_section->sec_start ();
}
in_section_p = 1; /* Now in a section */
}
else
{
/* Skip an unrecognized section with a warning. */
fprintf (stderr, "Warning: %s/%s: Unrecognized section: %s at "
"line %d: ignoring.\n", dir, filename, lexeme,
line_number);
/* just skip section */
while (NULL != next_lexeme (f, lexeme))
{
if (strcmp (lexeme, "end"))
{
break;
}
}
}
}
else if (in_section_p && strcmp (lexeme, "end") == 0)
{
/* End of section. Run the end of section code */
if (cur_section->sec_end)
{
cur_section->sec_end (cur_section->dat);
}
in_section_p = 0; /* Not in a section any more */
}
else if (in_section_p)
{
/* We're in a section, so this must be a parameter. */
struct config_param *param;
char *param_val;
param = lookup_param (lexeme, cur_section);
/* If we didn't recognize, then warn and skip to end of line/file) */
if (NULL == param)
{
fprintf (stderr, "Warning: %s/%s: Unrecognized parameter: %s at "
"line %d; ignored.\n", dir, filename, lexeme,
line_number);
/* Skip to end of line */
while (( '\n' != fgetc (f)) || feof (f))
;
line_number++;
continue; /* Start looking again */
}
/* Get the argument if one is expected. */
if (PARAMT_NONE != param->type)
{
param_val = next_lexeme (f, lexeme);
if (NULL == param_val)
{
fprintf (stderr, "Warning: %s/%s: No argument to parameter "
"%s at line %d; ignored.\n", dir, filename,
param->name, line_number);
/* Skip to end of line */
while (( '\n' != fgetc (f)) || feof (f))
;
line_number++;
continue; /* Start looking again */
}
/* We allow an optional '=' */
if (0 == strcmp (lexeme, "="))
{
param_val = next_lexeme (f, lexeme);
if (NULL == param_val)
{
fprintf (stderr, "Warning: %s/%s: No argument to "
"parameter %s at line %d; ignored.\n", dir,
filename, param->name, line_number);
/* Skip to end of line */
while (( '\n' != fgetc (f)) || feof (f))
;
line_number++;
continue; /* Start looking again */
}
}
}
else
{
/* No argument */
param_val = NULL;
}
/* Apply the parameter */
set_config_param (cur_section, param, param_val);
}
else
{
/* We're not in a section, so we don't know what we have */
fprintf (stderr, "Warning: %s/%s: Unrecognized config file contents "
" at line %d: ignored.\n", dir, filename, line_number);
/* Skip to end of line */
while (( '\n' != fgetc (f)) || feof (f))
;
line_number++;
continue; /* Start looking again */
}
}
fclose (f); /* All done */
} /* read_script_file () */
/*---------------------------------------------------------------------------*/
/*!Allocate a memory block
We can request a block of memory be allocated from the command line, rather
than in a configuration file. It will be allocated, starting at address
zero.
The memory size may be presented in any format recognized by strtol,
optionally followed by "G" or "g", "M" or "m" or "K" or "k" for giga, mega
and kilo bytes respectively, and leading to mutliplcation by 2^30, 2^20 and
2^10 respectively.
This is intended for simple use of the simulator in tool chain
verification, where the detailed memory behavior does not matter.
@param[in] size Memory size. */
/*---------------------------------------------------------------------------*/
static void
alloc_memory_block (const char *size)
{
/* Sort out the memory size. */
unsigned long int multiplier;
int last_ch = strlen (size) - 1;
switch (size[last_ch])
{
case 'G': case 'g': multiplier = 0x40000000UL; break;
case 'M': case 'm': multiplier = 0x100000UL; break;
case 'K': case 'k': multiplier = 0x400UL; break;
default: multiplier = 0x1UL; break;
}
unsigned long int mem_size = strtoul (size, NULL, 0) * multiplier;
if (0 == mem_size)
{
fprintf (stderr, "Warning: Memory size %s not recognized: ignored.\n",
size);
return;
}
if (mem_size > 0xffffffff)
{
fprintf (stderr, "Warning: Memory size %s too large: ignored.\n",
size);
return;
}
/* Turn the memory size back into a decimal string and allocate it */
char str_size[32];
sprintf (str_size, "%lu\n", mem_size);
struct config_section *sec = lookup_section ("memory");
sec->dat = sec->sec_start ();
set_config_param (sec, lookup_param ("name", sec), "Default RAM");
set_config_param (sec, lookup_param ("type", sec), "unknown");
set_config_param (sec, lookup_param ("baseaddr", sec), "0");
set_config_param (sec, lookup_param ("size", sec), str_size);
sec->sec_end (sec->dat);
if (config.sim.verbose)
{
PRINTF ("Memory block of 0x%lx bytes allocated\n", mem_size);
}
} /* alloc_memory_block () */
/*---------------------------------------------------------------------------*/
/*! Parse the arguments for the standalone simulator
Updated by Jeremy Bennett to use argtable2.
@param[in] argc Number of command args
@param[in] argv Vector of the command args
@return 0 on success, 1 on failure */
/*---------------------------------------------------------------------------*/
int
parse_args (int argc, char *argv[])
{
struct arg_lit *vercop;
struct arg_lit *help;
struct arg_file *cfg_file;
struct arg_lit *nosrv;
struct arg_int *srv;
struct arg_str *mem;
struct arg_str *dbg;
struct arg_lit *command;
struct arg_lit *quiet;
struct arg_lit *verbose;
struct arg_lit *trace;
struct arg_lit *trace_phy;
struct arg_lit *trace_virt;
struct arg_lit *report_mem_errs;
struct arg_lit *strict_npc;
struct arg_lit *profile;
struct arg_lit *mprofile;
struct arg_file *load_file;
struct arg_end *end;
/* Specify each argument, with fall back values */
vercop = arg_lit0 ("v", "version", "version and copyright notice");
help = arg_lit0 ("h", "help", "print this help message");
cfg_file = arg_file0 ("f", "file", "<file>",
"config file (default \"sim.cfg\")");
cfg_file->filename[0] = "sim.cfg";
nosrv = arg_lit0 (NULL, "nosrv", "do not launch debug server");
srv = arg_int0 (NULL, "srv", "<n>",
"launch debug server on port (default random)");
srv->ival[0] = random () % (65536 - 49152) + 49152;
srv->hdr.flag |= ARG_HASOPTVALUE;
mem = arg_str0 ("m", "memory", "<n>", "add memory block of <n> bytes");
dbg = arg_str0 ("d", "debug-config", "<str>", "Debug config string");
command = arg_lit0 ("i", "interactive", "launch interactive prompt");
quiet = arg_lit0 ("q", "quiet", "minimal message output");
verbose = arg_lit0 ("V", "verbose", "verbose message output");
trace = arg_lit0 ("t", "trace", "trace each instruction");
trace_phy = arg_lit0 (NULL, "trace-physical",
"show physical instruction address when tracing");
trace_virt = arg_lit0 (NULL, "trace-virtual",
"show virtual instruction address when tracing");
report_mem_errs = arg_lit0 (NULL, "report-memory-errors",
"Report out of memory accesses");
strict_npc = arg_lit0 (NULL, "strict-npc", "setting NPC flushes pipeline");
profile = arg_lit0 (NULL, "enable-profile", "enable profiling");
mprofile = arg_lit0 (NULL, "enable-mprofile", "enable memory profiling");
load_file = arg_file0 (NULL, NULL, "<file>", "OR32 executable");
end = arg_end (20);
/* The argument table */
void *argtab[] = {
vercop,
help,
cfg_file,
nosrv,
srv,
mem,