diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2021-08-26 20:41:45 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2021-08-26 20:43:08 +0300 |
| commit | 07af47eca912f3b56f013749a268718d78656961 (patch) | |
| tree | 1bb933b33af06b9ae1e4849a9e108de1a695a894 /common | |
| parent | 5dfac4879ce5f34503ae7537eefd3fc48d6fa750 (diff) | |
| download | kmi-07af47eca912f3b56f013749a268718d78656961.tar.gz kmi-07af47eca912f3b56f013749a268718d78656961.zip | |
Added debug flags and simple debug serial driver
Diffstat (limited to 'common')
| -rw-r--r-- | common/debug.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/common/debug.c b/common/debug.c new file mode 100644 index 0000000..be71cd2 --- /dev/null +++ b/common/debug.c @@ -0,0 +1,77 @@ +#include <apos/types.h> +#include <apos/debug.h> + +#ifdef DEBUG + +/* if there arises a need for more supported serial drivers, I should probably + * try to implement some kind of basic driver subsystem, but this is good enough + * for now. */ + +struct __packed ns16550a { + union { + struct { + uint8_t data; + uint8_t irq; + }; + + struct { + uint8_t lsbr; + uint8_t msbr; + }; + }; + + uint8_t irq_id; + uint8_t lcr; + uint8_t mcr; + uint8_t lsr; + uint8_t msr; + uint8_t scr; +}; + +#define LSR_DR (1 << 0) +#define LSR_OE (1 << 1) +#define LSR_PE (1 << 2) +#define LSR_FE (1 << 3) +#define LSR_BI (1 << 4) +#define LSR_THRE (1 << 5) +#define LSR_TEMT (1 << 6) +#define LSR_ERR (1 << 7) + +static struct ns16550a *port = 0; + +int __serial_tx_empty() +{ + return port->lsr & LSR_THRE; +} + +void __serial_putchar(char c) +{ + if (!port) + return; + + while(__serial_tx_empty() == 0); + + port->data = c; +} + +void dbg_init(void *pt, enum serial_dev_t dev) +{ + switch (dev) { + case NS16550A: + port = pt; + break; + } + + /* in the future possibly configure the serial connection, though the + * defaults (set by U-boot) seem to work alright */ +} + +void dbg(const char *fmt, ...) +{ + /* do a proper implementation later, for now just dump stuff */ + while(*fmt){ + __serial_putchar(*fmt++); + } +} + +#endif /* DEBUG */ |
