Commit 03c1847584dad4c766bea465c4febcf5892f31d9

Authored by bellard
1 parent 67e999be

endianness fixes


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2144 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 157 additions and 96 deletions
hw/pcnet.c
... ... @@ -253,147 +253,208 @@ struct pcnet_RMD {
253 253 (R)->rmd2.rcc, (R)->rmd2.rpc, (R)->rmd2.mcnt, \
254 254 (R)->rmd2.zeros)
255 255  
256   -static inline void pcnet_tmd_load(PCNetState *s, struct pcnet_TMD *tmd, target_phys_addr_t addr)
  256 +static inline void pcnet_tmd_load(PCNetState *s, struct pcnet_TMD *tmd1,
  257 + target_phys_addr_t addr)
257 258 {
  259 + uint32_t *tmd = (uint32_t *)tmd1;
  260 +
258 261 if (!BCR_SWSTYLE(s)) {
259 262 uint16_t xda[4];
260 263 s->phys_mem_read(s->dma_opaque, addr,
261 264 (void *)&xda[0], sizeof(xda));
262 265 if (CSR_BIGENDIAN(s)) {
263   - ((uint32_t *)tmd)[0] = be16_to_cpu(xda[0]) |
264   - ((be16_to_cpu(xda[1]) & 0x00ff) << 16);
265   - ((uint32_t *)tmd)[1] = be16_to_cpu(xda[2]) |
266   - ((be16_to_cpu(xda[1]) & 0xff00) << 16);
267   - ((uint32_t *)tmd)[2] =
268   - (be16_to_cpu(xda[3]) & 0xffff) << 16;
269   - ((uint32_t *)tmd)[3] = 0;
  266 + be16_to_cpus(&xda[0]);
  267 + be16_to_cpus(&xda[1]);
  268 + be16_to_cpus(&xda[2]);
  269 + be16_to_cpus(&xda[3]);
270 270 } else {
271   - ((uint32_t *)tmd)[0] = (xda[0]&0xffff) |
272   - ((xda[1]&0x00ff) << 16);
273   - ((uint32_t *)tmd)[1] = (xda[2]&0xffff)|
274   - ((xda[1] & 0xff00) << 16);
275   - ((uint32_t *)tmd)[2] =
276   - (xda[3] & 0xffff) << 16;
277   - ((uint32_t *)tmd)[3] = 0;
  271 + le16_to_cpus(&xda[0]);
  272 + le16_to_cpus(&xda[1]);
  273 + le16_to_cpus(&xda[2]);
  274 + le16_to_cpus(&xda[3]);
278 275 }
279   - }
280   - else
281   - if (BCR_SWSTYLE(s) != 3)
282   - s->phys_mem_read(s->dma_opaque, addr, (void *)tmd, 16);
283   - else {
  276 +
  277 + tmd[0] = (xda[0]&0xffff) |
  278 + ((xda[1]&0x00ff) << 16);
  279 + tmd[1] = (xda[2]&0xffff)|
  280 + ((xda[1] & 0xff00) << 16);
  281 + tmd[2] =
  282 + (xda[3] & 0xffff) << 16;
  283 + tmd[3] = 0;
  284 + } else {
284 285 uint32_t xda[4];
285 286 s->phys_mem_read(s->dma_opaque, addr,
286 287 (void *)&xda[0], sizeof(xda));
287   - ((uint32_t *)tmd)[0] = xda[2];
288   - ((uint32_t *)tmd)[1] = xda[1];
289   - ((uint32_t *)tmd)[2] = xda[0];
290   - ((uint32_t *)tmd)[3] = xda[3];
  288 + if (CSR_BIGENDIAN(s)) {
  289 + be32_to_cpus(&xda[0]);
  290 + be32_to_cpus(&xda[1]);
  291 + be32_to_cpus(&xda[2]);
  292 + be32_to_cpus(&xda[3]);
  293 + } else {
  294 + le32_to_cpus(&xda[0]);
  295 + le32_to_cpus(&xda[1]);
  296 + le32_to_cpus(&xda[2]);
  297 + le32_to_cpus(&xda[3]);
  298 + }
  299 + if (BCR_SWSTYLE(s) != 3) {
  300 + memcpy(tmd, xda, sizeof(xda));
  301 + } else {
  302 + tmd[0] = xda[2];
  303 + tmd[1] = xda[1];
  304 + tmd[2] = xda[0];
  305 + tmd[3] = xda[3];
  306 + }
291 307 }
292 308 }
293 309  
294   -static inline void pcnet_tmd_store(PCNetState *s, struct pcnet_TMD *tmd, target_phys_addr_t addr)
  310 +static inline void pcnet_tmd_store(PCNetState *s, const struct pcnet_TMD *tmd1,
  311 + target_phys_addr_t addr)
295 312 {
  313 + const uint32_t *tmd = (const uint32_t *)tmd1;
296 314 if (!BCR_SWSTYLE(s)) {
297 315 uint16_t xda[4];
  316 + xda[0] = tmd[0] & 0xffff;
  317 + xda[1] = ((tmd[0]>>16)&0x00ff) |
  318 + ((tmd[1]>>16)&0xff00);
  319 + xda[2] = tmd[1] & 0xffff;
  320 + xda[3] = tmd[2] >> 16;
298 321 if (CSR_BIGENDIAN(s)) {
299   - xda[0] = cpu_to_be16(((uint32_t *)tmd)[0] & 0xffff);
300   - xda[1] = cpu_to_be16(((((uint32_t *)tmd)[0] >> 16) & 0x00ff) |
301   - ((((uint32_t *)tmd)[1] >> 16) & 0xff00));
302   - xda[2] = cpu_to_be16(((uint32_t *)tmd)[1] & 0xffff);
303   - xda[3] = cpu_to_be16(((uint32_t *)tmd)[2] >> 16);
  322 + cpu_to_be16s(&xda[0]);
  323 + cpu_to_be16s(&xda[1]);
  324 + cpu_to_be16s(&xda[2]);
  325 + cpu_to_be16s(&xda[3]);
304 326 } else {
305   - xda[0] = ((uint32_t *)tmd)[0] & 0xffff;
306   - xda[1] = ((((uint32_t *)tmd)[0]>>16)&0x00ff) |
307   - ((((uint32_t *)tmd)[1]>>16)&0xff00);
308   - xda[2] = ((uint32_t *)tmd)[1] & 0xffff;
309   - xda[3] = ((uint32_t *)tmd)[2] >> 16;
  327 + cpu_to_le16s(&xda[0]);
  328 + cpu_to_le16s(&xda[1]);
  329 + cpu_to_le16s(&xda[2]);
  330 + cpu_to_le16s(&xda[3]);
310 331 }
311 332 s->phys_mem_write(s->dma_opaque, addr,
312 333 (void *)&xda[0], sizeof(xda));
313   - }
314   - else {
315   - if (BCR_SWSTYLE(s) != 3)
316   - s->phys_mem_write(s->dma_opaque, addr, (void *)tmd, 16);
317   - else {
318   - uint32_t xda[4];
319   - xda[0] = ((uint32_t *)tmd)[2];
320   - xda[1] = ((uint32_t *)tmd)[1];
321   - xda[2] = ((uint32_t *)tmd)[0];
322   - xda[3] = ((uint32_t *)tmd)[3];
323   - s->phys_mem_write(s->dma_opaque, addr,
324   - (void *)&xda[0], sizeof(xda));
  334 + } else {
  335 + uint32_t xda[4];
  336 + if (BCR_SWSTYLE(s) != 3) {
  337 + memcpy(xda, tmd, sizeof(xda));
  338 + } else {
  339 + xda[0] = tmd[2];
  340 + xda[1] = tmd[1];
  341 + xda[2] = tmd[0];
  342 + xda[3] = tmd[3];
325 343 }
  344 + if (CSR_BIGENDIAN(s)) {
  345 + cpu_to_be32s(&xda[0]);
  346 + cpu_to_be32s(&xda[1]);
  347 + cpu_to_be32s(&xda[2]);
  348 + cpu_to_be32s(&xda[3]);
  349 + } else {
  350 + cpu_to_le32s(&xda[0]);
  351 + cpu_to_le32s(&xda[1]);
  352 + cpu_to_le32s(&xda[2]);
  353 + cpu_to_le32s(&xda[3]);
  354 + }
  355 + s->phys_mem_write(s->dma_opaque, addr,
  356 + (void *)&xda[0], sizeof(xda));
326 357 }
327 358 }
328 359  
329   -static inline void pcnet_rmd_load(PCNetState *s, struct pcnet_RMD *rmd, target_phys_addr_t addr)
  360 +static inline void pcnet_rmd_load(PCNetState *s, struct pcnet_RMD *rmd1,
  361 + target_phys_addr_t addr)
330 362 {
  363 + uint32_t *rmd = (uint32_t *)rmd1;
  364 +
331 365 if (!BCR_SWSTYLE(s)) {
332 366 uint16_t rda[4];
333   - s->phys_mem_read(s->dma_opaque, addr,
334   - (void *)&rda[0], sizeof(rda));
  367 + s->phys_mem_read(s->dma_opaque, addr, (void *)&rda[0], sizeof(rda));
335 368 if (CSR_BIGENDIAN(s)) {
336   - ((uint32_t *)rmd)[0] = (be16_to_cpu(rda[0]) & 0xffff) |
337   - ((be16_to_cpu(rda[1]) & 0x00ff) << 16);
338   - ((uint32_t *)rmd)[1] = (be16_to_cpu(rda[2]) & 0xffff) |
339   - ((be16_to_cpu(rda[1]) & 0xff00) << 16);
340   - ((uint32_t *)rmd)[2] = be16_to_cpu(rda[3]) & 0xffff;
341   - ((uint32_t *)rmd)[3] = 0;
  369 + be16_to_cpus(&rda[0]);
  370 + be16_to_cpus(&rda[1]);
  371 + be16_to_cpus(&rda[2]);
  372 + be16_to_cpus(&rda[3]);
342 373 } else {
343   - ((uint32_t *)rmd)[0] = (rda[0]&0xffff)|
344   - ((rda[1] & 0x00ff) << 16);
345   - ((uint32_t *)rmd)[1] = (rda[2]&0xffff)|
346   - ((rda[1] & 0xff00) << 16);
347   - ((uint32_t *)rmd)[2] = rda[3] & 0xffff;
348   - ((uint32_t *)rmd)[3] = 0;
  374 + le16_to_cpus(&rda[0]);
  375 + le16_to_cpus(&rda[1]);
  376 + le16_to_cpus(&rda[2]);
  377 + le16_to_cpus(&rda[3]);
349 378 }
350   - }
351   - else
352   - if (BCR_SWSTYLE(s) != 3)
353   - s->phys_mem_read(s->dma_opaque, addr, (void *)rmd, 16);
354   - else {
  379 + rmd[0] = (rda[0]&0xffff)|
  380 + ((rda[1] & 0x00ff) << 16);
  381 + rmd[1] = (rda[2]&0xffff)|
  382 + ((rda[1] & 0xff00) << 16);
  383 + rmd[2] = rda[3] & 0xffff;
  384 + rmd[3] = 0;
  385 + } else {
355 386 uint32_t rda[4];
356   - s->phys_mem_read(s->dma_opaque, addr,
357   - (void *)&rda[0], sizeof(rda));
358   - ((uint32_t *)rmd)[0] = rda[2];
359   - ((uint32_t *)rmd)[1] = rda[1];
360   - ((uint32_t *)rmd)[2] = rda[0];
361   - ((uint32_t *)rmd)[3] = rda[3];
  387 + s->phys_mem_read(s->dma_opaque, addr, (void *)&rda[0], sizeof(rda));
  388 + if (CSR_BIGENDIAN(s)) {
  389 + be32_to_cpus(&rda[0]);
  390 + be32_to_cpus(&rda[1]);
  391 + be32_to_cpus(&rda[2]);
  392 + be32_to_cpus(&rda[3]);
  393 + } else {
  394 + le32_to_cpus(&rda[0]);
  395 + le32_to_cpus(&rda[1]);
  396 + le32_to_cpus(&rda[2]);
  397 + le32_to_cpus(&rda[3]);
  398 + }
  399 + if (BCR_SWSTYLE(s) != 3) {
  400 + memcpy(rmd, rda, sizeof(rda));
  401 + } else {
  402 + rmd[0] = rda[2];
  403 + rmd[1] = rda[1];
  404 + rmd[2] = rda[0];
  405 + rmd[3] = rda[3];
  406 + }
362 407 }
363 408 }
364 409  
365   -static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd, target_phys_addr_t addr)
  410 +static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd1,
  411 + target_phys_addr_t addr)
366 412 {
  413 + const uint32_t *rmd = (const uint32_t *)rmd1;
  414 +
367 415 if (!BCR_SWSTYLE(s)) {
368 416 uint16_t rda[4];
  417 + rda[0] = rmd[0] & 0xffff;
  418 + rda[1] = ((rmd[0]>>16)&0xff)|
  419 + ((rmd[1]>>16)&0xff00);
  420 + rda[2] = rmd[1] & 0xffff;
  421 + rda[3] = rmd[2] & 0xffff;
369 422 if (CSR_BIGENDIAN(s)) {
370   - rda[0] = cpu_to_be16(((uint32_t *)rmd)[0] & 0xffff);
371   - rda[1] = cpu_to_be16(((((uint32_t *)rmd)[0] >> 16) & 0xff) |
372   - ((((uint32_t *)rmd)[1] >> 16) & 0xff00));
373   - rda[2] = cpu_to_be16(((uint32_t *)rmd)[1] & 0xffff);
374   - rda[3] = cpu_to_be16(((uint32_t *)rmd)[2] & 0xffff);
  423 + cpu_to_be16s(&rda[0]);
  424 + cpu_to_be16s(&rda[1]);
  425 + cpu_to_be16s(&rda[2]);
  426 + cpu_to_be16s(&rda[3]);
375 427 } else {
376   - rda[0] = ((uint32_t *)rmd)[0] & 0xffff;
377   - rda[1] = ((((uint32_t *)rmd)[0]>>16)&0xff)|
378   - ((((uint32_t *)rmd)[1]>>16)&0xff00);
379   - rda[2] = ((uint32_t *)rmd)[1] & 0xffff;
380   - rda[3] = ((uint32_t *)rmd)[2] & 0xffff;
  428 + cpu_to_le16s(&rda[0]);
  429 + cpu_to_le16s(&rda[1]);
  430 + cpu_to_le16s(&rda[2]);
  431 + cpu_to_le16s(&rda[3]);
381 432 }
382 433 s->phys_mem_write(s->dma_opaque, addr,
383 434 (void *)&rda[0], sizeof(rda));
384   - }
385   - else {
386   - if (BCR_SWSTYLE(s) != 3)
387   - s->phys_mem_write(s->dma_opaque, addr, (void *)rmd, 16);
388   - else {
389   - uint32_t rda[4];
390   - rda[0] = ((uint32_t *)rmd)[2];
391   - rda[1] = ((uint32_t *)rmd)[1];
392   - rda[2] = ((uint32_t *)rmd)[0];
393   - rda[3] = ((uint32_t *)rmd)[3];
394   - s->phys_mem_write(s->dma_opaque, addr,
395   - (void *)&rda[0], sizeof(rda));
  435 + } else {
  436 + uint32_t rda[4];
  437 + if (BCR_SWSTYLE(s) != 3) {
  438 + memcpy(rda, rmd, sizeof(rda));
  439 + } else {
  440 + rda[0] = rmd[2];
  441 + rda[1] = rmd[1];
  442 + rda[2] = rmd[0];
  443 + rda[3] = rmd[3];
396 444 }
  445 + if (CSR_BIGENDIAN(s)) {
  446 + cpu_to_be32s(&rda[0]);
  447 + cpu_to_be32s(&rda[1]);
  448 + cpu_to_be32s(&rda[2]);
  449 + cpu_to_be32s(&rda[3]);
  450 + } else {
  451 + cpu_to_le32s(&rda[0]);
  452 + cpu_to_le32s(&rda[1]);
  453 + cpu_to_le32s(&rda[2]);
  454 + cpu_to_le32s(&rda[3]);
  455 + }
  456 + s->phys_mem_write(s->dma_opaque, addr,
  457 + (void *)&rda[0], sizeof(rda));
397 458 }
398 459 }
399 460  
... ...