feature: reboot on space with kpanic

This commit is contained in:
0x35c
2025-11-28 16:35:40 +01:00
parent 9c91830007
commit c6a5bf25c2
2 changed files with 30 additions and 24 deletions

View File

@ -31,6 +31,9 @@ __attribute__((noreturn)) void kpanic(const char *format, ...)
/* kprintf("\n\n"); */
/* print_stack(); */
/* kprintf("\n\n"); */
/* kprintf("PRESS SPACE TO REBOOT"); */
__asm__ __volatile__("jmp panic");
kprintf("PRESS SPACE TO REBOOT");
while (terminal_getkey().c != ' ')
;
reboot();
// __asm__ __volatile__("jmp panic");
}

View File

@ -21,7 +21,6 @@ static void lst_add_back(struct frame_zone **root, struct frame_zone *element)
it->next = element;
}
static void add_frame_node(multiboot_memory_map_t *mmmt)
{
static uint32_t index = 0;
@ -64,33 +63,40 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
((uint32_t)frame_zones_page_table - VIRT_OFFSET) | INIT_FLAGS;
/** We need to determine how many frames are available
to save how many frame the blocks contain etc we need some meta data
1 struct frame_zone and a frame_table, the size of the frame_table is 1 bit per frame
the frame_table is a uint8_t so 8 bit, 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)
Because we don't use float we can't have 1 / 8
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)
to save how many frame the blocks contain etc we need some meta
data 1 struct frame_zone and a frame_table, the size of the
frame_table is 1 bit per frame the frame_table is a uint8_t so 8 bit,
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) Because we don't use float we can't have 1 / 8
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));
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;
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 *)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->next = NULL;
current->remaining_frames = nb_frame;
current->total_frames = nb_frame;
current->addr = (void*)(uint32_t)start_addr + page_needed * PAGE_SIZE;
current->addr = (void *)(uint32_t)start_addr + page_needed * PAGE_SIZE;
bzero(current->frame_table, frame_table_size);
@ -98,15 +104,12 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
lst_add_back(&head, current);
}
static void init_frame_zones(void)
{
for(uint32_t i = 0; i < mmap_length;
i += sizeof(multiboot_memory_map_t))
{
multiboot_memory_map_t* mmmt =
(multiboot_memory_map_t*) ((uint32_t)mmap_addr + i);
for (uint32_t i = 0; i < mmap_length;
i += sizeof(multiboot_memory_map_t)) {
multiboot_memory_map_t *mmmt =
(multiboot_memory_map_t *)((uint32_t)mmap_addr + i);
if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE)
add_frame_node(mmmt);
}