1 1.1 christos /* This file is part of the program psim. 2 1.1 christos 3 1.1 christos Copyright (C) 1994-1995,1998, Andrew Cagney <cagney (at) highland.com.au> 4 1.1 christos 5 1.1 christos This program is free software; you can redistribute it and/or modify 6 1.1 christos it under the terms of the GNU General Public License as published by 7 1.1.1.2 christos the Free Software Foundation; either version 3 of the License, or 8 1.1 christos (at your option) any later version. 9 1.1 christos 10 1.1 christos This program is distributed in the hope that it will be useful, 11 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 12 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 1.1 christos GNU General Public License for more details. 14 1.1 christos 15 1.1 christos You should have received a copy of the GNU General Public License 16 1.1.1.2 christos along with this program; if not, see <http://www.gnu.org/licenses/>. 17 1.1 christos 18 1.1 christos */ 19 1.1 christos 20 1.1 christos 21 1.1 christos #ifndef _SIM_CALLBACKS_H_ 22 1.1 christos #define _SIM_CALLBACKS_H_ 23 1.1 christos 24 1.1.1.3 christos #include "ansidecl.h" 25 1.1.1.3 christos 26 1.1 christos /* Simulator output: 27 1.1 christos 28 1.1 christos Functions to report diagnostic information to the user. */ 29 1.1 christos 30 1.1 christos #define printf_filtered sim_io_printf_filtered 31 1.1 christos void sim_io_printf_filtered 32 1.1.1.3 christos (const char *msg, ...) ATTRIBUTE_PRINTF_1; 33 1.1 christos 34 1.1.1.3 christos extern void error (const char *msg, ...) 35 1.1.1.3 christos ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2); 36 1.1 christos 37 1.1 christos /* External environment: 38 1.1 christos 39 1.1 christos Some HOST OS's require regular polling so that external events such 40 1.1 christos as GUI io can be handled. */ 41 1.1 christos 42 1.1 christos void sim_io_poll_quit 43 1.1 christos (void); 44 1.1 christos 45 1.1 christos 46 1.1 christos 47 1.1 christos /* Model I/O: 48 1.1 christos 49 1.1 christos These functions provide the interface between the modeled targets 50 1.1 christos standard input and output streams and the hosts external 51 1.1 christos environment. 52 1.1 christos 53 1.1 christos The underlying model is responsible for co-ordinating I/O 54 1.1 christos interactions such as: 55 1.1 christos 56 1.1 christos main() 57 1.1 christos { 58 1.1 christos const char mess[] = "Hello World\r\n"; 59 1.1 christos int out; 60 1.1 christos out = dup(1); 61 1.1 christos close(1); 62 1.1 christos write(out, mess, sizeof(mess)) 63 1.1 christos } 64 1.1 christos 65 1.1 christos That is to say, the underlying model would, in implementing dup() 66 1.1 christos recorded the fact that any output directed at fid-OUT should be 67 1.1 christos displayed using sim_io_write_stdout(). While for the code stub: 68 1.1 christos 69 1.1 christos main() 70 1.1 christos { 71 1.1 christos const char mess[] = "Hello World\r\n"; 72 1.1 christos int out; 73 1.1 christos close(1); 74 1.1 christos out = open("output", 0x0001|0x0200, 0); // write+create 75 1.1 christos out = dup(1); 76 1.1 christos write(out, mess, sizeof(mess)) 77 1.1 christos } 78 1.1 christos 79 1.1 christos would result in output to fid-1 being directed towards the file 80 1.1 christos "output". */ 81 1.1 christos 82 1.1 christos 83 1.1 christos int 84 1.1 christos sim_io_write_stdout 85 1.1 christos (const char *buf, 86 1.1 christos int sizeof_buf); 87 1.1 christos 88 1.1 christos int 89 1.1 christos sim_io_write_stderr 90 1.1 christos (const char *buf, 91 1.1 christos int sizeof_buf); 92 1.1 christos 93 1.1 christos /* read results */ 94 1.1 christos enum { sim_io_eof = -1, sim_io_not_ready = -2, }; /* See: IEEE 1275 */ 95 1.1 christos 96 1.1 christos int 97 1.1 christos sim_io_read_stdin 98 1.1 christos (char *buf, 99 1.1 christos int sizeof_buf); 100 1.1 christos 101 1.1 christos #define flush_stdoutput sim_io_flush_stdoutput 102 1.1 christos void sim_io_flush_stdoutput 103 1.1 christos (void); 104 1.1 christos 105 1.1.1.3 christos /* TODO: Untangle this SIM_DESC forward decl someday. */ 106 1.1.1.3 christos typedef struct sim_state *SIM_DESC; 107 1.1.1.3 christos void sim_io_error (SIM_DESC sd, 108 1.1.1.3 christos const char *fmt, 109 1.1.1.3 christos ...) 110 1.1.1.3 christos ATTRIBUTE_PRINTF (2, 3) 111 1.1.1.3 christos ATTRIBUTE_NORETURN; 112 1.1 christos 113 1.1 christos /* Simulator instance. */ 114 1.1 christos extern psim *simulator; 115 1.1 christos 116 1.1 christos 117 1.1 christos /* Memory management with an allocator that clears memory before use. */ 118 1.1 christos 119 1.1 christos void *zalloc 120 1.1 christos (long size); 121 1.1 christos 122 1.1 christos #define ZALLOC(TYPE) (TYPE*)zalloc(sizeof (TYPE)) 123 1.1 christos 124 1.1 christos #endif 125