Clean up folders

This commit is contained in:
Fergal Moran
2020-06-09 00:49:30 +01:00
parent 4bbb3c6d1d
commit 2a31559cd9
25 changed files with 207 additions and 153 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@
*.bin
vm/
*.iso
obj

View File

@@ -1,13 +1,26 @@
GPPPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wall -Wextra
GCCPARAMS = -m32 -Iinclude -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wall -Wextra
ASPARAMS = --32
LDPARAMS = -melf_i386
objs = stdio.o loader.o gdt.o driver.o port.o interruptstubs.o interrupts.o keyboard.o echokeyboardhandler.o blockmousehandler.o mouse.o kernel.o
objs = obj/common/stdio.o \
obj/loader.o \
obj/gdt.o \
obj/drivers/driver.o \
obj/hardware/port.o \
obj/hardware/interrupts.o \
obj/drivers/keyboard.o \
obj/drivers/echokeyboardhandler.o \
obj/drivers/blockmousehandler.o \
obj/drivers/mouse.o \
obj/interruptstubs.o \
obj/kernel.o
%.o: src/%.cpp
g++ $(GPPPARAMS) -o $@ -c $<
obj/%.o: src/%.cpp
mkdir -p $(@D)
gcc $(GCCPARAMS) -c -o $@ $<
%.o: src/%.s
obj/%.o: src/%.s
mkdir -p $(@D)
as $(ASPARAMS) -o $@ $<
ferglos.bin: linker.ld $(objs)
@@ -34,5 +47,6 @@ run: ferglos.iso
run-qemu: ferglos.iso
qemu-system-i386 -boot d -cdrom ferglos.iso -m 512
.PHONY: clean
clean:
rm -rfv $(objects) iso *.iso *.o *.bin
rm -rfv obj iso *.iso *.o *.bin

View File

@@ -1,14 +0,0 @@
#ifndef __BLOCKMOUSEHANDLER_H
#define __BLOCKMOUSEHANDLER_H
#include "mouse.h"
#include "stdio.h"
class BlockMouseHandler : public MouseEventHandler {
private:
int8_t _screenX, _screenY;
public:
BlockMouseHandler();
virtual void OnMouseMove(int xoffset, int yoffset);
};
#endif

View File

@@ -1,10 +1,12 @@
#ifndef __STDIO_H
#define __STDIO_H
#include "types.h"
#ifndef __FERGLOS_COMMON_STDIO_H
#define __FERGLOS_COMMON_STDIO_H
#include <common/types.h>
namespace ferglos {
namespace common {
void printf(const char* str);
void wprintf(const wchar_t* str);
void printfHex(uint8_t key);
void clear();
} // namespace common
} // namespace ferglos
#endif

View File

@@ -1,14 +1,7 @@
/*
* types.h
* Author: Fergal Moran
* Copyright: 2020 Fergal Moran
*
* BSD License - do what you want
*/
#ifndef __TYPES_H
#define __TYPES_H
#ifndef __FERGLOS_COMMON_TYPES_H
#define __FERGLOS_COMMON_TYPES_H
namespace ferglos {
namespace common {
typedef char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
@@ -17,5 +10,6 @@ typedef int int32_t;
typedef unsigned int uint32_t;
typedef long long int int64_t;
typedef unsigned long long int uint64_t;
#endif
} // namespace common
} // namespace ferglos
#endif

View File

@@ -0,0 +1,20 @@
#ifndef __FERGLOS_DRIVERS_BLOCKMOUSEHANDLER_H
#define __FERGLOS_DRIVERS_BLOCKMOUSEHANDLER_H
#include <common/stdio.h>
#include <drivers/mouse.h>
using namespace ferglos::common;
namespace ferglos {
namespace drivers {
class BlockMouseHandler : public MouseEventHandler {
private:
int8_t _screenX, _screenY;
public:
BlockMouseHandler();
virtual void OnMouseMove(int xoffset, int yoffset);
};
} // namespace drivers
} // namespace ferglos
#endif

View File

@@ -1,5 +1,7 @@
#ifndef __DRIVER_H
#define __DRIVER_H
#ifndef __FERGLOS_DRIVERS_DRIVER_H
#define __FERGLOS_DRIVERS_DRIVER_H
namespace ferglos {
namespace drivers {
class Driver {
public:
Driver();
@@ -22,4 +24,6 @@ class DriverManager {
void ActivateAll();
};
} // namespace drivers
} // namespace ferglos
#endif

View File

@@ -0,0 +1,15 @@
#ifndef __FERGLOS_DRIVERS_ECHOKEYBOARDHANDLER_H
#define __FERGLOS_DRIVERS_ECHOKEYBOARDHANDLER_H
#include <common/stdio.h>
#include <drivers/keyboard.h>
namespace ferglos {
namespace drivers {
class EchoKeyboardHandler : public KeyboardEventHandler {
public:
virtual void OnKeyDown(const wchar_t* key);
};
} // namespace drivers
} // namespace ferglos
#endif

View File

@@ -1,10 +1,16 @@
#ifndef __KEYBOARD_H
#define __KEYBOARD_H
#ifndef __FERGLOS_DRIVERS_KEYBOARD_H
#define __FERGLOS_DRIVERS_KEYBOARD_H
#include <common/stdio.h>
#include <common/types.h>
#include <drivers/driver.h>
#include <hardware/interrupts.h>
#include <hardware/port.h>
#include "driver.h"
#include "interrupts.h"
#include "port.h"
#include "types.h"
using namespace ferglos::common;
using namespace ferglos::hardware;
namespace ferglos {
namespace drivers {
class KeyboardEventHandler {
public:
@@ -27,4 +33,6 @@ class KeyboardDriver : public InterruptHandler, public Driver {
virtual uint32_t HandleInterrupt(uint32_t esp);
virtual void Activate();
};
} // namespace drivers
} // namespace ferglos
#endif

View File

@@ -1,10 +1,15 @@
#ifndef __MOUSE_H
#define __MOUSE_H
#ifndef __FERGLOS_DRIVERS_MOUSE_H
#define __FERGLOS_DRIVERS_MOUSE_H
#include "driver.h"
#include "interrupts.h"
#include "port.h"
#include "types.h"
#include <common/types.h>
#include <drivers/driver.h>
#include <hardware/interrupts.h>
#include <hardware/port.h>
using namespace ferglos::common;
using namespace ferglos::hardware;
namespace ferglos {
namespace drivers {
class MouseEventHandler {
private:
public:
@@ -34,4 +39,6 @@ class MouseDriver : public InterruptHandler, public Driver {
virtual uint32_t HandleInterrupt(uint32_t esp);
virtual void Activate();
};
} // namespace drivers
} // namespace ferglos
#endif

View File

@@ -1,10 +0,0 @@
#ifndef __ECHOKEYBOARDHANDLER_H
#define __ECHOKEYBOARDHANDLER_H
#include "keyboard.h"
#include "stdio.h"
class EchoKeyboardHandler : public KeyboardEventHandler {
public:
virtual void OnKeyDown(const wchar_t* key);
};
#endif

View File

@@ -1,15 +1,9 @@
/*
* gdt.h
* Author: Fergal Moran
* Copyright: 2020 Fergal Moran
*
* BSD License - do what you want
*/
#ifndef __GDT_H
#define __GDT_H
#include "types.h"
#ifndef __FERGLOS_GDT_H
#define __FERGLOS_GDT_H
#include <common/types.h>
using namespace ferglos::common;
namespace ferglos {
/*
The Global Descriptor Table (GDT) is a data structure used by Intel x86-family processors
starting with the 80286 in order to define the characteristics of the various memory areas
@@ -50,5 +44,5 @@ class GlobalDescriptorTable {
uint16_t CodeSegmentSelector();
uint16_t DataSegmentSelector();
};
} // namespace ferglos
#endif

View File

@@ -1,9 +1,14 @@
#ifndef __INTERRUPTS_H
#define __INTERRUPTS_H
#include "gdt.h"
#include "port.h"
#include "types.h"
#ifndef __FERGLOS_HARDWARE_INTERRUPTS_H
#define __FERGLOS_HARDWARE_INTERRUPTS_H
#include <common/types.h>
#include <gdt.h>
#include <hardware/port.h>
using namespace ferglos::drivers;
namespace ferglos {
namespace hardware {
class InterruptManager;
class InterruptHandler {
protected:
@@ -61,7 +66,7 @@ class InterruptManager {
void Activate();
void Deactivate();
static uint32_t HandleInterrupt(uint8_t interruptNumber, uint32_t esp);
static uint32_t HandleInterrupt(uint8_t interrupt, uint32_t esp);
uint32_t DoHandleInterrupt(uint8_t interruptNumber, uint32_t esp);
static void IgnoreInterruptRequest();
@@ -69,4 +74,6 @@ class InterruptManager {
static void HandleInterruptRequest0x01();
static void HandleInterruptRequest0x0C();
};
} // namespace hardware
} // namespace ferglos
#endif

View File

@@ -1,14 +1,11 @@
/*
* port.h
* Author: Fergal Moran
* Copyright: 2020 Fergal Moran
*
* BSD License - do what you want
*/
#ifndef __PORT_H
#define __PORT_H
#ifndef __FERGLOS_HARDWARE_PORT_H
#define __FERGLOS_HARDWARE_PORT_H
#include "types.h"
#include <common/types.h>
using namespace ferglos::common;
namespace ferglos {
namespace drivers {
class Port {
protected:
@@ -51,5 +48,6 @@ class Port32Bit : public Port {
virtual void Write(uint32_t data);
virtual uint32_t Read();
};
} // namespace drivers
} // namespace ferglos
#endif

View File

@@ -1,6 +1,9 @@
#include "../include/stdio.h"
#include <common/stdio.h>
#include <common/types.h>
using namespace ferglos::common;
#include "../include/types.h"
namespace ferglos {
namespace common {
extern uint8_t x = 0, y = 0;
void printf(const char* str) {
@@ -68,4 +71,6 @@ void clear() {
VideoMemory[80 * y + x] = (VideoMemory[80 * y + x] & 0xFF00) | ' ';
}
}
}
}
} // namespace common
} // namespace ferglos

View File

@@ -1,7 +1,6 @@
#include "../include/blockmousehandler.h"
#include "stdio.h"
#include <drivers/blockmousehandler.h>
namespace ferglos {
namespace drivers {
BlockMouseHandler::BlockMouseHandler() {
//flip bit in center of screen - so mousepointer is initially here
static uint16_t* VideoMemory = (uint16_t*)0xb8000;
@@ -44,3 +43,5 @@ void BlockMouseHandler::OnMouseMove(int xoffset, int yoffset) {
((VideoMemory[80 * _screenY + _screenX] & 0x0F00) << 4) |
((VideoMemory[80 * _screenY + _screenX] & 0x00FF));
}
} // namespace drivers
} // namespace ferglos

View File

@@ -1,5 +1,6 @@
#include "../include/driver.h"
#include <drivers/driver.h>
namespace ferglos {
namespace drivers {
Driver::Driver() {}
Driver::~Driver() {}
@@ -21,3 +22,5 @@ void DriverManager::ActivateAll() {
_drivers[i]->Activate();
}
}
} // namespace drivers
} // namespace ferglos

View File

@@ -1,7 +1,10 @@
#include "../include/echokeyboardhandler.h"
#include <drivers/echokeyboardhandler.h>
namespace ferglos {
namespace drivers {
void EchoKeyboardHandler::OnKeyDown(const wchar_t* key) {
wchar_t* foo = (wchar_t*)" ";
foo = (wchar_t*)key;
wprintf(foo);
}
} // namespace drivers
} // namespace ferglos

View File

@@ -1,7 +1,7 @@
#include "../include/keyboard.h"
#include "../include/stdio.h"
#include <common/stdio.h>
#include <drivers/keyboard.h>
namespace ferglos {
namespace drivers {
KeyboardEventHandler::KeyboardEventHandler() {}
void KeyboardEventHandler::OnKeyDown(const wchar_t* /*key*/) {}
@@ -189,4 +189,6 @@ uint32_t KeyboardDriver::HandleInterrupt(uint32_t esp) {
}
return esp;
}
}
} // namespace drivers
} // namespace ferglos

View File

@@ -1,7 +1,7 @@
#include "../include/mouse.h"
#include "../include/stdio.h"
#include <common/stdio.h>
#include <drivers/mouse.h>
namespace ferglos {
namespace drivers {
MouseEventHandler::MouseEventHandler() {}
void MouseEventHandler::OnActivate() {}
@@ -64,4 +64,6 @@ uint32_t MouseDriver::HandleInterrupt(uint32_t esp) {
_buttons = _buffer[0];
}
return esp;
}
}
} // namespace drivers
} // namespace ferglos

View File

@@ -1,13 +1,6 @@
/*
* gdt.cpp
* Author: Fergal Moran
* Copyright: 2020 Fergal Moran
*
* BSD License - do what you want
*/
#include "../include/gdt.h"
#include <gdt.h>
using namespace ferglos::common;
namespace ferglos {
GlobalDescriptorTable::GlobalDescriptorTable() : nullSegmentSelector(0, 0, 0),
unusedSegmentSelector(0, 0, 0),
codeSegmentSelector(0, 64 * 1024 * 1024, 0x9A),
@@ -76,3 +69,4 @@ uint32_t GlobalDescriptorTable::SegmentDescriptor::Limit() {
}
return result;
}
}

View File

@@ -1,6 +1,8 @@
#include "../include/interrupts.h"
#include <common/stdio.h>
#include <hardware/interrupts.h>
#include "../include/stdio.h"
using namespace ferglos::common;
using namespace ferglos::hardware;
InterruptHandler::InterruptHandler(uint8_t interruptNumber, InterruptManager* interruptManager) {
this->_interruptNumber = interruptNumber;
@@ -91,9 +93,9 @@ void InterruptManager::SetInterruptDescriptorTableEntries(
_interruptDescriptorTable[interruptNumber].reserved = 0;
}
uint32_t InterruptManager::HandleInterrupt(uint8_t interruptNumber, uint32_t esp) {
uint32_t InterruptManager::HandleInterrupt(uint8_t interrupt, uint32_t esp) {
if (_activeInterruptManager != 0) {
return _activeInterruptManager->DoHandleInterrupt(interruptNumber, esp);
return _activeInterruptManager->DoHandleInterrupt(interrupt, esp);
}
return esp;
}
@@ -114,4 +116,4 @@ uint32_t InterruptManager::DoHandleInterrupt(uint8_t interruptNumber, uint32_t e
}
}
return esp;
}
}

View File

@@ -1,12 +1,8 @@
/*
* port.cpp
* Author: Fergal Moran
* Copyright: 2020 Fergal Moran
*
* BSD License - do what you want
*/
#include "../include/port.h"
#include <hardware/port.h>
using namespace ferglos::common;
namespace ferglos {
namespace drivers {
Port::Port(uint16_t portNumber) {
this->portNumber = portNumber;
}
@@ -68,4 +64,6 @@ uint32_t Port32Bit::Read() {
: "=a"(result)
: "Nd"(portNumber));
return result;
}
}
} // namespace drivers
} // namespace ferglos

View File

@@ -2,20 +2,20 @@
.section .text
.extern _ZN16InterruptManager15HandleInterruptEhj
.global _ZN16InterruptManager22IgnoreInterruptRequestEv
.extern _ZN7ferglos8hardware16InterruptManager15HandleInterruptEhj
.global _ZN7ferglos8hardware16InterruptManager22IgnoreInterruptRequestEv
.macro HandleException num
.global _ZN16InterruptManager16HandleException\num\()Ev
_ZN16InterruptManager16HandleException\num\()Ev:
.global _ZN7ferglos8hardware16InterruptManager16HandleException\num\()Ev
_ZN7ferglos8hardware16InterruptManager16HandleException\num\()Ev:
movb $\num, (interruptnumber)
jmp int_bottom
.endm
.macro HandleInterruptRequest num
.global _ZN16InterruptManager26HandleInterruptRequest\num\()Ev
_ZN16InterruptManager26HandleInterruptRequest\num\()Ev:
.global _ZN7ferglos8hardware16InterruptManager26HandleInterruptRequest\num\()Ev
_ZN7ferglos8hardware16InterruptManager26HandleInterruptRequest\num\()Ev:
movb $\num + IRQ_BASE, (interruptnumber)
jmp int_bottom
.endm
@@ -33,7 +33,7 @@ int_bottom:
pushl %esp
push (interruptnumber)
call _ZN16InterruptManager15HandleInterruptEhj
call _ZN7ferglos8hardware16InterruptManager15HandleInterruptEhj
movl %eax, %esp
popl %gs
@@ -42,7 +42,8 @@ int_bottom:
popl %ds
popa
_ZN16InterruptManager22IgnoreInterruptRequestEv:
.global _ZN7ferglos8hardware16InterruptManager22IgnoreInterruptRequestEv
_ZN7ferglos8hardware16InterruptManager22IgnoreInterruptRequestEv:
iret
.data

View File

@@ -1,12 +1,15 @@
#include "../include/blockmousehandler.h"
#include "../include/driver.h"
#include "../include/echokeyboardhandler.h"
#include "../include/gdt.h"
#include "../include/interrupts.h"
#include "../include/keyboard.h"
#include "../include/mouse.h"
#include "../include/stdio.h"
#include "../include/types.h"
#include <common/stdio.h>
#include <common/types.h>
#include <drivers/blockmousehandler.h>
#include <drivers/driver.h>
#include <drivers/echokeyboardhandler.h>
#include <drivers/keyboard.h>
#include <drivers/mouse.h>
#include <gdt.h>
#include <hardware/interrupts.h>
using namespace ferglos;
using namespace ferglos::hardware;
typedef void (*constructor)();
extern "C" constructor start_ctors;