From a9710cb73cc9ecadaff241428a39a26935cb5c0a Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Thu, 25 Feb 2021 20:45:10 +0100
Subject: Applied even more warning flags!

Fixing all the warnings wasn't that easy actually..
---
 kernel/drivers/interrupts.c |   4 +-
 kernel/drivers/keyboard.c   |   3 +-
 kernel/drivers/mouse.c      |   3 +-
 kernel/drivers/rtl8139.c    |   3 +-
 kernel/features/fs.c        |   8 ++--
 kernel/features/load.c      |   2 +-
 kernel/features/net.c       |   2 +-
 kernel/features/proc.c      |  27 ++++++------
 kernel/features/syscall.c   |   2 +-
 kernel/inc/boot.h           |   2 +-
 kernel/inc/fs.h             |   6 +--
 kernel/inc/interrupts.h     | 100 ++++++++++++++++++++++----------------------
 kernel/inc/load.h           |   2 +-
 kernel/inc/proc.h           |   6 +--
 kernel/main.c               |   2 +
 15 files changed, 89 insertions(+), 83 deletions(-)

(limited to 'kernel')

diff --git a/kernel/drivers/interrupts.c b/kernel/drivers/interrupts.c
index d9d514c..268bff5 100644
--- a/kernel/drivers/interrupts.c
+++ b/kernel/drivers/interrupts.c
@@ -29,7 +29,7 @@ void idt_set_gate(u8 num, u32 base, u16 sel, u8 flags)
 }
 
 // Install IDT
-static void idt_install()
+static void idt_install(void)
 {
 	// Set IDT pointer and limit
 	idt_ptr.limit = (sizeof(struct idt_entry) * 256) - 1;
@@ -60,7 +60,7 @@ void irq_uninstall_handler(int irq)
 }
 
 // Remap the IRQ table
-static void irq_remap()
+static void irq_remap(void)
 {
 	outb(0x20, 0x11);
 	outb(0xA0, 0x11);
diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c
index f7f9d2d..3ae3c0e 100644
--- a/kernel/drivers/keyboard.c
+++ b/kernel/drivers/keyboard.c
@@ -18,8 +18,9 @@ static u32 dev_id = 0;
 
 static int state = 0;
 static int merged = 0;
-static void keyboard_handler()
+static void keyboard_handler(struct regs *r)
 {
+	UNUSED(r);
 	int scancode = inb(0x60);
 
 	// TODO: Support more than two-byte scancodes
diff --git a/kernel/drivers/mouse.c b/kernel/drivers/mouse.c
index ce9d15c..40094d1 100644
--- a/kernel/drivers/mouse.c
+++ b/kernel/drivers/mouse.c
@@ -19,8 +19,9 @@ static u32 dev_id = 0;
 
 static struct event_mouse *event = NULL;
 
-static void mouse_handler()
+static void mouse_handler(struct regs *r)
 {
+	UNUSED(r);
 	switch (mouse_cycle) {
 	case 0:
 		mouse_byte[0] = (char)inb(0x60);
diff --git a/kernel/drivers/rtl8139.c b/kernel/drivers/rtl8139.c
index 1f9eed9..753bd6a 100644
--- a/kernel/drivers/rtl8139.c
+++ b/kernel/drivers/rtl8139.c
@@ -82,8 +82,9 @@ static void rtl8139_find(u32 device, u16 vendor_id, u16 device_id, void *extra)
 	}
 }
 
-static void rtl8139_irq_handler()
+static void rtl8139_irq_handler(struct regs *r)
 {
+	UNUSED(r);
 	u16 status = inw(rtl_iobase + RTL_PORT_ISR);
 	if (!status)
 		return;
diff --git a/kernel/features/fs.c b/kernel/features/fs.c
index 9ea5458..c7aacd0 100644
--- a/kernel/features/fs.c
+++ b/kernel/features/fs.c
@@ -186,7 +186,7 @@ s32 vfs_stat(const char *path, struct stat *buf)
 	return m->dev->vfs->stat(path, buf, m->dev);
 }
 
-s32 vfs_wait(const char *path, s32 (*func)())
+s32 vfs_wait(const char *path, u32 func_ptr)
 {
 	while (*path == ' ')
 		path++;
@@ -196,7 +196,7 @@ s32 vfs_wait(const char *path, s32 (*func)())
 
 	// Default wait
 	if (!m->dev->vfs->wait) {
-		proc_wait_for(vfs_find_dev(path)->id, PROC_WAIT_DEV, func);
+		proc_wait_for(vfs_find_dev(path)->id, PROC_WAIT_DEV, func_ptr);
 		return 1;
 	}
 
@@ -204,7 +204,7 @@ s32 vfs_wait(const char *path, s32 (*func)())
 	if (len > 1)
 		path += len;
 
-	return m->dev->vfs->wait(path, func, m->dev);
+	return m->dev->vfs->wait(path, func_ptr, m->dev);
 }
 
 s32 vfs_poll(const char **files)
@@ -217,7 +217,7 @@ s32 vfs_poll(const char **files)
 			return p - files;
 
 	for (const char **p = files; *p && **p; p++)
-		vfs_wait(*p, vfs_poll);
+		vfs_wait(*p, (u32)vfs_poll);
 
 	return PROC_MAX_WAIT_IDS + 1;
 }
diff --git a/kernel/features/load.c b/kernel/features/load.c
index 3e1ea8e..f79e6b4 100644
--- a/kernel/features/load.c
+++ b/kernel/features/load.c
@@ -14,7 +14,7 @@ void proc_load(struct proc *proc, void *data)
 	proc->regs.eip = (u32)data;
 }
 
-int bin_load(char *path, struct proc *proc)
+int bin_load(const char *path, struct proc *proc)
 {
 	// TODO: Remove hardcoded filesize
 	struct stat s = { 0 };
diff --git a/kernel/features/net.c b/kernel/features/net.c
index be36f14..104538f 100644
--- a/kernel/features/net.c
+++ b/kernel/features/net.c
@@ -817,7 +817,7 @@ int net_receive(struct socket *socket, void *buf, u32 len)
  * Install
  */
 
-int net_installed()
+int net_installed(void)
 {
 	return rtl8139_installed() != 0;
 }
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index c21ffcc..48bde72 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -74,7 +74,7 @@ void scheduler(struct regs *regs)
 	/* printf("{%d}", ((struct proc *)current->data)->pid); */
 }
 
-static void kernel_idle()
+static void kernel_idle(void)
 {
 	while (1)
 		;
@@ -121,7 +121,7 @@ struct proc *proc_from_pid(u32 pid)
 	return NULL;
 }
 
-void proc_clear_quantum()
+void proc_clear_quantum(void)
 {
 	quantum = 0;
 }
@@ -179,9 +179,10 @@ void proc_enable_waiting(u32 id, enum proc_wait_type type)
 			if (w->ids[i].magic == PROC_WAIT_MAGIC && w->ids[i].id == id &&
 			    w->ids[i].type == type) {
 				struct regs *r = &p->regs;
-				if (w->ids[i].func)
-					r->eax = (u32)w->ids[i].func((char *)r->ebx, (void *)r->ecx,
-								     r->edx, r->esi);
+				u32 (*func)(u32, u32, u32, u32) =
+					(u32(*)(u32, u32, u32, u32))w->ids[i].func_ptr;
+				if (w->ids[i].func_ptr)
+					r->eax = func(r->ebx, r->ecx, r->edx, r->esi);
 				memset(&w->ids[i], 0, sizeof(w->ids[i]));
 				p->wait.id_cnt--;
 				p->state = PROC_RUNNING;
@@ -196,7 +197,7 @@ void proc_enable_waiting(u32 id, enum proc_wait_type type)
 		current = list_first_data(proc_list, proc_bak);
 }
 
-void proc_wait_for(u32 id, enum proc_wait_type type, s32 (*func)())
+void proc_wait_for(u32 id, enum proc_wait_type type, u32 func_ptr)
 {
 	u8 already_exists = 0;
 	struct proc *p = proc_current();
@@ -204,7 +205,7 @@ void proc_wait_for(u32 id, enum proc_wait_type type, s32 (*func)())
 	// Check if already exists
 	for (u32 i = 0; i < p->wait.id_cnt; i++) {
 		if (p->wait.ids[i].id == id && p->wait.ids[i].type == type) {
-			assert(p->wait.ids[i].func == func);
+			assert(p->wait.ids[i].func_ptr == func_ptr);
 			already_exists = 1;
 		}
 	}
@@ -227,7 +228,7 @@ void proc_wait_for(u32 id, enum proc_wait_type type, s32 (*func)())
 	slot->magic = PROC_WAIT_MAGIC;
 	slot->id = id;
 	slot->type = type;
-	slot->func = func;
+	slot->func_ptr = func_ptr;
 	p->wait.id_cnt++;
 
 end:
@@ -369,7 +370,7 @@ static s32 procfs_read(const char *path, void *buf, u32 offset, u32 count, struc
 	return -1;
 }
 
-static s32 procfs_wait(const char *path, s32 (*func)(), struct device *dev)
+static s32 procfs_wait(const char *path, u32 func_ptr, struct device *dev)
 {
 	u32 pid = 0;
 	procfs_parse_path(&path, &pid);
@@ -381,10 +382,10 @@ static s32 procfs_wait(const char *path, s32 (*func)(), struct device *dev)
 
 		path++;
 		if (!memcmp(path, "msg", 4)) {
-			proc_wait_for(pid, PROC_WAIT_MSG, func);
+			proc_wait_for(pid, PROC_WAIT_MSG, func_ptr);
 			return 1;
 		} else {
-			proc_wait_for(dev->id, PROC_WAIT_DEV, func);
+			proc_wait_for(dev->id, PROC_WAIT_DEV, func_ptr);
 			return 1;
 		}
 	}
@@ -461,14 +462,14 @@ void proc_init(void)
 
 	// Idle proc
 	struct proc *kernel_proc = proc_make();
-	void (*func)() = kernel_idle;
+	void (*func)(void) = kernel_idle;
 	proc_load(kernel_proc, *(void **)&func);
 	strcpy(kernel_proc->name, "idle");
 	kernel_proc->state = PROC_SLEEPING;
 	idle_proc = list_add(proc_list, kernel_proc);
 
 	struct node *new = list_add(proc_list, proc_make());
-	bin_load((char *)"/bin/init", new->data);
+	bin_load("/bin/init", new->data);
 	current = new;
 
 	_eip = ((struct proc *)new->data)->regs.eip;
diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c
index 538fd59..61c7479 100644
--- a/kernel/features/syscall.c
+++ b/kernel/features/syscall.c
@@ -41,7 +41,7 @@ static void syscall_handler(struct regs *r)
 		if (vfs_ready((char *)r->ebx)) {
 			r->eax = (u32)vfs_read((char *)r->ebx, (void *)r->ecx, r->edx, r->esi);
 		} else {
-			if (vfs_wait((char *)r->ebx, vfs_read) < 0)
+			if (vfs_wait((char *)r->ebx, (u32)vfs_read) < 0)
 				r->eax = -1;
 			else
 				proc_yield(r);
diff --git a/kernel/inc/boot.h b/kernel/inc/boot.h
index 98e964d..6bacc31 100644
--- a/kernel/inc/boot.h
+++ b/kernel/inc/boot.h
@@ -6,7 +6,7 @@
 
 #include <def.h>
 
-struct vid_info *boot_passed;
+extern struct vid_info *boot_passed;
 struct vid_info {
 	u32 mode;
 	u32 *vbe;
diff --git a/kernel/inc/fs.h b/kernel/inc/fs.h
index 868cd3e..33b1afb 100644
--- a/kernel/inc/fs.h
+++ b/kernel/inc/fs.h
@@ -20,7 +20,7 @@ struct device {
 	void *data;
 	s32 (*read)(void *buf, u32 offset, u32 count, struct device *dev);
 	s32 (*write)(void *buf, u32 offset, u32 count, struct device *dev);
-	u8 (*ready)();
+	u8 (*ready)(void);
 };
 
 void device_install(void);
@@ -41,7 +41,7 @@ struct vfs {
 	s32 (*read)(const char *path, void *buf, u32 offset, u32 count, struct device *dev);
 	s32 (*write)(const char *path, void *buf, u32 offset, u32 count, struct device *dev);
 	s32 (*stat)(const char *path, struct stat *buf, struct device *dev);
-	s32 (*wait)(const char *path, s32 (*func)(), struct device *dev);
+	s32 (*wait)(const char *path, u32 func_ptr, struct device *dev);
 	u8 (*perm)(const char *path, enum vfs_perm perm, struct device *dev);
 	u8 (*ready)(const char *path, struct device *dev);
 };
@@ -61,7 +61,7 @@ struct device *vfs_find_dev(const char *path);
 s32 vfs_read(const char *path, void *buf, u32 offset, u32 count);
 s32 vfs_write(const char *path, void *buf, u32 offset, u32 count);
 s32 vfs_stat(const char *path, struct stat *buf);
-s32 vfs_wait(const char *path, s32 (*func)());
+s32 vfs_wait(const char *path, u32 func_ptr);
 s32 vfs_poll(const char **files);
 u8 vfs_ready(const char *path);
 
diff --git a/kernel/inc/interrupts.h b/kernel/inc/interrupts.h
index 1c475b1..30c91c3 100644
--- a/kernel/inc/interrupts.h
+++ b/kernel/inc/interrupts.h
@@ -37,56 +37,56 @@ void interrupts_install(void);
 
 // External handlers (ASM)
 
-extern void isr0();
-extern void isr1();
-extern void isr2();
-extern void isr3();
-extern void isr4();
-extern void isr5();
-extern void isr6();
-extern void isr7();
-extern void isr8();
-extern void isr9();
-extern void isr10();
-extern void isr11();
-extern void isr12();
-extern void isr13();
-extern void isr14();
-extern void isr15();
-extern void isr16();
-extern void isr17();
-extern void isr18();
-extern void isr19();
-extern void isr20();
-extern void isr21();
-extern void isr22();
-extern void isr23();
-extern void isr24();
-extern void isr25();
-extern void isr26();
-extern void isr27();
-extern void isr28();
-extern void isr29();
-extern void isr30();
-extern void isr31();
-extern void isr128();
+extern void isr0(struct regs *r);
+extern void isr1(struct regs *r);
+extern void isr2(struct regs *r);
+extern void isr3(struct regs *r);
+extern void isr4(struct regs *r);
+extern void isr5(struct regs *r);
+extern void isr6(struct regs *r);
+extern void isr7(struct regs *r);
+extern void isr8(struct regs *r);
+extern void isr9(struct regs *r);
+extern void isr10(struct regs *r);
+extern void isr11(struct regs *r);
+extern void isr12(struct regs *r);
+extern void isr13(struct regs *r);
+extern void isr14(struct regs *r);
+extern void isr15(struct regs *r);
+extern void isr16(struct regs *r);
+extern void isr17(struct regs *r);
+extern void isr18(struct regs *r);
+extern void isr19(struct regs *r);
+extern void isr20(struct regs *r);
+extern void isr21(struct regs *r);
+extern void isr22(struct regs *r);
+extern void isr23(struct regs *r);
+extern void isr24(struct regs *r);
+extern void isr25(struct regs *r);
+extern void isr26(struct regs *r);
+extern void isr27(struct regs *r);
+extern void isr28(struct regs *r);
+extern void isr29(struct regs *r);
+extern void isr30(struct regs *r);
+extern void isr31(struct regs *r);
+extern void isr128(struct regs *r);
 
-extern void irq0();
-extern void irq1();
-extern void irq2();
-extern void irq3();
-extern void irq4();
-extern void irq5();
-extern void irq6();
-extern void irq7();
-extern void irq8();
-extern void irq9();
-extern void irq10();
-extern void irq11();
-extern void irq12();
-extern void irq13();
-extern void irq14();
-extern void irq15();
-extern void irq128();
+extern void irq0(struct regs *r);
+extern void irq1(struct regs *r);
+extern void irq2(struct regs *r);
+extern void irq3(struct regs *r);
+extern void irq4(struct regs *r);
+extern void irq5(struct regs *r);
+extern void irq6(struct regs *r);
+extern void irq7(struct regs *r);
+extern void irq8(struct regs *r);
+extern void irq9(struct regs *r);
+extern void irq10(struct regs *r);
+extern void irq11(struct regs *r);
+extern void irq12(struct regs *r);
+extern void irq13(struct regs *r);
+extern void irq14(struct regs *r);
+extern void irq15(struct regs *r);
+extern void irq128(struct regs *r);
 
 #endif
diff --git a/kernel/inc/load.h b/kernel/inc/load.h
index 422a28c..407fbeb 100644
--- a/kernel/inc/load.h
+++ b/kernel/inc/load.h
@@ -6,6 +6,6 @@
 #include <proc.h>
 
 void proc_load(struct proc *proc, void *data);
-int bin_load(char *path, struct proc *proc);
+int bin_load(const char *path, struct proc *proc);
 
 #endif
diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h
index cd74b40..a232f46 100644
--- a/kernel/inc/proc.h
+++ b/kernel/inc/proc.h
@@ -30,7 +30,7 @@ struct proc_wait_identifier {
 	u32 magic;
 	u32 id;
 	enum proc_wait_type type;
-	s32 (*func)();
+	u32 func_ptr;
 };
 
 struct proc_wait {
@@ -63,9 +63,9 @@ u8 proc_super(void);
 struct proc *proc_from_pid(u32 pid);
 void proc_exit(struct proc *proc, int status);
 void proc_yield(struct regs *r);
-void proc_clear_quantum();
+void proc_clear_quantum(void);
 void proc_enable_waiting(u32 id, enum proc_wait_type type);
-void proc_wait_for(u32 id, enum proc_wait_type type, s32 (*func)());
+void proc_wait_for(u32 id, enum proc_wait_type type, u32 func_ptr);
 struct proc *proc_make(void);
 
 #endif
diff --git a/kernel/main.c b/kernel/main.c
index f8815eb..5e236a7 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -16,6 +16,8 @@
 #include <syscall.h>
 #include <timer.h>
 
+struct vid_info *boot_passed;
+
 void kernel_main(struct vid_info *vid_info); // Decl
 void kernel_main(struct vid_info *vid_info)
 {
-- 
cgit v1.2.3