]> git.buserror.net Git - polintos/scott/priv.git/blob - kernel/orb/invoke.cc
Initial checkin from Perforce.
[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 // Permission is hereby granted, free of charge, to any person obtaining a copy of
6 // this software and associated documentation files (the "Software"), to deal with
7 // the Software without restriction, including without limitation the rights to
8 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 // of the Software, and to permit persons to whom the Software is furnished to do
10 // so, subject to the following conditions:
11 // 
12 //     * Redistributions of source code must retain the above copyright notice,
13 //       this list of conditions and the following disclaimers.
14 // 
15 //     * Redistributions in binary form must reproduce the above copyright notice,
16 //       this list of conditions and the following disclaimers in the
17 //       documentation and/or other materials provided with the distribution.
18 // 
19 //     * The names of the Software's authors and/or contributors
20 //       may not be used to endorse or promote products derived from
21 //       this Software without specific prior written permission.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
25 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
26 // CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
29 // SOFTWARE.
30
31 #include <kern/types.h>
32 #include <kern/orb.h>
33 #include <kern/pagealloc.h>
34 #include <kern/compiler.h>
35 #include <arch/usercopy.h>
36 #include <orb.h>
37
38 using System::RunTime::ParamInfoBlock;
39 using namespace ORB;
40 using Threads::Thread;
41
42 namespace ORB {
43         static CallFrame *new_frame(Thread *thread)
44         {
45                 CallStackHeader *hdr = thread->orbstack_top_hdr;
46                 
47                 if (unlikely(thread->orbstack_top == hdr->num_frames - 1)) {
48                         hdr = static_cast<CallStackHeader *>(Mem::alloc_pages(1));
49                         new(hdr) CallStackHeader;
50                         hdr->thread = thread;
51                         hdr->num_frames = (Arch::page_size - sizeof(CallStackHeader)) /
52                                           sizeof(CallFrame);
53
54                         thread->orbstack_top_hdr->node.add_front(&hdr->node);
55                         thread->orbstack_top_hdr = hdr;
56                         thread->orbstack_top = 0;
57                         return &hdr->frames[0];
58                 }
59                 
60                 return &hdr->frames[thread->orbstack_top += 1];
61         }
62 }
63
64 extern "C" void invoke_method(ulong objid, ulong methid,
65                               ParamInfoBlock *user_pib, ulong ret_pc)
66 {
67         ParamInfoBlock pib = Arch::copyin(user_pib);
68         CallFrame *frame = new_frame(curthread);
69         
70         frame->object = objid;
71         frame->method = methid;
72         frame->caller_user_pib = user_pib;
73         frame->ret_pc = ret_pc;
74         
75         printf("invoke_method: frame %p object %lx method %lx pib %p ret %lx\n",
76                frame, frame->object, frame->method, frame->caller_user_pib,
77                frame->ret_pc);
78         
79         
80 }