]> git.buserror.net Git - polintos/scott/priv.git/blob - kernel/include/kern/orb.h
random kernel 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 <orb.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
15 namespace Mem {
16         class ProcAddrSpace;
17 };
18
19 namespace Threads {
20         class Thread;
21 };
22
23 namespace ORB {
24         typedef u32 ID;
25
26         struct CallFrame {
27                 // Address Space and PC to return to
28                 Mem::ProcAddrSpace *ret_aspace;
29                 ulong ret_pc;
30                 
31                 // Caller's PIB Pointer
32                 System::RunTime::ParamInfoBlock *caller_user_pib;
33                 
34                 // Object and Method that were called -- it probably isn't strictly
35                 // necessary to keep track of this here, but it'd help in doing a
36                 // "traceforward" of the method invocation stack in order to
37                 // debug a stalled method call.
38                 
39                 ID object, method;
40         };
41         
42         struct CallStackHeader {
43                 Threads::Thread *thread;
44                 Util::List node;
45                 
46                 // Number of CallFrames under this header.
47                 // For a full page, this is:
48                 //   (Arch::page_size - sizeof(CallStackHeader)) / sizeof(CallFrame)
49                 // There is also a much smaller group of call frames in the Thread
50                 // structure, so that an ORB stack page doesn't need to be allocated
51                 // in the common case of shallow method nesting.
52         
53                 int num_frames;
54                 
55                 CallFrame frames[0];
56         };
57         
58         struct ObjectHdr;
59         struct Object;
60         typedef u32 ID;
61
62         struct ObjectHdr {
63                 ID id;
64
65                 union {
66                         struct {
67                                 u32 Pointer:1;
68                         };
69                         
70                         u32 flags;
71                 };
72         };
73         
74         struct Object : public ObjectHdr {
75                 Mem::ProcAddrSpace *aspace;
76                 uintptr_t entry;
77         };
78
79         struct ObjectPtr : public ObjectHdr {
80                 Object *object;
81         };
82         
83         union ObjTableEntry {
84                 ObjectHdr hdr;
85                 Object obj;
86                 ObjectPtr ptr;
87         };
88
89         typedef Util::RadixTree<ObjTableEntry, ID, 6> IDTable;
90         typedef Util::RadixTree<ObjectHdr *, ID, 4> IDRMap;
91         typedef Util::BitmapTree<ID> IDAlloc;
92
93         class IDSpace {
94                 // Reverse mapping of object pointers to local IDs
95                 IDTable table;
96                 IDRMap rmap;
97                 IDAlloc alloc;
98         
99         public:
100                 Object *lookup(u32 id);
101                 ObjectHdr *get_local_hdr(Object *obj);
102                 Object *newobj(Mem::ProcAddrSpace *aspace, uintptr_t entry);
103         };
104 }
105
106 #endif