No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / microcode / aic7xxx / aicasm.c
blob246b57a03a81170850ce33e5d57077ed7eb62100
1 /* $NetBSD: aicasm.c,v 1.7 2009/03/18 10:22:40 cegger Exp $ */
3 /*
4 * Aic7xxx SCSI host adapter firmware asssembler
6 * Copyright (c) 1997, 1998, 2000, 2001 Justin T. Gibbs.
7 * Copyright (c) 2001, 2002 Adaptec Inc.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification.
16 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
17 * substantially similar to the "NO WARRANTY" disclaimer below
18 * ("Disclaimer") and any redistribution must be conditioned upon
19 * including a substantially similar Disclaimer requirement for further
20 * binary redistribution.
21 * 3. Neither the names of the above-listed copyright holders nor the names
22 * of any contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * Alternatively, this software may be distributed under the terms of the
26 * GNU General Public License ("GPL") version 2 as published by the Free
27 * Software Foundation.
29 * NO WARRANTY
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
39 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGES.
42 * $FreeBSD: src/sys/dev/aic7xxx/aicasm/aicasm.c,v 1.35 2002/08/31 06:39:40 gibbs Exp $
45 #include <sys/cdefs.h>
46 __RCSID("$NetBSD: aicasm.c,v 1.7 2009/03/18 10:22:40 cegger Exp $");
48 #include <sys/types.h>
49 #include <sys/mman.h>
51 #include <ctype.h>
52 #include <inttypes.h>
53 #include <regex.h>
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57 #include <sysexits.h>
58 #include <unistd.h>
60 #if linux
61 #include <endian.h>
62 #else
63 #include <machine/endian.h>
64 #endif
66 #include "aicasm.h"
67 #include "aicasm_symbol.h"
68 #include "aicasm_insformat.h"
70 typedef struct patch {
71 STAILQ_ENTRY(patch) links;
72 int patch_func;
73 u_int begin;
74 u_int skip_instr;
75 u_int skip_patch;
76 } patch_t;
78 STAILQ_HEAD(patch_list, patch) patches;
80 static void usage(void);
81 static void back_patch(void);
82 static void output_code(void);
83 static void output_listing(char *ifilename);
84 static void dump_scope(scope_t *scope);
85 static void emit_patch(scope_t *scope, int patch);
86 static int check_patch(patch_t **start_patch, int start_instr,
87 int *skip_addr, int *func_vals);
89 struct path_list search_path;
90 int includes_search_curdir;
91 char *appname;
92 char *stock_include_file;
93 FILE *ofile;
94 char *ofilename;
95 char *regfilename;
96 FILE *regfile;
97 char *listfilename;
98 FILE *listfile;
99 char *regdiagfilename;
100 FILE *regdiagfile;
101 int src_mode;
102 int dst_mode;
104 static STAILQ_HEAD(,instruction) seq_program;
105 struct cs_tailq cs_tailq;
106 struct scope_list scope_stack;
107 symlist_t patch_functions;
109 #if DEBUG
110 extern int yy_flex_debug;
111 extern int mm_flex_debug;
112 extern int yydebug;
113 extern int mmdebug;
114 #endif
115 extern FILE *yyin;
116 extern int yyparse(void);
118 int main(int argc, char *argv[]);
121 main(int argc, char *argv[])
123 extern char *optarg;
124 extern int optind;
125 int ch;
126 int retval;
127 char *inputfilename;
128 scope_t *sentinal;
130 STAILQ_INIT(&patches);
131 SLIST_INIT(&search_path);
132 STAILQ_INIT(&seq_program);
133 TAILQ_INIT(&cs_tailq);
134 SLIST_INIT(&scope_stack);
136 /* Set Sentinal scope node */
137 sentinal = scope_alloc();
138 sentinal->type = SCOPE_ROOT;
140 includes_search_curdir = 1;
141 appname = *argv;
142 regfile = NULL;
143 listfile = NULL;
144 #if DEBUG
145 yy_flex_debug = 0;
146 mm_flex_debug = 0;
147 yydebug = 0;
148 mmdebug = 0;
149 #endif
150 while ((ch = getopt(argc, argv, "d:i:l:n:o:p:r:I:")) != -1) {
151 switch(ch) {
152 case 'd':
153 #if DEBUG
154 if (strcmp(optarg, "s") == 0) {
155 yy_flex_debug = 1;
156 mm_flex_debug = 1;
157 } else if (strcmp(optarg, "p") == 0) {
158 yydebug = 1;
159 mmdebug = 1;
160 } else {
161 fprintf(stderr, "%s: -d Requires either an "
162 "'s' or 'p' argument\n", appname);
163 usage();
165 #else
166 stop("-d: Assembler not built with debugging "
167 "information", EX_SOFTWARE);
168 #endif
169 break;
170 case 'i':
171 stock_include_file = optarg;
172 break;
173 case 'l':
174 /* Create a program listing */
175 if ((listfile = fopen(optarg, "w")) == NULL) {
176 perror(optarg);
177 stop(NULL, EX_CANTCREAT);
179 listfilename = optarg;
180 break;
181 case 'n':
182 /* Don't complain about the -nostdinc directrive */
183 if (strcmp(optarg, "ostdinc")) {
184 fprintf(stderr, "%s: Unknown option -%c%s\n",
185 appname, ch, optarg);
186 usage();
187 /* NOTREACHED */
189 break;
190 case 'o':
191 if ((ofile = fopen(optarg, "w")) == NULL) {
192 perror(optarg);
193 stop(NULL, EX_CANTCREAT);
195 ofilename = optarg;
196 break;
197 case 'p':
198 /* Create Register Diagnostic "printing" Functions */
199 if ((regdiagfile = fopen(optarg, "w")) == NULL) {
200 perror(optarg);
201 stop(NULL, EX_CANTCREAT);
203 regdiagfilename = optarg;
204 break;
205 case 'r':
206 if ((regfile = fopen(optarg, "w")) == NULL) {
207 perror(optarg);
208 stop(NULL, EX_CANTCREAT);
210 regfilename = optarg;
211 break;
212 case 'I':
214 path_entry_t include_dir;
216 if (strcmp(optarg, "-") == 0) {
217 if (includes_search_curdir == 0) {
218 fprintf(stderr, "%s: Warning - '-I-' "
219 "specified multiple "
220 "times\n", appname);
222 includes_search_curdir = 0;
223 for (include_dir = SLIST_FIRST(&search_path);
224 include_dir != NULL;
225 include_dir = SLIST_NEXT(include_dir,
226 links))
228 * All entries before a '-I-' only
229 * apply to includes specified with
230 * quotes instead of "<>".
232 include_dir->quoted_includes_only = 1;
233 } else {
234 include_dir =
235 (path_entry_t)malloc(sizeof(*include_dir));
236 if (include_dir == NULL) {
237 perror(optarg);
238 stop(NULL, EX_OSERR);
240 include_dir->directory = strdup(optarg);
241 if (include_dir->directory == NULL) {
242 perror(optarg);
243 stop(NULL, EX_OSERR);
245 include_dir->quoted_includes_only = 0;
246 SLIST_INSERT_HEAD(&search_path, include_dir,
247 links);
249 break;
251 case '?':
252 default:
253 usage();
254 /* NOTREACHED */
257 argc -= optind;
258 argv += optind;
260 if (argc != 1) {
261 fprintf(stderr, "%s: No input file specifiled\n", appname);
262 usage();
263 /* NOTREACHED */
266 if (regdiagfile != NULL
267 && (regfile == NULL || stock_include_file == NULL)) {
268 fprintf(stderr,
269 "%s: The -p option requires the -r and -i options.\n",
270 appname);
271 usage();
272 /* NOTREACHED */
274 symtable_open();
275 inputfilename = *argv;
276 include_file(*argv, SOURCE_FILE);
277 retval = yyparse();
278 if (retval == 0) {
279 if (SLIST_FIRST(&scope_stack) == NULL
280 || SLIST_FIRST(&scope_stack)->type != SCOPE_ROOT) {
281 stop("Unterminated conditional expression", EX_DATAERR);
282 /* NOTREACHED */
285 /* Process outmost scope */
286 process_scope(SLIST_FIRST(&scope_stack));
288 * Decend the tree of scopes and insert/emit
289 * patches as appropriate. We perform a depth first
290 * tranversal, recursively handling each scope.
292 /* start at the root scope */
293 dump_scope(SLIST_FIRST(&scope_stack));
295 /* Patch up forward jump addresses */
296 back_patch();
298 if (ofile != NULL)
299 output_code();
300 if (regfile != NULL)
301 symtable_dump(regfile, regdiagfile);
302 if (listfile != NULL)
303 output_listing(inputfilename);
306 stop(NULL, 0);
307 /* NOTREACHED */
308 return (0);
311 static void
312 usage(void)
315 (void)fprintf(stderr,
316 "usage: %-16s [-nostdinc] [-I-] [-I directory] [-o output_file]\n"
317 " [-r register_output_file [-p register_diag_file -i includefile]]\n"
318 " [-l program_list_file]\n"
319 " input_file\n", appname);
320 exit(EX_USAGE);
323 static void
324 back_patch(void)
326 struct instruction *cur_instr;
328 for (cur_instr = STAILQ_FIRST(&seq_program);
329 cur_instr != NULL;
330 cur_instr = STAILQ_NEXT(cur_instr, links)) {
331 if (cur_instr->patch_label != NULL) {
332 struct ins_format3 *f3_instr;
333 u_int address;
335 if (cur_instr->patch_label->type != LABEL) {
336 char buf[255];
338 snprintf(buf, sizeof(buf),
339 "Undefined label %s",
340 cur_instr->patch_label->name);
341 stop(buf, EX_DATAERR);
342 /* NOTREACHED */
344 f3_instr = &cur_instr->format.format3;
345 address = f3_instr->address;
346 address += cur_instr->patch_label->info.linfo->address;
347 f3_instr->address = address;
352 static void
353 output_code(void)
355 struct instruction *cur_instr;
356 patch_t *cur_patch;
357 critical_section_t *cs;
358 symbol_node_t *cur_node;
359 int instrcount;
361 instrcount = 0;
362 fprintf(ofile,
363 "/*\n"
364 " * DO NOT EDIT - This file is automatically generated\n"
365 " * from the following source files:\n"
366 " *\n"
367 "%s */\n", versions);
369 fprintf(ofile, "static uint8_t seqprog[] = {\n");
370 for (cur_instr = STAILQ_FIRST(&seq_program);
371 cur_instr != NULL;
372 cur_instr = STAILQ_NEXT(cur_instr, links)) {
374 fprintf(ofile, "%s\t0x%02x, 0x%02x, 0x%02x, 0x%02x",
375 cur_instr == STAILQ_FIRST(&seq_program) ? "" : ",\n",
376 #if BYTE_ORDER == LITTLE_ENDIAN
377 cur_instr->format.bytes[0],
378 cur_instr->format.bytes[1],
379 cur_instr->format.bytes[2],
380 cur_instr->format.bytes[3]);
381 #else
382 cur_instr->format.bytes[3],
383 cur_instr->format.bytes[2],
384 cur_instr->format.bytes[1],
385 cur_instr->format.bytes[0]);
386 #endif
387 instrcount++;
389 fprintf(ofile, "\n};\n\n");
391 if (patch_arg_list == NULL)
392 stop("Patch argument list not defined",
393 EX_DATAERR);
396 * Output patch information. Patch functions first.
398 fprintf(ofile,
399 "typedef int %spatch_func_t (%s);\n", prefix, patch_arg_list);
401 for (cur_node = SLIST_FIRST(&patch_functions);
402 cur_node != NULL;
403 cur_node = SLIST_NEXT(cur_node,links)) {
404 fprintf(ofile,
405 "static %spatch_func_t %spatch%d_func;\n"
406 "\n"
407 "static int\n"
408 "%spatch%d_func(%s)\n"
409 "{\n"
410 " return (%s);\n"
411 "}\n\n",
412 prefix,
413 prefix,
414 cur_node->symbol->info.condinfo->func_num,
415 prefix,
416 cur_node->symbol->info.condinfo->func_num,
417 patch_arg_list,
418 cur_node->symbol->name);
421 fprintf(ofile,
422 "static struct patch {\n"
423 " %spatch_func_t *patch_func;\n"
424 " uint32_t begin :10,\n"
425 " skip_instr :10,\n"
426 " skip_patch :12;\n"
427 "} patches[] = {\n", prefix);
429 for (cur_patch = STAILQ_FIRST(&patches);
430 cur_patch != NULL;
431 cur_patch = STAILQ_NEXT(cur_patch,links)) {
432 fprintf(ofile, "%s\t{ %spatch%d_func, %d, %d, %d }",
433 cur_patch == STAILQ_FIRST(&patches) ? "" : ",\n",
434 prefix,
435 cur_patch->patch_func, cur_patch->begin,
436 cur_patch->skip_instr, cur_patch->skip_patch);
439 fprintf(ofile, "\n};\n\n");
441 fprintf(ofile,
442 "static struct cs {\n"
443 " uint16_t begin;\n"
444 " uint16_t end;\n"
445 "} critical_sections[] = {\n");
447 for (cs = TAILQ_FIRST(&cs_tailq);
448 cs != NULL;
449 cs = TAILQ_NEXT(cs, links)) {
450 fprintf(ofile, "%s\t{ %d, %d }",
451 cs == TAILQ_FIRST(&cs_tailq) ? "" : ",\n",
452 cs->begin_addr, cs->end_addr);
455 fprintf(ofile, "\n};\n\n");
457 fprintf(ofile,
458 "static const int num_critical_sections = sizeof(critical_sections)\n"
459 " / sizeof(*critical_sections);\n");
461 fprintf(stderr, "%s: %d instructions used\n", appname, instrcount);
464 static void
465 dump_scope(scope_t *scope)
467 scope_t *cur_scope;
470 * Emit the first patch for this scope
472 emit_patch(scope, 0);
475 * Dump each scope within this one.
477 cur_scope = TAILQ_FIRST(&scope->inner_scope);
479 while (cur_scope != NULL) {
481 dump_scope(cur_scope);
483 cur_scope = TAILQ_NEXT(cur_scope, scope_links);
487 * Emit the second, closing, patch for this scope
489 emit_patch(scope, 1);
492 void
493 emit_patch(scope_t *scope, int patch)
495 patch_info_t *pinfo;
496 patch_t *new_patch;
498 pinfo = &scope->patches[patch];
500 if (pinfo->skip_instr == 0)
501 /* No-Op patch */
502 return;
504 new_patch = (patch_t *)malloc(sizeof(*new_patch));
506 if (new_patch == NULL)
507 stop("Could not malloc patch structure", EX_OSERR);
509 memset(new_patch, 0, sizeof(*new_patch));
511 if (patch == 0) {
512 new_patch->patch_func = scope->func_num;
513 new_patch->begin = scope->begin_addr;
514 } else {
515 new_patch->patch_func = 0;
516 new_patch->begin = scope->end_addr;
518 new_patch->skip_instr = pinfo->skip_instr;
519 new_patch->skip_patch = pinfo->skip_patch;
520 STAILQ_INSERT_TAIL(&patches, new_patch, links);
523 void
524 output_listing(char *ifilename)
526 char buf[1024];
527 FILE *ifile;
528 struct instruction *cur_instr;
529 patch_t *cur_patch;
530 symbol_node_t *cur_func;
531 int *func_values;
532 int instrcount;
533 int instrptr;
534 int line;
535 int func_count;
536 int skip_addr;
538 instrcount = 0;
539 instrptr = 0;
540 line = 1;
541 skip_addr = 0;
542 if ((ifile = fopen(ifilename, "r")) == NULL) {
543 perror(ifilename);
544 stop(NULL, EX_DATAERR);
548 * Determine which options to apply to this listing.
550 for (func_count = 0, cur_func = SLIST_FIRST(&patch_functions);
551 cur_func != NULL;
552 cur_func = SLIST_NEXT(cur_func, links))
553 func_count++;
555 func_values = NULL;
556 if (func_count != 0) {
557 func_values = (int *)malloc(func_count * sizeof(int));
559 if (func_values == NULL)
560 stop("Could not malloc", EX_OSERR);
562 func_values[0] = 0; /* FALSE func */
563 func_count--;
566 * Ask the user to fill in the return values for
567 * the rest of the functions.
571 for (cur_func = SLIST_FIRST(&patch_functions);
572 cur_func != NULL && SLIST_NEXT(cur_func, links) != NULL;
573 cur_func = SLIST_NEXT(cur_func, links), func_count--) {
574 int input;
576 fprintf(stdout, "\n(%s)\n", cur_func->symbol->name);
577 fprintf(stdout,
578 "Enter the return value for "
579 "this expression[T/F]:");
581 while (1) {
583 input = getchar();
584 input = toupper(input);
586 if (input == 'T') {
587 func_values[func_count] = 1;
588 break;
589 } else if (input == 'F') {
590 func_values[func_count] = 0;
591 break;
594 if (isatty(fileno(stdin)) == 0)
595 putchar(input);
597 free(func_values);
598 fprintf(stdout, "\nThanks!\n");
601 /* Now output the listing */
602 cur_patch = STAILQ_FIRST(&patches);
603 for (cur_instr = STAILQ_FIRST(&seq_program);
604 cur_instr != NULL;
605 cur_instr = STAILQ_NEXT(cur_instr, links), instrcount++) {
607 if (check_patch(&cur_patch, instrcount,
608 &skip_addr, func_values) == 0) {
609 /* Don't count this instruction as it is in a patch
610 * that was removed.
612 continue;
615 while (line < cur_instr->srcline) {
616 fgets(buf, sizeof(buf), ifile);
617 fprintf(listfile, "\t\t%s", buf);
618 line++;
620 fprintf(listfile, "%03x %02x%02x%02x%02x", instrptr,
621 #if BYTE_ORDER == LITTLE_ENDIAN
622 cur_instr->format.bytes[0],
623 cur_instr->format.bytes[1],
624 cur_instr->format.bytes[2],
625 cur_instr->format.bytes[3]);
626 #else
627 cur_instr->format.bytes[3],
628 cur_instr->format.bytes[2],
629 cur_instr->format.bytes[1],
630 cur_instr->format.bytes[0]);
631 #endif
632 fgets(buf, sizeof(buf), ifile);
633 fprintf(listfile, "\t%s", buf);
634 line++;
635 instrptr++;
637 /* Dump the remainder of the file */
638 while(fgets(buf, sizeof(buf), ifile) != NULL)
639 fprintf(listfile, "\t\t%s", buf);
641 fclose(ifile);
644 static int
645 check_patch(patch_t **start_patch, int start_instr,
646 int *skip_addr, int *func_vals)
648 patch_t *cur_patch;
650 cur_patch = *start_patch;
652 while (cur_patch != NULL && start_instr == cur_patch->begin) {
653 if (func_vals[cur_patch->patch_func] == 0) {
654 int skip;
656 /* Start rejecting code */
657 *skip_addr = start_instr + cur_patch->skip_instr;
658 for (skip = cur_patch->skip_patch;
659 skip > 0 && cur_patch != NULL;
660 skip--)
661 cur_patch = STAILQ_NEXT(cur_patch, links);
662 } else {
663 /* Accepted this patch. Advance to the next
664 * one and wait for our intruction pointer to
665 * hit this point.
667 cur_patch = STAILQ_NEXT(cur_patch, links);
671 *start_patch = cur_patch;
672 if (start_instr < *skip_addr)
673 /* Still skipping */
674 return (0);
676 return (1);
680 * Print out error information if appropriate, and clean up before
681 * terminating the program.
683 void
684 stop(const char *string, int err_code)
686 if (string != NULL) {
687 fprintf(stderr, "%s: ", appname);
688 if (yyfilename != NULL) {
689 fprintf(stderr, "Stopped at file %s, line %d - ",
690 yyfilename, yylineno);
692 fprintf(stderr, "%s\n", string);
695 if (ofile != NULL) {
696 fclose(ofile);
697 if (err_code != 0) {
698 fprintf(stderr, "%s: Removing %s due to error\n",
699 appname, ofilename);
700 unlink(ofilename);
704 if (regfile != NULL) {
705 fclose(regfile);
706 if (err_code != 0) {
707 fprintf(stderr, "%s: Removing %s due to error\n",
708 appname, regfilename);
709 unlink(regfilename);
713 if (listfile != NULL) {
714 fclose(listfile);
715 if (err_code != 0) {
716 fprintf(stderr, "%s: Removing %s due to error\n",
717 appname, listfilename);
718 unlink(listfilename);
722 symlist_free(&patch_functions);
723 symtable_close();
725 exit(err_code);
728 struct instruction *
729 seq_alloc(void)
731 struct instruction *new_instr;
733 new_instr = (struct instruction *)malloc(sizeof(struct instruction));
734 if (new_instr == NULL)
735 stop("Unable to malloc instruction object", EX_SOFTWARE);
736 memset(new_instr, 0, sizeof(*new_instr));
737 STAILQ_INSERT_TAIL(&seq_program, new_instr, links);
738 new_instr->srcline = yylineno;
739 return new_instr;
742 critical_section_t *
743 cs_alloc(void)
745 critical_section_t *new_cs;
747 new_cs= (critical_section_t *)malloc(sizeof(critical_section_t));
748 if (new_cs == NULL)
749 stop("Unable to malloc critical_section object", EX_SOFTWARE);
750 memset(new_cs, 0, sizeof(*new_cs));
752 TAILQ_INSERT_TAIL(&cs_tailq, new_cs, links);
753 return new_cs;
756 scope_t *
757 scope_alloc(void)
759 scope_t *new_scope;
761 new_scope = (scope_t *)malloc(sizeof(scope_t));
762 if (new_scope == NULL)
763 stop("Unable to malloc scope object", EX_SOFTWARE);
764 memset(new_scope, 0, sizeof(*new_scope));
765 TAILQ_INIT(&new_scope->inner_scope);
767 if (SLIST_FIRST(&scope_stack) != NULL) {
768 TAILQ_INSERT_TAIL(&SLIST_FIRST(&scope_stack)->inner_scope,
769 new_scope, scope_links);
771 /* This patch is now the current scope */
772 SLIST_INSERT_HEAD(&scope_stack, new_scope, scope_stack_links);
773 return new_scope;
776 void
777 process_scope(scope_t *scope)
780 * We are "leaving" this scope. We should now have
781 * enough information to process the lists of scopes
782 * we encapsulate.
784 scope_t *cur_scope;
785 u_int skip_patch_count;
786 u_int skip_instr_count;
788 cur_scope = TAILQ_LAST(&scope->inner_scope, scope_tailq);
789 skip_patch_count = 0;
790 skip_instr_count = 0;
791 while (cur_scope != NULL) {
792 u_int patch0_patch_skip;
794 patch0_patch_skip = 0;
795 switch (cur_scope->type) {
796 case SCOPE_IF:
797 case SCOPE_ELSE_IF:
798 if (skip_instr_count != 0) {
799 /* Create a tail patch */
800 patch0_patch_skip++;
801 cur_scope->patches[1].skip_patch =
802 skip_patch_count + 1;
803 cur_scope->patches[1].skip_instr =
804 skip_instr_count;
807 /* Count Head patch */
808 patch0_patch_skip++;
810 /* Count any patches contained in our inner scope */
811 patch0_patch_skip += cur_scope->inner_scope_patches;
813 cur_scope->patches[0].skip_patch = patch0_patch_skip;
814 cur_scope->patches[0].skip_instr =
815 cur_scope->end_addr - cur_scope->begin_addr;
817 skip_instr_count += cur_scope->patches[0].skip_instr;
819 skip_patch_count += patch0_patch_skip;
820 if (cur_scope->type == SCOPE_IF) {
821 scope->inner_scope_patches += skip_patch_count;
822 skip_patch_count = 0;
823 skip_instr_count = 0;
825 break;
826 case SCOPE_ELSE:
827 /* Count any patches contained in our innter scope */
828 skip_patch_count += cur_scope->inner_scope_patches;
830 skip_instr_count += cur_scope->end_addr
831 - cur_scope->begin_addr;
832 break;
833 case SCOPE_ROOT:
834 stop("Unexpected scope type encountered", EX_SOFTWARE);
835 /* NOTREACHED */
838 cur_scope = TAILQ_PREV(cur_scope, scope_tailq, scope_links);