Commit 4f6ad66a authored by Achin Gupta's avatar Achin Gupta Committed by James Morrissey
Browse files

ARMv8 Trusted Firmware release v0.2

parents
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __PM_H__
#define __PM_H__
#ifndef __ASSEMBLY__
/*******************************************************************************
* Structure populated by platform specific code to export routines which
* perform common low level pm functions
******************************************************************************/
typedef struct {
int (*cpu_on)(unsigned long);
int (*cpu_off)(unsigned long);
int (*cpu_suspend)(unsigned long);
int (*affinity_info)(unsigned long, unsigned int);
} pm_frontend_ops;
/*******************************************************************************
* Structure populated by a generic power management api implementation e.g.
* psci to perform api specific bits after a cpu has been turned on.
******************************************************************************/
typedef struct {
unsigned long (*cpu_off_finisher)(unsigned long);
unsigned long (*cpu_suspend_finisher)(unsigned long);
} pm_backend_ops;
/*******************************************************************************
* Function & variable prototypes
******************************************************************************/
extern pm_frontend_ops *get_pm_frontend_ops(void);
extern pm_backend_ops *get_pm_backend_ops(void);
extern void set_pm_frontend_ops(pm_frontend_ops *);
extern void set_pm_backend_ops(pm_backend_ops *);
#endif /*__ASSEMBLY__*/
#endif /* __PM_H__ */
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __PSCI_H__
#define __PSCI_H__
/*******************************************************************************
* Defines for runtime services func ids
******************************************************************************/
#define PSCI_VERSION 0x84000000
#define PSCI_CPU_SUSPEND_AARCH32 0x84000001
#define PSCI_CPU_SUSPEND_AARCH64 0xc4000001
#define PSCI_CPU_OFF 0x84000002
#define PSCI_CPU_ON_AARCH32 0x84000003
#define PSCI_CPU_ON_AARCH64 0xc4000003
#define PSCI_AFFINITY_INFO_AARCH32 0x84000004
#define PSCI_AFFINITY_INFO_AARCH64 0xc4000004
#define PSCI_MIG_AARCH32 0x84000005
#define PSCI_MIG_AARCH64 0xc4000005
#define PSCI_MIG_INFO_TYPE 0x84000006
#define PSCI_MIG_INFO_UP_CPU_AARCH32 0x84000007
#define PSCI_MIG_INFO_UP_CPU_AARCH64 0xc4000007
#define PSCI_SYSTEM_OFF 0x84000008
#define PSCI_SYSTEM_RESET 0x84000009
/*******************************************************************************
* PSCI Migrate and friends
******************************************************************************/
#define PSCI_TOS_UP_MIG_CAP 0
#define PSCI_TOS_NOT_UP_MIG_CAP 1
#define PSCI_TOS_NOT_PRESENT 2
/*******************************************************************************
* PSCI CPU_SUSPEND 'power_state' parameter specific defines
******************************************************************************/
#define PSTATE_ID_SHIFT 15
#define PSTATE_TYPE_SHIFT 16
#define PSTATE_AFF_LVL_SHIFT 25
#define PSTATE_ID_MASK 0xffff
#define PSTATE_TYPE_MASK 0x1
#define PSTATE_AFF_LVL_MASK 0x3
#define psci_get_pstate_id(pstate) (pstate >> PSTATE_ID_SHIFT) & \
PSTATE_ID_MASK
#define psci_get_pstate_type(pstate) (pstate >> PSTATE_TYPE_SHIFT) & \
PSTATE_TYPE_MASK
#define psci_get_pstate_afflvl(pstate) (pstate >> PSTATE_AFF_LVL_SHIFT) & \
PSTATE_AFF_LVL_MASK
/*******************************************************************************
* PSCI version
******************************************************************************/
#define PSCI_MAJOR_VER (0 << 16)
#define PSCI_MINOR_VER 0x2
/*******************************************************************************
* PSCI error codes
******************************************************************************/
#define PSCI_E_SUCCESS 0
#define PSCI_E_NOT_SUPPORTED -1
#define PSCI_E_INVALID_PARAMS -2
#define PSCI_E_DENIED -3
#define PSCI_E_ALREADY_ON -4
#define PSCI_E_ON_PENDING -5
#define PSCI_E_INTERN_FAIL -6
#define PSCI_E_NOT_PRESENT -7
#define PSCI_E_DISABLED -8
/*******************************************************************************
* PSCI affinity state related constants. An affinity instance could be present
* or absent physically to cater for asymmetric topologies. If present then it
* could in one of the 4 further defined states.
******************************************************************************/
#define PSCI_STATE_SHIFT 1
#define PSCI_STATE_MASK 0x7
#define psci_get_state(x) (x >> PSCI_STATE_SHIFT) & PSCI_STATE_MASK
#define psci_set_state(x,y) x &= ~(PSCI_STATE_MASK << PSCI_STATE_SHIFT); \
x |= (y & PSCI_STATE_MASK) << PSCI_STATE_SHIFT;
#define PSCI_AFF_ABSENT 0x0
#define PSCI_AFF_PRESENT 0x1
#define PSCI_STATE_OFF 0x0
#define PSCI_STATE_ON_PENDING 0x1
#define PSCI_STATE_SUSPEND 0x2
#define PSCI_STATE_ON 0x3
/* Number of affinity instances whose state this psci imp. can track */
#define PSCI_NUM_AFFS 32ull
#ifndef __ASSEMBLY__
/*******************************************************************************
* Structure populated by platform specific code to export routines which
* perform common low level pm functions
******************************************************************************/
typedef struct {
int (*affinst_standby)(unsigned int);
int (*affinst_on)(unsigned long,
unsigned long,
unsigned long,
unsigned int,
unsigned int);
int (*affinst_off)(unsigned long, unsigned int, unsigned int);
int (*affinst_suspend)(unsigned long,
unsigned long,
unsigned long,
unsigned int,
unsigned int);
int (*affinst_on_finish)(unsigned long, unsigned int, unsigned int);
int (*affinst_suspend_finish)(unsigned long,
unsigned int,
unsigned int);
} plat_pm_ops;
/*******************************************************************************
* Function & Data prototypes
******************************************************************************/
extern unsigned int psci_version(void);
extern int psci_cpu_on(unsigned long,
unsigned long,
unsigned long);
extern int __psci_cpu_suspend(unsigned int, unsigned long, unsigned long);
extern int __psci_cpu_off(void);
extern int psci_affinity_info(unsigned long, unsigned int);
extern int psci_migrate(unsigned int);
extern unsigned int psci_migrate_info_type(void);
extern unsigned long psci_migrate_info_up_cpu(void);
extern void psci_system_off(void);
extern void psci_system_reset(void);
extern int psci_cpu_on(unsigned long,
unsigned long,
unsigned long);
extern void psci_aff_on_finish_entry(void);
extern void psci_aff_suspend_finish_entry(void);
extern void psci_setup(unsigned long);
#endif /*__ASSEMBLY__*/
#endif /* __PSCI_H__ */
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __RUNTIME_SVC_H__
#define __RUNTIME_SVC_H__
#include <psci.h>
/*******************************************************************************
* Bit definitions inside the function id as per the SMC calling convention
******************************************************************************/
#define FUNCID_TYPE_SHIFT 31
#define FUNCID_CC_SHIFT 30
#define FUNCID_OWNER_SHIFT 24
#define FUNCID_NUM_SHIFT 0
#define FUNCID_TYPE_MASK 0x1
#define FUNCID_CC_MASK 0x1
#define FUNCID_OWNER_MASK 0x3f
#define FUNCID_NUM_MASK 0xffff
#define GET_SMC_CC(id) ((id >> FUNCID_CC_SHIFT) & \
FUNCID_CC_MASK)
#define SMC_64 1
#define SMC_32 0
#define SMC_UNK 0xffffffff
/*******************************************************************************
* Constants to indicate type of exception to the common exception handler.
******************************************************************************/
#define SYNC_EXCEPTION_SP_EL0 0x0
#define IRQ_SP_EL0 0x1
#define FIQ_SP_EL0 0x2
#define SERROR_SP_EL0 0x3
#define SYNC_EXCEPTION_SP_ELX 0x4
#define IRQ_SP_ELX 0x5
#define FIQ_SP_ELX 0x6
#define SERROR_SP_ELX 0x7
#define SYNC_EXCEPTION_AARCH64 0x8
#define IRQ_AARCH64 0x9
#define FIQ_AARCH64 0xa
#define SERROR_AARCH64 0xb
#define SYNC_EXCEPTION_AARCH32 0xc
#define IRQ_AARCH32 0xd
#define FIQ_AARCH32 0xe
#define SERROR_AARCH32 0xf
#ifndef __ASSEMBLY__
typedef struct {
unsigned long x0;
unsigned long x1;
unsigned long x2;
unsigned long x3;
unsigned long x4;
unsigned long x5;
unsigned long x6;
unsigned long x7;
unsigned long x8;
unsigned long x9;
unsigned long x10;
unsigned long x11;
unsigned long x12;
unsigned long x13;
unsigned long x14;
unsigned long x15;
unsigned long x16;
unsigned long x17;
unsigned long x18;
unsigned long x19;
unsigned long x20;
unsigned long x21;
unsigned long x22;
unsigned long x23;
unsigned long x24;
unsigned long x25;
unsigned long x26;
unsigned long x27;
unsigned long x28;
unsigned long sp_el0;
unsigned long spsr;
unsigned long fp;
unsigned long lr;
} gp_regs;
/*******************************************************************************
* Function & variable prototypes
******************************************************************************/
extern void runtime_svc_init(unsigned long mpidr);
#endif /*__ASSEMBLY__*/
#endif /* __RUNTIME_SVC_H__ */
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SEMIHOSTING_H__
#define __SEMIHOSTING_H__
#define SEMIHOSTING_SYS_OPEN 0x01
#define SEMIHOSTING_SYS_CLOSE 0x02
#define SEMIHOSTING_SYS_WRITE0 0x04
#define SEMIHOSTING_SYS_WRITEC 0x03
#define SEMIHOSTING_SYS_WRITE 0x05
#define SEMIHOSTING_SYS_READ 0x06
#define SEMIHOSTING_SYS_READC 0x07
#define SEMIHOSTING_SYS_SEEK 0x0A
#define SEMIHOSTING_SYS_FLEN 0x0C
#define SEMIHOSTING_SYS_REMOVE 0x0E
#define SEMIHOSTING_SYS_SYSTEM 0x12
#define SEMIHOSTING_SYS_ERRNO 0x13
#define FOPEN_MODE_R 0x0
#define FOPEN_MODE_RB 0x1
#define FOPEN_MODE_RPLUS 0x2
#define FOPEN_MODE_RPLUSB 0x3
#define FOPEN_MODE_W 0x4
#define FOPEN_MODE_WB 0x5
#define FOPEN_MODE_WPLUS 0x6
#define FOPEN_MODE_WPLUSB 0x7
#define FOPEN_MODE_A 0x8
#define FOPEN_MODE_AB 0x9
#define FOPEN_MODE_APLUS 0xa
#define FOPEN_MODE_APLUSB 0xb
int semihosting_connection_supported(void);
int semihosting_file_open(const char *file_name, unsigned int mode);
int semihosting_file_seek(int file_handle, unsigned int offset);
int semihosting_file_read(int file_handle, int *length, void *buffer);
int semihosting_file_write(int file_handle, int *length, void *buffer);
int semihosting_file_close(int file_handle);
int semihosting_file_length(int file_handle);
int semihosting_system(char *command_line);
int semihosting_get_flen(const char* file_name);
int semihosting_download_file(const char* file_name, int buf_size, void *buf);
void semihosting_write_char(char character);
void semihosting_write_string(char *string);
char semihosting_read_char(void);
#endif /* __SEMIHOSTING_H__ */
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SPINLOCK_H__
#define __SPINLOCK_H__
typedef struct {
volatile unsigned int lock;
} spinlock_t;
void spin_lock(spinlock_t *lock);
void spin_unlock(spinlock_t *lock);
#endif /* __SPINLOCK_H__ */
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <arch_helpers.h>
#include <asm_macros.S>
.globl dcisw
.globl dccisw
.globl dccsw
.globl dccvac
.globl dcivac
.globl dccivac
.globl dccvau
.globl dczva
.globl flush_dcache_range
.globl inv_dcache_range
.globl dcsw_op_louis
.globl dcsw_op_all
.section .text, "ax"; .align 3
dcisw:; .type dcisw, %function
dc isw, x0
dsb sy
isb
ret
dccisw:; .type dccisw, %function
dc cisw, x0
dsb sy
isb
ret
dccsw:; .type dccsw, %function
dc csw, x0
dsb sy
isb
ret
dccvac:; .type dccvac, %function
dc cvac, x0
dsb sy
isb
ret
dcivac:; .type dcivac, %function
dc ivac, x0
dsb sy
isb
ret
dccivac:; .type dccivac, %function
dc civac, x0
dsb sy
isb
ret
dccvau:; .type dccvau, %function
dc cvau, x0
dsb sy
isb
ret
dczva:; .type dczva, %function
dc zva, x0
dsb sy
isb
ret
/* ------------------------------------------
* Clean+Invalidate from base address till
* size. 'x0' = addr, 'x1' = size
* ------------------------------------------
*/
flush_dcache_range:; .type flush_dcache_range, %function
dcache_line_size x2, x3
add x1, x0, x1
sub x3, x2, #1
bic x0, x0, x3
flush_loop:
dc civac, x0
add x0, x0, x2
cmp x0, x1
b.lo flush_loop
dsb sy
ret
/* ------------------------------------------
* Invalidate from base address till
* size. 'x0' = addr, 'x1' = size
* ------------------------------------------
*/
inv_dcache_range:; .type inv_dcache_range, %function
dcache_line_size x2, x3
add x1, x0, x1
sub x3, x2, #1
bic x0, x0, x3
inv_loop:
dc ivac, x0
add x0, x0, x2
cmp x0, x1
b.lo inv_loop
dsb sy
ret
/* ------------------------------------------
* Data cache operations by set/way to the
* level specified
* ------------------------------------------
* ----------------------------------
* Call this func with the clidr in
* x0, starting cache level in x10,
* last cache level in x3 & cm op in
* x14
* ----------------------------------
*/
dcsw_op:; .type dcsw_op, %function
all_start_at_level:
add x2, x10, x10, lsr #1 // work out 3x current cache level
lsr x1, x0, x2 // extract cache type bits from clidr
and x1, x1, #7 // mask of the bits for current cache only
cmp x1, #2 // see what cache we have at this level
b.lt skip // skip if no cache, or just i-cache
msr csselr_el1, x10 // select current cache level in csselr
isb // isb to sych the new cssr&csidr
mrs x1, ccsidr_el1 // read the new ccsidr
and x2, x1, #7 // extract the length of the cache lines
add x2, x2, #4 // add 4 (line length offset)
mov x4, #0x3ff
and x4, x4, x1, lsr #3 // find maximum number on the way size
clz w5, w4 // find bit position of way size increment
mov x7, #0x7fff
and x7, x7, x1, lsr #13 // extract max number of the index size
loop2:
mov x9, x4 // create working copy of max way size
loop3:
lsl x6, x9, x5
orr x11, x10, x6 // factor way and cache number into x11
lsl x6, x7, x2
orr x11, x11, x6 // factor index number into x11
mov x12, x0
mov x13, x30 // lr
mov x0, x11
blr x14
mov x0, x12
mov x30, x13 // lr
subs x9, x9, #1 // decrement the way
b.ge loop3
subs x7, x7, #1 // decrement the index
b.ge loop2
skip:
add x10, x10, #2 // increment cache number
cmp x3, x10
b.gt all_start_at_level
finished:
mov x10, #0 // swith back to cache level 0
msr csselr_el1, x10 // select current cache level in csselr
dsb sy
isb
ret
do_dcsw_op:; .type do_dcsw_op, %function
cbz x3, exit
cmp x0, #DCISW
b.eq dc_isw
cmp x0, #DCCISW
b.eq dc_cisw
cmp x0, #DCCSW
b.eq dc_csw
dc_isw:
mov x0, x9
adr x14, dcisw
b dcsw_op
dc_cisw:
mov x0, x9
adr x14, dccisw
b dcsw_op
dc_csw:
mov x0, x9
adr x14, dccsw
b dcsw_op
exit:
ret
dcsw_op_louis:; .type dcsw_op_louis, %function
dsb sy
setup_dcsw_op_args x10, x3, x9, #LOUIS_SHIFT, #CLIDR_FIELD_WIDTH, #LEVEL_SHIFT
b do_dcsw_op
dcsw_op_all:; .type dcsw_op_all, %function
dsb sy
setup_dcsw_op_args x10, x3, x9, #LOC_SHIFT, #CLIDR_FIELD_WIDTH, #LEVEL_SHIFT
b do_dcsw_op
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <arch_helpers.h>
.globl enable_irq
.globl disable_irq
.globl enable_fiq
.globl disable_fiq
.globl enable_serror
.globl disable_serror
.globl read_daif
.globl write_daif
.globl read_spsr
.globl read_spsr_el1
.globl read_spsr_el2
.globl read_spsr_el3
.globl write_spsr
.globl write_spsr_el1
.globl write_spsr_el2
.globl write_spsr_el3
.globl read_elr
.globl read_elr_el1
.globl read_elr_el2
.globl read_elr_el3
.globl write_elr
.globl write_elr_el1
.globl write_elr_el2
.globl write_elr_el3
.globl get_afflvl_shift
.globl mpidr_mask_lower_afflvls
.globl dsb
.globl isb
.globl sev
.globl wfe
.globl wfi
.globl eret
.globl smc
.section .text, "ax"
get_afflvl_shift:; .type get_afflvl_shift, %function
cmp x0, #3
cinc x0, x0, eq
mov x1, #MPIDR_AFFLVL_SHIFT
lsl x0, x0, x1
ret
mpidr_mask_lower_afflvls:; .type mpidr_mask_lower_afflvls, %function
cmp x1, #3
cinc x1, x1, eq
mov x2, #MPIDR_AFFLVL_SHIFT
lsl x2, x1, x2
lsr x0, x0, x2
lsl x0, x0, x2
ret
/* -----------------------------------------------------
* Asynchronous exception manipulation accessors
* -----------------------------------------------------
*/
enable_irq:; .type enable_irq, %function
msr daifclr, #DAIF_IRQ_BIT
ret
enable_fiq:; .type enable_fiq, %function
msr daifclr, #DAIF_FIQ_BIT
ret
enable_serror:; .type enable_serror, %function
msr daifclr, #DAIF_ABT_BIT
ret
disable_irq:; .type disable_irq, %function
msr daifset, #DAIF_IRQ_BIT
ret
disable_fiq:; .type disable_fiq, %function
msr daifset, #DAIF_FIQ_BIT
ret
disable_serror:; .type disable_serror, %function
msr daifset, #DAIF_ABT_BIT
ret
read_daif:; .type read_daif, %function
mrs x0, daif
ret
write_daif:; .type write_daif, %function
msr daif, x0
ret
read_spsr:; .type read_spsr, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_spsr_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_spsr_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_spsr_el3
read_spsr_el1:; .type read_spsr_el1, %function
mrs x0, spsr_el1
ret
read_spsr_el2:; .type read_spsr_el2, %function
mrs x0, spsr_el2
ret
read_spsr_el3:; .type read_spsr_el3, %function
mrs x0, spsr_el3
ret
write_spsr:; .type write_spsr, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_spsr_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_spsr_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_spsr_el3
write_spsr_el1:; .type write_spsr_el1, %function
msr spsr_el1, x0
isb
ret
write_spsr_el2:; .type write_spsr_el2, %function
msr spsr_el2, x0
isb
ret
write_spsr_el3:; .type write_spsr_el3, %function
msr spsr_el3, x0
isb
ret
read_elr:; .type read_elr, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_elr_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_elr_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_elr_el3
read_elr_el1:; .type read_elr_el1, %function
mrs x0, elr_el1
ret
read_elr_el2:; .type read_elr_el2, %function
mrs x0, elr_el2
ret
read_elr_el3:; .type read_elr_el3, %function
mrs x0, elr_el3
ret
write_elr:; .type write_elr, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_elr_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_elr_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_elr_el3
write_elr_el1:; .type write_elr_el1, %function
msr elr_el1, x0
isb
ret
write_elr_el2:; .type write_elr_el2, %function
msr elr_el2, x0
isb
ret
write_elr_el3:; .type write_elr_el3, %function
msr elr_el3, x0
isb
ret
dsb:; .type dsb, %function
dsb sy
ret
isb:; .type isb, %function
isb
ret
sev:; .type sev, %function
sev
ret
wfe:; .type wfe, %function
wfe
ret
wfi:; .type wfi, %function
wfi
ret
eret:; .type eret, %function
eret
smc:; .type smc, %function
smc #0
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <arch_helpers.h>
.globl read_vbar
.globl read_vbar_el1
.globl read_vbar_el2
.globl read_vbar_el3
.globl write_vbar
.globl write_vbar_el1
.globl write_vbar_el2
.globl write_vbar_el3
.globl read_sctlr
.globl read_sctlr_el1
.globl read_sctlr_el2
.globl read_sctlr_el3
.globl write_sctlr
.globl write_sctlr_el1
.globl write_sctlr_el2
.globl write_sctlr_el3
.globl read_actlr
.globl read_actlr_el1
.globl read_actlr_el2
.globl read_actlr_el3
.globl write_actlr
.globl write_actlr_el1
.globl write_actlr_el2
.globl write_actlr_el3
.globl read_esr
.globl read_esr_el1
.globl read_esr_el2
.globl read_esr_el3
.globl write_esr
.globl write_esr_el1
.globl write_esr_el2
.globl write_esr_el3
.globl read_afsr0
.globl read_afsr0_el1
.globl read_afsr0_el2
.globl read_afsr0_el3
.globl write_afsr0
.globl write_afsr0_el1
.globl write_afsr0_el2
.globl write_afsr0_el3
.globl read_afsr1
.globl read_afsr1_el1
.globl read_afsr1_el2
.globl read_afsr1_el3
.globl write_afsr1
.globl write_afsr1_el1
.globl write_afsr1_el2
.globl write_afsr1_el3
.globl read_far
.globl read_far_el1
.globl read_far_el2
.globl read_far_el3
.globl write_far
.globl write_far_el1
.globl write_far_el2
.globl write_far_el3
.globl read_mair
.globl read_mair_el1
.globl read_mair_el2
.globl read_mair_el3
.globl write_mair
.globl write_mair_el1
.globl write_mair_el2
.globl write_mair_el3
.globl read_amair
.globl read_amair_el1
.globl read_amair_el2
.globl read_amair_el3
.globl write_amair
.globl write_amair_el1
.globl write_amair_el2
.globl write_amair_el3
.globl read_rvbar
.globl read_rvbar_el1
.globl read_rvbar_el2
.globl read_rvbar_el3
.globl read_rmr
.globl read_rmr_el1
.globl read_rmr_el2
.globl read_rmr_el3
.globl write_rmr
.globl write_rmr_el1
.globl write_rmr_el2
.globl write_rmr_el3
.globl read_tcr
.globl read_tcr_el1
.globl read_tcr_el2
.globl read_tcr_el3
.globl write_tcr
.globl write_tcr_el1
.globl write_tcr_el2
.globl write_tcr_el3
.globl read_cptr
.globl read_cptr_el2
.globl read_cptr_el3
.globl write_cptr
.globl write_cptr_el2
.globl write_cptr_el3
.globl read_ttbr0
.globl read_ttbr0_el1
.globl read_ttbr0_el2
.globl read_ttbr0_el3
.globl write_ttbr0
.globl write_ttbr0_el1
.globl write_ttbr0_el2
.globl write_ttbr0_el3
.globl read_ttbr1
.globl read_ttbr1_el1
.globl read_ttbr1_el2
.globl write_ttbr1
.globl write_ttbr1_el1
.globl write_ttbr1_el2
.globl read_cpacr
.globl write_cpacr
.globl read_cntfrq
.globl write_cntfrq
.globl read_cpuectlr
.globl write_cpuectlr
.globl read_cnthctl_el2
.globl write_cnthctl_el2
.globl read_cntfrq_el0
.globl write_cntfrq_el0
.globl read_scr
.globl write_scr
.globl read_hcr
.globl write_hcr
.globl read_midr
.globl read_mpidr
.globl read_current_el
.globl read_id_pfr1_el1
.globl read_id_aa64pfr0_el1
#if SUPPORT_VFP
.globl enable_vfp
.globl read_fpexc
.globl write_fpexc
#endif
.section .text, "ax"
read_current_el:; .type read_current_el, %function
mrs x0, CurrentEl
ret
read_id_pfr1_el1:; .type read_id_pfr1_el1, %function
mrs x0, id_pfr1_el1
ret
read_id_aa64pfr0_el1:; .type read_id_aa64pfr0_el1, %function
mrs x0, id_aa64pfr0_el1
ret
/* -----------------------------------------------------
* VBAR accessors
* -----------------------------------------------------
*/
read_vbar:; .type read_vbar, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_vbar_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_vbar_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_vbar_el3
read_vbar_el1:; .type read_vbar_el1, %function
mrs x0, vbar_el1
ret
read_vbar_el2:; .type read_vbar_el2, %function
mrs x0, vbar_el2
ret
read_vbar_el3:; .type read_vbar_el3, %function
mrs x0, vbar_el3
ret
write_vbar:; .type write_vbar, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_vbar_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_vbar_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_vbar_el3
write_vbar_el1:; .type write_vbar_el1, %function
msr vbar_el1, x0
isb
ret
write_vbar_el2:; .type write_vbar_el2, %function
msr vbar_el2, x0
isb
ret
write_vbar_el3:; .type write_vbar_el3, %function
msr vbar_el3, x0
isb
ret
/* -----------------------------------------------------
* AFSR0 accessors
* -----------------------------------------------------
*/
read_afsr0:; .type read_afsr0, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_afsr0_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_afsr0_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_afsr0_el3
read_afsr0_el1:; .type read_afsr0_el1, %function
mrs x0, afsr0_el1
ret
read_afsr0_el2:; .type read_afsr0_el2, %function
mrs x0, afsr0_el2
ret
read_afsr0_el3:; .type read_afsr0_el3, %function
mrs x0, afsr0_el3
ret
write_afsr0:; .type write_afsr0, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_afsr0_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_afsr0_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_afsr0_el3
write_afsr0_el1:; .type write_afsr0_el1, %function
msr afsr0_el1, x0
isb
ret
write_afsr0_el2:; .type write_afsr0_el2, %function
msr afsr0_el2, x0
isb
ret
write_afsr0_el3:; .type write_afsr0_el3, %function
msr afsr0_el3, x0
isb
ret
/* -----------------------------------------------------
* FAR accessors
* -----------------------------------------------------
*/
read_far:; .type read_far, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_far_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_far_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_far_el3
read_far_el1:; .type read_far_el1, %function
mrs x0, far_el1
ret
read_far_el2:; .type read_far_el2, %function
mrs x0, far_el2
ret
read_far_el3:; .type read_far_el3, %function
mrs x0, far_el3
ret
write_far:; .type write_far, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_far_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_far_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_far_el3
write_far_el1:; .type write_far_el1, %function
msr far_el1, x0
isb
ret
write_far_el2:; .type write_far_el2, %function
msr far_el2, x0
isb
ret
write_far_el3:; .type write_far_el3, %function
msr far_el3, x0
isb
ret
/* -----------------------------------------------------
* MAIR accessors
* -----------------------------------------------------
*/
read_mair:; .type read_mair, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_mair_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_mair_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_mair_el3
read_mair_el1:; .type read_mair_el1, %function
mrs x0, mair_el1
ret
read_mair_el2:; .type read_mair_el2, %function
mrs x0, mair_el2
ret
read_mair_el3:; .type read_mair_el3, %function
mrs x0, mair_el3
ret
write_mair:; .type write_mair, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_mair_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_mair_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_mair_el3
write_mair_el1:; .type write_mair_el1, %function
msr mair_el1, x0
isb
ret
write_mair_el2:; .type write_mair_el2, %function
msr mair_el2, x0
isb
ret
write_mair_el3:; .type write_mair_el3, %function
msr mair_el3, x0
isb
ret
/* -----------------------------------------------------
* AMAIR accessors
* -----------------------------------------------------
*/
read_amair:; .type read_amair, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_amair_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_amair_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_amair_el3
read_amair_el1:; .type read_amair_el1, %function
mrs x0, amair_el1
ret
read_amair_el2:; .type read_amair_el2, %function
mrs x0, amair_el2
ret
read_amair_el3:; .type read_amair_el3, %function
mrs x0, amair_el3
ret
write_amair:; .type write_amair, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_amair_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_amair_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_amair_el3
write_amair_el1:; .type write_amair_el1, %function
msr amair_el1, x0
isb
ret
write_amair_el2:; .type write_amair_el2, %function
msr amair_el2, x0
isb
ret
write_amair_el3:; .type write_amair_el3, %function
msr amair_el3, x0
isb
ret
/* -----------------------------------------------------
* RVBAR accessors
* -----------------------------------------------------
*/
read_rvbar:; .type read_rvbar, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_rvbar_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_rvbar_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_rvbar_el3
read_rvbar_el1:; .type read_rvbar_el1, %function
mrs x0, rvbar_el1
ret
read_rvbar_el2:; .type read_rvbar_el2, %function
mrs x0, rvbar_el2
ret
read_rvbar_el3:; .type read_rvbar_el3, %function
mrs x0, rvbar_el3
ret
/* -----------------------------------------------------
* RMR accessors
* -----------------------------------------------------
*/
read_rmr:; .type read_rmr, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_rmr_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_rmr_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_rmr_el3
read_rmr_el1:; .type read_rmr_el1, %function
mrs x0, rmr_el1
ret
read_rmr_el2:; .type read_rmr_el2, %function
mrs x0, rmr_el2
ret
read_rmr_el3:; .type read_rmr_el3, %function
mrs x0, rmr_el3
ret
write_rmr:; .type write_rmr, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_rmr_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_rmr_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_rmr_el3
write_rmr_el1:; .type write_rmr_el1, %function
msr rmr_el1, x0
isb
ret
write_rmr_el2:; .type write_rmr_el2, %function
msr rmr_el2, x0
isb
ret
write_rmr_el3:; .type write_rmr_el3, %function
msr rmr_el3, x0
isb
ret
read_afsr1:; .type read_afsr1, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_afsr1_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_afsr1_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_afsr1_el3
/* -----------------------------------------------------
* AFSR1 accessors
* -----------------------------------------------------
*/
read_afsr1_el1:; .type read_afsr1_el1, %function
mrs x0, afsr1_el1
ret
read_afsr1_el2:; .type read_afsr1_el2, %function
mrs x0, afsr1_el2
ret
read_afsr1_el3:; .type read_afsr1_el3, %function
mrs x0, afsr1_el3
ret
write_afsr1:; .type write_afsr1, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_afsr1_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_afsr1_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_afsr1_el3
write_afsr1_el1:; .type write_afsr1_el1, %function
msr afsr1_el1, x0
isb
ret
write_afsr1_el2:; .type write_afsr1_el2, %function
msr afsr1_el2, x0
isb
ret
write_afsr1_el3:; .type write_afsr1_el3, %function
msr afsr1_el3, x0
isb
ret
/* -----------------------------------------------------
* SCTLR accessors
* -----------------------------------------------------
*/
read_sctlr:; .type read_sctlr, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_sctlr_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_sctlr_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_sctlr_el3
read_sctlr_el1:; .type read_sctlr_el1, %function
mrs x0, sctlr_el1
ret
read_sctlr_el2:; .type read_sctlr_el2, %function
mrs x0, sctlr_el2
ret
read_sctlr_el3:; .type read_sctlr_el3, %function
mrs x0, sctlr_el3
ret
write_sctlr:; .type write_sctlr, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_sctlr_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_sctlr_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_sctlr_el3
write_sctlr_el1:; .type write_sctlr_el1, %function
msr sctlr_el1, x0
dsb sy
isb
ret
write_sctlr_el2:; .type write_sctlr_el2, %function
msr sctlr_el2, x0
dsb sy
isb
ret
write_sctlr_el3:; .type write_sctlr_el3, %function
msr sctlr_el3, x0
dsb sy
isb
ret
/* -----------------------------------------------------
* ACTLR accessors
* -----------------------------------------------------
*/
read_actlr:; .type read_actlr, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_actlr_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_actlr_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_actlr_el3
read_actlr_el1:; .type read_actlr_el1, %function
mrs x0, actlr_el1
ret
read_actlr_el2:; .type read_actlr_el2, %function
mrs x0, actlr_el2
ret
read_actlr_el3:; .type read_actlr_el3, %function
mrs x0, actlr_el3
ret
write_actlr:; .type write_actlr, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_actlr_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_actlr_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_actlr_el3
write_actlr_el1:; .type write_actlr_el1, %function
msr actlr_el1, x0
dsb sy
isb
ret
write_actlr_el2:; .type write_actlr_el2, %function
msr actlr_el2, x0
dsb sy
isb
ret
write_actlr_el3:; .type write_actlr_el3, %function
msr actlr_el3, x0
dsb sy
isb
ret
/* -----------------------------------------------------
* ESR accessors
* -----------------------------------------------------
*/
read_esr:; .type read_esr, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_esr_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_esr_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_esr_el3
read_esr_el1:; .type read_esr_el1, %function
mrs x0, esr_el1
ret
read_esr_el2:; .type read_esr_el2, %function
mrs x0, esr_el2
ret
read_esr_el3:; .type read_esr_el3, %function
mrs x0, esr_el3
ret
write_esr:; .type write_esr, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_esr_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_esr_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_esr_el3
write_esr_el1:; .type write_esr_el1, %function
msr esr_el1, x0
dsb sy
isb
ret
write_esr_el2:; .type write_esr_el2, %function
msr esr_el2, x0
dsb sy
isb
ret
write_esr_el3:; .type write_esr_el3, %function
msr esr_el3, x0
dsb sy
isb
ret
/* -----------------------------------------------------
* TCR accessors
* -----------------------------------------------------
*/
read_tcr:; .type read_tcr, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_tcr_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_tcr_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_tcr_el3
read_tcr_el1:; .type read_tcr_el1, %function
mrs x0, tcr_el1
ret
read_tcr_el2:; .type read_tcr_el2, %function
mrs x0, tcr_el2
ret
read_tcr_el3:; .type read_tcr_el3, %function
mrs x0, tcr_el3
ret
write_tcr:; .type write_tcr, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_tcr_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_tcr_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_tcr_el3
write_tcr_el1:; .type write_tcr_el1, %function
msr tcr_el1, x0
dsb sy
isb
ret
write_tcr_el2:; .type write_tcr_el2, %function
msr tcr_el2, x0
dsb sy
isb
ret
write_tcr_el3:; .type write_tcr_el3, %function
msr tcr_el3, x0
dsb sy
isb
ret
/* -----------------------------------------------------
* CPTR accessors
* -----------------------------------------------------
*/
read_cptr:; .type read_cptr, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_cptr_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_cptr_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_cptr_el3
read_cptr_el1:; .type read_cptr_el1, %function
b read_cptr_el1
ret
read_cptr_el2:; .type read_cptr_el2, %function
mrs x0, cptr_el2
ret
read_cptr_el3:; .type read_cptr_el3, %function
mrs x0, cptr_el3
ret
write_cptr:; .type write_cptr, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_cptr_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_cptr_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_cptr_el3
write_cptr_el1:; .type write_cptr_el1, %function
b write_cptr_el1
write_cptr_el2:; .type write_cptr_el2, %function
msr cptr_el2, x0
dsb sy
isb
ret
write_cptr_el3:; .type write_cptr_el3, %function
msr cptr_el3, x0
dsb sy
isb
ret
/* -----------------------------------------------------
* TTBR0 accessors
* -----------------------------------------------------
*/
read_ttbr0:; .type read_ttbr0, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_ttbr0_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_ttbr0_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_ttbr0_el3
read_ttbr0_el1:; .type read_ttbr0_el1, %function
mrs x0, ttbr0_el1
ret
read_ttbr0_el2:; .type read_ttbr0_el2, %function
mrs x0, ttbr0_el2
ret
read_ttbr0_el3:; .type read_ttbr0_el3, %function
mrs x0, ttbr0_el3
ret
write_ttbr0:; .type write_ttbr0, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_ttbr0_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_ttbr0_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_ttbr0_el3
write_ttbr0_el1:; .type write_ttbr0_el1, %function
msr ttbr0_el1, x0
isb
ret
write_ttbr0_el2:; .type write_ttbr0_el2, %function
msr ttbr0_el2, x0
isb
ret
write_ttbr0_el3:; .type write_ttbr0_el3, %function
msr ttbr0_el3, x0
isb
ret
/* -----------------------------------------------------
* TTBR1 accessors
* -----------------------------------------------------
*/
read_ttbr1:; .type read_ttbr1, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq read_ttbr1_el1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq read_ttbr1_el2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq read_ttbr1_el3
read_ttbr1_el1:; .type read_ttbr1_el1, %function
mrs x0, ttbr1_el1
ret
read_ttbr1_el2:; .type read_ttbr1_el2, %function
b read_ttbr1_el2
read_ttbr1_el3:; .type read_ttbr1_el3, %function
b read_ttbr1_el3
write_ttbr1:; .type write_ttbr1, %function
mrs x1, CurrentEl
cmp x1, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq write_ttbr1_el1
cmp x1, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq write_ttbr1_el2
cmp x1, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq write_ttbr1_el3
write_ttbr1_el1:; .type write_ttbr1_el1, %function
msr ttbr1_el1, x0
isb
ret
write_ttbr1_el2:; .type write_ttbr1_el2, %function
b write_ttbr1_el2
write_ttbr1_el3:; .type write_ttbr1_el3, %function
b write_ttbr1_el3
read_hcr:; .type read_hcr, %function
mrs x0, hcr_el2
ret
write_hcr:; .type write_hcr, %function
msr hcr_el2, x0
dsb sy
isb
ret
read_cpacr:; .type read_cpacr, %function
mrs x0, cpacr_el1
ret
write_cpacr:; .type write_cpacr, %function
msr cpacr_el1, x0
ret
read_cntfrq_el0:; .type read_cntfrq_el0, %function
mrs x0, cntfrq_el0
ret
write_cntfrq_el0:; .type write_cntfrq_el0, %function
msr cntfrq_el0, x0
ret
read_cpuectlr:; .type read_cpuectlr, %function
mrs x0, CPUECTLR_EL1
ret
write_cpuectlr:; .type write_cpuectlr, %function
msr CPUECTLR_EL1, x0
dsb sy
isb
ret
read_cnthctl_el2:; .type read_cnthctl_el2, %function
mrs x0, cnthctl_el2
ret
write_cnthctl_el2:; .type write_cnthctl_el2, %function
msr cnthctl_el2, x0
ret
read_cntfrq:; .type read_cntfrq, %function
mrs x0, cntfrq_el0
ret
write_cntfrq:; .type write_cntfrq, %function
msr cntfrq_el0, x0
ret
write_scr:; .type write_scr, %function
msr scr_el3, x0
dsb sy
isb
ret
read_scr:; .type read_scr, %function
mrs x0, scr_el3
ret
read_midr:; .type read_midr, %function
mrs x0, midr_el1
ret
read_mpidr:; .type read_mpidr, %function
mrs x0, mpidr_el1
ret
#if SUPPORT_VFP
enable_vfp:; .type enable_vfp, %function
mrs x0, cpacr_el1
orr x0, x0, #CPACR_VFP_BITS
msr cpacr_el1, x0
mrs x0, cptr_el3
mov x1, #AARCH64_CPTR_TFP
bic x0, x0, x1
msr cptr_el3, x0
ret
// int read_fpexc(void)
read_fpexc:; .type read_fpexc, %function
b read_fpexc
ret
// void write_fpexc(int fpexc)
write_fpexc:; .type write_fpexc, %function
b write_fpexc
ret
#endif
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <arch_helpers.h>
.globl tlbiall
.globl tlbiallis
.globl tlbialle1
.globl tlbialle1is
.globl tlbialle2
.globl tlbialle2is
.globl tlbialle3
.globl tlbialle3is
.globl tlbivmalle1
.section .text, "ax"
tlbiall:; .type tlbiall, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq tlbialle1
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq tlbialle2
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq tlbialle3
tlbiallis:; .type tlbiallis, %function
mrs x0, CurrentEl
cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
b.eq tlbialle1is
cmp x0, #(MODE_EL2 << MODE_EL_SHIFT)
b.eq tlbialle2is
cmp x0, #(MODE_EL3 << MODE_EL_SHIFT)
b.eq tlbialle3is
tlbialle1:; .type tlbialle1, %function
tlbi alle1
dsb sy
isb
ret
tlbialle1is:; .type tlbialle1is, %function
tlbi alle1is
dsb sy
isb
ret
tlbialle2:; .type tlbialle2, %function
tlbi alle2
dsb sy
isb
ret
tlbialle2is:; .type tlbialle2is, %function
tlbi alle2is
dsb sy
isb
ret
tlbialle3:; .type tlbialle3, %function
tlbi alle3
dsb sy
isb
ret
tlbialle3is:; .type tlbialle3is, %function
tlbi alle3is
dsb sy
isb
ret
tlbivmalle1:; .type tlbivmalle1, %function
tlbi vmalle1
dsb sy
isb
ret
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
void mmio_write_32(uintptr_t addr, uint32_t value)
{
*(volatile uint32_t*)addr = value;
}
unsigned mmio_read_32(uintptr_t addr)
{
return *(volatile uint32_t*)addr;
}
/*-
* Copyright (c) 1982, 1988, 1991, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
/*
* Portions copyright (c) 2009-2013, ARM Ltd. All rights reserved.
* ---------------------------------------------------------------
* File: include/lib/ctype.h
*/
#ifndef _SYS_CTYPE_H_
#define _SYS_CTYPE_H_
#define isspace(c) ((c) == ' ' || ((c) >= '\t' && (c) <= '\r'))
#define isascii(c) (((c) & ~0x7f) == 0)
#define isupper(c) ((c) >= 'A' && (c) <= 'Z')
#define islower(c) ((c) >= 'a' && (c) <= 'z')
#define isalpha(c) (isupper(c) || islower(c))
#define isdigit(c) ((c) >= '0' && (c) <= '9')
#define isxdigit(c) (isdigit(c) \
|| ((c) >= 'A' && (c) <= 'F') \
|| ((c) >= 'a' && (c) <= 'f'))
#define isprint(c) ((c) >= ' ' && (c) <= '~')
#define toupper(c) ((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z')))
#define tolower(c) ((c) + 0x20 * (((c) >= 'A') && ((c) <= 'Z')))
#endif /* !_SYS_CTYPE_H_ */
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stddef.h> /* size_t */
/*
* Fill @count bytes of memory pointed to by @dst with @val
*/
void *memset(void *dst, int val, size_t count)
{
char *ptr = dst;
while (count--)
*ptr++ = val;
return dst;
}
/*
* Compare @len bytes of @s1 and @s2
*/
int memcmp(const void *s1, const void *s2, size_t len)
{
const char *s = s1;
const char *d = s2;
char dc;
char sc;
while (len--) {
sc = *s++;
dc = *d++;
if (sc - dc)
return (sc - dc);
}
return 0;
}
/*
* Move @len bytes from @src to @dst
*/
void *memmove(void *dst, const void *src, size_t len)
{
const char *s = src;
char *d = dst;
while (len--)
*d++ = *s++;
return d;
}
/*
* Copy @len bytes from @src to @dst
*/
void *memcpy(void *dst, const void *src, size_t len)
{
return memmove(dst, src, len);
}
/*
* Scan @len bytes of @src for value @c
*/
void *memchr(const void *src, int c, size_t len)
{
const char *s = src;
while (len--) {
if (*s == c)
return (void *) s;
s++;
}
return NULL;
}
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <console.h>
#if defined (__GNUC__)
#include <stdio.h>
#include <stddef.h> /* size_t */
#include <stdarg.h> /* va_list */
// Code from VTB.
#include "mem.c"
// Make mem functions that will operate on DEV mem. "memset_io"?
//Code from VTB
#include "strlen.c"
int puts(const char *s)
{
int count = 0;
while(*s)
{
if (console_putc(*s++)) {
count++;
} else {
count = EOF; // -1 in stdio.h
break;
}
}
return count;
}
// From VTB
#include "ctype.h"
#include "subr_prf.c"
// Choose max of 128 chars for now.
#define PRINT_BUFFER_SIZE 128
int printf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
char buf[PRINT_BUFFER_SIZE];
vsnprintf(buf, sizeof(buf) - 1, fmt, args);
buf[PRINT_BUFFER_SIZE - 1] = '\0';
return puts(buf);
}
// I just made this up. Probably make it beter.
void __assert_func (const char *file, int l, const char *func, const char *error)
{
printf("ASSERT: %s <%d> : %s\n\r", func, l, error);
while(1);
}
extern void __assert_fail (const char *assertion, const char *file,
unsigned int line, const char *function)
{
printf("ASSERT: %s <%d> : %s\n\r", function, line, assertion);
while(1);
}
// I just made this up. Probably make it beter.
void abort (void)
{
printf("ABORT\n\r");
while(1);
}
#else
#error "No standard library binding defined."
#endif
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Portions copyright (c) 2009-2013, ARM Ltd. All rights reserved.
* ---------------------------------------------------------------
* File: lib/strcmp.c
*/
/*
* Compare strings.
*/
int
strcmp(const char *s1, const char *s2)
{
while (*s1 == *s2++)
if (*s1++ == '\0')
return (0);
return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1));
}
/*
* Copyright (c) 2013, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "ctype.h"
/* Return pointer to the first non-space character */
const char *skip_spaces(const char *str)
{
while (isspace(*str))
++str;
return str;
}
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Portions copyright (c) 2009-2013, ARM Ltd. All rights reserved.
* ---------------------------------------------------------------
* File: lib/strlen.c
*/
#include <stddef.h>
size_t
strlen(str)
const char *str;
{
register const char *s;
for (s = str; *s; ++s);
return(s - str);
}
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Portions copyright (c) 2009-2013, ARM Ltd. All rights reserved.
* ---------------------------------------------------------------
* File: lib/strncmp.c
*/
#include "types.h"
int
strncmp(const char *s1, const char *s2, size_t n)
{
if (n == 0)
return (0);
do {
if (*s1 != *s2++)
return (*(const unsigned char *)s1 -
*(const unsigned char *)(s2 - 1));
if (*s1++ == '\0')
break;
} while (--n != 0);
return (0);
}
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Portions copyright (c) 2009-2013, ARM Ltd. All rights reserved.
* ---------------------------------------------------------------
* File: lib/strncpy.c
*/
#include "types.h"
/*
* Copy src to dst, truncating or null-padding to always copy n bytes.
* Return dst.
*/
char *
strncpy(char *dst, const char *src, size_t n)
{
if (n != 0) {
char *d = dst;
const char *s = src;
do {
if ((*d++ = *s++) == '\0') {
/* NUL pad the remaining n-1 bytes */
while (--n != 0)
*d++ = '\0';
break;
}
} while (--n != 0);
}
return (dst);
}
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Portions copyright (c) 2009-2013, ARM Ltd. All rights reserved.
* ---------------------------------------------------------------
* File: lib/strsep.c
*/
#include "types.h"
/*
* Get next token from string *stringp, where tokens are possibly-empty
* strings separated by characters from delim.
*
* Writes NULs into the string at *stringp to end tokens.
* delim need not remain constant from call to call.
* On return, *stringp points past the last NUL written (if there might
* be further tokens), or is NULL (if there are definitely no more tokens).
*
* If *stringp is NULL, strsep returns NULL.
*/
char *
strsep(char **stringp, const char *delim)
{
char *s;
const char *spanp;
int c, sc;
char *tok;
if ((s = *stringp) == NULL)
return (NULL);
for (tok = s;;) {
c = *s++;
spanp = delim;
do {
if ((sc = *spanp++) == c) {
if (c == 0)
s = NULL;
else
s[-1] = 0;
*stringp = s;
return (tok);
}
} while (sc != 0);
}
/* NOTREACHED */
}
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* From: @(#)strtol.c 8.1 (Berkeley) 6/4/93
*/
/*
* Portions copyright (c) 2009-2013, ARM Ltd. All rights reserved.
* ---------------------------------------------------------------
* File: lib/strtol.c
*/
#include "types.h"
#include "ctype.h"
#include "limits.h"
/*
* Convert a string to a long integer.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
static long
bsd_strtol(nptr, endptr, base)
const char *nptr;
char **endptr;
int base;
{
const char *s = nptr;
unsigned long acc;
unsigned char c;
unsigned long cutoff;
int neg = 0, any, cutlim;
/*
* Skip white space and pick up leading +/- sign if any.
* If base is 0, allow 0x for hex and 0 for octal, else
* assume decimal; if base is already 16, allow 0x.
*/
do {
c = *s++;
} while (isspace(c));
if (c == '-') {
neg = 1;
c = *s++;
} else if (c == '+')
c = *s++;
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
/*
* Compute the cutoff value between legal numbers and illegal
* numbers. That is the largest legal value, divided by the
* base. An input number that is greater than this value, if
* followed by a legal input character, is too big. One that
* is equal to this value may be valid or not; the limit
* between valid and invalid numbers is then based on the last
* digit. For instance, if the range for longs is
* [-2147483648..2147483647] and the input base is 10,
* cutoff will be set to 214748364 and cutlim to either
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
* a value > 214748364, or equal but the next digit is > 7 (or 8),
* the number is too big, and we will return a range error.
*
* Set any if any `digits' consumed; make it negative to indicate
* overflow.
*/
cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) {
if (!isascii(c))
break;
if (isdigit(c))
c -= '0';
else if (isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0) {
acc = neg ? LONG_MIN : LONG_MAX;
} else if (neg)
acc = -acc;
if (endptr != 0)
*((const char **)endptr) = any ? s - 1 : nptr;
return (acc);
}
int strict_strtol(const char *str, unsigned int base, long *result)
{
if (*str == '-')
*result = 0 - bsd_strtol(str + 1, NULL, base);
else
*result = bsd_strtol(str, NULL, base);
return 0;
}
int strict_strtoul(const char *str, unsigned int base, unsigned long *result)
{
*result = bsd_strtol(str, NULL, base);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment