Add input support; at end of user writes, call fflush
This commit is contained in:
parent
eaf2030fff
commit
262faa5417
|
@ -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>
|
Wed Feb 21 10:39:35 1996 Michael Meissner <meissner@tiktok.cygnus.com>
|
||||||
|
|
||||||
* emul_bugapi.c (bug_mapping): New structure to map bug system
|
* emul_bugapi.c (bug_mapping): New structure to map bug system
|
||||||
|
|
|
@ -22,6 +22,20 @@
|
||||||
#ifndef _EMUL_BUGAPI_C_
|
#ifndef _EMUL_BUGAPI_C_
|
||||||
#define _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 */
|
/* from PowerPCBug Debugging Package User's Manual, part 2 of 2 and also bug.S - Dale Rahn */
|
||||||
#define _INCHR 0x000 /* Input character */
|
#define _INCHR 0x000 /* Input character */
|
||||||
|
@ -137,13 +151,6 @@ static const struct bug_map bug_mapping[] = {
|
||||||
{ _SYMBOLDA, ".SYMBOLDA -- Detach symbol table" },
|
{ _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
|
#ifndef OEA_START_ADDRESS
|
||||||
#define OEA_START_ADDRESS 0x100000
|
#define OEA_START_ADDRESS 0x100000
|
||||||
#endif
|
#endif
|
||||||
|
@ -285,6 +292,40 @@ emul_bugapi_instruction_name(int call_id)
|
||||||
return buffer;
|
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
|
static void
|
||||||
emul_bugapi_do_write(cpu *processor,
|
emul_bugapi_do_write(cpu *processor,
|
||||||
unsigned_word cia,
|
unsigned_word cia,
|
||||||
|
@ -321,6 +362,8 @@ emul_bugapi_do_write(cpu *processor,
|
||||||
|
|
||||||
if (suffix)
|
if (suffix)
|
||||||
printf_filtered("%s", suffix);
|
printf_filtered("%s", suffix);
|
||||||
|
|
||||||
|
flush_stdoutput ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -331,6 +374,7 @@ emul_bugapi_instruction_call(cpu *processor,
|
||||||
{
|
{
|
||||||
const int call_id = cpu_registers(processor)->gpr[10];
|
const int call_id = cpu_registers(processor)->gpr[10];
|
||||||
const char *my_prefix = "bugapi";
|
const char *my_prefix = "bugapi";
|
||||||
|
unsigned char uc;
|
||||||
|
|
||||||
ITRACE (trace_os_emul,(" 0x%x %s, r3 = 0x%lx, r4 = 0x%lx\n",
|
ITRACE (trace_os_emul,(" 0x%x %s, r3 = 0x%lx, r4 = 0x%lx\n",
|
||||||
call_id, emul_bugapi_instruction_name (call_id),
|
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",
|
error("emul-bugapi: unimplemented bugapi %s from address 0x%lx\n",
|
||||||
emul_bugapi_instruction_name (call_id), SRR0);
|
emul_bugapi_instruction_name (call_id), SRR0);
|
||||||
break;
|
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 */
|
/* output a character, r3 = character */
|
||||||
case _OUTCHR:
|
case _OUTCHR:
|
||||||
printf_filtered("%c", (char)cpu_registers(processor)->gpr[3]);
|
printf_filtered("%c", (char)cpu_registers(processor)->gpr[3]);
|
||||||
|
|
|
@ -360,6 +360,8 @@ do_write(os_emul_data *emul,
|
||||||
status = write(d, scratch_buffer, nbytes);
|
status = write(d, scratch_buffer, nbytes);
|
||||||
emul_write_status(processor, status, errno);
|
emul_write_status(processor, status, errno);
|
||||||
zfree(scratch_buffer);
|
zfree(scratch_buffer);
|
||||||
|
|
||||||
|
flush_stdoutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* This file is part of the program psim.
|
/* 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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -23,8 +23,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "psim.h"
|
#include "psim.h"
|
||||||
#include "cpu.h"
|
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
#include "device.h" /* FIXME: psim should provide the interface */
|
||||||
|
|
||||||
#ifdef HAVE_STDLIB_H
|
#ifdef HAVE_STDLIB_H
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -43,10 +43,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
extern char *optarg;
|
|
||||||
extern int optind;
|
|
||||||
extern int optopt;
|
|
||||||
extern int opterr;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
printf_filtered(const char *msg, ...)
|
printf_filtered(const char *msg, ...)
|
||||||
|
@ -57,6 +53,12 @@ printf_filtered(const char *msg, ...)
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
flush_stdoutput(void)
|
||||||
|
{
|
||||||
|
fflush (stdout);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
error (char *msg, ...)
|
error (char *msg, ...)
|
||||||
{
|
{
|
||||||
|
@ -83,14 +85,6 @@ zfree(void *chunk)
|
||||||
free(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
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -98,56 +92,35 @@ main(int argc, char **argv)
|
||||||
const char *name_of_file;
|
const char *name_of_file;
|
||||||
char *arg_;
|
char *arg_;
|
||||||
psim_status status;
|
psim_status status;
|
||||||
int letter;
|
device *root = psim_tree();
|
||||||
int print_info = 0;
|
|
||||||
|
|
||||||
/* check for arguments -- note sim_calls.c also contains argument processing
|
/* parse the arguments */
|
||||||
code for the simulator linked within gdb. */
|
argv = psim_options(root, argv + 1);
|
||||||
while ((letter = getopt (argc, argv, "Iim:t:")) != EOF)
|
if (argv[0] == NULL)
|
||||||
{
|
psim_usage(0);
|
||||||
switch (letter) {
|
name_of_file = argv[0];
|
||||||
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];
|
|
||||||
|
|
||||||
if (ppc_trace[trace_opts])
|
if (ppc_trace[trace_opts])
|
||||||
print_options ();
|
print_options ();
|
||||||
|
|
||||||
/* create the simulator */
|
/* create the simulator */
|
||||||
system = psim_create(name_of_file);
|
system = psim_create(name_of_file, root);
|
||||||
|
|
||||||
/* fudge the environment so that _=prog-name */
|
/* 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_, "_=");
|
strcpy(arg_, "_=");
|
||||||
strcat(arg_, argv[optind]);
|
strcat(arg_, argv[0]);
|
||||||
putenv(arg_);
|
putenv(arg_);
|
||||||
|
|
||||||
/* initialize it */
|
/* initialize it */
|
||||||
psim_init(system);
|
psim_init(system);
|
||||||
psim_stack(system, &argv[optind], environ);
|
psim_stack(system, argv, environ);
|
||||||
|
|
||||||
psim_run(system);
|
psim_run(system);
|
||||||
|
|
||||||
/* any final clean up */
|
/* any final clean up */
|
||||||
if (print_info)
|
if (ppc_trace[trace_print_info])
|
||||||
psim_print_info (system, print_info);
|
psim_print_info (system, ppc_trace[trace_print_info]);
|
||||||
|
|
||||||
/* why did we stop */
|
/* why did we stop */
|
||||||
status = psim_get_status(system);
|
status = psim_get_status(system);
|
||||||
|
|
Loading…
Reference in New Issue