summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPatrick Georgi <patrick.georgi@coresystems.de>2010-05-05 12:05:25 +0000
committerPatrick Georgi <patrick.georgi@coresystems.de>2010-05-05 12:05:25 +0000
commit68befd5d34ce22b03ea78028dc362eec0440f83c (patch)
treec5b67ed5900c396cb0d9a57a7ed6ce994bd56b3f /util
parent114e7b2990cd2b64956ddb271638646ef5108d54 (diff)
downloadcoreboot-68befd5d34ce22b03ea78028dc362eec0440f83c.tar.xz
sconfig: Make cur_bus and cur_parent local to the parser.
Instead of accessing them globally, pass them as arguments where necessary. Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5524 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util')
-rwxr-xr-xutil/sconfig/main.c60
-rwxr-xr-xutil/sconfig/sconfig.h10
-rw-r--r--util/sconfig/sconfig.tab.c_shipped113
-rwxr-xr-xutil/sconfig/sconfig.y12
4 files changed, 102 insertions, 93 deletions
diff --git a/util/sconfig/main.c b/util/sconfig/main.c
index 00d0e5a5b2..9c7938617b 100755
--- a/util/sconfig/main.c
+++ b/util/sconfig/main.c
@@ -51,12 +51,12 @@ static struct device root = {
.enabled = 1
};
-static struct device *new_dev() {
+static struct device *new_dev(struct device *parent, struct device *bus) {
struct device *dev = malloc(sizeof(struct device));
memset(dev, 0, sizeof(struct device));
dev->id = ++devcount;
- dev->parent = cur_parent;
- dev->bus = cur_bus;
+ dev->parent = parent;
+ dev->bus = bus;
head->next = dev;
head = dev;
return dev;
@@ -110,8 +110,8 @@ void postprocess_devtree(void) {
}
}
-struct device *new_chip(char *path) {
- struct device *new_chip = new_dev();
+struct device *new_chip(struct device *parent, struct device *bus, char *path) {
+ struct device *new_chip = new_dev(parent, bus);
new_chip->chiph_exists = 1;
new_chip->name = path;
new_chip->name_underscore = strdup(new_chip->name);
@@ -129,13 +129,13 @@ struct device *new_chip(char *path) {
if ((stat(chip_h, &st) == -1) && (errno == ENOENT))
new_chip->chiph_exists = 0;
- if (cur_parent->latestchild) {
- cur_parent->latestchild->next_sibling = new_chip;
- cur_parent->latestchild->sibling = new_chip;
+ if (parent->latestchild) {
+ parent->latestchild->next_sibling = new_chip;
+ parent->latestchild->sibling = new_chip;
}
- cur_parent->latestchild = new_chip;
- if (!cur_parent->children)
- cur_parent->children = new_chip;
+ parent->latestchild = new_chip;
+ if (!parent->children)
+ parent->children = new_chip;
return new_chip;
}
@@ -162,8 +162,8 @@ void add_header(struct device *dev) {
}
}
-struct device *new_device(const int bus, const char *devnum, int enabled) {
- struct device *new_d = new_dev();
+struct device *new_device(struct device *parent, struct device *busdev, const int bus, const char *devnum, int enabled) {
+ struct device *new_d = new_dev(parent, busdev);
new_d->bustype = bus;
char *tmp;
@@ -181,13 +181,13 @@ struct device *new_device(const int bus, const char *devnum, int enabled) {
new_d->enabled = enabled;
new_d->chip = new_d->parent->chip;
- if (cur_parent->latestchild) {
- cur_parent->latestchild->next_sibling = new_d;
- cur_parent->latestchild->sibling = new_d;
+ if (parent->latestchild) {
+ parent->latestchild->next_sibling = new_d;
+ parent->latestchild->sibling = new_d;
}
- cur_parent->latestchild = new_d;
- if (!cur_parent->children)
- cur_parent->children = new_d;
+ parent->latestchild = new_d;
+ if (!parent->children)
+ parent->children = new_d;
lastdev->nextdev = new_d;
lastdev = new_d;
@@ -235,29 +235,29 @@ void alias_siblings(struct device *d) {
}
}
-void add_resource(int type, int index, int base) {
+void add_resource(struct device *dev, int type, int index, int base) {
struct resource *r = malloc(sizeof(struct resource));
memset (r, 0, sizeof(struct resource));
r->type = type;
r->index = index;
r->base = base;
- if (cur_parent->res) {
- struct resource *head = cur_parent->res;
+ if (dev->res) {
+ struct resource *head = dev->res;
while (head->next) head = head->next;
head->next = r;
} else {
- cur_parent->res = r;
+ dev->res = r;
}
- cur_parent->rescnt++;
+ dev->rescnt++;
}
-void add_register(char *name, char *val) {
+void add_register(struct device *dev, char *name, char *val) {
struct reg *r = malloc(sizeof(struct reg));
memset (r, 0, sizeof(struct reg));
r->key = name;
r->value = val;
- if (cur_parent->reg) {
- struct reg *head = cur_parent->reg;
+ if (dev->reg) {
+ struct reg *head = dev->reg;
// sorting to be equal to sconfig's behaviour
int sort = strcmp(r->key, head->key);
if (sort == 0) {
@@ -266,14 +266,14 @@ void add_register(char *name, char *val) {
}
if (sort<0) {
r->next = head;
- cur_parent->reg = r;
+ dev->reg = r;
} else {
while ((head->next) && (strcmp(head->next->key, r->key)<0)) head = head->next;
r->next = head->next;
head->next = r;
}
} else {
- cur_parent->reg = r;
+ dev->reg = r;
}
}
@@ -390,7 +390,7 @@ int main(int argc, char** argv) {
FILE *staticc = fopen(outputc, "w");
- cur_bus = cur_parent = lastdev = head = &root;
+ lastdev = head = &root;
yyparse();
fclose(filec);
diff --git a/util/sconfig/sconfig.h b/util/sconfig/sconfig.h
index 78305464ba..139ac86ae9 100755
--- a/util/sconfig/sconfig.h
+++ b/util/sconfig/sconfig.h
@@ -74,7 +74,7 @@ struct device {
struct reg *reg;
};
-extern struct device *cur_parent, *cur_bus;
+struct device *head;
struct header;
struct header {
@@ -85,9 +85,9 @@ struct header {
void fold_in(struct device *parent);
void postprocess_devtree(void);
-struct device *new_chip(char *path);
+struct device *new_chip(struct device *parent, struct device *bus, char *path);
void add_header(struct device *dev);
-struct device *new_device(const int bus, const char *devnum, int enabled);
+struct device *new_device(struct device *parent, struct device *busdev, const int bus, const char *devnum, int enabled);
void alias_siblings(struct device *d);
-void add_resource(int type, int index, int base);
-void add_register(char *name, char *val);
+void add_resource(struct device *dev, int type, int index, int base);
+void add_register(struct device *dev, char *name, char *val);
diff --git a/util/sconfig/sconfig.tab.c_shipped b/util/sconfig/sconfig.tab.c_shipped
index 7490546921..6f155ae8cc 100644
--- a/util/sconfig/sconfig.tab.c_shipped
+++ b/util/sconfig/sconfig.tab.c_shipped
@@ -90,7 +90,7 @@
#include "sconfig.h"
-struct device *cur_parent, *cur_bus;
+static struct device *cur_parent, *cur_bus;
@@ -378,18 +378,18 @@ union yyalloc
#endif
/* YYFINAL -- State number of the termination state. */
-#define YYFINAL 9
+#define YYFINAL 3
/* YYLAST -- Last index in YYTABLE. */
-#define YYLAST 23
+#define YYLAST 22
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 23
/* YYNNTS -- Number of nonterminals. */
-#define YYNNTS 11
+#define YYNNTS 12
/* YYNRULES -- Number of rules. */
-#define YYNRULES 16
+#define YYNRULES 17
/* YYNRULES -- Number of states. */
-#define YYNSTATES 30
+#define YYNSTATES 31
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
#define YYUNDEFTOK 2
@@ -436,25 +436,26 @@ static const yytype_uint8 yytranslate[] =
YYRHS. */
static const yytype_uint8 yyprhs[] =
{
- 0, 0, 3, 5, 7, 9, 12, 15, 16, 19,
- 22, 23, 24, 30, 31, 39, 44
+ 0, 0, 3, 4, 7, 9, 11, 14, 17, 18,
+ 21, 24, 25, 26, 32, 33, 41, 46
};
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yytype_int8 yyrhs[] =
{
- 24, 0, -1, 25, -1, 28, -1, 30, -1, 26,
- 25, -1, 26, 33, -1, -1, 27, 25, -1, 27,
- 32, -1, -1, -1, 3, 12, 29, 26, 9, -1,
- -1, 4, 7, 22, 6, 31, 27, 9, -1, 8,
- 22, 10, 22, -1, 5, 12, 10, 12, -1
+ 24, 0, -1, -1, 25, 26, -1, 29, -1, 31,
+ -1, 27, 26, -1, 27, 34, -1, -1, 28, 26,
+ -1, 28, 33, -1, -1, -1, 3, 12, 30, 27,
+ 9, -1, -1, 4, 7, 22, 6, 32, 28, 9,
+ -1, 8, 22, 10, 22, -1, 5, 12, 10, 12,
+ -1
};
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
- 0, 34, 34, 36, 36, 38, 38, 38, 40, 40,
- 40, 42, 42, 52, 52, 64, 67
+ 0, 34, 34, 34, 36, 36, 38, 38, 38, 40,
+ 40, 40, 42, 42, 52, 52, 64, 67
};
#endif
@@ -466,8 +467,8 @@ static const char *const yytname[] =
"$end", "error", "$undefined", "CHIP", "DEVICE", "REGISTER", "BOOL",
"BUS", "RESOURCE", "END", "EQUALS", "HEX", "STRING", "PCI", "PNP", "I2C",
"APIC", "APIC_CLUSTER", "PCI_DOMAIN", "IRQ", "DRQ", "IO", "NUMBER",
- "$accept", "devtree", "devchip", "devices", "devicesorresources", "chip",
- "@1", "device", "@2", "resource", "registers", 0
+ "$accept", "devtree", "$@1", "devchip", "devices", "devicesorresources",
+ "chip", "@2", "device", "@3", "resource", "registers", 0
};
#endif
@@ -485,15 +486,15 @@ static const yytype_uint16 yytoknum[] =
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] =
{
- 0, 23, 24, 25, 25, 26, 26, 26, 27, 27,
- 27, 29, 28, 31, 30, 32, 33
+ 0, 23, 25, 24, 26, 26, 27, 27, 27, 28,
+ 28, 28, 30, 29, 32, 31, 33, 34
};
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
static const yytype_uint8 yyr2[] =
{
- 0, 2, 1, 1, 1, 2, 2, 0, 2, 2,
- 0, 0, 5, 0, 7, 4, 4
+ 0, 2, 0, 2, 1, 1, 2, 2, 0, 2,
+ 2, 0, 0, 5, 0, 7, 4, 4
};
/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
@@ -501,33 +502,35 @@ static const yytype_uint8 yyr2[] =
means the default is an error. */
static const yytype_uint8 yydefact[] =
{
- 0, 0, 0, 0, 2, 3, 4, 11, 0, 1,
- 7, 0, 0, 13, 0, 12, 5, 6, 10, 0,
- 0, 0, 0, 14, 8, 9, 16, 0, 0, 15
+ 2, 0, 0, 1, 0, 0, 3, 4, 5, 12,
+ 0, 8, 0, 0, 14, 0, 13, 6, 7, 11,
+ 0, 0, 0, 0, 15, 9, 10, 17, 0, 0,
+ 16
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] =
{
- -1, 3, 4, 12, 20, 5, 10, 6, 18, 25,
- 17
+ -1, 1, 2, 6, 13, 21, 7, 11, 8, 19,
+ 26, 18
};
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
-#define YYPACT_NINF -13
+#define YYPACT_NINF -14
static const yytype_int8 yypact[] =
{
- 8, -6, 6, 14, -13, -13, -13, -13, -7, -13,
- -13, 10, -2, -13, 5, -13, -13, -13, -13, 9,
- 1, 11, -4, -13, -13, -13, -13, 12, -1, -13
+ -14, 6, 8, -14, 2, 9, -14, -14, -14, -14,
+ -9, -14, 11, -2, -14, 3, -14, -14, -14, -14,
+ 10, 1, 7, -4, -14, -14, -14, -14, 12, -1,
+ -14
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
- -13, -13, -12, -13, -13, -13, -13, -13, -13, -13,
- -13
+ -14, -14, -14, -13, -14, -14, -14, -14, -14, -14,
+ -14, -14
};
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
@@ -537,25 +540,26 @@ static const yytype_int8 yypgoto[] =
#define YYTABLE_NINF -1
static const yytype_uint8 yytable[] =
{
- 16, 1, 2, 14, 1, 2, 7, 15, 24, 22,
- 23, 1, 2, 8, 9, 11, 13, 19, 27, 21,
- 0, 29, 28, 26
+ 17, 4, 5, 15, 4, 5, 3, 16, 25, 23,
+ 24, 4, 5, 12, 9, 20, 10, 14, 28, 27,
+ 22, 30, 29
};
-static const yytype_int8 yycheck[] =
+static const yytype_uint8 yycheck[] =
{
- 12, 3, 4, 5, 3, 4, 12, 9, 20, 8,
- 9, 3, 4, 7, 0, 22, 6, 12, 22, 10,
- -1, 22, 10, 12
+ 13, 3, 4, 5, 3, 4, 0, 9, 21, 8,
+ 9, 3, 4, 22, 12, 12, 7, 6, 22, 12,
+ 10, 22, 10
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] =
{
- 0, 3, 4, 24, 25, 28, 30, 12, 7, 0,
- 29, 22, 26, 6, 5, 9, 25, 33, 31, 12,
- 27, 10, 8, 9, 25, 32, 12, 22, 10, 22
+ 0, 24, 25, 0, 3, 4, 26, 29, 31, 12,
+ 7, 30, 22, 27, 6, 5, 9, 26, 34, 32,
+ 12, 28, 10, 8, 9, 26, 33, 12, 22, 10,
+ 22
};
#define yyerrok (yyerrstatus = 0)
@@ -1368,18 +1372,23 @@ yyreduce:
{
case 2:
+ { cur_parent = cur_bus = head; ;}
+ break;
+
+ case 3:
+
{ postprocess_devtree(); ;}
break;
- case 11:
+ case 12:
{
- (yyval.device) = new_chip((yyvsp[(2) - (2)].string));
+ (yyval.device) = new_chip(cur_parent, cur_bus, (yyvsp[(2) - (2)].string));
cur_parent = (yyval.device);
;}
break;
- case 12:
+ case 13:
{
cur_parent = (yyvsp[(3) - (5)].device)->parent;
@@ -1388,16 +1397,16 @@ yyreduce:
;}
break;
- case 13:
+ case 14:
{
- (yyval.device) = new_device((yyvsp[(2) - (4)].number), (yyvsp[(3) - (4)].string), (yyvsp[(4) - (4)].number));
+ (yyval.device) = new_device(cur_parent, cur_bus, (yyvsp[(2) - (4)].number), (yyvsp[(3) - (4)].string), (yyvsp[(4) - (4)].number));
cur_parent = (yyval.device);
cur_bus = (yyval.device);
;}
break;
- case 14:
+ case 15:
{
cur_parent = (yyvsp[(5) - (7)].device)->parent;
@@ -1407,14 +1416,14 @@ yyreduce:
;}
break;
- case 15:
+ case 16:
- { add_resource((yyvsp[(1) - (4)].number), strtol((yyvsp[(2) - (4)].string), NULL, 0), strtol((yyvsp[(4) - (4)].string), NULL, 0)); ;}
+ { add_resource(cur_parent, (yyvsp[(1) - (4)].number), strtol((yyvsp[(2) - (4)].string), NULL, 0), strtol((yyvsp[(4) - (4)].string), NULL, 0)); ;}
break;
- case 16:
+ case 17:
- { add_register((yyvsp[(2) - (4)].string), (yyvsp[(4) - (4)].string)); ;}
+ { add_register(cur_parent, (yyvsp[(2) - (4)].string), (yyvsp[(4) - (4)].string)); ;}
break;
diff --git a/util/sconfig/sconfig.y b/util/sconfig/sconfig.y
index 3860569a95..162ce7050d 100755
--- a/util/sconfig/sconfig.y
+++ b/util/sconfig/sconfig.y
@@ -21,7 +21,7 @@
#include "sconfig.h"
-struct device *cur_parent, *cur_bus;
+static struct device *cur_parent, *cur_bus;
%}
%union {
@@ -31,7 +31,7 @@ struct device *cur_parent, *cur_bus;
}
%token CHIP DEVICE REGISTER BOOL BUS RESOURCE END EQUALS HEX STRING PCI PNP I2C APIC APIC_CLUSTER PCI_DOMAIN IRQ DRQ IO NUMBER
%%
-devtree: devchip { postprocess_devtree(); } ;
+devtree: { cur_parent = cur_bus = head; } devchip { postprocess_devtree(); } ;
devchip: chip | device ;
@@ -40,7 +40,7 @@ devices: devices devchip | devices registers | ;
devicesorresources: devicesorresources devchip | devicesorresources resource | ;
chip: CHIP STRING /* == path */ {
- $<device>$ = new_chip($<string>2);
+ $<device>$ = new_chip(cur_parent, cur_bus, $<string>2);
cur_parent = $<device>$;
}
devices END {
@@ -50,7 +50,7 @@ chip: CHIP STRING /* == path */ {
};
device: DEVICE BUS NUMBER /* == devnum */ BOOL {
- $<device>$ = new_device($<number>2, $<string>3, $<number>4);
+ $<device>$ = new_device(cur_parent, cur_bus, $<number>2, $<string>3, $<number>4);
cur_parent = $<device>$;
cur_bus = $<device>$;
}
@@ -62,9 +62,9 @@ device: DEVICE BUS NUMBER /* == devnum */ BOOL {
};
resource: RESOURCE NUMBER /* == resnum */ EQUALS NUMBER /* == resval */
- { add_resource($<number>1, strtol($<string>2, NULL, 0), strtol($<string>4, NULL, 0)); } ;
+ { add_resource(cur_parent, $<number>1, strtol($<string>2, NULL, 0), strtol($<string>4, NULL, 0)); } ;
registers: REGISTER STRING /* == regname */ EQUALS STRING /* == regval */
- { add_register($<string>2, $<string>4); } ;
+ { add_register(cur_parent, $<string>2, $<string>4); } ;
%%