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
|
/*
Nios-sim - one simple NIOSII simulator only for personal interest and fun.
Copyright (C) 2010 chysun2000@gmail.com
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 2 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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include "public.h"
static void print_help(void)
{
printf("\n----------------------------------------------\n");
printf(" HELP INFORMATION of NIOS2 Simulator\n");
printf("----------------------------------------------\n");
printf(" --image|-i image path name\n");
printf(" --srec|-s image format is SREC\n");
printf(" --mem_size|-m memory size of board\n");
printf(" --debug_mode|-d enter debug mode\n");
printf(" --base_addr|-b base address of memory\n");
printf(" --sys_map|-p load symbol table\n");
printf(" --cmdline|-c set kernel command line\n");
printf(" --initrd|-r set the address of initrd\n");
printf(" --fs_image|-f set the file system image\n");
printf(" --version|-v print the version information\n");
printf("----------------------------------------------\n");
printf(" For Example:\n");
printf(" nios-sim -s -i [srec file] -m [memsize] -d [set to debug mode] \n");
printf(" -b [base addr of mem] -p [symbol file]\n");
printf(" -c [kernel command line]\n");
printf("----------------------------------------------\n");
}
static const char * version = "Simulator for NIOSII(None-MMU) Version 0.1\n Copyright@chysun2000@gmail.com\n";
static void print_version(void)
{
printf("\n---------------------------------------------\n");
printf("%s", version);
printf("---------------------------------------------\n");
}
int main(int argc, char * argv[])
{
struct option long_opt [] = {
{"image",required_argument,NULL,'i'},
{"srec",no_argument, NULL, 's'},
{"mem_size",required_argument, NULL, 'm'},
{"debug_mode",no_argument, NULL, 'd'},
{"base_addr", required_argument, NULL, 'b'},
{"sys_map", required_argument, NULL, 'p'},
{"cmdline", required_argument, NULL, 'c'},
{"initrd", required_argument, NULL, 'r'},
{"fs_image",required_argument, NULL, 'f'},
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{0,0,0,0}
};
char * short_opt = "i:sm:db:p:c:vhr:f:";
int32_t c = 0;
while((c = getopt_long(argc, argv, short_opt, long_opt, NULL)) != -1){
switch(c){
case 'i':
set_image_pathname(optarg);
break;
case 's':
set_image_format(SREC_FMT);
break;
case 'm':
set_image_memsize(optarg);
break;
case 'd':
set_debug_mode(get_nios_cpu());
break;
case 'b':
set_image_base_addr(optarg);
break;
case 'p':
load_symbol_file(optarg);
break;
case 'c':
set_cmdline(optarg);
break;
case 'r':
set_initrd(optarg);
break;
case 'f':
set_fs_image(optarg);
break;
case 'v':
print_version();
return 0;
case 'h':
print_help();
return 0;
default:
break;
}
}
alloc_image_mem();
load_image();
print_image_info();
simulating();
return 0;
}
|