extracted assembly wrappers into src/x86_64/asm.c
This commit is contained in:
parent
ec82655698
commit
0d395aa899
4 changed files with 41 additions and 14 deletions
1
Makefile
1
Makefile
|
|
@ -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
11
include/asm.h
Normal 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
27
src/x86_64/asm.c
Normal 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));
|
||||||
|
}
|
||||||
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue