70d6c612300a1ca8bf6e75b2ceafcdd54244cf7e
[fw/openocd] / src / target / quark_d20xx.c
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 /*
4  * Copyright(c) 2015-2016 Intel Corporation.
5  *
6  * Jessica Gomez (jessica.gomez.hernandez@intel.com)
7  * Ivan De Cesaris (ivan.de.cesaris@intel.com)
8  *
9  * Contact Information:
10  * Intel Corporation
11  */
12
13 /*
14  * @file
15  * Debugger for Intel Quark D20xx
16  * The CPU TAP (Lakemont TAP) is used for software debug and the CLTAP is
17  * used for SoC level operations.
18  *
19  * Reference document:
20  * Intel Quark microcontroller D2000 Debug Operations (web search for doc num 333241)
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <helper/log.h>
28
29 #include "target.h"
30 #include "target_type.h"
31 #include "breakpoints.h"
32 #include "lakemont.h"
33 #include "x86_32_common.h"
34
35 static int quark_d20xx_target_create(struct target *t, Jim_Interp *interp)
36 {
37         struct x86_32_common *x86_32 = calloc(1, sizeof(struct x86_32_common));
38         if (!x86_32) {
39                 LOG_ERROR("%s out of memory", __func__);
40                 return ERROR_FAIL;
41         }
42         x86_32_common_init_arch_info(t, x86_32);
43         lakemont_init_arch_info(t, x86_32);
44         x86_32->core_type = LMT3_5;
45         return ERROR_OK;
46 }
47
48 static int quark_d20xx_init_target(struct command_context *cmd_ctx, struct target *t)
49 {
50         return lakemont_init_target(cmd_ctx, t);
51 }
52
53 static int quark_d20xx_reset_deassert(struct target *t)
54 {
55         int retval;
56
57         /* Can't detect if a warm reset happened while halted but we can make the
58          * openocd and target state consistent here if in probe mode already
59          */
60         if (!check_not_halted(t)) {
61                 retval = lakemont_update_after_probemode_entry(t);
62                 if (retval != ERROR_OK) {
63                         LOG_ERROR("%s core state update fail", __func__);
64                         return retval;
65                 }
66                 /* resume target if reset mode is run */
67                 if (!t->reset_halt) {
68                         retval = lakemont_resume(t, 1, 0, 0, 0);
69                         if (retval != ERROR_OK) {
70                                 LOG_ERROR("%s could not resume target", __func__);
71                                 return retval;
72                         }
73                 }
74         }
75
76         return ERROR_OK;
77 }
78
79 struct target_type quark_d20xx_target = {
80         .name = "quark_d20xx",
81         .target_create = quark_d20xx_target_create,
82         .init_target = quark_d20xx_init_target,
83         /* lakemont probemode specific code */
84         .poll = lakemont_poll,
85         .arch_state = lakemont_arch_state,
86         .halt = lakemont_halt,
87         .resume = lakemont_resume,
88         .step = lakemont_step,
89         .assert_reset = lakemont_reset_assert,
90         .deassert_reset = quark_d20xx_reset_deassert,
91         /* common x86 code */
92         .commands = x86_32_command_handlers,
93         .get_gdb_reg_list = x86_32_get_gdb_reg_list,
94         .read_memory = x86_32_common_read_memory,
95         .write_memory = x86_32_common_write_memory,
96         .add_breakpoint = x86_32_common_add_breakpoint,
97         .remove_breakpoint = x86_32_common_remove_breakpoint,
98         .add_watchpoint = x86_32_common_add_watchpoint,
99         .remove_watchpoint = x86_32_common_remove_watchpoint,
100         .virt2phys = x86_32_common_virt2phys,
101         .read_phys_memory = x86_32_common_read_phys_mem,
102         .write_phys_memory = x86_32_common_write_phys_mem,
103         .mmu = x86_32_common_mmu,
104 };