summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2015-05-13 16:18:24 +0200
committerMichal Idziorek <m.i@gmx.at>2015-05-13 16:18:24 +0200
commit9a60edf72a3112adae4a914134da1adaf472ad5d (patch)
tree64fe18ef416160244ad7dc80875e9f5a47390971
parent39d0c5ad74f69ef368d6f83e4eac575e76060eb4 (diff)
fixing gdt and interrupts
-rw-r--r--.gdbinit3
-rw-r--r--asm/GDT.asm78
-rw-r--r--asm/int_irq.asm36
-rw-r--r--asm/kernel_entry.asm27
-rw-r--r--asm/multiboot.s18
-rw-r--r--boot2/GDT.asm1
-rw-r--r--kernel/interrupts.c49
-rw-r--r--kernel/kernel.c70
-rw-r--r--kernel/mem.c92
-rw-r--r--kernel/multiboot.h4
-rw-r--r--kernel/task.c1
-rw-r--r--linker.ld2
12 files changed, 228 insertions, 153 deletions
diff --git a/.gdbinit b/.gdbinit
index 24efe1e..be3cb95 100644
--- a/.gdbinit
+++ b/.gdbinit
@@ -1 +1,4 @@
+file foolos.img
target remote localhost:1234
+set architecture i386
+break kernel_main
diff --git a/asm/GDT.asm b/asm/GDT.asm
new file mode 100644
index 0000000..f271377
--- /dev/null
+++ b/asm/GDT.asm
@@ -0,0 +1,78 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;; Miguel's FoolOS Helper Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; Global Descriptor Table
+; we have the null descriptor and a code and data block for a start
+;
+; 0x08 code segment
+; 0x10 data segment
+;
+; this file contains pure data
+;
+;
+;
+;
+
+global gdt_descriptor
+
+gdt_start:
+
+gdt_null: ;null descriptor (2 x 4 bytes)
+ dd 0x0
+ dd 0x0
+
+gdt_code:
+ ; flags:
+ ; present: 1 / privilege: 00 / type: 1
+ ; code: 1 / conforming: 0 / readable: 1 / accessed: 0
+ ; granularity: 1 / 16-bit default: 1 / 64-bit seg: 0 / AVL: 0
+ dw 0xffff ;limit
+ dw 0x0 ;base
+ db 0x0 ;base
+ db 10011010b ;flags
+ db 11001111b ;flags & seg.limit
+ db 0x0 ;base
+
+gdt_data:
+ ; flags:
+ ; code: 0 / expand down: 0 / writable: 1 / accessed: 0
+ dw 0xffff
+ dw 0x0
+ db 0x0
+ db 10010010b
+ db 11001111b
+ db 0x0
+
+gdt16_code:
+ ; flags:
+ ; present: 1 / privilege: 00 / type: 1
+ ; code: 1 / conforming: 0 / readable: 1 / accessed: 0
+ ; granularity: 1 / 16-bit default: 1 / 64-bit seg: 0 / AVL: 0
+ dw 0xffff ;limit
+ dw 0x0 ;base
+ db 0x0 ;base
+ db 10011010b ;flags
+ db 10001111b ;flags & seg.limit
+ db 0x0 ;base
+
+gdt16_data:
+ ; flags:
+ ; code: 0 / expand down: 0 / writable: 1 / accessed: 0
+ dw 0xffff
+ dw 0x0
+ db 0x0
+ db 10010010b
+ db 10001111b
+ db 0x0
+
+gdt_end:
+
+gdt_descriptor:
+ dw gdt_end-gdt_start-1
+ dd gdt_start
+
+CODE_SEG equ gdt_code - gdt_start
+DATA_SEG equ gdt_data - gdt_start
+CODE16_SEG equ gdt16_code - gdt_start
+DATA16_SEG equ gdt16_data - gdt_start
diff --git a/asm/int_irq.asm b/asm/int_irq.asm
index fd57a50..e9864f0 100644
--- a/asm/int_irq.asm
+++ b/asm/int_irq.asm
@@ -43,85 +43,85 @@ global int_irq18
int_irq0:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_0 ;this will never return due to panic!
jmp $
int_irq1:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_1 ;this will never return due to panic!
jmp $
int_irq2:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_2 ;this will never return due to panic!
jmp $
int_irq3:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_3 ;this will never return due to panic!
jmp $
int_irq4:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_4 ;this will never return due to panic!
jmp $
int_irq5:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_5 ;this will never return due to panic!
jmp $
int_irq6:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_6 ;this will never return due to panic!
jmp $
int_irq7:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_7 ;this will never return due to panic!
jmp $
int_irq8:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_8 ;this will never return due to panic!
jmp $
int_irq9:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_9;this will never return due to panic!
jmp $
int_irq10:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_10;this will never return due to panic!
jmp $
int_irq11:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_11;this will never return due to panic!
jmp $
int_irq12:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_12 ;this will never return due to panic!
jmp $
int_irq13:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_13;this will never return due to panic!
jmp $
int_irq14:
@@ -134,23 +134,23 @@ int_irq14:
int_irq15:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_15 ;this will never return due to panic!
jmp $
int_irq16:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_16 ;this will never return due to panic!
jmp $
int_irq17:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_17 ;this will never return due to panic!
jmp $
int_irq18:
cli
- call exception_handle ;this will never return due to panic!
+ call exception_handle_18;this will never return due to panic!
jmp $
diff --git a/asm/kernel_entry.asm b/asm/kernel_entry.asm
deleted file mode 100644
index 71bedd1..0000000
--- a/asm/kernel_entry.asm
+++ /dev/null
@@ -1,27 +0,0 @@
-; DEPRECATED . use multiboot.s instead!
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;;;;; Miguel's FoolOS Helper Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;
-; this will be compiled to an object file and linked with the kernel
-; to simplify the entrance!
-;
-;
-global kernel_start
-
-[bits 32]
-[extern kernel_main]
-
-kernel_start:
-
-push 0x1
-
-cmp eax,1
-je multiproc
-push 0x0
-multiproc:
-
-push esp
-call kernel_main ; jumps in the world of C
diff --git a/asm/multiboot.s b/asm/multiboot.s
index a497e18..21df7bb 100644
--- a/asm/multiboot.s
+++ b/asm/multiboot.s
@@ -45,6 +45,8 @@ stack_top:
# doesn't make sense to return from this function as the bootloader is gone.
.section .text
.global _start
+.global stack_top
+.global stack_bottom
.type _start, @function
_start:
# Welcome to kernel mode! We now have sufficient code for the bootloader to
@@ -67,6 +69,8 @@ _start:
# a stack. Note that the processor is not fully initialized yet and stuff
# such as floating point instructions are not available yet.
+ lgdt gdt_descriptor #load descriptor table!
+
# To set up a stack, we simply set the esp register to point to the top of
# our stack (as it grows downwards).
movl $stack_top, %esp
@@ -77,6 +81,20 @@ _start:
push %ebx #pass address of the multiboot information data structure
push %eax #pass eax, so kernel can check for magic number
+
+
+ reloadSegments:
+ #Reload CS register containing code selector:
+ jmp $0x08,$reload_CS # 0x08 points at the new code selector
+
+ reload_CS:
+ mov $0x10, %ax
+ mov %ax, %ds
+ mov %ax, %es
+ mov %ax, %fs
+ mov %ax, %gs
+ mov %ax, %ss
+
call kernel_main
# In case the function returns, we'll want to put the computer into an
diff --git a/boot2/GDT.asm b/boot2/GDT.asm
index 2eb2a1d..4c14b46 100644
--- a/boot2/GDT.asm
+++ b/boot2/GDT.asm
@@ -13,6 +13,7 @@
;
;
;
+global gdt_descriptor
gdt_start:
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index fed2b28..51d8f8e 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -51,7 +51,7 @@ void int_default()
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"default handler");
}
-/*
+
void show_error(uint32_t err)
{
@@ -61,23 +61,23 @@ void show_error(uint32_t err)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Selector: %x",err&0b1111111111111000);
}
-//void int_irq0(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Divide by 0"); X86_IRQ_END }
-void int_irq1(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Single step (debugger)"); X86_IRQ_END }
-void int_irq2(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Non Maskable Interrupt"); X86_IRQ_END }
-void int_irq3(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Breakpoint (debugger)"); X86_IRQ_END }
-void int_irq4(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Overflow"); X86_IRQ_END }
-void int_irq5(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Bounds check"); X86_IRQ_END }
-void int_irq6(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Undefined OP Code"); X86_IRQ_END }
-void int_irq7(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"No coprocessor"); X86_IRQ_END }
-void int_irq8(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Double Fault"); X86_IRQ_END }
-void int_irq9(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Coprocessor Segment Overrun"); X86_IRQ_END }
-void int_irq10(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Invalid TSS"); X86_IRQ_END }
-void int_irq11(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Segment Not Present"); X86_IRQ_END }
-void int_irq12(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Stack Segment Overrun"); X86_IRQ_END }
-
-void int_irq13()
+
+void exception_handle_0(){ panic(FOOLOS_MODULE_NAME,"Divide by 0"); }
+void exception_handle_1(){ panic(FOOLOS_MODULE_NAME,"Single step (debugger)"); }
+void exception_handle_2(){ panic(FOOLOS_MODULE_NAME,"Non Maskable Interrupt"); }
+void exception_handle_3(){ panic(FOOLOS_MODULE_NAME,"Breakpoint (debugger)"); }
+void exception_handle_4(){ panic(FOOLOS_MODULE_NAME,"Overflow"); }
+void exception_handle_5(){ panic(FOOLOS_MODULE_NAME,"Bounds check"); }
+void exception_handle_6(){ panic(FOOLOS_MODULE_NAME,"Undefined OP Code"); }
+void exception_handle_7(){ panic(FOOLOS_MODULE_NAME,"No coprocessor"); }
+void exception_handle_8(){ panic(FOOLOS_MODULE_NAME,"Double Fault"); }
+void exception_handle_9(){ panic(FOOLOS_MODULE_NAME,"Coprocessor Segment Overrun"); }
+void exception_handle_10(){ panic(FOOLOS_MODULE_NAME,"Invalid TSS"); }
+void exception_handle_11(){ panic(FOOLOS_MODULE_NAME,"Segment Not Present"); }
+void exception_handle_12(){ panic(FOOLOS_MODULE_NAME,"Stack Segment Overrun"); }
+
+void exception_handle_13()
{
- X86_IRQ_BEGIN
uint32_t err;
asm("pop %eax"); // get Error Code
@@ -85,16 +85,13 @@ void int_irq13()
show_error(err);
panic(FOOLOS_MODULE_NAME,"General Protection Fault");
-
- X86_IRQ_END
}
-void int_irq14(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Page Fault"); X86_IRQ_END }
-void int_irq15(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Unassigned"); X86_IRQ_END }
-void int_irq16(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Coprocessor error"); X86_IRQ_END }
-void int_irq17(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Alignment Check"); X86_IRQ_END }
-void int_irq18(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Machine Check"); X86_IRQ_END }
-*/
+void exception_handle_15(){ panic(FOOLOS_MODULE_NAME,"Unassigned"); }
+void exception_handle_16(){ panic(FOOLOS_MODULE_NAME,"Coprocessor error"); }
+void exception_handle_17(){ panic(FOOLOS_MODULE_NAME,"Alignment Check"); }
+void exception_handle_18(){ panic(FOOLOS_MODULE_NAME,"Machine Check"); }
+
//set a handler for a specific interrupt
void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr)
@@ -148,8 +145,6 @@ void int_init(uint16_t sel)
int_install_ir(17, 0b10001110, 0x08,&int_irq17);
int_install_ir(18, 0b10001110, 0x08,&int_irq18);
-
-
// setup some custom interrupts
// remember that we shifted all interrupts with the pic by 32
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 91e1c45..76ae8d7 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -26,10 +26,7 @@
void kernel_main(uint32_t eax,uint32_t ebx)
{
-
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"kernel_main: eax=0x%08X ebx=0x%08X",eax,ebx);
-
//
// Configuring the PIT timer.
//
@@ -48,6 +45,7 @@ void kernel_main(uint32_t eax,uint32_t ebx)
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Loaded by: \"%s\"",info->boot_loader_name);
}
+
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"multiboot flags: 0x%08X",info->flags);
if(info->flags&&1<<0)
@@ -61,6 +59,29 @@ void kernel_main(uint32_t eax,uint32_t ebx)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"cmdline: \"%s\"",info->cmdline);
}
+
+ //
+ // Memory Init
+ //
+ // after this is set up we will be able to allocate and deallocate
+ // blocks of physical memory :)
+ //
+ // we know that here, the bootloader placed the memory map and
+ // its length
+ //
+
+ if(info->flags&&1<<6)
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"memory map of length %d provided by bootloader",info->mmap_length);
+ mem_init(info->mmap_addr,info->mmap_length);
+ }
+
+ else panic(FOOLOS_MODULE_NAME,"Unable to continue without memory map, sorry!");
+
+ //
+ // Modules
+ //
+
if(info->flags&&1<<3)
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d modules loaded",info->mods_count);
@@ -75,39 +96,6 @@ void kernel_main(uint32_t eax,uint32_t ebx)
mod++;
}
}
-
- if(info->flags&&1<<6)
- {
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"memory map of length %d provided by bootloader",info->mmap_length);
-
- uint32_t mmap_addr=info->mmap_addr;
-
- while(mmap_addr<info->mmap_addr+info->mmap_length)
- {
- multiboot_mmap *mmap=mmap_addr;
- uint32_t mem_start=mmap->base_addr;
- uint32_t mem_end=mmap->base_addr+mmap->length;
-
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%08X - %08X / type: %d, size: %d",
- mem_start, mem_end, mmap->type, mmap->size);
-
- mmap_addr+=mmap->size+4;
- }
-
-
- }
- else panic(FOOLOS_MODULE_NAME,"Unable to continue without memory map, sorry!");
-
- //
- // Memory Init
- //
- // after this is set up we will be able to allocate and deallocate
- // blocks of physical memory :)
- //
- // we know that here, the bootloader placed the memory map and
- // the number of entries.
- //
-// mem_init((physical_address)0xa001,(int)(*((uint16_t *)(0xa000))));
//
@@ -118,19 +106,20 @@ void kernel_main(uint32_t eax,uint32_t ebx)
//
// Activate Virtual Memory (paging)
-// pdirectory *dir=vmem_init(physbase);
+ pdirectory *dir=vmem_init(physbase);
// log buffered messages to console
log_log();
- while(1);
-
//
// Setup Interrupts (code segment: 0x08)
//
+
int_init(0x08);
+ //while(1);
+
//
// Scan the PCI Bus
//
@@ -163,6 +152,9 @@ void kernel_main(uint32_t eax,uint32_t ebx)
// Initialize Multitasking
//
//task_init(dir); //; this will never return!
+ //
+ while(1);
+ //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,".");
}
diff --git a/kernel/mem.c b/kernel/mem.c
index 4e7d392..72b92af 100644
--- a/kernel/mem.c
+++ b/kernel/mem.c
@@ -3,6 +3,7 @@
#include <stdint.h>
#include "config.h"
+#include "multiboot.h"
#include "lib/logger/log.h" // logger facilities
//! 8 blocks per byte
@@ -14,6 +15,11 @@
//! block alignment ??? TODO: what is this!?
#define PMMNGR_BLOCK_ALIGN PMMNGR_BLOCK_SIZE
+extern uint32_t kernel_start[];
+extern uint32_t kernel_end[];
+extern uint32_t stack_top[];
+extern uint32_t stack_bottom[];
+
//memory map bit array. Each bit represents a 4KB memory block
static uint32_t *_mmngr_memory_map;
@@ -96,8 +102,9 @@ int mmap_first_free_s (uint32_t x)
void pmmngr_init_region (uint32_t base, uint32_t size)
{
- uint32_t align = base / PMMNGR_BLOCK_SIZE;
- uint32_t blocks = size / PMMNGR_BLOCK_SIZE;
+ if(base<0x100000)return;
+ uint32_t align = base / PMMNGR_BLOCK_SIZE +1; // TODO: calc properly
+ uint32_t blocks = size / PMMNGR_BLOCK_SIZE -1;
for (; blocks>0; blocks--)
{
@@ -108,8 +115,10 @@ void pmmngr_init_region (uint32_t base, uint32_t size)
void pmmngr_deinit_region (uint32_t base, uint32_t size)
{
- uint32_t align = base / PMMNGR_BLOCK_SIZE;
- uint32_t blocks = size / PMMNGR_BLOCK_SIZE;
+ uint32_t align = base / PMMNGR_BLOCK_SIZE -1; // TODO: calc properly
+ uint32_t blocks = size / PMMNGR_BLOCK_SIZE +2;
+
+ //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%08X, %08X -> deinit %d blocks",base,size,blocks);
for (; blocks>0; blocks--)
{
@@ -182,73 +191,72 @@ void pmmngr_free_block (void* p)
}
-void mem_init(uint16_t *memmap,uint16_t entries)
+void mem_init(uint32_t memmap,uint32_t length)
{
- // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"the memory map contains %d entries.",entries);
- // count available mem
- uint32_t total_mem=0, highest_end;
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"kernel loaded at: 0x%08X- 0x%08X",kernel_start,kernel_end);
- //save pointer to memmap
- uint16_t *save=memmap;
+ // we will place the memory map directly after the kernel for now (TODO: move somewehere else, so modules are not overwritten!)
+ _mmngr_memory_map=kernel_end;
- //print memory map and calc blocks.
- for(int i=0;i<entries;i++)
- {
- int mem=(memmap[4]+(memmap[5]<<16));
- uint32_t low_end=(((uint32_t)memmap[1])<<16)+memmap[0];
- uint32_t high_end=low_end+mem-1;
+ // count available mem and track high_end of usable memory
+ uint32_t total_mem=0, highest_end;
+ // iterate : print memory map and calc blocks.
+ for(uint32_t mmap_addr=memmap;mmap_addr<memmap+length;)
+ {
+ multiboot_mmap *mmap=mmap_addr;
+ uint64_t mem_start=mmap->base_addr;
+ uint64_t mem_end=mmap->base_addr+mmap->length;
#ifdef MEM_PRINT_MEMORYMAP
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"range: 0x%08x - 0x%08x (%s %d KB)",
- low_end,high_end,memmap_type_to_string[memmap[8]-1],mem/1024);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%08X - %08X / type: %s, (size: %d)",
+ (uint32_t)mem_start, (uint32_t)mem_end, memmap_type_to_string[mmap->type-1], mmap->size);
#endif
+ uint32_t mem=mmap->length;
+
//reclaimable OR usable
- if(memmap[8]==1||memmap[8]==3)
+ if(mmap->type==1||mmap->type==3)
{
total_mem+=mem;
- highest_end=high_end;
-
+ highest_end=mmap->base_addr+mmap->length-1;
}
- memmap+=12; // next entry;
+ //next
+ mmap_addr+=mmap->size+4;
}
- int blocks=highest_end/4096+1;
+ uint32_t blocks=highest_end/4096+1;
mem_array_size=blocks/32+1;
- _mmngr_memory_map=0x500000;
-
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Init bitmap for 0x%X blocks (size: %d bytes)",blocks,mem_array_size*4);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Init bitmap for %d blocks (array size: %d bytes)",blocks,mem_array_size*4);
pmmngr_init (); //clear memmap
- //restore pointer to memmap
- memmap=save;
-
- for(int i=0;i<entries;i++)
+ // iterate : initialize memory
+ for(uint32_t mmap_addr=memmap;mmap_addr<memmap+length;)
{
- if(memmap[8]==1||memmap[8]==3)
+ multiboot_mmap *mmap=mmap_addr;
+
+ //reclaimable OR usable
+ if(mmap->type==1||mmap->type==3)
{
- pmmngr_init_region(memmap[0]+(memmap[1]<<16),memmap[4]+((memmap[5])<<16));
+ pmmngr_init_region(mmap->base_addr,mmap->length);
}
- memmap+=12;
+
+ //next
+ mmap_addr+=mmap->size+4;
}
-
- // here is somewhere our kernel stuff.
- // reserve 4Mb (0x100000-0x500000) for kernel and ext2 img
- // even more!
- pmmngr_deinit_region(0x0,0x1400000);
+
- // and here is the memory map that we JUST created!
- pmmngr_deinit_region(0x500000,mem_array_size*4+PMMNGR_BLOCK_SIZE);
-
+ // deinitialize kernel + memory (TODO: modules)
+ pmmngr_deinit_region(kernel_start,((uint32_t)kernel_end-(uint32_t)kernel_start));
+ pmmngr_deinit_region(_mmngr_memory_map,mem_array_size*4+PMMNGR_BLOCK_SIZE);
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Usable Mem: %d (0x%X) bytes. (~%d MB)",total_mem,total_mem,total_mem/1024/1024);
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Currently Free 4K blocks: %d blocks.",mem_free_blocks);
-
+ // mmap_show_free();
}
// analytics
diff --git a/kernel/multiboot.h b/kernel/multiboot.h
index 874e473..c82d7e2 100644
--- a/kernel/multiboot.h
+++ b/kernel/multiboot.h
@@ -1,4 +1,6 @@
//# https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#Boot-information-format
+#ifndef MULTIBOOT_H
+#define MULTIBOOT_H
#include <stdbool.h>
@@ -48,3 +50,5 @@ typedef struct multiboot_mod_struct
uint32_t reserved;
}multiboot_mod;
+
+#endif
diff --git a/kernel/task.c b/kernel/task.c
index d0c1b0c..a2a2ab8 100644
--- a/kernel/task.c
+++ b/kernel/task.c
@@ -82,6 +82,7 @@ volatile uint32_t my_scheduler(uint32_t oldesp)
// this gets called by our clock interrupt regularly!
volatile uint32_t task_switch_next(uint32_t oldesp)
{
+
timer_tick();
// check if multitasking has been started
diff --git a/linker.ld b/linker.ld
index f823710..7c1c4bf 100644
--- a/linker.ld
+++ b/linker.ld
@@ -4,6 +4,8 @@ SECTIONS
{
. = 1M;
+ kernel_start = .;
+
.text BLOCK(4K) : ALIGN(4K)
{
*(.multiboot)