kernel: add basic console registration system and printk()
This commit is contained in:
@@ -1,12 +1,52 @@
|
||||
#include <socks/console.h>
|
||||
#include <socks/machine/console.h>
|
||||
#include <socks/queue.h>
|
||||
#include <socks/locks.h>
|
||||
#include <socks/libc/string.h>
|
||||
|
||||
void console_init(void)
|
||||
static queue_t consoles;
|
||||
static spin_lock_t consoles_lock = SPIN_LOCK_INIT;
|
||||
|
||||
kern_status_t console_register(console_t *con)
|
||||
{
|
||||
ml_console_init();
|
||||
unsigned long flags;
|
||||
spin_lock_irqsave(&consoles_lock, &flags);
|
||||
|
||||
queue_foreach (console_t, cur, &consoles, c_list) {
|
||||
if (!strcmp(cur->c_name, con->c_name)) {
|
||||
spin_unlock_irqrestore(&consoles_lock, flags);
|
||||
return KERN_NAME_EXISTS;
|
||||
}
|
||||
}
|
||||
|
||||
queue_push_back(&consoles, &con->c_list);
|
||||
spin_unlock_irqrestore(&consoles_lock, flags);
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
void console_putchar(int c)
|
||||
kern_status_t console_unregister(console_t *con)
|
||||
{
|
||||
ml_console_putchar(c);
|
||||
unsigned long flags;
|
||||
spin_lock_irqsave(&consoles_lock, &flags);
|
||||
|
||||
queue_delete(&consoles, &con->c_list);
|
||||
|
||||
spin_unlock_irqrestore(&consoles_lock, flags);
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
void console_write(console_t *con, const char *s, unsigned int len)
|
||||
{
|
||||
if (con->c_write) {
|
||||
con->c_write(con, s, len);
|
||||
}
|
||||
}
|
||||
|
||||
int console_read(console_t *con, char *s, unsigned int len)
|
||||
{
|
||||
int ret = -1;
|
||||
if (con->c_read) {
|
||||
ret = con->c_read(con, s, len);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user