Skip to content
Snippets Groups Projects
Commit fad1ce08 authored by Christoph Hellwig's avatar Christoph Hellwig
Browse files

simplify the console abstractions

This is the low-level console abstraction and should deal in the
char * hardware format.  The upper layer (debug.cc) already handles
all conversion from std::string and boost formats.
parent e4e06d18
No related branches found
No related tags found
No related merge requests found
...@@ -94,7 +94,7 @@ fs += fs/ramfs/ramfs_vfsops.o \ ...@@ -94,7 +94,7 @@ fs += fs/ramfs/ramfs_vfsops.o \
fs += fs/devfs/devfs_vnops.o \ fs += fs/devfs/devfs_vnops.o \
fs/devfs/device.o fs/devfs/device.o
drivers = drivers/vga.o drivers/console.o drivers/isa-serial.o drivers = drivers/vga.o drivers/isa-serial.o
drivers += $(fs) drivers += $(fs)
drivers += mmu.o drivers += mmu.o
drivers += elf.o drivers += elf.o
......
#include <cstring>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include "drivers/isa-serial.hh" #include "drivers/isa-serial.hh"
...@@ -8,9 +9,13 @@ using namespace std; ...@@ -8,9 +9,13 @@ using namespace std;
Debug* Debug::pinstance = 0; Debug* Debug::pinstance = 0;
void Debug::out(const char* msg, bool lf) { void Debug::out(const char* msg, bool lf)
if (!_console) return; {
(lf)? _console->writeln(msg):_console->write(msg); if (!_console)
return;
_console->write(msg, strlen(msg));
if (lf)
_console->newline();
} }
void debug(const char *msg, bool lf) void debug(const char *msg, bool lf)
......
#include "console.hh"
void Console::write(const boost::format& fmt)
{
return write(fmt.str());
}
void Console::writeln(const boost::format& fmt)
{
return writeln(fmt.str());
}
void Console::write(std::string str)
{
return write(str.c_str());
}
void Console::writeln(std::string str)
{
return writeln(str.c_str());
}
...@@ -6,13 +6,8 @@ ...@@ -6,13 +6,8 @@
class Console { class Console {
public: public:
virtual ~Console() {} virtual ~Console() {}
virtual void write(const char *str) = 0; virtual void write(const char *str, size_t len) = 0;
virtual void newline() = 0; virtual void newline() = 0;
void writeln(const char *str) { write(str); newline(); }
void write(std::string str);
void writeln(std::string str);
void write(const boost::format& fmt);
void writeln(const boost::format& fmt);
}; };
#endif #endif
...@@ -4,12 +4,12 @@ IsaSerialConsole::IsaSerialConsole() { ...@@ -4,12 +4,12 @@ IsaSerialConsole::IsaSerialConsole() {
reset(); reset();
} }
void IsaSerialConsole::write(const char *str) void IsaSerialConsole::write(const char *str, size_t len)
{ {
while (*str) { while (len > 0) {
writeByte(*str++); writeByte(*str++);
len--;
} }
} }
void IsaSerialConsole::writeByte(const char letter) void IsaSerialConsole::writeByte(const char letter)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
class IsaSerialConsole : public Console { class IsaSerialConsole : public Console {
public: public:
IsaSerialConsole(); IsaSerialConsole();
virtual void write(const char *str); virtual void write(const char *str, size_t len);
virtual void newline(); virtual void newline();
private: private:
static const u16 ioport = 0x3f8; static const u16 ioport = 0x3f8;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment