Trying to implement to ram disk
Posted: Mon Oct 06, 2014 1:36 pm
Edit: Found a solution, I set the ram disk only as readable and kept the other information at a lower location. I still would like clarification if anyone is willing to say where I went wrong.
If someone could give me advice on the ram disk, I've run into a page fault when trying to init the ram disk but it comes from init paging due to the high placement of the ram disk. (http://www.jamesmolloy.co.uk/tutorial_h ... 0Heap.html)
I did some research because I was confused why GRUB was loading the image at a high address and found that GRUB2 unlike legacy does this. The line that errors...
I had tested without the ramdisk at lower locations in memory it was fine. This made me conclude it was mapping physical->virtual and found the algorithm was mapping incorrectly at higher addresses 0x1FFxxxxx+. His expects to initialize the heap at a low placement address. I went back and checked and noticed that when mapping phys to virtual, some page frames are not zeroed when they have not yet been modified with the exception of memset 0.. This prevents the tables from being mapped as write and read. This is where I am stuck. Maybe I have completely missed a concept here but I thought I understood the code. The page fault gives a read only indication which has pointed me towards this as being the issue.
If someone could give me advice on the ram disk, I've run into a page fault when trying to init the ram disk but it comes from init paging due to the high placement of the ram disk. (http://www.jamesmolloy.co.uk/tutorial_h ... 0Heap.html)
I did some research because I was confused why GRUB was loading the image at a high address and found that GRUB2 unlike legacy does this. The line that errors...
Code: Select all
heap_t *create_heap(u32int start, u32int end_addr, u32int max, u8int supervisor, u8int readonly)
{
heap_t *heap = (heap_t*)kmalloc(sizeof(heap_t));
kout("HEAP IDX\n");
kohex(&heap);
kochr('\n');
//S&E MUST BE PAGE ALLIGNED
ASSERT(start%0x1000 == 0);
ASSERT(end_addr%0x1000 == 0);
//Index init - The error spot <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
heap->index = place_ordered_array( (void*)start, HEAP_INDEX_SIZE, &header_t_less_than);
Code: Select all
ordered_array_t place_ordered_array(void *addr, u32int max_size, lessthan_predicate_t less_than)
{
ordered_array_t to_ret;
to_ret.array = (type_t*)addr;
memset(to_ret.array, 0, max_size*sizeof(type_t));
to_ret.size = 0;
to_ret.max_size = max_size;
to_ret.less_than = less_than;
return to_ret;
}
Code: Select all
//16MB per 1 - F *16 physical memory - the issue
u32int mem_end_page = 0x1000000; //FIX ONE
int i = 0;
nframes = mem_end_page / 0x1000;
frames = (u32int*)kmalloc(INDEX_FROM_BIT(nframes));
memset(frames, 0, INDEX_FROM_BIT(nframes));
kernel_directory = (page_directory_t*)kmalloc_a(sizeof(page_directory_t));
memset(kernel_directory, 0, sizeof(page_directory_t));
current_directory = kernel_directory;
//map pages in kernel heap area
for (i = KHEAP_START; i < KHEAP_START+KHEAP_INITIAL_SIZE; i += 0x1000)
get_page(i, 1, kernel_directory);
//DEBUG ============================================
//phys->virt
for(i=0; i<placement_address+0x1000; i+=0x1000)
alloc_frame( get_page(i, 1, kernel_directory), 0, 0);
//DEBUG ============================================
//Allocate previously mapped pages
for (i = KHEAP_START; i < KHEAP_START+KHEAP_INITIAL_SIZE; i += 0x1000)
alloc_frame( get_page(i, 1, kernel_directory), 0, 0);
//handler
register_interrupt_handler(14, page_fault);
kout("Kernel directory: ");
kohex(kernel_directory);
kochr('\n');
//paging setup
switch_page_directory(kernel_directory);
kout("Entering problem state - kheap.c\n");
//Kheap init - THE PROBLEM
kheap = create_heap(KHEAP_START, KHEAP_START+KHEAP_INITIAL_SIZE, 0xCFFFF000, 0, 0);