fix: gdt init no longer crashes
WIP: change page directory and stuff so the memory can work properly
This commit is contained in:
parent
5969dcca54
commit
9855669662
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define GDT_ADDRESS 0x00000800
|
#define GDT_ADDRESS 0xC0105040
|
||||||
#define GDT_SIZE 7
|
#define GDT_SIZE 7
|
||||||
|
|
||||||
// https://wiki.osdev.org/Global_Descriptor_Table#GDTR
|
// https://wiki.osdev.org/Global_Descriptor_Table#GDTR
|
||||||
|
@ -27,9 +27,10 @@ void kernel_main(void)
|
|||||||
terminal_initialize();
|
terminal_initialize();
|
||||||
init_gdt();
|
init_gdt();
|
||||||
init_idt();
|
init_idt();
|
||||||
init_memory();
|
/* init_memory(); */
|
||||||
load_drivers();
|
load_drivers();
|
||||||
kprintf("I see no way to confuse an array of 256 seg:off pairs with a "
|
kprintf(KERN_ALERT
|
||||||
|
"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");
|
||||||
shell_init();
|
shell_init();
|
||||||
|
@ -6,19 +6,11 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#define MAX_FRAMES 1048319
|
#define MAX_FRAMES 1048319
|
||||||
#define GET_FRAME(i) (frame_table[i / 8] & (1 << (i % 8)))
|
|
||||||
#define SET_FRAME(i, used) \
|
|
||||||
do { \
|
|
||||||
if (used) \
|
|
||||||
frame_table[i / 8] |= (1 << (i % 8)); \
|
|
||||||
else \
|
|
||||||
frame_table[i / 8] &= ~(1 << (i % 8)); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
extern uint32_t end_kernel;
|
static uint32_t end_kernel; // WIP but it's useless now
|
||||||
|
|
||||||
static uint8_t frame_table[CEIL(MAX_FRAMES, 8)];
|
static uint8_t frame_table[MAX_FRAMES];
|
||||||
static uint32_t remaining_frames = MAX_FRAMES;
|
static uint32_t remaining_frames = MAX_FRAMES;
|
||||||
|
|
||||||
void *alloc_frames(size_t size)
|
void *alloc_frames(size_t size)
|
||||||
@ -32,17 +24,18 @@ void *alloc_frames(size_t size)
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while (i < MAX_FRAMES) {
|
while (i < MAX_FRAMES) {
|
||||||
size_t free_frames = 1;
|
size_t free_frames = 1;
|
||||||
while (!GET_FRAME(i + free_frames) && free_frames < nb_frames &&
|
while (!frame_table[i + free_frames] && free_frames < nb_frames)
|
||||||
i + free_frames < remaining_frames)
|
|
||||||
free_frames++;
|
free_frames++;
|
||||||
if (free_frames == nb_frames)
|
if (free_frames == nb_frames)
|
||||||
goto end;
|
goto end;
|
||||||
|
if (!free_frames)
|
||||||
|
i++;
|
||||||
i += free_frames;
|
i += free_frames;
|
||||||
}
|
}
|
||||||
end:
|
end:
|
||||||
if (i != MAX_FRAMES) {
|
if (i != MAX_FRAMES) {
|
||||||
for (size_t j = 0; j < nb_frames; j++)
|
for (size_t j = 0; j < nb_frames; j++)
|
||||||
SET_FRAME(j + i, 1);
|
frame_table[j + i] = 1;
|
||||||
remaining_frames -= nb_frames;
|
remaining_frames -= nb_frames;
|
||||||
return &end_kernel + i * PAGE_SIZE;
|
return &end_kernel + i * PAGE_SIZE;
|
||||||
}
|
}
|
||||||
@ -66,7 +59,7 @@ int free_frames(void *frame_ptr, size_t size)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for (size_t i = start; i < start + nb_frames; i++)
|
for (size_t i = start; i < start + nb_frames; i++)
|
||||||
SET_FRAME(i, 0);
|
frame_table[i] = 0;
|
||||||
remaining_frames += nb_frames;
|
remaining_frames += nb_frames;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user