BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / blob / master / kernel / printf.c

// Related

Nucleus

Barry System headers (remove libc dependency) 18495cf (3 years, 2 months ago)
/*
 * This file implements the kernel printf routine and the debug print system
 * call.  These routines output to the debug port and do not print to the
 * screen.
 */

#include <nucleus/io.h>
#include <nucleus/kernel.h>
#include <nucleus/lib.h>
#include <nucleus/memory.h>
#include <nucleus/task.h>

/* Print formatted text to debug port */
void
kprintf(char *fmt, ...)
{
	outb(0xE9, '\033');
	outb(0xE9, '[');
	outb(0xE9, '3');
	outb(0xE9, '6');
	outb(0xE9, 'm');

	char buf[1024], *p = buf;
	memset(buf, 0, 1024);

	sprintf(buf, "[CPU#%d] ", cpu->id);
	while (*p)
		outb(0xE9, *p++);
	memset(buf, 0, 1024);
	p = buf;

	/* Print message to debug port */
	va_list args;
	va_start(args, fmt);
	vsprintf(buf, fmt, args);
	va_end(args);
	while (*p)
		outb(0xE9, *p++);
	outb(0xE9, '\n');
}

/* Debug print */
void
dbgprintf(char *str)
{
	size_t len = 1024;
	if (!str || !verify_access(str, strnlen(str, len), PROT_READ))
		return;
	char buf[1024], *p = buf;

	/* Print message to debug port */
	sprintf(buf, "\033[93;01m(%d:%d): \033[0m%s",
	        current->tgid, current->tid, str);
	while (*p)
		outb(0xE9, *p++);
	outb(0xE9, '\n');
}