Index: tools/elf2emcoreapp/elf2emcoreapp.c |
— | — | @@ -148,9 +148,10 @@ |
149 | 149 | |
150 | 150 | int verbose = 0; /* extra output when running */ |
151 | 151 | int pic_with_got = 0; /* do elf/got processing with PIC code */ |
152 | | -int load_to_ram = 0; /* instruct loader to allocate everything into RAM */ |
| 152 | +int load_to_ram = 1; /* instruct loader to allocate everything into RAM */ |
153 | 153 | int ktrace = 0; /* instruct loader output kernel trace on load */ |
154 | | -int docompress = 0; /* 1 = compress everything, 2 = compress data only */ |
| 154 | +int docompress = 0; /* 1 = compress everything */ |
| 155 | +int lib = 0; /* 1 = this is a shared library */ |
155 | 156 | int use_resolved = 0; /* If true, get the value of symbol references from */ |
156 | 157 | /* the program contents, not from the relocation table. */ |
157 | 158 | /* In this case, the input ELF file must be already */ |
— | — | @@ -1590,10 +1591,8 @@ |
1591 | 1592 | fprintf(stderr, "Usage: %s [vrzd] [-p <abs-pic-file>] [-s stack-size] " |
1592 | 1593 | "[-o <output-file>] <elf-file>\n\n" |
1593 | 1594 | " -v : verbose operation\n" |
1594 | | - " -r : force load to RAM\n" |
1595 | | - " -k : enable kernel trace on load (for debug)\n" |
| 1595 | + " -l : the file to be processed is a shared library\n" |
1596 | 1596 | " -z : compress code/data/relocs\n" |
1597 | | - " -d : compress data/relocs\n" |
1598 | 1597 | " -a : use existing symbol references\n" |
1599 | 1598 | " instead of recalculating from\n" |
1600 | 1599 | " relocation info\n" |
— | — | @@ -1669,23 +1668,17 @@ |
1670 | 1669 | stack = 0x2020; |
1671 | 1670 | #endif |
1672 | 1671 | |
1673 | | - while ((opt = getopt(argc, argv, "avzdrkp:s:o:R:")) != -1) { |
| 1672 | + while ((opt = getopt(argc, argv, "avzlp:s:o:R:")) != -1) { |
1674 | 1673 | switch (opt) { |
1675 | 1674 | case 'v': |
1676 | 1675 | verbose++; |
1677 | 1676 | break; |
1678 | | - case 'r': |
1679 | | - load_to_ram++; |
| 1677 | + case 'l': |
| 1678 | + lib = 1; |
1680 | 1679 | break; |
1681 | | - case 'k': |
1682 | | - ktrace++; |
1683 | | - break; |
1684 | 1680 | case 'z': |
1685 | 1681 | docompress = 1; |
1686 | 1682 | break; |
1687 | | - case 'd': |
1688 | | - docompress = 2; |
1689 | | - break; |
1690 | 1683 | case 'p': |
1691 | 1684 | pfile = optarg; |
1692 | 1685 | break; |
— | — | @@ -1711,12 +1704,6 @@ |
1712 | 1705 | } |
1713 | 1706 | } |
1714 | 1707 | |
1715 | | - /* |
1716 | | - * if neither the -r or -p options was given, default to |
1717 | | - * a RAM load as that is the only option that makes sense. |
1718 | | - */ |
1719 | | - if (!load_to_ram && !pfile) |
1720 | | - load_to_ram = 1; |
1721 | 1708 | |
1722 | 1709 | fname = argv[argc-1]; |
1723 | 1710 | |
— | — | @@ -1865,16 +1852,17 @@ |
1866 | 1853 | |
1867 | 1854 | /* Fill in the binflt_flat header */ |
1868 | 1855 | memcpy(hdr.signature, "emCOexec", 8); |
1869 | | - hdr.version = EMCOREAPP_HEADER_VERSION;
|
1870 | | - hdr.textstart = sizeof(hdr);
|
1871 | | - hdr.textsize = text_len + data_len;
|
1872 | | - hdr.bsssize = bss_len;
|
1873 | | - hdr.stacksize = stack;
|
1874 | | - hdr.entrypoint = bfd_get_start_address(abs_bfd);
|
1875 | | - hdr.relocstart = sizeof(hdr) + text_len + data_len;
|
1876 | | - hdr.reloccount = reloc_len;
|
1877 | | - hdr.flags = docompress ? EMCOREAPP_FLAG_COMPRESSED : 0;
|
1878 | | - hdr.creationtime = (uint32_t)time(NULL);
|
| 1856 | + hdr.version = EMCOREAPP_HEADER_VERSION; |
| 1857 | + hdr.textstart = sizeof(hdr); |
| 1858 | + hdr.textsize = text_len + data_len; |
| 1859 | + hdr.bsssize = bss_len; |
| 1860 | + hdr.stacksize = stack; |
| 1861 | + hdr.entrypoint = bfd_get_start_address(abs_bfd); |
| 1862 | + hdr.relocstart = sizeof(hdr) + text_len + data_len; |
| 1863 | + hdr.reloccount = reloc_len; |
| 1864 | + hdr.flags = (docompress ? EMCOREAPP_FLAG_COMPRESSED : 0) |
| 1865 | + | (lib ? EMCOREAPP_FLAG_LIBRARY : 0); |
| 1866 | + hdr.creationtime = (uint32_t)time(NULL); |
1879 | 1867 | |
1880 | 1868 | for (i=0; i<reloc_len; i++) reloc[i] = reloc[i]; |
1881 | 1869 | |
— | — | @@ -1889,7 +1877,8 @@ |
1890 | 1878 | if (!ofile) { |
1891 | 1879 | ofile = xmalloc(strlen(fname) + 10 + 1); /* 10 to add suffix */ |
1892 | 1880 | strcpy(ofile, fname); |
1893 | | - strcat(ofile, ".emcoreapp"); |
| 1881 | + if (lib) strcat(ofile, ".emcorelib"); |
| 1882 | + else strcat(ofile, ".emcoreapp"); |
1894 | 1883 | } |
1895 | 1884 | |
1896 | 1885 | if ((fd = open (ofile, O_WRONLY|O_BINARY|O_CREAT|O_TRUNC, 0744)) < 0) |
Index: emcore/trunk/init.c |
— | — | @@ -200,7 +200,6 @@ |
201 | 201 | break;
|
202 | 202 | }
|
203 | 203 | success = execimage(buffer, false) != NULL;
|
204 | | - if (!success) free(buffer);
|
205 | 204 | break;
|
206 | 205 | }
|
207 | 206 | #endif
|
— | — | @@ -230,7 +229,6 @@ |
231 | 230 | }
|
232 | 231 | close(fd);
|
233 | 232 | success = execimage(buffer, false) != NULL;
|
234 | | - if (!success) free(buffer);
|
235 | 233 | break;
|
236 | 234 | }
|
237 | 235 | #endif
|
Index: emcore/trunk/execimage.c |
— | — | @@ -71,17 +71,11 @@ |
72 | 72 | return NULL;
|
73 | 73 | }
|
74 | 74 | uint32_t decompsize;
|
75 | | - if (ucl_decompress(image + offset, datasize, alloc, &decompsize))
|
76 | | - {
|
77 | | - cprintf(CONSOLE_BOOT, "execimage: Decompression failed!\n");
|
78 | | - if (!copy) free(image);
|
79 | | - free(alloc);
|
80 | | - return NULL;
|
81 | | - }
|
| 75 | + ucl_decompress(image + offset, datasize, alloc, &decompsize);
|
82 | 76 | if (!copy) free(image);
|
83 | 77 | if (datasize != decompsize)
|
84 | 78 | {
|
85 | | - cprintf(CONSOLE_BOOT, "execimage: Decompressed size mismatch!\n");
|
| 79 | + cprintf(CONSOLE_BOOT, "execimage: Decompression failed!\n");
|
86 | 80 | free(alloc);
|
87 | 81 | return NULL;
|
88 | 82 | }
|
Index: emcore/trunk/export/syscallwrappers.h |
— | — | @@ -187,6 +187,16 @@ |
188 | 188 | #define int_dma_set_handler __emcore_syscall->int_dma_set_handler
|
189 | 189 | #define thread_set_name __emcore_syscall->thread_set_name
|
190 | 190 | #define thread_set_priority __emcore_syscall->thread_set_priority
|
| 191 | +#define malloc __emcore_syscall->malloc
|
| 192 | +#define memalign __emcore_syscall->memalogn
|
| 193 | +#define realloc __emcore_syscall->realloc
|
| 194 | +#define reownalloc __emcore_syscall->reownalloc
|
| 195 | +#define free __emcore_syscall->free
|
| 196 | +#define library_unload __emcore_syscall->library_unload
|
| 197 | +#define get_library __emcore_syscall->get_library
|
| 198 | +#define get_library_ext __emcore_syscall->get_library_ext
|
| 199 | +#define release_library __emcore_syscall->release_library
|
| 200 | +#define release_library_ext __emcore_syscall->release_library_ext
|
191 | 201 |
|
192 | 202 |
|
193 | 203 | #endif
|
Index: emcore/trunk/export/emcorelib.h |
— | — | @@ -1,23 +1,23 @@ |
2 | 2 | #include "syscallwrappers.h"
|
3 | 3 |
|
4 | 4 |
|
5 | | -#define EMCORE_LIB_HEADER(libidentifier, libversion, initfunc, shutdownfunc, apipointer) \
|
| 5 | +#define EMCORE_LIB_HEADER(lib_identifier, lib_version, init_func, shutdown_func, api_pointer) \
|
6 | 6 | struct emcore_syscall_table* __emcore_syscall; \
|
7 | 7 | int __emcore_lib_init() \
|
8 | 8 | { \
|
9 | 9 | asm volatile("swi\t2\n\tldr\tr1, =__emcore_syscall\n\tstr\tr0, [r1]\n\t" \
|
10 | 10 | ::: "r0", "r1", "r2", "r3", "r12", "lr", "cc", "memory"); \
|
11 | | - if (__embios_syscall->table_version < EMCORE_API_VERSION \
|
12 | | - || __embios_syscall->table_minversion > EMCORE_API_VERSION) \
|
| 11 | + if (__emcore_syscall->table_version < EMCORE_API_VERSION \
|
| 12 | + || __emcore_syscall->table_minversion > EMCORE_API_VERSION) \
|
13 | 13 | return 0x80000000; \
|
14 | | - if (initfunc) return initfunc(); \
|
| 14 | + if (init_func) return init_func(); \
|
15 | 15 | } \
|
16 | | - struct emcorelib_header __attribute__((section(".emcoreentrypoint"))) __emcore_entrypoint() \
|
| 16 | + struct emcorelib_header __emcore_lib_header __attribute__((section(".emcoreentrypoint"))) = \
|
17 | 17 | { \
|
18 | 18 | .headerversion = EMCORELIB_HEADER_VERSION, \
|
19 | | - .identifier = libidentifier, \
|
20 | | - .version = libversion, \
|
| 19 | + .identifier = lib_identifier, \
|
| 20 | + .version = lib_version, \
|
21 | 21 | .initfunc = __emcore_lib_init, \
|
22 | | - .shutdownfunc = shutdownfunc, \
|
23 | | - .api = apipointer \
|
| 22 | + .shutdownfunc = shutdown_func, \
|
| 23 | + .api = &api_pointer \
|
24 | 24 | };
|
Index: emcore/trunk/export/syscallapi.h |
— | — | @@ -57,6 +57,8 @@ |
58 | 58 | #include "../contextswitch.h"
|
59 | 59 | #include "../hwkeyaes.h"
|
60 | 60 | #include "../hmacsha1.h"
|
| 61 | +#include "../malloc.h"
|
| 62 | +#include "../library.h"
|
61 | 63 | #include "../libc/include/string.h"
|
62 | 64 | #include "../libc/include/stdlib.h"
|
63 | 65 | #include "../libc/include/stdio.h"
|
— | — | @@ -231,6 +233,16 @@ |
232 | 234 | typeof(int_dma_set_handler) *int_dma_set_handler;
|
233 | 235 | typeof(thread_set_name) *thread_set_name;
|
234 | 236 | typeof(thread_set_priority) *thread_set_priority;
|
| 237 | + typeof(malloc) *malloc;
|
| 238 | + typeof(memalign) *memalign;
|
| 239 | + typeof(realloc) *realloc;
|
| 240 | + typeof(reownalloc) *reownalloc;
|
| 241 | + typeof(free) *free;
|
| 242 | + typeof(library_unload) *library_unload;
|
| 243 | + typeof(get_library) *get_library;
|
| 244 | + typeof(get_library_ext) *get_library_ext;
|
| 245 | + typeof(release_library) *release_library;
|
| 246 | + typeof(release_library_ext) *release_library_ext;
|
235 | 247 | };
|
236 | 248 |
|
237 | 249 |
|
Index: emcore/trunk/syscallapi.c |
— | — | @@ -198,5 +198,15 @@ |
199 | 199 | #endif
|
200 | 200 | .int_dma_set_handler = int_dma_set_handler,
|
201 | 201 | .thread_set_name = thread_set_name,
|
202 | | - .thread_set_priority = thread_set_priority
|
| 202 | + .thread_set_priority = thread_set_priority,
|
| 203 | + .malloc = malloc,
|
| 204 | + .memalign = memalign,
|
| 205 | + .realloc = realloc,
|
| 206 | + .reownalloc = reownalloc,
|
| 207 | + .free = free,
|
| 208 | + .library_unload = library_unload,
|
| 209 | + .get_library = get_library,
|
| 210 | + .get_library_ext = get_library_ext,
|
| 211 | + .release_library = release_library,
|
| 212 | + .release_library_ext = release_library_ext
|
203 | 213 | };
|
Index: emcore/trunk/library.c |
— | — | @@ -64,6 +64,7 @@ |
65 | 65 | handle->next = library_list_head;
|
66 | 66 | handle->lib = header;
|
67 | 67 | handle->alloc = image;
|
| 68 | + library_list_head = handle;
|
68 | 69 | mutex_unlock(&library_mutex);
|
69 | 70 | return handle;
|
70 | 71 | }
|
— | — | @@ -143,8 +144,71 @@ |
144 | 145 | }
|
145 | 146 | if (!best)
|
146 | 147 | {
|
147 | | - mutex_unlock(&library_mutex);
|
148 | | - return NULL;
|
| 148 | + switch (sourcetype)
|
| 149 | + {
|
| 150 | + case LIBSOURCE_RAM_ALLOCED:
|
| 151 | + {
|
| 152 | + best = (struct library_handle*)execimage(source, false);
|
| 153 | + break;
|
| 154 | + }
|
| 155 | +
|
| 156 | + case LIBSOURCE_RAM_NEEDCOPY:
|
| 157 | + {
|
| 158 | + best = (struct library_handle*)execimage(source, true);
|
| 159 | + break;
|
| 160 | + }
|
| 161 | +
|
| 162 | +#ifdef HAVE_BOOTFLASH
|
| 163 | + case LIBSOURCE_BOOTFLASH:
|
| 164 | + {
|
| 165 | + int size = bootflash_filesize((char*)source);
|
| 166 | + if (size <= 0) break;
|
| 167 | + void* buffer = memalign(0x10, size);
|
| 168 | + if (!buffer) break;
|
| 169 | + if (bootflash_read((char*)source, buffer, 0, size) != size)
|
| 170 | + {
|
| 171 | + free(buffer);
|
| 172 | + break;
|
| 173 | + }
|
| 174 | + best = (struct library_handle*)execimage(buffer, false);
|
| 175 | + break;
|
| 176 | + }
|
| 177 | +#endif
|
| 178 | +
|
| 179 | +#ifdef HAVE_STORAGE
|
| 180 | + case LIBSOURCE_FILESYSTEM:
|
| 181 | + {
|
| 182 | + int fd = file_open((char*)source, O_RDONLY);
|
| 183 | + if (fd <= 0) break;
|
| 184 | + int size = filesize(fd);
|
| 185 | + if (size <= 0)
|
| 186 | + {
|
| 187 | + close(fd);
|
| 188 | + break;
|
| 189 | + }
|
| 190 | + void* buffer = memalign(0x10, size);
|
| 191 | + if (!buffer)
|
| 192 | + {
|
| 193 | + close(fd);
|
| 194 | + break;
|
| 195 | + }
|
| 196 | + if (read(fd, buffer, size) != size)
|
| 197 | + {
|
| 198 | + free(buffer);
|
| 199 | + close(fd);
|
| 200 | + break;
|
| 201 | + }
|
| 202 | + close(fd);
|
| 203 | + best = (struct library_handle*)execimage(buffer, false);
|
| 204 | + break;
|
| 205 | + }
|
| 206 | +#endif
|
| 207 | + }
|
| 208 | + if (!best)
|
| 209 | + {
|
| 210 | + mutex_unlock(&library_mutex);
|
| 211 | + return NULL;
|
| 212 | + }
|
149 | 213 | }
|
150 | 214 | for (i = 0; i < ARRAYLEN(best->users); i++)
|
151 | 215 | if (best->users[i] == NULL)
|
Index: emcore/trunk/library.h |
— | — | @@ -56,6 +56,7 @@ |
57 | 57 |
|
58 | 58 | enum library_sourcetype
|
59 | 59 | {
|
| 60 | + LIBSOURCE_NONE = 0,
|
60 | 61 | LIBSOURCE_RAM_ALLOCED = 1,
|
61 | 62 | LIBSOURCE_RAM_NEEDCOPY = 2,
|
62 | 63 | LIBSOURCE_BOOTFLASH = 3,
|