2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include <bootconsole.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
)
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
)
33 for (l
= 0; str
[l
] && str
[l
] != '\n' && str
[l
] != 0x0F; l
++);
37 static const char *PrintCentered(const char *str
, struct KernelBase
*KernelBase
)
39 int len
= linelen(str
);
43 if (len
> (scr_Width
- 2))
44 len
= (scr_Width
- 2);
46 s
= scr_Width
- 2 - len
;
48 krnPutC(0xDB, KernelBase
);
50 krnPutC(' ', KernelBase
);
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
);
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>
74 extern volatile ULONG safedebug
;
76 void krnDisplayAlert(const char *text
, struct KernelBase
*KernelBase
)
79 #if defined(__AROSEXEC_SMP__)
82 while (bit_test_and_set_long((ULONG
*)&safedebug
, 1)) { asm volatile("pause"); };
85 if (scr_Type
== SCR_UNKNOWN
)
87 /* Default alert width (for possible serial output). */
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 */
102 text
++; /* Skip a newline */
105 PrintFrame(0xDC, KernelBase
);
107 /* Print the rest of alert text (if any) */
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__)
120 __AROS_ATOMIC_AND_L(safedebug
, ~(1 << 1));