1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2011 Amaury Pouly
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __DBPARSER__
#define __DBPARSER__
/**
* Command file parsing
*/
#include "sb.h"
#include "elf.h"
enum cmd_source_type_t
{
CMD_SRC_UNK,
CMD_SRC_ELF,
CMD_SRC_BIN
};
struct bin_param_t
{
uint32_t size;
void *data;
};
struct cmd_source_t
{
char *identifier;
bool is_extern;
// <union>
int extern_nr;
char *filename;
// </union>
struct cmd_source_t *next;
/* for later use */
enum cmd_source_type_t type;
bool loaded;
struct elf_params_t elf;
struct bin_param_t bin;
};
enum cmd_inst_type_t
{
CMD_LOAD, /* load image */
CMD_JUMP, /* jump at image */
CMD_CALL, /* call image */
CMD_LOAD_AT, /* load binary at */
CMD_CALL_AT, /* call at address */
CMD_JUMP_AT, /* jump at address */
CMD_MODE, /* change boot mode */
};
struct cmd_inst_t
{
enum cmd_inst_type_t type;
char *identifier;
uint32_t argument; // for jump, call, mode
uint32_t addr; // for 'at'
struct cmd_inst_t *next;
};
struct cmd_option_t
{
char *name;
bool is_string;
/* <union> */
uint32_t val;
char *str;
/* </union> */
struct cmd_option_t *next;
};
struct cmd_section_t
{
uint32_t identifier;
bool is_data;
// <union>
struct cmd_inst_t *inst_list;
char *source_id;
// </union>
struct cmd_section_t *next;
struct cmd_option_t *opt_list;
};
struct cmd_file_t
{
struct cmd_option_t *opt_list;
struct cmd_option_t *constant_list; /* constant all always integers */
struct cmd_source_t *source_list;
struct cmd_section_t *section_list;
};
struct cmd_source_t *db_find_source_by_id(struct cmd_file_t *cmd_file, const char *id);
struct cmd_option_t *db_find_option_by_id(struct cmd_option_t *opt, const char *name);
bool db_parse_sb_version(struct sb_version_t *ver, char *str);
void db_generate_default_sb_version(struct sb_version_t *ver);
struct cmd_file_t *db_parse_file(const char *file);
#endif /* __DBPARSER__ */
|