Removed excessive traces in loadelf.c
[marionette.git] / kernel / trace.c
blob639c2430e8f3984199c79ffe608f25b78632eb0f
1 /*
2 * Copyright (c) 2009 Joshua Phillips. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
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
13 * distribution.
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.
33 #include "trace.h"
34 #include "serial.h"
35 #include "console.h"
36 #include "stdio.h"
37 #include "string.h"
38 #include "portio.h"
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)
45 while (*str){
46 outb(0xE9, *str);
47 ++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;
54 int len;
55 va_list ap;
57 // file:line: (function): message
58 // ^str ^short_str ^actual_msg
60 va_start(ap, fmt);
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);
68 str[255] = '\0';
69 if (serial_is_initialized(&com1)){
70 serial_send(&com1, str);
72 bochs_e9_hack(str);
74 // print "(function): message" to console
75 // with colours
76 c = *actual_msg;
77 *actual_msg = '\0';
78 console_colour_fg(&tty1, COLOUR_BRIGHT_WHITE);
79 console_puts(&tty1, short_str);
80 console_colour_default(&tty1);
81 *actual_msg = c;
82 console_puts(&tty1, actual_msg);
84 va_end(ap);