Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Travis Geiselbrecht |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #include <stdarg.h> |
| 24 | #include <reg.h> |
| 25 | #include <printf.h> |
| 26 | #include <kernel/thread.h> |
| 27 | #include <platform/armemu/memmap.h> |
| 28 | #include <platform/debug.h> |
| 29 | |
Travis Geiselbrecht | eb94605 | 2008-09-07 22:32:49 -0700 | [diff] [blame] | 30 | void _dputc(char c) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 31 | { |
| 32 | *REG8(DEBUG_STDOUT) = c; |
| 33 | } |
| 34 | |
Travis Geiselbrecht | dbc2c68 | 2009-06-28 12:18:39 -0700 | [diff] [blame] | 35 | int dgetc(char *c, bool wait) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 36 | { |
Travis Geiselbrecht | dbc2c68 | 2009-06-28 12:18:39 -0700 | [diff] [blame] | 37 | for (;;) { |
| 38 | int8_t result = (int8_t)*REG8(DEBUG_STDIN); |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 39 | |
Travis Geiselbrecht | dbc2c68 | 2009-06-28 12:18:39 -0700 | [diff] [blame] | 40 | if (result == -1) { |
| 41 | if (wait) |
| 42 | continue; |
| 43 | else |
| 44 | return -1; |
| 45 | } |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 46 | |
Travis Geiselbrecht | dbc2c68 | 2009-06-28 12:18:39 -0700 | [diff] [blame] | 47 | *c = (char)result; |
| 48 | return 0; |
| 49 | } |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void debug_dump_regs(void) |
| 53 | { |
| 54 | *REG32(DEBUG_REGDUMP) = 1; |
| 55 | } |
| 56 | |
Travis Geiselbrecht | eb94605 | 2008-09-07 22:32:49 -0700 | [diff] [blame] | 57 | void platform_halt(void) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 58 | { |
| 59 | *REG32(DEBUG_HALT) = 1; |
| 60 | for(;;); |
| 61 | } |
| 62 | |
| 63 | void debug_dump_memory_bytes(void *mem, int len) |
| 64 | { |
| 65 | *REG32(DEBUG_MEMDUMPADDR) = (unsigned int)mem; |
| 66 | *REG32(DEBUG_MEMDUMPLEN) = len; |
| 67 | *REG32(DEBUG_MEMDUMP_BYTE) = 1; |
| 68 | } |
| 69 | |
| 70 | void debug_dump_memory_halfwords(void *mem, int len) |
| 71 | { |
| 72 | len /= 2; |
| 73 | |
| 74 | *REG32(DEBUG_MEMDUMPADDR) = (unsigned int)mem; |
| 75 | *REG32(DEBUG_MEMDUMPLEN) = len; |
| 76 | *REG32(DEBUG_MEMDUMP_HALFWORD) = 1; |
| 77 | } |
| 78 | |
| 79 | void debug_dump_memory_words(void *mem, int len) |
| 80 | { |
| 81 | len /= 4; |
| 82 | |
| 83 | *REG32(DEBUG_MEMDUMPADDR) = (unsigned int)mem; |
| 84 | *REG32(DEBUG_MEMDUMPLEN) = len; |
| 85 | *REG32(DEBUG_MEMDUMP_WORD) = 1; |
| 86 | } |
| 87 | |
| 88 | void debug_set_trace_level(int trace_type, int level) |
| 89 | { |
| 90 | if(trace_type < 0 || trace_type >= 4) |
| 91 | return; |
| 92 | |
| 93 | *REG32(DEBUG_SET_TRACELEVEL_CPU + trace_type * 4) = level; |
| 94 | } |
| 95 | |
| 96 | uint32_t debug_cycle_count() |
| 97 | { |
| 98 | return *REG32(DEBUG_CYCLE_COUNT); |
| 99 | } |