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

94 lines
2.0 KiB
Plaintext

#pypp 0
#ifndef _KERNEL_HH
#define _KERNEL_HH
#ifndef EXTERN
#define EXTERN extern
#endif
#define NULL 0
struct Object_base
struct Object
struct Page
struct Thread
struct Memory
#include "arch.hh"
struct Object_base:
// Next and previous object of any type in the same page.
Object *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
void free (Memory *parent, _T *&first)
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>:
void *physical
struct Thread : public Object <Thread>:
Memory *address_space
unsigned pc, sp
Thread_arch arch
Thread *schedule_prev, *schedule_next
struct Memory : public Object <Memory>:
Free *frees
Page *pages
Thread *threads
Memory *memories
unsigned limit, used
Memory_arch arch
// Allocation of pages.
void *palloc ()
void *zalloc ()
void pfree (void *page)
void zfree (void *page)
// Allocation routines for kernel structures
void *search_free (unsigned size, void *&first)
Page *alloc_page ()
Thread *alloc_thread ()
Memory *alloc_memory ()
// 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 on, bool tick)
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
template <typename _T> void Object <_T>::free (Memory *parent, _T *&first):
if prev:
prev->next = next
else:
first = next
if next:
next->prev = prev
free_obj (parent)
#endif