mirror of
https://github.com/cfenollosa/os-tutorial.git
synced 2025-12-18 04:44:35 +03:00
Lesson 18
This commit is contained in:
@@ -1 +0,0 @@
|
||||
../../16-video-driver/drivers/ports.c
|
||||
35
17-video-scroll/drivers/ports.c
Normal file
35
17-video-scroll/drivers/ports.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Read a byte from the specified port
|
||||
*/
|
||||
unsigned char port_byte_in (unsigned short port) {
|
||||
unsigned char result;
|
||||
/* Inline assembler syntax
|
||||
* !! Notice how the source and destination registers are switched from NASM !!
|
||||
*
|
||||
* '"=a" (result)'; set '=' the C variable '(result)' to the value of register e'a'x
|
||||
* '"d" (port)': map the C variable '(port)' into e'd'x register
|
||||
*
|
||||
* Inputs and outputs are separated by colons
|
||||
*/
|
||||
__asm__("in %%dx, %%al" : "=a" (result) : "d" (port));
|
||||
return result;
|
||||
}
|
||||
|
||||
void port_byte_out (unsigned short port, unsigned char data) {
|
||||
/* Notice how here both registers are mapped to C variables and
|
||||
* nothing is returned, thus, no equals '=' in the asm syntax
|
||||
* However we see a comma since there are two variables in the input area
|
||||
* and none in the 'return' area
|
||||
*/
|
||||
__asm__("out %%al, %%dx" : : "a" (data), "d" (port));
|
||||
}
|
||||
|
||||
unsigned short port_word_in (unsigned short port) {
|
||||
unsigned short result;
|
||||
__asm__("in %%dx, %%ax" : "=a" (result) : "d" (port));
|
||||
return result;
|
||||
}
|
||||
|
||||
void port_word_out (unsigned short port, unsigned short data) {
|
||||
__asm__("out %%ax, %%dx" : : "a" (data), "d" (port));
|
||||
}
|
||||
Reference in New Issue
Block a user