mirror of
https://github.com/tailix/kernel.git
synced 2024-11-20 11:16:10 -05:00
Use new drivers
This commit is contained in:
parent
6e7bb02546
commit
676fe25b6c
9 changed files with 57 additions and 57 deletions
|
@ -1,6 +1,7 @@
|
|||
CCPREFIX = /home/kotovalexarian/repos/global/tailix/cross/root/bin/i386-elf-
|
||||
|
||||
LIBKERNAUX_PREFIX = /opt/libkernaux/i386
|
||||
DRIVERS_PREFIX = /opt/drivers/i386
|
||||
|
||||
AS = $(CCPREFIX)as
|
||||
CC = $(CCPREFIX)gcc
|
||||
|
@ -16,7 +17,8 @@ CFLAGS = \
|
|||
-ffreestanding \
|
||||
-fno-builtin \
|
||||
-fno-stack-protector \
|
||||
-I$(LIBKERNAUX_PREFIX)/include
|
||||
-I$(LIBKERNAUX_PREFIX)/include \
|
||||
-I$(DRIVERS_PREFIX)/include
|
||||
|
||||
CPPFLAGS = \
|
||||
-DKERNAUX_ENABLE_ASSERT \
|
||||
|
@ -47,7 +49,7 @@ clean:
|
|||
rm -f $(KERNEL) $(OBJS)
|
||||
|
||||
$(KERNEL): $(OBJS)
|
||||
$(CC) -T linker.ld -o $@ $^ -ffreestanding -nostdlib -lkernaux -lgcc -Wl,-L$(LIBKERNAUX_PREFIX)/lib
|
||||
$(CC) -T linker.ld -o $@ $^ -ffreestanding -nostdlib -ldrivers -lkernaux -lgcc -Wl,-L$(LIBKERNAUX_PREFIX)/lib -Wl,-L$(DRIVERS_PREFIX)/lib
|
||||
grub-file --is-x86-multiboot2 $@
|
||||
|
||||
%.c.o: %.c
|
||||
|
|
32
src/info.c
32
src/info.c
|
@ -1,8 +1,8 @@
|
|||
#include "info.h"
|
||||
#include "panic.h"
|
||||
|
||||
#include <drivers/console.h>
|
||||
#include <kernaux/assert.h>
|
||||
#include <kernaux/drivers/console.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
@ -156,21 +156,21 @@ void kernel_info_print(const struct Kernel_Info *const kinfo)
|
|||
{
|
||||
KERNAUX_ASSERT(kinfo);
|
||||
|
||||
kernaux_drivers_console_printf("Kernel info\n");
|
||||
kernaux_drivers_console_printf(" cmdline: %s\n", kinfo->cmdline);
|
||||
kernaux_drivers_console_printf(" modules: %lu\n", kinfo->modules_count);
|
||||
kernaux_drivers_console_printf(" areas: %lu\n", kinfo->areas_count);
|
||||
kernaux_drivers_console_printf("\n");
|
||||
kernaux_drivers_console_printf(" offset: %lu\n", kinfo->kernel_offset);
|
||||
kernaux_drivers_console_printf(" size: %lu\n", kinfo->kernel_size);
|
||||
kernaux_drivers_console_printf(" phys base: %lu\n", kinfo->kernel_phys_base);
|
||||
kernaux_drivers_console_printf(" virt base: %lu\n", kinfo->kernel_virt_base);
|
||||
kernaux_drivers_console_printf("\n");
|
||||
kernaux_drivers_console_printf(" modules size: %lu\n", kinfo->modules_total_size);
|
||||
kernaux_drivers_console_printf(" kernel & modules size: %lu\n", kinfo->kernel_and_modules_total_size);
|
||||
kernaux_drivers_console_printf("\n");
|
||||
kernaux_drivers_console_printf(" stack start: %lu\n", kinfo->kernel_stack_start);
|
||||
kernaux_drivers_console_printf(" stack size: %lu\n", kinfo->kernel_stack_size);
|
||||
drivers_console_printf("Kernel info\n");
|
||||
drivers_console_printf(" cmdline: %s\n", kinfo->cmdline);
|
||||
drivers_console_printf(" modules: %lu\n", kinfo->modules_count);
|
||||
drivers_console_printf(" areas: %lu\n", kinfo->areas_count);
|
||||
drivers_console_printf("\n");
|
||||
drivers_console_printf(" offset: %lu\n", kinfo->kernel_offset);
|
||||
drivers_console_printf(" size: %lu\n", kinfo->kernel_size);
|
||||
drivers_console_printf(" phys base: %lu\n", kinfo->kernel_phys_base);
|
||||
drivers_console_printf(" virt base: %lu\n", kinfo->kernel_virt_base);
|
||||
drivers_console_printf("\n");
|
||||
drivers_console_printf(" modules size: %lu\n", kinfo->modules_total_size);
|
||||
drivers_console_printf(" kernel & modules size: %lu\n", kinfo->kernel_and_modules_total_size);
|
||||
drivers_console_printf("\n");
|
||||
drivers_console_printf(" stack start: %lu\n", kinfo->kernel_stack_start);
|
||||
drivers_console_printf(" stack size: %lu\n", kinfo->kernel_stack_size);
|
||||
}
|
||||
|
||||
bool kernel_info_is_valid(const struct Kernel_Info *const kinfo)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "main.h"
|
||||
#include "../panic.h"
|
||||
|
||||
#include <kernaux/drivers/console.h>
|
||||
#include <drivers/console.h>
|
||||
|
||||
static const char *const messages[] = {
|
||||
"0 #DE - Divide Error Exception",
|
||||
|
@ -42,7 +42,7 @@ void exception_handler(struct IsrRegisters regs)
|
|||
{
|
||||
if (regs.int_no > INT_EXCEPTION_LAST) return;
|
||||
|
||||
kernaux_drivers_console_printf(
|
||||
drivers_console_printf(
|
||||
"[FAIL] exception: Unhandled protected-mode exception: %s\n",
|
||||
messages[regs.int_no]
|
||||
);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "main.h"
|
||||
|
||||
#include <kernaux/drivers/console.h>
|
||||
#include <kernaux/drivers/intel_8259_pic.h>
|
||||
#include <drivers/console.h>
|
||||
#include <drivers/intel_8259_pic.h>
|
||||
|
||||
static hwint_handler_t handlers[INT_HWINT_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
|
@ -14,12 +14,12 @@ void hwint_handler(struct IsrRegisters regs)
|
|||
const hwint_handler_t handler = handlers[hwint_no];
|
||||
|
||||
if (!handler) {
|
||||
kernaux_drivers_console_printf("[WARN] hwint: Unhandled hardware interrupt: %u\n", hwint_no);
|
||||
drivers_console_printf("[WARN] hwint: Unhandled hardware interrupt: %u\n", hwint_no);
|
||||
return;
|
||||
}
|
||||
|
||||
handler();
|
||||
kernaux_drivers_intel_8259_pic_eoi(regs.int_no);
|
||||
drivers_intel_8259_pic_eoi(regs.int_no);
|
||||
}
|
||||
|
||||
void hwint_register_handler(unsigned int int_no, hwint_handler_t handler)
|
||||
|
@ -29,7 +29,7 @@ void hwint_register_handler(unsigned int int_no, hwint_handler_t handler)
|
|||
}
|
||||
|
||||
handlers[int_no] = handler;
|
||||
kernaux_drivers_intel_8259_pic_enable(int_no);
|
||||
drivers_intel_8259_pic_enable(int_no);
|
||||
}
|
||||
|
||||
void hwint_unregister_handler(unsigned int int_no)
|
||||
|
@ -38,6 +38,6 @@ void hwint_unregister_handler(unsigned int int_no)
|
|||
return;
|
||||
}
|
||||
|
||||
kernaux_drivers_intel_8259_pic_disable(int_no);
|
||||
drivers_intel_8259_pic_disable(int_no);
|
||||
handlers[int_no] = 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "main.h"
|
||||
|
||||
#include <kernaux/drivers/console.h>
|
||||
#include <drivers/console.h>
|
||||
|
||||
static void syscall_do_exit(struct IsrRegisters regs);
|
||||
|
||||
|
@ -8,7 +8,7 @@ void syscall_handler(const struct IsrRegisters regs)
|
|||
{
|
||||
const unsigned int id = regs.eax << 16 >> 16;
|
||||
|
||||
kernaux_drivers_console_printf("[INFO] syscall: number %u\n", id);
|
||||
drivers_console_printf("[INFO] syscall: number %u\n", id);
|
||||
|
||||
switch (id) {
|
||||
case KERNEL_SYSCALL_EXIT: syscall_do_exit(regs); break;
|
||||
|
@ -19,5 +19,5 @@ void syscall_do_exit(const struct IsrRegisters regs)
|
|||
{
|
||||
const unsigned int exit_code = regs.ebx << 16 >> 16;
|
||||
|
||||
kernaux_drivers_console_printf("[WARN] syscall: process try to exit with error code %u, haha\n", exit_code);
|
||||
drivers_console_printf("[WARN] syscall: process try to exit with error code %u, haha\n", exit_code);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "panic.h"
|
||||
#include "protected.h"
|
||||
|
||||
#include <kernaux/drivers/console.h>
|
||||
#include <drivers/console.h>
|
||||
#include <kernaux/multiboot2.h>
|
||||
#include <kernaux/pfa.h>
|
||||
|
||||
|
@ -33,8 +33,7 @@ void main(
|
|||
panic("Multiboot 2 info magic number is invalid.");
|
||||
}
|
||||
|
||||
KernAux_Multiboot2_Info_print(multiboot2_info,
|
||||
kernaux_drivers_console_printf);
|
||||
KernAux_Multiboot2_Info_print(multiboot2_info, drivers_console_printf);
|
||||
|
||||
if (!KernAux_Multiboot2_Info_is_valid(multiboot2_info)) {
|
||||
panic("Multiboot 2 info is invalid.");
|
||||
|
@ -68,5 +67,5 @@ void main(
|
|||
|
||||
protected_initialize(&kinfo);
|
||||
|
||||
kernaux_drivers_console_puts("[INFO] main: Finished.");
|
||||
drivers_console_puts("[INFO] main: Finished.");
|
||||
}
|
||||
|
|
15
src/panic.c
15
src/panic.c
|
@ -1,14 +1,13 @@
|
|||
#include "panic.h"
|
||||
|
||||
#include <drivers/console.h>
|
||||
#include <drivers/shutdown.h>
|
||||
#include <kernaux/asm/i386.h>
|
||||
#include <kernaux/drivers/console.h>
|
||||
#include <kernaux/drivers/shutdown.h>
|
||||
#include <kernaux/drivers/qemu.h>
|
||||
|
||||
void panic(const char *const s)
|
||||
{
|
||||
kernaux_drivers_console_printf("[FAIL] panic: %s\n", s);
|
||||
kernaux_drivers_shutdown_poweroff();
|
||||
drivers_console_printf("[FAIL] panic: %s\n", s);
|
||||
drivers_shutdown_poweroff();
|
||||
}
|
||||
|
||||
void halt()
|
||||
|
@ -21,7 +20,7 @@ void kernaux_assert_fn(
|
|||
const int line,
|
||||
const char *const str
|
||||
) {
|
||||
kernaux_drivers_console_printf("[FAIL] assertion failed: %s:%u: \"%s\"\n",
|
||||
file, line, str);
|
||||
kernaux_drivers_shutdown_poweroff();
|
||||
drivers_console_printf("[FAIL] assertion failed: %s:%u: \"%s\"\n",
|
||||
file, line, str);
|
||||
drivers_shutdown_poweroff();
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
#include "info.h"
|
||||
#include "interrupts/main.h"
|
||||
|
||||
#include <drivers/console.h>
|
||||
#include <drivers/intel_8259_pic.h>
|
||||
#include <kernaux/arch/i386.h>
|
||||
#include <kernaux/asm/i386.h>
|
||||
#include <kernaux/drivers/console.h>
|
||||
#include <kernaux/drivers/intel_8259_pic.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
@ -27,21 +27,21 @@ static void idt_set_gate(uint8_t num, uint32_t base, uint16_t sel, uint8_t flags
|
|||
|
||||
void protected_initialize(const struct Kernel_Info *const kinfo)
|
||||
{
|
||||
kernaux_drivers_intel_8259_pic_remap(32, 40);
|
||||
kernaux_drivers_intel_8259_pic_disable_all();
|
||||
drivers_intel_8259_pic_remap(32, 40);
|
||||
drivers_intel_8259_pic_disable_all();
|
||||
|
||||
kernaux_drivers_console_puts("[INFO] protected: Setup GDT.");
|
||||
drivers_console_puts("[INFO] protected: Setup GDT.");
|
||||
gdt_set_gates();
|
||||
|
||||
kernaux_drivers_console_puts("[INFO] protected: Setup IDT.");
|
||||
drivers_console_puts("[INFO] protected: Setup IDT.");
|
||||
idt_set_gates();
|
||||
|
||||
kernaux_drivers_console_puts("[INFO] protected: Setup TSS.");
|
||||
drivers_console_puts("[INFO] protected: Setup TSS.");
|
||||
memset(&tss, 0, sizeof(tss));
|
||||
tss.ss0 = GDT_KERNEL_DS_SELECTOR;
|
||||
tss.esp0 = kinfo->kernel_stack_start + kinfo->kernel_stack_size;
|
||||
|
||||
kernaux_drivers_console_puts("[INFO] protected: Load GDT.");
|
||||
drivers_console_puts("[INFO] protected: Load GDT.");
|
||||
gdt_pointer.size = sizeof(struct KernAux_Arch_I386_DTE) * GDT_SIZE - 1;
|
||||
gdt_pointer.offset = (uint32_t)&gdt_entries;
|
||||
kernaux_asm_i386_flush_gdt(
|
||||
|
@ -50,18 +50,18 @@ void protected_initialize(const struct Kernel_Info *const kinfo)
|
|||
GDT_KERNEL_CS_SELECTOR
|
||||
);
|
||||
|
||||
kernaux_drivers_console_puts("[INFO] protected: Load IDT.");
|
||||
drivers_console_puts("[INFO] protected: Load IDT.");
|
||||
idt_pointer.size = sizeof(struct KernAux_Arch_I386_IDTE) * IDT_SIZE - 1;
|
||||
idt_pointer.offset = (uint32_t)&idt_entries;
|
||||
kernaux_asm_i386_flush_idt((uint32_t)&idt_pointer);
|
||||
|
||||
// kernaux_drivers_console_puts("[INFO] protected: Load TSS.");
|
||||
// drivers_console_puts("[INFO] protected: Load TSS.");
|
||||
// kernaux_asm_i386_flush_tss(GDT_TSS_SELECTOR);
|
||||
|
||||
kernaux_drivers_console_puts("[INFO] protected: Enable interrupts.");
|
||||
drivers_console_puts("[INFO] protected: Enable interrupts.");
|
||||
asm volatile ("sti");
|
||||
|
||||
kernaux_drivers_console_puts("[INFO] protected: Finished.");
|
||||
drivers_console_puts("[INFO] protected: Finished.");
|
||||
}
|
||||
|
||||
void gdt_set_gates()
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include "timer.h"
|
||||
|
||||
#include <drivers/console.h>
|
||||
#include <drivers/intel_8253_pit.h>
|
||||
#include <kernaux/asm/i386.h>
|
||||
#include <kernaux/drivers/console.h>
|
||||
#include <kernaux/drivers/intel_8253_pit.h>
|
||||
|
||||
void timer_initialize(unsigned int frequency)
|
||||
{
|
||||
kernaux_drivers_console_puts("[INFO] timer: Initialize timer.");
|
||||
kernaux_drivers_intel_8253_pit_initialize(frequency);
|
||||
drivers_console_puts("[INFO] timer: Initialize timer.");
|
||||
drivers_intel_8253_pit_initialize(frequency);
|
||||
}
|
||||
|
||||
void timer_register_handler(timer_handler_t handler)
|
||||
|
|
Loading…
Reference in a new issue