blob: d93fc6e4c10422cf4bf1a67ecf03a0c7a7596715 [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>
Martin Rotha9e1a222016-01-14 14:15:24 -07004 *
Stefan Reinauer38cd29e2009-08-11 21:28:25 +00005 * All rights reserved.
Martin Rotha9e1a222016-01-14 14:15:24 -07006 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000030 *
31 * Contributors:
32 * IBM Corporation - initial implementation
33 *****************************************************************************/
34#ifndef _BIOSEMU_DEBUG_H_
35#define _BIOSEMU_DEBUG_H_
36
Denis 'GNUtoo' Carikli4cdc5d62013-05-15 00:19:49 +020037#include <timer.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000038#include <types.h>
39
Julius Wernercd49cce2019-03-05 16:53:33 -080040#if CONFIG(X86EMU_DEBUG_TIMINGS)
Denis 'GNUtoo' Carikli4cdc5d62013-05-15 00:19:49 +020041extern struct mono_time zero;
42#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000043extern u32 debug_flags;
44// from x86emu...needed for debugging
45extern void x86emu_dump_xregs(void);
46
47/* printf is not available in coreboot... use printk */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000048#include <console/console.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000049#include "x86emu/x86emu.h"
Uwe Hermann01ce6012010-03-05 10:03:50 +000050#define printf(x...) printk(BIOS_DEBUG, x)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000051
52/* PH: empty versions of set/clr_ci
53 * TODO: remove! */
54static inline void clr_ci(void) {};
55static inline void set_ci(void) {};
56
Uwe Hermann01ce6012010-03-05 10:03:50 +000057/* debug_flags is a binary switch that allows you to select the following items
58 * to debug. 1=on 0=off. After you decide what you want to debug create the
59 * binary value, convert to hex and set the option. These options can be
60 * selected in Kconfig.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000061 *
62 * |-DEBUG_JMP - print info about JMP and RETF opcodes from x86emu
63 * ||-DEBUG_TRACE_X86EMU - print _all_ opcodes that are executed by x86emu (WARNING: this will produce a LOT of output)
64 * |||-Currently unused
65 * ||||-Currently unused
66 * |||||-Currently unused
Stefan Reinauer14e22772010-04-27 06:56:47 +000067 * ||||||-DEBUG_PNP - Print Plug And Play access made by option rom
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000068 * |||||||-DEBUG_DISK - Print Disk I/O related messages, currently unused
69 * ||||||||-DEBUG_PMM - Print messages related to POST Memory Manager (PMM)
70 * |||||||||-DEBUG_VBE - Print messages related to VESA BIOS Extension (VBE) functions
71 * ||||||||||-DEBUG_PRINT_INT10 - let INT10 (i.e. character output) calls print messages to Debug output
72 * |||||||||||-DEBUG_INTR - Print messages related to interrupt handling
73 * ||||||||||||-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)
Elyes HAOUASfa640a22016-07-28 21:31:40 +020074 * |||||||||||||-DEBUG_MEM - Print memory access made by option ROM (NOTE: this also includes accesses to fetch instructions)
Stefan Reinauer14e22772010-04-27 06:56:47 +000075 * ||||||||||||||-DEBUG_IO - Print I/O access made by option rom
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000076 * 11000111111111 - Max Binary Value, Debug All (WARNING: - This could run for hours)
77 */
78
79#define DEBUG_IO 0x1
80#define DEBUG_MEM 0x2
81// set this to print messages for certain virtual memory accesses (Interrupt Vectors, ...)
82#define DEBUG_CHECK_VMEM_ACCESS 0x4
83#define DEBUG_INTR 0x8
84#define DEBUG_PRINT_INT10 0x10 // set to have the INT10 routine print characters
85#define DEBUG_VBE 0x20
86#define DEBUG_PMM 0x40
87#define DEBUG_DISK 0x80
88#define DEBUG_PNP 0x100
89
90#define DEBUG_TRACE_X86EMU 0x1000
91// set to enable tracing of JMPs in x86emu
92#define DEBUG_JMP 0x2000
93
Julius Wernercd49cce2019-03-05 16:53:33 -080094#if CONFIG(X86EMU_DEBUG)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000095
96#define CHECK_DBG(_flag) if (debug_flags & _flag)
97
98#define DEBUG_PRINTF(_x...) printf(_x);
99// prints the CS:IP before the printout, NOTE: actually its CS:IP of the _next_ instruction
100// to be executed, since the x86emu advances CS:IP _before_ actually executing an instruction
Denis 'GNUtoo' Carikli4cdc5d62013-05-15 00:19:49 +0200101
Julius Wernercd49cce2019-03-05 16:53:33 -0800102#if CONFIG(X86EMU_DEBUG_TIMINGS)
Denis 'GNUtoo' Carikli4cdc5d62013-05-15 00:19:49 +0200103#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);
104#else
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000105#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 +0200106#endif
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000107
108#define DEBUG_PRINTF_IO(_x...) CHECK_DBG(DEBUG_IO) { DEBUG_PRINTF_CS_IP(_x) }
109#define DEBUG_PRINTF_MEM(_x...) CHECK_DBG(DEBUG_MEM) { DEBUG_PRINTF_CS_IP(_x) }
110#define DEBUG_PRINTF_INTR(_x...) CHECK_DBG(DEBUG_INTR) { DEBUG_PRINTF_CS_IP(_x) }
111#define DEBUG_PRINTF_VBE(_x...) CHECK_DBG(DEBUG_VBE) { DEBUG_PRINTF_CS_IP(_x) }
112#define DEBUG_PRINTF_PMM(_x...) CHECK_DBG(DEBUG_PMM) { DEBUG_PRINTF_CS_IP(_x) }
113#define DEBUG_PRINTF_DISK(_x...) CHECK_DBG(DEBUG_DISK) { DEBUG_PRINTF_CS_IP(_x) }
114#define DEBUG_PRINTF_PNP(_x...) CHECK_DBG(DEBUG_PNP) { DEBUG_PRINTF_CS_IP(_x) }
115
116#else
117
118#define CHECK_DBG(_flag) if (0)
119
120#define DEBUG_PRINTF(_x...)
121#define DEBUG_PRINTF_CS_IP(_x...)
122
123#define DEBUG_PRINTF_IO(_x...)
124#define DEBUG_PRINTF_MEM(_x...)
125#define DEBUG_PRINTF_INTR(_x...)
126#define DEBUG_PRINTF_VBE(_x...)
127#define DEBUG_PRINTF_PMM(_x...)
128#define DEBUG_PRINTF_DISK(_x...)
129#define DEBUG_PRINTF_PNP(_x...)
130
Myles Watson8e9234f2010-02-19 19:08:11 +0000131#endif //DEBUG
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000132
Elyes HAOUASb0b0c8c2018-07-08 12:33:47 +0200133void dump(u8 *addr, u32 len);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000134
135#endif