Compare commits
No commits in common. "5fba376e2f5f727bf97978aaaee60672176cf04f" and "659ba24f12fb4e87e594275f855ef0aae5c35519" have entirely different histories.
5fba376e2f
...
659ba24f12
@ -16,9 +16,6 @@
|
|||||||
#define HEAP_START ((uint32_t) & _kernel_end - HEAP_END)
|
#define HEAP_START ((uint32_t) & _kernel_end - HEAP_END)
|
||||||
#define PT_START 256
|
#define PT_START 256
|
||||||
|
|
||||||
#define GET_PAGE_ADDR(pd_index, pt_index) \
|
|
||||||
(((pd_index * 1024) + pt_index) * 4096)
|
|
||||||
|
|
||||||
extern uint32_t _kernel_end;
|
extern uint32_t _kernel_end;
|
||||||
extern uint32_t boot_page_directory;
|
extern uint32_t boot_page_directory;
|
||||||
extern uint32_t *page_directory;
|
extern uint32_t *page_directory;
|
||||||
@ -31,4 +28,4 @@ int free_frames(void *frame_ptr, size_t size);
|
|||||||
void *alloc_pages(size_t size);
|
void *alloc_pages(size_t size);
|
||||||
int free_pages(void *page_ptr, size_t size);
|
int free_pages(void *page_ptr, size_t size);
|
||||||
void init_page_table(uint32_t page_table[1024], uint16_t start);
|
void init_page_table(uint32_t page_table[1024], uint16_t start);
|
||||||
int16_t add_page_table(uint16_t pd_index);
|
int16_t create_page_table(uint16_t pd_index);
|
||||||
|
@ -36,6 +36,9 @@ void kernel_main(void)
|
|||||||
"I see no way to confuse an array of 256 seg:off pairs with a "
|
"I see no way to confuse an array of 256 seg:off pairs with a "
|
||||||
"complex 8*unknown quantity -byte descriptor table. -- Troy "
|
"complex 8*unknown quantity -byte descriptor table. -- Troy "
|
||||||
"Martin 03:50, 22 March 2009 (UTC)\n");
|
"Martin 03:50, 22 March 2009 (UTC)\n");
|
||||||
|
char *str = vmalloc(10);
|
||||||
|
if (str)
|
||||||
|
strcpy(str, "hello");
|
||||||
/* int i = 0; */
|
/* int i = 0; */
|
||||||
/* while (vmalloc(10)) */
|
/* while (vmalloc(10)) */
|
||||||
/* ; */
|
/* ; */
|
||||||
|
@ -14,8 +14,10 @@ static uint32_t remaining_frames = MAX_FRAMES;
|
|||||||
|
|
||||||
static int32_t find_next_block(size_t nb_frames)
|
static int32_t find_next_block(size_t nb_frames)
|
||||||
{
|
{
|
||||||
|
PRINT_UINT(CEIL(HEAP_START, PAGE_SIZE));
|
||||||
for (uint32_t i = CEIL(HEAP_START, PAGE_SIZE);
|
for (uint32_t i = CEIL(HEAP_START, PAGE_SIZE);
|
||||||
i + nb_frames < MAX_FRAMES; i++) {
|
i + nb_frames < MAX_FRAMES; i++) {
|
||||||
|
PRINT_UINT(i);
|
||||||
uint32_t j;
|
uint32_t j;
|
||||||
for (j = 0; frame_table[i + j] == 0 && j < nb_frames; j++)
|
for (j = 0; frame_table[i + j] == 0 && j < nb_frames; j++)
|
||||||
;
|
;
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "debug.h"
|
|
||||||
#include "kprintf.h"
|
#include "kprintf.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@ -16,12 +15,11 @@ static int16_t find_next_block(size_t nb_pages)
|
|||||||
{
|
{
|
||||||
for (uint16_t pd_index = 1; pd_index < 768; pd_index++) {
|
for (uint16_t pd_index = 1; pd_index < 768; pd_index++) {
|
||||||
if (page_directory[pd_index] == 0x02) {
|
if (page_directory[pd_index] == 0x02) {
|
||||||
if (add_page_table(pd_index) < 0)
|
if (create_page_table(pd_index) < 0)
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
current_pd_index = pd_index;
|
current_pd_index = pd_index;
|
||||||
current_page_table =
|
current_page_table = (uint32_t *)((PT_START + pd_index) * 1024);
|
||||||
(uint32_t *)GET_PAGE_ADDR(0, pd_index + PT_START);
|
|
||||||
for (uint16_t i = 0; i + nb_pages < PT_SIZE; i++) {
|
for (uint16_t i = 0; i + nb_pages < PT_SIZE; i++) {
|
||||||
uint16_t j;
|
uint16_t j;
|
||||||
for (j = 0; current_page_table[i + j] >> 12 == i + j &&
|
for (j = 0; current_page_table[i + j] >> 12 == i + j &&
|
||||||
@ -58,7 +56,7 @@ void *alloc_pages(size_t size)
|
|||||||
current_page_table[i] =
|
current_page_table[i] =
|
||||||
((uint32_t)frame & PAGE_MASK) | INIT_FLAGS;
|
((uint32_t)frame & PAGE_MASK) | INIT_FLAGS;
|
||||||
}
|
}
|
||||||
return (void *)GET_PAGE_ADDR(current_pd_index, index);
|
return (void *)(((current_pd_index * 1024) + index) * 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
int free_pages(void *page_ptr, size_t size)
|
int free_pages(void *page_ptr, size_t size)
|
||||||
|
@ -1,22 +1,18 @@
|
|||||||
#include "debug.h"
|
|
||||||
#include "kprintf.h"
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
void init_page_table(uint32_t page_table[1024], uint16_t start)
|
void init_page_table(uint32_t page_table[1024], uint16_t start)
|
||||||
{
|
{
|
||||||
for (uint16_t i = start; i < 1024; i++)
|
for (uint16_t i = start; i < 1024; i++)
|
||||||
page_table[i] = (i << 12) | 0x03;
|
page_table[i] = (i << 12) | 0x03;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t add_page_table(uint16_t pd_index)
|
int16_t create_page_table(uint16_t pd_index)
|
||||||
{
|
{
|
||||||
void *frame = alloc_frames(PAGE_SIZE);
|
void *frame = alloc_frames(PAGE_SIZE);
|
||||||
if (!frame)
|
if (!frame)
|
||||||
return -1;
|
return -1;
|
||||||
page_table_default[PT_START + pd_index] =
|
|
||||||
((uint32_t)frame & PAGE_MASK) | 0x03;
|
|
||||||
uint32_t *page_table =
|
|
||||||
(uint32_t *)GET_PAGE_ADDR(0, PT_START + pd_index);
|
|
||||||
init_page_table(page_table, 0);
|
|
||||||
page_directory[pd_index] = ((uint32_t)frame & PAGE_MASK) | 0x03;
|
page_directory[pd_index] = ((uint32_t)frame & PAGE_MASK) | 0x03;
|
||||||
|
uint32_t *page_table = (uint32_t *)((PT_START + pd_index) * 1024);
|
||||||
|
init_page_table(page_table, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user