Subversion Repositories freemyipod

Rev

Rev 881 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
881 theseven 1
#include "global.h"
2
#include "sys/util.h"
3
 
4
__attribute__((noreturn,weak,alias("hang"))) void powerdown();
5
 
6
__attribute__((noreturn,weak)) void hang()
7
{
8
    enter_critical_section();
9
    while (true) idle();
10
}
11
 
12
__attribute__((pure,weak)) void idle()
13
{
14
}
15
 
16
__attribute__((noreturn,weak)) void execfirmware(void* address)
17
{
18
    __attribute__((noreturn)) void (*firmware)() = address;
19
    enter_critical_section();
20
    clean_dcache(0, 0xffffffff);
21
    invalidate_icache(0, 0xffffffff);
22
    disable_mmu();
23
    firmware();
24
}
25
 
26
__attribute__((weak)) void enter_critical_section()
27
{
28
}
29
 
30
__attribute__((weak)) void leave_critical_section()
31
{
32
}
33
 
34
__attribute__((weak)) void clean_dcache(const void* addr, uint32_t len)
35
{
36
}
37
 
38
__attribute__((weak)) void invalidate_dcache(const void* addr, uint32_t len)
39
{
40
}
41
 
42
__attribute__((weak)) void invalidate_icache(const void* addr, uint32_t len)
43
{
44
}
45
 
46
__attribute__((weak)) void enable_mmu()
47
{
48
}
49
 
50
__attribute__((weak)) void disable_mmu()
51
{
52
}
53
 
54
__attribute__((pure,weak)) uint32_t swap32(uint32_t data)
55
{
56
    return SWAP_32(data);
57
}
58
 
59
__attribute__((pure,weak)) uint32_t swap16(uint32_t data)
60
{
61
    return SWAP_16(data);
62
}
63
 
64
__attribute__((pure,weak)) uint32_t reverse32(uint32_t data)
65
{
66
    return REVERSE_32(data);
67
}
68
 
69
#define UNALIGNED(x) (((long)x & (sizeof (long) - 1)))
70
#define UNALIGNED2(x, y) (((long)x & (sizeof (long) - 1)) | ((long)y & (sizeof (long) - 1)))
71
#define BIGBLOCKSIZE (sizeof(long) << 2)
72
#define LITTLEBLOCKSIZE (sizeof(long))
73
#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
74
/*
75
__attribute__((weak)) void* memset(void* dst_void, int val, size_t len)
76
{
77
    val &= 0xff;
78
    uint8_t* dst = dst_void;
79
#ifndef SQUEEZE
80
    if (!TOO_SMALL(len) && !UNALIGNED(dst))
81
    {
82
        unsigned long* aligned_dst = (unsigned long*)dst;
83
        unsigned long longval = (val << 8) | val;
84
        longval |= longval << 16;
85
        while (len >= BIGBLOCKSIZE)
86
        {
87
            *aligned_dst++ = longval;
88
            *aligned_dst++ = longval;
89
            *aligned_dst++ = longval;
90
            *aligned_dst++ = longval;
91
            len -= BIGBLOCKSIZE;
92
        }
93
        while (len >= LITTLEBLOCKSIZE)
94
        {
95
            *aligned_dst++ = longval;
96
            len -= LITTLEBLOCKSIZE;
97
        }
98
        dst = (uint8_t*)aligned_dst;
99
      }
100
#endif
101
    while (len--) *dst++ = val;
102
    return dst_void;
103
}
104
 
105
__attribute__((weak)) void* memmove(void* dst_void, const void* src_void, size_t len)
106
{
107
    char* dst = dst_void;
108
    const char* src = src_void;
109
    if (src < dst && dst < src + len)
110
    {
111
        src += len;
112
        dst += len;
113
        while (len--) *--dst = *--src;
114
    }
115
    else
116
    {
117
#ifndef SQUEEZE
118
        if (!TOO_SMALL(len) && !UNALIGNED2(src, dst))
119
        {
120
            long* aligned_dst = (long*)dst;
121
            const long* aligned_src = (long*)src;
122
            while (len >= BIGBLOCKSIZE)
123
            {
124
                *aligned_dst++ = *aligned_src++;
125
                *aligned_dst++ = *aligned_src++;
126
                *aligned_dst++ = *aligned_src++;
127
                *aligned_dst++ = *aligned_src++;
128
                len -= BIGBLOCKSIZE;
129
            }
130
            while (len >= LITTLEBLOCKSIZE)
131
            {
132
                *aligned_dst++ = *aligned_src++;
133
                len -= LITTLEBLOCKSIZE;
134
            }
135
            dst = (char*)aligned_dst;
136
            src = (const char*)aligned_src;
137
        }
138
#endif
139
        while (len--) *dst++ = *src++;
140
    }
141
    return dst_void;
142
}
143
 
144
__attribute__((weak,alias("memmove"))) void* memcpy(void* dst, const void* src, size_t len);
145
*/
925 theseven 146
 
147
__attribute__((weak)) int memcmp(const void* ptr1, const void* ptr2, size_t len)
881 theseven 148
{
925 theseven 149
    uint8_t* a = (uint8_t*)ptr1;
150
    uint8_t* b = (uint8_t*)ptr2;
151
    int d;
152
    while (len--)
153
        if ((d = *a++ - *b++))
154
            return d;
155
    return 0;
156
}
157
 
158
__attribute__((weak)) size_t strlen(const char* string)
159
{
881 theseven 160
    const char* pos = string;
161
    while (*pos++);
925 theseven 162
    return pos - string - 1;
881 theseven 163
}
164
 
165
static const char hextab[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
166
 
167
void to_hex(char* dest, int len, uint32_t value)
168
{
169
    dest += len;
170
    while (len--)
171
    {
172
        *--dest = hextab[value & 0xf];
173
        value >>= 4;
174
    }
175
}