summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenedikt Spranger <b.spranger@pengutronix.de>2005-06-07 12:17:07 +0000
committerBenedikt Spranger <b.spranger@pengutronix.de>2005-06-07 12:17:07 +0000
commit1121651dc9049233a93a0ca90e8133c4eeb460a4 (patch)
tree34b66981a75da7b50bed6409d2285e66e61bead7
parentc9667fb5c490ba309120ee062e49e49d9fbd4cc4 (diff)
downloadmemedit-1121651dc9049233a93a0ca90e8133c4eeb460a4.tar.gz
memedit-1121651dc9049233a93a0ca90e8133c4eeb460a4.tar.xz
make /foo/bar accessible and some other minor changes
-rw-r--r--AUTHORS2
-rw-r--r--memedit.c1
-rw-r--r--memedit.l30
-rw-r--r--memedit.y50
4 files changed, 53 insertions, 30 deletions
diff --git a/AUTHORS b/AUTHORS
index 830dd08..8e27674 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,3 +1,3 @@
-Primary author: Benedikt Spranger <b.spranger@pengutronix.de> (address not valid any more)
+Primary author: Benedikt Spranger <b.spranger@linutronix.de>
Maintainer: Robert Schwebel <r.schwebel@pengutronix.de>
Contributor: Sascha Hauer <s.hauer@pengutronix.de>
diff --git a/memedit.c b/memedit.c
index ed797b4..1796de0 100644
--- a/memedit.c
+++ b/memedit.c
@@ -19,6 +19,7 @@ extern int yyparse();
#include "memedit_parser.h"
int debug = 0;
+int mmaped_access = 0;
FILE *rl_instream;
int fd = -1;
diff --git a/memedit.l b/memedit.l
index 1413e24..8739c7e 100644
--- a/memedit.l
+++ b/memedit.l
@@ -13,8 +13,10 @@
%{
#include <unistd.h>
#include <stdio.h>
+#include <stdlib.h>
#include <readline/readline.h>
#include <readline/history.h>
+#include <string.h>
/* need this for the call to atol() below */
#include <math.h>
@@ -85,7 +87,8 @@ rl_input (char *buf, int *result, int max)
%}
DIGIT [0-9]
-ID [a-z_][a-z0-9_]*
+FILE [a-z_/][a-z0-9_/]*
+VAR [a-z_][a-z0-9_]*
HEX [0-9a-z]
OCT [0-7]
BIN [01]
@@ -199,27 +202,40 @@ at {
o |
open {
- if (debug > 4) printf ("\n");
+ if (debug > 4) printf ("OPEN\n");
return OPEN;
}
c |
close {
- if (debug > 4) printf ("\n");
+ if (debug > 4) printf ("CLOSE\n");
return CLOSE;
}
map {
- if (debug > 4) printf ("\n");
+ if (debug > 4) printf ("MAP\n");
return MAP;
}
-{ID} {
+unmap {
+ if (debug > 4) printf ("UNMAP\n");
+ return UNMAP;
+}
+
+{FILE} {
+ yylval.tptr = malloc(sizeof(yytext));
+ if (yylval.tptr) strcpy(yylval.tptr, yytext);
+ else printf ("no mem in %s", __FUNCTION__);
+ if (debug > 4) printf ("FILE: >%s<\n", yytext);
+ return FILENAME;
+}
+
+{VAR} {
yylval.tptr = malloc(sizeof(yytext));
if (yylval.tptr) strcpy(yylval.tptr, yytext);
else printf ("no mem in %s", __FUNCTION__);
- if (debug > 4) printf ("ID: >%s<\n", yytext);
- return NAME;
+ if (debug > 4) printf ("VAR: >%s<\n", yytext);
+ return VARNAME;
}
{DIGIT}+ {
diff --git a/memedit.y b/memedit.y
index 8358021..ebbcadd 100644
--- a/memedit.y
+++ b/memedit.y
@@ -14,7 +14,7 @@
extern int errno;
extern int fd;
-extern int debug;
+extern int debug, mmaped_access;
extern void *mem;
unsigned int cur_position;
@@ -58,10 +58,12 @@ char *tptr;
%left <val> LSHIFT
%left <val> OBRA
%left <val> CBRA
-%left <tptr> NAME
+%left <tptr> FILENAME
+%left <tptr> VARNAME
%left <val> OPEN
%left <val> CLOSE
%left <val> MAP
+%left <val> UNMAP
%left <val> MD
%left <val> MM
%left <val> EQ
@@ -83,6 +85,7 @@ line: CR
| open CR
| close CR
| map CR
+ | UNMAP CR {if (mmaped_access) munmap (mem, map_size);}
| EXIT CR { exit(EXIT_SUCCESS); }
| HELP CR { print_help(); }
| ENV CR {
@@ -90,32 +93,33 @@ line: CR
for (l = vlist; l; l = l->next)
printf ("%s = 0x%x\n", l->name,l->val);
}
- | NAME CR { printf ("%s = %d\n", $1, get_variable($1)); free($1); }
+ | VARNAME CR { printf ("%s = %d\n", $1, get_variable($1)); free($1); }
| mem CR { printf ("\n"); }
- | NAME EQ num CR { set_variable ($1, $3); free($1); }
- | NAME EQ MD num CR {
-#if 0
- if (fhan)
+ | VARNAME EQ num CR { set_variable ($1, $3); free($1); }
+ | VARNAME EQ MD num CR {
+ if (mmaped_access) {
+ printf ("mmaped access: not implemented\n");
+ }
+ else if (fd)
{
- if (fseek (fhan, $4, SEEK_SET) == -1)
+ if (lseek (fd, $4, SEEK_SET) == -1)
printf ("set offset %ld failed\n", $4);
else
{
unsigned int c = 0;
- fread(&c, $3, 1, fhan);
+ read(fd, &c, $3);
set_variable ($1, c);
free($1);
}
}
else printf ("please open file\n");
-#endif
}
| error
;
open: OPEN { printf ("open <filename>\n"); }
- | OPEN NAME {
+ | OPEN FILENAME {
if (fd>=0)
close (fd);
fd = open($2, O_RDWR | O_SYNC);
@@ -128,7 +132,8 @@ open: OPEN { printf ("open <filename>\n"); }
close: CLOSE {
if (fd>0) {
- close (fd); fd = -1;
+ close (fd); fd = -1;
+ mmaped_access = 0;
}
}
;
@@ -136,15 +141,16 @@ close: CLOSE {
map: MAP { printf("map <start> <size>\n"); }
| MAP num num {
if (fd>0) {
- printf("mapping offset 0x%08lx (size 0x%lx)\n",$2,$3);
- map_ofs = $2;
- map_size = $3;
- mem = mmap(0, $3, PROT_READ | PROT_WRITE,
- MAP_SHARED, fd, $2);
- if(mem == MAP_FAILED) {
- perror("mmap");
- }
- cur_position = 0;
+ printf("mapping offset 0x%08lx (size 0x%lx)\n",$2,$3);
+ map_ofs = $2;
+ map_size = $3;
+ mem = mmap(0, $3, PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, $2);
+ if(mem == MAP_FAILED) {
+ perror("mmap");
+ }
+ cur_position = 0;
+ mmaped_access = 1;
} else
printf("load a file first\n");
}
@@ -225,7 +231,7 @@ num: NUM
| num RSHIFT num { $$ = $1 >> $3; if (debug > 3) printf ("RSHIFT: %ld\n", $$); }
| num LSHIFT num { $$ = $1 << $3; if (debug > 3) printf ("LSHIFT: %ld\n", $$); }
| OBRA num CBRA { $$ = $2; if (debug > 3) printf ("BRA: %ld\n", $$); }
- | NAME { $$ = get_variable ($1); if (debug > 3) printf ("VAR: %ld\n", $$); free($1); }
+ | VARNAME { $$ = get_variable ($1); if (debug > 3) printf ("VAR: %ld\n", $$); free($1); }
;
%%