1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-07-01 02:15:27 +03:00
iris/kernel.hhp

229 lines
6.7 KiB
Plaintext
Raw Normal View History

2009-05-11 01:28:12 +03:00
#pypp 0
2009-06-01 15:26:42 +03:00
// Iris: micro-kernel for a capability-based operating system.
// kernel.hhp: Header for all kernel sources.
// 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/>.
2009-05-11 01:28:12 +03:00
#ifndef _KERNEL_HH
#define _KERNEL_HH
2009-06-01 15:26:42 +03:00
// Include definitions which are shared with user space.
2009-05-25 01:31:35 +03:00
#define __KERNEL
2009-06-01 15:26:42 +03:00
#include "iris.h"
2009-05-22 23:48:49 +03:00
2009-06-01 15:26:42 +03:00
// Normally define all variables in this file as extern.
// Exactly once (in data.ccp), EXTERN is predefined empty.
// That results in space being allocated in its object file.
2009-05-18 10:30:27 +03:00
#ifndef EXTERN
#define EXTERN extern
#endif
struct Object_base
struct Page
struct Thread
2009-05-20 23:07:56 +03:00
struct Message
struct Receiver
struct Capability
2009-05-25 01:31:35 +03:00
struct Cappage
2009-05-18 10:30:27 +03:00
struct Memory
struct Object_base:
2009-05-25 01:31:35 +03:00
Capability *refs
Memory *address_space
2009-05-18 10:30:27 +03:00
inline bool is_free ()
2009-05-19 00:18:23 +03:00
template <typename _T> //
struct Object : public Object_base:
2009-05-18 10:30:27 +03:00
// Next and previous object of the same type in any page.
_T *prev, *next
2009-05-19 00:18:23 +03:00
struct Free : public Object <Free>:
2009-05-18 10:30:27 +03:00
// This marker is ~0. No other kernel structure may allow this value
// at this point. It is used to recognize free chunks.
unsigned marker
bool Object_base::is_free ():
return ((Free *)this)->marker == ~0
2009-06-01 15:26:42 +03:00
// Include architecture-specific parts.
#include "arch.hh"
2009-05-20 23:07:56 +03:00
struct Message : public Object <Message>:
Capability *capabilities[4]
unsigned data[4]
unsigned protected_data
2009-06-08 14:46:13 +03:00
struct Capability : public Object <Capability>:
struct Context:
unsigned data[4]
Capability *cap[4]
bool copy[4]
Receiver *target
Capability *parent
Capability *children
Capability *sibling_prev, *sibling_next
unsigned protected_data
2009-07-20 01:23:45 +03:00
void invoke (Context *c)
2009-06-08 14:46:13 +03:00
void invalidate ()
2009-07-25 01:54:12 +03:00
struct Thread : public Object <Thread>:
Receiver *receivers
unsigned pc, sp
Thread_arch arch
unsigned flags
Thread *schedule_prev, *schedule_next
// This is not a pointer, but a real Capability. That means that at capability destroy, no check is needed if it is used for an exception handler.
Capability exception
void raise (unsigned code, unsigned data)
void run ()
void unrun ()
void wait ()
void unwait ()
bool is_waiting ():
return flags & THREAD_FLAG_WAITING
2009-05-20 23:07:56 +03:00
struct Receiver : public Object <Receiver>:
Thread *owner
Receiver *prev_owned, *next_owned
2009-07-20 01:23:45 +03:00
Receiver *prev_alarm, *next_alarm
unsigned alarm_count
2009-05-20 23:07:56 +03:00
Capability *capabilities
Message *messages
2009-07-20 01:23:45 +03:00
Message *last_message
2009-06-01 02:12:54 +03:00
unsigned reply_protected_data
bool protected_only
2009-05-24 13:22:22 +03:00
void own (Thread *o)
void orphan ()
2009-06-01 02:12:54 +03:00
bool try_deliver ()
2009-06-08 14:46:13 +03:00
bool send_message (unsigned protected_data, Capability::Context *c)
2009-05-11 01:28:12 +03:00
2009-05-29 00:35:27 +03:00
struct ShareData :
unsigned frame
unsigned flags
void *share_first
void *share_prev, *share_next
struct Page : public Object <Page>:
ShareData data
Page_arch arch
2009-06-01 02:12:54 +03:00
void forget ()
2009-05-29 00:35:27 +03:00
2009-05-24 13:22:22 +03:00
struct Cappage : public Object <Cappage>:
2009-05-29 00:35:27 +03:00
ShareData data
2009-07-20 01:23:45 +03:00
Capability *cap (unsigned idx):
return &((Capability *)data.frame)[idx]
2009-06-01 02:12:54 +03:00
void forget ()
2009-05-24 13:22:22 +03:00
2009-05-18 10:30:27 +03:00
struct Memory : public Object <Memory>:
Free *frees
2009-05-11 01:28:12 +03:00
Page *pages
Thread *threads
2009-05-20 23:07:56 +03:00
Receiver *receivers
Capability *capabilities
2009-05-25 01:31:35 +03:00
Cappage *cappages
2009-05-11 01:28:12 +03:00
Memory *memories
unsigned limit, used
2009-05-18 10:30:27 +03:00
Memory_arch arch
2009-05-11 01:28:12 +03:00
2009-05-20 23:07:56 +03:00
inline bool map (Page *page, unsigned address, bool write)
inline void unmap (Page *page, unsigned address)
2009-05-24 13:22:22 +03:00
inline Page *get_mapping (unsigned address, bool *writable)
2009-05-19 00:18:23 +03:00
2009-05-18 10:30:27 +03:00
// Allocation of pages.
2009-07-20 01:23:45 +03:00
bool use (unsigned num = 1)
void unuse (unsigned num = 1)
2009-05-22 23:48:49 +03:00
unsigned palloc ()
unsigned zalloc ()
void pfree (unsigned page)
void zfree (unsigned page)
2009-05-11 01:28:12 +03:00
2009-05-18 10:30:27 +03:00
// Allocation routines for kernel structures
2009-05-19 00:18:23 +03:00
void *search_free (unsigned size, void **first)
2009-05-18 10:30:27 +03:00
Page *alloc_page ()
Thread *alloc_thread ()
2009-07-20 01:23:45 +03:00
Message *alloc_message (Receiver *target)
2009-05-20 23:07:56 +03:00
Receiver *alloc_receiver ()
2009-05-25 01:31:35 +03:00
Capability *alloc_capability (Receiver *target, Capability *parent, Capability **parent_ptr, unsigned protected_data, Capability *ret = NULL)
Capability *clone_capability (Capability *source, bool copy, Capability *ret = NULL)
Cappage *alloc_cappage ()
2009-05-18 10:30:27 +03:00
Memory *alloc_memory ()
2009-05-11 01:28:12 +03:00
2009-05-19 00:18:23 +03:00
void free_page (Page *page)
void free_thread (Thread *thread)
2009-07-20 01:23:45 +03:00
void free_message (Receiver *owner, Message *message)
2009-05-20 23:07:56 +03:00
void free_receiver (Receiver *receiver)
void free_capability (Capability *capability)
2009-05-25 01:31:35 +03:00
void free_cappage (Cappage *page)
2009-05-19 00:18:23 +03:00
void free_memory (Memory *mem)
2009-07-25 01:54:12 +03:00
void free_obj (Object_base *obj, void **first)
2009-05-25 01:31:35 +03:00
Capability *find_capability (unsigned code, bool *copy)
2009-05-19 00:18:23 +03:00
2009-05-18 10:30:27 +03:00
// Functions which can be called from assembly must not be mangled.
extern "C":
2009-05-11 01:28:12 +03:00
// Panic. n is sent over caps led. message is currently ignored.
2009-07-25 01:54:12 +03:00
void panic_impl (unsigned n, unsigned line, char const *name, char const *message = "")
2009-07-20 01:23:45 +03:00
EXTERN unsigned dbg_code
2009-07-23 13:06:32 +03:00
EXTERN Capability *dbg_cap
void dbg_log_char (unsigned ch)
void dbg_log (char const *str)
2009-07-25 01:54:12 +03:00
void dbg_log_num (unsigned num)
#define panic(n, m) panic_impl ((n), __LINE__, __PRETTY_FUNCTION__, (m))
2009-05-11 01:28:12 +03:00
2009-07-04 17:21:28 +03:00
/// Defined in schedule.ccp
2009-05-20 23:07:56 +03:00
void schedule ()
2009-07-04 17:21:28 +03:00
void timer_interrupt ()
2009-05-20 23:07:56 +03:00
2009-05-11 01:28:12 +03:00
EXTERN Memory top_memory
2009-07-20 01:23:45 +03:00
EXTERN Receiver *first_alarm
2009-05-11 01:28:12 +03:00
EXTERN Thread idle
EXTERN Memory idle_memory
EXTERN Page idle_page
2009-07-20 01:23:45 +03:00
EXTERN Thread *first_scheduled
2009-07-24 15:25:53 +03:00
EXTERN Thread *current, *old_current
2009-07-20 01:23:45 +03:00
EXTERN bool do_schedule
2009-05-20 23:07:56 +03:00
// Defined in memory.cc
unsigned init_memory (unsigned mem)
2009-06-01 02:12:54 +03:00
unsigned raw_zalloc ()
void raw_pfree (unsigned page)
2009-07-20 01:23:45 +03:00
unsigned phys_alloc (unsigned num)
void phys_free (unsigned page, unsigned num)
2009-06-01 02:12:54 +03:00
2009-06-01 15:26:42 +03:00
// Defined by architecture-specific files.
2009-05-20 23:07:56 +03:00
void Thread_arch_init (Thread *thread)
2009-06-10 23:54:12 +03:00
void Thread_arch_receive (Thread *thread, unsigned protected_data, Capability::Context *c)
2009-05-27 19:33:05 +03:00
unsigned *Thread_arch_info (Thread *thread, unsigned num)
2009-05-20 23:07:56 +03:00
void Memory_arch_init (Memory *mem)
void Memory_arch_free (Memory *mem)
bool Memory_arch_map (Memory *mem, Page *page, unsigned address, bool write)
void Memory_arch_unmap (Memory *mem, Page *page, unsigned address)
2009-05-24 13:22:22 +03:00
Page *Memory_arch_get_mapping (Memory *mem, unsigned address, bool *writable)
2009-05-29 00:35:27 +03:00
void Page_arch_update_mapping (Page *page)
2009-05-27 19:33:05 +03:00
void arch_register_interrupt (unsigned num, Receiver *r)
2009-05-20 23:07:56 +03:00
bool Memory::map (Page *page, unsigned address, bool write):
return Memory_arch_map (this, page, address, write)
void Memory::unmap (Page *page, unsigned address):
Memory_arch_unmap (this, page, address)
2009-05-24 13:22:22 +03:00
Page *Memory::get_mapping (unsigned address, bool *writable):
return Memory_arch_get_mapping (this, address, writable)
2009-05-11 01:28:12 +03:00
2009-07-20 01:23:45 +03:00
#define assert(x) do { if (!(x)) panic (__LINE__, "assertion failed"); } while (0)
2009-05-11 01:28:12 +03:00
#endif