📄 h8s_stub.c
字号:
//========================================================================
//
// h8s_stub.c
//
// Helper functions for H8S stub
//
//========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos 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 or (at your option) any later version.
//
// eCos 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 eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): Uwe Kindler
// Contributors: Uwe Kindler, Yoshinori Sato
// Date: 2003-12-06
// Purpose:
// Description: Helper functions for H8S stub
// Usage:
//
//####DESCRIPTIONEND####
//
//========================================================================
//========================================================================
// DOXYGEN FILE HEADER
/// \file h8s_stub.c
/// \brief Helper functions for H8S stub
/// \author Uwe Kindler, Yoshinori Sato
/// \date 2003-12-06
//========================================================================
//========================================================================
// INLCUDES
//========================================================================
#include <stddef.h>
#include <pkgconf/hal.h>
//
// This option causes a set of GDB stubs to be included into the system.
// When GDB stubs are include in a configuration, HAL serial drivers must
// also be included.
//
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
#include <cyg/hal/hal_stub.h>
#include <cyg/hal/hal_arch.h>
#include <cyg/hal/hal_intr.h>
//
// This option enables some extra HAL code which is needed to support
// multi-threaded source level debugging.
//
#ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
#include <cyg/hal/dbg-threads-api.h> // dbg_currthread_id
#endif
//========================================================================
// DEFINES
//========================================================================
//------------------------------------------------------------------------
// Branch instruction offsets
//
#define GDB_H8S_OP_BCC_BT 0x0
#define GDB_H8S_OP_BCC_BF 0x1
#define GDB_H8S_OP_BCC_BHI 0x2
#define GDB_H8S_OP_BCC_BLS 0x3
#define GDB_H8S_OP_BCC_BHS 0x4
#define GDB_H8S_OP_BCC_BLO 0x5
#define GDB_H8S_OP_BCC_BNE 0x6
#define GDB_H8S_OP_BCC_BEQ 0x7
#define GDB_H8S_OP_BCC_BVC 0x8
#define GDB_H8S_OP_BCC_BVS 0x9
#define GDB_H8S_OP_BCC_BPL 0xa
#define GDB_H8S_OP_BCC_BMI 0xb
#define GDB_H8S_OP_BCC_BGE 0xc
#define GDB_H8S_OP_BCC_BLT 0xd
#define GDB_H8S_OP_BCC_BGT 0xe
#define GDB_H8S_OP_BCC_BLE 0xf
//============================================================================
// MACROS
//============================================================================
//----------------------------------------------------------------------------
// Opcode test macros
//
#define GDB_H8S_OP_RTE(op) (0x5670 == (op))
#define GDB_H8S_OP_RTS(op) (0x5470 == (op))
#define GDB_H8S_OP_BSR8(op) (0x5500 == ((op) & 0xff00))
#define GDB_H8S_OP_BSR16(op) (0x5c00 == (op))
#define GDB_H8S_OP_JMPER(op) (0x5900 == ((op) & 0xff00))
#define GDB_H8S_OP_JMP24(op) (0x5a00 == ((op) & 0xff00))
#define GDB_H8S_OP_JMP8(op) (0x5b00 == ((op) & 0xff00))
#define GDB_H8S_OP_JSRER(op) (0x5d00 == ((op) & 0xff00))
#define GDB_H8S_OP_JSR24(op) (0x5e00 == ((op) & 0xff00))
#define GDB_H8S_OP_JSR8(op) (0x5f00 == ((op) & 0xff00))
#define GDB_H8S_OP_TRAPA(op) (0x5700 == ((op) & 0xff00))
#define GDB_H8S_OP_BCC16(op) (0x5800 == ((op) & 0xff00))
#define GDB_H8S_OP_BCC8(op) (0x4000 == ((op) & 0xf000))
//----------------------------------------------------------------------------
// CCR bit test macors
//
#define GDB_H8S_CCR_C(ccr) ((ccr) & 0x01)
#define GDB_H8S_CCR_V(ccr) ((ccr) & 0x02)
#define GDB_H8S_CCR_Z(ccr) ((ccr) & 0x04)
#define GDB_H8S_CCR_N(ccr) ((ccr) & 0x08)
#define GDB_H8S_CCR_U(ccr) ((ccr) & 0x10)
#define GDB_H8S_CCR_H(ccr) ((ccr) & 0x20)
#define GDB_H8S_CCR_UI(ccr) ((ccr) & 0x40)
#define GDB_H8S_CCR_I(ccr) ((ccr) & 0x80)
//========================================================================
// DATA TYPES
//========================================================================
///
/// Stores single H8S instruction.
/// The type represents one H8S instruction with a length of
/// 2 bytes
///
typedef unsigned short HAL_STUB_H8S_INSTR;
///
/// Stores breakpoint data.
/// When inserting a breakpoint instruction, we have to backup the
/// current instruction (saved_instr) and we have to know where we
/// have to restore this saved instruction (pinstr_addr)
///
typedef struct
{
HAL_STUB_H8S_INSTR *pinstr_addr; ///< points to saved instruction
HAL_STUB_H8S_INSTR saved_instr; ///< stores saved instruction
} HAL_STUB_INSTR_BACKUP;
///
/// For long, short and byte access.
/// This union is required in order to address the single bytes and words
/// of a long.
///
typedef union
{
long lbuf;
short sbuf;
/// an array of 4 chars in order to acces single bytes of a long or
/// a short value
char cbuf[sizeof(long)];
} HAL_STUB_LSC_BUF;
//========================================================================
// GLOBALS
//========================================================================
HAL_STUB_INSTR_BACKUP HalStubAsyncBuf; ///< stores data by CTRL C interruption
HAL_STUB_INSTR_BACKUP HalStubStepBuf; ///< stores data when stepping
unsigned char HalStubStepping = 0; ///< flag stores if single stepping is active
//========================================================================
// FUNCTIONS
//========================================================================
//========================================================================
// INSTALL BREAKPOINT
///
/// Called to asynchronously interrupt a running program.
/// Must be passed address of instruction interrupted.
/// This is typically called in response to a debug port
/// receive interrupt.
///
/// \param pc_in Address of instruction where bp should be placed
//========================================================================
void
install_async_breakpoint(void *pc_in)
{
HalStubAsyncBuf.pinstr_addr = pc_in; // save address of interrupted instruction
HalStubAsyncBuf.saved_instr = *(HAL_STUB_H8S_INSTR *)pc_in; // backup instruction
*(HAL_STUB_H8S_INSTR*)pc_in = (HAL_STUB_H8S_INSTR)HAL_BREAKINST;// install breakpoint - trapa #3
__instruction_cache(CACHE_FLUSH);
__data_cache(CACHE_FLUSH);
}
//========================================================================
// COMPUTE TRAP SIGNAL
///
/// Given a trap value TRAP, return the corresponding signal
///
/// \param trap_number Trap value to be converted into signal
/// \return Symbolic signal value
//========================================================================
int __computeSignal (unsigned int trap_number)
{
switch (trap_number)
{
case CYGNUM_HAL_VECTOR_TRAP0 :
// falling through
case CYGNUM_HAL_VECTOR_TRAP1 :
// falling through
case CYGNUM_HAL_VECTOR_TRAP2 :
// falling through
case CYGNUM_HAL_VECTOR_TRAP3 :
return SIGTRAP;
default:
return SIGINT;
}
}
//========================================================================
// GET TRAP NUMBER
///
/// Return the trap number corresponding to the last-taken trap.
/// '_hal_saved_intvec' is defined in 'vectors.s'.
/// We get the intvector from there.
///
/// \return Number of last occured trap exception
//========================================================================
int __get_trap_number (void)
{
extern int CYG_LABEL_NAME(_hal_saved_intvec);
return CYG_LABEL_NAME(_hal_saved_intvec);
}
//========================================================================
// SET PC
///
/// Set currently-saved pc register value to PC.
///
/// \param pc New value for program counter
//========================================================================
void set_pc (target_register_t pc)
{
put_register (PC, pc); // set PC to currently saved value
}
//============================================================================
// GET INSTRUCTION LENGTH OF H8S OPCODE
///
/// Returns length of H8S instruction.
/// H8S instructions aren't all the same length. This table is
/// instruction length vs. the first byte of its opcode, with a few
/// exceptions marked by a -1
///
/// \param addr_in Address of instruction which lengt is required
///
/// \return Length of instruction.
//============================================================================
short GdbH8sInstrLen (long addr_in)
{
unsigned char *op;
signed short op_len;
static const signed char Gdb_Op2Len[256] = {
2, -1, 2, 2, 2, 2, 2, 2, // 0
2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, // 1
2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, // 2
2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, // 3
2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, // 4
2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, // 5
4, 2, 4, 2, 4, 2, 4, 2,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -