add support for crt{i,n} - required for powerpc EABI
[prex.git] / sys / include / task.h
blob35cb4684a557b1e958e10987010d5b5a691cfa27
1 /*-
2 * Copyright (c) 2005-2006, Kohsuke Ohtani
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
30 #ifndef _TASK_H
31 #define _TASK_H
33 #include <list.h>
34 #include <timer.h>
36 #define TASK_MAGIC 0x54736b3f /* 'Tsk?' */
38 typedef uint32_t cap_t;
41 * Task struct
43 struct task {
44 int magic; /* Magic number */
45 char name[MAX_TASKNAME]; /* Task name */
46 struct list link; /* Link for all tasks in system */
47 struct list objects; /* Objects owned by this task */
48 struct list threads; /* Threads in this task */
49 struct vm_map *map; /* Virtual memory map */
50 int sus_count; /* Suspend counter */
51 cap_t capability; /* Security permission flag */
52 struct timer alarm; /* Alarm timer */
53 void (*exc_handler)(int, u_long); /* Pointer to excepion handler */
56 typedef struct task *task_t;
58 #define cur_task() (cur_thread->task)
59 #define task_valid(tsk) (kern_area(tsk) && ((tsk)->magic == TASK_MAGIC))
60 #define task_capable(cap) ((int)(cur_task()->capability & (1U << (cap))))
63 * Task capability
65 #define CAP_SETPCAP 0 /* Allow setting capability */
66 #define CAP_TASK 1 /* Allow controlling another task's execution */
67 #define CAP_MEMORY 2 /* Allow touching another task's memory */
68 #define CAP_KILL 3 /* Allow raising exception to another task */
69 #define CAP_SEMAPHORE 4 /* Allow accessing another task's semaphore */
70 #define CAP_NICE 5 /* Allow changing scheduling parameter */
71 #define CAP_IPC 6 /* Allow accessing another task's IPC object */
72 #define CAP_DEVIO 7 /* Allow device I/O operations */
73 #define CAP_POWER 8 /* Allow power control including shutdown */
74 #define CAP_TIME 9 /* Allow setting system time */
75 #define CAP_RAWIO 10 /* Allow direct I/O access */
76 #define CAP_DEBUG 11 /* Allow debugging reqeusts */
79 * vm_inherit options for task_create()
81 #define VM_NONE 0 /* Create new memory map */
82 #define VM_SHARE 1 /* Share parent's memory map */
83 #define VM_COPY 2 /* Duplicate parent's memory map */
85 #define KERN_TASK(task) \
86 { \
87 .magic = TASK_MAGIC, \
88 .name = "kernel", \
89 .link = LIST_INIT(task.link), \
90 .objects = LIST_INIT(task.objects), \
91 .threads = LIST_INIT(task.threads), \
92 .sus_count = 0, \
93 .capability = 0xffffffff, \
94 .exc_handler = NULL, \
97 extern void task_init(void);
98 extern void task_boot(void);
99 extern int __task_create(task_t parent, int vm_inherit, task_t *child);
100 extern int task_create(task_t parent, int vm_inherit, task_t *child);
101 extern int task_terminate(task_t task);
102 extern task_t task_self(void);
103 extern int task_suspend(task_t task);
104 extern int task_resume(task_t task);
105 extern int task_name(task_t task, char *name);
106 extern int task_getcap(task_t task, cap_t *cap);
107 extern int task_setcap(task_t task, cap_t *cap);
108 extern int __task_capable(cap_t cap);
110 #endif /* !_TASK_H */