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

176 lines
4.7 KiB
Plaintext
Raw Normal View History

2009-05-11 01:28:12 +03:00
#pypp 0
#ifndef _KERNEL_HH
#define _KERNEL_HH
2009-05-25 01:31:35 +03:00
#define __KERNEL
2009-05-22 23:48:49 +03:00
#include "boot-programs/sos.h"
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-25 01:31:35 +03:00
struct Cappage
2009-05-18 10:30:27 +03:00
struct Memory
struct Object_base:
2009-05-25 01:31:35 +03:00
Capability *refs
Memory *address_space
2009-05-18 10:30:27 +03:00
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
#include "arch.hh"
2009-05-18 10:30:27 +03:00
struct Page : public Object <Page>:
2009-05-22 23:48:49 +03:00
unsigned physical
Page_arch arch
2009-05-18 10:30:27 +03:00
struct Thread : public Object <Thread>:
2009-05-25 01:31:35 +03:00
Receiver *receivers
2009-05-18 10:30:27 +03:00
unsigned pc, sp
Thread_arch arch
2009-05-25 01:31:35 +03:00
unsigned flags
2009-05-18 10:30:27 +03:00
Thread *schedule_prev, *schedule_next
2009-05-25 01:31:35 +03:00
void run ()
void unrun ()
void wait ()
void unwait ()
bool is_waiting ():
return flags & THREAD_FLAG_WAITING
2009-05-20 23:07:56 +03:00
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
2009-05-24 13:22:22 +03:00
void own (Thread *o)
void orphan ()
2009-05-27 19:33:05 +03:00
bool send_message (unsigned protected_data, unsigned data[4], Capability *cap[4], bool copy[4])
2009-05-20 23:07:56 +03:00
struct Capability : public Object <Capability>:
Receiver *target
2009-05-25 01:31:35 +03:00
Capability *parent
2009-05-20 23:07:56 +03:00
Capability *children
Capability *sibling_prev, *sibling_next
unsigned protected_data
2009-05-25 01:31:35 +03:00
bool invoke (unsigned data[4], Capability *cap[4], bool copy[4])
2009-05-20 23:07:56 +03:00
void invalidate ()
2009-05-11 01:28:12 +03:00
2009-05-24 13:22:22 +03:00
struct Cappage : public Object <Cappage>:
Capability *page
2009-05-18 10:30:27 +03:00
struct Memory : public Object <Memory>:
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-25 01:31:35 +03:00
Cappage *cappages
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)
2009-05-24 13:22:22 +03:00
inline Page *get_mapping (unsigned address, bool *writable)
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-22 23:48:49 +03:00
unsigned palloc ()
unsigned zalloc ()
void pfree (unsigned page)
void zfree (unsigned 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-27 19:33:05 +03:00
Message *alloc_message (Receiver *target, unsigned protected_data)
2009-05-20 23:07:56 +03:00
Receiver *alloc_receiver ()
2009-05-25 01:31:35 +03:00
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 ()
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-25 01:31:35 +03:00
void free_cappage (Cappage *page)
2009-05-19 00:18:23 +03:00
void free_memory (Memory *mem)
2009-05-25 01:31:35 +03:00
void free_obj (Object_base *obj)
Capability *find_capability (unsigned code, bool *copy)
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.
2009-05-22 23:48:49 +03:00
void panic (unsigned n, char const *message = "")
2009-05-11 01:28:12 +03:00
// Debug: switch caps led
2009-05-25 01:31:35 +03:00
void dbg_led (bool one, bool two, bool three)
2009-05-22 23:48:49 +03:00
void dbg_sleep (unsigned ms)
2009-05-25 01:31:35 +03:00
void dbg_send (unsigned code, unsigned bits = 32)
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)
2009-05-25 01:31:35 +03:00
void Thread_arch_receive (Thread *thread, unsigned d[4], Capability *c[4])
void Thread_arch_receive_fail (Thread *thread)
2009-05-27 19:33:05 +03:00
unsigned *Thread_arch_info (Thread *thread, unsigned num)
2009-05-20 23:07:56 +03:00
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)
2009-05-24 13:22:22 +03:00
Page *Memory_arch_get_mapping (Memory *mem, unsigned address, bool *writable)
2009-05-23 21:55:31 +03:00
void arch_invoke ()
2009-05-27 19:33:05 +03:00
void arch_register_interrupt (unsigned num, Receiver *r)
2009-05-20 23:07:56 +03:00
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)
2009-05-24 13:22:22 +03:00
Page *Memory::get_mapping (unsigned address, bool *writable):
return Memory_arch_get_mapping (this, address, writable)
2009-05-11 01:28:12 +03:00
#endif