revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-pc / kernel / _displayalert.c
blob733519eb13d6514a3f1bfa6b2e36ee8afaed4f52
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <bootconsole.h>
7 #include <inttypes.h>
9 #include <kernel_base.h>
10 #include <kernel_debug.h>
11 #include "alert_arch.h"
14 * Display alert on the screen using libbootconsole.
15 * Very useful for early alerts, while the display driver not started yet.
16 * In this case the user gets a nice GURU. Not painted in red yet. :)
19 static inline void PrintChars(char c, ULONG n, struct KernelBase *KernelBase)
21 while (n--)
22 krnPutC(c, KernelBase);
26 * This function calculates length of line.
27 * It's similar to strlen(), but stops also at LF and FF codes.
29 static inline int linelen(const char *str)
31 int l;
33 for (l = 0; str[l] && str[l] != '\n' && str[l] != 0x0F; l++);
34 return l;
37 static const char *PrintCentered(const char *str, struct KernelBase *KernelBase)
39 int len = linelen(str);
40 int i;
41 ULONG s;
43 if (len > (scr_Width - 2))
44 len = (scr_Width - 2);
46 s = scr_Width - 2 - len;
48 krnPutC(0xDB, KernelBase);
49 if (s & 1)
50 krnPutC(' ', KernelBase);
51 s >>= 1;
52 PrintChars(' ', s, KernelBase);
54 for (i = 0; i < len; i++)
55 krnPutC(*str++, KernelBase);
57 PrintChars(' ', s, KernelBase);
58 krnPutC(0xDB, KernelBase);
59 krnPutC('\n', KernelBase);
61 return str;
64 static inline void PrintFrame(char c, struct KernelBase *KernelBase)
66 krnPutC(0xDB, KernelBase);
67 PrintChars(c, scr_Width - 2, KernelBase);
68 krnPutC(0xDB, KernelBase);
69 krnPutC('\n', KernelBase);
71 #if defined(__AROSEXEC_SMP__)
72 #include <aros/atomic.h>
73 #include <asm/cpu.h>
74 extern volatile ULONG safedebug;
75 #endif
76 void krnDisplayAlert(const char *text, struct KernelBase *KernelBase)
78 unsigned int i;
79 #if defined(__AROSEXEC_SMP__)
80 if (safedebug & 1)
82 while (bit_test_and_set_long((ULONG*)&safedebug, 1)) { asm volatile("pause"); };
84 #endif
85 if (scr_Type == SCR_UNKNOWN)
87 /* Default alert width (for possible serial output). */
88 scr_Width = 80;
91 /* Make sure that the output starts from a new line */
92 krnPutC('\n', KernelBase);
94 PrintFrame(0xDF, KernelBase);
96 /* Print first three lines (title, task and error) centered */
97 for (i = 0; i < 3; i++)
99 text = PrintCentered(text, KernelBase);
100 if (*text == 0) /* Handle early NULL terminator */
101 break;
102 text++; /* Skip a newline */
105 PrintFrame(0xDC, KernelBase);
107 /* Print the rest of alert text (if any) */
108 if (*text)
110 PrintString(text, KernelBase);
112 /* Print a line in the bottom */
113 krnPutC('\n', KernelBase);
114 PrintChars(0xDC, scr_Width, KernelBase);
115 krnPutC('\n', KernelBase);
117 #if defined(__AROSEXEC_SMP__)
118 if (safedebug & 1)
120 __AROS_ATOMIC_AND_L(safedebug, ~(1 << 1));
122 #endif