| OLD | NEW |
| 1 /* | 1 /* |
| 2 * ORG bytecode | 2 * ORG bytecode |
| 3 * | 3 * |
| 4 * Copyright (C) 2005-2007 Peter Johnson | 4 * Copyright (C) 2005-2007 Peter Johnson |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | 11 * 2. Redistributions in binary form must reproduce the above copyright |
| 12 * notice, this list of conditions and the following disclaimer in the | 12 * notice, this list of conditions and the following disclaimer in the |
| 13 * documentation and/or other materials provided with the distribution. | 13 * documentation and/or other materials provided with the distribution. |
| 14 * | 14 * |
| 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' | 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' |
| 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE | 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE |
| 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 * POSSIBILITY OF SUCH DAMAGE. | 25 * POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 #include "util.h" | 27 #include "util.h" |
| 28 /*@unused@*/ RCSID("$Id: bc-org.c 2130 2008-10-07 05:38:11Z peter $"); | |
| 29 | 28 |
| 30 #include "libyasm-stdint.h" | 29 #include "libyasm-stdint.h" |
| 31 #include "coretype.h" | 30 #include "coretype.h" |
| 32 #include "file.h" | 31 #include "file.h" |
| 33 | 32 |
| 34 #include "errwarn.h" | 33 #include "errwarn.h" |
| 35 #include "intnum.h" | 34 #include "intnum.h" |
| 36 #include "expr.h" | 35 #include "expr.h" |
| 37 #include "value.h" | 36 #include "value.h" |
| 38 | 37 |
| 39 #include "bytecode.h" | 38 #include "bytecode.h" |
| 40 | 39 |
| 41 | 40 |
| 42 typedef struct bytecode_org { | 41 typedef struct bytecode_org { |
| 43 unsigned long start; /* target starting offset within section */ | 42 unsigned long start; /* target starting offset within section */ |
| 44 unsigned long fill; /* fill value */ | 43 unsigned long fill; /* fill value */ |
| 45 } bytecode_org; | 44 } bytecode_org; |
| 46 | 45 |
| 47 static void bc_org_destroy(void *contents); | 46 static void bc_org_destroy(void *contents); |
| 48 static void bc_org_print(const void *contents, FILE *f, int indent_level); | 47 static void bc_org_print(const void *contents, FILE *f, int indent_level); |
| 49 static void bc_org_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); | 48 static void bc_org_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc); |
| 50 static int bc_org_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, | 49 static int bc_org_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, |
| 51 void *add_span_data); | 50 void *add_span_data); |
| 52 static int bc_org_expand(yasm_bytecode *bc, int span, long old_val, | 51 static int bc_org_expand(yasm_bytecode *bc, int span, long old_val, |
| 53 long new_val, /*@out@*/ long *neg_thres, | 52 long new_val, /*@out@*/ long *neg_thres, |
| 54 /*@out@*/ long *pos_thres); | 53 /*@out@*/ long *pos_thres); |
| 55 static int bc_org_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, | 54 static int bc_org_tobytes(yasm_bytecode *bc, unsigned char **bufp, |
| 55 unsigned char *bufstart, void *d, |
| 56 yasm_output_value_func output_value, | 56 yasm_output_value_func output_value, |
| 57 /*@null@*/ yasm_output_reloc_func output_reloc); | 57 /*@null@*/ yasm_output_reloc_func output_reloc); |
| 58 | 58 |
| 59 static const yasm_bytecode_callback bc_org_callback = { | 59 static const yasm_bytecode_callback bc_org_callback = { |
| 60 bc_org_destroy, | 60 bc_org_destroy, |
| 61 bc_org_print, | 61 bc_org_print, |
| 62 bc_org_finalize, | 62 bc_org_finalize, |
| 63 NULL, | 63 NULL, |
| 64 bc_org_calc_len, | 64 bc_org_calc_len, |
| 65 bc_org_expand, | 65 bc_org_expand, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 N_("ORG overlap with already existing data")); | 113 N_("ORG overlap with already existing data")); |
| 114 return -1; | 114 return -1; |
| 115 } | 115 } |
| 116 | 116 |
| 117 /* Generate space to start offset */ | 117 /* Generate space to start offset */ |
| 118 bc->len = org->start - new_val; | 118 bc->len = org->start - new_val; |
| 119 return 1; | 119 return 1; |
| 120 } | 120 } |
| 121 | 121 |
| 122 static int | 122 static int |
| 123 bc_org_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, | 123 bc_org_tobytes(yasm_bytecode *bc, unsigned char **bufp, |
| 124 unsigned char *bufstart, void *d, |
| 124 yasm_output_value_func output_value, | 125 yasm_output_value_func output_value, |
| 125 /*@unused@*/ yasm_output_reloc_func output_reloc) | 126 /*@unused@*/ yasm_output_reloc_func output_reloc) |
| 126 { | 127 { |
| 127 bytecode_org *org = (bytecode_org *)bc->contents; | 128 bytecode_org *org = (bytecode_org *)bc->contents; |
| 128 unsigned long len, i; | 129 unsigned long len, i; |
| 129 | 130 |
| 130 /* Sanity check for overrun */ | 131 /* Sanity check for overrun */ |
| 131 if (bc->offset > org->start) { | 132 if (bc->offset > org->start) { |
| 132 yasm_error_set(YASM_ERROR_GENERAL, | 133 yasm_error_set(YASM_ERROR_GENERAL, |
| 133 N_("ORG overlap with already existing data")); | 134 N_("ORG overlap with already existing data")); |
| 134 return 1; | 135 return 1; |
| 135 } | 136 } |
| 136 len = org->start - bc->offset; | 137 len = org->start - bc->offset; |
| 137 for (i=0; i<len; i++) | 138 for (i=0; i<len; i++) |
| 138 YASM_WRITE_8(*bufp, org->fill); /* XXX: handle more than 8 bit? */ | 139 YASM_WRITE_8(*bufp, org->fill); /* XXX: handle more than 8 bit? */ |
| 139 return 0; | 140 return 0; |
| 140 } | 141 } |
| 141 | 142 |
| 142 yasm_bytecode * | 143 yasm_bytecode * |
| 143 yasm_bc_create_org(unsigned long start, unsigned long fill, unsigned long line) | 144 yasm_bc_create_org(unsigned long start, unsigned long fill, unsigned long line) |
| 144 { | 145 { |
| 145 bytecode_org *org = yasm_xmalloc(sizeof(bytecode_org)); | 146 bytecode_org *org = yasm_xmalloc(sizeof(bytecode_org)); |
| 146 | 147 |
| 147 org->start = start; | 148 org->start = start; |
| 148 org->fill = fill; | 149 org->fill = fill; |
| 149 | 150 |
| 150 return yasm_bc_create_common(&bc_org_callback, org, line); | 151 return yasm_bc_create_common(&bc_org_callback, org, line); |
| 151 } | 152 } |
| OLD | NEW |