From 54691d34e3f23ec7b59f9c980c037394f3464044 Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Sat, 17 Oct 2015 11:28:06 +0200 Subject: [PATCH] Fixed the serial driver by checking, whether a serial ports exists. --- .gitignore | 1 + kernel/hal/x86/include/keyboard.hpp | 2 +- kernel/hal/x86/include/serial.hpp | 1 + kernel/hal/x86/io/keyboard.cpp | 2 +- kernel/hal/x86/io/serial.cpp | 13 +++++++++++-- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 1e70c5f..455ee4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *~ mtgos *.o +*anjuta* diff --git a/kernel/hal/x86/include/keyboard.hpp b/kernel/hal/x86/include/keyboard.hpp index 6c03f6a..6267224 100644 --- a/kernel/hal/x86/include/keyboard.hpp +++ b/kernel/hal/x86/include/keyboard.hpp @@ -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(); }; diff --git a/kernel/hal/x86/include/serial.hpp b/kernel/hal/x86/include/serial.hpp index fb8c28b..71399c6 100644 --- a/kernel/hal/x86/include/serial.hpp +++ b/kernel/hal/x86/include/serial.hpp @@ -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; diff --git a/kernel/hal/x86/io/keyboard.cpp b/kernel/hal/x86/io/keyboard.cpp index 7a52a22..de6260e 100644 --- a/kernel/hal/x86/io/keyboard.cpp +++ b/kernel/hal/x86/io/keyboard.cpp @@ -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; diff --git a/kernel/hal/x86/io/serial.cpp b/kernel/hal/x86/io/serial.cpp index bf17c23..b17d41d 100644 --- a/kernel/hal/x86/io/serial.cpp +++ b/kernel/hal/x86/io/serial.cpp @@ -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 {