Devil: an IDL for Hardware Programming Fabrice Mrillon, Laurent - - PowerPoint PPT Presentation

devil an idl for hardware programming
SMART_READER_LITE
LIVE PREVIEW

Devil: an IDL for Hardware Programming Fabrice Mrillon, Laurent - - PowerPoint PPT Presentation

Devil: an IDL for Hardware Programming Fabrice Mrillon, Laurent Rveillre, Charles Consel, Renaud Marlet, Gilles Muller Compose Group http://www.irisa.fr/compose Irisa/Labri, Rennes/Bordeaux (France) 1 Interfacing Devices ... The


slide-1
SLIDE 1

1

Fabrice Mérillon, Laurent Réveillère, Charles Consel, Renaud Marlet, Gilles Muller

Compose Group http://www.irisa.fr/compose Irisa/Labri, Rennes/Bordeaux (France)

Devil: an IDL for Hardware Programming

slide-2
SLIDE 2

Page 2 Page 2 Compose group Compose group

Interfacing Devices ...

The Devil is in t he det ails

slide-3
SLIDE 3

Page 3 Page 3 Compose group Compose group

Looking into the "Details"

#define MSE_DATA_PORT 0x23c #define MSE_SIGNATURE_PORT 0x23d #define MSE_CONTROL_PORT 0x23e ... #define MSE_READ_X_LOW 0x80 #define MSE_READ_X_HIGH 0xa0

(busmouse.h) (busmouse.h)

  • utb(MSE_READ_Y_LOW, MSE_CONTROL_PORT );

dy = (inb(MSE_DATA_PORT) & 0xf);

  • utb(MSE_READ_Y_HIGH, MSE_CONTROL_PORT);

buttons = inb(MSE_DATA_PORT); dy |= (buttons & 0xf) << 4; buttons = ((buttons >> 5) & 0x07);

(busmouse.c) (busmouse.c)

slide-4
SLIDE 4

Page 4 Page 4 Compose group Compose group

Assessment of Existing (Linux) Drivers

N Assembly-level programming style N Macros

– unreadable code factorized, not suppressed – no single programming style – no typing / consistency checking

The hardware interface code is: ¯hard to read and maintain ¯tedious and error prone

slide-5
SLIDE 5

Page 5 Page 5 Compose group Compose group

Lack of Support for the Driver Programmer

N Paper documentation » natural language » manufacturer-specific terminology » inconsistencies, ambiguities, omissions, typos N Mixed levels of abstractions » communication mechanisms, data layout, semantics N Inherent complexity of devices

¯Laborious testing until expected functionality is obtained

slide-6
SLIDE 6

Page 6 Page 6 Compose group Compose group

Devil: a DEVice Interface Language

Device Driver System Application

API API DI

  • utb(MSE_READ_Y_LOW,

MSE_CONTROL_PORT ); dy = (inb(MSE_DATA_PORT) & 0xf);

  • utb(MSE_READ_Y_HIGH,

MSE_CONTROL_PORT); buttons = inb(MSE_DATA_PORT); dy |= (buttons & 0xf) << 4;

Existing device interface code

DevI L

CDevil Generated Stubs

slide-7
SLIDE 7

Page 7 Page 7 Compose group Compose group

Our Vision

Hardware vendor, Public repository, Device expert

Verifier Compiler

  • Consistency checking
  • Code generation

Device Specification

  • High-level description
  • f device interface
  • Easy to write
  • Strongly typed

D e v I L D e v I L

Driver CDevil

Driver programmer

C stubs (run-time checks)

  • Functional interface
  • Easy to use
  • Debug/production mode
slide-8
SLIDE 8

Page 8 Page 8 Compose group Compose group

Devil: Key Concepts

N Ports

– communication point, address range

N Registers

– repository of data, granule of exchange

N Variables: programmer interface

– collection of register fragments – semantic values:

» bounded integers » enumerated types

slide-9
SLIDE 9

Page 9 Page 9 Compose group Compose group

Programmer Support: Verifying Critical Properties

N Consistency of Devil specifications

– no omission – no double definition – no overlapping – type/size of variables

N CDevil interface usage in debug mode

– compile-time (type checking) – run-time (assertion checking)

slide-10
SLIDE 10

Page 10 Page 10 Compose group Compose group

The Logitech Busmouse: functional interface

N dx (delta X)

– relative horizontal movement

N dy (delta Y)

– relative vertical movement

N buttons

– button state Read only variables !

slide-11
SLIDE 11

Page 11 Page 11 Compose group Compose group

Device Interface Code: CDevil vs. existing drivers

  • utb(MSE_READ_X_LOW, MSE_CONTROL_PORT);

dx = (inb(MSE_DATA_PORT) & 0xf);

  • utb(MSE_READ_X_HIGH, MSE_CONTROL_PORT);

dx |= (inb(MSE_DATA_PORT) & 0xf) << 4;

  • utb(MSE_READ_Y_LOW, MSE_CONTROL_PORT );

dy = (inb(MSE_DATA_PORT) & 0xf);

  • utb(MSE_READ_Y_HIGH, MSE_CONTROL_PORT);

buttons = inb(MSE_DATA_PORT); dy |= (buttons & 0xf) << 4; buttons = ((buttons >> 5) & 0x07); Existing code dx = get_dx(); dy = get_dy(); buttons = get_buttons(); CDevil

slide-12
SLIDE 12

Page 12 Page 12 Compose group Compose group

* * * * . . . . * * * * . . . . * * * * . . . . . . . * . . . . base + 0 1 . . 0 0 0 0 0 base + 2

1 1 2 2 3 3 index dx dy buttons

The Logitech Busmouse: detailed description

Direct register Register array

slide-13
SLIDE 13

Page 13 Page 13 Compose group Compose group

...

register index_reg = write base@2, mask ’1..00000’: bit[8];

* * * * . . . . * * * * . . . . * * * * . . . . . . . * . . . . base + 0

buttons dx dy

1 . . 0 0 0 0 0 base + 2

→ index_reg 1 1 2 2 3 3

Direct registers

index

Register array

slide-14
SLIDE 14

Page 14 Page 14 Compose group Compose group

... register index_reg = write base@2, mask ’1..00000’ : bit[8];

private variable index = index_reg[6..5] : int(2);

* * * * . . . . * * * * . . . . * * * * . . . . . . . * . . . . base + 0 1 . . 0 0 0 0 0 base + 2

→ index_reg 1 1 2 2 3 3 dx dy buttons

Private device variables

index

Register array

slide-15
SLIDE 15

Page 15 Page 15 Compose group Compose group

... register index_reg = write base@2, mask ’1..00000’ : bit[8]; private variable index = index_reg[6..5] : int(2); ...

register x_low = read base@0, pre {index = 0}, mask ’****....’ : bit[8]; register x_high = read base@0, pre {index = 1}, mask ’****....’ : bit[8];

...

* * * * . . . . * * * * . . . . * * * * . . . . . . . * . . . . base + 0

→ x_low → x_high → y_low → y_high

1 . . 0 0 0 0 0 base + 2

→ index_reg 1 1 2 2 3 3 dx dy buttons

Indexed registers

index

slide-16
SLIDE 16

Page 16 Page 16 Compose group Compose group

... register index_reg = write base@2, mask ’1..00000’ : bit[8]; private variable index = index_reg[6..5] : int(2); ... register x_low = read base@0, pre {index = 0}, mask ’****....’ : bit[8]; register x_high = read base@0, pre {index = 1}, mask ’****....’ : bit[8]; ...

variable dx = x_high[3..0] # x_low[3..0], volatile : signed int(8); variable dy = y_high[3..0] # y_low[3..0], volatile : signed int(8);

* * * * . . . . * * * * . . . . * * * * . . . . . . . * . . . . base + 0

→ x_low → x_high → y_low → y_high

1 . . 0 0 0 0 0 base + 2

→ index_reg 1 1 2 2 3 3 dx dy buttons

Interface variables

index

slide-17
SLIDE 17

Page 17 Page 17 Compose group Compose group

What About Performance ?

N Sharing registers between variables may

induce performance penalty

– additional I/O w.r.t. hand-crafted drivers – command parameters

N Re-engineering of performance critical

drivers

– IDE disk driver – Permedia2 X11 driver

slide-18
SLIDE 18

Page 18 Page 18 Compose group Compose group

IDE Linux Driver (intel 82371SB)

N Characteristics:

– many initializations – DMA/PIO-loop for transfer

N DMA mode C: 14 I/Os Devil: 20 I/Os 14.25 Mb/s N PIO-32bits mode, 16 sectors/interrupt C (rep loop): 8.17 Mb/s Devil (C loop): 7.36 Mb/s (90% of C) Devil (rep loop): 8.17 Mb/s

slide-19
SLIDE 19

Page 19 Page 19 Compose group Compose group

Permedia2 X11 driver

N Characteristics:

–registers mapped in memory –buffered write (on-chip FIFO) –same number of I/Os

N Screen copy operations (24 bpp) – 100% performance of C N Rectangle operations (24 bpp) – 97%-100% performance of C – difference due to stub code for small size operation

slide-20
SLIDE 20

Page 20 Page 20 Compose group Compose group

Benefits of Devil

N Expressivity » advanced Devil constructs (see paper and manual) » DMA, sound, interrupt, Ethernet controllers N Guaranteed safety » Mutation-based experiment (typo simulation) » 5 times less prone to errors than C code N Negligible performance overhead N Improved productivity » reuse of specifications » tools and verifications

slide-21
SLIDE 21

Page 21 Page 21 Compose group Compose group

Our Vision (On-going work)

Device specification Device interface implementation Verifier Compiler Hardware vendor Device interface documentation Device driver specification DSL type-checker DSL optimizer DSL compiler Driver programmer Device driver documentation Generated device driver

slide-22
SLIDE 22

Page 22 Page 22 Compose group Compose group

Conclusion

N Step toward the development of robust

drivers

N Compiler/checker available N No performance penalty N Expressive enough to allow the

specification of various devices Instance of our vision: “DSL for Operating System Design”

slide-23
SLIDE 23

Page 23 Page 23 Compose group Compose group

The details are in Devil

slide-24
SLIDE 24

Page 24 Page 24 Compose group Compose group

Questions ?

N Specifications/compiler/manual available :

www.irisa.fr/compose/devil

N Public CVS repository of specs

Please contribute …