xref: /haiku/src/system/boot/platform/efi/debug.cpp (revision 072d3935c2497638e9c2502f574c133caeba9d3d)
1 /*
2  * Copyright 2016 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <string.h>
8 
9 #include <boot/platform.h>
10 #include <boot/stage2.h>
11 #include <boot/stdio.h>
12 
13 #include "efi_platform.h"
14 #include "serial.h"
15 
16 
17 static char sBuffer[16384];
18 static uint32 sBufferPosition;
19 
20 
21 static void
22 syslog_write(const char* buffer, size_t length)
23 {
24 	if (sBufferPosition + length > sizeof(sBuffer))
25 		return;
26 	memcpy(sBuffer + sBufferPosition, buffer, length);
27 	sBufferPosition += length;
28 }
29 
30 
31 static void
32 dprintf_args(const char *format, va_list args)
33 {
34 	char buffer[512];
35 	int length = vsnprintf(buffer, sizeof(buffer), format, args);
36 	if (length == 0)
37 		return;
38 
39 	syslog_write(buffer, length);
40 	serial_puts(buffer, length);
41 }
42 
43 
44 extern "C" void
45 dprintf(const char *format, ...)
46 {
47 	va_list args;
48 
49 	va_start(args, format);
50 	dprintf_args(format, args);
51 	va_end(args);
52 }
53 
54 
55 extern "C" void
56 panic(const char *format, ...)
57 {
58 	va_list args;
59 
60 	platform_switch_to_text_mode();
61 
62 	puts("*** PANIC ***");
63 
64 	va_start(args, format);
65 	vprintf(format, args);
66 	va_end(args);
67 
68 	while (true)
69 		kBootServices->Stall(1000000);
70 }
71 
72 
73 char*
74 platform_debug_get_log_buffer(size_t *_size)
75 {
76 	if (_size != NULL)
77 		*_size = sizeof(sBuffer);
78 
79 	return sBuffer;
80 }
81