亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? arm7tdmi.c

?? PC連接ARM JTAG 接口工具的源代碼
?? C
字號:
/*
 * target/arm7tdmi/arm7tdmi: implements arm7tdmi target
 *
 * Copyright (C) 2003 2004, Rongkai zhan <zhanrk@163.com>
 *
 * 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
 */

/* $Id$ */

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

#include "jtager.h"
#include "jtag.h"
#include "target.h"

extern core_register_t arm7tdmi_regs[];
extern ice_register_t  arm7tdmi_ice_regs[];

target_t arm7tdmi_target = {
	.type		= TARGET_TYPE_ARM7TDMI,
	.mode		= TARGET_MODE_ARM,
	.status 	= TARGET_STATUS_RUNNING,
	.halt_reason 	= TARGET_HALTED_NONE,
	
	/*
	 * These two pointers are initialized in the function arm7tdmi_setup()
	 */
	.regs = NULL,
	.ice_regs = NULL,

	/* BYPASS register always output 0 */
	.bypass 	= {ARM7TDMI_BYPASS_REG_BITNR, 0, 0},
	.idcode 	= {ARM7TDMI_IDCODE_REG_BITNR, 0, 0},
	/* INSTRUCTION register always output b0001 during CAPTURE-DR stage */
	.instruction 	= {ARM7TDMI_INSTRUCTION_REG_BITNR, 0xffffffff, 0x01},
	/*
	 * The scan path select register always
	 * output b1000 during CAPTURE-DR stage.
	 */
	.scanpath = {ARM7TDMI_SCANPATH_REG_BITNR, 0x0, 0x08}, 
	
	/* scan chains of ARM7TDMI */
	.sc_num 	= 3, /* scan chain 0, 1, 2 */
	.active_sc 	= 0,
	.sc = {
		{"ARM7TDMI CPU core logic",
		 ARM7TDMI_SCANCHAIN0_BITNR, {0, }, {0, }, NULL},
		{"ARM7TDMI CPU core debug subset",
		 ARM7TDMI_SCANCHAIN1_BITNR, {0, }, {0, }, NULL},
		{"ARM7TDMI EmbeddedICE-RT logic",
		 ARM7TDMI_SCANCHAIN2_BITNR, {0, }, {0, }, NULL}
	},
	.private = NULL,
};

/*
 * arm7tdmi_halt - Halt the ARM7TDMI target and make it into the debug mode
 */
int arm7tdmi_halt(void)
{
	u32 status;
	int success, retval;
	int temp = 0;

	if (target->status != TARGET_STATUS_RUNNING) {
		printf("The target cpu has been halted!\n");
		return 0;
	}
	
	/*
	 * We halt the target by setting the DBGRQ bit (bit[1]) of the debug
	 * control register of ARM7TDMI EmbeddedICE-RT logic. We also set the
	 * INTDIS bit (bit[2]) of the ICE debug control register for disabling
	 * the interrupt on the target.
	 *
	 * NOTICE: Do not set DBGACK bit, please. The reason is:
	 * When a system-speed access from debug state occurs, the core will
	 * temporarily drop out of debug state, so DBGACK might go LOW.
	 * But if set the DBGACK bit of the debug control registerl,
	 * the DBGACK signal will always go HIGH.
	 */
	/* select scan chain 2 -- EmbeddedICE-RT */
	retval = jtag_select_scanchain(2);
	if (retval)
		return retval;
	retval = jtag_write_ireg(JTAG_INTEST); /* internal test mode */
	if (retval)
		return retval;
	
	/* set DBGRQ bit and disable interrupts */
	retval = arm7tdmi_ice_write(ARM7TDMI_ICE_DBGCTL, 0x6);
	if (retval)
		return retval;

	/* After sending DBGRQ, Run-Test/Idle state must be entered: */
	retval = jtag_write_ireg(JTAG_RESTART);
	if (retval)
		return retval;
	
	/* Read debug status register to see whether the DBGACK signal
	 * is asserted. If the DBGACK siganl goes HIGH, then the target
	 * has entered the debug state.
	 */
	success = 0;
	printf("Requesting HALT target ... ");
	while (temp++ < 10) {
		retval = arm7tdmi_ice_read(ARM7TDMI_ICE_DBGSTAT, &status);
		if (retval)
			return retval;
		
		if (status & 0x01) {
			/* success */
			success = 1;
			break;
		}
		//jtag_write_ireg(JTAG_RESTART);
		printf(".");
		usleep(100);
	}

	/* Whatever happens, the DBGRQ bit flag must be cleared */
	arm7tdmi_ice_write(ARM7TDMI_ICE_DBGCTL, 0x00);
	
	if (success) {
		printf("[OK]\n");
		target->status = TARGET_STATUS_HALTED;
		target->halt_reason = TARGET_HALTED_BY_DBGRQ;
		
		/*
		 * When the bit[4] of the debug status register of ARM7TDMI
		 * EmbeddedICE-RT logic is HIGH, the ARM7TDMI core has
		 * entered the debug state from THUMB mode. Otherwise the
		 * ARM7TDMI core has entered the debug state from ARM mode.
		 */
		printf("The target is halted in ");
		if (status & 0x10) {
			printf("THUMB mode.\n");
			target->mode = TARGET_MODE_THUMB;
		} else {
			printf("ARM mode.\n");
			target->mode = TARGET_MODE_ARM;
		}
		retval = 0;
		//retval = arm7tdmi_regs_read();
	} else {
		/* make the TAP controller into the Run-Test/Idle state */
		jtag_write_ireg(JTAG_RESTART);
		
		printf("[FAILED]\n");	
		retval = -ERR_TARGET_HALT_FAILED;
	}

	return retval;
} /* end of target_halt() */

/*
 * arm7tdmi_exec_instruction - Execute an instruction on the ARM7TDMI core
 * 	 		       while in debug state by scan chain 1
 * @writein: an array with 2 elements, writein[0] contains the instruction
 * 	     opcode to be executed, (writein[1] & 0x01) represents the
 * 	     value of BREAKPT signal.
 * @readout: used to return the data read out from scan chain 1
 * 
 * Return Value: the value of BREAKPT signal.
 *
 * NOTE: We assume that the target has been halted - the target has
 * been in debug state. And scan chain 1 has been selected, the INTEST
 * instruction has been written into the instruction register.
 */
int arm7tdmi_exec_instruction(u32 *writein, u32 *readout)
{
	u32 indata[2] = {0, 0};
	u32 outdata[2] = {0, 0};
	int bitnr = arm7tdmi_target.sc[1].bitnr; /* 33 bits */
	int retval;
	
	/* reverse the bit order of the data to be written in */
	reverse_bit_order(bitnr, (u8 *)writein, (u8 *)indata);
	
	/* 
	 * OK, write in and read out
	 * read or write JTAG data register will always change its state
	 * from Update-DR to Run-Test/Idle. Therefore, it will also pulse
	 * DCLK signal.
	 */
	retval = jtag_rw_dreg(bitnr, indata, outdata);
	if (retval)
		return retval;

	/* reverse the bit order of the data read out */
	reverse_bit_order(bitnr, (u8 *)outdata, (u8 *)readout);

	return retval;
} /* end of arm7tdmi_exec_instruction() */

/*
 * target_restart - Exit from the debug state, and return to
 * 		    the normal system state.
 */
int arm7tdmi_restart(void)
{
	core_register_t *reg_pc = reg_index("PC");
	core_register_t *reg_r0 = reg_index("R0");

	if (target->status == TARGET_STATUS_RUNNING)
		return -ERR_TARGET_IS_RUNNING;

	if (target->mode == TARGET_MODE_THUMB) {
		printf("Error: %s: THUMB mode is not yet implemented.\n",
			__FUNCTION__);
		return -1;
	}

	/* Cancel the DBGRQ and enable interrupts */
	jtag_select_scanchain(2);
	arm7tdmi_ice_write(0x00, 0x00);
	jtag_write_ireg(JTAG_RESTART);

	/* Select scan chain 1 and use INTEST instruction */
	jtag_select_scanchain(1);
	jtag_write_ireg(JTAG_INTEST);

	/*
	 * First, we recover the internal state of ARM7TDMI core.
	 * Use the following instructions sequence to recover R0 and PC:
	 * LDR R0, [R0] ; scan the value of PC into R0
	 * MOV PC, R0  ; update PC of the core
	 * LDR R0, [R0] ; scan in the value of R0 register
	 */

	/* LDR R0, [R0] = 0xE5900000       - restore PC */
	target->sc[1].writein[0] = 0xE5900000;
	target->sc[1].writein[1] = DEBUG_SPEED;
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);

	/* NOP */
	target->sc[1].writein[0] = 0xE1A00000;
	target->sc[1].writein[1] = DEBUG_SPEED;
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);

	/* NOP 
	 * 1st instruction is executed while fetching 3rd instruction
	 */
	target->sc[1].writein[0] = 0xE1A00000;
	target->sc[1].writein[1] = DEBUG_SPEED;
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);

	/* NOP                           -  scan in the value of PC */
	target->sc[1].writein[0] = reg_pc->value;
	target->sc[1].writein[1] = DEBUG_SPEED;
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);

	/* MOV PC, R0 = 0xE1A0F000       - put R0 into PC */
	target->sc[1].writein[0] = 0xE1A0F000;
	target->sc[1].writein[1] = DEBUG_SPEED;
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);

	/* NOP */
	target->sc[1].writein[0] = 0xE1A00000;
	target->sc[1].writein[1] = DEBUG_SPEED;
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);

	/* NOP 
	 * 1st instruction "MOV PC, R0" is executed,
	 * while fetching 3rd instruction
	 */
	target->sc[1].writein[0] = 0xE1A00000;
	target->sc[1].writein[1] = DEBUG_SPEED;
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);
	
	/* LDR R0, [R0] = 0xE5900000            - restore R0 */
	target->sc[1].writein[0] = 0xE5900000;
	target->sc[1].writein[1] = DEBUG_SPEED;
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);

	/* NOP */
	target->sc[1].writein[0] = 0xE1A00000;
	target->sc[1].writein[1] = DEBUG_SPEED;
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);

	/* NOP */
	target->sc[1].writein[0] = 0xE1A00000;
	target->sc[1].writein[1] = DEBUG_SPEED;
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);

	/* scan in the value of R0 register */
	target->sc[1].writein[0] = reg_r0->value;
	target->sc[1].writein[1] = DEBUG_SPEED;
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);

	/* 
	 * The penultimate instruction must be scanned in with bit33 set HIGH.
	 * insert NOP instruction: MOV R0, R0 = 0xE1A00000
	 */
	target->sc[1].writein[0] = 0xE1A00000;
	target->sc[1].writein[1] = SYSTEM_SPEED;
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);

	/*
	 * The final instruction is the branch instruction and it is
	 * scanned in with bit 33 set LOW. For small branches, you also
	 * can replace the final branch instruction with a substract
	 * instruction, with the PC as the destination operand.
	 * B -6 = 0xEAFFFFFA
	 */
	if (target->halt_reason == TARGET_HALTED_BY_BREAKPT)
		target->sc[1].writein[0] = 0xEAFFFFFB; /* opcode of "B -7" */
	else
		target->sc[1].writein[0] = 0xEAFFFFFA; /* opcode of "B -6" */
	target->sc[1].writein[1] = DEBUG_SPEED;	
	arm7tdmi_exec_instruction(target->sc[1].writein, target->sc[1].readout);

	/* Write RESTART instruction into the TAP controller.
	 * When the state machine enters the Run-Test/Idle state,
	 * the ARM7TDMI core will revert back to system mode,
	 * and it will resynchronize clock to MCLK.
	 */
	jtag_write_ireg(JTAG_RESTART);

	return 0;
} /* end of arm7tdmi_restart() */

struct target_operation arm7tdmi_tops = {
	/* ARM7TDMI EmbeddedICE-RT logic register read/write operations */
	.ice_read 	= arm7tdmi_ice_read,
	.ice_write 	= arm7tdmi_ice_write,

	/* ARM7TDMI cpu core operations */
	.halt		= arm7tdmi_halt,
	.restart	= arm7tdmi_restart,

	/* ARM7TDMI core registers read/write operations */
	.get_core_state = arm7tdmi_get_core_state,
	.register_read 	= arm7tdmi_register_read,
	.register_write	= arm7tdmi_register_write,

	/* ARM7TDMI target memory read/write operations */
	.mem_read16 	= arm7tdmi_memory_read16,
	.mem_write16 	= arm7tdmi_memory_write16,
	.mem_read32 	= arm7tdmi_memory_read32,
	.mem_write32 	= arm7tdmi_memory_write32,
};

int arm7tdmi_setup(void)
{
	arm7tdmi_target.regs = arm7tdmi_regs;
	arm7tdmi_target.ice_regs = arm7tdmi_ice_regs;

	target = &arm7tdmi_target;
	t_op = &arm7tdmi_tops;
	return 0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
777色狠狠一区二区三区| 欧美日韩三级视频| 精品一区二区三区的国产在线播放| 一区二区三区欧美视频| 亚洲综合色成人| 一区二区三区四区亚洲| 亚洲一区二区三区美女| 日韩中文字幕一区二区三区| 日韩av电影一区| 久久精品国产99| 国产福利电影一区二区三区| 懂色av一区二区三区免费看| 北岛玲一区二区三区四区| 99久久精品99国产精品| 欧美熟乱第一页| 欧美一区日本一区韩国一区| 精品国免费一区二区三区| 久久综合九色综合欧美就去吻| 国产欧美日韩麻豆91| 亚洲色图视频网| 日本一道高清亚洲日美韩| 国精产品一区一区三区mba视频| 国产精品一色哟哟哟| 北条麻妃一区二区三区| 4438成人网| 亚洲国产精品av| 一区二区日韩电影| 老司机一区二区| av一区二区三区在线| 91精选在线观看| 国产精品每日更新| 日本亚洲最大的色成网站www| 国产福利一区二区三区视频 | 6080日韩午夜伦伦午夜伦| 日韩亚洲欧美高清| 亚洲美女一区二区三区| 国产最新精品免费| 欧美日韩国产大片| 国产精品萝li| 精品午夜久久福利影院| 在线观看免费亚洲| 国产精品无码永久免费888| 亚洲成人激情自拍| 日韩国产在线观看| 91精品国产免费久久综合| 欧美午夜不卡在线观看免费| 欧美美女bb生活片| 亚洲精品在线免费观看视频| 欧美日本在线播放| 久久国产精品色婷婷| 久久久久久99久久久精品网站| 国产精品18久久久久久vr| 国产精品不卡在线| 欧美影院精品一区| 久久爱另类一区二区小说| 国产精品美女一区二区三区| 91国产免费看| 捆绑调教一区二区三区| 欧美国产成人在线| 欧美日韩国产美| 精品无人区卡一卡二卡三乱码免费卡| 国产蜜臀av在线一区二区三区| 色综合婷婷久久| 日日夜夜免费精品| 国产日韩欧美高清| 欧美肥妇free| 91在线观看视频| 奇米影视7777精品一区二区| 国产欧美日韩精品a在线观看| 色婷婷av一区二区三区gif | 91精品国产91久久久久久最新毛片| 免费人成在线不卡| 亚洲欧美一区二区三区孕妇| 91精品国产aⅴ一区二区| 国产大陆精品国产| 爽好多水快深点欧美视频| 国产亚洲成aⅴ人片在线观看| 欧洲一区在线观看| 成人午夜精品在线| 全国精品久久少妇| 亚洲综合色噜噜狠狠| 久久精品视频免费| 日韩限制级电影在线观看| 91蜜桃视频在线| 国产精品一二三| 蜜桃视频一区二区三区| 一区二区三区**美女毛片| 国产欧美日韩三级| 26uuu久久天堂性欧美| 7777精品伊人久久久大香线蕉超级流畅| 国产不卡免费视频| 国内成人免费视频| 日韩电影免费在线看| 亚洲午夜久久久久久久久久久| 国产夜色精品一区二区av| 欧美大尺度电影在线| 91精品久久久久久蜜臀| 欧美日韩日日骚| 欧美日韩一级黄| 色综合久久综合| 99久久99久久久精品齐齐| 成人影视亚洲图片在线| 国产二区国产一区在线观看| 久久99久久99精品免视看婷婷 | 欧美裸体bbwbbwbbw| 欧美主播一区二区三区| 色国产精品一区在线观看| 99精品偷自拍| av不卡在线播放| 99久久综合色| 成人av网站在线| 不卡的av网站| 91色婷婷久久久久合中文| 99国产精品久久久久久久久久久 | 日韩欧美亚洲国产精品字幕久久久| 91高清视频免费看| 欧美三级三级三级爽爽爽| 色诱亚洲精品久久久久久| 91麻豆6部合集magnet| 在线影视一区二区三区| 欧美亚洲图片小说| 欧美三级电影一区| 欧美顶级少妇做爰| 日韩欧美亚洲一区二区| 精品久久久久香蕉网| 欧美大片日本大片免费观看| 久久久亚洲精品石原莉奈| 国产女主播一区| 一区二区三区.www| 日韩成人精品视频| 国产精品一色哟哟哟| 91亚洲国产成人精品一区二三| 91精品福利视频| 91麻豆精品91久久久久同性| 26uuu精品一区二区| 成人免费在线观看入口| 天堂在线一区二区| 精品在线观看免费| 91亚洲精品乱码久久久久久蜜桃 | 国产欧美视频一区二区| 亚洲精品成人精品456| 天堂资源在线中文精品| 激情成人综合网| 色狠狠色狠狠综合| 欧美一级专区免费大片| 欧美国产精品专区| 亚洲超碰精品一区二区| 韩国女主播成人在线观看| 99精品视频在线免费观看| 欧美日韩国产123区| 国产午夜精品久久久久久免费视| 亚洲欧美在线视频| 蜜臀久久99精品久久久久宅男| 成人三级伦理片| 日韩欧美一级特黄在线播放| 国产精品福利一区二区| 日韩电影在线免费看| 成人一区在线看| 欧美一级搡bbbb搡bbbb| 国产精品久久一级| 日韩二区三区在线观看| 91丨porny丨中文| www国产成人| 亚洲风情在线资源站| k8久久久一区二区三区| 欧美不卡一二三| 午夜视频在线观看一区| 99国产精品久久| 久久久噜噜噜久久人人看| 天堂在线一区二区| 欧美亚洲国产一区二区三区va | 精品福利在线导航| 亚洲小少妇裸体bbw| 99re66热这里只有精品3直播| 精品久久久久香蕉网| 日韩和欧美一区二区| 在线观看成人小视频| 中文字幕日韩一区| 丁香激情综合五月| 欧美成人猛片aaaaaaa| 日韩中文字幕区一区有砖一区 | 亚洲不卡av一区二区三区| a美女胸又www黄视频久久| 久久色在线观看| 日本不卡一区二区三区| 欧美性高清videossexo| 国产精品全国免费观看高清| 国产成人免费视频一区| 国产亚洲精品超碰| 国产一区在线看| 日韩女优av电影| 免费不卡在线观看| 91精品国产综合久久久久久漫画| 亚洲国产精品一区二区久久| 在线一区二区观看| 亚洲一区二区视频在线| 欧美图区在线视频| 午夜欧美视频在线观看| 欧美日韩日日骚| 蜜臀av一区二区在线观看 |