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