about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYour Name <you@example.com>2020-06-28 03:51:09 +0200
committerYour Name <you@example.com>2020-06-28 03:51:09 +0200
commit2a962bfa1ce404726f0037d41098d2a9286f31ae (patch)
tree89a24a0ef050faf01a8bbf030ed1915c78cdd6ec
parentUpdated TODO (diff)
downloadpOS-2a962bfa1ce404726f0037d41098d2a9286f31ae.tar.gz
pOS-2a962bfa1ce404726f0037d41098d2a9286f31ae.tar.bz2
pOS-2a962bfa1ce404726f0037d41098d2a9286f31ae.zip
Base: PhysM formatting
-rw-r--r--src/pOS/arch/x86/kernel/physm.cpp12
-rw-r--r--src/pOS/include/kernel/physm.h1
2 files changed, 10 insertions, 3 deletions
diff --git a/src/pOS/arch/x86/kernel/physm.cpp b/src/pOS/arch/x86/kernel/physm.cpp
index e76116f..b2786bb 100644
--- a/src/pOS/arch/x86/kernel/physm.cpp
+++ b/src/pOS/arch/x86/kernel/physm.cpp
@@ -25,12 +25,12 @@ int PhysM::print_debug(void)
 int PhysM::init(void)
 {
     total_blocks = MEM_SIZE / BLOCK_SIZE;
-    memory = memset((void*)(&end), 0, total_blocks * BLOCK_SIZE);
+    memory = memset(static_cast<void*>(&end), 0, total_blocks * BLOCK_SIZE);
 
     /* Init memory in blocks */
     for(size_t i = 0; i < total_blocks; i++)
     {
-        blocks[i].memory = (char*)memory + (i * BLOCK_SIZE);
+        blocks[i].memory = static_cast<uint8_t*>(memory) + (i * BLOCK_SIZE);
     }
 
     return 0;
@@ -41,6 +41,8 @@ void* PhysM::malloc(size_t size, bool calloc)
     if(!size)
         return NULL;
 
+    usleep(1); //so id is diff
+
     uint32_t num = size / BLOCK_SIZE;
     if(num * BLOCK_SIZE < size)
         num++;
@@ -49,6 +51,9 @@ void* PhysM::malloc(size_t size, bool calloc)
 
 void* PhysM::realloc(void* oldmem, size_t size)
 {
+    if(!oldmem || !size)
+        return NULL;
+
     void* newmem = malloc(size, false);
     size_t oldsize = get_blocks_num(oldmem) * BLOCK_SIZE;
 
@@ -102,8 +107,9 @@ int PhysM::free_all_blocks_from(Block& block)
 
 Block& PhysM::find_block_from_memory(void* memory_from_block)
 {
-    int index = ((char*)memory_from_block - (char*)memory) / BLOCK_SIZE;//calculate block num from addr
+    uint32_t index = (static_cast<uint8_t*>(memory_from_block) - static_cast<uint8_t*>(memory)) / BLOCK_SIZE;//calculate block num from addr
     //printf("freeing block %d\n", index);
+    ASSERT(index < total_blocks);
     return blocks[index];
 }
 
diff --git a/src/pOS/include/kernel/physm.h b/src/pOS/include/kernel/physm.h
index a833a29..b260172 100644
--- a/src/pOS/include/kernel/physm.h
+++ b/src/pOS/include/kernel/physm.h
@@ -5,6 +5,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <stdio.h>
+#include <unistd.h>
 #include <kernel/timer.h>
 
 #define BLOCK_SIZE 20