blob: 30eee0ea05f408d96d1b04de26df031c7bf79ed4 [file] [log] [blame]
Aaron Durbinad935522012-12-24 14:28:37 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 ChromeOS Authors
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19#ifndef RMODULE_H
20#define RMODULE_H
21
22#include <stdint.h>
23
24#define RMODULE_MAGIC 0xf8fe
25#define RMODULE_VERSION_1 1
26
27enum {
28 RMODULE_TYPE_SMM,
Aaron Durbin9be4c472013-01-12 00:41:44 -060029 RMODULE_TYPE_SIPI_VECTOR,
Aaron Durbinad935522012-12-24 14:28:37 -060030};
31
32struct rmodule;
33
34/* Public API for loading rmdoules. */
35int rmodule_parse(void *ptr, struct rmodule *m);
36void *rmodule_parameters(const struct rmodule *m);
37void *rmodule_entry(const struct rmodule *m);
38int rmodule_entry_offset(const struct rmodule *m);
39int rmodule_memory_size(const struct rmodule *m);
40int rmodule_load(void *loc, struct rmodule *m);
41int rmodule_load_alignment(const struct rmodule *m);
42
43#define FIELD_ENTRY(x_) ((u32)&x_)
44#define RMODULE_HEADER(entry_, type_) \
45{ \
46 .magic = RMODULE_MAGIC, \
47 .version = RMODULE_VERSION_1, \
48 .type = type_, \
49 .payload_begin_offset = FIELD_ENTRY(_payload_begin_offset), \
50 .payload_end_offset = FIELD_ENTRY(_payload_end_offset), \
51 .relocations_begin_offset = \
52 FIELD_ENTRY(_relocations_begin_offset), \
53 .relocations_end_offset = \
54 FIELD_ENTRY(_relocations_end_offset), \
55 .module_link_start_address = \
56 FIELD_ENTRY(_module_link_start_addr), \
57 .module_program_size = FIELD_ENTRY(_module_program_size), \
58 .module_entry_point = FIELD_ENTRY(entry_), \
59 .parameters_begin = FIELD_ENTRY(_module_params_begin), \
60 .parameters_end = FIELD_ENTRY(_module_params_end), \
61 .bss_begin = FIELD_ENTRY(_bss_begin), \
62 .bss_end = FIELD_ENTRY(_bss_end), \
63}
64
65#define DEFINE_RMODULE_HEADER(name_, entry_, type_) \
66 struct rmodule_header name_ \
67 __attribute__ ((section (".module_header"))) = \
68 RMODULE_HEADER(entry_, type_)
69
70
71/* Private data structures below should not be used directly. */
72
73/* All fields with '_offset' in the name are byte offsets into the flat blob.
74 * The linker and the linker script takes are of assigning the values. */
75struct rmodule_header {
76 u16 magic;
77 u8 version;
78 u8 type;
79 /* The payload represents the program's loadable code and data. */
80 u32 payload_begin_offset;
81 u32 payload_end_offset;
82 /* Begin and of relocation information about the program module. */
83 u32 relocations_begin_offset;
84 u32 relocations_end_offset;
85 /* The starting address of the linked program. This address is vital
86 * for determining relocation offsets as the reloction info and other
87 * symbols (bss, entry point) need this value as a basis to calculate
88 * the offsets.
89 */
90 u32 module_link_start_address;
91 /* The module_program_size is the size of memory used while running
92 * the program. The program is assumed to consume a contiguos amount
93 * of memory. */
94 u32 module_program_size;
95 /* This is program's execution entry point. */
96 u32 module_entry_point;
97 /* Optional paramter structure that can be used to pass data into
98 * the module. */
99 u32 parameters_begin;
100 u32 parameters_end;
101 /* BSS section information so the loader can clear the bss. */
102 u32 bss_begin;
103 u32 bss_end;
Aaron Durbin3bf0ce72013-02-06 12:47:26 -0600104 /* Add some room for growth. */
105 u32 padding[4];
Aaron Durbinad935522012-12-24 14:28:37 -0600106} __attribute__ ((packed));
107
108struct rmodule {
109 void *location;
110 struct rmodule_header *header;
111 const void *payload;
112 int payload_size;
113 void *relocations;
114};
115
116/* These are the symbols assumed that every module contains. The linker script
117 * provides these symbols. */
118extern char _relocations_begin_offset[];
119extern char _relocations_end_offset[];
120extern char _payload_end_offset[];
121extern char _payload_begin_offset[];
122extern char _bss_begin[];
123extern char _bss_end[];
124extern char _module_program_size[];
125extern char _module_link_start_addr[];
126extern char _module_params_begin[];
127extern char _module_params_end[];
128
129#endif /* RMODULE_H */