Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

222 executables parse #224

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

222 executables parse #224

wants to merge 9 commits into from

Conversation

dreamos82
Copy link
Owner

Closes #222

@dreamos82 dreamos82 added this to the Executables milestone Nov 9, 2024
@dreamos82 dreamos82 marked this pull request as draft November 9, 2024 13:24
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldnt commit an executable to the git repo :)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i'm working on adding a new makefile goal to compile it from sources, i will add the source, removing this file as soon as i finish it.

@@ -47,7 +47,7 @@ void *map_phys_to_virt_addr_hh(void* physical_address, void* address, size_t fla
clean_new_table(new_table_hhdm);
pdpr_root = new_table_hhdm;
} else {
pretty_log(Verbose, "No need to allocate pml4");
//pretty_log(Verbose, "No need to allocate pml4");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of commenting these out, why not remove them? can always re-add them later if needed

idle_thread = idle_task->threads;
task_t* userspace_task = create_task("userspace_idle", NULL, &a, false);
//task_t* userspace_task = create_task_from_func("userspace_idle", NULL, &a, false);
task_t* elf_task = create_task_from_elf("elf_idle", NULL, (Elf64_Ehdr *) (uintptr_t) hhdm_get_variable(elf_module_start_phys));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the purpose of the double cast: (Elf64_Ehdr*)(uintptr_t)?

new_task->threads = thread;
}
scheduler_add_task(new_task);
//re-enable interrupts
asm("sti");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you enable interrupts unconditionally here, what if they were previously disabled before calling this function? Now the caller thinks they are disabled but in reality they arent. This is a pattern that will be used a lot, so it can be helpful to have something like:

const bool restore_intrs = disable_interrupts(); //returns previous state and ensure interrupts are disabled
[ ... ]
if (restore_intrs)
    enable_interrupts();

pretty_logf(Verbose, "Preparing to launch an ELF. entry_pint = 0x%x", (uint64_t) _entry_point);
new_thread->execution_frame->rip = (uint64_t)_entry_point;
} else {
new_thread->execution_frame->rip = prepare_userspace_function(&(parent_task->vmm_data));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the purpose of doing it this way? I feel like you could have prepare_userspace_function called when creating the task for the elf, and then create_thread doesnt need to know if the thread is for an elf or not. You can just tell it what address to begin executing and itll use that. It would also simplify things a bit.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the prepare_userspace_function is/was a temporary function that was basically copying a program (same for the one that now i'm running from ELF) from a char array into a userspace memory space and launch it.

I think this will be removed soon (but i think i'll keep it around until i fix the building of the elf that match the kernel PAGE_SIZE)

Copy link
Owner Author

@dreamos82 dreamos82 Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yeah, that function maybe can be repurposed to prepare the memory space for a new thread being launched from an executable file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[EXECUTABLES] Parse elf and get information on memory to allocate
2 participants