Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / ppc-all / prep / preplink.c
blobf9755dc1d0ddf8bfc984599c92078b4ce71fec6b
1 /*
2 preplink.c - description
3 $Id$
4 */
6 /*
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your opinion) any later version.
13 #include <stdio.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <fcntl.h>
17 #include <string.h>
19 volatile int bswap(int num)
21 int ret = (((num & 0x000000ff) << 24) |
22 ((num & 0x0000ff00) << 8 ) |
23 ((num & 0x00ff0000) >> 8 ) |
24 ((num & 0xff000000) >> 24));
25 return ret;
28 struct partition_entry {
29 unsigned char boot_indicator;
30 unsigned char starting_head;
31 unsigned char starting_sector;
32 unsigned char starting_cylinder;
34 unsigned char system_indicator;
35 unsigned char ending_head;
36 unsigned char ending_sector;
37 unsigned char ending_cylinder;
39 unsigned long beginning_sector;
40 unsigned long number_of_sectors;
43 int main(int argc, char *argv[])
45 unsigned char buff[512]={0,};
46 struct partition_entry *pe = (struct partition_entry *)&buff[0x1be];
47 unsigned long *entry = (unsigned long*)&buff[0];
48 unsigned long *length = (unsigned long*)&buff[sizeof(long)];
49 struct stat info;
50 int n;
52 int in,out;
54 if (!strcmp(argv[1],"-"))
56 in=0;
58 else if ((in=open(argv[1], 0)) < 0)
60 exit(-1);
63 if (!strcmp(argv[2],"-"))
65 out=0;
67 else if ((out=creat(argv[2], 0755)) < 0)
69 exit(-1);
72 if (fstat(in, &info) < 0)
74 fprintf(stderr, "info failed\n");
75 exit(-1);
78 #ifdef __i386__
79 *entry = 0x400;
80 *length = info.st_size + 0x400;
81 pe->number_of_sectors = 2*18*80;
82 #else
83 *entry = bswap(0x400);
84 *length = bswap(info.st_size + 0x400);
85 pe->number_of_sectors = bswap(2*18*80);
86 #endif
88 buff[510] = 0x55;
89 buff[511] = 0xaa;
91 pe->boot_indicator = 0x80;
92 pe->system_indicator = 0x41;
95 pe->starting_head = 0;
96 pe->starting_sector = 2;
97 pe->starting_cylinder = 2;
98 pe->ending_head = 1;
99 pe->ending_sector = 18;
100 pe->ending_cylinder = 79;
102 pe->beginning_sector = 0;
104 write(out, buff, sizeof(buff));
105 write(out, entry, sizeof(*entry));
106 write(out, length, sizeof(*length));
107 lseek(out, 0x400, SEEK_SET);
109 while ((n=read(in, buff, sizeof(buff))) > 0)
110 write(out, buff, n);
112 return 0;