Page 1 of 2

How can i remap IRQ1? [SOLVED: Stop replying.]

Posted: Mon Dec 19, 2016 1:06 pm
by NunoLava1998
For my keyboard handler, i need to remap IRQ1. However, i find barely any code on this, and the code that is provided doesn't work.
I tried doing the following:

Code: Select all

void PIC_remap(void) {
	asm(".intel_syntax noprefix");
	asm("mov al, 0x11");
	asm("out 0x20, al");
	asm("out 0xA0, al");
	asm("mov al, 0x20");
	asm("out 0x21, al");
	asm("mov al, 0x28");
	asm("out 0xA1, al");
	asm("mov al, 0x04");
	asm("out 0x21, al");
	asm("mov al, 0x02");
	asm("out 0xA1, al");
	asm("mov al, 0x01");
	asm("out 0x21, al");
	asm("out 0xA1, al");
}
However, this gives out this during my build.bat (i'm in windows so instead of using a makefile i will use a batch file):

Code: Select all

C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s: Assembler messages:
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:330: Error: no such instruction: `subl $4,%esp'
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:334: Error: operand size mismatch for `in'
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:337: Error: operand type mismatch for `movzbl'
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:338: Error: junk `(%eax)' after expression
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:339: Error: no such instruction: `movl %eax,(%esp)'
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:341: Error: no such instruction: `addl $4,%esp'
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:355: Error: operand size mismatch for `in'
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:363: Error: no such instruction: `subl $4,%esp'
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:367: Error: operand size mismatch for `in'
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:370: Error: operand type mismatch for `movzbl'
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:371: Error: junk `(%eax)' after expression
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:372: Error: no such instruction: `movl %eax,(%esp)'
C:\Users\Nuno\AppData\Local\Temp\ccyCmahd.s:374: Error: no such instruction: `addl $4,%esp'
i686-elf-gcc: error: kernel.o: No such file or directory
How do i successfully remap IRQ1? (I only need IRQ1, as i don't find a use for IRQ2 and what i need relies on IRQ1 anyway).

My keyboard handler is complete, it only needs a working IRQ remapper. And yes, i did write most of the additional code that was needed in order for it to stop spamming 7's ("7 "'s if nulls are not ignored in putchar) when the mouse was moved and filled the screen with whatever character was pressed.

Re: How can i remap IRQ1?

Posted: Mon Dec 19, 2016 1:35 pm
by Octocontrabass
The example code is only an example, not something you can copy and paste. You must understand what it does, and translate it into a format usable in your OS - in your case specifically, you would rewrite it in C using outb().

By the way, every single one of your asm() statements is wrong. Writing correct inline assembly for GCC is extremely difficult and should be avoided whenever possible.

Re: How can i remap IRQ1?

Posted: Mon Dec 19, 2016 2:14 pm
by NunoLava1998
Octocontrabass wrote:The example code is only an example, not something you can copy and paste. You must understand what it does, and translate it into a format usable in your OS - in your case specifically, you would rewrite it in C using outb().

By the way, every single one of your asm() statements is wrong. Writing correct inline assembly for GCC is extremely difficult and should be avoided whenever possible.
I am not trying to point out that. I am trying to find a alternative way, nothing else. I need this for my keyboard controller to work properly (so it doesn't do weird things, for some reason it writes 7's and a null at a random position every time the mouse moves a bit.).

Re: How can i remap IRQ1?

Posted: Mon Dec 19, 2016 2:42 pm
by sleephacker
NunoLava1998 wrote:for some reason it writes 7's and a null at a random position every time the mouse moves a bit
Do you happen to have a (emulated) PS/2 mouse?

Re: How can i remap IRQ1?

Posted: Mon Dec 19, 2016 3:00 pm
by Octocontrabass
NunoLava1998 wrote:I am trying to find a alternative way, nothing else.
Do you understand what the example code does?
NunoLava1998 wrote:I need this for my keyboard controller to work properly (so it doesn't do weird things, for some reason it writes 7's and a null at a random position every time the mouse moves a bit.).
The PS/2 controller does more than just provide keyboard input. You'll need to initialize it to get it to behave in a predictable way, although you might be able to just disable the mouse port until you're ready to completely initialize it.

Re: How can i remap IRQ1?

Posted: Mon Dec 19, 2016 3:01 pm
by NunoLava1998
sleephacker wrote:
NunoLava1998 wrote:for some reason it writes 7's and a null at a random position every time the mouse moves a bit
Do you happen to have a (emulated) PS/2 mouse?
I was running this on QEMU, and my mouse is PS/2.

If putchar ignores nulls, it's only "7".
If it doesn't, it's "7" plus a null character (0x00).

Re: How can i remap IRQ1?

Posted: Tue Dec 20, 2016 1:24 am
by NunoLava1998
I think i remapped, however it seems to be ignoring that the only way to get into the keyboard handler is an IRQ 1, however it's of course ignoring that.

EDIT:
Horray! Done! The only thing i need to fix is to somehow make my emulator NOT restart when i press a key. I still get 7's, but i can fix that later.

Re: How can i remap IRQ1?

Posted: Tue Dec 20, 2016 1:37 am
by iansjack
"I think...."

"It seems...."

You really ought to try to work with facts rather than conjectures. What makes you believe either of these statements? Rest assured that your computer isn't capable of independent thoughts; it only does what you tell it to, and only ignores what you tell it to ignore.

It would be useful if you gave a more coherent account of what you have done and what the result is.

Re: How can i remap IRQ1?

Posted: Tue Dec 20, 2016 6:14 am
by bauen1
(you shouldn't copy past and shouldn't put .c files in a directory called include but i'm gonna answer this anyway)
When you add a

Code: Select all

asm(".intel_syntax noprefix");
gcc switches the syntax used in asm statements to intel syntax without prefix, however you don't change the syntax back to the normal one used so gas will error because the next asm seems like "garbage" under the current settings => you need to switch the syntax back to what it was

(google how to do this its not hard and maybe you will learn something in the process)

Re: How can i remap IRQ1?

Posted: Tue Dec 20, 2016 6:26 am
by NunoLava1998
bauen1 wrote:(you shouldn't copy past and shouldn't put .c files in a directory called include but i'm gonna answer this anyway)
When you add a

Code: Select all

asm(".intel_syntax noprefix");
gcc switches the syntax used in asm statements to intel syntax without prefix, however you don't change the syntax back to the normal one used so gas will error because the next asm seems like "garbage" under the current settings => you need to switch the syntax back to what it was

(google how to do this its not hard and maybe you will learn something in the process)

I already fixed the issue, i simply had to use the OSDev original with some definitions.
Worked perfectly.
I just need to find out how to do some more stuff for IRQ1 to not triple-fault (as i somehow was intelligent enough to not load the IDT)

Re: How can i remap IRQ1?

Posted: Tue Dec 20, 2016 7:00 am
by iansjack
I'm glad to hear that you have solved your problem (though some nit-pickers might say that triple-faulting when a key is pressed falls a little short of "working perfectly").

Re: How can i remap IRQ1?

Posted: Tue Dec 20, 2016 7:32 am
by NunoLava1998
iansjack wrote:I'm glad to hear that you have solved your problem (though some nit-pickers might say that triple-faulting when a key is pressed falls a little short of "working perfectly").
Yep. However, triple faulting is actually fault of IRQ1's, but they're actually doing fine, it's the fact i didn't load the IDT. Which has no code that i know, only prerequisite code.
Again, i'm absolutely not into interrupt stuff. I know how they work, but loading interrupts? Uh.. absolutely not.

Re: How can i remap IRQ1?

Posted: Tue Dec 20, 2016 8:52 am
by iansjack
Oh dear! :(

Re: How can i remap IRQ1?

Posted: Tue Dec 20, 2016 10:22 am
by sleephacker
NunoLava1998 wrote:loading interrupts? Uh.. absolutely not.
You do realise that x86 is an interrupt driven architecture?

Re: How can i remap IRQ1?

Posted: Tue Dec 20, 2016 10:44 am
by NunoLava1998
sleephacker wrote:
NunoLava1998 wrote:loading interrupts? Uh.. absolutely not.
You do realise that x86 is an interrupt driven architecture?
Yes.
By "loading interrupts" i meant:

"the base size is 32 and will fit in a float, as the base = 16 and size = base*2 (32), also put the segment into bit 37 and 110101 for 32bit in bit 45..51, then do lidt pointing to the se-"
stuff like that.