xref: /haiku/src/system/boot/platform/openfirmware/debug.cpp (revision 899e0ef82b5624ace2ccfa5f5a58c8ebee54aaef)
1 /*
2  * Copyright 2003-2010, Axel Dörfler, axeld@pinc-software.de.
3  * Copyright 2016 Haiku, Inc. All rights reserved.
4  * Distributed under the terms of the MIT License.
5  */
6 
7 
8 #include <stdarg.h>
9 #include <string.h>
10 
11 #include <boot/platform.h>
12 #include <boot/stdio.h>
13 #include <platform/openfirmware/openfirmware.h>
14 
15 
16 static char sBuffer[16384];
17 static uint32 sBufferPosition;
18 
19 
20 static inline void
21 syslog_write(const char* buffer, size_t length)
22 {
23 	if (sBufferPosition + length > sizeof(sBuffer))
24 		return;
25 	memcpy(sBuffer + sBufferPosition, buffer, length);
26 	sBufferPosition += length;
27 }
28 
29 
30 extern "C" void
31 panic(const char* format, ...)
32 {
33 	// TODO: this works only after console_init() was called.
34 	va_list list;
35 
36 	puts("*** PANIC ***");
37 
38 	va_start(list, format);
39 	vprintf(format, list);
40 	va_end(list);
41 
42 	of_exit();
43 }
44 
45 
46 static inline void
47 dprintf_args(const char *format, va_list args)
48 {
49 	char buffer[512];
50 	int length = vsnprintf(buffer, sizeof(buffer), format, args);
51 	if (length == 0)
52 		return;
53 
54 	syslog_write(buffer, length);
55 	printf("%s", buffer);
56 }
57 
58 
59 extern "C" void
60 dprintf(const char *format, ...)
61 {
62 	va_list args;
63 
64 	va_start(args, format);
65 	dprintf_args(format, args);
66 	va_end(args);
67 }
68 
69 
70 
71 
72 char*
73 platform_debug_get_log_buffer(size_t* _size)
74 {
75 	if (_size != NULL)
76 		*_size = sizeof(sBuffer);
77 
78 	return sBuffer;
79 }
80