aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2019-11-24 23:34:32 +0100
committerMarvin Borner2019-11-24 23:34:32 +0100
commitbb57b124d1bb385d41747f50be7dd4f3625539c1 (patch)
treefe461afad63df40571784565e8d435cba8c8e59c
parentf9c50b9ff23e9a3e8db5826fef7a6e7ebb8af21d (diff)
Major coding style reformatting -> Kernighan & Ritchie
This project now (hopefully) uses the same style recommended by Kernighan and Ritchie and used in the Linux Kernel
-rw-r--r--Makefile5
-rw-r--r--src/bootloader/cd.asm4
-rw-r--r--src/bootloader/hdd1.asm2
-rw-r--r--src/bootloader/hdd2.asm18
-rw-r--r--src/kernel/acpi/acpi.c52
-rw-r--r--src/kernel/acpi/acpi.h2
-rw-r--r--src/kernel/cmos/rtc.c28
-rw-r--r--src/kernel/commands/command.c6
-rw-r--r--src/kernel/fs/ata_pio.c122
-rw-r--r--src/kernel/fs/ata_pio.h30
-rw-r--r--src/kernel/fs/atapi_pio.c12
-rw-r--r--src/kernel/fs/atapi_pio.h6
-rw-r--r--src/kernel/fs/install.c21
-rw-r--r--src/kernel/fs/iso9660/iso9660.c20
-rw-r--r--src/kernel/fs/iso9660/iso9660.h8
-rw-r--r--src/kernel/fs/marfs/directory.c44
-rw-r--r--src/kernel/fs/marfs/disklevel.c9
-rw-r--r--src/kernel/fs/marfs/marfs.h42
-rw-r--r--src/kernel/fs/marfs/new_file.c94
-rw-r--r--src/kernel/fs/marfs/read_whole_file.c40
-rw-r--r--src/kernel/fs/marfs/sectorlevel.c71
-rw-r--r--src/kernel/fs/vfs.c18
-rw-r--r--src/kernel/gdt/gdt.c14
-rw-r--r--src/kernel/graphics/vesa.c57
-rw-r--r--src/kernel/input/ps2/keyboard.c20
-rw-r--r--src/kernel/input/ps2/mouse.c41
-rw-r--r--src/kernel/interrupts/idt.c8
-rw-r--r--src/kernel/interrupts/irq.c44
-rw-r--r--src/kernel/interrupts/isr.c24
-rw-r--r--src/kernel/io/io.c69
-rw-r--r--src/kernel/io/io.h12
-rw-r--r--src/kernel/kernel.c19
-rw-r--r--src/kernel/lib/memory.c35
-rw-r--r--src/kernel/paging/paging.c66
-rw-r--r--src/kernel/smbios/smbios.c26
-rw-r--r--src/kernel/smbios/smbios.h17
-rw-r--r--src/kernel/sound/frequency.c23
-rw-r--r--src/kernel/syscall/syscall.c8
-rw-r--r--src/kernel/system.c34
-rw-r--r--src/kernel/timer/timer.c24
-rw-r--r--src/mlibc/math/pow.c3
-rw-r--r--src/mlibc/stdio/printf.c6
-rw-r--r--src/mlibc/stdio/writec.c3
-rw-r--r--src/mlibc/stdlib.h4
-rw-r--r--src/mlibc/stdlib/atoi.c3
-rw-r--r--src/mlibc/stdlib/htoa.c3
-rw-r--r--src/mlibc/stdlib/htoi.c3
-rw-r--r--src/mlibc/stdlib/itoa.c3
-rw-r--r--src/mlibc/stdlib/liballoc.c41
-rw-r--r--src/mlibc/string/strcat.c3
-rw-r--r--src/mlibc/string/strcati.c3
-rw-r--r--src/mlibc/string/strcmp.c3
-rw-r--r--src/mlibc/string/strcpy.c3
-rw-r--r--src/mlibc/string/strdisp.c6
-rw-r--r--src/mlibc/string/strdup.c3
-rw-r--r--src/mlibc/string/strinv.c3
-rw-r--r--src/mlibc/string/strlen.c3
-rw-r--r--src/userspace/main.c3
58 files changed, 740 insertions, 554 deletions
diff --git a/Makefile b/Makefile
index 196cfa2..11534d0 100644
--- a/Makefile
+++ b/Makefile
@@ -8,10 +8,11 @@ export PATH := $(PREFIX)/bin:$(PATH)
clean:
@-rm -rf ./build ./iso
- @echo Cleaned build directory
+ @echo "Cleaned build directory"
build: clean
@set -e; \
+ echo "Building..."; \
mkdir ./build/; \
# Assemble ASM files
@@ -34,7 +35,7 @@ build: clean
nasm ./src/bootloader/cd.asm -f bin -o ./iso/boot/cd.bin || exit; \
nasm ./src/bootloader/hdd1.asm -f bin -o ./iso/boot/hdd1.bin || exit; \
nasm ./src/bootloader/hdd2.asm -f bin -o ./iso/boot/hdd2.bin || exit; \
- genisoimage -no-emul-boot -b boot/cd.bin -o ./build/melvix.iso ./iso;
+ genisoimage -quiet -input-charset utf-8 -no-emul-boot -b boot/cd.bin -o ./build/melvix.iso ./iso;
cross:
@set -e; \
diff --git a/src/bootloader/cd.asm b/src/bootloader/cd.asm
index 1e83a3a..ec9fc9d 100644
--- a/src/bootloader/cd.asm
+++ b/src/bootloader/cd.asm
@@ -159,7 +159,7 @@ checkA20:
ret
welcome db "Melvix", 0x0A, 0x0D, 0x00
-nolba db "BIOS lacks support for LBA addressing.", 0x00
+nolba db "BIOS lacks support for lba addressing.", 0x00
noboot db "Boot directory could not be found.", 0x00
noa20 db "A20 could not be enabled.", 0
loading db "Loading kernel...", 0x0A, 0x0D, 0x00
@@ -169,7 +169,7 @@ nomem db "BIOS does not support memory detection!", 0
memno20 db "BIOS returns memory detection with 24 bytes. This has never been seen!", 0
start:
- ; Check if LBA is supported by the BIOS.
+ ; Check if lba is supported by the BIOS.
mov ah, 0x41
mov bx, 0x55AA
int 0x13
diff --git a/src/bootloader/hdd1.asm b/src/bootloader/hdd1.asm
index c347625..514deca 100644
--- a/src/bootloader/hdd1.asm
+++ b/src/bootloader/hdd1.asm
@@ -72,7 +72,7 @@ readwholefile:
ret
welcome db "Melvix", 0x0A, 0x0D, 0x00
-nolba db "BIOS lacks support for LBA addressing.", 0x00
+nolba db "BIOS lacks support for lba addressing.", 0x00
signaturebad db "Bad disk signature.", 0x00
start:
diff --git a/src/bootloader/hdd2.asm b/src/bootloader/hdd2.asm
index e289c39..3330c96 100644
--- a/src/bootloader/hdd2.asm
+++ b/src/bootloader/hdd2.asm
@@ -48,17 +48,17 @@ checkA20:
popf
ret
-last_maxlevel db 0
+last_max_level db 0
getrecursive:
push edi
push esi
push ecx
mov eax, edi
- cmp al, byte [last_maxlevel]
- jna .last_maxlevel_updated
- mov byte [last_maxlevel], al
- .last_maxlevel_updated:
+ cmp al, byte [last_max_level]
+ jna .last_max_level_updated
+ mov byte [last_max_level], al
+ .last_max_level_updated:
mov eax, esi
call 0x7c26
@@ -66,19 +66,19 @@ getrecursive:
mov eax, dword [esp]
sub eax, 10
- cmp byte [last_maxlevel], 1
+ cmp byte [last_max_level], 1
jna .check1
mov ebx, 1
shl ebx, 7
sub eax, ebx
.check1:
- cmp byte [last_maxlevel], 2
+ cmp byte [last_max_level], 2
jna .check2
mov ebx, 1
shl ebx, 14
sub eax, ebx
.check2:
- cmp byte [last_maxlevel], 3
+ cmp byte [last_max_level], 3
jna .check3
mov ebx, 1
shl ebx, 21
@@ -102,7 +102,7 @@ getrecursive:
mov ecx, [esp]
call getrecursive
.finish_recursion:
- mov byte [last_maxlevel], 0
+ mov byte [last_max_level], 0
pop ecx
pop esi
diff --git a/src/kernel/acpi/acpi.c b/src/kernel/acpi/acpi.c
index 919d0be..ab019c8 100644
--- a/src/kernel/acpi/acpi.c
+++ b/src/kernel/acpi/acpi.c
@@ -20,16 +20,17 @@ int SLP_EN;
int SCI_EN;
char PM1_CNT_LEN;
-unsigned int *acpi_check_rsd_ptr(unsigned int *ptr) {
+unsigned int *acpi_check_rsd_ptr(unsigned int *ptr)
+{
char *sig = "RSD PTR ";
- struct RSDPtr *rsdp = (struct RSDPtr *) ptr;
+ struct RSD_ptr *rsdp = (struct RSD_ptr *) ptr;
char *bptr;
char check = 0;
unsigned int i;
if (memcmp(sig, rsdp, 8) == 0) {
bptr = (char *) ptr;
- for (i = 0; i < sizeof(struct RSDPtr); i++) {
+ for (i = 0; i < sizeof(struct RSD_ptr); i++) {
check += *bptr;
bptr++;
}
@@ -42,7 +43,8 @@ unsigned int *acpi_check_rsd_ptr(unsigned int *ptr) {
return NULL;
}
-unsigned int *acpi_get_rsd_ptr() {
+unsigned int *acpi_get_rsd_ptr()
+{
unsigned int *addr;
unsigned int *rsdp;
@@ -64,20 +66,21 @@ unsigned int *acpi_get_rsd_ptr() {
return NULL;
}
-int acpi_enable() {
- if ((receive_w((unsigned int) PM1a_CNT) & SCI_EN) == 0) {
+int acpi_enable()
+{
+ if ((inw((unsigned int) PM1a_CNT) & SCI_EN) == 0) {
if (SMI_CMD != 0 && ACPI_ENABLE != 0) {
- send_b((unsigned int) SMI_CMD, ACPI_ENABLE); // Enable ACPI
+ outb((unsigned int) SMI_CMD, ACPI_ENABLE); // Enable ACPI
// Try 3s until ACPI is enabled
int i;
for (i = 0; i < 300; i++) {
- if ((receive_w((unsigned int) PM1a_CNT) & SCI_EN) == 1)
+ if ((inw((unsigned int) PM1a_CNT) & SCI_EN) == 1)
break;
timer_wait(1);
}
if (PM1b_CNT != 0)
for (; i < 300; i++) {
- if ((receive_w((unsigned int) PM1b_CNT) & SCI_EN) == 1)
+ if ((inw((unsigned int) PM1b_CNT) & SCI_EN) == 1)
break;
timer_wait(1);
}
@@ -97,7 +100,8 @@ int acpi_enable() {
}
}
-int acpi_install() {
+int acpi_install()
+{
unsigned int *ptr = acpi_get_rsd_ptr();
int success = 0;
@@ -109,7 +113,7 @@ int acpi_install() {
while (0 < entries--) {
if (memcmp((unsigned int *) *ptr, "FACP", 4) == 0) {
- fadt = (struct FADT *) *ptr;
+ fadt = (struct FADT *) *ptr; // TODO: Allocate ACPI tables after paging (page fault)!
if (memcmp((unsigned int *) fadt->DSDT, "DSDT", 4) == 0) {
char *S5Addr = (char *) fadt->DSDT + 36;
int dsdt_length = *(fadt->DSDT + 1) - 36;
@@ -148,7 +152,7 @@ int acpi_install() {
SCI_EN = 1;
acpi_enable();
- vga_log("Installed ACPI", 4);
+ vga_log("Installed ACPI", 3);
success = 1;
} // Else: \_S5 parse error
@@ -169,29 +173,31 @@ int acpi_install() {
return success == 1 ? 0 : -1;
}
-void acpi_poweroff() {
- asm volatile ("cli");
+void acpi_poweroff()
+{
+ asm ("cli");
if (SCI_EN == 0) {
warn("ACPI shutdown is not supported\n");
return;
}
// Send shutdown command
- send_w((unsigned int) PM1a_CNT, SLP_TYPa | SLP_EN);
+ outw((unsigned int) PM1a_CNT, SLP_TYPa | SLP_EN);
if (PM1b_CNT != 0)
- send_w((unsigned int) PM1b_CNT, SLP_TYPb | SLP_EN);
+ outw((unsigned int) PM1b_CNT, SLP_TYPb | SLP_EN);
else {
- send_w(0xB004, 0x2000); // Bochs
- send_w(0x604, 0x2000); // QEMU
- send_w(0x4004, 0x3400); // VirtualBox
+ outw(0xB004, 0x2000); // Bochs
+ outw(0x604, 0x2000); // QEMU
+ outw(0x4004, 0x3400); // VirtualBox
}
}
-void reboot() {
- asm volatile ("cli");
+void reboot()
+{
+ asm ("cli");
uint8_t good = 0x02;
while (good & 0x02)
- good = receive_b(0x64);
- send_b(0x64, 0xFE);
+ good = inb(0x64);
+ outb(0x64, 0xFE);
halt_loop();
}
diff --git a/src/kernel/acpi/acpi.h b/src/kernel/acpi/acpi.h
index 31b4841..43cb61e 100644
--- a/src/kernel/acpi/acpi.h
+++ b/src/kernel/acpi/acpi.h
@@ -17,7 +17,7 @@ void reboot();
*/
void acpi_poweroff();
-struct RSDPtr {
+struct RSD_ptr {
char signature[8];
char checksum;
char oem_id[6];
diff --git a/src/kernel/cmos/rtc.c b/src/kernel/cmos/rtc.c
index 20e1b50..044c58b 100644
--- a/src/kernel/cmos/rtc.c
+++ b/src/kernel/cmos/rtc.c
@@ -9,18 +9,21 @@ unsigned char day;
unsigned char month;
unsigned int year;
-int get_update_in_progress_flag() {
- send_b(0x70, 0x0A);
- return (receive_b(0x71) & 0x80);
+int get_update_in_progress_flag()
+{
+ outb(0x70, 0x0A);
+ return (inb(0x71) & 0x80);
}
-unsigned char get_rtc_register(int reg) {
- send_b(0x70, reg);
- return receive_b(0x71);
+unsigned char get_rtc_register(int reg)
+{
+ outb(0x70, reg);
+ return inb(0x71);
}
-void read_rtc() {
- unsigned int century;
+void read_rtc()
+{
+ unsigned int century = 20; // ...
unsigned char last_second;
unsigned char last_minute;
unsigned char last_hour;
@@ -37,7 +40,7 @@ void read_rtc() {
day = get_rtc_register(0x07);
month = get_rtc_register(0x08);
year = get_rtc_register(0x09);
- century = get_rtc_register(fadt->century);
+ // century = get_rtc_register(fadt->century); // TODO: Fix fadt table (page fault!)
// Try until the values are the same (fix for RTC updates)
do {
@@ -56,7 +59,7 @@ void read_rtc() {
day = get_rtc_register(0x07);
month = get_rtc_register(0x08);
year = get_rtc_register(0x09);
- century = get_rtc_register(fadt->century);
+ // century = get_rtc_register(fadt->century);
} while ((last_second != second) || (last_minute != minute) || (last_hour != hour) ||
(last_day != day) || (last_month != month) || (last_year != year) ||
(last_century != century));
@@ -70,7 +73,7 @@ void read_rtc() {
day = (day & 0x0F) + ((day / 16) * 10);
month = (month & 0x0F) + ((month / 16) * 10);
year = (year & 0x0F) + ((year / 16) * 10);
- century = (century & 0x0F) + ((century / 16) * 10);
+ // century = (century & 0x0F) + ((century / 16) * 10);
}
year += century * 100;
@@ -81,7 +84,8 @@ void read_rtc() {
}
}
-void write_time() {
+void write_time()
+{
read_rtc();
vesa_draw_string("Current time: ");
vesa_draw_number(hour);
diff --git a/src/kernel/commands/command.c b/src/kernel/commands/command.c
index 6b1afcc..9b6060e 100644
--- a/src/kernel/commands/command.c
+++ b/src/kernel/commands/command.c
@@ -6,13 +6,15 @@
#include <kernel/timer/timer.h>
#include <mlibc/string.h>
-int32_t starts_with(const char *a, const char *b) {
+int32_t starts_with(const char *a, const char *b)
+{
size_t length_pre = strlen(b);
size_t length_main = strlen(a);
return length_main < length_pre ? 0 : memcmp(b, a, length_pre) == 0;
}
-void exec_command(char *command) {
+void exec_command(char *command)
+{
if (starts_with(command, "ls"))
vesa_draw_string("Listing files\n");
else if (starts_with(command, "help"))
diff --git a/src/kernel/fs/ata_pio.c b/src/kernel/fs/ata_pio.c
index d3544ba..78cf7ac 100644
--- a/src/kernel/fs/ata_pio.c
+++ b/src/kernel/fs/ata_pio.c
@@ -3,123 +3,127 @@
#include <kernel/fs/ata_pio.h>
#include <kernel/interrupts/interrupts.h>
-struct ATA_INTERFACE *new_ATA(uint8_t master, uint16_t portBase) {
- struct ATA_INTERFACE *ret = kmalloc(sizeof(struct ATA_INTERFACE));
+struct ata_interface *new_ata(uint8_t master, uint16_t port_base)
+{
+ struct ata_interface *ret = kmalloc(sizeof(struct ata_interface));
ret->master = master;
- ret->dataPort = portBase;
- ret->errorPort = portBase + 0x1;
- ret->sectorCountPort = portBase + 0x2;
- ret->lbaLowPort = portBase + 0x3;
- ret->lbaMidPort = portBase + 0x4;
- ret->lbaHiPort = portBase + 0x5;
- ret->devicePort = portBase + 0x6;
- ret->commandPort = portBase + 0x7;
- ret->controlPort = portBase + 0x206;
-
- // isr_ignore(0x06);
+ ret->data_port = port_base;
+ ret->error_port = port_base + 0x1;
+ ret->sector_count_port = port_base + 0x2;
+ ret->lba_low_port = port_base + 0x3;
+ ret->lba_mid_port = port_base + 0x4;
+ ret->lba_high_port = port_base + 0x5;
+ ret->device_port = port_base + 0x6;
+ ret->command_port = port_base + 0x7;
+ ret->control_port = port_base + 0x206;
+
// isr_ignore(0x2E);
// isr_ignore(0x2F);
return ret;
}
-uint8_t ATA_identify(struct ATA_INTERFACE *iface, uint16_t *retdata) {
- send_b(iface->devicePort, iface->master ? 0xA0 : 0xB0);
- send_b(iface->controlPort, 0);
+uint8_t ata_identify(struct ata_interface *interface, uint16_t *ret_data)
+{
+ outb(interface->device_port, interface->master ? 0xA0 : 0xB0);
+ outb(interface->control_port, 0);
- send_b(iface->devicePort, 0xA0);
- uint8_t status = receive_b(iface->commandPort);
+ outb(interface->device_port, 0xA0);
+ uint8_t status = inb(interface->command_port);
if (status == 0xFF) return 1;
- send_b(iface->devicePort, iface->master ? 0xA0 : 0xB0);
- send_b(iface->sectorCountPort, 0);
- send_b(iface->lbaLowPort, 0);
- send_b(iface->lbaMidPort, 0);
- send_b(iface->lbaHiPort, 0);
- send_b(iface->commandPort, 0xEC); // Identify command
+ outb(interface->device_port, interface->master ? 0xA0 : 0xB0);
+ outb(interface->sector_count_port, 0);
+ outb(interface->lba_low_port, 0);
+ outb(interface->lba_mid_port, 0);
+ outb(interface->lba_high_port, 0);
+ outb(interface->command_port, 0xEC); // Identify command
- status = receive_b(iface->commandPort);
+ status = inb(interface->command_port);
if (!status) return 1;
while (((status & 0x80) == 0x80) && ((status & 0x01) != 0x01)) {
- status = receive_b(iface->commandPort);
+ status = inb(interface->command_port);
}
if (status & 0x01) return 1;
- for (int i = 0; i < 256; i++) retdata[i] = receive_w(iface->dataPort);
+ for (int i = 0; i < 256; i++) ret_data[i] = inw(interface->data_port);
return 0;
}
-uint8_t *ATA_read28(struct ATA_INTERFACE *iface, uint32_t sector) {
+uint8_t *ata_read28(struct ata_interface *interface, uint32_t sector)
+{
if (sector > 0x0FFFFFFF) return 0;
- send_b(iface->devicePort, (iface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24));
+ outb(interface->device_port, (interface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24));
- uint8_t status;
- for (int i = 0; i < 5; i++) status = receive_b(iface->commandPort);
+ uint8_t status = 0;
+ for (int i = 0; i < 5; i++) status = inb(interface->command_port);
if (status == 0xFF) return 0;
- send_b(iface->errorPort, 0);
- send_b(iface->sectorCountPort, 1);
- send_b(iface->lbaLowPort, sector & 0x000000FF);
- send_b(iface->lbaMidPort, (sector & 0x0000FF00) >> 8);
- send_b(iface->lbaHiPort, (sector & 0x00FF0000) >> 16);
- send_b(iface->commandPort, 0x20); // Read command
+ outb(interface->error_port, 0);
+ outb(interface->sector_count_port, 1);
+ outb(interface->lba_low_port, sector & 0x000000FF);
+ outb(interface->lba_mid_port, (sector & 0x0000FF00) >> 8);
+ outb(interface->lba_high_port, (sector & 0x00FF0000) >> 16);
+ outb(interface->command_port, 0x20); // Read command
- status = receive_b(iface->commandPort);
- while ((status & 0x80) && !(status & 0x01)) status = receive_b(iface->commandPort);
+ status = inb(interface->command_port);
+ while ((status & 0x80) && !(status & 0x01)) status = inb(interface->command_port);
uint8_t *ret = kmalloc(BYTES_PER_SECTOR);
for (int i = 0; i < BYTES_PER_SECTOR; i += 2) {
- uint16_t data = receive_w(iface->dataPort);
+ uint16_t data = inw(interface->data_port);
ret[i] = data & 0xFF;
ret[i + 1] = (data >> 8) & 0xFF;
}
return ret;
}
-uint8_t ATA_write28(struct ATA_INTERFACE *iface, uint32_t sector, uint8_t *contents) {
+uint8_t ata_write28(struct ata_interface *interface, uint32_t sector, const uint8_t *contents)
+{
if (sector > 0x0FFFFFFF) return 1;
- asm volatile ("cli");
+ asm ("cli");
- send_b(iface->devicePort, (iface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24));
+ outb(interface->device_port, (interface->master ? 0xE0 : 0xF0) | ((sector & 0x0F000000) >> 24));
- uint8_t status;
- for (int i = 0; i < 5; i++) status = receive_b(iface->commandPort);
+ uint8_t status = 0;
+ for (int i = 0; i < 5; i++) status = inb(interface->command_port);
if (status == 0xFF) return 1;
- send_b(iface->errorPort, 0);
- send_b(iface->sectorCountPort, 1);
- send_b(iface->lbaLowPort, sector & 0x000000FF);
- send_b(iface->lbaMidPort, (sector & 0x0000FF00) >> 8);
- send_b(iface->lbaHiPort, (sector & 0x00FF0000) >> 16);
- send_b(iface->commandPort, 0x30); // Write command
+ outb(interface->error_port, 0);
+ outb(interface->sector_count_port, 1);
+ outb(interface->lba_low_port, sector & 0x000000FF);
+ outb(interface->lba_mid_port, (sector & 0x0000FF00) >> 8);
+ outb(interface->lba_high_port, (sector & 0x00FF0000) >> 16);
+ outb(interface->command_port, 0x30); // Write command
- while ((status & 0x80) || !(status & 0x08)) status = receive_b(iface->commandPort);
+ while ((status & 0x80) || !(status & 0x08)) status = inb(interface->command_port);
if (status & (0x01 || 0x20)) return 2;
for (int i = 0; i < BYTES_PER_SECTOR; i += 2) {
uint16_t data = contents[i];
data |= ((uint16_t) contents[i + 1]) << 8;
- send_w(iface->dataPort, data);
+ outw(interface->data_port, data);
}
- send_b(iface->commandPort, 0xE7); // Flush command
+ outb(interface->command_port, 0xE7); // Flush command
- for (int i = 0; i < 5; i++) status = receive_b(iface->commandPort);
+ for (int i = 0; i < 5; i++) status = inb(interface->command_port);
if (!status) return 3;
while ((status & 0x80) && !(status & 0x01)) {
- status = receive_b(iface->commandPort);
+ status = inb(interface->command_port);
}
return 0;
}
-uint8_t ATA_clear28(struct ATA_INTERFACE *iface, uint32_t sector) {
- uint8_t emptysector[512] = {0};
- return ATA_write28(iface, sector, emptysector);
+uint8_t ata_clear28(struct ata_interface *interface, uint32_t sector)
+{
+ uint8_t empty_sector[512] = {0};
+ return ata_write28(interface, sector, empty_sector);
} \ No newline at end of file
diff --git a/src/kernel/fs/ata_pio.h b/src/kernel/fs/ata_pio.h
index 3f1439d..fa08a0c 100644
--- a/src/kernel/fs/ata_pio.h
+++ b/src/kernel/fs/ata_pio.h
@@ -5,27 +5,27 @@
#define BYTES_PER_SECTOR 512
-struct ATA_INTERFACE {
+struct ata_interface {
uint8_t master;
- uint16_t dataPort;
- uint16_t errorPort;
- uint16_t sectorCountPort;
- uint16_t lbaLowPort;
- uint16_t lbaMidPort;
- uint16_t lbaHiPort;
- uint16_t devicePort;
- uint16_t commandPort;
- uint16_t controlPort;
+ uint16_t data_port;
+ uint16_t error_port;
+ uint16_t sector_count_port;
+ uint16_t lba_low_port;
+ uint16_t lba_mid_port;
+ uint16_t lba_high_port;
+ uint16_t device_port;
+ uint16_t command_port;
+ uint16_t control_port;
};
-struct ATA_INTERFACE *new_ATA(uint8_t master, uint16_t portBase);
+struct ata_interface *new_ata(uint8_t master, uint16_t port_base);
-uint8_t ATA_identify(struct ATA_INTERFACE *iface, uint16_t *retdata);
+uint8_t ata_identify(struct ata_interface *interface, uint16_t *ret_data);
-uint8_t *ATA_read28(struct ATA_INTERFACE *iface, uint32_t sector);
+uint8_t *ata_read28(struct ata_interface *interface, uint32_t sector);
-uint8_t ATA_write28(struct ATA_INTERFACE *iface, uint32_t sector, uint8_t *contents);
+uint8_t ata_write28(struct ata_interface *interface, uint32_t sector, const uint8_t *contents);
-uint8_t ATA_clear28(struct ATA_INTERFACE *iface, uint32_t sector);
+uint8_t ata_clear28(struct ata_interface *interface, uint32_t sector);
#endif
diff --git a/src/kernel/fs/atapi_pio.c b/src/kernel/fs/atapi_pio.c
index e64cd75..34cd1e6 100644
--- a/src/kernel/fs/atapi_pio.c
+++ b/src/kernel/fs/atapi_pio.c
@@ -3,13 +3,14 @@
#include <kernel/system.h>
#include <kernel/paging/paging.h>
-void ATAPI_read(uint16_t nblocks, uint32_t lba) {
+void ATAPI_read(uint16_t nblocks, uint32_t lba)
+{
struct dapack *d = (struct dapack *) ATAPI_PIO_DAPACK;
d->size = 0x10;
d->null = 0x00;
- d->blkcount = nblocks;
- d->boffset = ATAPI_PIO_BUFFER;
- d->bsegment = 0x0000;
+ d->blk_count = nblocks;
+ d->b_offset = ATAPI_PIO_BUFFER;
+ d->b_segment = 0x0000;
d->start = lba;
d->upper_lba_bits = 0x00000000;
@@ -22,7 +23,8 @@ void ATAPI_read(uint16_t nblocks, uint32_t lba) {
v86(LBA_READ_INT, &regs);
}
-void ATAPI_granular_read(uint32_t nblocks, uint32_t lba, uint8_t *output) {
+void ATAPI_granular_read(uint32_t nblocks, uint32_t lba, uint8_t *output)
+{
for (uint32_t i = 0; i < nblocks; i++) {
ATAPI_read(1, lba + i);
for (uint16_t j = 0; j < ATAPI_SECTOR_SIZE; j++) output[j + (2048 * i)] = ((uint8_t *) ATAPI_PIO_BUFFER)[j];
diff --git a/src/kernel/fs/atapi_pio.h b/src/kernel/fs/atapi_pio.h
index 5e89e85..be48f2f 100644
--- a/src/kernel/fs/atapi_pio.h
+++ b/src/kernel/fs/atapi_pio.h
@@ -12,9 +12,9 @@
struct dapack {
uint8_t size;
uint8_t null;
- uint16_t blkcount;
- uint16_t boffset;
- uint16_t bsegment;
+ uint16_t blk_count;
+ uint16_t b_offset;
+ uint16_t b_segment;
uint32_t start;
uint32_t upper_lba_bits;
} __attribute__((packed));
diff --git a/src/kernel/fs/install.c b/src/kernel/fs/install.c
index c098266..d5f62b2 100644
--- a/src/kernel/fs/install.c
+++ b/src/kernel/fs/install.c
@@ -6,16 +6,18 @@
#include <mlibc/stdlib.h>
#include <kernel/acpi/acpi.h>
#include <kernel/io/io.h>
+#include <kernel/timer/timer.h>
-void install_melvix() {
- info("You're booting from a CD, Melvix will only run after an install");
- asm volatile ("cli");
- struct ATA_INTERFACE *primary_master = new_ATA(1, 0x1F0);
+void install_melvix()
+{
+ info("You're booting from a CD, Melvix will only run after an installation");
+ asm ("cli");
+ struct ata_interface *primary_master = new_ata(1, 0x1F0);
if (marfs_init(primary_master) != 0) {
panic("No HDD found!");
}
- struct marfs_SUPERBLOCK *currentSB = marfs_read_superblock();
+ struct marfs_superblock *currentSB = marfs_read_superblock();
if (currentSB->signature == 0x1083B99F34B59645) { // WEEEOOOWEEEOOO
panic("Melvix seems to be already installed!");
}
@@ -26,7 +28,7 @@ void install_melvix() {
// Copy MBR
info("Copying MBR... ");
char *stage1_p[] = {"BOOT", "HDD1.BIN"};
- struct ISO9660_entity *stage1_e = ISO9660_get(stage1_p, 2);
+ struct iso9660_entity *stage1_e = ISO9660_get(stage1_p, 2);
if (!stage1_e)
panic("Couldn't find the first HDD bootloader!");
uint8_t *stage1 = ISO9660_read(stage1_e);
@@ -40,7 +42,7 @@ void install_melvix() {
// Copy second stage
info("Copying second stage...");
char *stage2_p[] = {"BOOT", "HDD2.BIN"};
- struct ISO9660_entity *stage2_e = ISO9660_get(stage2_p, 2);
+ struct iso9660_entity *stage2_e = ISO9660_get(stage2_p, 2);
if (!stage2_e)
panic("Couldn't find the second HDD bootloader!");
uint8_t *stage2 = ISO9660_read(stage2_e);
@@ -50,16 +52,17 @@ void install_melvix() {
// Copy the kernel
info("Copying the kernel... ");
char *kernel_p[] = {"BOOT", "KERNEL.BIN"};
- struct ISO9660_entity *kernel_e = ISO9660_get(kernel_p, 2);
+ struct iso9660_entity *kernel_e = ISO9660_get(kernel_p, 2);
if (!kernel_e)
panic("WTH Kernel not found!?");
uint8_t *kernel = kmalloc(kernel_e->length + 2048);
- ATAPI_granular_read(1 + (kernel_e->length / 2048), kernel_e->LBA, kernel);
+ ATAPI_granular_read(1 + (kernel_e->length / 2048), kernel_e->lba, kernel);
marfs_new_file(kernel_e->length, kernel, 0, 0, 0);
kfree(kernel);
kfree(kernel_e);
info("Installation successful!");
serial_write("Installation successful!\nRebooting...\n");
+ timer_wait(200);
acpi_poweroff();
} \ No newline at end of file
diff --git a/src/kernel/fs/iso9660/iso9660.c b/src/kernel/fs/iso9660/iso9660.c
index f8eddd4..81b1ba6 100644
--- a/src/kernel/fs/iso9660/iso9660.c
+++ b/src/kernel/fs/iso9660/iso9660.c
@@ -4,21 +4,22 @@
#include <kernel/fs/iso9660/iso9660.h>
#include <mlibc/stdlib.h>
-struct ISO9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz) {
+struct iso9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz)
+{
ATAPI_read(1, 0x10);
uint32_t last_len = *(uint32_t *) (
ATAPI_PIO_BUFFER +
ISO9660_ROOT_RECORD_OFFSET +
ISO9660_DIR_EAR_LENGTH
);
- uint32_t last_LBA = *(uint32_t *) (
+ uint32_t last_lba = *(uint32_t *) (
ATAPI_PIO_BUFFER +
ISO9660_ROOT_RECORD_OFFSET +
ISO9660_DIR_EAR_LBA
);
for (uint8_t dirs_i = 0; dirs_i < dirs_sz; dirs_i++) {
- ATAPI_read((last_len % 2048 != 0) + (last_len / 2048), last_LBA);
+ ATAPI_read((last_len % 2048 != 0) + (last_len / 2048), last_lba);
uint8_t found = 0;
for (uint32_t i = 0; i < last_len && !found;) {
@@ -36,7 +37,7 @@ struct ISO9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz) {
if (strcmp(dirs[dirs_i], filename) == 0) {
found = 1;
- last_LBA = *(uint32_t *) (ATAPI_PIO_BUFFER + i + ISO9660_DIR_EAR_LBA);
+ last_lba = *(uint32_t *) (ATAPI_PIO_BUFFER + i + ISO9660_DIR_EAR_LBA);
last_len = *(uint32_t *) (ATAPI_PIO_BUFFER + i + ISO9660_DIR_EAR_LENGTH);
} else {
i += *(uint8_t *) (ATAPI_PIO_BUFFER + i + ISO9660_DIR_RECORD_LENGTH);
@@ -44,17 +45,18 @@ struct ISO9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz) {
}
if (!found) {
- return (struct ISO9660_entity *) 0;
+ return (struct iso9660_entity *) 0;
}
}
- struct ISO9660_entity *ret = (struct ISO9660_entity *) kmalloc(sizeof(struct ISO9660_entity));
- ret->LBA = last_LBA;
+ struct iso9660_entity *ret = (struct iso9660_entity *) kmalloc(sizeof(struct iso9660_entity));
+ ret->lba = last_lba;
ret->length = last_len;
return ret;
}
-uint8_t *ISO9660_read(struct ISO9660_entity *entity) {
- ATAPI_read((entity->length % 2048 != 0) + (entity->length / 2048), entity->LBA);
+uint8_t *ISO9660_read(struct iso9660_entity *entity)
+{
+ ATAPI_read((entity->length % 2048 != 0) + (entity->length / 2048), entity->lba);
return (uint8_t *) ATAPI_PIO_BUFFER;
} \ No newline at end of file
diff --git a/src/kernel/fs/iso9660/iso9660.h b/src/kernel/fs/iso9660/iso9660.h
index 3de5d1a..86629e4 100644
--- a/src/kernel/fs/iso9660/iso9660.h
+++ b/src/kernel/fs/iso9660/iso9660.h
@@ -10,13 +10,13 @@
#include <stdint.h>
-struct ISO9660_entity {
- uint32_t LBA;
+struct iso9660_entity {
+ uint32_t lba;
uint32_t length;
};
-struct ISO9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz);
+struct iso9660_entity *ISO9660_get(char **dirs, uint8_t dirs_sz);
-uint8_t *ISO9660_read(struct ISO9660_entity *entity);
+uint8_t *ISO9660_read(struct iso9660_entity *entity);
#endif
diff --git a/src/kernel/fs/marfs/directory.c b/src/kernel/fs/marfs/directory.c
index bf19fc7..210d908 100644
--- a/src/kernel/fs/marfs/directory.c
+++ b/src/kernel/fs/marfs/directory.c
@@ -3,52 +3,56 @@
#include <mlibc/stdlib.h>
#include <kernel/fs/marfs/marfs.h>
-uint32_t marfs_new_dir(uint32_t uid) { return marfs_new_file(0, 0, uid, 0, 1); }
+uint32_t marfs_new_dir(uint32_t uid)
+{
+ return marfs_new_file(0, 0, uid, 0, 1);
+}
-void marfs_add_to_dir(uint32_t LBAinode, char *filename, uint32_t lba) {
- struct marfs_INODE *inode = (struct marfs_INODE *) ATA_read28(iface, LBAinode);
+void marfs_add_to_dir(uint32_t lba_inode, char *filename, uint32_t lba)
+{
+ struct marfs_inode *inode = (struct marfs_inode *) ata_read28(interface, lba_inode);
// Read the content
- uint8_t *old = marfs_allocate_and_read_whole_file(LBAinode);
+ uint8_t *old = marfs_allocate_and_read_whole_file(lba_inode);
// Allocate memory
uint8_t *contents = kmalloc(inode->size + strlen(filename) + 1 + 4);
// Copy the content
- uint8_t lastWasNull = 0;
- uint64_t newsize = 0;
+ uint8_t last_was_null = 0;
+ uint64_t new_size = 0;
for (uint64_t i = 0; i < inode->size; i++) {
- if (old[i] == 0 && lastWasNull) continue;
+ if (old[i] == 0 && last_was_null) continue;
- contents[newsize++] = old[i];
- lastWasNull = (old[i] == 0);
+ contents[new_size++] = old[i];
+ last_was_null = (old[i] == 0);
}
kfree(old);
// Append new file
- for (uint16_t i = 0; i <= strlen(filename); i++) contents[newsize++] = filename[i];
- for (signed char j = 24; j > 0; j -= 8) contents[newsize++] = (lba >> j) & 0xFF;
+ for (size_t i = 0; i <= strlen(filename); i++) contents[new_size++] = filename[i];
+ for (signed char j = 24; j > 0; j -= 8) contents[new_size++] = (lba >> j) & 0xFF;
// Free the blocks
- uint32_t newsize_in_blocks = newsize / 512;
- if (newsize % 512) newsize_in_blocks++;
- for (uint32_t i = 0; i < newsize_in_blocks; i++)
+ uint32_t new_size_in_blocks = new_size / 512;
+ if (new_size % 512) new_size_in_blocks++;
+ for (uint32_t i = 0; i < new_size_in_blocks; i++)
marfs_mark_block_as_free(marfs_get_block(inode, i));
// Overwrite
- uint32_t aux_inode = marfs_new_file(newsize, contents, 0xDEADBEEF, 0, 0);
- struct marfs_INODE *real_aux_inode = (struct marfs_INODE *) ATA_read28(iface, aux_inode);
+ uint32_t aux_inode = marfs_new_file(new_size, contents, 0xDEADBEEF, 0, 0);
+ struct marfs_inode *real_aux_inode = (struct marfs_inode *) ata_read28(interface, aux_inode);
for (uint8_t i = 0; i < 10; i++) inode->DBPs[i] = real_aux_inode->DBPs[i];
inode->ext_1 = real_aux_inode->ext_1;
inode->ext_2 = real_aux_inode->ext_2;
inode->ext_3 = real_aux_inode->ext_3;
inode->ext_4 = real_aux_inode->ext_4;
- real_aux_inode->isUsed = 0;
- ATA_write28(iface, aux_inode, (uint8_t *) real_aux_inode);
+ real_aux_inode->is_used = 0;
+ ata_write28(interface, aux_inode, (uint8_t *) real_aux_inode);
kfree(real_aux_inode);
- inode->size = newsize;
- ATA_write28(iface, LBAinode, (uint8_t *) inode);
+ inode->size = new_size;
+ ata_write28(interface, lba_inode, (uint8_t *) inode);
kfree(inode);
}
diff --git a/src/kernel/fs/marfs/disklevel.c b/src/kernel/fs/marfs/disklevel.c
index f54dea1..a902362 100644
--- a/src/kernel/fs/marfs/disklevel.c
+++ b/src/kernel/fs/marfs/disklevel.c
@@ -2,9 +2,10 @@
#include <kernel/fs/ata_pio.h>
#include <kernel/fs/marfs/marfs.h>
-void marfs_format(void) {
+void marfs_format(void)
+{
// Create superblock
- struct marfs_SUPERBLOCK sb;
+ struct marfs_superblock sb;
sb.signature = 0x1083B99F34B59645; // Huh, magic?!
sb.n_inodes = (marfs_get_max_lba() - 2) >> 5;
sb.n_chunks = (marfs_get_max_lba() - (2 + sb.n_inodes)) >> 9;
@@ -16,8 +17,8 @@ void marfs_format(void) {
marfs_writeSB(&sb);
// Initialize the inodes
- for (uint32_t i = 0; i < sb.n_inodes; i++) ATA_clear28(iface, 2 + i);
+ for (uint32_t i = 0; i < sb.n_inodes; i++) ata_clear28(interface, 2 + i);
// Initialize the chunks
- for (uint32_t i = 0; i < sb.n_chunks; i++) ATA_clear28(iface, sb.s_first_chunk + i * 512);
+ for (uint32_t i = 0; i < sb.n_chunks; i++) ata_clear28(interface, sb.s_first_chunk + i * 512);
}
diff --git a/src/kernel/fs/marfs/marfs.h b/src/kernel/fs/marfs/marfs.h
index ba6f0b3..f197e5b 100644
--- a/src/kernel/fs/marfs/marfs.h
+++ b/src/kernel/fs/marfs/marfs.h
@@ -3,7 +3,7 @@
#include <stdint.h>
-struct marfs_SUPERBLOCK {
+struct marfs_superblock {
uint64_t signature;
uint32_t n_inodes;
uint32_t n_chunks;
@@ -12,7 +12,7 @@ struct marfs_SUPERBLOCK {
uint32_t s_first_chunk;
} __attribute__((packed));
-struct marfs_INODE {
+struct marfs_inode {
uint64_t size;
uint32_t creation_time;
uint32_t last_mod_time;
@@ -24,41 +24,35 @@ struct marfs_INODE {
uint32_t ext_3;
uint32_t ext_4;
uint32_t uid;
- uint8_t isApp;
- uint8_t isDir;
- uint8_t isUsed;
+ uint8_t is_app;
+ uint8_t is_dir;
+ uint8_t is_used;
} __attribute__((packed));
-enum marfs_RESERVED_INODES {
- marfs_INODE_JBOOT2,
- marfs_INODE_KERNEL,
- marfs_INODE_ROOT
-};
-
-struct ATA_INTERFACE *iface;
-struct marfs_SUPERBLOCK sb_cache;
-uint32_t maxLBA;
+struct ata_interface *interface;
+struct marfs_superblock sb_cache;
+uint32_t max_lba;
// marfs_sectorlevel.c
-uint8_t marfs_init(struct ATA_INTERFACE *iface);
+uint8_t marfs_init(struct ata_interface *interface);
uint32_t marfs_get_max_lba(void);
uint8_t marfs_write_mbr(uint8_t *mbr);
-struct marfs_SUPERBLOCK *marfs_read_superblock();
+struct marfs_superblock *marfs_read_superblock();
-uint8_t marfs_writeSB(struct marfs_SUPERBLOCK *sb);
+uint8_t marfs_writeSB(struct marfs_superblock *sb);
uint32_t marfs_get_free_lba_block(void);
-uint8_t marfs_mark_block_as_used(uint32_t LBAsector);
+uint8_t marfs_mark_block_as_used(uint32_t lba_sector);
-uint8_t marfs_mark_block_as_free(uint32_t LBAsector);
+uint8_t marfs_mark_block_as_free(uint32_t lba_sector);
uint32_t marfs_get_free_lba_inode(void);
-void marfs_mark_inode_as_free(uint32_t LBAsector);
+void marfs_mark_inode_as_free(uint32_t lba_sector);
// marfs_disklevel.c
void marfs_format(void);
@@ -69,13 +63,13 @@ uint32_t marfs_new_file(uint64_t size, uint8_t *data, uint32_t uid, uint8_t exec
// marfs_dir.c
uint32_t marfs_new_dir(uint32_t uid);
-void marfs_add_to_dir(uint32_t LBAinode, char *filename, uint32_t lba);
+void marfs_add_to_dir(uint32_t lba_inode, char *filename, uint32_t lba);
// marfs_read_whole_file.c
-uint32_t marfs_get_block(struct marfs_INODE *inode, uint32_t i);
+uint32_t marfs_get_block(struct marfs_inode *inode, uint32_t i);
-void marfs_read_whole_file(uint32_t LBAinode, uint8_t *buffer);
+void marfs_read_whole_file(uint32_t lba_inode, uint8_t *buffer);
-uint8_t *marfs_allocate_and_read_whole_file(uint32_t LBAinode);
+uint8_t *marfs_allocate_and_read_whole_file(uint32_t lba_inode);
#endif
diff --git a/src/kernel/fs/marfs/new_file.c b/src/kernel/fs/marfs/new_file.c
index ebc8152..4503ed1 100644
--- a/src/kernel/fs/marfs/new_file.c
+++ b/src/kernel/fs/marfs/new_file.c
@@ -3,16 +3,17 @@
#include <mlibc/stdlib.h>
#include <kernel/fs/marfs/marfs.h>
-static uint8_t last_maxlevel = 0;
+static uint8_t last_max_level = 0;
-void marfs_update_recursive(uint8_t level, uint32_t i, uint32_t recLBA, uint32_t realLBA) {
- if (level > last_maxlevel) last_maxlevel = level;
- uint32_t *contents = (uint32_t *) ATA_read28(iface, recLBA);
+void marfs_update_recursive(uint8_t level, uint32_t i, uint32_t rec_lba, uint32_t real_lba)
+{
+ if (level > last_max_level) last_max_level = level;
+ uint32_t *contents = (uint32_t *) ata_read28(interface, rec_lba);
uint32_t idx = i - 10;
- if (last_maxlevel > 1) idx -= 1 << 7;
- if (last_maxlevel > 2) idx -= 1 << (7 * 2);
- if (last_maxlevel > 3) idx -= 1 << (7 * 3);
+ if (last_max_level > 1) idx -= 1 << 7;
+ if (last_max_level > 2) idx -= 1 << (7 * 2);
+ if (last_max_level > 3) idx -= 1 << (7 * 3);
idx >>= 7 * (level - 1);
if (level > 1) {
@@ -21,82 +22,83 @@ void marfs_update_recursive(uint8_t level, uint32_t i, uint32_t recLBA, uint32_t
marfs_mark_block_as_used(contents[idx]);
}
} else {
- contents[idx] = realLBA;
+ contents[idx] = real_lba;
}
- ATA_write28(iface, recLBA, (uint8_t *) contents);
+ ata_write28(interface, rec_lba, (uint8_t *) contents);
uint32_t contents_idx = contents[idx];
kfree(contents);
if (level != 1) {
- marfs_update_recursive(level - 1, i, contents_idx, realLBA);
+ marfs_update_recursive(level - 1, i, contents_idx, real_lba);
}
- last_maxlevel = 0;
+ last_max_level = 0;
}
-uint32_t marfs_new_file(uint64_t size, uint8_t *data, uint32_t uid, uint8_t exec, uint8_t dir) {
- struct marfs_INODE *inode = (struct marfs_INODE *) kcalloc(1, 512);
+uint32_t marfs_new_file(uint64_t size, uint8_t *data, uint32_t uid, uint8_t exec, uint8_t dir)
+{
+ struct marfs_inode *inode = (struct marfs_inode *) kcalloc(1, 512);
inode->size = size;
inode->creation_time = inode->last_mod_time = inode->last_access_time = 0; // TODO: POSIX time
inode->n_blocks = size / 512;
if (size % 512) inode->n_blocks++;
inode->uid = uid;
- inode->isApp = exec;
- inode->isDir = dir;
- inode->isUsed = 1;
+ inode->is_app = exec;
+ inode->is_dir = dir;
+ inode->is_used = 1;
uint32_t size_in_blocks = inode->n_blocks;
- uint32_t LBA_singly, LBA_doubly, LBA_triply, LBA_quadruply;
- LBA_singly = LBA_doubly = LBA_triply = LBA_quadruply = 0;
+ uint32_t lba_singly, lba_doubly, lba_triply, lba_quadruply;
+ lba_singly = lba_doubly = lba_triply = lba_quadruply = 0;
for (uint32_t i = 0; i < size_in_blocks; i++) {
- uint32_t thisblock = marfs_get_free_lba_block();
+ uint32_t this_block = marfs_get_free_lba_block();
if (i != size_in_blocks - 1) {
- ATA_write28(iface, thisblock, data);
+ ata_write28(interface, this_block, data);
} else if (size % 512) {
uint8_t contents[512] = {0};
for (uint16_t i = 0; i < size % 512; i++) contents[i] = data[i];
- ATA_write28(iface, thisblock, contents);
+ ata_write28(interface, this_block, contents);
}
data += 512;
- marfs_mark_block_as_used(thisblock);
+ marfs_mark_block_as_used(this_block);
if (i > 9 + (128 * 128 * 128)) {
- if (!LBA_quadruply) {
- LBA_quadruply = marfs_get_free_lba_block();
- marfs_mark_block_as_used(LBA_quadruply);
- inode->ext_4 = LBA_quadruply;
+ if (!lba_quadruply) {
+ lba_quadruply = marfs_get_free_lba_block();
+ marfs_mark_block_as_used(lba_quadruply);
+ inode->ext_4 = lba_quadruply;
}
- marfs_update_recursive(4, i, LBA_quadruply, thisblock);
+ marfs_update_recursive(4, i, lba_quadruply, this_block);
} else if (i > 9 + (128 * 128)) {
- if (!LBA_triply) {
- LBA_triply = marfs_get_free_lba_block();
- marfs_mark_block_as_used(LBA_triply);
- inode->ext_3 = LBA_triply;
+ if (!lba_triply) {
+ lba_triply = marfs_get_free_lba_block();
+ marfs_mark_block_as_used(lba_triply);
+ inode->ext_3 = lba_triply;
}
- marfs_update_recursive(3, i, LBA_triply, thisblock);
+ marfs_update_recursive(3, i, lba_triply, this_block);
} else if (i > 9 + 128) {
- if (!LBA_doubly) {
- LBA_doubly = marfs_get_free_lba_block();
- marfs_mark_block_as_used(LBA_doubly);
- inode->ext_2 = LBA_doubly;
+ if (!lba_doubly) {
+ lba_doubly = marfs_get_free_lba_block();
+ marfs_mark_block_as_used(lba_doubly);
+ inode->ext_2 = lba_doubly;
}
- marfs_update_recursive(2, i, LBA_doubly, thisblock);
+ marfs_update_recursive(2, i, lba_doubly, this_block);
} else if (i > 9) {
- if (!LBA_singly) {
- LBA_singly = marfs_get_free_lba_block();
- marfs_mark_block_as_used(LBA_singly);
- inode->ext_1 = LBA_singly;
+ if (!lba_singly) {
+ lba_singly = marfs_get_free_lba_block();
+ marfs_mark_block_as_used(lba_singly);
+ inode->ext_1 = lba_singly;
}
- marfs_update_recursive(1, i, LBA_singly, thisblock);
+ marfs_update_recursive(1, i, lba_singly, this_block);
} else {
- inode->DBPs[i] = thisblock;
+ inode->DBPs[i] = this_block;
}
}
// Write the inode
- uint32_t inode_LBA = marfs_get_free_lba_inode();
- ATA_write28(iface, inode_LBA, (uint8_t *) inode);
+ uint32_t inode_lba = marfs_get_free_lba_inode();
+ ata_write28(interface, inode_lba, (uint8_t *) inode);
- return inode_LBA;
+ return inode_lba;
} \ No newline at end of file
diff --git a/src/kernel/fs/marfs/read_whole_file.c b/src/kernel/fs/marfs/read_whole_file.c
index 0d3af26..324cd9b 100644
--- a/src/kernel/fs/marfs/read_whole_file.c
+++ b/src/kernel/fs/marfs/read_whole_file.c
@@ -3,28 +3,30 @@
#include <mlibc/stdlib.h>
#include <kernel/fs/marfs/marfs.h>
-static uint8_t last_maxlevel = 0;
+static uint8_t last_max_level = 0;
-uint32_t marfs_get_recursive(uint8_t level, uint32_t i, uint32_t recLBA) {
- if (level > last_maxlevel) last_maxlevel = level;
- uint32_t *contents = (uint32_t *) ATA_read28(iface, recLBA);
+uint32_t marfs_get_recursive(uint8_t level, uint32_t i, uint32_t rec_lba)
+{
+ if (level > last_max_level) last_max_level = level;
+ uint32_t *contents = (uint32_t *) ata_read28(interface, rec_lba);
uint32_t idx = i - 10;
- if (last_maxlevel > 1) idx -= 1 << 7;
- if (last_maxlevel > 2) idx -= 1 << (7 * 2);
- if (last_maxlevel > 3) idx -= 1 << (7 * 3);
+ if (last_max_level > 1) idx -= 1 << 7;
+ if (last_max_level > 2) idx -= 1 << (7 * 2);
+ if (last_max_level > 3) idx -= 1 << (7 * 3);
idx >>= 7 * (level - 1);
- uint32_t next_recLBA = contents[idx];
+ uint32_t next_rec_lba = contents[idx];
kfree(contents);
uint32_t toRet;
- if (level > 1) toRet = marfs_get_recursive(level - 1, i, next_recLBA);
- else toRet = next_recLBA;
- last_maxlevel = 0;
+ if (level > 1) toRet = marfs_get_recursive(level - 1, i, next_rec_lba);
+ else toRet = next_rec_lba;
+ last_max_level = 0;
return toRet;
}
-uint32_t marfs_get_block(struct marfs_INODE *inode, uint32_t i) {
+uint32_t marfs_get_block(struct marfs_inode *inode, uint32_t i)
+{
if (i > 9 + (128 * 128 * 128)) {
return marfs_get_recursive(4, i, inode->ext_4);
} else if (i > 9 + (128 * 128)) {
@@ -38,13 +40,14 @@ uint32_t marfs_get_block(struct marfs_INODE *inode, uint32_t i) {
}
}
-void marfs_read_whole_file(uint32_t LBAinode, uint8_t *buffer) {
- struct marfs_INODE *inode = (struct marfs_INODE *) ATA_read28(iface, LBAinode);
+void marfs_read_whole_file(uint32_t lba_inode, uint8_t *buffer)
+{
+ struct marfs_inode *inode = (struct marfs_inode *) ata_read28(interface, lba_inode);
uint32_t size_in_blocks = inode->n_blocks;
for (uint32_t i = 0; i < size_in_blocks; i++) {
uint32_t this_block = marfs_get_block(inode, i);
- uint8_t *this_block_contents = ATA_read28(iface, this_block);
+ uint8_t *this_block_contents = ata_read28(interface, this_block);
uint16_t upper_bound = (i != size_in_blocks - 1) ? 512 : (inode->size % 512);
for (uint16_t j = 0; j < upper_bound; j++) buffer[(i * 512) + j] = this_block_contents[j];
kfree(this_block_contents);
@@ -54,12 +57,13 @@ void marfs_read_whole_file(uint32_t LBAinode, uint8_t *buffer) {
}
// TODO: Beautify
-uint8_t *marfs_allocate_and_read_whole_file(uint32_t LBAinode) {
- struct marfs_INODE *inode = (struct marfs_INODE *) ATA_read28(iface, LBAinode);
+uint8_t *marfs_allocate_and_read_whole_file(uint32_t lba_inode)
+{
+ struct marfs_inode *inode = (struct marfs_inode *) ata_read28(interface, lba_inode);
uint64_t size = inode->size;
kfree(inode);
uint8_t *buffer = kmalloc(size);
- marfs_read_whole_file(LBAinode, buffer);
+ marfs_read_whole_file(lba_inode, buffer);
return buffer;
}
diff --git a/src/kernel/fs/marfs/sectorlevel.c b/src/kernel/fs/marfs/sectorlevel.c
index d8795fa..d9fa2c4 100644
--- a/src/kernel/fs/marfs/sectorlevel.c
+++ b/src/kernel/fs/marfs/sectorlevel.c
@@ -3,36 +3,44 @@
#include <kernel/fs/ata_pio.h>
#include <kernel/fs/marfs/marfs.h>
-uint8_t marfs_init(struct ATA_INTERFACE *_iface) {
- iface = _iface;
- uint16_t identifydata[256 * 2];
- uint8_t ret = ATA_identify(iface, identifydata);
- maxLBA = (identifydata[61] << 16) + identifydata[60];
+uint8_t marfs_init(struct ata_interface *_interface)
+{
+ interface = _interface;
+ uint16_t identify_data[256 * 2];
+ uint8_t ret = ata_identify(interface, identify_data);
+ max_lba = (identify_data[61] << 16) + identify_data[60];
return ret;
}
-uint32_t marfs_get_max_lba(void) { return maxLBA; }
+uint32_t marfs_get_max_lba(void)
+{
+ return max_lba;
+}
-uint8_t marfs_write_mbr(uint8_t *mbr) {
- return ATA_write28(iface, 0, mbr);
+uint8_t marfs_write_mbr(uint8_t *mbr)
+{
+ return ata_write28(interface, 0, mbr);
}
-struct marfs_SUPERBLOCK *marfs_read_superblock() {
- struct marfs_SUPERBLOCK *p = (struct marfs_SUPERBLOCK *) ATA_read28(iface, 1);
+struct marfs_superblock *marfs_read_superblock()
+{
+ struct marfs_superblock *p = (struct marfs_superblock *) ata_read28(interface, 1);
sb_cache = *p;
return p;
}
-uint8_t marfs_writeSB(struct marfs_SUPERBLOCK *sb) {
+uint8_t marfs_writeSB(struct marfs_superblock *sb)
+{
sb_cache = *sb;
- return ATA_write28(iface, 1, (uint8_t *) sb);
+ return ata_write28(interface, 1, (uint8_t *) sb);
}
-uint32_t marfs_get_free_lba_block(void) {
+uint32_t marfs_get_free_lba_block(void)
+{
uint32_t offset = 2 + sb_cache.s_first_chunk;
uint8_t *p = 0;
for (uint32_t i = 0; i < sb_cache.n_chunks; i++) {
- p = ATA_read28(iface, offset);
+ p = ata_read28(interface, offset);
if (!(*p & 0x80)) break;
kfree(p);
offset += 512;
@@ -45,19 +53,20 @@ uint32_t marfs_get_free_lba_block(void) {
}
kfree(p);
- ATA_clear28(iface, offset);
+ ata_clear28(interface, offset);
return offset;
}
-static uint8_t marfs_mark_block(uint32_t lba_sector, uint8_t mode) {
+static uint8_t marfs_mark_block(uint32_t lba_sector, uint8_t mode)
+{
lba_sector -= 2;
lba_sector -= sb_cache.s_first_chunk;
uint16_t block_in_chunk = lba_sector % 512;
lba_sector /= 512;
lba_sector = 2 + sb_cache.s_first_chunk + (512 * lba_sector);
- uint8_t *p = ATA_read28(iface, lba_sector);
+ uint8_t *p = ata_read28(interface, lba_sector);
p[block_in_chunk] = mode;
if (mode == 0) {
@@ -73,29 +82,37 @@ static uint8_t marfs_mark_block(uint32_t lba_sector, uint8_t mode) {
p[0] = full_chunk;
}
- uint8_t ret = ATA_write28(iface, lba_sector, p);
+ uint8_t ret = ata_write28(interface, lba_sector, p);
kfree(p);
return ret;
}
-uint8_t marfs_mark_block_as_free(uint32_t lba_sector) { return marfs_mark_block(lba_sector, 0); }
+uint8_t marfs_mark_block_as_free(uint32_t lba_sector)
+{
+ return marfs_mark_block(lba_sector, 0);
+}
-uint8_t marfs_mark_block_as_used(uint32_t lba_sector) { return marfs_mark_block(lba_sector, 1); }
+uint8_t marfs_mark_block_as_used(uint32_t lba_sector)
+{
+ return marfs_mark_block(lba_sector, 1);
+}
-uint32_t marfs_get_free_lba_inode(void) {
+uint32_t marfs_get_free_lba_inode(void)
+{
uint32_t offset;
for (offset = 2; offset < 2 + sb_cache.n_inodes; offset++) {
- struct marfs_INODE *inode = (struct marfs_INODE *) ATA_read28(iface, offset);
- uint8_t used = inode->isUsed;
+ struct marfs_inode *inode = (struct marfs_inode *) ata_read28(interface, offset);
+ uint8_t used = inode->is_used;
kfree(inode);
if (!used) break;
}
return offset;
}
-void marfs_mark_inode_as_free(uint32_t lba_sector) {
- struct marfs_INODE *inode = (struct marfs_INODE *) ATA_read28(iface, lba_sector);
- inode->isUsed = 0;
- ATA_write28(iface, lba_sector, (uint8_t *) inode);
+void marfs_mark_inode_as_free(uint32_t lba_sector)
+{
+ struct marfs_inode *inode = (struct marfs_inode *) ata_read28(interface, lba_sector);
+ inode->is_used = 0;
+ ata_write28(interface, lba_sector, (uint8_t *) inode);
kfree(inode);
} \ No newline at end of file
diff --git a/src/kernel/fs/vfs.c b/src/kernel/fs/vfs.c
index 5591a60..702851e 100644
--- a/src/kernel/fs/vfs.c
+++ b/src/kernel/fs/vfs.c
@@ -2,31 +2,36 @@
fs_node_t *fs_root = 0;
-uint32_t read_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
+uint32_t read_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer)
+{
if (node->read != 0)
return node->read(node, offset, size, buffer);
else
return 0;
}
-uint32_t write_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
+uint32_t write_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer)
+{
if (node->write != 0)
return node->write(node, offset, size, buffer);
else
return 0;
}
-void open_fs(fs_node_t *node, uint8_t read, uint8_t write) {
+void open_fs(fs_node_t *node, uint8_t read, uint8_t write)
+{
if (node->open != 0)
return node->open(node);
}
-void close_fs(fs_node_t *node) {
+void close_fs(fs_node_t *node)
+{
if (node->close != 0)
return node->close(node);
}
-struct dirent *readdir_fs(fs_node_t *node, uint32_t index) {
+struct dirent *readdir_fs(fs_node_t *node, uint32_t index)
+{
if ((node->flags & 0x7) == FS_DIRECTORY &&
node->readdir != 0)
return node->readdir(node, index);
@@ -34,7 +39,8 @@ struct dirent *readdir_fs(fs_node_t *node, uint32_t index) {
return 0;
}
-fs_node_t *finddir_fs(fs_node_t *node, char *name) {
+fs_node_t *finddir_fs(fs_node_t *node, char *name)
+{
if ((node->flags & 0x7) == FS_DIRECTORY &&
node->finddir != 0)
return node->finddir(node, name);
diff --git a/src/kernel/gdt/gdt.c b/src/kernel/gdt/gdt.c
index 1c69602..70d5b7f 100644
--- a/src/kernel/gdt/gdt.c
+++ b/src/kernel/gdt/gdt.c
@@ -57,7 +57,8 @@ extern void gdt_flush();
extern void tss_flush();
-void gdt_set_gate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) {
+void gdt_set_gate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran)
+{
// Set descriptor base address
gdt[num].base_low = (base & 0xFFFF);
gdt[num].base_middle = (base >> 16) & 0xFF;
@@ -72,7 +73,8 @@ void gdt_set_gate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, ui
gdt[num].access = access;
}
-void gdt_install() {
+void gdt_install()
+{
// Set GDT pointer and limit
gp.limit = (sizeof(struct gdt_entry) * 6) - 1;
gp.base = &gdt;
@@ -99,10 +101,11 @@ void gdt_install() {
gdt_flush();
tss_flush();
- vga_log("Installed Global Descriptor Table", 2);
+ vga_log("Installed Global Descriptor Table", 1);
}
-void tss_write(int32_t num, uint16_t ss0, uint32_t esp0) {
+void tss_write(int32_t num, uint16_t ss0, uint32_t esp0)
+{
uint32_t base = (uint32_t) &tss_entry;
uint32_t limit = base + sizeof(tss_entry);
@@ -117,6 +120,7 @@ void tss_write(int32_t num, uint16_t ss0, uint32_t esp0) {
tss_entry.ss = tss_entry.ds = tss_entry.es = tss_entry.fs = tss_entry.gs = 0x13;
}
-void set_kernel_stack(uint32_t stack) {
+void set_kernel_stack(uint32_t stack)
+{
tss_entry.esp0 = stack;
}
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c
index 6193401..5e3080c 100644
--- a/src/kernel/graphics/vesa.c
+++ b/src/kernel/graphics/vesa.c
@@ -7,7 +7,8 @@
#include <mlibc/stdlib.h>
#include <kernel/commands/command.h>
-void switch_to_vga() {
+void switch_to_vga()
+{
serial_write("Force switch to VGA!\n");
uint16_t *terminal_buffer = (uint16_t *) 0xB8000;
char *error = "Melvix does not support this graphics hardware!";
@@ -16,7 +17,8 @@ void switch_to_vga() {
panic("No VESA support!");
}
-struct edid_data get_edid() {
+struct edid_data get_edid()
+{
regs16_t regs;
regs.ax = 0x4F15;
regs.bx = 0x1; // BL
@@ -33,7 +35,8 @@ struct edid_data get_edid() {
return *(struct edid_data *) edid;
}
-void vbe_set_mode(unsigned short mode) {
+void vbe_set_mode(unsigned short mode)
+{
regs16_t regs;
regs.ax = 0x4F02;
regs.bx = mode;
@@ -44,7 +47,8 @@ void vbe_set_mode(unsigned short mode) {
switch_to_vga();
}
-uint16_t *vbe_get_modes() {
+uint16_t *vbe_get_modes()
+{
char *info_address = (char *) 0x7E00;
strcpy(info_address, "VBE2");
for (int i = 4; i < 512; i++) *(info_address + i) = 0;
@@ -71,7 +75,8 @@ uint16_t *vbe_get_modes() {
return mode_ptr;
}
-struct vbe_mode_info *vbe_get_mode_info(uint16_t mode) {
+struct vbe_mode_info *vbe_get_mode_info(uint16_t mode)
+{
regs16_t regs;
regs.ax = 0x4F01;
regs.cx = mode;
@@ -94,10 +99,11 @@ struct vbe_mode_info *vbe_get_mode_info(uint16_t mode) {
return ret;
}
-void set_optimal_resolution() {
- asm volatile ("sti");
- vga_log("Switching to graphics mode", 9);
- vga_log("Trying to detect available modes", 10);
+void set_optimal_resolution()
+{
+ asm ("sti");
+ vga_log("Switching to graphics mode", 8);
+ vga_log("Trying to detect available modes", 9);
uint16_t *video_modes = vbe_get_modes();
uint16_t highest = 0;
@@ -217,12 +223,14 @@ uint16_t terminal_y = 0;
int font_width;
int font_height;
-void vesa_set_font(int height) {
+void vesa_set_font(int height)
+{
font_width = height / 2;
font_height = height;
}
-void vesa_convert_color(uint32_t *color_array, uint32_t color) {
+void vesa_convert_color(uint32_t *color_array, uint32_t color)
+{
uint8_t red = (color >> 16) & 255;
uint8_t green = (color >> 8) & 255;
uint8_t blue = color & 255;
@@ -246,7 +254,8 @@ void vesa_convert_color(uint32_t *color_array, uint32_t color) {
}
}
-void vesa_set_pixel(uint16_t x, uint16_t y, const uint32_t color[3]) {
+void vesa_set_pixel(uint16_t x, uint16_t y, const uint32_t color[3])
+{
unsigned pos = x * vbe_bpl + y * vbe_pitch;
char *draw = (char *) &fb[pos];
draw[pos] = color[2];
@@ -254,7 +263,8 @@ void vesa_set_pixel(uint16_t x, uint16_t y, const uint32_t color[3]) {
draw[pos + 2] = color[0];
}
-void vesa_draw_rectangle(int x1, int y1, int x2, int y2, const uint32_t color[3]) {
+void vesa_draw_rectangle(int x1, int y1, int x2, int y2, const uint32_t color[3])
+{
int pos1 = x1 * vbe_bpl + y1 * vbe_pitch;
char *draw = (char *) &fb[pos1];
for (int i = 0; i <= y2 - y1; i++) {
@@ -267,13 +277,15 @@ void vesa_draw_rectangle(int x1, int y1, int x2, int y2, const uint32_t color[3]
}
}
-void vesa_clear() {
+void vesa_clear()
+{
vesa_draw_rectangle(0, 0, vbe_width - 1, vbe_height - 1, terminal_background);
terminal_x = 0;
terminal_y = 0;
}
-void vesa_draw_char(char ch) {
+void vesa_draw_char(char ch)
+{
if (ch >= ' ') {
int pos = terminal_x * vbe_bpl + terminal_y * vbe_pitch;
char *draw = (char *) &fb[pos];
@@ -311,7 +323,8 @@ void vesa_draw_char(char ch) {
}
}
-void vesa_keyboard_char(char ch) {
+void vesa_keyboard_char(char ch)
+{
vesa_draw_rectangle(terminal_x, terminal_y, terminal_x + font_width, terminal_y + font_height,
terminal_background);
@@ -338,7 +351,8 @@ void vesa_keyboard_char(char ch) {
terminal_color);
}
-void vesa_draw_string(const char *data) {
+void vesa_draw_string(const char *data)
+{
int i = 0;
while (data[i] != '\0') {
vesa_draw_char(data[i]);
@@ -346,14 +360,16 @@ void vesa_draw_string(const char *data) {
}
}
-void vesa_draw_number(int n) {
+void vesa_draw_number(int n)
+{
vesa_draw_string(itoa(n));
}
char *prev = 0;
int prev_coords[2] = {};
-void vesa_draw_cursor(int x, int y) {
+void vesa_draw_cursor(int x, int y)
+{
// Reset previous area
if (prev != 0) {
char *reset = (char *) &fb[prev_coords[0] * vbe_bpl + prev_coords[1] * vbe_pitch];
@@ -394,7 +410,8 @@ void vesa_draw_cursor(int x, int y) {
}
}
-void vesa_set_color(uint32_t color) {
+void vesa_set_color(uint32_t color)
+{
vesa_convert_color(terminal_color, color);
vesa_convert_color(terminal_background, default_background_color);
}
diff --git a/src/kernel/input/ps2/keyboard.c b/src/kernel/input/ps2/keyboard.c
index 2a093e5..24802bd 100644
--- a/src/kernel/input/ps2/keyboard.c
+++ b/src/kernel/input/ps2/keyboard.c
@@ -64,12 +64,13 @@ char shift_keymap[128] = {
0, // Other keys
};
-void keyboard_handler(struct regs *r) {
+void keyboard_handler(struct regs *r)
+{
unsigned char scan_code;
char *current_keymap = keymap;
if (shift_pressed) current_keymap = shift_keymap;
- scan_code = receive_b(0x60);
+ scan_code = inb(0x60);
if ((scan_code & 0x80) == 0) { // PRESS
// TODO: Fix caps lock deactivation when pressing shift while shifted
@@ -87,18 +88,21 @@ void keyboard_handler(struct regs *r) {
}
}
-void keyboard_acknowledge() {
- while (receive_b(0x60) != 0xfa);
+void keyboard_acknowledge()
+{
+ while (inb(0x60) != 0xfa);
}
-void keyboard_rate() {
- send_b(0x60, 0xF3);
+void keyboard_rate()
+{
+ outb(0x60, 0xF3);
keyboard_acknowledge();
- send_b(0x60, 0x0); // Rate{00000} Delay{00} 0
+ outb(0x60, 0x0); // Rate{00000} Delay{00} 0
}
// Installs the keyboard handler into IRQ1
-void keyboard_install() {
+void keyboard_install()
+{
keyboard_rate();
irq_install_handler(1, keyboard_handler);
shift_pressed = 0;
diff --git a/src/kernel/input/ps2/mouse.c b/src/kernel/input/ps2/mouse.c
index 016b8b0..97ae256 100644
--- a/src/kernel/input/ps2/mouse.c
+++ b/src/kernel/input/ps2/mouse.c
@@ -10,19 +10,20 @@ int mouse_but_1 = 0;
int mouse_but_2 = 0;
int mouse_but_3 = 0;
-void mouse_handler(struct regs *a_r) {
+void mouse_handler(struct regs *a_r)
+{
switch (mouse_cycle) {
case 0:
- mouse_byte[0] = receive_b(0x60);
+ mouse_byte[0] = inb(0x60);
if (((mouse_byte[0] >> 3) & 1) == 1) mouse_cycle++;
else mouse_cycle = 0;
break;
case 1:
- mouse_byte[1] = receive_b(0x60);
+ mouse_byte[1] = inb(0x60);
mouse_cycle++;
break;
case 2:
- mouse_byte[2] = receive_b(0x60);
+ mouse_byte[2] = inb(0x60);
mouse_x += mouse_byte[1];
mouse_y -= mouse_byte[2];
mouse_but_1 = mouse_byte[0] & 1;
@@ -41,49 +42,53 @@ void mouse_handler(struct regs *a_r) {
}
}
-void mouse_wait(unsigned char a_type) {
+void mouse_wait(unsigned char a_type)
+{
unsigned int time_out = 100000;
if (a_type == 0) {
while (time_out--)
- if ((receive_b(0x64) & 1) == 1)
+ if ((inb(0x64) & 1) == 1)
return;
return;
} else {
while (time_out--)
- if ((receive_b(0x64) & 2) == 0)
+ if ((inb(0x64) & 2) == 0)
return;
return;
}
}
-void mouse_write(unsigned char a_write) {
+void mouse_write(unsigned char a_write)
+{
mouse_wait(1);
- send_b(0x64, 0xD4);
+ outb(0x64, 0xD4);
mouse_wait(1);
- send_b(0x60, a_write);
+ outb(0x60, a_write);
}
-char mouse_read() {
+char mouse_read()
+{
mouse_wait(0);
- return receive_b(0x60);
+ return inb(0x60);
}
-void mouse_install() {
+void mouse_install()
+{
unsigned char status;
// Enable auxiliary mouse device
mouse_wait(1);
- send_b(0x64, 0xA8);
+ outb(0x64, 0xA8);
// Enable interrupts
mouse_wait(1);
- send_b(0x64, 0x20);
+ outb(0x64, 0x20);
mouse_wait(0);
- status = (receive_b(0x60) | 2);
+ status = (inb(0x60) | 2);
mouse_wait(1);
- send_b(0x64, 0x60);
+ outb(0x64, 0x60);
mouse_wait(1);
- send_b(0x60, status);
+ outb(0x60, status);
// Use default settings
mouse_write(0xF6);
diff --git a/src/kernel/interrupts/idt.c b/src/kernel/interrupts/idt.c
index 5f92294..b06a52a 100644
--- a/src/kernel/interrupts/idt.c
+++ b/src/kernel/interrupts/idt.c
@@ -21,7 +21,8 @@ struct idt_ptr idtp;
// Defined in idt.asm
extern void idt_load();
-void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags) {
+void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags)
+{
// Specify the interrupt routine's base address
idt[num].base_lo = (base & 0xFFFF);
idt[num].base_hi = (base >> 16) & 0xFFFF;
@@ -33,7 +34,8 @@ void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, uns
}
// Install IDT
-void idt_install() {
+void idt_install()
+{
// Set IDT pointer and limit
idtp.limit = (sizeof(struct idt_entry) * 256) - 1;
idtp.base = &idt;
@@ -42,5 +44,5 @@ void idt_install() {
memset(&idt, 0, sizeof(struct idt_entry) * 256);
idt_load();
- vga_log("Installed Interrupt Descriptor Table", 6);
+ vga_log("Installed Interrupt Descriptor Table", 5);
}
diff --git a/src/kernel/interrupts/irq.c b/src/kernel/interrupts/irq.c
index 979b25c..a0a396d 100644
--- a/src/kernel/interrupts/irq.c
+++ b/src/kernel/interrupts/irq.c
@@ -41,35 +41,40 @@ void *irq_routines[16] = {
};
// Install custom IRQ handler
-void irq_install_handler(int irq, void (*handler)(struct regs *r)) {
+void irq_install_handler(int irq, void (*handler)(struct regs *r))
+{
irq_routines[irq] = handler;
}
// Removes the custom IRQ handler
-void irq_uninstall_handler(int irq) {
+void irq_uninstall_handler(int irq)
+{
irq_routines[irq] = 0;
}
-int irq_is_installed(int irq) {
+int irq_is_installed(int irq)
+{
return irq_routines[irq] != 0;
}
// Remap IRQs for protected mode compatibility via the PIC
-void irq_remap(void) {
- send_b(0x20, 0x11);
- send_b(0xA0, 0x11);
- send_b(0x21, 0x20);
- send_b(0xA1, 0x28);
- send_b(0x21, 0x04);
- send_b(0xA1, 0x02);
- send_b(0x21, 0x01);
- send_b(0xA1, 0x01);
- send_b(0x21, 0x0);
- send_b(0xA1, 0x0);
+void irq_remap(void)
+{
+ outb(0x20, 0x11);
+ outb(0xA0, 0x11);
+ outb(0x21, 0x20);
+ outb(0xA1, 0x28);
+ outb(0x21, 0x04);
+ outb(0xA1, 0x02);
+ outb(0x21, 0x01);
+ outb(0xA1, 0x01);
+ outb(0x21, 0x0);
+ outb(0xA1, 0x0);
}
// Map ISRs to the correct entries in the IDT
-void irq_install() {
+void irq_install()
+{
irq_remap();
idt_set_gate(32, (unsigned) irq0, 0x08, 0x8E);
idt_set_gate(33, (unsigned) irq1, 0x08, 0x8E);
@@ -87,11 +92,12 @@ void irq_install() {
idt_set_gate(45, (unsigned) irq13, 0x08, 0x8E);
idt_set_gate(46, (unsigned) irq14, 0x08, 0x8E);
idt_set_gate(47, (unsigned) irq15, 0x08, 0x8E);
- vga_log("Installed Interrupt Requests", 8);
+ vga_log("Installed Interrupt Requests", 7);
}
// Handle IRQ ISRs
-void irq_handler(struct regs *r) {
+void irq_handler(struct regs *r)
+{
void (*handler)(struct regs *r);
// Execute custom handler if exists
@@ -102,9 +108,9 @@ void irq_handler(struct regs *r) {
// Send end of interrupt to second (slave) IRQ controller
if (r->int_no >= 40) {
- send_b(0xA0, 0x20);
+ outb(0xA0, 0x20);
}
// Send end of interrupt to master interrupt controller
- send_b(0x20, 0x20);
+ outb(0x20, 0x20);
}
diff --git a/src/kernel/interrupts/isr.c b/src/kernel/interrupts/isr.c
index 28f67ae..d511dda 100644
--- a/src/kernel/interrupts/isr.c
+++ b/src/kernel/interrupts/isr.c
@@ -73,7 +73,8 @@ extern void isr31();
uint32_t ignored_isr[8] = {0};
// Install ISRs in IDT
-void isrs_install() {
+void isrs_install()
+{
idt_set_gate(0, (unsigned) isr0, 0x08, 0x8E);
idt_set_gate(1, (unsigned) isr1, 0x08, 0x8E);
idt_set_gate(2, (unsigned) isr2, 0x08, 0x8E);
@@ -110,7 +111,7 @@ void isrs_install() {
idt_set_gate(30, (unsigned) isr30, 0x08, 0x8E);
idt_set_gate(31, (unsigned) isr31, 0x08, 0x8E);
- vga_log("Installed Interrupt Service Routines", 7);
+ vga_log("Installed Interrupt Service Routines", 6);
}
// Error exception messages
@@ -153,10 +154,11 @@ const char *exception_messages[] = {
};
// Master exception/interrupt/fault handler - halt via panic
-void fault_handler(struct regs *r) {
+void fault_handler(struct regs *r)
+{
if (r->int_no < 32 && !(ignored_isr[r->int_no / 32] & (1 << (r->int_no % 32)))) {
uint32_t faulting_address;
- asm volatile("mov %%cr2, %0" : "=r" (faulting_address));
+ asm ("mov %%cr2, %0" : "=r" (faulting_address));
serial_write("\n[DEBUG]\nEIP: ");
serial_write_hex(r->eip);
@@ -174,14 +176,22 @@ void fault_handler(struct regs *r) {
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);
+ halt_loop(); // Idk loop?
char *message = (char *) exception_messages[r->int_no];
strcat(message, " Exception");
- if (r->err_code == 2) halt_loop(); // Idk loop?
panic(message);
}
}
-void isr_ignore(uint8_t int_no) { ignored_isr[int_no / 32] |= 1 << (int_no % 32); }
+void isr_ignore(uint8_t int_no)
+{
+ ignored_isr[int_no / 32] |= 1 << (int_no % 32);
+}
-void isr_remember(uint8_t int_no) { ignored_isr[int_no / 32] &= ~(1 << (int_no % 32)); }
+void isr_remember(uint8_t int_no)
+{
+ ignored_isr[int_no / 32] &= ~(1 << (int_no % 32));
+}
diff --git a/src/kernel/io/io.c b/src/kernel/io/io.c
index 3abbb18..c5ae657 100644
--- a/src/kernel/io/io.c
+++ b/src/kernel/io/io.c
@@ -5,64 +5,74 @@
#include <mlibc/string.h>
#include <mlibc/stdlib.h>
-uint8_t receive_b(uint16_t port) {
+uint8_t inb(uint16_t port)
+{
uint8_t value;
- asm volatile ("inb %1, %0" : "=a"(value) : "Nd"(port));
+ asm ("inb %1, %0" : "=a"(value) : "Nd"(port));
return value;
}
-uint16_t receive_w(uint16_t port) {
+uint16_t inw(uint16_t port)
+{
uint16_t value;
- asm volatile("inw %1, %0" : "=a"(value) : "Nd"(port));
+ asm ("inw %1, %0" : "=a"(value) : "Nd"(port));
return value;
}
-uint32_t receive_l(uint16_t port) {
+uint32_t inl(uint16_t port)
+{
uint32_t value;
- asm volatile ("inb %1, %0" : "=a"(value) : "Nd"(port));
+ asm ("inl %1, %0" : "=a"(value) : "Nd"(port));
return value;
}
-void send_b(uint16_t port, uint8_t data) {
- asm volatile ("outb %0, %1"::"a" (data), "Nd"(port));
+void outb(uint16_t port, uint8_t data)
+{
+ asm ("outb %0, %1"::"a" (data), "Nd"(port));
}
-void send_w(uint16_t port, uint16_t data) {
- asm volatile ("outw %0, %1"::"a" (data), "Nd"(port));
+void outw(uint16_t port, uint16_t data)
+{
+ asm ("outw %0, %1"::"a" (data), "Nd"(port));
}
-void send_l(uint16_t port, uint32_t data) {
- asm volatile ("outl %0, %1"::"a" (data), "Nd"(port));
+void outl(uint16_t port, uint32_t data)
+{
+ asm ("outl %0, %1"::"a" (data), "Nd"(port));
}
-void init_serial() {
- send_b(0x3f8 + 1, 0x00);
- send_b(0x3f8 + 3, 0x80);
- send_b(0x3f8 + 0, 0x03);
- send_b(0x3f8 + 1, 0x00);
- send_b(0x3f8 + 3, 0x03);
- send_b(0x3f8 + 2, 0xC7);
- send_b(0x3f8 + 4, 0x0B);
- serial_write("Installed serial connection!\n");
- vga_log("Installed serial connection", 3);
+void init_serial()
+{
+ outb(0x3f8 + 1, 0x00);
+ outb(0x3f8 + 3, 0x80);
+ outb(0x3f8 + 0, 0x03);
+ outb(0x3f8 + 1, 0x00);
+ outb(0x3f8 + 3, 0x03);
+ outb(0x3f8 + 2, 0xC7);
+ outb(0x3f8 + 4, 0x0B);
+ vga_log("Installed serial connection", 2);
}
-int is_transmit_empty() {
- return receive_b(0x3f8 + 5) & 0x20;
+int is_transmit_empty()
+{
+ return inb(0x3f8 + 5) & 0x20;
}
-void serial_put(char ch) {
+void serial_put(char ch)
+{
while (is_transmit_empty() == 0);
- send_b(0x3f8, ch);
+ outb(0x3f8, ch);
}
-void serial_write(const char *data) {
+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) {
+void serial_write_hex(int n)
+{
int tmp;
serial_write("0x");
@@ -89,6 +99,7 @@ void serial_write_hex(int n) {
}
}
-void serial_write_dec(int n) {
+void serial_write_dec(int n)
+{
serial_write(itoa(n));
}
diff --git a/src/kernel/io/io.h b/src/kernel/io/io.h
index 3c618d6..0ad5a54 100644
--- a/src/kernel/io/io.h
+++ b/src/kernel/io/io.h
@@ -8,42 +8,42 @@
* @param port The hardware port
* @return The hardware response
*/
-uint8_t receive_b(uint16_t port);
+uint8_t inb(uint16_t port);
/**
* Receive from specified hardware port
* @param port The hardware port
* @return The hardware response
*/
-uint16_t receive_w(uint16_t port);
+uint16_t inw(uint16_t port);
/**
* Receive from specified hardware port
* @param port The hardware port
* @return The hardware response
*/
-uint32_t receive_l(uint16_t port);
+uint32_t inl(uint16_t port);
/**
* Send data to the specified hardware port
* @param port The hardware port
* @param data The data that should be sent
*/
-void send_b(uint16_t port, uint8_t data);
+void outb(uint16_t port, uint8_t data);
/**
* Send data to the specified hardware port
* @param port The hardware port
* @param data The data that should be sent
*/
-void send_w(uint16_t port, uint16_t data);
+void outw(uint16_t port, uint16_t data);
/**
* Send data to the specified hardware port
* @param port The hardware port
* @param data The data that should be sent
*/
-void send_l(uint16_t port, uint32_t data);
+void outl(uint16_t port, uint32_t data);
/**
* Initialize the serial conenction
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index 20a7199..b717218 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -13,7 +13,8 @@
extern void switch_to_user();
-void kernel_main() {
+void kernel_main()
+{
vga_log("Installing basic features of Melvix...", 0);
// Install features
memory_init();
@@ -27,11 +28,11 @@ void kernel_main() {
set_optimal_resolution();
// Install drivers
- asm volatile ("cli");
+ asm ("cli");
mouse_install();
keyboard_install();
timer_install();
- asm volatile ("sti");
+ asm ("sti");
// Get hardware information
get_smbios();
@@ -44,14 +45,6 @@ void kernel_main() {
install_melvix();
}
- // Setup initial ramdisk
- /*assert(mboot_ptr->mods_count > 0);
- uint32_t initrd_location = *((uint32_t *) mboot_ptr->mods_addr);
- uint32_t initrd_end = *(uint32_t *) (mboot_ptr->mods_addr + 4);
- paging_set_used(0, (initrd_end >> 12) + 1);
- fs_root = initialise_initrd(initrd_location);
- initrd_test();*/
-
// User mode!
/* COMMENTED FOR DEVELOPMENT OF KERNEL
info("Switching to user mode...");
@@ -61,8 +54,8 @@ void kernel_main() {
panic("This should NOT happen!");
*/
- // asm volatile ("div %0" :: "r"(0)); // Exception testing x/0
+ // asm ("div %0" :: "r"(0)); // Exception testing x/0
loop:
- asm volatile ("hlt");
+ asm ("hlt");
goto loop;
}
diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c
index a80309e..c1c6ee1 100644
--- a/src/kernel/lib/memory.c
+++ b/src/kernel/lib/memory.c
@@ -2,20 +2,23 @@
#include <stdint.h>
#include <kernel/paging/paging.h>
-void *memcpy(void *dest, const void *src, size_t count) {
+void *memcpy(void *dest, const void *src, size_t count)
+{
const char *sp = (const char *) src;
char *dp = (char *) dest;
for (; count != 0; count--) *dp++ = *sp++;
return dest;
}
-void *memset(void *dest, char val, size_t count) {
+void *memset(void *dest, char val, size_t count)
+{
char *temp = (char *) dest;
for (; count != 0; count--) *temp++ = val;
return dest;
}
-int memcmp(const void *a_ptr, const void *b_ptr, size_t size) {
+int memcmp(const void *a_ptr, const void *b_ptr, size_t size)
+{
const unsigned char *a = (const unsigned char *) a_ptr;
const unsigned char *b = (const unsigned char *) b_ptr;
for (size_t i = 0; i < size; i++) {
@@ -35,25 +38,31 @@ struct memory_entry {
uint32_t type;
} __attribute__((packed));
-struct memory_entry *memory_get_entries() {
+struct memory_entry *memory_get_entries()
+{
return (struct memory_entry *) 0xA000;
}
-void memory_init() {
- uint64_t maxbase = 0;
- uint64_t maxlength = 0;
+void memory_init()
+{
+ uint64_t max_base = 0;
+ uint64_t max_length = 0;
for (struct memory_entry *i = memory_get_entries(); i->type; i++) {
- if (i->type == 1 && i->base > maxbase) {
- maxbase = i->base;
- maxlength = i->length;
+ if (i->type == 1 && i->base > max_base) {
+ max_base = i->base;
+ max_length = i->length;
}
}
- total_memory = maxbase + maxlength;
+ total_memory = max_base + max_length;
total_memory /= 1024;
}
-uint32_t memory_get_free() {
+uint32_t memory_get_free()
+{
return total_memory - paging_get_used_pages() * 4;
}
-uint32_t memory_get_all() { return total_memory; } \ No newline at end of file
+uint32_t memory_get_all()
+{
+ return total_memory;
+} \ No newline at end of file
diff --git a/src/kernel/paging/paging.c b/src/kernel/paging/paging.c
index 09cbbc0..4c8cb44 100644
--- a/src/kernel/paging/paging.c
+++ b/src/kernel/paging/paging.c
@@ -8,7 +8,8 @@ int paging_enabled = 0;
uint32_t page_directory[1024] __attribute__((aligned(4096)));
uint32_t page_tables[1024][1024] __attribute__((aligned(4096)));
-void paging_install() {
+void paging_install()
+{
for (uint32_t i = 0; i < 1024; i++) {
for (uint32_t j = 0; j < 1024; j++) {
page_tables[i][j] = ((j * 0x1000) + (i * 0x400000)) | PT_RW;
@@ -24,50 +25,58 @@ void paging_install() {
paging_enable();
serial_write_dec(memory_get_all() >> 10);
- vga_log("Installed paging", 5);
+
+ vga_log("Installed paging", 4);
}
-void paging_disable() {
+void paging_disable()
+{
uint32_t cr0;
- asm volatile("mov %%cr0, %0": "=r"(cr0));
+ asm ("mov %%cr0, %0": "=r"(cr0));
cr0 &= 0x7fffffff;
- asm volatile("mov %0, %%cr0"::"r"(cr0));
+ asm ("mov %0, %%cr0"::"r"(cr0));
paging_enabled = 0;
}
-void paging_enable() {
- asm volatile("mov %0, %%cr3"::"r"(page_directory));
+void paging_enable()
+{
+ asm ("mov %0, %%cr3"::"r"(page_directory));
uint32_t cr0;
- asm volatile("mov %%cr0, %0": "=r"(cr0));
+ asm ("mov %%cr0, %0": "=r"(cr0));
cr0 |= 0x80000000;
- asm volatile("mov %0, %%cr0"::"r"(cr0));
+ asm ("mov %0, %%cr0"::"r"(cr0));
paging_enabled = 1;
}
-inline void invlpg(uint32_t addr) {
- asm volatile("invlpg (%0)"::"r" (addr) : "memory");
+inline void invlpg(uint32_t addr)
+{
+ asm ("invlpg (%0)"::"r" (addr) : "memory");
}
-void paging_map(uint32_t phy, uint32_t virt, uint16_t flags) {
+void paging_map(uint32_t phy, uint32_t virt, uint16_t flags)
+{
uint32_t pdi = virt >> 22;
uint32_t pti = virt >> 12 & 0x03FF;
page_tables[pdi][pti] = phy | flags;
invlpg(virt);
}
-uint32_t paging_get_physical_addr(uint32_t virt) {
+uint32_t paging_get_physical_addr(uint32_t virt)
+{
uint32_t pdi = virt >> 22;
uint32_t pti = (virt >> 12) & 0x03FF;
return page_tables[pdi][pti] & 0xFFFFF000;
}
-uint16_t paging_get_flags(uint32_t virt) {
+uint16_t paging_get_flags(uint32_t virt)
+{
uint32_t pdi = virt >> 22;
uint32_t pti = (virt >> 12) & 0x03FF;
return page_tables[pdi][pti] & 0xFFF;
}
-void paging_set_flag_up(uint32_t virt, uint32_t count, uint32_t flag) {
+void paging_set_flag_up(uint32_t virt, uint32_t count, uint32_t flag)
+{
uint32_t page_n = virt / 4096;
for (uint32_t i = page_n; i < page_n + count; i++) {
page_tables[i / 1024][i % 1024] |= flag;
@@ -75,7 +84,8 @@ void paging_set_flag_up(uint32_t virt, uint32_t count, uint32_t flag) {
}
}
-void paging_set_flag_down(uint32_t virt, uint32_t count, uint32_t flag) {
+void paging_set_flag_down(uint32_t virt, uint32_t count, uint32_t flag)
+{
uint32_t page_n = virt / 4096;
for (uint32_t i = page_n; i < page_n + count; i++) {
page_tables[i / 1024][i % 1024] &= ~flag;
@@ -83,23 +93,28 @@ void paging_set_flag_down(uint32_t virt, uint32_t count, uint32_t flag) {
}
}
-void paging_set_present(uint32_t virt, uint32_t count) {
+void paging_set_present(uint32_t virt, uint32_t count)
+{
paging_set_flag_up(virt, count, PT_PRESENT);
}
-void paging_set_absent(uint32_t virt, uint32_t count) {
+void paging_set_absent(uint32_t virt, uint32_t count)
+{
paging_set_flag_down(virt, count, PT_PRESENT);
}
-void paging_set_used(uint32_t virt, uint32_t count) {
+void paging_set_used(uint32_t virt, uint32_t count)
+{
paging_set_flag_up(virt, count, PT_USED);
}
-void paging_set_free(uint32_t virt, uint32_t count) {
+void paging_set_free(uint32_t virt, uint32_t count)
+{
paging_set_flag_down(virt, count, PT_USED);
}
-void paging_set_user(uint32_t virt, uint32_t count) {
+void paging_set_user(uint32_t virt, uint32_t count)
+{
uint32_t page_n = virt / 4096;
for (uint32_t i = page_n; i < page_n + count; i += 1024) {
page_directory[i / 1024] |= PD_ALL_PRIV;
@@ -107,7 +122,8 @@ void paging_set_user(uint32_t virt, uint32_t count) {
paging_set_flag_up(virt, count, PT_ALL_PRIV);
}
-uint32_t paging_find_pages(uint32_t count) {
+uint32_t paging_find_pages(uint32_t count)
+{
uint32_t continous = 0;
uint32_t startDir = 0;
uint32_t startPage = 0;
@@ -128,13 +144,15 @@ uint32_t paging_find_pages(uint32_t count) {
return 0;
}
-uint32_t paging_alloc_pages(uint32_t count) {
+uint32_t paging_alloc_pages(uint32_t count)
+{
uint32_t ptr = paging_find_pages(count);
paging_set_used(ptr, count);
return ptr;
}
-uint32_t paging_get_used_pages() {
+uint32_t paging_get_used_pages()
+{
uint32_t n = 0;
for (uint32_t i = 0; i < 1024; i++) {
for (uint32_t j = 0; j < 1024; j++) {
diff --git a/src/kernel/smbios/smbios.c b/src/kernel/smbios/smbios.c
index 0275f48..95ea70c 100644
--- a/src/kernel/smbios/smbios.c
+++ b/src/kernel/smbios/smbios.c
@@ -4,33 +4,18 @@
#include <kernel/io/io.h>
#include <kernel/smbios/smbios.h>
-struct smbios_entry {
- int8_t signature[4];
- uint8_t checksum;
- uint8_t length;
- uint8_t major_version;
- uint8_t minor_version;
- uint8_t max_structure_size;
- int8_t entry_point_revision;
- int8_t formatted_area[5];
- int8_t entry_point_signature[5];
- uint8_t checksum2;
- uint16_t table_length;
- uint32_t table_address;
- uint16_t number_of_structures;
- uint8_t bcd_revision;
-};
-
struct smbios_entry *smbios = 0;
-size_t smbios_table_len(struct smbios_header *header) {
+size_t smbios_table_len(struct smbios_header *header)
+{
size_t i;
const char *strtab = (char *) header + header->length;
for (i = 1; strtab[i - 1] != '\0' || strtab[i] != '\0'; i++);
return header->length + i + 1;
}
-struct smbios_entry *get_smbios() {
+struct smbios_entry *get_smbios()
+{
if (smbios != 0) return smbios;
char *mem = (char *) 0xF0000;
@@ -59,7 +44,8 @@ struct smbios_entry *get_smbios() {
return smbios;
}
-void smbios_table(struct smbios_header *header) {
+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);
diff --git a/src/kernel/smbios/smbios.h b/src/kernel/smbios/smbios.h
index 384119c..4814a17 100644
--- a/src/kernel/smbios/smbios.h
+++ b/src/kernel/smbios/smbios.h
@@ -7,6 +7,23 @@ struct smbios_header {
uint16_t handle;
};
+struct smbios_entry {
+ int8_t signature[4];
+ uint8_t checksum;
+ uint8_t length;
+ uint8_t major_version;
+ uint8_t minor_version;
+ uint8_t max_structure_size;
+ int8_t entry_point_revision;
+ int8_t formatted_area[5];
+ int8_t entry_point_signature[5];
+ uint8_t checksum2;
+ uint16_t table_length;
+ uint32_t table_address;
+ uint16_t number_of_structures;
+ uint8_t bcd_revision;
+};
+
struct smbios_0 {
char *vendor;
char *bios_version;
diff --git a/src/kernel/sound/frequency.c b/src/kernel/sound/frequency.c
index 2a88446..5ad76b3 100644
--- a/src/kernel/sound/frequency.c
+++ b/src/kernel/sound/frequency.c
@@ -2,29 +2,32 @@
#include <kernel/io/io.h>
#include <kernel/timer/timer.h>
-void play_sound(uint32_t frequency) {
+void play_sound(uint32_t frequency)
+{
uint32_t divided;
uint8_t tmp;
divided = 1193180 / frequency;
- send_b(0x43, 0xb6);
- send_b(0x42, (uint8_t) (divided));
- send_b(0x42, (uint8_t) (divided >> 8));
+ outb(0x43, 0xb6);
+ outb(0x42, (uint8_t) (divided));
+ outb(0x42, (uint8_t) (divided >> 8));
- tmp = receive_b(0x61);
+ tmp = inb(0x61);
if (tmp != (tmp | 3)) {
- send_b(0x61, tmp | 3);
+ outb(0x61, tmp | 3);
}
}
-static void shut_up() {
- uint8_t tmp = receive_b(0x61) & 0xFC;
+static void shut_up()
+{
+ uint8_t tmp = inb(0x61) & 0xFC;
- send_b(0x61, tmp);
+ outb(0x61, tmp);
}
// Make a beep
-void beep(uint32_t frequency, uint32_t ticks) {
+void beep(uint32_t frequency, uint32_t ticks)
+{
play_sound(frequency);
timer_wait(ticks);
shut_up();
diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c
index dec3e8e..1a8de52 100644
--- a/src/kernel/syscall/syscall.c
+++ b/src/kernel/syscall/syscall.c
@@ -17,7 +17,8 @@ static void *syscalls[3] = {
};
uint32_t num_syscalls = 3;
-void syscall_handler(struct regs *r) {
+void syscall_handler(struct regs *r)
+{
serial_write("SYSCALL");
if (r->eax >= num_syscalls)
return;
@@ -25,7 +26,7 @@ void syscall_handler(struct regs *r) {
void *location = syscalls[r->eax];
int ret;
- asm volatile (" \
+ asm (" \
push %1; \
push %2; \
push %3; \
@@ -41,6 +42,7 @@ void syscall_handler(struct regs *r) {
r->eax = ret;
}
-void syscalls_install() {
+void syscalls_install()
+{
irq_install_handler(0x80, syscall_handler);
}
diff --git a/src/kernel/system.c b/src/kernel/system.c
index 560f6a5..2c9a6d2 100644
--- a/src/kernel/system.c
+++ b/src/kernel/system.c
@@ -8,14 +8,16 @@
char *vga_buffer = (char *) 0x500;
-void vga_clear() {
+void vga_clear()
+{
uint16_t *terminal_buffer = (uint16_t *) 0xB8000;
for (size_t y = 0; y < 25; y++)
for (size_t x = 0; x < 80; x++)
terminal_buffer[y * 80 + x] = 0 | (uint16_t) 0x700;
}
-void vga_log(char *msg, int line) {
+void vga_log(char *msg, int line)
+{
if (line == 0) vga_clear();
uint16_t *terminal_buffer = (uint16_t *) 0xB8000;
for (size_t i = 0; i < strlen(msg); i++)
@@ -30,21 +32,24 @@ void vga_log(char *msg, int line) {
strcat(vga_buffer, string);
}
-void kernel_time() {
+void kernel_time()
+{
vesa_draw_string("\n");
vesa_draw_string("[");
vesa_draw_number((int) get_time());
vesa_draw_string("] ");
}
-void log(char *msg) {
+void log(char *msg)
+{
vesa_set_color(vesa_dark_white);
kernel_time();
vesa_draw_string(msg);
vesa_set_color(default_text_color);
}
-void info(char *msg) {
+void info(char *msg)
+{
vesa_set_color(vesa_blue);
kernel_time();
vesa_draw_string("INFORMATION: ");
@@ -52,7 +57,8 @@ void info(char *msg) {
vesa_set_color(default_text_color);
}
-void warn(char *msg) {
+void warn(char *msg)
+{
vesa_set_color(vesa_dark_yellow);
kernel_time();
vesa_draw_string("WARNING: ");
@@ -60,8 +66,9 @@ void warn(char *msg) {
vesa_set_color(default_text_color);
}
-void panic(char *msg) {
- asm volatile ("cli");
+void panic(char *msg)
+{
+ asm ("cli");
vesa_set_color(vesa_dark_red);
kernel_time();
serial_write("\nPANIC: ");
@@ -73,20 +80,23 @@ void panic(char *msg) {
halt_loop();
}
-void assert(int x) {
+void assert(int x)
+{
if (x == 0) {
panic("Assertion failed");
}
}
-void halt_loop() {
+void halt_loop()
+{
serial_write("\n!!! HALT !!!\n");
loop:
- asm volatile ("hlt");
+ asm ("hlt");
goto loop;
}
-void v86(uint8_t code, regs16_t *regs) {
+void v86(uint8_t code, regs16_t *regs)
+{
paging_disable();
int32(code, regs);
paging_enable();
diff --git a/src/kernel/timer/timer.c b/src/kernel/timer/timer.c
index 0e10c07..defb95d 100644
--- a/src/kernel/timer/timer.c
+++ b/src/kernel/timer/timer.c
@@ -4,35 +4,39 @@
unsigned long timer_ticks = 0;
-void timer_phase(int hz) {
+void timer_phase(int hz)
+{
int divisor = (int) (3579545.0 / 3.0 / (double) hz);
- send_b(0x43, 0x36); // 01 10 11 0b // CTR, RW, MODE, BCD
- send_b(0x40, divisor & 0xFF);
- send_b(0x40, divisor >> 8);
+ outb(0x43, 0x36); // 01 10 11 0b // CTR, RW, MODE, BCD
+ outb(0x40, divisor & 0xFF);
+ outb(0x40, divisor >> 8);
}
// Executed 1000 times per second
-void timer_handler(struct regs *r) {
+void timer_handler(struct regs *r)
+{
timer_ticks++;
}
// "Delay" function with CPU sleep
-void timer_wait(int ticks) {
+void timer_wait(int ticks)
+{
unsigned int eticks;
eticks = timer_ticks + ticks;
while (timer_ticks < eticks) {
- asm volatile ("sti//hlt//cli");
+ asm ("sti//hlt//cli");
}
}
-unsigned int get_time() {
+unsigned int get_time()
+{
return timer_ticks;
}
// Install timer handler into IRQ0
-void timer_install() {
+void timer_install()
+{
timer_phase(1000);
irq_install_handler(0, timer_handler);
- vga_log("Installed timer", 1);
} \ No newline at end of file
diff --git a/src/mlibc/math/pow.c b/src/mlibc/math/pow.c
index 4f040bb..24670a0 100644
--- a/src/mlibc/math/pow.c
+++ b/src/mlibc/math/pow.c
@@ -1,4 +1,5 @@
-int pow(int base, int exp) {
+int pow(int base, int exp)
+{
if (exp < 0) return 0;
if (!exp) return 1;
diff --git a/src/mlibc/stdio/printf.c b/src/mlibc/stdio/printf.c
index 11516cf..23d8e6e 100644
--- a/src/mlibc/stdio/printf.c
+++ b/src/mlibc/stdio/printf.c
@@ -4,11 +4,13 @@
#include <mlibc/string.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]);
}
-void printf(const char *fmt, ...) {
+void printf(const char *fmt, ...)
+{
va_list args;
va_start(args, fmt);
diff --git a/src/mlibc/stdio/writec.c b/src/mlibc/stdio/writec.c
index 60f69e8..94d4fed 100644
--- a/src/mlibc/stdio/writec.c
+++ b/src/mlibc/stdio/writec.c
@@ -1,5 +1,6 @@
#include <kernel/graphics/vesa.h>
-void writec(char c) {
+void writec(char c)
+{
vesa_draw_char(c);
} \ No newline at end of file
diff --git a/src/mlibc/stdlib.h b/src/mlibc/stdlib.h
index 7ae9c5a..36a3b5f 100644
--- a/src/mlibc/stdlib.h
+++ b/src/mlibc/stdlib.h
@@ -4,11 +4,15 @@
#include <stdint.h>
#ifndef MELVIX_ALLOC_H
+
#include <mlibc/stdlib/liballoc.h>
+
#endif
#ifndef MELVIX_STRING_H
+
#include <mlibc/string.h>
+
#endif
char *itoa(int n);
diff --git a/src/mlibc/stdlib/atoi.c b/src/mlibc/stdlib/atoi.c
index 34f9991..0643372 100644
--- a/src/mlibc/stdlib/atoi.c
+++ b/src/mlibc/stdlib/atoi.c
@@ -3,7 +3,8 @@
#include <stdint.h>
#include <mlibc/string.h>
-int atoi(char *str) {
+int atoi(char *str)
+{
size_t s_str = strlen(str);
if (!s_str) return 0;
diff --git a/src/mlibc/stdlib/htoa.c b/src/mlibc/stdlib/htoa.c
index 5290c74..ab20260 100644
--- a/src/mlibc/stdlib/htoa.c
+++ b/src/mlibc/stdlib/htoa.c
@@ -4,7 +4,8 @@
static const char __HTOA_TABLE[] = "0123456789ABCDEF";
-char *htoa(uint32_t n) {
+char *htoa(uint32_t n)
+{
char *ret = kmalloc(10);
int i = 0;
diff --git a/src/mlibc/stdlib/htoi.c b/src/mlibc/stdlib/htoi.c
index 73a583b..c78fe9d 100644
--- a/src/mlibc/stdlib/htoi.c
+++ b/src/mlibc/stdlib/htoi.c
@@ -2,7 +2,8 @@
#include <stddef.h>
#include <mlibc/string.h>
-int htoi(char *str) {
+int htoi(char *str)
+{
size_t s_str = strlen(str);
size_t i = 0;
diff --git a/src/mlibc/stdlib/itoa.c b/src/mlibc/stdlib/itoa.c
index 8c557ab..3c8ee05 100644
--- a/src/mlibc/stdlib/itoa.c
+++ b/src/mlibc/stdlib/itoa.c
@@ -6,7 +6,8 @@
static const char __ITOA_TABLE[] = "0123456789";
-char *itoa(int n) {
+char *itoa(int n)
+{
if (paging_enabled == 0)
return "0"; // kmalloc isn't available
diff --git a/src/mlibc/stdlib/liballoc.c b/src/mlibc/stdlib/liballoc.c
index f4015f2..3938215 100644
--- a/src/mlibc/stdlib/liballoc.c
+++ b/src/mlibc/stdlib/liballoc.c
@@ -3,22 +3,26 @@
#include <kernel/paging/paging.h>
#include <mlibc/stdlib/liballoc.h>
-int liballoc_lock() {
- // asm volatile ("cli");
+int liballoc_lock()
+{
+ // asm ("cli");
return 0;
}
-int liballoc_unlock() {
- // asm volatile ("sti");
+int liballoc_unlock()
+{
+ // asm ("sti");
return 0;
}
-void *liballoc_alloc(size_t p) {
+void *liballoc_alloc(size_t p)
+{
uint32_t ptr = paging_alloc_pages((uint32_t) p);
return (void *) ptr;
}
-int liballoc_free(void *ptr, size_t p) {
+int liballoc_free(void *ptr, size_t p)
+{
paging_set_free((uint32_t) ptr, (uint32_t) p);
return 0;
}
@@ -52,8 +56,8 @@ int liballoc_free(void *ptr, size_t p) {
} \
}
-#define LIBALLOC_MAGIC 0xc001c0de
-#define LIBALLOC_DEAD 0xdeaddead
+#define LIBALLOC_MAGIC 0x900df00d
+#define LIBALLOC_DEAD 0xbaadf00d
struct liballoc_major {
struct liballoc_major *prev;
@@ -85,7 +89,8 @@ static long long l_warningCount = 0;
static long long l_errorCount = 0;
static long long l_possibleOverruns = 0;
-static void *liballoc_memset(void *s, int c, size_t n) {
+static void *liballoc_memset(void *s, int c, size_t n)
+{
unsigned int i;
for (i = 0; i < n; i++)
((char *) s)[i] = c;
@@ -93,7 +98,8 @@ static void *liballoc_memset(void *s, int c, size_t n) {
return s;
}
-static void *liballoc_memcpy(void *s1, const void *s2, size_t n) {
+static void *liballoc_memcpy(void *s1, const void *s2, size_t n)
+{
char *cdest;
char *csrc;
unsigned int *ldest = (unsigned int *) s1;
@@ -114,7 +120,8 @@ static void *liballoc_memcpy(void *s1, const void *s2, size_t n) {
return s1;
}
-static struct liballoc_major *allocate_new_page(unsigned int size) {
+static struct liballoc_major *allocate_new_page(unsigned int size)
+{
unsigned int st;
struct liballoc_major *maj;
@@ -147,7 +154,8 @@ static struct liballoc_major *allocate_new_page(unsigned int size) {
return maj;
}
-void *PREFIX(malloc)(size_t req_size) {
+void *PREFIX(malloc)(size_t req_size)
+{
int startedBet = 0;
unsigned long long bestSize = 0;
void *p = NULL;
@@ -334,7 +342,8 @@ void *PREFIX(malloc)(size_t req_size) {
return NULL;
}
-void PREFIX(free)(void *ptr) {
+void PREFIX(free)(void *ptr)
+{
struct liballoc_minor *min;
struct liballoc_major *maj;
@@ -386,7 +395,8 @@ void PREFIX(free)(void *ptr) {
liballoc_unlock();
}
-void *PREFIX(calloc)(size_t nobj, size_t size) {
+void *PREFIX(calloc)(size_t nobj, size_t size)
+{
int real_size;
void *p;
@@ -399,7 +409,8 @@ void *PREFIX(calloc)(size_t nobj, size_t size) {
return p;
}
-void *PREFIX(realloc)(void *p, size_t size) {
+void *PREFIX(realloc)(void *p, size_t size)
+{
void *ptr;
struct liballoc_minor *min;
unsigned int real_size;
diff --git a/src/mlibc/string/strcat.c b/src/mlibc/string/strcat.c
index 3cc56f1..0448430 100644
--- a/src/mlibc/string/strcat.c
+++ b/src/mlibc/string/strcat.c
@@ -1,6 +1,7 @@
#include <mlibc/string.h>
-void strcat(char *dest, const char *orig) {
+void strcat(char *dest, const char *orig)
+{
size_t s_dest = strlen(dest);
size_t s_orig = strlen(orig);
diff --git a/src/mlibc/string/strcati.c b/src/mlibc/string/strcati.c
index d925eb7..8fdcc1a 100644
--- a/src/mlibc/string/strcati.c
+++ b/src/mlibc/string/strcati.c
@@ -1,6 +1,7 @@
#include <mlibc/string.h>
-void strcati(char *dest, const char *orig) {
+void strcati(char *dest, const char *orig)
+{
size_t s_orig = strlen(orig);
strdisp(dest, (int) s_orig);
for (size_t i = 0; i < s_orig; i++) dest[i] = orig[i];
diff --git a/src/mlibc/string/strcmp.c b/src/mlibc/string/strcmp.c
index cc719da..be6c17a 100644
--- a/src/mlibc/string/strcmp.c
+++ b/src/mlibc/string/strcmp.c
@@ -1,6 +1,7 @@
#include <mlibc/string.h>
-char strcmp(const char *a, const char *b) {
+char strcmp(const char *a, const char *b)
+{
if (strlen(a) != strlen(b)) return 1;
for (size_t i = 0; i < strlen(a); i++) if (a[i] != b[i]) return 1;
diff --git a/src/mlibc/string/strcpy.c b/src/mlibc/string/strcpy.c
index 5a1ff4e..8dfa65f 100644
--- a/src/mlibc/string/strcpy.c
+++ b/src/mlibc/string/strcpy.c
@@ -1,6 +1,7 @@
#include <mlibc/string.h>
-void strcpy(char *dest, const char *orig) {
+void strcpy(char *dest, const char *orig)
+{
size_t s_orig = strlen(orig);
for (size_t i = 0; i < s_orig; i++) dest[i] = orig[i];
diff --git a/src/mlibc/string/strdisp.c b/src/mlibc/string/strdisp.c
index 6feb4ca..d793718 100644
--- a/src/mlibc/string/strdisp.c
+++ b/src/mlibc/string/strdisp.c
@@ -1,10 +1,12 @@
#include <mlibc/string.h>
-void strdisponce(char *str) {
+void strdisponce(char *str)
+{
for (size_t i = sizeof(str) + 2; i > 0; i--) str[i] = str[i - 1];
str[0] = 0;
}
-void strdisp(char *str, int n) {
+void strdisp(char *str, int n)
+{
for (int i = 0; i < n; i++) strdisponce(str);
} \ No newline at end of file
diff --git a/src/mlibc/string/strdup.c b/src/mlibc/string/strdup.c
index 0cddd79..0aa36f7 100644
--- a/src/mlibc/string/strdup.c
+++ b/src/mlibc/string/strdup.c
@@ -1,7 +1,8 @@
#include <mlibc/string.h>
#include <mlibc/stdlib.h>
-char *strdup(const char *orig) {
+char *strdup(const char *orig)
+{
size_t s_orig = strlen(orig);
char *ret = kmalloc(s_orig + 1);
strcpy(ret, orig);
diff --git a/src/mlibc/string/strinv.c b/src/mlibc/string/strinv.c
index c6dd7fd..71f3355 100644
--- a/src/mlibc/string/strinv.c
+++ b/src/mlibc/string/strinv.c
@@ -1,6 +1,7 @@
#include <mlibc/string.h>
-void strinv(char *str) {
+void strinv(char *str)
+{
size_t s_str = strlen(str);
int iterations = (int) s_str / 2;
diff --git a/src/mlibc/string/strlen.c b/src/mlibc/string/strlen.c
index 1143683..133ee3d 100644
--- a/src/mlibc/string/strlen.c
+++ b/src/mlibc/string/strlen.c
@@ -1,6 +1,7 @@
#include <mlibc/string.h>
-size_t strlen(const char *str) {
+size_t strlen(const char *str)
+{
size_t len = 0;
while (str[len]) len++;
return len;
diff --git a/src/userspace/main.c b/src/userspace/main.c
index 526144e..73e937f 100644
--- a/src/userspace/main.c
+++ b/src/userspace/main.c
@@ -1,5 +1,6 @@
#include <kernel/syscall/syscall.h>
-void test_user() {
+void test_user()
+{
syscall_serial_write("Hello, user world!\n");
} \ No newline at end of file