frv400_misc.c
来自「eCos操作系统源码」· C语言 代码 · 共 1,083 行 · 第 1/3 页
C
1,083 行
HAL_READ_UINT16(_FRV400_IRC_IRR3, _irr); _irr = (_irr & 0xFF0F) | ((vector-CYGNUM_HAL_VECTOR_EXTERNAL_INTERRUPT_LEVEL_1+1)<<4); HAL_WRITE_UINT16(_FRV400_IRC_IRR3, _irr); HAL_READ_UINT16(_FRV400_IRC_TM1, _tmr); _tmr = (_tmr & 0xFFF3) | (_trig<<2); HAL_WRITE_UINT16(_FRV400_IRC_TM1, _tmr); break; case CYGNUM_HAL_INTERRUPT_EXT2: HAL_READ_UINT16(_FRV400_IRC_IRR3, _irr); _irr = (_irr & 0xF0FF) | ((vector-CYGNUM_HAL_VECTOR_EXTERNAL_INTERRUPT_LEVEL_1+1)<<8); HAL_WRITE_UINT16(_FRV400_IRC_IRR3, _irr); HAL_READ_UINT16(_FRV400_IRC_TM1, _tmr); _tmr = (_tmr & 0xFFCF) | (_trig<<4); HAL_WRITE_UINT16(_FRV400_IRC_TM1, _tmr); break; case CYGNUM_HAL_INTERRUPT_EXT3: HAL_READ_UINT16(_FRV400_IRC_IRR3, _irr); _irr = (_irr & 0x0FFF) | ((vector-CYGNUM_HAL_VECTOR_EXTERNAL_INTERRUPT_LEVEL_1+1)<<12); HAL_WRITE_UINT16(_FRV400_IRC_IRR3, _irr); HAL_READ_UINT16(_FRV400_IRC_TM1, _tmr); _tmr = (_tmr & 0xFF3F) | (_trig<<6); HAL_WRITE_UINT16(_FRV400_IRC_TM1, _tmr); break; default: ; // Nothing to do };}void hal_interrupt_set_level(int vector, int level){// UNIMPLEMENTED(__FUNCTION__);}// PCI supportexternC void_frv400_pci_init(void){ static int _init = 0; cyg_uint8 next_bus; cyg_uint32 cmd_state; if (_init) return; _init = 1; // Enable controller - most of the basic configuration // was set up at boot time in "platform.inc" // Setup for bus mastering HAL_PCI_CFG_READ_UINT32(0, CYG_PCI_DEV_MAKE_DEVFN(0,0), CYG_PCI_CFG_COMMAND, cmd_state); if ((cmd_state & CYG_PCI_CFG_COMMAND_MEMORY) == 0) { HAL_PCI_CFG_WRITE_UINT32(0, CYG_PCI_DEV_MAKE_DEVFN(0,0), CYG_PCI_CFG_COMMAND, CYG_PCI_CFG_COMMAND_MEMORY | CYG_PCI_CFG_COMMAND_MASTER | CYG_PCI_CFG_COMMAND_PARITY | CYG_PCI_CFG_COMMAND_SERR); // Setup latency timer field HAL_PCI_CFG_WRITE_UINT8(0, CYG_PCI_DEV_MAKE_DEVFN(0,0), CYG_PCI_CFG_LATENCY_TIMER, 32); // Configure PCI bus. next_bus = 1; cyg_pci_configure_bus(0, &next_bus); }}externC void _frv400_pci_translate_interrupt(int bus, int devfn, int *vec, int *valid){ cyg_uint8 req; cyg_uint8 dev = CYG_PCI_DEV_GET_DEV(devfn); if (dev == CYG_PCI_MIN_DEV) { // On board LAN *vec = CYGNUM_HAL_INTERRUPT_LAN; *valid = true; } else { HAL_PCI_CFG_READ_UINT8(bus, devfn, CYG_PCI_CFG_INT_PIN, req); if (0 != req) { CYG_ADDRWORD __translation[4] = { CYGNUM_HAL_INTERRUPT_PCIINTC, /* INTC# */ CYGNUM_HAL_INTERRUPT_PCIINTB, /* INTB# */ CYGNUM_HAL_INTERRUPT_PCIINTA, /* INTA# */ CYGNUM_HAL_INTERRUPT_PCIINTD}; /* INTD# */ /* The PCI lines from the different slots are wired like this */ /* on the PCI backplane: */ /* pin6A pin7B pin7A pin8B */ /* I/O Slot 1 INTA# INTB# INTC# INTD# */ /* I/O Slot 2 INTD# INTA# INTB# INTC# */ /* I/O Slot 3 INTC# INTD# INTA# INTB# */ /* */ /* (From PCI Development Backplane, 3.2.2 Interrupts) */ /* */ /* Devsel signals are wired to, resulting in device IDs: */ /* I/O Slot 1 AD30 / dev 19 [(8+1)&3 = 1] */ /* I/O Slot 2 AD29 / dev 18 [(7+1)&3 = 0] */ /* I/O Slot 3 AD28 / dev 17 [(6+1)&3 = 3] */ *vec = __translation[((req+dev)&3)]; *valid = true; } else { /* Device will not generate interrupt requests. */ *valid = false; } diag_printf("Int - dev: %d, req: %d, vector: %d\n", dev, req, *vec); }}// PCI configuration space access#define _EXT_ENABLE 0x80000000 // Could be 0x80000000static __inline__ cyg_uint32_cfg_addr(int bus, int devfn, int offset){ return _EXT_ENABLE | (bus << 22) | (devfn << 8) | (offset << 0);}externC cyg_uint8 _frv400_pci_cfg_read_uint8(int bus, int devfn, int offset){ cyg_uint32 cfg_addr, addr, status; cyg_uint8 cfg_val = (cyg_uint8)0xFF;#ifdef CYGPKG_IO_PCI_DEBUG diag_printf("%s(bus=%x, devfn=%x, offset=%x) = ", __FUNCTION__, bus, devfn, offset);#endif // CYGPKG_IO_PCI_DEBUG if ((bus == 0) && (CYG_PCI_DEV_GET_DEV(devfn) == 0)) { // PCI bridge addr = _FRV400_PCI_CONFIG + ((offset << 1) ^ 0x03); } else { cfg_addr = _cfg_addr(bus, devfn, offset ^ 0x03); HAL_WRITE_UINT32(_FRV400_PCI_CONFIG_ADDR, cfg_addr); addr = _FRV400_PCI_CONFIG_DATA + ((offset & 0x03) ^ 0x03); } HAL_READ_UINT8(addr, cfg_val); HAL_READ_UINT16(_FRV400_PCI_STAT_CMD, status); if (status & _FRV400_PCI_STAT_ERROR_MASK) { // Cycle failed - clean up and get out cfg_val = (cyg_uint8)0xFF; HAL_WRITE_UINT16(_FRV400_PCI_STAT_CMD, status & _FRV400_PCI_STAT_ERROR_MASK); }#ifdef CYGPKG_IO_PCI_DEBUG diag_printf("%x\n", cfg_val);#endif // CYGPKG_IO_PCI_DEBUG HAL_WRITE_UINT32(_FRV400_PCI_CONFIG_ADDR, 0); return cfg_val;}externC cyg_uint16 _frv400_pci_cfg_read_uint16(int bus, int devfn, int offset){ cyg_uint32 cfg_addr, addr, status; cyg_uint16 cfg_val = (cyg_uint16)0xFFFF;#ifdef CYGPKG_IO_PCI_DEBUG diag_printf("%s(bus=%x, devfn=%x, offset=%x) = ", __FUNCTION__, bus, devfn, offset);#endif // CYGPKG_IO_PCI_DEBUG if ((bus == 0) && (CYG_PCI_DEV_GET_DEV(devfn) == 0)) { // PCI bridge addr = _FRV400_PCI_CONFIG + ((offset << 1) ^ 0x02); } else { cfg_addr = _cfg_addr(bus, devfn, offset ^ 0x02); HAL_WRITE_UINT32(_FRV400_PCI_CONFIG_ADDR, cfg_addr); addr = _FRV400_PCI_CONFIG_DATA + ((offset & 0x03) ^ 0x02); } HAL_READ_UINT16(addr, cfg_val); HAL_READ_UINT16(_FRV400_PCI_STAT_CMD, status); if (status & _FRV400_PCI_STAT_ERROR_MASK) { // Cycle failed - clean up and get out cfg_val = (cyg_uint16)0xFFFF; HAL_WRITE_UINT16(_FRV400_PCI_STAT_CMD, status & _FRV400_PCI_STAT_ERROR_MASK); }#ifdef CYGPKG_IO_PCI_DEBUG diag_printf("%x\n", cfg_val);#endif // CYGPKG_IO_PCI_DEBUG HAL_WRITE_UINT32(_FRV400_PCI_CONFIG_ADDR, 0); return cfg_val;}externC cyg_uint32 _frv400_pci_cfg_read_uint32(int bus, int devfn, int offset){ cyg_uint32 cfg_addr, addr, status; cyg_uint32 cfg_val = (cyg_uint32)0xFFFFFFFF;#ifdef CYGPKG_IO_PCI_DEBUG diag_printf("%s(bus=%x, devfn=%x, offset=%x) = ", __FUNCTION__, bus, devfn, offset);#endif // CYGPKG_IO_PCI_DEBUG if ((bus == 0) && (CYG_PCI_DEV_GET_DEV(devfn) == 0)) { // PCI bridge addr = _FRV400_PCI_CONFIG + (offset << 1); } else { cfg_addr = _cfg_addr(bus, devfn, offset); HAL_WRITE_UINT32(_FRV400_PCI_CONFIG_ADDR, cfg_addr); addr = _FRV400_PCI_CONFIG_DATA; } HAL_READ_UINT32(addr, cfg_val); HAL_READ_UINT16(_FRV400_PCI_STAT_CMD, status); if (status & _FRV400_PCI_STAT_ERROR_MASK) { // Cycle failed - clean up and get out cfg_val = (cyg_uint32)0xFFFFFFFF; HAL_WRITE_UINT16(_FRV400_PCI_STAT_CMD, status & _FRV400_PCI_STAT_ERROR_MASK); }#ifdef CYGPKG_IO_PCI_DEBUG diag_printf("%x\n", cfg_val);#endif // CYGPKG_IO_PCI_DEBUG HAL_WRITE_UINT32(_FRV400_PCI_CONFIG_ADDR, 0); return cfg_val;}externC void_frv400_pci_cfg_write_uint8(int bus, int devfn, int offset, cyg_uint8 cfg_val){ cyg_uint32 cfg_addr, addr, status;#ifdef CYGPKG_IO_PCI_DEBUG diag_printf("%s(bus=%x, devfn=%x, offset=%x, val=%x)\n", __FUNCTION__, bus, devfn, offset, cfg_val);#endif // CYGPKG_IO_PCI_DEBUG if ((bus == 0) && (CYG_PCI_DEV_GET_DEV(devfn) == 0)) { // PCI bridge addr = _FRV400_PCI_CONFIG + ((offset << 1) ^ 0x03); } else { cfg_addr = _cfg_addr(bus, devfn, offset ^ 0x03); HAL_WRITE_UINT32(_FRV400_PCI_CONFIG_ADDR, cfg_addr); addr = _FRV400_PCI_CONFIG_DATA + ((offset & 0x03) ^ 0x03); } HAL_WRITE_UINT8(addr, cfg_val); HAL_READ_UINT16(_FRV400_PCI_STAT_CMD, status); if (status & _FRV400_PCI_STAT_ERROR_MASK) { // Cycle failed - clean up and get out HAL_WRITE_UINT16(_FRV400_PCI_STAT_CMD, status & _FRV400_PCI_STAT_ERROR_MASK); } HAL_WRITE_UINT32(_FRV400_PCI_CONFIG_ADDR, 0);}externC void_frv400_pci_cfg_write_uint16(int bus, int devfn, int offset, cyg_uint16 cfg_val){ cyg_uint32 cfg_addr, addr, status;#ifdef CYGPKG_IO_PCI_DEBUG diag_printf("%s(bus=%x, devfn=%x, offset=%x, val=%x)\n", __FUNCTION__, bus, devfn, offset, cfg_val);#endif // CYGPKG_IO_PCI_DEBUG if ((bus == 0) && (CYG_PCI_DEV_GET_DEV(devfn) == 0)) { // PCI bridge addr = _FRV400_PCI_CONFIG + ((offset << 1) ^ 0x02); } else { cfg_addr = _cfg_addr(bus, devfn, offset ^ 0x02); HAL_WRITE_UINT32(_FRV400_PCI_CONFIG_ADDR, cfg_addr); addr = _FRV400_PCI_CONFIG_DATA + ((offset & 0x03) ^ 0x02); } HAL_WRITE_UINT16(addr, cfg_val); HAL_READ_UINT16(_FRV400_PCI_STAT_CMD, status); if (status & _FRV400_PCI_STAT_ERROR_MASK) { // Cycle failed - clean up and get out HAL_WRITE_UINT16(_FRV400_PCI_STAT_CMD, status & _FRV400_PCI_STAT_ERROR_MASK); } HAL_WRITE_UINT32(_FRV400_PCI_CONFIG_ADDR, 0);}externC void_frv400_pci_cfg_write_uint32(int bus, int devfn, int offset, cyg_uint32 cfg_val){ cyg_uint32 cfg_addr, addr, status;#ifdef CYGPKG_IO_PCI_DEBUG diag_printf("%s(bus=%x, devfn=%x, offset=%x, val=%x)\n", __FUNCTION__, bus, devfn, offset, cfg_val);#endif // CYGPKG_IO_PCI_DEBUG if ((bus == 0) && (CYG_PCI_DEV_GET_DEV(devfn) == 0)) { // PCI bridge addr = _FRV400_PCI_CONFIG + (offset << 1); } else { cfg_addr = _cfg_addr(bus, devfn, offset); HAL_WRITE_UINT32(_FRV400_PCI_CONFIG_ADDR, cfg_addr); addr = _FRV400_PCI_CONFIG_DATA; } HAL_WRITE_UINT32(addr, cfg_val); HAL_READ_UINT16(_FRV400_PCI_STAT_CMD, status); if (status & _FRV400_PCI_STAT_ERROR_MASK) { // Cycle failed - clean up and get out HAL_WRITE_UINT16(_FRV400_PCI_STAT_CMD, status & _FRV400_PCI_STAT_ERROR_MASK); } HAL_WRITE_UINT32(_FRV400_PCI_CONFIG_ADDR, 0);}// ------------------------------------------------------------------------//// Hardware breakpoint/watchpoint support// ======================================//// Now follows a load of extreme unpleasantness to deal with the totally// broken debug model of this device.//// To modify the special hardware debug registers, it is necessary to put// the CPU into "debug mode". This can only be done by executing a break// instruction, or taking a special hardware break event as described by// the special hardware debug registers.//// But once in debug mode, no break is taken, and break instructions are// ignored, because we are in debug mode.//// So we must exit debug mode for normal running, which you can only do via// a rett #1 instruction. Because rett is for returning from traps, it// halts the CPU if you do it with traps enabled. So you have to mess// about disabling traps before the rett. Also, because rett #1 is for// returning from a *debug* trap, you can only issue it from debug mode -// or it halts the CPU.//// To be able to set and unset hardware debug breakpoints and watchpoints,// we must enter debug mode (via a "break" instruction). Fortunately, it// is possible to return from a "break" remaining in debug mode, using a// rett #0, so we can arrange that a break instruction just means "go to// debug mode".//// So we can manipulate the special hardware debug registers by executing a// "break", doing the work, then doing the magic sequence to rett #1.// These are encapsulated in HAL_FRV_ENTER_DEBUG_MODE() and// HAL_FRV_EXIT_DEBUG_MODE() from plf_stub.h//// So, we get into break_hander() for two reasons:// 1) a break instruction. Detect this and do nothing; return skipping// over the break instruction. CPU remains in debug mode.// 2) a hardware debug trap. Continue just as for a normal exception;// GDB and the stubs will handle it. But first, exit debug mode, or// stuff happening in the stubs will go wrong.//// In order to be certain that we are in debug mode, for performing (2)// safely, vectors.S installs a special debug trap handler on vector #255.// That's the reason for break_handler() existing as a separate routine.// // Note that there is no need to define CYGSEM_HAL_FRV_HW_DEBUG for the// FRV_FRV400 target; while we do use Hardware Debug, we don't use *that*// sort of hardware debug, specifically we do not use hardware single-step,// because it breaks as soon as we exit debug mode, ie. whilst we are still// within the stub. So in fact defining CYGSEM_HAL_FRV_HW_DEBUG is bad; I// guess it is mis-named.//// ------------------------------------------------------------------------// First a load of ugly boilerplate for register access.#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS#include <cyg/hal/hal_stub.h> // HAL_STUB_HW_STOP_NONE et al#include <cyg/hal/frv_stub.h> // register names PC, PSR et al#include <cyg/hal/plf_stub.h> // HAL_FRV_EXIT_DEBUG_MODE()// First a load of gluestatic inline unsigned get_bpsr(void) { unsigned retval; asm volatile ( "movsg bpsr,%0\n" : "=r" (retval) : /* no inputs */ ); return retval;}static inline void set_bpsr(unsigned val) { asm volatile ( "movgs %0,bpsr\n" : /* no outputs */ : "r" (val) );}static inline unsigned get_dcr(void) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?