⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 excep.c

📁 MIPS下的boottloader yamon 的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:

/************************************************************************
*
*  excep.c
*
*  The 'EXCEP' module implements a first level exception and
*  interrupt handling and an API to register user defined
*  exception and interrupt service routines (ESR & ISR).
*
*  Interrupt Service Routine registration is possible at
*
*    a) The MIPS CPU SW/HW interrupt level (CPU-ISR) : 0..7
*    b) The Interrupt controller level     (IC-ISR)  : (platform specific)
*
*  Registration of ISR's imply enabling of the corresponding
*  interrupt MASK bit in the CPU or the interrupt controller.
*
*  Interrupt Service Routine handling is executed in a prioritized
*  scheme. First, registered handlers at CPU interrupt level are
*  called, second, registered handlers at interrupt controller
*  level are called.
*
*  Public API offers:
*
*  1) EXCEP_init()
*  2) EXCEP_register_esr()
*  3) EXCEP_register_cpu_isr()
*  4) EXCEP_register_ic_isr()
*  5) EXCEP_print_context()
*
*
* ######################################################################
*
* Copyright (c) 1999-2000 MIPS Technologies, Inc. All rights reserved. 
* 
* Unpublished rights reserved under the Copyright Laws of the United States of 
* America. 
* 
* This document contains information that is proprietary to MIPS Technologies, 
* Inc. ("MIPS Technologies"). Any copying, modifying or use of this information 
* (in whole or in part) which is not expressly permitted in writing by MIPS 
* Technologies or a contractually-authorized third party is strictly 
* prohibited. At a minimum, this information is protected under unfair 
* competition laws and the expression of the information contained herein is 
* protected under federal copyright laws. Violations thereof may result in 
* criminal penalties and fines. 
* MIPS Technologies or any contractually-authorized third party reserves the 
* right to change the information contained in this document to improve 
* function, design or otherwise. MIPS Technologies does not assume any 
* liability arising out of the application or use of this information. Any 
* license under patent rights or any other intellectual property rights owned 
* by MIPS Technologies or third parties shall be conveyed by MIPS Technologies 
* or any contractually-authorized third party in a separate license agreement 
* between the parties. 
* The information contained in this document constitutes one or more of the 
* following: commercial computer software, commercial computer software 
* documentation or other commercial items. If the user of this information, or 
* any related documentation of any kind, including related technical data or 
* manuals, is an agency, department, or other entity of the United States 
* government ("Government"), the use, duplication, reproduction, release, 
* modification, disclosure, or transfer of this information, or any related 
* documentation of any kind, is restricted in accordance with Federal 
* Acquisition Regulation 12.212 for civilian agencies and Defense Federal 
* Acquisition Regulation Supplement 227.7202 for military agencies. The use of 
* this information by the Government is further restricted in accordance with 
* the terms of the license agreement(s) and/or applicable contract terms and 
* conditions covering this information from MIPS Technologies or any 
* contractually-authorized third party. 
*
************************************************************************/


/************************************************************************
*      Include files
************************************************************************/

#include <sysdefs.h>
#include <sys_api.h>
#include <mips.h>
#include <excep_api.h>
#include <excep.h>
#include <syscon_api.h>
#include <stdio.h>
#include <string.h>

/************************************************************************
*      Definitions
************************************************************************/

/* max. number of interrupt sources from the CPU */
#define MAX_INTERRUPTS        (C0_STATUS_IM_MAX + 1)

/* max. number of exception codes from the CPU */
#define MAX_EXCEPTIONS        (C0_CAUSE_CODE_MAX + 1)

/* max. number of interrupt sources from interrupt controller */
#define MAX_IC		      32

/*  Basic definition for registered interrupt handler */
typedef struct int_handler
{
	t_EXCEP_isr handler;
	void        *data;
} t_INT_handler;

/*  Basic definition for registered exception handler */
typedef struct excep_handler
{
	t_EXCEP_esr handler;
	bool	       raw;
} t_EXCEP_handler;


/*  Element struct to be used for 8-bit-set of int.
*  pending to int. handler index list.
*/
typedef struct excep_set_to_list
{
	UINT8 list_size;
	UINT8 index[8];
} t_EXCEP_set_to_list;

/* max. number of interrupt handlers per line */
#define INT_HANDLERS_PER_LINE 4

/*  Element struct to be used for keeping a configurable
*  number of int. handlers per line.
*/
typedef struct excep_int_handler_list
{
	UINT8         list_size;
	t_INT_handler int_handler[INT_HANDLERS_PER_LINE];
} t_EXCEP_int_handler_list;

/* max. number of interrupt control handlers per line */
#define CTRL_HANDLERS_PER_LINE 4

/*  Element struct to be used for keeping a configurable
*  number of int. controller handlers per line.
*/
typedef struct excep_ctrl_handler_list
{
	UINT8         list_size;
	t_INT_handler ctrl_handler[CTRL_HANDLERS_PER_LINE];
} t_EXCEP_ctrl_handler_list;


/* Struct for holding exception handlers */
typedef struct
{
    /* Exception handler table. */
    t_EXCEP_handler           exception[MAX_EXCEPTIONS]; 
	
    /* EJTAG exception handler */
    t_EXCEP_handler	      ejtag;
	
    /* CPU Interrupt handler table. */
    t_EXCEP_int_handler_list  interrupt[MAX_INTERRUPTS];
	
    /* Int. controller handler table. */
    t_EXCEP_ctrl_handler_list controller[MAX_IC];
	
    /* Default handlers */
    t_EXCEP_handler	      default_exception;
    t_INT_handler	      default_int;
    t_INT_handler	      default_ctrl;
}
t_table;

/************************************************************************
*      Public variables
************************************************************************/

bool EXCEP_ejtag = FALSE;

/************************************************************************
*      Static variables
************************************************************************/

/* Number of interrupts handled by interrupt controller */
static UINT32 excep_ic_count;

/* HW interrupt used by interrupt controller */
static UINT32 excep_ic_int;

/* Are we in interrupt context ? */
static bool interrupt_context = FALSE;

/***********************************************************************
*
*      Handler function tables
*
************************************************************************/

static t_table table;
static t_table table_copy;

/***********************************************************************
*
*      Private lookup tables
*
************************************************************************/

/*
* An 8-bit set is converted to a list size and a list of indices
* to be sequentially executed in a loop, which
* is supposed to call handlers by index in a handler table.
*/
static const t_EXCEP_set_to_list EXCEP_set_to_list[256] =
{
	/*   set mask        list_size     index         */
	/*  '0' empty set */ {   0,  { 0,0,0,0,0,0,0,0 } },
	/*  '1'       set */ {   1,  { 0,0,0,0,0,0,0,0 } },
	/*  '2'       set */ {   1,  { 1,0,0,0,0,0,0,0 } },
	/*  '3'       set */ {   2,  { 1,0,0,0,0,0,0,0 } },
	
	/*  '4'       set */ {   1,  { 2,0,0,0,0,0,0,0 } },
	/*  '5'       set */ {   2,  { 2,0,0,0,0,0,0,0 } },
	/*  '6'       set */ {   2,  { 2,1,0,0,0,0,0,0 } },
	/*  '7'       set */ {   3,  { 2,1,0,0,0,0,0,0 } },
	
	/*  '8'       set */ {   1,  { 3,0,0,0,0,0,0,0 } },
	/*  '9'       set */ {   2,  { 3,0,0,0,0,0,0,0 } },
	/* '10'       set */ {   2,  { 3,1,0,0,0,0,0,0 } },
	/* '11'       set */ {   3,  { 3,1,0,0,0,0,0,0 } },
	
	/* '12'       set */ {   2,  { 3,2,0,0,0,0,0,0 } },
	/* '13'       set */ {   3,  { 3,2,0,0,0,0,0,0 } },
	/* '14'       set */ {   3,  { 3,2,1,0,0,0,0,0 } },
	/* '15'       set */ {   4,  { 3,2,1,0,0,0,0,0 } },
	
	/* '16'       set */ {   1,  { 4,0,0,0,0,0,0,0 } },
	/* '17'       set */ {   2,  { 4,0,0,0,0,0,0,0 } },
	/* '18'       set */ {   2,  { 4,1,0,0,0,0,0,0 } },
	/* '19'       set */ {   3,  { 4,1,0,0,0,0,0,0 } },
	
	/* '20'       set */ {   2,  { 4,2,0,0,0,0,0,0 } },
	/* '21'       set */ {   3,  { 4,2,0,0,0,0,0,0 } },
	/* '22'       set */ {   3,  { 4,2,1,0,0,0,0,0 } },
	/* '23'       set */ {   4,  { 4,2,1,0,0,0,0,0 } },
	
	/* '24'       set */ {   2,  { 4,3,0,0,0,0,0,0 } },
	/* '25'       set */ {   3,  { 4,3,0,0,0,0,0,0 } },
	/* '26'       set */ {   3,  { 4,3,1,0,0,0,0,0 } },
	/* '27'       set */ {   4,  { 4,3,1,0,0,0,0,0 } },
	
	/* '28'       set */ {   3,  { 4,3,2,0,0,0,0,0 } },
	/* '29'       set */ {   4,  { 4,3,2,0,0,0,0,0 } },
	/* '30'       set */ {   4,  { 4,3,2,1,0,0,0,0 } },
	/* '31'       set */ {   5,  { 4,3,2,1,0,0,0,0 } },
	
	/* '32'       set */ {   1,  { 5,0,0,0,0,0,0,0 } },
	/* '33'       set */ {   2,  { 5,0,0,0,0,0,0,0 } },
	/* '34'       set */ {   2,  { 5,1,0,0,0,0,0,0 } },
	/* '35'       set */ {   3,  { 5,1,0,0,0,0,0,0 } },
	
	/* '36'       set */ {   2,  { 5,2,0,0,0,0,0,0 } },
	/* '37'       set */ {   3,  { 5,2,0,0,0,0,0,0 } },
	/* '38'       set */ {   3,  { 5,2,1,0,0,0,0,0 } },
	/* '39'       set */ {   4,  { 5,2,1,0,0,0,0,0 } },
	
	/* '40'       set */ {   2,  { 5,3,0,0,0,0,0,0 } },
	/* '41'       set */ {   3,  { 5,3,0,0,0,0,0,0 } },
	/* '42'       set */ {   3,  { 5,3,1,0,0,0,0,0 } },
	/* '43'       set */ {   4,  { 5,3,1,0,0,0,0,0 } },
	
	/* '44'       set */ {   3,  { 5,3,2,0,0,0,0,0 } },
	/* '45'       set */ {   4,  { 5,3,2,0,0,0,0,0 } },
	/* '46'       set */ {   4,  { 5,3,2,1,0,0,0,0 } },
	/* '47'       set */ {   5,  { 5,3,2,1,0,0,0,0 } },
	
	/* '48'       set */ {   2,  { 5,4,0,0,0,0,0,0 } },
	/* '49'       set */ {   3,  { 5,4,0,0,0,0,0,0 } },
	/* '50'       set */ {   3,  { 5,4,1,0,0,0,0,0 } },
	/* '51'       set */ {   4,  { 5,4,1,0,0,0,0,0 } },
	
	/* '52'       set */ {   3,  { 5,4,2,0,0,0,0,0 } },
	/* '53'       set */ {   4,  { 5,4,2,0,0,0,0,0 } },
	/* '54'       set */ {   4,  { 5,4,2,1,0,0,0,0 } },
	/* '55'       set */ {   5,  { 5,4,2,1,0,0,0,0 } },
	
	/* '56'       set */ {   3,  { 5,4,3,0,0,0,0,0 } },
	/* '57'       set */ {   4,  { 5,4,3,0,0,0,0,0 } },
	/* '58'       set */ {   4,  { 5,4,3,1,0,0,0,0 } },
	/* '59'       set */ {   5,  { 5,4,3,1,0,0,0,0 } },
	
	/* '60'       set */ {   4,  { 5,4,3,2,0,0,0,0 } },
	/* '61'       set */ {   5,  { 5,4,3,2,0,0,0,0 } },
	/* '62'       set */ {   5,  { 5,4,3,2,1,0,0,0 } },
	/* '63'       set */ {   6,  { 5,4,3,2,1,0,0,0 } },
	
	/* '64'       set */ {   1,  { 6,0,0,0,0,0,0,0 } },
	/* '65'       set */ {   2,  { 6,0,0,0,0,0,0,0 } },
	/* '66'       set */ {   2,  { 6,1,0,0,0,0,0,0 } },
	/* '67'       set */ {   3,  { 6,1,0,0,0,0,0,0 } },
	
	/* '68'       set */ {   2,  { 6,2,0,0,0,0,0,0 } },
	/* '69'       set */ {   3,  { 6,2,0,0,0,0,0,0 } },
	/* '70'       set */ {   3,  { 6,2,1,0,0,0,0,0 } },
	/* '71'       set */ {   4,  { 6,2,1,0,0,0,0,0 } },
	
	/* '72'       set */ {   2,  { 6,3,0,0,0,0,0,0 } },
	/* '73'       set */ {   3,  { 6,3,0,0,0,0,0,0 } },
	/* '74'       set */ {   3,  { 6,3,1,0,0,0,0,0 } },
	/* '75'       set */ {   4,  { 6,3,1,0,0,0,0,0 } },
	
	/* '76'       set */ {   3,  { 6,3,2,0,0,0,0,0 } },
	/* '77'       set */ {   4,  { 6,3,2,0,0,0,0,0 } },
	/* '78'       set */ {   4,  { 6,3,2,1,0,0,0,0 } },
	/* '79'       set */ {   5,  { 6,3,2,1,0,0,0,0 } },

/* '80'       set */ {   2,  { 6,4,0,0,0,0,0,0 } },
/* '81'       set */ {   3,  { 6,4,0,0,0,0,0,0 } },
/* '82'       set */ {   3,  { 6,4,1,0,0,0,0,0 } },
/* '83'       set */ {   4,  { 6,4,1,0,0,0,0,0 } },

/* '84'       set */ {   3,  { 6,4,2,0,0,0,0,0 } },
/* '85'       set */ {   4,  { 6,4,2,0,0,0,0,0 } },
/* '86'       set */ {   4,  { 6,4,2,1,0,0,0,0 } },
/* '87'       set */ {   5,  { 6,4,2,1,0,0,0,0 } },

/* '88'       set */ {   3,  { 6,4,3,0,0,0,0,0 } },
/* '89'       set */ {   4,  { 6,4,3,0,0,0,0,0 } },
/* '90'       set */ {   4,  { 6,4,3,1,0,0,0,0 } },
/* '91'       set */ {   5,  { 6,4,3,1,0,0,0,0 } },

/* '92'       set */ {   4,  { 6,4,3,2,0,0,0,0 } },
/* '93'       set */ {   5,  { 6,4,3,2,0,0,0,0 } },
/* '94'       set */ {   5,  { 6,4,3,2,1,0,0,0 } },
/* '95'       set */ {   6,  { 6,4,3,2,1,0,0,0 } },

/* '96'       set */ {   2,  { 6,5,0,0,0,0,0,0 } },
/* '97'       set */ {   3,  { 6,5,0,0,0,0,0,0 } },
/* '98'       set */ {   3,  { 6,5,1,0,0,0,0,0 } },
/* '99'       set */ {   4,  { 6,5,1,0,0,0,0,0 } },

/* '100'      set */ {   3,  { 6,5,2,0,0,0,0,0 } },
/* '101'      set */ {   4,  { 6,5,2,0,0,0,0,0 } },
/* '102'      set */ {   4,  { 6,5,2,1,0,0,0,0 } },
/* '103'      set */ {   5,  { 6,5,2,1,0,0,0,0 } },

/* '104'      set */ {   3,  { 6,5,3,0,0,0,0,0 } },
/* '105'      set */ {   4,  { 6,5,3,0,0,0,0,0 } },
/* '106'      set */ {   4,  { 6,5,3,1,0,0,0,0 } },
/* '107'      set */ {   5,  { 6,5,3,1,0,0,0,0 } },

/* '108'      set */ {   4,  { 6,5,3,2,0,0,0,0 } },
/* '109'      set */ {   5,  { 6,5,3,2,0,0,0,0 } },
/* '110'      set */ {   5,  { 6,5,3,2,1,0,0,0 } },
/* '111'      set */ {   6,  { 6,5,3,2,1,0,0,0 } },

/* '112'      set */ {   3,  { 6,5,4,0,0,0,0,0 } },
/* '113'      set */ {   4,  { 6,5,4,0,0,0,0,0 } },
/* '114'      set */ {   4,  { 6,5,4,1,0,0,0,0 } },
/* '115'      set */ {   5,  { 6,5,4,1,0,0,0,0 } },

/* '116'      set */ {   4,  { 6,5,4,2,0,0,0,0 } },
/* '117'      set */ {   5,  { 6,5,4,2,0,0,0,0 } },
/* '118'      set */ {   5,  { 6,5,4,2,1,0,0,0 } },
/* '119'      set */ {   6,  { 6,5,4,2,1,0,0,0 } },

/* '120'      set */ {   4,  { 6,5,4,3,0,0,0,0 } },
/* '121'      set */ {   5,  { 6,5,4,3,0,0,0,0 } },
/* '122'      set */ {   5,  { 6,5,4,3,1,0,0,0 } },
/* '123'      set */ {   6,  { 6,5,4,3,1,0,0,0 } },

/* '124'      set */ {   5,  { 6,5,4,3,2,0,0,0 } },
/* '125'      set */ {   6,  { 6,5,4,3,2,0,0,0 } },
/* '126'      set */ {   6,  { 6,5,4,3,2,1,0,0 } },
/* '127'      set */ {   7,  { 6,5,4,3,2,1,0,0 } },

/* '128'      set */ {   1,  { 7,0,0,0,0,0,0,0 } },
/* '129'      set */ {   2,  { 7,0,0,0,0,0,0,0 } },
/* '130'      set */ {   2,  { 7,1,0,0,0,0,0,0 } },
/* '131'      set */ {   3,  { 7,1,0,0,0,0,0,0 } },

/* '132'      set */ {   2,  { 7,2,0,0,0,0,0,0 } },
/* '133'      set */ {   3,  { 7,2,0,0,0,0,0,0 } },
/* '134'      set */ {   3,  { 7,2,1,0,0,0,0,0 } },
/* '135'      set */ {   4,  { 7,2,1,0,0,0,0,0 } },

/* '136'      set */ {   2,  { 7,3,0,0,0,0,0,0 } },
/* '137'      set */ {   3,  { 7,3,0,0,0,0,0,0 } },
/* '138'      set */ {   3,  { 7,3,1,0,0,0,0,0 } },
/* '139'      set */ {   4,  { 7,3,1,0,0,0,0,0 } },

/* '140'      set */ {   3,  { 7,3,2,0,0,0,0,0 } },
/* '141'      set */ {   4,  { 7,3,2,0,0,0,0,0 } },
/* '142'      set */ {   4,  { 7,3,2,1,0,0,0,0 } },
/* '143'      set */ {   5,  { 7,3,2,1,0,0,0,0 } },

/* '144'      set */ {   2,  { 7,4,0,0,0,0,0,0 } },
/* '145'      set */ {   3,  { 7,4,0,0,0,0,0,0 } },
/* '146'      set */ {   3,  { 7,4,1,0,0,0,0,0 } },
/* '147'      set */ {   4,  { 7,4,1,0,0,0,0,0 } },

/* '148'      set */ {   3,  { 7,4,2,0,0,0,0,0 } },
/* '149'      set */ {   4,  { 7,4,2,0,0,0,0,0 } },
/* '150'      set */ {   4,  { 7,4,2,1,0,0,0,0 } },
/* '151'      set */ {   5,  { 7,4,2,1,0,0,0,0 } },

/* '152'      set */ {   3,  { 7,4,3,0,0,0,0,0 } },
/* '153'      set */ {   4,  { 7,4,3,0,0,0,0,0 } },
/* '154'      set */ {   4,  { 7,4,3,1,0,0,0,0 } },
/* '155'      set */ {   5,  { 7,4,3,1,0,0,0,0 } },

/* '156'      set */ {   4,  { 7,4,3,2,0,0,0,0 } },
/* '157'      set */ {   5,  { 7,4,3,2,0,0,0,0 } },
/* '158'      set */ {   5,  { 7,4,3,2,1,0,0,0 } },
/* '159'      set */ {   6,  { 7,4,3,2,1,0,0,0 } },

/* '160'      set */ {   2,  { 7,5,0,0,0,0,0,0 } },
/* '161'      set */ {   3,  { 7,5,0,0,0,0,0,0 } },
/* '162'      set */ {   3,  { 7,5,1,0,0,0,0,0 } },
/* '163'      set */ {   4,  { 7,5,1,0,0,0,0,0 } },

/* '164'      set */ {   3,  { 7,5,2,0,0,0,0,0 } },
/* '165'      set */ {   4,  { 7,5,2,0,0,0,0,0 } },
/* '166'      set */ {   4,  { 7,5,2,1,0,0,0,0 } },
/* '167'      set */ {   5,  { 7,5,2,1,0,0,0,0 } },

/* '168'      set */ {   3,  { 7,5,3,0,0,0,0,0 } },
/* '169'      set */ {   4,  { 7,5,3,0,0,0,0,0 } },
/* '170'      set */ {   4,  { 7,5,3,1,0,0,0,0 } },
/* '171'      set */ {   5,  { 7,5,3,1,0,0,0,0 } },

/* '172'      set */ {   4,  { 7,5,3,2,0,0,0,0 } },
/* '173'      set */ {   5,  { 7,5,3,2,0,0,0,0 } },
/* '174'      set */ {   5,  { 7,5,3,2,1,0,0,0 } },
/* '175'      set */ {   6,  { 7,5,3,2,1,0,0,0 } },

/* '176'      set */ {   3,  { 7,5,4,0,0,0,0,0 } },
/* '177'      set */ {   4,  { 7,5,4,0,0,0,0,0 } },
/* '178'      set */ {   4,  { 7,5,4,1,0,0,0,0 } },
/* '179'      set */ {   5,  { 7,5,4,1,0,0,0,0 } },

/* '180'      set */ {   4,  { 7,5,4,2,0,0,0,0 } },
/* '181'      set */ {   5,  { 7,5,4,2,0,0,0,0 } },
/* '182'      set */ {   5,  { 7,5,4,2,1,0,0,0 } },
/* '183'      set */ {   6,  { 7,5,4,2,1,0,0,0 } },

/* '184'      set */ {   4,  { 7,5,4,3,0,0,0,0 } },
/* '185'      set */ {   5,  { 7,5,4,3,0,0,0,0 } },
/* '186'      set */ {   5,  { 7,5,4,3,1,0,0,0 } },
/* '187'      set */ {   6,  { 7,5,4,3,1,0,0,0 } },

/* '188'      set */ {   5,  { 7,5,4,3,2,0,0,0 } },
/* '189'      set */ {   6,  { 7,5,4,3,2,0,0,0 } },
/* '190'      set */ {   6,  { 7,5,4,3,2,1,0,0 } },
/* '191'      set */ {   7,  { 7,5,4,3,2,1,0,0 } },

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -