2009-06-01 15:26:42 +03:00
|
|
|
/* Iris: micro-kernel for a capability-based operating system.
|
|
|
|
* iris.h: C header file for userspace programs.
|
|
|
|
* Copyright 2009 Bas Wijnen <wijnen@debian.org>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef __IRIS_H
|
|
|
|
#define __IRIS_H
|
2009-05-22 23:48:49 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2009-06-08 14:46:13 +03:00
|
|
|
#define PAGE_BITS (12)
|
|
|
|
#define PAGE_SIZE (1 << PAGE_BITS)
|
|
|
|
#define PAGE_MASK (~(PAGE_SIZE - 1))
|
|
|
|
|
2009-05-22 23:48:49 +03:00
|
|
|
#define KERNEL_MASK 0xfff
|
|
|
|
#define CAPTYPE_MASK 0xe00
|
2009-05-25 01:31:35 +03:00
|
|
|
#define REQUEST_MASK (KERNEL_MASK & ~CAPTYPE_MASK)
|
2009-05-27 19:33:05 +03:00
|
|
|
#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*/
|
2009-05-22 23:48:49 +03:00
|
|
|
/*#define CAPTYPE_??? 0xe00*/
|
|
|
|
|
|
|
|
/* This works on all kernel capabilities. */
|
|
|
|
#define CAP_DEGRADE 0
|
|
|
|
|
|
|
|
/* Operations */
|
|
|
|
#define CAP_RECEIVER_SET_OWNER 1
|
|
|
|
#define CAP_RECEIVER_CREATE_CAPABILITY 2
|
|
|
|
#define CAP_RECEIVER_CREATE_CALL_CAPABILITY 3
|
2009-06-01 02:12:54 +03:00
|
|
|
#define CAP_RECEIVER_GET_REPLY_PROTECTED_DATA 4
|
|
|
|
#define CAP_RECEIVER_SET_REPLY_PROTECTED_DATA 5
|
2009-05-27 19:33:05 +03:00
|
|
|
#define CAP_RECEIVER_ALL_RIGHTS 0x7f
|
2009-05-25 01:31:35 +03:00
|
|
|
/* Not an operation; a capability with this bit set is a call capability. */
|
2009-05-27 19:33:05 +03:00
|
|
|
#define CAP_RECEIVER_CALL 7
|
2009-05-27 15:38:52 +03:00
|
|
|
/* Same thing for reply capability. */
|
2009-05-27 19:33:05 +03:00
|
|
|
#define CAP_RECEIVER_REPLY 8
|
2009-06-01 02:12:54 +03:00
|
|
|
/* If set on a call capability, waiting for only this reply is disabled. */
|
|
|
|
#define CAP_RECEIVER_CALL_ASYNC 1
|
2009-05-22 23:48:49 +03:00
|
|
|
|
|
|
|
#define CAP_MEMORY_CREATE 1
|
|
|
|
#define CAP_MEMORY_DESTROY 2
|
|
|
|
#define CAP_MEMORY_LIST 3
|
2009-06-01 02:12:54 +03:00
|
|
|
#define CAP_MEMORY_MAP 4
|
|
|
|
#define CAP_MEMORY_MAPPING 5
|
|
|
|
#define CAP_MEMORY_SET_LIMIT 6
|
|
|
|
#define CAP_MEMORY_GET_LIMIT 7
|
|
|
|
#define CAP_MEMORY_DROP 8
|
2009-05-27 19:33:05 +03:00
|
|
|
#define CAP_MEMORY_ALL_RIGHTS 0x1ff
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
#define CAP_THREAD_INFO 1 /* Details of this are arch-specific. */
|
|
|
|
#define CAP_THREAD_SCHEDULE 2
|
2009-06-01 20:22:11 +03:00
|
|
|
#define CAP_THREAD_DEBUG 3
|
|
|
|
#define CAP_THREAD_ALLOC_PHYSICAL 5
|
2009-06-01 02:12:54 +03:00
|
|
|
#define CAP_THREAD_MAKE_PRIV 6
|
2009-05-27 19:33:05 +03:00
|
|
|
#define CAP_THREAD_GET_TOP_MEMORY 7
|
|
|
|
#define CAP_THREAD_REGISTER_INTERRUPT 8
|
2009-06-01 20:22:11 +03:00
|
|
|
#define CAP_THREAD_ALL_RIGHTS 0x1f
|
|
|
|
#define CAP_THREAD_ALL_PRIV_RIGHTS (CAP_THREAD_ALL_RIGHTS | (1 << CAP_THREAD_REGISTER_INTERRUPT) | (1 << CAP_THREAD_GET_TOP_MEMORY) | (1 << CAP_THREAD_MAKE_PRIV) | (1 << CAP_THREAD_ALLOC_PHYSICAL))
|
2009-05-27 19:33:05 +03:00
|
|
|
|
|
|
|
/* These get/set_info are not arch-specific. */
|
2009-05-27 20:29:21 +03:00
|
|
|
#define CAP_THREAD_INFO_PC ~0
|
|
|
|
#define CAP_THREAD_INFO_SP ~1
|
|
|
|
#define CAP_THREAD_INFO_FLAGS ~2
|
2009-07-04 17:21:28 +03:00
|
|
|
#define CAP_THREAD_INFO_SLEEP ~3
|
2009-05-25 01:31:35 +03:00
|
|
|
/* Flag values for processor state */
|
2009-06-01 02:12:54 +03:00
|
|
|
#define THREAD_FLAG_PRIV 0x80000000
|
|
|
|
#define THREAD_FLAG_WAITING 0x40000000
|
|
|
|
#define THREAD_FLAG_RUNNING 0x20000000
|
2009-05-27 15:38:52 +03:00
|
|
|
#define THREAD_FLAG_USER 0x1fffffff
|
2009-05-22 23:48:49 +03:00
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
#define CAP_PAGE_SHARE 1
|
|
|
|
#define CAP_PAGE_FLAGS 2
|
2009-05-29 00:35:27 +03:00
|
|
|
/* Not an operation; a capability without this bit cannot write to the page. */
|
2009-06-01 02:12:54 +03:00
|
|
|
#define CAP_PAGE_WRITE 3
|
2009-05-27 19:33:05 +03:00
|
|
|
#define CAP_PAGE_ALL_RIGHTS 0x1ff
|
2009-06-01 02:12:54 +03:00
|
|
|
|
|
|
|
/* Operation details for PAGE_SHARE */
|
|
|
|
/* Forget the source page during the operation. This makes it a move. */
|
|
|
|
#define PAGE_SHARE_FORGET 0x10000
|
|
|
|
/* Make the target unwritable. */
|
|
|
|
#define PAGE_SHARE_READONLY 0x20000
|
|
|
|
/* Make the target independent of the source (make a copy if needed). */
|
|
|
|
#define PAGE_SHARE_COPY 0x40000
|
|
|
|
|
2009-05-29 00:35:27 +03:00
|
|
|
/* Flag values for Page and Cappage objects. */
|
|
|
|
/* A writable page can be written to. This flag can not be set while the frame is shared. */
|
|
|
|
#define PAGE_FLAG_WRITABLE 1
|
2009-06-08 14:46:13 +03:00
|
|
|
/* When paying, the memory's use is incremented. If a frame is held, it cannot be lost. Frames are lost when the last payer forgets them. */
|
2009-05-29 00:35:27 +03:00
|
|
|
#define PAGE_FLAG_PAYING 2
|
2009-06-01 02:12:54 +03:00
|
|
|
/* Set if this page has a frame associated with it. This flag is automatically reset if the frame is lost because of payment problems. */
|
|
|
|
#define PAGE_FLAG_FRAME 4
|
2009-05-29 00:35:27 +03:00
|
|
|
/* This is a read-only flag, which is set if the Page is shared. */
|
|
|
|
#define PAGE_FLAG_SHARED 8
|
2009-06-08 14:46:13 +03:00
|
|
|
/* This is a read-only flag, saying if this is physical memory, which mustn't be freed. */
|
|
|
|
#define PAGE_FLAG_PHYSICAL 0x10
|
|
|
|
/* This is a read-only flag, saying if this is uncachable memory. */
|
|
|
|
#define PAGE_FLAG_UNCACHED 0x20
|
2009-05-22 23:48:49 +03:00
|
|
|
|
|
|
|
#define CAP_CAPABILITY_GET 1
|
2009-05-27 19:33:05 +03:00
|
|
|
#define CAP_CAPABILITY_ALL_RIGHTS 0x1ff
|
2009-05-22 23:48:49 +03:00
|
|
|
|
2009-05-25 01:31:35 +03:00
|
|
|
#define CAPPAGE_SIZE 102
|
2009-06-01 02:12:54 +03:00
|
|
|
/* Cappage has Page's operations as well. */
|
|
|
|
#define CAP_CAPPAGE_SET 4
|
2009-05-27 19:33:05 +03:00
|
|
|
#define CAP_CAPPAGE_ALL_RIGHTS 0x1ff
|
2009-05-25 01:31:35 +03:00
|
|
|
|
|
|
|
#ifndef __KERNEL
|
2009-06-01 02:12:54 +03:00
|
|
|
typedef unsigned Capability;
|
2009-05-25 01:31:35 +03:00
|
|
|
|
2009-06-01 20:22:11 +03:00
|
|
|
extern Capability __my_receiver;
|
|
|
|
extern Capability __my_thread;
|
|
|
|
extern Capability __my_memory;
|
|
|
|
extern Capability __my_call;
|
2009-05-25 01:31:35 +03:00
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
Capability cap_copy (Capability src)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
|
|
|
return src | 2;
|
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
typedef struct Message
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
|
|
|
unsigned data[4];
|
2009-06-01 02:12:54 +03:00
|
|
|
Capability cap[4];
|
2009-06-10 22:42:01 +03:00
|
|
|
unsigned protected_data; /* only used for receiving. */
|
2009-06-01 02:12:54 +03:00
|
|
|
} Message;
|
2009-05-25 01:31:35 +03:00
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static int invoke (Capability target, Message *msg)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-08 14:46:13 +03:00
|
|
|
unsigned ret;
|
|
|
|
__asm__ volatile ("lw $v0, %1\n"
|
|
|
|
"\tlw $a3, %2\n"
|
|
|
|
"\tlw $t0, 0($a3)\n"
|
|
|
|
"\tlw $t1, 4($a3)\n"
|
|
|
|
"\tlw $t2, 8($a3)\n"
|
|
|
|
"\tlw $t3, 12($a3)\n"
|
|
|
|
"\tlw $a0, 16($a3)\n"
|
|
|
|
"\tlw $a1, 20($a3)\n"
|
|
|
|
"\tlw $a2, 24($a3)\n"
|
|
|
|
"\tlw $a3, 28($a3)\n"
|
|
|
|
"\tsyscall\n"
|
|
|
|
"\tmove %0, $v0"
|
|
|
|
: "=r"(ret)
|
|
|
|
: "m"(target), "m"(msg)
|
|
|
|
: "v0", "t0", "t1", "t2", "t3", "a0", "a1", "a2", "a3");
|
2009-05-25 01:31:35 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-10 22:42:01 +03:00
|
|
|
static int wait (Message *msg)
|
2009-06-08 14:46:13 +03:00
|
|
|
{
|
2009-06-10 22:42:01 +03:00
|
|
|
int ret;
|
2009-06-08 14:46:13 +03:00
|
|
|
__asm__ volatile ("li $v0, 2\n"
|
|
|
|
"\tsyscall\n"
|
2009-06-10 22:42:01 +03:00
|
|
|
"\tsw $v0, %0\n"
|
|
|
|
"\tlw $v0, %1\n"
|
|
|
|
"\tsw $t0, 0($v0)\n"
|
|
|
|
"\tsw $t1, 4($v0)\n"
|
|
|
|
"\tsw $t2, 8($v0)\n"
|
|
|
|
"\tsw $t3, 12($v0)\n"
|
|
|
|
"\tsw $a0, 16($v0)\n"
|
|
|
|
"\tsw $a1, 20($v0)\n"
|
|
|
|
"\tsw $a2, 24($v0)\n"
|
|
|
|
"\tsw $a3, 28($v0)\n"
|
|
|
|
"\tsw $v1, 32($v0)"
|
|
|
|
: "=m"(ret)
|
2009-06-08 14:46:13 +03:00
|
|
|
: "m"(msg)
|
|
|
|
: "memory", "v0", "v1", "t0", "t1", "t2", "t3", "a0", "a1", "a2", "a3");
|
2009-06-10 23:54:12 +03:00
|
|
|
return ret;
|
2009-06-08 14:46:13 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static int call (Capability target, Message *msg)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-08 14:46:13 +03:00
|
|
|
unsigned ret;
|
|
|
|
Capability t = cap_copy (target);
|
|
|
|
__asm__ volatile ("lw $v0, %1\n"
|
|
|
|
"\tlw $v1, %2\n"
|
|
|
|
"\tlw $t0, 0($v1)\n"
|
|
|
|
"\tlw $t1, 4($v1)\n"
|
|
|
|
"\tlw $t2, 8($v1)\n"
|
|
|
|
"\tlw $t3, 12($v1)\n"
|
|
|
|
"\tlw $a0, 16($v1)\n"
|
|
|
|
"\tlw $a1, 20($v1)\n"
|
|
|
|
"\tlw $a2, 24($v1)\n"
|
|
|
|
"\tlw $a3, 28($v1)\n"
|
|
|
|
"\tsyscall\n"
|
2009-06-10 22:42:01 +03:00
|
|
|
"\tsw $v0, %0\n"
|
|
|
|
"\tlw $v0, %2\n"
|
|
|
|
"\tsw $t0, 0($v0)\n"
|
|
|
|
"\tsw $t1, 4($v0)\n"
|
|
|
|
"\tsw $t2, 8($v0)\n"
|
|
|
|
"\tsw $t3, 12($v0)\n"
|
|
|
|
"\tsw $a0, 16($v0)\n"
|
|
|
|
"\tsw $a1, 20($v0)\n"
|
|
|
|
"\tsw $a2, 24($v0)\n"
|
|
|
|
"\tsw $a3, 28($v0)\n"
|
|
|
|
"\tsw $v1, 32($v0)"
|
|
|
|
: "=m"(ret)
|
2009-06-08 14:46:13 +03:00
|
|
|
: "m"(t), "m"(msg)
|
|
|
|
: "memory", "v0", "v1", "t0", "t1", "t2", "t3", "a0", "a1", "a2", "a3");
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static int invoke_01 (Capability t, unsigned d)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
Message msg;
|
2009-05-25 01:31:35 +03:00
|
|
|
int ret;
|
|
|
|
msg.data[0] = d;
|
2009-06-01 02:12:54 +03:00
|
|
|
return invoke (t, &msg);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static int invoke_02 (Capability t, unsigned d0, unsigned d1)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
Message msg;
|
2009-05-25 01:31:35 +03:00
|
|
|
int ret;
|
|
|
|
msg.data[0] = d0;
|
|
|
|
msg.data[1] = d1;
|
2009-06-01 02:12:54 +03:00
|
|
|
return invoke (t, &msg);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static int invoke_04 (Capability t, unsigned d0, unsigned d1, unsigned d2, unsigned d3)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
Message msg;
|
2009-05-27 19:33:05 +03:00
|
|
|
int ret;
|
|
|
|
msg.data[0] = d0;
|
|
|
|
msg.data[1] = d1;
|
|
|
|
msg.data[2] = d2;
|
|
|
|
msg.data[3] = d3;
|
2009-06-01 02:12:54 +03:00
|
|
|
return invoke (t, &msg);
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static int invoke_11 (Capability t, Capability c, unsigned d)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
Message msg;
|
2009-05-25 01:31:35 +03:00
|
|
|
int ret;
|
|
|
|
msg.cap[0] = c;
|
|
|
|
msg.data[0] = d;
|
2009-06-01 02:12:54 +03:00
|
|
|
return invoke (t, &msg);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static int invoke_12 (Capability t, Capability c, unsigned d0, unsigned d1)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
Message msg;
|
2009-05-25 01:31:35 +03:00
|
|
|
int ret;
|
|
|
|
msg.cap[0] = c;
|
|
|
|
msg.data[0] = d0;
|
|
|
|
msg.data[1] = d1;
|
2009-06-01 02:12:54 +03:00
|
|
|
return invoke (t, &msg);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability call_c01 (Capability c, unsigned d)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
Message msg;
|
2009-05-25 01:31:35 +03:00
|
|
|
int ret;
|
|
|
|
msg.cap[0] = c;
|
|
|
|
msg.data[0] = d;
|
2009-06-01 20:22:11 +03:00
|
|
|
ret = call (__my_call, &msg);
|
2009-05-25 01:31:35 +03:00
|
|
|
return ret ? msg.cap[0] : 0;
|
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability call_c02 (Capability c, unsigned d0, unsigned d1)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
Message msg;
|
2009-05-25 01:31:35 +03:00
|
|
|
int ret;
|
|
|
|
msg.cap[0] = c;
|
|
|
|
msg.data[0] = d0;
|
|
|
|
msg.data[1] = d1;
|
2009-06-01 20:22:11 +03:00
|
|
|
ret = call (__my_call, &msg);
|
2009-05-25 01:31:35 +03:00
|
|
|
return ret ? msg.cap[0] : 0;
|
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability call_c12 (Capability c, Capability c1, unsigned d0, unsigned d1)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
Message msg;
|
2009-05-27 19:33:05 +03:00
|
|
|
int ret;
|
|
|
|
msg.cap[0] = c;
|
2009-06-01 02:12:54 +03:00
|
|
|
msg.cap[1] = c1;
|
2009-05-27 19:33:05 +03:00
|
|
|
msg.data[0] = d0;
|
|
|
|
msg.data[1] = d1;
|
2009-06-01 20:22:11 +03:00
|
|
|
ret = call (__my_call, &msg);
|
2009-06-01 02:12:54 +03:00
|
|
|
return ret ? msg.cap[0] : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned call_n01 (Capability c, unsigned d)
|
|
|
|
{
|
|
|
|
Message msg;
|
|
|
|
int ret;
|
|
|
|
msg.cap[0] = c;
|
|
|
|
msg.data[0] = d;
|
2009-06-01 20:22:11 +03:00
|
|
|
ret = call (__my_call, &msg);
|
2009-05-27 19:33:05 +03:00
|
|
|
return ret ? msg.data[0] : 0;
|
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static unsigned call_n02 (Capability c, unsigned d0, unsigned d1)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
Message msg;
|
|
|
|
int ret;
|
|
|
|
msg.cap[0] = c;
|
|
|
|
msg.data[0] = d0;
|
|
|
|
msg.data[1] = d1;
|
2009-06-01 20:22:11 +03:00
|
|
|
ret = call (__my_call, &msg);
|
2009-06-01 02:12:54 +03:00
|
|
|
return ret ? msg.data[0] : 0;
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static unsigned call_n03 (Capability c, unsigned d0, unsigned d1, unsigned d2)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
Message msg;
|
|
|
|
int ret;
|
|
|
|
msg.cap[0] = c;
|
|
|
|
msg.data[0] = d0;
|
|
|
|
msg.data[1] = d1;
|
|
|
|
msg.data[2] = d2;
|
2009-06-01 20:22:11 +03:00
|
|
|
ret = call (__my_call, &msg);
|
2009-06-01 02:12:54 +03:00
|
|
|
return ret ? msg.data[0] : 0;
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static unsigned call_n04 (Capability c, unsigned d0, unsigned d1, unsigned d2, unsigned d3)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
Message msg;
|
|
|
|
int ret;
|
|
|
|
msg.cap[0] = c;
|
|
|
|
msg.data[0] = d0;
|
|
|
|
msg.data[1] = d1;
|
|
|
|
msg.data[2] = d2;
|
|
|
|
msg.data[3] = d3;
|
2009-06-01 20:22:11 +03:00
|
|
|
ret = call (__my_call, &msg);
|
2009-06-01 02:12:54 +03:00
|
|
|
return ret ? msg.data[0] : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Capability degrade (Capability src, unsigned mask)
|
|
|
|
{
|
|
|
|
return call_c02 (src, CAP_DEGRADE, mask);
|
|
|
|
}
|
|
|
|
|
2009-06-10 23:54:12 +03:00
|
|
|
static void kdebug (unsigned code)
|
2009-06-01 20:22:11 +03:00
|
|
|
{
|
2009-06-10 23:54:12 +03:00
|
|
|
invoke_02 (__my_thread, CAP_THREAD_DEBUG, code);
|
2009-06-01 20:22:11 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static void schedule ()
|
|
|
|
{
|
2009-06-01 20:22:11 +03:00
|
|
|
invoke_01 (__my_thread, CAP_THREAD_SCHEDULE);
|
2009-06-01 02:12:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void register_interrupt (unsigned num)
|
|
|
|
{
|
2009-06-01 20:22:11 +03:00
|
|
|
invoke_12 (__my_thread, __my_receiver, CAP_THREAD_REGISTER_INTERRUPT, num);
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability get_top_memory ()
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 20:22:11 +03:00
|
|
|
return call_c01 (__my_thread, CAP_THREAD_GET_TOP_MEMORY);
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static void unregister_interrupt (unsigned num)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 20:22:11 +03:00
|
|
|
invoke_02 (__my_thread, CAP_THREAD_REGISTER_INTERRUPT, num);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void alloc_physical (Capability page, unsigned address, int cachable)
|
|
|
|
{
|
2009-06-08 14:46:13 +03:00
|
|
|
invoke_12 (__my_thread, page, CAP_THREAD_ALLOC_PHYSICAL, (address & PAGE_MASK) | (cachable ? 1 : 0));
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static int receiver_set_owner (Capability receiver, Capability owner)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return invoke_11 (receiver, owner, CAP_RECEIVER_SET_OWNER);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability receiver_create_capability (Capability receiver, unsigned protected_data)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return call_c02 (receiver, CAP_RECEIVER_CREATE_CAPABILITY, protected_data);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static int receiver_get_reply_protected_data (Capability receiver, unsigned data)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return call_n01 (receiver, CAP_RECEIVER_GET_REPLY_PROTECTED_DATA);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static int receiver_set_reply_protected_data (Capability receiver, unsigned data)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return invoke_02 (receiver, CAP_RECEIVER_SET_REPLY_PROTECTED_DATA, data);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability receiver_create_call_capability (Capability receiver)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return call_c02 (receiver, CAP_RECEIVER_CREATE_CALL_CAPABILITY, 0);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability receiver_create_async_call_capability (Capability receiver)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return call_c02 (receiver, CAP_RECEIVER_CREATE_CALL_CAPABILITY, 1);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability memory_create (Capability memory, unsigned type)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return call_c02 (memory, CAP_MEMORY_CREATE, type);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability memory_create_page (Capability memory)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-08 14:46:13 +03:00
|
|
|
return memory_create (memory, CAPTYPE_PAGE | REQUEST_MASK);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability memory_create_thread (Capability memory)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-08 14:46:13 +03:00
|
|
|
return memory_create (memory, CAPTYPE_THREAD | REQUEST_MASK);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability memory_create_receiver (Capability memory)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-08 14:46:13 +03:00
|
|
|
return memory_create (memory, CAPTYPE_RECEIVER | REQUEST_MASK);
|
2009-06-01 02:12:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static Capability memory_create_memory (Capability memory)
|
|
|
|
{
|
2009-06-08 14:46:13 +03:00
|
|
|
return memory_create (memory, CAPTYPE_MEMORY | REQUEST_MASK);
|
2009-06-01 02:12:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static Capability memory_create_cappage (Capability memory)
|
|
|
|
{
|
2009-06-08 14:46:13 +03:00
|
|
|
return memory_create (memory, CAPTYPE_CAPPAGE | REQUEST_MASK);
|
2009-06-01 02:12:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int memory_destroy (Capability memory, Capability target)
|
|
|
|
{
|
|
|
|
return invoke_11 (memory, target, CAP_MEMORY_DESTROY);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: #define CAP_MEMORY_LIST 3 */
|
|
|
|
|
2009-06-08 14:46:13 +03:00
|
|
|
static int memory_map (Capability memory, Capability page, unsigned address, int writable)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-08 14:46:13 +03:00
|
|
|
if (writable)
|
|
|
|
address |= 1 << CAP_PAGE_WRITE;
|
2009-06-01 02:12:54 +03:00
|
|
|
return invoke_12 (memory, page, CAP_MEMORY_MAP, address);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability memory_mapping (Capability memory, unsigned address)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return call_c02 (memory, CAP_MEMORY_MAPPING, address);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static void drop (Capability cap)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 20:22:11 +03:00
|
|
|
invoke_11 (__my_memory, cap, CAP_MEMORY_DROP);
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability thread_make_priv (Capability thread)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 20:22:11 +03:00
|
|
|
return call_c12 (__my_thread, thread, CAP_THREAD_MAKE_PRIV, ~0);
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static unsigned thread_info (Capability thread, unsigned info, unsigned value, unsigned mask)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return call_n04 (thread, CAP_THREAD_INFO, info, value, mask);
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static unsigned thread_set_pc (Capability thread, unsigned pc)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return thread_info (thread, CAP_THREAD_INFO_PC, pc, ~0);
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static unsigned thread_set_sp (Capability thread, unsigned sp)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return thread_info (thread, CAP_THREAD_INFO_SP, sp, ~0);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static unsigned thread_flags (Capability thread, unsigned value, unsigned mask)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return thread_info (thread, CAP_THREAD_INFO_FLAGS, value, mask);
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static unsigned thread_run (Capability thread, int run)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return thread_flags (thread, run ? THREAD_FLAG_RUNNING : 0, THREAD_FLAG_RUNNING);
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static unsigned thread_wait (Capability thread, int wait)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return thread_flags (thread, wait ? THREAD_FLAG_WAITING : 0, THREAD_FLAG_WAITING);
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
|
|
|
|
2009-07-04 17:21:28 +03:00
|
|
|
static unsigned thread_sleep (Capability thread, unsigned value)
|
|
|
|
{
|
|
|
|
return thread_info (thread, CAP_THREAD_INFO_SLEEP, value, ~0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void my_sleep (unsigned value)
|
|
|
|
{
|
|
|
|
call_n04 (__my_thread, CAP_THREAD_INFO, CAP_THREAD_INFO_SLEEP, value, ~0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned thread_get_sleep (Capability thread)
|
|
|
|
{
|
|
|
|
return thread_info (thread, CAP_THREAD_INFO_SLEEP, 0, 0);
|
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static unsigned thread_get_pc (Capability thread)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return thread_info (thread, CAP_THREAD_INFO_PC, 0, 0);
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static unsigned thread_get_sp (Capability thread)
|
2009-05-27 19:33:05 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return thread_info (thread, CAP_THREAD_INFO_SP, 0, 0);
|
2009-05-27 19:33:05 +03:00
|
|
|
}
|
2009-05-25 01:31:35 +03:00
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static int page_share (Capability page, Capability target, unsigned flags)
|
|
|
|
{
|
|
|
|
return invoke_12 (page, target, CAP_PAGE_SHARE, flags);
|
|
|
|
}
|
2009-05-25 01:31:35 +03:00
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static unsigned page_flags (Capability page, unsigned new_flags, unsigned mask)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return call_n03 (page, CAP_PAGE_FLAGS, new_flags, mask);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static Capability capability_get (Capability cap)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return call_c01 (cap, CAP_CAPABILITY_GET);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-01 02:12:54 +03:00
|
|
|
static int cappage_set (Capability page, Capability cap, unsigned index)
|
2009-05-25 01:31:35 +03:00
|
|
|
{
|
2009-06-01 02:12:54 +03:00
|
|
|
return invoke_12 (page, cap, CAP_CAPPAGE_SET, index);
|
2009-05-25 01:31:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2009-05-22 23:48:49 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|