1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-17 00:37:31 +02:00
iris/kernel.hhp

226 lines
6.4 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-26 00:09:42 +03:00
// Number of clock interrupts per second.
#define HZ 10
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
2009-06-01 15:26:42 +03:00
// 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.
2009-05-11 01:28:12 +03:00
#define NULL 0
2009-05-18 10:30:27 +03:00
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-18 10:30:27 +03:00
struct Thread : public Object <Thread>:
2009-05-25 01:31:35 +03:00
Receiver *receivers
2009-05-18 10:30:27 +03:00
unsigned pc, sp
Thread_arch arch
2009-05-25 01:31:35 +03:00
unsigned flags
2009-07-04 17:21:28 +03:00
unsigned sleep
2009-05-18 10:30:27 +03:00
Thread *schedule_prev, *schedule_next
2009-05-25 01:31:35 +03:00
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 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
bool invoke (Context *c)
void invalidate ()
2009-05-20 23:07:56 +03:00
struct Receiver : public Object <Receiver>:
Thread *owner
Receiver *prev_owned, *next_owned
Capability *capabilities
Message *messages
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-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-05-19 00:18:23 +03:00
bool use ()
void unuse ()
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-05-27 19:33:05 +03:00
Message *alloc_message (Receiver *target, unsigned protected_data)
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-05-20 23:07:56 +03:00
void free_message (Message *message)
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-05-25 01:31:35 +03:00
void free_obj (Object_base *obj)
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-05-22 23:48:49 +03:00
void panic (unsigned n, char const *message = "")
2009-05-11 01:28:12 +03:00
// Debug: switch caps led
2009-05-25 01:31:35 +03:00
void dbg_led (bool one, bool two, bool three)
2009-05-22 23:48:49 +03:00
void dbg_sleep (unsigned ms)
2009-05-25 01:31:35 +03:00
void dbg_send (unsigned code, unsigned bits = 32)
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
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
2009-07-04 17:21:28 +03:00
EXTERN Thread *first_scheduled, *first_sleeper
2009-05-20 23:07:56 +03:00
EXTERN Thread *current
2009-06-01 02:12:54 +03:00
// Defined in alloc.cc
unsigned raw_zalloc ()
void raw_pfree (unsigned page)
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-25 01:31:35 +03:00
void Thread_arch_receive_fail (Thread *thread)
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
#endif