mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-21 14:37:50 +00:00
dde_linux: remove custom *printf implementation
The DDE uses Linux-internal formatted printk for a while now, thus remove the unused code.
This commit is contained in:
parent
5ff1ef82d1
commit
66286d6f17
@ -19,7 +19,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void lx_emul_vprintf(char const *, va_list);
|
||||
void lx_emul_print_string(char const *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -18,8 +18,6 @@
|
||||
#ifndef _LX_KIT__CONSOLE_H_
|
||||
#define _LX_KIT__CONSOLE_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
namespace Lx_kit {
|
||||
class Console;
|
||||
|
||||
@ -36,98 +34,12 @@ class Lx_kit::Console
|
||||
char _buf[BUF_SIZE + 1];
|
||||
unsigned _idx = 0;
|
||||
|
||||
/**
|
||||
* Convert digit to ASCII value
|
||||
*/
|
||||
static inline char _ascii(int digit, int uppercase = 0)
|
||||
{
|
||||
if (digit > 9)
|
||||
return (char)(digit + (uppercase ? 'A' : 'a') - 10);
|
||||
|
||||
return (char)(digit + '0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Output signed value with the specified base
|
||||
*/
|
||||
template <typename T>
|
||||
void _out_signed(T value, unsigned base)
|
||||
{
|
||||
/**
|
||||
* for base 8, the number of digits is the number of value bytes times 3
|
||||
* at a max, because 0xff is 0o377 and accumulating this implies a
|
||||
* strictly decreasing factor
|
||||
*/
|
||||
char buf[sizeof(value)*3];
|
||||
|
||||
/* set flag if value is negative */
|
||||
int neg = value < 0 ? 1 : 0;
|
||||
|
||||
/* get absolute value */
|
||||
value = value < 0 ? -value : value;
|
||||
|
||||
int i = 0;
|
||||
|
||||
/* handle zero as special case */
|
||||
if (value == 0)
|
||||
buf[i++] = _ascii(0);
|
||||
|
||||
/* fill buffer starting with the least significant digits */
|
||||
else
|
||||
for (; value > 0; value /= base)
|
||||
buf[i++] = _ascii((value % base) & 0xff);
|
||||
|
||||
/* add sign to buffer for negative values */
|
||||
if (neg)
|
||||
_out_char('-');
|
||||
|
||||
/* output buffer in reverse order */
|
||||
for (; i--; )
|
||||
_out_char(buf[i]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Output unsigned value with the specified base and padding
|
||||
*/
|
||||
template <typename T>
|
||||
void _out_unsigned(T value, unsigned base, int pad)
|
||||
{
|
||||
/**
|
||||
* for base 8, the number of digits is the number of value bytes times 3
|
||||
* at a max, because 0xff is 0o377 and accumulating this implies a
|
||||
* strictly decreasing factor
|
||||
*/
|
||||
char buf[sizeof(value)*3];
|
||||
|
||||
int i = 0;
|
||||
|
||||
/* handle zero as special case */
|
||||
if (value == 0) {
|
||||
buf[i++] = _ascii(0);
|
||||
pad--;
|
||||
}
|
||||
|
||||
/* fill buffer starting with the least significant digits */
|
||||
for (; value > 0; value /= (T)base, pad--)
|
||||
buf[i++] = _ascii((value % base) & 0xff);
|
||||
|
||||
/* add padding zeros */
|
||||
for (; pad-- > 0; )
|
||||
_out_char(_ascii(0));
|
||||
|
||||
/* output buffer in reverse order */
|
||||
for (; i--; )
|
||||
_out_char(buf[i]);
|
||||
}
|
||||
|
||||
void _out_char(char c);
|
||||
void _out_string(const char *str);
|
||||
void _flush();
|
||||
|
||||
public:
|
||||
|
||||
void vprintf(const char *format, va_list list);
|
||||
void print_string(const char *str);
|
||||
};
|
||||
|
||||
|
@ -15,8 +15,5 @@
|
||||
#include <lx_kit/env.h>
|
||||
#include <lx_emul/log.h>
|
||||
|
||||
extern "C" void lx_emul_vprintf(char const *fmt, va_list va) {
|
||||
Lx_kit::env().console.vprintf(fmt, va); }
|
||||
|
||||
extern "C" void lx_emul_print_string(char const *str) {
|
||||
Lx_kit::env().console.print_string(str); }
|
||||
|
@ -23,163 +23,6 @@
|
||||
#include <lx_kit/console.h>
|
||||
|
||||
|
||||
namespace Lx_kit { class Format_command; }
|
||||
|
||||
|
||||
/**
|
||||
* Format string command representation
|
||||
*/
|
||||
class Lx_kit::Format_command
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type { INT, UINT, STRING, CHAR, PTR, PERCENT, VA_FORMAT, MAC,
|
||||
IPV4, INVALID };
|
||||
enum Length { DEFAULT, LONG, SIZE_T, LONG_LONG };
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Read decimal value from string
|
||||
*/
|
||||
int decode_decimal(const char *str, int *consumed)
|
||||
{
|
||||
int res = 0;
|
||||
while (1) {
|
||||
char c = str[*consumed];
|
||||
|
||||
if (!c || c < '0' || c > '0' + 9)
|
||||
return res;
|
||||
|
||||
res = (res * 10) + c - '0';
|
||||
(*consumed)++;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Type type = INVALID; /* format argument type */
|
||||
Length length = DEFAULT; /* format argument length */
|
||||
int padding = 0; /* min number of characters to print */
|
||||
int base = 10; /* base of numeric arguments */
|
||||
bool zeropad = false; /* pad with zero instead of space */
|
||||
bool uppercase = false; /* use upper case for hex numbers */
|
||||
bool prefix = false; /* prefix with 0x */
|
||||
int consumed = 0; /* nb of consumed format string chars */
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param format begin of command in format string
|
||||
*/
|
||||
explicit Format_command(const char *format)
|
||||
{
|
||||
/* check for command begin and eat the character */
|
||||
if (format[consumed] != '%')
|
||||
return;
|
||||
if (!format[++consumed])
|
||||
return;
|
||||
|
||||
/* check for %$x syntax */
|
||||
prefix = (format[consumed] == '#') || (format[consumed] == '.');
|
||||
if (prefix && !format[++consumed])
|
||||
return;
|
||||
|
||||
/* heading zero indicates zero-padding */
|
||||
zeropad = (format[consumed] == '0');
|
||||
|
||||
/* read decimal padding value */
|
||||
padding = decode_decimal(format, &consumed);
|
||||
if (!format[consumed])
|
||||
return;
|
||||
|
||||
/* decode length */
|
||||
switch (format[consumed]) {
|
||||
|
||||
case 'l':
|
||||
{
|
||||
/* long long ints are marked by a subsequenting 'l' character */
|
||||
bool is_long_long = (format[consumed + 1] == 'l');
|
||||
|
||||
length = is_long_long ? LONG_LONG : LONG;
|
||||
consumed += is_long_long ? 2 : 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'h':
|
||||
|
||||
length = DEFAULT;
|
||||
consumed++;
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
case 'Z':
|
||||
|
||||
length = SIZE_T;
|
||||
consumed++;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
|
||||
length = LONG;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!format[consumed])
|
||||
return;
|
||||
|
||||
/* decode type */
|
||||
switch (format[consumed]) {
|
||||
|
||||
case 'd':
|
||||
case 'i': type = INT; base = 10; break;
|
||||
case 'o': type = UINT; base = 8; break;
|
||||
case 'u': type = UINT; base = 10; break;
|
||||
case 'x': type = UINT; base = 16; break;
|
||||
case 'X': type = UINT; base = 16; uppercase = 1; break;
|
||||
case 'p': type = PTR; base = 16; break;
|
||||
case 'c': type = CHAR; break;
|
||||
case 's': type = STRING; break;
|
||||
case '%': type = PERCENT; break;
|
||||
|
||||
case 0: return;
|
||||
default: break;
|
||||
}
|
||||
|
||||
/* eat type character */
|
||||
consumed++;
|
||||
|
||||
if (type != PTR || !format[consumed])
|
||||
return;
|
||||
|
||||
switch (format[consumed]) {
|
||||
|
||||
case 'V': type = VA_FORMAT; break;
|
||||
case 'M': type = MAC; base = 16; padding = 2; break;
|
||||
|
||||
case 'I':
|
||||
|
||||
if (format[consumed + 1] != '4') break;
|
||||
consumed++;
|
||||
type = IPV4; base = 10;
|
||||
break;
|
||||
|
||||
default: return;
|
||||
}
|
||||
|
||||
consumed++;
|
||||
}
|
||||
|
||||
int numeric()
|
||||
{
|
||||
return (type == INT || type == UINT || type == PTR);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void Lx_kit::Console::_flush()
|
||||
{
|
||||
if (!_idx)
|
||||
@ -222,139 +65,3 @@ void Lx_kit::Console::print_string(const char *str)
|
||||
|
||||
_out_string(str);
|
||||
}
|
||||
|
||||
|
||||
void Lx_kit::Console::vprintf(const char *format, va_list list)
|
||||
{
|
||||
while (*format) {
|
||||
|
||||
/* eat and output plain characters */
|
||||
if (*format != '%') {
|
||||
_out_char(*format++);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* parse format argument descriptor */
|
||||
Format_command cmd(format);
|
||||
|
||||
/* read numeric argument from va_list */
|
||||
long long numeric_arg = 0;
|
||||
if (cmd.numeric()) {
|
||||
switch (cmd.length) {
|
||||
|
||||
case Format_command::LONG_LONG:
|
||||
|
||||
numeric_arg = va_arg(list, long long);
|
||||
break;
|
||||
|
||||
case Format_command::LONG:
|
||||
|
||||
numeric_arg = (cmd.type == Format_command::UINT) ?
|
||||
(long long)va_arg(list, unsigned long) : va_arg(list, long);
|
||||
break;
|
||||
|
||||
case Format_command::SIZE_T:
|
||||
|
||||
numeric_arg = va_arg(list, size_t);
|
||||
break;
|
||||
|
||||
case Format_command::DEFAULT:
|
||||
|
||||
numeric_arg = (cmd.type == Format_command::UINT) ?
|
||||
(long long)va_arg(list, unsigned int) : va_arg(list, int);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* call type-specific output routines */
|
||||
switch (cmd.type) {
|
||||
|
||||
case Format_command::INT:
|
||||
|
||||
if (cmd.length == Format_command::LONG_LONG)
|
||||
_out_signed<long long>(numeric_arg, cmd.base);
|
||||
else
|
||||
_out_signed<long>(static_cast<long>(numeric_arg), cmd.base);
|
||||
break;
|
||||
|
||||
case Format_command::UINT:
|
||||
|
||||
if (cmd.prefix && cmd.base == 16)
|
||||
_out_string("0x");
|
||||
|
||||
if (cmd.length == Format_command::LONG_LONG) {
|
||||
|
||||
_out_unsigned<unsigned long long>(numeric_arg, cmd.base, cmd.padding);
|
||||
break;
|
||||
}
|
||||
|
||||
/* fall through */
|
||||
|
||||
case Format_command::PTR:
|
||||
|
||||
_out_unsigned<unsigned long>(static_cast<unsigned long>(numeric_arg), cmd.base, cmd.padding);
|
||||
break;
|
||||
|
||||
case Format_command::CHAR:
|
||||
|
||||
_out_char((char)(va_arg(list, int)));
|
||||
break;
|
||||
|
||||
case Format_command::STRING:
|
||||
|
||||
_out_string(va_arg(list, const char *));
|
||||
break;
|
||||
|
||||
case Format_command::PERCENT:
|
||||
|
||||
_out_char('%');
|
||||
break;
|
||||
|
||||
case Format_command::VA_FORMAT: /* %pV */
|
||||
{
|
||||
struct va_format
|
||||
{
|
||||
const char *fmt;
|
||||
va_list *va;
|
||||
};
|
||||
|
||||
va_list va;
|
||||
va_format *vf = va_arg(list, va_format *);
|
||||
va_copy(va, *vf->va);
|
||||
vprintf(vf->fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
break;
|
||||
|
||||
case Format_command::MAC: /* %pM */
|
||||
{
|
||||
unsigned char const *mac = va_arg(list, unsigned char const *);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (i) _out_char(':');
|
||||
_out_unsigned<unsigned char>(mac[i], cmd.base, cmd.padding);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Format_command::IPV4: /* %pI4 */
|
||||
{
|
||||
unsigned char const *ip = va_arg(list, unsigned char const *);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (i) _out_char('.');
|
||||
_out_unsigned<unsigned char>(ip[i], cmd.base, cmd.padding);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Format_command::INVALID:
|
||||
|
||||
_out_string("<warning: unsupported format string argument>");
|
||||
/* consume the argument of the unsupported command */
|
||||
va_arg(list, long);
|
||||
break;
|
||||
}
|
||||
|
||||
/* proceed with format string after command */
|
||||
format += cmd.consumed;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user