xref: /netbsd-src/external/gpl3/gdb/dist/sim/m68hc11/interrupts.h (revision 9b2a9e00295c5af9c57a466f299054d5910e47d6)
14e98e3e1Schristos /* interrupts.h -- 68HC11 Interrupts Emulation
2*9b2a9e00Schristos    Copyright 1999-2024 Free Software Foundation, Inc.
34e98e3e1Schristos    Written by Stephane Carrez (stcarrez@worldnet.fr)
44e98e3e1Schristos 
54e98e3e1Schristos This file is part of GDB, GAS, and the GNU binutils.
64e98e3e1Schristos 
74e98e3e1Schristos This program is free software; you can redistribute it and/or modify
84e98e3e1Schristos it under the terms of the GNU General Public License as published by
94e98e3e1Schristos the Free Software Foundation; either version 3 of the License, or
104e98e3e1Schristos (at your option) any later version.
114e98e3e1Schristos 
124e98e3e1Schristos This program is distributed in the hope that it will be useful,
134e98e3e1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
144e98e3e1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
154e98e3e1Schristos GNU General Public License for more details.
164e98e3e1Schristos 
174e98e3e1Schristos You should have received a copy of the GNU General Public License
184e98e3e1Schristos along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
194e98e3e1Schristos 
204e98e3e1Schristos #ifndef _M6811_SIM_INTERRUPTS_H
214e98e3e1Schristos #define _M6811_SIM_INTERRUPTS_H
224e98e3e1Schristos 
234e98e3e1Schristos /* Definition of 68HC11 interrupts.  These enum are used as an index
244e98e3e1Schristos    in the interrupt table.  */
254e98e3e1Schristos enum M6811_INT
264e98e3e1Schristos {
274e98e3e1Schristos   M6811_INT_RESERVED1 = 0,
284e98e3e1Schristos   M6811_INT_RESERVED2,
294e98e3e1Schristos   M6811_INT_RESERVED3,
304e98e3e1Schristos   M6811_INT_RESERVED4,
314e98e3e1Schristos   M6811_INT_RESERVED5,
324e98e3e1Schristos   M6811_INT_RESERVED6,
334e98e3e1Schristos   M6811_INT_RESERVED7,
344e98e3e1Schristos   M6811_INT_RESERVED8,
354e98e3e1Schristos 
364e98e3e1Schristos   M6811_INT_RESERVED9,
374e98e3e1Schristos   M6811_INT_RESERVED10,
384e98e3e1Schristos   M6811_INT_RESERVED11,
394e98e3e1Schristos 
404e98e3e1Schristos   M6811_INT_SCI,
414e98e3e1Schristos   M6811_INT_SPI,
424e98e3e1Schristos   M6811_INT_AINPUT,
434e98e3e1Schristos   M6811_INT_AOVERFLOW,
444e98e3e1Schristos   M6811_INT_TCTN,
454e98e3e1Schristos 
464e98e3e1Schristos   M6811_INT_OUTCMP5,
474e98e3e1Schristos   M6811_INT_OUTCMP4,
484e98e3e1Schristos   M6811_INT_OUTCMP3,
494e98e3e1Schristos   M6811_INT_OUTCMP2,
504e98e3e1Schristos   M6811_INT_OUTCMP1,
514e98e3e1Schristos 
524e98e3e1Schristos   M6811_INT_INCMP3,
534e98e3e1Schristos   M6811_INT_INCMP2,
544e98e3e1Schristos   M6811_INT_INCMP1,
554e98e3e1Schristos 
564e98e3e1Schristos   M6811_INT_RT,
574e98e3e1Schristos   M6811_INT_IRQ,
584e98e3e1Schristos   M6811_INT_XIRQ,
594e98e3e1Schristos   M6811_INT_SWI,
604e98e3e1Schristos   M6811_INT_ILLEGAL,
614e98e3e1Schristos 
624e98e3e1Schristos   M6811_INT_COPRESET,
634e98e3e1Schristos   M6811_INT_COPFAIL,
644e98e3e1Schristos 
654e98e3e1Schristos   M6811_INT_RESET,
664e98e3e1Schristos   M6811_INT_NUMBER
674e98e3e1Schristos };
684e98e3e1Schristos 
694e98e3e1Schristos 
704e98e3e1Schristos /* Structure to describe how to recognize an interrupt in the
714e98e3e1Schristos    68hc11 IO regs.  */
724e98e3e1Schristos struct interrupt_def
734e98e3e1Schristos {
744e98e3e1Schristos   enum M6811_INT   int_number;
754e98e3e1Schristos   unsigned char    int_paddr;
764e98e3e1Schristos   unsigned char    int_mask;
774e98e3e1Schristos   unsigned char    enable_paddr;
784e98e3e1Schristos   unsigned char    enabled_mask;
794e98e3e1Schristos };
804e98e3e1Schristos 
814e98e3e1Schristos #define MAX_INT_HISTORY 64
824e98e3e1Schristos 
834e98e3e1Schristos /* Structure used to keep track of interrupt history.
844e98e3e1Schristos    This is used to understand in which order interrupts were
854e98e3e1Schristos    raised and when.  */
864e98e3e1Schristos struct interrupt_history
874e98e3e1Schristos {
884e98e3e1Schristos   enum M6811_INT   type;
894e98e3e1Schristos 
904e98e3e1Schristos   /* CPU cycle when interrupt handler is called.  */
914b169a6bSchristos   int64_t         taken_cycle;
924e98e3e1Schristos 
934e98e3e1Schristos   /* CPU cycle when the interrupt is first raised by the device.  */
944b169a6bSchristos   int64_t         raised_cycle;
954e98e3e1Schristos };
964e98e3e1Schristos 
974e98e3e1Schristos #define SIM_STOP_WHEN_RAISED 1
984e98e3e1Schristos #define SIM_STOP_WHEN_TAKEN  2
994e98e3e1Schristos 
1004e98e3e1Schristos /* Information and control of pending interrupts.  */
1014e98e3e1Schristos struct interrupt
1024e98e3e1Schristos {
1034e98e3e1Schristos   /* CPU cycle when the interrupt is raised by the device.  */
1044b169a6bSchristos   int64_t         cpu_cycle;
1054e98e3e1Schristos 
1064e98e3e1Schristos   /* Number of times the interrupt was raised.  */
1074e98e3e1Schristos   unsigned long    raised_count;
1084e98e3e1Schristos 
1094e98e3e1Schristos   /* Controls whether we must stop the simulator.  */
1104e98e3e1Schristos   int              stop_mode;
1114e98e3e1Schristos };
1124e98e3e1Schristos 
1134e98e3e1Schristos 
1144e98e3e1Schristos /* Management of 68HC11 interrupts:
1154e98e3e1Schristos     - We use a table of 'interrupt_def' to describe the interrupts that must be
1164e98e3e1Schristos       raised depending on IO register flags (enable and present flags).
1174e98e3e1Schristos     - We keep a mask of pending interrupts.  This mask is refreshed by
1184e98e3e1Schristos       calling 'interrupts_update_pending'.  It must be refreshed each time
1194e98e3e1Schristos       an IO register is changed.
1204e98e3e1Schristos     - 'interrupts_process' must be called after each insn. It has two purposes:
1214e98e3e1Schristos       first it maintains a min/max count of CPU cycles between which interrupts
1224e98e3e1Schristos       are masked; second it checks for pending interrupts and raise one if
1234e98e3e1Schristos       interrupts are enabled.  */
1244e98e3e1Schristos struct interrupts {
125796c32c9Schristos   sim_cpu           *cpu;
1264e98e3e1Schristos 
1274e98e3e1Schristos   /* Mask of current pending interrupts.  */
1284e98e3e1Schristos   unsigned long     pending_mask;
1294e98e3e1Schristos 
1304e98e3e1Schristos   /* Address of vector table.  This is set depending on the
1314e98e3e1Schristos      68hc11 init mode.  */
1324b169a6bSchristos   uint16_t            vectors_addr;
1334e98e3e1Schristos 
1344e98e3e1Schristos   /* Priority order of interrupts.  This is controlled by setting the HPRIO
1354e98e3e1Schristos      IO register.  */
1364e98e3e1Schristos   enum M6811_INT    interrupt_order[M6811_INT_NUMBER];
1374e98e3e1Schristos   struct interrupt  interrupts[M6811_INT_NUMBER];
1384e98e3e1Schristos 
1394e98e3e1Schristos   /* Simulator statistics to report useful debug information to users.  */
1404e98e3e1Schristos 
1414e98e3e1Schristos   /* - Max/Min number of CPU cycles executed with interrupts masked.  */
1424b169a6bSchristos   int64_t          start_mask_cycle;
1434b169a6bSchristos   int64_t          min_mask_cycles;
1444b169a6bSchristos   int64_t          max_mask_cycles;
1454b169a6bSchristos   int64_t          last_mask_cycles;
1464e98e3e1Schristos 
1474e98e3e1Schristos   /* - Same for XIRQ.  */
1484b169a6bSchristos   int64_t          xirq_start_mask_cycle;
1494b169a6bSchristos   int64_t          xirq_min_mask_cycles;
1504b169a6bSchristos   int64_t          xirq_max_mask_cycles;
1514b169a6bSchristos   int64_t          xirq_last_mask_cycles;
1524e98e3e1Schristos 
1534e98e3e1Schristos   /* - Total number of interrupts raised.  */
1544e98e3e1Schristos   unsigned long     nb_interrupts_raised;
1554e98e3e1Schristos 
1564e98e3e1Schristos   /* Interrupt history to help understand which interrupts
1574e98e3e1Schristos      were raised recently and in which order.  */
1584e98e3e1Schristos   int               history_index;
1594e98e3e1Schristos   struct interrupt_history interrupts_history[MAX_INT_HISTORY];
1604e98e3e1Schristos };
1614e98e3e1Schristos 
162796c32c9Schristos extern void interrupts_initialize     (SIM_DESC sd, sim_cpu *cpu);
1634e98e3e1Schristos extern void interrupts_reset          (struct interrupts* interrupts);
1644e98e3e1Schristos extern void interrupts_update_pending (struct interrupts* interrupts);
1654e98e3e1Schristos extern int  interrupts_get_current    (struct interrupts* interrupts);
1664e98e3e1Schristos extern int  interrupts_process        (struct interrupts* interrupts);
1674e98e3e1Schristos extern void interrupts_raise          (struct interrupts* interrupts,
1684e98e3e1Schristos                                        enum M6811_INT number);
1694e98e3e1Schristos 
1704e98e3e1Schristos extern void interrupts_info           (SIM_DESC sd,
1714e98e3e1Schristos                                        struct interrupts* interrupts);
1724e98e3e1Schristos 
1734e98e3e1Schristos #endif
174