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"
42 pal - glue logic device containing assorted junk
48 Typical hardware dependant hack. This device allows the firmware
49 to gain access to all the things the firmware needs (but the OS
52 The pal contains the following registers. Except for the interrupt
53 level register, each of the below is 8 bytes in size and must be
54 accessed using correct alignment. For 16 and 32 bit accesses the
55 bytes not directed to the register are ignored:
57 |0 reset register (write)
58 |4 processor id register (read)
59 |8 interrupt port (write)
60 |9 interrupt level (write)
61 |12 processor count register (read)
62 |16 tty input fifo register (read)
63 |20 tty input status register (read)
64 |24 tty output fifo register (write)
65 |28 tty output status register (read)
67 Reset register (write) halts the simulator exiting with the
70 Processor id register (read) returns the processor number (0
71 .. N-1) of the processor performing the read.
73 The interrupt registers should be accessed as a pair (using a 16 or
74 32 bit store). The low byte specifies the interrupt port while the
75 high byte specifies the level to drive that port at. By
76 convention, the pal's interrupt ports (int0, int1, ...) are wired
77 up to the corresponding processor's level sensative external
78 interrupt pin. Eg: A two byte write to address 8 of 0x0102
79 (big-endian) will result in processor 2's external interrupt pin to
82 Processor count register (read) returns the total number of
83 processors active in the current simulation.
85 TTY input fifo register (read), if the TTY input status register
86 indicates a character is available by being nonzero, returns the
87 next available character from the pal's tty input port.
89 Similarly, the TTY output fifo register (write), if the TTY output
90 status register indicates the output fifo is not full by being
91 nonzero, outputs the character written to the tty's output port.
97 reg = <address> <size> (required)
99 Specify the address (within the parent bus) that this device is to
107 hw_pal_reset_register
= 0x0,
108 hw_pal_cpu_nr_register
= 0x4,
109 hw_pal_int_register
= 0x8,
110 hw_pal_nr_cpu_register
= 0xa,
111 hw_pal_read_fifo
= 0x10,
112 hw_pal_read_status
= 0x14,
113 hw_pal_write_fifo
= 0x18,
114 hw_pal_write_status
= 0x1a,
115 hw_pal_address_mask
= 0x1f,
119 typedef struct _hw_pal_console_buffer
{
122 } hw_pal_console_buffer
;
124 typedef struct _hw_pal_device
{
125 hw_pal_console_buffer input
;
126 hw_pal_console_buffer output
;
131 /* check the console for an available character */
133 scan_hw_pal(hw_pal_device
*hw_pal
)
137 count
= sim_io_read_stdin(&c
, sizeof(c
));
139 case sim_io_not_ready
:
141 hw_pal
->input
.buffer
= 0;
142 hw_pal
->input
.status
= 0;
145 hw_pal
->input
.buffer
= c
;
146 hw_pal
->input
.status
= 1;
150 /* write the character to the hw_pal */
152 write_hw_pal(hw_pal_device
*hw_pal
,
155 sim_io_write_stdout(&val
, 1);
156 hw_pal
->output
.buffer
= val
;
157 hw_pal
->output
.status
= 1;
162 hw_pal_io_read_buffer_callback(device
*me
,
170 hw_pal_device
*hw_pal
= (hw_pal_device
*)device_data(me
);
172 switch (addr
& hw_pal_address_mask
) {
173 case hw_pal_cpu_nr_register
:
174 val
= cpu_nr(processor
);
175 DTRACE(pal
, ("read - cpu-nr %d\n", val
));
177 case hw_pal_nr_cpu_register
:
178 val
= tree_find_integer_property(me
, "/openprom/options/smp");
179 DTRACE(pal
, ("read - nr-cpu %d\n", val
));
181 case hw_pal_read_fifo
:
182 val
= hw_pal
->input
.buffer
;
183 DTRACE(pal
, ("read - input-fifo %d\n", val
));
185 case hw_pal_read_status
:
187 val
= hw_pal
->input
.status
;
188 DTRACE(pal
, ("read - input-status %d\n", val
));
190 case hw_pal_write_fifo
:
191 val
= hw_pal
->output
.buffer
;
192 DTRACE(pal
, ("read - output-fifo %d\n", val
));
194 case hw_pal_write_status
:
195 val
= hw_pal
->output
.status
;
196 DTRACE(pal
, ("read - output-status %d\n", val
));
200 DTRACE(pal
, ("read - ???\n"));
202 memset(dest
, 0, nr_bytes
);
203 *(unsigned_1
*)dest
= val
;
209 hw_pal_io_write_buffer_callback(device
*me
,
217 hw_pal_device
*hw_pal
= (hw_pal_device
*)device_data(me
);
218 unsigned_1
*byte
= (unsigned_1
*)source
;
220 switch (addr
& hw_pal_address_mask
) {
221 case hw_pal_reset_register
:
222 cpu_halt(processor
, cia
, was_exited
, byte
[0]);
224 case hw_pal_int_register
:
225 device_interrupt_event(me
,
227 (nr_bytes
> 1 ? byte
[1] : 0), /* val */
230 case hw_pal_read_fifo
:
231 hw_pal
->input
.buffer
= byte
[0];
232 DTRACE(pal
, ("write - input-fifo %d\n", byte
[0]));
234 case hw_pal_read_status
:
235 hw_pal
->input
.status
= byte
[0];
236 DTRACE(pal
, ("write - input-status %d\n", byte
[0]));
238 case hw_pal_write_fifo
:
239 write_hw_pal(hw_pal
, byte
[0]);
240 DTRACE(pal
, ("write - output-fifo %d\n", byte
[0]));
242 case hw_pal_write_status
:
243 hw_pal
->output
.status
= byte
[0];
244 DTRACE(pal
, ("write - output-status %d\n", byte
[0]));
251 /* instances of the hw_pal device */
254 hw_pal_instance_delete_callback(device_instance
*instance
)
256 /* nothing to delete, the hw_pal is attached to the device */
261 hw_pal_instance_read_callback(device_instance
*instance
,
265 DITRACE(pal
, ("read - %s (%ld)", (const char*)buf
, (long int)len
));
266 return sim_io_read_stdin(buf
, len
);
270 hw_pal_instance_write_callback(device_instance
*instance
,
275 const char *chp
= buf
;
276 hw_pal_device
*hw_pal
= device_instance_data(instance
);
277 DITRACE(pal
, ("write - %s (%ld)", (const char*)buf
, (long int)len
));
278 for (i
= 0; i
< len
; i
++)
279 write_hw_pal(hw_pal
, chp
[i
]);
280 sim_io_flush_stdoutput();
284 static const device_instance_callbacks hw_pal_instance_callbacks
= {
285 hw_pal_instance_delete_callback
,
286 hw_pal_instance_read_callback
,
287 hw_pal_instance_write_callback
,
290 static device_instance
*
291 hw_pal_create_instance(device
*me
,
295 return device_create_instance_from(me
, NULL
,
298 &hw_pal_instance_callbacks
);
301 static const device_interrupt_port_descriptor hw_pal_interrupt_ports
[] = {
302 { "int", 0, MAX_NR_PROCESSORS
},
308 hw_pal_attach_address(device
*me
,
316 hw_pal_device
*pal
= (hw_pal_device
*)device_data(me
);
321 static device_callbacks
const hw_pal_callbacks
= {
322 { generic_device_init_address
, },
323 { hw_pal_attach_address
, }, /* address */
324 { hw_pal_io_read_buffer_callback
,
325 hw_pal_io_write_buffer_callback
, },
327 { NULL
, NULL
, hw_pal_interrupt_ports
}, /* interrupt */
328 { generic_device_unit_decode
,
329 generic_device_unit_encode
,
330 generic_device_address_to_attach_address
,
331 generic_device_size_to_attach_size
},
332 hw_pal_create_instance
,
337 hw_pal_create(const char *name
,
338 const device_unit
*unit_address
,
341 /* create the descriptor */
342 hw_pal_device
*hw_pal
= ZALLOC(hw_pal_device
);
343 hw_pal
->output
.status
= 1;
344 hw_pal
->output
.buffer
= '\0';
345 hw_pal
->input
.status
= 0;
346 hw_pal
->input
.buffer
= '\0';
351 const device_descriptor hw_pal_device_descriptor
[] = {
352 { "pal", hw_pal_create
, &hw_pal_callbacks
},
356 #endif /* _HW_PAL_C_ */