diff options
author | Simon Glass <sjg@chromium.org> | 2012-06-03 09:28:45 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-06-08 17:55:40 -0700 |
commit | 3439e70a901477133ed0a22eea55afdd4fc89f7b (patch) | |
tree | f79165901c1d98b957e475a12edf5d557c7f8aa1 /include | |
parent | 6f44651eb063eeffd85d68311712378243aa96e8 (diff) | |
download | chrome-ec-3439e70a901477133ed0a22eea55afdd4fc89f7b.tar.gz |
Convert panic() to C code
Move the implementation of panic into C code. Only a very small part
needs to be in assembler, and the reset is easier to maintain as C.
As part of this, define panic_putc() and panic_puts() which directly
wite to the UART.
To make things more convenience for the future, add a simple printf()
implementation in the panic path. This is not reliant on the uart
buffering system being in a happy state. However, we do call the
emergency flush so that our panic message will appear after previous
output rather that surpressing it (which would be extremely confusing).
Code/data size for panic.o grows by about 200 bytes, but this is mostly
due to the increased flexibility.
text data bss dec hex filename
292 272 0 564 234 old panic.S
692 3 48 743 2e7 new panic.c
BUG=chrome-os-partner:10146
TEST=manual:
build and boot on snow:
> rw 0x06000000
=== EXCEPTION: 03 ====== xPSR: 01000000 ===========
r0 :0000000b r1 :00000047 r2 :06000000 r3 :200013dd
r4 :00000000 r5 :080052cc r6 :200013d0 r7 :00000002
r8 :00000000 r9 :200013de r10:00000000 r11:00000000
r12:00000000 sp :200009a0 lr :08002a5d pc :08003962
Rebooting...
Change-Id: If3e3f572e0f32af780b6ebda235b1b3cde4de5e4
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/24503
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/panic.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/include/panic.h b/include/panic.h new file mode 100644 index 0000000000..2cfda9bcee --- /dev/null +++ b/include/panic.h @@ -0,0 +1,69 @@ +/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Panic handling, including displaying a message on the panic reporting + * device, which is currently the UART. + */ + +#ifndef __PANIC_H +#include <stdarg.h> + +/** + * Write a character to the panic reporting device + * + * This function will not return until the character has left the UART + * data register. Any previously queued UART traffic is displayed first. + * + * @param ch Character to write + */ +void panic_putc(int ch); + +/** + * Write a string to the panic reporting device + * + * This function will not return until the string has left the UART + * data register. Any previously queued UART traffic is displayed first. + * + * @param ch Character to write + */ +void panic_puts(const char *s); + +/** + * Very basic vprintf() for use in panic situations + * + * We only support %s and %nx where n is the number of hex digits to display. + * Currently we don't even support %d, and it is aimed at small code size. + * + * TODO(sjg@chromium.org): Really what we need is a vsnprintf() that is + * shared between the console UART and panic (and is also available as an + * snprintf()). The only downside is that we would then require a large + * printf() implementation to be always present, whereas presumably now we + * can turn it off. + * + * @param format printf-style format string + * @param args List of arguments to process + */ +void panic_vprintf(const char *format, va_list args); + +/** + * Very basic printf() for use in panic situations + * + * See panic_vprintf() for full details + * + * @param format printf-style format string + * @param ... Arguments to process + */ +void panic_printf(const char *format, ...); + +/** + * Report a panic to the panic reporting device + * + * This is exported only to permit use from assembler. + * + * @param msg Panic message + * @param lregs Registers from the exception: psp, ipsr, lr, r4-r11 + */ +void report_panic(const char *msg, uint32_t *lregs); + +#endif |