[Solved] IRQ Firing Bug

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.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: IRQ Firing Bug

Post by BrightLight »

SpyderTL wrote:Any time you see repeated three stacked horizontal lines followed by an S, you are printing your 16-bit Interrupt Table to the screen. This is likely because you are passing a null to a draw string function, so it is drawing everything from RAM address zero until it finds a null value.
Which is why we use paging to prevent this. ;)
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: IRQ Firing Bug

Post by Octacone »

Ch4ozz wrote:Your drawstring function probably draws a string but your passing single characters to it which simply wont work.
Either code a proper printf function and you can use

Code: Select all

printf("%c", kbdus[keycode]);
or you find another solution.
Damn, that is not good.
How my PrintString functions works:
1. PrintString gets called: PrintString("abc123");
2. PrintString has a loop, foreach char inside that loop it calls another function called PrintCharacter.
3. PrintCharacter prints given char with wanted color using 0xB8000
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: IRQ Firing Bug

Post by Octacone »

SpyderTL wrote:
thehardcoreOS wrote:Should I use SendEOI Inside my kbd and timer handlers?
Yes. You should notify the master PIC any time it signals an IRQ (0-7), and notify both the master and slave PIC when the slave PIC signals an IRQ (8-15). Any IRQs that you have unmasked should have valid interrupt handlers that will notify the proper PICs installed before you unmask them.
thehardcoreOS wrote:When I enable while(1) loop I can use my timer and my keyboard. But I get these weird glyphs:
Any time you see repeated three stacked horizontal lines followed by an S, you are printing your 16-bit Interrupt Table to the screen. This is likely because you are passing a null to a draw string function, so it is drawing everything from RAM address zero until it finds a null value.

That's my guess.

(I get this a lot, by the way.. :))

I see you get this a lot. You seem to be interrupts expert. 8)

Hmm, about that slave master EOI sending etc, I already have that function inside my IRQ_Handler that does the same exact thing, to just copy paste it inside my Keyboard_Handler and Timer_Handler? :?

What do you mean by it prints 16bit interrupt table? I don't think so, because it prints only what I tell it to print. Little bit confused in there. :?: :?: :?: Drawing from RAM??? I don't have any kind of memory management set up and I don't interact with RAM as fair as I know, or maybe I do? :?:
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: IRQ Firing Bug

Post by Octacone »

omarrx024 wrote:
SpyderTL wrote:Any time you see repeated three stacked horizontal lines followed by an S, you are printing your 16-bit Interrupt Table to the screen. This is likely because you are passing a null to a draw string function, so it is drawing everything from RAM address zero until it finds a null value.
Which is why we use paging to prevent this. ;)
It is sad that I still don't have any kind of memory management. Paging is my next big thing on the list.
Also I already know that: string paging; paging = "hell". :oops: :D
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: IRQ Firing Bug

Post by BrightLight »

thehardcoreOS wrote:It is sad that I still don't have any kind of memory management. Paging is my next big thing on the list.
Also I already know that: string paging; paging = "hell". :oops: :D
Paging is actually very easy; but beginners to it seem to think it's difficult and I thought so myself. :P
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: IRQ Firing Bug

Post by SpyderTL »

thehardcoreOS wrote:Hmm, about that slave master EOI sending etc, I already have that function inside my IRQ_Handler that does the same exact thing, to just copy paste it inside my Keyboard_Handler and Timer_Handler? :?

What do you mean by it prints 16bit interrupt table? I don't think so, because it prints only what I tell it to print. Little bit confused in there. :?: :?: :?: Drawing from RAM??? I don't have any kind of memory management set up and I don't interact with RAM as fair as I know, or maybe I do? :?:
What I meant to say is that whenever I see that pattern on the screen, with three horizontal lines and an S, it looks like what you would see if you copied the bytes starting at RAM address zero to the screen.

RAM address 0000:0000 is where the interrupt handler table is located when the machine first boots. My guess is that you are (accidentally) passing the wrong address to your print string function, and from the looks of the screen, I'm guessing that your print string function is attempting to draw whatever string is sitting at memory address zero.

Maybe that is a hint to help you track down the actual problem, but I could be wrong.
Hmm, about that slave master EOI sending etc, I already have that function inside my IRQ_Handler that does the same exact thing, to just copy paste it inside my Keyboard_Handler and Timer_Handler?
No, you only have to send the EOI once per interrupt (for each PIC, of course). Your original code looks like you were sending it twice per interrupt. I'm assuming that's fixed now.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: IRQ Firing Bug

Post by onlyonemac »

SpyderTL wrote:What I meant to say is that whenever I see that pattern on the screen, with three horizontal lines and an S, it looks like what you would see if you copied the bytes starting at RAM address zero to the screen.
Oh, so that's why I always get an S when I pass a NULL pointer to a string output function in my kernel, I never realised that. Not that it's a problem, just fascinating.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: IRQ Firing Bug

Post by Octacone »

onlyonemac wrote:
SpyderTL wrote:What I meant to say is that whenever I see that pattern on the screen, with three horizontal lines and an S, it looks like what you would see if you copied the bytes starting at RAM address zero to the screen.
Oh, so that's why I always get an S when I pass a NULL pointer to a string output function in my kernel, I never realised that. Not that it's a problem, just fascinating.
lol, never tried printing an empty string. :| fascinating yeah :shock:
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: IRQ Firing Bug

Post by SpyderTL »

There is a difference between passing a null address and passing an address to an empty string. If I had to guess, I'd say that your code is passing a null address.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: IRQ Firing Bug

Post by Octacone »

SpyderTL wrote:There is a difference between passing a null address and passing an address to an empty string. If I had to guess, I'd say that your code is passing a null address.
No worries, I fixed it.
For all future generations reading this: don't be stupid like me and instead of PrintStringFunction use PrintCharacterFunction and everything should be just fine. ;)
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: IRQ Firing Bug

Post by Ch4ozz »

thehardcoreOS wrote:
SpyderTL wrote:There is a difference between passing a null address and passing an address to an empty string. If I had to guess, I'd say that your code is passing a null address.
No worries, I fixed it.
For all future generations reading this: don't be stupid like me and instead of PrintStringFunction use PrintCharacterFunction and everything should be just fine. ;)
Thats what I told you before didnt I? :D
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: IRQ Firing Bug

Post by Octacone »

omarrx024 wrote:
thehardcoreOS wrote:It is sad that I still don't have any kind of memory management. Paging is my next big thing on the list.
Also I already know that: string paging; paging = "hell". :oops: :D
Paging is actually very easy; but beginners to it seem to think it's difficult and I thought so myself. :P
ROFL, paging is easy. We shall see. :D :P
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: IRQ Firing Bug

Post by Octacone »

Ch4ozz wrote:
thehardcoreOS wrote:
SpyderTL wrote:There is a difference between passing a null address and passing an address to an empty string. If I had to guess, I'd say that your code is passing a null address.
No worries, I fixed it.
For all future generations reading this: don't be stupid like me and instead of PrintStringFunction use PrintCharacterFunction and everything should be just fine. ;)
Thats what I told you before didnt I? :D
Hmm... Did you? :D Lol, I forgot. oops :oops:
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: IRQ Firing Bug

Post by Octacone »

SpyderTL wrote:
thehardcoreOS wrote:Hmm, about that slave master EOI sending etc, I already have that function inside my IRQ_Handler that does the same exact thing, to just copy paste it inside my Keyboard_Handler and Timer_Handler? :?

What do you mean by it prints 16bit interrupt table? I don't think so, because it prints only what I tell it to print. Little bit confused in there. :?: :?: :?: Drawing from RAM??? I don't have any kind of memory management set up and I don't interact with RAM as fair as I know, or maybe I do? :?:
What I meant to say is that whenever I see that pattern on the screen, with three horizontal lines and an S, it looks like what you would see if you copied the bytes starting at RAM address zero to the screen.

RAM address 0000:0000 is where the interrupt handler table is located when the machine first boots. My guess is that you are (accidentally) passing the wrong address to your print string function, and from the looks of the screen, I'm guessing that your print string function is attempting to draw whatever string is sitting at memory address zero.

Maybe that is a hint to help you track down the actual problem, but I could be wrong.
Hmm, about that slave master EOI sending etc, I already have that function inside my IRQ_Handler that does the same exact thing, to just copy paste it inside my Keyboard_Handler and Timer_Handler?
No, you only have to send the EOI once per interrupt (for each PIC, of course). Your original code looks like you were sending it twice per interrupt. I'm assuming that's fixed now.
Now, I get it. Thanks for explaining. I send EOI only once per interrupts as supposed to, everything works just okay. ;)
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
ajxs
Member
Member
Posts: 27
Joined: Mon Jun 13, 2016 2:25 am
Libera.chat IRC: ajxs
Location: Sydney

Re: IRQ Firing Bug

Post by ajxs »

omarrx024 wrote:

Code: Select all

void ps2_wait_write()
{
	while(inb(0x64) & 2 == 0);
}

void ps2_wait_read()
{
	while(inb(0x64) & 1 == 0);
}
Are you positive this works as intended?
Shouldn't this be:

Code: Select all

void ps2_wait_write()
{
	while((inb(0x64) & 2) != 0);
}

void ps2_wait_read()
{
	while((inb(0x64) & 1) != 0);
}
You'll need to add the extra set of (...) brackets, since ==/!= operators have a higher precedence than bitwise operators, so the condition for the while loop in your wait functions won't ever be satisfied. ( depending on how your compiler interprets this. gcc actually generates a warning from your code with -Wall )
Post Reply