1 | /* |
---|
2 | * Copyright (c) 2011 Aeroflex Gaisler |
---|
3 | * |
---|
4 | * BSD license: |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
7 | * of this software and associated documentation files (the "Software"), to deal |
---|
8 | * in the Software without restriction, including without limitation the rights |
---|
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
10 | * copies of the Software, and to permit persons to whom the Software is |
---|
11 | * furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
---|
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
22 | * THE SOFTWARE. |
---|
23 | */ |
---|
24 | |
---|
25 | |
---|
26 | #include <asm-leon/leon.h> |
---|
27 | #include <asm-leon/leonstack.h> |
---|
28 | #include <asm-leon/asmmacro.h> |
---|
29 | |
---|
30 | extern volatile unsigned int __window_overflow_rettseq[3]; |
---|
31 | extern volatile unsigned int __window_overflow_slow1[2]; |
---|
32 | |
---|
33 | static unsigned int installed = 0; |
---|
34 | static unsigned int save__window_overflow_rettseq[3]; |
---|
35 | |
---|
36 | int |
---|
37 | install_winoverflow_hook (void (*func) (void)) |
---|
38 | { |
---|
39 | if (installed) |
---|
40 | { |
---|
41 | return 0; |
---|
42 | } |
---|
43 | if (!installed) |
---|
44 | { |
---|
45 | /* |
---|
46 | a7 50 00 00 rd %wim, %l3 |
---|
47 | ae 10 00 01 mov %g1, %l7 |
---|
48 | 83 34 e0 01 srl %l3, 1, %g1 |
---|
49 | |
---|
50 | 81 c4 40 00 jmp %l1 |
---|
51 | 81 cc 80 00 rett %l2 */ |
---|
52 | save__window_overflow_rettseq[0] = __window_overflow_rettseq[0]; |
---|
53 | save__window_overflow_rettseq[1] = __window_overflow_rettseq[1]; |
---|
54 | save__window_overflow_rettseq[2] = __window_overflow_rettseq[2]; |
---|
55 | |
---|
56 | /*29 10 00 31 sethi %hi(0x4000c400), %l4 |
---|
57 | 81 c5 22 48 jmp %l4 + 0x248 |
---|
58 | 01 00 00 00 nop */ |
---|
59 | |
---|
60 | __window_overflow_rettseq[0] = ((((unsigned int) func) >> 10) & 0x3fffff) | 0x29000000; /* upper 22 */ |
---|
61 | __window_overflow_rettseq[1] = ((((unsigned int) func)) & 0x03ff) | 0x81c52000; /* lower 10 */ |
---|
62 | __window_overflow_rettseq[2] = 0x01000000; /* nop */ |
---|
63 | |
---|
64 | sparc_leon23_icache_flush (); |
---|
65 | installed = 1; |
---|
66 | } |
---|
67 | return 0; |
---|
68 | } |
---|
69 | |
---|
70 | void |
---|
71 | uninstall_winoverflow_hook () |
---|
72 | { |
---|
73 | if (installed) |
---|
74 | { |
---|
75 | __window_overflow_rettseq[0] = save__window_overflow_rettseq[0]; |
---|
76 | __window_overflow_rettseq[1] = save__window_overflow_rettseq[1]; |
---|
77 | __window_overflow_rettseq[2] = save__window_overflow_rettseq[2]; |
---|
78 | |
---|
79 | sparc_leon23_icache_flush (); |
---|
80 | installed = 0; |
---|
81 | } |
---|
82 | } |
---|