ebb1f4ce02779c7305989a70b138b19a9b9eba22
[jump.git] / dol / src / dol / visitor / cell / template / spu_process_wrapper_template.cpp
1 /*
2  * Square_wrapper.cpp
3  *
4  *  Created on: Feb 27, 2009
5  *      Author: lschor
6  */
7
8
9 #include "@PROCESSNAME@Wrapper.h"
10 #include "../lib/spu/dolSupport.h"
11
12 #include "@PROCESSNAME@.c"
13
14 @PROCESSNAME@Wrapper::@PROCESSNAME@Wrapper(uint64_t argp) {
15         // reserve DMA tag ID
16         uint32_t tag_id;
17         if((tag_id=mfc_tag_reserve())==MFC_TAG_INVALID){
18                 printf("SPE: ERROR - can't reserve a tag ID\n"); return;
19         }
20
21         // Get the context information for the whole system
22         mfc_get((void*) &ctx_proc, argp, sizeof(ctx_proc), tag_id, 0, 0);
23         mfc_write_tag_mask(1<<tag_id);
24         mfc_read_tag_status_all();
25
26         this->name = (char *)_malloc_align((uint32_t)ctx_proc.processNameLen, 4);
27         if(!this->name) {
28             fprintf(stderr,"[SPUProcessWrapper] Memory allocation failure\n");
29             exit(-1);
30         }
31         mfc_get((void *)this->name, ctx_proc.processName, ctx_proc.processNameLen, tag_id, 0, 0);
32         waittag(tag_id);
33
34
35         //initialize the index array
36         for (int i = 0; i < 4; i++)     {
37                 this->_iteratorIndex[i] = getIndex(this->name, "_", i);
38         }
39
40     try { _state = (LocalState) new @PROCESSNAME_UPPER@_State; }
41     catch(std::bad_alloc &e) {
42         fprintf(stderr, "[SPUProcessWrapper] Memory allocation failure\n");
43         exit(-1);
44     }
45     _process.local = _state;
46     _process.init = @PROCESSNAME@_init;
47     _process.fire = @PROCESSNAME@_fire;
48     _process.wptr = (void*)&_wrapper_data;
49
50     _wrapper_data.wrapper = this;
51
52         // Init the process
53         _process.init(&_process);
54
55         // release tag ID before exiting
56         mfc_tag_release(tag_id);
57 }
58
59 @PROCESSNAME@Wrapper::~@PROCESSNAME@Wrapper() {
60         // Free the state
61     if (_state)
62         delete (@PROCESSNAME_UPPER@_State*) _state;
63
64         // Free the name of the wrapper
65         _free_align(this->name);
66 }