feature: reboot on space with kpanic
This commit is contained in:
@ -31,6 +31,9 @@ __attribute__((noreturn)) void kpanic(const char *format, ...)
|
|||||||
/* kprintf("\n\n"); */
|
/* kprintf("\n\n"); */
|
||||||
/* print_stack(); */
|
/* print_stack(); */
|
||||||
/* kprintf("\n\n"); */
|
/* kprintf("\n\n"); */
|
||||||
/* kprintf("PRESS SPACE TO REBOOT"); */
|
kprintf("PRESS SPACE TO REBOOT");
|
||||||
__asm__ __volatile__("jmp panic");
|
while (terminal_getkey().c != ' ')
|
||||||
|
;
|
||||||
|
reboot();
|
||||||
|
// __asm__ __volatile__("jmp panic");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,6 @@ static void lst_add_back(struct frame_zone **root, struct frame_zone *element)
|
|||||||
it->next = element;
|
it->next = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void add_frame_node(multiboot_memory_map_t *mmmt)
|
static void add_frame_node(multiboot_memory_map_t *mmmt)
|
||||||
{
|
{
|
||||||
static uint32_t index = 0;
|
static uint32_t index = 0;
|
||||||
@ -64,27 +63,34 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
|
|||||||
((uint32_t)frame_zones_page_table - VIRT_OFFSET) | INIT_FLAGS;
|
((uint32_t)frame_zones_page_table - VIRT_OFFSET) | INIT_FLAGS;
|
||||||
|
|
||||||
/** We need to determine how many frames are available
|
/** We need to determine how many frames are available
|
||||||
to save how many frame the blocks contain etc we need some meta data
|
to save how many frame the blocks contain etc we need some meta
|
||||||
1 struct frame_zone and a frame_table, the size of the frame_table is 1 bit per frame
|
data 1 struct frame_zone and a frame_table, the size of the
|
||||||
the frame_table is a uint8_t so 8 bit, so its size must be CEIL(max_frames, 8)
|
frame_table is 1 bit per frame the frame_table is a uint8_t so 8 bit,
|
||||||
But we don't have max_frames.
|
so its size must be CEIL(max_frames, 8) But we don't have max_frames.
|
||||||
We can determine max_frame = (block_len - sizeof(struct frame_zone)) / (PAGE_SIZE + 1 / 8) (1 / 8 because size is in byte but we only need one bit)
|
We can determine max_frame = (block_len - sizeof(struct
|
||||||
Because we don't use float we can't have 1 / 8
|
frame_zone)) / (PAGE_SIZE + 1 / 8) (1 / 8 because size is in byte but
|
||||||
So we will multiplicate every members of this equation by 8 to have only complet number
|
we only need one bit) Because we don't use float we can't have 1 / 8
|
||||||
So... max_frame = (block_len - sizeof(struct frame_zone)) * 8 / (PAGE_SIZE * 8 + 1)
|
So we will multiplicate every members of this equation by 8 to
|
||||||
|
have only complet number So... max_frame = (block_len - sizeof(struct
|
||||||
|
frame_zone)) * 8 / (PAGE_SIZE * 8 + 1)
|
||||||
*/
|
*/
|
||||||
const uint32_t nb_frame = (len - sizeof(struct frame_zone)) * 8 / (PAGE_SIZE * 8 + 1);
|
const uint32_t nb_frame =
|
||||||
|
(len - sizeof(struct frame_zone)) * 8 / (PAGE_SIZE * 8 + 1);
|
||||||
|
|
||||||
const uint32_t frame_table_size = CEIL(nb_frame, (sizeof(uint8_t) * 8));
|
const uint32_t frame_table_size = CEIL(nb_frame, (sizeof(uint8_t) * 8));
|
||||||
uint32_t page_needed = CEIL(frame_table_size + sizeof(struct frame_zone), PAGE_SIZE);
|
uint32_t page_needed =
|
||||||
|
CEIL(frame_table_size + sizeof(struct frame_zone), PAGE_SIZE);
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (; i < page_needed; i++)
|
for (; i < page_needed; i++)
|
||||||
frame_zones_page_table[index + i] = (((uint32_t)start_addr + i * PAGE_SIZE) & PAGE_MASK) | INIT_FLAGS;
|
frame_zones_page_table[index + i] =
|
||||||
|
(((uint32_t)start_addr + i * PAGE_SIZE) & PAGE_MASK) |
|
||||||
|
INIT_FLAGS;
|
||||||
|
|
||||||
struct frame_zone *current =
|
struct frame_zone *current =
|
||||||
(struct frame_zone *)PTE2VA(PDE_FRAME_ZONES, index);
|
(struct frame_zone *)PTE2VA(PDE_FRAME_ZONES, index);
|
||||||
|
|
||||||
current->frame_table = (uint8_t*) ((uint32_t) current + sizeof(struct frame_zone));
|
current->frame_table =
|
||||||
|
(uint8_t *)((uint32_t)current + sizeof(struct frame_zone));
|
||||||
|
|
||||||
current->first_free_frame = 0;
|
current->first_free_frame = 0;
|
||||||
current->next = NULL;
|
current->next = NULL;
|
||||||
@ -98,15 +104,12 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
|
|||||||
lst_add_back(&head, current);
|
lst_add_back(&head, current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void init_frame_zones(void)
|
static void init_frame_zones(void)
|
||||||
{
|
{
|
||||||
for (uint32_t i = 0; i < mmap_length;
|
for (uint32_t i = 0; i < mmap_length;
|
||||||
i += sizeof(multiboot_memory_map_t))
|
i += sizeof(multiboot_memory_map_t)) {
|
||||||
{
|
|
||||||
multiboot_memory_map_t *mmmt =
|
multiboot_memory_map_t *mmmt =
|
||||||
(multiboot_memory_map_t *)((uint32_t)mmap_addr + i);
|
(multiboot_memory_map_t *)((uint32_t)mmap_addr + i);
|
||||||
|
|
||||||
if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE)
|
if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE)
|
||||||
add_frame_node(mmmt);
|
add_frame_node(mmmt);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user