Fixed the serial driver by checking, whether a serial ports exists.

This commit is contained in:
Morten Delenk 2015-10-17 11:28:06 +02:00
parent 25ee3336c8
commit 54691d34e3
5 changed files with 15 additions and 4 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
*~
mtgos
*.o
*anjuta*

View file

@ -14,7 +14,7 @@ namespace MTGosHAL {
auto getChar() -> char;
auto sendCommand(uint8_t command) -> void;
static auto handleIRQ1(struct cpu_state* cpu) -> void;
bool shift, numlock, caps, scrollock;
bool numlock, caps, scrollock;
public:
Keyboard();
};

View file

@ -17,6 +17,7 @@ namespace MTGosHAL {
uint16_t port;
uint64_t waittimes;
uint64_t transmits;
bool works;
auto isTransmitEmpty() -> int;
auto putChar(char chr) -> void;
auto serial_received() -> int;

View file

@ -63,7 +63,7 @@ namespace MTGosHAL {
//TODO add checking for shift, and so on
debug << "Keyboard interrupt received.\nGot: 0x" << Base::HEXADECIMAL << (int)scancode << " -> 0x" << (int)keycode << ".\n";
}
Keyboard::Keyboard(): shift(false), numlock(true), caps(false), scrollock(false) {
Keyboard::Keyboard(): numlock(true), caps(false), scrollock(false) {
if(!idt.request(0x21, (void(*)(struct cpu_state*))&MTGosHAL::Keyboard::handleIRQ1)) {
debug << "Could not get an handler for IRQ1 (Keyboard)\n";
return;

View file

@ -5,8 +5,17 @@ namespace MTGosHAL {
return inb(port+SERIAL_LSR)&0x20;
}
auto Serial::putChar(char chr) -> void {
while(!isTransmitEmpty())
if(!works)
return;
int tries=65535;
while(!isTransmitEmpty()) {
waittimes++;
tries--;
if(!tries){
works=false;
return;
}
}
outb(port, chr);
transmits++;
}
@ -31,7 +40,7 @@ namespace MTGosHAL {
*this << '\n';
return chr;
}
Serial::Serial() {
Serial::Serial(): works(true) {
uint32_t baud=115200;
port=*((uint16_t*)0x0400);
union {