summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/kernel.c42
-rw-r--r--kernel/mem.c57
2 files changed, 68 insertions, 31 deletions
diff --git a/kernel/kernel.c b/kernel/kernel.c
index c95df11..33624ad 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -12,7 +12,7 @@
#endif
-// some multiprocessor shit that should move away
+// some multiprocessor shit that should move away TODO
uint32_t c1,c2,c3;
volatile uint8_t proc;
uint32_t cpu_counter[SMP_MAX_PROC];
@@ -33,6 +33,9 @@ void kernel_ap()
void kernel_main(uint32_t initial_stack, int mp)
{
+
+ /// TODO
+/////// SYMMETRIC MULTIPROCESSING, APS get caought here, move it away ///
// catch the APs (Application Processors)
if(mp==1)
{
@@ -77,7 +80,6 @@ void kernel_main(uint32_t initial_stack, int mp)
// this function returns the physical base address of
// our video memory
//
-
uint32_t vesa_physbase=vesa_init(0x8300,0x8400,0x90000+0x200);
// self-log message of logger :P
@@ -88,14 +90,12 @@ void kernel_main(uint32_t initial_stack, int mp)
//
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial esp: 0x%08X",initial_stack);
-
//
// Setup PIC
//
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"setting up PIC.");
pic_setup();
-
//
// Configuring the PIT timer.
//
@@ -106,21 +106,20 @@ void kernel_main(uint32_t initial_stack, int mp)
//
int_init(0x08);
-
//
// Memory Init
//
// after this is set up we can allocate and deallocate blocks
// of physical memory :)
//
-
- // we know that here, the bootloader placed the mamory map and
- // number of entries.
+ // we know that here, the bootloader placed the mamory map and
+ // the number of entries.
+ //
mem_init(0x7c00+0x400,*((uint16_t *)(0x7c00+0x600)));
//
- // Gather Info about other processors.
+ // Gather Info about other processors. (APs)
// ACPI or MP
//
smp_processors procdata;
@@ -130,50 +129,55 @@ void kernel_main(uint32_t initial_stack, int mp)
if(!mp_find(&procdata))
panic(FOOLOS_MODULE_NAME,"ACPI and MP search failed! I do not want to continue!");
+ //
// Start the other Processors (also before paging !)
- smp_start_aps(&procdata,0x90000);// starts at 0x90000 but will be copied over mbr
+ //
+ smp_start_aps(&procdata,0x90000); // starts at 0x90000
+ // but it will be copied over mbr
-
- /////////////////////
-
+ //
+ // Activate Virtual Memory (paging)
+ //
// paging (pass the vesa physbase address for identity mapping)
+ // TODO: we will work on this later (not needed so urgently yet)
+ //
// vmem_init(vesa_physbase);
//
// Scan the PCI Bus
//
// We are interested in the E1000 Network Adapter in particular
- // Its driver will be hopefully implemented one day ;)
+ // Its driver will be hopefully implemented one day ;) TODO
//
// pci_init();
//
// Initialize Floppy Disk if activated in config.h
+ // Sadly we won't use it anyway so its uncommented anyway.
//
//#ifdef FOOLOS_COMPILE_FLOPPY
//floppy_init();
//#endif
-
//
// "Shell"
//
// Will process input from the keyboard but will be completely
- // redesigned soon.
+ // redesigned soon. TODO!!
//
shell_init();
-
//
// Initialize Multitasking
//
- // For now this starts two tasks which are scheduled
+ // For now this starts three "tasks" which are scheduled
// round robin style.
//
task_init();
//
- // Just hang here.
+ // Just hang around here, if its reached.
+ // we do our tasks anyway. on the next clock tick.
//
while(1)asm("hlt");
diff --git a/kernel/mem.c b/kernel/mem.c
index 0b9dab7..ffa56c4 100644
--- a/kernel/mem.c
+++ b/kernel/mem.c
@@ -45,25 +45,36 @@ void pmmngr_init ()
}
}
+//find the first free bit
int mmap_first_free ()
{
- //! find the first free bit
- uint32_t i;
- int j;
-
- for (i=0; i< mem_array_size ; i++)
+ for (int i=0; i< mem_array_size ; i++)
if (_mmngr_memory_map[i] != 0xffffffff)
- for (j=0; j<32; j++)
+ for (int j=0; j<32; j++)
{
- //! test each bit in the dword
- int bit = 1 << j;
- if (! (_mmngr_memory_map[i] & bit) )
- return i*4*8+j;
+ if(!mmap_test(32*i+j))return 32*i+j;
}
return -1;
}
+//find the first free consecutive x bits
+int mmap_first_free_s (uint32_t x)
+{
+ int found=0;
+
+ for (int i=0; i< mem_array_size; i++)
+ if (_mmngr_memory_map[i] != 0xffffffff)
+ for (int j=0; j<32; j++)
+ {
+ if(!mmap_test(32*i+j))found++;
+ else found=0;
+ if(found==x)return 32*i+j;
+ }
+
+ return -1;
+}
+
void pmmngr_init_region (uint32_t base, uint32_t size)
{
uint32_t align = base / PMMNGR_BLOCK_SIZE;
@@ -95,14 +106,36 @@ void* pmmngr_alloc_block ()
if (frame == -1)
{
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"OUT OF MEMORY");
+ panic(FOOLOS_MODULE_NAME,"OUT OF MEMORY (alloc_block)");
return 0; //out of memory
}
mmap_set (frame);
+ mem_free_blocks--;
+
+ uint32_t addr = frame * PMMNGR_BLOCK_SIZE;
+
+ return (void*)addr;
+}
+
+void* pmmngr_alloc_blocks (uint32_t size)
+{
+
+ int frame = mmap_first_free_s (size);
+
+ if (frame == -1)
+ {
+ panic(FOOLOS_MODULE_NAME,"OUT OF MEMORY (alloc_blocks)");
+ return 0; //out of memory
+ }
+
+ for (int i=0; i<size; i++)
+ {
+ mmap_set (frame+i);
+ mem_free_blocks--;
+ }
uint32_t addr = frame * PMMNGR_BLOCK_SIZE;
- mem_free_blocks--;
return (void*)addr;
}