mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-11-04 22:54:03 +02:00
152 lines
3.9 KiB
Plaintext
152 lines
3.9 KiB
Plaintext
#pypp 0
|
|
#ifndef _KERNEL_HH
|
|
#define _KERNEL_HH
|
|
|
|
#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 Memory
|
|
|
|
#include "arch.hh"
|
|
|
|
struct Object_base:
|
|
// Next and previous object of any type in the same page.
|
|
Object_base *prev_obj, *next_obj
|
|
void free_obj (Memory *parent)
|
|
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
|
|
|
|
struct Page : public Object <Page>:
|
|
unsigned physical
|
|
|
|
struct Thread : public Object <Thread>:
|
|
Memory *address_space
|
|
unsigned pc, sp
|
|
Thread_arch arch
|
|
Thread *schedule_prev, *schedule_next
|
|
Receiver *receivers
|
|
|
|
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
|
|
|
|
struct Capability : public Object <Capability>:
|
|
Receiver *target
|
|
Capability *children
|
|
Capability *sibling_prev, *sibling_next
|
|
unsigned protected_data
|
|
void invoke (unsigned d0, unsigned d1, unsigned d2, unsigned d3, Capability *c0, Capability *c1, Capability *c2, Capability *c3)
|
|
void invalidate ()
|
|
|
|
struct Memory : public Object <Memory>:
|
|
Memory *parent
|
|
Free *frees
|
|
Page *pages
|
|
Thread *threads
|
|
Receiver *receivers
|
|
Capability *capabilities
|
|
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)
|
|
|
|
// 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 (Capability *source)
|
|
Receiver *alloc_receiver ()
|
|
Capability *alloc_capability (Receiver *target, Capability **parent, unsigned protected_data)
|
|
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_memory (Memory *mem)
|
|
|
|
Capability *find_capability (unsigned code)
|
|
|
|
// 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 led (bool one, bool two, bool three)
|
|
void dbg_sleep (unsigned ms)
|
|
|
|
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_invoke ()
|
|
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)
|
|
void arch_schedule (Thread *previous, Thread *target)
|
|
|
|
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):
|
|
return Memory_arch_get_mapping (this, address)
|
|
|
|
#endif
|