1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-11-27 11:24:34 -05:00

Use port I/O from "libkernaux"

This commit is contained in:
Alex Kotov 2020-11-29 04:50:35 +05:00
parent 82b2116a2a
commit 656b7f434c
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
5 changed files with 36 additions and 82 deletions

View file

@ -1,48 +0,0 @@
#ifndef KERNELMQ_INCLUDED_ASM
#define KERNELMQ_INCLUDED_ASM 1
inline static unsigned char inportb(unsigned short port);
inline static unsigned short inportw(unsigned short port);
inline static unsigned int inportd(unsigned short port);
inline static void outportb(unsigned short port, unsigned char value);
inline static void outportw(unsigned short port, unsigned short value);
inline static void outportd(unsigned short port, unsigned int value);
unsigned char inportb(unsigned short port)
{
register unsigned char result;
asm volatile("inb %1, %0" : "=a" (result) : "dN" (port));
return result;
}
unsigned short inportw(unsigned short port)
{
register unsigned short result;
asm volatile("inw %1, %0" : "=a" (result) : "dN" (port));
return result;
}
unsigned int inportd(unsigned short port)
{
register unsigned int result;
asm volatile("ind %1, %0" : "=a" (result) : "dN" (port));
return result;
}
void outportb(unsigned short port, unsigned char value)
{
asm volatile("outb %1, %0" : : "dN" (port), "a" (value));
}
void outportw(unsigned short port, unsigned short value)
{
asm volatile("outw %1, %0" : : "dN" (port), "a" (value));
}
void outportd(unsigned short port, unsigned int value)
{
asm volatile("outd %1, %0" : : "dN" (port), "a" (value));
}
#endif

View file

@ -1,7 +1,8 @@
#include "console.h"
#include "stdlib.h"
#include "asm.h"
#include <kernaux/arch/i386.h>
void console_print(const char *const s)
{
@ -9,7 +10,7 @@ void console_print(const char *const s)
}
void console_putc(const char c) {
outportb(0x3F8, c);
kernaux_arch_i386_outportb(0x3F8, c);
}
void console_puts(const char *const s)

View file

@ -2,7 +2,6 @@
#include "interrupt.h"
#include "config.h"
#include "asm.h"
#include "logger.h"
#include "pic.h"

View file

@ -1,7 +1,8 @@
#include "pic.h"
#include "logger.h"
#include "asm.h"
#include <kernaux/arch/i386.h>
#define MASTER_COMMAND 0x20
#define MASTER_DATA 0x21
@ -19,16 +20,16 @@ void pic_enable_all()
{
logger_info_from("pic", "Enable all IRQs.");
outportb(MASTER_DATA, 0);
outportb(SLAVE_DATA, 0);
kernaux_arch_i386_outportb(MASTER_DATA, 0);
kernaux_arch_i386_outportb(SLAVE_DATA, 0);
}
void pic_disable_all()
{
logger_info_from("pic", "Disable all IRQs.");
outportb(MASTER_DATA, 0xFF);
outportb(SLAVE_DATA, 0xFF);
kernaux_arch_i386_outportb(MASTER_DATA, 0xFF);
kernaux_arch_i386_outportb(SLAVE_DATA, 0xFF);
}
void pic_enable(const unsigned char line)
@ -41,12 +42,12 @@ void pic_enable(const unsigned char line)
logger_info_from("pic", "Enable line %u.", line);
if (line < IRQS_COUNT) {
const unsigned char mask = inportb(MASTER_DATA);
outportb(MASTER_DATA, mask & ~(1 << line));
const unsigned char mask = kernaux_arch_i386_inportb(MASTER_DATA);
kernaux_arch_i386_outportb(MASTER_DATA, mask & ~(1 << line));
}
else {
const unsigned char mask = inportb(SLAVE_DATA);
outportb(SLAVE_DATA, mask & ~(1 << (line - IRQS_COUNT)));
const unsigned char mask = kernaux_arch_i386_inportb(SLAVE_DATA);
kernaux_arch_i386_outportb(SLAVE_DATA, mask & ~(1 << (line - IRQS_COUNT)));
}
}
@ -60,12 +61,12 @@ void pic_disable(const unsigned char line)
logger_info_from("pic", "Disable line %u.", line);
if (line < IRQS_COUNT) {
const unsigned char mask = inportb(MASTER_DATA);
outportb(MASTER_DATA, mask | (1 << line));
const unsigned char mask = kernaux_arch_i386_inportb(MASTER_DATA);
kernaux_arch_i386_outportb(MASTER_DATA, mask | (1 << line));
}
else {
const unsigned char mask = inportb(SLAVE_DATA);
outportb(SLAVE_DATA, mask | (1 << (line - IRQS_COUNT)));
const unsigned char mask = kernaux_arch_i386_inportb(SLAVE_DATA);
kernaux_arch_i386_outportb(SLAVE_DATA, mask | (1 << (line - IRQS_COUNT)));
}
}
@ -79,28 +80,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 = inportb(MASTER_DATA);
unsigned char slave_mask = inportb(SLAVE_DATA);
unsigned char master_mask = kernaux_arch_i386_inportb(MASTER_DATA);
unsigned char slave_mask = kernaux_arch_i386_inportb(SLAVE_DATA);
// Start the initialization sequence
outportb(MASTER_COMMAND, 0x11);
outportb(SLAVE_COMMAND, 0x11);
kernaux_arch_i386_outportb(MASTER_COMMAND, 0x11);
kernaux_arch_i386_outportb(SLAVE_COMMAND, 0x11);
// Set IRQ vectors
outportb(MASTER_DATA, new_master_irq_start);
outportb(SLAVE_DATA, new_slave_irq_start);
kernaux_arch_i386_outportb(MASTER_DATA, new_master_irq_start);
kernaux_arch_i386_outportb(SLAVE_DATA, new_slave_irq_start);
// Connect master and slave with each other
outportb(MASTER_DATA, 0x04);
outportb(SLAVE_DATA, 0x02);
kernaux_arch_i386_outportb(MASTER_DATA, 0x04);
kernaux_arch_i386_outportb(SLAVE_DATA, 0x02);
// 8086/88 (MCS-80/85) mode
outportb(MASTER_DATA, 0x01);
outportb(SLAVE_DATA, 0x01);
kernaux_arch_i386_outportb(MASTER_DATA, 0x01);
kernaux_arch_i386_outportb(SLAVE_DATA, 0x01);
// Restore masks
outportb(MASTER_DATA, master_mask);
outportb(SLAVE_DATA, slave_mask);
kernaux_arch_i386_outportb(MASTER_DATA, master_mask);
kernaux_arch_i386_outportb(SLAVE_DATA, slave_mask);
}
unsigned char pic_end_of_interrupt(const unsigned char irq)
@ -113,10 +114,10 @@ unsigned char pic_end_of_interrupt(const unsigned char irq)
}
if (to_slave) {
outportb(SLAVE_COMMAND, 0x20);
kernaux_arch_i386_outportb(SLAVE_COMMAND, 0x20);
}
outportb(MASTER_COMMAND, 0x20);
kernaux_arch_i386_outportb(MASTER_COMMAND, 0x20);
return 1;
}

View file

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