show useful info on kernel crash screen
This commit is contained in:
parent
e4c652f475
commit
f77ac794c4
15
+
Normal file
15
+
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef _CLIPPER_IO_H_
|
||||||
|
#define _CLIPPER_IO_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
inline void outb(uint16_t port, uint8_t val) {
|
||||||
|
asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint8_t peek(void* addr) {
|
||||||
|
uint8_t val;
|
||||||
|
asm volatile ("mov [%addr], %%eax" : : "m"(addr) : "eax");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _CLIPPER_IO_H_
|
|
@ -7,4 +7,9 @@ inline void outb(uint16_t port, uint8_t val) {
|
||||||
asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory");
|
asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline uint8_t peek(void* addr) {
|
||||||
|
uint32_t ret = 3;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _CLIPPER_IO_H_
|
#endif // _CLIPPER_IO_H_
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "internal/havarie.h"
|
#include "internal/havarie.h"
|
||||||
|
|
||||||
#include "internal/text_screen.h"
|
#include "internal/text_screen.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
void capsize() {
|
void capsize() {
|
||||||
print_havarie_msg();
|
print_havarie_msg();
|
||||||
|
@ -11,6 +13,73 @@ void capsize() {
|
||||||
for(;;);
|
for(;;);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
uint8_t peek(void* addr) {
|
||||||
|
uint32_t ret;
|
||||||
|
asm ( "push %%fs\n\t"
|
||||||
|
"mov $0, %%eax\n\t"
|
||||||
|
"mov %%ax, %%fs\n\t"
|
||||||
|
"mov %%fs:(%1), %0\n\t"
|
||||||
|
"pop %%fs"
|
||||||
|
: "=r"(ret) : "r"(addr) );
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void dump_stack(uint8_t col, uint8_t row) {
|
||||||
|
tscursor_set(col, row);
|
||||||
|
tsputs("Stack dump", TEXT_SCREEN_BG_BLACK | TEXT_SCREEN_FG_LIGHT_BLUE);
|
||||||
|
row++;
|
||||||
|
|
||||||
|
tscursor_set(col, row);
|
||||||
|
tsputs(" 0 1 2 3 4 5 6 7 8 9 A B C D E F", TEXT_SCREEN_BG_BLACK | TEXT_SCREEN_FG_GRAY);
|
||||||
|
row++;
|
||||||
|
|
||||||
|
int esp, ebp;
|
||||||
|
asm("mov %%esp, %[esp]\n"
|
||||||
|
"mov %%ebp, %[ebp]\n"
|
||||||
|
: [esp]"=m" (esp), [ebp]"=m" (ebp)
|
||||||
|
);
|
||||||
|
|
||||||
|
int start_address = esp & ~0xF;
|
||||||
|
char tmp[16];
|
||||||
|
for (int table_row = 0; table_row < 16; table_row++) {
|
||||||
|
tscursor_set(col, row);
|
||||||
|
|
||||||
|
itoa(start_address, tmp, 16);
|
||||||
|
size_t len = strlen(tmp);
|
||||||
|
|
||||||
|
char* src = tmp + len - 1;
|
||||||
|
char* dst = tmp + 7;
|
||||||
|
|
||||||
|
if (len < 9) {
|
||||||
|
do {
|
||||||
|
*dst-- = *src--;
|
||||||
|
} while(src >= tmp);
|
||||||
|
|
||||||
|
do {
|
||||||
|
*dst-- = '0';
|
||||||
|
} while (src != dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
tsputs(tmp, TEXT_SCREEN_BG_BLACK | TEXT_SCREEN_FG_GRAY);
|
||||||
|
tsprintf(" ");
|
||||||
|
|
||||||
|
for (int table_col = 0; table_col < 4; table_col++) {
|
||||||
|
uint8_t x = peek((void*)(long)(start_address + 4 * table_col + 0));
|
||||||
|
uint8_t y = peek((void*)(long)(start_address + 4 * table_col + 1));
|
||||||
|
uint8_t z = peek((void*)(long)(start_address + 4 * table_col + 2));
|
||||||
|
uint8_t w = peek((void*)(long)(start_address + 4 * table_col + 3));
|
||||||
|
|
||||||
|
tsprintf("%02x %02x %02x %02x ", x, y, z, w);
|
||||||
|
}
|
||||||
|
|
||||||
|
row++;
|
||||||
|
|
||||||
|
start_address -= 0x10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void print_havarie_msg() {
|
void print_havarie_msg() {
|
||||||
tsclear_screen();
|
tsclear_screen();
|
||||||
tscursor_set(0, 0);
|
tscursor_set(0, 0);
|
||||||
|
@ -30,8 +99,24 @@ void print_havarie_msg() {
|
||||||
[esi]"=m" (esi), [edi]"=m" (edi), [esp]"=m" (esp), [ebp]"=m" (ebp)
|
[esi]"=m" (esi), [edi]"=m" (edi), [esp]"=m" (esp), [ebp]"=m" (ebp)
|
||||||
);
|
);
|
||||||
|
|
||||||
tsprintf("eax=0x%08x\t\tesi=0x%08x\n", eax, esi);
|
tsputs("Registers\n", TEXT_SCREEN_BG_BLACK | TEXT_SCREEN_FG_LIGHT_BLUE);
|
||||||
tsprintf("ebx=0x%08x\t\tedi=0x%08x\n", ebx, edi);
|
tsprintf("eax=0x%08x\nebx=0x%08x\necx=0x%08x\nedx=0x%08x\n\n", eax, ebx, ecx, edx);
|
||||||
tsprintf("ecx=0x%08x\t\tesp=0x%08x\n", ecx, esp);
|
tsprintf("esi=0x%08x\nedi=0x%08x\nesp=0x%08x\nebp=0x%08x\n\n", esi, edi, esp, ebp);
|
||||||
tsprintf("edx=0x%08x\t\tebp=0x%08x\n", edx, ebp);
|
|
||||||
|
short cs, ds, es, ss, fs, gs;
|
||||||
|
asm("mov %%cs, %[cs]\n"
|
||||||
|
"mov %%ds, %[ds]\n"
|
||||||
|
"mov %%es, %[es]\n"
|
||||||
|
"mov %%ss, %[ss]\n"
|
||||||
|
"mov %%fs, %[fs]\n"
|
||||||
|
"mov %%gs, %[gs]\n"
|
||||||
|
: [cs]"=m" (cs), [ds]"=m" (ds), [es]"=m" (es),
|
||||||
|
[ss]"=m" (ss), [fs]"=m" (fs), [gs]"=m" (gs)
|
||||||
|
);
|
||||||
|
|
||||||
|
tsputs("\nSegments\n", TEXT_SCREEN_BG_BLACK | TEXT_SCREEN_FG_LIGHT_BLUE);
|
||||||
|
tsprintf("cs=%08x\nds=%08x\nes=%08x\n\n", cs, ds, es);
|
||||||
|
tsprintf("ss=%08x\nfs=%08x\ngs=%08x\n\n", ss, fs, gs);
|
||||||
|
|
||||||
|
dump_stack(18, 3);
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,8 +121,6 @@ const char* decode_format_specifier_field_width(const char* str, struct printf_f
|
||||||
|
|
||||||
tmp[i] = *str++;
|
tmp[i] = *str++;
|
||||||
}
|
}
|
||||||
tmp[0] = '8';
|
|
||||||
tmp[1] = 0;
|
|
||||||
tmp[i] = '\0';
|
tmp[i] = '\0';
|
||||||
|
|
||||||
data->field_size = atoi(tmp);
|
data->field_size = atoi(tmp);
|
||||||
|
|
Loading…
Reference in a new issue