-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
581 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ dd 32 | |
section .bss | ||
align 16 | ||
stackBottom: | ||
resb 16384 | ||
resb 32768 | ||
stackTop: | ||
|
||
section .text | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <ports.h> | ||
|
||
void ports_byteOut(unsigned short port, unsigned char data){ | ||
asm ("out %%al, %%dx" : : "a" (data), "d"(port)); | ||
return; | ||
} | ||
|
||
void ports_wordOut(unsigned short port, unsigned short data){ | ||
asm ("out %%ax, %%dx" : : "a" (data), "d"(port)); | ||
return; | ||
} | ||
|
||
unsigned char ports_byteIn(unsigned short port){ | ||
unsigned char data; | ||
asm ("in %%dx, %%al" : "=a" (data) : "d"(port)); | ||
return data; | ||
} | ||
|
||
unsigned short ports_wordIn(unsigned short port){ | ||
unsigned char data; | ||
asm ("in %%dx, %%ax" : "=a" (data) : "d"(port)); | ||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <ports.h> | ||
#include <util.h> | ||
#include <console.h> | ||
#include <ps2.h> | ||
|
||
int ps2Port1 = 0; | ||
int ps2Port2 = 0; | ||
|
||
unsigned char ps2_readPort(unsigned short port){ | ||
char status = ports_byteIn(PS2_STATUS); | ||
while(!CHECK_BIT(status, 0)) {status = ports_byteIn(PS2_STATUS);} | ||
char data = ports_byteIn(port); | ||
return data; | ||
} | ||
|
||
void ps2_sendPort(unsigned short port, unsigned char data){ | ||
char status = ports_byteIn(PS2_STATUS); | ||
while(CHECK_BIT(status, 1)) {status = ports_byteIn(PS2_STATUS);} | ||
ports_byteOut(port, data); | ||
return; | ||
} | ||
|
||
int ps2_init(void){ | ||
console_print("INFO: Initalizing PS/2 driver\n"); | ||
|
||
ps2_sendPort(PS2_COMMAND, 0x20); | ||
char configByte = ps2_readPort(PS2_DATA); | ||
|
||
configByte &= ~(1 << 0); | ||
configByte &= ~(1 << 1); | ||
configByte &= ~(1 << 6); | ||
if(CHECK_BIT(configByte, 5)) | ||
//ps2Port2 = 1; | ||
|
||
ps2_sendPort(PS2_COMMAND, 0x60); | ||
ps2_sendPort(PS2_DATA, configByte); | ||
|
||
ps2_sendPort(PS2_COMMAND, 0xAD); | ||
ps2_sendPort(PS2_COMMAND, 0xA7); | ||
|
||
ports_byteIn(PS2_DATA); | ||
|
||
ps2_sendPort(PS2_COMMAND, 0xAA); | ||
if(ps2_readPort(PS2_DATA) != 0x55) | ||
return 0; | ||
|
||
ps2_sendPort(PS2_COMMAND, 0xAB); | ||
if(ps2_readPort(PS2_DATA) == 0x00) | ||
ps2Port1 = 1; | ||
|
||
ps2_sendPort(PS2_COMMAND, 0xA9); | ||
if(ps2_readPort(PS2_DATA) != 0x00) | ||
ps2Port2 = 0; | ||
|
||
if(!ps2Port1) | ||
console_print("WARNING: PS/2 port 1 unavailable for use\n"); | ||
else | ||
console_print("INFO: PS/2 port 1 available for use\n"); | ||
if(!ps2Port2) | ||
console_print("WARNING: PS/2 port 2 unavailable for use\n"); | ||
else | ||
console_print("INFO: PS/2 port 2 available for use\n"); | ||
|
||
console_print("INFO: PS/2 controller successfully initialized\n"); | ||
|
||
return 1; | ||
} |
Oops, something went wrong.