From mboxrd@z Thu Jan 1 00:00:00 1970 From: ron minnich To: 9fans@cse.psu.edu Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: [9fans] A simple question Date: Wed, 9 Jul 2003 07:20:20 -0600 Topicbox-Message-UUID: f0047724-eacb-11e9-9e20-41e7f4b1d025 I have a little program, a.c: #include int a(){ print("hi\n"); } I want to link the a.8 program produced by 8.c against the 9pcdisk image and produce an 8.out, something like this: 8l -T some-base-address a.8 9pcdisk I want the 8.out to be JUST the a.8 with symbol fixups from 9pcdisk, and based at 'some-base-address'. Now obviously that doesn't *quite* work, since 9pcdisk is not something you can link against. So what I'm really after is something like this: 8l -T some-base-address -d 9pcdisk a.8 This would use 9pcdisk to define the symbols. I don't really want to work with 9pcdisk directly, so I did this: nm 9pcdisk > kname I get a log of entries in kname like this: 0x80400040 T somesymbol And then all I need to do is set up 8l to read this file and pre-define a bunch of symbols (or so I think). So as a test I put this code into 8l, ripping off the readundefs code (defs is an array of names of define files to use, defsp is how many there are): void readdefs(void) { int i, n; Sym *s; Biobuf *b; char *l, buf[256], *fields[3]; for(i = 0; i < defsp; i++) { b = Bopen(defs[i], OREAD); if(b == nil) { diag("could not open %s: %r", defs[i]); errorexit(); } while((l = Brdline(b, '\n')) != nil) { n = Blinelen(b); if(n >= sizeof(buf)) { diag("%s: line too long", defs[i]); errorexit(); } strncpy(buf, l, n); n = getfields(buf, fields, nelem(fields), 1, " \t\r\n"); if(n == nelem(fields)) { diag("%s: bad format", defs[i]); errorexit(); } if ((*fields[1] != 'T') && (*fields[1] != 'D')) continue; s = lookup(fields[2], 0); if (*fields[1] == 'T') s->type = STEXT; else s->type = SDATA; s->value = strtol(fields[0], 0, 0); } Bterm(b); } } I.e. read the kname file, and for all the 'T' and 'D' entries, put a symbol table entry in for those names. Well, this sort of works, but I have not figured out how to make 8l NOT change the values of these symbols. In other words, print starts out with some value from 9pcdisk, but in 8.out it has a different value. Not what I want at all. I want 8.out to have a fixed up symbol for print, with the value found in 9pcdisk. I also think I'm missing some bits which are probably needed to link correctly. I set name, value, and type; I think I might need to set frame; are version and become required? If it's not obvious I need this to allow me to put code images into kernel space and call them. I'm doing this via a device I've called zoot (#z) since I don't believe anybody else is using #z. This work is for two uses: modules and Plan 9 booting Plan 9. I started on Plan 9 booting Plan 9 since fixing 9load AND Plan 9 issues for linuxbios is twice as much work as just trying to fix Plan 9 for linuxbios. If Plan 9 can boot Plan 9, then I can stop worrying about 9load. Now if somebody has already done both these things just tell me and I can stop :-) BTW #z, so far, is in port, not pc, and I hope to keep it that way. ron