iPXE
dmesg.c File Reference

In-memory ring buffer console. More...

#include <errno.h>
#include <ipxe/ansiesc.h>
#include <ipxe/settings.h>
#include <ipxe/console.h>

Go to the source code of this file.

Macros

#define CONSOLE_DMESG   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_TUI )
#define DMESG_LEN   8192
 Size of ring buffer.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static void dmesg_putchar (int character)
 Print a character to the ring buffer.
static int dmesg_fetch (void *data, size_t len)
 Fetch ring buffer setting.
static int dmesg_store (const void *data __unused, size_t len)
 Store ring buffer setting.
const struct setting dmesg_setting __setting (SETTING_MISC, dmesg)
 Ring buffer setting.

Variables

static char dmesg [DMESG_LEN]
 Ring buffer.
static unsigned int dmesg_offset
 Offset within ring buffer.
static struct ansiesc_handler dmesg_ansiesc_handlers []
 Ring buffer ANSI escape sequence handlers.
static struct ansiesc_context dmesg_ansiesc_ctx
 Ring buffer ANSI escape sequence context.
struct console_driver dmesg_console __console_driver
 Ring buffer console driver.
struct builtin_setting dmesg_builtin_setting __builtin_setting
 Ring buffer built-in setting.

Detailed Description

In-memory ring buffer console.

Definition in file dmesg.c.

Macro Definition Documentation

◆ CONSOLE_DMESG

#define CONSOLE_DMESG   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_TUI )

Definition at line 41 of file dmesg.c.

◆ DMESG_LEN

#define DMESG_LEN   8192

Size of ring buffer.

Definition at line 45 of file dmesg.c.

Referenced by dmesg_fetch(), and dmesg_putchar().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ dmesg_putchar()

void dmesg_putchar ( int character)
static

Print a character to the ring buffer.

Parameters
characterCharacter to be printed

Definition at line 68 of file dmesg.c.

68 {
69
70 /* Strip ANSI escape sequences */
71 character = ansiesc_process ( &dmesg_ansiesc_ctx, character );
72 if ( character < 0 )
73 return;
74
75 /* Handle backspace characters */
76 if ( character == '\b' ) {
77 if ( dmesg_offset )
79 return;
80 }
81
82 /* Record character */
83 dmesg[ dmesg_offset++ % DMESG_LEN ] = character;
84}
int ansiesc_process(struct ansiesc_context *ctx, int c)
Process character that may be part of ANSI escape sequence.
Definition ansiesc.c:75
#define DMESG_LEN
Size of ring buffer.
Definition dmesg.c:45
static unsigned int dmesg_offset
Offset within ring buffer.
Definition dmesg.c:51
static struct ansiesc_context dmesg_ansiesc_ctx
Ring buffer ANSI escape sequence context.
Definition dmesg.c:59
static char dmesg[DMESG_LEN]
Ring buffer.
Definition dmesg.c:48

References ansiesc_process(), dmesg, dmesg_ansiesc_ctx, DMESG_LEN, and dmesg_offset.

◆ dmesg_fetch()

int dmesg_fetch ( void * data,
size_t len )
static

Fetch ring buffer setting.

Parameters
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 99 of file dmesg.c.

99 {
100 uint8_t *bytes = data;
101 size_t max;
102 unsigned int offset;
103
104 /* Calculate length */
106 if ( max > DMESG_LEN )
107 max = DMESG_LEN;
108 if ( len > max )
109 len = max;
110
111 /* Copy data */
112 offset = ( dmesg_offset - len );
113 while ( len-- )
114 *(bytes++) = dmesg[ offset++ % DMESG_LEN ];
115
116 return max;
117}
unsigned char uint8_t
Definition stdint.h:10
#define max(x, y)
Definition ath.h:41
uint16_t offset
Offset to command line.
Definition bzimage.h:3
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint8_t bytes[64]
Definition ib_mad.h:5

References bytes, data, dmesg, DMESG_LEN, dmesg_offset, len, max, and offset.

◆ dmesg_store()

int dmesg_store ( const void *data __unused,
size_t len )
static

Store ring buffer setting.

Parameters
dataSetting data, or NULL to clear setting
lenLength of setting data
Return values
rcReturn status code

Definition at line 126 of file dmesg.c.

126 {
127
128 /* Only clearing the log is supported */
129 if ( len )
130 return -ENOTSUP;
131
132 /* Clear log */
133 dmesg_offset = 0;
134
135 return 0;
136}
#define ENOTSUP
Operation not supported.
Definition errno.h:590

References __unused, data, dmesg_offset, ENOTSUP, and len.

◆ __setting()

const struct setting dmesg_setting __setting ( SETTING_MISC ,
dmesg  )

Ring buffer setting.

References __setting, builtin_scope, dmesg, and SETTING_MISC.

Variable Documentation

◆ dmesg

char dmesg[DMESG_LEN]
static

Ring buffer.

Definition at line 48 of file dmesg.c.

Referenced by __setting(), dmesg_fetch(), dmesg_putchar(), and PROVIDE_REQUIRING_SYMBOL().

◆ dmesg_offset

unsigned int dmesg_offset
static

Offset within ring buffer.

Definition at line 51 of file dmesg.c.

Referenced by dmesg_fetch(), dmesg_putchar(), and dmesg_store().

◆ dmesg_ansiesc_handlers

struct ansiesc_handler dmesg_ansiesc_handlers[]
static
Initial value:
= {
{ 0, NULL }
}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321

Ring buffer ANSI escape sequence handlers.

Definition at line 54 of file dmesg.c.

54 {
55 { 0, NULL }
56};

◆ dmesg_ansiesc_ctx

struct ansiesc_context dmesg_ansiesc_ctx
static
Initial value:
= {
}
static struct ansiesc_handler dmesg_ansiesc_handlers[]
Ring buffer ANSI escape sequence handlers.
Definition dmesg.c:54

Ring buffer ANSI escape sequence context.

Definition at line 59 of file dmesg.c.

59 {
60 .handlers = dmesg_ansiesc_handlers,
61};

Referenced by dmesg_putchar().

◆ __console_driver

struct console_driver dmesg_console __console_driver
Initial value:
= {
.putchar = dmesg_putchar,
.usage = CONSOLE_DMESG,
}
static void dmesg_putchar(int character)
Print a character to the ring buffer.
Definition dmesg.c:68
#define CONSOLE_DMESG
Definition dmesg.c:41

Ring buffer console driver.

Definition at line 87 of file dmesg.c.

87 {
88 .putchar = dmesg_putchar,
89 .usage = CONSOLE_DMESG,
90};

◆ __builtin_setting

struct builtin_setting dmesg_builtin_setting __builtin_setting
Initial value:
= {
.setting = &dmesg_setting,
.fetch = dmesg_fetch,
.store = dmesg_store,
}
static int dmesg_fetch(void *data, size_t len)
Fetch ring buffer setting.
Definition dmesg.c:99
static int dmesg_store(const void *data __unused, size_t len)
Store ring buffer setting.
Definition dmesg.c:126

Ring buffer built-in setting.

Definition at line 147 of file dmesg.c.

147 {
148 .setting = &dmesg_setting,
149 .fetch = dmesg_fetch,
150 .store = dmesg_store,
151};