[tcp] Allow out-of-order receive queue to be discarded
[gpxe.git] / src / arch / i386 / core / wince_loader.c
blobf452b659b8af31548458aac9ac2c139e5d1c8767
1 #define LOAD_DEBUG 0
3 static int get_x_header(unsigned char *data, unsigned long now);
4 static void jump_2ep();
5 static unsigned char ce_signature[] = {'B', '0', '0', '0', 'F', 'F', '\n',};
6 static char ** ep;
8 #define BOOT_ARG_PTR_LOCATION 0x001FFFFC
10 typedef struct _BOOT_ARGS{
11 unsigned char ucVideoMode;
12 unsigned char ucComPort;
13 unsigned char ucBaudDivisor;
14 unsigned char ucPCIConfigType;
16 unsigned long dwSig;
17 #define BOOTARG_SIG 0x544F4F42
18 unsigned long dwLen;
20 unsigned char ucLoaderFlags;
21 unsigned char ucEshellFlags;
22 unsigned char ucEdbgAdapterType;
23 unsigned char ucEdbgIRQ;
25 unsigned long dwEdbgBaseAddr;
26 unsigned long dwEdbgDebugZone;
27 unsigned long dwDHCPLeaseTime;
28 unsigned long dwEdbgFlags;
30 unsigned long dwEBootFlag;
31 unsigned long dwEBootAddr;
32 unsigned long dwLaunchAddr;
34 unsigned long pvFlatFrameBuffer;
35 unsigned short vesaMode;
36 unsigned short cxDisplayScreen;
37 unsigned short cyDisplayScreen;
38 unsigned short cxPhysicalScreen;
39 unsigned short cyPhysicalScreen;
40 unsigned short cbScanLineLength;
41 unsigned short bppScreen;
43 unsigned char RedMaskSize;
44 unsigned char REdMaskPosition;
45 unsigned char GreenMaskSize;
46 unsigned char GreenMaskPosition;
47 unsigned char BlueMaskSize;
48 unsigned char BlueMaskPosition;
49 } BOOT_ARGS;
51 BOOT_ARGS BootArgs;
53 static struct segment_info{
54 unsigned long addr; // Section Address
55 unsigned long size; // Section Size
56 unsigned long checksum; // Section CheckSum
57 } X;
59 #define PSIZE (1500) //Max Packet Size
60 #define DSIZE (PSIZE+12)
61 static unsigned long dbuffer_available =0;
62 static unsigned long not_loadin =0;
63 static unsigned long d_now =0;
65 unsigned long entry;
66 static unsigned long ce_curaddr;
69 static sector_t ce_loader(unsigned char *data, unsigned int len, int eof);
70 static os_download_t wince_probe(unsigned char *data, unsigned int len)
72 if (strncmp(ce_signature, data, sizeof(ce_signature)) != 0) {
73 return 0;
75 printf("(WINCE)");
76 return ce_loader;
79 static sector_t ce_loader(unsigned char *data, unsigned int len, int eof)
81 static unsigned char dbuffer[DSIZE];
82 int this_write = 0;
83 static int firsttime = 1;
86 * new packet in, we have to
87 * [1] copy data to dbuffer,
89 * update...
90 * [2] dbuffer_available
92 memcpy( (dbuffer+dbuffer_available), data, len); //[1]
93 dbuffer_available += len; // [2]
94 len = 0;
96 d_now = 0;
98 #if 0
99 printf("dbuffer_available =%ld \n", dbuffer_available);
100 #endif
102 if (firsttime)
104 d_now = sizeof(ce_signature);
105 printf("String Physical Address = %lx \n",
106 *(unsigned long *)(dbuffer+d_now));
108 d_now += sizeof(unsigned long);
109 printf("Image Size = %ld [%lx]\n",
110 *(unsigned long *)(dbuffer+d_now),
111 *(unsigned long *)(dbuffer+d_now));
113 d_now += sizeof(unsigned long);
114 dbuffer_available -= d_now;
116 d_now = (unsigned long)get_x_header(dbuffer, d_now);
117 firsttime = 0;
120 if (not_loadin == 0)
122 d_now = get_x_header(dbuffer, d_now);
125 while ( not_loadin > 0 )
127 /* dbuffer do not have enough data to loading, copy all */
128 #if LOAD_DEBUG
129 printf("[0] not_loadin = [%ld], dbuffer_available = [%ld] \n",
130 not_loadin, dbuffer_available);
131 printf("[0] d_now = [%ld] \n", d_now);
132 #endif
134 if( dbuffer_available <= not_loadin)
136 this_write = dbuffer_available ;
137 memcpy(phys_to_virt(ce_curaddr), (dbuffer+d_now), this_write );
138 ce_curaddr += this_write;
139 not_loadin -= this_write;
141 /* reset index and available in the dbuffer */
142 dbuffer_available = 0;
143 d_now = 0;
144 #if LOAD_DEBUG
145 printf("[1] not_loadin = [%ld], dbuffer_available = [%ld] \n",
146 not_loadin, dbuffer_available);
147 printf("[1] d_now = [%ld], this_write = [%d] \n",
148 d_now, this_write);
149 #endif
151 // get the next packet...
152 return (0);
155 /* dbuffer have more data then loading ... , copy partital.... */
156 else
158 this_write = not_loadin;
159 memcpy(phys_to_virt(ce_curaddr), (dbuffer+d_now), this_write);
160 ce_curaddr += this_write;
161 not_loadin = 0;
163 /* reset index and available in the dbuffer */
164 dbuffer_available -= this_write;
165 d_now += this_write;
166 #if LOAD_DEBUG
167 printf("[2] not_loadin = [%ld], dbuffer_available = [%ld] \n",
168 not_loadin, dbuffer_available);
169 printf("[2] d_now = [%ld], this_write = [%d] \n\n",
170 d_now, this_write);
171 #endif
173 /* dbuffer not empty, proceed processing... */
175 // don't have enough data to get_x_header..
176 if ( dbuffer_available < (sizeof(unsigned long) * 3) )
178 // printf("we don't have enough data remaining to call get_x. \n");
179 memcpy( (dbuffer+0), (dbuffer+d_now), dbuffer_available);
180 return (0);
182 else
184 #if LOAD_DEBUG
185 printf("with remaining data to call get_x \n");
186 printf("dbuffer available = %ld , d_now = %ld\n",
187 dbuffer_available, d_now);
188 #endif
189 d_now = get_x_header(dbuffer, d_now);
193 return (0);
196 static int get_x_header(unsigned char *dbuffer, unsigned long now)
198 X.addr = *(unsigned long *)(dbuffer + now);
199 X.size = *(unsigned long *)(dbuffer + now + sizeof(unsigned long));
200 X.checksum = *(unsigned long *)(dbuffer + now + sizeof(unsigned long)*2);
202 if (X.addr == 0)
204 entry = X.size;
205 done(1);
206 printf("Entry Point Address = [%lx] \n", entry);
207 jump_2ep();
210 if (!prep_segment(X.addr, X.addr + X.size, X.addr + X.size, 0, 0)) {
211 longjmp(restart_etherboot, -2);
214 ce_curaddr = X.addr;
215 now += sizeof(unsigned long)*3;
217 /* re-calculate dbuffer available... */
218 dbuffer_available -= sizeof(unsigned long)*3;
220 /* reset index of this section */
221 not_loadin = X.size;
223 #if 1
224 printf("\n");
225 printf("\t Section Address = [%lx] \n", X.addr);
226 printf("\t Size = %d [%lx]\n", X.size, X.size);
227 printf("\t Checksum = %ld [%lx]\n", X.checksum, X.checksum);
228 #endif
229 #if LOAD_DEBUG
230 printf("____________________________________________\n");
231 printf("\t dbuffer_now = %ld \n", now);
232 printf("\t dbuffer available = %ld \n", dbuffer_available);
233 printf("\t not_loadin = %ld \n", not_loadin);
234 #endif
236 return now;
239 static void jump_2ep()
241 BootArgs.ucVideoMode = 1;
242 BootArgs.ucComPort = 1;
243 BootArgs.ucBaudDivisor = 1;
244 BootArgs.ucPCIConfigType = 1; // do not fill with 0
246 BootArgs.dwSig = BOOTARG_SIG;
247 BootArgs.dwLen = sizeof(BootArgs);
249 if(BootArgs.ucVideoMode == 0)
251 BootArgs.cxDisplayScreen = 640;
252 BootArgs.cyDisplayScreen = 480;
253 BootArgs.cxPhysicalScreen = 640;
254 BootArgs.cyPhysicalScreen = 480;
255 BootArgs.bppScreen = 16;
256 BootArgs.cbScanLineLength = 1024;
257 BootArgs.pvFlatFrameBuffer = 0x800a0000; // ollie say 0x98000000
259 else if(BootArgs.ucVideoMode != 0xFF)
261 BootArgs.cxDisplayScreen = 0;
262 BootArgs.cyDisplayScreen = 0;
263 BootArgs.cxPhysicalScreen = 0;
264 BootArgs.cyPhysicalScreen = 0;
265 BootArgs.bppScreen = 0;
266 BootArgs.cbScanLineLength = 0;
267 BootArgs.pvFlatFrameBuffer = 0;
270 ep = phys_to_virt(BOOT_ARG_PTR_LOCATION);
271 *ep= virt_to_phys(&BootArgs);
272 xstart32(entry);