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: |
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.15 2006/04/19 18:55:57 debug Exp $ |
29 |
*/ |
*/ |
30 |
|
|
31 |
#include <stdio.h> |
#include <stdio.h> |
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++; |
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("#define DYNTRANS_MAX_VPH_TLB_ENTRIES " |
printf("#define DYNTRANS_MAX_VPH_TLB_ENTRIES " |
75 |
"%s_MAX_VPH_TLB_ENTRIES\n", uppercase(a)); |
"%s_MAX_VPH_TLB_ENTRIES\n", uppercase(a)); |
76 |
printf("#define DYNTRANS_ARCH %s\n", a); |
printf("#define DYNTRANS_ARCH %s\n", a); |
77 |
printf("#define DYNTRANS_%s\n", uppercase(a)); |
printf("#define DYNTRANS_%s\n", uppercase(a)); |
78 |
printf("#ifdef DYNTRANS_32\n" |
|
79 |
"#define DYNTRANS_1LEVEL\n" |
/* For 64-bit platforms, arch_L2N, and arch_L3N must be defined. */ |
80 |
"#endif\n"); |
printf("#ifndef DYNTRANS_32\n"); |
81 |
|
printf("#define DYNTRANS_L2N %s_L2N\n" |
82 |
|
"#define DYNTRANS_L3N %s_L3N\n" |
83 |
|
"#if !defined(%s_L2N) || !defined(%s_L3N)\n" |
84 |
|
"#error arch_L2N, and arch_L3N must be defined for this arch!\n" |
85 |
|
"#endif\n", |
86 |
|
uppercase(a), uppercase(a), uppercase(a), uppercase(a)); |
87 |
|
printf("#define DYNTRANS_L2_64_TABLE %s_l2_64_table\n" |
88 |
|
"#define DYNTRANS_L3_64_TABLE %s_l3_64_table\n", a, a); |
89 |
|
printf("#endif\n"); |
90 |
|
|
91 |
|
/* Default pagesize is 4KB. */ |
92 |
printf("#ifndef DYNTRANS_PAGESIZE\n" |
printf("#ifndef DYNTRANS_PAGESIZE\n" |
93 |
"#define DYNTRANS_PAGESIZE 4096\n" |
"#define DYNTRANS_PAGESIZE 4096\n" |
94 |
"#endif\n"); |
"#endif\n"); |
95 |
|
|
96 |
printf("#define DYNTRANS_IC %s_instr_call\n", a); |
printf("#define DYNTRANS_IC %s_instr_call\n", a); |
97 |
printf("#define DYNTRANS_IC_ENTRIES_PER_PAGE " |
printf("#define DYNTRANS_IC_ENTRIES_PER_PAGE " |
98 |
"%s_IC_ENTRIES_PER_PAGE\n", uppercase(a)); |
"%s_IC_ENTRIES_PER_PAGE\n", uppercase(a)); |
119 |
"extern int old_show_trace_tree;\n" |
"extern int old_show_trace_tree;\n" |
120 |
"extern int old_instruction_trace;\n" |
"extern int old_instruction_trace;\n" |
121 |
"extern int old_quiet_mode;\n" |
"extern int old_quiet_mode;\n" |
|
"extern int show_opcode_statistics;\n" |
|
122 |
"extern int quiet_mode;\n"); |
"extern int quiet_mode;\n"); |
123 |
|
|
124 |
printf("\n/* instr uses the same names as in " |
printf("\n/* instr uses the same names as in " |
150 |
printf("\tcpu->cd.%s.next_ic --;\n", a); |
printf("\tcpu->cd.%s.next_ic --;\n", a); |
151 |
printf("}\n\n"); |
printf("}\n\n"); |
152 |
|
|
153 |
/* TODO: solve this in a nicer way! */ |
printf("#ifdef DYNTRANS_VARIABLE_INSTRUCTION_LENGTH\n"); |
154 |
if (strcmp(a, "avr") == 0) |
printf("static struct %s_instr_call nothing_call = { " |
155 |
printf("static struct %s_instr_call nothing_call = { " |
"instr(nothing), {0,0,0} };\n", a); |
156 |
"instr(nothing), 0, {0,0} };\n", a); |
printf("#else\n"); |
157 |
else { |
printf("static struct %s_instr_call nothing_call = { " |
158 |
printf("#ifdef DYNTRANS_VARIABLE_INSTRUCTION_LENGTH\n"); |
"instr(nothing), {0,0,0} };\n", a); |
159 |
printf("static struct %s_instr_call nothing_call = { " |
printf("#endif\n"); |
|
"instr(nothing), 0, {0,0,0} };\n", a); |
|
|
printf("#else\n"); |
|
|
printf("static struct %s_instr_call nothing_call = { " |
|
|
"instr(nothing), {0,0,0} };\n", a); |
|
|
printf("#endif\n"); |
|
|
} |
|
160 |
|
|
161 |
printf("\n"); |
printf("\n"); |
162 |
|
|