/[gxemul]/trunk/src/cpus/generate_head.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/cpus/generate_head.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC revision 32 by dpavlin, Mon Oct 8 16:20:58 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2005-2006  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: generate_head.c,v 1.8 2005/11/06 22:41:12 debug Exp $   *  $Id: generate_head.c,v 1.24 2006/10/25 09:24:06 debug Exp $
29   */   */
30    
31  #include <stdio.h>  #include <stdio.h>
# Line 33  Line 33 
33  #include <string.h>  #include <string.h>
34    
35    
36    /*  NOTE:  Static return buffer, so calling it multiple times in the
37            same printf statement with the same argument works :-)  but not
38            with different args. Hahaha. Really ugly.  */
39  char *uppercase(char *l)  char *uppercase(char *l)
40  {  {
41          static char staticbuf[1000];          static char staticbuf[1000];
42          int i = 0;          size_t i = 0;
43    
44          while (*l && i < sizeof(staticbuf)) {          while (*l && i < sizeof(staticbuf)) {
45                  char u = *l++;                  char u = *l++;
# Line 65  int main(int argc, char *argv[]) Line 68  int main(int argc, char *argv[])
68          a = argv[1];          a = argv[1];
69          b = argv[2];          b = argv[2];
70    
71    
72          printf("\n/*  AUTOMATICALLY GENERATED! Do not edit.  */\n\n");          printf("\n/*  AUTOMATICALLY GENERATED! Do not edit.  */\n\n");
73    
74            printf("#include <assert.h>\n");
75            printf("#include \"debugger.h\"\n");
76    
77          printf("#define DYNTRANS_MAX_VPH_TLB_ENTRIES "          printf("#define DYNTRANS_MAX_VPH_TLB_ENTRIES "
78              "%s_MAX_VPH_TLB_ENTRIES\n", uppercase(a));              "%s_MAX_VPH_TLB_ENTRIES\n", uppercase(a));
79          printf("#define DYNTRANS_ARCH %s\n", a);          printf("#define DYNTRANS_ARCH %s\n", a);
80          printf("#define DYNTRANS_%s\n", uppercase(a));          printf("#define DYNTRANS_%s\n", uppercase(a));
81          printf("#ifdef DYNTRANS_32\n"  
82              "#define DYNTRANS_1LEVEL\n"          /*  For 64-bit platforms, arch_L2N, and arch_L3N must be defined.  */
83              "#endif\n");          printf("#ifndef DYNTRANS_32\n");
84            printf("#define DYNTRANS_L2N %s_L2N\n"
85                "#define DYNTRANS_L3N %s_L3N\n"
86                "#if !defined(%s_L2N) || !defined(%s_L3N)\n"
87                "#error arch_L2N, and arch_L3N must be defined for this arch!\n"
88                "#endif\n",
89                uppercase(a), uppercase(a), uppercase(a), uppercase(a));
90            printf("#define DYNTRANS_L2_64_TABLE %s_l2_64_table\n"
91                "#define DYNTRANS_L3_64_TABLE %s_l3_64_table\n", a, a);
92            printf("#endif\n");
93    
94            /*  Default pagesize is 4KB.  */
95          printf("#ifndef DYNTRANS_PAGESIZE\n"          printf("#ifndef DYNTRANS_PAGESIZE\n"
96              "#define DYNTRANS_PAGESIZE 4096\n"              "#define DYNTRANS_PAGESIZE 4096\n"
97              "#endif\n");              "#endif\n");
98    
99          printf("#define DYNTRANS_IC %s_instr_call\n", a);          printf("#define DYNTRANS_IC %s_instr_call\n", a);
100          printf("#define DYNTRANS_IC_ENTRIES_PER_PAGE "          printf("#define DYNTRANS_IC_ENTRIES_PER_PAGE "
101              "%s_IC_ENTRIES_PER_PAGE\n", uppercase(a));              "%s_IC_ENTRIES_PER_PAGE\n", uppercase(a));
# Line 103  int main(int argc, char *argv[]) Line 122  int main(int argc, char *argv[])
122              "extern int old_show_trace_tree;\n"              "extern int old_show_trace_tree;\n"
123              "extern int old_instruction_trace;\n"              "extern int old_instruction_trace;\n"
124              "extern int old_quiet_mode;\n"              "extern int old_quiet_mode;\n"
             "extern int show_opcode_statistics;\n"  
125              "extern int quiet_mode;\n");              "extern int quiet_mode;\n");
126    
127          printf("\n/* instr uses the same names as in "          printf("\n/* instr uses the same names as in "
# Line 113  int main(int argc, char *argv[]) Line 131  int main(int argc, char *argv[])
131              "#define instr32(n) %s32_instr_ ## n\n\n", a);              "#define instr32(n) %s32_instr_ ## n\n\n", a);
132          printf("#endif\n\n");          printf("#endif\n\n");
133    
         printf("/*  This is for marking a physical page as containing"  
             "\n    combined instructions:  */\n");  
         printf("#define combined (cpu->cd.%s.cur_physpage->flags "  
             "|= COMBINATIONS)\n", a);  
   
134          printf("\n#define X(n) void %s_instr_ ## n(struct cpu *cpu, \\\n"          printf("\n#define X(n) void %s_instr_ ## n(struct cpu *cpu, \\\n"
135              " struct %s_instr_call *ic)\n", a, a);              " struct %s_instr_call *ic)\n", a, a);
136    
137          printf("\n/*\n *  nothing:  Do nothing.\n *\n"          printf("\n/*\n *  nothing:  Do nothing.\n *\n"
138              " *  The difference between this function and a \"nop\" "              " *  The difference between this function and a \"nop\" "
139              "instruction is that\n *  this function does not increase "              "instruction is that\n *  this function does not increase "
140              "the program counter or the number of\n *  translated "              "the program counter.  It is used to \"get out\" of running in "
141              "instructions.  It is used to \"get out\" of running in "              "translated\n *  mode.\n */\n");
             "translated\n *  mode.\n *\n"  
             " *  IMPORTANT NOTE: Do a   cpu->running_translated = 0;\n"  
             " *                  before setting cpu->cd.%s.next_ic = "  
             "&nothing_call;\n */\n", a);  
142          printf("X(nothing)\n{\n");          printf("X(nothing)\n{\n");
         printf("\tcpu->n_translated_instrs --;\n");  
143          printf("\tcpu->cd.%s.next_ic --;\n", a);          printf("\tcpu->cd.%s.next_ic --;\n", a);
144          printf("}\n\n");          printf("}\n\n");
145    
146          /*  TODO: solve this in a nicer way!  */          /*  Ugly special hacks for Transputer and SH[34]:  */
147          if (strcmp(a, "avr") == 0)          if (strcasecmp(argv[1], "transputer") == 0) {
148                    printf("static struct %s_instr_call nothing_call = { "
149                        "instr(nothing), {0} };\n", a);
150            } else if (strcasecmp(argv[1], "sh") == 0) {
151                  printf("static struct %s_instr_call nothing_call = { "                  printf("static struct %s_instr_call nothing_call = { "
152                      "instr(nothing), 0, {0,0} };\n", a);                      "instr(nothing), {0,0} };\n", a);
153          else {          } else if (strcasecmp(argv[1], "avr32") == 0) {
                 printf("#ifdef DYNTRANS_VARIABLE_INSTRUCTION_LENGTH\n");  
154                  printf("static struct %s_instr_call nothing_call = { "                  printf("static struct %s_instr_call nothing_call = { "
155                      "instr(nothing), 0, {0,0,0} };\n", a);                      "instr(nothing), {0,0} };\n", a);
156                  printf("#else\n");          } else {
157                  printf("static struct %s_instr_call nothing_call = { "                  printf("static struct %s_instr_call nothing_call = { "
158                      "instr(nothing), {0,0,0} };\n", a);                      "instr(nothing), {0,0,0} };\n", a);
                 printf("#endif\n");  
159          }          }
160    
161          printf("\n");          printf("\n");

Legend:
Removed from v.20  
changed lines
  Added in v.32

  ViewVC Help
Powered by ViewVC 1.1.26