aboutsummaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
authorMichael Meissner <gnu@the-meissners.org>1996-02-22 20:11:41 +0000
committerMichael Meissner <gnu@the-meissners.org>1996-02-22 20:11:41 +0000
commit262faa5417cda51e88583546bb1f1d22eec6ec77 (patch)
tree6351626ae5b12bb407852ff1cb217a76d515eefe /sim
parenteaf2030fff1f05462b962e8785ab4104569dc7b7 (diff)
downloadgdb-262faa5417cda51e88583546bb1f1d22eec6ec77.zip
gdb-262faa5417cda51e88583546bb1f1d22eec6ec77.tar.gz
gdb-262faa5417cda51e88583546bb1f1d22eec6ec77.tar.bz2
Add input support; at end of user writes, call fflush
Diffstat (limited to 'sim')
-rw-r--r--sim/ppc/ChangeLog14
-rw-r--r--sim/ppc/emul_bugapi.c71
-rw-r--r--sim/ppc/emul_netbsd.c2
-rw-r--r--sim/ppc/main.c69
4 files changed, 101 insertions, 55 deletions
diff --git a/sim/ppc/ChangeLog b/sim/ppc/ChangeLog
index 3583f82..c0e9b33 100644
--- a/sim/ppc/ChangeLog
+++ b/sim/ppc/ChangeLog
@@ -1,3 +1,17 @@
+Thu Feb 22 14:01:56 1996 Michael Meissner <meissner@tiktok.cygnus.com>
+
+ * emul_bugapi.c (emul_bugapi_do_read): New function to handle
+ reads.
+ (emul_bugapi_instruction_call): Add support for .INCHR/.INLN
+ system calls.
+
+ * emul_bugapi.c (emul_bugapi_do_write): Call flush_stdoutput.
+ * emul_netbsd.c (do_write): Call flush_stdoutput.
+
+ * main.c (flush_stdoutput): Do fflush (stdout).
+ * sim_calls.c (flush_stdoutput): Do gdb_flush (gdb_stdout);
+ * sim_callbacks.h (flush_stdoutput): Declare.
+
Wed Feb 21 10:39:35 1996 Michael Meissner <meissner@tiktok.cygnus.com>
* emul_bugapi.c (bug_mapping): New structure to map bug system
diff --git a/sim/ppc/emul_bugapi.c b/sim/ppc/emul_bugapi.c
index 2b1a308..35357dd 100644
--- a/sim/ppc/emul_bugapi.c
+++ b/sim/ppc/emul_bugapi.c
@@ -22,6 +22,20 @@
#ifndef _EMUL_BUGAPI_C_
#define _EMUL_BUGAPI_C_
+/* Note: this module is called via a table. There is no benefit in
+ making it inline */
+
+#include "emul_generic.h"
+#include "emul_bugapi.h"
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
/* from PowerPCBug Debugging Package User's Manual, part 2 of 2 and also bug.S - Dale Rahn */
#define _INCHR 0x000 /* Input character */
@@ -137,13 +151,6 @@ static const struct bug_map bug_mapping[] = {
{ _SYMBOLDA, ".SYMBOLDA -- Detach symbol table" },
};
-/* Note: this module is called via a table. There is no benefit in
- making it inline */
-
-#include "emul_generic.h"
-#include "emul_bugapi.h"
-
-
#ifndef OEA_START_ADDRESS
#define OEA_START_ADDRESS 0x100000
#endif
@@ -285,6 +292,40 @@ emul_bugapi_instruction_name(int call_id)
return buffer;
}
+static int
+emul_bugapi_do_read(cpu *processor,
+ unsigned_word cia,
+ unsigned_word buf,
+ int nbytes)
+{
+ unsigned char *scratch_buffer;
+ int status;
+
+ /* get a tempoary bufer */
+ scratch_buffer = (unsigned char *) zalloc(nbytes);
+
+ /* check if buffer exists by reading it */
+ emul_read_buffer((void *)scratch_buffer, buf, nbytes, processor, cia);
+
+ /* read */
+ status = read (0, (void *)scratch_buffer, nbytes);
+
+ if (status == -1) {
+ status = 0;
+ }
+
+ if (status > 0) {
+ emul_write_buffer((void *)scratch_buffer, buf, status, processor, cia);
+
+ /* Bugapi chops off the trailing n, but leaves it in the buffer */
+ if (scratch_buffer[status-1] == '\n' || scratch_buffer[status-1] == '\r')
+ status--;
+ }
+
+ zfree(scratch_buffer);
+ return status;
+}
+
static void
emul_bugapi_do_write(cpu *processor,
unsigned_word cia,
@@ -321,6 +362,8 @@ emul_bugapi_do_write(cpu *processor,
if (suffix)
printf_filtered("%s", suffix);
+
+ flush_stdoutput ();
}
static int
@@ -331,6 +374,7 @@ emul_bugapi_instruction_call(cpu *processor,
{
const int call_id = cpu_registers(processor)->gpr[10];
const char *my_prefix = "bugapi";
+ unsigned char uc;
ITRACE (trace_os_emul,(" 0x%x %s, r3 = 0x%lx, r4 = 0x%lx\n",
call_id, emul_bugapi_instruction_name (call_id),
@@ -345,6 +389,19 @@ emul_bugapi_instruction_call(cpu *processor,
error("emul-bugapi: unimplemented bugapi %s from address 0x%lx\n",
emul_bugapi_instruction_name (call_id), SRR0);
break;
+ /* read a single character, output r3 = byte */
+ /* FIXME: Add support to unbuffer input */
+ case _INCHR:
+ if (read (0, &uc, 1) < 0)
+ uc = 0;
+ cpu_registers(processor)->gpr[3] = uc;
+ break;
+ /* read a line of at most 256 bytes, r3 = ptr to 1st byte, output r3 = ptr to last byte+1 */
+ case _INLN:
+ cpu_registers(processor)->gpr[3] += emul_bugapi_do_read(processor, cia,
+ cpu_registers(processor)->gpr[3],
+ 256);
+ break;
/* output a character, r3 = character */
case _OUTCHR:
printf_filtered("%c", (char)cpu_registers(processor)->gpr[3]);
diff --git a/sim/ppc/emul_netbsd.c b/sim/ppc/emul_netbsd.c
index 27de365..3fc64bc 100644
--- a/sim/ppc/emul_netbsd.c
+++ b/sim/ppc/emul_netbsd.c
@@ -360,6 +360,8 @@ do_write(os_emul_data *emul,
status = write(d, scratch_buffer, nbytes);
emul_write_status(processor, status, errno);
zfree(scratch_buffer);
+
+ flush_stdoutput();
}
diff --git a/sim/ppc/main.c b/sim/ppc/main.c
index 41791a1..7837782 100644
--- a/sim/ppc/main.c
+++ b/sim/ppc/main.c
@@ -1,6 +1,6 @@
/* This file is part of the program psim.
- Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
+ Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
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
@@ -23,8 +23,8 @@
#include <stdio.h>
#include "psim.h"
-#include "cpu.h"
#include "options.h"
+#include "device.h" /* FIXME: psim should provide the interface */
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
@@ -43,10 +43,6 @@
#endif
extern char **environ;
-extern char *optarg;
-extern int optind;
-extern int optopt;
-extern int opterr;
void
printf_filtered(const char *msg, ...)
@@ -58,6 +54,12 @@ printf_filtered(const char *msg, ...)
}
void
+flush_stdoutput(void)
+{
+ fflush (stdout);
+}
+
+void
error (char *msg, ...)
{
va_list ap;
@@ -83,14 +85,6 @@ zfree(void *chunk)
free(chunk);
}
-static void
-usage(void)
-{
- printf_filtered("Usage:\n\tpsim [ -t <trace-option> ] [-m model] [-i] [-I] <image> [ <image-args> ... ]\n");
- trace_usage();
- error("");
-}
-
int
main(int argc, char **argv)
{
@@ -98,56 +92,35 @@ main(int argc, char **argv)
const char *name_of_file;
char *arg_;
psim_status status;
- int letter;
- int print_info = 0;
-
- /* check for arguments -- note sim_calls.c also contains argument processing
- code for the simulator linked within gdb. */
- while ((letter = getopt (argc, argv, "Iim:t:")) != EOF)
- {
- switch (letter) {
- case 't':
- trace_option(optarg);
- break;
- case 'm':
- model_set(optarg);
- break;
- case 'i':
- print_info = 1;
- break;
- case 'I':
- current_model_issue = MODEL_ISSUE_PROCESS;
- print_info = 2;
- break;
- default:
- usage();
- }
- }
- if (optind >= argc)
- usage();
- name_of_file = argv[optind];
+ device *root = psim_tree();
+
+ /* parse the arguments */
+ argv = psim_options(root, argv + 1);
+ if (argv[0] == NULL)
+ psim_usage(0);
+ name_of_file = argv[0];
if (ppc_trace[trace_opts])
print_options ();
/* create the simulator */
- system = psim_create(name_of_file);
+ system = psim_create(name_of_file, root);
/* fudge the environment so that _=prog-name */
- arg_ = (char*)zalloc(strlen(argv[optind]) + strlen("_=") + 1);
+ arg_ = (char*)zalloc(strlen(argv[0]) + strlen("_=") + 1);
strcpy(arg_, "_=");
- strcat(arg_, argv[optind]);
+ strcat(arg_, argv[0]);
putenv(arg_);
/* initialize it */
psim_init(system);
- psim_stack(system, &argv[optind], environ);
+ psim_stack(system, argv, environ);
psim_run(system);
/* any final clean up */
- if (print_info)
- psim_print_info (system, print_info);
+ if (ppc_trace[trace_print_info])
+ psim_print_info (system, ppc_trace[trace_print_info]);
/* why did we stop */
status = psim_get_status(system);