mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-11-16 22:25:19 +02:00
226 lines
6.4 KiB
Plaintext
226 lines
6.4 KiB
Plaintext
#pypp 0
|
|
// 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/>.
|
|
|
|
#ifndef _KERNEL_HH
|
|
#define _KERNEL_HH
|
|
|
|
// Number of clock interrupts per second.
|
|
#define HZ 10
|
|
|
|
// Include definitions which are shared with user space.
|
|
#define __KERNEL
|
|
#include "iris.h"
|
|
|
|
// 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.
|
|
#ifndef EXTERN
|
|
#define EXTERN extern
|
|
#endif
|
|
|
|
// Without the standard library, we don't have this definition.
|
|
// I preferred ((void*)0), but C++ has too strict type-checking to
|
|
// make that work.
|
|
#define NULL 0
|
|
|
|
struct Object_base
|
|
struct Page
|
|
struct Thread
|
|
struct Message
|
|
struct Receiver
|
|
struct Capability
|
|
struct Cappage
|
|
struct Memory
|
|
|
|
struct Object_base:
|
|
Capability *refs
|
|
Memory *address_space
|
|
inline bool is_free ()
|
|
|
|
template <typename _T> //
|
|
struct Object : public Object_base:
|
|
// Next and previous object of the same type in any page.
|
|
_T *prev, *next
|
|
|
|
struct Free : public Object <Free>:
|
|
// 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
|
|
|
|
// Include architecture-specific parts.
|
|
#include "arch.hh"
|
|
|
|
struct Thread : public Object <Thread>:
|
|
Receiver *receivers
|
|
unsigned pc, sp
|
|
Thread_arch arch
|
|
unsigned flags
|
|
unsigned sleep
|
|
Thread *schedule_prev, *schedule_next
|
|
void run ()
|
|
void unrun ()
|
|
void wait ()
|
|
void unwait ()
|
|
bool is_waiting ():
|
|
return flags & THREAD_FLAG_WAITING
|
|
|
|
struct Message : public Object <Message>:
|
|
Capability *capabilities[4]
|
|
unsigned data[4]
|
|
unsigned protected_data
|
|
|
|
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
|
|
bool invoke (Context *c)
|
|
void invalidate ()
|
|
|
|
struct Receiver : public Object <Receiver>:
|
|
Thread *owner
|
|
Receiver *prev_owned, *next_owned
|
|
Capability *capabilities
|
|
Message *messages
|
|
unsigned reply_protected_data
|
|
bool protected_only
|
|
void own (Thread *o)
|
|
void orphan ()
|
|
bool try_deliver ()
|
|
bool send_message (unsigned protected_data, Capability::Context *c)
|
|
|
|
struct ShareData :
|
|
unsigned frame
|
|
unsigned flags
|
|
void *share_first
|
|
void *share_prev, *share_next
|
|
|
|
struct Page : public Object <Page>:
|
|
ShareData data
|
|
Page_arch arch
|
|
void forget ()
|
|
|
|
struct Cappage : public Object <Cappage>:
|
|
ShareData data
|
|
void forget ()
|
|
|
|
struct Memory : public Object <Memory>:
|
|
Free *frees
|
|
Page *pages
|
|
Thread *threads
|
|
Receiver *receivers
|
|
Capability *capabilities
|
|
Cappage *cappages
|
|
Memory *memories
|
|
unsigned limit, used
|
|
Memory_arch arch
|
|
|
|
inline bool map (Page *page, unsigned address, bool write)
|
|
inline void unmap (Page *page, unsigned address)
|
|
inline Page *get_mapping (unsigned address, bool *writable)
|
|
|
|
// Allocation of pages.
|
|
bool use ()
|
|
void unuse ()
|
|
unsigned palloc ()
|
|
unsigned zalloc ()
|
|
void pfree (unsigned page)
|
|
void zfree (unsigned page)
|
|
|
|
// Allocation routines for kernel structures
|
|
void *search_free (unsigned size, void **first)
|
|
Page *alloc_page ()
|
|
Thread *alloc_thread ()
|
|
Message *alloc_message (Receiver *target, unsigned protected_data)
|
|
Receiver *alloc_receiver ()
|
|
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 ()
|
|
Memory *alloc_memory ()
|
|
|
|
void free_page (Page *page)
|
|
void free_thread (Thread *thread)
|
|
void free_message (Message *message)
|
|
void free_receiver (Receiver *receiver)
|
|
void free_capability (Capability *capability)
|
|
void free_cappage (Cappage *page)
|
|
void free_memory (Memory *mem)
|
|
|
|
void free_obj (Object_base *obj)
|
|
|
|
Capability *find_capability (unsigned code, bool *copy)
|
|
|
|
// Functions which can be called from assembly must not be mangled.
|
|
extern "C":
|
|
// Panic. n is sent over caps led. message is currently ignored.
|
|
void panic (unsigned n, char const *message = "")
|
|
// Debug: switch caps led
|
|
void dbg_led (bool one, bool two, bool three)
|
|
void dbg_sleep (unsigned ms)
|
|
void dbg_send (unsigned code, unsigned bits = 32)
|
|
|
|
/// Defined in schedule.ccp
|
|
void schedule ()
|
|
void timer_interrupt ()
|
|
|
|
struct FreePage:
|
|
FreePage *next
|
|
|
|
EXTERN FreePage *zero_pages, *junk_pages
|
|
EXTERN Memory top_memory
|
|
EXTERN Thread *sleepers, *runners
|
|
EXTERN Thread idle
|
|
EXTERN Memory idle_memory
|
|
EXTERN Page idle_page
|
|
EXTERN Thread *first_scheduled, *first_sleeper
|
|
EXTERN Thread *current
|
|
|
|
// Defined in alloc.cc
|
|
unsigned raw_zalloc ()
|
|
void raw_pfree (unsigned page)
|
|
|
|
// Defined by architecture-specific files.
|
|
void Thread_arch_init (Thread *thread)
|
|
void Thread_arch_receive (Thread *thread, unsigned protected_data, Capability::Context *c)
|
|
void Thread_arch_receive_fail (Thread *thread)
|
|
unsigned *Thread_arch_info (Thread *thread, unsigned num)
|
|
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)
|
|
Page *Memory_arch_get_mapping (Memory *mem, unsigned address, bool *writable)
|
|
void Page_arch_update_mapping (Page *page)
|
|
void arch_register_interrupt (unsigned num, Receiver *r)
|
|
|
|
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)
|
|
Page *Memory::get_mapping (unsigned address, bool *writable):
|
|
return Memory_arch_get_mapping (this, address, writable)
|
|
|
|
#endif
|