aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2019-12-21 22:22:03 +0100
committerMarvin Borner2019-12-21 22:22:03 +0100
commit499784a824c541001c2fd52ae95eba88dcfc952b (patch)
treec3c26d7c8a3b9291d909f4655b7d27a5ae2369bc
parent38610cd06dc0b5a3a4ee46f5fe7c341191aa2bc1 (diff)
Many debugging/serial improvements
Sorry for the little information, but I did many things :)
-rw-r--r--Makefile10
-rw-r--r--src/kernel/acpi/acpi.c12
-rw-r--r--src/kernel/boot.asm17
-rw-r--r--src/kernel/cmos/rtc.c2
-rw-r--r--src/kernel/fs/ata_pio.c1
-rw-r--r--src/kernel/fs/install.c5
-rw-r--r--src/kernel/graphics/font.c1
-rw-r--r--src/kernel/graphics/vesa.c21
-rw-r--r--src/kernel/input/ps2/keyboard.c4
-rw-r--r--src/kernel/input/ps2/mouse.c5
-rw-r--r--src/kernel/interrupts/isr.c30
-rw-r--r--src/kernel/io/io.c46
-rw-r--r--src/kernel/io/io.h18
-rw-r--r--src/kernel/kernel.c8
-rw-r--r--src/kernel/lib/stdio.h6
-rw-r--r--src/kernel/lib/stdio/debug.c59
-rw-r--r--src/kernel/lib/stdio/vprintf.c8
-rw-r--r--src/kernel/lib/stdlib/htoa.c4
-rw-r--r--src/kernel/lib/stdlib/itoa.c4
-rw-r--r--src/kernel/net/rtl8139.c5
-rw-r--r--src/kernel/paging/paging.c2
-rw-r--r--src/kernel/smbios/smbios.c7
-rw-r--r--src/kernel/syscall/actions/sys_paging_alloc.c1
-rw-r--r--src/kernel/syscall/actions/sys_read.c1
-rw-r--r--src/kernel/syscall/actions/sys_write.c2
-rw-r--r--src/kernel/syscall/syscall.c7
-rw-r--r--src/kernel/system.c6
-rw-r--r--src/userspace/main.c7
-rw-r--r--src/userspace/mlibc/stdio/readline.c6
-rw-r--r--src/userspace/mlibc/stdio/vprintf.c8
-rw-r--r--src/userspace/mlibc/stdlib/atoi.c2
-rw-r--r--src/userspace/mlibc/stdlib/htoa.c6
-rw-r--r--src/userspace/mlibc/stdlib/htoi.c2
-rw-r--r--src/userspace/mlibc/stdlib/itoa.c5
-rw-r--r--src/userspace/mlibc/string/strcat.c2
-rw-r--r--src/userspace/mlibc/string/strcati.c2
-rw-r--r--src/userspace/mlibc/string/strcmp.c2
-rw-r--r--src/userspace/mlibc/string/strcpy.c2
-rw-r--r--src/userspace/mlibc/string/strdisp.c2
-rw-r--r--src/userspace/mlibc/string/strdup.c2
-rw-r--r--src/userspace/mlibc/string/strinv.c2
-rw-r--r--src/userspace/mlibc/string/strlen.c2
-rw-r--r--src/userspace/syscall.h14
43 files changed, 153 insertions, 205 deletions
diff --git a/Makefile b/Makefile
index e8c01e3..a51af76 100644
--- a/Makefile
+++ b/Makefile
@@ -92,29 +92,29 @@ debug:
@echo "Starting simulation..."
@head -c 10485760 /dev/zero > ./build/hdd10M.img
@echo "[SERIAL OUTPUT]"
- @qemu-system-x86_64 ${QEMU_OPTIONS} -cdrom ./build/melvix.iso -drive file=./build/hdd10M.img,format=raw
+ @qemu-system-i386 ${QEMU_OPTIONS} -cdrom ./build/melvix.iso -drive file=./build/hdd10M.img,format=raw
@echo "[END OF CONNECTION]"
image: build
@echo "Starting simulation..."
@head -c 10485760 /dev/zero > ./build/hdd10M.img
@echo "[SERIAL OUTPUT]"
- @qemu-system-x86_64 ${QEMU_OPTIONS} -cdrom ./build/melvix.iso -drive file=./build/hdd10M.img,format=raw
+ @qemu-system-i386 ${QEMU_OPTIONS} -cdrom ./build/melvix.iso -drive file=./build/hdd10M.img,format=raw
@echo "[END OF CONNECTION]"
@printf "\n"
@echo "[SERIAL OUTPUT]"
- @qemu-system-x86_64 ${QEMU_OPTIONS} -drive file=./build/hdd10M.img,format=raw
+ @qemu-system-i386 ${QEMU_OPTIONS} -drive file=./build/hdd10M.img,format=raw
@echo "[END OF CONNECTION]"
debugHDD:
@echo "Starting simulation..."
@echo "[SERIAL OUTPUT]"
- @qemu-system-x86_64 ${QEMU_OPTIONS} -drive file=./build/hdd10M.img,format=raw
+ @qemu-system-i386 ${QEMU_OPTIONS} -drive file=./build/hdd10M.img,format=raw
@echo "[END OF CONNECTION]"
bochs: build
@head -c 10485760 /dev/zero > ./build/hdd10M.img
- @qemu-system-x86_64 ${QEMU_OPTIONS} -cdrom ./build/melvix.iso -drive file=./build/hdd10M.img,format=raw
+ @qemu-system-i386 ${QEMU_OPTIONS} -cdrom ./build/melvix.iso -drive file=./build/hdd10M.img,format=raw
@bochs -f bochs.txt
bochsHDD:
diff --git a/src/kernel/acpi/acpi.c b/src/kernel/acpi/acpi.c
index ab019c8..7348127 100644
--- a/src/kernel/acpi/acpi.c
+++ b/src/kernel/acpi/acpi.c
@@ -7,6 +7,7 @@
#include <kernel/acpi/acpi.h>
#include <stddef.h>
#include <kernel/system.h>
+#include <kernel/lib/stdio.h>
struct FADT *fadt;
uint32_t *SMI_CMD;
@@ -87,15 +88,15 @@ int acpi_enable()
if (i < 300) {
return 0; // Successfully enabled ACPI
} else {
- serial_write("ACPI couldn't be enabled!\n");
+ serial_printf("ACPI couldn't be enabled!");
return -1; // ACPI couldn't be enabled
}
} else {
- serial_write("ACPI is not supported!\n");
+ serial_printf("ACPI is not supported!");
return -1; // ACPI is not supported
}
} else {
- serial_write("ACPI was already enabled!\n");
+ serial_printf("ACPI was already enabled!");
return 0; // ACPI was already enabled
}
}
@@ -161,13 +162,12 @@ int acpi_install()
}
if (memcmp((unsigned int *) *ptr, "HPET", 4) == 0) {
hpet = (struct HPET *) *ptr;
- // serial_write(hpet->signature);
- // serial_write_hex((int) hpet->base_address);
+ // serial_printf("%d", hpet->base_address);
}
ptr++;
} // Else: no valid FADT present
} else {
- serial_write("ACPI is not supported!\n");
+ serial_printf("ACPI is not supported!");
}
return success == 1 ? 0 : -1;
diff --git a/src/kernel/boot.asm b/src/kernel/boot.asm
index 2180069..3353a30 100644
--- a/src/kernel/boot.asm
+++ b/src/kernel/boot.asm
@@ -38,10 +38,8 @@ section .text
global jump_userspace
jump_userspace:
- push ebp
- mov ebp, esp
- mov edx, DWORD[ebp + 0xC]
- mov esp, edx
+ cli
+ mov ebx, dword [esp + 4]
mov ax, 0x23
mov ds, ax
@@ -53,17 +51,16 @@ section .text
push 0x23
push eax
pushf
- pop eax
+ ; Enable interrupts
+ pop eax
or eax, 0x200
push eax
- push 0x1B
-
- push DWORD[ebp + 0x8]
+ push 0x1B
+ push ebx
+ mov ebp, ebx
iret
- pop ebp
- ret
section .end_section
global ASM_KERNEL_END
diff --git a/src/kernel/cmos/rtc.c b/src/kernel/cmos/rtc.c
index 0a5b63d..378bfd5 100644
--- a/src/kernel/cmos/rtc.c
+++ b/src/kernel/cmos/rtc.c
@@ -1,6 +1,4 @@
#include <kernel/io/io.h>
-#include <kernel/graphics/vesa.h>
-#include <kernel/acpi/acpi.h>
#include <kernel/lib/stdio.h>
unsigned char second;
diff --git a/src/kernel/fs/ata_pio.c b/src/kernel/fs/ata_pio.c
index 2de57b8..0134ee4 100644
--- a/src/kernel/fs/ata_pio.c
+++ b/src/kernel/fs/ata_pio.c
@@ -1,7 +1,6 @@
#include <kernel/io/io.h>
#include <kernel/lib/stdlib.h>
#include <kernel/fs/ata_pio.h>
-#include <kernel/interrupts/interrupts.h>
struct ata_interface *new_ata(uint8_t master, uint16_t port_base)
{
diff --git a/src/kernel/fs/install.c b/src/kernel/fs/install.c
index da0407d..8a687d7 100644
--- a/src/kernel/fs/install.c
+++ b/src/kernel/fs/install.c
@@ -5,8 +5,7 @@
#include <kernel/fs/atapi_pio.h>
#include <kernel/lib/stdlib.h>
#include <kernel/acpi/acpi.h>
-#include <kernel/io/io.h>
-#include <kernel/timer/timer.h>
+#include <kernel/lib/stdio.h>
void install_melvix()
{
@@ -84,7 +83,7 @@ void install_melvix()
kfree(font_e);
info("Installation successful!");
- serial_write("Installation successful!\nRebooting...\n");
+ serial_printf("Installation successful!\nRebooting...");
// timer_wait(200);
acpi_poweroff();
halt_loop();
diff --git a/src/kernel/graphics/font.c b/src/kernel/graphics/font.c
index 3f55d01..2a16d2f 100644
--- a/src/kernel/graphics/font.c
+++ b/src/kernel/graphics/font.c
@@ -1,6 +1,5 @@
#include <kernel/fs/marfs/marfs.h>
#include <kernel/paging/paging.h>
-#include <kernel/io/io.h>
#include <kernel/graphics/font.h>
#include <kernel/lib/stdlib/liballoc.h>
#include <kernel/fs/ata_pio.h>
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c
index 5090025..c06bef6 100644
--- a/src/kernel/graphics/vesa.c
+++ b/src/kernel/graphics/vesa.c
@@ -1,6 +1,5 @@
#include <kernel/graphics/vesa.h>
#include <kernel/graphics/font.h>
-#include <kernel/io/io.h>
#include <kernel/lib/lib.h>
#include <kernel/paging/paging.h>
#include <kernel/system.h>
@@ -10,7 +9,7 @@
void switch_to_vga()
{
- serial_write("Force switch to VGA!\n");
+ serial_printf("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++)
@@ -117,15 +116,7 @@ void set_optimal_resolution()
continue;
}
- serial_write("Found mode: (");
- serial_write_hex(*mode);
- serial_write(") ");
- serial_write_dec(mode_info->width);
- serial_write("x");
- serial_write_dec(mode_info->height);
- serial_write("x");
- serial_write_dec(mode_info->bpp);
- serial_write("\n");
+ serial_printf("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)) {
// if (mode_info->bpp == 32) { // Force specific bpp for debugging
@@ -143,7 +134,7 @@ void set_optimal_resolution()
kfree(video_modes);
if (highest == 0) {
- serial_write("Mode detection failed!\nTrying common modes...\n");
+ serial_printf("Mode detection failed!\nTrying common modes...");
vga_log("Mode detection failed!", 11);
vga_log("Trying common modes...", 12);
struct vbe_mode_info *mode_info;
@@ -195,8 +186,6 @@ void set_optimal_resolution()
paging_map((uint32_t) fb + z, (uint32_t) fb + z, PT_PRESENT | PT_RW | PT_USED | PT_ALL_PRIV);
paging_map((uint32_t) cursor_buffer + z, (uint32_t) cursor_buffer + z, PT_PRESENT | PT_RW | PT_USED);
}
- serial_write_hex((int) &fb);
- serial_write("\n");
if (vbe_height > 1440) vesa_set_font(32);
else if (vbe_height > 720) vesa_set_font(24);
@@ -210,9 +199,7 @@ void set_optimal_resolution()
info("Successfully switched to video mode!");
- serial_write("Using mode: ");
- serial_write_hex(highest);
- serial_write("\n");
+ serial_printf("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/keyboard.c b/src/kernel/input/ps2/keyboard.c
index bafecd5..4cbbf04 100644
--- a/src/kernel/input/ps2/keyboard.c
+++ b/src/kernel/input/ps2/keyboard.c
@@ -4,8 +4,6 @@
#include <kernel/input/input.h>
#include <kernel/lib/stdlib/liballoc.h>
#include <kernel/lib/string.h>
-#include <kernel/paging/paging.h>
-#include <kernel/lib/lib.h>
int shift_pressed;
int control_pressed;
@@ -109,7 +107,7 @@ void keyboard_handler(struct regs *r)
keyboard_char_buffer = current_keymap[scan_code];
keyboard_buffer[strlen(keyboard_buffer)] = keyboard_char_buffer;
} else { // RELEASE
- if (current_keymap[scan_code] == -107) // TODO: IDK WHY -107?!
+ if (current_keymap[scan_code] == (int) 0xffffffb5) // TODO: IDK WHY -107?!
control_pressed = 0;
}
}
diff --git a/src/kernel/input/ps2/mouse.c b/src/kernel/input/ps2/mouse.c
index 75d80a1..8b36ef9 100644
--- a/src/kernel/input/ps2/mouse.c
+++ b/src/kernel/input/ps2/mouse.c
@@ -1,6 +1,7 @@
#include <kernel/interrupts/interrupts.h>
#include <kernel/io/io.h>
#include <kernel/graphics/vesa.h>
+#include <kernel/lib/stdio.h>
char mouse_cycle = 0;
char mouse_byte[3];
@@ -109,7 +110,7 @@ void mouse_install()
mouse_write(0xF2);
mouse_read();
status = mouse_read();
- if (status == 3) serial_write("Scrollwheel support!\n");
+ if (status == 3) serial_printf("Scrollwheel support!");
// Activate 4th and 5th mouse buttons
mouse_write(0xF2);
@@ -130,7 +131,7 @@ void mouse_install()
mouse_write(0xF2);
mouse_read();
status = mouse_read();
- if (status == 4) serial_write("4th and 5th mouse button support!\n");
+ if (status == 4) serial_printf("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 3dfd24c..f774b86 100644
--- a/src/kernel/interrupts/isr.c
+++ b/src/kernel/interrupts/isr.c
@@ -1,9 +1,8 @@
#include <stdint.h>
#include <kernel/interrupts/interrupts.h>
-#include <kernel/lib/lib.h>
#include <kernel/system.h>
-#include <kernel/io/io.h>
#include <kernel/lib/string.h>
+#include <kernel/lib/stdio.h>
// Install ISRs in IDT
void isrs_install()
@@ -112,28 +111,11 @@ void fault_handler(struct regs *r)
uint32_t faulting_address;
asm ("mov %%cr2, %0" : "=r" (faulting_address));
- serial_write("\n[DEBUG]\nEIP: ");
- serial_write_hex(r->eip);
- serial_write("\nEAX: ");
- serial_write_hex(r->eax);
- serial_write("\nEBX: ");
- serial_write_hex(r->ebx);
- serial_write("\nECX: ");
- serial_write_hex(r->ecx);
- serial_write("\nEDX: ");
- serial_write_hex(r->edx);
- serial_write("\nESP: ");
- serial_write_hex(r->esp);
- serial_write("\nFaulting address: ");
- serial_write_hex(faulting_address);
- serial_write("\nError flags: ");
- serial_write_hex(r->eflags);
- serial_write("\nError code: ");
- serial_write_hex(r->err_code);
- serial_write("\nInterrupt code: ");
- serial_write_hex(r->int_no);
- serial_write("\nInterrupt message: ");
- serial_write(exception_messages[r->int_no]);
+ 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]
+ );
// halt_loop(); // Idk loop?
char *message = (char *) exception_messages[r->int_no];
strcat(message, " Exception");
diff --git a/src/kernel/io/io.c b/src/kernel/io/io.c
index 6bd87e0..b54a859 100644
--- a/src/kernel/io/io.c
+++ b/src/kernel/io/io.c
@@ -1,9 +1,5 @@
#include <stdint.h>
-#include <kernel/lib/lib.h>
-#include <kernel/io/io.h>
#include <kernel/system.h>
-#include <kernel/lib/string.h>
-#include <kernel/lib/stdlib.h>
uint8_t inb(uint16_t port)
{
@@ -62,44 +58,4 @@ void serial_put(char ch)
{
while (is_transmit_empty() == 0);
outb(0x3f8, ch);
-}
-
-void serial_write(const char *data)
-{
- for (size_t i = 0; i < strlen(data); i++) {
- serial_put(data[i]);
- }
-}
-
-void serial_write_hex(int n)
-{
- int tmp;
-
- serial_write("0x");
- char noZeroes = 1;
-
- for (int i = 28; i > 0; i -= 4) {
- tmp = (n >> i) & 0xF;
- if (tmp == 0 && noZeroes != 0) continue;
-
- if (tmp >= 0xA) {
- noZeroes = 0;
- serial_put(tmp - 0xA + 'a');
- } else {
- noZeroes = 0;
- serial_put(tmp + '0');
- }
- }
-
- tmp = n & 0xF;
- if (tmp >= 0xA) {
- serial_put(tmp - 0xA + 'a');
- } else {
- serial_put(tmp + '0');
- }
-}
-
-void serial_write_dec(int n)
-{
- serial_write(itoa(n));
-}
+} \ No newline at end of file
diff --git a/src/kernel/io/io.h b/src/kernel/io/io.h
index 0ad5a54..b62e90f 100644
--- a/src/kernel/io/io.h
+++ b/src/kernel/io/io.h
@@ -56,22 +56,4 @@ void init_serial();
*/
void serial_put(char ch);
-/**
- * Write a string to the serial port (QEMU logging)
- * @param data The string
- */
-void serial_write(const char *data);
-
-/**
- * Write a hexadecimal formatted int to the serial port (QEMU logging)
- * @param n The decimal number
- */
-void serial_write_hex(int n);
-
-/**
- * Write a decimal number to the serial port (QEMU logging)
- * @param n The decimal number
- */
-void serial_write_dec(int n);
-
#endif
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index 196b44e..412a289 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -7,18 +7,16 @@
#include <kernel/input/input.h>
#include <kernel/acpi/acpi.h>
#include <kernel/smbios/smbios.h>
-#include <kernel/fs/install.h>
#include <kernel/lib/lib.h>
#include <kernel/syscall/syscall.h>
#include <kernel/fs/marfs/marfs.h>
#include <kernel/fs/iso9660/iso9660.h>
#include <kernel/fs/atapi_pio.h>
#include <kernel/lib/stdlib/liballoc.h>
-#include <kernel/lib/stdio.h>
#include <kernel/pci/pci.h>
#include <kernel/net/network.h>
-extern void jump_userspace(uintptr_t location, uintptr_t stack);
+extern void jump_userspace();
void kernel_main()
{
@@ -66,10 +64,10 @@ void kernel_main()
if (!user_e) panic("Userspace binary not found!");
ATAPI_granular_read(1 + (user_e->length / 2048), user_e->lba, (uint8_t *) (userspace + 4096));
kfree(user_e);
- jump_userspace(userspace + 4096, (uintptr_t) umalloc(4096));
+ jump_userspace(userspace + 4096);
} else {
marfs_read_whole_file(4, (uint8_t *) (userspace + 4096));
- jump_userspace(userspace + 4096, (uintptr_t) umalloc(4096));
+ jump_userspace(userspace + 4096);
}
panic("This should NOT happen!");
diff --git a/src/kernel/lib/stdio.h b/src/kernel/lib/stdio.h
index d102dd6..8299dea 100644
--- a/src/kernel/lib/stdio.h
+++ b/src/kernel/lib/stdio.h
@@ -9,8 +9,10 @@ char *readline();
void writec(char c);
-void vprintf(const char *format, va_list args);
+void vprintf(const char *fmt, va_list args);
-void printf(const char *format, ...);
+void printf(const char *fmt, ...);
+
+void serial_printf(const char *fmt, ...);
#endif
diff --git a/src/kernel/lib/stdio/debug.c b/src/kernel/lib/stdio/debug.c
new file mode 100644
index 0000000..d66ee59
--- /dev/null
+++ b/src/kernel/lib/stdio/debug.c
@@ -0,0 +1,59 @@
+#include <stdarg.h>
+#include <stdint.h>
+#include <kernel/lib/string.h>
+#include <kernel/lib/stdlib.h>
+#include <kernel/io/io.h>
+
+void _write_serial(const char *data)
+{
+ for (size_t i = 0; i < strlen(data); i++) serial_put(data[i]);
+}
+
+void serial_printf(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+
+ uint8_t readyToFormat = 0;
+
+ char buff = 0;
+
+ for (; *fmt; fmt++) {
+ if (readyToFormat) {
+ if (*fmt == '%') {
+ serial_put('%');
+ readyToFormat = 0;
+ continue;
+ }
+
+ buff = *fmt;
+ if (buff == 's') {
+ const char *str = va_arg(args, const char*);
+ _write_serial(str);
+ readyToFormat = 0;
+ } else if (buff == 'x') {
+ char *p = htoa((uint32_t) va_arg(args, int));
+ _write_serial(p);
+ kfree(p);
+ readyToFormat = 0;
+ } else if (buff == 'd') {
+ char *p = itoa(va_arg(args, int));
+ _write_serial(p);
+ kfree(p);
+ readyToFormat = 0;
+ } else if (buff == 'c') {
+ serial_put((char) va_arg(args, int));
+ readyToFormat = 0;
+ }
+ } else {
+ if (*fmt == '%')
+ readyToFormat = 1;
+ else
+ serial_put(*fmt);
+ }
+ }
+
+ serial_put('\n');
+
+ va_end(args);
+} \ No newline at end of file
diff --git a/src/kernel/lib/stdio/vprintf.c b/src/kernel/lib/stdio/vprintf.c
index 885f584..81b7be0 100644
--- a/src/kernel/lib/stdio/vprintf.c
+++ b/src/kernel/lib/stdio/vprintf.c
@@ -4,7 +4,7 @@
#include <kernel/lib/string.h>
#include <kernel/lib/stdlib.h>
-void __writes(const char *data)
+void _writes(const char *data)
{
for (size_t i = 0; i < strlen(data); i++) writec(data[i]);
}
@@ -26,16 +26,16 @@ void vprintf(const char *fmt, va_list args)
buff = *fmt;
if (buff == 's') {
const char *str = va_arg(args, const char*);
- __writes(str);
+ _writes(str);
readyToFormat = 0;
} else if (buff == 'x') {
char *p = htoa((uint32_t) va_arg(args, int));
- __writes(p);
+ _writes(p);
kfree(p);
readyToFormat = 0;
} else if (buff == 'd') {
char *p = itoa(va_arg(args, int));
- __writes(p);
+ _writes(p);
kfree(p);
readyToFormat = 0;
} else if (buff == 'c') {
diff --git a/src/kernel/lib/stdlib/htoa.c b/src/kernel/lib/stdlib/htoa.c
index 85bd750..660e26c 100644
--- a/src/kernel/lib/stdlib/htoa.c
+++ b/src/kernel/lib/stdlib/htoa.c
@@ -2,7 +2,7 @@
#include <kernel/lib/string.h>
#include <kernel/lib/stdlib.h>
-static const char __HTOA_TABLE[] = "0123456789ABCDEF";
+static const char HTOA_TABLE[] = "0123456789ABCDEF";
char *htoa(uint32_t n)
{
@@ -10,7 +10,7 @@ char *htoa(uint32_t n)
int i = 0;
while (n) {
- ret[i++] = __HTOA_TABLE[n & 0xF];
+ ret[i++] = HTOA_TABLE[n & 0xF];
n >>= 4;
}
diff --git a/src/kernel/lib/stdlib/itoa.c b/src/kernel/lib/stdlib/itoa.c
index 897fd55..67273b3 100644
--- a/src/kernel/lib/stdlib/itoa.c
+++ b/src/kernel/lib/stdlib/itoa.c
@@ -4,7 +4,7 @@
#include <kernel/lib/stdlib.h>
#include <kernel/paging/paging.h>
-static const char __ITOA_TABLE[] = "0123456789";
+static const char ITOA_TABLE[] = "0123456789";
char *itoa(int n)
{
@@ -27,7 +27,7 @@ char *itoa(int n)
for (int i = 0; i < sz; i++) {
int digit = (n % pow(10, i + 1)) / pow(10, i);
- ret[i] = __ITOA_TABLE[digit];
+ ret[i] = ITOA_TABLE[digit];
}
ret[sz] = 0;
diff --git a/src/kernel/net/rtl8139.c b/src/kernel/net/rtl8139.c
index de68700..cfddebc 100644
--- a/src/kernel/net/rtl8139.c
+++ b/src/kernel/net/rtl8139.c
@@ -3,6 +3,7 @@
#include <kernel/system.h>
#include <kernel/interrupts/interrupts.h>
#include <kernel/lib/stdlib/liballoc.h>
+#include <kernel/lib/stdio.h>
int rtl_irq = 0;
uint8_t mac[6];
@@ -19,14 +20,14 @@ void find_rtl(uint32_t device, uint16_t vendor_id, uint16_t device_id, void *ext
void rtl8139_irq_handler(struct regs *r)
{
- serial_write("RTL INT!\n");
+ serial_printf("RTL INT!");
uint16_t status = inw(rtl_iobase + 0x3E);
if (!status) return;
outw(rtl_iobase + 0x3E, status);
if (status & 0x01 || status & 0x02) {
while ((inw(rtl_iobase + 0x37) & 0x01) == 0) {
- serial_write("RECEIVE\n");
+ serial_printf("RECEIVE");
// RECEIVE
}
}
diff --git a/src/kernel/paging/paging.c b/src/kernel/paging/paging.c
index 5797940..723e09a 100644
--- a/src/kernel/paging/paging.c
+++ b/src/kernel/paging/paging.c
@@ -1,7 +1,6 @@
#include <stdint.h>
#include <kernel/paging/paging.h>
#include <kernel/system.h>
-#include <kernel/io/io.h>
#include <kernel/lib/lib.h>
int paging_enabled = 0;
@@ -22,7 +21,6 @@ void paging_install()
paging_set_present(0, memory_get_all() >> 2); // /4
paging_set_used(0, ((uint32_t) ASM_KERNEL_END >> 12) + 1); // /4096
- paging_set_user(0, memory_get_all() >> 2); // TODO: Fix major security issue (all memory = shared)
paging_enable();
diff --git a/src/kernel/smbios/smbios.c b/src/kernel/smbios/smbios.c
index 95ea70c..967b683 100644
--- a/src/kernel/smbios/smbios.c
+++ b/src/kernel/smbios/smbios.c
@@ -1,8 +1,8 @@
#include <stdint.h>
#include <kernel/graphics/vesa.h>
#include <stddef.h>
-#include <kernel/io/io.h>
#include <kernel/smbios/smbios.h>
+#include <kernel/lib/stdio.h>
struct smbios_entry *smbios = 0;
@@ -46,7 +46,6 @@ struct smbios_entry *get_smbios()
void smbios_table(struct smbios_header *header)
{
- serial_write("\n\n");
- struct smbios_0 *table = (struct smbios_0 *) (header + sizeof(struct smbios_header));
- serial_write(table->bios_version);
+ // struct smbios_0 *table = (struct smbios_0 *) (header + sizeof(struct smbios_header));
+ // serial_printf("\n\n %d", table->bios_version);
}
diff --git a/src/kernel/syscall/actions/sys_paging_alloc.c b/src/kernel/syscall/actions/sys_paging_alloc.c
index fb4e415..57ffd39 100644
--- a/src/kernel/syscall/actions/sys_paging_alloc.c
+++ b/src/kernel/syscall/actions/sys_paging_alloc.c
@@ -1,6 +1,5 @@
#include <stdint.h>
#include <kernel/paging/paging.h>
-#include <kernel/io/io.h>
uint32_t sys_paging_alloc(uint32_t count)
{
diff --git a/src/kernel/syscall/actions/sys_read.c b/src/kernel/syscall/actions/sys_read.c
index 83e645c..ed2cca8 100644
--- a/src/kernel/syscall/actions/sys_read.c
+++ b/src/kernel/syscall/actions/sys_read.c
@@ -3,7 +3,6 @@
#include <kernel/input/input.h>
#include <kernel/lib/lib.h>
#include <kernel/lib/string.h>
-#include <kernel/io/io.h>
uint32_t sys_read(char *buf)
{
diff --git a/src/kernel/syscall/actions/sys_write.c b/src/kernel/syscall/actions/sys_write.c
index d395384..76d88b8 100644
--- a/src/kernel/syscall/actions/sys_write.c
+++ b/src/kernel/syscall/actions/sys_write.c
@@ -1,7 +1,6 @@
#include <stdint.h>
#include <kernel/lib/stdio.h>
#include <kernel/lib/string.h>
-#include <kernel/io/io.h>
uint32_t sys_write(char *buf)
{
@@ -11,7 +10,6 @@ uint32_t sys_write(char *buf)
uint32_t sys_writec(char ch)
{
- serial_write_hex(ch);
writec((char) ch);
return 0;
} \ No newline at end of file
diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c
index 7d5420d..5f32c42 100644
--- a/src/kernel/syscall/syscall.c
+++ b/src/kernel/syscall/syscall.c
@@ -1,9 +1,8 @@
#include <stdint.h>
#include <kernel/syscall/syscall.h>
#include <kernel/interrupts/interrupts.h>
-#include <kernel/io/io.h>
-#include <kernel/paging/paging.h>
#include <kernel/system.h>
+#include <kernel/lib/stdio.h>
typedef uint32_t (*syscall_func)(unsigned int, ...);
@@ -20,7 +19,7 @@ uint32_t (*syscalls[])() = {
void syscall_handler(struct regs *r)
{
- serial_write("Received syscall!\n");
+ serial_printf("Received syscall!");
if (r->eax >= sizeof(syscalls) / sizeof(*syscalls))
return;
@@ -29,6 +28,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);
+
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 179b2a2..ada1750 100644
--- a/src/kernel/system.c
+++ b/src/kernel/system.c
@@ -89,9 +89,7 @@ void panic(char *msg)
asm ("cli");
vesa_set_color(vesa_dark_red);
kernel_time();
- serial_write("\nPANIC: ");
- serial_write(msg);
- serial_write(" - System halted!\n");
+ serial_printf("PANIC: %s - System halted!", msg);
printf("PANIC: %s - System halted!\n", msg);
halt_loop();
}
@@ -105,7 +103,7 @@ void assert(int x)
void halt_loop()
{
- serial_write("\n!!! HALT !!!\n");
+ serial_printf("\n!!! HALT !!!");
asm ("cli");
loop:
asm ("hlt");
diff --git a/src/userspace/main.c b/src/userspace/main.c
index 982a5ff..62bdc4e 100644
--- a/src/userspace/main.c
+++ b/src/userspace/main.c
@@ -1,6 +1,6 @@
#include <syscall.h>
#include <mlibc/stdio.h>
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
int32_t starts_with(const char *a, const char *b)
{
@@ -11,10 +11,11 @@ int32_t starts_with(const char *a, const char *b)
void user_main()
{
- printf("> Successfully switched to usermode!");
+ char text[] = "> Successfully switched to usermode!\n";
+ printf(text);
// init_framebuffer();
- writec((char) strlen("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
+ // writec((char) strlen("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
while (1) {
char *input = readline();
diff --git a/src/userspace/mlibc/stdio/readline.c b/src/userspace/mlibc/stdio/readline.c
index 91b5da0..8937702 100644
--- a/src/userspace/mlibc/stdio/readline.c
+++ b/src/userspace/mlibc/stdio/readline.c
@@ -1,16 +1,14 @@
-#include <syscall.h>
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
#include <mlibc/stdio.h>
char *readline()
{
- char *ret = "";
+ char ret[256] = {'\0'};
char buf = 0;
while (buf != '\n') {
buf = getch();
writec(buf);
strcpy(ret, &buf);
}
- strcpy(ret, &buf);
return ret;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/stdio/vprintf.c b/src/userspace/mlibc/stdio/vprintf.c
index 1d43c77..2536b79 100644
--- a/src/userspace/mlibc/stdio/vprintf.c
+++ b/src/userspace/mlibc/stdio/vprintf.c
@@ -3,7 +3,7 @@
#include <mlibc/stdio.h>
#include <mlibc/stdlib.h>
-void __writes(const char *data)
+void _writes(const char *data)
{
for (size_t i = 0; i < strlen(data); i++) writec(data[i]);
}
@@ -25,16 +25,16 @@ void vprintf(const char *fmt, va_list args)
buff = *fmt;
if (buff == 's') {
const char *str = va_arg(args, const char*);
- __writes(str);
+ _writes(str);
readyToFormat = 0;
} else if (buff == 'x') {
char *p = htoa((uint32_t) va_arg(args, int));
- __writes(p);
+ _writes(p);
free(p);
readyToFormat = 0;
} else if (buff == 'd') {
char *p = itoa(va_arg(args, int));
- __writes(p);
+ _writes(p);
free(p);
readyToFormat = 0;
} else if (buff == 'c') {
diff --git a/src/userspace/mlibc/stdlib/atoi.c b/src/userspace/mlibc/stdlib/atoi.c
index 0643372..67a603e 100644
--- a/src/userspace/mlibc/stdlib/atoi.c
+++ b/src/userspace/mlibc/stdlib/atoi.c
@@ -1,7 +1,7 @@
#include <mlibc/math.h>
#include <stddef.h>
#include <stdint.h>
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
int atoi(char *str)
{
diff --git a/src/userspace/mlibc/stdlib/htoa.c b/src/userspace/mlibc/stdlib/htoa.c
index 098e1c8..579db5d 100644
--- a/src/userspace/mlibc/stdlib/htoa.c
+++ b/src/userspace/mlibc/stdlib/htoa.c
@@ -1,8 +1,8 @@
#include <stdint.h>
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
#include <mlibc/stdlib.h>
-static const char __HTOA_TABLE[] = "0123456789ABCDEF";
+static const char HTOA_TABLE[] = "0123456789ABCDEF";
char *htoa(uint32_t n)
{
@@ -11,7 +11,7 @@ char *htoa(uint32_t n)
int i = 0;
while (n) {
- ret[i++] = __HTOA_TABLE[n & 0xF];
+ ret[i++] = HTOA_TABLE[n & 0xF];
n >>= 4;
}
diff --git a/src/userspace/mlibc/stdlib/htoi.c b/src/userspace/mlibc/stdlib/htoi.c
index 489e5c0..93b387a 100644
--- a/src/userspace/mlibc/stdlib/htoi.c
+++ b/src/userspace/mlibc/stdlib/htoi.c
@@ -1,6 +1,6 @@
#include <stddef.h>
#include <mlibc/math.h>
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
int htoi(char *str)
{
diff --git a/src/userspace/mlibc/stdlib/itoa.c b/src/userspace/mlibc/stdlib/itoa.c
index 55c1383..567824f 100644
--- a/src/userspace/mlibc/stdlib/itoa.c
+++ b/src/userspace/mlibc/stdlib/itoa.c
@@ -1,9 +1,8 @@
#include <stdint.h>
#include <mlibc/math.h>
-#include <mlibc/string.h>
#include <mlibc/stdlib.h>
-static const char __ITOA_TABLE[] = "0123456789";
+static const char ITOA_TABLE[] = "0123456789";
char *itoa(int n)
{
@@ -28,7 +27,7 @@ char *itoa(int n)
for (int i = 0; i < sz; i++) {
int digit = (n % pow(10, i + 1)) / pow(10, i);
- ret[i] = __ITOA_TABLE[digit];
+ ret[i] = ITOA_TABLE[digit];
}
ret[sz] = 0;
diff --git a/src/userspace/mlibc/string/strcat.c b/src/userspace/mlibc/string/strcat.c
index 0448430..2876604 100644
--- a/src/userspace/mlibc/string/strcat.c
+++ b/src/userspace/mlibc/string/strcat.c
@@ -1,4 +1,4 @@
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
void strcat(char *dest, const char *orig)
{
diff --git a/src/userspace/mlibc/string/strcati.c b/src/userspace/mlibc/string/strcati.c
index 8fdcc1a..312792f 100644
--- a/src/userspace/mlibc/string/strcati.c
+++ b/src/userspace/mlibc/string/strcati.c
@@ -1,4 +1,4 @@
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
void strcati(char *dest, const char *orig)
{
diff --git a/src/userspace/mlibc/string/strcmp.c b/src/userspace/mlibc/string/strcmp.c
index be6c17a..903234f 100644
--- a/src/userspace/mlibc/string/strcmp.c
+++ b/src/userspace/mlibc/string/strcmp.c
@@ -1,4 +1,4 @@
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
char strcmp(const char *a, const char *b)
{
diff --git a/src/userspace/mlibc/string/strcpy.c b/src/userspace/mlibc/string/strcpy.c
index 8dfa65f..18f3f25 100644
--- a/src/userspace/mlibc/string/strcpy.c
+++ b/src/userspace/mlibc/string/strcpy.c
@@ -1,4 +1,4 @@
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
void strcpy(char *dest, const char *orig)
{
diff --git a/src/userspace/mlibc/string/strdisp.c b/src/userspace/mlibc/string/strdisp.c
index d793718..5d8ee7d 100644
--- a/src/userspace/mlibc/string/strdisp.c
+++ b/src/userspace/mlibc/string/strdisp.c
@@ -1,4 +1,4 @@
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
void strdisponce(char *str)
{
diff --git a/src/userspace/mlibc/string/strdup.c b/src/userspace/mlibc/string/strdup.c
index bb3597d..e77536c 100644
--- a/src/userspace/mlibc/string/strdup.c
+++ b/src/userspace/mlibc/string/strdup.c
@@ -1,4 +1,4 @@
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
#include <mlibc/stdlib.h>
char *strdup(const char *orig)
diff --git a/src/userspace/mlibc/string/strinv.c b/src/userspace/mlibc/string/strinv.c
index 71f3355..4f54775 100644
--- a/src/userspace/mlibc/string/strinv.c
+++ b/src/userspace/mlibc/string/strinv.c
@@ -1,4 +1,4 @@
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
void strinv(char *str)
{
diff --git a/src/userspace/mlibc/string/strlen.c b/src/userspace/mlibc/string/strlen.c
index f6a06a4..c8d9c4f 100644
--- a/src/userspace/mlibc/string/strlen.c
+++ b/src/userspace/mlibc/string/strlen.c
@@ -1,4 +1,4 @@
-#include <mlibc/string.h>
+#include <mlibc/stdlib.h>
size_t strlen(const char *str)
{
diff --git a/src/userspace/syscall.h b/src/userspace/syscall.h
index 8dd647f..60fb288 100644
--- a/src/userspace/syscall.h
+++ b/src/userspace/syscall.h
@@ -18,25 +18,25 @@
#define DEFN_SYSCALL1(fn, num, P1) \
int syscall_##fn(P1 p1) { \
- int __res; __asm__ __volatile__("int $0x80" \
+ int __res; __asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
: "=a" (__res) \
- : "0" (num), "b" ((int)(p1)) \
+ : "0" (num), "r" ((int)(p1)) \
: "memory"); \
return __res; \
}
#define DEFN_SYSCALL2(fn, num, P1, P2) \
int syscall_##fn(P1 p1, P2 p2) { \
- int __res; __asm__ __volatile__("int $0x80" \
+ int __res; __asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
: "=a" (__res) \
- : "0" (num), "b" ((int)(p1)), "c"((int)(p2)) \
+ : "0" (num), "r" ((int)(p1)), "c"((int)(p2)) \
: "memory"); \
return __res; \
}
#define DEFN_SYSCALL3(fn, num, P1, P2, P3) \
int syscall_##fn(P1 p1, P2 p2, P3 p3) { \
- int __res; __asm__ __volatile__("int $0x80" \
+ int __res; __asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
: "=a" (__res) \
: "0" (num), "b" ((int)(p1)), "c"((p2)), "d"((int)(p3)) \
: "memory"); \
@@ -45,7 +45,7 @@
#define DEFN_SYSCALL4(fn, num, P1, P2, P3, P4) \
int syscall_##fn(P1 p1, P2 p2, P3 p3, P4 p4) { \
- int __res; __asm__ __volatile__("int $0x80" \
+ int __res; __asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
: "=a" (__res) \
: "0" (num), "b" ((int)(p1)), "c"((int)(p2)), "d"((int)(p3)), "S"((int)(p4)) \
: "memory"); \
@@ -54,7 +54,7 @@
#define DEFN_SYSCALL5(fn, num, P1, P2, P3, P4, P5) \
int syscall_##fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { \
- int __res; __asm__ __volatile__("int $0x80" \
+ int __res; __asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
: "=a" (__res) \
: "0" (num), "b" ((int)(p1)), "c"((int)(p2)), "d"((int)(p3)), "S"((int)(p4)), "D"((int)(p5)) \
: "memory"); \