mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-11-05 12:23:09 +02:00
97 lines
2.0 KiB
Plaintext
97 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 Page
|
|
struct Thread
|
|
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>:
|
|
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>:
|
|
Memory *parent
|
|
Free *frees
|
|
Page *pages
|
|
Thread *threads
|
|
Memory *memories
|
|
unsigned limit, used
|
|
Memory_arch arch
|
|
|
|
void unmap (Page *page, void *address):
|
|
Memory_arch_unmap (this, page, address)
|
|
|
|
// Allocation of pages.
|
|
bool use ()
|
|
void unuse ()
|
|
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 ()
|
|
|
|
void free_page (Page *page)
|
|
void free_thread (Thread *thread)
|
|
void free_memory (Memory *mem)
|
|
|
|
#define ARCH_PART2
|
|
#include "arch.hh"
|
|
|
|
// 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)
|
|
|
|
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
|
|
|
|
#endif
|