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:

Higher Half Kernel not working with Meaty Skeleton

Post by Bowlslaw »

Hello, I am new to osdev and am running into a problem that I do not understand.

When I use the code from this article: https://wiki.osdev.org/User:Glauxosdeve ... Bare_Bones

I copy it as the kernel., boot.S, and yes, I also change the video memory address to the correct address as defined in the Glauxosdever code.

However, when I try to run ./qemu script, the kernel seems to start up. I see the grub menu and select “myos”. However, it appears to load for around one second and then goes back to the GRUB boot menu.

Are there any known compatibility issues with Higher Half and meaty skeleton?

I can run both higher half and meaty skeleton individually just find.
pat
Member
Member
Posts: 36
Joined: Tue Apr 03, 2018 2:44 pm
Libera.chat IRC: patv

Re: Higher Half Kernel not working with Meaty Skeleton

Post by pat »

You're going to need to provide more information for people to help.
Bowlslaw wrote: However, when I try to run ./qemu script, the kernel seems to start up. I see the grub menu and select “myos”. However, it appears to load for around one second and then goes back to the GRUB boot menu.
This sounds like a triple fault. You should modify your qemu script and add the following args: -s -no-reboot -no-shutdown. Then you can connect with gdb with "target remote localhost:1234". Add a breakpoint to _start, and start single stepping until something breaks.
Image is my operating system.

"...not because [it is] easy, but because [it is] hard; because that goal will serve to organize and measure the best of [my] energies and skills..."
Bowlslaw
Posts: 20
Joined: Fri Oct 26, 2018 12:54 pm
Contact:

Re: Higher Half Kernel not working with Meaty Skeleton

Post by Bowlslaw »

pat wrote:You're going to need to provide more information for people to help.
Bowlslaw wrote: However, when I try to run ./qemu script, the kernel seems to start up. I see the grub menu and select “myos”. However, it appears to load for around one second and then goes back to the GRUB boot menu.
This sounds like a triple fault. You should modify your qemu script and add the following args: -s -no-reboot -no-shutdown. Then you can connect with gdb with "target remote localhost:1234". Add a breakpoint to _start, and start single stepping until something breaks.
Thank you! I was not aware that I could do this. I read about the “triple fault” and it, typically, causes the CPU to reset?

Cool debug tip. I will make note of this and try to debug myself.
pat
Member
Member
Posts: 36
Joined: Tue Apr 03, 2018 2:44 pm
Libera.chat IRC: patv

Re: Higher Half Kernel not working with Meaty Skeleton

Post by pat »

Bowlslaw wrote:Thank you! I was not aware that I could do this. I read about the “triple fault” and it, typically, causes the CPU to reset?
Yeah, basically at that point all hope is lost and the CPU commits sudoku and restarts. You can't recover from it, but you can stop QEMU from restarting to give yourself an opportunity to figure out what's going on.
Image is my operating system.

"...not because [it is] easy, but because [it is] hard; because that goal will serve to organize and measure the best of [my] energies and skills..."
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: Higher Half Kernel not working with Meaty Skeleton

Post by glauxosdever »

Hi,


Some time ago, a contributor to that page made some changes in the code, mostly make it easier for a beginner to understand it, use more descriptive symbols and align the code style to the regular Bare Bones. However, he overlooked that "boot_page_table1" was not defined (boot_pagetab1 was defined instead), so you maybe confused it with "boot_page_directory" or something. After these changes, it works for me. I also updated the page accordingly.


Regards,
glauxosdever
Bowlslaw
Posts: 20
Joined: Fri Oct 26, 2018 12:54 pm
Contact:

Re: Higher Half Kernel not working with Meaty Skeleton

Post by Bowlslaw »

glauxosdever wrote:Hi,


Some time ago, a contributor to that page made some changes in the code, mostly make it easier for a beginner to understand it, use more descriptive symbols and align the code style to the regular Bare Bones. However, he overlooked that "boot_page_table1" was not defined (boot_pagetab1 was defined instead), so you maybe confused it with "boot_page_directory" or something. After these changes, it works for me. I also updated the page accordingly.


Regards,
glauxosdever
Thanks. I did notice that issue in the code and changed it just as you did, yesterday, but I am still receiving the same apparent triple fault. I haven't had time to debug as pat mentioned, though.

EDIT: Maybe it's something with my qemu or something.
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 »

It works for me. Do you have a copy of your ISO image available somewhere that I can download and try out? With your ISO I can try out what you have built to see why it may be failing. What is the command(s) inside of your shell scripts that launch QEMU.

Also be curious what Distribution/OS/Version you are using to build the kernel.
Bowlslaw
Posts: 20
Joined: Fri Oct 26, 2018 12:54 pm
Contact:

Re: Higher Half Kernel not working with Meaty Skeleton

Post by Bowlslaw »

Ok, I figured it out.

After a while, I noticed that the only real difference was how the memory address of the VGA text buffer was set.

In 'Meaty Skeleton', it is like this:

Code: Select all

static uint16_t *const VGA_MEMORY = (uint16_t *)0xC03FF000;

...

terminal_initialize(void) {
    ...
    terminal_buffer = VGA_MEMORY;
    ...
}
This kills the crab, er, OS.

However, I was able to get it to my by simply changing the definition of 'terminal_buffer' to the address itself, without an intermediate varable, like this:

Code: Select all

terminal_buffer = (uint16_t *)0xC03FF000;
The only difference I can see is that the code that works does not have the 'const' modifier. Does anyoen know why this is?

EDIT: AH, I got it. I simply had incorrect syntax for where I placed my '*' operator.

I accidentally made it so the VGA_MEMORY was unchangeable, heh, what a noob error on my part.

I also had code in my kernel which intentionally tried to scroll offscreen so that I could test my scrolling, but, when removed, stopped causing the crash as well.
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 »

This sounds like a side effect of some other problem. Have you added some other code (besides the video change) or made other changes that diverge from what is in the tutorial?Are you compiling/assembling/linking the kernel with the same commands as the tutorialor have youdone things differently?
Last edited by MichaelPetch on Sun Oct 28, 2018 11:08 am, edited 1 time in total.
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:This sounds like aside effect of some other problem. Have you added some other code or made other changes that diverge from what is in the tutorial?
Would changing some of the libc functions, like memcpy, to use pointers, insead of arrays, do it?
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: Would changing some of the libc functions, like memcpy, to use pointers, insead of arrays, do it?
Could well be a problem if you introduced bugs. It sounds like you have added other code to this project other than what is in the tutorial you linked to. You really should consider putting your whole project on something like github/gitlab or some other service so we can take a look at it. Sounds like the issue may not be the code in the skeleton but something else that has been done beyond that.
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: Would changing some of the libc functions, like memcpy, to use pointers, insead of arrays, do it?
Could well be a problem if you introduced bugs. It sounds like you have added other code to this project other than what is in the tutorial you linked to. You really should consider putting your whole project on something like github/gitlab or some other service so we can take a look at it. Sounds like the issue may not be the code in the skeleton but something else that has been done beyond that.
I have changed some. But, I did change it to be a copy of the tutorial. Once I changed the boot.S, linker.ld, and vga address, it works fine, UNTIL I try to scroll offscreen.

https://github.com/Bowlslaw/slawOS/tree/revamp

I have made changes to the 'terminal_putchar(char c)' function in order to test scrolling. The thing that confuses me is that this bug did not exist with meaty skeleton's default tutorial code. It only started crashing once I added the alternate higher half code.
Bowlslaw
Posts: 20
Joined: Fri Oct 26, 2018 12:54 pm
Contact:

Re: Higher Half Kernel not working with Meaty Skeleton

Post by Bowlslaw »

Ok, I hooked up the kernel to GDB like this:

Code: Select all

./build.sh
qemu-system-i386 -cdrom myos.iso -s -no-reboot -no-shutdown
gdb sysroot/boot/myos.kernel
gdb> target remote localhost:1234
I then 's' through the code, until I reach these values:

Code: Select all

0xc0100179 <_start+36>  mov    %edx,(%edi)
Where it proceeds to crash with SIGSEGV. It seems like it crashes the moment it hits _start.

I'm just trying test scrolling, and so the changes I made to tty.c are on lines 48 and 62 in the repo.
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 »

My apologies, I misread one of your updates and I thought you got it working somehow. Is Github updated with what you are now testing?
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:My apologies, I misread one of your updates and I thought you got it working somehow. Is Github updated with what you are now testing?
Yes, but at this moment I think I figured it out. In the repo I linked, look at (https://github.com/Bowlslaw/slawOS/blob ... /tty.c#L62), line 62-72. I removed this, and the problem vanished, even when I get the for loop in kernel.c to way beyond the VGA_WIDTH/HEIGHT.

I was getting a SIGSEGV, so...I think I was trying to write colors to areas outside of the VGA buffer?
Post Reply