Page 1 of 1

unable to change scancode set. pls help

Posted: Thu Sep 20, 2012 8:20 am
by hegde1997
I don't know what is wrong but i am unable to change the scan code set and when i read in to see which scan code is set, i got value 25
pls help.

Code: Select all

#define _KbdCommand 0x64
#define _KbdRW 0x60
#define _KbdLed_cmd 0xED
#define _KbdSc_code_cmd 0xF0
#define _KbdAck 0xFA
#define _KbdResend 0xFE
#define _CapsL_val 4
#define _NumL_val 2
#define _ScrlL_val 1

void init_keyboard()
{
	led_status=0;
	kbd_on=true;
	
	outbyte(' ');
	
	kbdstatus_init();
	set_irq_handler(1,irq1_keyb);
	
	kbd_scancode_set(scancode_set);
	kbd_write(0xf0,_KbdRW);
	outb(0,_KbdRW);
	outbyte(kbd_read(_KbdRW));	
}

Code: Select all

void kbd_io_wait()
{
	uint8 a; 
	do
	{
		a=inb(_KbdCommand);
	}while(a&2);
	
}
char kbd_write(uint8 bytes, uint16 port)
{
	kbd_io_wait();
	outb(port,bytes);
	if(inb(port)==_KbdAck)
	  return 1;
	else if(inb(port)==_KbdResend) //{// try maximum 3 more times
	  return kbd_cmd_resend(port,port,bytes);
	  
	return 0;
}
uint8 kbd_read(uint16 port)
{
	while(!(inb(_KbdCommand)&1)) ;//wait till output buffer is full
	 return inb(port);
}

char kbd_cmd_resend(uint16 inport,uint16 outport,uint8 data)
{
	kbd_io_wait();
	outb(outport,data);// make maximum of 3 tries
	if(inb(inport)==_KbdAck)
	  return 1;
	else if(inb(inport)==_KbdResend)
	 {
		 kbd_io_wait();
		 outb(outport,data);
	 }
	if(inb(inport)==_KbdAck)
	  return 1;
	else if(inb(inport)==_KbdResend)
	 {
		 kbd_io_wait();
		 outb(outport,data);
	 }	
	if(inb(inport)==_KbdAck)
	  return 1;
	return 0;	
}

Re: unable to change scancode set. pls help

Posted: Thu Sep 20, 2012 8:53 am
by Brendan
Hi,

Normally, the keyboard uses scancode set 2, and the PS/2 controller converts this into scancode set 1. For example; if you press F5 the keyboard sends the make code 0x03 to the PS/2 controller, and the PS/2 controller converts this into 0x3F, and software (e.g. an OS) would read the value 0x3F from the PS/2 controller.

This translation happens for all data sent from the keyboard to the computer (not just make and break codes). For example, if you ask the keyboard which scancode set it's using and it sends 0x02 back, then the PS/2 controller would convert this into 0x41 (as far as I can tell), and software (e.g. an OS) would read the value 0x41 from the PS/2 controller. Of course different values from the keyboard can be translated into the same value. For example, if your software receives the value 0x41 from the PS/2 controller then the keyboard itself may have sent 0x02 or 0x83, and there's no way to tell what was originally sent.

Your "PS/2 controller driver" should probably disable this translation as part of its initialisation (e.g. before your "PS/2 keyboard driver" is started). To do this you want to read the "PS/2 Controller Configuration Byte", then clear bit 6 and write the result back.

Also note that a lot of keyboards only support scancode set 2, and a lot of keyboards don't support the "get current scan code set" command.


Cheers,

Brendan

Re: unable to change scancode set. pls help

Posted: Thu Sep 20, 2012 9:02 am
by hegde1997
thanks a lot. One more wierd thing is that in qemu i get 156 and in vmware 25 so now i will deal with that disabling the translation and get back.

thank you