2010-06-07 00:03:25 +03:00
|
|
|
#pypp 0
|
|
|
|
#include <iris.hh>
|
|
|
|
#include <devices.hh>
|
|
|
|
|
|
|
|
#define NUM_PARTITIONS 4
|
|
|
|
#define SECTOR_BITS 9
|
|
|
|
#define BLOCK_MASK (~((1 << SECTOR_BITS) - 1))
|
|
|
|
|
2010-06-22 21:55:02 +03:00
|
|
|
unsigned bits
|
|
|
|
|
2010-06-07 00:03:25 +03:00
|
|
|
struct Partition:
|
|
|
|
static Iris::Num device_size
|
|
|
|
unsigned lba_start, lba_size
|
|
|
|
unsigned type
|
|
|
|
bool active
|
|
|
|
Iris::Num start, size
|
|
|
|
static unsigned read_num (char *data):
|
|
|
|
return data[0] & 0xff | (data[1] & 0xff) << 8 | (data[2] & 0xff) << 16 | (data[3] & 0xff) << 24
|
|
|
|
void read (char *data):
|
|
|
|
if data[0] == 0:
|
|
|
|
active = false
|
|
|
|
else:
|
|
|
|
active = true
|
|
|
|
if (data[0] & 0xff) != 0x80:
|
|
|
|
kdebug ("Warning: invalid active code ")
|
|
|
|
kdebug_num (data[0], 2)
|
|
|
|
kdebug ("\n")
|
|
|
|
type = data[4] & 0xff
|
|
|
|
lba_start = read_num (data + 8)
|
|
|
|
lba_size = read_num (data + 12)
|
|
|
|
start = Iris::Num (lba_start).value () << SECTOR_BITS
|
|
|
|
size = Iris::Num (lba_size).value () << SECTOR_BITS
|
2010-06-22 21:55:02 +03:00
|
|
|
kdebug ("Partition read: ")
|
|
|
|
kdebug_num (lba_start)
|
|
|
|
kdebug ("+")
|
|
|
|
kdebug_num (lba_size)
|
|
|
|
kdebug ("\n")
|
2010-06-07 00:03:25 +03:00
|
|
|
|
|
|
|
Iris::Num Partition::device_size
|
|
|
|
|
2010-09-02 00:27:14 +03:00
|
|
|
static Iris::WBlock dev
|
2010-06-22 21:55:02 +03:00
|
|
|
static void read_sector (Iris::Num idx, Iris::Page page, unsigned size = 1 << SECTOR_BITS, unsigned offset = 0):
|
2010-06-07 00:03:25 +03:00
|
|
|
offset &= ~PAGE_MASK
|
|
|
|
if size + offset > PAGE_SIZE:
|
|
|
|
size = PAGE_SIZE - offset
|
|
|
|
size >>= SECTOR_BITS
|
2010-06-22 21:55:02 +03:00
|
|
|
idx = idx.value () >> SECTOR_BITS
|
2010-06-07 00:03:25 +03:00
|
|
|
for unsigned i = 0; i < size; ++i:
|
|
|
|
dev.get_block ((idx.value () + i) << SECTOR_BITS, 1 << SECTOR_BITS, (i << SECTOR_BITS) + offset, page)
|
|
|
|
|
|
|
|
Iris::Num start ():
|
|
|
|
Partition::device_size = 0
|
2010-09-02 00:27:14 +03:00
|
|
|
dev = Iris::my_parent.get_capability <Iris::WBlock> ()
|
2010-06-22 21:55:02 +03:00
|
|
|
bits = dev.get_align_bits ()
|
|
|
|
if bits > SECTOR_BITS:
|
|
|
|
Iris::panic (bits, "partitioned device doesn't support 512 byte access\n")
|
2010-06-07 00:03:25 +03:00
|
|
|
Partition::device_size = dev.get_size ()
|
|
|
|
Iris::Page page = Iris::my_memory.create_page ()
|
2010-06-22 21:55:02 +03:00
|
|
|
page.set_flags (Iris::Page::PAYING)
|
2010-06-07 00:03:25 +03:00
|
|
|
char *buffer = (char *)0x15000
|
|
|
|
unsigned *ubuffer = (unsigned *)buffer
|
|
|
|
Iris::my_memory.map (page, (unsigned)buffer)
|
2010-06-22 21:55:02 +03:00
|
|
|
read_sector (0, page)
|
2010-06-07 00:03:25 +03:00
|
|
|
|
|
|
|
if buffer[0x1fe] != 0x55 || (buffer[0x1ff] & 0xff) != 0xaa:
|
|
|
|
kdebug ("invalid mbr signature\n")
|
|
|
|
|
|
|
|
Partition partition[NUM_PARTITIONS]
|
|
|
|
|
|
|
|
Iris::Cap cap
|
|
|
|
for unsigned i = 0; i < NUM_PARTITIONS; ++i:
|
|
|
|
partition[i].read (buffer + 0x1be + 0x10 * i)
|
|
|
|
cap = Iris::my_receiver.create_capability (i)
|
2010-09-02 00:27:14 +03:00
|
|
|
Iris::my_parent.provide_capability <Iris::WBlock> (cap.copy (), i)
|
2010-06-07 00:03:25 +03:00
|
|
|
Iris::free_cap (cap)
|
|
|
|
|
|
|
|
page.set_flags (0, Iris::Page::PAYING | Iris::Page::FRAME)
|
|
|
|
|
|
|
|
Iris::my_parent.init_done ()
|
|
|
|
|
|
|
|
while true:
|
|
|
|
Iris::wait ()
|
2010-06-22 21:55:02 +03:00
|
|
|
//kdebug ("partition received: ")
|
|
|
|
//kdebug_num (Iris::recv.data[0].l)
|
|
|
|
//kdebug ("\n")
|
2010-06-07 00:03:25 +03:00
|
|
|
switch Iris::recv.data[0].l:
|
2010-09-02 00:27:14 +03:00
|
|
|
case Iris::Block::GET_SIZE:
|
2010-06-07 00:03:25 +03:00
|
|
|
Iris::recv.reply.invoke (partition[Iris::recv.protected_data.l].size)
|
|
|
|
break
|
2010-09-02 00:27:14 +03:00
|
|
|
case Iris::Block::GET_ALIGN_BITS:
|
2010-06-07 00:03:25 +03:00
|
|
|
Iris::recv.reply.invoke (SECTOR_BITS)
|
|
|
|
break
|
2010-09-02 00:27:14 +03:00
|
|
|
case Iris::Block::GET_BLOCK:
|
2010-06-07 00:03:25 +03:00
|
|
|
Iris::Cap reply = Iris::get_reply ()
|
|
|
|
Iris::Cap arg = Iris::get_arg ()
|
|
|
|
Iris::Num p = Iris::recv.data[1].value () & BLOCK_MASK
|
|
|
|
Iris::Num offset = partition[Iris::recv.protected_data.l].start.value ()
|
|
|
|
unsigned size = Iris::recv.data[0].h >> 16
|
|
|
|
unsigned out_offset = Iris::recv.data[0].h & 0xffff
|
|
|
|
//kdebug ("partition sending sector ")
|
|
|
|
//kdebug_num (offset.h)
|
|
|
|
//kdebug (":")
|
|
|
|
//kdebug_num (offset.l)
|
|
|
|
//kdebug (" + ")
|
|
|
|
//kdebug_num (p.h)
|
|
|
|
//kdebug (":")
|
|
|
|
//kdebug_num (p.l)
|
|
|
|
//kdebug (" = ")
|
|
|
|
//kdebug_num (Iris::Num (offset.value () + p.value ()).h)
|
|
|
|
//kdebug (":")
|
|
|
|
//kdebug_num (Iris::Num (offset.value () + p.value ()).l)
|
|
|
|
//kdebug ("\n")
|
2010-06-22 21:55:02 +03:00
|
|
|
read_sector (offset.value () + p.value (), arg, size, out_offset)
|
2010-06-07 00:03:25 +03:00
|
|
|
reply.invoke ()
|
|
|
|
Iris::free_cap (reply)
|
|
|
|
Iris::free_cap (arg)
|
|
|
|
break
|
2010-09-02 00:27:14 +03:00
|
|
|
case Iris::WBlock::SET_BLOCK:
|
2010-06-07 00:03:25 +03:00
|
|
|
Iris::panic (Iris::recv.data[0].l, "writing to partitions not supported yet")
|
2010-09-02 00:27:14 +03:00
|
|
|
case Iris::WBlock::TRUNCATE:
|
2010-06-07 00:03:25 +03:00
|
|
|
default:
|
|
|
|
Iris::panic (Iris::recv.data[0].l, "invalid request for partition handler")
|