From 60a463c6739ca7240f62f0b5f697c081cfdf6f9c Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 15 Jan 2005 21:36:50 +0000 Subject: [PATCH] Added /dev/dprintf driver. It's probably quite different from R5's, but nevertheless useful for debugging. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10757 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/drivers/common/Jamfile | 4 + src/add-ons/kernel/drivers/common/dprintf.cpp | 168 ++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 src/add-ons/kernel/drivers/common/dprintf.cpp diff --git a/src/add-ons/kernel/drivers/common/Jamfile b/src/add-ons/kernel/drivers/common/Jamfile index 2e2291d9f0..27e0a3255a 100644 --- a/src/add-ons/kernel/drivers/common/Jamfile +++ b/src/add-ons/kernel/drivers/common/Jamfile @@ -1,5 +1,9 @@ SubDir OBOS_TOP src add-ons kernel drivers common ; +KernelAddon dprintf : kernel drivers dev : + dprintf.cpp + ; + KernelAddon null : kernel drivers dev : null.c ; diff --git a/src/add-ons/kernel/drivers/common/dprintf.cpp b/src/add-ons/kernel/drivers/common/dprintf.cpp new file mode 100644 index 0000000000..b8756383f4 --- /dev/null +++ b/src/add-ons/kernel/drivers/common/dprintf.cpp @@ -0,0 +1,168 @@ +/* + * Copyright 2005, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Author(s): + * Ingo Weinhold + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + + +#include + +#include + +#include +#include + + + +#define DEVICE_NAME "dprintf" + +int32 api_version = B_CUR_DRIVER_API_VERSION; + + +static status_t +dprintf_open(const char *name, uint32 flags, void **cookie) +{ + *cookie = NULL; + return B_OK; +} + + +static status_t +dprintf_close(void *cookie) +{ + return B_OK; +} + + +static status_t +dprintf_freecookie(void *cookie) +{ + return B_OK; +} + + +static status_t +dprintf_ioctl(void *cookie, uint32 op, void *buffer, size_t length) +{ + return EPERM; +} + + +static status_t +dprintf_read(void *cookie, off_t pos, void *buffer, size_t *length) +{ + *length = 0; + return B_OK; +} + + +static status_t +dprintf_write(void *cookie, off_t pos, const void *buffer, size_t *_length) +{ + const char *str = (const char*)buffer; + + int bytesLeft = *_length; + while (bytesLeft > 0) { + int chunkSize = strnlen(str, bytesLeft); + if (chunkSize == 0) { + // null bytes -- skip + str++; + bytesLeft--; + continue; + } + + if (chunkSize == bytesLeft) { + // no null-byte in the remainder of the buffer + // we need to copy to a local buffer and null-terminate + while (bytesLeft > 0) { + chunkSize = bytesLeft; + + char localBuffer[512]; + if (bytesLeft > (int)sizeof(localBuffer) - 1) + chunkSize = (int)sizeof(localBuffer) - 1; + memcpy(localBuffer, str, chunkSize); + localBuffer[chunkSize] = '\0'; + + dbg_puts(localBuffer); + + str += chunkSize; + bytesLeft -= chunkSize; + } + } else { + // null-terminated chunk -- just write it + dbg_puts(str); + + str += chunkSize + 1; + bytesLeft -= chunkSize + 1; + } + } + + return B_OK; +} + + +// #pragma mark - + + +status_t +init_hardware(void) +{ + return B_OK; +} + + +const char ** +publish_devices(void) +{ + static const char *devices[] = { + DEVICE_NAME, + NULL + }; + + return devices; +} + + +device_hooks * +find_device(const char *name) +{ + static device_hooks hooks = { + &dprintf_open, + &dprintf_close, + &dprintf_freecookie, + &dprintf_ioctl, + &dprintf_read, + &dprintf_write, + /* Leave select/deselect/readv/writev undefined. The kernel will + * use its own default implementation. The basic hooks above this + * line MUST be defined, however. */ + NULL, + NULL, + NULL, + NULL + }; + + if (!strcmp(name, DEVICE_NAME)) + return &hooks; + + return NULL; +} + + +status_t +init_driver(void) +{ + return B_OK; +} + + +void +uninit_driver(void) +{ +} +