aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/lib/memory.c')
-rw-r--r--src/kernel/lib/memory.c35
1 files changed, 22 insertions, 13 deletions
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