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