1 /* This file is part of the program psim.
3 Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
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.
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.
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/>.
24 #ifndef STATIC_INLINE_HW_PAL
25 #define STATIC_INLINE_HW_PAL STATIC_INLINE
28 #include "device_table.h"
51 pal - glue logic device containing assorted junk
57 Typical hardware dependant hack. This device allows the firmware
58 to gain access to all the things the firmware needs (but the OS
61 The pal contains the following registers. Except for the interrupt
62 level register, each of the below is 8 bytes in size and must be
63 accessed using correct alignment. For 16 and 32 bit accesses the
64 bytes not directed to the register are ignored:
66 |0 reset register (write)
67 |4 processor id register (read)
68 |8 interrupt port (write)
69 |9 interrupt level (write)
70 |12 processor count register (read)
71 |16 tty input fifo register (read)
72 |20 tty input status register (read)
73 |24 tty output fifo register (write)
74 |28 tty output status register (read)
76 Reset register (write) halts the simulator exiting with the
79 Processor id register (read) returns the processor number (0
80 .. N-1) of the processor performing the read.
82 The interrupt registers should be accessed as a pair (using a 16 or
83 32 bit store). The low byte specifies the interrupt port while the
84 high byte specifies the level to drive that port at. By
85 convention, the pal's interrupt ports (int0, int1, ...) are wired
86 up to the corresponding processor's level sensative external
87 interrupt pin. Eg: A two byte write to address 8 of 0x0102
88 (big-endian) will result in processor 2's external interrupt pin to
91 Processor count register (read) returns the total number of
92 processors active in the current simulation.
94 TTY input fifo register (read), if the TTY input status register
95 indicates a character is available by being nonzero, returns the
96 next available character from the pal's tty input port.
98 Similarly, the TTY output fifo register (write), if the TTY output
99 status register indicates the output fifo is not full by being
100 nonzero, outputs the character written to the tty's output port.
106 reg = <address> <size> (required)
108 Specify the address (within the parent bus) that this device is to
116 hw_pal_reset_register
= 0x0,
117 hw_pal_cpu_nr_register
= 0x4,
118 hw_pal_int_register
= 0x8,
119 hw_pal_nr_cpu_register
= 0xa,
120 hw_pal_read_fifo
= 0x10,
121 hw_pal_read_status
= 0x14,
122 hw_pal_write_fifo
= 0x18,
123 hw_pal_write_status
= 0x1a,
124 hw_pal_address_mask
= 0x1f,
128 typedef struct _hw_pal_console_buffer
{
131 } hw_pal_console_buffer
;
133 typedef struct _hw_pal_device
{
134 hw_pal_console_buffer input
;
135 hw_pal_console_buffer output
;
140 /* check the console for an available character */
142 scan_hw_pal(hw_pal_device
*hw_pal
)
146 count
= sim_io_read_stdin(&c
, sizeof(c
));
148 case sim_io_not_ready
:
150 hw_pal
->input
.buffer
= 0;
151 hw_pal
->input
.status
= 0;
154 hw_pal
->input
.buffer
= c
;
155 hw_pal
->input
.status
= 1;
159 /* write the character to the hw_pal */
161 write_hw_pal(hw_pal_device
*hw_pal
,
164 sim_io_write_stdout(&val
, 1);
165 hw_pal
->output
.buffer
= val
;
166 hw_pal
->output
.status
= 1;
171 hw_pal_io_read_buffer_callback(device
*me
,
179 hw_pal_device
*hw_pal
= (hw_pal_device
*)device_data(me
);
181 switch (addr
& hw_pal_address_mask
) {
182 case hw_pal_cpu_nr_register
:
183 val
= cpu_nr(processor
);
184 DTRACE(pal
, ("read - cpu-nr %d\n", val
));
186 case hw_pal_nr_cpu_register
:
187 val
= tree_find_integer_property(me
, "/openprom/options/smp");
188 DTRACE(pal
, ("read - nr-cpu %d\n", val
));
190 case hw_pal_read_fifo
:
191 val
= hw_pal
->input
.buffer
;
192 DTRACE(pal
, ("read - input-fifo %d\n", val
));
194 case hw_pal_read_status
:
196 val
= hw_pal
->input
.status
;
197 DTRACE(pal
, ("read - input-status %d\n", val
));
199 case hw_pal_write_fifo
:
200 val
= hw_pal
->output
.buffer
;
201 DTRACE(pal
, ("read - output-fifo %d\n", val
));
203 case hw_pal_write_status
:
204 val
= hw_pal
->output
.status
;
205 DTRACE(pal
, ("read - output-status %d\n", val
));
209 DTRACE(pal
, ("read - ???\n"));
211 memset(dest
, 0, nr_bytes
);
212 *(unsigned_1
*)dest
= val
;
218 hw_pal_io_write_buffer_callback(device
*me
,
226 hw_pal_device
*hw_pal
= (hw_pal_device
*)device_data(me
);
227 unsigned_1
*byte
= (unsigned_1
*)source
;
229 switch (addr
& hw_pal_address_mask
) {
230 case hw_pal_reset_register
:
231 cpu_halt(processor
, cia
, was_exited
, byte
[0]);
233 case hw_pal_int_register
:
234 device_interrupt_event(me
,
236 (nr_bytes
> 1 ? byte
[1] : 0), /* val */
239 case hw_pal_read_fifo
:
240 hw_pal
->input
.buffer
= byte
[0];
241 DTRACE(pal
, ("write - input-fifo %d\n", byte
[0]));
243 case hw_pal_read_status
:
244 hw_pal
->input
.status
= byte
[0];
245 DTRACE(pal
, ("write - input-status %d\n", byte
[0]));
247 case hw_pal_write_fifo
:
248 write_hw_pal(hw_pal
, byte
[0]);
249 DTRACE(pal
, ("write - output-fifo %d\n", byte
[0]));
251 case hw_pal_write_status
:
252 hw_pal
->output
.status
= byte
[0];
253 DTRACE(pal
, ("write - output-status %d\n", byte
[0]));
260 /* instances of the hw_pal device */
263 hw_pal_instance_delete_callback(device_instance
*instance
)
265 /* nothing to delete, the hw_pal is attached to the device */
270 hw_pal_instance_read_callback(device_instance
*instance
,
274 DITRACE(pal
, ("read - %s (%ld)", (const char*)buf
, (long int)len
));
275 return sim_io_read_stdin(buf
, len
);
279 hw_pal_instance_write_callback(device_instance
*instance
,
284 const char *chp
= buf
;
285 hw_pal_device
*hw_pal
= device_instance_data(instance
);
286 DITRACE(pal
, ("write - %s (%ld)", (const char*)buf
, (long int)len
));
287 for (i
= 0; i
< len
; i
++)
288 write_hw_pal(hw_pal
, chp
[i
]);
289 sim_io_flush_stdoutput();
293 static const device_instance_callbacks hw_pal_instance_callbacks
= {
294 hw_pal_instance_delete_callback
,
295 hw_pal_instance_read_callback
,
296 hw_pal_instance_write_callback
,
299 static device_instance
*
300 hw_pal_create_instance(device
*me
,
304 return device_create_instance_from(me
, NULL
,
307 &hw_pal_instance_callbacks
);
310 static const device_interrupt_port_descriptor hw_pal_interrupt_ports
[] = {
311 { "int", 0, MAX_NR_PROCESSORS
},
317 hw_pal_attach_address(device
*me
,
325 hw_pal_device
*pal
= (hw_pal_device
*)device_data(me
);
330 static device_callbacks
const hw_pal_callbacks
= {
331 { generic_device_init_address
, },
332 { hw_pal_attach_address
, }, /* address */
333 { hw_pal_io_read_buffer_callback
,
334 hw_pal_io_write_buffer_callback
, },
336 { NULL
, NULL
, hw_pal_interrupt_ports
}, /* interrupt */
337 { generic_device_unit_decode
,
338 generic_device_unit_encode
,
339 generic_device_address_to_attach_address
,
340 generic_device_size_to_attach_size
},
341 hw_pal_create_instance
,
346 hw_pal_create(const char *name
,
347 const device_unit
*unit_address
,
350 /* create the descriptor */
351 hw_pal_device
*hw_pal
= ZALLOC(hw_pal_device
);
352 hw_pal
->output
.status
= 1;
353 hw_pal
->output
.buffer
= '\0';
354 hw_pal
->input
.status
= 0;
355 hw_pal
->input
.buffer
= '\0';
360 const device_descriptor hw_pal_device_descriptor
[] = {
361 { "pal", hw_pal_create
, &hw_pal_callbacks
},
365 #endif /* _HW_PAL_C_ */