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 16static char sBuffer[16384]; 17static uint32 sBufferPosition; 18 19 20static inline void 21syslog_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 30extern "C" void 31panic(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 46static inline void 47dprintf_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 59extern "C" void 60dprintf(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 72char* 73platform_debug_get_log_buffer(size_t* _size) 74{ 75 if (_size != NULL) 76 *_size = sizeof(sBuffer); 77 78 return sBuffer; 79} 80