Hallo
Also, das ist mein erster Post.
Bitte nicht sauer sein wenn es nicht ganz passt, aber jetzt zu meinem problem:
Wenn ich in meinem OS (wenn man das so nennen darf) eine taste
z.b das "S" Drücke, dann erscheint auf dem bildschirm ein großes S.
Das Problem ist jetzt aber dass Immer ein S erscheint, egal welche Taste ich drücke.
Keyboard.c
#include "keyboard.h"
#include "externs.h"
#include "util.h"
int ShiftKeyDown;
void keyboard_init()
{
while (inportb(0x64)&1)
inportb(0x60);
};
unsigned int FetchAndAnalyzeScancode()
{
unsigned int scancode;
while(TRUE)
{
scancode = inportb(0x60);
if ( scancode & 0x80 )
{
scancode &= 0x7F;
if ( scancode != KRLEFT_SHIFT || scancode == KRRIGHT_SHIFT )
{
ShiftKeyDown = 0;
}
}
else
{
if ( scancode == KRLEFT_SHIFT || scancode == KRRIGHT_SHIFT )
{
ShiftKeyDown = 1;
continue;
}
}
break;
}
return scancode;
}
unsigned char const k_getch()
{
unsigned int scan;
unsigned char retchar;
scan = FetchAndAnalyzeScancode();
if ( ShiftKeyDown )
retchar = asciiShift[ scan ];
else
retchar = asciiNonShift[ scan ];
return retchar;
}
void keyboard_handler()
{
//unsigned char bufferKEY[10];
//bufferKEY[0] = k_getch();
//k_printf(bufferKEY, 9,0x9);
k_printf(k_getch(), 9,0x9);
}
void keyboard_install()
{
keyboard_init();
irq_install_handler(1, keyboard_handler);
}
Keyboard.h
#ifndef KEYBOARD_H
#define KEYBOARD_H
#define NULL 0
#define ESC 27
#define BACKSPACE '\b'
#define TAB '\t'
#define ENTER '\n'
#define RETURN '\r'
#define NEWLINE ENTER
// Non-ASCII special scancodes // Esc in scancode is 1
#define KESC 1
#define KF1 0x80
#define KF2 (KF1 + 1)
#define KF3 (KF2 + 1)
#define KF4 (KF3 + 1)
#define KF5 (KF4 + 1)
#define KF6 (KF5 + 1)
#define KF7 (KF6 + 1)
#define KF8 (KF7 + 1)
#define KF9 (KF8 + 1)
#define KF10 (KF9 + 1)
#define KF11 (KF10 + 1)
#define KF12 (KF11 + 1)
// Cursor Keys
#define KINS 0x90
#define KDEL (KINS + 1)
#define KHOME (KDEL + 1)
#define KEND (KHOME + 1)
#define KPGUP (KEND + 1)
#define KPGDN (KPGUP + 1)
#define KLEFT (KPGDN + 1)
#define KUP (KLEFT + 1)
#define KDOWN (KUP + 1)
#define KRIGHT (KDOWN + 1)
// "Meta" keys
#define KMETA_ALT 0x0200 // Alt is pressed
#define KMETA_CTRL 0x0400 // Ctrl is pressed
#define KMETA_SHIFT 0x0800 // Shift is pressed
#define KMETA_ANY (KMETA_ALT | KMETA_CTRL | KMETA_SHIFT)
#define KMETA_CAPS 0x1000 // CapsLock is on
#define KMETA_NUM 0x2000 // NumLock is on
#define KMETA_SCRL 0x4000 // ScrollLock is on
// Other keys
#define KPRNT ( KRT + 1 )
#define KPAUSE ( KPRNT + 1 )
#define KLWIN ( KPAUSE + 1 )
#define KRWIN ( KLWIN + 1 )
#define KMENU ( KRWIN + 1 )
#define KRLEFT_CTRL 0x1D
#define KRRIGHT_CTRL 0x1D
#define KRLEFT_ALT 0x38
#define KRRIGHT_ALT 0x38
#define KRLEFT_SHIFT 0x2A
#define KRRIGHT_SHIFT 0x36
#define KRCAPS_LOCK 0x3A
#define KRSCROLL_LOCK 0x46
#define KRNUM_LOCK 0x45
#define KRDEL 0x53
#define MAXKEYBUFFER 64 // max keyboard buffer
// Keymaps: US International
// Non-Shifted scan codes to ASCII:
static unsigned char asciiNonShift[] = {
NULL, ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 's', '´', BACKSPACE,
TAB, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p','ü', '+', ENTER, 0,
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'ö', 'ä', '#', 0, '>',
'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '-', 0, 0, 0, ' ', 0,
KF1, KF2, KF3, KF4, KF5, KF6, KF7, KF8, KF9, KF10, 0, 0,
KHOME, KUP, KPGUP,'-', KLEFT, '5', KRIGHT, '+', KEND, KDOWN, KPGDN, KINS, KDEL, 0, 0, 0, KF11, KF12 };
// Shifted scan codes to ASCII:
static unsigned char asciiShift[] = {
NULL, ESC, '!', '"', '§', '$', '%', '&', '/', '(', ')', '=', '?', '´', BACKSPACE,
TAB, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', ENTER, 0,
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Ö', 'Ä', '\'', 0, '>',
'Y', 'X', 'C', 'V', 'B', 'N', 'M', ';', ':', '_', 0, 0, 0, ' ', 0,
KF1, KF2, KF3, KF4, KF5, KF6, KF7, KF8, KF9, KF10, 0, 0,
KHOME, KUP, KPGUP, '-', KLEFT, '5', KRIGHT, '+', KEND, KDOWN, KPGDN, KINS, KDEL, 0, 0, 0, KF11, KF12 };
#endif
externs.h
#ifndef EXTERNS_H_INCLUDED
#define EXTERNS_H_INCLUDED
#define TRUE 1
#define FALSE 0
/* This defines what the stack looks like after an ISR was running */
struct regs
{
unsigned int gs, fs, es, ds;
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
unsigned int int_no, err_code;
unsigned int eip, cs, eflags, useresp, ss;
};
extern void k_clear_screen();
extern unsigned int k_printf(char* message, unsigned int line, char attribute);
extern void update_cursor(int row, int col);
extern void keyboard_init();
extern unsigned char const k_getch();
extern unsigned int FetchAndAnalyzeScancode();
extern void keyboard_handler();
extern void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
extern void gdt_install();
extern void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags);
extern void idt_install();
extern void isrs_install();
extern void irq_install();
extern void keyboard_install();
extern void fault_handler(struct regs* r);
extern void irq_install_handler(int irq, void (*handler)(struct regs* r));
extern void irq_uninstall_handler(int irq);
extern void irq_handler(struct regs* r);
#endif // EXTERNS_H_INCLUDED
idt.c
#include "externs.h"
#include "util.h"
struct idt_entry
{
unsigned short base_lo;
unsigned short sel;
unsigned char always0;
unsigned char flags;
unsigned short base_hi;
}__attribute__((packed));
struct idt_ptr
{
unsigned short limit;
unsigned int base;
}__attribute__((packed));
struct idt_entry idt[256];
struct idt_ptr idt_register;
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags)
{
idt[num].base_lo = (base & 0xFFFF);
idt[num].base_hi = (base >> 16) & 0xFFFF;
idt[num].sel = sel;
idt[num].always0 = 0;
idt[num].flags = flags;
}
void idt_install()
{
// Hier legen wir die Base und das Limit der IDT fest
idt_register.limit = (sizeof (struct idt_entry) * 256)-1;
idt_register.base = (unsigned int) &idt;
k_memset(&idt, 0, sizeof(struct idt_entry) * 256); // Jetzt schmeißen wir den eintrag "IDT" raus
// man kann mit der Funktion idt_set_gate(...) neue ISRs Hinzufügen
asm volatile("lidt %0" : "=m" (idt_register));
}
irq.c
#include "externs.h"
#include "util.h"
extern inline void outportb(unsigned port, unsigned val);
extern void irq0(); extern void irq1(); extern void irq2(); extern void irq3();
extern void irq4(); extern void irq5(); extern void irq6(); extern void irq7();
extern void irq8(); extern void irq9(); extern void irq10(); extern void irq11();
extern void irq12(); extern void irq13(); extern void irq14(); extern void irq15();
void* irq_routines[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
void irq_install_handler(int irq, void (*handler)(struct regs* r)) {irq_routines[irq] = handler;}
void irq_uninstall_handler(int irq) {irq_routines[irq] = 0;}
void irq_remap()
{
outportb(0x20, 0x11); outportb(0xA0, 0x11);
outportb(0x21, 0x20);
outportb(0xA1, 0x28);
outportb(0x21, 0x04); outportb(0xA1, 0x02);
outportb(0x21, 0x01); outportb(0xA1, 0x01);
outportb(0x21, 0x00); outportb(0xA1, 0x00);
}
void irq_install()
{
irq_remap();
idt_set_gate(32, (unsigned) irq0, 0x08, 0x8E); idt_set_gate(33, (unsigned) irq1, 0x08, 0x8E);
idt_set_gate(34, (unsigned) irq2, 0x08, 0x8E); idt_set_gate(35, (unsigned) irq3, 0x08, 0x8E);
idt_set_gate(36, (unsigned) irq4, 0x08, 0x8E); idt_set_gate(37, (unsigned) irq5, 0x08, 0x8E);
idt_set_gate(38, (unsigned) irq6, 0x08, 0x8E); idt_set_gate(39, (unsigned) irq7, 0x08, 0x8E);
idt_set_gate(40, (unsigned) irq8, 0x08, 0x8E); idt_set_gate(41, (unsigned) irq9, 0x08, 0x8E);
idt_set_gate(42, (unsigned) irq10, 0x08, 0x8E); idt_set_gate(43, (unsigned) irq11, 0x08, 0x8E);
idt_set_gate(44, (unsigned) irq12, 0x08, 0x8E); idt_set_gate(45, (unsigned) irq13, 0x08, 0x8E);
idt_set_gate(46, (unsigned) irq14, 0x08, 0x8E); idt_set_gate(47, (unsigned) irq15, 0x08, 0x8E);
}
void irq_handler(struct regs* r)
{
void (*handler)(struct regs* r);
handler = irq_routines[r->int_no - 32];
if (handler) { handler(r); }
if (r->int_no >= 40) { outportb(0xA0, 0x20); }
outportb(0x20, 0x20);
}
Ach, außerdem kommt beim kompilieren immer die meldung:
C:\OS\nasm>gcc -Wall -O -c keyboard.c -o keyboard.o
keyboard.c: In function `keyboard_handler':
keyboard.c:61: warning: passing arg 1 of `k_printf' makes pointer from integer w
ithout a cast
EDIT:
Wie Benutzt man den "cast"- Operator