📄 traps.c
字号:
/*
** Copyright (C) 2006 Tamir Michael
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/***********************************************************************/
/* This file is part of the C166 Compiler package */
/* Copyright KEIL ELEKTRONIK GmbH 1996-2003 */
/***********************************************************************/
/* */
/* TRAPS.C: TRAP Handler for C16x/XC16x/ST10/Super10 hardware traps */
/* */
/* To translate this file use C166 with the following invocation: */
/* */
/* C166 TRAPS.C */
/* */
/* To link the modified TRAPS.OBJ file to your application use the */
/* following L166 invocation: */
/* */
/* L166 <your object file list>, TRAPS.OBJ <controls> */
/* */
/***********************************************************************/
#include <intrins.h>
#include "system_messages.h"
/*
* Non-Maskable Interrupt
*/
void NMI_trap (void) interrupt 0x02
{
software_error("%s %s %d", resolve_system_message(ERR_NMI_TRAP), __FILE__, __LINE__ ) ;
while (1)
{
}
}
/*
* Stack Overflow Interrupt
*/
void STKOF_trap (void) interrupt 0x04
{
software_error("%s %s %d", resolve_system_message(ERR_STKOF_TRAP), __FILE__, __LINE__ ) ;
while (1)
{
}
}
/*
* Stack Underflow Interrupt
*/
void STKUF_trap (void) interrupt 0x06
{
software_error("%s %s %d", resolve_system_message(ERR_STKUF_TRAP), __FILE__, __LINE__ ) ;
while (1)
{
}
}
/*
* Class B Hardware Trap:
* -> Undefined Opcode
* -> Protected Instruction Fault
* -> Illegal Word Operand Access
* -> Illegal Instruction Access
* -> Illegal External Bus Access
*/
#pragma NOFRAME // do not save registers for interrupt
sfr TFR = 0xFFAC; // TFR contais Trap Reason
/* TFR Bit Conditions
* TFR.0 = Illegal External Bus Access (no external BUS defined for address)
* TFR.1 = Illegal Instruction Access (branch to odd address)
* TFR.2 = Illegal Word Operand Access (word read/write on odd address)
* TFR.3 = Protection Fault (protected instruction with illegal format)
* TFR.4 = Illegal or erroneous access to program memory interface
* TFR.7 = Undefined Opcode (invalid 166/167 op-code)
* TFR.12 = Software break event
* TFR.13 = Stack Underflow
* TFR.14 = Stack Overflow
* TFR.15 = Non Maskable Interrupt
*/
void Class_B_trap (void) interrupt 0x0A {
unsigned int ip, csp;
ip = _pop_ ();
csp = _pop_ ();
software_error("Class B Trap at PC=0x%02X%04X TFR=0x%04X %s %d\n", csp, ip, TFR, __FILE__, __LINE__);
while (1) ; /* infinite loop */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -