Skip to content

Commit

Permalink
Send early kernel prints (before display setup) to serial console
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed Nov 17, 2016
1 parent ada6df8 commit e26a099
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions makefiles/utils.mk
Expand Up @@ -28,7 +28,7 @@ $(EFIKERN): $(BIN)
$(Q) cp $< $@

launch: $(BIN)
$(QEMU) -kernel $< -smp cores=2,threads=2 -cpu Broadwell
$(QEMU) -kernel $< -smp cores=2,threads=2 -cpu Broadwell -serial stdio

launch-efi: $(EFIKERN) $(EFIBIOS)
$(QEMU) -drive file=fat:$(EFIROOT) -smp cores=2,threads=2 -cpu Broadwell -bios $(EFIBIOS)
$(QEMU) -drive file=fat:$(EFIROOT) -smp cores=2,threads=2 -cpu Broadwell -bios $(EFIBIOS) -serial stdio
1 change: 1 addition & 0 deletions src/boot/x32to64.s
Expand Up @@ -220,6 +220,7 @@ x64_entry:
call reloc_vtables
call static_init
call _ZN9Pagetable4initEv
call _ZN7Display5setupEv
mov %rsp, %rbp
jmp main

Expand Down
31 changes: 24 additions & 7 deletions src/kernlib/display.cpp
Expand Up @@ -37,6 +37,20 @@ class EFIDisplay: public Display {
void clean();
};

class SerialDisplay: public Display {
public:
SerialDisplay() {
// TODO: setup serial
}
void write(const char *str) {
char c;
while ((c = *str++) != 0) {
outportb(0x3F8, c);
}
}
void clean() {}
};

char *const ConsoleDisplay::base = reinterpret_cast<char*>(0xB8000);
char *const ConsoleDisplay::top = reinterpret_cast<char*>(0xB8FA0);
const size_t ConsoleDisplay::size = ConsoleDisplay::top - ConsoleDisplay::base;
Expand Down Expand Up @@ -127,20 +141,23 @@ void EFIDisplay::write(const char *str) {
mutex.release();
}

static ConsoleDisplay sharedConsole;
Display *Display::instance = Display::initInstance();
static SerialDisplay serialConsole;
Display *Display::instance = &serialConsole;
Mutex Display::instanceMutex;

Display *Display::initInstance() {
if (EFI::getSystemTable()) return new EFIDisplay();
return &sharedConsole;
void Display::setup() {
if (instance != &serialConsole) return;
if (EFI::getSystemTable()) {
instance = new EFIDisplay();
} else {
instance = new ConsoleDisplay();
}
}

Display *Display::getInstance() {
if (instance) return instance;
instanceMutex.lock();
if (!instance)
instance = initInstance();
if (!instance) setup();
instanceMutex.release();
return instance;
}
Expand Down
2 changes: 1 addition & 1 deletion src/kernlib/include/kernlib/display.hpp
Expand Up @@ -21,8 +21,8 @@
class Display {
private:
static Mutex instanceMutex;
static Display *initInstance();
static Display *instance;
static void setup();
protected:
Mutex mutex;
public:
Expand Down

0 comments on commit e26a099

Please sign in to comment.