aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/newconfig/config.g52
-rw-r--r--util/options/build_opt_tbl.c148
-rw-r--r--util/romcc/Makefile7
-rw-r--r--util/romcc/romcc.c33
-rw-r--r--util/romcc/tests/fail_test6.c11
-rw-r--r--util/romcc/tests/fail_test7.c10
-rw-r--r--util/romcc/tests/fail_test8.c10
7 files changed, 234 insertions, 37 deletions
diff --git a/util/newconfig/config.g b/util/newconfig/config.g
index 03cf941702..b7f3d6fbf3 100644
--- a/util/newconfig/config.g
+++ b/util/newconfig/config.g
@@ -740,6 +740,18 @@ class partobj:
value = dequote(value)
setdict(self.registercode, field, value)
+ def start_resources(self):
+ self.path = "%s, .resource={" % (self.path)
+
+ def end_resources(self):
+ self.path = "%s}}," % (self.path)
+
+ def add_resource(self, type, index, value):
+ """ Add a resource to a device """
+ self.path = "%s\n\t\t\t{ .flags=%s, .index=0x%x, .base=0x%x}," % (self.path, type, index, value)
+
+
+
def addpcipath(self, enable, bus, slot, function):
""" Add a relative pci style path from our parent to this device """
if ((bus < 0) or (bus > 255)):
@@ -748,7 +760,7 @@ class partobj:
fatal("Invalid device id")
if ((function < 0) or (function > 7)):
fatal("Invalid function")
- self.path = "%s\n\t\t{ .enable = %d, .path = {.type=DEVICE_PATH_PCI,.u={.pci={ .bus = 0x%x, .devfn = PCI_DEVFN(0x%x,%d) }}}}," % (self.path, enable, bus, slot, function)
+ self.path = "%s\n\t\t{ .enable = %d, .path = {.type=DEVICE_PATH_PCI,.u={.pci={ .bus = 0x%x, .devfn = PCI_DEVFN(0x%x,%d)}}}" % (self.path, enable, bus, slot, function)
def addpnppath(self, enable, port, device):
""" Add a relative path to a pnp device hanging off our parent """
@@ -756,13 +768,14 @@ class partobj:
fatal("Invalid port")
if ((device < 0) or (device > 0xff)):
fatal("Invalid device")
- self.path = "%s\n\t\t{ .enable = %d, .path={.type=DEVICE_PATH_PNP,.u={.pnp={ .port = 0x%x, .device = 0x%x }}}}," % (self.path, enable, port, device)
-
+ self.path = "%s\n\t\t{ .enable = %d, .path={.type=DEVICE_PATH_PNP,.u={.pnp={ .port = 0x%x, .device = 0x%x }}}" % (self.path, enable, port, device)
+
def addi2cpath(self, enable, device):
""" Add a relative path to a i2c device hanging off our parent """
if ((device < 0) or (device > 0x7f)):
fatal("Invalid device")
- self.path = "%s\n\t\t{ .enable = %d, .path = {.type=DEVICE_PATH_I2C,.u={.i2c={ .device = 0x%x }}}}, " % (self.path, enable, device)
+ self.path = "%s\n\t\t{ .enable = %d, .path = {.type=DEVICE_PATH_I2C,.u={.i2c={ .device = 0x%x }}} " % (self.path, enable, device)
+
def usesoption(self, name):
"""Declare option that can be used by this part"""
@@ -1111,7 +1124,7 @@ def endromimage():
def mainboard(path):
full_path = os.path.join(treetop, 'src', 'mainboard', path)
- vendor = re.sub("/.*", "", path)
+ vendor = re.sub("/.*", "", path)
part_number = re.sub("[^/]*/", "", path)
setdefault('MAINBOARD', full_path, 1)
setdefault('MAINBOARD_VENDOR', vendor, 1)
@@ -1278,7 +1291,7 @@ def dequote(str):
return a
def flatten_name(str):
- a = re.sub("/", "_", str)
+ a = re.sub("[/-]", "_", str)
return a
def topify(path):
@@ -1316,6 +1329,7 @@ parser Config:
token DEPENDS: 'depends'
token DIR: 'dir'
token DRIVER: 'driver'
+ token DRQ: 'drq'
token ELSE: 'else'
token END: 'end'
token EOF: '$'
@@ -1326,12 +1340,15 @@ parser Config:
token INIT: 'init'
token INITOBJECT: 'initobject'
token INITINCLUDE: 'initinclude'
+ token IO: 'io'
+ token IRQ: 'irq'
token LDSCRIPT: 'ldscript'
token LOADOPTIONS: 'loadoptions'
token MAINBOARD: 'mainboard'
token MAINBOARDINIT: 'mainboardinit'
token MAKEDEFINE: 'makedefine'
token MAKERULE: 'makerule'
+ token MEM: 'mem'
token NEVER: 'never'
token NONE: 'none'
token NORTHBRIDGE: 'northbridge'
@@ -1353,7 +1370,7 @@ parser Config:
token HEX_PREFIX: '0x'
# Why is path separate? Because paths to resources have to at least
# have a slash, we thinks
- token PATH: r'[a-zA-Z0-9_.][a-zA-Z0-9/_.]+[a-zA-Z0-9_.]+'
+ token PATH: r'[-a-zA-Z0-9_.][-a-zA-Z0-9/_.]+[-a-zA-Z0-9_.]+'
# Dir's on the other hand are abitrary
# this may all be stupid.
token DIRPATH: r'[-a-zA-Z0-9_$()./]+'
@@ -1471,21 +1488,42 @@ parser Config:
[ ( ON {{ val = 1 }}
| OFF {{ val = 0 }}
) ] {{ return val }}
+
+ rule resource<<C>>: {{ type = "" }}
+ ( IO {{ type = "IORESOURCE_IO" }}
+ | MEM {{ type = "IORESOURCE_MEM" }}
+ | IRQ {{ type = "IORESOURCE_IRQ" }}
+ | DRQ {{ type = "IORESOURCE_DRQ" }}
+ )
+ term '=' {{ index = term }}
+ term {{ value = term }}
+ {{ if (C): partstack.tos().add_resource(type, index, value) }}
+
+
+ rule resources<<C>>: {{ if (C): partstack.tos().start_resources() }}
+ ( resource<<C>> )*
+ {{ if (C): partstack.tos().end_resources() }}
+
rule pci<<C>>: PCI HEX_NUM {{ bus = int(HEX_NUM,16) }}
':' HEX_NUM {{ slot = int(HEX_NUM,16) }}
'.' HEX_NUM {{ function = int(HEX_NUM, 16) }}
enable
{{ if (C): partstack.tos().addpcipath(enable, bus, slot, function) }}
+ resources<<C>>
rule pnp<<C>>: PNP HEX_NUM {{ port = int(HEX_NUM,16) }}
'.' HEX_NUM {{ device = int(HEX_NUM, 16) }}
enable
{{ if (C): partstack.tos().addpnppath(enable, port, device) }}
+ resources<<C>>
+
rule i2c<<C>>: I2C HEX_NUM {{ device = int(HEX_NUM, 16) }}
enable
{{ if (C): partstatck.tos().addi2cpath(enable, device) }}
+ resources<<C>>
+
rule prtval: expr {{ return str(expr) }}
| STR {{ return STR }}
diff --git a/util/options/build_opt_tbl.c b/util/options/build_opt_tbl.c
index 183aeab1bd..a6b5cd3062 100644
--- a/util/options/build_opt_tbl.c
+++ b/util/options/build_opt_tbl.c
@@ -3,6 +3,7 @@
#include <sys/io.h>
#include <string.h>
#include <ctype.h>
+#include <errno.h>
#include "../../src/include/pc80/mc146818rtc.h"
#include "../../src/include/boot/linuxbios_tables.h"
@@ -99,9 +100,11 @@ void display_usage(void)
{
printf("Usage build_opt_table [-b] [--option filename]\n");
printf(" [--config filename]\n");
+ printf(" [--header filename]\n");
printf("b = build option_table.c\n");
printf("--option = name of option table output file\n");
printf("--config = build the definitions table from the given file\n");
+ printf("--header = ouput a header file with the definitions\n");
exit(1);
}
@@ -131,6 +134,67 @@ static unsigned long get_number(char *line, char **ptr, int base)
return value;
}
+static int is_ident_digit(int c)
+{
+ int result;
+ switch(c) {
+ case '0': case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ case '8': case '9':
+ result = 1;
+ break;
+ default:
+ result = 0;
+ break;
+ }
+ return result;
+}
+
+static int is_ident_nondigit(int c)
+{
+ int result;
+ switch(c) {
+ case 'A': case 'B': case 'C': case 'D':
+ case 'E': case 'F': case 'G': case 'H':
+ case 'I': case 'J': case 'K': case 'L':
+ case 'M': case 'N': case 'O': case 'P':
+ case 'Q': case 'R': case 'S': case 'T':
+ case 'U': case 'V': case 'W': case 'X':
+ case 'Y': case 'Z':
+ case 'a': case 'b': case 'c': case 'd':
+ case 'e': case 'f': case 'g': case 'h':
+ case 'i': case 'j': case 'k': case 'l':
+ case 'm': case 'n': case 'o': case 'p':
+ case 'q': case 'r': case 's': case 't':
+ case 'u': case 'v': case 'w': case 'x':
+ case 'y': case 'z':
+ case '_':
+ result = 1;
+ break;
+ default:
+ result = 0;
+ break;
+ }
+ return result;
+}
+
+static int is_ident(char *str)
+{
+ int result;
+ int ch;
+ ch = *str;
+ result = 0;
+ if (is_ident_nondigit(ch)) {
+ do {
+ str++;
+ ch = *str;
+ } while(ch && (is_ident_nondigit(ch) || (is_ident_digit(ch))));
+ result = (ch == '\0');
+ }
+ return result;
+}
+
+
/* This routine builds the cmos definition table from the cmos layout file
input The input comes from the configuration file which contains two parts
entries and enumerations. Each section is started with the key words
@@ -148,6 +212,7 @@ int main(int argc, char **argv)
int i;
char *config=0;
char *option=0;
+ char *header=0;
FILE *fp;
struct cmos_option_table *ct;
struct cmos_entries *ce;
@@ -188,11 +253,18 @@ int main(int argc, char **argv)
}
option=argv[++i];
break;
+ case 'h': /* Output a header file */
+ if (strcmp(&argv[i][2], "header") != 0) {
+ display_usage();
+ }
+ header=argv[++i];
+ break;
default:
display_usage();
break;
}
break;
+
default:
display_usage();
break;
@@ -203,13 +275,13 @@ int main(int argc, char **argv)
/* Has the user specified a configuration file */
if(config) { /* if yes, open it */
if((fp=fopen(config,"r"))==NULL){
- printf("Error - Can not open config file %s\n",config);
+ fprintf(stderr, "Error - Can not open config file %s\n",config);
exit(1); /* exit if it can not be opened */
}
}
else { /* no configuration file specified, so try the default */
if((fp=fopen("cmos.layout","r"))==NULL){
- printf("Error - Can not open cmos.layout\n");
+ fprintf(stderr, "Error - Can not open cmos.layout\n");
exit(1); /* end of no configuration file is found */
}
}
@@ -254,11 +326,17 @@ int main(int argc, char **argv)
ce->config=(int)uc;
/* check bit and length ranges */
if(ce->bit>(CMOS_IMAGE_BUFFER_SIZE*8)) {
- printf("Error - bit is to big in line \n%s\n",line);
+ fprintf(stderr, "Error - bit is to big in line \n%s\n",line);
exit(1);
}
if((ce->length>(MAX_VALUE_BYTE_LENGTH*8))&&(uc!='r')) {
- printf("Error - Length is to long in line \n%s\n",line);
+ fprintf(stderr, "Error - Length is to long in line \n%s\n",line);
+ exit(1);
+ }
+ if (!is_ident(ce->name)) {
+ fprintf(stderr,
+ "Error - Name %s is an invalid identifier in line\n %s\n",
+ ce->name, line);
exit(1);
}
/* put in the record type */
@@ -353,43 +431,43 @@ int main(int argc, char **argv)
skip_spaces(line, &ptr);
if ((cs->range_start%8) != 0) {
- printf("Error - range start is not byte aligned in line\n%s\n", line);
+ fprintf(stderr, "Error - range start is not byte aligned in line\n%s\n", line);
exit(1);
}
if (cs->range_start >= (CMOS_IMAGE_BUFFER_SIZE*8)) {
- printf("Error - range start is to big in line\n%s\n", line);
+ fprintf(stderr, "Error - range start is to big in line\n%s\n", line);
exit(1);
}
if ((cs->range_end%8) != 7) {
- printf("Error - range end is not byte aligned in line\n%s\n", line);
+ fprintf(stderr, "Error - range end is not byte aligned in line\n%s\n", line);
exit(1);
}
if ((cs->range_end) >= (CMOS_IMAGE_BUFFER_SIZE*8)) {
- printf("Error - range end is to long in line\n%s\n", line);
+ fprintf(stderr, "Error - range end is to long in line\n%s\n", line);
exit(1);
}
if ((cs->location%8) != 0) {
- printf("Error - location is not byte aligned in line\n%s\n", line);
+ fprintf(stderr, "Error - location is not byte aligned in line\n%s\n", line);
exit(1);
}
if ((cs->location >= (CMOS_IMAGE_BUFFER_SIZE*8)) ||
((cs->location + 16) > (CMOS_IMAGE_BUFFER_SIZE*8)))
{
- printf("Error - location is to big in line\n%s\n", line);
+ fprintf(stderr, "Error - location is to big in line\n%s\n", line);
exit(1);
}
/* And since we are not ready to be fully general purpose yet.. */
if ((cs->range_start/8) != LB_CKS_RANGE_START) {
- printf("Error - Range start(%d) does not match define(%d) in line\n%s\n",
+ fprintf(stderr, "Error - Range start(%d) does not match define(%d) in line\n%s\n",
cs->range_start/8, LB_CKS_RANGE_START, line);
exit(1);
}
if ((cs->range_end/8) != LB_CKS_RANGE_END) {
- printf("Error - Range end does not match define in line\n%s\n", line);
+ fprintf(stderr, "Error - Range end does not match define in line\n%s\n", line);
exit(1);
}
if ((cs->location/8) != LB_CKS_LOC) {
- printf("Error - Location does not match define in line\n%s\n", line);
+ fprintf(stderr, "Error - Location does not match define in line\n%s\n", line);
exit(1);
}
@@ -407,19 +485,19 @@ int main(int argc, char **argv)
/* test if an alternate file is to be created */
if(option) {
if((fp=fopen(option,"w"))==NULL){
- printf("Error - Can not open %s\n",option);
+ fprintf(stderr, "Error - Can not open %s\n",option);
exit(1);
}
}
else { /* no, so use the default option_table.c */
if((fp=fopen("option_table.c","w"))==NULL){
- printf("Error - Can not open option_table.c\n");
+ fprintf(stderr, "Error - Can not open option_table.c\n");
exit(1);
}
}
/* write the header */
if(!fwrite("unsigned char option_table[] = {",1,32,fp)) {
- printf("Error - Could not write image file\n");
+ fprintf(stderr, "Error - Could not write image file\n");
fclose(fp);
exit(1);
}
@@ -433,12 +511,48 @@ int main(int argc, char **argv)
sprintf(buf,"0x%02x",cmos_table[i]);
fwrite(buf,1,4,fp);
if(!fwrite("};\n",1,3,fp)) {
- printf("Error - Could not write image file\n");
+ fprintf(stderr, "Error - Could not write image file\n");
fclose(fp);
exit(1);
}
fclose(fp);
+
+ /* See if we also want to output a C header file */
+ if (header) {
+ struct cmos_option_table *hdr;
+ struct lb_record *ptr, *end;
+ fp = fopen(header, "w");
+ if (!fp) {
+ fprintf(stderr, "Error Can not open %s: %s\n",
+ header, strerror(errno));
+ exit(1);
+ }
+ /* Get the cmos table header */
+ hdr = (struct cmos_option_table *)cmos_table;
+ /* Walk through the entry records */
+ ptr = (struct lb_record *)(cmos_table + hdr->header_length);
+ end = (struct lb_record *)(cmos_table + hdr->size);
+ for(;ptr < end; ptr = (struct lb_record *)(((char *)ptr) + ptr->size)) {
+ if (ptr->tag != LB_TAG_OPTION) {
+ continue;
+ }
+ ce = (struct cmos_entries *)ptr;
+ if (ce->config == 'r') {
+ continue;
+ }
+ if (!is_ident(ce->name)) {
+ fprintf(stderr, "Invalid identifier: %s\n",
+ ce->name);
+ exit(1);
+ }
+ fprintf(fp, "#define CMOS_VSTART_%s %d\n",
+ ce->name, ce->bit);
+ fprintf(fp, "#define CMOS_VLEN_%s %d\n",
+ ce->name, ce->length);
+ }
+ fclose(fp);
+ }
return(0);
}
diff --git a/util/romcc/Makefile b/util/romcc/Makefile
index e8dd0a9679..75fb56c01f 100644
--- a/util/romcc/Makefile
+++ b/util/romcc/Makefile
@@ -1,5 +1,5 @@
-VERSION:=0.37
-RELEASE_DATE:=21 October 2003
+VERSION:=0.38
+RELEASE_DATE:=18 December 2003
PACKAGE:=romcc
@@ -108,6 +108,9 @@ FAIL_TESTS = \
fail_test3.c \
fail_test4.c \
fail_test5.c \
+ fail_test6.c \
+ fail_test7.c \
+ fail_test8.c \
TEST_SRCS:=$(patsubst %, tests/%, $(TESTS))
TEST_ASM:=$(patsubst %.c, tests/%.S, $(TESTS))
diff --git a/util/romcc/romcc.c b/util/romcc/romcc.c
index d460cfb548..ff7aee669b 100644
--- a/util/romcc/romcc.c
+++ b/util/romcc/romcc.c
@@ -1579,7 +1579,7 @@ static unsigned short triple_sizes(struct compile_state *state,
rhs = rhs_wanted;
lhs = 0;
if ((type->type & TYPE_MASK) == TYPE_STRUCT) {
- lhs = type->left->elements;
+ lhs = type->elements;
}
}
else if (op == OP_VAL_VEC) {
@@ -4822,7 +4822,8 @@ static int is_stable(struct compile_state *state, struct triple *def)
if ((def->op == OP_ADECL) ||
(def->op == OP_SDECL) ||
(def->op == OP_DEREF) ||
- (def->op == OP_BLOBCONST)) {
+ (def->op == OP_BLOBCONST) ||
+ (def->op == OP_LIST)) {
ret = 1;
}
else if (def->op == OP_DOT) {
@@ -4930,6 +4931,9 @@ static struct triple *do_mk_addr_expr(struct compile_state *state,
RHS(expr, 0),
int_const(state, &ulong_type, offset));
}
+ else if (expr->op == OP_LIST) {
+ error(state, 0, "Function addresses not supported");
+ }
if (!result) {
internal_error(state, expr, "cannot take address of expression");
}
@@ -4951,8 +4955,9 @@ static struct triple *mk_deref_expr(
return triple(state, OP_DEREF, base_type, expr, 0);
}
-static struct triple *array_to_pointer(struct compile_state *state, struct triple *def)
+static struct triple *lvalue_conversion(struct compile_state *state, struct triple *def)
{
+ /* Tranform an array to a pointer to the first element */
if ((def->type->type & TYPE_MASK) == TYPE_ARRAY) {
struct type *type;
type = new_type(
@@ -4971,6 +4976,10 @@ static struct triple *array_to_pointer(struct compile_state *state, struct tripl
def = triple(state, OP_COPY, type, def, 0);
}
}
+ /* Transform a function to a pointer to it */
+ else if ((def->type->type & TYPE_MASK) == TYPE_FUNCTION) {
+ def = mk_addr_expr(state, def, 0);
+ }
return def;
}
@@ -5010,15 +5019,12 @@ static struct triple *read_expr(struct compile_state *state, struct triple *def)
if (!def) {
return 0;
}
+#warning "CHECK_ME is this the only place I need to do lvalue conversions?"
+ /* Transform lvalues into something we can read */
+ def = lvalue_conversion(state, def);
if (!is_stable(state, def)) {
return def;
}
- /* Tranform an array to a pointer to the first element */
-
-#warning "CHECK_ME is this the right place to transform arrays to pointers?"
- if ((def->type->type & TYPE_MASK) == TYPE_ARRAY) {
- return array_to_pointer(state, def);
- }
if (is_in_reg(state, def)) {
op = OP_READ;
} else {
@@ -8268,7 +8274,11 @@ static struct triple *expr(struct compile_state *state)
static void expr_statement(struct compile_state *state, struct triple *first)
{
if (peek(state) != TOK_SEMI) {
- flatten(state, first, expr(state));
+ /* lvalue conversions always apply except when certaion operators
+ * are applied so the values so apply them here as I know no more
+ * operators will be applied.
+ */
+ flatten(state, first, lvalue_conversion(state, expr(state)));
}
eat(state, TOK_SEMI);
}
@@ -9650,7 +9660,7 @@ static struct triple *initializer(
((result->type->type & TYPE_MASK) == TYPE_ARRAY) &&
(type->type & TYPE_MASK) != TYPE_ARRAY)
{
- result = array_to_pointer(state, result);
+ result = lvalue_conversion(state, result);
}
if (!is_init_compatible(state, type, result->type)) {
error(state, 0, "Incompatible types in initializer");
@@ -18548,6 +18558,7 @@ static void print_const(struct compile_state *state,
case TYPE_UINT:
case TYPE_LONG:
case TYPE_ULONG:
+ case TYPE_POINTER:
fprintf(fp, ".int %lu\n",
(unsigned long)(ins->u.cval));
break;
diff --git a/util/romcc/tests/fail_test6.c b/util/romcc/tests/fail_test6.c
new file mode 100644
index 0000000000..cc7bcf52c6
--- /dev/null
+++ b/util/romcc/tests/fail_test6.c
@@ -0,0 +1,11 @@
+
+
+static void hlt(void)
+{
+}
+
+static void main(void)
+{
+ void *foo;
+ foo = hlt;
+}
diff --git a/util/romcc/tests/fail_test7.c b/util/romcc/tests/fail_test7.c
new file mode 100644
index 0000000000..e7a0db93d3
--- /dev/null
+++ b/util/romcc/tests/fail_test7.c
@@ -0,0 +1,10 @@
+
+
+static void hlt(void)
+{
+}
+
+static void main(void)
+{
+ &hlt;
+}
diff --git a/util/romcc/tests/fail_test8.c b/util/romcc/tests/fail_test8.c
new file mode 100644
index 0000000000..10ade55f75
--- /dev/null
+++ b/util/romcc/tests/fail_test8.c
@@ -0,0 +1,10 @@
+
+
+static void hlt(void)
+{
+}
+
+static void main(void)
+{
+ hlt;
+}