Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2005-2006 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 | #ifndef __MEMMAP_H |
| 24 | #define __MEMMAP_H |
| 25 | |
| 26 | #define MEMBANK_SIZE (4*1024*1024) |
| 27 | |
| 28 | /* some helpful macros */ |
| 29 | #define REG(x) ((volatile unsigned int *)(x)) |
| 30 | #define REG_H(x) ((volatile unsigned short *)(x)) |
| 31 | #define REG_B(x) ((volatile unsigned char *)(x)) |
| 32 | |
| 33 | /* memory map of our generic arm system */ |
| 34 | // XXX make more dynamic |
| 35 | #define MAINMEM_BASE 0x0 |
| 36 | #define MAINMEM_SIZE (MEMBANK_SIZE) |
| 37 | |
| 38 | /* peripherals are all mapped here */ |
| 39 | #define PERIPHERAL_BASE (0xf0000000) |
| 40 | |
| 41 | /* system info */ |
| 42 | #define SYSINFO_REGS_BASE (PERIPHERAL_BASE) |
| 43 | #define SYSINFO_REGS_SIZE MEMBANK_SIZE |
| 44 | #define SYSINFO_FEATURES (SYSINFO_REGS_BASE + 0) |
| 45 | #define SYSINFO_FEATURE_DISPLAY 0x00000001 |
| 46 | #define SYSINFO_FEATURE_CONSOLE 0x00000002 |
| 47 | #define SYSINFO_FEATURE_NETWORK 0x00000004 |
| 48 | |
| 49 | /* a write to this register latches the current emulator system time, so the next two regs can be read atomically */ |
| 50 | #define SYSINFO_TIME_LATCH (SYSINFO_REGS_BASE + 4) |
| 51 | /* gettimeofday() style time values */ |
| 52 | #define SYSINFO_TIME_SECS (SYSINFO_REGS_BASE + 8) |
| 53 | #define SYSINFO_TIME_USECS (SYSINFO_REGS_BASE + 12) |
| 54 | |
| 55 | /* display */ |
| 56 | #define DISPLAY_BASE (SYSINFO_REGS_BASE + SYSINFO_REGS_SIZE) |
| 57 | #define DISPLAY_SIZE MEMBANK_SIZE |
| 58 | #define DISPLAY_FRAMEBUFFER DISPLAY_BASE |
| 59 | #define DISPLAY_REGS_BASE (DISPLAY_BASE + DISPLAY_SIZE) |
| 60 | #define DISPLAY_REGS_SIZE MEMBANK_SIZE |
| 61 | /* no display regs for now */ |
| 62 | |
| 63 | /* console (keyboard controller */ |
| 64 | #define CONSOLE_REGS_BASE (DISPLAY_REGS_BASE + DISPLAY_REGS_SIZE) |
| 65 | #define CONSOLE_REGS_SIZE MEMBANK_SIZE |
| 66 | #define KYBD_STAT (CONSOLE_REGS_BASE + 0) |
| 67 | #define KYBD_DATA (CONSOLE_REGS_BASE + 4) |
| 68 | |
| 69 | /* programmable timer */ |
| 70 | #define PIT_REGS_BASE (CONSOLE_REGS_BASE + CONSOLE_REGS_SIZE) |
| 71 | #define PIT_REGS_SIZE MEMBANK_SIZE |
| 72 | #define PIT_STATUS (PIT_REGS_BASE + 0) // status bit |
| 73 | #define PIT_CLEAR (PIT_REGS_BASE + 4) // a nonzero write clears any pending timer |
| 74 | #define PIT_CLEAR_INT (PIT_REGS_BASE + 8) // a nonzero write clears the pending interrupt |
| 75 | #define PIT_INTERVAL (PIT_REGS_BASE + 12) // set the countdown interval, and what the interval is reset to if periodic |
| 76 | #define PIT_START_ONESHOT (PIT_REGS_BASE + 16) // a nonzero write starts a oneshot countdown |
| 77 | #define PIT_START_PERIODIC (PIT_REGS_BASE + 20) // a nonzero write starts a periodic countdown |
| 78 | |
| 79 | #define PIT_STATUS_ACTIVE 0x1 |
| 80 | #define PIT_STATUS_INT_PEND 0x2 |
| 81 | |
| 82 | /* interrupt controller */ |
| 83 | #define PIC_REGS_BASE (PIT_REGS_BASE + PIT_REGS_SIZE) |
| 84 | #define PIC_REGS_SIZE MEMBANK_SIZE |
| 85 | |
| 86 | /* Current vector mask, read-only */ |
| 87 | #define PIC_MASK (PIC_REGS_BASE + 0) |
| 88 | /* Mask any of the 32 interrupt vectors by writing a 1 in the appropriate bit */ |
| 89 | #define PIC_MASK_LATCH (PIC_REGS_BASE + 4) |
| 90 | /* Unmask any of the 32 interrupt vectors by writing a 1 in the appropriate bit */ |
| 91 | #define PIC_UNMASK_LATCH (PIC_REGS_BASE + 8) |
| 92 | /* each bit corresponds to the current status of the interrupt line */ |
| 93 | #define PIC_STAT (PIC_REGS_BASE + 12) |
| 94 | /* one bit set for the highest priority non-masked active interrupt */ |
| 95 | #define PIC_CURRENT_BIT (PIC_REGS_BASE + 16) |
| 96 | /* holds the current interrupt number of the highest priority non-masked active interrupt, |
| 97 | * or 0xffffffff if no interrupt is active |
| 98 | */ |
| 99 | #define PIC_CURRENT_NUM (PIC_REGS_BASE + 20) |
| 100 | |
| 101 | /* interrupt map */ |
| 102 | #define INT_PIT 0 |
| 103 | #define INT_KEYBOARD 1 |
| 104 | #define INT_NET 2 |
| 105 | #define PIC_MAX_INT 32 |
| 106 | |
| 107 | /* debug interface */ |
| 108 | #define DEBUG_REGS_BASE (PIC_REGS_BASE + PIC_REGS_SIZE) |
| 109 | #define DEBUG_REGS_SIZE MEMBANK_SIZE |
| 110 | #define DEBUG_STDOUT (DEBUG_REGS_BASE + 0) /* writes to this register are sent through to stdout */ |
| 111 | #define DEBUG_STDIN (DEBUG_REGS_BASE + 0) /* reads from this register return the contents of stdin |
| 112 | * or -1 if no data is pending */ |
| 113 | #define DEBUG_REGDUMP (DEBUG_REGS_BASE + 4) /* writes to this register cause the emulator to dump registers */ |
| 114 | #define DEBUG_HALT (DEBUG_REGS_BASE + 8) /* writes to this register will halt the emulator */ |
| 115 | |
| 116 | #define DEBUG_MEMDUMPADDR (DEBUG_REGS_BASE + 12) /* set the base address of memory to dump */ |
| 117 | #define DEBUG_MEMDUMPLEN (DEBUG_REGS_BASE + 16) /* set the length of memory to dump */ |
| 118 | #define DEBUG_MEMDUMP_BYTE (DEBUG_REGS_BASE + 20) /* trigger a memory dump in byte format */ |
| 119 | #define DEBUG_MEMDUMP_HALFWORD (DEBUG_REGS_BASE + 24) /* trigger a memory dump in halfword format */ |
| 120 | #define DEBUG_MEMDUMP_WORD (DEBUG_REGS_BASE + 28) /* trigger a memory dump in word format */ |
| 121 | |
| 122 | /* lets you set the trace level of the various subsystems from within the emulator */ |
| 123 | /* only works on emulator builds that support dynamic trace levels */ |
| 124 | #define DEBUG_SET_TRACELEVEL_CPU (DEBUG_REGS_BASE + 32) |
| 125 | #define DEBUG_SET_TRACELEVEL_UOP (DEBUG_REGS_BASE + 36) |
| 126 | #define DEBUG_SET_TRACELEVEL_SYS (DEBUG_REGS_BASE + 40) |
| 127 | #define DEBUG_SET_TRACELEVEL_MMU (DEBUG_REGS_BASE + 44) |
| 128 | |
| 129 | #define DEBUG_CYCLE_COUNT (DEBUG_REGS_BASE + 48) |
| 130 | #define DEBUG_INS_COUNT (DEBUG_REGS_BASE + 52) |
| 131 | |
| 132 | /* network interface */ |
| 133 | #define NET_REGS_BASE (DEBUG_REGS_BASE + DEBUG_REGS_SIZE) |
| 134 | #define NET_REGS_SIZE MEMBANK_SIZE |
| 135 | |
| 136 | #define NET_BUF_LEN 2048 |
| 137 | #define NET_IN_BUF_COUNT 32 |
| 138 | |
| 139 | #define NET_HEAD (NET_REGS_BASE + 0) /* current next buffer the hardware will write to */ |
| 140 | #define NET_TAIL (NET_REGS_BASE + 4) /* currently selected input buffer */ |
| 141 | #define NET_SEND (NET_REGS_BASE + 8) /* writes to this register sends whatever is in the out buf */ |
| 142 | #define NET_SEND_LEN (NET_REGS_BASE + 12) /* length of packet to send */ |
| 143 | #define NET_OUT_BUF (NET_REGS_BASE + NET_BUF_LEN) |
| 144 | |
| 145 | #define NET_IN_BUF_LEN (NET_REGS_BASE + 16) /* length of the currently selected in buffer, via tail register */ |
| 146 | #define NET_IN_BUF (NET_REGS_BASE + NET_BUF_LEN*2) |
| 147 | |
| 148 | #endif |