Page 2 of 3
Re: not unique keyboard scancodes
Posted: Sun Nov 18, 2012 6:34 am
by zgintasz
egos wrote:Do you use Multiboot header in your executable module? If so, check for its location within the first 8 Kbytes.
I think so, here is the code:
build.sh(compiling using cygwin):
Code: Select all
#!/bin/sh
build=temp_build
compiler=i586-elf-gcc
linker=i586-elf-ld
opt="-Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I./kernel/include -c -fno-strict-aliasing -fno-common -fno-stack-protector"
echo "Building..."
echo "============================================="
echo "--Building C files..."
$compiler $opt -o $build/main.o ./kernel/main.c
$compiler $opt -o $build/console.o ./kernel/drivers/console.c
$compiler $opt -o $build/gdt.o ./kernel/gdt.c
$compiler $opt -o $build/idt.o ./kernel/idt.c
$compiler $opt -o $build/isrs.o ./kernel/isrs.c
$compiler $opt -o $build/irq.o ./kernel/irq.c
$compiler $opt -o $build/timer.o ./kernel/timer.c
$compiler $opt -o $build/keyboard.o ./kernel/drivers/keyboard.c
echo "--Building ASM files..."
nasm -f elf ./kernel/loader.asm -o $build/loader.o
echo "--Linking files..."
$linker -T linker.ld $build/*.o
echo "--Cleaning up temporary files..."
rm $build/*.o
echo "--Putting on floppy image..."
mount A: /mnt/floppy
cp kernel.bin /mnt/floppy/
echo "============================================="
echo "Build completed!"
linker.ld:
Code: Select all
ENTRY (loader)
OUTPUT ("kernel.bin")
addr = 0x100000;
SECTIONS
{
.text addr :
ALIGN(0x1000)
{
*(.text*);
*(.rodata*);
}
.data :
ALIGN(0x1000)
{
*(.data*);
}
.bss :
ALIGN(0x1000)
{
*(.bss*);
}
}
loader.asm:
Code: Select all
bits 32
global loader
global magic
extern kmain
; Multiboot header
MODULEALIGN equ 1<<0
MEMINFO equ 1<<1
FLAGS equ MODULEALIGN | MEMINFO
MAGIC equ 0x1BADB002
CHECKSUM equ -(MAGIC + FLAGS)
MultibootHeader:
dd MAGIC
dd FLAGS
dd CHECKSUM
STACKSIZE equ 0x4000 ; 16KB
loader:
cmp eax, 0x2BADB002 ; verify booted with grub
jne .bad
mov esp, STACKSIZE + stack
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
push ebx
call kmain
;cli ; clear interrupts
;mov eax, cr0 ; set bit 0 in cr0--enter pmode
;or eax, 1
;mov cr0, eax
;cli
;hlt
.bad:
cli
hlt
align 4
stack:
TIMES STACKSIZE db 0
...
main.c(there is "void* MultibootHeader", but I don't use it anywhere, I can change it to anything):
Code: Select all
...
void kmain(void* MultibootHeader)
{
...
for(;;);
}
How can I fix it(I don't understand your solution)? I'm really newbie in os development, I don't know very much, but I really want to create my own OS(I've got some free time, I'm ready to learn. The only thing I learnt fully is making console driver -.-).
Re: not unique keyboard scancodes
Posted: Mon Nov 19, 2012 6:31 am
by Combuster
Which section in your linker script holds the multiboot header?
Re: not unique keyboard scancodes
Posted: Mon Nov 19, 2012 12:45 pm
by zgintasz
I fixed the problem with that grub message, thanks
.
Now I'm back in keyboard... I worked for it all day, can't find the solution. If I set keyboard scancode or don't set it, scancodes are the same. Just to test function:
Code: Select all
void KeyboardWaitOutport()
{
int fail_safe=200000;
while ((inportb(0x64)&2)!=0 && fail_safe>0) fail_safe--;
}
void KeyboardSetScancodeSet(uint8 set)
{
if (set>3 || set <= 0) return;
KeyboardWaitOutport();
outportb (0x60, 0xf0);
KeyboardWaitOutport();
outportb (0x60, set);
}
this is how I print scancode(no if sentences):
I'm sure it's look like very easy for experts, but for I think newbie it's not
.
Re: not unique keyboard scancodes
Posted: Mon Nov 19, 2012 12:55 pm
by egos
Disable translation.
Re: not unique keyboard scancodes
Posted: Mon Nov 19, 2012 1:15 pm
by SparrowOS
Your time-out delay is hoeky, but works for reasons you probably don't understand. IN/OUT instructions move at ISA bus speed which is roughly 1uS.
This has my keyboard routine. It only supports US ENGLISH keyboards. I don't care.
http://www.sparrowos.com/Wb/OSMain/KbdM ... board.html
This has the rest of my code on-line(in case you want to see mouse):
http://www.sparrowos.com/Wb/Accts/TS/Wb ... .html#l700
This has my ASU transcripts (someone else was wondering):
http://www.sparrowos.com/files/ASU_Transcripts.pdf
Re: not unique keyboard scancodes
Posted: Wed Nov 21, 2012 7:33 am
by zgintasz
egos wrote:Disable translation.
How to disable it? I need to somehow set byte 6 to 0 by writing to 0x20 or 0x60, right? How(code please)?
EDIT:
is it correct?
Code: Select all
KeyboardWaitOutport();
outportb (0x60, 6);
KeyboardWaitOutport();
outportb (0x60, 0);
because scancodes are still the same as without it
.
Re: not unique keyboard scancodes
Posted: Thu Nov 22, 2012 11:45 pm
by egos
zgintasz wrote:is it correct?
No, of course. Try something like this:
Code: Select all
KeyboardWaitOutport();
outportb (0x64, 0x60);
KeyboardWaitOutport();
outportb (0x60, CONTROLLER_COMMAND_BYTE);
If you are not sure what value should be in every bit, read the "Controller Command byte" first (use controller command 20h for that).
Re: not unique keyboard scancodes
Posted: Fri Nov 23, 2012 12:11 am
by Brendan
Hi,
From
this part of the wiki:
"
Note: Bits listed in the table above as "unknown" should be treated as either "chipset specific" or "unknown". Bits that are marked as "only if 2 PS/2 ports supported" should also be treated as either "chipset specific" or "unknown" if the controller only supports one PS/2 port."
What this means is that you should read the old value, then clear bit 6, then write the new value. For example:
Code: Select all
KeyboardWaitOutport();
outportb (0x64, 0x20); // Send "read configuration byte" command
KeyboardWaitInport();
foo = inportb(0x60); // foo = old value of configuration byte
foo = foo & ~(1 << 6); // foo = old value with translation disabled
KeyboardWaitOutport();
outportb (0x64, 0x60); // Send "write configuration byte" command
KeyboardWaitOutport();
outportb (0x60, foo); // Set configuration byte to disable translation
Cheers,
Brendan
Re: not unique keyboard scancodes
Posted: Fri Nov 23, 2012 1:18 am
by Antti
I disable the keyboard translation similar way. However, I have added some "extra" delay. When I write the configuration byte, I do not immediately read the status register. There is a small nop loop between the port I/Os. Same applies to other similar cases.
Brendan, is this totally pointless (or even harmful)? I know that this is not based on facts (that I know of) but I feel comfortable to be dilatory when doing port I/Os.
Re: not unique keyboard scancodes
Posted: Fri Nov 23, 2012 1:50 am
by Brendan
Hi,
Antti wrote:I disable the keyboard translation similar way. However, I have added some "extra" delay. When I write the configuration byte, I do not immediately read the status register. There is a small nop loop between the port I/Os. Same applies to other similar cases.
Brendan, is this totally pointless (or even harmful)? I know that this is not based on facts (that I know of) but I feel comfortable to be dilatory when doing port I/Os.
First; if a delay was necessary, then NOPs (which may be simply "skipped" by the CPU without causing any delay at all) wouldn't be adequate. However; I doubt that any delay is necessary, as long as you're waiting for the relevant bits in the status register correctly. Small delays (e.g. less than 1 millisecond) should be harmless though.
A much larger problem is attempting to do this while a device (e.g. the keyboard and/or mouse) is still active; because there's no way to avoid race conditions. For example, you might send the "read configuration byte" command and the user might press a key at exactly the wrong time, and when you think you're reading the configuration byte you're actually reading the keyboard's scan code. To avoid this problem (and others like it), I'd recommend complete PS/2 controller initialisation (e.g. like
this) where the device/s are disabled (step 3) before you do much of anything (e.g. step 5).
Cheers,
Brendan
Re: not unique keyboard scancodes
Posted: Fri Nov 23, 2012 1:00 pm
by zgintasz
Strange, still doesn't work: (by the way, using Virtual Box)
Code: Select all
void keyboard_install()
{
irq_install_handler(1, keyboard_handler);
KeyboardWaitOutport();
outportb(0x60, KeybCmdReset); // Reset kb
KeyboardScancodeSet(2);
KeyboardWaitOutport();
outportb (0x64, 0x20); // Send "read configuration byte" command
KeyboardWaitInport();
foo = inportb(0x60); // foo = old value of configuration byte
foo = foo & ~(1 << 6); // foo = old value with translation disabled
KeyboardWaitOutport();
outportb (0x64, 0x60); // Send "write configuration byte" command
KeyboardWaitOutport();
outportb (0x60, foo); // Set configuration byte to disable translation
}
Re: not unique keyboard scancodes
Posted: Fri Nov 23, 2012 8:47 pm
by Brendan
Hi,
zgintasz wrote:Strange, still doesn't work: (by the way, using Virtual Box)
Does it make no difference at all, or crash, or lock up, or make your cat explode?
Does the old "configuration byte" you read look sane?
Did you try it on any other emulators and/or computers?
Cheers,
Brendan
Re: not unique keyboard scancodes
Posted: Sun Nov 25, 2012 9:29 am
by zgintasz
Neverming, it was very very very stupid mistake, sorry.
Scancode set and translation are working fine. The only thing left to do is to get the correct scancode. Example(it's a single press scancodes), numpad 7 scancodes: 108 240 108(I get 240 and 108 when I release button), home key scancodes: 224 108 224 240 108(I get 224, 240 and 108 when I release button). Please give me a code for getting the unique scancode.
Thanks, have a nice day
.
Re: not unique keyboard scancodes
Posted: Sun Nov 25, 2012 10:30 am
by egos
Heh, what you want that you get
Set #2 is better but it requires a special handling.
Re: not unique keyboard scancodes
Posted: Sun Nov 25, 2012 10:36 am
by zgintasz
egos wrote:Heh, what you want that you get
single scancode, not many scancodes on key press. For example if I press home key, I get these scancodes: 224 108 224 240 108(224, 108 and 224 when key is pressed, 240 and 108 when key is released). So how to make if sentence to get
unique and
single(single = 1, many = more than 1) scancode, so I can write keyboard ascii map - I can't write it now, because I get not single scancode on key press. Hope you understood.