source: titan/titan/sh4port.h @ 24222

Last change on this file since 24222 was 23293, checked in by nit, 11 years ago

fix

File size: 17.4 KB
Line 
1#ifndef SH4PORT_H
2#define SH4PORT_H
3
4#include <bpamem.h>
5#include <libmmeimage.h>
6#include <linux/stmfb.h>
7
8struct stmfbio_output_configuration outcfg;
9struct stmfbio_outputinfo outinfo;
10struct stmfbio_planeinfo planemode;
11struct stmfbio_var_screeninfo_ex infoex;
12
13#define VIDEO_DISCONTINUITY                   _IO('o',  84)
14#define DVB_DISCONTINUITY_SKIP                0x01
15#define DVB_DISCONTINUITY_CONTINUOUS_REVERSE  0x02
16
17// inform the player about the jump in the stream data
18// flag 0: skip
19// flag 1: cont. reverse
20int videodiscontinuityskip(struct dvbdev* node, int flag)
21{
22        int param = 0;
23
24        if(node == NULL)
25        {
26                err("NULL detect");
27                return 1;
28        }
29
30        if(flag >= 0)
31                param = DVB_DISCONTINUITY_SKIP;
32        else
33                param = DVB_DISCONTINUITY_CONTINUOUS_REVERSE;
34
35        debug(200, "VIDEO_DISCONTINUITY");
36        if(ioctl(node->fd, VIDEO_DISCONTINUITY, (void*)param) < 0)
37        {
38                perr("VIDEO_DISCONTINUITY");
39                return 1;
40        }
41
42        return 0;
43}
44
45void fbsave()
46{
47  outcfg.outputid = STMFBIO_OUTPUTID_MAIN;
48  if(ioctl(fb->fd, STMFBIO_GET_OUTPUT_CONFIG, &outcfg) < 0)
49  {
50    perr("ioctl STMFBIO_GET_OUTPUT_CONFIG");
51  }
52
53        outinfo.outputid = STMFBIO_OUTPUTID_MAIN;
54        if(ioctl(fb->fd, STMFBIO_GET_OUTPUTINFO, &outinfo) < 0)
55  {
56                perr("ioctl STMFBIO_GET_OUTPUTINFO");
57  }
58
59        planemode.layerid = 0;
60        if(ioctl(fb->fd, STMFBIO_GET_PLANEMODE, &planemode) < 0)
61  {
62    perr("ioctl STMFBIO_GET_PLANEMODE");
63  }
64
65  if(ioctl(fb->fd, STMFBIO_GET_VAR_SCREENINFO_EX, &infoex) < 0)
66  {
67    perr("ioctl STMFBIO_GET_VAR_SCREENINFO_EX");
68  }
69}
70
71void fbrestore()
72{
73  if(ioctl(fb->fd, STMFBIO_SET_VAR_SCREENINFO_EX, &infoex) < 0)
74  {
75    perr("ioctl STMFBIO_SET_VAR_SCREENINFO_EX");
76  }
77
78        if(ioctl(fb->fd, STMFBIO_SET_PLANEMODE, &planemode) < 0)
79  {
80                perr("ioctl STMFBIO_SET_PLANEMODE");
81  }
82
83        if(ioctl(fb->fd, STMFBIO_SET_VAR_SCREENINFO_EX, &infoex) < 0)
84  {
85                perr("ioctl STMFBIO_SET_VAR_SCREENINFO_EX");
86  }
87
88        if(ioctl(fb->fd, STMFBIO_SET_OUTPUTINFO, &outinfo) < 0)
89  {
90                perr("ioctl STMFBIO_SET_OUTPUTINFO");
91  }
92
93        if(ioctl(fb->fd, STMFBIO_SET_OUTPUT_CONFIG, &outcfg) < 0)
94  {
95                perr("ioctl STMFBIO_SET_OUTPUT_CONFIG");
96  }
97}
98
99void setfbvarsize(struct fb* newnode)
100{
101        if(newnode != NULL)
102                newnode->varfbsize = 1920 * 1080 * newnode->colbytes;
103}
104
105void enablemanualblit()
106{
107}
108
109//flag 0 = no animation
110//flag 1 = animation
111void blitfb2(struct fb* fbnode, int flag)
112{
113        int i = 0, max = 1, wstep = 0, hstep = 0, ret = 0;
114        unsigned char buf[10];
115
116        if(fbnode == NULL) return;
117        if(fbnode == fb) return;
118
119        if(status.rguidfd > -1)
120        {
121                m_lock(&status.accelfbmutex, 16);
122               
123                int zlen = 0;
124                char* zbuf = NULL;
125                blitscale(0, 0, fbnode->width, fbnode->height, 440, 330, 1);
126                ret = ozip((char*)accelfb->fb, 440 * 330 * 4, &zbuf, &zlen, 1);
127
128                if(ret == 0)
129                {
130                        memset(buf, 0, 10);
131                        char* tmpnr = oitoa(zlen);
132                        memcpy(buf, tmpnr, strlen(tmpnr));
133                        free(tmpnr); tmpnr = NULL;
134                        socksend(&status.rguidfd, buf, 10, 5000 * 1000);
135                        socksend(&status.rguidfd, (unsigned char*)zbuf, zlen, 5000 * 1000);
136                }
137                free(zbuf); zbuf = NULL;
138                zlen = 0;
139
140                m_unlock(&status.accelfbmutex, 16);
141        }
142
143        if(status.write_png == 1 && status.infobaraktiv == 0)
144        {
145                m_lock(&status.accelfbmutex, 16);
146                blitscale(0, 0, fbnode->width, fbnode->height, 320, 240, 1);
147                if(writeFBfile.ActBuf == NULL)
148                {
149                        writeFBfile.buf1 = malloc(4 * 320 * 240);
150                        writeFBfile.ActBuf = writeFBfile.buf1;
151                        memcpy(writeFBfile.buf1, accelfb->fb, 4 * 320 * 240);
152                        addtimer(&fb2png_thread, START, 10000, 1, NULL, NULL, NULL);
153                }
154                else if(writeFBfile.buf1 == writeFBfile.ActBuf)
155                {
156                        if(writeFBfile.buf2 == NULL)
157                                writeFBfile.buf2 = malloc(4 * 320 * 240);
158                        memcpy(writeFBfile.buf2, accelfb->fb, 4 * 320 * 240);
159                }
160                else if(writeFBfile.buf2 == writeFBfile.ActBuf)
161                {
162                        if(writeFBfile.buf1 == NULL)
163                                writeFBfile.buf1 = malloc(4 * 320 * 240);
164                        memcpy(writeFBfile.buf1, accelfb->fb, 4 * 320 * 240);
165                }
166                m_unlock(&status.accelfbmutex, 16);
167        }
168
169        int mode3d = 0;
170        char* mode3dstr = NULL;
171
172        if(status.leftoffset != 0) blitrect(0, 0, status.leftoffset, fb->height, 0, 255, 2);
173        if(status.rightoffset != 0) blitrect(fb->width - status.rightoffset, 0, status.rightoffset, fb->height, 0, 255, 2);
174        if(status.topoffset != 0) blitrect(0, 0, fb->width, status.topoffset, 0, 255, 2);
175        if(status.bottomoffset != 0) blitrect(0, fb->height - status.bottomoffset, fb->width, status.bottomoffset, 0, 255, 2);
176
177        mode3dstr = getconfig("av_mode3d", NULL);
178        if(ostrcmp(mode3dstr, "sbs") == 0)
179                mode3d = 1;
180        else if(ostrcmp(mode3dstr, "tab") == 0)
181                mode3d = 2;
182
183        STMFBIO_BLT_DATA  bltData;
184        memset(&bltData, 0, sizeof(STMFBIO_BLT_DATA));
185
186        bltData.operation  = BLT_OP_COPY;
187        bltData.srcOffset  = fbnode->fb - fb->fb;
188        bltData.srcPitch   = fbnode->pitch;
189        bltData.src_top    = 0;
190        bltData.src_left   = 0;
191        bltData.src_right  = fbnode->width;
192        bltData.src_bottom = fbnode->height;
193        bltData.srcFormat  = SURF_BGRA8888;
194        bltData.srcMemBase = STMFBGP_FRAMEBUFFER;
195
196        bltData.dstOffset  = 0;
197        bltData.dstPitch   = fb->pitch;
198        bltData.dst_left   = status.leftoffset;
199        bltData.dst_top    = status.topoffset;
200        if(mode3d == 1)
201                bltData.dst_right = (fb->width - status.rightoffset) / 2;
202        else
203                bltData.dst_right = fb->width - status.rightoffset;
204        if(mode3d == 2)
205                bltData.dst_bottom = (fb->height - status.bottomoffset) / 2;
206        else
207                bltData.dst_bottom = fb->height - status.bottomoffset;
208        bltData.dstFormat  = SURF_BGRA8888;
209        bltData.dstMemBase = STMFBGP_FRAMEBUFFER;
210
211        if(flag == 1 && status.screenanim > 0 && mode3d == 0)
212        {
213                int width = (fb->width - status.rightoffset) - status.leftoffset;
214                int height = (fb->height - status.topoffset) - status.bottomoffset;
215                max = 25;
216                if(status.screenanim == 1 || status.screenanim == 3)
217                {
218                        bltData.dst_left = (width / 2) - 1;
219                        bltData.dst_right = (width / 2) + 1;
220                }
221                if(status.screenanim == 2 || status.screenanim == 3)
222                {
223                        bltData.dst_top = (height / 2) - 1;
224                        bltData.dst_bottom = (height / 2) + 1;
225                }
226                wstep = width / max;
227                hstep = height / max;
228        }
229
230        for(i = 0; i < max; i++)
231        {
232
233                if(status.screenanim == 1 || status.screenanim == 3)
234                {
235                        int tmpleft = bltData.dst_left - wstep;
236                        int tmpright = bltData.dst_right + wstep;
237                        if(tmpleft < status.leftoffset)
238                                tmpleft = status.leftoffset;
239                        if(tmpright > fb->width - status.rightoffset)
240                                tmpright = fb->width - status.rightoffset;
241                        bltData.dst_left = tmpleft;
242                        bltData.dst_right = tmpright;
243                }
244
245                if(status.screenanim == 2 || status.screenanim == 3)
246                {
247                        int tmptop = bltData.dst_top - hstep;
248                        int tmpbottom = bltData.dst_bottom + hstep;
249                        if(tmptop < status.topoffset)
250                                tmptop = status.topoffset;
251                        if(tmpbottom > fb->height - status.bottomoffset)
252                                tmpbottom = fb->height - status.bottomoffset;
253                        bltData.dst_top = tmptop;
254                        bltData.dst_bottom = tmpbottom;
255                }
256
257                if(status.screenanim > 0) usleep(status.screenanimspeed * 1000);
258
259                if (ioctl(fb->fd, STMFBIO_BLT, &bltData) < 0)
260                {
261                        perr("ioctl STMFBIO_BLT");
262                }
263                if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
264                {
265                        perr("ioctl STMFBIO_SYNC_BLITTER");
266                }
267
268                if(mode3d != 0)
269                {
270                        if(mode3d == 1)
271                                bltData.dst_left = status.leftoffset + ((fb->width - status.rightoffset) / 2);
272                        if(mode3d == 2)
273                                bltData.dst_top = status.topoffset + ((fb->height - status.bottomoffset) / 2);
274                        bltData.dst_right  = fb->width - status.rightoffset;
275                        bltData.dst_bottom = fb->height - status.bottomoffset;
276
277                        if (ioctl(fb->fd, STMFBIO_BLT, &bltData) < 0)
278                        {
279                                perr("ioctl STMFBIO_BLT");
280                        }
281                        if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
282                        {
283                                perr("ioctl STMFBIO_SYNC_BLITTER");
284                        }
285                }
286        }
287}
288
289void setfbtransparent(int value)
290{
291        struct stmfbio_var_screeninfo_ex varEx = {0};
292
293        varEx.layerid  = 0;
294        varEx.activate = STMFBIO_ACTIVATE_IMMEDIATE;
295        varEx.caps = STMFBIO_VAR_CAPS_OPACITY;
296        varEx.opacity = value;
297
298
299        if(ioctl(fb->fd, STMFBIO_SET_VAR_SCREENINFO_EX, &varEx) < 0)
300                perr("STMFBIO_SET_VAR_SCREENINFO_EX");
301}
302
303int allocbpamem(size_t size, int *memfd, unsigned char **mem)
304{
305        *memfd = open("/dev/bpamem0", O_RDWR);
306       
307        if(*memfd < 0)
308        {
309                err("cannot access /dev/bpamem0! err = %d", (int)*memfd);
310                return -1;
311        }
312
313        BPAMemAllocMemData bpa_data;
314        bpa_data.bpa_part = "LMI_VID";
315        bpa_data.mem_size = size;
316        int res;
317        res = ioctl(*memfd, BPAMEMIO_ALLOCMEM, &bpa_data); // request memory from bpamem
318        if(res)
319        {
320                err("cannot alloc required bpa mem");
321                close(*memfd);
322                return -1;
323        }
324
325        char* bpa_mem_device = NULL;
326        bpa_mem_device = malloc(30);
327        if(bpa_mem_device == NULL)
328        {
329                err("no mem");
330                return -1;
331        }
332
333        sprintf(bpa_mem_device, "/dev/bpamem%d", bpa_data.device_num);
334        close(*memfd);
335
336        *memfd = open(bpa_mem_device, O_RDWR);
337
338        if(*memfd < 0)
339        {
340                free(bpa_mem_device);
341                err("cannot access %s! err = %d", bpa_mem_device, (int)*memfd);
342                return -1;
343        }
344
345        *mem = (unsigned char *)mmap(0, bpa_data.mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, *memfd, 0);
346
347        if(*mem == MAP_FAILED)
348        {
349                err("could not map bpa mem");
350                free(bpa_mem_device);
351                ioctl(*memfd, BPAMEMIO_FREEMEM);
352                close(*memfd);
353                return -1;
354        }
355       
356        free(bpa_mem_device);
357        return 0;
358}
359
360void freebpamem(int memfd, unsigned char* mem, size_t len)
361{
362        munmap(mem, len);
363        ioctl(memfd, BPAMEMIO_FREEMEM);
364        close(memfd);
365}
366
367//mode 0: with fill (draw to skinfb)
368//mode 1: without fill (draw to skinfb)
369//mode 2: with fill (draw to fb)
370//mode 3: without fill (draw to fb)
371void blitrect(int posx, int posy, int width, int height, long color, int transparent, int mode)
372{
373        unsigned long tmpcol;
374
375        transparent = (transparent - 255) * -1;
376        tmpcol = color | ((transparent & 0xff) << 24);
377
378        STMFBIO_BLT_DATA  bltData;
379        memset(&bltData, 0, sizeof(STMFBIO_BLT_DATA));
380
381        if(posx < 0) posx = 0;
382        if(posy < 0) posy = 0;
383        if(mode < 2)
384        {
385                if(posx > skinfb->width) posx = skinfb->width;
386                if(posy > skinfb->height) posy = skinfb->height;
387                if(posx + width > skinfb->width) width = skinfb->width - posx;
388                if(posy + height > skinfb->height) height = skinfb->height - posy;
389        }
390        else
391        {
392                if(posx > fb->width) posx = fb->width;
393                if(posy > fb->height) posy = fb->height;
394                if(posx + width > fb->width) width = fb->width - posx;
395                if(posy + height > fb->height) height = fb->height - posy;
396        }
397
398        if(width <= 0 || height <= 0) return;
399
400        if(mode == 0 || mode == 2)
401                bltData.operation  = BLT_OP_FILL;
402        else if(mode == 1 || mode == 3)
403                bltData.operation  = BLT_OP_DRAW_RECTANGLE;
404        bltData.colour     = tmpcol;
405        bltData.srcFormat  = SURF_ARGB8888;
406        bltData.srcMemBase = STMFBGP_FRAMEBUFFER;
407
408        if(status.usedirectfb == 1)
409                bltData.dstOffset  = 0;
410        else
411        {
412                if(mode < 2)
413                        bltData.dstOffset  = fb->varfbsize;
414                else
415                        bltData.dstOffset  = 0;
416        }
417        if(mode < 2)
418                bltData.dstPitch   = skinfb->pitch;
419        else
420                bltData.dstPitch   = fb->pitch;
421        bltData.dst_top    = posy;
422        bltData.dst_left   = posx;
423        bltData.dst_bottom = posy + height;
424        bltData.dst_right  = posx + width;
425        bltData.dstFormat  = SURF_ARGB8888;
426        bltData.dstMemBase = STMFBGP_FRAMEBUFFER;
427
428        if(ioctl(fb->fd, STMFBIO_BLT, &bltData) < 0)
429        {
430                perr("ioctl STMFBIO_BLT");
431        }
432        if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
433        {
434                perr("ioctl STMFBIO_SYNC_BLITTER");
435        }
436}
437
438int readjpg(const char* filename, unsigned long* width, unsigned long* height, unsigned long* rowbytes, int* channels, unsigned char **mem, int *memfd)
439{
440        FILE *fp;
441        unsigned int temp1, temp2, temp3, temp4;
442
443        if(filename == NULL) return -1;
444
445        debug(200, "hardware decode picture (%s)...", filename);
446
447        if (!(fp = fopen(filename, "rb")))
448                return -1;
449         
450        if(get_jpeg_img_size(fp, &temp1, &temp2) != LIBMMEIMG_SUCCESS)
451                return -1;
452       
453        *width = temp1;
454        *height = temp2;
455        *channels = 3;
456        *rowbytes = *channels * temp1;
457       
458        if(allocbpamem(temp1 * temp2 * (*channels), memfd, mem) != 0)
459        {
460                fclose(fp);
461                return -1;
462        }
463       
464        temp3 = temp1;
465        temp4 = temp2;
466       
467        if(temp3 > skinfb->width) temp3 = skinfb->width;
468        if(temp4 > skinfb->height) temp4 = skinfb->height;
469               
470        if(decode_jpeg_noalloc(fp, temp1, temp2, 200, 200, (char *)*mem, 1) == LIBMMEIMG_SUCCESS)
471        {
472                fclose(fp);
473                return 0;
474        }
475       
476        fclose(fp);
477        freebpamem(*memfd, *mem, temp1 * temp2 * (*channels));
478        err("hardware decode error");
479
480        return -1;
481}
482
483//flag 0: blit from accelfb to skinfb
484//flag 1: blit from skinfb to accelfb
485void blitscale(int posx, int posy, int width, int height, int scalewidth, int scaleheight, int flag)
486{
487        STMFBIO_BLT_DATA  blt_data;
488        memset(&blt_data, 0, sizeof(STMFBIO_BLT_DATA));
489
490        if(scalewidth == 0) scalewidth = width;
491        if(scaleheight == 0) scaleheight = height;
492
493        if(posx < 0) posx = 0;
494        if(posx > skinfb->width) posx = skinfb->width;
495        if(posy < 0) posy = 0;
496        if(posy > skinfb->height) posy = skinfb->height;
497        if(posx + scalewidth > skinfb->width) scalewidth = skinfb->width - posx;
498        if(posy + scaleheight > skinfb->height) scaleheight = skinfb->height - posy;
499       
500        if(width <= 0 || height <= 0 || scalewidth <= 0 || scaleheight <= 0) return;
501       
502        if(flag == 1 && (scalewidth * scaleheight * 4) > accelfb->varfbsize)
503        {
504                err("accelfb to small %d -> %lu ", scalewidth * scaleheight * 4, accelfb->varfbsize);
505                return;
506        }
507
508        blt_data.operation  = BLT_OP_COPY;
509       
510        if(flag == 0)
511        {
512                if(status.usedirectfb == 1)
513                        blt_data.srcOffset  = fb->varfbsize;
514                else
515                        blt_data.srcOffset  = fb->varfbsize + skinfb->varfbsize;
516        }
517        else
518        {
519                if(status.usedirectfb == 1)
520                        blt_data.srcOffset  = 0;
521                else
522                        blt_data.srcOffset  = fb->varfbsize;
523        }
524       
525        blt_data.srcPitch   = width * 4;
526        blt_data.src_top    = 0;
527        blt_data.src_left   = 0;
528        blt_data.src_right  = width;
529        blt_data.src_bottom = height;
530        blt_data.srcFormat  = SURF_ARGB8888;
531        blt_data.srcMemBase = STMFBGP_FRAMEBUFFER;
532       
533        if(flag == 0)
534        {
535                if(status.usedirectfb == 1)
536                {
537                        blt_data.dstOffset  = 0;
538                        blt_data.dstPitch   = fb->pitch;
539                }
540                else
541                {
542                        blt_data.dstOffset  = fb->varfbsize;
543                        blt_data.dstPitch   = skinfb->pitch;
544                }
545        }
546        else
547        {
548                if(status.usedirectfb == 1)
549                {
550                        blt_data.dstOffset  = fb->varfbsize;
551                        blt_data.dstPitch   = skinfb->pitch;
552                }
553                else
554                {
555                        blt_data.dstOffset  = fb->varfbsize + skinfb->varfbsize;
556                        blt_data.dstPitch   = scalewidth * 4;
557                }
558        }
559       
560        blt_data.dst_left   = posx;
561        blt_data.dst_top    = posy;
562        blt_data.dst_right  = posx + scalewidth;
563        blt_data.dst_bottom = posy + scaleheight;
564        blt_data.dstFormat  = SURF_ARGB8888;
565        blt_data.dstMemBase = STMFBGP_FRAMEBUFFER;
566       
567        if (ioctl(fb->fd, STMFBIO_BLT, &blt_data) < 0)
568        {
569                perr("ioctl STMFBIO_BLT");
570        }
571        if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
572        {
573                perr("ioctl STMFBIO_SYNC_BLITTER");
574        }
575}
576
577void blitjpg(unsigned char* buf, int posx, int posy, int width, int height, int scalewidth, int scaleheight, int mwidth, int mheight, int halign, int valign)
578{
579        STMFBIO_BLT_EXTERN_DATA blt_data;
580        memset(&blt_data, 0, sizeof(STMFBIO_BLT_EXTERN_DATA));
581       
582        //auto scale to mwidth / mheight
583        if(scalewidth == 1 && scaleheight == 1)
584                calcautoscale(width, height, mwidth, mheight, &scalewidth, &scaleheight);
585               
586        if(scalewidth == 0) scalewidth = width;
587        if(scaleheight == 0) scaleheight = height;
588
589        if(scalewidth > mwidth) scalewidth = mwidth;
590        if(scaleheight > mheight) scaleheight = mheight;
591
592        if(halign == CENTER)
593                posx += mwidth / 2 - width / 2;
594        else if(halign == RIGHT)
595                posx += mwidth - width;
596        if(valign == MIDDLE)
597                posy += mheight / 2 - height / 2;
598        else if(valign == BOTTOM)
599                posy += mheight - height;
600
601        blt_data.operation  = BLT_OP_COPY;
602        blt_data.ulFlags    = 0;
603        blt_data.srcOffset  = 0;
604        blt_data.srcPitch   = width * 3;
605        blt_data.dstOffset  = 0;
606        blt_data.dstPitch   = skinfb->pitch;
607        blt_data.src_top    = 0;
608        blt_data.src_left   = 0;
609        blt_data.src_right  = width;
610        blt_data.src_bottom = height;
611        blt_data.dst_left   = posx;
612        blt_data.dst_top    = posy;
613       
614        blt_data.dst_right  = posx + scalewidth;
615        blt_data.dst_bottom = posy + scaleheight;
616        blt_data.srcFormat  = SURF_BGR888;
617        blt_data.dstFormat  = SURF_ARGB8888;
618        blt_data.srcMemBase = (char *)buf;
619        blt_data.dstMemBase = (char *)skinfb->fb;
620        blt_data.srcMemSize = width * height * 3;
621        blt_data.dstMemSize = skinfb->pitch * skinfb->height;
622       
623        if(ioctl(skinfb->fd, STMFBIO_BLT_EXTERN, &blt_data) < 0)
624        {
625                err("ioctl STMFBIO_BLT_EXTERN");
626        }
627        if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
628        {
629                perr("ioctl STMFBIO_SYNC_BLITTER");
630        }
631}
632
633void initsignal(struct sigaction* sa)
634{
635        sigaction(SIGILL, sa, NULL);
636        sigaction(SIGBUS, sa, NULL);
637        sigaction(SIGFPE, sa, NULL);
638        sigaction(SIGUSR1, sa, NULL);
639        sigaction(SIGSEGV, sa, NULL);
640        sigaction(SIGUSR2, sa, NULL);
641        sigaction(SIGPIPE, sa, NULL);
642        sigaction(SIGALRM, sa, NULL);
643        sigaction(SIGSTKFLT, sa, NULL);
644        sigaction(SIGABRT, sa, NULL);
645
646        signal(SIGHUP, SIG_IGN);
647        signal(SIGINT, SIG_IGN);
648        signal(SIGTRAP, SIG_IGN);
649        signal(SIGTERM, SIG_IGN);
650        signal(SIGXCPU, SIG_IGN);
651        signal(SIGXFSZ, SIG_IGN);
652        signal(SIGVTALRM, SIG_IGN);
653        signal(SIGPROF, SIG_IGN);
654        signal(SIGPOLL, SIG_IGN);
655        signal(SIGRTMAX, SIG_IGN);
656        signal(SIGPWR, SIG_IGN);
657        signal(SIGSYS, SIG_IGN);
658}
659
660void sighandler(int sig, struct sigcontext ctx)
661{
662        switch(sig)
663        {
664                case SIGALRM:
665                {
666                        err("got signal sigalrm but ignore it");
667                        break;
668                }
669                case SIGPIPE:
670                {
671                        err("got signal sigpipe but ignore it");
672                        break;
673                }
674                case SIGUSR1:
675                {
676                        //todo all configs
677                        reloadconfig(status.configfile);
678                        reloadconfig(getconfig("ownconfig", NULL));
679                        break;
680                }
681                case SIGUSR2: //called if hanging mainthread detect
682                {
683                        debugstack(sig, NULL, NULL);
684                        break;
685                }
686                case SIGILL:
687                case SIGBUS:
688                case SIGFPE:
689                case SIGSEGV:
690                case SIGSTKFLT:
691                {
692                        /* sh4
693                        unsigned long sc_regs[16];
694                        unsigned long sc_pc; //programm counter register
695                        unsigned long sc_pr; //procedure register
696                        unsigned long sc_sr; //status register
697                        unsigned long sc_gbr;
698                        unsigned long sc_mach;
699                        unsigned long sc_macl; */
700
701                        debugstack(sig, (void *)ctx.sc_pr, (void *)ctx.sc_pc);
702                        err("got signal %d (%s), programm counter reg: 0x%lx,  procedure reg: 0x%lx", sig, strsignal(sig), ctx.sc_pc, ctx.sc_pr);
703
704                        if(getconfigint("saverun", NULL) == 1 && status.longjumpbuf != NULL)
705                                siglongjmp(status.longjumpbuf, 999);
706                        else
707                                exit(100);
708                        break;
709                }
710        }
711}
712
713#endif
Note: See TracBrowser for help on using the repository browser.