add vorgabe04
This commit is contained in:
@ -4,6 +4,8 @@
|
||||
* *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Implementierung einer Abstraktion fuer den Prozessor. *
|
||||
* Derzeit wird nur angeboten, Interrupts zuzulassen, zu *
|
||||
* verbieten oder den Prozessor anzuhalten. *
|
||||
* *
|
||||
* Autor: Michael Schoettner, 30.7.16 *
|
||||
*****************************************************************************/
|
||||
@ -18,6 +20,23 @@ private:
|
||||
|
||||
public:
|
||||
CPU() {}
|
||||
|
||||
// Erlauben von (Hardware-)Interrupts
|
||||
inline void enable_int () {
|
||||
asm volatile ( "sti" );
|
||||
}
|
||||
|
||||
// Interrupts werden ignoriert/verboten
|
||||
inline void disable_int () {
|
||||
asm volatile ( "cli" );
|
||||
}
|
||||
|
||||
// Prozessor bis zum naechsten Interrupt anhalten
|
||||
inline void idle () {
|
||||
asm volatile ( "sti;"
|
||||
"hlt"
|
||||
);
|
||||
}
|
||||
|
||||
// Prozessor anhalten
|
||||
inline void halt () {
|
||||
@ -25,6 +44,7 @@ public:
|
||||
"hlt"
|
||||
);
|
||||
}
|
||||
|
||||
// Time-Stamp-Counter auslesen
|
||||
inline unsigned long long int rdtsc() {
|
||||
unsigned long long int ret;
|
||||
|
||||
6
c_os/kernel/Globals.cc
Executable file → Normal file
6
c_os/kernel/Globals.cc
Executable file → Normal file
@ -14,7 +14,9 @@ CPU cpu; // CPU-spezifische Funktionen
|
||||
PCSPK pcspk; // PC-Lautsprecher
|
||||
CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
||||
Keyboard kb; // Tastatur
|
||||
IntDispatcher intdis; // Unterbrechungsverteilung
|
||||
PIC pic; // Interrupt-Controller
|
||||
unsigned int total_mem; // RAM total
|
||||
// BumpAllocator allocator;
|
||||
// LinkedListAllocator allocator;
|
||||
// BumpAllocator allocator;
|
||||
// LinkedListAllocator allocator;
|
||||
TreeAllocator allocator;
|
||||
|
||||
9
c_os/kernel/Globals.h
Executable file → Normal file
9
c_os/kernel/Globals.h
Executable file → Normal file
@ -15,16 +15,19 @@
|
||||
#include "devices/PCSPK.h"
|
||||
#include "kernel/allocator/BumpAllocator.h"
|
||||
#include "kernel/allocator/LinkedListAllocator.h"
|
||||
#include "kernel/allocator/TreeAllocator.h"
|
||||
#include "kernel/CPU.h"
|
||||
#include "kernel/interrupts/IntDispatcher.h"
|
||||
#include "kernel/interrupts/PIC.h"
|
||||
|
||||
extern CPU cpu; // CPU-spezifische Funktionen
|
||||
extern PCSPK pcspk; // PC-Lautsprecher
|
||||
extern CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
||||
extern Keyboard kb; // Tastatur
|
||||
extern IntDispatcher intdis; // Unterbrechungsverteilung
|
||||
extern PIC pic; // Interrupt-Controller
|
||||
extern unsigned int total_mem; // RAM total
|
||||
// extern BumpAllocator allocator;
|
||||
// extern LinkedListAllocator allocator;
|
||||
// extern BumpAllocator allocator;
|
||||
// extern LinkedListAllocator allocator;
|
||||
extern TreeAllocator allocator;
|
||||
|
||||
#endif
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#define BASIC_ALIGN 8
|
||||
|
||||
// NOTE: I added this file
|
||||
// NOTE: I can't imagine that this is very fast with all the tree logic?
|
||||
|
||||
typedef struct list_block {
|
||||
// Doubly linked list for every block
|
||||
@ -15,11 +16,10 @@ typedef struct list_block {
|
||||
struct list_block* previous;
|
||||
} list_block_t;
|
||||
|
||||
// Format eines freien Blocks
|
||||
// The free blocks are organized in a red-black tree to enable fast insertion with best-fit strategy.
|
||||
// To allow fast merging of freed blocks every block is part of a doubly linked list.
|
||||
// Because the red-black tree only contains the free blocks, the memory overhead comes
|
||||
// down to only 4 + 4 + 4 Bytes for the allocated flag, next and previous pointers.
|
||||
// down to 4 + 4 + 4 Bytes for the allocated flag, next and previous pointers.
|
||||
// The size can be calculated by using the next pointer so it doesn't have to be stored.
|
||||
typedef struct tree_block {
|
||||
// Doubly linked list for every block
|
||||
|
||||
27
c_os/kernel/interrupts/ISR.h
Executable file
27
c_os/kernel/interrupts/ISR.h
Executable file
@ -0,0 +1,27 @@
|
||||
/*****************************************************************************
|
||||
* *
|
||||
* I S R *
|
||||
* *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Interrupt Service Routine. Jeweils ein Objekt pro ISR. *
|
||||
* Erlaubt es einen Kontext mit Variablen fuer die Unter- *
|
||||
* brechungsroutine bereitzustellen. *
|
||||
* *
|
||||
* Autor: Michael Schoettner, 06.04.20 *
|
||||
*****************************************************************************/
|
||||
#ifndef __ISR_include__
|
||||
#define __ISR_include__
|
||||
|
||||
class ISR {
|
||||
|
||||
private:
|
||||
ISR (const ISR ©); // Verhindere Kopieren
|
||||
|
||||
public:
|
||||
ISR () {}
|
||||
|
||||
// Unterbrechungsbehandlungsroutine
|
||||
virtual void trigger () = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -8,11 +8,78 @@
|
||||
* Interrupts an. Wenn eine Interrupt Service Routine *
|
||||
* registriert ist, wird diese aufgerufen. *
|
||||
* *
|
||||
* Autor: Michael Schoettner, 30.7.16 *
|
||||
* Autor: Michael Schoettner, 31.8.2016 *
|
||||
*****************************************************************************/
|
||||
#include "kernel/CPU.h"
|
||||
#include "kernel/Globals.h"
|
||||
#include "kernel/interrupts/IntDispatcher.h"
|
||||
|
||||
extern "C" void int_disp(unsigned int slot);
|
||||
|
||||
// Low-Level Interrupt-Behandlung. (Die Funktion wird spaeter noch erweitert)
|
||||
void int_disp(unsigned int slot) {
|
||||
extern "C" void int_disp (unsigned int slot);
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Prozedur: int_disp *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Low-Level Interrupt-Behandlung. *
|
||||
* Diese Funktion ist in der IDT fuer alle Eintraege einge- *
|
||||
* tragen. Dies geschieht bereits im Bootloader. *
|
||||
* Sie wird also fuer alle Interrupts aufgerufen. Von hier *
|
||||
* aus sollen die passenden ISR-Routinen der Treiber-Objekte*
|
||||
* mithilfe von 'IntDispatcher::report' aufgerufen werden. *
|
||||
* Parameter: *
|
||||
* vector: Vektor-Nummer der Unterbrechung *
|
||||
*****************************************************************************/
|
||||
void int_disp (unsigned int vector) {
|
||||
|
||||
/* hier muss Code eingefuegt werden */
|
||||
|
||||
kout << "Ein Interrupt ist aufgetreten" << slot << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Konstruktor: IntDispatcher::IntDispatcher *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Initialisierung der ISR map mit einer Default-ISR. *
|
||||
*****************************************************************************/
|
||||
IntDispatcher::IntDispatcher () {
|
||||
for (unsigned int slot=0; slot<size; slot++)
|
||||
map[slot] = 0;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: IntDispatcher::assign *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Registrierung einer ISR. *
|
||||
* *
|
||||
* Parameter: *
|
||||
* vector: Vektor-Nummer der Unterbrechung *
|
||||
* isr: ISR die registriert werden soll *
|
||||
* *
|
||||
* Rueckgabewert: 0 = Erfolg, -1 = Fehler *
|
||||
*****************************************************************************/
|
||||
int IntDispatcher::assign (unsigned int vector, ISR& isr) {
|
||||
|
||||
/* hier muss Code eingefuegt werden */
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: IntDispatcher::report *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Eingetragene ISR ausfuehren. *
|
||||
* *
|
||||
* Parameter: *
|
||||
* vector: Gesuchtes ISR-Objekt fuer diese Vektor-Nummer. *
|
||||
* *
|
||||
* Rueckgabewert: 0 = ISR wurde aufgerufen, -1 = unbekannte Vektor-Nummer *
|
||||
*****************************************************************************/
|
||||
int IntDispatcher::report (unsigned int vector) {
|
||||
|
||||
/* hier muss Code eingefuegt werden */
|
||||
|
||||
}
|
||||
|
||||
45
c_os/kernel/interrupts/IntDispatcher.h
Executable file
45
c_os/kernel/interrupts/IntDispatcher.h
Executable file
@ -0,0 +1,45 @@
|
||||
/*****************************************************************************
|
||||
* *
|
||||
* I N T D I S P A T C H E R *
|
||||
* *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Zentrale Unterbrechungsbehandlungsroutine des Systems. *
|
||||
* Der Parameter gibt die Nummer des aufgetretenen *
|
||||
* Interrupts an. Wenn eine Interrupt Service Routine (ISR) *
|
||||
* in der Map registriert ist, so wird diese aufgerufen. *
|
||||
* *
|
||||
* Autor: Michael Schoettner, 30.7.16 *
|
||||
*****************************************************************************/
|
||||
#ifndef __IntDispatcher_include__
|
||||
#define __IntDispatcher_include__
|
||||
|
||||
#include "kernel/ISR.h"
|
||||
|
||||
|
||||
class IntDispatcher {
|
||||
|
||||
private:
|
||||
IntDispatcher(const IntDispatcher ©); // Verhindere Kopieren
|
||||
|
||||
enum { size = 256 };
|
||||
ISR* map[size];
|
||||
|
||||
public:
|
||||
// Vektor-Nummern
|
||||
enum {
|
||||
timer = 32,
|
||||
keyboard = 33
|
||||
};
|
||||
|
||||
// Initialisierung der ISR map mit einer Default-ISR.
|
||||
IntDispatcher ();
|
||||
|
||||
// Registrierung einer ISR. (Rueckgabewert: 0 = Erfolg, -1 = Fehler)
|
||||
int assign (unsigned int vector, ISR& gate);
|
||||
|
||||
// ISR fuer 'vector' ausfuehren
|
||||
int report (unsigned int vector);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
73
c_os/kernel/interrupts/PIC.cc
Executable file
73
c_os/kernel/interrupts/PIC.cc
Executable file
@ -0,0 +1,73 @@
|
||||
/*****************************************************************************
|
||||
* *
|
||||
* P I C *
|
||||
* *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Mit Hilfe des PICs koennen Hardware-Interrupts (IRQs) *
|
||||
* einzeln zugelassen oder unterdrueckt werden. Auf diese *
|
||||
* Weise wird also bestimmt, ob die Unterbrechung eines *
|
||||
* Geraetes ueberhaupt an den Prozessor weitergegeben wird. *
|
||||
* Selbst dann erfolgt eine Aktivierung der Unterbrechungs- *
|
||||
* routine nur, wenn der Prozessor bereit ist, auf Unter- *
|
||||
* brechungen zu reagieren. Dies kann mit Hilfe der Klasse *
|
||||
* CPU festgelegt werden. *
|
||||
* *
|
||||
* Autor: Olaf Spinczyk, TU Dortmund *
|
||||
*****************************************************************************/
|
||||
|
||||
#include "kernel/PIC.h"
|
||||
#include "kernel/IOport.h"
|
||||
|
||||
|
||||
static IOport IMR1 (0x21); // interrupt mask register von PIC 1
|
||||
static IOport IMR2 (0xa1); // interrupt mask register von PIC 2
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: PIC::allow *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Sorgt dafuer, dass der uebergebene IRQ ab sofort durch *
|
||||
* den PIC an den Prozessor weitergereicht wird. Um eine *
|
||||
* Unterbrechungsbehandlung zu ermoeglichen, muss *
|
||||
* zusaetzlich CPU::enable_int() aufgerufen werden. *
|
||||
* *
|
||||
* Parameter: *
|
||||
* irq: IRQ der erlaubt werden soll *
|
||||
*****************************************************************************/
|
||||
void PIC::allow (int irq) {
|
||||
|
||||
/* hier muss Code eingefuegt werden */
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: PIC::forbid *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Unterdrueckt mit Hilfe des PICs einen bestimmten IRQ. *
|
||||
* *
|
||||
* Parameter: *
|
||||
* interrupt: IRQ der maskiert werden soll *
|
||||
*****************************************************************************/
|
||||
void PIC::forbid (int irq) {
|
||||
|
||||
/* hier muss Code eingefuegt werden */
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: PIC::status *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Liefert den aktuellen Zustand des Maskierbits eines *
|
||||
* bestimmten IRQs. *
|
||||
* *
|
||||
* Parameter: *
|
||||
* irq: IRQ dessen Status erfragt werden soll *
|
||||
*****************************************************************************/
|
||||
bool PIC::status (int irq) {
|
||||
|
||||
/* hier muss Code eingefuegt werden */
|
||||
|
||||
}
|
||||
|
||||
44
c_os/kernel/interrupts/PIC.h
Executable file
44
c_os/kernel/interrupts/PIC.h
Executable file
@ -0,0 +1,44 @@
|
||||
/*****************************************************************************
|
||||
* *
|
||||
* P I C *
|
||||
* *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Mit Hilfe des PICs koennen Hardware-Interrupts (IRQs) *
|
||||
* einzeln zugelassen oder unterdrueckt werden. Auf diese *
|
||||
* Weise wird also bestimmt, ob die Unterbrechung eines *
|
||||
* Geraetes ueberhaupt an den Prozessor weitergegeben wird. *
|
||||
* Selbst dann erfolgt eine Aktivierung der Unterbrechungs- *
|
||||
* routine nur, wenn der Prozessor bereit ist, auf Unter- *
|
||||
* brechungen zu reagieren. Dies kann mit Hilfe der Klasse *
|
||||
* CPU festgelegt werden. *
|
||||
* *
|
||||
* Autor: Olaf Spinczyk, TU Dortmund *
|
||||
*****************************************************************************/
|
||||
#ifndef __PIC_include__
|
||||
#define __PIC_include__
|
||||
|
||||
class PIC {
|
||||
|
||||
private:
|
||||
PIC(const PIC ©); // Verhindere Kopieren
|
||||
public:
|
||||
PIC() {}
|
||||
|
||||
public:
|
||||
// IRQ-Nummern von Geraeten
|
||||
enum {
|
||||
timer = 0, // Programmable Interrupt Timer (PIT)
|
||||
keyboard = 1 // Tastatur
|
||||
};
|
||||
|
||||
// Freischalten der Weiterleitung eines IRQs durch den PIC an die CPU
|
||||
void allow (int irq);
|
||||
|
||||
// Unterdruecken der Weiterleitung eines IRQs durch den PIC an die CPU
|
||||
void forbid (int irq);
|
||||
|
||||
// Abfragen, ob die Weiterleitung fuer einen bestimmten IRQ unterdrueckt ist
|
||||
bool status (int interrupt_device);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user