1 #include <bootconsole.h>
4 #include <kernel_base.h>
5 #include <kernel_debug.h>
6 #include "alert_arch.h"
9 * Display alert on the screen using libbootconsole.
10 * Very useful for early alerts, while the display driver not started yet.
11 * In this case the user gets a nice GURU. Not painted in red yet. :)
14 static inline void PrintChars(char c
, ULONG n
, struct KernelBase
*KernelBase
)
17 krnPutC(c
, KernelBase
);
21 * This function calculates length of line.
22 * It's similar to strlen(), but stops also at LF and FF codes.
24 static inline int linelen(const char *str
)
28 for (l
= 0; str
[l
] && str
[l
] != '\n' && str
[l
] != 0x0F; l
++);
32 static const char *PrintCentered(const char *str
, struct KernelBase
*KernelBase
)
34 int len
= linelen(str
);
38 if (len
> (scr_Width
- 2))
39 len
= (scr_Width
- 2);
41 s
= scr_Width
- 2 - len
;
43 krnPutC(0xDB, KernelBase
);
45 krnPutC(' ', KernelBase
);
47 PrintChars(' ', s
, KernelBase
);
49 for (i
= 0; i
< len
; i
++)
50 krnPutC(*str
++, KernelBase
);
52 PrintChars(' ', s
, KernelBase
);
53 krnPutC(0xDB, KernelBase
);
54 krnPutC('\n', KernelBase
);
59 static inline void PrintFrame(char c
, struct KernelBase
*KernelBase
)
61 krnPutC(0xDB, KernelBase
);
62 PrintChars(c
, scr_Width
- 2, KernelBase
);
63 krnPutC(0xDB, KernelBase
);
64 krnPutC('\n', KernelBase
);
67 void krnDisplayAlert(const char *text
, struct KernelBase
*KernelBase
)
71 if (scr_Type
== SCR_UNKNOWN
)
73 /* Default alert width (for possible serial output). */
77 /* Make sure that the output starts from a new line */
78 krnPutC('\n', KernelBase
);
80 PrintFrame(0xDF, KernelBase
);
82 /* Print first three lines (title, task and error) centered */
83 for (i
= 0; i
< 3; i
++)
85 text
= PrintCentered(text
, KernelBase
);
86 if (*text
== 0) /* Handle early NULL terminator */
88 text
++; /* Skip a newline */
91 PrintFrame(0xDC, KernelBase
);
93 /* Print the rest of alert text (if any) */
96 PrintString(text
, KernelBase
);
98 /* Print a line in the bottom */
99 krnPutC('\n', KernelBase
);
100 PrintChars(0xDC, scr_Width
, KernelBase
);
101 krnPutC('\n', KernelBase
);