kthacker | 6de6775 | 2006-04-17 15:02:26 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2003, Adam Dunkels. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * 3. All advertising materials mentioning features or use of this |
| 15 | * software must display the following acknowledgement: |
| 16 | * This product includes software developed by Adam Dunkels. |
| 17 | * 4. The name of the author may not be used to endorse or promote |
| 18 | * products derived from this software without specific prior |
| 19 | * written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 27 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | * |
| 33 | * This file is part of the Contiki desktop OS |
| 34 | * |
| 35 | * $Id: loader-arch.c.old,v 1.1 2006/04/17 15:02:38 kthacker Exp $ |
| 36 | * |
| 37 | */ |
| 38 | |
| 39 | #include <stdlib.h> |
| 40 | #include <modload.h> |
| 41 | |
| 42 | #ifndef NULL |
| 43 | #define NULL (void *)0 |
| 44 | #endif /* NULL */ |
| 45 | |
| 46 | #include "cpc-fs.h" |
| 47 | |
| 48 | #include "loader.h" |
| 49 | |
| 50 | #include "loader-arch.h" |
| 51 | |
| 52 | struct loader_arch_hdr { |
| 53 | char arch[8]; |
| 54 | char version[8]; |
| 55 | |
| 56 | char initfunc[1]; |
| 57 | }; |
| 58 | |
| 59 | /*-----------------------------------------------------------------------------------*/ |
| 60 | /* load(name) |
| 61 | * |
| 62 | * Loads a program from disk and executes it. Code originally written by |
| 63 | * Ullrich von Bassewitz. |
| 64 | */ |
| 65 | /*-----------------------------------------------------------------------------------*/ |
| 66 | static unsigned char |
| 67 | load(const char *name) |
| 68 | { |
| 69 | unsigned char res; |
| 70 | int ret; |
| 71 | |
| 72 | /* Now open the file */ |
| 73 | ret = cpc_fs_open(name); |
| 74 | if(ret < 0) { |
| 75 | /* Could not open the file, display an error and return */ |
| 76 | /* ### */ |
| 77 | return LOADER_ERR_OPEN; |
| 78 | } |
| 79 | /* ctrl.callerdata = (int)&file; */ |
| 80 | |
| 81 | /* Load the module */ |
| 82 | res = cpc_fs_read(); |
| 83 | |
| 84 | /* Close the input file */ |
| 85 | cpc_fs_close(); |
| 86 | |
| 87 | /* Check the return code */ |
| 88 | if(res != MLOAD_OK) { |
| 89 | /* Wrong module, out of memory or whatever. Print an error |
| 90 | * message and return. |
| 91 | */ |
| 92 | /* ### */ |
| 93 | return res; |
| 94 | } |
| 95 | |
| 96 | /* We've successfully loaded the module. */ |
| 97 | |
| 98 | return LOADER_OK; |
| 99 | } |
| 100 | /*-----------------------------------------------------------------------------------*/ |
| 101 | unsigned char |
| 102 | loader_arch_load(const char *name, char *arg) |
| 103 | { |
| 104 | unsigned char r; |
| 105 | struct loader_arch_hdr *hdr; |
| 106 | |
| 107 | r = load(name); |
| 108 | if(r != MLOAD_OK) { |
| 109 | return r; |
| 110 | } |
| 111 | // hdr = (struct loader_arch_hdr *)ctrl.module; |
| 112 | |
| 113 | /* Check the program header and see that version and architecture |
| 114 | matches. */ |
| 115 | |
| 116 | /* Call the init function. */ |
| 117 | |
| 118 | ((void (*)(char *))hdr->initfunc)(arg); |
| 119 | |
| 120 | return LOADER_OK; |
| 121 | } |
| 122 | /*-----------------------------------------------------------------------------------*/ |
| 123 | struct dsc * |
| 124 | loader_arch_load_dsc(const char *name) |
| 125 | { |
| 126 | unsigned char r; |
| 127 | |
| 128 | r = load(name); |
| 129 | if(r == MLOAD_OK) { |
| 130 | return (struct dsc *)ctrl.module; |
| 131 | } |
| 132 | return NULL; |
| 133 | } |
| 134 | /*-----------------------------------------------------------------------------------*/ |
| 135 | void |
| 136 | loader_arch_free(void *addr) |
| 137 | { |
| 138 | mod_free(addr); |
| 139 | } |
| 140 | /*-----------------------------------------------------------------------------------*/ |
| 141 | |