aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-04-15 21:17:41 +0200
committerMarvin Borner2020-04-15 21:17:41 +0200
commite07894d21a0101b10ee6ad851773b725cbb9150d (patch)
tree75631b318a9403395fbb3b40abdade8a475cd30b
parentaa3d1b4689e6dadd982fe1e5ca8af69ca39c617d (diff)
Used macro magic to implement function-based logs
-rwxr-xr-xrun8
-rw-r--r--src/kernel/acpi/acpi.c14
-rw-r--r--src/kernel/fs/ata.c11
-rw-r--r--src/kernel/fs/ata.h2
-rw-r--r--src/kernel/fs/elf.c2
-rw-r--r--src/kernel/fs/ext2/ext2.c14
-rw-r--r--src/kernel/fs/load.c4
-rw-r--r--src/kernel/fs/vfs/vfs.c10
-rw-r--r--src/kernel/graphics/vesa.c10
-rw-r--r--src/kernel/input/ps2/mouse.c4
-rw-r--r--src/kernel/interrupts/isr.c9
-rw-r--r--src/kernel/io/io.c2
-rw-r--r--src/kernel/kernel.c3
-rw-r--r--src/kernel/lib/memory.c6
-rw-r--r--src/kernel/lib/stdio.h4
-rw-r--r--src/kernel/lib/stdio/debug.c23
-rw-r--r--src/kernel/net/rtl8139.c6
-rw-r--r--src/kernel/pci/pci.c2
-rw-r--r--src/kernel/pci/pci.h2
-rw-r--r--src/kernel/smbios/smbios.c2
-rw-r--r--src/kernel/syscall/syscall.c6
-rw-r--r--src/kernel/system.c42
-rw-r--r--src/kernel/system.h36
23 files changed, 106 insertions, 116 deletions
diff --git a/run b/run
index 4a5e4b7..b32fe1c 100755
--- a/run
+++ b/run
@@ -120,9 +120,9 @@ make_build() {
cp ./build/user.bin ./iso/user.bin
cp ./build/font.bin ./iso/font.bin
grub-mkrescue -o ./build/melvix.iso ./iso/
- dd if=/dev/zero of=./build/ext2_hda.img bs=1k count=100000 > /dev/zero
- mkfs -t ext2 -i 1024 -b 1024 -F ./build/ext2_hda.img > /dev/zero
- fdisk ./build/ext2_hda.img <<EOF
+ dd if=/dev/zero of=./build/ext2_hda.img bs=1k count=100000 >/dev/zero
+ mkfs -t ext2 -i 1024 -b 1024 -F ./build/ext2_hda.img >/dev/zero
+ fdisk ./build/ext2_hda.img <<EOF
x
c
10
@@ -148,7 +148,7 @@ EOF
}
make_test() {
- qemu_with_flags -cdrom ./build/melvix.iso -hda ./build/ext2_hda.img -boot d
+ qemu_with_flags -cdrom ./build/melvix.iso -hda ./build/ext2_hda.img -hdb ./build/ext2_hdb.img -hdd ./build/ext2_hdd.img -boot d
}
make_debug() {
diff --git a/src/kernel/acpi/acpi.c b/src/kernel/acpi/acpi.c
index e129a95..8eee5f1 100644
--- a/src/kernel/acpi/acpi.c
+++ b/src/kernel/acpi/acpi.c
@@ -89,15 +89,15 @@ int acpi_enable()
if (i < 300) {
return 0; // Successfully enabled ACPI
} else {
- serial_printf("ACPI couldn't be enabled!");
+ log("ACPI couldn't be enabled!");
return -1; // ACPI couldn't be enabled
}
} else {
- serial_printf("ACPI is not supported!");
+ log("ACPI is not supported!");
return -1; // ACPI is not supported
}
} else {
- serial_printf("ACPI was already enabled!");
+ log("ACPI was already enabled!");
return 0; // ACPI was already enabled
}
}
@@ -166,15 +166,15 @@ int acpi_install()
}
if (memcmp((unsigned int *)*ptr, "HPET", 4) == 0) {
hpet = (struct HPET *)*ptr;
- //serial_printf("%c%c%c%c", hpet->signature[0], hpet->signature[1],
+ //log("%c%c%c%c", hpet->signature[0], hpet->signature[1],
//hpet->signature[2], hpet->signature[3]);
- //serial_printf("%d", hpet->legacy_replacement);
- //serial_printf("%d", hpet->address.address);
+ //log("%d", hpet->legacy_replacement);
+ //log("%d", hpet->address.address);
}
ptr++;
} // Else: no valid FADT present
} else {
- serial_printf("ACPI is not supported!");
+ log("ACPI is not supported!");
}
return success == 1 ? 0 : -1;
diff --git a/src/kernel/fs/ata.c b/src/kernel/fs/ata.c
index 52d1040..952261f 100644
--- a/src/kernel/fs/ata.c
+++ b/src/kernel/fs/ata.c
@@ -3,6 +3,7 @@
#include <kernel/fs/ata.h>
#include <kernel/lib/lib.h>
#include <kernel/lib/stdlib.h>
+#include <kernel/lib/stdio.h>
#include <kernel/memory/alloc.h>
#include <kernel/pci/pci.h>
#include <kernel/interrupts/interrupts.h>
@@ -239,14 +240,14 @@ void ata_device_detect(ata_dev_t *dev, int primary)
outb(dev->command, COMMAND_IDENTIFY);
if (!inb(dev->status)) {
- log("ata_detect_device: device does not exist");
+ log("Device does not exist");
return;
}
uint8_t lba_lo = inb(dev->lba_lo);
uint8_t lba_hi = inb(dev->lba_high);
if (lba_lo != 0 || lba_hi != 0) {
- log("ata_detect_device: not ata device");
+ log("Device is not ata-compatible");
return;
}
uint8_t drq = 0, err = 0;
@@ -255,7 +256,7 @@ void ata_device_detect(ata_dev_t *dev, int primary)
err = inb(dev->status) & STATUS_ERR;
}
if (err) {
- log("ata_detect_device: err when polling");
+ log("Error while polling");
return;
}
@@ -268,6 +269,7 @@ void ata_device_detect(ata_dev_t *dev, int primary)
pci_write_field(ata_device, PCI_COMMAND, pci_command_reg);
}
+ log("Detected drive: %d", dev->drive);
vfs_mount(dev->mountpoint, create_ata_device(dev));
}
@@ -279,7 +281,10 @@ void ata_find(uint32_t device, uint16_t vendor_id, uint16_t device_id, void *ext
void ata_init()
{
+ log("0x%x", ata_device);
pci_scan(&ata_find, -1, &ata_device);
+ serial_printf("0x%x - ", ata_device);
+ log("0x%x", ata_device);
irq_install_handler(32 + 14, ata_handler);
diff --git a/src/kernel/fs/ata.h b/src/kernel/fs/ata.h
index 049f2bf..72ded20 100644
--- a/src/kernel/fs/ata.h
+++ b/src/kernel/fs/ata.h
@@ -116,4 +116,4 @@ void ata_device_detect(ata_dev_t *dev, int primary);
void ata_init();
-#endif
+#endif \ No newline at end of file
diff --git a/src/kernel/fs/elf.c b/src/kernel/fs/elf.c
index 9af3636..b6d90c9 100644
--- a/src/kernel/fs/elf.c
+++ b/src/kernel/fs/elf.c
@@ -14,7 +14,7 @@ int is_elf(char *elf_data)
elf_header_t *header = (elf_header_t *)elf_data;
if (header->ident[0] == 0x7f && header->ident[1] == 'E' && header->ident[2] == 'L' &&
header->ident[3] == 'F') {
- serial_printf("Buffer is valid ELF file!");
+ log("Buffer is valid ELF file!");
return 1;
}
return 0;
diff --git a/src/kernel/fs/ext2/ext2.c b/src/kernel/fs/ext2/ext2.c
index fe45547..5fcc929 100644
--- a/src/kernel/fs/ext2/ext2.c
+++ b/src/kernel/fs/ext2/ext2.c
@@ -769,29 +769,21 @@ void ext2_init(char *device_path, char *mountpoint)
ext2fs->blocks_per_group = ext2fs->sb->blocks_per_group;
ext2fs->inodes_per_group = ext2fs->sb->inodes_per_group;
- ext2fs->total_groups = ext2fs->sb->total_blocks / ext2fs->blocks_per_group; // REMEMBER: Zero Division Exception
- log("9");
+ ext2fs->total_groups = ext2fs->sb->total_blocks /
+ ext2fs->blocks_per_group; // REMEMBER: Zero Division Exception
if (ext2fs->blocks_per_group * ext2fs->total_groups < ext2fs->total_groups)
ext2fs->total_groups++;
- log("10");
ext2fs->bgd_blocks = (ext2fs->total_groups * sizeof(bgd_t)) / ext2fs->block_size;
- log("11");
if (ext2fs->bgd_blocks * ext2fs->block_size < ext2fs->total_groups * sizeof(bgd_t))
ext2fs->bgd_blocks++;
- log("12");
ext2fs->bgds = kcalloc(sizeof(bgd_t), ext2fs->bgd_blocks * ext2fs->block_size);
- log("13");
for (uint32_t i = 0; i < ext2fs->bgd_blocks; i++) {
read_disk_block(ext2fs, 2, (void *)ext2fs->bgds + i * ext2fs->block_size);
}
- log("14");
inode_t *root_inode = kcalloc(sizeof(inode_t), 1);
- log("15");
read_inode_metadata(ext2fs, root_inode, ROOT_INODE_NUMBER);
- log("16");
vfs_mount(mountpoint, get_ext2_root(ext2fs, root_inode));
- log("17");
-}
+} \ No newline at end of file
diff --git a/src/kernel/fs/load.c b/src/kernel/fs/load.c
index ad76c5b..0206401 100644
--- a/src/kernel/fs/load.c
+++ b/src/kernel/fs/load.c
@@ -28,10 +28,10 @@ void load_binaries()
kfree(user_e);
if (font->magic != 0xf0f0f0f0) {
- serial_printf("0x%x: WRONG FONT MAGIC!", font->magic);
+ log("0x%x: WRONG FONT MAGIC!", font->magic);
halt_loop();
}
*/
}
vga_log("Successfully loaded binaries");
-}
+} \ No newline at end of file
diff --git a/src/kernel/fs/vfs/vfs.c b/src/kernel/fs/vfs/vfs.c
index bbc3912..10d3c21 100644
--- a/src/kernel/fs/vfs/vfs.c
+++ b/src/kernel/fs/vfs/vfs.c
@@ -22,7 +22,7 @@ void vfs_db_listdir(char *name)
{
vfs_node_t *n = file_open(name, 0);
if (!n) {
- log("Could not list a directory that does not exist\n");
+ log("Could not list a directory that does not exist");
return;
}
if (!n->listdir)
@@ -35,7 +35,6 @@ void vfs_db_listdir(char *name)
files++;
}
kfree(save);
- log("\n");
}
void print_vfstree_recur(gtreenode_t *node, int parent_offset)
@@ -48,12 +47,11 @@ void print_vfstree_recur(gtreenode_t *node, int parent_offset)
for (int i = 0; i < parent_offset; ++i) {
strcat(tmp, " ");
}
- char *curr = tmp + strlen(tmp);
struct vfs_entry *fnode = (struct vfs_entry *)node->value;
if (fnode->file) {
- log(curr, "%s(0x%x, %s)", fnode->name, (uint32_t)fnode->file, fnode->file->name);
+ log("%s(0x%x, %s)", fnode->name, (uint32_t)fnode->file, fnode->file->name);
} else {
- log(curr, "%s(empty)", fnode->name);
+ log("%s(empty)", fnode->name);
}
log("%s\n", tmp);
len = strlen(fnode->name);
@@ -368,4 +366,4 @@ void vfs_mount(char *path, vfs_node_t *fs_obj)
return;
}
vfs_mount_recur(path + 1, vfs_tree->root, fs_obj);
-} \ No newline at end of file
+}
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c
index 71e8de6..490c8ea 100644
--- a/src/kernel/graphics/vesa.c
+++ b/src/kernel/graphics/vesa.c
@@ -8,7 +8,7 @@
void switch_to_vga()
{
- serial_printf("Force switch to VGA!");
+ log("Force switch to VGA!");
uint16_t *terminal_buffer = (uint16_t *)0xB8000;
char *error = "Melvix does not support this graphics hardware!";
for (size_t i = 0; i < strlen(error); i++)
@@ -119,8 +119,8 @@ void set_optimal_resolution()
continue;
}
- serial_printf("Found mode: (0x%x) %dx%dx%d", *mode, mode_info->width,
- mode_info->height, mode_info->bpp);
+ log("Found mode: (0x%x) %dx%dx%d", *mode, mode_info->width, mode_info->height,
+ mode_info->bpp);
if (mode_info->width > vbe_width ||
(mode_info->width == vbe_width && (mode_info->bpp >> 3) > vbe_bpl)) {
@@ -139,7 +139,7 @@ void set_optimal_resolution()
kfree(video_modes);
if (highest == 0) {
- serial_printf("Mode detection failed!\nTrying common modes...");
+ log("Mode detection failed!\nTrying common modes...");
vga_log("Mode detection failed!");
vga_log("Trying common modes...");
struct vbe_mode_info *mode_info;
@@ -210,7 +210,7 @@ void set_optimal_resolution()
info("Successfully switched to video mode!");
- serial_printf("Using mode: (0x%x) %dx%dx%d", highest, vbe_width, vbe_height, vbe_bpl << 3);
+ log("Using mode: (0x%x) %dx%dx%d", highest, vbe_width, vbe_height, vbe_bpl << 3);
debug("Using mode: %dx%dx%d", vbe_width, vbe_height, vbe_bpl << 3);
}
diff --git a/src/kernel/input/ps2/mouse.c b/src/kernel/input/ps2/mouse.c
index 31002ad..bf3cbf6 100644
--- a/src/kernel/input/ps2/mouse.c
+++ b/src/kernel/input/ps2/mouse.c
@@ -117,7 +117,7 @@ void mouse_install()
mouse_read();
status = (unsigned char)mouse_read();
if (status == 3)
- serial_printf("Scrollwheel support!");
+ log("Scrollwheel support!");
// Activate 4th and 5th mouse buttons
mouse_write(0xF2);
@@ -139,7 +139,7 @@ void mouse_install()
mouse_read();
status = (unsigned char)mouse_read();
if (status == 4)
- serial_printf("4th and 5th mouse button support!");
+ log("4th and 5th mouse button support!");
/* TODO: Fix mouse laggyness
mouse_write(0xE8);
diff --git a/src/kernel/interrupts/isr.c b/src/kernel/interrupts/isr.c
index 61d0fcc..c34d951 100644
--- a/src/kernel/interrupts/isr.c
+++ b/src/kernel/interrupts/isr.c
@@ -110,10 +110,9 @@ void fault_handler(struct regs *r)
uint32_t faulting_address;
asm("mov %%cr2, %0" : "=r"(faulting_address));
- serial_printf(
- "\n[DEBUG]\nEIP: 0x%x\nEAX: 0x%x\nEBX: 0x%x\nECX: 0x%x\nEDX: 0x%x\nESP: 0x%x\nFault addr: 0x%x\nErr flag: 0x%x\nErr code: 0x%x\nINT code: 0x%x\nINT msg: %s",
- r->eip, r->eax, r->ebx, r->ecx, r->edx, r->esp, faulting_address, r->eflags,
- r->err_code, r->int_no, exception_messages[r->int_no]);
+ log("\n[DEBUG]\nEIP: 0x%x\nEAX: 0x%x\nEBX: 0x%x\nECX: 0x%x\nEDX: 0x%x\nESP: 0x%x\nFault addr: 0x%x\nErr flag: 0x%x\nErr code: 0x%x\nINT code: 0x%x\nINT msg: %s",
+ r->eip, r->eax, r->ebx, r->ecx, r->edx, r->esp, faulting_address, r->eflags,
+ r->err_code, r->int_no, exception_messages[r->int_no]);
if (r->int_no <= 32) {
char *message = (char *)exception_messages[r->int_no];
@@ -128,4 +127,4 @@ void fault_handler(struct regs *r)
panic("Unknown Exception");
}
}
-} \ No newline at end of file
+}
diff --git a/src/kernel/io/io.c b/src/kernel/io/io.c
index 1f67c11..803a78a 100644
--- a/src/kernel/io/io.c
+++ b/src/kernel/io/io.c
@@ -74,4 +74,4 @@ void serial_put(char ch)
while (is_transmit_empty() == 0)
;
outb(0x3f8, (uint8_t)ch);
-}
+} \ No newline at end of file
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index f116ab8..e0c4f54 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -50,6 +50,7 @@ void kernel_main(uint32_t magic, multiboot_info_t *grub_header)
network_install();
sti();
+ log("%x", 0x42);
vfs_init();
ata_init();
ext2_init("/dev/hda", "/");
@@ -60,7 +61,7 @@ void kernel_main(uint32_t magic, multiboot_info_t *grub_header)
// Print total memory
info("Total memory found: %dMiB", (memory_get_all() >> 10) + 1);
- serial_printf("Total memory found: %dMiB", (memory_get_all() >> 10) + 1);
+ log("Total memory found: %dMiB", (memory_get_all() >> 10) + 1);
#ifdef INSTALL_MELVIX
panic("Installation isn't supported right now!");
diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c
index 4763ca0..3202691 100644
--- a/src/kernel/lib/memory.c
+++ b/src/kernel/lib/memory.c
@@ -40,10 +40,10 @@ multiboot_info_t *multiboot_header;
void memory_print()
{
if (multiboot_header->flags & MULTIBOOT_INFO_MEMORY) {
- serial_printf("Mem lower: 0x%x", multiboot_header->mem_lower);
- serial_printf("Mem upper: 0x%x", multiboot_header->mem_upper);
+ log("Mem lower: 0x%x", multiboot_header->mem_lower);
+ log("Mem upper: 0x%x", multiboot_header->mem_upper);
} else {
- serial_printf("No memory information available!");
+ log("No memory information available!");
}
}
diff --git a/src/kernel/lib/stdio.h b/src/kernel/lib/stdio.h
index e1d7b9a..6da0f37 100644
--- a/src/kernel/lib/stdio.h
+++ b/src/kernel/lib/stdio.h
@@ -13,6 +13,8 @@ void vprintf(const char *fmt, va_list args);
void printf(const char *fmt, ...);
+void serial_vprintf(const char *fmt, va_list args);
+
void serial_printf(const char *fmt, ...);
-#endif \ No newline at end of file
+#endif
diff --git a/src/kernel/lib/stdio/debug.c b/src/kernel/lib/stdio/debug.c
index b5e5094..68f0785 100644
--- a/src/kernel/lib/stdio/debug.c
+++ b/src/kernel/lib/stdio/debug.c
@@ -5,17 +5,14 @@
#include <kernel/io/io.h>
#include <kernel/memory/alloc.h>
-void _write_serial(const char *data)
+void serial_print(const char *data)
{
for (size_t i = 0; i < strlen(data); i++)
serial_put(data[i]);
}
-void serial_printf(const char *fmt, ...)
+void serial_vprintf(const char *fmt, va_list args)
{
- va_list args;
- va_start(args, fmt);
-
uint8_t readyToFormat = 0;
char buff = 0;
@@ -31,16 +28,16 @@ void serial_printf(const char *fmt, ...)
buff = *fmt;
if (buff == 's') {
const char *str = va_arg(args, const char *);
- _write_serial(str);
+ serial_print(str);
readyToFormat = 0;
} else if (buff == 'x') {
char *p = htoa((uint32_t)va_arg(args, int));
- _write_serial(p);
+ serial_print(p);
kfree(p);
readyToFormat = 0;
} else if (buff == 'd') {
char *p = itoa(va_arg(args, int));
- _write_serial(p);
+ serial_print(p);
kfree(p);
readyToFormat = 0;
} else if (buff == 'c') {
@@ -54,8 +51,12 @@ void serial_printf(const char *fmt, ...)
serial_put(*fmt);
}
}
+}
- serial_put('\n');
-
+void serial_printf(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ serial_vprintf(fmt, args);
va_end(args);
-} \ No newline at end of file
+}
diff --git a/src/kernel/net/rtl8139.c b/src/kernel/net/rtl8139.c
index c722632..a934e52 100644
--- a/src/kernel/net/rtl8139.c
+++ b/src/kernel/net/rtl8139.c
@@ -20,7 +20,7 @@ void find_rtl(uint32_t device, uint16_t vendor_id, uint16_t device_id, void *ext
void rtl8139_irq_handler(struct regs *r)
{
- serial_printf("RTL INT!");
+ log("RTL INT!");
uint16_t status = inw((uint16_t)(rtl_iobase + 0x3E));
if (!status)
return;
@@ -28,7 +28,7 @@ void rtl8139_irq_handler(struct regs *r)
if (status & 0x01 || status & 0x02) {
while ((inw((uint16_t)(rtl_iobase + 0x37)) & 0x01) == 0) {
- serial_printf("RECEIVE");
+ log("RECEIVE");
// RECEIVE
}
}
@@ -100,4 +100,4 @@ void rtl8139_install()
if (rtl8139_init() == 0)
info("Installed rtl8139 network driver");
-}
+} \ No newline at end of file
diff --git a/src/kernel/pci/pci.c b/src/kernel/pci/pci.c
index abccb00..7ba48ab 100644
--- a/src/kernel/pci/pci.c
+++ b/src/kernel/pci/pci.c
@@ -136,4 +136,4 @@ int pci_get_interrupt(uint32_t device)
} else {
return (int)pci_read_field(device, PCI_INTERRUPT_LINE, 1);
}
-}
+} \ No newline at end of file
diff --git a/src/kernel/pci/pci.h b/src/kernel/pci/pci.h
index fc4bb5d..e358076 100644
--- a/src/kernel/pci/pci.h
+++ b/src/kernel/pci/pci.h
@@ -105,4 +105,4 @@ void pci_remap();
int pci_get_interrupt(uint32_t device);
-#endif
+#endif \ No newline at end of file
diff --git a/src/kernel/smbios/smbios.c b/src/kernel/smbios/smbios.c
index a3224bf..f2650bb 100644
--- a/src/kernel/smbios/smbios.c
+++ b/src/kernel/smbios/smbios.c
@@ -49,5 +49,5 @@ struct smbios_entry *get_smbios()
void smbios_table(struct smbios_header *header)
{
// struct smbios_0 *table = (struct smbios_0 *) (header + sizeof(struct smbios_header));
- // serial_printf("\n\n %d", table->bios_version);
+ // log("\n\n %d", table->bios_version);
} \ No newline at end of file
diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c
index d8bc4b8..1454198 100644
--- a/src/kernel/syscall/syscall.c
+++ b/src/kernel/syscall/syscall.c
@@ -17,7 +17,7 @@ uint32_t (*syscalls[])() = { [0] = (uint32_t(*)())halt_loop, // DEBUG!
void syscall_handler(struct regs *r)
{
- serial_printf("Received syscall!");
+ log("Received syscall!");
if (r->eax >= sizeof(syscalls) / sizeof(*syscalls))
return;
@@ -26,8 +26,8 @@ void syscall_handler(struct regs *r)
if (!location)
return;
- serial_printf("[SYSCALL] %d (0x%x) 0x%x 0x%x 0x%x 0x%x 0x%x", r->eax, location, r->ebx,
- r->ecx, r->edx, r->esi, r->edi);
+ log("[SYSCALL] %d (0x%x) 0x%x 0x%x 0x%x 0x%x 0x%x", r->eax, location, r->ebx, r->ecx,
+ r->edx, r->esi, r->edi);
r->eax = location(r->ebx, r->ecx, r->edx, r->esi, r->edi);
}
diff --git a/src/kernel/system.c b/src/kernel/system.c
index a8544e6..9a181f3 100644
--- a/src/kernel/system.c
+++ b/src/kernel/system.c
@@ -28,7 +28,7 @@ void vga_log(char *msg)
uint16_t *terminal_buffer = (uint16_t *)0xB8000;
for (size_t i = 0; i < strlen(msg); i++)
terminal_buffer[line * 80 + i] = (uint16_t)msg[i] | (uint16_t)0x700;
- serial_printf(msg);
+ log("%s", msg);
char string[80];
strcpy(string, "[");
strcat(string, itoa((int)get_time()));
@@ -40,16 +40,10 @@ void vga_log(char *msg)
line++;
}
-void kernel_time()
-{
- printf("[%d] ", (int)get_time());
-}
-
-void debug(const char *fmt, ...)
+void _debug(const char *f, const char *fmt, ...)
{
vesa_set_color(vesa_dark_white);
- kernel_time();
- printf("DBG: ");
+ printf("[%s] DBG: ", f);
va_list args;
va_start(args, fmt);
@@ -60,11 +54,10 @@ void debug(const char *fmt, ...)
writec('\n');
}
-void info(const char *fmt, ...)
+void _info(const char *f, const char *fmt, ...)
{
vesa_set_color(vesa_blue);
- kernel_time();
- printf("INF: ");
+ printf("[%s] INF: ", f);
va_list args;
va_start(args, fmt);
@@ -75,11 +68,10 @@ void info(const char *fmt, ...)
writec('\n');
}
-void warn(const char *fmt, ...)
+void _warn(const char *f, const char *fmt, ...)
{
vesa_set_color(vesa_dark_yellow);
- kernel_time();
- printf("WRN: ");
+ printf("[%s] WRN: ", f);
va_list args;
va_start(args, fmt);
@@ -90,12 +82,15 @@ void warn(const char *fmt, ...)
writec('\n');
}
-void log(const char *fmt, ...)
+void _log(const char *f, const char *fmt, ...)
{
+ serial_printf("[%s] ", f);
va_list args;
va_start(args, fmt);
- serial_printf(fmt, args);
+ serial_vprintf(fmt, args);
va_end(args);
+
+ serial_put('\n');
}
const char *random_message[10] = { "Uh... Did I do that?",
@@ -109,21 +104,20 @@ const char *random_message[10] = { "Uh... Did I do that?",
"Call 01189998819991197253 pls",
"Please fix me!" };
-void panic(char *msg)
+void _panic(const char *f, const char *msg)
{
cli();
vesa_set_color(vesa_dark_red);
- kernel_time();
- serial_printf("PNC: %s - System halted!", msg);
- printf("PNC: %s - System halted!\n\n", msg);
+ _log(f, "PNC: %s - System halted!", msg);
+ printf("[%s] PNC: %s - System halted!\n\n", f, msg);
printf("> %s", random_message[get_time() % 10]);
halt_loop();
}
-void assert(int x)
+void _assert(const char *f, int x)
{
if (x == 0) {
- panic("Assertion failed");
+ _panic(f, "Assertion failed");
}
}
@@ -140,4 +134,4 @@ void v86(uint8_t code, regs16_t *regs)
paging_disable();
int32(code, regs);
paging_enable();
-} \ No newline at end of file
+}
diff --git a/src/kernel/system.h b/src/kernel/system.h
index 29097bd..74f0185 100644
--- a/src/kernel/system.h
+++ b/src/kernel/system.h
@@ -52,48 +52,46 @@ char *vga_buffer;
void vga_log(char *msg);
/**
- * Print the current kernel time
- */
-void kernel_time();
-
-/**
* Display a general log message
- * @param msg The message
+ * @param fmt The message
*/
-void debug(const char *fmt, ...);
+void _debug(const char *f, const char *fmt, ...);
+#define debug(fmt, ...) _debug(__func__, fmt, ##__VA_ARGS__)
/**
* Display an information message
- * @param msg The information
+ * @param fmt The information
*/
-void info(const char *fmt, ...);
+void _info(const char *f, const char *fmt, ...);
+#define info(fmt, ...) _info(__func__, fmt, ##__VA_ARGS__)
/**
* Display a warning message
- * TODO: Add line number and file name
- * @param msg The warning cause/reason
+ * @param fmt The warning cause/reason
*/
-void warn(const char *fmt, ...);
+void _warn(const char *f, const char *fmt, ...);
+#define warn(fmt, ...) _warn(__func__, fmt, ##__VA_ARGS__)
/**
* Log into serial console
- * @param msg The log string
+ * @param fmt The log message
*/
-void log(const char *fmt, ...);
+void _log(const char *f, const char *fmt, ...);
+#define log(fmt, ...) _log(__func__, fmt, ##__VA_ARGS__)
/**
* Halt the entire system and display a message
- * TODO: Add line number and file name
* @param msg The error cause/reason
*/
-void panic(char *msg);
+void _panic(const char *f, const char *msg);
+#define panic(msg) _panic(__func__, msg)
/**
* Assert that a value is non-zero, else panic
- * TODO: Add line number and file name
* @param x The value
*/
-void assert(int x);
+void _assert(const char *f, int x);
+#define assert(x) _assert(__func__, x)
/**
* Creates an infinite halt loop
@@ -107,4 +105,4 @@ void halt_loop();
*/
void v86(uint8_t code, regs16_t *regs);
-#endif \ No newline at end of file
+#endif