SVN repository for sources Source code for the Lab is available via - - PDF document

svn repository for sources
SMART_READER_LITE
LIVE PREVIEW

SVN repository for sources Source code for the Lab is available via - - PDF document

Faculty of Computer Science Institute for System Architecture, Operating Systems Group Keyboard Driver & Pong Client 2007 SVN repository for sources Source code for the Lab is available via SVN:


slide-1
SLIDE 1

Faculty of Computer Science Institute for System Architecture, Operating Systems Group

2007 Keyboard Driver & Pong Client

TU Dresden Slide 2

SVN repository for sources

Source code for the Lab is available via SVN:

http://os.inf.tu-dresden.de/Studium/Praktikum/src/trunk/kpr2007

To check out the repository use:

  • svn co <URL> <target_dir>

To get an update go to your working copy and use:

  • svn up
slide-2
SLIDE 2

TU Dresden Slide 3

Course Goal

Fiasco Kernel RootServer Sigma0 Pong Server Paddle Client 1 Paddle Client 2 Keyboard Driver File System Loader Memory Manager Name Server Console

TU Dresden Slide 4

Keyboard Driver

  • Programs keyboard hardware
  • Provides interface for several clients:

Paddle Client 1 Paddle Client 2 Keyboard Driver ‘y’, ‘x’ ‘n’, ‘m’

slide-3
SLIDE 3

TU Dresden Slide 5

Fiasco-UX Keyboard Driver

  • Fiasco-UX provides keyboard and mouse input

through graphical console

– Interrupt 1 to signal input event – Ring buffer with list of input events:

typedef struct input_ev { long long time; /* event timestamp */ unsigned short type; /* type: 1 … key event * (includes mouse buttons) * 2 … mouse move */ unsigned short code; /* key: keycode * move: 0 … X direction * 1 … Y direction */ unsigned int value; /* key: 1 … button pressed * 0 … button released * move: distance */ } input_ev_t;

TU Dresden Slide 6

Attach Keyboard Interrupt

#include <l4/sys/ipc.h> #include <l4/rmgr/librmgr.h> l4_threadid_t irq_id; l4_msgdope_t result; l4_umword_t dummy; int ret; /* attach interrupt */ l4_make_taskid_from_irq(INPUT_IRQ_NUM, &irq_id); ret = l4_ipc_receive(irq_id, 0, &dummy, &dummy, L4_IPC_TIMEOUT(0,0,0,1,0,0), &result); if (ret != L4_IPC_RETIMEOUT) /* error … */ /* interrupt handler loop */ while(1) { /* send 0, 0 to IRQ to enable it wait for interrupt */ ret = l4_ipc_{call|replay_and_wait}(irq_id, L4_IPC_SHORT_MSG, 0, 0, L4_IPC_SHORT_MSG, &dummy, &dummy, L4_IPC_NEVER, &result); /* handle interrupt */ … }

slide-4
SLIDE 4

TU Dresden Slide 7

Map Event Buffer

  • Event buffer is I/O memory

#include <l4/base/rm.h> #include <l4/base/memory.h> #include <l4/base/name.h> #include <l4/base/info_page.h> #include <l4/base/exceptions.h> ... L4::Memory input; L4::Rm rm; void *input_buffer_addr; try { input = L4::Info_page::info_page()->root().resolve("dev/input"); rm = L4::Info_page::info_page()->region_mapper(); input_buffer_addr = rm.attach((void*)0x40000000, 1024*1024*4, L4::Rm::Search_addr, input, 0); } catch (L4::Base_exception const &e) { L4::cout << "Error looking up input device: " << e.str() << "\n"; return -1; }

TU Dresden Slide 8

Use Event Buffer

  • If interrupt received, walk through event buffer

 One interrupt can signal several input events

input_ev_t * ev; int input_pos = 0; /* read input events */ while(1) { ev = (input_ev_t *)(input_buffer_addr + input_pos * sizeof(input_ev_t)); /* end of valid input events is marked with timestamp 0 */ if (ev->time == 0) break; if (ev->type == INPUT_EV_KEY) { /* got keyboard event */ … } /* mark event handled */ ev->time = 0; /* next event */ input_pos++; if (input_pos == INPUT_NUM_OBJS) input_pos = 0; }

slide-5
SLIDE 5

TU Dresden Slide 9

Keyboard Driver – Assignment

  • Given: l4/libinput/input.h

– provides input event structure, keycode  character mapping

  • Design keyboard driver

– Interrupt handling – Event buffering – Should support several clients

  • Write C++ interface, server and client

TU Dresden Slide 10

Pong Client

  • Uses keyboard driver to wait for key events
  • Attaches to Pong server to move paddles

Pong Server Paddle Client 1 Paddle Client 2 Keyboard Driver Key events Paddle moves

slide-6
SLIDE 6

TU Dresden Slide 11

Pong Server

  • Pong Server interface

kpr/pong/example/main.cc: class Paddle

– Modify class Paddle to fit your needs – Methods:

  • int connect() // connect to a paddle and

// returns the ID

  • int lifes() // get the number of lifes left
  • void move(int pos) // move to possition

// 0 <= pos <= 1023

  • run() // must be implemented by you

TU Dresden Slide 12

Pong Client – Assignments

  • Register Pong server at your name server

l4/kpr/pong/server/dummies.h:

void pong_names_register(l4_threadid_t id, char const * name) { /* fill in your name server functions */ }

  • Write Pong client which

– uses keyboard driver to get input events, – implements paddle moves  sets paddle position, – initializes and periodically requests lifes