Higher Half Kernel not working with Meaty Skeleton

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Bowlslaw
Posts: 20
Joined: Fri Oct 26, 2018 12:54 pm
Contact:

Re: Higher Half Kernel not working with Meaty Skeleton

Post by Bowlslaw »

Hm, this is strange.

When I try to test scrolling with code like this:

Code: Select all

for(int i = 0; i < 25; i++)
    printf("HERE\n");
it does not crash using the standard 'Meaty Skeleton', completely unchanged.

However, when I use 'Meaty Skeleton' with the 'Alternate Higher-Half Kernel' code, and no other changes, it crashes with a SIGSEGV when I try to printf past i = 24.
MichaelPetch
Member
Member
Posts: 799
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Higher Half Kernel not working with Meaty Skeleton

Post by MichaelPetch »

I haven't had time to debug this, but I can tell you that at some point you are writing to a memory address outside of the first video page (in my case I noticed an attempt by terminal_putchar to write to physical memory address 0xc03ff000+0x1040). Without paging (0xb8000+0x1040) you can do this because it is okay to write to physical memory addresses between 0xb8000 and 0xc0000. This is video memory. Part of it isn't visible on the screen but you are allowed to write to it. When you enable paging you only map the first 4kb of video memory. 80x25 text mode only takes 2000*2=4000 bytes. That fits inside the one 4096 byte page you have mapped. Once you write beyond that first 4096 bytes it crashes because you are writing to a page that isn't mapped.

This suggests a bug in your screen output routines and I would investigate the real possibility that your scrolling isn't correct.

Effectively paging has identified a bug in your software that always existed.
Bowlslaw
Posts: 20
Joined: Fri Oct 26, 2018 12:54 pm
Contact:

Re: Higher Half Kernel not working with Meaty Skeleton

Post by Bowlslaw »

MichaelPetch wrote:I haven't had time to debug this, but I can tell you that at some point you are writing to a memory address outside of the first video page (in my case I noticed an attempt by terminal_putchar to write to physical memory address 0xc03ff000+0x1040). Without paging (0xb8000+0x1040) you can do this because it is okay to write to physical memory addresses between 0xb8000 and 0xc0000. This is video memory. Part of it isn't visible on the screen but you are allowed to write to it. When you enable paging you only map the first 4kb of video memory. 80x25 text mode only takes 2000*2=4000 bytes. That fits inside the one 4096 byte page you have mapped. Once you write beyond that first 4096 bytes it crashes because you are writing to a page that isn't mapped.

This suggests a bug in your screen output routines and I would investigate the real possibility that your scrolling isn't correct.

Effectively paging has identified a bug in your software that always existed.
Thank you for the very informative response. Based on what I have, this means that the provided code on the wiki was not designed to deal with scrolling.

Which is fine; I don't expect you guys to do everything for me, and this difficulty encourages me to become an expert and truly learn.

So, it looks like I will need to better understand paging and also create a "page frame allocator" in order to deal with this scrolling issue.
MichaelPetch
Member
Member
Posts: 799
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Higher Half Kernel not working with Meaty Skeleton

Post by MichaelPetch »

Bowlslaw wrote:Thank you for the very informative response. Based on what I have, this means that the provided code on the wiki was not designed to deal with scrolling.
No, this means really that your scrolling is buggy IMHO. The Paging code is fine. When I ran it you were writing beyond the displayable video area. When scrolling you shouldn't have to write anything to the off screen video memory.
Bowlslaw
Posts: 20
Joined: Fri Oct 26, 2018 12:54 pm
Contact:

Re: Higher Half Kernel not working with Meaty Skeleton

Post by Bowlslaw »

MichaelPetch wrote:
Bowlslaw wrote:Thank you for the very informative response. Based on what I have, this means that the provided code on the wiki was not designed to deal with scrolling.
No, this means really that your scrolling is buggy IMHO. The Paging code is fine. When I ran it you were writing beyond the displayable video area. When scrolling you shouldn't have to write anything to the off screen video memory.
So, in the kernel code, this loop:

Code: Select all

for(int i = 0; i < 25; i++) {
    printf("HERE\n");
}
I need to make the code handle it once it gets beyond the vga video memory by NOT allowing anything to be written outside of the video memory. Instead, it should take the data and "move" it so that it stays within the vga text buffer.

EDIT: My problem has been solved. I just needed to add bounds checks, which I was unaware I needed because I did not need them when paging not not enabled. I did not understand paging, but I do now, and the code works fine.

Thank you for your help. Lesson learned on my part.
Post Reply