3 Copyright (c) 2011, Adapteva, Inc.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of Adapteva nor the names of its contributors may be
14 used to endorse or promote products derived from this software without
15 specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE. */
34 int trap_7( char *s
, int _bsize
, int _argsize
) {
35 volatile register void* buff_adrr
asm("r0") = s
;
36 volatile register unsigned bsize
asm("r1") = _bsize
;
37 volatile register unsigned argsize
asm("r2") = _argsize
;
38 volatile register int result
asm("r0");
39 __asm__
__volatile__ ("trap 7" : "=r" (result
) : "r" (buff_adrr
), "r" (bsize
) , "r" (argsize
));
48 volatile static int*fp_int
=0;
49 volatile int getIntFromFloat(float *f
) {
56 int e_printf(const char *fmt
, ...) {
58 char buf
[256],*p
,*fmt_p
;
67 unsigned fmt_len
= strnlen(fmt
,128);
71 //printf("---- 111 +++ %d \n", strlen(fmt));
92 if(*fmt_p
== 's' && percentMet
== 1 ) {
94 v_arg_s
= va_arg(args
, char *);
95 if (!v_arg_s
) v_arg_s
= "<NULL>";
97 strcpy(p
+ pos
, v_arg_s
);
104 if((*fmt_p
== 'i' || *fmt_p
== 'd' || *fmt_p
== 'u' || *fmt_p
== 'x' || *fmt_p
== 'f' ) && percentMet
== 1 ) {
107 fl_f
[0] = (float)va_arg(args
, double);
108 //printf("v_arg_ float --- %f \n", fl_f[0]);
109 //printf("v_arg_ p --- %x \n", *( (unsigned *)fl_f));
111 v_arg_int
= getIntFromFloat (fl_f
);
116 v_arg_int
= (int)va_arg(args
, int);
119 // if(*fmt_p == 'd') {
120 // printf("v_arg_int --- %d \n", v_arg_int);
122 // if(*fmt_p == 'x') {
123 // printf("v_arg_int --- %x \n", v_arg_int);
125 // if(*fmt_p == 'f') {
126 // printf("fff++v_arg_int --- %x \n", v_arg_int);
127 // fl = (float*)&v_arg_int;
128 // printf("fff++ v_arg_float --- %f \n", *fl);
131 *(p
+ pos
) = ((v_arg_int
>>24) & 0xff);
133 *(p
+ pos
) = ((v_arg_int
>>16) & 0xff);
135 *(p
+ pos
) = ((v_arg_int
>>8) & 0xff);
137 *(p
+ pos
) = ((v_arg_int
>>0) & 0xff);
146 //printf(" +++ %d %d \n" , strlen(fmt), pos);
148 return trap_7((char*)buf
,fmt_len
, pos
) ;