1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2025-04-21 12:27:27 +03:00
This commit is contained in:
Bas Wijnen
2009-05-27 18:33:05 +02:00
parent 35fb72c239
commit 305bc03711
9 changed files with 337 additions and 121 deletions

View File

@@ -8,29 +8,27 @@ extern "C" {
#define KERNEL_MASK 0xfff
#define CAPTYPE_MASK 0xe00
#define REQUEST_MASK (KERNEL_MASK & ~CAPTYPE_MASK)
#define CAPTYPE_ADMIN 0x000
#define CAPTYPE_RECEIVER 0x200
#define CAPTYPE_MEMORY 0x400
#define CAPTYPE_THREAD 0x600
#define CAPTYPE_PAGE 0x800
#define CAPTYPE_CAPABILITY 0xa00
#define CAPTYPE_CAPPAGE 0xc00
#define CAPTYPE_RECEIVER 0x000
#define CAPTYPE_MEMORY 0x200
#define CAPTYPE_THREAD 0x400
#define CAPTYPE_PAGE 0x600
#define CAPTYPE_CAPABILITY 0x800
#define CAPTYPE_CAPPAGE 0xa00
/*#define CAPTYPE_??? 0xc00*/
/*#define CAPTYPE_??? 0xe00*/
/* This works on all kernel capabilities. */
#define CAP_DEGRADE 0
/* Operations */
#define CAP_ADMIN_SCHEDULE 1
/* TODO: add priviledged operations. */
#define CAP_RECEIVER_SET_OWNER 1
#define CAP_RECEIVER_CREATE_CAPABILITY 2
#define CAP_RECEIVER_CREATE_CALL_CAPABILITY 3
#define CAP_RECEIVER_ALL_RIGHTS 0x7f
/* Not an operation; a capability with this bit set is a call capability. */
#define CAP_RECEIVER_CALL 8
#define CAP_RECEIVER_CALL 7
/* Same thing for reply capability. */
#define CAP_RECEIVER_REPLY 9
#define CAP_RECEIVER_REPLY 8
#define CAP_MEMORY_CREATE 1
#define CAP_MEMORY_DESTROY 2
@@ -39,10 +37,20 @@ extern "C" {
#define CAP_MEMORY_SET_LIMIT 5
#define CAP_MEMORY_GET_LIMIT 6
#define CAP_MEMORY_DROP 7
#define CAP_MEMORY_ALL_RIGHTS 0x1ff
#define CAP_THREAD_RUN 1
#define CAP_THREAD_GET_INFO 2 /* Details of this are arch-specific. */
#define CAP_THREAD_SET_INFO 3 /* Details of this are arch-specific. */
#define CAP_THREAD_GET_INFO 1 /* Details of this are arch-specific. */
#define CAP_THREAD_SET_INFO 2 /* Details of this are arch-specific. */
#define CAP_THREAD_SCHEDULE 3
#define CAP_THREAD_GET_TOP_MEMORY 7
#define CAP_THREAD_REGISTER_INTERRUPT 8
#define CAP_THREAD_ALL_RIGHTS 0xff
#define CAP_THREAD_ALL_PRIV_RIGHTS (CAP_THREAD_ALL_RIGHTS | (1 << CAP_THREAD_REGISTER_INTERRUPT) | (1 << CAP_THREAD_GET_TOP_MEMORY))
/* These get/set_info are not arch-specific. */
#define CAP_THREAD_INFO_PC 0
#define CAP_THREAD_INFO_SP 1
#define CAP_THREAD_INFO_FLAGS 2
/* Flag values for processor state */
#define THREAD_FLAG_WAITING 0x80000000
#define THREAD_FLAG_RUNNING 0x40000000
@@ -55,19 +63,22 @@ extern "C" {
#define CAP_PAGE_FORGET 4
// Not an operation; a capability without this bit cannot write to the page. */
#define CAP_PAGE_WRITE 5
#define CAP_PAGE_ALL_RIGHTS 0x1ff
#define CAP_CAPABILITY_GET 1
#define CAP_CAPABILITY_SET_DEATH_NOTIFY 2
#define CAP_CAPABILITY_ALL_RIGHTS 0x1ff
#define CAPPAGE_SIZE 102
/* Cappage has page's operations as well. */
#define CAP_CAPPAGE_SET 6
#define CAP_CAPPAGE_ALL_RIGHTS 0x1ff
#ifndef __KERNEL
typedef unsigned __Capability;
extern __Capability __my_receiver;
extern __Capability __my_admin;
extern __Capability __my_thread;
extern __Capability __my_memory;
extern __Capability __my_call;
@@ -139,6 +150,17 @@ static int __invoke_02 (__Capability t, unsigned d0, unsigned d1)
return __invoke (t, &msg);
}
static int __invoke_04 (__Capability t, unsigned d0, unsigned d1, unsigned d2, unsigned d3)
{
__Message msg;
int ret;
msg.data[0] = d0;
msg.data[1] = d1;
msg.data[2] = d2;
msg.data[3] = d3;
return __invoke (t, &msg);
}
static int __invoke_11 (__Capability t, __Capability c, unsigned d)
{
__Message msg;
@@ -179,6 +201,17 @@ static __Capability __call_c02 (__Capability c, unsigned d0, unsigned d1)
return ret ? msg.cap[0] : 0;
}
static unsigned __call_n02 (__Capability c, unsigned d0, unsigned d1)
{
__Message msg;
int ret;
msg.cap[0] = c;
msg.data[0] = d0;
msg.data[1] = d1;
ret = __call (__my_call, &msg);
return ret ? msg.data[0] : 0;
}
static __Capability __degrade (__Capability src, unsigned mask)
{
return __call_c02 (src, CAP_DEGRADE, mask);
@@ -186,7 +219,22 @@ static __Capability __degrade (__Capability src, unsigned mask)
static void __schedule ()
{
__invoke_01 (__my_admin, CAP_ADMIN_SCHEDULE);
__invoke_01 (__my_thread, CAP_THREAD_SCHEDULE);
}
static void __register_interrupt (unsigned num)
{
__invoke_12 (__my_thread, __my_receiver, CAP_THREAD_REGISTER_INTERRUPT, num);
}
static __Capability __get_top_memory ()
{
return __call_c01 (__my_thread, CAP_THREAD_GET_TOP_MEMORY);
}
static void __unregister_interrupt (unsigned num)
{
__invoke_02 (__my_thread, CAP_THREAD_REGISTER_INTERRUPT, num);
}
static int __receiver_set_owner (__Capability receiver, __Capability owner)
@@ -251,17 +299,57 @@ static void __drop (__Capability cap)
__invoke_11 (__my_memory, cap, CAP_MEMORY_DROP);
}
static int __thread_run (__Capability thread, int run)
static int __thread_set_info (__Capability thread, unsigned info, unsigned value, unsigned mask)
{
return __invoke_02 (thread, CAP_THREAD_RUN, run);
return __invoke_04 (thread, CAP_THREAD_SET_INFO, info, value, mask);
}
/* TODO:
#define CAP_THREAD_GET_INFO 4
#define CAP_THREAD_SET_INFO 5
*/
static int __thread_set_pc (__Capability thread, unsigned pc)
{
return __thread_set_info (thread, CAP_THREAD_INFO_PC, pc, ~0);
}
/* TODO: all except map should also work for cappages.
static int __thread_set_sp (__Capability thread, unsigned sp)
{
return __thread_set_info (thread, CAP_THREAD_INFO_SP, sp, ~0);
}
static int __thread_set_flags (__Capability thread, unsigned value, unsigned mask)
{
return __thread_set_info (thread, CAP_THREAD_INFO_FLAGS, value, mask);
}
static int __thread_run (__Capability thread, int run)
{
return __thread_set_flags (thread, run ? THREAD_FLAG_RUNNING : 0, THREAD_FLAG_RUNNING);
}
static int __thread_wait (__Capability thread, int wait)
{
return __thread_set_flags (thread, wait ? THREAD_FLAG_WAITING : 0, THREAD_FLAG_WAITING);
}
static unsigned __thread_get_info (__Capability thread, unsigned info)
{
return __call_n02 (thread, CAP_THREAD_GET_INFO, info);
}
static unsigned __thread_get_pc (__Capability thread)
{
return __thread_get_info (thread, CAP_THREAD_INFO_PC);
}
static unsigned __thread_get_sp (__Capability thread)
{
return __thread_get_info (thread, CAP_THREAD_INFO_SP);
}
static unsigned __thread_get_flags (__Capability thread)
{
return __thread_get_info (thread, CAP_THREAD_INFO_FLAGS);
}
/* TODO. All except map should also work for cappages.
#define CAP_PAGE_MAP 1
#define CAP_PAGE_SHARE 2
#define CAP_PAGE_SHARE_COW 3