1
This commit is contained in:
2022-06-23 13:15:23 +02:00
parent ceb17dd2c1
commit 704af6a6fd
4 changed files with 180 additions and 201 deletions

View File

@ -48,9 +48,8 @@
* * * *
* Autor: Michael Schoettner, 20.12.2018 * * Autor: Michael Schoettner, 20.12.2018 *
*****************************************************************************/ *****************************************************************************/
#include "kernel/Globals.h"
#include "kernel/Paging.h" #include "kernel/Paging.h"
#include "kernel/Globals.h"
// Bits fuer Eintraege in der Page-Table // Bits fuer Eintraege in der Page-Table
#define PAGE_PRESENT 0x001 #define PAGE_PRESENT 0x001
@ -68,14 +67,12 @@
#define FST_ALLOCABLE_PAGE 0x202000 #define FST_ALLOCABLE_PAGE 0x202000
#define LST_ALLOCABLE_PAGE 0x2FF000 #define LST_ALLOCABLE_PAGE 0x2FF000
// Externe Funktionen in startup.asm // Externe Funktionen in startup.asm
extern "C" { extern "C" {
void paging_on(unsigned int* p_pdir); // Paging einschalten void paging_on(unsigned int* p_pdir); // Paging einschalten
void invalidate_tlb_entry(unsigned int* ptr); // Page in TLB invalid. void invalidate_tlb_entry(unsigned int* ptr); // Page in TLB invalid.
} }
/***************************************************************************** /*****************************************************************************
* Funktion: pg_alloc_page * * Funktion: pg_alloc_page *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -101,7 +98,6 @@ extern "C" {
return 0; return 0;
} }
/***************************************************************************** /*****************************************************************************
* Funktion: pg_write_protect_page * * Funktion: pg_write_protect_page *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -111,10 +107,8 @@ extern "C" {
void pg_write_protect_page(unsigned int* p_page) { void pg_write_protect_page(unsigned int* p_page) {
/* hier muss Code eingefügt werden */ /* hier muss Code eingefügt werden */
} }
/***************************************************************************** /*****************************************************************************
* Funktion: pg_notpresent_page * * Funktion: pg_notpresent_page *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -123,10 +117,8 @@ void pg_write_protect_page(unsigned int *p_page) {
void pg_notpresent_page(unsigned int* p_page) { void pg_notpresent_page(unsigned int* p_page) {
/* hier muss Code eingefügt werden */ /* hier muss Code eingefügt werden */
} }
/***************************************************************************** /*****************************************************************************
* Funktion: pg_free_page * * Funktion: pg_free_page *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -137,7 +129,9 @@ void pg_free_page(unsigned int *p_page) {
int idx = (unsigned int)p_page >> 12; int idx = (unsigned int)p_page >> 12;
// ausserhalb Page ? // ausserhalb Page ?
if (idx < 1 || idx > 1023) return ; if (idx < 1 || idx > 1023) {
return;
}
// Eintrag einlesen und aendern (PAGE_WRITEABLE loeschen) // Eintrag einlesen und aendern (PAGE_WRITEABLE loeschen)
p_page = (unsigned int*)PAGE_TABLE; p_page = (unsigned int*)PAGE_TABLE;
@ -146,7 +140,6 @@ void pg_free_page(unsigned int *p_page) {
*p_page = ((idx << 12) | PAGE_WRITEABLE | PAGE_PRESENT); *p_page = ((idx << 12) | PAGE_WRITEABLE | PAGE_PRESENT);
} }
/***************************************************************************** /*****************************************************************************
* Funktion: pg_init * * Funktion: pg_init *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -168,7 +161,6 @@ void pg_init() {
kout << " total_mem: " << total_mem << endl; kout << " total_mem: " << total_mem << endl;
kout << " #pages: " << total_mem / (4096 * 1024) << endl; kout << " #pages: " << total_mem / (4096 * 1024) << endl;
// //
// Aufbau des Page-Directory // Aufbau des Page-Directory
// //
@ -180,12 +172,12 @@ void pg_init() {
// Eintraege 1-1023: Direktes Mapping (1:1) auf 4 MB Pages (ohne Page-Table) // Eintraege 1-1023: Direktes Mapping (1:1) auf 4 MB Pages (ohne Page-Table)
for (i = 1; i < 1024; i++) { for (i = 1; i < 1024; i++) {
p_pdir++; p_pdir++;
if (i>num_pages) if (i > num_pages) {
*p_pdir = ((i << 22) | PAGE_BIGSIZE); *p_pdir = ((i << 22) | PAGE_BIGSIZE);
else } else {
*p_pdir = ((i << 22) | PAGE_BIGSIZE | PAGE_WRITEABLE | PAGE_PRESENT); *p_pdir = ((i << 22) | PAGE_BIGSIZE | PAGE_WRITEABLE | PAGE_PRESENT);
} }
}
// //
// 1. Page-Table // 1. Page-Table
@ -201,11 +193,12 @@ void pg_init() {
// Seiten unter FST_ALLOCABLE_PAGE reservieren, damit diese nicht // Seiten unter FST_ALLOCABLE_PAGE reservieren, damit diese nicht
// alloziert werden und das System kaputt geht // alloziert werden und das System kaputt geht
if ( (i<<12) >= FST_ALLOCABLE_PAGE) if ((i << 12) >= FST_ALLOCABLE_PAGE) {
*p_page = ((i << 12) | PAGE_WRITEABLE | PAGE_PRESENT); *p_page = ((i << 12) | PAGE_WRITEABLE | PAGE_PRESENT);
else } else {
*p_page = ((i << 12) | PAGE_WRITEABLE | PAGE_PRESENT | PAGE_RESERVED); *p_page = ((i << 12) | PAGE_WRITEABLE | PAGE_PRESENT | PAGE_RESERVED);
} }
}
// Paging aktivieren (in startup.asm) // Paging aktivieren (in startup.asm)
paging_on((unsigned int*)PAGE_DIRECTORY); paging_on((unsigned int*)PAGE_DIRECTORY);

View File

@ -68,5 +68,3 @@ extern void pg_notpresent_page(unsigned int *p_page);
extern void pg_free_page(unsigned int* p_page); extern void pg_free_page(unsigned int* p_page);
#endif #endif

View File

@ -9,9 +9,8 @@
* * * *
* Autor: Michael Schoettner, 11.12.2018 * * Autor: Michael Schoettner, 11.12.2018 *
*****************************************************************************/ *****************************************************************************/
#include "kernel/Globals.h"
#include "devices/CGA.h" #include "devices/CGA.h"
#include "kernel/Globals.h"
// in startup.asm // in startup.asm
extern "C" { extern "C" {
@ -48,42 +47,39 @@ extern "C" {
// |-------------| <-- int_esp // |-------------| <-- int_esp
void get_int_esp(unsigned int** esp); void get_int_esp(unsigned int** esp);
} }
void break_on_bluescreen() { void break_on_bluescreen() {
/* wenn auf diese Methode ein breakpoint in GDB gesetzt wird /* wenn auf diese Methode ein breakpoint in GDB gesetzt wird
so kann man sich mithilfe des Hex-Dumps umsehen so kann man sich mithilfe des Hex-Dumps umsehen
*/ */
} }
// Cursor-Position // Cursor-Position
int bs_xpos = 0; int bs_xpos = 0;
int bs_ypos = 0; int bs_ypos = 0;
/***************************************************************************** /*****************************************************************************
* Funktion: bs_clear * * Funktion: bs_clear *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Bildschirm loeschen. * * Beschreibung: Bildschirm loeschen. *
*****************************************************************************/ *****************************************************************************/
void bs_clear() { void bs_clear() {
unsigned int x,y; unsigned int x;
unsigned int y;
unsigned short* ptr = (unsigned short*)0xb8000; unsigned short* ptr = (unsigned short*)0xb8000;
for (x = 0; x < 80; x++) { for (x = 0; x < 80; x++) {
for (y=0; y<25; y++) for (y = 0; y < 25; y++) {
*(ptr + y * 80 + x) = (short)0x1F00; *(ptr + y * 80 + x) = (short)0x1F00;
} }
}
bs_xpos = 0; bs_xpos = 0;
bs_ypos = 0; bs_ypos = 0;
} }
/***************************************************************************** /*****************************************************************************
* Funktion: bs_lf * * Funktion: bs_lf *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -94,7 +90,6 @@ void bs_lf() {
bs_xpos = 0; bs_xpos = 0;
} }
/***************************************************************************** /*****************************************************************************
* Funktion: bs_print_char * * Funktion: bs_print_char *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -107,7 +102,6 @@ void bs_print_char(char c) {
bs_xpos++; bs_xpos++;
} }
/***************************************************************************** /*****************************************************************************
* Funktion: bs_print_string * * Funktion: bs_print_string *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -121,17 +115,18 @@ void bs_print_string(char *str) {
} }
} }
/***************************************************************************** /*****************************************************************************
* Funktion: bs_printHexDigit * * Funktion: bs_printHexDigit *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Ein Hex-Zeichen ausgeben. * * Beschreibung: Ein Hex-Zeichen ausgeben. *
*****************************************************************************/ *****************************************************************************/
void bs_printHexDigit(int c) { void bs_printHexDigit(int c) {
if (c<10) bs_print_char('0'+(unsigned char)c); if (c < 10) {
else bs_print_char('A'+(unsigned char)(c-10)); bs_print_char('0' + (unsigned char)c);
} else {
bs_print_char('A' + (unsigned char)(c - 10));
}
} }
/***************************************************************************** /*****************************************************************************
* Funktion: bs_print_uintHex * * Funktion: bs_print_uintHex *
@ -144,7 +139,6 @@ void bs_print_uintHex(unsigned int c) {
} }
} }
/***************************************************************************** /*****************************************************************************
* Funktion: bs_printReg * * Funktion: bs_printReg *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -157,7 +151,6 @@ void bs_printReg(char *str, int value) {
bs_print_string(" \0"); bs_print_string(" \0");
} }
/***************************************************************************** /*****************************************************************************
* Funktion: bs_dump * * Funktion: bs_dump *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
@ -169,21 +162,22 @@ void bs_dump (unsigned int exceptionNr) {
unsigned int faultAdress; unsigned int faultAdress;
unsigned int has_error_code = 0; unsigned int has_error_code = 0;
bs_clear(); bs_clear();
bs_print_string("HHUos crashed with Exception\0"); bs_print_string("HHUos crashed with Exception\0");
// Exception mit Error-Code? // Exception mit Error-Code?
if ( (exceptionNr>=8 && exceptionNr<=14) || exceptionNr==17 || exceptionNr==30) if ((exceptionNr >= 8 && exceptionNr <= 14) || exceptionNr == 17 || exceptionNr == 30) {
has_error_code = 1; has_error_code = 1;
}
// Liegt ein Page-Fault vor? // Liegt ein Page-Fault vor?
if (exceptionNr == 14) { if (exceptionNr == 14) {
faultAdress = get_page_fault_address(); faultAdress = get_page_fault_address();
// Zugriff auf Seite 0 ? -> Null-Ptr. Exception // Zugriff auf Seite 0 ? -> Null-Ptr. Exception
if ((faultAdress & 0xFFFFF000) == 0) if ((faultAdress & 0xFFFFF000) == 0) {
exceptionNr = 0x1B; exceptionNr = 0x1B;
} }
}
bs_print_uintHex(exceptionNr); bs_print_uintHex(exceptionNr);
bs_print_string(" (\0"); bs_print_string(" (\0");
@ -210,7 +204,8 @@ void bs_dump (unsigned int exceptionNr) {
case 0x1F: bs_print_string("Stack overflow\0"); break; case 0x1F: bs_print_string("Stack overflow\0"); break;
default: bs_print_string("unknown\0"); default: bs_print_string("unknown\0");
} }
bs_print_string(")\0"); bs_lf(); bs_print_string(")\0");
bs_lf();
// Zeiger auf int_esp ueber startup.asm beschaffen (Stack-Layout siehe Anfang dieser Datei) // Zeiger auf int_esp ueber startup.asm beschaffen (Stack-Layout siehe Anfang dieser Datei)
get_int_esp(&int_esp); get_int_esp(&int_esp);
@ -229,7 +224,6 @@ void bs_dump (unsigned int exceptionNr) {
bs_printReg(" CS=\0", *(sptr + 9 + has_error_code)); bs_printReg(" CS=\0", *(sptr + 9 + has_error_code));
bs_lf(); bs_lf();
// verbleibende nicht-fluechtige Register ausgeben // verbleibende nicht-fluechtige Register ausgeben
bs_printReg("EBX=\0", *(sptr + 4)); bs_printReg("EBX=\0", *(sptr + 4));
bs_printReg("ESI=\0", *(sptr + 1)); bs_printReg("ESI=\0", *(sptr + 1));
@ -243,7 +237,6 @@ void bs_dump (unsigned int exceptionNr) {
bs_printReg("EFL=\0", *(sptr + 10)); bs_printReg("EFL=\0", *(sptr + 10));
bs_lf(); bs_lf();
// Pagefault oder Null-Pointer? // Pagefault oder Null-Pointer?
if (exceptionNr == 14 || exceptionNr == 0x1B) { if (exceptionNr == 14 || exceptionNr == 0x1B) {
bs_lf(); bs_lf();
@ -264,20 +257,16 @@ void bs_dump (unsigned int exceptionNr) {
if (exceptionNr == 14) { if (exceptionNr == 14) {
if (error_nr == 3) { if (error_nr == 3) {
bs_print_string("Error: write access to read-only page.\0"); bs_print_string("Error: write access to read-only page.\0");
} } else if (error_nr == 2) {
else if (error_nr==2) {
bs_print_string("Error: read access to not-present page.\0"); bs_print_string("Error: read access to not-present page.\0");
} } else if (error_nr == 0) {
else if (error_nr==0) {
bs_print_string("Error: access to a not-present page.\0"); bs_print_string("Error: access to a not-present page.\0");
} } else {
else {
bs_print_string("Error code = \0"); bs_print_string("Error code = \0");
bs_print_uintHex(error_nr); bs_print_uintHex(error_nr);
} }
bs_lf(); bs_lf();
} } else {
else {
bs_print_string("Error code = \0"); bs_print_string("Error code = \0");
bs_print_uintHex(error_nr); bs_print_uintHex(error_nr);
bs_lf(); bs_lf();
@ -286,7 +275,8 @@ void bs_dump (unsigned int exceptionNr) {
// Calling stack ... // Calling stack ...
bs_lf(); bs_lf();
bs_print_string("Calling Stack:\0"); bs_lf(); bs_print_string("Calling Stack:\0");
bs_lf();
int x = 0; int x = 0;
unsigned int* ebp = (unsigned int*)*(sptr + 2); unsigned int* ebp = (unsigned int*)*(sptr + 2);
unsigned int raddr; unsigned int raddr;
@ -295,7 +285,8 @@ void bs_dump (unsigned int exceptionNr) {
while (*ebp > 0x100000 && *ebp < 0x8000000 && x < 10) { while (*ebp > 0x100000 && *ebp < 0x8000000 && x < 10) {
raddr = *(ebp + 1); raddr = *(ebp + 1);
bs_printReg(" raddr=\0", raddr ); bs_lf(); bs_printReg(" raddr=\0", raddr);
bs_lf();
// dynamische Kette -> zum Aufrufer // dynamische Kette -> zum Aufrufer
ebp = (unsigned int*)*ebp; ebp = (unsigned int*)*ebp;
@ -303,7 +294,8 @@ void bs_dump (unsigned int exceptionNr) {
x++; x++;
} }
if (x == 0) { if (x == 0) {
bs_print_string(" empty\0"); bs_lf(); bs_print_string(" empty\0");
bs_lf();
} }
bs_lf(); bs_lf();
@ -312,5 +304,3 @@ void bs_dump (unsigned int exceptionNr) {
bs_print_string("System halted\0"); bs_print_string("System halted\0");
} }

View File

@ -17,5 +17,3 @@
void bs_dump(unsigned int exceptionNr); void bs_dump(unsigned int exceptionNr);
#endif #endif