Skip to content
Snippets Groups Projects
Commit f585cf0b authored by ivan.pavlovic's avatar ivan.pavlovic
Browse files

Keyboard done

parent 818d2971
Branches master
No related tags found
No related merge requests found
Showing
with 130 additions and 26 deletions
No preview for this file type
#include <stdint.h>
#include <stdio.h>
#include "idt.h"
#include "utils.h"
#include "pmio.h"
......@@ -15,6 +16,8 @@
#define timer_sleep timer_sleep_phys
#endif
extern uint32_t key;
void timer_sleep_pv(int usec) {
hyper_timer_sleep_params_t *timer_sleep_params = (hyper_timer_sleep_params_t*)(SHARED_STORAGE_ADDRESS);
timer_sleep_params->us = usec;
......@@ -66,8 +69,29 @@ void guest_main() {
// console_pv("Débloquage du display!\n");
// affichage_pv(400, 300);
console_pv("Attente de 100000\n");
//console_pv("Attente de 100000\n");
// timer_sleep(10000000);
timer_sleep_phys(10000000);
console_pv("Après attente!!\n");
//timer_sleep_phys(10000000);
//console_pv("Après attente!!\n");
console_pv("Start affichage");
affichage_pv(600, 400);
int quit = 0;
while (quit == 0)
{
if (key != 100000){
char buffer[100];
snprintf(buffer, 100, "Key: %d\n", key);
console_pv(buffer);
if( key == 27){
quit = 1;
}
key = 100000;
}
}
}
No preview for this file type
......@@ -2,9 +2,14 @@
#include "utils.h"
#include "descriptors.h"
#include "x86.h"
#include "pmio.h"
#define GDT_KERNEL_CODE_SELECTOR 0x08
// My test
uint32_t key;
// --------
// Structure of an IDT descriptor. There are 3 types of descriptors:
// task-gates, interrupt-gates, trap-gates.
// See 5.11 of Intel 64 & IA32 architectures software developer's manual for more details.
......@@ -53,9 +58,13 @@ static idt_entry_t idt_build_entry(uint16_t selector, uint32_t offset, uint8_t t
// Low level handler defined in idt_asm.s
void _irq0();
void _irq1();
// IRQ handler
void irq_handler(uint32_t irq_number) {
if (irq_number == 1){
key = ind(0x60);
}
}
void idt_init() {
......@@ -66,6 +75,7 @@ void idt_init() {
memset(idt, 0, sizeof(idt));
idt[0] = idt_build_entry(GDT_KERNEL_CODE_SELECTOR, (uint32_t)_irq0, TYPE_INTERRUPT_GATE, DPL_KERNEL);
idt[1] = idt_build_entry(GDT_KERNEL_CODE_SELECTOR, (uint32_t)_irq1, TYPE_INTERRUPT_GATE, DPL_KERNEL);
idt_load(&idt_ptr);
}
idt.o: idt.c idt.h utils.h descriptors.h x86.h
idt.o: idt.c idt.h utils.h descriptors.h x86.h pmio.h
No preview for this file type
No preview for this file type
......@@ -15,6 +15,11 @@ _irq0:
push 0 ; put irq number on the stack
jmp irq_handler_wrapper
global _irq1
_irq1:
push 1 ; put irq number on the stack
jmp irq_handler_wrapper
extern irq_handler
irq_handler_wrapper:
......
......@@ -39,4 +39,8 @@ typedef struct {
int32_t y ; // y position
} __attribute__((packed)) hyper_sprite_position_params_t;
typedef struct {
uint32_t key ; // code of the pressed key
} __attribute__((packed)) hyper_keyboard_params_t;
#endif
......@@ -48,14 +48,14 @@ void disk_store_sector_4(void *addr) {
}
void disk_store_data(void *addr) {
printf("Storring on id=%ld\n", data_index);
//printf("Storring on id=%ld\n", data_index);
buffer_16[data_index] = *(uint16_t *)addr;
data_index++;
if (data_index == SECTOR_SIZE/2) {
stop_loop = true;
printf("Stopping loop after id=%ld\n", data_index);
//printf("Stopping loop after id=%ld\n", data_index);
}
}
......@@ -63,7 +63,7 @@ void disk_conclude(void *addr){
hyper_disk_params_t* tmp_params = addr == NULL ? &disk_params : (hyper_disk_params_t*) addr;
printf("Mem: %d\n", mem);
//printf("Mem: %d\n", mem);
// Pv not working for some reason
// Wrong data writen
......@@ -95,5 +95,5 @@ void disk_conclude(void *addr){
}
fclose(disk);
printf("Storing data\n");
//printf("Storing data\n");
}
\ No newline at end of file
No preview for this file type
......@@ -30,7 +30,7 @@ void gfx_init_conclude(void *addr){
display_width = tmp_params->width;
display_height = tmp_params->height;
printf("Initialising display!!! Width: %d, Height: %d\n", display_width, display_height);
//printf("Initialising display!!! Width: %d, Height: %d\n", display_width, display_height);
sem_post(&display_sem);
}
\ No newline at end of file
No preview for this file type
#include "keyboard.h"
state_t keyboard_states[] = {
{WRITE_KEY, 0x60, 0, 4, NULL},
{EMULATE, 0, 0, 0, NULL}
};
state_machine_t keyboard_state_machine = {
.current_state = 0,
.states = keyboard_states
};
hyper_keyboard_params_t keyboard_params;
\ No newline at end of file
peripheriques/keyboard/keyboard.o: peripheriques/keyboard/keyboard.c \
peripheriques/keyboard/keyboard.h \
peripheriques/keyboard/../state_machine.h \
peripheriques/keyboard/../../../shared/hypercall_params.h
#ifndef KEYBOARD_H
#define KEYBOARD_H
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include "../state_machine.h"
#include "../../../shared/hypercall_params.h"
extern state_t keyboard_states[];
extern state_machine_t keyboard_state_machine;
extern hyper_keyboard_params_t keyboard_params;
void timer_store(void *addr);
void timer_conclude(void *addr);
#endif
\ No newline at end of file
File added
......@@ -8,25 +8,45 @@ state_machine_t* state_machines[NB_STATE_MACHINE] = {
&disk_state_machine,
&sprite_content_state_machine,
&sprite_visibility_state_machine,
&sprite_position_state_machine
&sprite_position_state_machine,
&keyboard_state_machine
};
void check_state(uint64_t addr, uint8_t* addr_p, uint8_t size, uint32_t value){
printf("Checking... addr: 0x%lX, size: %d, value: %d\n", addr, size, value);
//printf("Checking... addr: 0x%lX, size: %d, value: %d\n", addr, size, value);
for (int i = 0; i < NB_STATE_MACHINE; i++){
printf("State machine n°%d\n", i);
printf("State machine state: %d\n", state_machines[i]->current_state);
//printf("State machine n°%d\n", i);
//printf("State machine state: %d\n", state_machines[i]->current_state);
state_t tmp_state = state_machines[i]->states[state_machines[i]->current_state];
switch (tmp_state.act)
{
case WRITE:
printf("WRITE\n");
//printf("WRITE\n");
if(tmp_state.address == addr && tmp_state.size == size){
printf("Test OK\n");
//printf("Test OK\n");
*((uint32_t *)addr_p) = (uint32_t)tmp_state.value;
printf("Wrote %ld on 0x%lX\n", tmp_state.value, addr);
//printf("Wrote %ld on 0x%lX\n", tmp_state.value, addr);
state_machines[i]->current_state += 1;
if(tmp_state.callback != NULL){
tmp_state.callback(addr_p);
}
}
else{
state_machines[i]->current_state = 0;
}
break;
case WRITE_KEY:
//printf("WRITE_KEY\n");
if(tmp_state.address == addr && tmp_state.size == size){
printf("Test OK\n");
*((uint32_t *)addr_p) = (uint32_t)keyboard_params.key;
printf("Wrote %d on 0x%lX\n", keyboard_params.key, addr);
usleep(100000);
state_machines[i]->current_state += 1;
if(tmp_state.callback != NULL){
......@@ -38,10 +58,10 @@ void check_state(uint64_t addr, uint8_t* addr_p, uint8_t size, uint32_t value){
}
break;
case STORE:
printf("STORE\n");
//printf("STORE\n");
if(tmp_state.address == addr && tmp_state.size == size){
printf("Test OK\n");
//printf("Test OK\n");
tmp_state.callback(addr_p);
state_machines[i]->current_state += 1;
}
......@@ -50,10 +70,10 @@ void check_state(uint64_t addr, uint8_t* addr_p, uint8_t size, uint32_t value){
}
break;
case STORE_LOOP:
printf("STORE_LOOP\n");
//printf("STORE_LOOP\n");
if(tmp_state.address == addr && tmp_state.size == size){
printf("Test OK\n");
//printf("Test OK\n");
tmp_state.callback(addr_p);
if (stop_loop){
state_machines[i]->current_state += 1;
......@@ -64,9 +84,9 @@ void check_state(uint64_t addr, uint8_t* addr_p, uint8_t size, uint32_t value){
}
break;
case EQUALS:
printf("EQUALS\n");
//printf("EQUALS\n");
if(tmp_state.address == addr && tmp_state.size == size && tmp_state.value == value){
printf("Test OK\n");
//printf("Test OK\n");
state_machines[i]->current_state += 1;
}
else{
......@@ -77,10 +97,13 @@ void check_state(uint64_t addr, uint8_t* addr_p, uint8_t size, uint32_t value){
break;
}
printf("State machine state: %d\n", state_machines[i]->current_state);
//cprintf("State machine state: %d\n", state_machines[i]->current_state);
if (state_machines[i]->states[state_machines[i]->current_state].act == EMULATE){
if(state_machines[i]->states[state_machines[i]->current_state].callback != NULL){
state_machines[i]->states[state_machines[i]->current_state].callback(NULL);
}
state_machines[i]->current_state = 0;
}
}
......
......@@ -14,4 +14,7 @@ peripheriques/peripheriques.o: peripheriques/peripheriques.c \
peripheriques/sprites/visibility/sprite_visibility.h \
peripheriques/sprites/visibility/../sprites.h \
peripheriques/sprites/position/sprite_position.h \
peripheriques/sprites/position/../sprites.h
peripheriques/sprites/position/../sprites.h \
peripheriques/keyboard/keyboard.h \
peripheriques/keyboard/../state_machine.h \
peripheriques/keyboard/../../../shared/hypercall_params.h
......@@ -10,8 +10,9 @@
#include "sprites/content/sprite_content.h"
#include "sprites/visibility/sprite_visibility.h"
#include "sprites/position/sprite_position.h"
#include "keyboard/keyboard.h"
#define NB_STATE_MACHINE 6
#define NB_STATE_MACHINE 7
void check_state(uint64_t addr, uint8_t* addr_p, uint8_t size, uint32_t value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment