📄 sys.c
字号:
/************************************************************************ * * sys.c * * System functions * * ###################################################################### * * mips_start_of_legal_notice * * Copyright (c) 2004 MIPS Technologies, Inc. All rights reserved. * * * Unpublished rights (if any) reserved under the copyright laws of the * United States of America and other countries. * * This code is proprietary to MIPS Technologies, Inc. ("MIPS * Technologies"). Any copying, reproducing, modifying or use of this code * (in whole or in part) that is not expressly permitted in writing by MIPS * Technologies or an authorized third party is strictly prohibited. At a * minimum, this code is protected under unfair competition and copyright * laws. Violations thereof may result in criminal penalties and fines. * * MIPS Technologies reserves the right to change this code to improve * function, design or otherwise. MIPS Technologies does not assume any * liability arising out of the application or use of this code, or of any * error or omission in such code. Any warranties, whether express, * statutory, implied or otherwise, including but not limited to the implied * warranties of merchantability or fitness for a particular purpose, are * excluded. Except as expressly provided in any written license agreement * from MIPS Technologies or an authorized third party, the furnishing of * this code does not give recipient any license to any intellectual * property rights, including any patent rights, that cover this code. * * This code shall not be exported, reexported, transferred, or released, * directly or indirectly, in violation of the law of any country or * international law, regulation, treaty, Executive Order, statute, * amendments or supplements thereto. Should a conflict arise regarding the * export, reexport, transfer, or release of this code, the laws of the * United States of America shall be the governing law. * * This code constitutes one or more of the following: commercial computer * software, commercial computer software documentation or other commercial * items. If the user of this code, or any related documentation of any * kind, including related technical data or manuals, is an agency, * department, or other entity of the United States government * ("Government"), the use, duplication, reproduction, release, * modification, disclosure, or transfer of this code, or any related * documentation of any kind, is restricted in accordance with Federal * Acquisition Regulation 12.212 for civilian agencies and Defense Federal * Acquisition Regulation Supplement 227.7202 for military agencies. The use * of this code by the Government is further restricted in accordance with * the terms of the license agreement(s) and/or applicable contract terms * and conditions covering this code from MIPS Technologies or an authorized * third party. * * * * * mips_end_of_legal_notice * * ************************************************************************//************************************************************************ * Include files ************************************************************************/#include <sysdefs.h>#include <io_api.h>#include <syscon_api.h>#include <net_api.h>#include <serial_api.h>#include <syserror.h>#include <shell_api.h>#include <sys_api.h>#include <product.h>#include <stdio.h>#include <mips.h>/************************************************************************ * Definitions ************************************************************************//************************************************************************ * Public variables ************************************************************************//************************************************************************ * Static variables ************************************************************************/static char msg[30];/************************************************************************ * Static function prototypes ************************************************************************/static booldetermine_dev( UINT32 port, UINT32 *major, UINT32 *minor );static UINT32sys_validate_ram_range( UINT32 start, /* Start address (physical) */ UINT32 last ); /* Last address (physical) *//************************************************************************ * Implementation : Public functions ************************************************************************//************************************************************************ * sys_putchar ************************************************************************/void sys_putchar( UINT32 port, char ch ){ UINT32 major, minor; /* LF -> CR+LF due to some terminal programs */ if( ch == LF ) sys_putchar( port, CR ); if( determine_dev( port, &major, &minor ) ) { IO_write( major, minor, (UINT8 *)(&ch) ); }}/************************************************************************ * sys_puts ************************************************************************/voidsys_puts( UINT32 port, char *s ){ while( *s != '\0' ) { sys_putchar( port, *(s++) ); }} /************************************************************************ * sys_getchar ************************************************************************/bool /* TRUE -> OK, FALSE -> FAILED */sys_getchar( UINT32 port, char *ch ){ UINT32 major, minor; INT32 rc; if( port == PORT_NET ) { *ch = net_getchar(); return TRUE; } if( determine_dev( port, &major, &minor ) ) { /* Poll whatever needs to be polled (platform specific) */ sys_poll(); rc = IO_read( major, minor, (UINT8 *)(ch) ); if ( (rc == OK) || (rc == ERROR_SERIAL_COMM_BREAK) ) { return TRUE; } if ( rc == ERROR_SERIAL_COMM_ERROR ) { *ch = UART_ERROR; return TRUE; } return FALSE; } else return FALSE;}/************************************************************************ * sys_getchar_ctrlc ************************************************************************/bool /* TRUE -> CTRL-C received */sys_getchar_ctrlc( UINT32 port ){ UINT32 major, minor; t_SERIAL_ctrl_descriptor descr; descr.sc_command = SERIAL_CTRL_POLL_BREAK; if( determine_dev( port, &major, &minor ) ) { return (IO_ctrl( major, minor, (void *)&descr ) == ERROR_SERIAL_COMM_BREAK) ? TRUE : FALSE; } else return FALSE;}/************************************************************************ * * sys_disp * Description : * ------------- * * Display value in ASCII display * * Return values : * --------------- * * None * ************************************************************************/void sys_disp( UINT32 val ){ SYSCON_write( SYSCON_BOARD_ASCIIWORD_ID, (void *)&val, sizeof(UINT32) );}/************************************************************************ * * sys_disp_ch * Description : * ------------- * * Display character in ASCII display * * Return values : * --------------- * * None * ************************************************************************/void sys_disp_ch( UINT8 pos, char ch ){ t_sys_alphanumeric data; data.posid = pos; data.string = (UINT8 *)&ch; SYSCON_write( SYSCON_BOARD_ASCIICHAR_ID, (void *)&data, sizeof(t_sys_alphanumeric) );}/************************************************************************ * * sys_disp_str * Description : * ------------- * * Display string in ASCII display * * Return values : * --------------- * * None * ************************************************************************/void sys_disp_str( char *s ){ t_sys_alphanumeric data; data.posid = 0; data.string = (UINT8 *)s; SYSCON_write( SYSCON_BOARD_ASCIISTRING_ID,\ (void *)&data, sizeof(t_sys_alphanumeric) );}/************************************************************************ * * sys_wait_ms * Description : * ------------- * * Wait for the specified interval * * Return values : * --------------- * * None * ************************************************************************/voidsys_wait_ms( UINT32 ms ) /* Interval in milliseconds */{ UINT32 first, current, last; UINT32 cycle_per_count; SYSCON_read( SYSCON_CPU_CYCLE_PER_COUNT_ID, &cycle_per_count, sizeof(UINT32) ); /* read start value */ SYSCON_read( SYSCON_CPU_CP0_COUNT_ID, (void *)(&first), sizeof(UINT32) ); last = first + ((sys_cpufreq_hz / 1000) * ms / cycle_per_count); if (last >= first) do { /* no wrap - continue while between first and last */ SYSCON_read( SYSCON_CPU_CP0_COUNT_ID, (void *)(¤t), sizeof(UINT32) ); } while( current < last && current >= first ); else do { /* wrap - continue until between first and last */ SYSCON_read( SYSCON_CPU_CP0_COUNT_ID, (void *)(¤t), sizeof(UINT32) ); } while( current < last || current >= first );}/************************************************************************ * * sys_reg_addr * Description : * ------------- * * Calc address from base address, register spacing and register offset. * Also, in case of device with different endianness than CPU, adjust * for endianness (only supported for 1 byte spacings). * * In case the following is true, the 2 lsb of the address need * to be inverted : * * 1) Endianness of target and CPU are not the same * 3) spacing is 1 byte * * Return values : * --------------- * * address (void pointer) * ************************************************************************/void *sys_reg_addr( bool target_bigend, /* TRUE -> target is big endian. FALSE -> target is little endian. */ UINT8 spacing, /* spacing of regs in bytes */ void *base, /* Base address */ UINT32 offset ) /* Offset scaled down by spacing */{ UINT32 addr = (UINT32)base + offset * spacing; if( spacing == sizeof(UINT8) ) { addr = target_bigend ? SWAP_BYTEADDR_EB( addr ) : SWAP_BYTEADDR_EL( addr ); } return (void *)addr;}/************************************************************************ * * sys_validate_range * Description : * ------------- * * Validate address range (alignment, TLB if mapped address, RAM range). * * Return values : * --------------- * * OK : No error * SHELL_ERROR_ALIGN : Alignment error * SHELL_ERROR_OVERFLOW : Range overflow * SHELL_ERROR_TLB : Mapped address with no match in TLB * SHELL_ERROR_TLB_WP : Write access to mapped write protected address * SHELL_ERROR_RAM_RANGE : Address in unused RAM space * ************************************************************************/UINT32sys_validate_range( UINT32 addr, /* Start address */ UINT32 count, /* Byte count */ UINT8 size, /* Access size (number of bytes) */ bool write ) /* Write access */{ UINT32 last, pagesize; bool sys_mmu_tlb; UINT32 phys; UINT32 rc; UINT8 range_start; UINT32 erl;#define R_KUSEG 0#define R_KSEG0 1#define R_KSEG1 2#define R_KSSEG 3#define R_KSEG3 4 if( !sys_legal_align( addr, size ) || !sys_legal_align( count, size ) ) return SHELL_ERROR_ALIGN; if( count == 0 ) return OK;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -