diff options
-rw-r--r-- | mkbootfs/mkbootfs.c | 101 |
1 files changed, 93 insertions, 8 deletions
diff --git a/mkbootfs/mkbootfs.c b/mkbootfs/mkbootfs.c index 75e1523e..42c7e2bd 100644 --- a/mkbootfs/mkbootfs.c +++ b/mkbootfs/mkbootfs.c @@ -30,28 +30,113 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ _execserver_start The .o will then be linked along with the rest of the filesystem, which - will spawn an execserver with the right bits when it starts. */ + will spawn an execserver with the right bits when it starts. -/* This is non-general, and only intended for the i386 Mach 3.0 with its - own weird format. */ + The text should be loaded at 0x10000 and the data at + 0x10000 + _execserver_text_size and the bss cleared at + 0x10000 + _execserver_text_size + _execserver_data_size. + */ -/* Usage: mkbootfs execserver */ +/* This is non-general, and only intended for the i386 Mach 3.0 with + its own weird format. It expects the header files to be from such a + Mach system as CMU sets them up. */ + +/* Usage: mkbootfs execserver newdoto */ main (int argc, char **argv) { - int execserver; + int execserver, newdoto; + struct exec a, newa; + unsigned long foo; + void *buf; + struct nlist n; - if (argc != 2) + if (argc != 3) { - fprintf (stderr, "Usage: %s execserver\n", argv[0]); + fprintf (stderr, "Usage: %s execserver newdoto\n", argv[0]); exit (1); } - execserver = open (argv[1]); + execserver = open (argv[1], O_RDONLY); if (execserver == -1) { perror (argv[1]); exit (1); } + newdoto = open (argv[2], O_WRONLY | O_CREAT, 0666); + if (newdoto == -1) + { + perror (argv[2]); + exit (1); + } + + read (execserver, &a, sizeof (struct exec)); + + /* Write the new data segment to the new file. */ + lseek (newdoto, sizeof (struct exec), L_SET); + + /* First, _execserver_text_size */ + foo = a.a_text + sizeof (struct exec); + write (newdoto, &foo, sizeof foo); + + /* Next, _execserver_data_size */ + write (newdoto, &a.a_data, sizeof a.a_data); + + /* Next, _execserver_bss_size */ + write (newdoto, &a.a_bss, sizeof a.a_bss); + + /* Next, _execserver_text */ + buf = malloc (a.a_text + sizeof (struct exec)); + lseek (execserver, 0, L_SET); + read (execserver, buf, a.a_text + sizeof (struct exec)); + write (newdoto, buf, a.a_text + sizeof (struct exec)); + free (buf); + + /* Next, _execserver_data */ + buf = malloc (a.a_data); + read (execserver, buf, a.a_data); + write (newdoto, buf, a.a_data); + free (bof); + + /* Finally, _execserver_start */ + write (newdoto, &a.a_entry, sizeof a.a_entry); + + /* We have no relocation information */ + + /* Now, write the symbol table */ + n.n_un.n_strx = 50; + n.n_type = N_DATA | N_EXT; + n.n_value = 0; + + /* First, _execserver_text_size */ + write (newdoto, &n, sizeof (n)); + n.n_value += sizeof (foo); + + /* Now, _execserver_data_size */ + n.n_un.n_strx += 50; + write (newdoto, &n, sizeof (n)); + n.n_value += sizeof (foo); + + /* Now, _execserver_bss_size */ + n.n_un.n_strx += 50; + write (newdoto, &n, sizeof (n)); + n.n_value += sizeof (foo); + + /* Now, _execserver_text */ + n.n_un.n_strx += 50; + write (newdoto, &n, sizeof (n)); + n.n_value += a.a_text + sizeof (struct exec); + + /* Now, _execserver_data */ + n.n_un.n_strx += 50; + write (newdoto, &n, sizeof (n)); + n.n_value += a.a_data; + + /* Now, _execserver_start */ + n.n_un.n_strx += 50; + write (newdoto, &n, sizeof (n)); + n.n_value += sizeof (foo); + + /* Now, we have to write out the string table */ |