Skip to content

Commit

Permalink
feat(memory): get frame ref
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasanchez committed Jul 22, 2022
1 parent dd3742b commit 441b8ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions memory/inc/module/os_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#pragma once

#include "memory_module.h"
#include "page_table.h"

/**
* @brief Create a new process object
Expand Down Expand Up @@ -68,3 +69,6 @@ uint32_t read_from_memory(memory_t *memory, uint32_t physical_address);

uint32_t
get_table_lvl2_number(memory_t *memory, uint32_t frame);

page_table_lvl_2_t *
get_frame_ref(memory_t *memory, uint32_t frame);
17 changes: 17 additions & 0 deletions memory/src/module/os_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ uint32_t create_frame_for_table(memory_t *memory, uint32_t table_index, uint32_t
{
table[i].present = true;
table[i].frame = frame;
table[i].use = true;
return i;
}
}
Expand Down Expand Up @@ -155,6 +156,22 @@ get_table_lvl2_number(memory_t *memory, uint32_t frame)
return INVALID_FRAME;
}

page_table_lvl_2_t *
get_frame_ref(memory_t *memory, uint32_t frame)
{
uint32_t id = get_table_lvl2_number(memory, frame);
page_table_lvl_2_t *table = safe_list_get(memory->tables_lvl_2, id);

for (uint32_t i = 0; i < memory->max_rows; i++)
{
if (table[i].frame == frame)
{
return &table[i];
}
}

return NULL;
}
// ============================================================================================================
// ***** Private Functions *****
// ============================================================================================================
Expand Down

0 comments on commit 441b8ce

Please sign in to comment.