Qemu crashes after interrupt.

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.
Luca1
Posts: 15
Joined: Tue Apr 11, 2017 11:18 am

Re: Qemu crashes after interrupt.

Post by Luca1 »

matt11235 wrote:
Luca1 wrote:Sorry, but if all people in the OS dev community are as "open" to new people as some people in this thread I am not sure if I want/need friends in here.
imo this is one of the nicest places on the internet.

You just walked in, threw your code on the table and asked other people to fix it and then got upset when nobody spoon fed you more code. There's nothing wrong with asking for help, but you need to put some effort in yourself.
I don't want copy and paste code - but someone telling me that I forgot to read the data it would've been more helpful than what I got.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Qemu crashes after interrupt.

Post by xenos »

Luca1 wrote:
XenOS wrote:I doubt that QEMU crashes because you forgot to read the keyboard's status and data.
Well then give me another reason why my code works afterwards.
You are the one who made a claim which doesn't make sense at all, so you are the one from whom to request a proof, not the other way round. If you want to know what was really going wrong, then show all your code, explain every line in it and start understanding it. Right now all you're doing is guesswork, which is impossible to reconstruct.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Luca1
Posts: 15
Joined: Tue Apr 11, 2017 11:18 am

Re: Qemu crashes after interrupt.

Post by Luca1 »

XenOS wrote:
Luca1 wrote:
XenOS wrote:I doubt that QEMU crashes because you forgot to read the keyboard's status and data.
Well then give me another reason why my code works afterwards.
You are the one who made a claim which doesn't make sense at all, so you are the one from whom to request a proof, not the other way round. If you want to know what was really going wrong, then show all your code, explain every line in it and start understanding it. Right now all you're doing is guesswork, which is impossible to reconstruct.
You have the full code in my original post, which lead to qemu crashing with the error shown in the original post. After adding

Code: Select all


        unsigned char status = inb(0x64);
	if (status & 0x01) {
		inb(0x60);
       }
to my cihandle function it worked.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Qemu crashes after interrupt.

Post by iansjack »

Luca1 wrote:Sorry, but if all people in the OS dev community are as "open" to new people as some people in this thread I am not sure if I want/need friends in here.
One day, should you persist with OS development, you will realise how good the advice to learn debugging was.

Whatever, you say you don't need friends here, and that's fine by me. People do tend to react badly to those who are rude to the unpaid volunteers here who try to help them.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Qemu crashes after interrupt.

Post by xenos »

First of all, you have not shown any linker script or specified where the kernel is loaded, or given any compiler / linker command line. Without this information we can only guess what your code does.

Second, the change you introduced does not fix the problem, at best it hides it, or is even completely unrelated. Your code enables interrupts at some point by executing "sti". Once your kmain function is done, it returns and you execute "hlt", with interrupts enabled. As soon as an interrupt occurs, the interrupt handler is executed, and returns. After that, the instruction after hlt is executed, which happens to be your inb function. It ends with a "ret", but since there was no "call" to return from, it jumps to whatever happens to be on the stack right now, obviously some bogus address, and continues running from there, until it leads to a crash (like the one QEMU reports - execution runs somewhere where there is no usable RAM). Now your change may have caused something to run differently, so it doesn't jump to the same bogus address, but it still jumps to a different one, it just doesn't crash immediately (but it will at some point).

The best way to actually figure out what's going wrong is to single-step your code in a debugger, so you could use QEMU + GDB for that, or use Bochs instead, which has its own debugger and also tells you much more about what happens in your code.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Luca1
Posts: 15
Joined: Tue Apr 11, 2017 11:18 am

Re: Qemu crashes after interrupt.

Post by Luca1 »

iansjack wrote:
Luca1 wrote:Sorry, but if all people in the OS dev community are as "open" to new people as some people in this thread I am not sure if I want/need friends in here.
One day, should you persist with OS development, you will realise how good the advice to learn debugging was.

Whatever, you say you don't need friends here, and that's fine by me. People do tend to react badly to those who are rude to the unpaid volunteers here who try to help them.
I am not saying that a debugger is not a good advice.
The problem is that the help that was provided to me was not help at all.
XenOS wrote:First of all, you have not shown any linker script or specified where the kernel is loaded, or given any compiler / linker command line. Without this information we can only guess what your code does.

Second, the change you introduced does not fix the problem, at best it hides it, or is even completely unrelated. Your code enables interrupts at some point by executing "sti". Once your kmain function is done, it returns and you execute "hlt", with interrupts enabled. As soon as an interrupt occurs, the interrupt handler is executed, and returns. After that, the instruction after hlt is executed, which happens to be your inb function. It ends with a "ret", but since there was no "call" to return from, it jumps to whatever happens to be on the stack right now, obviously some bogus address, and continues running from there, until it leads to a crash (like the one QEMU reports - execution runs somewhere where there is no usable RAM). Now your change may have caused something to run differently, so it doesn't jump to the same bogus address, but it still jumps to a different one, it just doesn't crash immediately (but it will at some point).

The best way to actually figure out what's going wrong is to single-step your code in a debugger, so you could use QEMU + GDB for that, or use Bochs instead, which has its own debugger and also tells you much more about what happens in your code.
This is the first thing that actually helped - thanks!

I added

Code: Select all

while(1){asm("hlt");}
to the end of kmain let's hope it stays bug free.

if you are still interested:

link.ld

Code: Select all

OUTPUT_FORMAT(elf32-i386)
ENTRY(start)
SECTIONS
 {
   . = 0x100000;
   .text : { *(.text) }
   .data : { *(.data) }
   .bss  : { *(.bss)  }
 }
and the commands used to compile:

Code: Select all

nasm -f elf32 kernel.asm -o kasm.o
gcc -fno-stack-protector -m32 -g -c kernel.c -o kc.o
ld -m elf_i386 -T link.ld -o kernel kasm.o kc.o
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Qemu crashes after interrupt.

Post by dozniak »

Luca1 wrote:
iansjack wrote:Whatever, you say you don't need friends here, and that's fine by me. People do tend to react badly to those who are rude to the unpaid volunteers here who try to help them.
I am not saying that a debugger is not a good advice.
The problem is that the help that was provided to me was not help at all.
That's fine, we don't need you too.
Learn to read.
Luca1
Posts: 15
Joined: Tue Apr 11, 2017 11:18 am

Re: Qemu crashes after interrupt.

Post by Luca1 »

dozniak wrote:
Luca1 wrote:
iansjack wrote:Whatever, you say you don't need friends here, and that's fine by me. People do tend to react badly to those who are rude to the unpaid volunteers here who try to help them.
I am not saying that a debugger is not a good advice.
The problem is that the help that was provided to me was not help at all.
That's fine, we don't need you too.
That
Luca1 wrote:I am not sure if I want/need friends in here.
was meant as "I am not sure if I will continue in OS dev", because if someone is saying
iansjack wrote:That's, fairly obviously, the cause of your problem.
it means that they know what the problem is without telling me why it occurs or how it is fixed. Which is, in my opinion, not nice.
FusT
Member
Member
Posts: 91
Joined: Wed Sep 19, 2012 3:43 am
Location: The Netherlands

Re: Qemu crashes after interrupt.

Post by FusT »

Luca1 wrote:it means that they know what the problem is without telling me why it occurs or how it is fixed. Which is, in my opinion, not nice.
First off, it's perfectly fine to have that opinion.
Having said that, the goal is to help people out by giving them a push in the right direction, not give them the answer to solve their problem. This is because you should completely understand why your code doesn't do what you expect it to do instead of relying on others to fix it for you. If you don't completely understand why something is/isn't working you'll never be able to fix future (and more complicated) problems by yourself.

I do realize this approach may seem hostile towards newcomers but it scares of copy/pasters not willing to learn.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Qemu crashes after interrupt.

Post by iansjack »

Luca1 wrote:That
Luca1 wrote:I am not sure if I want/need friends in here.
was meant as "I am not sure if I will continue in OS dev", because if someone is saying
iansjack wrote:That's, fairly obviously, the cause of your problem.
it means that they know what the problem is without telling me why it occurs or how it is fixed. Which is, in my opinion, not nice.
Now, do you think it fair to quote a single sentence out of context? The fuller quote is:
Do you know the state of the stack? Do you know how the stack go into that state? (That's, fairly obviously, the cause of your problem.) Is your stack even valid?
I told you exactly what I thought the cause of your problem was (a corrupted stack) and, in the same post I told you exactly how to solve it. (Use a debugger to find out where and why the stack is being corrupted.) You seem to be expecting someone to debug your program for you and then tell you exactly where the incorrect instruction in your program is without putting in any effort yourself. That's not the way it works.

In my opinion it is not nice to be rude to people trying to help you and it is not nice to twist their words - and lie about what they told you - by quoting out of context.

I think your inability to accept advice, and your willingness to give up so easily without putting in a little groundwork, are not going to stand you in good stead with what is a fairly difficult field of study. I think you are right to doubt whether you will continue with OS development.
User avatar
obiwac
Member
Member
Posts: 149
Joined: Fri Jan 27, 2017 12:15 pm
Libera.chat IRC: obiwac
Location: Belgium

Re: Qemu crashes after interrupt.

Post by obiwac »

This is probably not going to help this situation at all, but why don't you just leave this post, to preserve the kindness / niceness of these forums?
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Qemu crashes after interrupt.

Post by iansjack »

If that was addressed at me, I'm more than happy to leave.
Luca1
Posts: 15
Joined: Tue Apr 11, 2017 11:18 am

Re: Qemu crashes after interrupt.

Post by Luca1 »

FusT wrote:
Luca1 wrote:it means that they know what the problem is without telling me why it occurs or how it is fixed. Which is, in my opinion, not nice.
First off, it's perfectly fine to have that opinion.
Having said that, the goal is to help people out by giving them a push in the right direction, not give them the answer to solve their problem. This is because you should completely understand why your code doesn't do what you expect it to do instead of relying on others to fix it for you. If you don't completely understand why something is/isn't working you'll never be able to fix future (and more complicated) problems by yourself.

I do realize this approach may seem hostile towards newcomers but it scares of copy/pasters not willing to learn.
It just looks like you are trying to keep the knowledge to yourself if you are not giving answers to the problem. This is the first forum that I'm in where it is handled this way.
Post Reply