1995-09-09 01:56:38 +02:00
|
|
|
/* This file is part of the program psim.
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
|
1995-09-09 01:56:38 +02:00
|
|
|
|
|
|
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _PSIM_C_
|
|
|
|
#define _PSIM_C_
|
|
|
|
|
1996-07-23 17:42:42 +02:00
|
|
|
#include "cpu.h" /* includes psim.h */
|
|
|
|
#include "idecode.h"
|
|
|
|
#include "options.h"
|
|
|
|
|
1997-01-27 22:34:50 +01:00
|
|
|
#include "tree.h"
|
1996-02-21 17:47:06 +01:00
|
|
|
|
1995-11-02 15:27:18 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
1995-11-02 21:21:35 +01:00
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
1995-09-09 01:56:38 +02:00
|
|
|
#include <setjmp.h>
|
|
|
|
|
1995-11-02 21:21:35 +01:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
1996-07-23 17:42:42 +02:00
|
|
|
|
1995-11-02 15:27:18 +01:00
|
|
|
#include "bfd.h"
|
|
|
|
|
|
|
|
|
1995-09-09 01:56:38 +02:00
|
|
|
/* system structure, actual size of processor array determined at
|
|
|
|
runtime */
|
|
|
|
|
|
|
|
struct _psim {
|
|
|
|
event_queue *events;
|
1996-02-21 17:47:06 +01:00
|
|
|
device *devices;
|
1995-11-02 15:27:18 +01:00
|
|
|
mon *monitor;
|
1996-02-21 17:47:06 +01:00
|
|
|
os_emul *os_emulation;
|
1995-09-09 01:56:38 +02:00
|
|
|
core *memory;
|
1996-02-21 17:47:06 +01:00
|
|
|
|
1995-09-09 01:56:38 +02:00
|
|
|
/* escape routine for inner functions */
|
|
|
|
void *path_to_halt;
|
|
|
|
void *path_to_restart;
|
1996-02-21 17:47:06 +01:00
|
|
|
|
1995-09-09 01:56:38 +02:00
|
|
|
/* status from last halt */
|
|
|
|
psim_status halt_status;
|
1996-02-21 17:47:06 +01:00
|
|
|
|
|
|
|
/* the processors proper */
|
1995-09-09 01:56:38 +02:00
|
|
|
int nr_cpus;
|
|
|
|
int last_cpu; /* CPU that last (tried to) execute an instruction */
|
1995-11-02 15:27:18 +01:00
|
|
|
cpu *processors[MAX_NR_PROCESSORS];
|
1995-09-09 01:56:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int current_target_byte_order;
|
|
|
|
int current_host_byte_order;
|
|
|
|
int current_environment;
|
|
|
|
int current_alignment;
|
1995-11-02 15:27:18 +01:00
|
|
|
int current_floating_point;
|
1995-11-28 19:47:07 +01:00
|
|
|
int current_model_issue = MODEL_ISSUE_IGNORE;
|
1997-01-27 22:34:50 +01:00
|
|
|
int current_stdio = DO_USE_STDIO;
|
1995-11-12 15:20:39 +01:00
|
|
|
model_enum current_model = WITH_DEFAULT_MODEL;
|
1995-11-02 15:27:18 +01:00
|
|
|
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
/* create the device tree */
|
1995-11-02 15:27:18 +01:00
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(device *)
|
|
|
|
psim_tree(void)
|
1995-11-02 15:27:18 +01:00
|
|
|
{
|
1997-01-27 22:34:50 +01:00
|
|
|
device *root = tree_parse(NULL, "core");
|
|
|
|
tree_parse(root, "/aliases");
|
|
|
|
tree_parse(root, "/options");
|
|
|
|
tree_parse(root, "/chosen");
|
|
|
|
tree_parse(root, "/packages");
|
|
|
|
tree_parse(root, "/cpus");
|
|
|
|
tree_parse(root, "/openprom");
|
|
|
|
tree_parse(root, "/openprom/init");
|
|
|
|
tree_parse(root, "/openprom/trace");
|
|
|
|
tree_parse(root, "/openprom/options");
|
1996-02-21 17:47:06 +01:00
|
|
|
return root;
|
1995-11-02 15:27:18 +01:00
|
|
|
}
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
STATIC_INLINE_PSIM\
|
|
|
|
(char *)
|
|
|
|
find_arg(char *err_msg,
|
|
|
|
int *ptr_to_argp,
|
|
|
|
char **argv)
|
1995-11-02 15:27:18 +01:00
|
|
|
{
|
1996-02-21 17:47:06 +01:00
|
|
|
*ptr_to_argp += 1;
|
|
|
|
if (argv[*ptr_to_argp] == NULL)
|
|
|
|
error(err_msg);
|
|
|
|
return argv[*ptr_to_argp];
|
1995-11-02 15:27:18 +01:00
|
|
|
}
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
|
|
|
psim_usage(int verbose)
|
1995-11-02 15:27:18 +01:00
|
|
|
{
|
1996-02-21 17:47:06 +01:00
|
|
|
printf_filtered("Usage:\n");
|
|
|
|
printf_filtered("\n");
|
|
|
|
printf_filtered("\tpsim [ <psim-option> ... ] <image> [ <image-arg> ... ]\n");
|
|
|
|
printf_filtered("\n");
|
|
|
|
printf_filtered("Where\n");
|
|
|
|
printf_filtered("\n");
|
1997-01-27 22:34:50 +01:00
|
|
|
printf_filtered("\t<image> Name of the PowerPC program to run.\n");
|
1996-02-21 17:47:06 +01:00
|
|
|
if (verbose) {
|
1997-01-27 22:34:50 +01:00
|
|
|
printf_filtered("\t This can either be a PowerPC binary or\n");
|
|
|
|
printf_filtered("\t a text file containing a device tree\n");
|
|
|
|
printf_filtered("\t specification.\n");
|
|
|
|
printf_filtered("\t PSIM will attempt to determine from the\n");
|
|
|
|
printf_filtered("\t specified <image> the intended emulation\n");
|
|
|
|
printf_filtered("\t environment.\n");
|
|
|
|
printf_filtered("\t If PSIM gets it wrong, the emulation\n");
|
|
|
|
printf_filtered("\t environment can be specified using the\n");
|
|
|
|
printf_filtered("\t `-e' option (described below).\n");
|
1996-02-21 17:47:06 +01:00
|
|
|
printf_filtered("\n"); }
|
1997-01-27 22:34:50 +01:00
|
|
|
printf_filtered("\t<image-arg> Argument to be passed to <image>\n");
|
1996-02-21 17:47:06 +01:00
|
|
|
if (verbose) {
|
1997-01-27 22:34:50 +01:00
|
|
|
printf_filtered("\t These arguments will be passed to\n");
|
|
|
|
printf_filtered("\t <image> (as standard C argv, argc)\n");
|
|
|
|
printf_filtered("\t when <image> is started.\n");
|
1996-02-21 17:47:06 +01:00
|
|
|
printf_filtered("\n"); }
|
1997-01-27 22:34:50 +01:00
|
|
|
printf_filtered("\t<psim-option> See below\n");
|
1996-02-21 17:47:06 +01:00
|
|
|
printf_filtered("\n");
|
|
|
|
printf_filtered("The following are valid <psim-option>s:\n");
|
|
|
|
printf_filtered("\n");
|
1997-01-27 22:34:50 +01:00
|
|
|
|
|
|
|
printf_filtered("\t-i Print instruction counting statistics\n");
|
|
|
|
if (verbose) { printf_filtered("\n"); }
|
|
|
|
|
|
|
|
printf_filtered("\t-I Print execution unit statistics\n");
|
|
|
|
if (verbose) { printf_filtered("\n"); }
|
|
|
|
|
|
|
|
printf_filtered("\t-e <os-emul> specify an OS or platform to model\n");
|
1996-02-21 17:47:06 +01:00
|
|
|
if (verbose) {
|
1997-01-27 22:34:50 +01:00
|
|
|
printf_filtered("\t Can be any of the following:\n");
|
|
|
|
printf_filtered("\t bug - OEA + MOTO BUG ROM calls\n");
|
|
|
|
printf_filtered("\t netbsd - UEA + NetBSD system calls\n");
|
|
|
|
printf_filtered("\t solaris - UEA + Solaris system calls\n");
|
|
|
|
printf_filtered("\t linux - UEA + Linux system calls\n");
|
|
|
|
printf_filtered("\t chirp - OEA + a few OpenBoot calls\n");
|
1996-02-21 17:47:06 +01:00
|
|
|
printf_filtered("\n"); }
|
1997-01-27 22:34:50 +01:00
|
|
|
|
|
|
|
printf_filtered("\t-f <file> Merge <file> into the device tree\n");
|
1996-02-21 17:47:06 +01:00
|
|
|
if (verbose) { printf_filtered("\n"); }
|
1997-01-27 22:34:50 +01:00
|
|
|
|
|
|
|
printf_filtered("\t-h -? -H give more detailed usage\n");
|
1996-02-21 17:47:06 +01:00
|
|
|
if (verbose) { printf_filtered("\n"); }
|
1997-01-27 22:34:50 +01:00
|
|
|
|
|
|
|
printf_filtered("\t-m <model> Specify the processor to model (604)\n");
|
|
|
|
if (verbose) {
|
|
|
|
printf_filtered("\t Selects the processor to use when\n");
|
|
|
|
printf_filtered("\t modeling execution units. Includes:\n");
|
|
|
|
printf_filtered("\t 604, 603 and 603e\n");
|
|
|
|
printf_filtered("\n"); }
|
|
|
|
|
|
|
|
printf_filtered("\t-n <nr-smp> Specify the number of processors in SMP simulations\n");
|
|
|
|
if (verbose) {
|
|
|
|
printf_filtered("\t Specifies the number of processors that are\n");
|
|
|
|
printf_filtered("\t to be modeled in a symetric multi-processor (SMP)\n");
|
|
|
|
printf_filtered("\t simulation\n");
|
|
|
|
printf_filtered("\n"); }
|
|
|
|
|
|
|
|
printf_filtered("\t-o <dev-spec> Add device <dev-spec> to the device tree\n");
|
1996-02-21 17:47:06 +01:00
|
|
|
if (verbose) { printf_filtered("\n"); }
|
1997-01-27 22:34:50 +01:00
|
|
|
|
|
|
|
printf_filtered("\t-r <ram-size> Set RAM size in bytes (OEA environments)\n");
|
1996-02-21 17:47:06 +01:00
|
|
|
if (verbose) { printf_filtered("\n"); }
|
1997-01-27 22:34:50 +01:00
|
|
|
|
|
|
|
printf_filtered("\t-t [!]<trace> Enable (disable) <trace> option\n");
|
1996-02-21 17:47:06 +01:00
|
|
|
if (verbose) { printf_filtered("\n"); }
|
1997-01-27 22:34:50 +01:00
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
printf_filtered("\n");
|
|
|
|
trace_usage(verbose);
|
|
|
|
device_usage(verbose);
|
|
|
|
if (verbose > 1) {
|
|
|
|
printf_filtered("\n");
|
|
|
|
print_options();
|
1995-11-02 15:27:18 +01:00
|
|
|
}
|
1996-02-21 17:47:06 +01:00
|
|
|
error("");
|
1995-11-02 15:27:18 +01:00
|
|
|
}
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(char **)
|
|
|
|
psim_options(device *root,
|
|
|
|
char **argv)
|
1995-11-02 15:27:18 +01:00
|
|
|
{
|
1996-02-21 17:47:06 +01:00
|
|
|
device *current = root;
|
|
|
|
int argp;
|
|
|
|
if (argv == NULL)
|
|
|
|
return NULL;
|
|
|
|
argp = 0;
|
|
|
|
while (argv[argp] != NULL && argv[argp][0] == '-') {
|
|
|
|
char *p = argv[argp] + 1;
|
|
|
|
char *param;
|
|
|
|
while (*p != '\0') {
|
|
|
|
switch (*p) {
|
|
|
|
default:
|
|
|
|
psim_usage(0);
|
|
|
|
error ("");
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
param = find_arg("Missing <emul> option for -e\n", &argp, argv);
|
1997-01-27 22:34:50 +01:00
|
|
|
tree_parse(root, "/openprom/options/os-emul %s", param);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
param = find_arg("Missing <file> option for -f\n", &argp, argv);
|
|
|
|
psim_merge_device_file(root, param);
|
1996-02-21 17:47:06 +01:00
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
psim_usage(1);
|
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
psim_usage(2);
|
|
|
|
break;
|
|
|
|
case 'i':
|
1997-01-27 22:34:50 +01:00
|
|
|
tree_parse(root, "/openprom/trace/print-info 1");
|
1996-02-21 17:47:06 +01:00
|
|
|
break;
|
|
|
|
case 'I':
|
1997-01-27 22:34:50 +01:00
|
|
|
tree_parse(root, "/openprom/trace/print-info 2");
|
|
|
|
tree_parse(root, "/openprom/options/model-issue %d",
|
|
|
|
MODEL_ISSUE_PROCESS);
|
1996-02-21 17:47:06 +01:00
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
param = find_arg("Missing <model> option for -m\n", &argp, argv);
|
1997-01-27 22:34:50 +01:00
|
|
|
tree_parse(root, "/openprom/options/model \"%s", param);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
param = find_arg("Missing <nr-smp> option for -n\n", &argp, argv);
|
|
|
|
tree_parse(root, "/openprom/options/smp %s", param);
|
1996-02-21 17:47:06 +01:00
|
|
|
break;
|
|
|
|
case 'o':
|
1997-01-27 22:34:50 +01:00
|
|
|
param = find_arg("Missing <dev-spec> option for -o\n", &argp, argv);
|
|
|
|
current = tree_parse(current, "%s", param);
|
1996-02-21 17:47:06 +01:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
param = find_arg("Missing <ram-size> option for -r\n", &argp, argv);
|
1997-01-27 22:34:50 +01:00
|
|
|
tree_parse(root, "/openprom/options/oea-memory-size %s",
|
|
|
|
param);
|
1996-02-21 17:47:06 +01:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
param = find_arg("Missing <trace> option for -t\n", &argp, argv);
|
|
|
|
if (param[0] == '!')
|
1997-01-27 22:34:50 +01:00
|
|
|
tree_parse(root, "/openprom/trace/%s 0", param+1);
|
1996-02-21 17:47:06 +01:00
|
|
|
else
|
1997-01-27 22:34:50 +01:00
|
|
|
tree_parse(root, "/openprom/trace/%s 1", param);
|
1996-02-21 17:47:06 +01:00
|
|
|
break;
|
1995-11-02 15:27:18 +01:00
|
|
|
}
|
1996-02-21 17:47:06 +01:00
|
|
|
p += 1;
|
1995-11-02 15:27:18 +01:00
|
|
|
}
|
1996-02-21 17:47:06 +01:00
|
|
|
argp += 1;
|
1995-11-02 15:27:18 +01:00
|
|
|
}
|
1997-01-27 22:34:50 +01:00
|
|
|
/* force the trace node to process its options now *before* the tree
|
|
|
|
initialization occures */
|
|
|
|
device_ioctl(tree_find_device(root, "/openprom/trace"),
|
|
|
|
NULL, 0,
|
|
|
|
device_ioctl_set_trace);
|
1996-07-23 17:42:42 +02:00
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
/* return where the options end */
|
|
|
|
return argv + argp;
|
1995-11-02 15:27:18 +01:00
|
|
|
}
|
|
|
|
|
1997-01-27 22:34:50 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
|
|
|
psim_command(device *root,
|
|
|
|
char **argv)
|
|
|
|
{
|
|
|
|
int argp = 0;
|
|
|
|
if (argv[argp] == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[argp], "trace") == 0) {
|
|
|
|
const char *opt = find_arg("Missing <trace> option", &argp, argv);
|
|
|
|
if (opt[0] == '!')
|
|
|
|
trace_option(opt + 1, 0);
|
|
|
|
else
|
|
|
|
trace_option(opt, 1);
|
|
|
|
}
|
|
|
|
else if (strcmp(*argv, "change-media") == 0) {
|
|
|
|
char *device = find_arg("Missing device name", &argp, argv);
|
|
|
|
char *media = argv[++argp];
|
|
|
|
device_ioctl(tree_find_device(root, device), NULL, 0,
|
|
|
|
device_ioctl_change_media, media);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf_filtered("Unknown PSIM command %s, try\n", argv[argp]);
|
|
|
|
printf_filtered(" trace <trace-option>\n");
|
|
|
|
printf_filtered(" change-media <device> [ <new-image> ]\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-11-02 15:27:18 +01:00
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
/* create the simulator proper from the device tree and executable */
|
1995-09-09 01:56:38 +02:00
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(psim *)
|
|
|
|
psim_create(const char *file_name,
|
|
|
|
device *root)
|
1995-09-09 01:56:38 +02:00
|
|
|
{
|
|
|
|
int cpu_nr;
|
1995-11-02 15:27:18 +01:00
|
|
|
const char *env;
|
1995-09-09 01:56:38 +02:00
|
|
|
psim *system;
|
1996-02-21 17:47:06 +01:00
|
|
|
os_emul *os_emulation;
|
|
|
|
int nr_cpus;
|
1995-09-09 01:56:38 +02:00
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
/* given this partially populated device tree, os_emul_create() uses
|
|
|
|
it and file_name to determine the selected emulation and hence
|
|
|
|
further populate the tree with any other required nodes. */
|
|
|
|
|
|
|
|
os_emulation = os_emul_create(file_name, root);
|
|
|
|
if (os_emulation == NULL)
|
|
|
|
error("psim: either file %s was not reconized or unreconized or unknown os-emulation type\n", file_name);
|
1995-09-09 01:56:38 +02:00
|
|
|
|
1995-11-02 15:27:18 +01:00
|
|
|
/* fill in the missing real number of CPU's */
|
1997-01-27 22:34:50 +01:00
|
|
|
nr_cpus = tree_find_integer_property(root, "/openprom/options/smp");
|
1996-02-21 17:47:06 +01:00
|
|
|
if (MAX_NR_PROCESSORS < nr_cpus)
|
|
|
|
error("target and configured number of cpus conflict\n");
|
1995-11-02 15:27:18 +01:00
|
|
|
|
|
|
|
/* fill in the missing TARGET BYTE ORDER information */
|
1996-02-21 17:47:06 +01:00
|
|
|
current_target_byte_order
|
1997-01-27 22:34:50 +01:00
|
|
|
= (tree_find_boolean_property(root, "/options/little-endian?")
|
1996-02-21 17:47:06 +01:00
|
|
|
? LITTLE_ENDIAN
|
|
|
|
: BIG_ENDIAN);
|
1995-11-02 15:27:18 +01:00
|
|
|
if (CURRENT_TARGET_BYTE_ORDER != current_target_byte_order)
|
1996-02-21 17:47:06 +01:00
|
|
|
error("target and configured byte order conflict\n");
|
1995-09-09 01:56:38 +02:00
|
|
|
|
1995-11-02 15:27:18 +01:00
|
|
|
/* fill in the missing HOST BYTE ORDER information */
|
|
|
|
current_host_byte_order = (current_host_byte_order = 1,
|
|
|
|
(*(char*)(¤t_host_byte_order)
|
|
|
|
? LITTLE_ENDIAN
|
|
|
|
: BIG_ENDIAN));
|
|
|
|
if (CURRENT_HOST_BYTE_ORDER != current_host_byte_order)
|
1996-02-21 17:47:06 +01:00
|
|
|
error("host and configured byte order conflict\n");
|
1995-09-09 01:56:38 +02:00
|
|
|
|
|
|
|
/* fill in the missing OEA/VEA information */
|
1997-01-27 22:34:50 +01:00
|
|
|
env = tree_find_string_property(root, "/openprom/options/env");
|
1995-11-06 16:37:43 +01:00
|
|
|
current_environment = ((strcmp(env, "user") == 0
|
|
|
|
|| strcmp(env, "uea") == 0)
|
1995-11-02 15:27:18 +01:00
|
|
|
? USER_ENVIRONMENT
|
1995-11-06 16:37:43 +01:00
|
|
|
: (strcmp(env, "virtual") == 0
|
|
|
|
|| strcmp(env, "vea") == 0)
|
1995-09-09 01:56:38 +02:00
|
|
|
? VIRTUAL_ENVIRONMENT
|
1995-11-06 16:37:43 +01:00
|
|
|
: (strcmp(env, "operating") == 0
|
|
|
|
|| strcmp(env, "oea") == 0)
|
1995-11-02 15:27:18 +01:00
|
|
|
? OPERATING_ENVIRONMENT
|
|
|
|
: 0);
|
|
|
|
if (current_environment == 0)
|
1996-02-21 17:47:06 +01:00
|
|
|
error("unreconized /options env property\n");
|
1995-11-02 15:27:18 +01:00
|
|
|
if (CURRENT_ENVIRONMENT != current_environment)
|
1996-02-21 17:47:06 +01:00
|
|
|
error("target and configured environment conflict\n");
|
1995-09-09 01:56:38 +02:00
|
|
|
|
|
|
|
/* fill in the missing ALLIGNMENT information */
|
1996-02-21 17:47:06 +01:00
|
|
|
current_alignment
|
1997-01-27 22:34:50 +01:00
|
|
|
= (tree_find_boolean_property(root, "/openprom/options/strict-alignment?")
|
1996-02-21 17:47:06 +01:00
|
|
|
? STRICT_ALIGNMENT
|
|
|
|
: NONSTRICT_ALIGNMENT);
|
1995-11-02 15:27:18 +01:00
|
|
|
if (CURRENT_ALIGNMENT != current_alignment)
|
1996-02-21 17:47:06 +01:00
|
|
|
error("target and configured alignment conflict\n");
|
1995-11-02 15:27:18 +01:00
|
|
|
|
|
|
|
/* fill in the missing FLOATING POINT information */
|
1996-02-21 17:47:06 +01:00
|
|
|
current_floating_point
|
1997-01-27 22:34:50 +01:00
|
|
|
= (tree_find_boolean_property(root, "/openprom/options/floating-point?")
|
1996-02-21 17:47:06 +01:00
|
|
|
? HARD_FLOATING_POINT
|
|
|
|
: SOFT_FLOATING_POINT);
|
1995-11-02 15:27:18 +01:00
|
|
|
if (CURRENT_FLOATING_POINT != current_floating_point)
|
1996-02-21 17:47:06 +01:00
|
|
|
error("target and configured floating-point conflict\n");
|
|
|
|
|
1997-01-27 22:34:50 +01:00
|
|
|
/* fill in the missing STDIO information */
|
|
|
|
current_stdio
|
|
|
|
= (tree_find_boolean_property(root, "/openprom/options/use-stdio?")
|
|
|
|
? DO_USE_STDIO
|
|
|
|
: DONT_USE_STDIO);
|
|
|
|
if (CURRENT_STDIO != current_stdio)
|
|
|
|
error("target and configured stdio interface conflict\n");
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
/* sort out the level of detail for issue modeling */
|
|
|
|
current_model_issue
|
1997-01-27 22:34:50 +01:00
|
|
|
= tree_find_integer_property(root, "/openprom/options/model-issue");
|
1996-02-21 17:47:06 +01:00
|
|
|
if (CURRENT_MODEL_ISSUE != current_model_issue)
|
|
|
|
error("target and configured model-issue conflict\n");
|
|
|
|
|
|
|
|
/* sort out our model architecture - wrong.
|
|
|
|
|
|
|
|
FIXME: this should be obtaining the required information from the
|
|
|
|
device tree via the "/chosen" property "cpu" which is an instance
|
|
|
|
(ihandle) for the only executing processor. By converting that
|
|
|
|
ihandle into the corresponding cpu's phandle and then querying
|
|
|
|
the "name" property, the cpu type can be determined. Ok? */
|
|
|
|
|
1997-01-27 22:34:50 +01:00
|
|
|
model_set(tree_find_string_property(root, "/openprom/options/model"));
|
1996-02-21 17:47:06 +01:00
|
|
|
|
|
|
|
/* create things */
|
|
|
|
system = ZALLOC(psim);
|
|
|
|
system->events = event_queue_create();
|
1996-07-23 17:42:42 +02:00
|
|
|
system->memory = core_from_device(root);
|
1996-02-21 17:47:06 +01:00
|
|
|
system->monitor = mon_create();
|
|
|
|
system->nr_cpus = nr_cpus;
|
|
|
|
system->os_emulation = os_emulation;
|
|
|
|
system->devices = root;
|
|
|
|
|
|
|
|
/* now all the processors attaching to each their per-cpu information */
|
|
|
|
for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++) {
|
|
|
|
system->processors[cpu_nr] = cpu_create(system,
|
|
|
|
system->memory,
|
|
|
|
mon_cpu(system->monitor,
|
|
|
|
cpu_nr),
|
|
|
|
system->os_emulation,
|
|
|
|
cpu_nr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dump out the contents of the device tree */
|
|
|
|
if (ppc_trace[trace_print_device_tree] || ppc_trace[trace_dump_device_tree])
|
1997-01-27 22:34:50 +01:00
|
|
|
tree_print(root);
|
1996-02-21 17:47:06 +01:00
|
|
|
if (ppc_trace[trace_dump_device_tree])
|
|
|
|
error("");
|
1995-09-09 01:56:38 +02:00
|
|
|
|
|
|
|
return system;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* allow the simulation to stop/restart abnormaly */
|
|
|
|
|
1996-07-23 17:42:42 +02:00
|
|
|
INLINE_PSIM\
|
1996-02-21 17:47:06 +01:00
|
|
|
(void)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_set_halt_and_restart(psim *system,
|
|
|
|
void *halt_jmp_buf,
|
|
|
|
void *restart_jmp_buf)
|
|
|
|
{
|
|
|
|
system->path_to_halt = halt_jmp_buf;
|
|
|
|
system->path_to_restart = restart_jmp_buf;
|
|
|
|
}
|
|
|
|
|
1996-07-23 17:42:42 +02:00
|
|
|
INLINE_PSIM\
|
1996-02-21 17:47:06 +01:00
|
|
|
(void)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_clear_halt_and_restart(psim *system)
|
|
|
|
{
|
|
|
|
system->path_to_halt = NULL;
|
|
|
|
system->path_to_restart = NULL;
|
|
|
|
}
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_restart(psim *system,
|
|
|
|
int current_cpu)
|
|
|
|
{
|
|
|
|
system->last_cpu = current_cpu;
|
|
|
|
longjmp(*(jmp_buf*)(system->path_to_restart), current_cpu + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_halt(psim *system,
|
|
|
|
int current_cpu,
|
|
|
|
stop_reason reason,
|
|
|
|
int signal)
|
|
|
|
{
|
1996-06-02 17:40:16 +02:00
|
|
|
ASSERT(current_cpu >= 0 && current_cpu < system->nr_cpus);
|
1995-09-09 01:56:38 +02:00
|
|
|
system->last_cpu = current_cpu;
|
|
|
|
system->halt_status.cpu_nr = current_cpu;
|
|
|
|
system->halt_status.reason = reason;
|
|
|
|
system->halt_status.signal = signal;
|
1996-06-02 17:40:16 +02:00
|
|
|
system->halt_status.program_counter =
|
|
|
|
cpu_get_program_counter(system->processors[current_cpu]);
|
1995-09-09 01:56:38 +02:00
|
|
|
longjmp(*(jmp_buf*)(system->path_to_halt), current_cpu + 1);
|
|
|
|
}
|
|
|
|
|
1997-01-27 22:34:50 +01:00
|
|
|
|
1996-07-23 17:42:42 +02:00
|
|
|
INLINE_PSIM\
|
|
|
|
(int)
|
|
|
|
psim_last_cpu(psim *system)
|
|
|
|
{
|
|
|
|
return system->last_cpu;
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE_PSIM\
|
|
|
|
(int)
|
|
|
|
psim_nr_cpus(psim *system)
|
|
|
|
{
|
|
|
|
return system->nr_cpus;
|
|
|
|
}
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(psim_status)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_get_status(psim *system)
|
|
|
|
{
|
|
|
|
return system->halt_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(cpu *)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_cpu(psim *system,
|
|
|
|
int cpu_nr)
|
|
|
|
{
|
|
|
|
if (cpu_nr < 0 || cpu_nr >= system->nr_cpus)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return system->processors[cpu_nr];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(device *)
|
1995-11-02 15:27:18 +01:00
|
|
|
psim_device(psim *system,
|
|
|
|
const char *path)
|
1995-09-09 01:56:38 +02:00
|
|
|
{
|
1997-01-27 22:34:50 +01:00
|
|
|
return tree_find_device(system->devices, path);
|
1995-09-09 01:56:38 +02:00
|
|
|
}
|
|
|
|
|
1996-06-02 17:40:16 +02:00
|
|
|
INLINE_PSIM\
|
|
|
|
(event_queue *)
|
|
|
|
psim_event_queue(psim *system)
|
|
|
|
{
|
|
|
|
return system->events;
|
|
|
|
}
|
|
|
|
|
1995-09-09 01:56:38 +02:00
|
|
|
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
1995-11-02 15:27:18 +01:00
|
|
|
psim_init(psim *system)
|
1995-09-09 01:56:38 +02:00
|
|
|
{
|
1995-11-02 15:27:18 +01:00
|
|
|
int cpu_nr;
|
1995-09-09 01:56:38 +02:00
|
|
|
|
1995-11-02 15:27:18 +01:00
|
|
|
/* scrub the monitor */
|
|
|
|
mon_init(system->monitor, system->nr_cpus);
|
1996-07-23 17:42:42 +02:00
|
|
|
|
|
|
|
/* trash any pending events */
|
1996-02-21 17:47:06 +01:00
|
|
|
event_queue_init(system->events);
|
1995-09-09 01:56:38 +02:00
|
|
|
|
1995-11-02 15:27:18 +01:00
|
|
|
/* scrub all the cpus */
|
|
|
|
for (cpu_nr = 0; cpu_nr < system->nr_cpus; cpu_nr++)
|
|
|
|
cpu_init(system->processors[cpu_nr]);
|
1995-09-09 01:56:38 +02:00
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
/* init all the devices (which updates the cpus) */
|
1997-01-27 22:34:50 +01:00
|
|
|
tree_init(system->devices, system);
|
1995-09-09 01:56:38 +02:00
|
|
|
|
1996-07-23 17:42:42 +02:00
|
|
|
/* and the emulation (which needs an initialized device tree) */
|
|
|
|
os_emul_init(system->os_emulation, system->nr_cpus);
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
/* now sync each cpu against the initialized state of its registers */
|
|
|
|
for (cpu_nr = 0; cpu_nr < system->nr_cpus; cpu_nr++) {
|
1997-01-27 22:34:50 +01:00
|
|
|
cpu *processor = system->processors[cpu_nr];
|
|
|
|
cpu_synchronize_context(processor, cpu_get_program_counter(processor));
|
|
|
|
cpu_page_tlb_invalidate_all(processor);
|
1996-02-21 17:47:06 +01:00
|
|
|
}
|
|
|
|
|
1997-01-27 22:34:50 +01:00
|
|
|
/* force loop to start with first cpu (after processing events) */
|
|
|
|
system->last_cpu = system->nr_cpus - 1;
|
1995-09-09 01:56:38 +02:00
|
|
|
}
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_stack(psim *system,
|
|
|
|
char **argv,
|
|
|
|
char **envp)
|
|
|
|
{
|
1995-11-02 15:27:18 +01:00
|
|
|
/* pass the stack device the argv/envp and let it work out what to
|
|
|
|
do with it */
|
1997-01-27 22:34:50 +01:00
|
|
|
device *stack_device = tree_find_device(system->devices,
|
|
|
|
"/openprom/init/stack");
|
1996-02-21 17:47:06 +01:00
|
|
|
if (stack_device != (device*)0) {
|
|
|
|
unsigned_word stack_pointer;
|
|
|
|
psim_read_register(system, 0, &stack_pointer, "sp", cooked_transfer);
|
|
|
|
device_ioctl(stack_device,
|
|
|
|
NULL, /*cpu*/
|
|
|
|
0, /*cia*/
|
1997-01-27 22:34:50 +01:00
|
|
|
device_ioctl_create_stack,
|
1996-02-21 17:47:06 +01:00
|
|
|
stack_pointer,
|
|
|
|
argv,
|
|
|
|
envp);
|
|
|
|
}
|
1995-09-09 01:56:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* SIMULATE INSTRUCTIONS, various different ways of achieving the same
|
|
|
|
thing */
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_step(psim *system)
|
|
|
|
{
|
|
|
|
volatile int keep_running = 0;
|
1996-07-23 17:42:42 +02:00
|
|
|
idecode_run_until_stop(system, &keep_running,
|
|
|
|
system->events, system->processors, system->nr_cpus);
|
1995-09-09 01:56:38 +02:00
|
|
|
}
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_run(psim *system)
|
|
|
|
{
|
1996-07-23 17:42:42 +02:00
|
|
|
idecode_run(system,
|
|
|
|
system->events, system->processors, system->nr_cpus);
|
1995-09-09 01:56:38 +02:00
|
|
|
}
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_run_until_stop(psim *system,
|
|
|
|
volatile int *keep_running)
|
|
|
|
{
|
1996-07-23 17:42:42 +02:00
|
|
|
idecode_run_until_stop(system, keep_running,
|
|
|
|
system->events, system->processors, system->nr_cpus);
|
1995-09-09 01:56:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* storage manipulation functions */
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_read_register(psim *system,
|
|
|
|
int which_cpu,
|
|
|
|
void *buf,
|
|
|
|
const char reg[],
|
|
|
|
transfer_mode mode)
|
|
|
|
{
|
|
|
|
register_descriptions description;
|
1996-03-26 22:20:54 +01:00
|
|
|
char cooked_buf[sizeof(unsigned_8)];
|
1995-09-09 01:56:38 +02:00
|
|
|
cpu *processor;
|
|
|
|
|
|
|
|
/* find our processor */
|
1995-11-02 15:27:18 +01:00
|
|
|
if (which_cpu == MAX_NR_PROCESSORS)
|
1995-09-09 01:56:38 +02:00
|
|
|
which_cpu = system->last_cpu;
|
1995-11-02 15:27:18 +01:00
|
|
|
if (which_cpu < 0 || which_cpu >= system->nr_cpus)
|
|
|
|
error("psim_read_register() - invalid processor %d\n", which_cpu);
|
1995-09-09 01:56:38 +02:00
|
|
|
processor = system->processors[which_cpu];
|
|
|
|
|
|
|
|
/* find the register description */
|
|
|
|
description = register_description(reg);
|
|
|
|
if (description.type == reg_invalid)
|
|
|
|
error("psim_read_register() invalid register name `%s'\n", reg);
|
|
|
|
|
|
|
|
/* get the cooked value */
|
|
|
|
switch (description.type) {
|
|
|
|
|
|
|
|
case reg_gpr:
|
|
|
|
*(gpreg*)cooked_buf = cpu_registers(processor)->gpr[description.index];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_spr:
|
|
|
|
*(spreg*)cooked_buf = cpu_registers(processor)->spr[description.index];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_sr:
|
|
|
|
*(sreg*)cooked_buf = cpu_registers(processor)->sr[description.index];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_fpr:
|
|
|
|
*(fpreg*)cooked_buf = cpu_registers(processor)->fpr[description.index];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_pc:
|
|
|
|
*(unsigned_word*)cooked_buf = cpu_get_program_counter(processor);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_cr:
|
|
|
|
*(creg*)cooked_buf = cpu_registers(processor)->cr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_msr:
|
|
|
|
*(msreg*)cooked_buf = cpu_registers(processor)->msr;
|
|
|
|
break;
|
|
|
|
|
1996-07-23 17:42:42 +02:00
|
|
|
case reg_insns:
|
|
|
|
*(unsigned_word*)cooked_buf = mon_get_number_of_insns(system->monitor,
|
|
|
|
which_cpu);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_stalls:
|
|
|
|
if (cpu_model(processor) == NULL)
|
|
|
|
error("$stalls only valid if processor unit model enabled (-I)\n");
|
|
|
|
*(unsigned_word*)cooked_buf = model_get_number_of_stalls(cpu_model(processor));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_cycles:
|
|
|
|
if (cpu_model(processor) == NULL)
|
|
|
|
error("$cycles only valid if processor unit model enabled (-I)\n");
|
|
|
|
*(unsigned_word*)cooked_buf = model_get_number_of_cycles(cpu_model(processor));
|
|
|
|
break;
|
|
|
|
|
1995-09-09 01:56:38 +02:00
|
|
|
default:
|
1995-11-24 17:44:37 +01:00
|
|
|
printf_filtered("psim_read_register(processor=0x%lx,buf=0x%lx,reg=%s) %s\n",
|
|
|
|
(unsigned long)processor, (unsigned long)buf, reg,
|
1995-09-09 01:56:38 +02:00
|
|
|
"read of this register unimplemented");
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the PSIM internal values are in host order. To fetch raw data,
|
|
|
|
they need to be converted into target order and then returned */
|
|
|
|
if (mode == raw_transfer) {
|
|
|
|
/* FIXME - assumes that all registers are simple integers */
|
|
|
|
switch (description.size) {
|
|
|
|
case 1:
|
|
|
|
*(unsigned_1*)buf = H2T_1(*(unsigned_1*)cooked_buf);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
*(unsigned_2*)buf = H2T_2(*(unsigned_2*)cooked_buf);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
*(unsigned_4*)buf = H2T_4(*(unsigned_4*)cooked_buf);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
*(unsigned_8*)buf = H2T_8(*(unsigned_8*)cooked_buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1995-11-24 17:44:37 +01:00
|
|
|
memcpy(buf/*dest*/, cooked_buf/*src*/, description.size);
|
1995-09-09 01:56:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_write_register(psim *system,
|
|
|
|
int which_cpu,
|
|
|
|
const void *buf,
|
|
|
|
const char reg[],
|
|
|
|
transfer_mode mode)
|
|
|
|
{
|
|
|
|
cpu *processor;
|
|
|
|
register_descriptions description;
|
1996-03-26 22:20:54 +01:00
|
|
|
char cooked_buf[sizeof(unsigned_8)];
|
1995-09-09 01:56:38 +02:00
|
|
|
|
|
|
|
/* find our processor */
|
1995-11-02 15:27:18 +01:00
|
|
|
if (which_cpu == MAX_NR_PROCESSORS)
|
|
|
|
which_cpu = system->last_cpu;
|
1995-09-09 01:56:38 +02:00
|
|
|
if (which_cpu == -1) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < system->nr_cpus; i++)
|
|
|
|
psim_write_register(system, i, buf, reg, mode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (which_cpu < 0 || which_cpu >= system->nr_cpus) {
|
|
|
|
error("psim_read_register() - invalid processor %d\n", which_cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
processor = system->processors[which_cpu];
|
|
|
|
|
|
|
|
/* find the description of the register */
|
|
|
|
description = register_description(reg);
|
|
|
|
if (description.type == reg_invalid)
|
|
|
|
error("psim_write_register() invalid register name %s\n", reg);
|
|
|
|
|
|
|
|
/* If the data is comming in raw (target order), need to cook it
|
|
|
|
into host order before putting it into PSIM's internal structures */
|
|
|
|
if (mode == raw_transfer) {
|
|
|
|
switch (description.size) {
|
|
|
|
case 1:
|
|
|
|
*(unsigned_1*)cooked_buf = T2H_1(*(unsigned_1*)buf);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
*(unsigned_2*)cooked_buf = T2H_2(*(unsigned_2*)buf);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
*(unsigned_4*)cooked_buf = T2H_4(*(unsigned_4*)buf);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
*(unsigned_8*)cooked_buf = T2H_8(*(unsigned_8*)buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1995-11-24 17:44:37 +01:00
|
|
|
memcpy(cooked_buf/*dest*/, buf/*src*/, description.size);
|
1995-09-09 01:56:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* put the cooked value into the register */
|
|
|
|
switch (description.type) {
|
|
|
|
|
|
|
|
case reg_gpr:
|
|
|
|
cpu_registers(processor)->gpr[description.index] = *(gpreg*)cooked_buf;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_fpr:
|
|
|
|
cpu_registers(processor)->fpr[description.index] = *(fpreg*)cooked_buf;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_pc:
|
|
|
|
cpu_set_program_counter(processor, *(unsigned_word*)cooked_buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_spr:
|
|
|
|
cpu_registers(processor)->spr[description.index] = *(spreg*)cooked_buf;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_sr:
|
|
|
|
cpu_registers(processor)->sr[description.index] = *(sreg*)cooked_buf;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_cr:
|
|
|
|
cpu_registers(processor)->cr = *(creg*)cooked_buf;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reg_msr:
|
|
|
|
cpu_registers(processor)->msr = *(msreg*)cooked_buf;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1995-11-24 17:44:37 +01:00
|
|
|
printf_filtered("psim_write_register(processor=0x%lx,cooked_buf=0x%lx,reg=%s) %s\n",
|
|
|
|
(unsigned long)processor, (unsigned long)cooked_buf, reg,
|
1995-09-09 01:56:38 +02:00
|
|
|
"read of this register unimplemented");
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(unsigned)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_read_memory(psim *system,
|
|
|
|
int which_cpu,
|
|
|
|
void *buffer,
|
|
|
|
unsigned_word vaddr,
|
1995-11-02 15:27:18 +01:00
|
|
|
unsigned nr_bytes)
|
1995-09-09 01:56:38 +02:00
|
|
|
{
|
|
|
|
cpu *processor;
|
1995-11-02 15:27:18 +01:00
|
|
|
if (which_cpu == MAX_NR_PROCESSORS)
|
1995-09-09 01:56:38 +02:00
|
|
|
which_cpu = system->last_cpu;
|
1995-11-02 15:27:18 +01:00
|
|
|
if (which_cpu < 0 || which_cpu >= system->nr_cpus)
|
|
|
|
error("psim_read_memory() invalid cpu\n");
|
1995-09-09 01:56:38 +02:00
|
|
|
processor = system->processors[which_cpu];
|
|
|
|
return vm_data_map_read_buffer(cpu_data_map(processor),
|
1997-01-27 22:34:50 +01:00
|
|
|
buffer, vaddr, nr_bytes,
|
|
|
|
NULL, -1);
|
1995-09-09 01:56:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(unsigned)
|
1995-09-09 01:56:38 +02:00
|
|
|
psim_write_memory(psim *system,
|
|
|
|
int which_cpu,
|
|
|
|
const void *buffer,
|
|
|
|
unsigned_word vaddr,
|
1995-11-02 15:27:18 +01:00
|
|
|
unsigned nr_bytes,
|
1995-09-09 01:56:38 +02:00
|
|
|
int violate_read_only_section)
|
|
|
|
{
|
|
|
|
cpu *processor;
|
1995-11-02 15:27:18 +01:00
|
|
|
if (which_cpu == MAX_NR_PROCESSORS)
|
1995-09-09 01:56:38 +02:00
|
|
|
which_cpu = system->last_cpu;
|
1995-11-02 15:27:18 +01:00
|
|
|
if (which_cpu < 0 || which_cpu >= system->nr_cpus)
|
|
|
|
error("psim_read_memory() invalid cpu\n");
|
1995-09-09 01:56:38 +02:00
|
|
|
processor = system->processors[which_cpu];
|
|
|
|
return vm_data_map_write_buffer(cpu_data_map(processor),
|
1997-01-27 22:34:50 +01:00
|
|
|
buffer, vaddr, nr_bytes, 1/*violate-read-only*/,
|
|
|
|
NULL, -1);
|
1995-09-09 01:56:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
1995-11-02 15:27:18 +01:00
|
|
|
psim_print_info(psim *system,
|
|
|
|
int verbose)
|
1995-10-02 19:19:17 +01:00
|
|
|
{
|
1995-11-08 19:57:06 +01:00
|
|
|
mon_print_info(system, system->monitor, verbose);
|
1995-10-02 19:19:17 +01:00
|
|
|
}
|
|
|
|
|
1995-11-02 15:27:18 +01:00
|
|
|
|
1996-02-21 17:47:06 +01:00
|
|
|
/* Merge a device tree and a device file. */
|
|
|
|
|
|
|
|
INLINE_PSIM\
|
|
|
|
(void)
|
|
|
|
psim_merge_device_file(device *root,
|
|
|
|
const char *file_name)
|
|
|
|
{
|
1997-01-27 22:34:50 +01:00
|
|
|
FILE *description;
|
|
|
|
int line_nr;
|
1996-02-21 17:47:06 +01:00
|
|
|
char device_path[1000];
|
1997-01-27 22:34:50 +01:00
|
|
|
device *current;
|
|
|
|
|
|
|
|
/* try opening the file */
|
|
|
|
description = fopen(file_name, "r");
|
|
|
|
if (description == NULL) {
|
|
|
|
perror(file_name);
|
|
|
|
error("Invalid file %s specified", file_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
line_nr = 0;
|
|
|
|
current = root;
|
1996-02-21 17:47:06 +01:00
|
|
|
while (fgets(device_path, sizeof(device_path), description)) {
|
1997-01-27 22:34:50 +01:00
|
|
|
char *device;
|
|
|
|
/* check that the full line was read */
|
1996-02-21 17:47:06 +01:00
|
|
|
if (strchr(device_path, '\n') == NULL) {
|
|
|
|
fclose(description);
|
1997-01-27 22:34:50 +01:00
|
|
|
error("%s:%d: line to long - %s",
|
|
|
|
file_name, line_nr, device_path);
|
1996-02-21 17:47:06 +01:00
|
|
|
}
|
1997-01-27 22:34:50 +01:00
|
|
|
else
|
|
|
|
*strchr(device_path, '\n') = '\0';
|
1996-02-21 17:47:06 +01:00
|
|
|
line_nr++;
|
1997-01-27 22:34:50 +01:00
|
|
|
/* skip comments ("#" or ";") and blank lines lines */
|
|
|
|
for (device = device_path;
|
|
|
|
*device != '\0' && isspace(*device);
|
|
|
|
device++);
|
|
|
|
if (device[0] == '#'
|
|
|
|
|| device[0] == ';'
|
|
|
|
|| device[0] == '\0')
|
|
|
|
continue;
|
|
|
|
/* merge any appended lines */
|
|
|
|
while (device_path[strlen(device_path) - 1] == '\\') {
|
|
|
|
int curlen = strlen(device_path) - 1;
|
|
|
|
/* zap \ */
|
|
|
|
device_path[curlen] = '\0';
|
|
|
|
/* append the next line */
|
|
|
|
if (!fgets(device_path + curlen, sizeof(device_path) - curlen, description)) {
|
|
|
|
fclose(description);
|
|
|
|
error("%s:%s: unexpected eof in line continuation - %s",
|
|
|
|
file_name, line_nr, device_path);
|
|
|
|
}
|
|
|
|
if (strchr(device_path, '\n') == NULL) {
|
|
|
|
fclose(description);
|
|
|
|
error("%s:%d: line to long - %s",
|
|
|
|
file_name, line_nr, device_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*strchr(device_path, '\n') = '\0';
|
|
|
|
line_nr++;
|
|
|
|
}
|
1996-02-21 17:47:06 +01:00
|
|
|
/* parse this line */
|
1997-01-27 22:34:50 +01:00
|
|
|
current = tree_parse(current, "%s", device);
|
1996-02-21 17:47:06 +01:00
|
|
|
}
|
|
|
|
fclose(description);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-09-09 01:56:38 +02:00
|
|
|
#endif /* _PSIM_C_ */
|