瀏覽代碼

remove keyboard drive, make serial module

greatbridf 10 月之前
父節點
當前提交
4572e5ce46

+ 4 - 8
CMakeLists.txt

@@ -31,7 +31,6 @@ add_subdirectory(user-space-program)
 set(BOOTLOADER_SOURCES src/boot.s
                        src/mbr.S
                        src/asm/interrupt.s
-                       src/asm/port_io.s
                        )
 
 set(KERNEL_MAIN_SOURCES src/fs/fat.cpp
@@ -53,10 +52,9 @@ set(KERNEL_MAIN_SOURCES src/fs/fat.cpp
                         src/kernel/vfs.cpp
                         src/kernel/vga.cpp
                         src/kernel/hw/ahci.cc
-                        src/kernel/hw/keyboard.cpp
                         src/kernel/hw/pci.cc
-                        src/kernel/hw/serial.cpp
-                        src/kernel/hw/timer.c
+                        src/kernel/hw/serial.cc
+                        src/kernel/hw/timer.cc
                         src/kernel/task/thread.cc
                         src/kernel/task/readyqueue.cc
                         src/kernel/user/thread_local.cc
@@ -64,7 +62,6 @@ set(KERNEL_MAIN_SOURCES src/fs/fat.cpp
                         src/kernel/signal.cpp
                         src/types/elf.cpp
                         src/types/libstdcpp.cpp
-                        include/asm/port_io.h
                         include/fs/fat.hpp
                         include/kernel/async/waitlist.hpp
                         include/kernel/async/lock.hpp
@@ -89,11 +86,10 @@ set(KERNEL_MAIN_SOURCES src/fs/fat.cpp
                         include/kernel/task/forward.hpp
                         include/kernel/task/thread.hpp
                         include/kernel/task/readyqueue.hpp
-                        include/kernel/hw/keyboard.h
                         include/kernel/hw/pci.hpp
                         include/kernel/hw/port.hpp
-                        include/kernel/hw/serial.h
-                        include/kernel/hw/timer.h
+                        include/kernel/hw/serial.hpp
+                        include/kernel/hw/timer.hpp
                         include/kernel/input/keycodes.h
                         include/kernel/user/thread_local.hpp
                         include/types/bitmap.hpp

+ 0 - 43
include/asm/port_io.h

@@ -1,43 +0,0 @@
-#pragma once
-
-#include <types/types.h>
-
-typedef uint16_t port_id_t;
-
-#define PORT_PIC1 (0x20)
-#define PORT_PIC2 (0xa0)
-#define PORT_PIC1_COMMAND (PORT_PIC1)
-#define PORT_PIC1_DATA ((PORT_PIC1) + 1)
-#define PORT_PIC2_COMMAND (PORT_PIC2)
-#define PORT_PIC2_DATA ((PORT_PIC2) + 1)
-
-#define PORT_KEYBOARD_COMMAND (0x64)
-#define PORT_KEYBOARD_DATA (0x60)
-
-#define PORT_PIT_CONTROL (0x43)
-#define PORT_PIT_COUNT (0x40)
-
-#define PORT_KEYDATA 0x0060u
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void asm_outb(port_id_t port_number, uint8_t data);
-extern uint8_t asm_inb(port_id_t port_number);
-
-extern void asm_hlt(void);
-extern void asm_cli(void);
-extern void asm_sti(void);
-
-inline void NORETURN die()
-{
-    for (;;) {
-        asm_cli();
-        asm_hlt();
-    }
-}
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 15
include/kernel/hw/keyboard.h

@@ -1,15 +0,0 @@
-#pragma once
-
-#include <types/types.h>
-
-// TODO: this whole thing needs rewriting
-
-int32_t keyboard_has_data(void);
-
-void process_keyboard_data(void);
-
-#ifdef __cplusplus
-extern "C" void handle_keyboard_interrupt(void);
-#else
-void handle_keyboard_interrupt(void);
-#endif

+ 0 - 1
include/kernel/hw/serial.h → include/kernel/hw/serial.hpp

@@ -1,5 +1,4 @@
 #pragma once
-#include <asm/port_io.h>
 
 #ifdef __cplusplus
 extern "C" {

+ 0 - 17
include/kernel/hw/timer.h

@@ -1,17 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void init_pit(void);
-
-void inc_tick(void);
-
-size_t current_ticks(void);
-
-#ifdef __cplusplus
-}
-#endif

+ 11 - 0
include/kernel/hw/timer.hpp

@@ -0,0 +1,11 @@
+#pragma once
+
+#include <cstddef>
+
+namespace kernel::hw::timer {
+void init_pit(void);
+void inc_tick(void);
+
+std::size_t current_ticks(void);
+
+}

+ 0 - 2
include/kernel/interrupt.h

@@ -9,8 +9,6 @@ extern "C" {
 #define KERNEL_INTERRUPT_GATE_TYPE (0x8e)
 #define USER_INTERRUPT_GATE_TYPE (0xee)
 
-#define PIC_EOI (0x20)
-
 struct regs_64 {
     uint64_t rax;
     uint64_t rbx;

+ 1 - 1
include/kernel/log.hpp

@@ -11,4 +11,4 @@
         console->print(buf); \
     }
 
-#define kmsg(msg) console->print(msg)
+#define kmsg(msg) if (console) console->print(msg)

+ 4 - 3
include/kernel/mem/paging.hpp

@@ -46,12 +46,13 @@ constexpr psattr_t PA_NXE  = 0x8000000000000000ULL;
 constexpr psattr_t PA_MASK = 0xfff0000000000fffULL;
 
 constexpr psattr_t PA_DATA = PA_P | PA_RW | PA_NXE;
+constexpr psattr_t PA_KERNEL_DATA = PA_DATA | PA_G;
 
 constexpr psattr_t PA_PAGE_TABLE = PA_DATA;
-constexpr psattr_t PA_KERNEL_PAGE_TABLE = PA_DATA;
+constexpr psattr_t PA_KERNEL_PAGE_TABLE = PA_PAGE_TABLE | PA_G;
 
-constexpr psattr_t PA_KERNEL_DATA = PA_DATA | PA_G;
-constexpr psattr_t PA_KERNEL_DATA_HUGE = PA_KERNEL_DATA | PA_PS;
+constexpr psattr_t PA_DATA_HUGE = PA_DATA | PA_PS;
+constexpr psattr_t PA_KERNEL_DATA_HUGE = PA_DATA_HUGE | PA_G;
 
 namespace __inner {
     using pse_t = uint64_t;

+ 0 - 9
include/kernel/tty.hpp

@@ -69,13 +69,4 @@ public:
     virtual void putchar(char c) override;
 };
 
-class serial_tty : public virtual tty {
-public:
-    serial_tty(int id);
-    virtual void putchar(char c) override;
-
-public:
-    uint16_t id;
-};
-
 inline tty* console;

+ 0 - 40
src/asm/port_io.s

@@ -1,40 +0,0 @@
-.text
-
-.globl asm_outb
-.type  asm_outb @function
-asm_outb:
-    push %rax
-    push %rdx
-    mov 12(%esp), %dx
-    mov 16(%esp), %al
-    outb %al, %dx
-    pop %rdx
-    pop %rax
-    ret
-
-.globl asm_inb
-.type  asm_inb @function
-asm_inb:
-    push %rdx
-    mov 8(%esp), %dx
-    inb %dx, %al
-    pop %rdx
-    ret
-
-.globl asm_hlt
-.type  asm_hlt @function
-asm_hlt:
-    hlt
-    ret
-
-.globl asm_cli
-.type  asm_cli @function
-asm_cli:
-    cli
-    ret
-
-.globl asm_sti
-.type  asm_sti @function
-asm_sti:
-    sti
-    ret

+ 4 - 4
src/kernel/hw/ahci.cc

@@ -1,14 +1,14 @@
-#include "kernel/mem/phys.hpp"
 #include <vector>
 #include <cstddef>
 #include <algorithm>
 
-#include <kernel/vfs.hpp>
+#include <kernel/hw/pci.hpp>
+#include <kernel/irq.hpp>
 #include <kernel/log.hpp>
+#include <kernel/mem/phys.hpp>
 #include <kernel/mm.hpp>
 #include <kernel/module.hpp>
-#include <kernel/hw/pci.hpp>
-#include <kernel/irq.hpp>
+#include <kernel/vfs.hpp>
 
 #include <stdint.h>
 #include <errno.h>

+ 0 - 31
src/kernel/hw/keyboard.cpp

@@ -1,31 +0,0 @@
-#include <asm/port_io.h>
-#include <kernel/hw/keyboard.h>
-#include <kernel/input/input_event.h>
-
-extern "C" void
-handle_keyboard_interrupt(void)
-{
-    input_event evt {
-        .type = input_event::input_event_type::KEYBOARD,
-        .code = KEY_DOWN,
-        .data = 0
-    };
-
-    uint8_t keycode = asm_inb(PORT_KEYDATA);
-    if (keycode >= 0xd8) {
-        // TODO: report not_supported event
-        return;
-    }
-
-    // key release
-    if (keycode >= 0x80) {
-        evt.code = KEY_UP;
-        keycode -= 0x80;
-    }
-
-    evt.data = keycode;
-
-    // TODO: fix it
-    // commit_input_event(&evt);
-    (void)evt;
-}

+ 128 - 0
src/kernel/hw/serial.cc

@@ -0,0 +1,128 @@
+#include <errno.h>
+#include <stdio.h>
+
+#include <kernel/hw/port.hpp>
+#include <kernel/irq.hpp>
+#include <kernel/module.hpp>
+#include <kernel/tty.hpp>
+
+constexpr int PORT0 = 0x3f8;
+constexpr int PORT1 = 0x2f8;
+
+using port_group = kernel::hw::p8[6];
+
+constexpr kernel::hw::p8 port0[] = {
+    kernel::hw::p8{PORT0+0},
+    kernel::hw::p8{PORT0+1},
+    kernel::hw::p8{PORT0+2},
+    kernel::hw::p8{PORT0+3},
+    kernel::hw::p8{PORT0+4},
+    kernel::hw::p8{PORT0+5},
+};
+
+constexpr kernel::hw::p8 port1[] = {
+    kernel::hw::p8{PORT1+0},
+    kernel::hw::p8{PORT1+1},
+    kernel::hw::p8{PORT1+2},
+    kernel::hw::p8{PORT1+3},
+    kernel::hw::p8{PORT1+4},
+    kernel::hw::p8{PORT1+5},
+};
+
+static inline bool _serial_has_data(port_group ports)
+{
+    return *ports[5] & 1;
+}
+
+static inline int _init_port(port_group ports)
+{
+    // taken from osdev.org
+
+    ports[1] = 0x00; // Disable all interrupts
+    ports[3] = 0x80; // Enable DLAB (set baud rate divisor)
+    // TODO: set baud rate
+    ports[0] = 0x00; // Set divisor to 0 -3- (lo byte) 115200 -38400- baud
+    ports[1] = 0x00; //                  (hi byte)
+    ports[3] = 0x03; // 8 bits, no parity, one stop bit
+    ports[2] = 0xC7; // Enable FIFO, clear them, with 14-byte threshold
+    // TODO: IRQ disabled
+    ports[4] = 0x0B; // IRQs enabled, RTS/DSR set
+    ports[4] = 0x1E; // Set in loopback mode, test the serial chip
+    ports[0] = 0xAE; // Test serial chip (send byte 0xAE and check if serial returns same byte)
+
+    // Check if serial is faulty (i.e: not same byte as sent)
+    if (*ports[0] != 0xAE)
+        return -EIO;
+
+    // If serial is not faulty set it in normal operation mode
+    // (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
+    ports[4] = 0x0F;
+
+    ports[1] = 0x01; // Enable interrupts #0: Received Data Available
+
+    // TODO: LONG MODE
+    // kernel::irq::register_handler(4, serial_receive_data_interrupt);
+
+    return 0;
+}
+
+// TODO: LONG MODE
+// static void serial_receive_data_interrupt(void)
+// {
+//     while (_serial_has_data(PORT_SERIAL0)) {
+//         uint8_t data = serial_read_data(PORT_SERIAL0);
+//         console->commit_char(data);
+//     }
+// }
+// 
+// uint8_t serial_read_data(port_id_t port)
+// {
+//     while (is_serial_has_data(port) == 0)
+//         ;
+//     return asm_inb(port);
+// }
+// 
+// int32_t is_serial_ready_for_transmition(port_id_t port)
+// {
+//     return asm_inb(port + 5) & 0x20;
+// }
+// 
+// void serial_send_data(port_id_t port, uint8_t data)
+// {
+//     while (is_serial_ready_for_transmition(port) == 0)
+//         ;
+//     return asm_outb(port, data);
+// }
+
+class serial_tty : public virtual tty {
+public:
+    serial_tty(int id): id(id)
+    {
+        snprintf(name, sizeof(name), "ttyS%d", id);
+    }
+
+    virtual void putchar(char c) override
+    {
+        // TODO: LONG MODE
+        // serial_send_data(id, c);
+    }
+
+public:
+    uint16_t id;
+};
+
+class serial_module : public virtual kernel::module::module {
+public:
+    serial_module() : module("serial-tty") { }
+
+    virtual int init() override
+    {
+        // TODO: LONG MODE
+        return kernel::module::MODULE_FAILED;
+    }
+
+};
+
+kernel::module::module* serial_module_init()
+{ return new serial_module(); }
+INTERNAL_MODULE(serial_module_loader, serial_module_init);

+ 0 - 71
src/kernel/hw/serial.cpp

@@ -1,71 +0,0 @@
-#include <errno.h>
-#include <stdio.h>
-
-#include <asm/port_io.h>
-#include <kernel/hw/serial.h>
-#include <kernel/irq.hpp>
-#include <kernel/tty.hpp>
-
-static void serial_receive_data_interrupt(void)
-{
-    while (is_serial_has_data(PORT_SERIAL0)) {
-        uint8_t data = serial_read_data(PORT_SERIAL0);
-        console->commit_char(data);
-    }
-}
-
-SECTION(".text.kinit")
-int32_t init_serial_port(port_id_t port)
-{
-    // taken from osdev.org
-
-    asm_outb(port + 1, 0x00); // Disable all interrupts
-    asm_outb(port + 3, 0x80); // Enable DLAB (set baud rate divisor)
-    // TODO: set baud rate
-    asm_outb(port + 0, 0x00); // Set divisor to 0 -3- (lo byte) 115200 -38400- baud
-    asm_outb(port + 1, 0x00); //                  (hi byte)
-    asm_outb(port + 3, 0x03); // 8 bits, no parity, one stop bit
-    asm_outb(port + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
-    // TODO: IRQ disabled
-    asm_outb(port + 4, 0x0B); // IRQs enabled, RTS/DSR set
-    asm_outb(port + 4, 0x1E); // Set in loopback mode, test the serial chip
-    asm_outb(port + 0, 0xAE); // Test serial chip (send byte 0xAE and check if serial returns same byte)
-
-    // Check if serial is faulty (i.e: not same byte as sent)
-    if (asm_inb(port + 0) != 0xAE)
-        return -EIO;
-
-    // If serial is not faulty set it in normal operation mode
-    // (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
-    asm_outb(port + 4, 0x0F);
-
-    asm_outb(port + 1, 0x01); // Enable interrupts #0: Received Data Available
-
-    kernel::irq::register_handler(4, serial_receive_data_interrupt);
-
-    return 0;
-}
-
-int32_t is_serial_has_data(port_id_t port)
-{
-    return asm_inb(port + 5) & 1;
-}
-
-uint8_t serial_read_data(port_id_t port)
-{
-    while (is_serial_has_data(port) == 0)
-        ;
-    return asm_inb(port);
-}
-
-int32_t is_serial_ready_for_transmition(port_id_t port)
-{
-    return asm_inb(port + 5) & 0x20;
-}
-
-void serial_send_data(port_id_t port, uint8_t data)
-{
-    while (is_serial_ready_for_transmition(port) == 0)
-        ;
-    return asm_outb(port, data);
-}

+ 0 - 26
src/kernel/hw/timer.c

@@ -1,26 +0,0 @@
-#include <asm/port_io.h>
-#include <kernel/hw/timer.h>
-
-static size_t _current_ticks = 0;
-
-SECTION(".text.kinit")
-void init_pit(void)
-{
-    // set interval
-    asm_outb(PORT_PIT_CONTROL, 0x34);
-
-    // send interval number
-    // 0x2e9a = 11930 = 100Hz
-    asm_outb(PORT_PIT_COUNT, 0x9a);
-    asm_outb(PORT_PIT_COUNT, 0x2e);
-}
-
-void inc_tick(void)
-{
-    ++_current_ticks;
-}
-
-size_t current_ticks(void)
-{
-    return _current_ticks;
-}

+ 31 - 0
src/kernel/hw/timer.cc

@@ -0,0 +1,31 @@
+#include <types/types.h>
+
+#include <kernel/hw/port.hpp>
+#include <kernel/hw/timer.hpp>
+
+constexpr kernel::hw::p8 port_control(0x43);
+constexpr kernel::hw::p8 port_count(0x40);
+
+static std::size_t _current_ticks = 0;
+
+SECTION(".text.kinit")
+void kernel::hw::timer::init_pit(void)
+{
+    // set interval
+    port_control = 0x34;
+
+    // send interval number
+    // 0x2e9a = 11930 = 100Hz
+    port_count = 0x9a;
+    port_count = 0x2e;
+}
+
+void kernel::hw::timer::inc_tick(void)
+{
+    ++_current_ticks;
+}
+
+size_t kernel::hw::timer::current_ticks(void)
+{
+    return _current_ticks;
+}

+ 22 - 19
src/kernel/interrupt.cpp

@@ -7,10 +7,8 @@
 
 #include <types/types.h>
 
-#include <asm/port_io.h>
-#include <kernel/hw/keyboard.h>
-#include <kernel/hw/serial.h>
-#include <kernel/hw/timer.h>
+#include <kernel/hw/port.hpp>
+#include <kernel/hw/timer.hpp>
 #include <kernel/interrupt.h>
 #include <kernel/irq.hpp>
 #include <kernel/log.hpp>
@@ -19,6 +17,11 @@
 #include <kernel/vfs.hpp>
 #include <kernel/vga.hpp>
 
+constexpr kernel::hw::p8 port_pic1_command{0x20};
+constexpr kernel::hw::p8 port_pic1_data{0x21};
+constexpr kernel::hw::p8 port_pic2_command{0xa0};
+constexpr kernel::hw::p8 port_pic2_data{0xa1};
+
 struct IDT_entry {
     uint16_t offset_low;
     uint16_t selector;
@@ -118,29 +121,27 @@ void kernel::irq::register_handler(int irqno, irq_handler_t handler)
 SECTION(".text.kinit")
 void init_pic(void)
 {
-    asm_cli();
-
     s_irq_handlers.resize(16);
 
     // TODO: move this to timer driver
     kernel::irq::register_handler(0, []() {
-        inc_tick();
+        kernel::hw::timer::inc_tick();
         schedule();
     });
 
-    asm_outb(PORT_PIC1_COMMAND, 0x11); // edge trigger mode
-    asm_outb(PORT_PIC1_DATA, 0x20); // start from int 0x20
-    asm_outb(PORT_PIC1_DATA, 0x04); // PIC1 is connected to IRQ2 (1 << 2)
-    asm_outb(PORT_PIC1_DATA, 0x01); // no buffer mode
+    port_pic1_command = 0x11; // edge trigger mode
+    port_pic1_data = 0x20;    // start from int 0x20
+    port_pic1_data = 0x04;    // PIC1 is connected to IRQ2 (1 << 2)
+    port_pic1_data = 0x01;    // no buffer mode
 
-    asm_outb(PORT_PIC2_COMMAND, 0x11); // edge trigger mode
-    asm_outb(PORT_PIC2_DATA, 0x28); // start from int 0x28
-    asm_outb(PORT_PIC2_DATA, 0x02); // connected to IRQ2
-    asm_outb(PORT_PIC2_DATA, 0x01); // no buffer mode
+    port_pic2_command = 0x11; // edge trigger mode
+    port_pic2_data = 0x28;    // start from int 0x28
+    port_pic2_data = 0x02;    // connected to IRQ2
+    port_pic2_data = 0x01;    // no buffer mode
 
     // allow all the interrupts
-    asm_outb(PORT_PIC1_DATA, 0x00);
-    asm_outb(PORT_PIC2_DATA, 0x00);
+    port_pic1_data = 0x00;
+    port_pic2_data = 0x00;
 
     // 0x08 stands for kernel code segment
     SET_UP_IRQ(0, 0x08);
@@ -311,9 +312,11 @@ extern "C" void irq_handler(
     interrupt_stack* context,
     mmx_registers* mmxregs)
 {
-    asm_outb(PORT_PIC1_COMMAND, PIC_EOI);
+    constexpr uint8_t PIC_EOI = 0x20;
+
+    port_pic1_command = PIC_EOI;
     if (irqno >= 8)
-        asm_outb(PORT_PIC2_COMMAND, PIC_EOI);
+        port_pic2_command = PIC_EOI;
 
     for (const auto& handler : s_irq_handlers[irqno])
         handler();

+ 0 - 1
src/kernel/mem.cpp

@@ -5,7 +5,6 @@
 #include <stdint.h>
 #include <stdio.h>
 
-#include <asm/port_io.h>
 #include <kernel/mem/paging.hpp>
 #include <kernel/mm.hpp>
 #include <kernel/process.hpp>

+ 7 - 10
src/kernel/process.cpp

@@ -14,7 +14,6 @@
 #include <types/elf.hpp>
 #include <types/types.h>
 
-#include <asm/port_io.h>
 #include <kernel/async/lock.hpp>
 #include <kernel/interrupt.h>
 #include <kernel/log.hpp>
@@ -40,7 +39,7 @@ namespace kernel {
 struct no_irq_guard {
     explicit no_irq_guard()
     {
-        asm_cli();
+        asm volatile("cli");
     }
 
     no_irq_guard(const no_irq_guard&) = delete;
@@ -48,7 +47,7 @@ struct no_irq_guard {
 
     ~no_irq_guard()
     {
-        asm_sti();
+        asm volatile("sti");
     }
 };
 
@@ -262,7 +261,7 @@ void kernel_threadd_main(void)
             // }
         }
         // TODO: sleep here to wait for new_kernel_thread event
-        asm_hlt();
+        asm volatile("hlt");
     }
 }
 
@@ -343,7 +342,7 @@ void proclist::kill(pid_t pid, int exit_code)
 
     // init should never exit
     if (proc.ppid == 0) {
-        console->print("kernel panic: init exited!\n");
+        kmsg("kernel panic: init exited!\n");
         freeze();
     }
 
@@ -408,7 +407,7 @@ void NORETURN _kernel_init(void)
 {
     release_kinit();
 
-    asm_sti();
+    asm volatile("sti");
 
     // ------------------------------------------
     // interrupt enabled
@@ -461,7 +460,7 @@ void NORETURN _kernel_init(void)
 
     d.exec_dent = fs::vfs_open(*fs::fs_root, types::path{argv[0]});
     if (!d.exec_dent) {
-        console->print("kernel panic: init not found!\n");
+        kmsg("kernel panic: init not found!\n");
         freeze();
     }
 
@@ -573,10 +572,8 @@ void NORETURN schedule_noreturn(void)
 
 void NORETURN freeze(void)
 {
-    asm_cli();
-    asm_hlt();
     for (;;)
-        ;
+        asm volatile("cli\n\thlt");
 }
 
 void NORETURN kill_current(int signo)

+ 0 - 1
src/kernel/syscall.cpp

@@ -1,5 +1,4 @@
 #include <asm/port_io.h>
-#include <asm/sys.h>
 
 #include <assert.h>
 #include <errno.h>

+ 0 - 12
src/kernel/tty.cpp

@@ -5,7 +5,6 @@
 #include <termios.h>
 
 #include <kernel/async/lock.hpp>
-#include <kernel/hw/serial.h>
 #include <kernel/process.hpp>
 #include <kernel/tty.hpp>
 #include <kernel/vga.hpp>
@@ -285,17 +284,6 @@ vga_tty::vga_tty()
     snprintf(this->name, sizeof(this->name), "ttyVGA");
 }
 
-serial_tty::serial_tty(int id)
-    : id(id)
-{
-    snprintf(this->name, sizeof(this->name), "ttyS%x", (int)id);
-}
-
-void serial_tty::putchar(char c)
-{
-    serial_send_data(id, c);
-}
-
 void vga_tty::putchar(char c)
 {
     static struct vga_char vc = { .c = '\0', .color = VGA_CHAR_COLOR_WHITE };

+ 12 - 51
src/kinit.cpp

@@ -1,31 +1,23 @@
-#include <asm/port_io.h>
-
 #include <assert.h>
 #include <stdint.h>
-#include <stdio.h>
 #include <sys/utsname.h>
 
 #include <types/allocator.hpp>
 #include <types/types.h>
 
-#include <kernel/hw/keyboard.h>
 #include <kernel/hw/pci.hpp>
-#include <kernel/hw/serial.h>
-#include <kernel/hw/timer.h>
+#include <kernel/hw/timer.hpp>
 #include <kernel/interrupt.h>
 #include <kernel/log.hpp>
 #include <kernel/mem/paging.hpp>
 #include <kernel/mem/types.hpp>
 #include <kernel/process.hpp>
 #include <kernel/syscall.hpp>
-#include <kernel/task.h>
-#include <kernel/tty.hpp>
 #include <kernel/utsname.hpp>
-#include <kernel/vga.hpp>
 
-typedef void (*constructor)(void);
-extern constructor const SECTION(".rodata.kinit") start_ctors;
-extern constructor const SECTION(".rodata.kinit") end_ctors;
+using constructor = void (*)();
+extern "C" constructor const start_ctors, end_ctors;
+extern "C" uint64_t BSS_ADDR, BSS_LENGTH;
 
 struct PACKED bootloader_data {
     uint32_t meminfo_entry_count;
@@ -62,29 +54,7 @@ static inline void enable_sse()
 }
 
 SECTION(".text.kinit")
-static inline int init_console(const char* name)
-{
-    if (name[0] == 't' && name[1] == 't' && name[2] == 'y') {
-        if (name[3] == 'S' || name[3] == 's') {
-            if (name[4] == '0') {
-                console = new serial_tty(PORT_SERIAL0);
-                return 0;
-            }
-            if (name[4] == '1') {
-                console = new serial_tty(PORT_SERIAL1);
-                return 0;
-            }
-        }
-        if (name[3] == 'V' && name[3] == 'G' && name[3] == 'A') {
-            console = new vga_tty{};
-            return 0;
-        }
-    }
-    return -EINVAL;
-}
-
-SECTION(".text.kinit")
-static void init_uname()
+static inline void set_uname()
 {
     kernel::sys_utsname = new new_utsname;
     strcpy(kernel::sys_utsname->sysname, "Linux"); // linux compatible
@@ -104,32 +74,22 @@ void NORETURN real_kernel_init()
     for (auto* ctor = &start_ctors; ctor != &end_ctors; ++ctor)
         (*ctor)();
 
+    set_uname();
+
     init_idt();
-    // TODO: LONG MODE
-    // init_mem();
     init_pic();
-    init_pit();
-
-    init_uname();
-
-    int ret = init_serial_port(PORT_SERIAL0);
-    assert(ret == 0);
-
-    ret = init_console("ttyS0");
-    assert(ret == 0);
+    hw::timer::init_pit();
 
     kernel::kinit::init_pci();
+
+    // TODO: remove this
     init_vfs();
     // TODO: LONG MODE
     // init_syscall();
 
-    kmsg("switching execution to the scheduler...\n");
     init_scheduler();
 }
 
-extern "C" uint64_t BSS_ADDR;
-extern "C" uint64_t BSS_LENGTH;
-
 SECTION(".text.kinit")
 static inline void setup_early_kernel_page_table()
 {
@@ -261,7 +221,8 @@ void NORETURN kernel_init(bootloader_data* data)
             : "r"(real_kernel_init)
             :
             );
-    die();
+    for (;;)
+        asm volatile("cli\n\thlt");
 }
 
 } // namespace kernel::kinit

+ 0 - 1
src/types/libstdcpp.cpp

@@ -1,4 +1,3 @@
-#include <asm/port_io.h>
 #include <assert.h>
 #include <kernel/log.hpp>
 #include <kernel/process.hpp>