Skip to content

Commit 498d8cf

Browse files
committed
more verbose panic log
1 parent 78d4385 commit 498d8cf

9 files changed

Lines changed: 104 additions & 44 deletions

File tree

boot/boot.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ gfxi:
3333
mov es, ax
3434
mov di, 0x7E00
3535
mov ax, 0x4F01
36-
mov cx, 0x11B
36+
mov cx, 0x111
3737
int 0x10
3838
pop es
3939
popa
@@ -46,7 +46,7 @@ gfxe:
4646
mov es, ax
4747
mov di, 0x7E00
4848
mov ax, 0x4F02
49-
mov bx, 0x11B | 0x4000
49+
mov bx, 0x111 | 0x4000
5050
int 0x10
5151
pop es
5252
popa

kernel/core/hwi.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdint.h>
2+
#include "hwi.h"
3+
#include "../drivers/tty.h"
4+
5+
void cpuident() {
6+
char brand[49];
7+
uint32_t *b = (uint32_t*)brand;
8+
for (uint32_t i = 0; i < 3; i++) {
9+
uint32_t eax, ebx, ecx, edx;
10+
asm volatile(
11+
"cpuid"
12+
: "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
13+
: "a"(0x80000002 + i)
14+
);
15+
b[i*4 + 0] = eax;
16+
b[i*4 + 1] = ebx;
17+
b[i*4 + 2] = ecx;
18+
b[i*4 + 3] = edx;
19+
}
20+
brand[48] = '\0';
21+
tty_puts(brand);
22+
tty_putc('\n');
23+
}

kernel/core/hwi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#pragma once
2+
void cpuident(void);

kernel/core/init.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This is the first part of the kernel ran when the kernel actually starts executi
1414
#include "../int/interrupts.h"
1515
#include "log.h"
1616
#include "../lib/io.h"
17+
#include "hwi.h"
1718
void tirq0(void) {
1819
/* Reduced to 10 for faster boot */
1920
klog("running IRQ0 (timer) test.\n");
@@ -27,26 +28,6 @@ void tirq0(void) {
2728
klog("10 ticks elapsed\n");
2829
}
2930

30-
void cpuident() {
31-
char brand[49];
32-
uint32_t *b = (uint32_t*)brand;
33-
for (uint32_t i = 0; i < 3; i++) {
34-
uint32_t eax, ebx, ecx, edx;
35-
asm volatile(
36-
"cpuid"
37-
: "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
38-
: "a"(0x80000002 + i)
39-
);
40-
b[i*4 + 0] = eax;
41-
b[i*4 + 1] = ebx;
42-
b[i*4 + 2] = ecx;
43-
b[i*4 + 3] = edx;
44-
}
45-
brand[48] = '\0';
46-
klog("cpu: ");
47-
tty_puts(brand);
48-
tty_putc('\n');
49-
}
5031

5132
static inline uint32_t syscall3(uint32_t num, uint32_t arg1, uint32_t arg2, uint32_t arg3) {
5233
uint32_t ret;
@@ -61,6 +42,7 @@ static inline uint32_t syscall3(uint32_t num, uint32_t arg1, uint32_t arg2, uint
6142

6243
void kmain(unsigned char *vbe){
6344
tty_init(vbe);
45+
tty_putc('\n');
6446
klog(" - system44 v");
6547
puts(infoKernelVersion);
6648
puts(" (");
@@ -69,9 +51,17 @@ void kmain(unsigned char *vbe){
6951
pitsetfreq(1000);
7052
int_init();
7153
asm volatile("sti");
54+
klog("cpu: ");
7255
cpuident();
7356
mmp();
7457
pmm_init();
7558
kfs_mount();
59+
fbcstr(190,240,"STATUS UPDATE", 0xFFFFFFF, FONT_BASIC8X8);
60+
fbcstr(190,260,"MACHINE ID: V1", 0xFFFFFF, FONT_BASIC8X8);
61+
fbcstr(190,270,"LOCATION: APPROACHING HELL", 0xFFFFFF, FONT_BASIC8X8);
62+
fbcstr(190,280,"CURRENT OBJECTIVE: FIND A WEAPON", 0xFFFFFF, FONT_BASIC8X8);
63+
fbcstr(190,300,"MANKIND IS DEAD", 0xFF0000, FONT_BASIC8X8);
64+
fbcstr(190,310,"BLOOD IS FUEL", 0xFF0000, FONT_BASIC8X8);
65+
fbcstr(190,320,"HELL IS FULL", 0xFF0000, FONT_BASIC8X8);
7666
sh();
7767
}

kernel/core/log.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ static void ts(void) {
1717
uint32_t t = ticks;
1818
uint32_t sec = t / 1000;
1919
uint32_t ms = t % 1000;
20-
char buf[32];
20+
char buf[33];
2121
int pos = 0;
22+
buf[pos++] = ' ';
2223
buf[pos++] = '[';
2324
buf[pos++] = ' ';
2425
buf[pos++] = '\t';

kernel/core/panic.c

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,48 @@
11
/* Do CPUs dream of eternal halting? */
22

3-
43
#include "../drivers/tty.h"
5-
void panic(const char *msg) {
6-
tty_puts("\n\npanic: ");
7-
tty_puts(msg);
8-
tty_puts("\n");
9-
asm volatile ("cli");
10-
for (;;) {
11-
asm volatile ("hlt");
4+
#include <stdint.h>
5+
#include "log.h"
6+
#include "hwi.h"
7+
#include "version.h"
8+
typedef struct {
9+
uint32_t eax, ebx, ecx, edx;
10+
uint32_t esi, edi, ebp, esp;
11+
uint32_t eip, cs, eflags;
12+
} cpu_regs_t;
13+
14+
static void puthex(uint32_t val) {
15+
const char hex[] = "0123456789ABCDEF";
16+
char buf[9];
17+
for (int i = 0; i < 8; i++) {
18+
buf[7-i] = hex[val & 0xF];
19+
val >>= 4;
1220
}
21+
buf[8] = 0;
22+
tty_puts(buf);
23+
}
24+
25+
void panic(const char *msg, cpu_regs_t *r) {
26+
tty_puts("\n ----- oops! -----\n\n Kernel: ");
27+
tty_puts(infoKernelVersion);
28+
tty_puts("\n CPU: ");
29+
cpuident();
30+
tty_puts("\n EAX="); puthex(r->eax);tty_putc(' ');
31+
tty_puts("EBX="); puthex(r->ebx);tty_putc(' ');
32+
tty_puts("ECX="); puthex(r->ecx);tty_putc(' ');
33+
tty_putc('\n');
34+
tty_puts(" EDX="); puthex(r->edx);tty_putc(' ');
35+
tty_puts("ESI="); puthex(r->esi);tty_putc(' ');
36+
tty_puts("EDI="); puthex(r->edi);tty_putc(' ');
37+
tty_putc('\n');
38+
tty_puts(" EBP="); puthex(r->ebp);tty_putc(' ');
39+
tty_puts("ESP="); puthex(r->esp);tty_putc(' ');
40+
tty_puts("EIP="); puthex(r->eip);tty_putc(' ');
41+
tty_putc('\n');
42+
tty_puts(" CS="); puthex(r->cs);tty_putc(' ');
43+
tty_puts("EFLAGS="); puthex(r->eflags);
44+
tty_puts("\n\n panic: ");
45+
tty_puts(msg);
46+
asm volatile("cli");
47+
for (;;) asm volatile("hlt");
1348
}

kernel/drivers/fbcon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void fbcputchar(uint16_t px, uint16_t py, char c, uint32_t color, font_t font){
3333
void fbcstr(uint16_t x, uint16_t y, const char *s, uint32_t color, font_t font){
3434
while(*s){
3535
fbcputchar(x, y, *s, color, font);
36-
x += 8;
36+
x += 6;
3737
s++;
3838
}
3939
}

kernel/drivers/fonts/basic8x8

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -687,14 +687,14 @@ static const fontentry_t basic8x8[] = {
687687
"...#.....",
688688
".........",
689689
"........."}},
690-
{' ', {"#########",
691-
"#########",
692-
"#########",
693-
"#########",
694-
"#########",
695-
"#########",
696-
"#########",
697-
"#########"}},
690+
{' ', {".........",
691+
".........",
692+
".........",
693+
".........",
694+
".........",
695+
".........",
696+
".........",
697+
"........."}},
698698
{'$', {"..#......",
699699
".####....",
700700
"#.#......",
@@ -743,4 +743,13 @@ static const fontentry_t basic8x8[] = {
743743
"..#......",
744744
"..#......",
745745
"..#......"}},
746-
};
746+
{'\b', {"#########",
747+
"#########",
748+
"#########",
749+
"#########",
750+
"#########",
751+
"#########",
752+
"#########",
753+
"#########"}},
754+
755+
};

kernel/drivers/tty.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ void tty_init(u8 *vbe) {
1010

1111
void tty_putc(char c) {
1212
int colour = 0xFFFFFFFF;
13-
fbcputchar(cx, cy, ' ', BGC, FONT_BASIC8X8);
13+
fbcputchar(cx, cy, '\b', BGC, FONT_BASIC8X8);
1414
fbcputchar(cx+CHAR_W, cy, '_', colour, FONT_BASIC8X8);
1515
switch (c) {
1616
case '\n':
17-
fbcputchar(cx+CHAR_W, cy, ' ', BGC, FONT_BASIC8X8);
17+
fbcputchar(cx+CHAR_W, cy, '\b', BGC, FONT_BASIC8X8);
1818
cx = 0;
1919
cy += CHAR_H;
2020
if (cy >= SCREEN_HEIGHT) cy = 0;
2121
return;
2222
case '\b':
23-
fbcputchar(cx+CHAR_W, cy, ' ', BGC, FONT_BASIC8X8);
23+
fbcputchar(cx+CHAR_W, cy, '\b', BGC, FONT_BASIC8X8);
2424
if (cx >= CHAR_W) {
2525
cx -= CHAR_W;
2626
} else if (cy >= CHAR_H) {

0 commit comments

Comments
 (0)