kernel: add basic console registration system and printk()
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
#ifndef SOCKS_X86_64_CONSOLE_H_
|
||||
#define SOCKS_X86_64_CONSOLE_H_
|
||||
|
||||
extern void ml_console_init(void);
|
||||
extern void ml_console_putchar(int c);
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <socks/machine/_gdt.h>
|
||||
|
||||
#define ml_halt_cpu() asm volatile("cli;hlt")
|
||||
|
||||
typedef struct ml_cpu_block {
|
||||
struct gdt c_gdt;
|
||||
struct gdt_ptr c_gdt_ptr;
|
||||
|
||||
6
arch/x86_64/include/socks/machine/vgacon.h
Normal file
6
arch/x86_64/include/socks/machine/vgacon.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef SOCKS_X86_64_CONSOLE_H_
|
||||
#define SOCKS_X86_64_CONSOLE_H_
|
||||
|
||||
extern void vgacon_init(void);
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <socks/machine/cpu.h>
|
||||
#include <socks/machine/vgacon.h>
|
||||
|
||||
static ml_cpu_block g_bootstrap_cpu = {0};
|
||||
|
||||
@@ -11,5 +12,6 @@ static void bootstrap_cpu_init(void)
|
||||
int ml_init(uintptr_t arg)
|
||||
{
|
||||
bootstrap_cpu_init();
|
||||
vgacon_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include <socks/libc/string.h>
|
||||
#include <socks/libc/ctype.h>
|
||||
#include <socks/machine/ports.h>
|
||||
#include <socks/console.h>
|
||||
#include <socks/printk.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define VGA_PORT_CMD 0x3D4
|
||||
@@ -36,15 +38,6 @@ static void move_vga_cursor(unsigned int x, unsigned int y)
|
||||
outportb(VGA_PORT_DATA, (uint8_t)((offset >> 8) & 0xFF));
|
||||
}
|
||||
|
||||
void ml_console_init(void)
|
||||
{
|
||||
g_console_cursor_xpos = 0;
|
||||
g_console_cursor_ypos = 5;
|
||||
|
||||
init_vga_cursor();
|
||||
move_vga_cursor(g_console_cursor_xpos, g_console_cursor_ypos);
|
||||
}
|
||||
|
||||
static void scroll_display()
|
||||
{
|
||||
uint16_t *src = g_console_fb + k_console_width;
|
||||
@@ -79,7 +72,7 @@ static void handle_ctrl(int c)
|
||||
move_vga_cursor(g_console_cursor_xpos, g_console_cursor_ypos);
|
||||
}
|
||||
|
||||
void ml_console_putchar(int c)
|
||||
static void vgacon_putchar(int c)
|
||||
{
|
||||
if (iscntrl(c)) {
|
||||
handle_ctrl(c);
|
||||
@@ -103,3 +96,29 @@ void ml_console_putchar(int c)
|
||||
|
||||
move_vga_cursor(g_console_cursor_xpos, g_console_cursor_ypos);
|
||||
}
|
||||
|
||||
static void vgacon_write(console_t *con, const char *s, unsigned int len)
|
||||
{
|
||||
for (unsigned int i = 0; i < len; i++) {
|
||||
vgacon_putchar(s[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static console_t vgacon = {
|
||||
.c_name = "vgacon",
|
||||
.c_flags = CON_BOOT,
|
||||
.c_write = vgacon_write,
|
||||
.c_lock = SPIN_LOCK_INIT,
|
||||
};
|
||||
|
||||
void vgacon_init(void)
|
||||
{
|
||||
g_console_cursor_xpos = 0;
|
||||
g_console_cursor_ypos = 5;
|
||||
|
||||
init_vga_cursor();
|
||||
move_vga_cursor(g_console_cursor_xpos, g_console_cursor_ypos);
|
||||
|
||||
console_register(&vgacon);
|
||||
early_printk_init(&vgacon);
|
||||
}
|
||||
Reference in New Issue
Block a user