14e98e3e1Schristos /* The common simulator framework for GDB, the GNU Debugger. 24e98e3e1Schristos 3*88241920Schristos Copyright 2002-2024 Free Software Foundation, Inc. 44e98e3e1Schristos 54e98e3e1Schristos Contributed by Andrew Cagney and Red Hat. 64e98e3e1Schristos 74e98e3e1Schristos This file is part of GDB. 84e98e3e1Schristos 94e98e3e1Schristos This program is free software; you can redistribute it and/or modify 104e98e3e1Schristos it under the terms of the GNU General Public License as published by 114e98e3e1Schristos the Free Software Foundation; either version 3 of the License, or 124e98e3e1Schristos (at your option) any later version. 134e98e3e1Schristos 144e98e3e1Schristos This program is distributed in the hope that it will be useful, 154e98e3e1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 164e98e3e1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 174e98e3e1Schristos GNU General Public License for more details. 184e98e3e1Schristos 194e98e3e1Schristos You should have received a copy of the GNU General Public License 204e98e3e1Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 214e98e3e1Schristos 224e98e3e1Schristos 234e98e3e1Schristos #ifndef SIM_CORE_H 244e98e3e1Schristos #define SIM_CORE_H 254e98e3e1Schristos 26*88241920Schristos #include "symcat.h" 274e98e3e1Schristos 284e98e3e1Schristos /* core signals (error conditions) 294e98e3e1Schristos Define SIM_CORE_SIGNAL to catch these signals - see sim-core.c for 304e98e3e1Schristos details. */ 314e98e3e1Schristos 324e98e3e1Schristos typedef enum { 334e98e3e1Schristos sim_core_unmapped_signal, 344e98e3e1Schristos sim_core_unaligned_signal, 354e98e3e1Schristos nr_sim_core_signals, 364e98e3e1Schristos } sim_core_signals; 374e98e3e1Schristos 384e98e3e1Schristos /* Type of SIM_CORE_SIGNAL handler. */ 394e98e3e1Schristos typedef void (SIM_CORE_SIGNAL_FN) 404e98e3e1Schristos (SIM_DESC sd, sim_cpu *cpu, sim_cia cia, unsigned map, int nr_bytes, 414e98e3e1Schristos address_word addr, transfer_type transfer, sim_core_signals sig); 424e98e3e1Schristos 43*88241920Schristos extern SIM_CORE_SIGNAL_FN sim_core_signal ATTRIBUTE_NORETURN; 444e98e3e1Schristos 454e98e3e1Schristos 464e98e3e1Schristos /* basic types */ 474e98e3e1Schristos 484e98e3e1Schristos typedef struct _sim_core_mapping sim_core_mapping; 494e98e3e1Schristos struct _sim_core_mapping { 504e98e3e1Schristos /* common */ 514e98e3e1Schristos int level; 524e98e3e1Schristos int space; 534e98e3e1Schristos unsigned_word base; 544e98e3e1Schristos unsigned_word bound; 554e98e3e1Schristos unsigned_word nr_bytes; 564e98e3e1Schristos unsigned mask; 574e98e3e1Schristos /* memory map */ 584e98e3e1Schristos void *free_buffer; 594e98e3e1Schristos void *buffer; 604e98e3e1Schristos /* callback map */ 614e98e3e1Schristos struct hw *device; 624e98e3e1Schristos /* tracing */ 634e98e3e1Schristos int trace; 644e98e3e1Schristos /* growth */ 654e98e3e1Schristos sim_core_mapping *next; 664e98e3e1Schristos }; 674e98e3e1Schristos 684e98e3e1Schristos typedef struct _sim_core_map sim_core_map; 694e98e3e1Schristos struct _sim_core_map { 704e98e3e1Schristos sim_core_mapping *first; 714e98e3e1Schristos }; 724e98e3e1Schristos 734e98e3e1Schristos 744e98e3e1Schristos typedef struct _sim_core_common { 754e98e3e1Schristos sim_core_map map[nr_maps]; 764e98e3e1Schristos } sim_core_common; 774e98e3e1Schristos 784e98e3e1Schristos 794e98e3e1Schristos /* Main core structure */ 804e98e3e1Schristos 814e98e3e1Schristos typedef struct _sim_core sim_core; 824e98e3e1Schristos struct _sim_core { 834e98e3e1Schristos sim_core_common common; 844e98e3e1Schristos address_word byte_xor; /* apply xor universally */ 854e98e3e1Schristos }; 864e98e3e1Schristos 874e98e3e1Schristos 884e98e3e1Schristos /* Per CPU distributed component of the core. At present this is 894e98e3e1Schristos mostly a clone of the global core data structure. */ 904e98e3e1Schristos 914e98e3e1Schristos typedef struct _sim_cpu_core { 924e98e3e1Schristos sim_core_common common; 934559860eSchristos address_word byte_xor[WITH_XOR_ENDIAN + 1]; /* +1 to avoid zero-sized array */ 944e98e3e1Schristos } sim_cpu_core; 954e98e3e1Schristos 964e98e3e1Schristos 974e98e3e1Schristos /* Install the "core" module. */ 984e98e3e1Schristos 994e98e3e1Schristos extern SIM_RC sim_core_install (SIM_DESC sd); 1004e98e3e1Schristos 1014e98e3e1Schristos 1024e98e3e1Schristos 1034e98e3e1Schristos /* Create a memory region within the core. 1044e98e3e1Schristos 1054e98e3e1Schristos CPU - when non NULL, specifes the single processor that the memory 1064e98e3e1Schristos space is to be attached to. (INIMPLEMENTED). 1074e98e3e1Schristos 1084e98e3e1Schristos LEVEL - specifies the ordering of the memory region. Lower regions 1094e98e3e1Schristos are searched first. Within a level, memory regions can not 1104e98e3e1Schristos overlap. 1114e98e3e1Schristos 1124e98e3e1Schristos MAPMASK - Bitmask specifying the memory maps that the region is to 1134e98e3e1Schristos be attached to. Typically the enums sim-basics.h:access_* are used. 1144e98e3e1Schristos 1154e98e3e1Schristos ADDRESS_SPACE - For device regions, a MAP:ADDRESS pair is 1164e98e3e1Schristos translated into ADDRESS_SPACE:OFFSET before being passed to the 1174e98e3e1Schristos client device. 1184e98e3e1Schristos 119ba340e45Schristos MODULO - Specifies that accesses to the region [ADDR .. ADDR+NR_BYTES) 120ba340e45Schristos should be mapped onto the sub region [ADDR .. ADDR+MODULO). The modulo 121ba340e45Schristos value must be a power of two. 1224e98e3e1Schristos 1234e98e3e1Schristos DEVICE - When non NULL, indicates that this is a callback memory 1244e98e3e1Schristos space and specified device's memory callback handler should be 1254e98e3e1Schristos called. 1264e98e3e1Schristos 1274e98e3e1Schristos OPTIONAL_BUFFER - when non NULL, specifies the buffer to use for 1284e98e3e1Schristos data read & written to the region. Normally a more efficient 1294e98e3e1Schristos internal structure is used. It is assumed that buffer is allocated 1304e98e3e1Schristos such that the byte alignmed of OPTIONAL_BUFFER matches ADDR vis 1314e98e3e1Schristos (OPTIONAL_BUFFER % 8) == (ADDR % 8)). It is defined to be a sub-optimal 1324e98e3e1Schristos hook that allows clients to do nasty things that the interface doesn't 1334e98e3e1Schristos accomodate. */ 1344e98e3e1Schristos 1354e98e3e1Schristos extern void sim_core_attach 1364e98e3e1Schristos (SIM_DESC sd, 1374e98e3e1Schristos sim_cpu *cpu, 1384e98e3e1Schristos int level, 1394e98e3e1Schristos unsigned mapmask, 1404e98e3e1Schristos int address_space, 1414e98e3e1Schristos address_word addr, 1424e98e3e1Schristos address_word nr_bytes, 1434e98e3e1Schristos unsigned modulo, 1444e98e3e1Schristos struct hw *client, 1454e98e3e1Schristos void *optional_buffer); 1464e98e3e1Schristos 1474e98e3e1Schristos 1484e98e3e1Schristos /* Delete a memory section within the core. 1494e98e3e1Schristos 1504e98e3e1Schristos */ 1514e98e3e1Schristos 1524e98e3e1Schristos extern void sim_core_detach 1534e98e3e1Schristos (SIM_DESC sd, 1544e98e3e1Schristos sim_cpu *cpu, 1554e98e3e1Schristos int level, 1564e98e3e1Schristos int address_space, 1574e98e3e1Schristos address_word addr); 1584e98e3e1Schristos 1594e98e3e1Schristos 1604e98e3e1Schristos /* Variable sized read/write 1614e98e3e1Schristos 1624e98e3e1Schristos Transfer a variable sized block of raw data between the host and 1634e98e3e1Schristos target. Should any problems occur, the number of bytes 1644e98e3e1Schristos successfully transfered is returned. 1654e98e3e1Schristos 1664e98e3e1Schristos No host/target byte endian conversion is performed. No xor-endian 1674e98e3e1Schristos conversion is performed. 1684e98e3e1Schristos 1694e98e3e1Schristos If CPU argument, when non NULL, specifies the processor specific 1704e98e3e1Schristos address map that is to be used in the transfer. */ 1714e98e3e1Schristos 1724e98e3e1Schristos 1734e98e3e1Schristos extern unsigned sim_core_read_buffer 1744e98e3e1Schristos (SIM_DESC sd, 1754e98e3e1Schristos sim_cpu *cpu, 1764e98e3e1Schristos unsigned map, 1774e98e3e1Schristos void *buffer, 1784e98e3e1Schristos address_word addr, 1794e98e3e1Schristos unsigned nr_bytes); 1804e98e3e1Schristos 1814e98e3e1Schristos extern unsigned sim_core_write_buffer 1824e98e3e1Schristos (SIM_DESC sd, 1834e98e3e1Schristos sim_cpu *cpu, 1844e98e3e1Schristos unsigned map, 1854e98e3e1Schristos const void *buffer, 1864e98e3e1Schristos address_word addr, 1874e98e3e1Schristos unsigned nr_bytes); 1884e98e3e1Schristos 1894e98e3e1Schristos 1904e98e3e1Schristos 1914e98e3e1Schristos /* Configure the core's XOR endian transfer mode. Only applicable 1924e98e3e1Schristos when WITH_XOR_ENDIAN is enabled. 1934e98e3e1Schristos 1944e98e3e1Schristos Targets suporting XOR endian, shall notify the core of any changes 1954e98e3e1Schristos in state via this call. 1964e98e3e1Schristos 1974e98e3e1Schristos The CPU argument, when non NULL, specifes the single processor that 1984e98e3e1Schristos the xor-endian configuration is to be applied to. */ 1994e98e3e1Schristos 2004e98e3e1Schristos extern void sim_core_set_xor 2014e98e3e1Schristos (SIM_DESC sd, 2024e98e3e1Schristos sim_cpu *cpu, 2034e98e3e1Schristos int is_xor); 2044e98e3e1Schristos 2054e98e3e1Schristos 2064e98e3e1Schristos /* XOR version of variable sized read/write. 2074e98e3e1Schristos 2084e98e3e1Schristos Transfer a variable sized block of raw data between the host and 2094e98e3e1Schristos target. Should any problems occur, the number of bytes 2104e98e3e1Schristos successfully transfered is returned. 2114e98e3e1Schristos 2124e98e3e1Schristos No host/target byte endian conversion is performed. If applicable 2134e98e3e1Schristos (WITH_XOR_ENDIAN and xor-endian set), xor-endian conversion *is* 2144e98e3e1Schristos performed. 2154e98e3e1Schristos 2164e98e3e1Schristos If CPU argument, when non NULL, specifies the processor specific 2174e98e3e1Schristos address map that is to be used in the transfer. */ 2184e98e3e1Schristos 2194e98e3e1Schristos extern unsigned sim_core_xor_read_buffer 2204e98e3e1Schristos (SIM_DESC sd, 2214e98e3e1Schristos sim_cpu *cpu, 2224e98e3e1Schristos unsigned map, 2234e98e3e1Schristos void *buffer, 2244e98e3e1Schristos address_word addr, 2254e98e3e1Schristos unsigned nr_bytes); 2264e98e3e1Schristos 2274e98e3e1Schristos extern unsigned sim_core_xor_write_buffer 2284e98e3e1Schristos (SIM_DESC sd, 2294e98e3e1Schristos sim_cpu *cpu, 2304e98e3e1Schristos unsigned map, 2314e98e3e1Schristos const void *buffer, 2324e98e3e1Schristos address_word addr, 2334e98e3e1Schristos unsigned nr_bytes); 2344e98e3e1Schristos 2354e98e3e1Schristos 236a2e2270fSchristos /* Translate an address based on a map. */ 237a2e2270fSchristos 238a2e2270fSchristos extern void *sim_core_trans_addr 239a2e2270fSchristos (SIM_DESC sd, 240a2e2270fSchristos sim_cpu *cpu, 241a2e2270fSchristos unsigned map, 242a2e2270fSchristos address_word addr); 243a2e2270fSchristos 2444e98e3e1Schristos 2454e98e3e1Schristos /* Fixed sized, processor oriented, read/write. 2464e98e3e1Schristos 2474e98e3e1Schristos Transfer a fixed amout of memory between the host and target. The 2484e98e3e1Schristos data transfered is translated from/to host to/from target byte 2494e98e3e1Schristos order (including xor endian). Should the transfer fail, the 2504e98e3e1Schristos operation shall abort (no return). 2514e98e3e1Schristos 2524b169a6bSchristos ALIGNED assumes that the specified ADDRESS is correctly aligned 2534e98e3e1Schristos for an N byte transfer (no alignment checks are made). Passing an 2544e98e3e1Schristos incorrectly aligned ADDRESS is erroneous. 2554e98e3e1Schristos 2564e98e3e1Schristos UNALIGNED checks/modifies the ADDRESS according to the requirements 2574e98e3e1Schristos of an N byte transfer. Action, as defined by WITH_ALIGNMENT, being 2584e98e3e1Schristos taken should the check fail. 2594e98e3e1Schristos 2604b169a6bSchristos MISALIGNED transfers the data regardless. 2614e98e3e1Schristos 2624e98e3e1Schristos Misaligned xor-endian accesses are broken into a sequence of 2634e98e3e1Schristos transfers each <= WITH_XOR_ENDIAN bytes */ 2644e98e3e1Schristos 2654e98e3e1Schristos 2664e98e3e1Schristos #define DECLARE_SIM_CORE_WRITE_N(ALIGNMENT,N,M) \ 2674e98e3e1Schristos INLINE_SIM_CORE\ 2684e98e3e1Schristos (void) sim_core_write_##ALIGNMENT##_##N \ 2694e98e3e1Schristos (sim_cpu *cpu, \ 2704e98e3e1Schristos sim_cia cia, \ 2714e98e3e1Schristos unsigned map, \ 2724e98e3e1Schristos address_word addr, \ 2734e98e3e1Schristos unsigned_##M val); 2744e98e3e1Schristos 2754e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(aligned,1,1) 2764e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(aligned,2,2) 2774e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(aligned,4,4) 2784e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(aligned,8,8) 2794e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(aligned,16,16) 2804e98e3e1Schristos 2814e98e3e1Schristos #define sim_core_write_unaligned_1 sim_core_write_aligned_1 2824e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(unaligned,2,2) 2834e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(unaligned,4,4) 2844e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(unaligned,8,8) 2854e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(unaligned,16,16) 2864e98e3e1Schristos 2874e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(misaligned,3,4) 2884e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(misaligned,5,8) 2894e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(misaligned,6,8) 2904e98e3e1Schristos DECLARE_SIM_CORE_WRITE_N(misaligned,7,8) 2914e98e3e1Schristos 2924e98e3e1Schristos #define sim_core_write_1 sim_core_write_aligned_1 2934e98e3e1Schristos #define sim_core_write_2 sim_core_write_aligned_2 2944e98e3e1Schristos #define sim_core_write_4 sim_core_write_aligned_4 2954e98e3e1Schristos #define sim_core_write_8 sim_core_write_aligned_8 2964e98e3e1Schristos #define sim_core_write_16 sim_core_write_aligned_16 2974e98e3e1Schristos 2984e98e3e1Schristos #define sim_core_write_unaligned_word XCONCAT2(sim_core_write_unaligned_,WITH_TARGET_WORD_BITSIZE) 2994e98e3e1Schristos #define sim_core_write_aligned_word XCONCAT2(sim_core_write_aligned_,WITH_TARGET_WORD_BITSIZE) 3004e98e3e1Schristos #define sim_core_write_word XCONCAT2(sim_core_write_,WITH_TARGET_WORD_BITSIZE) 3014e98e3e1Schristos 3024e98e3e1Schristos #undef DECLARE_SIM_CORE_WRITE_N 3034e98e3e1Schristos 3044e98e3e1Schristos 3054e98e3e1Schristos #define DECLARE_SIM_CORE_READ_N(ALIGNMENT,N,M) \ 3064e98e3e1Schristos INLINE_SIM_CORE\ 3074e98e3e1Schristos (unsigned_##M) sim_core_read_##ALIGNMENT##_##N \ 3084e98e3e1Schristos (sim_cpu *cpu, \ 3094e98e3e1Schristos sim_cia cia, \ 3104e98e3e1Schristos unsigned map, \ 3114e98e3e1Schristos address_word addr); 3124e98e3e1Schristos 3134e98e3e1Schristos DECLARE_SIM_CORE_READ_N(aligned,1,1) 3144e98e3e1Schristos DECLARE_SIM_CORE_READ_N(aligned,2,2) 3154e98e3e1Schristos DECLARE_SIM_CORE_READ_N(aligned,4,4) 3164e98e3e1Schristos DECLARE_SIM_CORE_READ_N(aligned,8,8) 3174e98e3e1Schristos DECLARE_SIM_CORE_READ_N(aligned,16,16) 3184e98e3e1Schristos 3194e98e3e1Schristos #define sim_core_read_unaligned_1 sim_core_read_aligned_1 3204e98e3e1Schristos DECLARE_SIM_CORE_READ_N(unaligned,2,2) 3214e98e3e1Schristos DECLARE_SIM_CORE_READ_N(unaligned,4,4) 3224e98e3e1Schristos DECLARE_SIM_CORE_READ_N(unaligned,8,8) 3234e98e3e1Schristos DECLARE_SIM_CORE_READ_N(unaligned,16,16) 3244e98e3e1Schristos 3254e98e3e1Schristos DECLARE_SIM_CORE_READ_N(misaligned,3,4) 3264e98e3e1Schristos DECLARE_SIM_CORE_READ_N(misaligned,5,8) 3274e98e3e1Schristos DECLARE_SIM_CORE_READ_N(misaligned,6,8) 3284e98e3e1Schristos DECLARE_SIM_CORE_READ_N(misaligned,7,8) 3294e98e3e1Schristos 3304e98e3e1Schristos 3314e98e3e1Schristos #define sim_core_read_1 sim_core_read_aligned_1 3324e98e3e1Schristos #define sim_core_read_2 sim_core_read_aligned_2 3334e98e3e1Schristos #define sim_core_read_4 sim_core_read_aligned_4 3344e98e3e1Schristos #define sim_core_read_8 sim_core_read_aligned_8 3354e98e3e1Schristos #define sim_core_read_16 sim_core_read_aligned_16 3364e98e3e1Schristos 3374e98e3e1Schristos #define sim_core_read_unaligned_word XCONCAT2(sim_core_read_unaligned_,WITH_TARGET_WORD_BITSIZE) 3384e98e3e1Schristos #define sim_core_read_aligned_word XCONCAT2(sim_core_read_aligned_,WITH_TARGET_WORD_BITSIZE) 3394e98e3e1Schristos #define sim_core_read_word XCONCAT2(sim_core_read_,WITH_TARGET_WORD_BITSIZE) 3404e98e3e1Schristos 3414e98e3e1Schristos #undef DECLARE_SIM_CORE_READ_N 3424e98e3e1Schristos 3434e98e3e1Schristos #endif 344