extracted assembly wrappers into src/x86_64/asm.c

This commit is contained in:
uosfz 2025-01-30 15:27:09 +01:00
parent ec82655698
commit 0d395aa899
Signed by: uosfz
SSH key fingerprint: SHA256:FlktuluyhTQg3jHZNLKwxOOC5hbfrUXM0tz3IA3lGJo
4 changed files with 41 additions and 14 deletions

View file

@ -8,6 +8,7 @@ include config.mk
KERNEL_SOURCES_x86_64 := \ KERNEL_SOURCES_x86_64 := \
src/x86_64/uart.c \ src/x86_64/uart.c \
src/x86_64/mem.c \ src/x86_64/mem.c \
src/x86_64/asm.c \
# end of x86_64 specific kernel sources list # end of x86_64 specific kernel sources list
# Architecture-agnostic kernel sources. # Architecture-agnostic kernel sources.

11
include/asm.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef KARLOS_ASM_H
#define KARLOS_ASM_H
#include <stdint.h>
int inb(int port);
uint32_t inl(int port);
void outb(int port, int value);
void outl(int port, uint32_t value);
#endif

27
src/x86_64/asm.c Normal file
View file

@ -0,0 +1,27 @@
#include "asm.h"
int
inb(int port)
{
unsigned char value;
__asm__ ("inb %%dx" : "=a"(value) : "d"(port));
return value;
}
uint32_t inl(int port) {
uint32_t value;
__asm__ ("inl %%dx" : "=a"(value) : "d"(port));
return value;
}
void
outb(int port, int value)
{
__asm__ ("outb %%dx" :: "d"(port), "a"(value));
}
void
outl(int port, uint32_t value)
{
__asm__ ("outl %%dx" :: "d"(port), "a"(value));
}

View file

@ -1,19 +1,7 @@
#include "asm.h"
#define COM1_BASE_PORT 0x3F8 #define COM1_BASE_PORT 0x3F8
int
inb(int port)
{
unsigned char value;
__asm__ ("inb %%dx" : "=a"(value) : "d"(port));
return value;
}
void
outb(int port, int value)
{
__asm__ ("outb %%dx" :: "d"(port), "a"(value));
}
void void
uart_write_char(char c) uart_write_char(char c)
{ {