OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 7:17 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Wed Apr 12, 2017 9:10 am 
Offline

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


Top
 Profile  
 
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Wed Apr 12, 2017 9:14 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1110
Location: Tartu, Estonia
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


Top
 Profile  
 
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Wed Apr 12, 2017 9:31 am 
Offline

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

        unsigned char status = inb(0x64);
   if (status & 0x01) {
      inb(0x60);
       }


to my cihandle function it worked.


Top
 Profile  
 
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Wed Apr 12, 2017 10:01 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Wed Apr 12, 2017 10:04 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1110
Location: Tartu, Estonia
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


Top
 Profile  
 
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Wed Apr 12, 2017 10:35 am 
Offline

Joined: Tue Apr 11, 2017 11:18 am
Posts: 15
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:
while(1){asm("hlt");}
to the end of kmain let's hope it stays bug free.

if you are still interested:

link.ld
Code:
OUTPUT_FORMAT(elf32-i386)
ENTRY(start)
SECTIONS
{
   . = 0x100000;
   .text : { *(.text) }
   .data : { *(.data) }
   .bss  : { *(.bss)  }
}

and the commands used to compile:
Code:
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


Top
 Profile  
 
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Thu Apr 13, 2017 1:56 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
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.


Top
 Profile  
 
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Thu Apr 13, 2017 2:55 am 
Offline

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


Top
 Profile  
 
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Thu Apr 13, 2017 3:23 am 
Offline
Member
Member

Joined: Wed Sep 19, 2012 3:43 am
Posts: 91
Location: The Netherlands
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.


Top
 Profile  
 
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Thu Apr 13, 2017 4:13 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
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:
Quote:
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.


Top
 Profile  
 
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Thu Apr 13, 2017 10:11 am 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2017 12:15 pm
Posts: 149
Location: Belgium
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?

_________________
AQUA OS: https://obiwac.wordpress.com/aqua-os/


Top
 Profile  
 
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Thu Apr 13, 2017 10:38 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
If that was addressed at me, I'm more than happy to leave.


Top
 Profile  
 
 Post subject: Re: Qemu crashes after interrupt.
PostPosted: Thu Apr 13, 2017 12:02 pm 
Offline

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 93 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group