1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-04 22:54:03 +02:00
iris/kernel.hhp

148 lines
3.8 KiB
Plaintext
Raw Normal View History

2009-05-11 01:28:12 +03:00
#pypp 0
#ifndef _KERNEL_HH
#define _KERNEL_HH
2009-05-18 10:30:27 +03:00
#ifndef EXTERN
#define EXTERN extern
#endif
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-18 10:30:27 +03:00
struct Memory
#include "arch.hh"
struct Object_base:
// Next and previous object of any type in the same page.
2009-05-19 00:18:23 +03:00
Object_base *prev_obj, *next_obj
2009-05-18 10:30:27 +03:00
void free_obj (Memory *parent)
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
struct Page : public Object <Page>:
void *physical
struct Thread : public Object <Thread>:
2009-05-11 01:28:12 +03:00
Memory *address_space
2009-05-18 10:30:27 +03:00
unsigned pc, sp
Thread_arch arch
Thread *schedule_prev, *schedule_next
2009-05-20 23:07:56 +03:00
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 ()
2009-05-11 01:28:12 +03:00
2009-05-18 10:30:27 +03:00
struct Memory : public Object <Memory>:
2009-05-19 00:18:23 +03:00
Memory *parent
2009-05-18 10:30:27 +03:00
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-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)
inline Page *get_mapping (unsigned address)
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-18 10:30:27 +03:00
void *palloc ()
void *zalloc ()
void pfree (void *page)
void zfree (void *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-20 23:07:56 +03:00
Message *alloc_message (Capability *source)
Receiver *alloc_receiver ()
Capability *alloc_capability (Receiver *target, Capability **parent, unsigned protected_data)
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-19 00:18:23 +03:00
void free_memory (Memory *mem)
2009-05-20 23:07:56 +03:00
Capability *find_capability (unsigned code)
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.
void panic (unsigned n, char const *message)
// Debug: switch caps led
2009-05-19 00:18:23 +03:00
void led (bool one, bool two, bool three)
2009-05-11 01:28:12 +03:00
2009-05-20 23:07:56 +03:00
void schedule ()
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-05-20 23:07:56 +03:00
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)
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)
2009-05-11 01:28:12 +03:00
#endif