2 * Copyright (c) 2009 Joshua Phillips. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * The TRACE macro provides simple debugging output, either to the
30 * serial port or vgatext.
40 // Use a hack in Bochs - repeatedly output to port 0xE9
41 // On real hardware, 0xE9 is unused, so it does nothing
43 static void bochs_e9_hack(const char *str
)
51 void trace_internal(const char *file
, int line
, const char *func
, const char *fmt
, ...)
53 char str
[256], *short_str
, *actual_msg
, c
;
57 // file:line: (function): message
58 // ^str ^short_str ^actual_msg
62 len
= snprintf(str
, 256, "%s:%d: ", file
, line
);
63 short_str
= str
+ len
;
64 len
+= snprintf(str
+ len
, 256 - len
, "(%s): ", func
);
65 actual_msg
= str
+ len
;
66 len
+= vsnprintf(str
+ len
, 256 - len
, fmt
, ap
);
67 strncat(str
+ len
, "\n", 256 - len
);
69 if (serial_is_initialized(&com1
)){
70 serial_send(&com1
, str
);
74 // print "(function): message" to console
78 console_colour_fg(&tty1
, COLOUR_BRIGHT_WHITE
);
79 console_puts(&tty1
, short_str
);
80 console_colour_default(&tty1
);
82 console_puts(&tty1
, actual_msg
);