1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-11-20 11:16:10 -05:00

Use <kernaux/asm/*.h>

This commit is contained in:
Alex Kotov 2021-12-20 11:14:07 +05:00
parent 18deba7396
commit 3e44e7c0df
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 46 additions and 45 deletions

View file

@ -1,6 +1,7 @@
#include "paging.h"
#include "panic.h"
#include <kernaux/asm/i386.h>
#include <kernaux/libc.h>
#include <kernaux/stdlib.h>
@ -9,37 +10,37 @@ static void mapping(struct Paging *paging, uint32_t virt, uint32_t phys);
void paging_load(struct Paging *const paging)
{
uint32_t page_dir_phys = (uint32_t)&paging->page_dir;
kernaux_arch_i386_write_cr3(page_dir_phys);
kernaux_asm_i386_write_cr3(page_dir_phys);
}
void paging_enable()
{
uint32_t cr0 = kernaux_arch_i386_read_cr0();
uint32_t cr4 = kernaux_arch_i386_read_cr4();
uint32_t cr0 = kernaux_asm_i386_read_cr0();
uint32_t cr4 = kernaux_asm_i386_read_cr4();
assert(cr0 & KERNAUX_ARCH_I386_CR0_PE, "The boot loader should have put us in protected mode.");
// First clear PG and PGE flag, as PGE must be enabled after PG.
kernaux_arch_i386_write_cr0(cr0 & ~KERNAUX_ARCH_I386_CR0_PG);
kernaux_arch_i386_write_cr4(cr4 & ~(KERNAUX_ARCH_I386_CR4_PGE | KERNAUX_ARCH_I386_CR4_PSE));
kernaux_asm_i386_write_cr0(cr0 & ~KERNAUX_ARCH_I386_CR0_PG);
kernaux_asm_i386_write_cr4(cr4 & ~(KERNAUX_ARCH_I386_CR4_PGE | KERNAUX_ARCH_I386_CR4_PSE));
cr0 = kernaux_arch_i386_read_cr0();
cr4 = kernaux_arch_i386_read_cr4();
cr0 = kernaux_asm_i386_read_cr0();
cr4 = kernaux_asm_i386_read_cr4();
// Our page table contains 4MB entries.
// cr4 |= KERNAUX_ARCH_I386_CR4_PSE;
kernaux_arch_i386_write_cr4(cr4);
kernaux_asm_i386_write_cr4(cr4);
// First enable paging, then enable global page flag.
cr0 |= KERNAUX_ARCH_I386_CR0_PG;
kernaux_arch_i386_write_cr0(cr0);
kernaux_asm_i386_write_cr0(cr0);
cr0 |= KERNAUX_ARCH_I386_CR0_WP;
kernaux_arch_i386_write_cr0(cr0);
kernaux_arch_i386_write_cr4(cr4);
kernaux_asm_i386_write_cr0(cr0);
kernaux_asm_i386_write_cr4(cr4);
}
void paging_clear(struct Paging *const paging)

View file

@ -1,12 +1,12 @@
#include "panic.h"
#include <kernaux/arch/i386.h>
#include <kernaux/asm/i386.h>
#include <kernaux/console.h>
void panic(const char *const s)
{
kernaux_console_printf("[FAIL] panic: %s\n", s);
kernaux_arch_i386_hang();
kernaux_asm_i386_hang();
}
void halt()
@ -21,5 +21,5 @@ void kernaux_assert_fn(
) {
kernaux_console_printf("[FAIL] assertion failed: %s:%u: \"%s\"\n",
file, line, str);
kernaux_arch_i386_hang();
kernaux_asm_i386_hang();
}

View file

@ -1,6 +1,6 @@
#include "pic.h"
#include <kernaux/arch/i386.h>
#include <kernaux/asm/i386.h>
#include <kernaux/console.h>
#define MASTER_COMMAND 0x20
@ -19,16 +19,16 @@ void pic_enable_all()
{
kernaux_console_print("[INFO] pic: Enable all IRQs.\n");
kernaux_arch_i386_outportb(MASTER_DATA, 0);
kernaux_arch_i386_outportb(SLAVE_DATA, 0);
kernaux_asm_i386_outportb(MASTER_DATA, 0);
kernaux_asm_i386_outportb(SLAVE_DATA, 0);
}
void pic_disable_all()
{
kernaux_console_print("[INFO] pic: Disable all IRQs.\n");
kernaux_arch_i386_outportb(MASTER_DATA, 0xFF);
kernaux_arch_i386_outportb(SLAVE_DATA, 0xFF);
kernaux_asm_i386_outportb(MASTER_DATA, 0xFF);
kernaux_asm_i386_outportb(SLAVE_DATA, 0xFF);
}
void pic_enable(const unsigned char line)
@ -41,12 +41,12 @@ void pic_enable(const unsigned char line)
kernaux_console_printf("[INFO] pic: Enable line %u.\n", line);
if (line < IRQS_COUNT) {
const unsigned char mask = kernaux_arch_i386_inportb(MASTER_DATA);
kernaux_arch_i386_outportb(MASTER_DATA, mask & ~(1 << line));
const unsigned char mask = kernaux_asm_i386_inportb(MASTER_DATA);
kernaux_asm_i386_outportb(MASTER_DATA, mask & ~(1 << line));
}
else {
const unsigned char mask = kernaux_arch_i386_inportb(SLAVE_DATA);
kernaux_arch_i386_outportb(SLAVE_DATA, mask & ~(1 << (line - IRQS_COUNT)));
const unsigned char mask = kernaux_asm_i386_inportb(SLAVE_DATA);
kernaux_asm_i386_outportb(SLAVE_DATA, mask & ~(1 << (line - IRQS_COUNT)));
}
}
@ -60,12 +60,12 @@ void pic_disable(const unsigned char line)
kernaux_console_printf("[INFO] pic: Disable line %u.\n", line);
if (line < IRQS_COUNT) {
const unsigned char mask = kernaux_arch_i386_inportb(MASTER_DATA);
kernaux_arch_i386_outportb(MASTER_DATA, mask | (1 << line));
const unsigned char mask = kernaux_asm_i386_inportb(MASTER_DATA);
kernaux_asm_i386_outportb(MASTER_DATA, mask | (1 << line));
}
else {
const unsigned char mask = kernaux_arch_i386_inportb(SLAVE_DATA);
kernaux_arch_i386_outportb(SLAVE_DATA, mask | (1 << (line - IRQS_COUNT)));
const unsigned char mask = kernaux_asm_i386_inportb(SLAVE_DATA);
kernaux_asm_i386_outportb(SLAVE_DATA, mask | (1 << (line - IRQS_COUNT)));
}
}
@ -79,28 +79,28 @@ void pic_remap(const unsigned char new_master_irq_start, const unsigned char new
slave_irq_start = new_slave_irq_start;
// Save masks
unsigned char master_mask = kernaux_arch_i386_inportb(MASTER_DATA);
unsigned char slave_mask = kernaux_arch_i386_inportb(SLAVE_DATA);
unsigned char master_mask = kernaux_asm_i386_inportb(MASTER_DATA);
unsigned char slave_mask = kernaux_asm_i386_inportb(SLAVE_DATA);
// Start the initialization sequence
kernaux_arch_i386_outportb(MASTER_COMMAND, 0x11);
kernaux_arch_i386_outportb(SLAVE_COMMAND, 0x11);
kernaux_asm_i386_outportb(MASTER_COMMAND, 0x11);
kernaux_asm_i386_outportb(SLAVE_COMMAND, 0x11);
// Set IRQ vectors
kernaux_arch_i386_outportb(MASTER_DATA, new_master_irq_start);
kernaux_arch_i386_outportb(SLAVE_DATA, new_slave_irq_start);
kernaux_asm_i386_outportb(MASTER_DATA, new_master_irq_start);
kernaux_asm_i386_outportb(SLAVE_DATA, new_slave_irq_start);
// Connect master and slave with each other
kernaux_arch_i386_outportb(MASTER_DATA, 0x04);
kernaux_arch_i386_outportb(SLAVE_DATA, 0x02);
kernaux_asm_i386_outportb(MASTER_DATA, 0x04);
kernaux_asm_i386_outportb(SLAVE_DATA, 0x02);
// 8086/88 (MCS-80/85) mode
kernaux_arch_i386_outportb(MASTER_DATA, 0x01);
kernaux_arch_i386_outportb(SLAVE_DATA, 0x01);
kernaux_asm_i386_outportb(MASTER_DATA, 0x01);
kernaux_asm_i386_outportb(SLAVE_DATA, 0x01);
// Restore masks
kernaux_arch_i386_outportb(MASTER_DATA, master_mask);
kernaux_arch_i386_outportb(SLAVE_DATA, slave_mask);
kernaux_asm_i386_outportb(MASTER_DATA, master_mask);
kernaux_asm_i386_outportb(SLAVE_DATA, slave_mask);
}
unsigned char pic_end_of_interrupt(const unsigned char irq)
@ -113,10 +113,10 @@ unsigned char pic_end_of_interrupt(const unsigned char irq)
}
if (to_slave) {
kernaux_arch_i386_outportb(SLAVE_COMMAND, 0x20);
kernaux_asm_i386_outportb(SLAVE_COMMAND, 0x20);
}
kernaux_arch_i386_outportb(MASTER_COMMAND, 0x20);
kernaux_asm_i386_outportb(MASTER_COMMAND, 0x20);
return 1;
}

View file

@ -1,6 +1,6 @@
#include "timer.h"
#include <kernaux/arch/i386.h>
#include <kernaux/asm/i386.h>
#include <kernaux/console.h>
void timer_initialize(unsigned int frequency)
@ -12,9 +12,9 @@ void timer_initialize(unsigned int frequency)
const unsigned char l = divisor & 0xFF;
const unsigned char h = (divisor >> 8) & 0xFF;
kernaux_arch_i386_outportb(0x43, 0x36);
kernaux_arch_i386_outportb(0x40, l);
kernaux_arch_i386_outportb(0x40, h);
kernaux_asm_i386_outportb(0x43, 0x36);
kernaux_asm_i386_outportb(0x40, l);
kernaux_asm_i386_outportb(0x40, h);
}
void timer_register_handler(timer_handler_t handler)