diff options
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/interrupts.c | 13 | ||||
| -rw-r--r-- | kernel/kernel.c | 16 | ||||
| -rw-r--r-- | kernel/mouse.c | 128 | ||||
| -rw-r--r-- | kernel/vesa.c | 27 | ||||
| -rw-r--r-- | kernel/x86.h | 2 |
5 files changed, 166 insertions, 20 deletions
diff --git a/kernel/interrupts.c b/kernel/interrupts.c index 308028f..f5bd18f 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -11,6 +11,7 @@ void int_clock_handler(); void int_kb_handler(); void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr); void int_default_handler(); +void mouse_handler(); // the interrupt descriptor table @@ -34,13 +35,6 @@ static struct idt_desc } idtd; -void int_mouse() -{ - - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"mouse interrupt"); - -} - void int_default() { @@ -148,9 +142,8 @@ void int_init(uint16_t sel) int_install_ir(38, 0b10001110, 0x08,&int_floppy_handler); #endif - //mouse - int_install_ir(44, 0b10001110, 0x08,&int_mouse); - + //mouse + int_install_ir(44, 0b10001110, 0x08,&mouse_handler); int_install(); diff --git a/kernel/kernel.c b/kernel/kernel.c index ae5036a..f8b6571 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -142,15 +142,13 @@ void kernel_main(uint32_t initial_stack, int mp) // init spinlocks init_spinlocks(); - // - //vesa_init_doublebuff(); // // Start the other Processors (also before paging !) // smp_log_procdata(&procdata); - smp_start_aps(&procdata,0x80000); // starts at 0x90000 +// smp_start_aps(&procdata,0x80000); // starts at 0x90000 // but it will be copied over mbr @@ -194,14 +192,22 @@ void kernel_main(uint32_t initial_stack, int mp) // For now this starts three "tasks" which are scheduled // round robin style. // - task_init(); + //task_init(); // // Just hang around here, if its reached. // we do our tasks anyway. on the next clock tick. // - while(1)asm("hlt"); + // + //vesa_init_doublebuff(); + while(1) + { + + // lock_spin(0); +// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"x: %d y:%d",mouse_get_x(), mouse_get_y()); + // lock_release(0); + } } diff --git a/kernel/mouse.c b/kernel/mouse.c index b6fd14d..de1e3bf 100644 --- a/kernel/mouse.c +++ b/kernel/mouse.c @@ -1,9 +1,135 @@ +//http://forum.osdev.org/viewtopic.php?t=10247 +//based on Mouse.inc by SANiK +//License: Use as you wish, except to cause damage + #define FOOLOS_MODULE_NAME "mouse" #include "lib/logger/log.h" +#include "lib/int/stdint.h" + +#include "x86.h" + + +static volatile uint8_t mouse_cycle; +static volatile int8_t mouse_byte[3]; +static volatile int8_t mouse_x; +static volatile int8_t mouse_y; + + +uint8_t mouse_read(); + +int8_t mouse_get_x() +{ + return mouse_x; +} +int8_t mouse_get_y() +{ + return mouse_y; +} void mouse_init() { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"Initializing mouse driver"); + mouse_cycle=mouse_x=mouse_y=0; + + uint8_t _status; //unsigned char + + //Enable the auxiliary mouse device + mouse_wait(1); + x86_outb(0x64, 0xA8); + + //Enable the interrupts + mouse_wait(1); + x86_outb(0x64, 0x20); + mouse_wait(0); + _status=(x86_inb(0x60) | 2); + mouse_wait(1); + x86_outb(0x64, 0x60); + mouse_wait(1); + x86_outb(0x60, _status); + + //Tell the mouse to use default settings + mouse_write(0xF6); + mouse_read(); //Acknowledge + + //Enable the mouse + mouse_write(0xF4); + mouse_read(); //Acknowledge + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Mouse Initialized"); + +} + +//Mouse functions +void mouse_handler()//struct regs *a_r) //struct regs *a_r (not used but just there) +{ + X86_IRQ_BEGIN + + switch(mouse_cycle) + { + case 0: + mouse_byte[0]=x86_inb(0x60); + mouse_cycle++; + break; + case 1: + mouse_byte[1]=x86_inb(0x60); + mouse_cycle++; + break; + case 2: + mouse_byte[2]=x86_inb(0x60); + mouse_x=mouse_byte[1]; + mouse_y=mouse_byte[2]; + mouse_cycle=0; + break; + + } + + //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"irq12"); + + X86_IRQ_END +} +uint8_t mouse_read() +{ + //Get's response from mouse + mouse_wait(0); + return x86_inb(0x60); +} + +inline void mouse_write(uint8_t a_write) +{ + //Wait to be able to send a command + mouse_wait(1); + //Tell the mouse we are sending a command + x86_outb(0x64, 0xD4); + //Wait for the final part + mouse_wait(1); + //Finally write + x86_outb(0x60, a_write); +} + +inline void mouse_wait(uint8_t a_type) //unsigned char +{ + uint32_t _time_out=100000; //unsigned int + if(a_type==0) + { + while(_time_out--) //Data + { + if((x86_inb(0x64) & 1)==1) + { + return; + } + } + return; + } + else + { + while(_time_out--) //Signal + { + if((x86_inb(0x64) & 2)==0) + { + return; + } + } + return; + } } diff --git a/kernel/vesa.c b/kernel/vesa.c index 7b7b531..0619f1a 100644 --- a/kernel/vesa.c +++ b/kernel/vesa.c @@ -191,15 +191,28 @@ void PutConsoleNL() } } +static int boxx; +static int boxy; //////////////// - void vesa_render() { + vesa_clear_screen(); + vesa_put_rect(100,100,VbeModeInfoBlock->Xres-200,VbeModeInfoBlock->Yres-200,0xff); + vesa_put_rect(boxx-10,boxy-10,20,20,0x999999); + + boxx++; +// boxy+=boxx; + if(boxx>VbeModeInfoBlock->Xres-100)boxx=100; + // if(boxy>VbeModeInfoBlock->Yres-200)boxy=200; + + vesa_switch_buffers(); } void vesa_init_doublebuff() { + boxx=300; + boxy=300; int blocks=800*600*2/4096+1; physbase=VbeModeInfoBlock->physbase; @@ -207,8 +220,6 @@ void vesa_init_doublebuff() log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Init buffer of %d blocks at 0x%08X",blocks,buffer); VbeModeInfoBlock->physbase=buffer; - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test"); - vesa_switch_buffers(); } void vesa_switch_buffers() @@ -217,6 +228,16 @@ void vesa_switch_buffers() } +void vesa_clear_screen() +{ + vesa_put_rect(0,0,VbeModeInfoBlock->Xres, VbeModeInfoBlock->Yres, 0xffffff); +} +void vesa_put_rect(int x, int y, int w , int h, int color) +{ + for(int i=x;i<x+w;i++) + for(int j=y;j<y+h;j++) + PutPixel(i,j,color); +} diff --git a/kernel/x86.h b/kernel/x86.h index a7c1953..6942816 100644 --- a/kernel/x86.h +++ b/kernel/x86.h @@ -7,7 +7,7 @@ // http://wiki.osdev.org/Interrupt_Service_Routines // Black Magic: Strongly Discouraged! #define X86_IRQ_BEGIN asm("\ncli\npusha"); -#define X86_IRQ_END asm("mov $0x20, %al\nout %al, $0x20\npopa\nleave\nsti\niret"); +#define X86_IRQ_END asm("mov $0x20, %al\nout %al, $0x20\nmov $0x20, %al\noutb %al,$0xa0\npopa\nleave\nsti\niret"); void x86_outb(int port, uint8_t data); uint8_t x86_inb(int port); |
