blob: 9f16abf71d32a2682e08684786c2e629b0d3b208 [file] [log] [blame]
adamdunkels1e45c6d2003-09-02 21:47:27 +00001/**
2 * \file
3 * Default definitions and error values for the Contiki program loader.
4 * \author Adam Dunkels <adam@dunkels.com>
5 *
6 */
7
adamdunkelsb1e962a2003-04-08 07:17:48 +00008/*
9 * Copyright (c) 2003, Adam Dunkels.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials provided
20 * with the distribution.
adamdunkels1e45c6d2003-09-02 21:47:27 +000021 * 3. The name of the author may not be used to endorse or promote
adamdunkelsb1e962a2003-04-08 07:17:48 +000022 * products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
26 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
29 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
31 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * This file is part of the Contiki desktop OS
38 *
adamdunkels1e45c6d2003-09-02 21:47:27 +000039 * $Id: loader.h,v 1.7 2003/09/02 21:47:28 adamdunkels Exp $
adamdunkelsb1e962a2003-04-08 07:17:48 +000040 *
41 */
42#ifndef __LOADER_H__
43#define __LOADER_H__
44
adamdunkels1d7a5752003-04-24 17:18:43 +000045/* Errors that the LOADER_LOAD() function may return: */
46
adamdunkels1e45c6d2003-09-02 21:47:27 +000047#define LOADER_OK 0 /**< No error. */
48#define LOADER_ERR_READ 1 /**< Read error. */
49#define LOADER_ERR_HDR 2 /**< Header error. */
50#define LOADER_ERR_OS 3 /**< Wrong OS. */
51#define LOADER_ERR_FMT 4 /**< Data format error. */
52#define LOADER_ERR_MEM 5 /**< Not enough memory. */
53#define LOADER_ERR_OPEN 6 /**< Could not open file. */
54#define LOADER_ERR_ARCH 7 /**< Wrong architecture. */
55#define LOADER_ERR_VERSION 8 /**< Wrong OS version. */
56#define LOADER_ERR_NOLOADER 9 /**< Program loading not supported. */
adamdunkels1d7a5752003-04-24 17:18:43 +000057
adamdunkelsb1e962a2003-04-08 07:17:48 +000058#ifdef WITH_LOADER_ARCH
59#include "loader-arch.h"
adamdunkels8bb5cca2003-08-24 22:41:31 +000060#define LOADER_INIT_FUNC(name, arg) void init(char *arg)
adamdunkelsf038eea2003-04-08 19:28:55 +000061#else /* WITH_LOADER_ARCH */
adamdunkels8bb5cca2003-08-24 22:41:31 +000062#define LOADER_INIT_FUNC(name, arg) void name(char *arg)
adamdunkelsb1e962a2003-04-08 07:17:48 +000063#endif /* WITH_LOADER_ARCH */
64
adamdunkels1e45c6d2003-09-02 21:47:27 +000065/**
66 * Load and execute a program.
67 *
68 * This macro is used for loading and executing a program, and
69 * requires support from the architecture dependant code. The actual
70 * program loading is made by architecture specific functions.
71 *
72 * \note A program loaded with LOADER_LOAD() must call the
73 * LOADER_UNLOAD() function to unload itself.
74 *
75 * \param name The name of the program to be loaded.
76 *
77 * \param arg A pointer argument that is passed to the program.
78 *
79 * \return A loader error, or LOADER_OK if loading was successful.
80 */
adamdunkelsb1e962a2003-04-08 07:17:48 +000081#ifndef LOADER_LOAD
adamdunkels1e45c6d2003-09-02 21:47:27 +000082#define LOADER_LOAD(name, arg) LOADER_ERR_NOLOADER
adamdunkelsb1e962a2003-04-08 07:17:48 +000083#endif /* LOADER_LOAD */
84
adamdunkels1e45c6d2003-09-02 21:47:27 +000085/**
86 * Unload a program from memory.
87 *
88 * This macro is used for unloading a program and deallocating any
89 * memory that was allocated during the loading of the program. This
90 * function must be called by the program itself.
91 *
92 */
adamdunkelsb1e962a2003-04-08 07:17:48 +000093#ifndef LOADER_UNLOAD
94#define LOADER_UNLOAD()
95#endif /* LOADER_UNLOAD */
96
adamdunkels1e45c6d2003-09-02 21:47:27 +000097/**
98 * Load a DSC (program description).
99 *
100 * Loads a DSC (program description) into memory and returns a pointer
101 * to the dsc.
102 *
103 * \return A pointer to the DSC or NULL if it could not be loaded.
104 */
105#ifndef LOADER_LOAD_DSC
106#define LOADER_LOAD_DSC(name) NULL
107#endif /* LOADER_LOAD_DSC */
108
109/**
110 * Unload a DSC (program description).
111 *
112 * Unload a DSC from memory and deallocate any memory that was
113 * allocated when it was loaded.
114 */
adamdunkels67694372003-04-17 20:06:35 +0000115#ifndef LOADER_UNLOAD_DSC
adamdunkels43c3d1d2003-04-17 19:00:00 +0000116#define LOADER_UNLOAD_DSC(dsc)
117#endif /* LOADER_UNLOAD */
118
adamdunkelsf038eea2003-04-08 19:28:55 +0000119
120
adamdunkelsf038eea2003-04-08 19:28:55 +0000121
adamdunkelsb1e962a2003-04-08 07:17:48 +0000122#endif /* __LOADER_H__ */