]> git.buserror.net Git - polintos/scott/priv.git/blob - kernel/include/kern/orb.h
update
[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         struct ObjectHdr {
53                 ID id;
54
55                 union {
56                         struct {
57                                 u32 Valid:1;
58                                 u32 Pointer:1;
59                         };
60                         
61                         u32 flags;
62                 };
63         };
64         
65         struct Object : public ObjectHdr {
66                 Mem::ProcAddrSpace *aspace;
67         };
68
69         struct ObjectPtr : public ObjectHdr {
70                 Object *object;
71         };
72         
73         union ObjTableEntry {
74                 ObjectHdr hdr;
75                 Object obj;
76                 ObjectPtr ptr;
77         };
78
79         typedef Util::RadixTree<ObjTableEntry, ID, 6> IDTable;
80         typedef Util::RBPtr<Object *, ObjectPtr *> IDRMap;
81         typedef Util::BitmapTree<ID> IDAlloc;
82
83         class IDSpace {
84                 Lock::SpinLock lock; // For add/del only; not needed for lookup
85                 IDTable table; // Forward mapping of local IDs to object ptrs
86                 IDRMap rmap; // Reverse mapping of remote object pointers to local IDs
87                 IDAlloc alloc; // Bitmap for allocating IDs
88         
89         public:
90                 Object *lookup(u32 id);
91                 ObjectHdr *get_local(Object *obj);
92                 Object *newobj(Mem::ProcAddrSpace *aspace);
93         };
94         
95         void invoke_method(System::RunTime::ParamInfoBlock *pib, uintptr_t &stack);
96         uintptr_t return_from_method(uintptr_t &exptr, size_t &exlen);
97         void init();
98 }
99
100 #endif