[SOLVED] Updating Keyboard LEDS & Reserved Exceptions

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.
Post Reply
User avatar
Js2xxx
Member
Member
Posts: 48
Joined: Sat Dec 31, 2016 1:43 am
Libera.chat IRC: wrgq
Location: China

[SOLVED] Updating Keyboard LEDS & Reserved Exceptions

Post by Js2xxx »

I'm updating keyboard leds while there's a Coprocessor Segment Overrun on VMware (and nothing on Bochs)...??? WTF???

My code:

Code: Select all

	// I'm sure these constants are correct.
	uint8_t leds = (__capsLock << 2) | (__numLock << 1) | __scrollLock;

	asm_OutByte(__8042Port::Data, __KCommand::Leds);

	while(asm_InByte(__8042Port::Data) != 0xFA);

	asm_OutByte(__8042Port::Data, leds);
Thanks for help.
Last edited by Js2xxx on Tue Jun 27, 2017 7:08 pm, edited 1 time in total.
Doing steadfastly, or doing nil.
LtG
Member
Member
Posts: 384
Joined: Thu Aug 13, 2015 4:57 pm

Re: Updating Keyboard LEDS & Reserved Exceptions

Post by LtG »

I don't understand the question, are you saying that when you get the exception you attempt to change the keyboard LEDs? If so, why?

Also, is there a reason you are using the double underscore (__)? That's reserved for the compiler...
User avatar
Sik
Member
Member
Posts: 251
Joined: Wed Aug 17, 2016 4:55 am

Re: Updating Keyboard LEDS & Reserved Exceptions

Post by Sik »

This was more confusing than I expected:
https://stackoverflow.com/questions/156 ... -exception

Before enabling interrupts in protected mode you need to make sure to tell the PIC to generate a different set of IRQs since the default ones overlap with some of the CPU exceptions. That Coprocessor Segment Overrun exception you're getting is actually an interrupt caused by the keyboard.

In other words: reprogram the PIC. The information is in the wiki, conveniently
http://wiki.osdev.org/PIC#Protected_Mode
User avatar
Js2xxx
Member
Member
Posts: 48
Joined: Sat Dec 31, 2016 1:43 am
Libera.chat IRC: wrgq
Location: China

Re: Updating Keyboard LEDS & Reserved Exceptions

Post by Js2xxx »

So do you mean that double dashes causes multiple meanings so the compiler generates wrong code? (if so, it's amazing!! And I'll use single.)

And now I think it have a relationship with IOPL. That code runs on CPL =3 and IOPL =0 so it can't use port operations directly. Am I right?
Doing steadfastly, or doing nil.
User avatar
Js2xxx
Member
Member
Posts: 48
Joined: Sat Dec 31, 2016 1:43 am
Libera.chat IRC: wrgq
Location: China

Re: Updating Keyboard LEDS & Reserved Exceptions

Post by Js2xxx »

Sik wrote:In other words: reprogram the PIC.
I'm programming I/O APIC. So should I initialize 8259 and disable all the irqs?
Doing steadfastly, or doing nil.
User avatar
Sik
Member
Member
Posts: 251
Joined: Wed Aug 17, 2016 4:55 am

Re: Updating Keyboard LEDS & Reserved Exceptions

Post by Sik »

Well, it does seem like the PIC is the one sending the interrupts, so yeah you may want to disable the PIC and let the APIC take over. Again, check the wiki =P
User avatar
Js2xxx
Member
Member
Posts: 48
Joined: Sat Dec 31, 2016 1:43 am
Libera.chat IRC: wrgq
Location: China

Re: Updating Keyboard LEDS & Reserved Exceptions

Post by Js2xxx »

Thanks a lot. It makes sense. :D
Doing steadfastly, or doing nil.
Post Reply