Fixed bugs about kheap, paging and ordered list

Furthermore, added Heap kernel driver code
for both allocation and deallocation
free() does not works yet:
`ASSERTION-FAILED(head->magic == HEAP_MAGIC) at kheap.c:261`
This commit is contained in:
ice-bit
2019-09-24 18:32:38 +02:00
parent a378ca4061
commit 3c574238cf
6 changed files with 117 additions and 80 deletions

View File

@@ -1,41 +1,67 @@
#ifndef PAGING_H
#define PAGING_G
#define PAGING_H
#include <stdint.h>
#include "isr.h"
#include "tty.h"
#include "kheap.h"
typedef struct page {
uint32_t present : 1; // Presence in memory of single page
uint32_t rw : 1; // if set read write otherwise read only
uint32_t user : 1; // Supervisored mode only if cleared
uint32_t accessed : 1; // true if page has been accessed since last refresh
uint32_t dirty : 1; // Same as above for write.
uint32_t unused : 7; // unused bits
uint32_t frame : 20; // Frame address (shifted to the right)
} page_t;
#define FRAME_SIZE 4096
#define PAGE_TABLE_SIZE 1024
#define PAGE_DIRECTORY_SIZE 1024
#define PAGE_NOT_PRESENT 0
#define PAGE_PRESENT 1
#define PAGE_READ_ONLY 0
#define PAGE_READ_WRITE 1
#define PAGE_USER 0
#define PAGE_SUPERVISOR 0
#define PAGE_SIZE_4KB 0
#define PAGE_SIZE_4MB 1
#define FRAME_ALLOCATION_SECTION_SIZE 32
#define USED_FRAME_ALLOCATIONS_SECTION 0xFFFFFFFF
#define FREE_FRAME_ALLOCATIONS_SECTION 0x00000000
typedef struct page_table {
page_t pages[1024];
} page_table_t;
// Reserve 16 MiB of physical memory
#define PHYSICAL_MEMORY_SIZE 0x10000000
typedef struct page_directory {
page_table_t *tables[1024]; // array of pointers to page tables
uint32_t tables_physical[1024]; // address of tables physical.
uint32_t physical_addr;
} page_directory_t;
struct page { // Page structure from Intel's developer manual
uint8_t present : 1;
uint8_t rw : 1;
uint8_t user : 1;
uint8_t pwt : 1;
uint8_t pcd : 1;
uint8_t a : 1;
uint8_t d : 1;
uint8_t pat : 1;
uint8_t g : 1;
uint8_t unused : 3;
uint32_t frame : 20;
} __attribute__((packed));
typedef struct page page_t;
struct page_table {
page_t pages[PAGE_TABLE_SIZE];
};
typedef struct page_table page_table_t;
/* For each page we hold two arrays:
* one is used by the CPU to hold the physical address
* the other is used to hold the virtual address to actual read
* or write to it. */
struct page_directory {
page_table_t *page_table_virtual[PAGE_DIRECTORY_SIZE];
uint32_t page_table_physical[PAGE_DIRECTORY_SIZE];
};
typedef struct page_directory page_directory_t;
// Setup the environment
void init_paging();
// Load specified page directory into CR3 register
void switch_page_directory(page_directory_t *new);
void enable_paging(page_directory_t *new);
// Retrieve pointer to specified page address
page_t *get_page(uint32_t addr, int32_t make, page_directory_t *dir);
// Handle page faults
void page_fault(registers_t regs);
// Allocate a new frame
void alloc_frame(page_t *page, int32_t is_kernel, int32_t is_writeable);
void alloc_frame(page_t *page, int32_t is_supervisored, int32_t is_writeable);
// Deallocate frame
void free_frame(page_t *page);