| 1 | /*
|
|---|
| 2 | * kdmsg.c - output kernel debug/trace/information to an available terminal
|
|---|
| 3 | * (see kern/kdmsg.h)
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
|
|---|
| 6 | * Copyright (c) 2011,2012 UPMC Sorbonne Universites
|
|---|
| 7 | *
|
|---|
| 8 | * This file is part of ALMOS-kernel.
|
|---|
| 9 | *
|
|---|
| 10 | * ALMOS-kernel is free software; you can redistribute it and/or modify it
|
|---|
| 11 | * under the terms of the GNU General Public License as published by
|
|---|
| 12 | * the Free Software Foundation; version 2.0 of the License.
|
|---|
| 13 | *
|
|---|
| 14 | * ALMOS-kernel is distributed in the hope that it will be useful, but
|
|---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 17 | * General Public License for more details.
|
|---|
| 18 | *
|
|---|
| 19 | * You should have received a copy of the GNU General Public License
|
|---|
| 20 | * along with ALMOS-kernel; if not, write to the Free Software Foundation,
|
|---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|---|
| 22 | */
|
|---|
| 23 |
|
|---|
| 24 | #include <types.h>
|
|---|
| 25 | #include <cpu.h>
|
|---|
| 26 | #include <chdev.h>
|
|---|
| 27 | #include <soclib_tty.h>
|
|---|
| 28 | #include <arch-config.h>
|
|---|
| 29 | #include <spinlock.h>
|
|---|
| 30 | #include <distlock.h>
|
|---|
| 31 | #include <mcs_sync.h>
|
|---|
| 32 | #include <libk.h>
|
|---|
| 33 | #include <kdmsg.h>
|
|---|
| 34 |
|
|---|
| 35 | #define MSB(paddr) ((uint_t)((paddr)>>32))
|
|---|
| 36 | #define LSB(paddr) ((uint_t)(paddr))
|
|---|
| 37 |
|
|---|
| 38 | //spinlock_t printk_lock;
|
|---|
| 39 | DISTLOCK_DECLARE(printk_lock);
|
|---|
| 40 | //spinlock_t isr_lock;
|
|---|
| 41 | DISTLOCK_DECLARE(isr_lock);
|
|---|
| 42 |
|
|---|
| 43 | DISTLOCK_DECLARE(boot_lock);
|
|---|
| 44 |
|
|---|
| 45 | kdmsg_channel_t klog_tty = {{.id = 1}};
|
|---|
| 46 | kdmsg_channel_t kisr_tty = {{.id = 1}};
|
|---|
| 47 | kdmsg_channel_t kexcept_tty = {{.id = 1}};
|
|---|
| 48 |
|
|---|
| 49 | void kdmsg_init()
|
|---|
| 50 | {
|
|---|
| 51 | uint_t tty_count;
|
|---|
| 52 |
|
|---|
| 53 | tty_count = 0;
|
|---|
| 54 | while((tty_count < TTY_DEV_NR) && (ttys_tbl[tty_count++] != NULL));
|
|---|
| 55 |
|
|---|
| 56 | if(tty_count >= 3)
|
|---|
| 57 | {
|
|---|
| 58 | kisr_tty.id = 3;
|
|---|
| 59 | kexcept_tty.id = 3;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | uint_t boot_cluster;
|
|---|
| 65 | uint_t kboot_tty_cid;
|
|---|
| 66 | uint_t kboot_tty_base;
|
|---|
| 67 |
|
|---|
| 68 | void kboot_tty_init(boot_info_t *info)
|
|---|
| 69 | {
|
|---|
| 70 | kboot_tty_base = info->tty_base;
|
|---|
| 71 |
|
|---|
| 72 | kboot_tty_cid = info->tty_cid;
|
|---|
| 73 |
|
|---|
| 74 | boot_cluster = info->boot_cluster_id;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | //TODO ?
|
|---|
| 78 | int early_boot_dmsg (const char *fmt, ...)
|
|---|
| 79 | {
|
|---|
| 80 | va_list ap;
|
|---|
| 81 | int count;
|
|---|
| 82 |
|
|---|
| 83 | //if(current_cluster->cid != boot_cluster)
|
|---|
| 84 | // return 0;
|
|---|
| 85 |
|
|---|
| 86 | va_start (ap, fmt);
|
|---|
| 87 |
|
|---|
| 88 | count = iprintk ((char*)kboot_tty_base, kboot_tty_cid, 0, (char *) fmt, ap);
|
|---|
| 89 |
|
|---|
| 90 | va_end (ap);
|
|---|
| 91 |
|
|---|
| 92 | return count;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | int __arch_boot_dmsg (const char *fmt, ...)
|
|---|
| 96 | {
|
|---|
| 97 | va_list ap;
|
|---|
| 98 | int count;
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | va_start (ap, fmt);
|
|---|
| 102 |
|
|---|
| 103 | distlock_lock(&boot_lock);
|
|---|
| 104 |
|
|---|
| 105 | count = iprintk ((char*)kboot_tty_base, kboot_tty_cid, 0, (char *) fmt, ap);
|
|---|
| 106 |
|
|---|
| 107 | distlock_unlock(&boot_lock);
|
|---|
| 108 |
|
|---|
| 109 | va_end (ap);
|
|---|
| 110 |
|
|---|
| 111 | return count;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | int __fprintk (int tty, ktty_lock_t ktty, const char *fmt, ...)
|
|---|
| 115 | {
|
|---|
| 116 | va_list ap;
|
|---|
| 117 | int count;
|
|---|
| 118 | //uint_t irq_state;
|
|---|
| 119 | distlock_t *lock;
|
|---|
| 120 |
|
|---|
| 121 | va_start (ap, fmt);
|
|---|
| 122 |
|
|---|
| 123 | switch(ktty)
|
|---|
| 124 | {
|
|---|
| 125 | case PRINTK_KTTY_LOCK:
|
|---|
| 126 | lock = &printk_lock;
|
|---|
| 127 | break;
|
|---|
| 128 | case ISR_KTTY_LOCK:
|
|---|
| 129 | lock = &isr_lock;
|
|---|
| 130 | break;
|
|---|
| 131 | default:
|
|---|
| 132 | case NO_KTTY_LOCK:
|
|---|
| 133 | lock = NULL;
|
|---|
| 134 | break;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | if(lock)
|
|---|
| 138 | {
|
|---|
| 139 | distlock_lock(lock);
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | count = iprintk ((char*)(ttys_tbl[tty]->base + TTY_WRITE_REG),
|
|---|
| 143 | ttys_tbl[tty]->cid, 0, (char *) fmt, ap);
|
|---|
| 144 |
|
|---|
| 145 | if(lock)
|
|---|
| 146 | {
|
|---|
| 147 | distlock_unlock(lock);
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | va_end (ap);
|
|---|
| 151 |
|
|---|
| 152 | return count;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | #include <thread.h>
|
|---|
| 156 |
|
|---|
| 157 | int __perror (int fatal, const char *fmt, ...)
|
|---|
| 158 | {
|
|---|
| 159 | va_list ap;
|
|---|
| 160 | int count;
|
|---|
| 161 |
|
|---|
| 162 | va_start (ap, fmt);
|
|---|
| 163 | count = iprintk ((char*)(ttys_tbl[kexcept_tty.id]->base + TTY_WRITE_REG),
|
|---|
| 164 | ttys_tbl[kexcept_tty.id]->cid,
|
|---|
| 165 | 0, (char *) fmt, ap);
|
|---|
| 166 |
|
|---|
| 167 | va_end (ap);
|
|---|
| 168 |
|
|---|
| 169 | if(fatal) while(1);
|
|---|
| 170 | return count;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | #if 0
|
|---|
| 174 | //FIXME add 40 bits support
|
|---|
| 175 | void bdump(uint8_t *buff, size_t count)
|
|---|
| 176 | {
|
|---|
| 177 | uint8_t b1, b2;
|
|---|
| 178 | char *tab = "0123456789ABCDEF";
|
|---|
| 179 |
|
|---|
| 180 | spinlock_lock(&ttys_tbl[klog_tty.id]->lock);
|
|---|
| 181 |
|
|---|
| 182 | while(count--)
|
|---|
| 183 | {
|
|---|
| 184 | b1 = tab[(*buff & 0xF0)>>4];
|
|---|
| 185 | b2 = tab[*buff & 0x0F];
|
|---|
| 186 | buff++;
|
|---|
| 187 | *(char*)(ttys_tbl[klog_tty.id]->base + TTY_WRITE_REG) = b1;
|
|---|
| 188 | *(char*)(ttys_tbl[klog_tty.id]->base + TTY_WRITE_REG) = b2;
|
|---|
| 189 | }
|
|---|
| 190 | *(char*)(ttys_tbl[klog_tty.id]->base + TTY_WRITE_REG) = '\n';
|
|---|
| 191 | spinlock_unlock (&ttys_tbl[klog_tty.id]->lock);
|
|---|
| 192 | }
|
|---|
| 193 | #endif
|
|---|