Home | History | Annotate | Line # | Download | only in m68hc11
interrupts.h revision 1.1.1.1.8.1
      1          1.1  christos /* interrupts.h -- 68HC11 Interrupts Emulation
      2  1.1.1.1.8.1       tls    Copyright 1999-2014 Free Software Foundation, Inc.
      3          1.1  christos    Written by Stephane Carrez (stcarrez (at) worldnet.fr)
      4          1.1  christos 
      5          1.1  christos This file is part of GDB, GAS, and the GNU binutils.
      6          1.1  christos 
      7          1.1  christos This program is free software; you can redistribute it and/or modify
      8          1.1  christos it under the terms of the GNU General Public License as published by
      9          1.1  christos the Free Software Foundation; either version 3 of the License, or
     10          1.1  christos (at your option) any later version.
     11          1.1  christos 
     12          1.1  christos This program is distributed in the hope that it will be useful,
     13          1.1  christos but WITHOUT ANY WARRANTY; without even the implied warranty of
     14          1.1  christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15          1.1  christos GNU General Public License for more details.
     16          1.1  christos 
     17          1.1  christos You should have received a copy of the GNU General Public License
     18          1.1  christos along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19          1.1  christos 
     20          1.1  christos #ifndef _M6811_SIM_INTERRUPTS_H
     21          1.1  christos #define _M6811_SIM_INTERRUPTS_H
     22          1.1  christos 
     23          1.1  christos /* Definition of 68HC11 interrupts.  These enum are used as an index
     24          1.1  christos    in the interrupt table.  */
     25          1.1  christos enum M6811_INT
     26          1.1  christos {
     27          1.1  christos   M6811_INT_RESERVED1 = 0,
     28          1.1  christos   M6811_INT_RESERVED2,
     29          1.1  christos   M6811_INT_RESERVED3,
     30          1.1  christos   M6811_INT_RESERVED4,
     31          1.1  christos   M6811_INT_RESERVED5,
     32          1.1  christos   M6811_INT_RESERVED6,
     33          1.1  christos   M6811_INT_RESERVED7,
     34          1.1  christos   M6811_INT_RESERVED8,
     35          1.1  christos 
     36          1.1  christos   M6811_INT_RESERVED9,
     37          1.1  christos   M6811_INT_RESERVED10,
     38          1.1  christos   M6811_INT_RESERVED11,
     39          1.1  christos 
     40          1.1  christos   M6811_INT_SCI,
     41          1.1  christos   M6811_INT_SPI,
     42          1.1  christos   M6811_INT_AINPUT,
     43          1.1  christos   M6811_INT_AOVERFLOW,
     44          1.1  christos   M6811_INT_TCTN,
     45          1.1  christos 
     46          1.1  christos   M6811_INT_OUTCMP5,
     47          1.1  christos   M6811_INT_OUTCMP4,
     48          1.1  christos   M6811_INT_OUTCMP3,
     49          1.1  christos   M6811_INT_OUTCMP2,
     50          1.1  christos   M6811_INT_OUTCMP1,
     51          1.1  christos 
     52          1.1  christos   M6811_INT_INCMP3,
     53          1.1  christos   M6811_INT_INCMP2,
     54          1.1  christos   M6811_INT_INCMP1,
     55          1.1  christos 
     56          1.1  christos   M6811_INT_RT,
     57          1.1  christos   M6811_INT_IRQ,
     58          1.1  christos   M6811_INT_XIRQ,
     59          1.1  christos   M6811_INT_SWI,
     60          1.1  christos   M6811_INT_ILLEGAL,
     61          1.1  christos 
     62          1.1  christos   M6811_INT_COPRESET,
     63          1.1  christos   M6811_INT_COPFAIL,
     64          1.1  christos 
     65          1.1  christos   M6811_INT_RESET,
     66          1.1  christos   M6811_INT_NUMBER
     67          1.1  christos };
     68          1.1  christos 
     69          1.1  christos 
     70          1.1  christos /* Structure to describe how to recognize an interrupt in the
     71          1.1  christos    68hc11 IO regs.  */
     72          1.1  christos struct interrupt_def
     73          1.1  christos {
     74          1.1  christos   enum M6811_INT   int_number;
     75          1.1  christos   unsigned char    int_paddr;
     76          1.1  christos   unsigned char    int_mask;
     77          1.1  christos   unsigned char    enable_paddr;
     78          1.1  christos   unsigned char    enabled_mask;
     79          1.1  christos };
     80          1.1  christos 
     81          1.1  christos #define MAX_INT_HISTORY 64
     82          1.1  christos 
     83          1.1  christos /* Structure used to keep track of interrupt history.
     84          1.1  christos    This is used to understand in which order interrupts were
     85          1.1  christos    raised and when.  */
     86          1.1  christos struct interrupt_history
     87          1.1  christos {
     88          1.1  christos   enum M6811_INT   type;
     89          1.1  christos 
     90          1.1  christos   /* CPU cycle when interrupt handler is called.  */
     91          1.1  christos   signed64         taken_cycle;
     92          1.1  christos 
     93          1.1  christos   /* CPU cycle when the interrupt is first raised by the device.  */
     94          1.1  christos   signed64         raised_cycle;
     95          1.1  christos };
     96          1.1  christos 
     97          1.1  christos #define SIM_STOP_WHEN_RAISED 1
     98          1.1  christos #define SIM_STOP_WHEN_TAKEN  2
     99          1.1  christos 
    100          1.1  christos /* Information and control of pending interrupts.  */
    101          1.1  christos struct interrupt
    102          1.1  christos {
    103          1.1  christos   /* CPU cycle when the interrupt is raised by the device.  */
    104          1.1  christos   signed64         cpu_cycle;
    105          1.1  christos 
    106          1.1  christos   /* Number of times the interrupt was raised.  */
    107          1.1  christos   unsigned long    raised_count;
    108          1.1  christos 
    109          1.1  christos   /* Controls whether we must stop the simulator.  */
    110          1.1  christos   int              stop_mode;
    111          1.1  christos };
    112          1.1  christos 
    113          1.1  christos 
    114          1.1  christos /* Management of 68HC11 interrupts:
    115          1.1  christos     - We use a table of 'interrupt_def' to describe the interrupts that must be
    116          1.1  christos       raised depending on IO register flags (enable and present flags).
    117          1.1  christos     - We keep a mask of pending interrupts.  This mask is refreshed by
    118          1.1  christos       calling 'interrupts_update_pending'.  It must be refreshed each time
    119          1.1  christos       an IO register is changed.
    120          1.1  christos     - 'interrupts_process' must be called after each insn. It has two purposes:
    121          1.1  christos       first it maintains a min/max count of CPU cycles between which interrupts
    122          1.1  christos       are masked; second it checks for pending interrupts and raise one if
    123          1.1  christos       interrupts are enabled.  */
    124          1.1  christos struct interrupts {
    125          1.1  christos   struct _sim_cpu   *cpu;
    126          1.1  christos 
    127          1.1  christos   /* Mask of current pending interrupts.  */
    128          1.1  christos   unsigned long     pending_mask;
    129          1.1  christos 
    130          1.1  christos   /* Address of vector table.  This is set depending on the
    131          1.1  christos      68hc11 init mode.  */
    132          1.1  christos   uint16            vectors_addr;
    133          1.1  christos 
    134          1.1  christos   /* Priority order of interrupts.  This is controlled by setting the HPRIO
    135          1.1  christos      IO register.  */
    136          1.1  christos   enum M6811_INT    interrupt_order[M6811_INT_NUMBER];
    137          1.1  christos   struct interrupt  interrupts[M6811_INT_NUMBER];
    138          1.1  christos 
    139          1.1  christos   /* Simulator statistics to report useful debug information to users.  */
    140          1.1  christos 
    141          1.1  christos   /* - Max/Min number of CPU cycles executed with interrupts masked.  */
    142          1.1  christos   signed64          start_mask_cycle;
    143          1.1  christos   signed64          min_mask_cycles;
    144          1.1  christos   signed64          max_mask_cycles;
    145          1.1  christos   signed64          last_mask_cycles;
    146          1.1  christos 
    147          1.1  christos   /* - Same for XIRQ.  */
    148          1.1  christos   signed64          xirq_start_mask_cycle;
    149          1.1  christos   signed64          xirq_min_mask_cycles;
    150          1.1  christos   signed64          xirq_max_mask_cycles;
    151          1.1  christos   signed64          xirq_last_mask_cycles;
    152          1.1  christos 
    153          1.1  christos   /* - Total number of interrupts raised.  */
    154          1.1  christos   unsigned long     nb_interrupts_raised;
    155          1.1  christos 
    156          1.1  christos   /* Interrupt history to help understand which interrupts
    157          1.1  christos      were raised recently and in which order.  */
    158          1.1  christos   int               history_index;
    159          1.1  christos   struct interrupt_history interrupts_history[MAX_INT_HISTORY];
    160          1.1  christos };
    161          1.1  christos 
    162          1.1  christos extern void interrupts_initialize     (SIM_DESC sd, struct _sim_cpu* cpu);
    163          1.1  christos extern void interrupts_reset          (struct interrupts* interrupts);
    164          1.1  christos extern void interrupts_update_pending (struct interrupts* interrupts);
    165          1.1  christos extern int  interrupts_get_current    (struct interrupts* interrupts);
    166          1.1  christos extern int  interrupts_process        (struct interrupts* interrupts);
    167          1.1  christos extern void interrupts_raise          (struct interrupts* interrupts,
    168          1.1  christos                                        enum M6811_INT number);
    169          1.1  christos 
    170          1.1  christos extern void interrupts_info           (SIM_DESC sd,
    171          1.1  christos                                        struct interrupts* interrupts);
    172          1.1  christos 
    173          1.1  christos #endif
    174