1 /* This file is part of the program GDB, the GNU debugger.
3 Copyright (C) 1998-2024 Free Software Foundation, Inc.
4 Contributed by Cygnus Solutions.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 /* This must come before any other includes. */
30 mn103iop - mn103002 I/O ports 0-3.
35 Implements the mn103002 i/o ports as described in the mn103002 user guide.
40 reg = <ioport-addr> <ioport-size> ...
48 /* The I/O ports' registers' address block */
50 struct mn103iop_block
{
57 enum io_port_register_types
{
89 typedef struct _mn10300_ioport
{
90 uint8_t output
, output_mode
, control
, pin
;
91 struct hw_event
*event
;
97 struct mn103iop_block block
[NR_BLOCKS
];
98 mn10300_ioport port
[NR_PORTS
];
103 /* Finish off the partially created hw device. Attach our local
104 callbacks. Wire up our port names etc */
106 static hw_io_read_buffer_method mn103iop_io_read_buffer
;
107 static hw_io_write_buffer_method mn103iop_io_write_buffer
;
110 attach_mn103iop_regs (struct hw
*me
,
111 struct mn103iop
*io_port
)
114 unsigned_word attach_address
;
116 unsigned attach_size
;
117 reg_property_spec reg
;
119 if (hw_find_property (me
, "reg") == NULL
)
120 hw_abort (me
, "Missing \"reg\" property");
122 for (i
=0; i
< NR_BLOCKS
; ++i
)
124 if (!hw_find_reg_array_property (me
, "reg", i
, ®
))
125 hw_abort (me
, "\"reg\" property must contain five addr/size entries");
126 hw_unit_address_to_attach_address (hw_parent (me
),
131 io_port
->block
[i
].base
= attach_address
;
132 hw_unit_size_to_attach_size (hw_parent (me
),
135 io_port
->block
[i
].bound
= attach_address
+ (attach_size
- 1);
136 hw_attach_address (hw_parent (me
),
138 attach_space
, attach_address
, attach_size
,
144 mn103iop_finish (struct hw
*me
)
146 struct mn103iop
*io_port
;
149 io_port
= HW_ZALLOC (me
, struct mn103iop
);
150 set_hw_data (me
, io_port
);
151 set_hw_io_read_buffer (me
, mn103iop_io_read_buffer
);
152 set_hw_io_write_buffer (me
, mn103iop_io_write_buffer
);
154 /* Attach ourself to our parent bus */
155 attach_mn103iop_regs (me
, io_port
);
157 /* Initialize the i/o port registers. */
158 for ( i
=0; i
<NR_PORTS
; ++i
)
160 io_port
->port
[i
].output
= 0;
161 io_port
->port
[i
].output_mode
= 0;
162 io_port
->port
[i
].control
= 0;
163 io_port
->port
[i
].pin
= 0;
165 io_port
->port
[2].output_mode
= 0xff;
167 io_port
->p4ss
= 0x0f;
174 decode_addr (struct hw
*me
,
175 struct mn103iop
*io_port
,
176 unsigned_word address
)
178 unsigned_word offset
;
179 offset
= address
- io_port
->block
[0].base
;
182 case 0x00: return P0OUT
;
183 case 0x01: return P1OUT
;
184 case 0x04: return P2OUT
;
185 case 0x05: return P3OUT
;
186 case 0x20: return P0MD
;
187 case 0x21: return P1MD
;
188 case 0x24: return P2MD
;
189 case 0x25: return P3MD
;
190 case 0x44: return P2SS
;
191 case 0x48: return P4SS
;
192 case 0x60: return P0DIR
;
193 case 0x61: return P1DIR
;
194 case 0x64: return P2DIR
;
195 case 0x65: return P3DIR
;
196 case 0x80: return P0IN
;
197 case 0x81: return P1IN
;
198 case 0x84: return P2IN
;
199 case 0x85: return P3IN
;
202 hw_abort (me
, "bad address");
210 read_output_reg (struct hw
*me
,
211 struct mn103iop
*io_port
,
212 unsigned_word io_port_reg
,
218 *(uint8_t *)dest
= io_port
->port
[io_port_reg
].output
;
222 hw_abort (me
, "bad read size of %d bytes from P%dOUT.", nr_bytes
,
229 read_output_mode_reg (struct hw
*me
,
230 struct mn103iop
*io_port
,
231 unsigned_word io_port_reg
,
237 /* check if there are fields which can't be written and
238 take appropriate action depending what bits are set */
239 *(uint8_t *)dest
= io_port
->port
[io_port_reg
].output_mode
;
243 hw_abort (me
, "bad read size of %d bytes to P%dMD.", nr_bytes
,
250 read_control_reg (struct hw
*me
,
251 struct mn103iop
*io_port
,
252 unsigned_word io_port_reg
,
258 *(uint8_t *)dest
= io_port
->port
[io_port_reg
].control
;
262 hw_abort (me
, "bad read size of %d bytes to P%dDIR.", nr_bytes
,
269 read_pin_reg (struct hw
*me
,
270 struct mn103iop
*io_port
,
271 unsigned_word io_port_reg
,
277 *(uint8_t *)dest
= io_port
->port
[io_port_reg
].pin
;
281 hw_abort (me
, "bad read size of %d bytes to P%dIN.", nr_bytes
,
288 read_dedicated_control_reg (struct hw
*me
,
289 struct mn103iop
*io_port
,
290 unsigned_word io_port_reg
,
296 /* select on io_port_reg: */
297 if ( io_port_reg
== P2SS
)
299 *(uint8_t *)dest
= io_port
->p2ss
;
303 *(uint8_t *)dest
= io_port
->p4ss
;
308 hw_abort (me
, "bad read size of %d bytes to PSS.", nr_bytes
);
314 mn103iop_io_read_buffer (struct hw
*me
,
320 struct mn103iop
*io_port
= hw_data (me
);
321 enum io_port_register_types io_port_reg
;
322 HW_TRACE ((me
, "read 0x%08lx %d", (long) base
, (int) nr_bytes
));
324 io_port_reg
= decode_addr (me
, io_port
, base
);
327 /* Port output registers */
332 read_output_reg(me
, io_port
, io_port_reg
-P0OUT
, dest
, nr_bytes
);
335 /* Port output mode registers */
340 read_output_mode_reg(me
, io_port
, io_port_reg
-P0MD
, dest
, nr_bytes
);
343 /* Port control registers */
348 read_control_reg(me
, io_port
, io_port_reg
-P0DIR
, dest
, nr_bytes
);
351 /* Port pin registers */
355 read_pin_reg(me
, io_port
, io_port_reg
-P0IN
, dest
, nr_bytes
);
360 read_dedicated_control_reg(me
, io_port
, io_port_reg
, dest
, nr_bytes
);
364 hw_abort(me
, "invalid address");
372 write_output_reg (struct hw
*me
,
373 struct mn103iop
*io_port
,
374 unsigned_word io_port_reg
,
378 uint8_t buf
= *(uint8_t *)source
;
381 if ( io_port_reg
== 3 && (buf
& 0xfc) != 0 )
383 hw_abort(me
, "Cannot write to read-only bits of P3OUT.");
387 io_port
->port
[io_port_reg
].output
= buf
;
392 hw_abort (me
, "bad read size of %d bytes from P%dOUT.", nr_bytes
,
399 write_output_mode_reg (struct hw
*me
,
400 struct mn103iop
*io_port
,
401 unsigned_word io_port_reg
,
405 uint8_t buf
= *(uint8_t *)source
;
408 /* check if there are fields which can't be written and
409 take appropriate action depending what bits are set */
410 if ( ( io_port_reg
== 3 && (buf
& 0xfc) != 0 )
411 || ( (io_port_reg
== 0 || io_port_reg
== 1) && (buf
& 0xfe) != 0 ) )
413 hw_abort(me
, "Cannot write to read-only bits of output mode register.");
417 io_port
->port
[io_port_reg
].output_mode
= buf
;
422 hw_abort (me
, "bad write size of %d bytes to P%dMD.", nr_bytes
,
429 write_control_reg (struct hw
*me
,
430 struct mn103iop
*io_port
,
431 unsigned_word io_port_reg
,
435 uint8_t buf
= *(uint8_t *)source
;
438 if ( io_port_reg
== 3 && (buf
& 0xfc) != 0 )
440 hw_abort(me
, "Cannot write to read-only bits of P3DIR.");
444 io_port
->port
[io_port_reg
].control
= buf
;
449 hw_abort (me
, "bad write size of %d bytes to P%dDIR.", nr_bytes
,
456 write_dedicated_control_reg (struct hw
*me
,
457 struct mn103iop
*io_port
,
458 unsigned_word io_port_reg
,
462 uint8_t buf
= *(uint8_t *)source
;
465 /* select on io_port_reg: */
466 if ( io_port_reg
== P2SS
)
468 if ( (buf
& 0xfc) != 0 )
470 hw_abort(me
, "Cannot write to read-only bits in p2ss.");
479 if ( (buf
& 0xf0) != 0 )
481 hw_abort(me
, "Cannot write to read-only bits in p4ss.");
491 hw_abort (me
, "bad write size of %d bytes to PSS.", nr_bytes
);
497 mn103iop_io_write_buffer (struct hw
*me
,
503 struct mn103iop
*io_port
= hw_data (me
);
504 enum io_port_register_types io_port_reg
;
505 HW_TRACE ((me
, "write 0x%08lx %d", (long) base
, (int) nr_bytes
));
507 io_port_reg
= decode_addr (me
, io_port
, base
);
510 /* Port output registers */
515 write_output_reg(me
, io_port
, io_port_reg
-P0OUT
, source
, nr_bytes
);
518 /* Port output mode registers */
523 write_output_mode_reg(me
, io_port
, io_port_reg
-P0MD
, source
, nr_bytes
);
526 /* Port control registers */
531 write_control_reg(me
, io_port
, io_port_reg
-P0DIR
, source
, nr_bytes
);
534 /* Port pin registers */
538 hw_abort(me
, "Cannot write to pin register.");
543 write_dedicated_control_reg(me
, io_port
, io_port_reg
, source
, nr_bytes
);
547 hw_abort(me
, "invalid address");
554 const struct hw_descriptor dv_mn103iop_descriptor
[] = {
555 { "mn103iop", mn103iop_finish
, },