1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-04 22:54:03 +02:00
iris/kernel.hhp
Bas Wijnen e7f42c6b7e more
2009-05-28 23:35:27 +02:00

183 lines
4.8 KiB
Plaintext

#pypp 0
#ifndef _KERNEL_HH
#define _KERNEL_HH
#define __KERNEL
#include "boot-programs/sos.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#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 "arch.hh"
struct Thread : public Object <Thread>:
Receiver *receivers
unsigned pc, sp
Thread_arch arch
unsigned flags
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 Receiver : public Object <Receiver>:
Thread *owner
Receiver *prev_owned, *next_owned
Capability *capabilities
Message *messages
void own (Thread *o)
void orphan ()
bool send_message (unsigned protected_data, unsigned data[4], Capability *cap[4], bool copy[4])
struct Capability : public Object <Capability>:
Receiver *target
Capability *parent
Capability *children
Capability *sibling_prev, *sibling_next
unsigned protected_data
bool invoke (unsigned data[4], Capability *cap[4], bool copy[4])
void invalidate ()
struct ShareData :
unsigned frame
unsigned flags
void *share_first
void *share_prev, *share_next
struct Page : public Object <Page>:
ShareData data
Page_arch arch
struct Cappage : public Object <Cappage>:
ShareData data
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)
void schedule ()
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
EXTERN Thread *current
// Defined in arch.cc
void Thread_arch_init (Thread *thread)
void Thread_arch_receive (Thread *thread, unsigned d[4], Capability *c[4])
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_invoke ()
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