diff options
-rw-r--r-- | main.c | 51 | ||||
-rw-r--r-- | simulator.h | 40 |
2 files changed, 49 insertions, 42 deletions
@@ -30,10 +30,10 @@ #include "nios2sim-ng.h" #include "image.h" - -/* XXX: TMP */ -#include "instruction.h" #include "nios2.h" +#include "memory.h" +#include "device.h" +#include "simulator.h" #define PROGRAM_NAME "nios2sim-ng" #define PROGRAM_VERSION VERSION /* Set in Makefile */ @@ -45,6 +45,8 @@ bool verbose = false; static void usage_and_exit(const int status) { fprintf(stdout, "Usage: %s [OPTION...] IMAGE\n" + " -b BASE, --baseaddr=BASE\n" + " specify image base address\n" " -c CMDLINE, --cmdline=CMDLINE\n" " specify kernel command line\n" " -m MEMSIZE, --memsize=MEMSIZE\n" @@ -66,6 +68,7 @@ static void usage_and_exit(const int status) exit(status); } static const struct option long_opts[] = { + { "baseaddr", required_argument, NULL, 'b' }, { "cmdline", required_argument, NULL, 'c' }, { "memsize", required_argument, NULL, 'm' }, { "mmu", no_argument, NULL, 'M' }, @@ -116,21 +119,27 @@ int main(int argc, char *argv[]) char *image_path; char *cmdline = ""; int image_format = FORMAT_ELF; - uint8_t *mem_base; - size_t mem_size = DEFAULT_MEM_SIZE; struct nios2 cpu; + struct memory mem; int c; + mem.size = DEFAULT_MEM_SIZE; + mem.image_base = IMAGE_BASE_UNINITIALIZED; + while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { switch(c) { + case 'b': + mem.image_base = strtoul(optarg, NULL, 0); + break; case 'c': cmdline = optarg; break; case 'm': - mem_size = parse_mem_size(optarg); + mem.size = parse_mem_size(optarg); break; case 'M': cpu.has_mmu = true; + break; case 'e': image_format = FORMAT_ELF; break; @@ -162,21 +171,34 @@ int main(int argc, char *argv[]) image_path = argv[optind]; - mem_base = malloc(mem_size); - if (unlikely(mem_base == NULL)) { + if (mem.image_base != IMAGE_BASE_UNINITIALIZED + && mem.image_base >= mem.size) { + err("Image base address points beyond memory\n"); + exit(EXIT_FAILURE); + } + + mem.base = zalloc(mem.size); + if (unlikely(mem.base == NULL)) { err("Failed to allocate memory\n"); exit(EXIT_FAILURE); } - memset(mem_base, 0x00, mem_size); + /* Load the image to memory */ + if (image_load(image_path, image_format, &mem)) + exit(EXIT_FAILURE); - if (image_load(image_path, image_format, mem_base, mem_size)) + /* Initialize devices */ + if (device_init_all() < 0) exit(EXIT_FAILURE); + /* XXX: tmp */ + mem.image_base = 0x00500000; + vinfo(" Image file: %s\n", image_path); vinfo(" Image format: %s\n", image_format_str(image_format)); - vinfo(" Memory size: %zu %sbytes\n", size_scale(mem_size), size_postfix(mem_size)); - vinfo(" Memory base: %p\n", mem_base); + vinfo(" Memory size: %zu %sbytes\n", size_scale(mem.size), size_postfix(mem.size)); + vinfo(" Memory base: %p\n", mem.base); + vinfo(" Image base: 0x%08x\n", mem.image_base); vinfo(" Kernel command line: %s\n", cmdline); #if 0 @@ -185,9 +207,10 @@ int main(int argc, char *argv[]) printf("Set command line:%s\n", cmd_line); printf("Initrd: 0x%08x size:0x%08x\n",initrd_start, initrd_size); printf("rootfs: %s \n",fs_image); - - simulating(); #endif + cpu.mem = &mem; + simulator_run(&cpu); + exit(EXIT_SUCCESS); } diff --git a/simulator.h b/simulator.h index 4773fb6..deb609a 100644 --- a/simulator.h +++ b/simulator.h @@ -1,32 +1,16 @@ /* - Nios-sim - one simple NIOSII simulator only for personal interest and fun. - Copyright (C) 2010 chysun2000@gmail.com + * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch> + * + * This file is part of nios2sim-ng. + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file "COPYING" in the main directory of this archive + * for more details. + */ - 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. +#ifndef _SIMULATOR_H_ +#define _SIMULATOR_H_ - 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. +extern void simulator_run(struct nios2 *cpu); - 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. -*/ - -#ifndef __SIMULATOR_H__ -#define __SIMULATOR_H__ - -#include <stdio.h> -#include "public.h" - -struct debug_command { - char * short_cmd; - char * long_cmd; - char * desc; - int32_t code; -}; -#endif /* __SIMULATOR_H__*/ +#endif /* _SIMULATOR_H_*/ |