[email protected]/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM...

59
L YREBIRD David Cock [email protected] L Lyrebird λ

Transcript of [email protected]/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM...

Page 1: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

LYREBIRDDavid Cock

[email protected]

bir

d

λ

Page 2: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

What is the Motivation?

Program proof is important, but there’s more to do.

NICTA Copyright c© 2011 From Imagination to Impact 2

Page 3: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

What is the Motivation?

Program proof is important, but there’s more to do.

Code

NICTA Copyright c© 2011 From Imagination to Impact 2

Page 4: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

What is the Motivation?

Program proof is important, but there’s more to do.

CodeProof

NICTA Copyright c© 2011 From Imagination to Impact 2

Page 5: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

What is the Motivation?

Program proof is important, but there’s more to do.

CodeProof

Model

Any statement ”P is True” is incomplete:

It must be read as ”, under Q - my model of the world”.

Goal: Development outcomes: program, proof and model.

NICTA Copyright c© 2011 From Imagination to Impact 2

Page 6: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

What is the Motivation?

Program proof is important, but there’s more to do.

Code

seL4

Proof

ModelLLyre

bir

d

λ

Any statement ”P is True” is incomplete:

It must be read as ”, under Q - my model of the world”.

Goal: Development outcomes: program, proof and model.

NICTA Copyright c© 2011 From Imagination to Impact 2

Page 7: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

What is the Motivation?

Program proof is important, but there’s more to do.

Code

seL4

Proof

ModelLLyre

bir

d

λ

Any statement ”P is True” is incomplete:

It must be read as ”, under Q - my model of the world”.

Goal: Development outcomes: program, proof and model.

Our approach is a language framework: Lyrebird.

NICTA Copyright c© 2011 From Imagination to Impact 2

Page 8: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

What is the Motivation?

Code

seL4

Proof

Model

L

Lyrebird

λ

NICTA Copyright c© 2011 From Imagination to Impact 3

Page 9: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

What is the Motivation?

Abstract

Haskell

C

Proof

Model

L

Lyrebird

λ

NICTA Copyright c© 2011 From Imagination to Impact 4

Page 10: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

What is the Motivation?

Abstract

Haskell

C

1st Refinement

2nd Refinement

Model

L

Lyrebird

λ

NICTA Copyright c© 2011 From Imagination to Impact 5

Page 11: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

What is the Motivation?

Abstract

Haskell

C

1st Refinement

2nd Refinement

Machine M

onad

MSR

?

"The World"

Model

L

Lyrebird

λ

NICTA Copyright c© 2011 From Imagination to Impact 6

Page 12: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

What is the Motivation?

LLyre

bir

d

λ

Formal Hardware Model

Machine Monad

MSR

Machine Refinement

Simulator

NICTA Copyright c© 2011 From Imagination to Impact 7

Page 13: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

What is the Motivation?

LLyre

bir

d

λ

Simulator

Formal Model

Lyrebird model

Lyrebird is a framework built around a modelling language.

Tools are included to generate simulators and formal models.

NICTA Copyright c© 2011 From Imagination to Impact 8

Page 14: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Observations

LLyre

bir

d

λ

Errata

Testing

The Model Should be Progressively Refined:

Even the manufacturer doesn’t have a complete model,

they publish errata when they find mistakes.

Goal: Updating the model should be easy.

NICTA Copyright c© 2011 From Imagination to Impact 9

Page 15: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Observations

To a program, the world is the machine.

Building machine models is hard, often boring work.

It’s easy to get started, and cover the part that’s well behaved.

Handling the rest, and getting it right takes a lot longer.

It’s also mind-numbingly, soul-destroyingly dull.

So only model those parts that we actually need.

NICTA Copyright c© 2011 From Imagination to Impact 10

Page 16: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

What does this code do? What ends up in r1?

address data instruction r1 r2 r3 @100 @108

... ... ... ... 100 108 42 ...

1000 e5921000 ldr r1, [r2]

1004 e5832000 str r1, [r3]

1008 e2811001 add r1, r1, #1

NICTA Copyright c© 2011 From Imagination to Impact 11

Page 17: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

What does this code do? What ends up in r1?

address data instruction r1 r2 r3 @100 @108

... ... ... ... 100 108 42 ...

1000 e5921000 ldr r1, [r2] 42 100 108 42 ...

1004 e5832000 str r1, [r3]

1008 e2811001 add r1, r1, #1

NICTA Copyright c© 2011 From Imagination to Impact 11

Page 18: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

What does this code do? What ends up in r1?

address data instruction r1 r2 r3 @100 @108

... ... ... ... 100 108 42 ...

1000 e5921000 ldr r1, [r2] 42 100 108 42 ...

1004 e5832000 str r1, [r3] 42 100 108 42 42

1008 e2811001 add r1, r1, #1

NICTA Copyright c© 2011 From Imagination to Impact 11

Page 19: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

What does this code do? What ends up in r1?

address data instruction r1 r2 r3 @100 @108

... ... ... ... 100 108 42 ...

1000 e5921000 ldr r1, [r2] 42 100 108 42 ...

1004 e5832000 str r1, [r3] 42 100 108 42 42

1008 e2811001 add r1, r1, #1 43 100 108 42 42

NICTA Copyright c© 2011 From Imagination to Impact 11

Page 20: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

What does this code do? What ends up in r1?

address data instruction r1 r2 r3 @100 @108

... ... ... ... 100 108 42 ...

1000 e5921000 ldr r1, [r2] 42 100 108 42 ...

1004 e5832000 str r1, [r3] 42 100 108 42 42

1008 e2811001 add r1, r1, #1 43 100 108 42 42

Most code is like the above, and it’s easy to understand;

The challenge here is how to express that formally.

Goal: Easy things should be straightforward.

NICTA Copyright c© 2011 From Imagination to Impact 11

Page 21: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

90% is not too bad and moreover it’s been done.

We should focus on the 10%, the hard parts.

NICTA Copyright c© 2011 From Imagination to Impact 12

Page 22: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

90% is not too bad and moreover it’s been done.

We should focus on the 10%, the hard parts.

So what is a hard part?

NICTA Copyright c© 2011 From Imagination to Impact 12

Page 23: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

90% is not too bad and moreover it’s been done.

We should focus on the 10%, the hard parts.

So what is a hard part?

Let’s have another look at that example. . .

NICTA Copyright c© 2011 From Imagination to Impact 12

Page 24: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

Another look at the example:

What value ends up in r1 now?

r1 r2 r3 @1000 @1008

... ... ... ... 1000 1008 e5921000 ...

1000 e5921000 ldr r1, [r2]

1004 e5832000 str r1, [r3]

1008 e2811001 add r1, r1, #1

NICTA Copyright c© 2011 From Imagination to Impact 13

Page 25: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

Another look at the example:

What value ends up in r1 now?

r1 r2 r3 @1000 @1008

... ... ... ... 1000 1008 e5921000 ...

1000 e5921000 ldr r1, [r2] e5921000 1000 1008 e5921000 ...

1004 e5832000 str r1, [r3]

1008 e2811001 add r1, r1, #1

NICTA Copyright c© 2011 From Imagination to Impact 13

Page 26: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

Another look at the example:

What value ends up in r1 now?

r1 r2 r3 @1000 @1008

... ... ... ... 1000 1008 e5921000 ...

1000 e5921000 ldr r1, [r2] e5921000 1000 1008 e5921000 ...

1004 e5832000 str r1, [r3] e5921000 1000 1008 e5921000 e5921000

1008 e2811001 add r1, r1, #1

NICTA Copyright c© 2011 From Imagination to Impact 13

Page 27: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

Another look at the example:

What value ends up in r1 now?

r1 r2 r3 @1000 @1008

... ... ... ... 1000 1008 e5921000 ...

1000 e5921000 ldr r1, [r2] e5921000 1000 1008 e5921000 ...

1004 e5832000 str r1, [r3] e5921000 1000 1008 e5921000 e5921000

1008 e2811001 add r1, r1, #1 e5921001 1000 1008 e5921000 e5921000

NICTA Copyright c© 2011 From Imagination to Impact 13

Page 28: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

Another look at the example:

What value ends up in r1 now?

r1 r2 r3 @1000 @1008

... ... ... ... 1000 1008 e5921000 ...

1000 e5921000 ldr r1, [r2] e5921000 1000 1008 e5921000 ...

1004 e5832000 str r1, [r3] e5921000 1000 1008 e5921000 e5921000

1008 e2811001 add r1, r1, #1 e5921001 1000 1008 e5921000 e5921000

Wait a minute, what was that address? Didn’t we just overwrite this instruction?

NICTA Copyright c© 2011 From Imagination to Impact 13

Page 29: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

Another look at the example:

What value ends up in r1 now?

r1 r2 r3 @1000 @1008

... ... ... ... 1000 1008 e5921000 ...

1000 e5921000 ldr r1, [r2] e5921000 1000 1008 e5921000 ...

1004 e5832000 str r1, [r3] e5921000 1000 1008 e5921000 e5921000

1008 e2811001 add r1, r1, #1 e5921001 1000 1008 e5921000 e5921000

Wait a minute, what was that address? Didn’t we just overwrite this instruction?

1008 e5921000 ldr r1, [r2] e5921000 1000 1008 e5921000 e5921000

NICTA Copyright c© 2011 From Imagination to Impact 13

Page 30: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

Another look at the example:

What value ends up in r1 now?

r1 r2 r3 @1000 @1008

... ... ... ... 1000 1008 e5921000 ...

1000 e5921000 ldr r1, [r2] e5921000 1000 1008 e5921000 ...

1004 e5832000 str r1, [r3] e5921000 1000 1008 e5921000 e5921000

1008 e2811001 add r1, r1, #1 e5921001 1000 1008 e5921000 e5921000

Wait a minute, what was that address? Didn’t we just overwrite this instruction?

1008 e5921000 ldr r1, [r2] e5921000 1000 1008 e5921000 e5921000

Which of these is the right answer?

NICTA Copyright c© 2011 From Imagination to Impact 13

Page 31: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Example

It depends . . . on the CPU, the cache, and the state.

This isn’t hypothetical;

We need to write code to memory and then run it

. . . and we need to make sure we do it right.

In a formal model, this is a corner case and it’s abstracted.

Sometimes, however, you’ve got to get your hands dirty.

Goal: Hard things should be possible.

NICTA Copyright c© 2011 From Imagination to Impact 14

Page 32: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

How to Build Models

LLyre

bir

d

λ

Formal Hardware Model

Simulator

Invariants

Inconsistencies

Verification uncovers what the machine should do.

These models are too abstract.

Programming uncovers what the machine does.

These models are too informal.

We must combine this knowledge rigorously.

NICTA Copyright c© 2011 From Imagination to Impact 15

Page 33: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

How to Build Models

LLyre

bir

d

λ

Formal Hardware Model

Simulator

Invariants

Inconsistencies

Close the loop

Iterative refinement

Work Iteratively:

Start with a simple model and only add details as required.

When verification uncovers a requirement, update the model.

When programming discovers a behaviour, update the model.

NICTA Copyright c© 2011 From Imagination to Impact 16

Page 34: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

How to Build Models

LLyre

bir

d

λ

This workflow requires a common language.

Our solution is Lyrebird

NICTA Copyright c© 2011 From Imagination to Impact 17

Page 35: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

Read

A simple model of a CPU connected to RAM.

NICTA Copyright c© 2011 From Imagination to Impact 18

Page 36: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

module vsr;

cycle {

Memory.Read[[PC, Instr]];

decode_execute VSR;

}

instruction ADD {

execute { Ra <- Rb + Rc; }

}

instruction LDR {

execute { Memory.Read[[Rb,Ra]]; }

}

Memory

addr

data

Read

Modules are written in Lyrebird.

NICTA Copyright c© 2011 From Imagination to Impact 19

Page 37: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

module vsr;

cycle {

Memory.Read[[PC, Instr]];

decode_execute VSR;

}

instruction ADD {

execute { Ra <- Rb + Rc; }

}

instruction LDR {

execute { Memory.Read[[Rb,Ra]]; }

}

Memory

addr

data

Read

The cycle specifies asynchronous behaviour.

NICTA Copyright c© 2011 From Imagination to Impact 20

Page 38: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

module vsr;

cycle {

Memory.Read[[PC, Instr]];

decode_execute VSR;

}

instruction ADD {

execute { Ra <- Rb + Rc; }

}

instruction LDR {

execute { Memory.Read[[Rb,Ra]]; }

}

Memory

addr

data

Read

Modules export instructions.

NICTA Copyright c© 2011 From Imagination to Impact 21

Page 39: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

module vsr;

cycle {

Memory.Read[[PC, Instr]];

decode_execute VSR;

}

instruction ADD {

execute { Ra <- Rb + Rc; }

}

instruction LDR {

execute { Memory.Read[[Rb,Ra]]; }

}

Memory

addr

data

Read

All behaviour is built from register transfers.

NICTA Copyright c© 2011 From Imagination to Impact 22

Page 40: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

module vsr;

cycle {

Memory.Read[[PC, Instr]];

decode_execute VSR;

}

instruction ADD {

execute { Ra <- Rb + Rc; }

}

instruction LDR {

execute { Memory.Read[[Rb,Ra]]; }

}

Memory

addr

data

Read

Modules are linked by interfaces.

NICTA Copyright c© 2011 From Imagination to Impact 23

Page 41: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

module vsr;

cycle {

Memory.Read[[PC, Instr]];

decode_execute VSR;

}

instruction ADD {

execute { Ra <- Rb + Rc; }

}

instruction LDR {

execute { Memory.Read[[Rb,Ra]]; }

}

Memory

addr

data

Read

Interfaces define transactions.

NICTA Copyright c© 2011 From Imagination to Impact 24

Page 42: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

module vsr;

cycle {

Memory.Read[[PC, Instr]];

decode_execute VSR;

}

instruction ADD {

execute { Ra <- Rb + Rc; }

}

instruction LDR {

execute { Memory.Read[[Rb,Ra]]; }

}

Memory

addr

data

Read

Transactions access the datapath.

NICTA Copyright c© 2011 From Imagination to Impact 25

Page 43: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

Memory

CPU

MMU

Read

Interfaces and modules allow different implementations.

NICTA Copyright c© 2011 From Imagination to Impact 26

Page 44: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

Memory

CPU

MMU

module mmu; cycle {}

macro Walk(int<30> va, int<30> &pa) {

register int<32> entry;

vpn= va[29:14];

Memory.Read[[vpn zext 30,entry]];

pa<- entry[29:14] ++ va[13:0];

}

transaction CPU.Read {

register int<30> pa;

%Walk(addr, pa);

Memory.Read(pa, data);

}

Memory

addr

data

CPU

addr

data

module mmu; cycle {}

macro Walk(int<30> va, int<30> &pa) {

register int<32> entry;

vpn= va[29:14];

Memory.Read[[vpn zext 30,entry]];

pa<- entry[29:14] ++ va[13:0];

}

transaction CPU.Read {

register int<30> pa;

%Walk(addr, pa);

Memory.Read[[pa, data]];

}

Memory

addr

data

CPU

addr

data

Read

Lyrebird can also be used to model devices.

NICTA Copyright c© 2011 From Imagination to Impact 27

Page 45: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

Memory

CPU

MMU

module mmu; cycle {}

macro Walk(int<30> va, int<30> &pa) {

register int<32> entry;

vpn= va[29:14];

Memory.Read[[vpn zext 30,entry]];

pa<- entry[29:14] ++ va[13:0];

}

transaction CPU.Read {

register int<30> pa;

%Walk(addr, pa);

Memory.Read(pa, data);

}

Memory

addr

data

CPU

addr

data

module mmu; cycle {}

macro Walk(int<30> va, int<30> &pa) {

register int<32> entry;

vpn= va[29:14];

Memory.Read[[vpn zext 30,entry]];

pa<- entry[29:14] ++ va[13:0];

}

transaction CPU.Read {

register int<30> pa;

%Walk(addr, pa);

Memory.Read[[pa, data]];

}

Memory

addr

data

CPU

addr

data

Read

Register types have explicit width.

NICTA Copyright c© 2011 From Imagination to Impact 28

Page 46: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

Memory

CPU

MMU

module mmu; cycle {}

macro Walk(int<30> va, int<30> &pa) {

register int<32> entry;

vpn= va[29:14];

Memory.Read[[vpn zext 30,entry]];

pa<- entry[29:14] ++ va[13:0];

}

transaction CPU.Read {

register int<30> pa;

%Walk(addr, pa);

Memory.Read(pa, data);

}

Memory

addr

data

CPU

addr

data

module mmu; cycle {}

macro Walk(int<30> va, int<30> &pa) {

register int<32> entry;

vpn= va[29:14];

Memory.Read[[vpn zext 30,entry]];

pa<- entry[29:14] ++ va[13:0];

}

transaction CPU.Read {

register int<30> pa;

%Walk(addr, pa);

Memory.Read[[pa, data]];

}

Memory

addr

data

CPU

addr

data

Read

Type-checked macros minimize duplication.

NICTA Copyright c© 2011 From Imagination to Impact 29

Page 47: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Memory

VSR

CPU

RAM

Memory

CPU

MMU

module mmu; cycle {}

macro Walk(int<30> va, int<30> &pa) {

register int<32> entry;

vpn= va[29:14];

Memory.Read[[vpn zext 30,entry]];

pa<- entry[29:14] ++ va[13:0];

}

transaction CPU.Read {

register int<30> pa;

%Walk(addr, pa);

Memory.Read(pa, data);

}

Memory

addr

data

CPU

addr

data

module mmu; cycle {}

macro Walk(int<30> va, int<30> &pa) {

register int<32> entry;

vpn= va[29:14];

Memory.Read[[vpn zext 30,entry]];

pa<- entry[29:14] ++ va[13:0];

}

transaction CPU.Read {

register int<30> pa;

%Walk(addr, pa);

Memory.Read[[pa, data]];

}

Memory

addr

data

CPU

addr

data

Read

Transactions are implemented by modules.

NICTA Copyright c© 2011 From Imagination to Impact 30

Page 48: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

ARMv6 Model:

We have an ARMv6 user-level integer instruction model.

Floating-point and vector operations are excluded.

The complete model is approximately 1600 lines.

We used it to validate the seL4 Haskell prototype.

NICTA Copyright c© 2011 From Imagination to Impact 31

Page 49: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

LLyre

bir

d

λ

Simulator

Simulation:

Register transfer is easy to simulate.

The simulator is portable and fast — 10MIPS for ARMv6 user.

The output is a single C module;

It is easily incorporated into larger simulations.

NICTA Copyright c© 2011 From Imagination to Impact 32

Page 50: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

LLyre

bir

d

λ

Formal Hardware Model

Generated Models:

An Isabelle model is generated by a tool.

We co-generate code and proofs for kernel objects.

We should be able to do the same for device structures.

NICTA Copyright c© 2011 From Imagination to Impact 33

Page 51: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Lyrebird

Abstract

Haskell

C

Machine M

onad

MSR

Sim

ulator

User C

ode

LLyre

bir

d

λ

ARMv6

Rapid Modelling and Early Simulation:

We ran real user code against the Haskell seL4 model.

We found bugs in both the machine model and the kernel.

We tested the model against the implementation;

We fixed things before we tried to prove them.

NICTA Copyright c© 2011 From Imagination to Impact 34

Page 52: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Project Status

Goals:

➜ Development outcomes: program, proof and model.

➜ Updating the model should be easy.

➜ Easy things should be straightforward.

➜ Hard things should be possible.

NICTA Copyright c© 2011 From Imagination to Impact 35

Page 53: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Project Status

Goals:

➜ Development outcomes: program, proof and model.

Yes - The model is generated automatically.

➜ Updating the model should be easy.

➜ Easy things should be straightforward.

➜ Hard things should be possible.

NICTA Copyright c© 2011 From Imagination to Impact 35

Page 54: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Project Status

Goals:

➜ Development outcomes: program, proof and model.

Yes - The model is generated automatically.

➜ Updating the model should be easy.

Yes - Recompile for a new formal model.

➜ Easy things should be straightforward.

➜ Hard things should be possible.

NICTA Copyright c© 2011 From Imagination to Impact 35

Page 55: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Project Status

Goals:

➜ Development outcomes: program, proof and model.

Yes - The model is generated automatically.

➜ Updating the model should be easy.

Yes - Recompile for a new formal model.

➜ Easy things should be straightforward.

Yes - User-level ARMv6 in 1600 lines.

➜ Hard things should be possible.

NICTA Copyright c© 2011 From Imagination to Impact 35

Page 56: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Project Status

Goals:

➜ Development outcomes: program, proof and model.

Yes - The model is generated automatically.

➜ Updating the model should be easy.

Yes - Recompile for a new formal model.

➜ Easy things should be straightforward.

Yes - User-level ARMv6 in 1600 lines.

➜ Hard things should be possible.

Maybe - Work is ongoing.

NICTA Copyright c© 2011 From Imagination to Impact 35

Page 57: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Future Work

Semantics:

Model generation is not ideal, the generator is trusted.

A statement’s meaning should be intrinsic.

Building a semantics early will force discipline.

Underspecification:

Behaviour is often undefined or non-deterministic.

Should be modelled by underspecification and assertions.

NICTA Copyright c© 2011 From Imagination to Impact 36

Page 58: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

Future Work

The Abstract Model Stack:

We should end up with a very detailed model of the machine.

We’d rather reason about a simple, abstract machine.

We’ll build the simpler model in layers.

Validation:

Any model must be extensively validated against hardware.

It must also be consistent with existing models e.g. Fox et. al.

Many models exist in different formalisms, this is a challenge.

NICTA Copyright c© 2011 From Imagination to Impact 37

Page 59: davec@cse.unsw.eduresearch.davidcock.fastmail.fm/slides/lyrebird.pdfLyrebird Memory VSR CPU RAM Memory CPU MMU module mmu; cycle {} macro Walk(int va, int &pa)

QUESTIONS?

NICTA Copyright c© 2011 From Imagination to Impact 38