blob: eb882d02e4a945eb330933af085ddbc81ff0b47d [file] [log] [blame]
Stefan Reinauer38cd29e2009-08-11 21:28:25 +00001/******************************************************************************
2 * Copyright (c) 2004, 2008 IBM Corporation
3 * Copyright (c) 2009 Pattrick Hueper <phueper@hueper.net>
4 * All rights reserved.
5 * This program and the accompanying materials
6 * are made available under the terms of the BSD License
7 * which accompanies this distribution, and is available at
8 * http://www.opensource.org/licenses/bsd-license.php
9 *
10 * Contributors:
11 * IBM Corporation - initial implementation
12 *****************************************************************************/
13#ifndef _BIOSEMU_DEBUG_H_
14#define _BIOSEMU_DEBUG_H_
15
Denis 'GNUtoo' Carikli4cdc5d62013-05-15 00:19:49 +020016#include <timer.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000017#include <types.h>
18
Stefan Reinauer21f81932015-10-21 13:04:34 -070019#if IS_ENABLED(CONFIG_X86EMU_DEBUG_TIMINGS)
Denis 'GNUtoo' Carikli4cdc5d62013-05-15 00:19:49 +020020extern struct mono_time zero;
21#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000022extern u32 debug_flags;
23// from x86emu...needed for debugging
24extern void x86emu_dump_xregs(void);
25
26/* printf is not available in coreboot... use printk */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000027#include <console/console.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000028#include "x86emu/x86emu.h"
Uwe Hermann01ce6012010-03-05 10:03:50 +000029#define printf(x...) printk(BIOS_DEBUG, x)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000030
31/* PH: empty versions of set/clr_ci
32 * TODO: remove! */
33static inline void clr_ci(void) {};
34static inline void set_ci(void) {};
35
Uwe Hermann01ce6012010-03-05 10:03:50 +000036/* debug_flags is a binary switch that allows you to select the following items
37 * to debug. 1=on 0=off. After you decide what you want to debug create the
38 * binary value, convert to hex and set the option. These options can be
39 * selected in Kconfig.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000040 *
41 * |-DEBUG_JMP - print info about JMP and RETF opcodes from x86emu
42 * ||-DEBUG_TRACE_X86EMU - print _all_ opcodes that are executed by x86emu (WARNING: this will produce a LOT of output)
43 * |||-Currently unused
44 * ||||-Currently unused
45 * |||||-Currently unused
Stefan Reinauer14e22772010-04-27 06:56:47 +000046 * ||||||-DEBUG_PNP - Print Plug And Play access made by option rom
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000047 * |||||||-DEBUG_DISK - Print Disk I/O related messages, currently unused
48 * ||||||||-DEBUG_PMM - Print messages related to POST Memory Manager (PMM)
49 * |||||||||-DEBUG_VBE - Print messages related to VESA BIOS Extension (VBE) functions
50 * ||||||||||-DEBUG_PRINT_INT10 - let INT10 (i.e. character output) calls print messages to Debug output
51 * |||||||||||-DEBUG_INTR - Print messages related to interrupt handling
52 * ||||||||||||-DEBUG_CHECK_VMEM_ACCESS - Print messages related to accesse to certain areas of the virtual Memory (e.g. BDA (BIOS Data Area) or Interrupt Vectors)
53 * |||||||||||||-DEBUG_MEM - Print memory access made by option rom (NOTE: this also includes accesses to fetch instructions)
Stefan Reinauer14e22772010-04-27 06:56:47 +000054 * ||||||||||||||-DEBUG_IO - Print I/O access made by option rom
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000055 * 11000111111111 - Max Binary Value, Debug All (WARNING: - This could run for hours)
56 */
57
58#define DEBUG_IO 0x1
59#define DEBUG_MEM 0x2
60// set this to print messages for certain virtual memory accesses (Interrupt Vectors, ...)
61#define DEBUG_CHECK_VMEM_ACCESS 0x4
62#define DEBUG_INTR 0x8
63#define DEBUG_PRINT_INT10 0x10 // set to have the INT10 routine print characters
64#define DEBUG_VBE 0x20
65#define DEBUG_PMM 0x40
66#define DEBUG_DISK 0x80
67#define DEBUG_PNP 0x100
68
69#define DEBUG_TRACE_X86EMU 0x1000
70// set to enable tracing of JMPs in x86emu
71#define DEBUG_JMP 0x2000
72
Stefan Reinauer21f81932015-10-21 13:04:34 -070073#if IS_ENABLED(CONFIG_X86EMU_DEBUG)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000074
75#define CHECK_DBG(_flag) if (debug_flags & _flag)
76
77#define DEBUG_PRINTF(_x...) printf(_x);
78// prints the CS:IP before the printout, NOTE: actually its CS:IP of the _next_ instruction
79// to be executed, since the x86emu advances CS:IP _before_ actually executing an instruction
Denis 'GNUtoo' Carikli4cdc5d62013-05-15 00:19:49 +020080
Stefan Reinauer21f81932015-10-21 13:04:34 -070081#if IS_ENABLED(CONFIG_X86EMU_DEBUG_TIMINGS)
Denis 'GNUtoo' Carikli4cdc5d62013-05-15 00:19:49 +020082#define DEBUG_PRINTF_CS_IP(_x...) DEBUG_PRINTF("[%08lx]%x:%x ", (current_time_from(&zero)).microseconds, M.x86.R_CS, M.x86.R_IP); DEBUG_PRINTF(_x);
83#else
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000084#define DEBUG_PRINTF_CS_IP(_x...) DEBUG_PRINTF("%x:%x ", M.x86.R_CS, M.x86.R_IP); DEBUG_PRINTF(_x);
Denis 'GNUtoo' Carikli4cdc5d62013-05-15 00:19:49 +020085#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000086
87#define DEBUG_PRINTF_IO(_x...) CHECK_DBG(DEBUG_IO) { DEBUG_PRINTF_CS_IP(_x) }
88#define DEBUG_PRINTF_MEM(_x...) CHECK_DBG(DEBUG_MEM) { DEBUG_PRINTF_CS_IP(_x) }
89#define DEBUG_PRINTF_INTR(_x...) CHECK_DBG(DEBUG_INTR) { DEBUG_PRINTF_CS_IP(_x) }
90#define DEBUG_PRINTF_VBE(_x...) CHECK_DBG(DEBUG_VBE) { DEBUG_PRINTF_CS_IP(_x) }
91#define DEBUG_PRINTF_PMM(_x...) CHECK_DBG(DEBUG_PMM) { DEBUG_PRINTF_CS_IP(_x) }
92#define DEBUG_PRINTF_DISK(_x...) CHECK_DBG(DEBUG_DISK) { DEBUG_PRINTF_CS_IP(_x) }
93#define DEBUG_PRINTF_PNP(_x...) CHECK_DBG(DEBUG_PNP) { DEBUG_PRINTF_CS_IP(_x) }
94
95#else
96
97#define CHECK_DBG(_flag) if (0)
98
99#define DEBUG_PRINTF(_x...)
100#define DEBUG_PRINTF_CS_IP(_x...)
101
102#define DEBUG_PRINTF_IO(_x...)
103#define DEBUG_PRINTF_MEM(_x...)
104#define DEBUG_PRINTF_INTR(_x...)
105#define DEBUG_PRINTF_VBE(_x...)
106#define DEBUG_PRINTF_PMM(_x...)
107#define DEBUG_PRINTF_DISK(_x...)
108#define DEBUG_PRINTF_PNP(_x...)
109
Myles Watson8e9234f2010-02-19 19:08:11 +0000110#endif //DEBUG
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000111
112void dump(u8 * addr, u32 len);
113
114#endif