summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2021-12-12 21:28:58 -0500
committerJon Santmyer <jon@jonsantmyer.com>2021-12-12 21:28:58 -0500
commit20eabc31afd313857d3e127fbd8c58af76e848ed (patch)
tree05362f6aa6536a5da6221fed04273018ccc9796c
parent63a5f312b06143951a49faad190d1ab2fd37fcc5 (diff)
downloadmodit-kernel-20eabc31afd313857d3e127fbd8c58af76e848ed.tar.gz
modit-kernel-20eabc31afd313857d3e127fbd8c58af76e848ed.tar.bz2
modit-kernel-20eabc31afd313857d3e127fbd8c58af76e848ed.zip
add license information to headers; prepare for rework
-rw-r--r--.gitmodules3
-rw-r--r--include/arch_common/ansi.h6
-rw-r--r--include/arch_common/boot.h19
-rw-r--r--include/arch_common/edid.h78
-rw-r--r--include/arch_common/heap.h28
-rw-r--r--include/arch_common/initrd.h17
-rw-r--r--include/arch_common/list.h25
-rw-r--r--include/arch_common/modit.h23
-rw-r--r--include/arch_common/panic.h21
-rw-r--r--include/arch_common/pmm.h20
-rw-r--r--include/arch_common/serialtxt.h20
-rw-r--r--include/arch_common/stdio.h17
-rw-r--r--include/arch_common/stdlib.h13
-rw-r--r--include/arch_common/string.h25
-rw-r--r--include/arch_common/vgatxt.h19
-rw-r--r--include/arch_common/vmm.h19
-rw-r--r--include/arch_x86/64/apic.h18
-rw-r--r--include/arch_x86/64/idt.h18
-rw-r--r--include/arch_x86/64/page.h18
-rw-r--r--include/arch_x86/64/registers.h18
-rw-r--r--include/arch_x86/common/acpi.h17
-rw-r--r--include/arch_x86/common/gdt.h18
-rw-r--r--include/arch_x86/common/interrupt.h18
-rw-r--r--include/arch_x86/common/ipc.h18
-rw-r--r--include/arch_x86/common/pic.h18
-rw-r--r--include/arch_x86/common/pit.h18
-rw-r--r--include/arch_x86/common/syscall.h18
-rw-r--r--include/arch_x86/common/task.h18
-rw-r--r--include/arch_x86/common/timer.h18
-rw-r--r--include/arch_x86/common/user.h18
-rw-r--r--include/arch_x86/common/x86.h18
-rw-r--r--src/arch_common/init/init.c3
-rw-r--r--src/arch_common/initrd/initrd.c2
-rw-r--r--src/arch_common/initrd/tar.c2
-rw-r--r--src/arch_x86/64/apic/ioapic.c4
-rw-r--r--src/arch_x86/64/heap/Makefile (renamed from src/arch_x86/common/heap/Makefile)3
m---------src/arch_x86/64/heap/diheap0
-rw-r--r--src/arch_x86/64/heap/main.c66
-rw-r--r--src/arch_x86/64/task/context.c3
-rw-r--r--src/arch_x86/64/task/load.c8
-rw-r--r--src/arch_x86/64/task/message.c10
-rw-r--r--src/arch_x86/64/task/port.c6
-rw-r--r--src/arch_x86/common/acpi/madt.c8
-rw-r--r--src/arch_x86/common/acpi/main.c2
-rw-r--r--src/arch_x86/common/acpi/rsdt.c7
-rw-r--r--src/arch_x86/common/heap/main.c311
46 files changed, 587 insertions, 470 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..b281561
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "src/arch_x86/64/heap/diheap"]
+ path = src/arch_x86/64/heap/diheap
+ url = https://git.jonsantmyer.com/diheap
diff --git a/include/arch_common/ansi.h b/include/arch_common/ansi.h
deleted file mode 100644
index e847f78..0000000
--- a/include/arch_common/ansi.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef KERNEL_ANSI_H
-#define KERNEL_ANSI_H 1
-
-char ansi_parse(char c);
-
-#endif
diff --git a/include/arch_common/boot.h b/include/arch_common/boot.h
index bac9b5e..bdd1b8b 100644
--- a/include/arch_common/boot.h
+++ b/include/arch_common/boot.h
@@ -1,4 +1,21 @@
-/* Generalized functions for accessing information passed to the kernel through the boot loader
+/**
+ * include/arch_common/boot.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Generalized functions for accessing information passed to the kernel through the boot loader
* */
#ifndef KERNEL_BOOT_H
diff --git a/include/arch_common/edid.h b/include/arch_common/edid.h
deleted file mode 100644
index a8341d9..0000000
--- a/include/arch_common/edid.h
+++ /dev/null
@@ -1,78 +0,0 @@
-#ifndef KERNEL_EDID_H
-#define KERNEL_EDID_H 1
-
-struct edid {
- uint8_t padding[8];
- uint16_t manufacturer;
- uint16_t id_code;
- uint32_t serial;
- uint8_t man_week;
- uint8_t man_year;
- uint8_t version;
- uint8_t revision;
- uint8_t input_type;
- uint8_t horizontal_size;
- uint8_t vertical_size;
- uint8_t gamma;
- uint8_t dpms;
- uint8_t chroma[10];
- uint8_t timings_1;
- uint8_t timings_2;
- uint8_t timings_reserved;
- uint16_t time_identification[8];
- uint8_t timing_1_description[18];
- uint8_t timing_2_description[18];
- uint8_t timing_3_description[18];
- uint8_t timing_4_description[18];
- uint8_t reserved;
- uint8_t checksum;
-};
-
-#define EDID_VIDEO_INPUT_SEPERATE_SYNC 0b00000001
-#define EDID_VIDEO_INPUT_COMPOSITE_SYNC 0b00000010
-#define EDID_VIDEO_INPUT_SYNC_GREEN 0b00000100
-#define EDID_VIDEO_INPUT_VOLTAGE_LEVEL 0b01100000
-#define EDID_VIDEO_INPUT_DIGITAL_SIGNAL 0b10000000
-
-#define EDID_DPMS_DISPLAY_TYPE 0b00001000
-#define EDID_DPMS_SUPPORT_ACTIVE_OFF 0b00100000
-#define EDID_DPMS_SUPPORT_SUSPEND 0b01000000
-#define EDID_DPMS_SUPPORT_STANDBY 0b10000000
-
-#define EDID_CHROMA_GREENXY_REDXY 0
-#define EDID_CHROMA_WHITEXY_BLUEXY 1
-#define EDID_CHROMA_RED_Y 2
-#define EDID_CHROMA_RED_X 3
-#define EDID_CHROMA_GREEN_Y 4
-#define EDID_CHROMA_GREEN_X 5
-#define EDID_CHROMA_BLUE_Y 6
-#define EDID_CHROMA_BLUE_X 7
-#define EDID_CHROMA_WHITE_Y 8
-#define EDID_CHROMA_WHITE_X 9
-
-#define EDID_TIMING_DESC_HORIZONTAL_FREQ 0
-#define EDID_TIMING_DESC_VERTICAL_FREQ 1
-#define EDID_TIMING_DESC_HORIZONTAL_ACTIVE 2
-#define EDID_TIMING_DESC_HORIZONTAL_BLANKING 3
-#define EDID_TIMING_DESC_HORIZONTAL_RATIO 4
-#define EDID_TIMING_DESC_VERTICAL_ACTIVE 5
-#define EDID_TIMING_DESC_VERTICAL_BLANKING 6
-#define EDID_TIMING_DESC_VERTICAL_RATIO 7
-#define EDID_TIMING_DESC_HORIZ_SYNC_OFF 8
-#define EDID_TIMING_DESC_HORIZ_SYNC_PULSE 9
-#define EDID_TIMING_DESC_VERT_SYNC_RATIO 10
-#define EDID_TIMING_DESC_SYNC_RATIO 11
-#define EDID_TIMING_DESC_HORIZONTAL_SIZE 12
-#define EDID_TIMING_DESC_VERTICAL_SIZE 13
-#define EDID_TIMING_DESC_SIZE_RATIO 14
-#define EDID_TIMING_DESC_HORIZONTAL_BORDER 15
-#define EDID_TIMING_DESC_VERTICAL_BORDER 16
-#define EDID_TIMING_DESC_DISPLAY_TYPE 17
-
-#define EDID_DISPLAY_TYPE_INTERLACED 0b10000000
-#define EDID_DISPLAY_TYPE_STEREO_MODE 0b01100000
-#define EDID_DISPLAY_TYPE_SYNC_TYPE 0b00011000
-#define EDID_DISPLAY_TYPE_SEPERATE 0b00000100
-#define EDID_DISPLAY_TYPE_SYNC_LOCATION 0b00000010
-
-#endif
diff --git a/include/arch_common/heap.h b/include/arch_common/heap.h
index d50fa0e..6fc28af 100644
--- a/include/arch_common/heap.h
+++ b/include/arch_common/heap.h
@@ -1,11 +1,33 @@
+/**
+ * include/arch_common/heap.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Provides a stdlib-like interface for allocating dynamic memory
+ */
#ifndef MODIT_KERNEL_HEAP_H
#define MODIT_KERNEL_HEAP_H 1
#include <stddef.h>
-void *kmalloc(size_t size, const char *reason);
-void *kmalloc_a(size_t size, size_t alignto, const char *reason);
+/* Allocates a block of memory atleast [size] bytes wide
+ * If size is a multiple of PAGE_SIZE, address returned is
+ * always page aligned */
+void *malloc(size_t size);
-void kfree(void *ptr);
+/* Frees memory allocated by malloc */
+void free(void *ptr);
#endif
diff --git a/include/arch_common/initrd.h b/include/arch_common/initrd.h
index 76b84e0..06ffd50 100644
--- a/include/arch_common/initrd.h
+++ b/include/arch_common/initrd.h
@@ -1,3 +1,20 @@
+/**
+ * include/arch_common/initrd.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#ifndef MODIT_KERNEL_INITRD_H
#define MODIT_KERNEL_INITRD_H 1
diff --git a/include/arch_common/list.h b/include/arch_common/list.h
deleted file mode 100644
index 923010c..0000000
--- a/include/arch_common/list.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef MODIT_KERNEL_KLIBC_LIST_H
-#define MODIT_KERNEL_KLIBC_LIST_H 1
-
-#include <stddef.h>
-
-//Add struct to top of struct to create sll node object for data type
-struct sllist
-{
- struct sllist *next;
-};
-
-#define sll_foreach(type, head) for(type * node = head; node != NULL; node = (type*)(((struct sllist*) node)->next))
-
-//Returns count of all elements in sll
-size_t sll_count(void *head);
-
-//Returns data for element at index n, NULL for oob
-void *sll_at(void *head, size_t n);
-
-//Returns new tail
-void *sll_append(void *tail, void *node);
-
-void *sll_appbeg(void *head, void *node);
-
-#endif
diff --git a/include/arch_common/modit.h b/include/arch_common/modit.h
index cdb79cc..f046191 100644
--- a/include/arch_common/modit.h
+++ b/include/arch_common/modit.h
@@ -1,3 +1,23 @@
+/**
+ * include/arch_common/modit.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Provides kernel specific types and abstractions of compiler defined
+ * attributes
+ */
#ifndef KERNEL_MODIT_H
#define KERNEL_MODIT_H
@@ -9,7 +29,4 @@ typedef char symbol_t[];
#define ALIGNED(n) __attribute__((aligned(n)))
#define PAGEALIGN ALIGNED(4096)
-//Upon the initialization of other processors, this section is cloned instead of linked
-#define THREAD __attribute__((section(".thread")))
-
#endif
diff --git a/include/arch_common/panic.h b/include/arch_common/panic.h
index 50daef3..dbebd62 100644
--- a/include/arch_common/panic.h
+++ b/include/arch_common/panic.h
@@ -1,5 +1,22 @@
-/* For when things go horribly wrong
- * */
+/**
+ * include/arch_common/panic.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Provides functions for halting process execution
+ */
#ifndef MODIT_PANIC_H
#define MODIT_PANIC_H 1
diff --git a/include/arch_common/pmm.h b/include/arch_common/pmm.h
index ceaf2c9..9efeaf2 100644
--- a/include/arch_common/pmm.h
+++ b/include/arch_common/pmm.h
@@ -1,4 +1,22 @@
-/* Generalized physical memory managment functions for inter-operability between different pmm schemes and the rest of the kernel
+/**
+ * include/arch_common/pmm.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Generalized physical memory managment functions for inter-operability
+ * between different pmm schemes and the rest of the kernel
* */
#ifndef KERNEL_PMM_H
diff --git a/include/arch_common/serialtxt.h b/include/arch_common/serialtxt.h
index 21b469e..686e0c5 100644
--- a/include/arch_common/serialtxt.h
+++ b/include/arch_common/serialtxt.h
@@ -1,3 +1,23 @@
+/**
+ * include/arch_common/serialtxt.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Provides definitions and functions for interfacing with serial ports,
+ * specifically COM1
+ */
#ifndef KERNEL_SERIALTXT_H
#define KERNEL_SERIALTXT_H 1
diff --git a/include/arch_common/stdio.h b/include/arch_common/stdio.h
index 1ae48dd..91912cc 100644
--- a/include/arch_common/stdio.h
+++ b/include/arch_common/stdio.h
@@ -1,3 +1,20 @@
+/**
+ * include/arch_common/stdio.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#ifndef KERNEL_STDIO_H
#define KERNEL_STDIO_H 1
diff --git a/include/arch_common/stdlib.h b/include/arch_common/stdlib.h
deleted file mode 100644
index b638d1b..0000000
--- a/include/arch_common/stdlib.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef KERNEL_STDLIB_H
-#define KERNEL_STDLIB_H 1
-
-#include <stddef.h>
-
-void *memset(void *s, int c, size_t n);
-void *memcpy(void *restrict dest, const void *restrict src, size_t n);
-int memcmp(const void *s1, const void *s2, size_t n);
-
-char *itoa(unsigned long value, char *str, int base);
-
-#endif
-/* vim: set ts=4 sw=4 tw=0 et :*/
diff --git a/include/arch_common/string.h b/include/arch_common/string.h
index fee0c26..a881286 100644
--- a/include/arch_common/string.h
+++ b/include/arch_common/string.h
@@ -1,8 +1,33 @@
+/**
+ * include/arch_common/string.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Provides functions similar to libc string
+ */
#ifndef KERNEL_STRING_H
#define KERNEL_STRING_H 1
#include <stddef.h>
+void *memset(void *s, int c, size_t n);
+void *memcpy(void *restrict dest, const void *restrict src, size_t n);
+int memcmp(const void *s1, const void *s2, size_t n);
+
+char *itoa(unsigned long value, char *str, int base);
+
size_t strlen(const char *s);
char *strcpy(char *restrict dest, const char *src);
diff --git a/include/arch_common/vgatxt.h b/include/arch_common/vgatxt.h
index 0786046..e795a52 100644
--- a/include/arch_common/vgatxt.h
+++ b/include/arch_common/vgatxt.h
@@ -1,3 +1,22 @@
+/**
+ * include/arch_common/vgatxt.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Provides functions for outputting to VGA text mode buffer
+ */
#ifndef KERNEL_VGATXT_H
#define KERNEL_VGATXT_H 1
diff --git a/include/arch_common/vmm.h b/include/arch_common/vmm.h
index 005a475..e4bd9d0 100644
--- a/include/arch_common/vmm.h
+++ b/include/arch_common/vmm.h
@@ -1,4 +1,21 @@
-/* Generic interface for virtual memory managnemt. Abstracts away larger pages for 4K blocks. Pages should be allocated with best-fit sizes
+/**
+ * include/arch_common/vmm.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Generic interface for virtual memory managnemt. Abstracts away larger pages for 4K blocks. Pages should be allocated with best-fit sizes
* */
#ifndef KERNEL_VMM_H
diff --git a/include/arch_x86/64/apic.h b/include/arch_x86/64/apic.h
index 67d4aac..858e9d2 100644
--- a/include/arch_x86/64/apic.h
+++ b/include/arch_x86/64/apic.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/64/apic.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_KERNEL_APIC_H
#define MODIT_KERNEL_APIC_H 1
diff --git a/include/arch_x86/64/idt.h b/include/arch_x86/64/idt.h
index 8713d35..5279d9a 100644
--- a/include/arch_x86/64/idt.h
+++ b/include/arch_x86/64/idt.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/64/idt.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_KERNEL_IDT_H
#define MODIT_KERNEL_IDT_H 1
diff --git a/include/arch_x86/64/page.h b/include/arch_x86/64/page.h
index e86076b..dd27e3d 100644
--- a/include/arch_x86/64/page.h
+++ b/include/arch_x86/64/page.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/64/page.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_X86_64_PAGE_H
#define MODIT_X86_64_PAGE_H 1
diff --git a/include/arch_x86/64/registers.h b/include/arch_x86/64/registers.h
index 780113f..e9fe81d 100644
--- a/include/arch_x86/64/registers.h
+++ b/include/arch_x86/64/registers.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/64/registers.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_REGISTERS_H
#define MODIT_REGISTERS_H 1
diff --git a/include/arch_x86/common/acpi.h b/include/arch_x86/common/acpi.h
index a3abfdc..dd55ee7 100644
--- a/include/arch_x86/common/acpi.h
+++ b/include/arch_x86/common/acpi.h
@@ -1,3 +1,20 @@
+/**
+ * include/arch_x86/common/acpi.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#ifndef MODIT_KERNEL_ACPI_H
#define MODIT_KERNEL_ACPI_H 1
diff --git a/include/arch_x86/common/gdt.h b/include/arch_x86/common/gdt.h
index 973fae7..2fcbc21 100644
--- a/include/arch_x86/common/gdt.h
+++ b/include/arch_x86/common/gdt.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/common/gdt.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_KERNEL_GDT_H
#define MODIT_KERNEL_GDT_H 1
diff --git a/include/arch_x86/common/interrupt.h b/include/arch_x86/common/interrupt.h
index 7f0d1a7..8295e84 100644
--- a/include/arch_x86/common/interrupt.h
+++ b/include/arch_x86/common/interrupt.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/common/interrupt.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_KERNEL_INTERRUPT_H
#define MODIT_KERNEL_INTERRUPT_H 1
diff --git a/include/arch_x86/common/ipc.h b/include/arch_x86/common/ipc.h
index c8ed004..a319e59 100644
--- a/include/arch_x86/common/ipc.h
+++ b/include/arch_x86/common/ipc.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/common/ipc.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_KERNEL_IPC_H
#define MODIT_KERNEL_IPC_H 1
diff --git a/include/arch_x86/common/pic.h b/include/arch_x86/common/pic.h
index 574b144..69110e5 100644
--- a/include/arch_x86/common/pic.h
+++ b/include/arch_x86/common/pic.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/common/pic.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_KERNEL_PIC_H
#define MODIT_KERNEL_PIC_H 1
diff --git a/include/arch_x86/common/pit.h b/include/arch_x86/common/pit.h
index 5f7d43f..c653c44 100644
--- a/include/arch_x86/common/pit.h
+++ b/include/arch_x86/common/pit.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/common/pit.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_KERNEL_PIT_H
#define MODIT_KERNEL_PIT_H 1
diff --git a/include/arch_x86/common/syscall.h b/include/arch_x86/common/syscall.h
index 406664e..f0c42b6 100644
--- a/include/arch_x86/common/syscall.h
+++ b/include/arch_x86/common/syscall.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/common/syscall.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_KERNEL_SYSCALL_H
#define MODIT_KERNEL_SYSCALL_H 1
diff --git a/include/arch_x86/common/task.h b/include/arch_x86/common/task.h
index df2035a..6af8036 100644
--- a/include/arch_x86/common/task.h
+++ b/include/arch_x86/common/task.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/common/task.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_KERNEL_TASK_H
#define MODIT_KERNEL_TASK_H 1
diff --git a/include/arch_x86/common/timer.h b/include/arch_x86/common/timer.h
index c7334e8..eee91cf 100644
--- a/include/arch_x86/common/timer.h
+++ b/include/arch_x86/common/timer.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/common/timer.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_KERNEL_TIMER_H
#define MODIT_KERNEL_TIMER_H 1
diff --git a/include/arch_x86/common/user.h b/include/arch_x86/common/user.h
index 6ea7661..6bf1d95 100644
--- a/include/arch_x86/common/user.h
+++ b/include/arch_x86/common/user.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/common/user.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_KERNEL_USER_H
#define MODIT_KERNEL_USER_H 1
diff --git a/include/arch_x86/common/x86.h b/include/arch_x86/common/x86.h
index b2d359d..95dde22 100644
--- a/include/arch_x86/common/x86.h
+++ b/include/arch_x86/common/x86.h
@@ -1,3 +1,21 @@
+/**
+ * include/arch_x86/common/x86.h
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
#ifndef MODIT_KERNEL_X86_H
#define MODIT_KERNEL_X86_H 1
diff --git a/src/arch_common/init/init.c b/src/arch_common/init/init.c
index 2edfba3..939312d 100644
--- a/src/arch_common/init/init.c
+++ b/src/arch_common/init/init.c
@@ -9,6 +9,7 @@
#include "panic.h"
#include "string.h"
+#include "stdlib.h"
#include <stdbool.h>
struct ldexpect {
@@ -19,7 +20,7 @@ struct ldexpect {
static void
init_spawn(struct initrd_file *init, struct initrd_file *ld)
{
- struct ldexpect *ldstk = kmalloc(init->size + 2, "initstk");
+ struct ldexpect *ldstk = malloc(init->size + 2);
memcpy(ldstk->elf, init->data, init->size);
memset(ldstk->nulterm, 0, 2);
diff --git a/src/arch_common/initrd/initrd.c b/src/arch_common/initrd/initrd.c
index 715f9fe..ab3a3ab 100644
--- a/src/arch_common/initrd/initrd.c
+++ b/src/arch_common/initrd/initrd.c
@@ -26,7 +26,7 @@ module_setup(struct modit_kernel_module *mod)
size_t mpagestotal = ((mod->end - mod->begin) + (PAGE_SIZE - 1)) / PAGE_SIZE;
vmptr_t modpages = 0;
- modpages = (uintptr_t)kmalloc_a(mpagestotal * PAGE_SIZE, PAGE_SIZE, "initrd");
+ modpages = (uintptr_t)malloc(mpagestotal * PAGE_SIZE);
for(size_t i = 0; i < mpagestotal * PAGE_SIZE; i += PAGE_SIZE) {
vmm_mappg(mod->begin + i, modpages + i, 0, 3);
}
diff --git a/src/arch_common/initrd/tar.c b/src/arch_common/initrd/tar.c
index 26819be..9049cfa 100644
--- a/src/arch_common/initrd/tar.c
+++ b/src/arch_common/initrd/tar.c
@@ -19,7 +19,7 @@ static struct initrd_file *
tar_parse_file(struct tar_header *block)
{
uintptr_t data = (uintptr_t)block + TAR_BLOCKSIZE;
- struct initrd_file *file = kmalloc(sizeof(struct initrd_file), "tar file");
+ struct initrd_file *file = malloc(sizeof(struct initrd_file));
memset(file, 0, sizeof(struct initrd_file));
file->name = block->name;
diff --git a/src/arch_x86/64/apic/ioapic.c b/src/arch_x86/64/apic/ioapic.c
index 57fc4dd..915d4de 100644
--- a/src/arch_x86/64/apic/ioapic.c
+++ b/src/arch_x86/64/apic/ioapic.c
@@ -107,14 +107,14 @@ apic_ioapic_setup(void)
ioapic_entries = madt_get_ioapic_ents(&nioapic);
ioapic_isos = madt_get_iso_ents(&niso);
- ioapics = kmalloc(sizeof(struct ioapic) * nioapic, "ioapices");
+ ioapics = malloc(sizeof(struct ioapic) * nioapic);
for(size_t i = 0; i < nioapic; i++){
struct madt_ioapic *entry = ioapic_entries[i];
struct ioapic *ioapic = &ioapics[i];
pmptr_t ioapic_frame = entry->address;
- vmptr_t ioapic_addr = (uintptr_t)kmalloc_a(0x1000, 0x1000, "ioapic base");
+ vmptr_t ioapic_addr = (uintptr_t)malloc(PAGE_SIZE);
vmm_mappg(ioapic_frame, ioapic_addr, 0, 3);
ioapic_addr += ioapic_frame % 0x1000;
diff --git a/src/arch_x86/common/heap/Makefile b/src/arch_x86/64/heap/Makefile
index 5ca143b..fec58e6 100644
--- a/src/arch_x86/common/heap/Makefile
+++ b/src/arch_x86/64/heap/Makefile
@@ -1,4 +1,5 @@
CFILES := $(wildcard *.c)
+CFILES += $(wildcard diheap/*.c)
CFILES += $(wildcard *.s)
OFILES := $(patsubst %.c,%.o,$(CFILES))
@@ -15,7 +16,7 @@ OUT := heap
.PHONY: all
all: ${OFILES}
- $(AR) -rcs ../$(OUT).a *.o
+ $(AR) -rcs ../$(OUT).a *.o */*.o
%.o:%.c
$(CC) $(CFLAGS) -c $< -o $@
diff --git a/src/arch_x86/64/heap/diheap b/src/arch_x86/64/heap/diheap
new file mode 160000
+Subproject cc8beb0a8b6b83b884b2f310b766700816cf368
diff --git a/src/arch_x86/64/heap/main.c b/src/arch_x86/64/heap/main.c
new file mode 100644
index 0000000..b9c5eb8
--- /dev/null
+++ b/src/arch_x86/64/heap/main.c
@@ -0,0 +1,66 @@
+#include "heap.h"
+#include "diheap/heap.h"
+
+#include <stdint.h>
+#include "stdio.h"
+#include "stdlib.h"
+#include "vmm.h"
+#include "string.h"
+#include "mutex.h"
+#include "modit.h"
+#include "boot.h"
+
+#define MODIT_HEAP_VL_START (MODIT_HIGHER_HALF + 0x10000000)
+#define MODIT_HEAP_VL_SIZE 0x10000000
+
+#define MODIT_HEAP_PF_START (MODIT_HEAP_VL_START + 0x10000000)
+#define MODIT_HEAP_PF_SIZE 0x10000000
+
+static struct heap kernel_heap_vl; /*Variable length*/
+static struct heap kernel_heap_pf; /*Page Frame*/
+/*TODO: Add SLAB/SLUB allocator*/
+
+MODULE static void
+heap_constructor(void)
+{
+ vmm_alloc(MODIT_HEAP_VL_START, MODIT_HEAP_VL_SIZE, 0, 0);
+ vmm_alloc(MODIT_HEAP_PF_START, MODIT_HEAP_PF_SIZE, 0, 0);
+
+ heap_create(&kernel_heap_vl, MODIT_HEAP_VL_START, MODIT_HEAP_VL_SIZE);
+ heap_create(&kernel_heap_pf, MODIT_HEAP_PF_START, MODIT_HEAP_PF_SIZE);
+}
+
+void *
+malloc(size_t size)
+{
+ void *ret = NULL;
+ if(size % PAGE_SIZE == 0) {
+ ret = heap_alloc(&kernel_heap_pf, size);
+ }else{
+ ret = heap_alloc(&kernel_heap_vl, size);
+ }
+ return ret;
+}
+
+void *
+calloc(size_t nmemb, size_t size)
+{
+ size_t truesize = nmemb * size;
+ void *ret = malloc(truesize);
+ memset(ret, 0, truesize);
+ return ret;
+}
+
+void free(void *ptr)
+{
+ if((uintptr_t)ptr > MODIT_HEAP_PF_START) {
+ heap_free(&kernel_heap_pf, ptr);
+ }else if((uintptr_t)ptr > MODIT_HEAP_VL_START){
+ heap_free(&kernel_heap_vl, ptr);
+ }
+}
+
+void heap_print(void)
+{
+
+}
diff --git a/src/arch_x86/64/task/context.c b/src/arch_x86/64/task/context.c
index 5f84223..e4de9d6 100644
--- a/src/arch_x86/64/task/context.c
+++ b/src/arch_x86/64/task/context.c
@@ -6,6 +6,7 @@
#include "vmm.h"
#include "gdt.h"
#include "apic.h"
+#include "idt.h"
//Current execution context
THREAD struct execution_context *current_excontext;
@@ -60,7 +61,7 @@ excontext_append(uintptr_t cr3, uintptr_t ip, uintptr_t sp, uintptr_t bp)
{
char reasonstr[32];
sprintf(reasonstr, "context %i", nextid);
- struct execution_context *ctx = kmalloc(sizeof(struct execution_context), reasonstr);
+ struct execution_context *ctx = malloc(sizeof(struct execution_context));
memset(ctx, 0, sizeof(struct execution_context));
if(execution_contexts == 0) {
diff --git a/src/arch_x86/64/task/load.c b/src/arch_x86/64/task/load.c
index 094530b..b04c632 100644
--- a/src/arch_x86/64/task/load.c
+++ b/src/arch_x86/64/task/load.c
@@ -48,7 +48,7 @@ excontext_spawn_secondhalf(const uint8_t *bin, size_t binsz, const uint8_t *stac
memcpy((void*)start, bin, binsz);
vmm_alloc_force(MODIT_KERNEL_STAST - 0x2000, 0x2000, false, false);
- kfree((void*)((uintptr_t)&stacksz - 0xFE0));
+ free((void*)((uintptr_t)&stacksz - 0xFE0));
user_enter(start, ustk);
}
@@ -59,7 +59,7 @@ excontext_spawn(const uint8_t *bin, size_t binsz, const uint8_t *stack, size_t s
vmptr_t ip = (uintptr_t)excontext_spawn_firsthalf;
size_t kstacksz = binsz + stacksz + (sizeof(uintptr_t) * 4) + PAGE_SIZE;
- vmptr_t kstack = (vmptr_t)kmalloc(kstacksz, "spawnkstk");
+ vmptr_t kstack = (vmptr_t)malloc(kstacksz);
vmptr_t sp = kstack + kstacksz;
//Push data to stack
@@ -77,7 +77,7 @@ excontext_spawn(const uint8_t *bin, size_t binsz, const uint8_t *stack, size_t s
//Spawn context
char reasonstr[32];
- vmptr_t newcr3 = (uintptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "spawn cr3");
+ vmptr_t newcr3 = (uintptr_t)malloc(PAGE_SIZE);
vmm_mappg(pcr3, newcr3, 0, 3);
return excontext_append(newcr3, ip, sp, 0);
}
@@ -96,7 +96,7 @@ excontext_fork(void)
return current_excontext;
}
- cr3 = (uintptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "fork cr3");
+ cr3 = (uintptr_t)malloc(PAGE_SIZE);
pcr3 = tlb_copycr3();
stkf = tlb_clonepml(4, 255);
diff --git a/src/arch_x86/64/task/message.c b/src/arch_x86/64/task/message.c
index 28244d0..ab95ff2 100644
--- a/src/arch_x86/64/task/message.c
+++ b/src/arch_x86/64/task/message.c
@@ -3,6 +3,8 @@
#include "task.h"
#include "mutex.h"
#include "stdio.h"
+#include "stdlib.h"
+#include "heap.h"
int
message_send(size_t tgt, uint8_t *data, size_t len)
@@ -17,8 +19,8 @@ message_send(size_t tgt, uint8_t *data, size_t len)
mbx->messagec++;
mutex_lock(&mbx->lock);
- struct message *msg = kmalloc(sizeof(struct message), "message");
- uint8_t *msgdat = kmalloc(len, "message data");
+ struct message *msg = malloc(sizeof(struct message));
+ uint8_t *msgdat = malloc(len);
memset(msg, 0, sizeof(struct message));
memcpy(msgdat, data, len);
@@ -59,8 +61,8 @@ message_recv(uint8_t *buffer, intmax_t *sender)
memcpy(buffer, msg->data, msg->datalen);
*sender = msg->sender;
- kfree(msg->data);
- kfree(msg);
+ free(msg->data);
+ free(msg);
mutex_unlock(&mbx->lock);
return 0;
diff --git a/src/arch_x86/64/task/port.c b/src/arch_x86/64/task/port.c
index 601c12c..38be3c7 100644
--- a/src/arch_x86/64/task/port.c
+++ b/src/arch_x86/64/task/port.c
@@ -23,9 +23,9 @@ port_findopen(portid_t *id)
}
//Make space for new port
- struct port *tmp = kmalloc(sizeof(struct port) * (portc + 1), "ports");
+ struct port *tmp = malloc(sizeof(struct port) * (portc + 1));
memcpy(tmp, ports, sizeof(struct port) * (portc));
- kfree(ports);
+ free(ports);
ports = tmp;
*id = portc++;
@@ -147,7 +147,7 @@ port_write(portid_t id, uint8_t *buffer, size_t n)
MODULE static void
ipc_port_constructor(void)
{
- ports = kmalloc(sizeof(struct port), "ports");
+ ports = malloc(sizeof(struct port));
memset(ports, 0, sizeof(struct port));
portc = 1;
diff --git a/src/arch_x86/common/acpi/madt.c b/src/arch_x86/common/acpi/madt.c
index bdf3a3f..6f58990 100644
--- a/src/arch_x86/common/acpi/madt.c
+++ b/src/arch_x86/common/acpi/madt.c
@@ -82,13 +82,13 @@ madt_parse(struct acpisdthdr *madthdr)
}
//Allocate memory for lists
- lapicids = kmalloc(ncores, "acpids");
+ lapicids = malloc(ncores);
ncores = 0;
- ioapics = kmalloc(nioapic * sizeof(uintptr_t), "ioapics");
+ ioapics = malloc(nioapic * sizeof(uintptr_t));
nioapic = 0;
- isos = kmalloc(niso * sizeof(uintptr_t), "isos");
+ isos = malloc(niso * sizeof(uintptr_t));
niso = 0;
//Second pass, add IDs to list, lapic_addr
@@ -106,7 +106,7 @@ madt_parse(struct acpisdthdr *madthdr)
}
}
- lapic_registers = (uintptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "lapicrs");
+ lapic_registers = (uintptr_t)malloc(PAGE_SIZE);
vmm_mappg(lapic_addr, lapic_registers, 0, 3);
lapic_registers += (lapic_addr % 0x1000);
}
diff --git a/src/arch_x86/common/acpi/main.c b/src/arch_x86/common/acpi/main.c
index 52927d8..0f4fce7 100644
--- a/src/arch_x86/common/acpi/main.c
+++ b/src/arch_x86/common/acpi/main.c
@@ -22,7 +22,7 @@ static void
rsdp_find_rsdt(struct rsdp1 *rsdp)
{
pmptr_t rsdtphys = rsdp->rsdt;
- vmptr_t rsdtaddr = (vmptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "rsdp");
+ vmptr_t rsdtaddr = (vmptr_t)malloc(PAGE_SIZE);
if(!checksum_validate(rsdp, sizeof(struct rsdp1))) {
panic(NULL, "Passed RSDP does not match checksum\n");
diff --git a/src/arch_x86/common/acpi/rsdt.c b/src/arch_x86/common/acpi/rsdt.c
index 04aac04..26ec2e3 100644
--- a/src/arch_x86/common/acpi/rsdt.c
+++ b/src/arch_x86/common/acpi/rsdt.c
@@ -13,7 +13,7 @@ rsdt_parse_table(struct acpisdthdr *table)
madt_parse(table);
return;
}
- printk(KERNEL_WARN, "Unrecognized table %4s\n", table->sig);
+ //printk(KERNEL_WARN, "Unrecognized table %4s\n", table->sig);
}
void
@@ -24,7 +24,7 @@ rsdt_parse(struct rsdp1 *rsdp, struct acpisdthdr *rsdthdr)
if(rsdp->rev == 2){
for(size_t i = 0; i < (rsdt->header.len - sizeof(struct acpisdthdr)) / sizeof(uint64_t); i++) {
pmptr_t table_phys = (pmptr_t)((struct xsdt*)rsdt)->sdtptrs[i];
- vmptr_t table_virt = (vmptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "xsdt tbl");
+ vmptr_t table_virt = (vmptr_t)malloc(PAGE_SIZE);
struct acpisdthdr *table = NULL;
vmm_mappg(table_phys, table_virt, 0, 3);
table_virt += (table_phys % PAGE_SIZE);
@@ -35,7 +35,8 @@ rsdt_parse(struct rsdp1 *rsdp, struct acpisdthdr *rsdthdr)
}else{
for(size_t i = 0; i < (rsdt->header.len - sizeof(struct acpisdthdr)) / sizeof(uint32_t); i++) {
pmptr_t table_phys = (pmptr_t)rsdt->sdtptrs[i];
- vmptr_t table_virt = (vmptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "rsdt tbl");
+ vmptr_t table_virt = (vmptr_t)malloc(PAGE_SIZE);
+ if(table_phys == 0) break;
struct acpisdthdr *table = NULL;
vmm_mappg(table_phys, table_virt, 0, 3);
table_virt += (table_phys % PAGE_SIZE);
diff --git a/src/arch_x86/common/heap/main.c b/src/arch_x86/common/heap/main.c
deleted file mode 100644
index 9601946..0000000
--- a/src/arch_x86/common/heap/main.c
+++ /dev/null
@@ -1,311 +0,0 @@
-#include "heap.h"
-#include <stdint.h>
-#include "stdio.h"
-#include "stdlib.h"
-#include "vmm.h"
-#include "string.h"
-#include "mutex.h"
-#include "modit.h"
-
-#define BUCKET_SIZE 64
-#define BUCKET_DATA_SIZE (sizeof(uintptr_t) * 3)
-#define BUCKET_REASON_SIZE (BUCKET_SIZE - BUCKET_DATA_SIZE)
-
-#define BIN_SIZE 4096
-#define BIN_DATA_SIZE (sizeof(uintptr_t))
-#define BIN_BUCKET_SIZE (BIN_SIZE - BIN_DATA_SIZE)
-#define BIN_BUCKET_COUNT (BIN_BUCKET_SIZE / BUCKET_SIZE)
-
-#define BUCKET_GETADDR(bucket) (bucket->addr)
-#define BUCKET_GETLEN(bucket) (bucket->len & ~(1))
-#define BUCKET_GETLIMIT(bucket) (BUCKET_GETADDR(bucket) + BUCKET_GETLEN(bucket))
-#define BUCKET_GETTAKEN(bucket) (bucket->len & 1)
-
-struct bucket
-{
- struct bucket *prev;
- struct bucket *next;
- uintptr_t addr;
- uintptr_t len;
- char reason[BUCKET_REASON_SIZE-1];
- char zero;
-} __attribute__((packed));
-
-struct bin
-{
- struct bin *next;
- struct bucket buckets[BIN_BUCKET_COUNT];
-};
-
-static struct bin *bin_head;
-static uintptr_t heap_limit;
-
-static struct bucket *heap_head;
-static struct bucket *heap_tail;
-
-static struct bucket *free_head;
-
-MUTEX(heap)
-
-static void
-heap_expandtofit(struct bucket *bucket)
-{
- if(bucket == NULL) return;
- uintptr_t limit = BUCKET_GETLIMIT(bucket);
- if(limit >= heap_limit) {
- uintptr_t len = limit - heap_limit;
- vmm_alloc(heap_limit, len, false, false);
- heap_limit = limit;
- }
-}
-
-static void
-heap_newbin(void)
-{
- bin_head->next = (struct bin*)heap_limit;
- vmm_alloc(heap_limit, sizeof(struct bin), false, false);
- heap_limit += sizeof(struct bin);
-
- bin_head = bin_head->next;
-
- memset(bin_head, 0, sizeof(struct bin));
- bin_head->buckets[0].addr = (uintptr_t)bin_head;
- bin_head->buckets[0].len = sizeof(struct bin) | 1;
- bin_head->buckets[0].prev = heap_tail;
- strcpy(bin_head->buckets[0].reason, "new bin");
- heap_tail->next = &(bin_head->buckets[0]);
- heap_tail = heap_tail->next;
-
- for(size_t i = 1; i < BIN_BUCKET_COUNT-1; i++)
- {
- bin_head->buckets[i-1].next = &(bin_head->buckets[i]);
- bin_head->buckets[i].prev = &(bin_head->buckets[i-1]);
- bin_head->buckets[i].next = &(bin_head->buckets[i+1]);
- bin_head->buckets[i+1].prev = &(bin_head->buckets[i]);
- }
- bin_head->buckets[0].next = NULL;
- free_head = &(bin_head->buckets[1]);
-}
-
-static struct bucket*
-heap_addbucketbetween(struct bucket *prev, struct bucket *next, size_t size)
-{
- if(free_head == NULL) heap_newbin();
- struct bucket *added = free_head;
- free_head = added->next;
-
- added->next = next;
- added->prev = prev;
-
- if(prev) prev->next = added;
- if(next) next->prev = added;
-
- added->addr = BUCKET_GETLIMIT(prev);
- added->len = size;
- if(next == NULL) heap_tail = added;
- heap_expandtofit(added);
- return added;
-}
-
-static struct bucket*
-heap_appendbucket(size_t size)
-{
- return heap_addbucketbetween(heap_tail, NULL, size);
-}
-
-static void
-heap_freebucket(struct bucket *bucket)
-{
- if(bucket->prev != NULL) bucket->prev->next = bucket->next;
- if(bucket->next != NULL) bucket->next->prev = bucket->prev;
- if(free_head != NULL){
- free_head->prev = bucket;
- }
- bucket->next = free_head;
- bucket->prev = NULL;
- free_head = bucket;
-}
-
-static struct bucket*
-heap_makebest(size_t size)
-{
- if(BUCKET_GETTAKEN(heap_tail) == 0){
- heap_tail->len = size;
- heap_expandtofit(heap_tail);
- return heap_tail;
- }
- return heap_appendbucket(size);
-}
-
-static struct bucket*
-heap_splitbucket(struct bucket *start, size_t size)
-{
- size_t diff = BUCKET_GETLEN(start) - size;
- if(diff == 0) return start;
- start->len = size;
-
- heap_addbucketbetween(start, start->next, diff);
- return start;
-}
-
-static struct bucket*
-heap_mergebucket(struct bucket *bucket)
-{
- if(bucket->next)
- if(BUCKET_GETTAKEN(bucket->next) == 0) {
- bucket->len += bucket->next->len;
- heap_freebucket(bucket->next);
- bucket = heap_mergebucket(bucket);
- }
- if(bucket->prev)
- if(BUCKET_GETTAKEN(bucket->prev) == 0) {
- bucket = bucket->prev;
- bucket->len += bucket->next->len;
- heap_freebucket(bucket->next);
- bucket = heap_mergebucket(bucket);
- }
- return bucket;
-}
-
-static struct bucket*
-heap_getbest(size_t size, size_t align)
-{
- struct bucket *best = NULL;
- for(struct bucket *bucket = heap_head; bucket != 0; bucket = bucket->next)
- {
- if(BUCKET_GETTAKEN(bucket)) continue;
- if(BUCKET_GETLEN(bucket) < size) continue;
- if(bucket->addr % align != 0) continue;
- if(best == NULL) {
- best = bucket;
- continue;
- }
-
- int64_t diff = BUCKET_GETLEN(best) - BUCKET_GETLEN(bucket);
- if(diff <= 0) continue;
- best = bucket;
- }
-
- if(best == NULL && align == 1) {
- best = heap_makebest(size);
- }
- return best;
-}
-
-void*
-kmalloc(size_t size, const char *reason)
-{
- if(size == 0) return NULL;
- if(reason == 0) reason = "unknown";
-
- size = ((size / 2) + (size % 2)) * 2;
-
- LOCK(heap)
- struct bucket *bestfit = heap_getbest(size, 1);
-
- bestfit = heap_splitbucket(bestfit, size);
- bestfit->len |= 1;
- strcpy(bestfit->reason, reason);
-
- UNLOCK(heap)
- return (void*)bestfit->addr;
-}
-
-void*
-kmalloc_a(size_t size, uintptr_t alignto, const char *reason)
-{
- if(size == 0) return NULL;
- if(reason == 0) reason = "unknown";
-
- size = ((size / 2) + (size % 2)) * 2;
-
- LOCK(heap)
- struct bucket *best = heap_getbest(size, alignto);
- if(best == NULL) {
- uintptr_t ht_addr = BUCKET_GETADDR(heap_tail);
- uintptr_t ht_size = BUCKET_GETLEN(heap_tail);
- uintptr_t ht_lim = ht_addr + ht_size;
-
- uintptr_t buffersize = alignto - (ht_lim % alignto);
- if(BUCKET_GETTAKEN(heap_tail)){
- heap_makebest(buffersize);
- }
-
- struct bucket *buffer = heap_tail;
- best = buffer;
- best->len = size;
- if(heap_tail->addr % alignto != 0) {
- buffer->len = buffersize | 1;
- best = heap_makebest(size);
- buffer->len &= ~1;
- }
- }
- best->len |= 1;
- strcpy(best->reason, reason);
-
- UNLOCK(heap)
- return (void*)best->addr;
-}
-
-void
-kfree(void *ptr)
-{
- if(ptr == 0) return;
- struct bucket *tofree = NULL;
-
- LOCK(heap)
- for(struct bucket *bucket = heap_head; bucket != 0; bucket = bucket->next)
- {
- if(BUCKET_GETTAKEN(bucket) == 0) continue;
- if(bucket->addr != (uintptr_t)ptr) continue;
- tofree = bucket;
- break;
- }
-
- if(tofree == NULL) goto kfree_unlock_return;
- tofree->len &= (~1);
- heap_mergebucket(tofree);
-
-kfree_unlock_return:
- UNLOCK(heap)
-}
-
-void
-heap_print(void)
-{
- printk(KERNEL_INFO, "Printing block debug info\n");
- int i = 0;
- for(struct bucket *bucket = heap_head; bucket; bucket = bucket->next) {
- printk(KERNEL_INFO, "%i : [%s] %X bytes %X (%s)\n", i++, bucket->len & 1 ? "TAKEN" : "FREE", bucket->len, bucket->addr, bucket->reason);
- }
- printk(KERNEL_INFO, "End debug info\n");
-}
-
-MODULE static void
-heap_constructor(void)
-{
- extern uintptr_t _modules_end;
- uintptr_t heap_start = (uintptr_t)(&_modules_end);
- heap_start = ((heap_start + 0x1000) - (heap_start % 0x1000));
-
- vmm_alloc(heap_start, 0x1000, false, false);
- bin_head = (struct bin*)heap_start;
- heap_limit = heap_start + 0x1000;
-
- memset(bin_head, 0, sizeof(struct bin));
- bin_head->buckets[0].addr = (uintptr_t)bin_head;
- bin_head->buckets[0].len = sizeof(struct bin) | 1;
- strcpy(bin_head->buckets[0].reason, "initial bin");
-
- for(size_t i = 1; i < BIN_BUCKET_COUNT-1; i++)
- {
- bin_head->buckets[i-1].next = &(bin_head->buckets[i]);
- bin_head->buckets[i].prev = &(bin_head->buckets[i-1]);
- bin_head->buckets[i].next = &(bin_head->buckets[i+1]);
- bin_head->buckets[i+1].prev = &(bin_head->buckets[i]);
- }
- bin_head->buckets[0].next = NULL;
- free_head = &(bin_head->buckets[1]);
-
- heap_head = heap_tail = bin_head->buckets;
-}