summarylogtreecommitdiffstats
path: root/gcc5-something_something_the_dark_side.patch
blob: 6ec3de3dfdf05fa6b297dbbaf444db87430addbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
diff -uNr 15.12/common/lib/modules/fglrx/15.12/common/lib/modules/fglrx/build_mod/firegl_public.c 15.12b/common/lib/modules/fglrx/build_mod/firegl_public.c
--- 15.12/common/lib/modules/fglrx/build_mod/firegl_public.c	2015-12-22 20:38:02.000000000 +0100
+++ 15.12b/common/lib/modules/fglrx/build_mod/firegl_public.c	2015-12-22 21:23:25.960041558 +0100
@@ -6154,6 +6154,7 @@
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
     kernel_fpu_begin();
 #else
+    preempt_disable();
     __kernel_fpu_begin();
 #endif
 #else
@@ -6208,6 +6209,7 @@
     kernel_fpu_end();
 #else
     __kernel_fpu_end();
+    preempt_enable();
 #endif
 }
 
diff -uNr 15.12/common/lib/modules/fglrx/build_mod/kcl_debug.c 15.12b/common/lib/modules/fglrx/build_mod/kcl_debug.c
--- 15.12/common/lib/modules/fglrx/build_mod/kcl_debug.c	2015-12-22 20:38:02.000000000 +0100
+++ 15.12b/common/lib/modules/fglrx/build_mod/kcl_debug.c	2015-11-25 19:05:48.000000000 +0100
@@ -29,19 +29,20 @@
  * - not declared in the corresponding header
  *
  */
-
 #include <asm-generic/errno-base.h> //for EINVAL definition
 
 #include <linux/version.h>
 #include <linux/kernel.h>
 #include <linux/sysrq.h>
-
+#include <linux/thread_info.h>
+#include "firegl_public.h"
 #include "kcl_debug.h"
 
+extern void* ATI_API_CALL KCL_MEM_SmallBufferAllocAtomic(kcl_size_t size);
+extern void ATI_API_CALL KCL_MEM_SmallBufferFree(void* p);
+
 extern int ATI_API_CALL firegl_debug_dump(void);
 
-extern void* ATI_API_CALL KCL_MEM_SmallBufferAllocAtomic(unsigned long size);
-extern void ATI_API_CALL KCL_MEM_SmallBufferFree(void* p);
 static unsigned int prvGetCpuId(void);
 
 static void kcl_debug_sysrq_dump_handler(int key
@@ -141,7 +142,6 @@
  */
 void ATI_API_CALL KCL_DEBUG_Print(const char* fmt, ...)
 {
-
     char* buffer=KCL_MEM_SmallBufferAllocAtomic(MAX_STRING_LENGTH);
     va_list marker;
 
@@ -156,6 +156,47 @@
     KCL_MEM_SmallBufferFree(buffer);
 }
 
+/** \brief Print debug information to the OS debug console according to traceMask and debugMask 
+ *  \param traceMask Bit mask of enabled trace function
+ *  \param debugMask Bit mask of enabled debug level. 0-7 total
+ *  \param name function name
+ *  \param line line number inside the file 
+ *  \param the print parameter
+ *  \param fmt printf-like formatting string
+ *  \param ... printf-like parameters
+ */
+void ATI_API_CALL KCL_DEBUG_Print_Trace(unsigned int traceMask, unsigned int debugMask, void* name, int line, long param, const char* fmt, ...)
+{
+    int print = firegl_trace(traceMask, debugMask, name, line, param);
+    if(print)
+    {
+        int len;
+        char* buffer=KCL_MEM_SmallBufferAllocAtomic(MAX_STRING_LENGTH);
+        if(buffer==NULL)
+            return;
+        if(fmt == NULL)
+        {
+            buffer[0] = '\n';
+            buffer[1] = '\0';
+        }
+        else
+        {
+            va_list marker;
+            va_start(marker, fmt);
+            kcl_vsnprintf(buffer,255,fmt, marker);
+            va_end(marker);
+            len = strlen(buffer);
+            if(buffer[len-1] != '\n')
+            {
+                buffer[len]='\n';
+                buffer[len+1]='\0';
+            }
+        }
+        KCL_DEBUG_Print("[fglrx] %s:%d %s", (char*)name, line, buffer);
+        KCL_MEM_SmallBufferFree(buffer);
+    }
+}
+
 /** \brief Register keyboard handler to dump module internal state
  *  \param enable 1 to register the handler, 0 to unregister it
  *  \return 0
@@ -170,7 +211,6 @@
     {
         unregister_sysrq_key('l', &kcl_debug_sysrq_dump_op);
     }
-
     return 0;
 }
 
@@ -180,7 +220,6 @@
 {
     dump_stack();
 }
-
 /* FIXME: this is temporary workaround to support code using old naming convention */
 
 void ATI_API_CALL __ke_printk(const char* fmt, ...)
@@ -204,4 +243,67 @@
 
 /* End of FIXME */
 
+#ifdef CONFIG_4KSTACKS
+#define STACK_SIZE_MASK 4095UL
+#define STACK_SIZE (4096 - sizeof(struct thread_info))
+#else
+#define STACK_SIZE_MASK 8191UL
+#define STACK_SIZE (8192 - sizeof(struct thread_info))
+#endif
 
+static unsigned long stackBase(void)
+{
+    unsigned long esp = ((unsigned long)&esp) & ~STACK_SIZE_MASK;
+    return esp + sizeof(struct thread_info);
+}
+
+/* Don't inline this. The stack frame of this function provides
+ * protection to the caller's stack frame. */
+static noinline unsigned long stackCur(void)
+{
+    unsigned long esp = (unsigned long)&esp;
+    return esp;
+}
+
+/** \brief Mark unused stack with a magick number
+ *
+ * \return  Current amount of stack used in bytes
+ */
+#define STACK_TAG 0x89abcdef
+unsigned ATI_API_CALL KCL_DEBUG_StackTag(void)
+{
+    unsigned *p, *q;
+    unsigned free;
+
+    p = (unsigned *)((stackBase() + sizeof(unsigned)-1) &
+                     ~(sizeof(unsigned)-1));
+    q = (unsigned *)(stackCur() & ~(sizeof(unsigned)-1));
+    free = (unsigned long)q - (unsigned long)p;
+
+    while (p < q)
+    {
+        *p++ = STACK_TAG;
+    }
+
+    return STACK_SIZE - free;
+}
+
+/** \brief Measure maximum amount of stack usage since last call to StackTag
+ *
+ * \return  Maximum amount of stack usage since last call to StackTag in bytes
+ */
+unsigned ATI_API_CALL KCL_DEBUG_StackMeasure(void)
+{
+    unsigned *base, *p, *q;
+
+    base = p = (unsigned *)((stackBase() + sizeof(unsigned)-1) &
+                            ~(sizeof(unsigned)-1));
+    q = (unsigned *)(stackCur() & ~(sizeof(unsigned)-1));
+
+    while (p < q && *p == STACK_TAG)
+    {
+        p++;
+    }
+
+    return STACK_SIZE - ((unsigned long)p - (unsigned long)base);
+}
diff -uNr 15.12/common/lib/modules/fglrx/build_mod/kcl_debug.h 15.12b/common/lib/modules/fglrx/build_mod/kcl_debug.h
--- 15.12/common/lib/modules/fglrx/build_mod/kcl_debug.h	2015-12-22 20:38:02.000000000 +0100
+++ 15.12b/common/lib/modules/fglrx/build_mod/kcl_debug.h	2015-11-25 19:05:48.000000000 +0100
@@ -64,20 +64,27 @@
    FN_GENERIC_MAXIMUM     = 0x3f
 } FN_TRACE;
 
-extern void ATI_API_CALL firegl_trace(unsigned int traceMask,
+extern int ATI_API_CALL firegl_trace(unsigned int traceMask,
                                       unsigned int debugMask,
                                       void* name,
                                       int line,
-                                      long param,
-                                      const char* fmt,
-                                      ...);
+                                      long param);
 
 #define MAX_STRING_LENGTH    512
 
 void ATI_API_CALL KCL_DEBUG_Print(const char* fmt, ...);
+void ATI_API_CALL KCL_DEBUG_Print_Trace(unsigned int traceMask,
+	                                             unsigned int debugMask,
+	                                             void* name,
+	                                             int line,
+	                                             long param,
+	                                             const char* fmt,
+	                                             ...);
 int ATI_API_CALL KCL_DEBUG_RegKbdHandler(int enable);
 int ATI_API_CALL KCL_DEBUG_RegKbdDumpHandler(int enable);
 void ATI_API_CALL KCL_DEBUG_OsDump(void);
+unsigned ATI_API_CALL KCL_DEBUG_StackTag(void);
+unsigned ATI_API_CALL KCL_DEBUG_StackMeasure(void);
 
 #ifdef SPECIAL
 #undef SPECIAL
@@ -209,102 +216,106 @@
     KCL_DEBUG_Print("<6>[fglrx] " fmt, ##arg)
 
 
-#define KCL_DEBUG_TRACE(m, p, fmt, arg...)  \
-    do                                      \
-    {                                       \
-        firegl_trace(m,                     \
-                     FN_DEBUG_TRACE,        \
-                     (void*)__FUNCTION__,   \
-                     (int)(__LINE__),       \
-                     (long)(p),             \
-                     fmt,                   \
-                     ##arg);                \
+#define KCL_DEBUG_TRACE(m, p, fmt, arg...)       \
+    do                                           \
+    {                                            \
+        KCL_DEBUG_Print_Trace(m,                 \
+                     FN_DEBUG_TRACE,             \
+                     (void*)__FUNCTION__,        \
+                     (int)(__LINE__),            \
+                     (long)(p),                  \
+                     fmt,                        \
+                     ##arg);                     \
     } while (0)
 
 #define KCL_DEBUG_TRACEIN  KCL_DEBUG_TRACE
 
-#define KCL_DEBUG_TRACEOUT(m, p, fmt, arg...)                                                                     \
-    do                                      \
-    {                                       \
-        firegl_trace(m,                     \
-                     FN_DEBUG_TRACEOUT,     \
-                     (void*)__FUNCTION__,   \
-                     (int)(__LINE__),       \
-                     (long)(p),             \
-                     fmt,                   \
-                     ##arg);                \
-    } while (0)
-
-#define KCL_DEBUG1(m, fmt, arg...)          \
-    do                                      \
-    {                                       \
-        firegl_trace(m,                     \
-                     FN_DEBUG_LEVEL1,       \
-                     (void*)__FUNCTION__,   \
-                     (int)__LINE__,         \
-                     0,                     \
-                     fmt,                   \
-                     ##arg);                \
-    } while (0)
-
-#define KCL_DEBUG2(m, fmt, arg...)          \
-    do                                      \
-    {                                       \
-        firegl_trace(m,                     \
-                     FN_DEBUG_LEVEL2,       \
-                     (void*)__FUNCTION__,   \
-                     (int)__LINE__,         \
-                     0,                     \
-                     fmt,                   \
-                     ##arg);                \
-    } while (0)
-
-#define KCL_DEBUG3(m, fmt, arg...)          \
-    do                                      \
-    {                                       \
-        firegl_trace(m,                     \
-                     FN_DEBUG_LEVEL3,       \
-                     (void*)__FUNCTION__,   \
-                     (int)__LINE__,         \
-                     0,                     \
-                     fmt,                   \
-                     ##arg);                \
-    } while (0)
-
-#define KCL_DEBUG4(m, fmt, arg...)          \
-    do                                      \
-    {                                       \
-        firegl_trace(m,                     \
-                     FN_DEBUG_LEVEL4,       \
-                     (void*)__FUNCTION__,   \
-                     (int)__LINE__,         \
-                     0,                     \
-                     fmt,                   \
-                     ##arg);                \
-    } while (0)
-
-#define KCL_DEBUG5(m, fmt, arg...)          \
-    do                                      \
-    {                                       \
-        firegl_trace(m,                     \
-                     FN_DEBUG_LEVEL5,       \
-                     (void*)__FUNCTION__,   \
-                     (int)__LINE__,         \
-                     0,                     \
-                     fmt,                   \
-                     ##arg);                \
-    } while (0)
-
-#define KCL_DEBUG6(m, fmt, arg...)          \
-    do                                      \
-    {                                       \
-        firegl_trace(m,                     \
-                     FN_DEBUG_LEVEL6,       \
-                     (void*)__FUNCTION__,   \
-                     (int)__LINE__,         \
-                     0,                     \
-                     fmt,                   \
-                     ##arg);                \
+#define KCL_DEBUG_TRACEOUT(m, p, fmt, arg...)    \
+    do                                           \
+    {                                            \
+        KCL_DEBUG_Print_Trace(m,                 \
+                     FN_DEBUG_TRACEOUT,          \
+                     (void*)__FUNCTION__,        \
+                     (int)(__LINE__),            \
+                     (long)(p),                  \
+                     fmt,                        \
+                     ##arg);                     \
+    } while (0)
+
+
+#define KCL_DEBUG1(m, fmt, arg...)               \
+    do                                           \
+    {                                            \
+        KCL_DEBUG_Print_Trace(m,                 \
+                     FN_DEBUG_LEVEL1,            \
+                     (void*)__FUNCTION__,        \
+                     (int)(__LINE__),            \
+                     0,                          \
+                     fmt,                        \
+                     ##arg);                     \
+    } while (0)
+
+#define KCL_DEBUG2(m, fmt, arg...)               \
+    do                                           \
+    {                                            \
+        KCL_DEBUG_Print_Trace(m,                 \
+                     FN_DEBUG_LEVEL2,            \
+                     (void*)__FUNCTION__,        \
+                     (int)(__LINE__),            \
+                     0,                          \
+                     fmt,                        \
+                     ##arg);                     \
+    } while (0)
+
+#define KCL_DEBUG3(m, fmt, arg...)               \
+    do                                           \
+    {                                            \
+        KCL_DEBUG_Print_Trace(m,                 \
+                     FN_DEBUG_LEVEL3,            \
+                     (void*)__FUNCTION__,        \
+                     (int)(__LINE__),            \
+                     0,                          \
+                     fmt,                        \
+                     ##arg);                     \
+    } while (0)
+
+
+#define KCL_DEBUG4(m, fmt, arg...)               \
+    do                                           \
+    {                                            \
+        KCL_DEBUG_Print_Trace(m,                 \
+                     FN_DEBUG_LEVEL4,            \
+                     (void*)__FUNCTION__,        \
+                     (int)(__LINE__),            \
+                     0,                          \
+                     fmt,                        \
+                     ##arg);                     \
+    } while (0)
+
+
+#define KCL_DEBUG5(m, fmt, arg...)               \
+    do                                           \
+    {                                            \
+        KCL_DEBUG_Print_Trace(m,                 \
+                     FN_DEBUG_LEVEL5,            \
+                     (void*)__FUNCTION__,        \
+                     (int)(__LINE__),            \
+                     0,                          \
+                     fmt,                        \
+                     ##arg);                     \
+    } while (0)
+
+
+#define KCL_DEBUG6(m, fmt, arg...)               \
+    do                                           \
+    {                                            \
+        KCL_DEBUG_Print_Trace(m,                 \
+                     FN_DEBUG_LEVEL6,            \
+                     (void*)__FUNCTION__,        \
+                     (int)(__LINE__),            \
+                     0,                          \
+                     fmt,                        \
+                     ##arg);                     \
     } while (0)
 
 #endif