xref: /netbsd-src/external/gpl3/gdb/dist/sim/common/dv-core.c (revision 88241920d21b339bf319c0e979ffda80c49a2936)
198b9484cSchristos /* The common simulator framework for GDB, the GNU Debugger.
298b9484cSchristos 
3*88241920Schristos    Copyright 2002-2024 Free Software Foundation, Inc.
498b9484cSchristos 
598b9484cSchristos    Contributed by Andrew Cagney and Red Hat.
698b9484cSchristos 
798b9484cSchristos    This file is part of GDB.
898b9484cSchristos 
998b9484cSchristos    This program is free software; you can redistribute it and/or modify
1098b9484cSchristos    it under the terms of the GNU General Public License as published by
1198b9484cSchristos    the Free Software Foundation; either version 3 of the License, or
1298b9484cSchristos    (at your option) any later version.
1398b9484cSchristos 
1498b9484cSchristos    This program is distributed in the hope that it will be useful,
1598b9484cSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1698b9484cSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1798b9484cSchristos    GNU General Public License for more details.
1898b9484cSchristos 
1998b9484cSchristos    You should have received a copy of the GNU General Public License
2098b9484cSchristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
2198b9484cSchristos 
224b169a6bSchristos /* This must come before any other includes.  */
234b169a6bSchristos #include "defs.h"
2498b9484cSchristos 
2598b9484cSchristos #include "sim-main.h"
2698b9484cSchristos #include "hw-main.h"
2798b9484cSchristos 
2898b9484cSchristos /* DEVICE
2998b9484cSchristos 
3098b9484cSchristos    core - root of the device tree
3198b9484cSchristos 
3298b9484cSchristos    DESCRIPTION
3398b9484cSchristos 
3498b9484cSchristos    The core device, positioned at the root of the device tree appears
3598b9484cSchristos    to its child devices as a normal device just like every other
3698b9484cSchristos    device in the tree.
3798b9484cSchristos 
3898b9484cSchristos    Internally it is implemented using a core object.  Requests to
3998b9484cSchristos    attach (or detach) address spaces are passed to that core object.
4098b9484cSchristos    Requests to transfer (DMA) data are reflected back down the device
4198b9484cSchristos    tree using the core_map data transfer methods.
4298b9484cSchristos 
4398b9484cSchristos    PROPERTIES
4498b9484cSchristos 
4598b9484cSchristos    None.
4698b9484cSchristos 
4798b9484cSchristos    */
4898b9484cSchristos 
4998b9484cSchristos 
5098b9484cSchristos static void
5198b9484cSchristos dv_core_attach_address_callback (struct hw *me,
5298b9484cSchristos 				 int level,
5398b9484cSchristos 				 int space,
5498b9484cSchristos 				 address_word addr,
5598b9484cSchristos 				 address_word nr_bytes,
5698b9484cSchristos 				 struct hw *client)
5798b9484cSchristos {
5898b9484cSchristos   HW_TRACE ((me, "attach - level=%d, space=%d, addr=0x%lx, nr_bytes=%ld, client=%s",
5998b9484cSchristos 	     level, space, (unsigned long) addr, (unsigned long) nr_bytes, hw_path (client)));
6098b9484cSchristos   /* NOTE: At preset the space is assumed to be zero.  Perhaphs the
6198b9484cSchristos      space should be mapped onto something for instance: space0 -
6298b9484cSchristos      unified memory; space1 - IO memory; ... */
6398b9484cSchristos   sim_core_attach (hw_system (me),
6498b9484cSchristos 		   NULL, /*cpu*/
6598b9484cSchristos 		   level,
6698b9484cSchristos 		   access_read_write_exec,
6798b9484cSchristos 		   space, addr,
6898b9484cSchristos 		   nr_bytes,
6998b9484cSchristos 		   0, /* modulo */
7098b9484cSchristos 		   client,
7198b9484cSchristos 		   NULL);
7298b9484cSchristos }
7398b9484cSchristos 
7498b9484cSchristos 
75*88241920Schristos static void
76*88241920Schristos dv_core_detach_address_callback (struct hw *me,
77*88241920Schristos 				 int level,
78*88241920Schristos 				 int space,
79*88241920Schristos 				 address_word addr,
80*88241920Schristos 				 address_word nr_bytes,
81*88241920Schristos 				 struct hw *client)
82*88241920Schristos {
83*88241920Schristos   HW_TRACE ((me, "detach - level=%d, space=%d, addr=0x%lx, nr_bytes=%ld, client=%s",
84*88241920Schristos 	     level, space, (unsigned long) addr, (unsigned long) nr_bytes, hw_path (client)));
85*88241920Schristos   /* NOTE: At preset the space is assumed to be zero.  Perhaphs the
86*88241920Schristos      space should be mapped onto something for instance: space0 -
87*88241920Schristos      unified memory; space1 - IO memory; ... */
88*88241920Schristos   sim_core_detach (hw_system (me), NULL, /*cpu*/ level, space, addr);
89*88241920Schristos }
90*88241920Schristos 
91*88241920Schristos 
9298b9484cSchristos static unsigned
9398b9484cSchristos dv_core_dma_read_buffer_callback (struct hw *me,
9498b9484cSchristos 				  void *dest,
9598b9484cSchristos 				  int space,
9698b9484cSchristos 				  unsigned_word addr,
9798b9484cSchristos 				  unsigned nr_bytes)
9898b9484cSchristos {
9998b9484cSchristos   return sim_core_read_buffer (hw_system (me),
10098b9484cSchristos 			       NULL, /*CPU*/
10198b9484cSchristos 			       space, /*???*/
10298b9484cSchristos 			       dest,
10398b9484cSchristos 			       addr,
10498b9484cSchristos 			       nr_bytes);
10598b9484cSchristos }
10698b9484cSchristos 
10798b9484cSchristos 
10898b9484cSchristos static unsigned
10998b9484cSchristos dv_core_dma_write_buffer_callback (struct hw *me,
11098b9484cSchristos 				   const void *source,
11198b9484cSchristos 				   int space,
11298b9484cSchristos 				   unsigned_word addr,
11398b9484cSchristos 				   unsigned nr_bytes,
11498b9484cSchristos 				   int violate_read_only_section)
11598b9484cSchristos {
11698b9484cSchristos   return sim_core_write_buffer (hw_system (me),
11798b9484cSchristos 				NULL, /*cpu*/
11898b9484cSchristos 				space, /*???*/
11998b9484cSchristos 				source,
12098b9484cSchristos 				addr,
12198b9484cSchristos 				nr_bytes);
12298b9484cSchristos }
12398b9484cSchristos 
12498b9484cSchristos 
12598b9484cSchristos static void
12698b9484cSchristos dv_core_finish (struct hw *me)
12798b9484cSchristos {
12898b9484cSchristos   set_hw_attach_address (me, dv_core_attach_address_callback);
129*88241920Schristos   set_hw_detach_address (me, dv_core_detach_address_callback);
13098b9484cSchristos   set_hw_dma_write_buffer (me, dv_core_dma_write_buffer_callback);
13198b9484cSchristos   set_hw_dma_read_buffer (me, dv_core_dma_read_buffer_callback);
13298b9484cSchristos }
13398b9484cSchristos 
13498b9484cSchristos const struct hw_descriptor dv_core_descriptor[] = {
13598b9484cSchristos   { "core", dv_core_finish, },
13698b9484cSchristos   { NULL, NULL },
13798b9484cSchristos };
138