Supplement base/log.h with raw output function

This patch introduces the Genode::raw function that prints output
directly via a low-level kernel mechanism, if available.

On base-linux, it replaces the former 'raw_write_str' function.
On base-hw, it replaces the former kernel/log.h interface.

Fixes #2012
This commit is contained in:
Norman Feske 2016-06-16 15:55:36 +02:00 committed by Christian Helmuth
parent ebdb1c6892
commit 2030ae678e
27 changed files with 351 additions and 217 deletions

View File

@ -0,0 +1,31 @@
/*
* \brief Kernel-specific raw-output back end
* \author Norman Feske
* \date 2016-03-08
*/
/*
* Copyright (C) 2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
#define _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
/* Fiasco includes */
namespace Fiasco {
#include <l4/sys/kdebug.h>
}
namespace Genode {
void raw_write_string(char const *str)
{
using namespace Fiasco;
outstring(const_cast<char *>(str));
}
}
#endif /* _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_ */

View File

@ -0,0 +1,31 @@
/*
* \brief Kernel-specific raw-output back end
* \author Norman Feske
* \date 2016-03-08
*/
/*
* Copyright (C) 2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
#define _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
/* Fiasco includes */
namespace Fiasco {
#include <l4/sys/kdebug.h>
}
namespace Genode {
void raw_write_string(char const *str)
{
using namespace Fiasco;
outstring(const_cast<char *>(str));
}
}
#endif /* _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_ */

View File

@ -1,117 +0,0 @@
/*
* \brief Print to the standard output of the kernel
* \author Martin stein
* \date 2012-04-05
*/
/*
* Copyright (C) 2012-2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__KERNEL__LOG_H_
#define _INCLUDE__KERNEL__LOG_H_
/* Genode includes */
#include <kernel/interface.h>
namespace Kernel
{
/**
* Prints incoming streams to the standard output of the kernel
*/
class Log
{
private:
/**
* Print an unsigned 4 bit integer x as hexadecimal value
*/
void _print_4bit_hex(unsigned char x) const
{
/* decode to ASCII char */
x &= 0x0f;
if (x > 9) x += 39;
x += 48;
/* print ASCII char */
print_char(x);
}
public:
/**
* Print a zero-terminated string s
*/
Log & operator << (char const * s)
{
while (*s) print_char(*s++);
if (*--s != '\n') { print_char(' '); }
return *this;
}
/**
* Print an unsigned integer x as hexadecimal value
*/
Log & operator << (unsigned long const x)
{
enum {
BYTE_WIDTH = 8,
CW = sizeof(unsigned char)*BYTE_WIDTH,
IW = sizeof(unsigned int)*BYTE_WIDTH
};
/*
* Walk from most significant to least significant bit and
* process 2 hex digits per step.
*/
bool leading = true;
for (int i = IW - CW; i >= 0; i = i - CW)
{
/* fetch the 2 current digits */
unsigned char c = (char)((x >> i) & 0xff);
/* has the payload part of the value already begun? */
if (leading)
{
/* ignore leading zeros ... */
if (!c)
{
/* ... expect they are the only digits */
if (i == 0) _print_4bit_hex(c);
continue;
}
/* transit from leading to payload part */
leading = false;
if (c < 0x10) {
_print_4bit_hex(c);
continue;
}
}
/* print both digits */
_print_4bit_hex(c >> 4);
_print_4bit_hex(c);
}
print_char(' ');
return *this;
}
/**
* Print a pointer p as hexadecimal value
*/
Log & operator << (void * const p) { return *this << (unsigned long)p; }
};
/**
* Return singleton kernel-log
*/
inline Log & log()
{
static Log s;
return s;
}
}
#endif /* _INCLUDE__KERNEL__LOG_H_ */

View File

@ -21,7 +21,6 @@
#include <irq_session/irq_session.h>
/* base-hw includes */
#include <kernel/log.h>
#include <kernel/configuration.h>
#include <kernel/core_interface.h>

View File

@ -27,9 +27,9 @@
#include <address_space.h>
#include <object.h>
/* kernel includes */
#include <kernel/core_interface.h>
#include <kernel/thread.h>
#include <kernel/log.h>
namespace Genode {

View File

@ -12,9 +12,6 @@
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <kernel/log.h>
/* core includes */
#include <io_mem_session_component.h>

View File

@ -15,7 +15,7 @@
/* Genode includes */
#include <base/printf.h>
#include <base/sleep.h>
#include <kernel/log.h>
#include <base/log.h>
/* core includes */
#include <core_parent.h>
@ -200,8 +200,8 @@ Platform::Platform()
void Core_parent::exit(int exit_value)
{
Kernel::log() << __PRETTY_FUNCTION__ << "not implemented\n";
while (1) ;
log(__PRETTY_FUNCTION__, "not implemented");
while (1);
}

View File

@ -0,0 +1,28 @@
/*
* \brief Kernel-specific raw-output back end
* \author Norman Feske
* \date 2016-03-08
*/
/*
* Copyright (C) 2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
#define _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
#include <kernel/interface.h>
namespace Genode {
void raw_write_string(char const *str)
{
while (char c = *str++)
Kernel::print_char(c);
}
}
#endif /* _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_ */

View File

@ -28,7 +28,6 @@
/* base-hw includes */
#include <kernel/interface.h>
#include <kernel/log.h>
namespace Hw { extern Genode::Untyped_capability _main_thread_cap; }

View File

@ -0,0 +1,28 @@
/*
* \brief Kernel-specific raw-output back end
* \author Norman Feske
* \date 2016-03-08
*/
/*
* Copyright (C) 2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
#define _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
#include <util/string.h>
#include <linux_syscalls.h>
namespace Genode {
void raw_write_string(const char *str)
{
lx_syscall(SYS_write, (int)1, str, strlen(str));
}
}
#endif /* _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_ */

View File

@ -11,34 +11,7 @@
* under the terms of the GNU General Public License version 2.
*/
/*
* With the enabled 'DEBUG' flag, status information can be printed directly
* via a Linux system call by using the 'raw_write_str' function. This output
* bypasses the Genode 'LOG' mechanism, which is useful for debugging low-level
* code such as a libC back-end.
*/
#define DEBUG 1
#if DEBUG
#include <linux_syscalls.h>
#endif /* DEBUG */
/**
* Write function targeting directly the Linux system call layer and bypassing
* any Genode code.
*/
extern "C" int raw_write_str(const char *str)
{
#if DEBUG
unsigned len = 0;
for (; str[len] != 0; len++);
lx_syscall(SYS_write, (int)1, str, len);
return len;
#endif /* DEBUG */
}
/**
* Debug function waiting until the user presses return
@ -50,8 +23,6 @@ extern "C" int raw_write_str(const char *str)
*/
extern "C" void wait_for_continue(void)
{
#if DEBUG
char buf[16];
lx_syscall(SYS_read, (int)0, buf, sizeof(buf));
#endif /* DEBUG */
}

View File

@ -14,6 +14,7 @@
/* Genode includes */
#include <base/stdint.h>
#include <base/env.h>
#include <base/log.h>
#include <linux_syscalls.h>
@ -41,7 +42,8 @@ extern "C" int stdout_write(char const *);
*/
extern "C" __attribute__((weak)) int stdout_write(char const *s)
{
return raw_write_str(s);
raw(s);
return strlen(s);
}
/**

View File

@ -13,6 +13,7 @@
/* Genode includes */
#include <base/printf.h>
#include <base/log.h>
#include <base/component.h>
#include <linux_syscalls.h>
#include <linux_native_cpu/client.h>
@ -22,8 +23,6 @@
#include <base/internal/globals.h>
extern "C" int raw_write_str(const char *str);
/**
* Define stack area
*/
@ -39,7 +38,7 @@ enum { verbose_atexit = false };
int genode___cxa_atexit(void (*func)(void*), void *arg, void *dso)
{
if (verbose_atexit)
raw_write_str("genode___cxa_atexit called, not implemented\n");
Genode::raw("genode___cxa_atexit called, not implemented\n");
return 0;
}

View File

@ -43,6 +43,7 @@
#include <util/string.h>
#include <base/printf.h>
#include <base/snprintf.h>
#include <base/log.h>
/***********************************
@ -50,14 +51,13 @@
***********************************/
extern "C" void wait_for_continue(void);
extern "C" int raw_write_str(const char *str);
#define PRAW(fmt, ...) \
do { \
char str[128]; \
Genode::snprintf(str, sizeof(str), \
ESC_ERR fmt ESC_END "\n", ##__VA_ARGS__); \
raw_write_str(str); \
Genode::raw(str); \
} while (0)

View File

@ -0,0 +1,19 @@
/*
* \brief Kernel-specific raw-output back end
* \author Norman Feske
* \date 2016-03-08
*/
/*
* Copyright (C) 2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
#define _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
namespace Genode { void raw_write_string(char const *) { } }
#endif /* _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_ */

View File

@ -0,0 +1,30 @@
/*
* \brief Kernel-specific raw-output back end
* \author Norman Feske
* \date 2016-03-08
*/
/*
* Copyright (C) 2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
#define _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
namespace Okl4 { extern "C" {
#include <l4/kdebug.h>
} }
namespace Genode {
void raw_write_string(char const *str)
{
while (char c = *str++)
Okl4::L4_KDB_PrintChar(c);
}
}
#endif /* _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_ */

View File

@ -0,0 +1,29 @@
/*
* \brief Kernel-specific raw-output back end
* \author Norman Feske
* \date 2016-03-08
*/
/*
* Copyright (C) 2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
#define _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
namespace Pistachio {
#include <l4/kdebug.h>
}
namespace Genode {
void raw_write_string(char const *str)
{
Pistachio::L4_KDB_PrintString(const_cast<char *>(str));
}
}
#endif /* _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_ */

View File

@ -0,0 +1,30 @@
/*
* \brief Kernel-specific raw-output back end
* \author Norman Feske
* \date 2016-03-08
*/
/*
* Copyright (C) 2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
#define _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_
/* seL4 includes */
#include <sel4/arch/functions.h>
#include <sel4/arch/syscalls.h>
namespace Genode {
void raw_write_string(char const *str)
{
while (char c = *str++)
seL4_DebugPutChar(c);
}
}
#endif /* _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_ */

View File

@ -17,7 +17,11 @@
#include <base/output.h>
#include <base/lock.h>
namespace Genode { class Log; }
namespace Genode {
class Log;
class Raw;
}
/**
@ -45,19 +49,6 @@ class Genode::Log
void _release();
Output &_output;
/**
* Helper for the sequential output of a variable list of arguments
*/
template <typename HEAD, typename... TAIL>
void _output_args(Output &output, HEAD && head, TAIL &&... tail)
{
print(output, head);
_output_args(output, tail...);
}
template <typename LAST>
void _output_args(Output &output, LAST && last) { print(output, last); }
public:
Log(Output &output) : _output(output) { }
@ -72,7 +63,7 @@ class Genode::Log
* using a lock guard.
*/
_acquire(type);
_output_args(_output, args...);
Output::out_args(_output, args...);
_release();
}
@ -83,6 +74,31 @@ class Genode::Log
};
/**
* Raw-output back end
*
* \noapi
*/
class Genode::Raw
{
private:
static void _acquire();
static void _release();
static Output &_output();
public:
template <typename... ARGS>
static void output(ARGS &&... args)
{
_acquire();
Output::out_args(_output(), args...);
_release();
}
};
namespace Genode {
/**
@ -104,6 +120,15 @@ namespace Genode {
*/
template <typename... ARGS>
void error(ARGS &&... args) { Log::log().output(Log::ERROR, args...); }
/**
* Write 'args' directly via the kernel (i.e., kernel debugger)
*
* This function is intended for temporarly debugging purposes only.
*/
template <typename... ARGS>
void raw(ARGS &&... args) { Raw::output(args...); }
}
#endif /* _INCLUDE__BASE__LOG_H_ */

View File

@ -39,6 +39,19 @@ struct Genode::Output
* overridden by the backend for improving efficiency.
*/
virtual void out_string(char const *str, size_t n = ~0UL);
/**
* Helper for the sequential output of a variable list of arguments
*/
template <typename HEAD, typename... TAIL>
static void out_args(Output &output, HEAD && head, TAIL &&... tail)
{
print(output, head);
out_args(output, tail...);
}
template <typename LAST>
static void out_args(Output &output, LAST && last) { print(output, last); }
};

View File

@ -18,6 +18,7 @@ SRC_CC += elf_binary.cc
SRC_CC += ipc.cc
SRC_CC += lock.cc
SRC_CC += log.cc
SRC_CC += raw_output.cc
SRC_CC += rpc_entrypoint.cc
SRC_CC += signal.cc signal_common.cc
SRC_CC += sleep.cc

View File

@ -42,3 +42,20 @@ void Log::_release()
_lock.unlock();
}
void Raw::_acquire()
{
/*
* Mark raw output with distinct color
*/
_output().out_string("\033[32mKernel: ");
}
void Raw::_release()
{
/*
* Reset color and add newline
*/
_output().out_string("\033[0m\n");
}

View File

@ -0,0 +1,35 @@
/*
* \brief Access to raw output back end
* \author Norman Feske
* \date 2016-06-16
*/
/*
* Copyright (C) 2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <base/log.h>
/* base-internal includes */
#include <base/internal/unmanaged_singleton.h>
#include <base/internal/output.h>
#include <base/internal/raw_write_string.h>
using namespace Genode;
Output &Raw::_output()
{
struct Write_fn { void operator () (char const *s) { raw_write_string(s); } };
typedef Buffered_output<256, Write_fn> Buffered_raw_output;
static Buffered_raw_output *buffered_raw_output =
unmanaged_singleton<Buffered_raw_output>(Write_fn());
return *buffered_raw_output;
}

View File

@ -36,7 +36,6 @@
wait_for_continue;
stdout_write;
stdout_reconnect;
raw_write_str;
/* Testing */
extern "C++" {

View File

@ -11,10 +11,11 @@
* under the terms of the GNU General Public License version 2.
*/
#include "libc_debug.h"
/* Genode includes */
#include <base/log.h>
extern "C" int issetugid(void)
{
raw_write_str("issetugid called, not yet implemented, returning 1\n");
Genode::raw("issetugid called, not yet implemented, returning 1");
return 1;
}

View File

@ -1,35 +0,0 @@
/*
* \brief Debugging hooks
* \author Norman Feske
* \date 2009-05-26
*/
/*
* Copyright (C) 2009-2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _LIBC_DEBUG_H_
#define _LIBC_DEBUG_H_
#define LIBC_DEBUG 0
#if (LIBC_DEBUG == 1)
/*
* This function is implemented in base-linux (env lib)
*/
extern "C" int raw_write_str(const char *s);
#else
/*
* Discard external references to 'raw_write_str'
*/
static inline int raw_write_str(const char *s) { return 0; }
#endif /* LIBC_DEBUG == 1 */
#endif /* _LIBC_DEBUG_H_ */

View File

@ -11,12 +11,14 @@
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <base/log.h>
/* libc includes */
#include <sys/time.h>
#include <sys/resource.h>
#include <stdio.h>
#include "libc_debug.h"
extern "C" int __attribute__((weak)) getrlimit(int resource, struct rlimit *rlim)
{
/*
@ -30,7 +32,7 @@ extern "C" int __attribute__((weak)) getrlimit(int resource, struct rlimit *rlim
return 0;
}
raw_write_str("getrlimit called, return 0\n");
Genode::raw("getrlimit called, return 0");
return 0;
}