You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

324 lines
7.8 KiB

  1. /*
  2. * Copyright(c) 2013 Intel Corporation.
  3. *
  4. * Adrian Burns (adrian.burns@intel.com)
  5. * Thomas Faust (thomas.faust@intel.com)
  6. * Ivan De Cesaris (ivan.de.cesaris@intel.com)
  7. * Julien Carreno (julien.carreno@intel.com)
  8. * Jeffrey Maxwell (jeffrey.r.maxwell@intel.com)
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  22. *
  23. * Contact Information:
  24. * Intel Corporation
  25. */
  26. /*
  27. * @file
  28. * This is the interface to the x86 32 bit memory and breakpoint operations.
  29. */
  30. #ifndef X86_32_COMMON_H
  31. #define X86_32_COMMON_H
  32. #include <jtag/jtag.h>
  33. #include <helper/command.h>
  34. extern const struct command_registration x86_32_command_handlers[];
  35. /* for memory access */
  36. #define BYTE 1
  37. #define WORD 2
  38. #define DWORD 4
  39. #define EFLAGS_TF 0x00000100 /* Trap Flag */
  40. #define EFLAGS_IF 0x00000200 /* Interrupt Flag */
  41. #define EFLAGS_RF 0x00010000 /* Resume Flag */
  42. #define EFLAGS_VM86 0x00020000 /* Virtual 8086 Mode */
  43. #define CSAR_DPL 0x00006000
  44. #define CSAR_D 0x00400000
  45. #define SSAR_DPL 0x00006000
  46. #define CR0_PE 0x00000001 /* Protected Mode Enable */
  47. #define CR0_NW 0x20000000 /* Non Write-Through */
  48. #define CR0_CD 0x40000000 /* Cache Disable */
  49. #define CR0_PG 0x80000000 /* Paging Enable */
  50. /* TODO - move back to PM specific file */
  51. #define PM_DR6 0xFFFF0FF0
  52. #define DR6_BRKDETECT_0 0x00000001 /* B0 through B3 */
  53. #define DR6_BRKDETECT_1 0x00000002 /* breakpoint condition detected */
  54. #define DR6_BRKDETECT_2 0x00000004
  55. #define DR6_BRKDETECT_3 0x00000008
  56. enum {
  57. /* general purpose registers */
  58. EAX = 0,
  59. ECX,
  60. EDX,
  61. EBX,
  62. ESP,
  63. EBP,
  64. ESI,
  65. EDI,
  66. /* instruction pointer & flags */
  67. EIP,
  68. EFLAGS,
  69. /* segment registers */
  70. CS,
  71. SS,
  72. DS,
  73. ES,
  74. FS,
  75. GS,
  76. /* floating point unit registers */
  77. ST0,
  78. ST1,
  79. ST2,
  80. ST3,
  81. ST4,
  82. ST5,
  83. ST6,
  84. ST7,
  85. FCTRL,
  86. FSTAT,
  87. FTAG,
  88. FISEG,
  89. FIOFF,
  90. FOSEG,
  91. FOOFF,
  92. FOP,
  93. /* control registers */
  94. CR0,
  95. CR2,
  96. CR3,
  97. CR4,
  98. /* debug registers */
  99. DR0,
  100. DR1,
  101. DR2,
  102. DR3,
  103. DR6,
  104. DR7,
  105. /* descriptor tables */
  106. IDTB,
  107. IDTL,
  108. IDTAR,
  109. GDTB,
  110. GDTL,
  111. GDTAR,
  112. TR,
  113. LDTR,
  114. LDTB,
  115. LDTL,
  116. LDTAR,
  117. /* segment registers */
  118. CSB,
  119. CSL,
  120. CSAR,
  121. DSB,
  122. DSL,
  123. DSAR,
  124. ESB,
  125. ESL,
  126. ESAR,
  127. FSB,
  128. FSL,
  129. FSAR,
  130. GSB,
  131. GSL,
  132. GSAR,
  133. SSB,
  134. SSL,
  135. SSAR,
  136. TSSB,
  137. TSSL,
  138. TSSAR,
  139. /* PM control reg */
  140. PMCR,
  141. };
  142. #define X86_32_COMMON_MAGIC 0x86328632
  143. enum {
  144. /* memory read/write */
  145. MEMRDB32 = 0,
  146. MEMRDB16,
  147. MEMRDH32,
  148. MEMRDH16,
  149. MEMRDW32,
  150. MEMRDW16,
  151. MEMWRB32,
  152. MEMWRB16,
  153. MEMWRH32,
  154. MEMWRH16,
  155. MEMWRW32,
  156. MEMWRW16,
  157. /* IO read/write */
  158. IORDB32,
  159. IORDB16,
  160. IORDH32,
  161. IORDH16,
  162. IORDW32,
  163. IORDW16,
  164. IOWRB32,
  165. IOWRB16,
  166. IOWRH32,
  167. IOWRH16,
  168. IOWRW32,
  169. IOWRW16,
  170. /* lakemont1 core shadow ram access opcodes */
  171. SRAMACCESS,
  172. SRAM2PDR,
  173. PDR2SRAM,
  174. WBINVD,
  175. };
  176. struct swbp_mem_patch {
  177. uint8_t orig_byte;
  178. uint32_t swbp_unique_id;
  179. uint32_t physaddr;
  180. struct swbp_mem_patch *next;
  181. };
  182. /* TODO - probemode specific - consider removing */
  183. #define NUM_PM_REGS 18 /* regs used in save/restore */
  184. struct x86_32_common {
  185. uint32_t common_magic;
  186. void *arch_info;
  187. struct reg_cache *cache;
  188. struct jtag_tap *curr_tap;
  189. uint32_t stored_pc;
  190. int flush;
  191. /* pm_regs are for probemode save/restore state */
  192. uint32_t pm_regs[NUM_PM_REGS];
  193. /* working area for fastdata access */
  194. struct working_area *fast_data_area;
  195. int num_hw_bpoints;
  196. struct x86_32_dbg_reg *hw_break_list;
  197. struct swbp_mem_patch *swbbp_mem_patch_list;
  198. /* core probemode implementation dependent functions */
  199. uint8_t (*get_num_user_regs)(struct target *t);
  200. bool (*is_paging_enabled)(struct target *t);
  201. int (*disable_paging)(struct target *t);
  202. int (*enable_paging)(struct target *t);
  203. bool (*sw_bpts_supported)(struct target *t);
  204. int (*transaction_status)(struct target *t);
  205. int (*submit_instruction)(struct target *t, int num);
  206. int (*read_hw_reg)(struct target *t, int reg, uint32_t *regval, uint8_t cache);
  207. int (*write_hw_reg)(struct target *t, int reg,
  208. uint32_t regval, uint8_t cache);
  209. /* register cache to processor synchronization */
  210. int (*read_hw_reg_to_cache)(struct target *target, int num);
  211. int (*write_hw_reg_from_cache)(struct target *target, int num);
  212. };
  213. static inline struct x86_32_common *
  214. target_to_x86_32(struct target *target)
  215. {
  216. return target->arch_info;
  217. }
  218. bool check_not_halted(const struct target *t);
  219. /* breakpoint defines */
  220. #define MAX_DEBUG_REGS 4
  221. #define SW_BP_OPCODE 0xf1
  222. #define MAX_SW_BPTS 20
  223. struct x86_32_dbg_reg {
  224. int used;
  225. uint32_t bp_value;
  226. };
  227. #define DR7_G_ENABLE_SHIFT 1
  228. #define DR7_ENABLE_SIZE 2 /* 2 bits per debug reg */
  229. #define DR7_RW_SHIFT 16
  230. #define DR7_LENGTH_SHIFT 18
  231. #define DR7_RW_LEN_SIZE 4
  232. #define DR7_BP_EXECUTE 0 /* 00 - only on instruction execution*/
  233. #define DR7_BP_WRITE 1 /* 01 - only on data writes */
  234. /*#define DR7_RW_IORW 2 UNSUPPORTED 10 - an I/O read and I/O write */
  235. #define DR7_BP_READWRITE 3 /* on data read or data write */
  236. #define DR7_BP_LENGTH_1 0 /* 00 - 1 byte length */
  237. #define DR7_BP_LENGTH_2 1 /* 01 - 2 byte length */
  238. #define DR7_BP_LENGTH_4 3 /* 11 - 4 byte length */
  239. #define DR7_GLOBAL_ENABLE(val, regnum) \
  240. (val |= (1 << (DR7_G_ENABLE_SHIFT + (DR7_ENABLE_SIZE * (regnum)))))
  241. #define DR7_GLOBAL_DISABLE(val, regnum) \
  242. (val &= ~(3 << (DR7_ENABLE_SIZE * (regnum))))
  243. #define DR7_BP_FREE(val, regnum) \
  244. ((val & (3 << (DR7_ENABLE_SIZE * (regnum)))) == 0)
  245. #define DR7_RESET_RWLEN_BITS(val, regnum) \
  246. (val &= ~(0x0f << (DR7_RW_SHIFT + DR7_RW_LEN_SIZE * (regnum))))
  247. #define DR7_SET_EXE(val, regnum) \
  248. (val &= ~(0x0f << (DR7_RW_SHIFT + DR7_RW_LEN_SIZE * (regnum))))
  249. #define DR7_SET_WRITE(val, regnum) \
  250. (val |= (DR7_BP_WRITE << (DR7_RW_SHIFT + DR7_RW_LEN_SIZE * (regnum))))
  251. #define DR7_SET_ACCESS(val, regnum) \
  252. (val |= (DR7_BP_READWRITE << (DR7_RW_SHIFT + DR7_RW_LEN_SIZE * (regnum))))
  253. #define DR7_SET_LENGTH(val, regnum, len) \
  254. (val |= (len == 1) ? (DR7_BP_LENGTH_1 << (DR7_LENGTH_SHIFT + DR7_RW_LEN_SIZE * (regnum))) : \
  255. (len == 2) ? (DR7_BP_LENGTH_2 << (DR7_LENGTH_SHIFT + DR7_RW_LEN_SIZE * (regnum))) : \
  256. (DR7_BP_LENGTH_4 << (DR7_LENGTH_SHIFT + DR7_RW_LEN_SIZE * (regnum))))
  257. /* public interface */
  258. int x86_32_get_gdb_reg_list(struct target *t,
  259. struct reg **reg_list[], int *reg_list_size,
  260. enum target_register_class reg_class);
  261. int x86_32_common_init_arch_info(struct target *target,
  262. struct x86_32_common *x86_32);
  263. int x86_32_common_mmu(struct target *t, int *enabled);
  264. int x86_32_common_virt2phys(struct target *t, uint32_t address, uint32_t *physical);
  265. int x86_32_common_read_phys_mem(struct target *t, uint32_t phys_address,
  266. uint32_t size, uint32_t count, uint8_t *buffer);
  267. int x86_32_common_write_phys_mem(struct target *t, uint32_t phys_address,
  268. uint32_t size, uint32_t count, const uint8_t *buffer);
  269. int x86_32_common_read_memory(struct target *t, uint32_t addr,
  270. uint32_t size, uint32_t count, uint8_t *buf);
  271. int x86_32_common_write_memory(struct target *t, uint32_t addr,
  272. uint32_t size, uint32_t count, const uint8_t *buf);
  273. int x86_32_common_read_io(struct target *t, uint32_t addr,
  274. uint32_t size, uint8_t *buf);
  275. int x86_32_common_write_io(struct target *t, uint32_t addr,
  276. uint32_t size, const uint8_t *buf);
  277. int x86_32_common_add_breakpoint(struct target *t, struct breakpoint *bp);
  278. int x86_32_common_remove_breakpoint(struct target *t, struct breakpoint *bp);
  279. int x86_32_common_add_watchpoint(struct target *t, struct watchpoint *wp);
  280. int x86_32_common_remove_watchpoint(struct target *t, struct watchpoint *wp);
  281. #endif /* X86_32_COMMON_H */