void bsp_free(void* ptr) { uint8_t* p; buffer_header_t* hdr; pool_t* pool; irqflags_t flags; if (ptr == 0) bsp_reset(BSP_RESET_FREE_INVALID); p = (uint8_t*)((int)ptr & ~0x3); // 4-byte align #ifdef CONFIG_BSP_BUFFERS_BOUNDARY_CHECK hdr = (buffer_header_t*) (p - 8); #else hdr = (buffer_header_t*) (p - 4); #endif if (hdr->pool >= CONFIG_BSP_BUFFERS_NUM_POOLS || hdr->used != 1) bsp_reset(BSP_RESET_FREE_INVALID); pool = &s_pools[hdr->pool]; if (p < pool->pool || p >= (pool->pool + (pool->bufsize+BUFFER_OVERHEAD)*pool->count)) bsp_reset(BSP_RESET_FREE_INVALID); #ifdef CONFIG_BSP_BUFFERS_BOUNDARY_CHECK if (hdr->magic != BOUNDARY_MAGIC || memcmp(p+hdr->alloc_size,&s_magic,4)) { bsp_reset(BSP_RESET_FREE_BOUNDARY); } #endif flags = cpu_irq_save(); hdr->used = 0; pool->frees++; cpu_irq_restore(flags); }
void reset(void) { bsp_reset(); /* should not exit */ direct_print("Reset not supported."); while (1); }
static void rebootQuestion(void) { printk("Press a key to reboot\n"); BSP_poll_char_via_serial(); bsp_reset(); }
void bsp_fatal_extension( rtems_fatal_source source, bool always_set_to_false, rtems_fatal_code code ) { #if (BSP_PRINT_EXCEPTION_CONTEXT) if ( source == RTEMS_FATAL_SOURCE_EXCEPTION ) { rtems_exception_frame_print( (const rtems_exception_frame *) code ); } #endif #if (BSP_PRESS_KEY_FOR_RESET) printk( "\nFATAL ERROR - Executive shutdown! Any key to reboot..." ); /* * Wait for a key to be pressed */ while ( getchark() == -1 ) ; printk("\n"); #endif /* * Check both conditions -- if you want to ask for reboot, then * you must have meant to reset the board. */ #if (BSP_PRESS_KEY_FOR_RESET) || (BSP_RESET_BOARD_AT_EXIT) bsp_reset(); #endif }
void bsp_fatal_extension( rtems_fatal_source source, bool is_internal, rtems_fatal_code error ) { bsp_reset(); }
void bsp_cleanup( uint32_t status ) { /* We can't go back to MotLoad since we blew it's memory area * and vectors. Just pull the reset line... */ printk( "bsp_cleanup(): RTEMS terminated -- no way back to MotLoad " "so I reset the card\n" ); bsp_reset(); }
static BSP_START_TEXT_SECTION void fmpll_wait_for_lock(void) { int i = 0; bool lock = false; while (!lock && i < 6000) { lock = FMPLL.SYNSR.B.LOCK != 0; ++i; } if (!lock) { bsp_reset(); } }
void bsp_fatal_extension( rtems_fatal_source source, bool is_internal, rtems_fatal_code error ) { #if AUTO_BOOT /* Till Straumann <*****@*****.**> for SVGM */ bsp_reset(); #else /* Kate Feng <*****@*****.**> for the MVME5500 */ printk("\nPrinting a stack trace for your convenience :-)\n"); CPU_print_stack(); printk("RTEMS terminated; Boot manually or turn on AUTO_BOOT.\n"); #endif }
void bsp_cleanup( uint32_t status ) { #if (BSP_PRESS_KEY_FOR_RESET) printk( "\nEXECUTIVE SHUTDOWN! Any key to reboot..." ); /* * Wait for a key to be pressed */ while ( getchark() == -1 ) ; printk("\n"); #endif /* * Check both conditions -- if you want to ask for reboot, then * you must have meant to reset the board. */ #if (BSP_PRESS_KEY_FOR_RESET) || (BSP_RESET_BOARD_AT_EXIT) bsp_reset(); #endif }
void bsp_fatal_extension( rtems_fatal_source src, bool is_internal, rtems_fatal_code code ) { #ifdef RTEMS_SMP if (src == RTEMS_FATAL_SOURCE_SMP && code == SMP_FATAL_SHUTDOWN_RESPONSE) { while (true) { _ARM_Wait_for_event(); } } #endif #if BSP_PRINT_EXCEPTION_CONTEXT if (src == RTEMS_FATAL_SOURCE_EXCEPTION) { rtems_exception_frame_print((const rtems_exception_frame *) code); } #endif #if BSP_RESET_BOARD_AT_EXIT bsp_reset(); #endif }
/*-------------------------------------------------------------------------+ | Function: _IBMPC_scankey | Description: This function can be called during a poll for input, or by | an ISR. Basically any time you want to process a keypress. | Global Variables: key_map, shift_map. | Arguments: outChar - character read in case of a valid reading, | otherwise unchanged. | Returns: true in case a valid character has been read, | false otherwise. +--------------------------------------------------------------------------*/ bool _IBMPC_scankey(char *outChar) { unsigned char inChar; static int alt_pressed = 0; static int ctrl_pressed = 0; static int shift_pressed = 0; static int caps_pressed = 0; static int extended = 0; *outChar = 0; /* default value if we return false */ /* Read keyboard controller, toggle enable */ inChar=kbd_inb(KBD_CTL); kbd_outb(KBD_CTL, inChar & ~0x80); kbd_outb(KBD_CTL, inChar | 0x80); kbd_outb(KBD_CTL, inChar & ~0x80); /* See if it has data */ inChar=kbd_inb(KBD_STATUS); if ((inChar & 0x01) == 0) return false; /* Read the data. Handle nonsense with shift, control, etc. */ inChar=kbd_inb(KBD_DATA); if (extended) extended--; switch (inChar) { case 0xe0: extended = 2; return false; break; case 0x38: alt_pressed = 1; return false; break; case 0xb8: alt_pressed = 0; return false; break; case 0x1d: ctrl_pressed = 1; return false; break; case 0x9d: ctrl_pressed = 0; return false; break; case 0x2a: if (extended) return false; case 0x36: shift_pressed = 1; return false; break; case 0xaa: if (extended) return false; case 0xb6: shift_pressed = 0; return false; break; case 0x3a: caps_pressed = 1; return false; break; case 0xba: caps_pressed = 0; return false; break; case 0x53: if (ctrl_pressed && alt_pressed) bsp_reset(); /* ctrl+alt+del -> reboot */ break; /* * Ignore unrecognized keys--usually arrow and such */ default: if ((inChar & 0x80) || (inChar > 0x39)) /* High-bit on means key is being released, not pressed */ return false; break; } /* switch */ /* Strip high bit, look up in our map */ inChar &= 0x7f; if (ctrl_pressed) { *outChar = key_map[inChar]; *outChar &= 037; } else { *outChar = shift_pressed ? shift_map[inChar] : key_map[inChar]; if (caps_pressed) { if (*outChar >= 'A' && *outChar <= 'Z') *outChar += 'a' - 'A'; else if (*outChar >= 'a' && *outChar <= 'z') *outChar -= 'a' - 'A'; } } return true; } /* _IBMPC_scankey */
void BSP_exceptionHandler(BSP_Exception_frame* excPtr) { uint32_t note; BSP_ExceptionExtension ext=0; rtems_id id=0; int recoverable = 0; char *fmt="Uhuuuh, Exception %d in unknown task???\n"; int quiet=0; if (!quiet) printk("In BSP_exceptionHandler()\n"); /* If we are in interrupt context, we are in trouble - skip the user * hook and panic */ if (rtems_interrupt_is_in_progress()) { fmt="Aieeh, Exception %d in interrupt handler\n"; } else if ( !_Thread_Executing) { fmt="Aieeh, Exception %d in initialization code\n"; } else { /* retrieve the notepad which possibly holds an extention pointer */ if (RTEMS_SUCCESSFUL==rtems_task_ident(RTEMS_SELF,RTEMS_LOCAL,&id) && #if 0 /* Must not use a notepad due to unknown initial value (notepad memory is allocated from the * workspace)! */ RTEMS_SUCCESSFUL==rtems_task_get_note(id, BSP_EXCEPTION_NOTEPAD, ¬e) #else RTEMS_SUCCESSFUL==rtems_task_variable_get(id, (void*)&BSP_exceptionExtension, (void**)¬e) #endif ) { ext = (BSP_ExceptionExtension)note; if (ext) quiet=ext->quiet; if (!quiet) { printk("Task (Id 0x%08x) got ",id); } fmt="exception %d\n"; } } if (ext && ext->lowlevelHook && ext->lowlevelHook(excPtr,ext,0)) { /* they did all the work and want us to do nothing! */ printk("they did all the work and want us to do nothing!\n"); return; } if (!quiet) { /* message about exception */ printk(fmt, excPtr->_EXC_number); /* register dump */ printk("\t Next PC or Address of fault = %x, ", excPtr->EXC_SRR0); printk("Mvme5500 Saved MSR = %x\n", excPtr->EXC_SRR1); printk("\t R0 = %08x", excPtr->GPR0); printk(" R1 = %08x", excPtr->GPR1); printk(" R2 = %08x", excPtr->GPR2); printk(" R3 = %08x\n", excPtr->GPR3); printk("\t R4 = %08x", excPtr->GPR4); printk(" R5 = %08x", excPtr->GPR5); printk(" R6 = %08x", excPtr->GPR6); printk(" R7 = %08x\n", excPtr->GPR7); printk("\t R8 = %08x", excPtr->GPR8); printk(" R9 = %08x", excPtr->GPR9); printk(" R10 = %08x", excPtr->GPR10); printk(" R11 = %08x\n", excPtr->GPR11); printk("\t R12 = %08x", excPtr->GPR12); printk(" R13 = %08x", excPtr->GPR13); printk(" R14 = %08x", excPtr->GPR14); printk(" R15 = %08x\n", excPtr->GPR15); printk("\t R16 = %08x", excPtr->GPR16); printk(" R17 = %08x", excPtr->GPR17); printk(" R18 = %08x", excPtr->GPR18); printk(" R19 = %08x\n", excPtr->GPR19); printk("\t R20 = %08x", excPtr->GPR20); printk(" R21 = %08x", excPtr->GPR21); printk(" R22 = %08x", excPtr->GPR22); printk(" R23 = %08x\n", excPtr->GPR23); printk("\t R24 = %08x", excPtr->GPR24); printk(" R25 = %08x", excPtr->GPR25); printk(" R26 = %08x", excPtr->GPR26); printk(" R27 = %08x\n", excPtr->GPR27); printk("\t R28 = %08x", excPtr->GPR28); printk(" R29 = %08x", excPtr->GPR29); printk(" R30 = %08x", excPtr->GPR30); printk(" R31 = %08x\n", excPtr->GPR31); printk("\t CR = %08x\n", excPtr->EXC_CR); printk("\t CTR = %08x\n", excPtr->EXC_CTR); printk("\t XER = %08x\n", excPtr->EXC_XER); printk("\t LR = %08x\n", excPtr->EXC_LR); BSP_printStackTrace(excPtr); } if (ASM_MACH_VECTOR == excPtr->_EXC_number) { /* ollah , we got a machine check - this could either * be a TEA, MCP or internal; let's see and provide more info */ if (!quiet) printk("Machine check; reason:"); if ( ! (excPtr->EXC_SRR1 & (SRR1_TEA_EXC | SRR1_MCP_EXC)) ) { if (!quiet) printk("SRR1\n"); } else { if (excPtr->EXC_SRR1 & (SRR1_TEA_EXC)) { if (!quiet) printk(" TEA"); } if (excPtr->EXC_SRR1 & (SRR1_MCP_EXC)) { unsigned long gerr; if (!quiet) printk(" MCP\n"); /* it's MCP; gather info from the host bridge */ gerr=_BSP_clear_hostbridge_errors(0,0); if (gerr&0x80000000) printk("GT64260 Parity error\n"); if (gerr&0x40000000) printk("GT64260 SysErr\n"); if ((!quiet) && (!gerr)) printk("GT64260 host bridge seems OK\n"); } } } else if (ASM_DEC_VECTOR == excPtr->_EXC_number) { recoverable = 1; } else if (ASM_SYS_VECTOR == excPtr->_EXC_number) { #ifdef TEST_RAW_EXCEPTION_CODE recoverable = 1; #else recoverable = 0; #endif } /* call them for a second time giving a chance to intercept * the task_suspend */ if (ext && ext->lowlevelHook && ext->lowlevelHook(excPtr, ext, 1)) return; if (!recoverable) { if (id) { /* if there's a highlevel hook, install it */ if (ext && ext->highlevelHook) { excPtr->EXC_SRR0 = (uint32_t)ext->highlevelHook; excPtr->GPR3 = (uint32_t)ext; return; } if (excPtr->EXC_SRR1 & MSR_FP) { /* thread dispatching is _not_ disabled at this point; hence * we must make sure we have the FPU enabled... */ _write_MSR( _read_MSR() | MSR_FP ); __asm__ __volatile__("isync"); } printk("unrecoverable exception!!! task %08x suspended\n",id); rtems_task_suspend(id); } else { printk("PANIC, rebooting...\n"); bsp_reset(); } } }
void* bsp_malloc(size_t bytes) { void * buf = 0; irqflags_t flags; if (bytes == 0) bsp_reset(BSP_RESET_ALLOC_NULL); //print_dbg("malloc "); print_dbg_ulong(bytes); print_dbg("\r\n"); flags = cpu_irq_save(); for (int i=0; i<CONFIG_BSP_BUFFERS_NUM_POOLS && buf == 0; i++) { pool_t* pool = &s_pools[i]; if (bytes <= pool->bufsize) { uint8_t* p = pool->pool; for (uint16_t j=0; j<pool->count; j++) { if (((buffer_header_t*)p)->used == 0) { buffer_header_t* hdr = (buffer_header_t*)p; hdr->used = 1; hdr->pool = (uint8_t) i; hdr->alloc_size = (uint16_t) bytes; #ifdef CONFIG_BSP_BUFFERS_BOUNDARY_CHECK hdr->magic = BOUNDARY_MAGIC; memcpy(p+8+bytes,&s_magic,4); buf = p + 8; #else buf = p + 4; #endif if (pool->max_size < bytes) pool->max_size = bytes; if (pool->allocs < 0xffffffff) { pool->allocs++; } else { pool->allocs = 0; pool->frees = 0; } if (pool->max_used < (pool->allocs - pool->frees)) { pool->max_used = pool->allocs - pool->frees; } break; } p += pool->bufsize + BUFFER_OVERHEAD; } } } cpu_irq_restore(flags); if (buf == 0) { print_dbg("malloc failed "); print_dbg_int(bytes); print_dbg("\r\n"); bsp_logcat_printf(BSP_LOGCAT_CRITICAL, "malloc failed %d", bytes); bsp_reset(BSP_RESET_ALLOC_FAIL); } return buf; }