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

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

?? arm7tdmi.c

?? 自制JTAG調試代碼
?? C
?? 第 1 頁 / 共 3 頁
字號:
/*
 * arm7tdmi.c:	implement the core routes for ARM7TDMI
 *
 * Copyright (C) 2004, OPEN-JTAG, All rights reserved.
 */

#include <windows.h>
#include "../tool.h"
#include "../xjerr.h"
#include "../tapctrl.h"
#include "arm7tdmi.h"
#include "ice.h"



//Used to record some important staus of the arm7tdmi
arm7tdmi_status_t arm7tdmi_status;
static arm7tdmi_breakpt_list_t *arm7tdmi_breakpt_head = NULL;
static arm7tdmi_watchpt_status_t arm7tdmi_watchpt_status = {0, 0};

/*
 * arm7tdmi_init() -
 *		Used to initialize the arm7tdmi's core status.
 *		Please call this route before starting any debug
 *		operations.
 */
int arm7tdmi_init(void)
{
	arm7tdmi_status.by = -1;
	arm7tdmi_status.scanchain = 3;				//On reset, scan chain 3 is selected by default.
	arm7tdmi_status.from = ARM7TDMI_FROM_ARM;
	arm7tdmi_status.state = ARM7TDMI_SYSTEM_STATE;
	arm7tdmi_status.endian = ARM7TDMI_LITTLE_END;
	
	return XJ_OK;	
}


/*
 * arm7tdmi_connect_scanchain() - 
 *		Used to select specific scan chian of arm7tmi and put
 *		the selected scan chain into test state. Before returning,
 *		the avtive scan chain is updated.
 *
 *		@sc_num: the scan chain to be selected.
 */
int arm7tdmi_connect_scanchain(int sc_num)
{
	int status;
	int shift_out;

	if(sc_num < 0 || sc_num > ARM7TDMI_NUMOF_SCANCHAIN)
		return XJ_ERROR;

	/*
	 * In SYSTEM state, select scan chain 0 and 1 is not allowed. Select scan
	 * chain 0 or 1 when in SYSTEM state will affect the debug and put the debug
	 * into unpredictable situation.
	 */
	if( (arm7tdmi_status.state != ARM7TDMI_DEBUG_STATE) && (sc_num != 2) )
		return XJERR_TARGET_RUNNING;

	status = tapctrl_acs_ireg(JTAG_SCAN_N);
	if(status != XJ_OK)
		return status;

	status = tapctrl_acs_dreg(ARM7TDMI_REGLEN_SCSEL, &sc_num, &shift_out);
	if(status != XJ_OK)
		return status;
	if(shift_out != 0x8)			//shift out should be b1000
		return XJERR_SCANCHAIN_FAIL;

	//Enter INTEST state
	status = tapctrl_acs_ireg(JTAG_INTEST);
	if(status != XJ_OK)
		return status;
	
	//Update the active scan chain
	arm7tdmi_status.scanchain = sc_num;

	return XJ_OK;
}


/*
 * arm7tdmi_acs_sc1() - 
 *		Used to acces scan chain 1. By calling this route, ARM/THUMB 
 *		instructions can be scaned into the databus and clocked into
 *		the pipeline. When scan chain 1 is selected and put into 
 *		INTEST state, everytime enter the RUN-TEST/IDLE state, a DCLK
 *		is generated. Please make sure scan chain 1 is selected and 
 *		put it into INTEST state before calling this route.
 * 
 *		Due to the reverse bit sequence of scan chain 1 cells,
 *		all the data shifted in and out from scan chain 1 should
 *		be reversed.
 *
 *		@shift_in:  data shifted into scan chain 1
 *		@shift_out: data shifted out from scan chain 1
 */
int arm7tdmi_acs_sc1(u32 *shift_in, u32 *shift_out)
{
	int status;
	u32 in_temp[2];
	u32 out_temp[2];

	//In DEBUG state?
	if(arm7tdmi_status.state != ARM7TDMI_DEBUG_STATE)
		return XJERR_TARGET_RUNNING;
	
	//Scan chain 1 selected?
	if(arm7tdmi_status.scanchain != 1)
		return XJERR_SC1_NOT_SELECTED;
	
	tool_reverse_bit_order(ARM7TDMI_REGLEN_SC1, shift_in, in_temp);		//Revert shifted in
	status = tapctrl_acs_dreg(ARM7TDMI_REGLEN_SC1, in_temp, out_temp);
	tool_reverse_bit_order(ARM7TDMI_REGLEN_SC1, out_temp, shift_out);	//Revert shifted out
	
	return XJ_OK;
}


/*
 * arm7tdmi_system_reste() -
 *		This route use nRESET to reset the system.
 *		To reset the system by nRESET, there must have a
 *		connection between the jtag interface and nRESET
 */
int arm7tdmi_system_reset(void)
{
	return XJ_OK;
}


/*
 * arm7tdmi_enter_dbgstat() - 
 *		This route is used to force the target enter DEBUG state by 
 *		forcing DEBUGRQ signal HIGH. The value of PC when entering
 *		DEBUG state is recorded. 
 *
 *		The obtained value of PC indicates the next instruction to 
 *		be executed on exit from DEBUG state, which is important and
 *		critcal to resume the normal execution of program under debug.
 *		It is for later use to return from the DEBUG state back to 
 *		the SYSTEM state.
 *
 *		Please modify this function carefully.
 * 
 *		@pc:	used to return the value of PC which indicates the
 *				next instruction to be execute on exit from DEBUG
 *				state.
 */
int arm7tdmi_enter_dbgstat(u32 *pc)
{
	int status;
	u32 r0;
	u32 dbgstat;
	u32 shift_in[2];
	u32 shift_out[2];

	if(pc == NULL)
		return XJERR_INVALID_PARAMATER;

	//Check whether already in DEBUG state?
	if(arm7tdmi_status.state == ARM7TDMI_DEBUG_STATE)
		return XJERR_TARGET_HALTED;

	//Enter DEBUG state by forcing DEBUGRQ signal HIGH 
	
	//Select scan chain 2
	status = arm7tdmi_connect_scanchain(2);
	if(status != XJ_OK)
		return status;
	
	//Write DEBUG control register
	status = arm7tdmi_ice_write(ARM7TDMI_ICE_DBGCTRL, 0x6);
	status = tapctrl_runtest();

	//Check the DBGACK signal to judge whether operation success?
	status = arm7tdmi_ice_read(ARM7TDMI_ICE_DBGSTAT, &dbgstat);
	if(status != XJ_OK)
		return status;
	if( (dbgstat & 0x1) == 0 )
		return XJERR_ENTDBG_FAIL;

	//Successful, update the arm7tdmi status
	arm7tdmi_status.by = ARM7TDMI_BY_BREAKPT;
	arm7tdmi_status.state = ARM7TDMI_DEBUG_STATE;
	
	if (dbgstat & 0x10)
		arm7tdmi_status.from = ARM7TDMI_FROM_THUMB;
	else
		arm7tdmi_status.from = ARM7TDMI_FROM_ARM;

	/*
	 * Don't forget to clear the DEBUG control register to 
	 * avoid enter DEBUG state. This is necessary.
	 */
	arm7tdmi_ice_write(ARM7TDMI_ICE_DBGCTRL, 0x0);


	/*
	 * Try to obtain the value of PC when entering DEBUG state. The obtained
	 * value of PC indicates the next instruction to be executed on exit from
	 * DEBUG state.
	 */

	//Select scan chain 1
	status = arm7tdmi_connect_scanchain(1);
	if(status != XJ_OK)
		return status;

	if(arm7tdmi_status.from == ARM7TDMI_FROM_ARM){    //Enter DEBUG from ARM state

		//Step 1 - Read R0

		//STR R0, [R0] = 0xE5800000					
		shift_in[0] = 0xE5800000;					//Instruction 1
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP
		shift_in[0] = ARM7TDMI_NOP;					//Instruction 2
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP
		shift_in[0] = ARM7TDMI_NOP;					//Instruction 3
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP
		shift_in[0] = ARM7TDMI_NOP;
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);
		r0 = shift_out[0];

		//Step 2 - Move PC to R0

		//MOV R0, PC = 0xE1A0000F
		shift_in[0] = 0xE1A0000F;					//Instruction 4
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);	

		//NOP
		shift_in[0] = ARM7TDMI_NOP;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP
		shift_in[0] = ARM7TDMI_NOP;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//Step 3 - Read the value of PC from R0

		//STR R0, [R0] = 0xE5800000
		shift_in[0] = 0xE5800000;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP
		shift_in[0] = ARM7TDMI_NOP;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP
		shift_in[0] = ARM7TDMI_NOP;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP
		shift_in[0] = ARM7TDMI_NOP;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);
		*pc = shift_out[0];

		/* 
		 * Entry into DEBUG state through a debug request is similar to a 
		 * breakpoint. However, unlike a breakpoint, the last instruction 
		 * has completed execution and so must not be refetched on exit 
		 * from DEBUG state. You can assume that entry to DEBUG state adds
		 * three addresses to the PC and every instruction executed in DEBUG
		 * state adds one address. To move the value of PC to R0, 4 instructions
		 * have been executed in DEBUG state. So, the value of PC which 
		 * indicates the next instruction should be executed on exit from 
		 * DEBUG state is
		 *				pc - 4 x (3 + 4)
		 */
		*pc -= 28;

	}else{		//Enter DEBUG from THUMB state
		
		//Step 1 - Read R0 

		//STR R0, [R0] = 0x60006000
		shift_in[0] = 0x60006000;					//Instruction 1
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP 
		shift_in[0] = 0x1C001C00;					//Instruction 2
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP 
		shift_in[0] = 0x1C001C00;					//Instruction 3
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//R0
		shift_in[0] = 0x1C001C00;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);
		r0 = shift_out[0];

		//Step 2 - Move PC to R0

		//MOV R0, PC = 0x46784678
		shift_in[0] = 0x46784678;					//Instruction 4			
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP 
		shift_in[0] = 0x1C001C00;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP 
		shift_in[0] = 0x1C001C00;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//Step 3 - Read the value of PC from R0

		//STR R0, [R0] = 0x60006000
		shift_in[0] = 0x60006000;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP 
		shift_in[0] = 0x1C001C00;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP 
		shift_in[0] = 0x1C001C00;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP 
		shift_in[0] = 0x1C001C00;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);
		*pc = shift_out[0];

		/* 
		 * Entry into DEBUG state through a debug request is similar to a 
		 * breakpoint. However, unlike a breakpoint, the last instruction 
		 * has completed execution and so must not be refetched on exit 
		 * from DEBUG state. You can assume that entry to DEBUG state adds
		 * three addresses to the PC and every instruction executed in DEBUG
		 * state adds one address. To move the value of PC to R0, 4 instructions
		 * have been executed in DEBUG state. So, the value of PC which 
		 * indicates the next instruction should be executed on exit from 
		 * DEBUG state is
		 *				pc - 2 x (3 + 4)
		 */
		*pc -= 14;

		//Step4 - Switch from THUMB state to ARM state

		/*
		 * When enter DEBUG state from THUBM state, we make ARM7TDMI enter ARM 
		 * state before any other debug operation is performed. Before leave the
		 * DEBUG state, we make ARM7TDMI return back to THUMB state before the
		 * normal operation is resumed.
		 */

		//BX PC = 0x47784778
		shift_in[0] = 0x47784778;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP 
		shift_in[0] = 0x1C001C00;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);

		//NOP 
		shift_in[0] = 0x1C001C00;					
		shift_in[1] = ARM7TDMI_DEBUG_SPEED;
		arm7tdmi_acs_sc1(shift_in, shift_out);
	}

	//Last Step - Restore R0
	arm7tdmi_core_wri_reg(ARM7TDMI_R0, r0);

	return XJ_OK;
}


/* 
 * arm7tdmi_check_dbgstat() -
 *		After some breakpts or watchpts are setting, this route is used
 *		to check the DEBUG status register to check whether the ARM7TDMI
 *		enter DEBUG state by breakpt/watchpt. 
 *
 *		When DBGACK flag is not set, XJ_ERROR is returned. When DBGACK 
 *		flag is set, it means the ARM7TDMI is in DEBUG state. Next, try
 *		to obtain the value of PC when entering the DEBUG state. 
 *
 *		The obtained value of PC indicates the next instruction to be 
 *		executed on exit from DEBUG state, which is important and
 *		critcal to resume the normal execution of program under debug.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产69精品一区二区亚洲孕妇| 91麻豆精品在线观看| 国产麻豆91精品| 成人免费视频播放| 欧美日韩高清在线播放| 精品国产乱码久久久久久夜甘婷婷| 久久精品视频免费| 亚洲电影视频在线| 成人一级黄色片| 91精品国产aⅴ一区二区| 亚洲欧洲日韩综合一区二区| 日韩不卡一区二区| 在线精品视频小说1| 国产亚洲午夜高清国产拍精品| 亚洲图片有声小说| 91女人视频在线观看| 国产亚洲污的网站| 麻豆极品一区二区三区| 欧美日韩免费视频| 亚洲视频综合在线| 不卡电影免费在线播放一区| 欧美变态凌虐bdsm| 日韩国产欧美在线视频| 91国在线观看| 日韩美女精品在线| 成人午夜视频免费看| 久久伊人蜜桃av一区二区| 亚洲成在人线在线播放| 91精品1区2区| 亚洲激情第一区| 91日韩精品一区| 亚洲欧洲国产日韩| av亚洲精华国产精华| 国产精品美女一区二区| 福利电影一区二区三区| 欧美激情自拍偷拍| 成人一二三区视频| 亚洲欧美综合在线精品| 波多野结衣亚洲一区| 国产精品美日韩| 99精品偷自拍| 亚洲精品一二三| 色婷婷精品大视频在线蜜桃视频| 一区在线观看视频| 欧洲国产伦久久久久久久| 亚洲精品日韩一| 欧美亚洲国产bt| 亚洲国产欧美日韩另类综合| 欧美三级日本三级少妇99| 亚洲精品国产成人久久av盗摄| 91尤物视频在线观看| 一区二区三区中文免费| 欧美性猛交xxxxxxxx| 亚洲成av人片| 日韩欧美不卡一区| 国产精品影视在线观看| 国产精品福利一区二区三区| 99r精品视频| 亚洲图片欧美一区| 欧美一卡二卡三卡| 国产在线麻豆精品观看| 国产欧美一区二区精品性色超碰| 成人永久aaa| 亚洲一区二区视频| 欧美变态口味重另类| 不卡的av中国片| 日韩国产高清在线| 国产片一区二区| 在线观看亚洲精品视频| 日本欧美在线看| 亚洲国产精品成人久久综合一区| 欧美日韩激情在线| 毛片一区二区三区| 欧美激情一区二区三区全黄| 在线观看成人小视频| 奇米四色…亚洲| 欧美激情一区二区三区在线| 欧美视频一区二区三区四区 | 人妖欧美一区二区| 精品三级在线观看| 99re热视频精品| 日韩成人av影视| 综合av第一页| 日韩你懂的电影在线观看| av在线不卡观看免费观看| 爽好多水快深点欧美视频| 国产精品久久久久三级| 91精品国产色综合久久 | 日韩精品一级中文字幕精品视频免费观看| 日韩欧美aaaaaa| 欧美日韩在线三级| 成人激情校园春色| 国产在线播放一区三区四| 亚洲一区二区三区爽爽爽爽爽 | 国产一区二区精品久久99| 亚洲国产成人精品视频| 国产日韩欧美一区二区三区乱码| 欧美区一区二区三区| 91性感美女视频| 国产乱人伦偷精品视频不卡| 日本少妇一区二区| 亚洲不卡一区二区三区| 亚洲美女免费视频| 国产精品青草久久| 久久久久久免费网| 欧美成人综合网站| 欧美丰满嫩嫩电影| 欧美丰满高潮xxxx喷水动漫| 91精品福利在线| 91色.com| 99久久99精品久久久久久| 成人性生交大片免费看在线播放| 精品综合免费视频观看| 免费在线看成人av| 肉色丝袜一区二区| 午夜精品久久久久久久久久久| 一区二区三区电影在线播| 亚洲欧美日韩一区| 亚洲精品乱码久久久久久| 亚洲人精品午夜| 亚洲色欲色欲www| 亚洲欧美福利一区二区| 亚洲天堂中文字幕| 亚洲欧美日韩国产另类专区 | 久久久久久久久久久久久久久99 | 欧美日韩一区 二区 三区 久久精品| 波多野结衣中文一区| 国产 欧美在线| 成人av影视在线观看| jizz一区二区| 欧美在线看片a免费观看| 欧美日韩精品欧美日韩精品| 欧美日韩激情在线| 日韩免费观看高清完整版 | 亚洲欧洲av在线| 一片黄亚洲嫩模| 日韩精品成人一区二区三区| 蜜臀国产一区二区三区在线播放| 男女男精品网站| 国产在线精品不卡| 99在线视频精品| 欧美视频在线不卡| 精品国产乱子伦一区| 亚洲欧洲精品成人久久奇米网| 亚洲影视在线播放| 久久国产精品免费| 成人激情开心网| 欧美日韩免费不卡视频一区二区三区| 欧美伦理影视网| 欧美精品一区二区三区很污很色的 | 日韩精品一区二区三区视频| 久久精品人人做人人综合| 亚洲丝袜自拍清纯另类| 蜜桃av噜噜一区| av一二三不卡影片| 日韩欧美区一区二| 亚洲同性同志一二三专区| 日韩—二三区免费观看av| 成人国产在线观看| 欧美一区二区三区视频免费播放| 日本一区二区成人| 天天操天天综合网| 不卡一区二区三区四区| 日韩一区二区电影网| 亚洲天堂2014| 国产精品白丝jk白祙喷水网站| 欧美亚洲国产一区在线观看网站| 欧美v日韩v国产v| 亚洲综合在线视频| 粉嫩嫩av羞羞动漫久久久| 欧美日韩不卡在线| 亚洲人成在线播放网站岛国 | 色综合天天综合狠狠| 精品少妇一区二区三区免费观看 | 99re6这里只有精品视频在线观看| 日韩一区二区免费在线电影| 亚洲免费看黄网站| 国产成人aaa| 欧美刺激午夜性久久久久久久| 一级做a爱片久久| 成人网男人的天堂| 久久综合九色综合欧美98| 亚洲成av人综合在线观看| 色综合 综合色| 国产精品久久免费看| 激情亚洲综合在线| 日韩视频在线你懂得| 亚洲mv大片欧洲mv大片精品| 91麻豆免费视频| 中文字幕亚洲成人| 成人黄色综合网站| 国产女人水真多18毛片18精品视频| 免费人成在线不卡| 91精品国产91综合久久蜜臀| 亚洲va国产天堂va久久en| 欧美性猛交xxxxxx富婆| 亚洲夂夂婷婷色拍ww47| 色综合久久久久久久久| 亚洲视频免费看| 色综合一区二区三区|