AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
printk.c File Reference

printk(): the kernel's messages. More...

#include <core/system.h>
#include <ds/queue.h>
#include <sys/waitq.h>
#include <core/string.h>
#include <console/earlycon.h>
#include <ds/ringbuf.h>

Go to the source code of this file.

Macros

#define KMSG_SIZE   8192

Functions

void earlycon_disable ()
 Stops sending the kernel's messages to the early console, once a real console has taken over.
void printk_console (void(*write)(const char *s, size_t len))
 Registers the console that the kernel's messages are written to, besides the message buffer.
static int putc (char c)
 Writes one character of a message.
static int puts (char *s)
 Writes a string of a message ("(null)" for NULL).
static int putx (uint32_t val)
 Writes a 32-bit number in hexadecimal, without leading zeros.
static int putlx (uint64_t val)
 Writes a 64-bit number in hexadecimal, all 16 digits.
static int putud (uint32_t val)
 Writes an unsigned 32-bit number in decimal.
static int putul (uint64_t val)
 Writes an unsigned 64-bit number in decimal.
static int putb (uint8_t val)
 Writes a byte in binary, all 8 digits.
int vprintk (const char *fmt, va_list args)
 Writes a kernel message, with its arguments in a va_list.
int printk (const char *fmt,...)
 Writes a kernel message, to the message buffer and the consoles.

Variables

struct ringbuf * kmsg = RINGBUF_NEW(KMSG_SIZE)
struct waitq * kmsg_wait = &(struct waitq){0}
static int use_earlycon = 1
static void(*) console_write (const char *s, size_t len)

Detailed Description

printk(): the kernel's messages.

A message goes to three places: the kernel's message buffer (kmsg, which /dev/kmsg reads, the oldest messages overwritten when it's full), the console if one has registered (printk_console()), and the early console until it's disabled. printk() understands a small set of formats: c, s, d and u (32-bit), ld and lu (64-bit), x and lx (hexadecimal), b (binary) and p. The l formats take a 64-bit argument on every architecture: cast a long to int64_t or uint64_t.

Definition in file printk.c.

Macro Definition Documentation

◆ KMSG_SIZE

#define KMSG_SIZE   8192

Definition at line 24 of file printk.c.

Function Documentation

◆ earlycon_disable()

void earlycon_disable ( void )

Stops sending the kernel's messages to the early console, once a real console has taken over.

Definition at line 34 of file printk.c.

References earlycon_disable(), and use_earlycon.

Referenced by earlycon_disable(), kmain(), and vt_probe().

◆ printk()

int printk ( const char * fmt,
... )

Writes a kernel message, to the message buffer and the consoles.

Parameters
fmtthe format (see the top of this file for what it supports)
Returns
what the early console's writes returned, added up

Definition at line 249 of file printk.c.

References printk(), va_end, va_list, va_start, and vprintk().

Referenced by aarch64_bad(), aarch64_init(), abort(), acpi_tables(), apic_route(), arch_stack_trace(), ata_detect_drive(), ata_poll(), ata_probe(), buddy_set_unusable(), buddy_setup(), cpio_load(), dma_transfer(), dump(), e1000_probe(), enqueue(), ext2_load(), fbdev_vesa_prope(), fdt_boot(), i8042_init(), initramfs_archiver_register(), isr_dispatch(), kargs_parse(), kdev_blkdev_register(), kdev_chrdev_register(), kdev_init(), kernel_ctrlaltdel(), kernel_reboot(), kfree(), kmain(), kmsgdev_write(), kvmem_guardtest(), kvmem_selftest(), load_ramdisk(), mm_page_fault(), mm_setup(), modules_init(), netif_config(), netif_register(), pci_assign(), pci_host_set(), pio_read_sectors(), platform_init(), pmap_init(), printk(), proc_kill(), scan_device(), sync_dispatch(), syscall_dispatch(), time_resync(), timer_setup(), uart_8250_attach(), uart_register(), vfs_mount_root_dev(), vm_object_page(), vnode_pages_update(), vt_probe(), x86_acpi_poweroff(), x86_apic_setup(), x86_clock_init(), x86_clock_ticks(), x86_cmos_setup(), x86_cpu_init(), x86_dump_registers(), x86_hpet_init(), x86_lapic_timer_setup(), x86_pc_irq_init(), x86_pic_setup(), x86_pit_delay(), x86_pit_period_set(), x86_pit_setup(), and x86_smp_init().

◆ printk_console()

void printk_console ( void(* write )(const char *s, size_t len))

Registers the console that the kernel's messages are written to, besides the message buffer.

Parameters
writethe console's write function

Definition at line 47 of file printk.c.

References console_write, and printk_console().

Referenced by printk_console(), and vt_probe().

◆ putb()

int putb ( uint8_t val)
static

Writes a byte in binary, all 8 digits.

Definition at line 145 of file printk.c.

References putb(), and puts().

Referenced by putb(), and vprintk().

◆ putc()

int putc ( char c)
static

Writes one character of a message.

Returns what the early console's write returned, or 0.

Definition at line 54 of file printk.c.

References console_write, earlycon_putc(), kmsg, putc(), and use_earlycon.

Referenced by putc(), and vprintk().

◆ putlx()

int putlx ( uint64_t val)
static

Writes a 64-bit number in hexadecimal, all 16 digits.

Definition at line 103 of file printk.c.

References putlx(), and puts().

Referenced by putlx(), and vprintk().

◆ puts()

int puts ( char * s)
static

Writes a string of a message ("(null)" for NULL).

Definition at line 67 of file printk.c.

References console_write, earlycon_puts(), kmsg, puts(), and use_earlycon.

Referenced by putb(), putlx(), puts(), putud(), putul(), putx(), and vprintk().

◆ putud()

int putud ( uint32_t val)
static

Writes an unsigned 32-bit number in decimal.

Definition at line 117 of file printk.c.

References puts(), and putud().

Referenced by putud(), and vprintk().

◆ putul()

int putul ( uint64_t val)
static

Writes an unsigned 64-bit number in decimal.

Definition at line 131 of file printk.c.

References puts(), and putul().

Referenced by putul(), and vprintk().

◆ putx()

int putx ( uint32_t val)
static

Writes a 32-bit number in hexadecimal, without leading zeros.

Definition at line 84 of file printk.c.

References puts(), and putx().

Referenced by putx(), and vprintk().

◆ vprintk()

int vprintk ( const char * fmt,
va_list args )

Writes a kernel message, with its arguments in a va_list.

Parameters
fmtthe format (see the top of this file for what it supports)
argsthe arguments
Returns
what the early console's writes returned, added up

Definition at line 164 of file printk.c.

References putb(), putc(), putlx(), puts(), putud(), putul(), putx(), va_arg, va_list, and vprintk().

Referenced by printk(), and vprintk().

Variable Documentation

◆ console_write

void(*) console_write(const char *s, size_t len) ( const char * s,
size_t len )
static

Definition at line 39 of file printk.c.

Referenced by printk_console(), putc(), and puts().

◆ kmsg

struct ringbuf* kmsg = RINGBUF_NEW(KMSG_SIZE)

Definition at line 25 of file printk.c.

Referenced by kmsgdev_read(), putc(), puts(), and vt_kmsg_replay().

◆ kmsg_wait

struct waitq* kmsg_wait = &(struct waitq){0}

Definition at line 26 of file printk.c.

Referenced by kmsg_file_open().

◆ use_earlycon

int use_earlycon = 1
static

Definition at line 28 of file printk.c.

Referenced by earlycon_disable(), putc(), and puts().