]> git.buserror.net Git - polintos/scott/priv.git/blob - kernel/include/kern/orb.h
Random stuff.
[polintos/scott/priv.git] / kernel / include / kern / orb.h
1 #ifndef _KERN_ORB_H
2 #define _KERN_ORB_H
3
4 #include <kern/types.h>
5 #include <kern/radix.h>
6 #include <kern/lock.h>
7
8 #include <util/list.h>
9 #include <util/rbtree.h>
10 #include <util/radix.h>
11 #include <util/bmaptree.h>
12
13 #include <System/Objects.h>
14 #include <orb.h>
15
16 namespace Mem {
17         class ProcAddrSpace;
18 };
19
20 namespace Threads {
21         class Thread;
22 };
23
24 namespace ORB {
25         typedef u32 ID;
26
27         struct CallFrame {
28                 // Address Space and PC to return to
29                 Mem::ProcAddrSpace *ret_aspace;
30                 uintptr_t ret_stack;
31                 
32                 // Caller's PIB Pointer
33                 System::RunTime::ParamInfoBlock *caller_user_pib;
34         };
35         
36         struct CallStackHeader {
37                 Threads::Thread *thread;
38                 Util::List node;
39                 
40                 // Number of CallFrames under this header.
41                 // For a full page, this is:
42                 //   (Arch::page_size - sizeof(CallStackHeader)) / sizeof(CallFrame)
43                 // There is also a much smaller group of call frames in the Thread
44                 // structure, so that an ORB stack page doesn't need to be allocated
45                 // in the common case of shallow method nesting.
46         
47                 int num_frames;
48                 
49                 CallFrame frames[0];
50         };
51
52         static const ID invalid_id = 0xffffffff;
53         struct ObjectHdr {
54                 ID id;
55         };
56         
57         struct Object : public ObjectHdr {
58                 Mem::ProcAddrSpace *aspace;
59         };
60
61         struct ObjectPtr : public ObjectHdr {
62                 Object *object;
63         };
64         
65         typedef Util::RadixTree<Object, ID, 6> LocalIDTable;
66         typedef Util::RadixTree<ObjectPtr, ID, 6> RemoteIDTable;
67         typedef Util::RBPtr<Object *, ObjectPtr *> IDRMap;
68         typedef Util::BitmapTree<ID> IDAlloc;
69
70         class IDSpace {
71                 Lock::SpinLock lock; // For add/del only; not needed for lookup
72                 LocalIDTable locals; // Objects that live in this address space
73                 RemoteIDTable remotes; // Objects that live in other address spaces
74                 IDRMap rmap; // Reverse mapping of remote object pointers to local IDs
75                 IDAlloc alloc; // Bitmap for allocating IDs
76         
77         public:
78                 Object *lookup(u32 id);
79                 ObjectHdr *get_local(Object *obj);
80                 Object *newobj(Mem::ProcAddrSpace *aspace);
81         };
82         
83         void invoke_method(System::RunTime::ParamInfoBlock *pib, uintptr_t &stack);
84         uintptr_t return_from_method(uintptr_t &exptr, size_t &exlen);
85         void init();
86 }
87
88 #endif