adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file |
| 3 | * Default definitions and error values for the Contiki program loader. |
| 4 | * \author Adam Dunkels <adam@dunkels.com> |
| 5 | * |
| 6 | */ |
| 7 | |
adamdunkels | e937ded | 2003-10-01 07:53:57 +0000 | [diff] [blame] | 8 | /** |
| 9 | * \defgroup loader The Contiki program loader |
| 10 | * @{ |
| 11 | * |
| 12 | * The Contiki program loader is an abstract interface for loading and |
| 13 | * starting programs. |
| 14 | */ |
| 15 | |
adamdunkels | b1e962a | 2003-04-08 07:17:48 +0000 | [diff] [blame] | 16 | /* |
| 17 | * Copyright (c) 2003, Adam Dunkels. |
| 18 | * All rights reserved. |
| 19 | * |
| 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions |
| 22 | * are met: |
| 23 | * 1. Redistributions of source code must retain the above copyright |
| 24 | * notice, this list of conditions and the following disclaimer. |
| 25 | * 2. Redistributions in binary form must reproduce the above |
| 26 | * copyright notice, this list of conditions and the following |
| 27 | * disclaimer in the documentation and/or other materials provided |
| 28 | * with the distribution. |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 29 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | b1e962a | 2003-04-08 07:17:48 +0000 | [diff] [blame] | 30 | * products derived from this software without specific prior |
| 31 | * written permission. |
| 32 | * |
| 33 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 34 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 35 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 36 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 37 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 38 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 39 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 40 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 41 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 44 | * |
| 45 | * This file is part of the Contiki desktop OS |
| 46 | * |
oliverschmidt | 3e2db00 | 2005-05-07 14:24:59 +0000 | [diff] [blame] | 47 | * $Id: loader.h,v 1.10 2005/05/07 14:24:59 oliverschmidt Exp $ |
adamdunkels | b1e962a | 2003-04-08 07:17:48 +0000 | [diff] [blame] | 48 | * |
| 49 | */ |
| 50 | #ifndef __LOADER_H__ |
| 51 | #define __LOADER_H__ |
| 52 | |
adamdunkels | 1d7a575 | 2003-04-24 17:18:43 +0000 | [diff] [blame] | 53 | /* Errors that the LOADER_LOAD() function may return: */ |
| 54 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 55 | #define LOADER_OK 0 /**< No error. */ |
| 56 | #define LOADER_ERR_READ 1 /**< Read error. */ |
| 57 | #define LOADER_ERR_HDR 2 /**< Header error. */ |
| 58 | #define LOADER_ERR_OS 3 /**< Wrong OS. */ |
| 59 | #define LOADER_ERR_FMT 4 /**< Data format error. */ |
| 60 | #define LOADER_ERR_MEM 5 /**< Not enough memory. */ |
| 61 | #define LOADER_ERR_OPEN 6 /**< Could not open file. */ |
| 62 | #define LOADER_ERR_ARCH 7 /**< Wrong architecture. */ |
| 63 | #define LOADER_ERR_VERSION 8 /**< Wrong OS version. */ |
| 64 | #define LOADER_ERR_NOLOADER 9 /**< Program loading not supported. */ |
adamdunkels | 1d7a575 | 2003-04-24 17:18:43 +0000 | [diff] [blame] | 65 | |
adamdunkels | b1e962a | 2003-04-08 07:17:48 +0000 | [diff] [blame] | 66 | #ifdef WITH_LOADER_ARCH |
| 67 | #include "loader-arch.h" |
oliverschmidt | 3e2db00 | 2005-05-07 14:24:59 +0000 | [diff] [blame] | 68 | #include "loader-arch-dsc.h" |
adamdunkels | 7241302 | 2004-06-06 06:23:57 +0000 | [diff] [blame] | 69 | #define LOADER_INIT_FUNC(name, arg) void loader_appinit(char *arg) |
adamdunkels | f038eea | 2003-04-08 19:28:55 +0000 | [diff] [blame] | 70 | #else /* WITH_LOADER_ARCH */ |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 71 | #define LOADER_INIT_FUNC(name, arg) void name(char *arg) |
adamdunkels | b1e962a | 2003-04-08 07:17:48 +0000 | [diff] [blame] | 72 | #endif /* WITH_LOADER_ARCH */ |
| 73 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 74 | /** |
| 75 | * Load and execute a program. |
| 76 | * |
| 77 | * This macro is used for loading and executing a program, and |
| 78 | * requires support from the architecture dependant code. The actual |
| 79 | * program loading is made by architecture specific functions. |
| 80 | * |
| 81 | * \note A program loaded with LOADER_LOAD() must call the |
| 82 | * LOADER_UNLOAD() function to unload itself. |
| 83 | * |
| 84 | * \param name The name of the program to be loaded. |
| 85 | * |
| 86 | * \param arg A pointer argument that is passed to the program. |
| 87 | * |
| 88 | * \return A loader error, or LOADER_OK if loading was successful. |
| 89 | */ |
adamdunkels | b1e962a | 2003-04-08 07:17:48 +0000 | [diff] [blame] | 90 | #ifndef LOADER_LOAD |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 91 | #define LOADER_LOAD(name, arg) LOADER_ERR_NOLOADER |
adamdunkels | b1e962a | 2003-04-08 07:17:48 +0000 | [diff] [blame] | 92 | #endif /* LOADER_LOAD */ |
| 93 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 94 | /** |
| 95 | * Unload a program from memory. |
| 96 | * |
| 97 | * This macro is used for unloading a program and deallocating any |
| 98 | * memory that was allocated during the loading of the program. This |
| 99 | * function must be called by the program itself. |
| 100 | * |
| 101 | */ |
adamdunkels | b1e962a | 2003-04-08 07:17:48 +0000 | [diff] [blame] | 102 | #ifndef LOADER_UNLOAD |
| 103 | #define LOADER_UNLOAD() |
| 104 | #endif /* LOADER_UNLOAD */ |
| 105 | |
adamdunkels | 1e45c6d | 2003-09-02 21:47:27 +0000 | [diff] [blame] | 106 | /** |
| 107 | * Load a DSC (program description). |
| 108 | * |
| 109 | * Loads a DSC (program description) into memory and returns a pointer |
| 110 | * to the dsc. |
| 111 | * |
| 112 | * \return A pointer to the DSC or NULL if it could not be loaded. |
| 113 | */ |
| 114 | #ifndef LOADER_LOAD_DSC |
| 115 | #define LOADER_LOAD_DSC(name) NULL |
| 116 | #endif /* LOADER_LOAD_DSC */ |
| 117 | |
| 118 | /** |
| 119 | * Unload a DSC (program description). |
| 120 | * |
| 121 | * Unload a DSC from memory and deallocate any memory that was |
| 122 | * allocated when it was loaded. |
| 123 | */ |
adamdunkels | 6769437 | 2003-04-17 20:06:35 +0000 | [diff] [blame] | 124 | #ifndef LOADER_UNLOAD_DSC |
adamdunkels | 43c3d1d | 2003-04-17 19:00:00 +0000 | [diff] [blame] | 125 | #define LOADER_UNLOAD_DSC(dsc) |
| 126 | #endif /* LOADER_UNLOAD */ |
| 127 | |
adamdunkels | f038eea | 2003-04-08 19:28:55 +0000 | [diff] [blame] | 128 | |
| 129 | |
adamdunkels | f038eea | 2003-04-08 19:28:55 +0000 | [diff] [blame] | 130 | |
adamdunkels | b1e962a | 2003-04-08 07:17:48 +0000 | [diff] [blame] | 131 | #endif /* __LOADER_H__ */ |