1 /*
2  * Copyright(c) 2015-2016 Intel Corporation.
3  *
4  * Jessica Gomez (jessica.gomez.hernandez@intel.com)
5  * Ivan De Cesaris (ivan.de.cesaris@intel.com)
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  * Contact Information:
21  * Intel Corporation
22  */
23 
24 /*
25  * @file
26  * Debugger for Intel Quark D20xx
27  * The CPU TAP (Lakemont TAP) is used for software debug and the CLTAP is
28  * used for SoC level operations.
29  *
30  * Reference document:
31  * Intel Quark microcontroller D2000 Debug Operations (web search for doc num 333241)
32  */
33 
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
37 
38 #include <helper/log.h>
39 
40 #include "target.h"
41 #include "target_type.h"
42 #include "breakpoints.h"
43 #include "lakemont.h"
44 #include "x86_32_common.h"
45 
quark_d20xx_target_create(struct target * t,Jim_Interp * interp)46 static int quark_d20xx_target_create(struct target *t, Jim_Interp *interp)
47 {
48 	struct x86_32_common *x86_32 = calloc(1, sizeof(struct x86_32_common));
49 	if (x86_32 == NULL) {
50 		LOG_ERROR("%s out of memory", __func__);
51 		return ERROR_FAIL;
52 	}
53 	x86_32_common_init_arch_info(t, x86_32);
54 	lakemont_init_arch_info(t, x86_32);
55 	x86_32->core_type = LMT3_5;
56 	return ERROR_OK;
57 }
58 
quark_d20xx_init_target(struct command_context * cmd_ctx,struct target * t)59 static int quark_d20xx_init_target(struct command_context *cmd_ctx, struct target *t)
60 {
61 	return lakemont_init_target(cmd_ctx, t);
62 }
63 
quark_d20xx_reset_deassert(struct target * t)64 static int quark_d20xx_reset_deassert(struct target *t)
65 {
66 	int retval;
67 
68 	/* Can't detect if a warm reset happened while halted but we can make the
69 	 * openocd and target state consistent here if in probe mode already
70 	 */
71 	if (!check_not_halted(t)) {
72 		retval = lakemont_update_after_probemode_entry(t);
73 		if (retval != ERROR_OK) {
74 			LOG_ERROR("%s core state update fail", __func__);
75 			return retval;
76 		}
77 		/* resume target if reset mode is run */
78 		if (!t->reset_halt) {
79 			retval = lakemont_resume(t, 1, 0, 0, 0);
80 			if (retval != ERROR_OK) {
81 				LOG_ERROR("%s could not resume target", __func__);
82 				return retval;
83 			}
84 		}
85 	}
86 
87 	return ERROR_OK;
88 }
89 
90 struct target_type quark_d20xx_target = {
91 	.name = "quark_d20xx",
92 	.target_create = quark_d20xx_target_create,
93 	.init_target = quark_d20xx_init_target,
94 	/* lakemont probemode specific code */
95 	.poll = lakemont_poll,
96 	.arch_state = lakemont_arch_state,
97 	.halt = lakemont_halt,
98 	.resume = lakemont_resume,
99 	.step = lakemont_step,
100 	.assert_reset = lakemont_reset_assert,
101 	.deassert_reset = quark_d20xx_reset_deassert,
102 	/* common x86 code */
103 	.commands = x86_32_command_handlers,
104 	.get_gdb_reg_list = x86_32_get_gdb_reg_list,
105 	.read_memory = x86_32_common_read_memory,
106 	.write_memory = x86_32_common_write_memory,
107 	.add_breakpoint = x86_32_common_add_breakpoint,
108 	.remove_breakpoint = x86_32_common_remove_breakpoint,
109 	.add_watchpoint = x86_32_common_add_watchpoint,
110 	.remove_watchpoint = x86_32_common_remove_watchpoint,
111 	.virt2phys = x86_32_common_virt2phys,
112 	.read_phys_memory = x86_32_common_read_phys_mem,
113 	.write_phys_memory = x86_32_common_write_phys_mem,
114 	.mmu = x86_32_common_mmu,
115 };
116