Add ports files and add use ANSI C.
This commit is contained in:
23
kernel/ports.c
Normal file
23
kernel/ports.c
Normal file
@ -0,0 +1,23 @@
|
||||
unsigned char port_byte_in(unsigned char port) {
|
||||
unsigned char res;
|
||||
/*
|
||||
* `"=a" (res)' means: put result of `al' into `res' variable
|
||||
* `"d" (port)' means: load `port' into `dx'.
|
||||
*/
|
||||
__asm__("in %%dx, %%al" : "=a" (res) : "d" (port));
|
||||
return res;
|
||||
}
|
||||
|
||||
void port_byte_out(unsigned char port, unsigned char data) {
|
||||
__asm__("out %%al, %%dx" : : "a" (data), "d" (port));
|
||||
}
|
||||
|
||||
unsigned short port_word_in(unsigned short port) {
|
||||
unsigned short res;
|
||||
__asm__("in %%dx, %%ax" : "=a" (res) : "d" (port));
|
||||
return res;
|
||||
}
|
||||
|
||||
void port_word_out(unsigned short port, unsigned short data) {
|
||||
__asm__("out %%ax, %%dx" : : "a" (data), "d" (port));
|
||||
}
|
18
kernel/ports.h
Normal file
18
kernel/ports.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* return a byte from a port.
|
||||
*/
|
||||
unsigned char port_byte_in(unsigned char port);
|
||||
/*
|
||||
* write a byte of data to a port.
|
||||
*/
|
||||
void port_byte_out(unsigned char port, unsigned char data);
|
||||
/*
|
||||
* return a word of data from a port.
|
||||
*/
|
||||
unsigned short port_word_in(unsigned short port);
|
||||
/*
|
||||
* write a word of data to a port.
|
||||
*/
|
||||
void port_word_out(unsigned short port, unsigned short data);
|
Reference in New Issue
Block a user