Skip to content

Commit 15dffe9

Browse files
committed
kernel: Prettify logs
1 parent 74afaa6 commit 15dffe9

File tree

8 files changed

+78
-30
lines changed

8 files changed

+78
-30
lines changed

kernel/boot/gdt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <logger.h>
12
#include "boot/gdt.h"
23

34
gdt_entry_t gdt[GDT_SIZE];
@@ -25,6 +26,8 @@ void gdt_set_entry(uint32_t offset, uint32_t base, uint32_t limit,
2526

2627
void gdt_init(void)
2728
{
29+
klog_status_init(LOG_DEBUG, "GDT");
30+
2831
/* first entry is NULL entry */
2932
gdt_set_entry(0, 0, 0, 0);
3033

@@ -42,4 +45,6 @@ void gdt_init(void)
4245

4346
gdt_load(gdt, GDT_SIZE * sizeof(gdt_entry_t) - 1);
4447
reload_segments();
48+
49+
klog_status_ok(LOG_DEBUG);
4550
}

kernel/boot/multiboot.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,34 @@
44

55
static inline void multiboot_dump_mmap(multiboot_info_t *info)
66
{
7+
#ifdef DEBUG
78
if (info->flags & MULTIBOOT_FLAG_MEM_MAP) {
89
klog(LOG_DEBUG, "mem map len : 0x%x\n", info->mmap_len);
910
klog(LOG_DEBUG, "mem map addr : 0x%x\n", info->mmap_addr);
1011

1112
int i = 0;
13+
klog(LOG_DEBUG, LOG_HRULE);
1214
klog(LOG_DEBUG, " | size | base | length | type\n");
13-
klog(LOG_DEBUG, "------------------------------------------------------------------\n");
15+
klog(LOG_DEBUG, LOG_HRULE);
1416
FOREACH_MEMORY_MAP(mmap, info) {
1517
klog(LOG_DEBUG, " %d | 0x%x | 0x%x %x | 0x%x %x | %d\n",
1618
i, mmap->size, mmap->base_addr_high, mmap->base_addr_low,
1719
mmap->len_high, mmap->len_low, mmap->type);
1820
i++;
1921
}
22+
klog(LOG_DEBUG, LOG_HRULE);
2023
} else {
2124
klog(LOG_WARN, "memory map not set\n");
2225
}
26+
#endif
2327
}
2428

25-
void multiboot_dump_info(multiboot_info_t *info)
29+
inline void multiboot_dump_info(multiboot_info_t *info)
2630
{
27-
#ifndef DEBUG
28-
return;
29-
#endif
30-
klog(LOG_DEBUG, "------------ MULTIBOOT DUMP ------------\n");
31+
#ifdef DEBUG
32+
klog(LOG_DEBUG, LOG_HRULE);
33+
klog(LOG_DEBUG, "MULTIBOOT DUMP START\n");
34+
klog(LOG_DEBUG, LOG_HRULE);
3135
klog(LOG_DEBUG, "multiboot header: 0x%x\n", info);
3236
klog(LOG_DEBUG, "flags : 0x%x\n", info->flags);
3337
klog(LOG_DEBUG, "mem lower : 0x%x\n", info->mem_lower);
@@ -39,5 +43,9 @@ void multiboot_dump_info(multiboot_info_t *info)
3943
multiboot_dump_mmap(info);
4044
klog(LOG_DEBUG, "config table : 0x%x\n", info->config_table);
4145
klog(LOG_DEBUG, "bootloader name : %s\n", info->bootloader_name);
42-
klog(LOG_DEBUG, "----------------------------------------\n");
46+
klog(LOG_DEBUG, LOG_HRULE);
47+
klog(LOG_DEBUG, "MULTIBOOT DUMP END\n");
48+
klog(LOG_DEBUG, LOG_HRULE);
49+
klog(LOG_DEBUG, "\n");
50+
#endif
4351
}

kernel/include/logger.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,34 @@
88
# define LOG_INFO 2
99
# define LOG_DEBUG 3
1010

11+
# define LOG_HRULE \
12+
"------------------------------------------------------------------------\n"
13+
1114
# ifdef DEBUG
1215
# include<kio.h>
16+
1317
# define klog(LOG_LEVEL, FORMAT, ...) \
1418
keprintf(LOG_LEVEL, FORMAT, ##__VA_ARGS__)
19+
20+
# define klog_status_init(LOG_LEVEL, INIT_STRING) \
21+
keprintf(LOG_LEVEL, "Initializing %s...", INIT_STRING)
22+
23+
# ifdef DEBUG_TO_SERIAL
24+
# define STATUS_FORMAT_STRING "%s\n"
25+
# else
26+
# define STATUS_FORMAT_STRING "\n%c%c%c%c%c%c%s", 8, 8, 8, 8, 8, 8
27+
# endif
28+
# define klog_status_ok(LOG_LEVEL) \
29+
keprintf(LOG_LEVEL, STATUS_FORMAT_STRING, " [OK]");
30+
31+
# define klog_status_fail(LOG_LEVEL) \
32+
keprintf(LOG_LEVEL, STATUS_FORMAT_STRING, "[FAIL]");
33+
1534
# else
1635
# define klog(...)
36+
# define klog_status_init(...)
37+
# define klog_status_ok(...)
38+
# define klog_status_fail(...)
1739
# endif /* end of DEBUG */
1840

1941
#endif /* end of include guard: DEBUG_H_IEXU6FAG */

kernel/interrupt/interrupt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <logger.h>
2+
#include <types.h>
13
#include "interrupt/interrupt.h"
24
#include "io/portio/portio.h"
35

@@ -18,8 +20,10 @@ void isr_set_double_fault(void)
1820

1921
void isr_init_keyboard(void)
2022
{
23+
klog_status_init(LOG_DEBUG, "keyboard");
2124
/* TODO: This will disable all other interrupts; prevent that */
2225
write_port(0x21, 0xfd);
26+
klog_status_ok(LOG_DEBUG);
2327
}
2428

2529
idt_t idt[IDT_SIZE];
@@ -36,6 +40,8 @@ void idt_set_gate(int offset, uint32_t base, uint16_t selector,
3640

3741
void idt_init(void)
3842
{
43+
klog_status_init(LOG_DEBUG, "IDT");
44+
3945
uint32_t idt_address = (uint32_t)&idt;
4046
idt_ptr_t idt_pointer = {
4147
.limit = (sizeof(idt_t) * IDT_SIZE) - 1,
@@ -65,4 +71,6 @@ void idt_init(void)
6571
write_port(PIC2_DATA, 0xff);
6672

6773
idt_load(&idt_pointer);
74+
75+
klog_status_ok(LOG_DEBUG);
6876
}

kernel/io/serial/serial.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <logger.h>
12
#include <io.h>
23
#include <stdarg.h>
34
#include "io/serial/serial.h"
@@ -9,7 +10,7 @@
910
#define MAX_BUFFER_SIZE 1024
1011
static char buffer[MAX_BUFFER_SIZE];
1112

12-
void serial_init(int port)
13+
static inline void serial_init_port(int port)
1314
{
1415
write_port(port + 1, 0x00); // Disable all interrupts
1516
write_port(port + 3, 0x80); // Enable DLAB (set baud rate divisor)
@@ -20,6 +21,18 @@ void serial_init(int port)
2021
write_port(port + 4, 0x0B); // IRQs enabled, RTS/DSR set
2122
}
2223

24+
void serial_init()
25+
{
26+
klog_status_init(LOG_DEBUG, "serial ports");
27+
28+
serial_init_port(SERIAL_PORT1);
29+
serial_init_port(SERIAL_PORT2);
30+
serial_init_port(SERIAL_PORT3);
31+
serial_init_port(SERIAL_PORT4);
32+
33+
klog_status_ok(LOG_DEBUG);
34+
}
35+
2336
void serial_write(int port, char *data)
2437
{
2538
while(*data != '\0') {

kernel/io/serial/serial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define SERIAL_PORT3 0x3e8
77
#define SERIAL_PORT4 0x2e8
88

9-
void serial_init (int port);
9+
void serial_init ();
1010
void serial_write (int port, char *data);
1111
int serial_read (int port);
1212

kernel/kernel.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,12 @@ extern void kmain(multiboot_info_t *multiboot_info, uint32_t multiboot_magic)
1616
page_frame_init(multiboot_info);
1717
page_frame_dump_map();
1818

19-
klog(LOG_DEBUG, "\nInitializing Serial ports... ");
20-
serial_init(SERIAL_PORT1);
21-
serial_init(SERIAL_PORT2);
22-
serial_init(SERIAL_PORT3);
23-
serial_init(SERIAL_PORT4);
24-
klog(LOG_DEBUG, "OK");
25-
26-
klog(LOG_DEBUG, "\nInitializing GDT... ");
19+
serial_init();
2720
gdt_init();
28-
klog(LOG_DEBUG, "OK");
29-
30-
klog(LOG_DEBUG, "\nInitializing IDT... ");
3121
idt_init();
32-
klog(LOG_DEBUG, "OK");
33-
34-
klog(LOG_DEBUG, "\nInitializing ISRs... ");
3522
isr_set_keyboard();
3623
isr_set_double_fault();
3724
isr_init_keyboard();
38-
klog(LOG_DEBUG, "OK");
3925

4026
klog(LOG_DEBUG, "\nInitialization complete.\n");
4127
kprintf("\n$ ");

kernel/mm/page_frame.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ int page_frame_init(multiboot_info_t *multiboot_info)
6868
num_frames_bitset_frames =
6969
NUM_OF_A_PER_B(num_frames_bitset_lines, BITSET_LINES_PER_FRAME);
7070

71-
klog(LOG_DEBUG, "Number of frames: %d\n", num_frames);
72-
klog(LOG_DEBUG, "Number of bitset lines: %d\nNumber of bitset pages: %d\n",
73-
num_frames_bitset_lines, num_frames_bitset_frames);
74-
7571
/* mark all free pages */
7672
FOREACH_MEMORY_MAP(mmap, multiboot_info) {
7773
if (mmap->type == MULTIBOOT_MEM_TYPE_FREE) {
@@ -96,10 +92,17 @@ void page_frame_dump_map(void)
9692
{
9793
#ifdef DEBUG
9894
uint32_t *frame = frames_bitset;
99-
klog(LOG_DEBUG, "frames_bitset addr: 0x%x\n", frame);
95+
klog(LOG_DEBUG, LOG_HRULE);
96+
klog(LOG_DEBUG, "PAGE FRAMES MEMORY DUMP START\n");
97+
klog(LOG_DEBUG, LOG_HRULE);
98+
klog(LOG_DEBUG, "Number of frames: %d\n", num_frames);
99+
klog(LOG_DEBUG, "Number of bitset lines: %d\n", num_frames_bitset_lines);
100+
klog(LOG_DEBUG, "Number of bitset pages: %d\n", num_frames_bitset_frames);
101+
klog(LOG_DEBUG, "Frames bitmap at 0x%x\n", frame);
100102
for (int j = 0; j < num_frames_bitset_lines; j++) {
101-
klog(LOG_DEBUG, "\n%x: ", FRAME_NUM_TO_PAGE_ADDR(j * FRAMES_PER_BITSET));
103+
klog(LOG_DEBUG, "\n%x:", FRAME_NUM_TO_PAGE_ADDR(j * FRAMES_PER_BITSET));
102104
for (int k = 0; k < FRAMES_PER_BITSET; k++) {
105+
(k % 4) || klog(LOG_DEBUG, " ");
103106
if (frame[j] & (0x1 << k)) { /* free */
104107
klog(LOG_DEBUG, ".");
105108
} else {
@@ -108,6 +111,9 @@ void page_frame_dump_map(void)
108111
}
109112
}
110113
klog(LOG_DEBUG, "\n");
114+
klog(LOG_DEBUG, LOG_HRULE);
115+
klog(LOG_DEBUG, "PAGE FRAMES MEMORY DUMP END\n");
116+
klog(LOG_DEBUG, LOG_HRULE);
111117
#endif
112118
}
113119

0 commit comments

Comments
 (0)