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 *
*****************************************************************************/
#include "kernel/Globals.h"
#include "kernel/Paging.h"
#include "kernel/Globals.h"
// Bits fuer Eintraege in der Page-Table
#define PAGE_PRESENT 0x001
@ -68,14 +67,12 @@
#define FST_ALLOCABLE_PAGE 0x202000
#define LST_ALLOCABLE_PAGE 0x2FF000
// Externe Funktionen in startup.asm
extern "C" {
void paging_on(unsigned int* p_pdir); // Paging einschalten
void invalidate_tlb_entry(unsigned int* ptr); // Page in TLB invalid.
}
/*****************************************************************************
* Funktion: pg_alloc_page *
*---------------------------------------------------------------------------*
@ -101,7 +98,6 @@ extern "C" {
return 0;
}
/*****************************************************************************
* Funktion: pg_write_protect_page *
*---------------------------------------------------------------------------*
@ -111,10 +107,8 @@ extern "C" {
void pg_write_protect_page(unsigned int* p_page) {
/* hier muss Code eingefügt werden */
}
/*****************************************************************************
* 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) {
/* hier muss Code eingefügt werden */
}
/*****************************************************************************
* Funktion: pg_free_page *
*---------------------------------------------------------------------------*
@ -137,7 +129,9 @@ void pg_free_page(unsigned int *p_page) {
int idx = (unsigned int)p_page >> 12;
// ausserhalb Page ?
if (idx < 1 || idx > 1023) return ;
if (idx < 1 || idx > 1023) {
return;
}
// Eintrag einlesen und aendern (PAGE_WRITEABLE loeschen)
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);
}
/*****************************************************************************
* Funktion: pg_init *
*---------------------------------------------------------------------------*
@ -168,7 +161,6 @@ void pg_init() {
kout << " total_mem: " << total_mem << endl;
kout << " #pages: " << total_mem / (4096 * 1024) << endl;
//
// 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)
for (i = 1; i < 1024; i++) {
p_pdir++;
if (i>num_pages)
if (i > num_pages) {
*p_pdir = ((i << 22) | PAGE_BIGSIZE);
else
} else {
*p_pdir = ((i << 22) | PAGE_BIGSIZE | PAGE_WRITEABLE | PAGE_PRESENT);
}
}
//
// 1. Page-Table
@ -201,11 +193,12 @@ void pg_init() {
// Seiten unter FST_ALLOCABLE_PAGE reservieren, damit diese nicht
// 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);
else
} else {
*p_page = ((i << 12) | PAGE_WRITEABLE | PAGE_PRESENT | PAGE_RESERVED);
}
}
// Paging aktivieren (in startup.asm)
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);
#endif

View File

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

View File

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