diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2017-06-03 17:15:56 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2017-06-03 17:15:56 +0200 |
commit | 4a8b8b5a9efb260448eb4cbb37eaeba7bcf82dac (patch) | |
tree | b843613677c216ddea095a8e0096d5b17f4dd781 | |
parent | cbe68cd045bf3db770c89d8fe022d71563790966 (diff) | |
download | abaos-4a8b8b5a9efb260448eb4cbb37eaeba7bcf82dac.tar.gz abaos-4a8b8b5a9efb260448eb4cbb37eaeba7bcf82dac.tar.bz2 |
added mouse driver
changed acknoledgment of interrupts, if we acknowledge an interrupt
originating from the slave PIC we also have to acknoledge the master PIC
-rw-r--r-- | src/Makefile | 7 | ||||
-rw-r--r-- | src/interrupts.asm | 1 | ||||
-rw-r--r-- | src/interrupts.c | 11 | ||||
-rw-r--r-- | src/interrupts.h | 1 | ||||
-rw-r--r-- | src/kernel.c | 8 | ||||
-rw-r--r-- | src/keyboard.c | 13 | ||||
-rw-r--r-- | src/mouse.h | 22 |
7 files changed, 51 insertions, 12 deletions
diff --git a/src/Makefile b/src/Makefile index 3b21ab3..d0e9d68 100644 --- a/src/Makefile +++ b/src/Makefile @@ -28,11 +28,11 @@ kernel.bin: kernel.elf kernel.sym: kernel.elf $(OBJCOPY) --only-keep-debug kernel.elf kernel.sym -kernel.elf: kernel.o kernel_asm.o console.o vga.o serial.o port.o port_asm.o interrupts.o interrupts_asm.o keyboard.o string.o stdlib.o stdio.o setjmp.o +kernel.elf: kernel.o kernel_asm.o console.o vga.o serial.o port.o port_asm.o interrupts.o interrupts_asm.o keyboard.o mouse.o string.o stdlib.o stdio.o setjmp.o $(LD) -o kernel.elf -N -n -Ttext 0x8400 --oformat elf32-i386 \ kernel.o kernel_asm.o console.o vga.o serial.o \ port.o port_asm.o interrupts.o interrupts_asm.o \ - keyboard.o \ + keyboard.o mouse.o \ string.o stdlib.o stdio.o setjmp.o magic.bin: magic.asm @@ -68,6 +68,9 @@ interrupts_asm.o: interrupts.asm keyboard.o: keyboard.c keyboard.h $(CC) $(CFLAGS) -c -o keyboard.o keyboard.c +mouse.o: mouse.c mouse.h + $(CC) $(CFLAGS) -c -o mouse.o mouse.c + string.o: string.c string.h $(CC) $(CFLAGS) -c -o string.o string.c diff --git a/src/interrupts.asm b/src/interrupts.asm index e0b0707..155b2af 100644 --- a/src/interrupts.asm +++ b/src/interrupts.asm @@ -58,6 +58,7 @@ interrupts_handle_irq_%1: irq_stub 0x00 irq_stub 0x01 +irq_stub 0x0C int_entry: ; safe state of interrupted code diff --git a/src/interrupts.c b/src/interrupts.c index a1e7ace..614dbf0 100644 --- a/src/interrupts.c +++ b/src/interrupts.c @@ -104,9 +104,13 @@ void interrupts_init( interrupt_t *interrupt ) &interrupts_handle_irq_0x00, KERNEL_RING, IDT_TYPE_INTERRUPT_GATE ); interrupts_register_interrupt_handler( pit_interrupt_handler ); - // IRQ 1 - keyboard + // IRQ 1 - PS/2 keyboard interrupts_register_interrupt_gate( interrupt, IRQ_BASE + 0x01, GDT_CODE_SEGMENT_SELECTOR, &interrupts_handle_irq_0x01, KERNEL_RING, IDT_TYPE_INTERRUPT_GATE ); + + // IRQ 12 - PS/2 mouse + interrupts_register_interrupt_gate( interrupt, IRQ_BASE + 0x0C, GDT_CODE_SEGMENT_SELECTOR, + &interrupts_handle_irq_0x0C, KERNEL_RING, IDT_TYPE_INTERRUPT_GATE ); port8_init( &interrupt->PIC_master_control, 0x20 ); port8_init( &interrupt->PIC_master_data, 0x21 ); @@ -201,9 +205,8 @@ uint32_t interrupts_handle_interrupt( interrupt_t *interrupt, uint8_t interrupt_ // send ACK to PIC for hardware interrups if( interrupt_no >= IRQ_BASE && interrupt_no <= IRQ_BASE + 16 ) { - if( interrupt_no < IRQ_BASE + 8 ) { - port8_write( &interrupt->PIC_master_control, OCW2_EOI ); - } else { + port8_write( &interrupt->PIC_master_control, OCW2_EOI ); + if( interrupt_no >= IRQ_BASE + 8 ) { port8_write( &interrupt->PIC_slave_control, OCW2_EOI ); } } diff --git a/src/interrupts.h b/src/interrupts.h index 4e4dd2d..8ab485e 100644 --- a/src/interrupts.h +++ b/src/interrupts.h @@ -96,6 +96,7 @@ void interrupts_ignore_request( ); void interrupts_handle_exception_0x00( ); void interrupts_handle_irq_0x00( ); void interrupts_handle_irq_0x01( ); +void interrupts_handle_irq_0x0C( ); // later: tasks and stacks, queues diff --git a/src/kernel.c b/src/kernel.c index fc6f262..9ee9ede 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -8,6 +8,7 @@ #include "stdio.h" #include "interrupts.h" #include "keyboard.h" +#include "mouse.h" #include "setjmp.h" #include "kernel.h" @@ -45,6 +46,13 @@ void entry( void ) interrupt_handler_init( &keyboard_interrupt_handler, IRQ_BASE + 0x01, &interrupt, keyboard_handle_interrupt, &keyboard ); interrupts_register_interrupt_handler( keyboard_interrupt_handler ); + puts( "Initializing PS/2 mouse" ); + mouse_t mouse; + mouse_init( &mouse ); + interrupt_handler_t mouse_interrupt_handler; + interrupt_handler_init( &mouse_interrupt_handler, IRQ_BASE + 0x0C, &interrupt, mouse_handle_interrupt, &mouse ); + interrupts_register_interrupt_handler( mouse_interrupt_handler ); + // exit point in case of kernel panic, do this as soon as // possible if( setjmp( panic_jmp_buf ) > 0 ) { diff --git a/src/keyboard.c b/src/keyboard.c index ba2835d..a2314da 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -14,14 +14,15 @@ #define COMMAND_DISABLE_PORT1 0xAD #define COMMAND_ENABLE_PORT1 0xAE +// status control register flags +#define STATUS_CONTROL_CONFIG_ENABLE_IRQ_PORT1 0x01 +#define STATUS_CONTROL_CONFIG_CLOCK_PORT1 0x10 + // keyboard specific commands, PSAUX1 #define KBD_COMMAND_SET_LEDS 0xED #define KBD_SET_SCANCODE 0xF0 #define KBD_ACTIVATE 0xF4 -#define STATUS_CONTROL_CONFIG_ENABLE_IRQ_PORT1 0x01 -#define STATUS_CONTROL_CONFIG_CLOCK_PORT1 0x10 - // keyboard LED status codes #define KBD_LED_SCROLL_LOCK_ON 0x01 #define KBD_LED_NUM_LOCK_ON 0x02 @@ -69,9 +70,6 @@ void keyboard_init( keyboard_t *keyboard ) port8_read( &keyboard->data_port ); } - // enable port 1 - send_command( keyboard, COMMAND_ENABLE_PORT1 ); - // enable interrupts for port 1 send_command( keyboard, COMMAND_GET_STATE ); uint8_t status = read_data( keyboard ); @@ -90,6 +88,9 @@ void keyboard_init( keyboard_t *keyboard ) // activate keyboard //~ send_command( keyboard, KBD_ACTIVATE ); + + // enable port 1 + send_command( keyboard, COMMAND_ENABLE_PORT1 ); } typedef enum { diff --git a/src/mouse.h b/src/mouse.h new file mode 100644 index 0000000..d85e2fe --- /dev/null +++ b/src/mouse.h @@ -0,0 +1,22 @@ +#ifndef MOUSE_H +#define MOUSE_H + +#include "string.h" + +#include "interrupts.h" +#include "port.h" + +typedef struct { + interrupt_t *interrupts; + port8_t command_port; + port8_t data_port; + uint8_t buf[3]; + uint8_t offset; + uint8_t buttons; +} mouse_t; + +void mouse_init( mouse_t *mouse ); + +uint32_t mouse_handle_interrupt( interrupt_handler_t *handler, uint32_t esp ); + +#endif // MOUSE_H |