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

Solution to bootloops or kernel weird behaviour #36

Open
kirstenjg opened this issue Apr 18, 2022 · 1 comment
Open

Solution to bootloops or kernel weird behaviour #36

kirstenjg opened this issue Apr 18, 2022 · 1 comment

Comments

@kirstenjg
Copy link

I posted this in a comment but it deserves its own post as I have questions.

I had this issue which creeps up when I change to certain resolutions causing boot loops but sometimes undefined behavior in the kernel and it took me a while to figure this out but the first page at address 0 is already allocated causing the AllocatePages to fail. I assume it's reserved by the bootloader for itself? I have unallocated it and after that it allocates fine but then you are overwriting memory which also causes boot failures or problems in the kernel.

What does work is changing this line to:
Elf64_Addr segment = phdr->p_paddr;
to
Elf64_Addr segment = phdr->p_paddr + 0x1000;

This starts loading the kernel at page 2.

Then change:
void (KernelStart)(BootInfo) = ((attribute((sysv_abi)) void ()(BootInfo) ) header.e_entry);
to
void (KernelStart)(BootInfo) = ((attribute((sysv_abi)) void ()(BootInfo) ) header.e_entry + 0x1000);

This loads the kernel from page 2.

Now the kernel boots fine and everything works except interrupts. To fix this and I am not happy with this fix is in the kernel kernelUtil.cpp change:
interrupt->SetOffset((uint64_t)handler);
to
interrupt->SetOffset((uint64_t)handler + 0x1000);

I do not want to have to add this offset to certain things inside the kernel.
Is there any way to tell the compiler or linker to account for this 0x1000 offset and remap the addresses?
I am sure there is a way I just don't know how.

If there is another solution let me know.

@kirstenjg
Copy link
Author

It looks like the solution to above is not the changes I suggested above but rather change the kernel.ld script by adding this line:
. = 0x1000; just before _KernelStart = .;

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

No branches or pull requests

1 participant