diff --git a/Makefile b/Makefile index b1b7582..f2cdd06 100755 --- a/Makefile +++ b/Makefile @@ -6,3 +6,4 @@ all: make -C boot1/apps/Boot_Burn -j8 make -C boot1/apps/Card_Android -j8 make -C boot1/driver/drv_de -j8 + make -C boot1/driver/drv_de_hdmi -j8 diff --git a/boot0/Boot0_C_part.c b/boot0/Boot0_C_part.c index 3d67f65..2626392 100755 --- a/boot0/Boot0_C_part.c +++ b/boot0/Boot0_C_part.c @@ -30,6 +30,7 @@ ************************************************************************************************************************ */ #include "boot0_i.h" +#include "arm_a8.h" #include @@ -43,6 +44,9 @@ static int check_bootid(void); static void timer_init(void); static void print_version(void); static __u32 check_odt(int ms); +static void open_cpuX(__u32 cpu); +static void close_cpuX(__u32 cpu); + static __u32 cpu_freq = 0; static __u32 overhead = 0; @@ -69,6 +73,8 @@ void Boot0_C_part( void ) { jump_to( FEL_BASE ); } + + timer_init(); UART_open( BT0_head.prvt_head.uart_port, (void *)BT0_head.prvt_head.uart_ctrl, 24*1000*1000 ); odt_status = check_odt(5); @@ -78,17 +84,16 @@ void Boot0_C_part( void ) } msg("HELLO! BOOT0 is starting!\n"); print_version(); - - mmu_system_init(EGON2_DRAM_BASE, 4 * 1024, EGON2_MMU_BASE); - mmu_enable(); - init_perfcounters(1, 0); + init_perfcounters(1, 0); change_runtime_env(0); - #ifdef CONFIG_HOLD_SUPERSTANDBY_DATA_BY_PMU - //for A20 super standby - boot0_twi_init(); - #endif + open_cpuX(1); + close_cpuX(1); + + mmu_system_init(EGON2_DRAM_BASE, 1 * 1024, EGON2_MMU_BASE); + mmu_enable(); + if(BT0_head.boot_head.platform[7]) { msg("read dram para.\n"); @@ -98,12 +103,10 @@ void Boot0_C_part( void ) } dram_size = init_DRAM(BT0_head.boot_head.platform[7]); // 初始化DRAM - #ifdef CONFIG_HOLD_SUPERSTANDBY_DATA_BY_PMU - boot0_twi_exit(); - #endif + if(dram_size) { - msg("dram size =%d\n", dram_size); + msg("dram size =%dMB\n", dram_size); } else { @@ -111,17 +114,6 @@ void Boot0_C_part( void ) mmu_disable( ); jump_to( FEL_BASE ); } - -#ifdef CONFIG_AW_FPGA_PLATFORM - dram_size=*((volatile unsigned int*)(0x7000-0x4)); - msg("sram data=%x\n",dram_size); - if(dram_size==0x12345678) - { - msg("force jump to superstandby!\n"); - jump_to( 0x52000000 ); - } -#endif - msg("%x\n", *(volatile int *)0x52000000); msg("super_standby_flag = %d\n", super_standby_flag); if(1 == super_standby_flag) @@ -458,3 +450,122 @@ void delay_us(__u32 us) return; } + +__asm void cpuX_startup_to_wfi(void) +{ + + mrs r0, cpsr + bic r0, r0, #ARMV7_MODE_MASK + orr r0, r0, #ARMV7_SVC_MODE + orr r0, r0, #( ARMV7_IRQ_MASK | ARMV7_FIQ_MASK ) // After reset, ARM automaticly disables IRQ and FIQ, and runs in SVC mode. + bic r0, r0, #ARMV7_CC_E_BIT // set little-endian + msr cpsr_c, r0 + + // configure memory system : disable MMU,cache and write buffer; set little_endian; + mrc p15, 0, r0, c1, c0 + bic r0, r0, #( ARMV7_C1_M_BIT | ARMV7_C1_C_BIT )// disable MMU, data cache + bic r0, r0, #( ARMV7_C1_I_BIT | ARMV7_C1_Z_BIT )// disable instruction cache, disable flow prediction + bic r0, r0, #( ARMV7_C1_A_BIT) // disable align + mcr p15, 0, r0, c1, c0 + // set SP for SVC mode + mrs r0, cpsr + bic r0, r0, #ARMV7_MODE_MASK + orr r0, r0, #ARMV7_SVC_MODE + msr cpsr_c, r0 + ldr sp, =0xb400 + + //let the cpu1+ enter wfi state; + /* step3: execute a CLREX instruction */ + clrex + /* step5: execute an ISB instruction */ + isb sy + /* step6: execute a DSB instruction */ + dsb sy + /* step7: execute a WFI instruction */ + wfi + /* step8:wait here */ + b . +} + +#define SW_PA_CPUCFG_IO_BASE 0x01c25c00 +/* + * CPUCFG + */ +#define AW_CPUCFG_P_REG0 0x01a4 +#define CPUX_RESET_CTL(x) (0x40 + (x)*0x40) +#define CPUX_CONTROL(x) (0x44 + (x)*0x40) +#define CPUX_STATUS(x) (0x48 + (x)*0x40) +#define AW_CPUCFG_GENCTL 0x0184 +#define AW_CPUCFG_DBGCTL0 0x01e0 +#define AW_CPUCFG_DBGCTL1 0x01e4 + +#define AW_CPU1_PWR_CLAMP 0x01b0 +#define AW_CPU1_PWROFF_REG 0x01b4 +#define readl(addr) (*((volatile unsigned long *)(addr))) +#define writel(v, addr) (*((volatile unsigned long *)(addr)) = (unsigned long)(v)) + +#define IO_ADDRESS(IO_ADDR) (IO_ADDR) +#define IS_WFI_MODE(cpu) (readl(IO_ADDRESS(SW_PA_CPUCFG_IO_BASE) + CPUX_STATUS(cpu)) & (1<<2)) + +void open_cpuX(__u32 cpu) +{ + long paddr; + __u32 pwr_reg; + + paddr = (__u32)cpuX_startup_to_wfi; + writel(paddr, IO_ADDRESS(SW_PA_CPUCFG_IO_BASE) + AW_CPUCFG_P_REG0); + + /* step1: Assert nCOREPORESET LOW and hold L1RSTDISABLE LOW. + Ensure DBGPWRDUP is held LOW to prevent any external + debug access to the processor. + */ + /* assert cpu core reset */ + writel(0, IO_ADDRESS(SW_PA_CPUCFG_IO_BASE) + CPUX_RESET_CTL(cpu)); + /* L1RSTDISABLE hold low */ + pwr_reg = readl(IO_ADDRESS(SW_PA_CPUCFG_IO_BASE) + AW_CPUCFG_GENCTL); + pwr_reg &= ~(1<>1) -#define AXP19_ADDR (0x68>>1) -#define AXP18_ADDR (0x2C>>1) - -#define PMU_TYPE_NONE (0) -#define PMU_TYPE_AXP189 (1) -#define PMU_TYPE_AXP199 (2) -#define PMU_TYPE_AXP209 (3) -//AXP18X REG DEFINE -#define BOOT_POWER_STATUS (0x00) -#define BOOT_POWER_IPS_SET (0x01) -#define BOOT_POWER_ONOFF (0x02) -#define BOOT_POWER_CHARGE1 (0x03) -#define BOOT_POWER_CHARGE2 (0x04) -#define BOOT_POWER_PEK (0x05) -#define BOOT_POWER_INTEN1 (0x06) -#define BOOT_POWER_INTEN2 (0x07) -#define BOOT_POWER_INTEN3 (0x08) -#define BOOT_POWER_INTSTS1 (0x09) -#define BOOT_POWER_INTSTS2 (0x0A) -#define BOOT_POWER_INTSTS3 (0x0B) -#define BOOT_POWER_VENDER_USED1 (0x0C) -#define BOOT_POWER_DCDCCTL (0x0D) -#define BOOT_POWER_DC12OUT_VOL (0x0E) -#define BOOT_POWER_LDOOUT_VOL (0x0F) -#define BOOT_POWER_SW_CTL (0x10) -#define BOOT_POWER_BATTERY_VOL (0x11) -#define BOOT_POWER_BATTERY_CURRENT (0x12) -#define BOOT_POWER_DCIN_VOL (0x13) -#define BOOT_POWER_DCIN_CURRENT (0x14) -#define BOOT_POWER_ADCSW_CTL (0x15) -#define BOOT_POWER_CLASSD_PAEN (0x16) -#define BOOT_POWER_EPT_SW (0x17) -#define BOOT_POWER_DATA_BUFFER1 (0x18) -#define BOOT_POWER_DATA_BUFFER2 (0x19) -#define BOOT_POWER_VENDER_USED3 (0x1A) -//AXP19X REG DEFINE -#define POWER_STATUS (0x00) -#define POWER_MODE_CHGSTATUS (0x01) -#define POWER_OTG_STATUS (0x02) -#define POWER_DATA_BUFFER1 (0x06) -#define POWER_DATA_BUFFER2 (0x07) -#define POWER_DATA_BUFFER3 (0x08) -#define POWER_DATA_BUFFER4 (0x09) -#define POWER_VERSION (0x0C) -#define POWER_LDO3_DC2_CTL (0x10) -#define POWER_LDO24_DC13_CTL (0x12) -#define POWER_DC2OUT_VOL (0x23) -#define POWER_LDO3_DC2_DVM (0x25) -#define POWER_DC1OUT_VOL (0x26) -#define POWER_DC3OUT_VOL (0x27) -#define POWER_LDO24OUT_VOL (0x28) -#define POWER_LDO3OUT_VOL (0x29) -#define POWER_IPS_SET (0x30) -#define POWER_VOFF_SET (0x31) -#define POWER_OFF_CTL (0x32) -#define POWER_CHARGE1 (0x33) -#define POWER_CHARGE2 (0x34) -#define POWER_BACKUP_CHG (0x35) -#define POWER_POK_SET (0x36) -#define POWER_DCDC_FREQSET (0x37) -#define POWER_VLTF_CHGSET (0x38) -#define POWER_VHTF_CHGSET (0x39) -#define POWER_APS_WARNING1 (0x3A) -#define POWER_APS_WARNING2 (0x3B) -#define POWER_VLTF_DISCHGSET (0x3C) -#define POWER_VHTF_DISCHGSET (0x3D) -#define POWER_DCDC_MODESET (0x80) -#define POWER_VOUT_MONITOR (0x81) -#define POWER_ADC_EN1 (0x82) -#define POWER_ADC_EN2 (0x83) -#define POWER_ADC_SPEED (0x84) -#define POWER_ADC_INPUTRANGE (0x85) -#define POWER_TIMER_CTL (0x8A) -#define POWER_VBUS_DET_SRP (0x8B) -#define POWER_HOTOVER_CTL (0x8F) -#define POWER_GPIO0_CTL (0x90) -#define POWER_GPIO0_VOL (0x91) -#define POWER_GPIO1_CTL (0x92) -#define POWER_GPIO2_CTL (0x93) -#define POWER_GPIO012_SIGNAL (0x94) -#define POWER_SENSE_CTL (0x95) -#define POWER_SENSE_SIGNAL (0x96) -#define POWER_GPIO20_PDCTL (0x97) -#define POWER_PWM1_FREQ (0x98) -#define POWER_PWM1_DUTYDE (0x99) -#define POWER_PWM1_DUTY (0x9A) -#define POWER_PWM2_FREQ (0x9B) -#define POWER_PWM2_DUTYDE (0x9C) -#define POWER_PWM2_DUTY (0x9D) -#define POWER_RSTO_CTL (0x9E) -#define POWER_GPIO67_CTL (0x9F) -#define POWER_INTEN1 (0x40) -#define POWER_INTEN2 (0x41) -#define POWER_INTEN3 (0x42) -#define POWER_INTEN4 (0x43) -#define POWER_INTSTS1 (0x44) -#define POWER_INTSTS2 (0x45) -#define POWER_INTSTS3 (0x46) -#define POWER_INTSTS4 (0x47) -#define POWER_COULOMB_CTL (0xB8) - -//adc data register -#define POWER_BAT_AVERVOL_H8 (0x78) -#define POWER_BAT_AVERVOL_L4 (0x79) -#define POWER_BAT_RTVOL_H8 (0x50) -#define POWER_BAT_RTVOL_L4 (0x51) -#define POWER_BAT_AVERCHGCUR_H8 (0x7A) -#define POWER_BAT_AVERCHGCUR_L5 (0x7B) -#define POWER_ACIN_VOL_H8 (0x56) -#define POWER_ACIN_VOL_L4 (0x57) -#define POWER_ACIN_CUR_H8 (0x58) -#define POWER_ACIN_CUR_L4 (0x59) -#define POWER_VBUS_VOL_H8 (0x5A) -#define POWER_VBUS_VOL_L4 (0x5B) -#define POWER_VBUS_CUR_H8 (0x5C) -#define POWER_VBUS_CUR_L4 (0x5D) -#define POWER_BAT_AVERDISCHGCUR_H8 (0x7C) -#define POWER_BAT_AVERDISCHGCUR_L5 (0x7D) -#define POWER_APS_AVERVOL_H8 (0x7E) -#define POWER_APS_AVERVOL_L4 (0x7F) -#define POWER_BAT_CHGCOULOMB3 (0xB0) -#define POWER_BAT_CHGCOULOMB2 (0xB1) -#define POWER_BAT_CHGCOULOMB1 (0xB2) -#define POWER_BAT_CHGCOULOMB0 (0xB3) -#define POWER_BAT_DISCHGCOULOMB3 (0xB4) -#define POWER_BAT_DISCHGCOULOMB2 (0xB5) -#define POWER_BAT_DISCHGCOULOMB1 (0xB6) -#define POWER_BAT_DISCHGCOULOMB0 (0xB7) -#define POWER_BAT_POWERH8 (0x70) -#define POWER_BAT_POWERM8 (0x71) -#define POWER_BAT_POWERL8 (0x72) - -//define AXP20 REGISTER -#define BOOT_POWER20_STATUS (0x00) -#define BOOT_POWER20_MODE_CHGSTATUS (0x01) -#define BOOT_POWER20_OTG_STATUS (0x02) -#define BOOT_POWER20_VERSION (0x03) -#define BOOT_POWER20_DATA_BUFFER0 (0x04) -#define BOOT_POWER20_DATA_BUFFER1 (0x05) -#define BOOT_POWER20_DATA_BUFFER2 (0x06) -#define BOOT_POWER20_DATA_BUFFER3 (0x07) -#define BOOT_POWER20_DATA_BUFFER4 (0x08) -#define BOOT_POWER20_DATA_BUFFER5 (0x09) -#define BOOT_POWER20_DATA_BUFFER6 (0x0a) -#define BOOT_POWER20_DATA_BUFFER7 (0x0b) -#define BOOT_POWER20_DATA_BUFFER8 (0x0c) -#define BOOT_POWER20_DATA_BUFFER9 (0x0d) -#define BOOT_POWER20_DATA_BUFFER10 (0x0e) -#define BOOT_POWER20_DATA_BUFFER11 (0x0f) -#define BOOT_POWER20_OUTPUT_CTL (0x12) -#define BOOT_POWER20_DC2OUT_VOL (0x23) -#define BOOT_POWER20_LDO3_DC2_DVM (0x25) -#define BOOT_POWER20_DC3OUT_VOL (0x27) -#define BOOT_POWER20_LDO24OUT_VOL (0x28) -#define BOOT_POWER20_LDO3OUT_VOL (0x29) -#define BOOT_POWER20_IPS_SET (0x30) -#define BOOT_POWER20_VOFF_SET (0x31) -#define BOOT_POWER20_OFF_CTL (0x32) -#define BOOT_POWER20_CHARGE1 (0x33) -#define BOOT_POWER20_CHARGE2 (0x34) -#define BOOT_POWER20_BACKUP_CHG (0x35) -#define BOOT_POWER20_POK_SET (0x36) -#define BOOT_POWER20_DCDC_FREQSET (0x37) -#define BOOT_POWER20_VLTF_CHGSET (0x38) -#define BOOT_POWER20_VHTF_CHGSET (0x39) -#define BOOT_POWER20_APS_WARNING1 (0x3A) -#define BOOT_POWER20_APS_WARNING2 (0x3B) -#define BOOT_POWER20_VLTF_DISCHGSET (0x3C) -#define BOOT_POWER20_VHTF_DISCHGSET (0x3D) -#define BOOT_POWER20_DCDC_MODESET (0x80) -#define BOOT_POWER20_VOUT_MONITOR (0x81) -#define BOOT_POWER20_ADC_EN1 (0x82) -#define BOOT_POWER20_ADC_EN2 (0x83) -#define BOOT_POWER20_ADC_SPEED (0x84) -#define BOOT_POWER20_ADC_INPUTRANGE (0x85) -#define BOOT_BOOT_POWER20_GPIO1ADC_VTH (0x86) -#define BOOT_POWER20_GPIO1ADC_VTL (0x87) -#define BOOT_POWER20_TIMER_CTL (0x8A) -#define BOOT_POWER20_VBUS_DET_SRP (0x8B) -#define BOOT_POWER20_HOTOVER_CTL (0x8F) -#define BOOT_POWER20_GPIO0_CTL (0x90) -#define BOOT_POWER20_GPIO0_VOL (0x91) -#define BOOT_POWER20_GPIO1_CTL (0x92) -#define BOOT_POWER20_GPIO2_CTL (0x93) -#define BOOT_POWER20_GPIO012_SIGNAL (0x94) -#define BOOT_POWER20_GPIO3_CTL (0x95) -#define BOOT_POWER20_GPIO012_PDCTL (0x97) -#define BOOT_POWER20_INTEN1 (0x40) -#define BOOT_POWER20_INTEN2 (0x41) -#define BOOT_POWER20_INTEN3 (0x42) -#define BOOT_POWER20_INTEN4 (0x43) -#define BOOT_POWER20_INTEN5 (0x44) -#define BOOT_POWER20_INTSTS1 (0x48) -#define BOOT_POWER20_INTSTS2 (0x49) -#define BOOT_POWER20_INTSTS3 (0x4a) -#define BOOT_POWER20_INTSTS4 (0x4b) -#define BOOT_POWER20_INTSTS5 (0x4c) -#define BOOT_POWER20_COULOMB_CTL (0xB8) -#define BOOT_POWER20_COULOMB_CAL (0xB9) - -//adc data register -#define BOOT_POWER20_BAT_AVERVOL_H8 (0x78) -#define BOOT_POWER20_BAT_AVERVOL_L4 (0x79) -#define BOOT_POWER20_BAT_AVERCHGCUR_H8 (0x7A) -#define BOOT_POWER20_BAT_AVERCHGCUR_L4 (0x7B) -#define BOOT_POWER20_ACIN_VOL_H8 (0x56) -#define BOOT_POWER20_ACIN_VOL_L4 (0x57) -#define BOOT_POWER20_ACIN_CUR_H8 (0x58) -#define BOOT_POWER20_ACIN_CUR_L4 (0x59) -#define BOOT_POWER20_VBUS_VOL_H8 (0x5A) -#define BOOT_POWER20_VBUS_VOL_L4 (0x5B) -#define BOOT_POWER20_VBUS_CUR_H8 (0x5C) -#define BOOT_POWER20_VBUS_CUR_L4 (0x5D) -#define BOOT_POWER20_BAT_AVERDISCHGCUR_H8 (0x7C) -#define BOOT_POWER20_BAT_AVERDISCHGCUR_L5 (0x7D) -#define BOOT_POWER20_APS_AVERVOL_H8 (0x7E) -#define BOOT_POWER20_APS_AVERVOL_L4 (0x7F) -#define BOOT_POWER20_BAT_CHGCOULOMB3 (0xB0) -#define BOOT_POWER20_BAT_CHGCOULOMB2 (0xB1) -#define BOOT_POWER20_BAT_CHGCOULOMB1 (0xB2) -#define BOOT_POWER20_BAT_CHGCOULOMB0 (0xB3) -#define BOOT_POWER20_BAT_DISCHGCOULOMB3 (0xB4) -#define BOOT_POWER20_BAT_DISCHGCOULOMB2 (0xB5) -#define BOOT_POWER20_BAT_DISCHGCOULOMB1 (0xB6) -#define BOOT_POWER20_BAT_DISCHGCOULOMB0 (0xB7) -#define BOOT_POWER20_BAT_POWERH8 (0x70) -#define BOOT_POWER20_BAT_POWERM8 (0x71) -#define BOOT_POWER20_BAT_POWERL8 (0x72) - - - - - -#endif /* _BOOT_POWER_I_H_ */ diff --git a/boot0/drv/iic/sw_iic.c b/boot0/drv/iic/sw_iic.c deleted file mode 100644 index 2764518..0000000 --- a/boot0/drv/iic/sw_iic.c +++ /dev/null @@ -1,602 +0,0 @@ -/* -********************************************************************************************************************** -* ePDK -* the Easy Portable/Player Develop Kits -* eBIOS Sub-System -* -* (c) Copyright 2007-2009, Steven.ZGJ.China -* All Rights Reserved -* -* Moudle : iis controller bios -* File : iisc.c -* -* By : Steven -* Version : v1.00 -* Date : 2008-8-19 18:32:00 -********************************************************************************************************************** -*/ - -#include "boot0_i.h" -#include "sw_iic.h" - -#define i2c_ctl twi_ports[0] - - -static sw_iic_t twi_ports[3] = { - (sw_iic_t)CFG_SW_IIC_CTL0, - (sw_iic_t)CFG_SW_IIC_CTL1, - (sw_iic_t)CFG_SW_IIC_CTL2 -}; - - -static void _for_loop(unsigned int loop) -{ - unsigned int i; - - for( i = 0; i < loop; i++ ); -} -__s32 boot0_twi_setfreq(void); -/* -********************************************************************************************************************** -* sw_iic_exit -* -* Description: 通过IIC控制器读取IIC设备一个字节,暂时只支持标准的设备 -* -* Arguments : -* -* Returns : 读取成功返回0,否则返回 -1 -* -* Notes : none -* -********************************************************************************************************************** -*/ -static __s32 _iic_SendStart(void) -{ - __s32 time = 0xfffff; - __u32 tmp_val; - - i2c_ctl->srst = 1; - - i2c_ctl->ctl |= 0x20; - - while((time--)&&(!(i2c_ctl->ctl & 0x08))); - if(time <= 0) - { - return SW_IIC_OPERATION_START_NO_INT; - } - - tmp_val = i2c_ctl->status; - if(tmp_val != 0x08) - { - return -1; - } - - return SW_IIC_OPERATION_NO_ERR; -} -/* -********************************************************************************************************************** -* TWIC_SendReStart -* -* Description: -* -* Arguments : -* -* Returns : -* -* Notes : -* -********************************************************************************************************************** -*/ -__s32 _iic_SendReStart(void) -{ - __s32 time = 0xffff; - __u32 tmp_val; - - tmp_val = i2c_ctl->ctl & 0xC0; - tmp_val |= 0x20; - i2c_ctl->ctl = tmp_val; - - while( (time--) && (!(i2c_ctl->ctl & 0x08)) ); - if(time <= 0) - { - return -1; - } - - tmp_val = i2c_ctl->status; - if(tmp_val != 0x10) - { - return -1; - } - - return 0; -} -/* -********************************************************************************************************************** -* TWIC_SendSlaveAddr -* -* Description: -* -* Arguments : -* -* Returns : EPDK_OK = successed; EPDK_FAIL = failed -* -* Notes : none -* -********************************************************************************************************************** -*/ -static __s32 _iic_SendSlaveAddr(__u32 saddr, __u32 rw) -{ - __s32 time = 0xffff; - __u32 tmp_val; - - if(( rw != SW_IIC_READ ) && ( rw != SW_IIC_WRITE )) - { - return -1; - } - - i2c_ctl->data = ((saddr & 0xff) << 1) | rw; - i2c_ctl->ctl &= 0xF7; - - while(( time-- ) && (!( i2c_ctl->ctl & 0x08 ))); - if(time <= 0) - { - return -1; - } - - tmp_val = i2c_ctl->status; - if(rw == SW_IIC_WRITE)//+write - { - if(tmp_val != 0x18) - { - return -1; - } - } - else//+read - { - if(tmp_val != 0x40) - { - return -1; - } - } - - return 0; -} -/* -********************************************************************************************************************** -* _iic_SendByteAddr -* -* Description: -* -* Arguments : -* -* Returns : EPDK_OK = successed; EPDK_FAIL = failed -* -* Notes : none -* -********************************************************************************************************************** -*/ -static __s32 _iic_SendByteAddr(__u32 byteaddr) -{ - __s32 time = 0xffff; - __u32 tmp_val; - - i2c_ctl->data = byteaddr & 0xff; - i2c_ctl->ctl &= 0xF7; - - while( (time--) && (!(i2c_ctl->ctl & 0x08)) ); - if(time <= 0) - { - return -1; - } - - tmp_val = i2c_ctl->status; - if(tmp_val != 0x28) - { - return -1; - } - - return 0; -} -/* -********************************************************************************************************************** -* TWIC_GetData -* -* Description: -* -* Arguments : -* -* Returns : EPDK_OK = successed; EPDK_FAIL = failed -* -* Notes : none -* -********************************************************************************************************************** -*/ -static __s32 _iic_GetData(__u8 *data_addr, __u32 data_count) -{ - __s32 time = 0xffff; - __u32 tmp_val, i; - - if(data_count == 1) - { - i2c_ctl->ctl &= 0xF7; - - while( (time--) && (!(i2c_ctl->ctl & 0x08)) ); - if(time <= 0) - { - return -1; - } - for(time=0;time<100;time++); - *data_addr = i2c_ctl->data; - - tmp_val = i2c_ctl->status; - if(tmp_val != 0x58) - { - return -1; - } - } - else - { - for(i=0; i< data_count - 1; i++) - { - time = 0xffff; - tmp_val = i2c_ctl->ctl & 0xF7; - tmp_val |= 0x04; - i2c_ctl->ctl = tmp_val; - - while( (time--) && (!(i2c_ctl->ctl & 0x08)) ); - if(time <= 0) - { - return -1; - } - for(time=0;time<100;time++); - time = 0xffff; - data_addr[i] = i2c_ctl->data; - while( (time--) && (i2c_ctl->status != 0x50) ); - if(time <= 0) - { - return -1; - } - } - - time = 0xffff; - i2c_ctl->ctl &= 0xF3; - while( (time--) && (!(i2c_ctl->ctl & 0x08)) ); - if(time <= 0) - { - return -1; - } - for(time=0;time<100;time++); - data_addr[data_count - 1] = i2c_ctl->data; - while( (time--) && (i2c_ctl->status != 0x58) ); - if(time <= 0) - { - return -1; - } - } - - return 0; -} -/* -********************************************************************************************************************** -* _iic_SendData -* -* Description: -* -* Arguments : -* -* Returns : EPDK_OK = successed; EPDK_FAIL = failed -* -* Notes : none -* -********************************************************************************************************************** -*/ -static __s32 _iic_SendData(__u8 *data_addr, __u32 data_count) -{ - __s32 time = 0xffff; - __u32 i; - - for(i=0; i< data_count; i++) - { - time = 0xffff; - i2c_ctl->data = data_addr[i]; - i2c_ctl->ctl &= 0xF7; - - while( (time--) && (!(i2c_ctl->ctl & 0x08)) ); - if(time <= 0) - { - return -1; - } - time = 0xffff; - while( (time--) && (i2c_ctl->status != 0x28) ); - if(time <= 0) - { - return -1; - } - } - - return 0; -} -/* -********************************************************************************************************************** -* _iic_Stop -* -* Description: -* -* Arguments : -* -* Returns : EPDK_OK = successed; EPDK_FAIL = failed -* -* Notes : none -* -********************************************************************************************************************** -*/ -__s32 _iic_Stop(void) -{ - __s32 time = 0xffff; - __u32 tmp_val; - - tmp_val = (i2c_ctl->ctl & 0xC0) | 0x10; - i2c_ctl->ctl = tmp_val; - while( (time--) && (i2c_ctl->ctl & 0x10) ); - if(time <= 0) - { - return -1; - } - time = 0xffff; - while( (time--) && (i2c_ctl->status != 0xf8) ); - tmp_val = i2c_ctl->status; - if(tmp_val != 0xf8) - { - return -1; - } - - return 0; -} -/* -********************************************************************************************************************** -* sw_iic_init -* -* Description: Init I2C controller -* -* Arguments : sw_iic_t i2c_ctl -* -* Returns : 0 = successed; -1 = failed -* -* Notes : none -* -********************************************************************************************************************** -*/ -__s32 boot0_twi_init(void) -{ - __s32 reset_delay; - __u32 reg_val; - - CCMU_REG_APB_MOD1 &= ~(1 << 0); - _for_loop(100); - CCMU_REG_APB_MOD1 |= (1 << 0); - - reg_val = *(volatile __u32 *)(0x1c20800 + 0x24); - reg_val &= ~(0xff << 0); - reg_val |= (0x22 << 0); - *(volatile __u32 *)(0x1c20800 + 0x24) = reg_val; - - reg_val = *(volatile __u32 *)(0x1c20800 + 0x40); - reg_val &= ~(0x33 << 0); - *(volatile __u32 *)(0x1c20800 + 0x40) = reg_val; - - reset_delay = 0xffff; - i2c_ctl->srst = 1; - while((i2c_ctl->srst) && (reset_delay--)); - if(reset_delay <= 0) - { - return -1; - } - - return boot0_twi_setfreq(); -} -/* -********************************************************************************************************************** -* sw_iic_setfreq -* -* Description: SET I2C controller Frequency -* -* Arguments : sw_iic_t i2c_ctl -* -* Returns : 0 = successed; -1 = failed -* -* Notes : none -* -********************************************************************************************************************** -*/ -__s32 boot0_twi_setfreq(void) -{ - __u32 clk_m = 0; - __u32 clk_n = 0; - - clk_m = 2; - clk_n = 1; - - i2c_ctl->clk = (clk_m<<3) | clk_n; - i2c_ctl->ctl = 0x40; - i2c_ctl->eft = 0; - - return 0; -} - -/* -********************************************************************************************************************** -* sw_iic_exit -* -* Description: exit I2C controller -* -* Arguments : sw_iic_t i2c_ctl -* -* Returns : 0 = successed; -1 = failed -* -* Notes : none -* -********************************************************************************************************************** -*/ -__s32 boot0_twi_exit(void) -{ - CCMU_REG_APB_MOD1 &= ~(1 << 0); - - return 0; -} -/* -**************************************************************************************************** -* -* sw_iic_read -* -* Description: -* -* -* Parameters: -* -* Return value: -* EPDK_OK -* EPDK_FAIL -**************************************************************************************************** -*/ -__s32 boot0_twi_read(void *twi_arg) -{ - __u32 tmp, rw_flag; - __s32 ret = -1; - _twi_arg_t *arg = (_twi_arg_t *)twi_arg; - - tmp = 0; - rw_flag = SW_IIC_WRITE; - - i2c_ctl->eft = tmp; - if(_iic_SendStart() != 0) - { - ret = -1; - goto _iic_read_stop; - } - if(_iic_SendSlaveAddr(arg->slave_addr, rw_flag) != 0) - { - ret = -1; - goto _iic_read_stop; - } - //send byte address - if(_iic_SendByteAddr(arg->byte_addr[0] & 0xff) != 0) - { - ret = -1; - goto _iic_read_stop; - } - //restart - if(_iic_SendReStart() != 0) - { - ret = -1; - goto _iic_read_stop; - } - //send slave address + read flag - if(_iic_SendSlaveAddr(arg->slave_addr, SW_IIC_READ) == -1) - { - ret = -1; - goto _iic_read_stop; - } - //get data - if(_iic_GetData(arg->data, arg->byte_count) != 0) - { - ret = -1; - goto _iic_read_stop; - } - ret = 0; - -_iic_read_stop: - if(_iic_Stop() != 0) - { - ret = -1; - } - - //restore the byte address counter to default - return ret; -} - -/* -**************************************************************************************************** -* -* TWIC_Write -* -* Description: -* DRV_MOpen -* -* Parameters: -* -* Return value: -* EPDK_OK -* EPDK_FAIL -**************************************************************************************************** -*/ -__s32 boot0_twi_write(void *twi_arg) -{ - __s32 ret = -1; - _twi_arg_t *arg = (_twi_arg_t *)twi_arg; - - i2c_ctl->eft = 0; - if(_iic_SendStart() != 0) - { - ret = -1; - goto _iic_write_stop; - } - if(_iic_SendSlaveAddr(arg->slave_addr, SW_IIC_WRITE) != 0) - { - ret = -1; - goto _iic_write_stop; - } - - if(_iic_SendByteAddr(arg->byte_addr[0] & 0xff) != 0) - { - ret = -1; - goto _iic_write_stop; - } - - if(_iic_SendData(arg->data, arg->byte_count) != 0) - { - ret = -1; - goto _iic_write_stop; - } - ret = 0; - -_iic_write_stop: - if(_iic_Stop() != 0) - { - ret = -1; - } - - return ret; -} - - -__s32 BOOT_TWI_Read(__u32 arg1, __u8 *arg2, __u8 *arg3) -{ - _twi_arg_t twi_data; - - twi_data.slave_addr = arg1; - twi_data.slave_addr_flag = 0; - twi_data.byte_addr = arg2; - twi_data.byte_addr_width = 1; - twi_data.byte_count = 1; - twi_data.data = arg3; - twi_data.if_restart = 1; - - return boot0_twi_read((void *)&twi_data); -} - -__s32 BOOT_TWI_Write(__u32 arg1, __u8 *arg2, __u8 *arg3) -{ - _twi_arg_t twi_data; - - twi_data.slave_addr = arg1; - twi_data.slave_addr_flag = 0; - twi_data.byte_addr = arg2; - twi_data.byte_addr_width = 1; - twi_data.byte_count = 1; - twi_data.data = arg3; - - return boot0_twi_write((void *)&twi_data); -} - - - diff --git a/boot0/drv/iic/sw_iic.h b/boot0/drv/iic/sw_iic.h deleted file mode 100644 index 66896f1..0000000 --- a/boot0/drv/iic/sw_iic.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -********************************************************************************************************************** -* ePDK -* the Easy Portable/Player Develop Kits -* eBIOS Sub-System -* -* (c) Copyright 2007-2009, Steven.ZGJ.China -* All Rights Reserved -* -* Moudle : iis bios module -* File : iisc_private.h -* -* By : Steven -* Version : v1.00 -* Date : 2008-8-19 18:38:16 -********************************************************************************************************************** -*/ -#ifndef _SW_IIC_H_ -#define _SW_IIC_H_ - -#include "axp_i.h" - -#define CFG_SW_IIC_MAX 4 -#define CFG_SW_IIC_CTL0 TWIC0_REGS_BASE /* iic0 */ -#define CFG_SW_IIC_CTL1 TWIC1_REGS_BASE /* iic1 */ -#define CFG_SW_IIC_CTL2 TWIC2_REGS_BASE /* iic2 */ - -#define SW_IIC_READ (1) -#define SW_IIC_WRITE (0) - -struct sw_iic -{ - volatile unsigned int addr; /* slave address */ - volatile unsigned int xaddr; /* extend address */ - volatile unsigned int data; /* data */ - volatile unsigned int ctl; /* control */ - volatile unsigned int status; /* status */ - volatile unsigned int clk; /* clock */ - volatile unsigned int srst; /* soft reset */ - volatile unsigned int eft; /* enhanced future */ -}; - -typedef struct _twi_arg -{ - __u32 slave_addr; //从设备地址 - __u32 slave_addr_flag; //从设置地址宽度 0:7bit; 1:10bit - __u8 *byte_addr; //需要读写的数据在从设备中的地址 - __u32 byte_addr_width; //从设置地址宽度 0或1:8 bit; 其它:数字代表字节数 - __u32 byte_count; //一次读写要完成的字节数 - __u32 if_restart; //是否需要发送restart命令 - __u8 *data; //数据的地址 -} -_twi_arg_t; - - - -typedef volatile struct sw_iic *sw_iic_t; - -enum _sw_iic_operation_status -{ - SW_IIC_OPERATION_NO_ERR = 0, - SW_IIC_OPERATION_START_NO_INT = -1 - -}; - -extern __s32 boot0_twi_init(void); -extern __s32 boot0_twi_exit(void); - - -extern __s32 BOOT_TWI_Read(__u32 arg1, __u8 *arg2, __u8 *arg3); -extern __s32 BOOT_TWI_Write(__u32 arg1, __u8 *arg2, __u8 *arg3); - -#endif /* _SW_IIC_H_ */ - -/*end of sw_iic.h*/ diff --git a/boot0/drv/init_dram/dram_init.c b/boot0/drv/init_dram/dram_init.c index 7366b84..7e816f4 100755 --- a/boot0/drv/init_dram/dram_init.c +++ b/boot0/drv/init_dram/dram_init.c @@ -14,6 +14,10 @@ * 2012-06-28 Daniel 1.6 Add Three Times DRAM Initial for CARD Boot (DRAMC_init_EX) * 2012-06-28 Daniel 1.7 Add DLL Parameter Scan Function * 2012-09-07 Daniel 1.8 Add more delay to all delay_us +* 2013-03-04 CPL 1.9 modify for A20 +* 2013-03-06 CPL 1.10 use dram_tpr4 bit1 as DQ & CA mode setup +* 2013-03-08 CPL 1.11 fix the problem [EFR DRAM can't not exit from super selfrefresh] +* 2013-03-15 CPL 1.12 modify mbus source to PLL6*2 /4 = 300MHz ********************************************************************************************************* */ #include "boot0_i.h" @@ -65,6 +69,8 @@ void mctl_set_drive(void) reg_val |= (0x6<<12); reg_val |= 0xFFC; reg_val &= ~0x3; + reg_val &= ~(0x3<<28); +// reg_val |= 0x7<<20; mctl_write_w(SDR_CR, reg_val); } @@ -178,10 +184,10 @@ void mctl_disable_dll(void) void mctl_configure_hostport(void) { -__u32 i; + __u32 i; __u32 hpcr_value[32] = { 0x00000301,0x00000301,0x00000301,0x00000301, - 0x00000301,0x00000301,0x0, 0x0, + 0x00000301,0x00000301,0x00000301,0x00000301, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x00001031,0x00001031,0x00000735,0x00001035, @@ -190,10 +196,18 @@ __u32 i; 0x00001031,0x00000301,0x00000301,0x00000731, }; - for(i=0; i<32; i++) + for(i=0; i<8; i++) { mctl_write_w(SDR_HPCR + (i<<2), hpcr_value[i]); } + + for(i=16; i<28; i++) + { + mctl_write_w(SDR_HPCR + (i<<2), hpcr_value[i]); + } + + mctl_write_w(SDR_HPCR + (29<<2), hpcr_value[i]); + mctl_write_w(SDR_HPCR + (31<<2), hpcr_value[i]); } void mctl_setup_dram_clock(__u32 clk) @@ -220,7 +234,7 @@ void mctl_setup_dram_clock(__u32 clk) mctl_write_w(DRAM_CCM_SDRAM_PLL_REG, reg_val); //setup MBUS clock - reg_val = (0x1U<<31)|(0x2<<24)|(0x1); + reg_val = (0x1U<<31) | (0x1<<24) | (0x1<<0) | (0x1<<16); mctl_write_w(DRAM_CCM_MUS_CLK_REG, reg_val); //open DRAMC AHB & DLL register clock @@ -242,12 +256,9 @@ void mctl_setup_dram_clock(__u32 clk) __s32 DRAMC_init(__dram_para_t *para) { __u32 reg_val; - __u8 reg_addr_1st = 0x0a; - __u8 reg_addr_2nd = 0x0b; - __u8 reg_addr_3rd = 0x0c; __u8 reg_value; - __s32 ret_val; + __s32 ret_val; //check input dram parameter structure if(!para) @@ -297,23 +308,33 @@ __s32 DRAMC_init(__dram_para_t *para) //SDR_ZQCR1 set bit24 to 1 reg_val = mctl_read_w(SDR_ZQCR1); - reg_val |= 0x1<<24; + reg_val |= (0x1<<24) | (0x1<<1); + if(para->dram_tpr4 & 0x2) + { + reg_val &= ~((0x1<<24) | (0x1<<1)); + } mctl_write_w(SDR_ZQCR1, reg_val); + //dram clock on + DRAMC_clock_output_en(1); + //set odt impendance divide ratio reg_val=((para->dram_zq)>>8)&0xfffff; reg_val |= ((para->dram_zq)&0xff)<<20; reg_val |= (para->dram_zq)&0xf0000000; + reg_val |= (0x1u<<31); mctl_write_w(SDR_ZQCR0, reg_val); + while( !((mctl_read_w(SDR_ZQSR)&(0x1<<31))) ); + //Set CKE Delay to about 1ms reg_val = mctl_read_w(SDR_IDCR); reg_val |= 0x1ffff; mctl_write_w(SDR_IDCR, reg_val); - //dram clock on - DRAMC_clock_output_en(1); - //reset external DRAM when CKE is Low +// //dram clock on +// DRAMC_clock_output_en(1); + //reset external DRAM when CKE is Low reg_val = mctl_read_w(SDR_DPCR); if((reg_val & 0x1) != 1) { @@ -327,8 +348,7 @@ __s32 DRAMC_init(__dram_para_t *para) reg_val |= (0x1<<12); mctl_write_w(SDR_CR, reg_val); } - - + mctl_delay(0x10); while(mctl_read_w(SDR_CCR) & (0x1U<<31)) {}; @@ -370,6 +390,11 @@ __s32 DRAMC_init(__dram_para_t *para) reg_val = mctl_read_w(SDR_CCR); reg_val |= 0x1U<<14; reg_val &= ~(0x1U<<17); + //2T & 1T mode + if(para->dram_tpr4 & 0x1) + { + reg_val |= 0x1<<5; + } mctl_write_w(SDR_CCR, reg_val); //initial external DRAM @@ -378,6 +403,8 @@ __s32 DRAMC_init(__dram_para_t *para) mctl_write_w(SDR_CCR, reg_val); while(mctl_read_w(SDR_CCR) & (0x1U<<31)) {}; + +// while(1); //setup zq calibration manual reg_val = mctl_read_w(SDR_DPCR); @@ -386,32 +413,44 @@ __s32 DRAMC_init(__dram_para_t *para) super_standby_flag = 1; - #ifdef CONFIG_HOLD_SUPERSTANDBY_DATA_BY_PMU - //restore calibration value - reg_val = 0; - if(!BOOT_TWI_Read(AXP20_ADDR, ®_addr_3rd, ®_value)){ - reg_val |= (reg_value&0x0f); - } - if(!BOOT_TWI_Read(AXP20_ADDR, ®_addr_2nd, ®_value)){ - reg_val <<= 8; - reg_val |= reg_value; - } - if(!BOOT_TWI_Read(AXP20_ADDR, ®_addr_1st, ®_value)){ - reg_val <<= 8; - reg_val |= reg_value; - reg_val |= 0x17b00000; - } - - #else - reg_val = mctl_read_w(SDR_GP_REG0); - reg_val &= 0x000fffff; - reg_val |= 0x17b00000; - #endif - + reg_val = mctl_read_w(SDR_GP_REG0); + reg_val &= 0x000fffff; + reg_val |= 0x17b00000; mctl_write_w(SDR_ZQCR0, reg_val); + + //03-08 + reg_val = mctl_read_w(SDR_DCR); + reg_val &= ~(0x1fU<<27); + reg_val |= 0x12U<<27; + mctl_write_w(SDR_DCR, reg_val); + while( mctl_read_w(SDR_DCR)& (0x1U<<31) ); + + mctl_delay(0x100); //dram pad hold off mctl_write_w(SDR_DPCR, 0x16510000); + + while(mctl_read_w(SDR_DPCR) & 0x1){} + + //exit self-refresh state + reg_val = mctl_read_w(SDR_DCR); + reg_val &= ~(0x1fU<<27); + reg_val |= 0x17U<<27; + mctl_write_w(SDR_DCR, reg_val); + + //check whether command has been executed + while( mctl_read_w(SDR_DCR)& (0x1U<<31) ); + mctl_delay(0x100);; + + //issue a refresh command + reg_val = mctl_read_w(SDR_DCR); + reg_val &= ~(0x1fU<<27); + reg_val |= 0x13U<<27; + mctl_write_w(SDR_DCR, reg_val); + + while( mctl_read_w(SDR_DCR)& (0x1U<<31) ); + + mctl_delay(0x100); } //scan read pipe value @@ -801,7 +840,7 @@ __s32 DRAMC_to_card_init(__dram_para_t *para) { __u32 i, m; __u32 dram_den; - __u32 err_flag; + __u32 err_flag = 0; __u32 start_adr, end_adr; __u32 bonding_id; __u32 reg_val; @@ -843,16 +882,18 @@ __s32 DRAMC_to_card_init(__dram_para_t *para) } } //try 2048/4096 chip density - para->dram_chip_density = 4096; - dram_den = para->dram_chip_density<<17; - if(para->dram_rank_num == 2) - dram_den<<=1; - if(para->dram_bus_width == 32) - dram_den<<=1; + para->dram_chip_density = 8192; +// dram_den = para->dram_chip_density<<17; +// if(para->dram_rank_num == 2) +// dram_den<<=1; +// if(para->dram_bus_width == 32) +// dram_den<<=1; if(!DRAMC_init_EX(para)) { return 0; } + +#if 0 //write preset value at special address start_adr = 0x40000000; end_adr = 0x40000000 + dram_den; @@ -890,6 +931,53 @@ __s32 DRAMC_to_card_init(__dram_para_t *para) } para->dram_size = dram_den>>21; +#else + for(m =0x50000000; m<0xC0000000; m+=0x10000000) + { + for(i=0; i<32; i++) + { + if(mctl_read_w(m + i*4) != mctl_read_w(0x40000000 + i*4)) + break; + } + if(i == 32) + { + err_flag = 1; + para->dram_size = (m - 0x40000000)>>20; + para->dram_chip_density = (m - 0x40000000)>>17; + if(para->dram_bus_width == 32) + para->dram_chip_density>>=1; + break; + + } + } + + if(m == 0xC0000000) + { + para->dram_size = 2048; + para->dram_chip_density = 8192; + + } + + reg_val = mctl_read_w(SDR_DCR); + reg_val &= ~(0x7<<3); + if(para->dram_chip_density == 256) + reg_val |= 0x0<<3; + else if(para->dram_chip_density == 512) + reg_val |= 0x1<<3; + else if(para->dram_chip_density == 1024) + reg_val |= 0x2<<3; + else if(para->dram_chip_density == 2048) + reg_val |= 0x3<<3; + else if(para->dram_chip_density == 4096) + reg_val |= 0x4<<3; + else if(para->dram_chip_density == 8192) + reg_val |= 0x5<<3; + else + reg_val |= 0x0<<3; + mctl_write_w(SDR_DCR, reg_val); + + mctl_configure_hostport(); +#endif return para->dram_size; } #endif @@ -901,7 +989,7 @@ __s32 init_DRAM(int type) boot_dram_para_t boot0_para; get_boot0_dram_para( &boot0_para ); - print_boot0_dram_para(&boot0_para); + // print_boot0_dram_para(&boot0_para); if(boot0_para.dram_clk > 2000) { boot0_para.dram_clk /= 1000000; @@ -930,7 +1018,7 @@ __s32 init_DRAM(int type) i++; } - +// print_boot0_dram_para(&boot0_para); return ret_val; } diff --git a/boot0/drv/init_dram/dram_para.h b/boot0/drv/init_dram/dram_para.h old mode 100644 new mode 100755 diff --git a/boot0/lib/service/service.c b/boot0/lib/service/service.c index eb82a75..3425d6a 100755 --- a/boot0/lib/service/service.c +++ b/boot0/lib/service/service.c @@ -53,20 +53,27 @@ void get_boot0_dram_para( boot_dram_para_t *boot0_dram_para_p ) memcpy( boot0_dram_para_p, &(BT0_head.prvt_head.dram_para), sizeof(boot_dram_para_t) ); } void print_boot0_dram_para( boot_dram_para_t *boot0_dram_para_p ) -{ +{ + msg("boot0_para->dram_clk = %d\n",boot0_dram_para_p->dram_clk); msg("boot0_para->dram_type = %d\n",boot0_dram_para_p->dram_type); - msg("boot0_para->dram_io_width = %d\n",boot0_dram_para_p->dram_io_width); - msg("boot0_para->dram_chip_density = %d\n",boot0_dram_para_p->dram_chip_density); + msg("boot0_para->dram_rank_num = %d\n",boot0_dram_para_p->dram_rank_num); + msg("boot0_para->dram_chip_density = %d\n",boot0_dram_para_p->dram_chip_density); + msg("boot0_para->dram_io_width = %d\n",boot0_dram_para_p->dram_io_width); + msg("boot0_para->dram_bus_width = %d\n",boot0_dram_para_p->dram_bus_width); + msg("boot0_para->dram_cas = %d\n",boot0_dram_para_p->dram_cas); - msg("boot0_para->dram_bus_width = %d\n",boot0_dram_para_p->dram_bus_width); - msg("boot0_para->dram_rank_num = %d\n",boot0_dram_para_p->dram_rank_num); - msg("boot0_para->dram_tpr0 = %d\n",boot0_dram_para_p->dram_tpr0); - msg("boot0_para.dram_tpr1 = %d\n",boot0_dram_para_p->dram_tpr1); - msg("boot0_para->dram_tpr2 = %d\n",boot0_dram_para_p->dram_tpr2); - msg("boot0_para->dram_emr1 = %d\n",boot0_dram_para_p->dram_emr1); - msg("boot0_para->dram_emr2 = %d\n",boot0_dram_para_p->dram_emr2); - msg("boot0_para->dram_emr2 = %d\n",boot0_dram_para_p->dram_emr2); - msg("boot0_para->dram_clk = %d\n",boot0_dram_para_p->dram_clk); + msg("boot0_para->dram_zq = %x\n",boot0_dram_para_p->dram_zq); + msg("boot0_para->dram_odt_en = %d\n",boot0_dram_para_p->dram_odt_en); + msg("boot0_para->dram_size = %d\n",boot0_dram_para_p->dram_size); + + + msg("boot0_para->dram_tpr0 = %x\n",boot0_dram_para_p->dram_tpr0); + msg("boot0_para.dram_tpr1 = %x\n",boot0_dram_para_p->dram_tpr1); + msg("boot0_para->dram_tpr2 = %x\n",boot0_dram_para_p->dram_tpr2); + msg("boot0_para->dram_emr1 = %x\n",boot0_dram_para_p->dram_emr1); + msg("boot0_para->dram_emr2 = %x\n",boot0_dram_para_p->dram_emr2); + msg("boot0_para->dram_emr2 = %x\n",boot0_dram_para_p->dram_emr2); + } void set_boot0_dram_para( boot_dram_para_t *boot0_dram_para_p ) diff --git a/boot0/load_Boot1_from_nand/load_Boot1_from_nand.c b/boot0/load_Boot1_from_nand/load_Boot1_from_nand.c index 0d6d1b4..4b1745e 100755 --- a/boot0/load_Boot1_from_nand/load_Boot1_from_nand.c +++ b/boot0/load_Boot1_from_nand/load_Boot1_from_nand.c @@ -84,8 +84,8 @@ __s32 load_Boot1_from_nand( void ) bfh = (boot_file_head_t *) BOOT1_BASE; length = bfh->length; - msg("The size of Boot1 is %x.\n", length ); - msg("The align size of Boot1 is %x.\n", bfh->align_size); + // msg("The size of Boot1 is %x.\n", length ); + // msg("The align size of Boot1 is %x.\n", bfh->align_size); if( ( length & ( NF_SECTOR_SIZE - 1 ) ) != 0 ) // length必须是NF_SECTOR_SIZE对齐的 { msg("the boot1 is not aligned by %x\n", NF_SECTOR_SIZE); diff --git a/boot0/load_boot1_from_sdmmc/bsp_mmc_for_boot/mmc_bsp.c b/boot0/load_boot1_from_sdmmc/bsp_mmc_for_boot/mmc_bsp.c index edb8ce2..4c494da 100755 --- a/boot0/load_boot1_from_sdmmc/bsp_mmc_for_boot/mmc_bsp.c +++ b/boot0/load_boot1_from_sdmmc/bsp_mmc_for_boot/mmc_bsp.c @@ -170,7 +170,7 @@ static int mmc_clk_io_onoff(int sdc_no, int onoff) if (onoff) { writel(0x222222, gpiof_base + 0x0); writel(0x555, gpiof_base + 0x1c); - writel(0xaaa, gpiof_base + 0x14); + writel(0xfff, gpiof_base + 0x14); } else { writel(0x404044, gpiof_base + 0x0); writel(0, gpiof_base + 0x1c); @@ -184,7 +184,7 @@ static int mmc_clk_io_onoff(int sdc_no, int onoff) writel(0x33000000, gpioc_base + 0x0); writel(0x3333, gpioc_base + 0x4); writel(0x555 << 12, gpioc_base + 0x1c); - writel(0xaaa << 12, gpioc_base + 0x14); + writel(0xfff << 12, gpioc_base + 0x14); } else { writel(0, gpioc_base + 0x0); writel(0, gpioc_base + 0x4); diff --git a/boot0/load_boot1_from_sdmmc/load_boot1_from_sdmmc.c b/boot0/load_boot1_from_sdmmc/load_boot1_from_sdmmc.c index 0da8ded..2d2cfb1 100755 --- a/boot0/load_boot1_from_sdmmc/load_boot1_from_sdmmc.c +++ b/boot0/load_boot1_from_sdmmc/load_boot1_from_sdmmc.c @@ -62,8 +62,8 @@ __s32 load_boot1_from_sdmmc( char *buf) // continue; // } - msg("sdcard %d line count =%d\n", card_no, sdcard_info->line_count[index] ); - msg("sdcard %d line sel =%d\n", card_no, sdcard_info->line_sel[index] ); + // msg("sdcard %d line count =%d\n", card_no, sdcard_info->line_count[index] ); + //msg("sdcard %d line sel =%d\n", card_no, sdcard_info->line_sel[index] ); if(!sdcard_info->line_sel[index]) { sdcard_info->line_sel[index] = 4; diff --git a/boot0/make.cfg b/boot0/make.cfg index e3aef9c..03a8eb7 100755 --- a/boot0/make.cfg +++ b/boot0/make.cfg @@ -43,6 +43,7 @@ STORAGE_TYPE = -I$(SDKROOT)/config/storage_media_cfg/nand SRCDIRS = $(shell find $(ROOT)/load_Boot1_from_nand -maxdepth 3 -type d) TARGET = $(WORKSPACEPATH)/eGon/boot0_nand.bin TARGET1 = $(LICHEEPATH)/eGon/boot0_nand.bin +TARGET2 = $(SDKROOT)/pack/chips/sun7i/eGon/boot0_nand.bin LOCALTARGET = __boot0_nand.axf else @@ -53,6 +54,7 @@ STORAGE_TYPE = -I$(SDKROOT)/config/storage_media_cfg/sdcard SRCDIRS = $(shell find $(ROOT)/load_Boot1_from_sdmmc -maxdepth 3 -type d) TARGET = $(WORKSPACEPATH)/eGon/boot0_sdcard.bin TARGET1 = $(LICHEEPATH)/eGon/boot0_sdcard.bin +TARGET2 = $(SDKROOT)/pack/chips/sun7i/eGon/boot0_sdcard.bin LOCALTARGET = __boot0_sdmmc.axf else diff --git a/boot0/make_nand b/boot0/make_nand index 6a144e6..e756e18 100755 --- a/boot0/make_nand +++ b/boot0/make_nand @@ -36,6 +36,7 @@ nand:$(LOCALTARGET) -$(WORKTOOLS)/gen_check_code.exe $(TMPTARGET) boot0.bin cp boot0.bin $(TARGET) cp boot0.bin $(TARGET1) + cp boot0.bin $(TARGET2) -rm $(OBJS) $(TMPTARGET) boot0.bin @echo ---------------------------- @echo target make finish diff --git a/boot0/make_sdmmc b/boot0/make_sdmmc index 68745ee..c9a72a8 100755 --- a/boot0/make_sdmmc +++ b/boot0/make_sdmmc @@ -36,6 +36,7 @@ sdmmc:$(LOCALTARGET) -$(WORKTOOLS)/gen_check_code.exe $(TMPTARGET) boot0.bin cp boot0.bin $(TARGET) cp boot0.bin $(TARGET1) + cp boot0.bin $(TARGET2) -rm $(OBJS) $(TMPTARGET) boot0.bin @echo ---------------------------- @echo target make finish diff --git a/boot1/apps/BootQC/BootMain.c b/boot1/apps/BootQC/BootMain.c index 93a5aab..758365c 100755 --- a/boot1/apps/BootQC/BootMain.c +++ b/boot1/apps/BootQC/BootMain.c @@ -21,6 +21,7 @@ #include "include.h" #include "board.h" #include "common_res.h" +#include boot_hardware_res board_res; /* @@ -42,6 +43,21 @@ boot_hardware_res board_res; ******************************************************************************* */ +void mathlib_test(void) +{ + double x,y; + __inf("begain mathlib_test!\n"); + __s32 print_x,print_y; + for(x=0;x<6.28;x+=0.1) + { + y=sin(x); + print_x=x*1000; + print_y=y*1000; + __inf("sin(%d)=%d\n",print_x,print_y); + } + __inf("mathlib test done!\n"); +} + int BootMain(int argc, char **argv) { DMSG_INFO("\n\n\n[MSG]: BootMain start\n"); @@ -71,8 +87,8 @@ int BootMain(int argc, char **argv) } else if(ch == '1') { -// usb_start(); -// usb_run(); + usb_start(0); + usb_run(); break; } else @@ -83,7 +99,7 @@ int BootMain(int argc, char **argv) //关闭DCACHE wlibc_DCacheDisable(); BoardInit_Display(0, 0); //初始化显示 - + mathlib_test(); // if(Amain() == 1) // __dinf("test ok\n"); // else diff --git a/boot1/apps/BootQC/Common/libm/acos.c b/boot1/apps/BootQC/Common/libm/acos.c new file mode 100755 index 0000000..0ff939f --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/acos.c @@ -0,0 +1,75 @@ +/* + * libm/acos.c + */ +#include + +static const double + one = 1.00000000000000000000e+00, + pi = 3.14159265358979311600e+00, + pio2_hi = 1.57079632679489655800e+00, + pio2_lo = 6.12323399573676603587e-17, + pS0 = 1.66666666666666657415e-01, + pS1 = -3.25565818622400915405e-01, + pS2 = 2.01212532134862925881e-01, + pS3 = -4.00555345006794114027e-02, + pS4 = 7.91534994289814532176e-04, + pS5 = 3.47933107596021167570e-05, + qS1 = -2.40339491173441421878e+00, + qS2 = 2.02094576023350569471e+00, + qS3 = -6.88283971605453293030e-01, + qS4 = 7.70381505559019352791e-02; + +double acos(double x) +{ + double z, p, q, r, w, s, c, df; + s32_t hx, ix; + + GET_HIGH_WORD(hx,x); + ix = hx & 0x7fffffff; + if (ix >= 0x3ff00000) + { + u32_t lx; + GET_LOW_WORD(lx,x); + if (((ix - 0x3ff00000) | lx) == 0) + { + if (hx > 0) + return 0.0; + else + return pi + 2.0 * pio2_lo; + } + return (x - x) / (x - x); + } + if (ix < 0x3fe00000) + { + if (ix <= 0x3c600000) + return pio2_hi + pio2_lo; + z = x * x; + p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5))))); + q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); + r = p / q; + return pio2_hi - (x - (pio2_lo - x * r)); + } + else if (hx < 0) + { + z = (one + x) * 0.5; + p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5))))); + q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); + s = sqrt(z); + r = p / q; + w = r * s - pio2_lo; + return pi - 2.0 * (s + w); + } + else + { + z = (one - x) * 0.5; + s = sqrt(z); + df = s; + SET_LOW_WORD(df,0); + c = (z - df * df) / (s + df); + p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5))))); + q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); + r = p / q; + w = r * s + c; + return 2.0 * (df + w); + } +} diff --git a/boot1/apps/BootQC/Common/libm/acosf.c b/boot1/apps/BootQC/Common/libm/acosf.c new file mode 100755 index 0000000..86ffca0 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/acosf.c @@ -0,0 +1,76 @@ +/* + * libm/acosf.c + */ + +#include + +static const float + one = 1.0000000000e+00, + pi = 3.1415925026e+00, + pio2_hi = 1.5707962513e+00, + pio2_lo = 7.5497894159e-08, + pS0 = 1.6666667163e-01, + pS1 = -3.2556581497e-01, + pS2 = 2.0121252537e-01, + pS3 = -4.0055535734e-02, + pS4 = 7.9153501429e-04, + pS5 = 3.4793309169e-05, + qS1 = -2.4033949375e+00, + qS2 = 2.0209457874e+00, + qS3 = -6.8828397989e-01, + qS4 = 7.7038154006e-02; + +float acosf(float x) +{ + float z, p, q, r, w, s, c, df; + s32_t hx, ix; + + GET_FLOAT_WORD(hx,x); + ix = hx & 0x7fffffff; + if (ix == 0x3f800000) + { + if (hx > 0) + return 0.0; + else + return pi + (float) 2.0 * pio2_lo; + } + else if (ix > 0x3f800000) + { + return (x - x) / (x - x); + } + if (ix < 0x3f000000) + { + if (ix <= 0x23000000) + return pio2_hi + pio2_lo; + z = x * x; + p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5))))); + q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); + r = p / q; + return pio2_hi - (x - (pio2_lo - x * r)); + } + else if (hx < 0) + { + z = (one + x) * (float) 0.5; + p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5))))); + q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); + s = sqrtf(z); + r = p / q; + w = r * s - pio2_lo; + return pi - (float) 2.0 * (s + w); + } + else + { + s32_t idf; + z = (one - x) * (float) 0.5; + s = sqrtf(z); + df = s; + GET_FLOAT_WORD(idf,df); + SET_FLOAT_WORD(df,idf&0xfffff000); + c = (z - df * df) / (s + df); + p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5))))); + q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); + r = p / q; + w = r * s + c; + return (float) 2.0 * (df + w); + } +} diff --git a/boot1/apps/BootQC/Common/libm/asin.c b/boot1/apps/BootQC/Common/libm/asin.c new file mode 100755 index 0000000..a49561a --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/asin.c @@ -0,0 +1,78 @@ +/* + * libm/asin.c + */ + +#include + +static const double + one = 1.00000000000000000000e+00, + huge = 1.000e+300, + pio2_hi = 1.57079632679489655800e+00, + pio2_lo = 6.12323399573676603587e-17, + pio4_hi = 7.85398163397448278999e-01, + pS0 = 1.66666666666666657415e-01, + pS1 = -3.25565818622400915405e-01, + pS2 = 2.01212532134862925881e-01, + pS3 = -4.00555345006794114027e-02, + pS4 = 7.91534994289814532176e-04, + pS5 = 3.47933107596021167570e-05, + qS1 = -2.40339491173441421878e+00, + qS2 = 2.02094576023350569471e+00, + qS3 = -6.88283971605453293030e-01, + qS4 = 7.70381505559019352791e-02; + +double asin(double x) +{ + double t = 0.0, w, p, q, c, r, s; + s32_t hx, ix; + + GET_HIGH_WORD(hx,x); + ix = hx & 0x7fffffff; + if (ix >= 0x3ff00000) + { + u32_t lx; + GET_LOW_WORD(lx,x); + if (((ix - 0x3ff00000) | lx) == 0) + return x * pio2_hi + x * pio2_lo; + return (x - x) / (x - x); + } + else if (ix < 0x3fe00000) + { + if (ix < 0x3e400000) + { + if (huge + x > one) + return x; + } + else + t = x * x; + p = t * (pS0 + t * (pS1 + t * (pS2 + t * (pS3 + t * (pS4 + t * pS5))))); + q = one + t * (qS1 + t * (qS2 + t * (qS3 + t * qS4))); + w = p / q; + return x + x * w; + } + + w = one - fabs(x); + t = w * 0.5; + p = t * (pS0 + t * (pS1 + t * (pS2 + t * (pS3 + t * (pS4 + t * pS5))))); + q = one + t * (qS1 + t * (qS2 + t * (qS3 + t * qS4))); + s = sqrt(t); + if (ix >= 0x3FEF3333) + { + w = p / q; + t = pio2_hi - (2.0 * (s + s * w) - pio2_lo); + } + else + { + w = s; + SET_LOW_WORD(w,0); + c = (t - w * w) / (s + w); + r = p / q; + p = 2.0 * s * r - (pio2_lo - 2.0 * c); + q = pio4_hi - 2.0 * w; + t = pio4_hi - (p - q); + } + if (hx > 0) + return t; + else + return -t; +} diff --git a/boot1/apps/BootQC/Common/libm/asinf.c b/boot1/apps/BootQC/Common/libm/asinf.c new file mode 100755 index 0000000..4ec37ed --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/asinf.c @@ -0,0 +1,80 @@ +/* + * libm/asinf.c + */ + +#include + +static const float + one = 1.0000000000e+00, + huge = 1.000e+30, + pio2_hi = 1.5707962513e+00, + pio2_lo = 7.5497894159e-08, + pio4_hi = 7.8539812565e-01, + pS0 = 1.6666667163e-01, + pS1 = -3.2556581497e-01, + pS2 = 2.0121252537e-01, + pS3 = -4.0055535734e-02, + pS4 = 7.9153501429e-04, + pS5 = 3.4793309169e-05, + qS1 = -2.4033949375e+00, + qS2 = 2.0209457874e+00, + qS3 = -6.8828397989e-01, + qS4 = 7.7038154006e-02; + +float asinf(float x) +{ + float t = 0.0, w, p, q, c, r, s; + s32_t hx, ix; + + GET_FLOAT_WORD(hx,x); + ix = hx & 0x7fffffff; + if (ix == 0x3f800000) + { + return x * pio2_hi + x * pio2_lo; + } + else if (ix > 0x3f800000) + { + return (x - x) / (x - x); + } + else if (ix < 0x3f000000) + { + if (ix < 0x32000000) + { + if (huge + x > one) + return x; + } + else + t = x * x; + p = t * (pS0 + t * (pS1 + t * (pS2 + t * (pS3 + t * (pS4 + t * pS5))))); + q = one + t * (qS1 + t * (qS2 + t * (qS3 + t * qS4))); + w = p / q; + return x + x * w; + } + + w = one - fabsf(x); + t = w * (float) 0.5; + p = t * (pS0 + t * (pS1 + t * (pS2 + t * (pS3 + t * (pS4 + t * pS5))))); + q = one + t * (qS1 + t * (qS2 + t * (qS3 + t * qS4))); + s = sqrtf(t); + if (ix >= 0x3F79999A) + { + w = p / q; + t = pio2_hi - ((float) 2.0 * (s + s * w) - pio2_lo); + } + else + { + s32_t iw; + w = s; + GET_FLOAT_WORD(iw,w); + SET_FLOAT_WORD(w,iw&0xfffff000); + c = (t - w * w) / (s + w); + r = p / q; + p = (float) 2.0 * s * r - (pio2_lo - (float) 2.0 * c); + q = pio4_hi - (float) 2.0 * w; + t = pio4_hi - (p - q); + } + if (hx > 0) + return t; + else + return -t; +} diff --git a/boot1/apps/BootQC/Common/libm/atan.c b/boot1/apps/BootQC/Common/libm/atan.c new file mode 100755 index 0000000..83504bd --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/atan.c @@ -0,0 +1,108 @@ +/* + * libm/atan.c + */ + +#include + +static const double atanhi[] = { + 4.63647609000806093515e-01, + 7.85398163397448278999e-01, + 9.82793723247329054082e-01, + 1.57079632679489655800e+00, +}; + +static const double atanlo[] = { + 2.26987774529616870924e-17, + 3.06161699786838301793e-17, + 1.39033110312309984516e-17, + 6.12323399573676603587e-17, +}; + +static const double aT[] = { + 3.33333333333329318027e-01, + -1.99999999998764832476e-01, + 1.42857142725034663711e-01, + -1.11111104054623557880e-01, + 9.09088713343650656196e-02, + -7.69187620504482999495e-02, + 6.66107313738753120669e-02, + -5.83357013379057348645e-02, + 4.97687799461593236017e-02, + -3.65315727442169155270e-02, + 1.62858201153657823623e-02, +}; + +static const double one = 1.0, huge = 1.0e300; + +double atan(double x) +{ + double w, s1, s2, z; + s32_t ix, hx, id; + + GET_HIGH_WORD(hx,x); + ix = hx & 0x7fffffff; + if (ix >= 0x44100000) + { + u32_t low; + GET_LOW_WORD(low,x); + if (ix > 0x7ff00000 || (ix == 0x7ff00000 && (low != 0))) + return x + x; + if (hx > 0) + return atanhi[3] + atanlo[3]; + else + return -atanhi[3] - atanlo[3]; + } + if (ix < 0x3fdc0000) + { + if (ix < 0x3e200000) + { + if (huge + x > one) + return x; + } + id = -1; + } + else + { + x = fabs(x); + if (ix < 0x3ff30000) + { + if (ix < 0x3fe60000) + { + id = 0; + x = (2.0 * x - one) / (2.0 + x); + } + else + { + id = 1; + x = (x - one) / (x + one); + } + } + else + { + if (ix < 0x40038000) + { + id = 2; + x = (x - 1.5) / (one + 1.5 * x); + } + else + { + id = 3; + x = -1.0 / x; + } + } + } + + z = x * x; + w = z * z; + + s1 = z * (aT[0] + w * (aT[2] + w * (aT[4] + w * (aT[6] + w * (aT[8] + w + * aT[10]))))); + s2 = w * (aT[1] + w * (aT[3] + w * (aT[5] + w * (aT[7] + w * aT[9])))); + if (id < 0) + return x - x * (s1 + s2); + else + { + z = atanhi[id] - ((x * (s1 + s2) - atanlo[id]) - x); + return (hx < 0) ? -z : z; + } +} diff --git a/boot1/apps/BootQC/Common/libm/atan2.c b/boot1/apps/BootQC/Common/libm/atan2.c new file mode 100755 index 0000000..276f92e --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/atan2.c @@ -0,0 +1,106 @@ +/* + * libm/atan2.c + */ +#include + +static const double + tiny = 1.0e-300, + zero = 0.0, + pi_o_4 = 7.8539816339744827900E-01, + pi_o_2 = 1.5707963267948965580E+00, + pi = 3.1415926535897931160E+00, + pi_lo = 1.2246467991473531772E-16; + +double atan2(double y, double x) +{ + double z; + s32_t k, m, hx, hy, ix, iy; + u32_t lx, ly; + + EXTRACT_WORDS(hx,lx,x); + ix = hx & 0x7fffffff; + EXTRACT_WORDS(hy,ly,y); + iy = hy & 0x7fffffff; + if (((ix | ((lx | -lx) >> 31)) > 0x7ff00000) || + ((iy | ((ly | -ly) >> 31)) > 0x7ff00000)) + return x + y; + if (((hx - 0x3ff00000) | lx) == 0) + return atan(y); + m = ((hy >> 31) & 1) | ((hx >> 30) & 2); + + if ((iy | ly) == 0) + { + switch (m) + { + case 0: + case 1: + return y; + case 2: + return pi + tiny; + case 3: + return -pi - tiny; + } + } + + if ((ix | lx) == 0) + return (hy < 0) ? -pi_o_2 - tiny : pi_o_2 + tiny; + + if (ix == 0x7ff00000) + { + if (iy == 0x7ff00000) + { + switch (m) + { + case 0: + return pi_o_4 + tiny; + case 1: + return -pi_o_4 - tiny; + case 2: + return 3.0 * pi_o_4 + tiny; + case 3: + return -3.0 * pi_o_4 - tiny; + } + } + else + { + switch (m) + { + case 0: + return zero; + case 1: + return -zero; + case 2: + return pi + tiny; + case 3: + return -pi - tiny; + } + } + } + + if (iy == 0x7ff00000) + return (hy < 0) ? -pi_o_2 - tiny : pi_o_2 + tiny; + + k = (iy - ix) >> 20; + if (k > 60) + z = pi_o_2 + 0.5 * pi_lo; + else if (hx < 0 && k < -60) + z = 0.0; + else + z = atan(fabs(y / x)); + switch (m) + { + case 0: + return z; + case 1: + { + u32_t zh; + GET_HIGH_WORD(zh,z); + SET_HIGH_WORD(z,zh ^ 0x80000000); + } + return z; + case 2: + return pi - (z - pi_lo); + default: + return (z - pi_lo) - pi; + } +} diff --git a/boot1/apps/BootQC/Common/libm/atan2f.c b/boot1/apps/BootQC/Common/libm/atan2f.c new file mode 100755 index 0000000..610c463 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/atan2f.c @@ -0,0 +1,105 @@ +/* + * libm/atan2f.c + */ + +#include + +static const float + tiny = 1.0e-30, + zero = 0.0, + pi_o_4 = 7.8539818525e-01, + pi_o_2 = 1.5707963705e+00, + pi = 3.1415927410e+00, + pi_lo = -8.7422776573e-08; + +float atan2f(float y, float x) +{ + float z; + s32_t k, m, hx, hy, ix, iy; + + GET_FLOAT_WORD(hx,x); + ix = hx & 0x7fffffff; + GET_FLOAT_WORD(hy,y); + iy = hy & 0x7fffffff; + if ((ix > 0x7f800000) || (iy > 0x7f800000)) + return x + y; + if (hx == 0x3f800000) + return atanf(y); + m = ((hy >> 31) & 1) | ((hx >> 30) & 2); + + if (iy == 0) + { + switch (m) + { + case 0: + case 1: + return y; + case 2: + return pi + tiny; + case 3: + return -pi - tiny; + } + } + + if (ix == 0) + return (hy < 0) ? -pi_o_2 - tiny : pi_o_2 + tiny; + + if (ix == 0x7f800000) + { + if (iy == 0x7f800000) + { + switch (m) + { + case 0: + return pi_o_4 + tiny; + case 1: + return -pi_o_4 - tiny; + case 2: + return (float) 3.0 * pi_o_4 + tiny; + case 3: + return (float) -3.0 * pi_o_4 - tiny; + } + } + else + { + switch (m) + { + case 0: + return zero; + case 1: + return -zero; + case 2: + return pi + tiny; + case 3: + return -pi - tiny; + } + } + } + + if (iy == 0x7f800000) + return (hy < 0) ? -pi_o_2 - tiny : pi_o_2 + tiny; + + k = (iy - ix) >> 23; + if (k > 60) + z = pi_o_2 + (float) 0.5 * pi_lo; + else if (hx < 0 && k < -60) + z = 0.0; + else + z = atanf(fabsf(y / x)); + switch (m) + { + case 0: + return z; + case 1: + { + u32_t zh; + GET_FLOAT_WORD(zh,z); + SET_FLOAT_WORD(z,zh ^ 0x80000000); + } + return z; + case 2: + return pi - (z - pi_lo); + default: + return (z - pi_lo) - pi; + } +} diff --git a/boot1/apps/BootQC/Common/libm/atanf.c b/boot1/apps/BootQC/Common/libm/atanf.c new file mode 100755 index 0000000..4b88751 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/atanf.c @@ -0,0 +1,107 @@ +/* + * libm/atanf.c + */ + +#include + +static const float atanhi[] = { + 4.6364760399e-01, + 7.8539812565e-01, + 9.8279368877e-01, + 1.5707962513e+00, +}; + +static const float atanlo[] = { + 5.0121582440e-09, + 3.7748947079e-08, + 3.4473217170e-08, + 7.5497894159e-08, +}; + +static const float aT[] = { + 3.3333334327e-01, + -2.0000000298e-01, + 1.4285714924e-01, + -1.1111110449e-01, + 9.0908870101e-02, + -7.6918758452e-02, + 6.6610731184e-02, + -5.8335702866e-02, + 4.9768779427e-02, + -3.6531571299e-02, + 1.6285819933e-02, +}; + +static const float one = 1.0, huge = 1.0e30; + +float atanf(float x) +{ + float w, s1, s2, z; + s32_t ix, hx, id; + + GET_FLOAT_WORD(hx,x); + ix = hx & 0x7fffffff; + if (ix >= 0x50800000) + { + if (ix > 0x7f800000) + return x + x; + if (hx > 0) + return atanhi[3] + atanlo[3]; + else + return -atanhi[3] - atanlo[3]; + } + if (ix < 0x3ee00000) + { + if (ix < 0x31000000) + { + if (huge + x > one) + return x; + } + id = -1; + } + else + { + x = fabsf(x); + if (ix < 0x3f980000) + { + if (ix < 0x3f300000) + { + id = 0; + x = ((float) 2.0 * x - one) / ((float) 2.0 + x); + } + else + { + id = 1; + x = (x - one) / (x + one); + } + } + else + { + if (ix < 0x401c0000) + { + id = 2; + x = (x - (float) 1.5) / (one + (float) 1.5 * x); + } + else + { + id = 3; + x = -(float) 1.0 / x; + } + } + } + + z = x * x; + w = z * z; + + s1 = z * (aT[0] + w * (aT[2] + w * (aT[4] + w * (aT[6] + w * (aT[8] + w + * aT[10]))))); + s2 = w * (aT[1] + w * (aT[3] + w * (aT[5] + w * (aT[7] + w * aT[9])))); + if (id < 0) + return x - x * (s1 + s2); + else + { + z = atanhi[id] - ((x * (s1 + s2) - atanlo[id]) - x); + return (hx < 0) ? -z : z; + } +} + diff --git a/boot1/apps/BootQC/Common/libm/ceil.c b/boot1/apps/BootQC/Common/libm/ceil.c new file mode 100755 index 0000000..97cf104 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/ceil.c @@ -0,0 +1,81 @@ +/* + * libm/ceil.c + */ + +#include + +static const double huge = 1.0e300; + +double ceil(double x) +{ + s32_t i0, i1, j0; + u32_t i, j; + + EXTRACT_WORDS(i0,i1,x); + j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; + + if (j0 < 20) + { + if (j0 < 0) + { + if (huge + x > 0.0) + { + if (i0 < 0) + { + i0 = 0x80000000; + i1 = 0; + } + else if ((i0 | i1) != 0) + { + i0 = 0x3ff00000; + i1 = 0; + } + } + } + else + { + i = (0x000fffff) >> j0; + if (((i0 & i) | i1) == 0) + return x; + if (huge + x > 0.0) + { + if (i0 > 0) + i0 += (0x00100000) >> j0; + i0 &= (~i); + i1 = 0; + } + } + } + else if (j0 > 51) + { + if (j0 == 0x400) + return x + x; + else + return x; + } + else + { + i = ((u32_t)(0xffffffff)) >> (j0 - 20); + if ((i1 & i) == 0) + return x; + if (huge + x > 0.0) + { + if (i0 > 0) + { + if (j0 == 20) + i0 += 1; + else + { + j = i1 + (1 << (52 - j0)); + if (j < i1) + i0 += 1; + i1 = j; + } + } + i1 &= (~i); + } + } + + INSERT_WORDS(x,i0,i1); + return x; +} diff --git a/boot1/apps/BootQC/Common/libm/ceilf.c b/boot1/apps/BootQC/Common/libm/ceilf.c new file mode 100755 index 0000000..27f15af --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/ceilf.c @@ -0,0 +1,56 @@ +/* + * libm/ceilf.c + */ + +#include + +static const float huge = 1.0e30; + +float ceilf(float x) +{ + s32_t i0, j0; + u32_t i; + + GET_FLOAT_WORD(i0,x); + j0 = ((i0 >> 23) & 0xff) - 0x7f; + + if (j0 < 23) + { + if (j0 < 0) + { + if (huge + x > (float) 0.0) + { + if (i0 < 0) + { + i0 = 0x80000000; + } + else if (i0 != 0) + { + i0 = 0x3f800000; + } + } + } + else + { + i = (0x007fffff) >> j0; + if ((i0 & i) == 0) + return x; + if (huge + x > (float) 0.0) + { + if (i0 > 0) + i0 += (0x00800000) >> j0; + i0 &= (~i); + } + } + } + else + { + if (j0 == 0x80) + return x + x; + else + return x; + } + + SET_FLOAT_WORD(x,i0); + return x; +} diff --git a/boot1/apps/BootQC/Common/libm/copysign.c b/boot1/apps/BootQC/Common/libm/copysign.c new file mode 100755 index 0000000..aeeaa81 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/copysign.c @@ -0,0 +1,16 @@ +/* + * libm/copysign.c + */ + +#include + +double copysign(double x, double y) +{ + u32_t hx, hy; + + GET_HIGH_WORD(hx, x); + GET_HIGH_WORD(hy, y); + SET_HIGH_WORD(x, (hx & 0x7fffffff) | (hy & 0x80000000)); + + return x; +} diff --git a/boot1/apps/BootQC/Common/libm/copysignf.c b/boot1/apps/BootQC/Common/libm/copysignf.c new file mode 100755 index 0000000..369b0d3 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/copysignf.c @@ -0,0 +1,16 @@ +/* + * libm/copysignf.c + */ + +#include + +float copysignf(float x, float y) +{ + u32_t ix, iy; + + GET_FLOAT_WORD(ix, x); + GET_FLOAT_WORD(iy, y); + SET_FLOAT_WORD(x, (ix & 0x7fffffff) | (iy & 0x80000000)); + + return x; +} diff --git a/boot1/apps/BootQC/Common/libm/cos.c b/boot1/apps/BootQC/Common/libm/cos.c new file mode 100755 index 0000000..6c8e2ef --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/cos.c @@ -0,0 +1,39 @@ +/* + * libm/cos.c + */ + +#include + +double cos(double x) +{ + double y[2], z = 0.0; + s32_t n, ix; + + GET_HIGH_WORD(ix,x); + + ix &= 0x7fffffff; + if (ix <= 0x3fe921fb) + { + if (ix < 0x3e400000) + if (((int) x) == 0) + return 1.0; + return __kernel_cos(x, z); + } + else if (ix >= 0x7ff00000) + return x - x; + else + { + n = __ieee754_rem_pio2(x, y); + switch (n & 3) + { + case 0: + return __kernel_cos(y[0], y[1]); + case 1: + return -__kernel_sin(y[0], y[1], 1); + case 2: + return -__kernel_cos(y[0], y[1]); + default: + return __kernel_sin(y[0], y[1], 1); + } + } +} diff --git a/boot1/apps/BootQC/Common/libm/cosf.c b/boot1/apps/BootQC/Common/libm/cosf.c new file mode 100755 index 0000000..762e89a --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/cosf.c @@ -0,0 +1,70 @@ +/* + * libm/cosf.c + */ + +#include + +static const double + c1pio2 = 1 * M_PI_2, + c2pio2 = 2 * M_PI_2, + c3pio2 = 3 * M_PI_2, + c4pio2 = 4 * M_PI_2; + +float cosf(float x) +{ + float y[2]; + s32_t n, hx, ix; + + GET_FLOAT_WORD(hx,x); + ix = hx & 0x7fffffff; + + if (ix <= 0x3f490fda) + { + if (ix < 0x39800000) + if (((int) x) == 0) + return 1.0; + return __kernel_cosdf(x); + } + if (ix <= 0x407b53d1) + { + if (ix > 0x4016cbe3) + return -__kernel_cosdf(x + (hx > 0 ? -c2pio2 : c2pio2)); + else + { + if (hx > 0) + return __kernel_sindf(c1pio2 - x); + else + return __kernel_sindf(x + c1pio2); + } + } + if (ix <= 0x40e231d5) + { + if (ix > 0x40afeddf) + return __kernel_cosdf(x + (hx > 0 ? -c4pio2 : c4pio2)); + else + { + if (hx > 0) + return __kernel_sindf(x - c3pio2); + else + return __kernel_sindf(-c3pio2 - x); + } + } + else if (ix >= 0x7f800000) + return x - x; + else + { + n = __ieee754_rem_pio2f(x, y); + switch (n & 3) + { + case 0: + return __kernel_cosdf((double) y[0] + y[1]); + case 1: + return __kernel_sindf(-(double) y[0] - y[1]); + case 2: + return -__kernel_cosdf((double) y[0] + y[1]); + default: + return __kernel_sindf((double) y[0] + y[1]); + } + } +} + diff --git a/boot1/apps/BootQC/Common/libm/cosh.c b/boot1/apps/BootQC/Common/libm/cosh.c new file mode 100755 index 0000000..d4dcd5e --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/cosh.c @@ -0,0 +1,49 @@ +/* + * libm/cosh.c + */ + +#include + +static const double one = 1.0, half = 0.5, huge = 1.0e300; + +double cosh(double x) +{ + double t, w; + s32_t ix; + u32_t lx; + + GET_HIGH_WORD(ix,x); + ix &= 0x7fffffff; + + if (ix >= 0x7ff00000) + return x * x; + + if (ix < 0x3fd62e43) + { + t = expm1(fabs(x)); + w = one + t; + if (ix < 0x3c800000) + return w; + return one + (t * t) / (w + w); + } + + if (ix < 0x40360000) + { + t = exp(fabs(x)); + return half * t + half / t; + } + + if (ix < 0x40862E42) + return half * exp(fabs(x)); + + GET_LOW_WORD(lx,x); + if (ix < 0x408633CE || ((ix == 0x408633ce) + && (lx <= (u32_t) 0x8fb9f87d))) + { + w = exp(half * fabs(x)); + t = half * w; + return t * w; + } + + return huge * huge; +} diff --git a/boot1/apps/BootQC/Common/libm/coshf.c b/boot1/apps/BootQC/Common/libm/coshf.c new file mode 100755 index 0000000..db51a34 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/coshf.c @@ -0,0 +1,46 @@ +/* + * libm/coshf.c + */ + +#include + +static const float one = 1.0, half = 0.5, huge = 1.0e30; + +float coshf(float x) +{ + float t, w; + s32_t ix; + + GET_FLOAT_WORD(ix,x); + ix &= 0x7fffffff; + + if (ix >= 0x7f800000) + return x * x; + + if (ix < 0x3eb17218) + { + t = expm1f(fabsf(x)); + w = one + t; + if (ix < 0x39800000) + return one; + return one + (t * t) / (w + w); + } + + if (ix < 0x41100000) + { + t = expf(fabsf(x)); + return half * t + half / t; + } + + if (ix < 0x42b17217) + return half * expf(fabsf(x)); + + if (ix <= 0x42b2d4fc) + { + w = expf(half * fabsf(x)); + t = half * w; + return t * w; + } + + return huge * huge; +} diff --git a/boot1/apps/BootQC/Common/libm/e_rem_pio2.c b/boot1/apps/BootQC/Common/libm/e_rem_pio2.c new file mode 100755 index 0000000..0c4b28b --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/e_rem_pio2.c @@ -0,0 +1,166 @@ +/* + * libm/e_rem_pio2.c + */ + +#include + +static const s32_t two_over_pi[] = { + 0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, + 0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, + 0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, + 0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, + 0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, + 0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, + 0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, + 0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, + 0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, + 0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, + 0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, +}; + +static const s32_t npio2_hw[] = { + 0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C, + 0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C, + 0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A, + 0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C, + 0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB, + 0x404858EB, 0x404921FB, +}; + +static const double + zero = 0.00000000000000000000e+00, + half = 5.00000000000000000000e-01, + two24 = 1.67772160000000000000e+07, + invpio2 = 6.36619772367581382433e-01, + pio2_1 = 1.57079632673412561417e+00, + pio2_1t = 6.07710050650619224932e-11, + pio2_2 = 6.07710050630396597660e-11, + pio2_2t = 2.02226624879595063154e-21, + pio2_3 = 2.02226624871116645580e-21, + pio2_3t = 8.47842766036889956997e-32; + +s32_t __ieee754_rem_pio2(double x, double *y) +{ + double z = 0, w, t, r, fn; + double tx[3]; + s32_t e0, i, j, nx, n, ix, hx; + u32_t low; + + GET_HIGH_WORD(hx,x); + ix = hx & 0x7fffffff; + if (ix <= 0x3fe921fb) + { + y[0] = x; + y[1] = 0; + return 0; + } + if (ix < 0x4002d97c) + { + if (hx > 0) + { + z = x - pio2_1; + if (ix != 0x3ff921fb) + { + y[0] = z - pio2_1t; + y[1] = (z - y[0]) - pio2_1t; + } + else + { + z -= pio2_2; + y[0] = z - pio2_2t; + y[1] = (z - y[0]) - pio2_2t; + } + return 1; + } + else + { + z = x + pio2_1; + if (ix != 0x3ff921fb) + { + y[0] = z + pio2_1t; + y[1] = (z - y[0]) + pio2_1t; + } + else + { + z += pio2_2; + y[0] = z + pio2_2t; + y[1] = (z - y[0]) + pio2_2t; + } + return -1; + } + } + if (ix <= 0x413921fb) + { + t = fabs(x); + n = (s32_t)(t * invpio2 + half); + fn = (double) n; + r = t - fn * pio2_1; + w = fn * pio2_1t; + if (n < 32 && ix != npio2_hw[n - 1]) + { + y[0] = r - w; + } + else + { + u32_t high; + j = ix >> 20; + y[0] = r - w; + GET_HIGH_WORD(high,y[0]); + i = j - ((high >> 20) & 0x7ff); + if (i > 16) + { + t = r; + w = fn * pio2_2; + r = t - w; + w = fn * pio2_2t - ((t - r) - w); + y[0] = r - w; + GET_HIGH_WORD(high,y[0]); + i = j - ((high >> 20) & 0x7ff); + if (i > 49) + { + t = r; + w = fn * pio2_3; + r = t - w; + w = fn * pio2_3t - ((t - r) - w); + y[0] = r - w; + } + } + } + y[1] = (r - y[0]) - w; + if (hx < 0) + { + y[0] = -y[0]; + y[1] = -y[1]; + return -n; + } + else + return n; + } + + if (ix >= 0x7ff00000) + { + y[0] = y[1] = x - x; + return 0; + } + GET_LOW_WORD(low,x); + SET_LOW_WORD(z,low); + e0 = (ix >> 20) - 1046; + SET_HIGH_WORD(z, ix - ((s32_t)(e0<<20))); + for (i = 0; i < 2; i++) + { + tx[i] = (double) ((s32_t)(z)); + z = (z - tx[i]) * two24; + } + tx[2] = z; + nx = 3; + while (tx[nx - 1] == zero) + nx--; + n = __kernel_rem_pio2(tx, y, e0, nx, 2, two_over_pi); + if (hx < 0) + { + y[0] = -y[0]; + y[1] = -y[1]; + return -n; + } + return n; +} diff --git a/boot1/apps/BootQC/Common/libm/e_rem_pio2f.c b/boot1/apps/BootQC/Common/libm/e_rem_pio2f.c new file mode 100755 index 0000000..74c56f5 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/e_rem_pio2f.c @@ -0,0 +1,77 @@ +/* + * libm/e_rem_pio2f.c + */ + +#include + +static const s32_t two_over_pi[] = { + 0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, + 0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, + 0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, + 0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, + 0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, + 0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, + 0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, + 0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, + 0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, + 0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, + 0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, +}; + +static const double + zero = 0.00000000000000000000e+00, + half = 5.00000000000000000000e-01, + two24 = 1.67772160000000000000e+07, + invpio2 = 6.36619772367581382433e-01, + pio2_1 = 1.57079632673412561417e+00, + pio2_1t = 6.07710050650619224932e-11; + +s32_t __ieee754_rem_pio2f(float x, float *y) +{ + double w, t, r, fn; + double tx[1], ty[2]; + float z; + s32_t e0, n, ix, hx; + + GET_FLOAT_WORD(hx,x); + ix = hx & 0x7fffffff; + + if (ix <= 0x49490f80) + { + t = fabsf(x); + n = (s32_t)(t * invpio2 + half); + fn = (double) n; + r = t - fn * pio2_1; + w = fn * pio2_1t; + y[0] = r - w; + y[1] = (r - y[0]) - w; + if (hx < 0) + { + y[0] = -y[0]; + y[1] = -y[1]; + return -n; + } + else + return n; + } + + if (ix >= 0x7f800000) + { + y[0] = y[1] = x - x; + return 0; + } + + e0 = (ix >> 23) - 150; + SET_FLOAT_WORD(z, ix - ((s32_t)(e0<<23))); + tx[0] = z; + n = __kernel_rem_pio2(tx, ty, e0, 1, 1, two_over_pi); + y[0] = ty[0]; + y[1] = ty[0] - y[0]; + if (hx < 0) + { + y[0] = -y[0]; + y[1] = -y[1]; + return -n; + } + return n; +} diff --git a/boot1/apps/BootQC/Common/libm/exp.c b/boot1/apps/BootQC/Common/libm/exp.c new file mode 100755 index 0000000..c88b022 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/exp.c @@ -0,0 +1,98 @@ +/* + * libm/exp.c + */ + + +#include + +static const double + one = 1.0, + halF[2] = {0.5,-0.5,}, + huge = 1.0e+300, + twom1000 = 9.33263618503218878990e-302, + o_threshold = 7.09782712893383973096e+02, + u_threshold = -7.45133219101941108420e+02, + ln2HI[2] = { 6.93147180369123816490e-01, + -6.93147180369123816490e-01,}, + ln2LO[2] ={ 1.90821492927058770002e-10, + -1.90821492927058770002e-10,}, + invln2 = 1.44269504088896338700e+00, + P1 = 1.66666666666666019037e-01, + P2 = -2.77777777770155933842e-03, + P3 = 6.61375632143793436117e-05, + P4 = -1.65339022054652515390e-06, + P5 = 4.13813679705723846039e-08; + +double exp(double x) +{ + double y, hi = 0.0, lo = 0.0, c, t; + s32_t k = 0, xsb; + u32_t hx; + + GET_HIGH_WORD(hx,x); + xsb = (hx >> 31) & 1; + hx &= 0x7fffffff; + + if (hx >= 0x40862E42) + { + if (hx >= 0x7ff00000) + { + u32_t lx; + GET_LOW_WORD(lx,x); + if (((hx & 0xfffff) | lx) != 0) + return x + x; + else + return (xsb == 0) ? x : 0.0; + } + if (x > o_threshold) + return huge * huge; + if (x < u_threshold) + return twom1000 * twom1000; + } + + if (hx > 0x3fd62e42) + { + if (hx < 0x3FF0A2B2) + { + hi = x - ln2HI[xsb]; + lo = ln2LO[xsb]; + k = 1 - xsb - xsb; + } + else + { + k = (int) (invln2 * x + halF[xsb]); + t = k; + hi = x - t * ln2HI[0]; + lo = t * ln2LO[0]; + } + x = hi - lo; + } + else if (hx < 0x3e300000) + { + if (huge + x > one) + return one + x; + } + else + k = 0; + + t = x * x; + c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); + if (k == 0) + return one - ((x * c) / (c - 2.0) - x); + else + y = one - ((lo - (x * c) / (2.0 - c)) - hi); + if (k >= -1021) + { + u32_t hy; + GET_HIGH_WORD(hy,y); + SET_HIGH_WORD(y,hy+(k<<20)); + return y; + } + else + { + u32_t hy; + GET_HIGH_WORD(hy,y); + SET_HIGH_WORD(y,hy+((k+1000)<<20)); + return y * twom1000; + } +} diff --git a/boot1/apps/BootQC/Common/libm/expf.c b/boot1/apps/BootQC/Common/libm/expf.c new file mode 100755 index 0000000..5a7c42e --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/expf.c @@ -0,0 +1,92 @@ +/* + * libm/expf.c + */ + +#include + +static const float + one = 1.0, + halF[2] = {0.5,-0.5,}, + huge = 1.0e+30, + twom100 = 7.8886090522e-31, + o_threshold = 8.8721679688e+01, + u_threshold = -1.0397208405e+02, + ln2HI[2] = { 6.9314575195e-01, + -6.9314575195e-01,}, + ln2LO[2] = { 1.4286067653e-06, + -1.4286067653e-06,}, + invln2 = 1.4426950216e+00, + P1 = 1.6666667163e-01, + P2 = -2.7777778450e-03, + P3 = 6.6137559770e-05, + P4 = -1.6533901999e-06, + P5 = 4.1381369442e-08; + +float expf(float x) +{ + float y, hi = 0.0, lo = 0.0, c, t; + s32_t k = 0, xsb; + u32_t hx; + + GET_FLOAT_WORD(hx,x); + xsb = (hx >> 31) & 1; + hx &= 0x7fffffff; + + if (hx >= 0x42b17218) + { + if (hx > 0x7f800000) + return x + x; + if (hx == 0x7f800000) + return (xsb == 0) ? x : 0.0; + if (x > o_threshold) + return huge * huge; + if (x < u_threshold) + return twom100 * twom100; + } + + if (hx > 0x3eb17218) + { + if (hx < 0x3F851592) + { + hi = x - ln2HI[xsb]; + lo = ln2LO[xsb]; + k = 1 - xsb - xsb; + } + else + { + k = invln2 * x + halF[xsb]; + t = k; + hi = x - t * ln2HI[0]; + lo = t * ln2LO[0]; + } + x = hi - lo; + } + else if (hx < 0x31800000) + { + if (huge + x > one) + return one + x; + } + else + k = 0; + + t = x * x; + c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); + if (k == 0) + return one - ((x * c) / (c - (float) 2.0) - x); + else + y = one - ((lo - (x * c) / ((float) 2.0 - c)) - hi); + if (k >= -125) + { + u32_t hy; + GET_FLOAT_WORD(hy,y); + SET_FLOAT_WORD(y,hy+(k<<23)); + return y; + } + else + { + u32_t hy; + GET_FLOAT_WORD(hy,y); + SET_FLOAT_WORD(y,hy+((k+100)<<23)); + return y * twom100; + } +} diff --git a/boot1/apps/BootQC/Common/libm/expm1.c b/boot1/apps/BootQC/Common/libm/expm1.c new file mode 100755 index 0000000..34f042c --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/expm1.c @@ -0,0 +1,141 @@ +/* + * libm/expm1.c + */ + +#include + +static const double + one = 1.0, + huge = 1.0e+300, + tiny = 1.0e-300, + o_threshold = 7.09782712893383973096e+02, + ln2_hi = 6.93147180369123816490e-01, + ln2_lo = 1.90821492927058770002e-10, + invln2 = 1.44269504088896338700e+00, + Q1 = -3.33333333333331316428e-02, + Q2 = 1.58730158725481460165e-03, + Q3 = -7.93650757867487942473e-05, + Q4 = 4.00821782732936239552e-06, + Q5 = -2.01099218183624371326e-07; + +double expm1(double x) +{ + double y, hi, lo, c=0, t, e, hxs, hfx, r1; + s32_t k, xsb; + u32_t hx; + + GET_HIGH_WORD(hx,x); + xsb = hx & 0x80000000; + if (xsb == 0) + y = x; + else + y = -x; + hx &= 0x7fffffff; + + if (hx >= 0x4043687A) + { + if (hx >= 0x40862E42) + { + if (hx >= 0x7ff00000) + { + u32_t low; + GET_LOW_WORD(low,x); + if (((hx & 0xfffff) | low) != 0) + return x + x; + else + return (xsb == 0) ? x : -1.0; + } + if (x > o_threshold) + return huge * huge; + } + if (xsb != 0) + { + if (x + tiny < 0.0) + return tiny - one; + } + } + + if (hx > 0x3fd62e42) + { + if (hx < 0x3FF0A2B2) + { + if (xsb == 0) + { + hi = x - ln2_hi; + lo = ln2_lo; + k = 1; + } + else + { + hi = x + ln2_hi; + lo = -ln2_lo; + k = -1; + } + } + else + { + k = invln2 * x + ((xsb == 0) ? 0.5 : -0.5); + t = k; + hi = x - t * ln2_hi; + lo = t * ln2_lo; + } + x = hi - lo; + c = (hi - x) - lo; + } + else if (hx < 0x3c900000) + { + t = huge + x; + return x - (t - (huge + x)); + } + else + k = 0; + + hfx = 0.5 * x; + hxs = x * hfx; + r1 = one + hxs * (Q1 + hxs * (Q2 + hxs * (Q3 + hxs * (Q4 + hxs * Q5)))); + t = 3.0 - r1 * hfx; + e = hxs * ((r1 - t) / (6.0 - x * t)); + if (k == 0) + return x - (x * e - hxs); + else + { + e = (x * (e - c) - c); + e -= hxs; + if (k == -1) + return 0.5 * (x - e) - 0.5; + if (k == 1) + { + if (x < -0.25) + return -2.0 * (e - (x + 0.5)); + else + return one + 2.0 * (x - e); + } + if (k <= -2 || k > 56) + { + u32_t high; + y = one - (e - x); + GET_HIGH_WORD(high,y); + SET_HIGH_WORD(y,high+(k<<20)); + return y - one; + } + t = one; + if (k < 20) + { + u32_t high; + SET_HIGH_WORD(t,0x3ff00000 - (0x200000>>k)); + y = t - (e - x); + GET_HIGH_WORD(high,y); + SET_HIGH_WORD(y,high+(k<<20)); + } + else + { + u32_t high; + SET_HIGH_WORD(t,((0x3ff-k)<<20)); + y = x - (e + t); + y += one; + GET_HIGH_WORD(high,y); + SET_HIGH_WORD(y,high+(k<<20)); + } + } + return y; +} diff --git a/boot1/apps/BootQC/Common/libm/expm1f.c b/boot1/apps/BootQC/Common/libm/expm1f.c new file mode 100755 index 0000000..a81cb82 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/expm1f.c @@ -0,0 +1,136 @@ +/* + * libm/expm1f.c + */ + +#include + +static const float + one = 1.0, + huge = 1.0e+30, + tiny = 1.0e-30, + o_threshold = 8.8721679688e+01, + ln2_hi = 6.9313812256e-01, + ln2_lo = 9.0580006145e-06, + invln2 = 1.4426950216e+00, + Q1 = -3.3333335072e-02, + Q2 = 1.5873016091e-03, + Q3 = -7.9365076090e-05, + Q4 = 4.0082177293e-06, + Q5 = -2.0109921195e-07; + +float expm1f(float x) +{ + float y, hi, lo, c=0, t, e, hxs, hfx, r1; + s32_t k, xsb; + u32_t hx; + + GET_FLOAT_WORD(hx,x); + xsb = hx & 0x80000000; + if (xsb == 0) + y = x; + else + y = -x; + hx &= 0x7fffffff; + + if (hx >= 0x4195b844) + { + if (hx >= 0x42b17218) + { + if (hx > 0x7f800000) + return x + x; + if (hx == 0x7f800000) + return (xsb == 0) ? x : -1.0; + if (x > o_threshold) + return huge * huge; + } + if (xsb != 0) + { + if (x + tiny < (float) 0.0) + return tiny - one; + } + } + + if (hx > 0x3eb17218) + { + if (hx < 0x3F851592) + { + if (xsb == 0) + { + hi = x - ln2_hi; + lo = ln2_lo; + k = 1; + } + else + { + hi = x + ln2_hi; + lo = -ln2_lo; + k = -1; + } + } + else + { + k = invln2 * x + ((xsb == 0) ? (float) 0.5 : (float) -0.5); + t = k; + hi = x - t * ln2_hi; + lo = t * ln2_lo; + } + x = hi - lo; + c = (hi - x) - lo; + } + else if (hx < 0x33000000) + { + t = huge + x; + return x - (t - (huge + x)); + } + else + k = 0; + + hfx = (float) 0.5 * x; + hxs = x * hfx; + r1 = one + hxs * (Q1 + hxs * (Q2 + hxs * (Q3 + hxs * (Q4 + hxs * Q5)))); + t = (float) 3.0 - r1 * hfx; + e = hxs * ((r1 - t) / ((float) 6.0 - x * t)); + if (k == 0) + return x - (x * e - hxs); + else + { + e = (x * (e - c) - c); + e -= hxs; + if (k == -1) + return (float) 0.5 * (x - e) - (float) 0.5; + if (k == 1) + { + if (x < (float) -0.25) + return -(float) 2.0 * (e - (x + (float) 0.5)); + else + return one + (float) 2.0 * (x - e); + } + if (k <= -2 || k > 56) + { + s32_t i; + y = one - (e - x); + GET_FLOAT_WORD(i,y); + SET_FLOAT_WORD(y,i+(k<<23)); + return y - one; + } + t = one; + if (k < 23) + { + s32_t i; + SET_FLOAT_WORD(t,0x3f800000 - (0x1000000>>k)); + y = t - (e - x); + GET_FLOAT_WORD(i,y); + SET_FLOAT_WORD(y,i+(k<<23)); + } + else + { + s32_t i; + SET_FLOAT_WORD(t,((0x7f-k)<<23)); + y = x - (e + t); + y += one; + GET_FLOAT_WORD(i,y); + SET_FLOAT_WORD(y,i+(k<<23)); + } + } + return y; +} diff --git a/boot1/apps/BootQC/Common/libm/fabs.c b/boot1/apps/BootQC/Common/libm/fabs.c new file mode 100755 index 0000000..48bf19b --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/fabs.c @@ -0,0 +1,15 @@ +/* + * libm/fabs.c + */ + + +#include + +double fabs(double x) +{ + u32_t high; + + GET_HIGH_WORD(high, x); + SET_HIGH_WORD(x, high & 0x7fffffff); + return x; +} diff --git a/boot1/apps/BootQC/Common/libm/fabsf.c b/boot1/apps/BootQC/Common/libm/fabsf.c new file mode 100755 index 0000000..a05e11d --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/fabsf.c @@ -0,0 +1,16 @@ +/* + * libm/fabsf.c + */ + + +#include + +float fabsf(float x) +{ + u32_t ix; + + GET_FLOAT_WORD(ix, x); + SET_FLOAT_WORD(x, ix & 0x7fffffff); + return x; +} + diff --git a/boot1/apps/BootQC/Common/libm/floor.c b/boot1/apps/BootQC/Common/libm/floor.c new file mode 100755 index 0000000..a7138c4 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/floor.c @@ -0,0 +1,81 @@ +/* + * libm/floor.c + */ + +#include + +static const double huge = 1.0e300; + +double floor(double x) +{ + s32_t i0, i1, j0; + u32_t i, j; + + EXTRACT_WORDS(i0,i1,x); + j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; + + if (j0 < 20) + { + if (j0 < 0) + { + if (huge + x > 0.0) + { + if (i0 >= 0) + { + i0 = i1 = 0; + } + else if (((i0 & 0x7fffffff) | i1) != 0) + { + i0 = 0xbff00000; + i1 = 0; + } + } + } + else + { + i = (0x000fffff) >> j0; + if (((i0 & i) | i1) == 0) + return x; + if (huge + x > 0.0) + { + if (i0 < 0) + i0 += (0x00100000) >> j0; + i0 &= (~i); + i1 = 0; + } + } + } + else if (j0 > 51) + { + if (j0 == 0x400) + return x + x; + else + return x; + } + else + { + i = ((u32_t)(0xffffffff)) >> (j0 - 20); + if ((i1 & i) == 0) + return x; + if (huge + x > 0.0) + { + if (i0 < 0) + { + if (j0 == 20) + i0 += 1; + else + { + j = i1 + (1 << (52 - j0)); + if (j < i1) + i0 += 1; + i1 = j; + } + } + i1 &= (~i); + } + } + + INSERT_WORDS(x,i0,i1); + return x; +} + diff --git a/boot1/apps/BootQC/Common/libm/floorf.c b/boot1/apps/BootQC/Common/libm/floorf.c new file mode 100755 index 0000000..528ace1 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/floorf.c @@ -0,0 +1,57 @@ +/* + * libm/floorf.c + */ + + +#include + +static const float huge = 1.0e30; + +float floorf(float x) +{ + s32_t i0, j0; + u32_t i; + + GET_FLOAT_WORD(i0,x); + j0 = ((i0 >> 23) & 0xff) - 0x7f; + + if (j0 < 23) + { + if (j0 < 0) + { + if (huge + x > (float) 0.0) + { + if (i0 >= 0) + { + i0 = 0; + } + else if ((i0 & 0x7fffffff) != 0) + { + i0 = 0xbf800000; + } + } + } + else + { + i = (0x007fffff) >> j0; + if ((i0 & i) == 0) + return x; + if (huge + x > (float) 0.0) + { + if (i0 < 0) + i0 += (0x00800000) >> j0; + i0 &= (~i); + } + } + } + else + { + if (j0 == 0x80) + return x + x; + else + return x; + } + + SET_FLOAT_WORD(x,i0); + return x; +} diff --git a/boot1/apps/BootQC/Common/libm/fmod.c b/boot1/apps/BootQC/Common/libm/fmod.c new file mode 100755 index 0000000..759dd80 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/fmod.c @@ -0,0 +1,162 @@ +/* + * libm/fmod.c + */ + + +#include + +static const double one = 1.0, Zero[] = {0.0, -0.0,}; + +double fmod(double x, double y) +{ + s32_t n, hx, hy, hz, ix, iy, sx, i; + u32_t lx, ly, lz; + + EXTRACT_WORDS(hx,lx,x); + EXTRACT_WORDS(hy,ly,y); + sx = hx & 0x80000000; + hx ^= sx; + hy &= 0x7fffffff; + + if ((hy | ly) == 0 || (hx >= 0x7ff00000) || + ((hy | ((ly | -ly) >> 31)) > 0x7ff00000)) + return (x * y) / (x * y); + if (hx <= hy) + { + if ((hx < hy) || (lx < ly)) + return x; + if (lx == ly) + return Zero[(u32_t) sx >> 31]; + } + + if (hx < 0x00100000) + { + if (hx == 0) + { + for (ix = -1043, i = lx; i > 0; i <<= 1) + ix -= 1; + } + else + { + for (ix = -1022, i = (hx << 11); i > 0; i <<= 1) + ix -= 1; + } + } + else + ix = (hx >> 20) - 1023; + + if (hy < 0x00100000) + { + if (hy == 0) + { + for (iy = -1043, i = ly; i > 0; i <<= 1) + iy -= 1; + } + else + { + for (iy = -1022, i = (hy << 11); i > 0; i <<= 1) + iy -= 1; + } + } + else + iy = (hy >> 20) - 1023; + + if (ix >= -1022) + hx = 0x00100000 | (0x000fffff & hx); + else + { + n = -1022 - ix; + if (n <= 31) + { + hx = (hx << n) | (lx >> (32 - n)); + lx <<= n; + } + else + { + hx = lx << (n - 32); + lx = 0; + } + } + if (iy >= -1022) + hy = 0x00100000 | (0x000fffff & hy); + else + { + n = -1022 - iy; + if (n <= 31) + { + hy = (hy << n) | (ly >> (32 - n)); + ly <<= n; + } + else + { + hy = ly << (n - 32); + ly = 0; + } + } + + n = ix - iy; + while (n--) + { + hz = hx - hy; + lz = lx - ly; + if (lx < ly) + hz -= 1; + if (hz < 0) + { + hx = hx + hx + (lx >> 31); + lx = lx + lx; + } + else + { + if ((hz | lz) == 0) + return Zero[(u32_t) sx >> 31]; + hx = hz + hz + (lz >> 31); + lx = lz + lz; + } + } + hz = hx - hy; + lz = lx - ly; + if (lx < ly) + hz -= 1; + if (hz >= 0) + { + hx = hz; + lx = lz; + } + + if ((hx | lx) == 0) + return Zero[(u32_t) sx >> 31]; + while (hx < 0x00100000) + { + hx = hx + hx + (lx >> 31); + lx = lx + lx; + iy -= 1; + } + if (iy >= -1022) + { + hx = ((hx - 0x00100000) | ((iy + 1023) << 20)); + INSERT_WORDS(x,hx|sx,lx); + } + else + { + n = -1022 - iy; + if (n <= 20) + { + lx = (lx >> n) | ((u32_t) hx << (32 - n)); + hx >>= n; + } + else if (n <= 31) + { + lx = (hx << (32 - n)) | (lx >> n); + hx = sx; + } + else + { + lx = hx >> (n - 32); + hx = sx; + } + INSERT_WORDS(x,hx|sx,lx); + x *= one; + } + return x; +} diff --git a/boot1/apps/BootQC/Common/libm/fmodf.c b/boot1/apps/BootQC/Common/libm/fmodf.c new file mode 100755 index 0000000..e840d27 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/fmodf.c @@ -0,0 +1,98 @@ +/* + * libm/fmodf.c + */ + +#include + +static const float one = 1.0, Zero[] = {0.0, -0.0,}; + +float fmodf(float x, float y) +{ + s32_t n, hx, hy, hz, ix, iy, sx, i; + + GET_FLOAT_WORD(hx,x); + GET_FLOAT_WORD(hy,y); + sx = hx & 0x80000000; + hx ^= sx; + hy &= 0x7fffffff; + + if (hy == 0 || (hx >= 0x7f800000) || (hy > 0x7f800000)) + return (x * y) / (x * y); + if (hx < hy) + return x; + if (hx == hy) + return Zero[(u32_t) sx >> 31]; + + if (hx < 0x00800000) + { + for (ix = -126, i = (hx << 8); i > 0; i <<= 1) + ix -= 1; + } + else + ix = (hx >> 23) - 127; + + if (hy < 0x00800000) + { + for (iy = -126, i = (hy << 8); i >= 0; i <<= 1) + iy -= 1; + } + else + iy = (hy >> 23) - 127; + + if (ix >= -126) + hx = 0x00800000 | (0x007fffff & hx); + else + { + n = -126 - ix; + hx = hx << n; + } + if (iy >= -126) + hy = 0x00800000 | (0x007fffff & hy); + else + { + n = -126 - iy; + hy = hy << n; + } + + n = ix - iy; + while (n--) + { + hz = hx - hy; + if (hz < 0) + { + hx = hx + hx; + } + else + { + if (hz == 0) + return Zero[(u32_t) sx >> 31]; + hx = hz + hz; + } + } + hz = hx - hy; + if (hz >= 0) + { + hx = hz; + } + + if (hx == 0) + return Zero[(u32_t) sx >> 31]; + while (hx < 0x00800000) + { + hx = hx + hx; + iy -= 1; + } + if (iy >= -126) + { + hx = ((hx - 0x00800000) | ((iy + 127) << 23)); + SET_FLOAT_WORD(x,hx|sx); + } + else + { + n = -126 - iy; + hx >>= n; + SET_FLOAT_WORD(x,hx|sx); + x *= one; + } + return x; +} diff --git a/boot1/apps/BootQC/Common/libm/frexp.c b/boot1/apps/BootQC/Common/libm/frexp.c new file mode 100755 index 0000000..6a3f953 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/frexp.c @@ -0,0 +1,35 @@ +/* + * libm/frexp.c + */ + + +#include + +static const double two54 = 1.80143985094819840000e+16; + +double frexp(double x, int *eptr) +{ + s32_t hx, ix, lx; + + EXTRACT_WORDS(hx,lx,x); + ix = 0x7fffffff & hx; + *eptr = 0; + + if (ix >= 0x7ff00000 || ((ix | lx) == 0)) + return x; + + if (ix < 0x00100000) + { + x *= two54; + GET_HIGH_WORD(hx,x); + ix = hx & 0x7fffffff; + *eptr = -54; + } + + *eptr += (ix >> 20) - 1022; + hx = (hx & 0x800fffff) | 0x3fe00000; + SET_HIGH_WORD(x,hx); + + return x; +} + diff --git a/boot1/apps/BootQC/Common/libm/frexpf.c b/boot1/apps/BootQC/Common/libm/frexpf.c new file mode 100755 index 0000000..a603e27 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/frexpf.c @@ -0,0 +1,34 @@ +/* + * libm/frexpf.c + */ + + +#include + +static const float two25 = 3.3554432000e+07; + +float frexpf(float x, int *eptr) +{ + s32_t hx, ix; + + GET_FLOAT_WORD(hx,x); + ix = 0x7fffffff & hx; + *eptr = 0; + + if (ix >= 0x7f800000 || (ix == 0)) + return x; + + if (ix < 0x00800000) + { + x *= two25; + GET_FLOAT_WORD(hx,x); + ix = hx & 0x7fffffff; + *eptr = -25; + } + + *eptr += (ix >> 23) - 126; + hx = (hx & 0x807fffff) | 0x3f000000; + SET_FLOAT_WORD(x,hx); + + return x; +} diff --git a/boot1/apps/BootQC/Common/libm/hypot.c b/boot1/apps/BootQC/Common/libm/hypot.c new file mode 100755 index 0000000..93b3ccf --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/hypot.c @@ -0,0 +1,110 @@ +/* + * libm/hypot.c + */ + + +#include + +double hypot(double x, double y) +{ + double a = x, b = y, t1, t2, y1, y2, w; + s32_t j, k, ha, hb; + + GET_HIGH_WORD(ha, x); + ha &= 0x7fffffff; + GET_HIGH_WORD(hb, y); + hb &= 0x7fffffff; + if (hb > ha) + { + a = y; + b = x; + j = ha; + ha = hb; + hb = j; + } + else + { + a = x; + b = y; + } + SET_HIGH_WORD(a, ha); + SET_HIGH_WORD(b, hb); + if ((ha - hb) > 0x3c00000) + { + return a + b; + } + k = 0; + if (ha > 0x5f300000) + { + if (ha >= 0x7ff00000) + { + u32_t low; + w = a + b; + GET_LOW_WORD(low, a); + if (((ha & 0xfffff) | low) == 0) + w = a; + GET_LOW_WORD(low, b); + if (((hb ^ 0x7ff00000) | low) == 0) + w = b; + return w; + } + ha -= 0x25800000; + hb -= 0x25800000; + k += 600; + SET_HIGH_WORD(a, ha); + SET_HIGH_WORD(b, hb); + } + if (hb < 0x20b00000) + { + if (hb <= 0x000fffff) + { + u32_t low; + GET_LOW_WORD(low, b); + if ((hb | low) == 0) + return a; + t1 = 0; + SET_HIGH_WORD(t1, 0x7fd00000); + b *= t1; + a *= t1; + k -= 1022; + } + else + { + ha += 0x25800000; + hb += 0x25800000; + k -= 600; + SET_HIGH_WORD(a, ha); + SET_HIGH_WORD(b, hb); + } + } + w = a - b; + if (w > b) + { + t1 = 0; + SET_HIGH_WORD(t1, ha); + t2 = a - t1; + w = sqrt(t1 * t1 - (b * (-b) - t2 * (a + t1))); + } + else + { + a = a + a; + y1 = 0; + SET_HIGH_WORD(y1, hb); + y2 = b - y1; + t1 = 0; + SET_HIGH_WORD(t1, ha+0x00100000); + t2 = a - t1; + w = sqrt(t1 * y1 - (w * (-w) - (t1 * y2 + t2 * b))); + } + if (k != 0) + { + u32_t high; + t1 = 1.0; + GET_HIGH_WORD(high, t1); + SET_HIGH_WORD(t1, high+(k<<20)); + return t1 * w; + } + else + return w; +} + diff --git a/boot1/apps/BootQC/Common/libm/hypotf.c b/boot1/apps/BootQC/Common/libm/hypotf.c new file mode 100755 index 0000000..64ddff4 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/hypotf.c @@ -0,0 +1,98 @@ +/* + * libm/hypotf.c + */ + + +#include + +float hypotf(float x, float y) +{ + float a = x, b = y, t1, t2, y1, y2, w; + s32_t j, k, ha, hb; + + GET_FLOAT_WORD(ha, x); + ha &= 0x7fffffff; + GET_FLOAT_WORD(hb, y); + hb &= 0x7fffffff; + if (hb > ha) + { + a = y; + b = x; + j = ha; + ha = hb; + hb = j; + } + else + { + a = x; + b = y; + } + SET_FLOAT_WORD(a, ha); + SET_FLOAT_WORD(b, hb); + if ((ha - hb) > 0xf000000) + { + return a + b; + } + k = 0; + if (ha > 0x58800000) + { + if (ha >= 0x7f800000) + { + w = a + b; + if (ha == 0x7f800000) + w = a; + if (hb == 0x7f800000) + w = b; + return w; + } + ha -= 0x22000000; + hb -= 0x22000000; + k += 68; + SET_FLOAT_WORD(a, ha); + SET_FLOAT_WORD(b, hb); + } + if (hb < 0x26800000) + { + if (hb <= 0x007fffff) + { + if (hb == 0) + return a; + SET_FLOAT_WORD(t1, 0x7e800000); + b *= t1; + a *= t1; + k -= 126; + } + else + { + ha += 0x22000000; + hb += 0x22000000; + k -= 68; + SET_FLOAT_WORD(a, ha); + SET_FLOAT_WORD(b, hb); + } + } + w = a - b; + if (w > b) + { + SET_FLOAT_WORD(t1, ha&0xfffff000); + t2 = a - t1; + w = sqrtf(t1 * t1 - (b * (-b) - t2 * (a + t1))); + } + else + { + a = a + a; + SET_FLOAT_WORD(y1, hb&0xfffff000); + y2 = b - y1; + SET_FLOAT_WORD(t1, ha+0x00800000); + t2 = a - t1; + w = sqrtf(t1 * y1 - (w * (-w) - (t1 * y2 + t2 * b))); + } + if (k != 0) + { + SET_FLOAT_WORD(t1, 0x3f800000+(k<<23)); + return t1 * w; + } + else + return w; +} + diff --git a/boot1/apps/BootQC/Common/libm/k_cos.c b/boot1/apps/BootQC/Common/libm/k_cos.c new file mode 100755 index 0000000..6a6610e --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/k_cos.c @@ -0,0 +1,25 @@ +/* + * libm/k_cos.c + */ + +#include + +static const double + one = 1.00000000000000000000e+00, + C1 = 4.16666666666666019037e-02, + C2 = -1.38888888888741095749e-03, + C3 = 2.48015872894767294178e-05, + C4 = -2.75573143513906633035e-07, + C5 = 2.08757232129817482790e-09, + C6 = -1.13596475577881948265e-11; + +double __kernel_cos(double x, double y) +{ + double hz, z, r, w; + + z = x * x; + r = z * (C1 + z * (C2 + z * (C3 + z * (C4 + z * (C5 + z * C6))))); + hz = (float) 0.5 * z; + w = one - hz; + return w + (((one - w) - hz) + (z * r - x * y)); +} diff --git a/boot1/apps/BootQC/Common/libm/k_cosf.c b/boot1/apps/BootQC/Common/libm/k_cosf.c new file mode 100755 index 0000000..e6cb202 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/k_cosf.c @@ -0,0 +1,22 @@ +/* + * libm/k_cosf.c + */ + +#include + +static const double + one = 1.0, + C0 = -0x1ffffffd0c5e81.0p-54, + C1 = 0x155553e1053a42.0p-57, + C2 = -0x16c087e80f1e27.0p-62, + C3 = 0x199342e0ee5069.0p-68; + +float __kernel_cosdf(double x) +{ + double r, w, z; + + z = x * x; + w = z * z; + r = C2 + z * C3; + return ((one + z * C0) + w * C1) + (w * z) * r; +} diff --git a/boot1/apps/BootQC/Common/libm/k_rem_pio2.c b/boot1/apps/BootQC/Common/libm/k_rem_pio2.c new file mode 100755 index 0000000..23bc8c9 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/k_rem_pio2.c @@ -0,0 +1,226 @@ +/* + * libm/k_rem_pio2.c + */ + +#include + +static const int init_jk[] = { 2, 3, 4, 6 }; + +static const double PIo2[] = { + 1.57079625129699707031e+00, + 7.54978941586159635335e-08, + 5.39030252995776476554e-15, + 3.28200341580791294123e-22, + 1.27065575308067607349e-29, + 1.22933308981111328932e-36, + 2.73370053816464559624e-44, + 2.16741683877804819444e-51, +}; + +static const double + zero = 0.0, + one = 1.0, + two24 = 1.67772160000000000000e+07, + twon24 = 5.96046447753906250000e-08; + +int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, + const s32_t *ipio2) +{ + s32_t jz, jx, jv, jp, jk, carry, n, iq[20], i, j, k, m, q0, ih; + double z, fw, f[20], fq[20], q[20]; + + jk = init_jk[prec]; + jp = jk; + + jx = nx - 1; + jv = (e0 - 3) / 24; + if (jv < 0) + jv = 0; + q0 = e0 - 24 * (jv + 1); + + j = jv - jx; + m = jx + jk; + for (i = 0; i <= m; i++, j++) + f[i] = (j < 0) ? zero : (double) ipio2[j]; + + for (i = 0; i <= jk; i++) + { + for (j = 0, fw = 0.0; j <= jx; j++) + fw += x[j] * f[jx + i - j]; + q[i] = fw; + } + + jz = jk; + recompute: + + for (i = 0, j = jz, z = q[jz]; j > 0; i++, j--) + { + fw = (double) ((s32_t)(twon24 * z)); + iq[i] = (s32_t)(z - two24 * fw); + z = q[j - 1] + fw; + } + + z = scalbn(z, q0); + z -= 8.0 * floor(z * 0.125); + n = (s32_t) z; + z -= (double) n; + ih = 0; + if (q0 > 0) + { + i = (iq[jz - 1] >> (24 - q0)); + n += i; + iq[jz - 1] -= i << (24 - q0); + ih = iq[jz - 1] >> (23 - q0); + } + else if (q0 == 0) + ih = iq[jz - 1] >> 23; + else if (z >= 0.5) + ih = 2; + + if (ih > 0) + { + n += 1; + carry = 0; + for (i = 0; i < jz; i++) + { + j = iq[i]; + if (carry == 0) + { + if (j != 0) + { + carry = 1; + iq[i] = 0x1000000 - j; + } + } + else + iq[i] = 0xffffff - j; + } + if (q0 > 0) + { + switch (q0) + { + case 1: + iq[jz - 1] &= 0x7fffff; + break; + case 2: + iq[jz - 1] &= 0x3fffff; + break; + } + } + if (ih == 2) + { + z = one - z; + if (carry != 0) + z -= scalbn(one, q0); + } + } + + if (z == zero) + { + j = 0; + for (i = jz - 1; i >= jk; i--) + j |= iq[i]; + if (j == 0) + { + for (k = 1; iq[jk - k] == 0; k++); + + for (i = jz + 1; i <= jz + k; i++) + { + f[jx + i] = (double) ipio2[jv + i]; + for (j = 0, fw = 0.0; j <= jx; j++) + fw += x[j] * f[jx + i - j]; + q[i] = fw; + } + jz += k; + goto recompute; + } + } + + if (z == 0.0) + { + jz -= 1; + q0 -= 24; + while (iq[jz] == 0) + { + jz--; + q0 -= 24; + } + } + else + { + z = scalbn(z, -q0); + if (z >= two24) + { + fw = (double) ((s32_t)(twon24 * z)); + iq[jz] = (s32_t)(z - two24 * fw); + jz += 1; + q0 += 24; + iq[jz] = (s32_t) fw; + } + else + iq[jz] = (s32_t) z; + } + + fw = scalbn(one, q0); + for (i = jz; i >= 0; i--) + { + q[i] = fw * (double) iq[i]; + fw *= twon24; + } + + for (i = jz; i >= 0; i--) + { + for (fw = 0.0, k = 0; k <= jp && k <= jz - i; k++) + fw += PIo2[k] * q[i + k]; + fq[jz - i] = fw; + } + + switch (prec) + { + case 0: + fw = 0.0; + for (i = jz; i >= 0; i--) + fw += fq[i]; + y[0] = (ih == 0) ? fw : -fw; + break; + case 1: + case 2: + fw = 0.0; + for (i = jz; i >= 0; i--) + fw += fq[i]; + y[0] = (ih == 0) ? fw : -fw; + fw = fq[0] - fw; + for (i = 1; i <= jz; i++) + fw += fq[i]; + y[1] = (ih == 0) ? fw : -fw; + break; + case 3: + for (i = jz; i > 0; i--) + { + fw = fq[i - 1] + fq[i]; + fq[i] += fq[i - 1] - fw; + fq[i - 1] = fw; + } + for (i = jz; i > 1; i--) + { + fw = fq[i - 1] + fq[i]; + fq[i] += fq[i - 1] - fw; + fq[i - 1] = fw; + } + for (fw = 0.0, i = jz; i >= 2; i--) + fw += fq[i]; + if (ih == 0) + { + y[0] = fq[0]; + y[1] = fq[1]; + y[2] = fw; + } + else + { + y[0] = -fq[0]; + y[1] = -fq[1]; + y[2] = -fw; + } + } + return n & 7; +} diff --git a/boot1/apps/BootQC/Common/libm/k_rem_pio2f.c b/boot1/apps/BootQC/Common/libm/k_rem_pio2f.c new file mode 100755 index 0000000..a70aa7f --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/k_rem_pio2f.c @@ -0,0 +1,229 @@ +/* + * libm/k_rem_pio2f.c + */ + +#include + +static const int init_jk[] = { 4, 7, 9 }; + +static const float PIo2[] = { + 1.5703125000e+00, + 4.5776367188e-04, + 2.5987625122e-05, + 7.5437128544e-08, + 6.0026650317e-11, + 7.3896444519e-13, + 5.3845816694e-15, + 5.6378512969e-18, + 8.3009228831e-20, + 3.2756352257e-22, + 6.3331015649e-25, +}; + +static const float + zero = 0.0, + one = 1.0, + two8 = 2.5600000000e+02, + twon8 = 3.9062500000e-03; + +int __kernel_rem_pio2f(float *x, float *y, int e0, int nx, int prec, + const s32_t *ipio2) +{ + s32_t jz, jx, jv, jp, jk, carry, n, iq[20], i, j, k, m, q0, ih; + float z, fw, f[20], fq[20], q[20]; + + jk = init_jk[prec]; + jp = jk; + + jx = nx - 1; + jv = (e0 - 3) / 8; + if (jv < 0) + jv = 0; + q0 = e0 - 8 * (jv + 1); + + j = jv - jx; + m = jx + jk; + for (i = 0; i <= m; i++, j++) + f[i] = (j < 0) ? zero : (float) ipio2[j]; + + for (i = 0; i <= jk; i++) + { + for (j = 0, fw = 0.0; j <= jx; j++) + fw += x[j] * f[jx + i - j]; + q[i] = fw; + } + + jz = jk; + recompute: + for (i = 0, j = jz, z = q[jz]; j > 0; i++, j--) + { + fw = (float) ((s32_t)(twon8 * z)); + iq[i] = (s32_t)(z - two8 * fw); + z = q[j - 1] + fw; + } + + z = scalbnf(z, q0); + z -= (float) 8.0 * floorf(z * (float) 0.125); + n = (s32_t) z; + z -= (float) n; + ih = 0; + if (q0 > 0) + { + i = (iq[jz - 1] >> (8 - q0)); + n += i; + iq[jz - 1] -= i << (8 - q0); + ih = iq[jz - 1] >> (7 - q0); + } + else if (q0 == 0) + ih = iq[jz - 1] >> 7; + else if (z >= (float) 0.5) + ih = 2; + + if (ih > 0) + { + n += 1; + carry = 0; + for (i = 0; i < jz; i++) + { + j = iq[i]; + if (carry == 0) + { + if (j != 0) + { + carry = 1; + iq[i] = 0x100 - j; + } + } + else + iq[i] = 0xff - j; + } + if (q0 > 0) + { + switch (q0) + { + case 1: + iq[jz - 1] &= 0x7f; + break; + case 2: + iq[jz - 1] &= 0x3f; + break; + } + } + if (ih == 2) + { + z = one - z; + if (carry != 0) + z -= scalbnf(one, q0); + } + } + + if (z == zero) + { + j = 0; + for (i = jz - 1; i >= jk; i--) + j |= iq[i]; + if (j == 0) + { + for (k = 1; iq[jk - k] == 0; k++); + + for (i = jz + 1; i <= jz + k; i++) + { + f[jx + i] = (float) ipio2[jv + i]; + for (j = 0, fw = 0.0; j <= jx; j++) + fw += x[j] * f[jx + i - j]; + q[i] = fw; + } + jz += k; + goto recompute; + } + } + + if (z == (float) 0.0) + { + jz -= 1; + q0 -= 8; + while (iq[jz] == 0) + { + jz--; + q0 -= 8; + } + } + else + { + z = scalbnf(z, -q0); + if (z >= two8) + { + fw = (float) ((s32_t)(twon8 * z)); + iq[jz] = (s32_t)(z - two8 * fw); + jz += 1; + q0 += 8; + iq[jz] = (s32_t) fw; + } + else + iq[jz] = (s32_t) z; + } + + fw = scalbnf(one, q0); + for (i = jz; i >= 0; i--) + { + q[i] = fw * (float) iq[i]; + fw *= twon8; + } + + for (i = jz; i >= 0; i--) + { + for (fw = 0.0, k = 0; k <= jp && k <= jz - i; k++) + fw += PIo2[k] * q[i + k]; + fq[jz - i] = fw; + } + + switch (prec) + { + case 0: + fw = 0.0; + for (i = jz; i >= 0; i--) + fw += fq[i]; + y[0] = (ih == 0) ? fw : -fw; + break; + case 1: + case 2: + fw = 0.0; + for (i = jz; i >= 0; i--) + fw += fq[i]; + fw = *(volatile float *) &fw; + y[0] = (ih == 0) ? fw : -fw; + fw = fq[0] - fw; + for (i = 1; i <= jz; i++) + fw += fq[i]; + y[1] = (ih == 0) ? fw : -fw; + break; + case 3: + for (i = jz; i > 0; i--) + { + fw = fq[i - 1] + fq[i]; + fq[i] += fq[i - 1] - fw; + fq[i - 1] = fw; + } + for (i = jz; i > 1; i--) + { + fw = fq[i - 1] + fq[i]; + fq[i] += fq[i - 1] - fw; + fq[i - 1] = fw; + } + for (fw = 0.0, i = jz; i >= 2; i--) + fw += fq[i]; + if (ih == 0) + { + y[0] = fq[0]; + y[1] = fq[1]; + y[2] = fw; + } + else + { + y[0] = -fq[0]; + y[1] = -fq[1]; + y[2] = -fw; + } + } + return n & 7; +} diff --git a/boot1/apps/BootQC/Common/libm/k_sin.c b/boot1/apps/BootQC/Common/libm/k_sin.c new file mode 100755 index 0000000..6d6e356 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/k_sin.c @@ -0,0 +1,27 @@ +/* + * libm/k_sin.c + */ + +#include + +static const double + half = 5.00000000000000000000e-01, + S1 = -1.66666666666666324348e-01, + S2 = 8.33333333332248946124e-03, + S3 = -1.98412698298579493134e-04, + S4 = 2.75573137070700676789e-06, + S5 = -2.50507602534068634195e-08, + S6 = 1.58969099521155010221e-10; + +double __kernel_sin(double x, double y, int iy) +{ + double z, r, v; + + z = x * x; + v = z * x; + r = S2 + z * (S3 + z * (S4 + z * (S5 + z * S6))); + if (iy == 0) + return x + v * (S1 + z * r); + else + return x - ((z * (half * y - v * r) - y) - v * S1); +} diff --git a/boot1/apps/BootQC/Common/libm/k_sinf.c b/boot1/apps/BootQC/Common/libm/k_sinf.c new file mode 100755 index 0000000..3b03c93 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/k_sinf.c @@ -0,0 +1,22 @@ +/* + * libm/k_sinf.c + */ + +#include + +static const double + S1 = -0x15555554cbac77.0p-55, + S2 = 0x111110896efbb2.0p-59, + S3 = -0x1a00f9e2cae774.0p-65, + S4 = 0x16cd878c3b46a7.0p-71; + +float __kernel_sindf(double x) +{ + double r, s, w, z; + + z = x * x; + w = z * z; + r = S3 + z * S4; + s = z * x; + return (x + s * (S1 + z * S2)) + s * w * r; +} diff --git a/boot1/apps/BootQC/Common/libm/k_tan.c b/boot1/apps/BootQC/Common/libm/k_tan.c new file mode 100755 index 0000000..d9dc15b --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/k_tan.c @@ -0,0 +1,79 @@ +/* + * libm/k_tan.c + */ + +#include + +static const double xxx[] = { + 3.33333333333334091986e-01, + 1.33333333333201242699e-01, + 5.39682539762260521377e-02, + 2.18694882948595424599e-02, + 8.86323982359930005737e-03, + 3.59207910759131235356e-03, + 1.45620945432529025516e-03, + 5.88041240820264096874e-04, + 2.46463134818469906812e-04, + 7.81794442939557092300e-05, + 7.14072491382608190305e-05, + -1.85586374855275456654e-05, + 2.59073051863633712884e-05, + 1.00000000000000000000e+00, + 7.85398163397448278999e-01, + 3.06161699786838301793e-17 +}; + +#define one xxx[13] +#define pio4 xxx[14] +#define pio4lo xxx[15] +#define T xxx + +double __kernel_tan(double x, double y, int iy) +{ + double z, r, v, w, s; + s32_t ix, hx; + + GET_HIGH_WORD(hx,x); + ix = hx & 0x7fffffff; + if (ix >= 0x3FE59428) + { + if (hx < 0) + { + x = -x; + y = -y; + } + z = pio4 - x; + w = pio4lo - y; + x = z + w; + y = 0.0; + } + z = x * x; + w = z * z; + + r = T[1] + w * (T[3] + w * (T[5] + w * (T[7] + w * (T[9] + w * T[11])))); + v = z * (T[2] + w * (T[4] + w * (T[6] + w + * (T[8] + w * (T[10] + w * T[12]))))); + s = z * x; + r = y + z * (s * (r + v) + y); + r += T[0] * s; + w = x + r; + if (ix >= 0x3FE59428) + { + v = (double) iy; + return (double) (1 - ((hx >> 30) & 2)) * (v - 2.0 * (x - (w * w / (w + + v) - r))); + } + if (iy == 1) + return w; + else + { + double a, t; + z = w; + SET_LOW_WORD(z,0); + v = r - (z - x); + t = a = -1.0 / w; + SET_LOW_WORD(t,0); + s = 1.0 + t * z; + return t + a * (s + t * v); + } +} diff --git a/boot1/apps/BootQC/Common/libm/k_tanf.c b/boot1/apps/BootQC/Common/libm/k_tanf.c new file mode 100755 index 0000000..08f528a --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/k_tanf.c @@ -0,0 +1,32 @@ +/* + * libm/k_tanf.c + */ + +#include + +static const double T[] = { + 0x15554d3418c99f.0p-54, + 0x1112fd38999f72.0p-55, + 0x1b54c91d865afe.0p-57, + 0x191df3908c33ce.0p-58, + 0x185dadfcecf44e.0p-61, + 0x1362b9bf971bcd.0p-59, +}; + +float __kernel_tandf(double x, int iy) +{ + double z, r, w, s, t, u; + + z = x * x; + + r = T[4] + z * T[5]; + t = T[2] + z * T[3]; + w = z * z; + s = z * x; + u = T[0] + z * T[1]; + r = (x + s * u) + (s * w) * (t + w * r); + if (iy == 1) + return r; + else + return -1.0 / r; +} diff --git a/boot1/apps/BootQC/Common/libm/log.c b/boot1/apps/BootQC/Common/libm/log.c new file mode 100755 index 0000000..e68ee01 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/log.c @@ -0,0 +1,95 @@ +/* + * libm/log.c + */ + + +#include + +static const double + ln2_hi = 6.93147180369123816490e-01, + ln2_lo = 1.90821492927058770002e-10, + two54 = 1.80143985094819840000e+16, + Lg1 = 6.666666666666735130e-01, + Lg2 = 3.999999999940941908e-01, + Lg3 = 2.857142874366239149e-01, + Lg4 = 2.222219843214978396e-01, + Lg5 = 1.818357216161805012e-01, + Lg6 = 1.531383769920937332e-01, + Lg7 = 1.479819860511658591e-01; + +static const double zero = 0.0; + +double log(double x) +{ + double hfsq, f, s, z, R, w, t1, t2, dk; + s32_t k, hx, i, j; + u32_t lx; + + EXTRACT_WORDS(hx,lx,x); + + k = 0; + if (hx < 0x00100000) + { + if (((hx & 0x7fffffff) | lx) == 0) + return -two54 / zero; + if (hx < 0) + return (x - x) / zero; + k -= 54; + x *= two54; + GET_HIGH_WORD(hx,x); + } + if (hx >= 0x7ff00000) + return x + x; + k += (hx >> 20) - 1023; + hx &= 0x000fffff; + i = (hx + 0x95f64) & 0x100000; + SET_HIGH_WORD(x,hx|(i^0x3ff00000)); + k += (i >> 20); + f = x - 1.0; + if ((0x000fffff & (2 + hx)) < 3) + { + if (f == zero) + { + if (k == 0) + return zero; + else + { + dk = (double) k; + return dk * ln2_hi + dk * ln2_lo; + } + } + R = f * f * (0.5 - 0.33333333333333333 * f); + if (k == 0) + return f - R; + else + { + dk = (double) k; + return dk * ln2_hi - ((R - dk * ln2_lo) - f); + } + } + s = f / (2.0 + f); + dk = (double) k; + z = s * s; + i = hx - 0x6147a; + w = z * z; + j = 0x6b851 - hx; + t1 = w * (Lg2 + w * (Lg4 + w * Lg6)); + t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7))); + i |= j; + R = t2 + t1; + if (i > 0) + { + hfsq = 0.5 * f * f; + if (k == 0) + return f - (hfsq - s * (hfsq + R)); + else + return dk * ln2_hi - ((hfsq - (s * (hfsq + R) + dk * ln2_lo)) - f); + } + else + { + if (k == 0) + return f - s * (f - R); + else + return dk * ln2_hi - ((s * (f - R) - dk * ln2_lo) - f); + } +} diff --git a/boot1/apps/BootQC/Common/libm/log10.c b/boot1/apps/BootQC/Common/libm/log10.c new file mode 100755 index 0000000..49a10fd --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/log10.c @@ -0,0 +1,45 @@ +/* + * libm/log10.c + */ + + +#include + +static const double + two54 = 1.80143985094819840000e+16, + ivln10 = 4.34294481903251816668e-01, + log10_2hi = 3.01029995663611771306e-01, + log10_2lo = 3.69423907715893078616e-13; + +static const double zero = 0.0; + +double log10(double x) +{ + double y, z; + s32_t i, k, hx; + u32_t lx; + + EXTRACT_WORDS(hx,lx,x); + + k = 0; + if (hx < 0x00100000) + { + if (((hx & 0x7fffffff) | lx) == 0) + return -two54 / zero; + if (hx < 0) + return (x - x) / zero; + k -= 54; + x *= two54; + GET_HIGH_WORD(hx,x); + } + if (hx >= 0x7ff00000) + return x + x; + k += (hx >> 20) - 1023; + i = ((u32_t) k & 0x80000000) >> 31; + hx = (hx & 0x000fffff) | ((0x3ff - i) << 20); + y = (double) (k + i); + SET_HIGH_WORD(x,hx); + z = y * log10_2lo + ivln10 * log(x); + return z + y * log10_2hi; +} + diff --git a/boot1/apps/BootQC/Common/libm/log10f.c b/boot1/apps/BootQC/Common/libm/log10f.c new file mode 100755 index 0000000..0c141c1 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/log10f.c @@ -0,0 +1,42 @@ +/* + * libm/log10f.c + */ + +#include + +static const float + two25 = 3.3554432000e+07, + ivln10 = 4.3429449201e-01, + log10_2hi = 3.0102920532e-01, + log10_2lo = 7.9034151668e-07; + +static const float zero = 0.0; + +float log10f(float x) +{ + float y, z; + s32_t i, k, hx; + + GET_FLOAT_WORD(hx,x); + + k = 0; + if (hx < 0x00800000) + { + if ((hx & 0x7fffffff) == 0) + return -two25 / zero; + if (hx < 0) + return (x - x) / zero; + k -= 25; + x *= two25; + GET_FLOAT_WORD(hx,x); + } + if (hx >= 0x7f800000) + return x + x; + k += (hx >> 23) - 127; + i = ((u32_t) k & 0x80000000) >> 31; + hx = (hx & 0x007fffff) | ((0x7f - i) << 23); + y = (float) (k + i); + SET_FLOAT_WORD(x,hx); + z = y * log10_2lo + ivln10 * logf(x); + return z + y * log10_2hi; +} diff --git a/boot1/apps/BootQC/Common/libm/logf.c b/boot1/apps/BootQC/Common/libm/logf.c new file mode 100755 index 0000000..302135d --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/logf.c @@ -0,0 +1,91 @@ +/* + * libm/logf.c + */ + +#include + +static const float + ln2_hi = 6.9313812256e-01, + ln2_lo = 9.0580006145e-06, + two25 = 3.355443200e+07, + Lg1 = 0xaaaaaa.0p-24, + Lg2 = 0xccce13.0p-25, + Lg3 = 0x91e9ee.0p-25, + Lg4 = 0xf89e26.0p-26; + +static const float zero = 0.0; + +float logf(float x) +{ + float hfsq, f, s, z, R, w, t1, t2, dk; + s32_t k, ix, i, j; + + GET_FLOAT_WORD(ix,x); + + k = 0; + if (ix < 0x00800000) + { + if ((ix & 0x7fffffff) == 0) + return -two25 / zero; + if (ix < 0) + return (x - x) / zero; + k -= 25; + x *= two25; + GET_FLOAT_WORD(ix,x); + } + if (ix >= 0x7f800000) + return x + x; + k += (ix >> 23) - 127; + ix &= 0x007fffff; + i = (ix + (0x95f64 << 3)) & 0x800000; + SET_FLOAT_WORD(x,ix|(i^0x3f800000)); + k += (i >> 23); + f = x - (float) 1.0; + if ((0x007fffff & (15 + ix)) < 16) + { + if (f == zero) + { + if (k == 0) + return zero; + else + { + dk = (float) k; + return dk * ln2_hi + dk * ln2_lo; + } + } + R = f * f * ((float) 0.5 - (float) 0.33333333333333333 * f); + if (k == 0) + return f - R; + else + { + dk = (float) k; + return dk * ln2_hi - ((R - dk * ln2_lo) - f); + } + } + s = f / ((float) 2.0 + f); + dk = (float) k; + z = s * s; + i = ix - (0x6147a << 3); + w = z * z; + j = (0x6b851 << 3) - ix; + t1 = w * (Lg2 + w * Lg4); + t2 = z * (Lg1 + w * Lg3); + i |= j; + R = t2 + t1; + if (i > 0) + { + hfsq = (float) 0.5 * f * f; + if (k == 0) + return f - (hfsq - s * (hfsq + R)); + else + return dk * ln2_hi - ((hfsq - (s * (hfsq + R) + dk * ln2_lo)) - f); + } + else + { + if (k == 0) + return f - s * (f - R); + else + return dk * ln2_hi - ((s * (f - R) - dk * ln2_lo) - f); + } +} + diff --git a/boot1/apps/BootQC/Common/libm/math.h b/boot1/apps/BootQC/Common/libm/math.h new file mode 100755 index 0000000..6b21ccb --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/math.h @@ -0,0 +1,258 @@ +#ifndef __MATH_H__ +#define __MATH_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +typedef signed char s8_t; +typedef unsigned char u8_t; + +typedef signed short s16_t; +typedef unsigned short u16_t; + +typedef signed int s32_t; +typedef unsigned int u32_t; + +typedef signed long long s64_t; +typedef unsigned long long u64_t; + +typedef signed long long intmax_t; +typedef unsigned long long uintmax_t; + +typedef signed int ptrdiff_t; +typedef signed int intptr_t; +typedef unsigned int uintptr_t; + +typedef unsigned int size_t; +typedef signed int ssize_t; + +typedef signed int off_t; +typedef signed long long loff_t; + +typedef unsigned int clock_t; +typedef signed int time_t; + +typedef signed int bool_t; + +typedef signed int register_t; +typedef unsigned int irq_flags_t; + +typedef unsigned int virtual_addr_t; +typedef unsigned int virtual_size_t; +typedef unsigned int physical_addr_t; +typedef unsigned int physical_size_t; + +typedef struct { + volatile long counter; +} atomic_t; + +typedef struct { + volatile long lock; +} spinlock_t; + + +typedef union { + double value; + struct { + u32_t lsw; + u32_t msw; + } parts; +} ieee_double_shape_type; + + +/* + * Get two 32 bit ints from a double + */ +#define EXTRACT_WORDS(ix0,ix1,d) \ +do { \ + ieee_double_shape_type ew_u; \ + ew_u.value = (d); \ + (ix0) = ew_u.parts.msw; \ + (ix1) = ew_u.parts.lsw; \ +} while (0) + +/* + * Get the more significant 32 bit int from a double + */ +#define GET_HIGH_WORD(i,d) \ +do { \ + ieee_double_shape_type gh_u; \ + gh_u.value = (d); \ + (i) = gh_u.parts.msw; \ +} while (0) + +/* + * Get the less significant 32 bit int from a double + */ +#define GET_LOW_WORD(i,d) \ +do { \ + ieee_double_shape_type gl_u; \ + gl_u.value = (d); \ + (i) = gl_u.parts.lsw; \ +} while (0) + +/* + * Set a double from two 32 bit ints + */ +#define INSERT_WORDS(d,ix0,ix1) \ +do { \ + ieee_double_shape_type iw_u; \ + iw_u.parts.msw = (ix0); \ + iw_u.parts.lsw = (ix1); \ + (d) = iw_u.value; \ +} while (0) + +/* + * Set the more significant 32 bits of a double from an int + */ +#define SET_HIGH_WORD(d,v) \ +do { \ + ieee_double_shape_type sh_u; \ + sh_u.value = (d); \ + sh_u.parts.msw = (v); \ + (d) = sh_u.value; \ +} while (0) + +/* + * Set the less significant 32 bits of a double from an int + */ +#define SET_LOW_WORD(d,v) \ +do { \ + ieee_double_shape_type sl_u; \ + sl_u.value = (d); \ + sl_u.parts.lsw = (v); \ + (d) = sl_u.value; \ +} while (0) + +/* + * A union which permits us to convert between a float and a 32 bit int + */ +typedef union { + float value; + u32_t word; +} ieee_float_shape_type; + +/* + * Get a 32 bit int from a float + */ +#define GET_FLOAT_WORD(i,d) \ +do { \ + ieee_float_shape_type gf_u; \ + gf_u.value = (d); \ + (i) = gf_u.word; \ +} while (0) + +/* + * Set a float from a 32 bit int + */ +#define SET_FLOAT_WORD(d,i) \ +do { \ + ieee_float_shape_type sf_u; \ + sf_u.word = (i); \ + (d) = sf_u.value; \ +} while (0) + +#define M_E 2.7182818284590452354 /* e */ +#define M_LOG2E 1.4426950408889634074 /* log 2e */ +#define M_LOG10E 0.43429448190325182765 /* log 10e */ +#define M_LN2 0.69314718055994530942 /* log e2 */ +#define M_LN10 2.30258509299404568402 /* log e10 */ +#define M_PI 3.14159265358979323846 /* pi */ +#define M_PI_2 1.57079632679489661923 /* pi/2 */ +#define M_PI_4 0.78539816339744830962 /* pi/4 */ +#define M_1_PI 0.31830988618379067154 /* 1/pi */ +#define M_2_PI 0.63661977236758134308 /* 2/pi */ +#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ +#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ +#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ + +#define HUGE_VAL __builtin_huge_val() + +/* + * fdlibm kernel function + */ +s32_t __ieee754_rem_pio2(double x, double *y); +int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const s32_t *ipio2); +double __kernel_sin(double x, double y, int iy); +double __kernel_cos(double x, double y); +double __kernel_tan(double x, double y, int iy); + +/* + * float versions of fdlibm kernel functions + */ +s32_t __ieee754_rem_pio2f(float x, float *y); +int __kernel_rem_pio2f(float *x, float *y, int e0, int nx, int prec, const s32_t *ipio2); +float __kernel_sindf(double x); +float __kernel_cosdf(double x); +float __kernel_tandf(double x, int iy); + + +double copysign(double x, double y); +float copysignf(float x, float y); + +double scalbn(double x, int n); +double ldexp(double x, int n); + +float scalbnf(float x, int n); +float ldexpf(float x, int n); + +double expm1(double x); +float expm1f(float x); + + +double fabs(double x); +float fabsf(float x); +double ceil(double x); +float ceilf(float x); +double floor(double x); +float floorf(float x); +double modf(double x, double *iptr); +float modff(float x, float *iptr); +double frexp(double x, int *eptr); +float frexpf(float x, int *eptr); + +double sqrt(double x); +float sqrtf(float x); +double exp(double x); +float expf(float x); +double fmod(double x, double y); +float fmodf(float x, float y); +double pow(double x, double y); +float powf(float x, float y); +double log(double x); +float logf(float x); +double log10(double x); +float log10f(float x); +double hypot(double x, double y); +float hypotf(float x, float y); + +double sin(double x); +float sinf(float x); +double cos(double x); +float cosf(float x); +double tan(double x); +float tanf(float x); + +double sinh(double x); +float sinhf(float x); +double cosh(double x); +float coshf(float x); +double tanh(double x); +float tanhf(float x); + +double asin(double x); +float asinf(float x); +double acos(double x); +float acosf(float x); +double atan(double x); +float atanf(float x); +double atan2(double y, double x); +float atan2f(float y, float x); + +#ifdef __cplusplus +} +#endif + +#endif /* __MATH_H__ */ diff --git a/boot1/apps/BootQC/Common/libm/modf.c b/boot1/apps/BootQC/Common/libm/modf.c new file mode 100755 index 0000000..d3679ac --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/modf.c @@ -0,0 +1,68 @@ +/* + * libm/modf.c + */ + + +#include + +static const double one = 1.0; + +double modf(double x, double *iptr) +{ + s32_t i0, i1, j0; + u32_t i; + + EXTRACT_WORDS(i0,i1,x); + j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; + if (j0 < 20) + { + if (j0 < 0) + { + INSERT_WORDS(*iptr,i0&0x80000000,0); + return x; + } + else + { + i = (0x000fffff) >> j0; + if (((i0 & i) | i1) == 0) + { + u32_t high; + *iptr = x; + GET_HIGH_WORD(high,x); + INSERT_WORDS(x,high&0x80000000,0); + return x; + } + else + { + INSERT_WORDS(*iptr,i0&(~i),0); + return x - *iptr; + } + } + } + else if (j0 > 51) + { + u32_t high; + *iptr = x * one; + GET_HIGH_WORD(high,x); + INSERT_WORDS(x,high&0x80000000,0); + return x; + } + else + { + i = ((u32_t)(0xffffffff)) >> (j0 - 20); + if ((i1 & i) == 0) + { + u32_t high; + *iptr = x; + GET_HIGH_WORD(high,x); + INSERT_WORDS(x,high&0x80000000,0); + return x; + } + else + { + INSERT_WORDS(*iptr,i0,i1&(~i)); + return x - *iptr; + } + } +} + diff --git a/boot1/apps/BootQC/Common/libm/modff.c b/boot1/apps/BootQC/Common/libm/modff.c new file mode 100755 index 0000000..bae6f79 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/modff.c @@ -0,0 +1,51 @@ +/* + * libm/modff.c + */ + + +#include + +static const float one = 1.0; + +float modff(float x, float *iptr) +{ + s32_t i0, j0; + u32_t i; + + GET_FLOAT_WORD(i0,x); + j0 = ((i0 >> 23) & 0xff) - 0x7f; + if (j0 < 23) + { + if (j0 < 0) + { + SET_FLOAT_WORD(*iptr,i0&0x80000000); + return x; + } + else + { + i = (0x007fffff) >> j0; + if ((i0 & i) == 0) + { + u32_t ix; + *iptr = x; + GET_FLOAT_WORD(ix,x); + SET_FLOAT_WORD(x,ix&0x80000000); + return x; + } + else + { + SET_FLOAT_WORD(*iptr,i0&(~i)); + return x - *iptr; + } + } + } + else + { + u32_t ix; + *iptr = x * one; + GET_FLOAT_WORD(ix,x); + SET_FLOAT_WORD(x,ix&0x80000000); + return x; + } +} + diff --git a/boot1/apps/BootQC/Common/libm/pow.c b/boot1/apps/BootQC/Common/libm/pow.c new file mode 100755 index 0000000..3f7684f --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/pow.c @@ -0,0 +1,276 @@ +/* + * libm/pow.c + */ + + +#include + +static const double + bp[] = { 1.0, 1.5, }, + dp_h[] = { 0.0, 5.84962487220764160156e-01, }, + dp_l[] = { 0.0, 1.35003920212974897128e-08, }, + zero = 0.0, + one = 1.0, + two = 2.0, + two53 = 9007199254740992.0, + huge = 1.0e300, + tiny = 1.0e-300, + L1 = 5.99999999999994648725e-01, + L2 = 4.28571428578550184252e-01, + L3 = 3.33333329818377432918e-01, + L4 = 2.72728123808534006489e-01, + L5 = 2.30660745775561754067e-01, + L6 = 2.06975017800338417784e-01, + P1 = 1.66666666666666019037e-01, + P2 = -2.77777777770155933842e-03, + P3 = 6.61375632143793436117e-05, + P4 = -1.65339022054652515390e-06, + P5 = 4.13813679705723846039e-08, + lg2 = 6.93147180559945286227e-01, + lg2_h = 6.93147182464599609375e-01, + lg2_l = -1.90465429995776804525e-09, + ovt = 8.0085662595372944372e-0017, + cp = 9.61796693925975554329e-01, + cp_h = 9.61796700954437255859e-01, + cp_l = -7.02846165095275826516e-09, + ivln2 = 1.44269504088896338700e+00, + ivln2_h = 1.44269502162933349609e+00, + ivln2_l = 1.92596299112661746887e-08; + +double pow(double x, double y) +{ + double z, ax, z_h, z_l, p_h, p_l; + double y1, t1, t2, r, s, t, u, v, w; + s32_t i, j, k, yisint, n; + s32_t hx, hy, ix, iy; + u32_t lx, ly; + + EXTRACT_WORDS(hx,lx,x); + EXTRACT_WORDS(hy,ly,y); + ix = hx & 0x7fffffff; + iy = hy & 0x7fffffff; + + if ((iy | ly) == 0) + return one; + + if (ix > 0x7ff00000 || ((ix == 0x7ff00000) && (lx != 0)) || iy > 0x7ff00000 + || ((iy == 0x7ff00000) && (ly != 0))) + return x + y; + + yisint = 0; + if (hx < 0) + { + if (iy >= 0x43400000) + yisint = 2; + else if (iy >= 0x3ff00000) + { + k = (iy >> 20) - 0x3ff; + if (k > 20) + { + j = ly >> (52 - k); + if ((j << (52 - k)) == ly) + yisint = 2 - (j & 1); + } + else if (ly == 0) + { + j = iy >> (20 - k); + if ((j << (20 - k)) == iy) + yisint = 2 - (j & 1); + } + } + } + + if (ly == 0) + { + if (iy == 0x7ff00000) + { + if (((ix - 0x3ff00000) | lx) == 0) + return y - y; + else if (ix >= 0x3ff00000) + return (hy >= 0) ? y : zero; + else + return (hy < 0) ? -y : zero; + } + if (iy == 0x3ff00000) + { + if (hy < 0) + return one / x; + else + return x; + } + if (hy == 0x40000000) + return x * x; + if (hy == 0x3fe00000) + { + if (hx >= 0) + return sqrt(x); + } + } + + ax = fabs(x); + if (lx == 0) + { + if (ix == 0x7ff00000 || ix == 0 || ix == 0x3ff00000) + { + z = ax; + if (hy < 0) + z = one / z; + if (hx < 0) + { + if (((ix - 0x3ff00000) | yisint) == 0) + { + z = (z - z) / (z - z); + } + else if (yisint == 1) + z = -z; + } + return z; + } + } + + n = ((u32_t) hx >> 31) - 1; + + if ((n | yisint) == 0) + return (x - x) / (x - x); + + s = one; + if ((n | (yisint - 1)) == 0) + s = -one; + + if (iy > 0x41e00000) + { + if (iy > 0x43f00000) + { + if (ix <= 0x3fefffff) + return (hy < 0) ? huge * huge : tiny * tiny; + if (ix >= 0x3ff00000) + return (hy > 0) ? huge * huge : tiny * tiny; + } + if (ix < 0x3fefffff) + return (hy < 0) ? s * huge * huge : s * tiny * tiny; + if (ix > 0x3ff00000) + return (hy > 0) ? s * huge * huge : s * tiny * tiny; + t = ax - one; + w = (t * t) * (0.5 - t * (0.3333333333333333333333 - t * 0.25)); + u = ivln2_h * t; + v = t * ivln2_l - w * ivln2; + t1 = u + v; + SET_LOW_WORD(t1,0); + t2 = v - (t1 - u); + } + else + { + double ss, s2, s_h, s_l, t_h, t_l; + n = 0; + if (ix < 0x00100000) + { + ax *= two53; + n -= 53; + GET_HIGH_WORD(ix,ax); + } + n += ((ix) >> 20) - 0x3ff; + j = ix & 0x000fffff; + ix = j | 0x3ff00000; + if (j <= 0x3988E) + k = 0; + else if (j < 0xBB67A) + k = 1; + else + { + k = 0; + n += 1; + ix -= 0x00100000; + } + SET_HIGH_WORD(ax,ix); + + u = ax - bp[k]; + v = one / (ax + bp[k]); + ss = u * v; + s_h = ss; + SET_LOW_WORD(s_h,0); + t_h = zero; + SET_HIGH_WORD(t_h,((ix>>1)|0x20000000)+0x00080000+(k<<18)); + t_l = ax - (t_h - bp[k]); + s_l = v * ((u - s_h * t_h) - s_h * t_l); + s2 = ss * ss; + r = s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 + * (L5 + s2 * L6))))); + r += s_l * (s_h + ss); + s2 = s_h * s_h; + t_h = 3.0 + s2 + r; + SET_LOW_WORD(t_h,0); + t_l = r - ((t_h - 3.0) - s2); + u = s_h * t_h; + v = s_l * t_h + t_l * ss; + p_h = u + v; + SET_LOW_WORD(p_h,0); + p_l = v - (p_h - u); + z_h = cp_h * p_h; + z_l = cp_l * p_h + p_l * cp + dp_l[k]; + + t = (double) n; + t1 = (((z_h + z_l) + dp_h[k]) + t); + SET_LOW_WORD(t1,0); + t2 = z_l - (((t1 - t) - dp_h[k]) - z_h); + } + + y1 = y; + SET_LOW_WORD(y1,0); + p_l = (y - y1) * t1 + y * t2; + p_h = y1 * t1; + z = p_l + p_h; + EXTRACT_WORDS(j,i,z); + if (j >= 0x40900000) + { + if (((j - 0x40900000) | i) != 0) + return s * huge * huge; + else + { + if (p_l + ovt > z - p_h) + return s * huge * huge; + } + } + else if ((j & 0x7fffffff) >= 0x4090cc00) + { + if (((j - 0xc090cc00) | i) != 0) + return s * tiny * tiny; + else + { + if (p_l <= z - p_h) + return s * tiny * tiny; + } + } + + i = j & 0x7fffffff; + k = (i >> 20) - 0x3ff; + n = 0; + if (i > 0x3fe00000) + { + n = j + (0x00100000 >> (k + 1)); + k = ((n & 0x7fffffff) >> 20) - 0x3ff; + t = zero; + SET_HIGH_WORD(t,n&~(0x000fffff>>k)); + n = ((n & 0x000fffff) | 0x00100000) >> (20 - k); + if (j < 0) + n = -n; + p_h -= t; + } + t = p_l + p_h; + SET_LOW_WORD(t,0); + u = t * lg2_h; + v = (p_l - (t - p_h)) * lg2 + t * lg2_l; + z = u + v; + w = v - (z - u); + t = z * z; + t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); + r = (z * t1) / (t1 - two) - (w + z * w); + z = one - (r - z); + GET_HIGH_WORD(j,z); + j += (n << 20); + if ((j >> 20) <= 0) + z = scalbn(z, n); + else + SET_HIGH_WORD(z,j); + return s * z; +} + diff --git a/boot1/apps/BootQC/Common/libm/powf.c b/boot1/apps/BootQC/Common/libm/powf.c new file mode 100755 index 0000000..3c49df1 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/powf.c @@ -0,0 +1,258 @@ +/* + * libm/powf.c + */ + +#include + +static const float + bp[] = { 1.0, 1.5, }, + dp_h[] = { 0.0, 5.84960938e-01, }, + dp_l[] = { 0.0, 1.56322085e-06, }, + zero = 0.0, + one = 1.0, + two = 2.0, + two24 = 16777216.0, + huge = 1.0e30, + tiny = 1.0e-30, + L1 = 6.0000002384e-01, + L2 = 4.2857143283e-01, + L3 = 3.3333334327e-01, + L4 = 2.7272811532e-01, + L5 = 2.3066075146e-01, + L6 = 2.0697501302e-01, + P1 = 1.6666667163e-01, + P2 = -2.7777778450e-03, + P3 = 6.6137559770e-05, + P4 = -1.6533901999e-06, + P5 = 4.1381369442e-08, + lg2 = 6.9314718246e-01, + lg2_h = 6.93145752e-01, + lg2_l = 1.42860654e-06, + ovt = 4.2995665694e-08, + cp = 9.6179670095e-01, + cp_h = 9.6179199219e-01, + cp_l = 4.7017383622e-06, + ivln2 = 1.4426950216e+00, + ivln2_h = 1.4426879883e+00, + ivln2_l = 7.0526075433e-06; + +float powf(float x, float y) +{ + float z, ax, z_h, z_l, p_h, p_l; + float y1, t1, t2, r, s, sn, t, u, v, w; + s32_t i, j, k, yisint, n; + s32_t hx, hy, ix, iy, is; + + GET_FLOAT_WORD(hx,x); + GET_FLOAT_WORD(hy,y); + ix = hx & 0x7fffffff; + iy = hy & 0x7fffffff; + + if (iy == 0) + return one; + + if (ix > 0x7f800000 || iy > 0x7f800000) + return x + y; + + yisint = 0; + if (hx < 0) + { + if (iy >= 0x4b800000) + yisint = 2; + else if (iy >= 0x3f800000) + { + k = (iy >> 23) - 0x7f; + j = iy >> (23 - k); + if ((j << (23 - k)) == iy) + yisint = 2 - (j & 1); + } + } + + if (iy == 0x7f800000) + { + if (ix == 0x3f800000) + return y - y; + else if (ix > 0x3f800000) + return (hy >= 0) ? y : zero; + else + return (hy < 0) ? -y : zero; + } + if (iy == 0x3f800000) + { + if (hy < 0) + return one / x; + else + return x; + } + if (hy == 0x40000000) + return x * x; + if (hy == 0x3f000000) + { + if (hx >= 0) + return sqrtf(x); + } + + ax = fabsf(x); + + if (ix == 0x7f800000 || ix == 0 || ix == 0x3f800000) + { + z = ax; + if (hy < 0) + z = one / z; + if (hx < 0) + { + if (((ix - 0x3f800000) | yisint) == 0) + { + z = (z - z) / (z - z); + } + else if (yisint == 1) + z = -z; + } + return z; + } + + n = ((u32_t) hx >> 31) - 1; + + if ((n | yisint) == 0) + return (x - x) / (x - x); + + sn = one; + if ((n | (yisint - 1)) == 0) + sn = -one; + + if (iy > 0x4d000000) + { + if (ix < 0x3f7ffff8) + return (hy < 0) ? sn * huge * huge : sn * tiny * tiny; + if (ix > 0x3f800007) + return (hy > 0) ? sn * huge * huge : sn * tiny * tiny; + + t = ax - 1; + w = (t * t) * ((float) 0.5 - t * ((float) 0.333333333333 - t + * (float) 0.25)); + u = ivln2_h * t; + v = t * ivln2_l - w * ivln2; + t1 = u + v; + GET_FLOAT_WORD(is,t1); + SET_FLOAT_WORD(t1,is&0xfffff000); + t2 = v - (t1 - u); + } + else + { + float s2, s_h, s_l, t_h, t_l; + n = 0; + + if (ix < 0x00800000) + { + ax *= two24; + n -= 24; + GET_FLOAT_WORD(ix,ax); + } + n += ((ix) >> 23) - 0x7f; + j = ix & 0x007fffff; + + ix = j | 0x3f800000; + if (j <= 0x1cc471) + k = 0; + else if (j < 0x5db3d7) + k = 1; + else + { + k = 0; + n += 1; + ix -= 0x00800000; + } + SET_FLOAT_WORD(ax,ix); + + u = ax - bp[k]; + v = one / (ax + bp[k]); + s = u * v; + s_h = s; + GET_FLOAT_WORD(is,s_h); + SET_FLOAT_WORD(s_h,is&0xfffff000); + + is = ((ix >> 1) & 0xfffff000) | 0x20000000; + SET_FLOAT_WORD(t_h,is+0x00400000+(k<<21)); + t_l = ax - (t_h - bp[k]); + s_l = v * ((u - s_h * t_h) - s_h * t_l); + + s2 = s * s; + r = s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 + * (L5 + s2 * L6))))); + r += s_l * (s_h + s); + s2 = s_h * s_h; + t_h = (float) 3.0 + s2 + r; + GET_FLOAT_WORD(is,t_h); + SET_FLOAT_WORD(t_h,is&0xfffff000); + t_l = r - ((t_h - (float) 3.0) - s2); + + u = s_h * t_h; + v = s_l * t_h + t_l * s; + + p_h = u + v; + GET_FLOAT_WORD(is,p_h); + SET_FLOAT_WORD(p_h,is&0xfffff000); + p_l = v - (p_h - u); + z_h = cp_h * p_h; + z_l = cp_l * p_h + p_l * cp + dp_l[k]; + + t = (float) n; + t1 = (((z_h + z_l) + dp_h[k]) + t); + GET_FLOAT_WORD(is,t1); + SET_FLOAT_WORD(t1,is&0xfffff000); + t2 = z_l - (((t1 - t) - dp_h[k]) - z_h); + } + + GET_FLOAT_WORD(is,y); + SET_FLOAT_WORD(y1,is&0xfffff000); + p_l = (y - y1) * t1 + y * t2; + p_h = y1 * t1; + z = p_l + p_h; + GET_FLOAT_WORD(j,z); + if (j > 0x43000000) + return sn * huge * huge; + else if (j == 0x43000000) + { + if (p_l + ovt > z - p_h) + return sn * huge * huge; + } + else if ((j & 0x7fffffff) > 0x43160000) + return sn * tiny * tiny; + else if (j == 0xc3160000) + { + if (p_l <= z - p_h) + return sn * tiny * tiny; + } + + i = j & 0x7fffffff; + k = (i >> 23) - 0x7f; + n = 0; + if (i > 0x3f000000) + { + n = j + (0x00800000 >> (k + 1)); + k = ((n & 0x7fffffff) >> 23) - 0x7f; + SET_FLOAT_WORD(t,n&~(0x007fffff>>k)); + n = ((n & 0x007fffff) | 0x00800000) >> (23 - k); + if (j < 0) + n = -n; + p_h -= t; + } + t = p_l + p_h; + GET_FLOAT_WORD(is,t); + SET_FLOAT_WORD(t,is&0xffff8000); + u = t * lg2_h; + v = (p_l - (t - p_h)) * lg2 + t * lg2_l; + z = u + v; + w = v - (z - u); + t = z * z; + t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); + r = (z * t1) / (t1 - two) - (w + z * w); + z = one - (r - z); + GET_FLOAT_WORD(j,z); + j += (n << 23); + if ((j >> 23) <= 0) + z = scalbnf(z, n); + else + SET_FLOAT_WORD(z,j); + return sn * z; +} diff --git a/boot1/apps/BootQC/Common/libm/scalbn.c b/boot1/apps/BootQC/Common/libm/scalbn.c new file mode 100755 index 0000000..7260f4f --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/scalbn.c @@ -0,0 +1,54 @@ +/* + * libm/scalbn.c + */ + +#include + +static const double + two54 = 1.80143985094819840000e+16, + twom54 = 5.55111512312578270212e-17, + huge = 1.0e+300, tiny = 1.0e-300; + +double scalbn(double x, int n) +{ + s32_t k, hx, lx; + + EXTRACT_WORDS(hx,lx,x); + k = (hx & 0x7ff00000) >> 20; + if (k == 0) + { + if ((lx | (hx & 0x7fffffff)) == 0) + return x; + x *= two54; + GET_HIGH_WORD(hx,x); + k = ((hx & 0x7ff00000) >> 20) - 54; + if (n < -50000) + return tiny * x; + } + if (k == 0x7ff) + return x + x; + k = k + n; + if (k > 0x7fe) + return huge * copysign(huge, x); + if (k > 0) + { + SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); + return x; + } + if (k <= -54) + { + if (n > 50000) + return huge * copysign(huge, x); + else + return tiny * copysign(tiny, x); + } + k += 54; + SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); + + return x * twom54; +} + +double ldexp(double x, int n) +{ + return scalbn(x, n); +} diff --git a/boot1/apps/BootQC/Common/libm/scalbnf.c b/boot1/apps/BootQC/Common/libm/scalbnf.c new file mode 100755 index 0000000..45c9044 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/scalbnf.c @@ -0,0 +1,54 @@ +/* + * libm/scalbnf.c + */ + +#include + +static const float + two25 = 3.355443200e+07, + twom25 = 2.9802322388e-08, + huge = 1.0e+30, tiny = 1.0e-30; + +float scalbnf(float x, int n) +{ + s32_t k, ix; + + GET_FLOAT_WORD(ix,x); + k = (ix & 0x7f800000) >> 23; + if (k == 0) + { + if ((ix & 0x7fffffff) == 0) + return x; + x *= two25; + GET_FLOAT_WORD(ix,x); + k = ((ix & 0x7f800000) >> 23) - 25; + if (n < -50000) + return tiny * x; + } + if (k == 0xff) + return x + x; + k = k + n; + if (k > 0xfe) + return huge * copysignf(huge, x); + if (k > 0) + { + SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); + return x; + } + if (k <= -25) + { + if (n > 50000) + return huge * copysignf(huge, x); + else + return tiny * copysignf(tiny, x); + } + k += 25; + SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); + + return x * twom25; +} + +float ldexpf(float x, int n) +{ + return scalbnf(x, n); +} diff --git a/boot1/apps/BootQC/Common/libm/sin.c b/boot1/apps/BootQC/Common/libm/sin.c new file mode 100755 index 0000000..4f7ac2f --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/sin.c @@ -0,0 +1,43 @@ +/* + * libm/sin.c + */ + + +#include + +double sin(double x) +{ + double y[2], z = 0.0; + s32_t n, ix; + + GET_HIGH_WORD(ix,x); + + ix &= 0x7fffffff; + if (ix <= 0x3fe921fb) + { + if (ix < 0x3e400000) + { + if ((int) x == 0) + return x; + } + return __kernel_sin(x, z, 0); + } + else if (ix >= 0x7ff00000) + return x - x; + else + { + n = __ieee754_rem_pio2(x, y); + switch (n & 3) + { + case 0: + return __kernel_sin(y[0], y[1], 1); + case 1: + return __kernel_cos(y[0], y[1]); + case 2: + return -__kernel_sin(y[0], y[1], 1); + default: + return -__kernel_cos(y[0], y[1]); + } + } +} + diff --git a/boot1/apps/BootQC/Common/libm/sinf.c b/boot1/apps/BootQC/Common/libm/sinf.c new file mode 100755 index 0000000..1b58949 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/sinf.c @@ -0,0 +1,73 @@ +/* + * libm/sinf.c + */ + + +#include + +static const double + s1pio2 = 1 * M_PI_2, + s2pio2 = 2 * M_PI_2, + s3pio2 = 3 * M_PI_2, + s4pio2 = 4 * M_PI_2; + +float sinf(float x) +{ + float y[2]; + s32_t n, hx, ix; + + GET_FLOAT_WORD(hx,x); + ix = hx & 0x7fffffff; + + if (ix <= 0x3f490fda) + { + if (ix < 0x39800000) + if (((int) x) == 0) + return x; + return __kernel_sindf(x); + } + + if (ix <= 0x407b53d1) + { + if (ix <= 0x4016cbe3) + { + if (hx > 0) + return __kernel_cosdf(x - s1pio2); + else + return -__kernel_cosdf(x + s1pio2); + } + else + return __kernel_sindf((hx > 0 ? s2pio2 : -s2pio2) - x); + } + + if (ix <= 0x40e231d5) + { + if (ix <= 0x40afeddf) + { + if (hx > 0) + return -__kernel_cosdf(x - s3pio2); + else + return __kernel_cosdf(x + s3pio2); + } + else + return __kernel_sindf(x + (hx > 0 ? -s4pio2 : s4pio2)); + } + else if (ix >= 0x7f800000) + return x - x; + else + { + n = __ieee754_rem_pio2f(x, y); + switch (n & 3) + { + case 0: + return __kernel_sindf((double) y[0] + y[1]); + case 1: + return __kernel_cosdf((double) y[0] + y[1]); + case 2: + return __kernel_sindf(-(double) y[0] - y[1]); + default: + return -__kernel_cosdf((double) y[0] + y[1]); + } + } +} + diff --git a/boot1/apps/BootQC/Common/libm/sinh.c b/boot1/apps/BootQC/Common/libm/sinh.c new file mode 100755 index 0000000..3c17c5f --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/sinh.c @@ -0,0 +1,51 @@ +/* + * libm/sinh.c + */ + + +#include + +static const double one = 1.0, shuge = 1.0e307; + +double sinh(double x) +{ + double t, w, h; + s32_t ix, jx; + u32_t lx; + + GET_HIGH_WORD(jx,x); + ix = jx & 0x7fffffff; + + if (ix >= 0x7ff00000) + return x + x; + + h = 0.5; + if (jx < 0) + h = -h; + + if (ix < 0x40360000) + { + if (ix < 0x3e300000) + if (shuge + x > one) + return x; + t = expm1(fabs(x)); + if (ix < 0x3ff00000) + return h * (2.0 * t - t * t / (t + one)); + return h * (t + t / (t + one)); + } + + if (ix < 0x40862E42) + return h * exp(fabs(x)); + + GET_LOW_WORD(lx,x); + if (ix < 0x408633CE || ((ix == 0x408633ce) + && (lx <= (u32_t) 0x8fb9f87d))) + { + w = exp(0.5 * fabs(x)); + t = h * w; + return t * w; + } + + return x * shuge; +} + diff --git a/boot1/apps/BootQC/Common/libm/sinhf.c b/boot1/apps/BootQC/Common/libm/sinhf.c new file mode 100755 index 0000000..12b169c --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/sinhf.c @@ -0,0 +1,47 @@ +/* + * libm/sinhf.c + */ + +#include + +static const float one = 1.0, shuge = 1.0e37; + +float sinhf(float x) +{ + float t, w, h; + s32_t ix, jx; + + GET_FLOAT_WORD(jx,x); + ix = jx & 0x7fffffff; + + if (ix >= 0x7f800000) + return x + x; + + h = 0.5; + if (jx < 0) + h = -h; + + if (ix < 0x41100000) + { + if (ix < 0x39800000) + if (shuge + x > one) + return x; + t = expm1f(fabsf(x)); + if (ix < 0x3f800000) + return h * ((float) 2.0 * t - t * t / (t + one)); + return h * (t + t / (t + one)); + } + + if (ix < 0x42b17217) + return h * expf(fabsf(x)); + + if (ix <= 0x42b2d4fc) + { + w = expf((float) 0.5 * fabsf(x)); + t = h * w; + return t * w; + } + + return x * shuge; +} + diff --git a/boot1/apps/BootQC/Common/libm/sqrt.c b/boot1/apps/BootQC/Common/libm/sqrt.c new file mode 100755 index 0000000..27664a0 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/sqrt.c @@ -0,0 +1,125 @@ +/* + * libm/sqrt.c + */ + +#include + +static const double one = 1.0, tiny = 1.0e-300; + +double sqrt(double x) +{ + double z; + s32_t sign = (int) 0x80000000; + s32_t ix0, s0, q, m, t, i; + u32_t r, t1, s1, ix1, q1; + + EXTRACT_WORDS(ix0,ix1,x); + + if ((ix0 & 0x7ff00000) == 0x7ff00000) + { + return x * x + x; + } + + if (ix0 <= 0) + { + if (((ix0 & (~sign)) | ix1) == 0) + return x; + else if (ix0 < 0) + return (x - x) / (x - x); + } + + m = (ix0 >> 20); + if (m == 0) + { + while (ix0 == 0) + { + m -= 21; + ix0 |= (ix1 >> 11); + ix1 <<= 21; + } + for (i = 0; (ix0 & 0x00100000) == 0; i++) + ix0 <<= 1; + m -= i - 1; + ix0 |= (ix1 >> (32 - i)); + ix1 <<= i; + } + m -= 1023; + ix0 = (ix0 & 0x000fffff) | 0x00100000; + if (m & 1) + { + ix0 += ix0 + ((ix1 & sign) >> 31); + ix1 += ix1; + } + m >>= 1; + + ix0 += ix0 + ((ix1 & sign) >> 31); + ix1 += ix1; + q = q1 = s0 = s1 = 0; + r = 0x00200000; + + while (r != 0) + { + t = s0 + r; + if (t <= ix0) + { + s0 = t + r; + ix0 -= t; + q += r; + } + ix0 += ix0 + ((ix1 & sign) >> 31); + ix1 += ix1; + r >>= 1; + } + + r = sign; + while (r != 0) + { + t1 = s1 + r; + t = s0; + if ((t < ix0) || ((t == ix0) && (t1 <= ix1))) + { + s1 = t1 + r; + if (((t1 & sign) == sign) && (s1 & sign) == 0) + s0 += 1; + ix0 -= t; + if (ix1 < t1) + ix0 -= 1; + ix1 -= t1; + q1 += r; + } + ix0 += ix0 + ((ix1 & sign) >> 31); + ix1 += ix1; + r >>= 1; + } + + if ((ix0 | ix1) != 0) + { + z = one - tiny; + if (z >= one) + { + z = one + tiny; + if (q1 == (u32_t) 0xffffffff) + { + q1 = 0; + q += 1; + } + else if (z > one) + { + if (q1 == (u32_t) 0xfffffffe) + q += 1; + q1 += 2; + } + else + q1 += (q1 & 1); + } + } + + ix0 = (q >> 1) + 0x3fe00000; + ix1 = q1 >> 1; + if ((q & 1) == 1) + ix1 |= sign; + ix0 += (m << 20); + + INSERT_WORDS(z,ix0,ix1); + return z; +} diff --git a/boot1/apps/BootQC/Common/libm/sqrtf.c b/boot1/apps/BootQC/Common/libm/sqrtf.c new file mode 100755 index 0000000..ecbd066 --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/sqrtf.c @@ -0,0 +1,80 @@ +/* + * libm/sqrtf.c + */ + + +#include + +static const float one = 1.0, tiny = 1.0e-30; + +float sqrtf(float x) +{ + float z; + s32_t sign = (int) 0x80000000; + s32_t ix, s, q, m, t, i; + u32_t r; + + GET_FLOAT_WORD(ix,x); + + if ((ix & 0x7f800000) == 0x7f800000) + { + return x * x + x; + } + + if (ix <= 0) + { + if ((ix & (~sign)) == 0) + return x; + else if (ix < 0) + return (x - x) / (x - x); + } + + m = (ix >> 23); + if (m == 0) + { + for (i = 0; (ix & 0x00800000) == 0; i++) + ix <<= 1; + m -= i - 1; + } + m -= 127; + ix = (ix & 0x007fffff) | 0x00800000; + if (m & 1) + ix += ix; + m >>= 1; + + ix += ix; + q = s = 0; + r = 0x01000000; + + while (r != 0) + { + t = s + r; + if (t <= ix) + { + s = t + r; + ix -= t; + q += r; + } + ix += ix; + r >>= 1; + } + + if (ix != 0) + { + z = one - tiny; + if (z >= one) + { + z = one + tiny; + if (z > one) + q += 2; + else + q += (q & 1); + } + } + ix = (q >> 1) + 0x3f000000; + ix += (m << 23); + + SET_FLOAT_WORD(z,ix); + return z; +} + diff --git a/boot1/apps/BootQC/Common/libm/tan.c b/boot1/apps/BootQC/Common/libm/tan.c new file mode 100755 index 0000000..52500ff --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/tan.c @@ -0,0 +1,31 @@ +/* + * libm/tan.c + */ + + +#include + +double tan(double x) +{ + double y[2], z = 0.0; + s32_t n, ix; + + GET_HIGH_WORD(ix,x); + + ix &= 0x7fffffff; + if (ix <= 0x3fe921fb) + { + if (ix < 0x3e300000) + if ((int) x == 0) + return x; + return __kernel_tan(x, z, 1); + } + else if (ix >= 0x7ff00000) + return x - x; + else + { + n = __ieee754_rem_pio2(x, y); + return __kernel_tan(y[0], y[1], 1 - ((n & 1) << 1)); + } +} + diff --git a/boot1/apps/BootQC/Common/libm/tanf.c b/boot1/apps/BootQC/Common/libm/tanf.c new file mode 100755 index 0000000..153194b --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/tanf.c @@ -0,0 +1,51 @@ +/* + * libm/tanf.c + */ + + +#include + +static const double + t1pio2 = 1 * M_PI_2, + t2pio2 = 2 * M_PI_2, + t3pio2 = 3 * M_PI_2, + t4pio2 = 4 * M_PI_2; + +float tanf(float x) +{ + float y[2]; + s32_t n, hx, ix; + + GET_FLOAT_WORD(hx,x); + ix = hx & 0x7fffffff; + + if (ix <= 0x3f490fda) + { + if (ix < 0x39800000) + if (((int) x) == 0) + return x; + return __kernel_tandf(x, 1); + } + if (ix <= 0x407b53d1) + { + if (ix <= 0x4016cbe3) + return __kernel_tandf(x + (hx > 0 ? -t1pio2 : t1pio2), -1); + else + return __kernel_tandf(x + (hx > 0 ? -t2pio2 : t2pio2), 1); + } + if (ix <= 0x40e231d5) + { + if (ix <= 0x40afeddf) + return __kernel_tandf(x + (hx > 0 ? -t3pio2 : t3pio2), -1); + else + return __kernel_tandf(x + (hx > 0 ? -t4pio2 : t4pio2), 1); + } + else if (ix >= 0x7f800000) + return x - x; + else + { + n = __ieee754_rem_pio2f(x, y); + return __kernel_tandf((double) y[0] + y[1], 1 - ((n & 1) << 1)); + } +} + diff --git a/boot1/apps/BootQC/Common/libm/tanh.c b/boot1/apps/BootQC/Common/libm/tanh.c new file mode 100755 index 0000000..258382a --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/tanh.c @@ -0,0 +1,46 @@ +/* + * libm/tanh.c + */ + + +#include + +static const double one = 1.0, two = 2.0, tiny = 1.0e-300; + +double tanh(double x) +{ + double t, z; + s32_t jx, ix; + + GET_HIGH_WORD(jx,x); + ix = jx & 0x7fffffff; + + if (ix >= 0x7ff00000) + { + if (jx >= 0) + return one / x + one; + else + return one / x - one; + } + + if (ix < 0x40360000) + { + if (ix < 0x3c800000) + return x * (one + x); + if (ix >= 0x3ff00000) + { + t = expm1(two * fabs(x)); + z = one - two / (t + two); + } + else + { + t = expm1(-two * fabs(x)); + z = -t / (t + two); + } + } + else + { + z = one - tiny; + } + return (jx >= 0) ? z : -z; +} diff --git a/boot1/apps/BootQC/Common/libm/tanhf.c b/boot1/apps/BootQC/Common/libm/tanhf.c new file mode 100755 index 0000000..4cb8dea --- /dev/null +++ b/boot1/apps/BootQC/Common/libm/tanhf.c @@ -0,0 +1,49 @@ +/* + * libm/tanhf.c + */ + +#include + +static const float one = 1.0, two = 2.0, tiny = 1.0e-30, huge = 1.0e30; + +float tanhf(float x) +{ + float t, z; + s32_t jx, ix; + + GET_FLOAT_WORD(jx,x); + ix = jx & 0x7fffffff; + + if (ix >= 0x7f800000) + { + if (jx >= 0) + return one / x + one; + else + return one / x - one; + } + + if (ix < 0x41100000) + { + if (ix < 0x39800000) + { + if (huge + x > one) + return x; + } + if (ix >= 0x3f800000) + { + t = expm1f(two * fabsf(x)); + z = one - two / (t + two); + } + else + { + t = expm1f(-two * fabsf(x)); + z = -t / (t + two); + } + } + else + { + z = one - tiny; + } + return (jx >= 0) ? z : -z; +} + diff --git a/boot1/apps/BootQC/Common/ui/ui.c b/boot1/apps/BootQC/Common/ui/ui.c index e478c69..2c4a3d6 100755 --- a/boot1/apps/BootQC/Common/ui/ui.c +++ b/boot1/apps/BootQC/Common/ui/ui.c @@ -48,26 +48,32 @@ __u32 WORD_SIZE; */ __s32 WaitForDeInitFinish(void) { - __u32 time = 0; + __s32 ret; + __s32 timedly = 2000; + __s32 check_time = timedly/50; - if(De_IsLCDOpen() < 0){ - DMSG_PANIC("ERR: Not need to wait LCD open\n"); - return -1; - } - - /* 最大超时时间为 5s */ - time = 500; - while(!De_IsLCDOpen() && time--) + do { -// DMSG_INFO("[MSG]: Wait for lcd open finish\n"); - wBoot_timer_delay(10); + ret = De_IsLCDOpen(); + if(ret == 1) + { + break; + } + else if(ret == -1) + { + return -1; + } + wBoot_timer_delay(50); + check_time --; + if(check_time <= 0) + { + return -1; + } } - -// if(!time){ -// DMSG_PANIC("ERR: Wait for lcd open finish timeout\n"); -// } + while(1); return 0; + } /* ******************************************************************************* diff --git a/boot1/apps/BootQC/makefile b/boot1/apps/BootQC/makefile index 91f3cd2..e1a3f05 100755 --- a/boot1/apps/BootQC/makefile +++ b/boot1/apps/BootQC/makefile @@ -33,6 +33,7 @@ OBJS=$(SRCCS:.c=.o) $(SRCSS:.S=.o) all:$(LOCALTARGET) $(LOAD) $(LDFLAGS) $(LOCALTARGET) $(TARGET) cp $(TARGET) $(TARGET1) + -rm $(OBJS) $(LTARGET) @echo ---------------------------- @echo target make finish @echo ---------------------------- diff --git a/boot1/apps/BootQC/part_info/part_info.c b/boot1/apps/BootQC/part_info/part_info.c new file mode 100755 index 0000000..17ec6d8 --- /dev/null +++ b/boot1/apps/BootQC/part_info/part_info.c @@ -0,0 +1,86 @@ +/* +************************************************************************************* +* eGon +* Application Of eGon2.0 +* +* (c) Copyright 2006-2010, All winners Co,Ld. +* All Rights Reserved +* +* File Name : Board.c +* +* Author : javen +* +* Description : 启动引导 +* +* History : +*