]> git.buserror.net Git - polintos/scott/priv.git/blob - kernel/orb/invoke.cc
random kernel stuff
[polintos/scott/priv.git] / kernel / orb / invoke.cc
1 // orb/invoke.cc -- Method Invocation
2 //
3 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
4 // 
5 // This software is provided 'as-is', without any express or implied warranty.
6 // In no event will the authors or contributors be held liable for any damages
7 // arising from the use of this software.
8 // 
9 // Permission is hereby granted to everyone, free of charge, to use, copy,
10 // modify, prepare derivative works of, publish, distribute, perform,
11 // sublicense, and/or sell copies of the Software, provided that the above
12 // copyright notice and disclaimer of warranty be included in all copies or
13 // substantial portions of this software.
14
15 #include <kern/types.h>
16 #include <kern/orb.h>
17 #include <kern/pagealloc.h>
18 #include <kern/compiler.h>
19 #include <kern/thread.h>
20
21 #include <arch/usercopy.h>
22
23 #include <orb.h>
24
25 using System::RunTime::ParamInfoBlock;
26 using namespace ORB;
27 using Threads::Thread;
28
29 namespace ORB {
30         static CallFrame *new_frame(Thread *thread)
31         {
32                 CallStackHeader *hdr = thread->orbstack_top_hdr;
33                 
34                 if (unlikely(thread->orbstack_top == hdr->num_frames - 1)) {
35                         hdr = static_cast<CallStackHeader *>(Mem::alloc_pages(1));
36                         new(hdr) CallStackHeader;
37                         hdr->thread = thread;
38                         hdr->num_frames = (Arch::page_size - sizeof(CallStackHeader)) /
39                                           sizeof(CallFrame);
40
41                         thread->orbstack_top_hdr->node.add_front(&hdr->node);
42                         thread->orbstack_top_hdr = hdr;
43                         thread->orbstack_top = 0;
44                         return &hdr->frames[0];
45                 }
46                 
47                 return &hdr->frames[++thread->orbstack_top];
48         }
49
50         ObjectHdr *IDSpace::get_local_hdr(Object *obj)
51         {
52                 ObjectHdr *hdr = *rmap.lookup(obj->id);
53                 if (hdr)
54                         return hdr;
55                 
56                 int id = alloc.alloc();
57                 ObjectPtr *ptr = &table.lookup(id, true)->ptr;
58
59                 ptr->id = id;
60                 ptr->flags = 0;
61                 ptr->Pointer = 1;
62                 ptr->object = obj;
63
64                 *rmap.lookup(id, true) = ptr;
65                 return ptr;
66         }
67
68         Object *IDSpace::newobj(Mem::ProcAddrSpace *aspace, uintptr_t entry)
69         {
70                 int id = alloc.alloc();
71                 Object *obj = &table.lookup(id, true)->obj;
72
73                 obj->id = id;
74                 obj->flags = 0;
75                 obj->aspace = aspace;
76                 obj->entry = entry;
77                 
78                 return obj;
79         }
80 }
81
82 extern "C" void invoke_method(ParamInfoBlock *user_pib, ulong ret_pc)
83 {
84         ParamInfoBlock pib = Arch::copyin(user_pib);
85         CallFrame *frame = new_frame(curthread);
86         
87 //      frame->object = objid;
88         frame->caller_user_pib = user_pib;
89         frame->ret_pc = ret_pc;
90         
91         printf("invoke_method: frame %p pib %p ret %lx\n",
92                frame, frame->caller_user_pib,
93                frame->ret_pc);
94         
95         
96 }