1 /* The common simulator framework for GDB, the GNU Debugger. 2 3 Copyright 2002 Free Software Foundation, Inc. 4 5 Contributed by Andrew Cagney and Red Hat. 6 7 This file is part of GDB. 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 2 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 59 Temple Place - Suite 330, 22 Boston, MA 02111-1307, USA. */ 23 24 25 #ifndef HW_INSTANCES_H 26 #define HW_INSTANCES_H 27 28 /* Instances: 29 30 As with IEEE1275, a device can be opened, creating an instance. 31 Instances provide more abstract interfaces to the underlying 32 hardware. For example, the instance methods for a disk may include 33 code that is able to interpret file systems found on disks. Such 34 methods would there for allow the manipulation of files on the 35 disks file system. The operations would be implemented using the 36 basic block I/O model provided by the disk. 37 38 This model includes methods that faciliate the creation of device 39 instance and (should a given device support it) standard operations 40 on those instances. 41 42 */ 43 44 45 struct hw_instance; 46 47 48 typedef void (hw_finish_instance_method) 49 (struct hw *hw, 50 struct hw_instance *); 51 52 extern void set_hw_finish_instance 53 (struct hw *hw, 54 hw_finish_instance_method *method); 55 56 57 /* construct an instance of the hardware */ 58 59 struct hw_instance *hw_instance_create 60 (struct hw *hw, 61 struct hw_instance *parent, 62 const char *path, 63 const char *args); 64 65 struct hw_instance *hw_instance_interceed 66 (struct hw_instance *parent, 67 const char *path, 68 const char *args); 69 70 void hw_instance_delete 71 (struct hw_instance *instance); 72 73 74 /* methods applied to an instance of the hw */ 75 76 typedef int (hw_instance_read_method) 77 (struct hw_instance *instance, 78 void *addr, 79 unsigned_cell len); 80 81 #define hw_instance_read(instance, addr, len) \ 82 ((instance)->to_instance_read ((instance), (addr), (len))) 83 84 #define set_hw_instance_read(instance, method) \ 85 ((instance)->to_instance_read = (method)) 86 87 88 typedef int (hw_instance_write_method) 89 (struct hw_instance *instance, 90 const void *addr, 91 unsigned_cell len); 92 93 #define hw_instance_write(instance, addr, len) \ 94 ((instance)->to_instance_write ((instance), (addr), (len))) 95 96 #define set_hw_instance_write(instance, method) \ 97 ((instance)->to_instance_write = (method)) 98 99 100 typedef int (hw_instance_seek_method) 101 (struct hw_instance *instance, 102 unsigned_cell pos_hi, 103 unsigned_cell pos_lo); 104 105 #define hw_instance_seek(instance, pos_hi, pos_lo) \ 106 ((instance)->to_instance_seek ((instance), (pos_hi), (pos_lo))); 107 108 #define set_hw_instance_seek(instance, method) \ 109 ((instance)->to_instance_seek = (method)) 110 111 112 int hw_instance_call_method 113 (struct hw_instance *instance, 114 const char *method, 115 int n_stack_args, 116 unsigned_cell stack_args[/*n_stack_args + 1(NULL)*/], 117 int n_stack_returns, 118 unsigned_cell stack_returns[/*n_stack_returns + 1(NULL)*/]); 119 120 121 122 /* the definition of the instance */ 123 124 #define hw_instance_hw(instance) ((instance)->hw_of_instance + 0) 125 126 #define hw_instance_path(instance) ((instance)->path_of_instance + 0) 127 128 #define hw_instance_args(instance) ((instance)->args_of_instance) 129 130 #define hw_instance_data(instance) ((instance)->data_of_instance) 131 132 #define hw_instance_system(instance) (hw_system (hw_instance_hw (instance))) 133 134 135 136 /* Finally an instance of a hardware device - keep your grubby little 137 mits off of these internals! :-) */ 138 139 struct hw_instance { 140 141 void *data_of_instance; 142 char *args_of_instance; 143 char *path_of_instance; 144 145 /* the device that owns the instance */ 146 struct hw *hw_of_instance; 147 struct hw_instance *sibling_of_instance; 148 149 /* interposed instance */ 150 struct hw_instance *parent_of_instance; 151 struct hw_instance *child_of_instance; 152 153 /* methods */ 154 hw_instance_read_method *to_instance_read; 155 hw_instance_write_method *to_instance_write; 156 hw_instance_seek_method *to_instance_seek; 157 158 }; 159 160 #endif 161