byte_access.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2019 Clementine Computing LLC.
  3. *
  4. * This file is part of PopuFare.
  5. *
  6. * PopuFare is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * PopuFare is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #ifndef BYTE_ACCESS_H
  21. #define BYTE_ACCESS_H
  22. /* Conversion routines for accessing
  23. * integers (short, long, long long)
  24. * from a byte array.
  25. *
  26. * The viper (gcc I assume) does not
  27. * allow for non frame aligned access.
  28. * From what I can tell, it clamps
  29. * the address to the nearest frame
  30. * depending on the type you're accessing
  31. * and reads starting from this position.
  32. * This leads to misframed data being
  33. * read if you dereference it from a
  34. * non framed position. I would
  35. * also assume writing has the same problem.
  36. *
  37. * These functions will read or write
  38. * short, long or long long (unsigned)
  39. * integers starting at the pointer location.
  40. *
  41. * Storage is least significant byte first.
  42. * For example:
  43. * _uliw(p, 67305985) would write:
  44. *
  45. * p[0] = 0x01
  46. * p[1] = 0x02
  47. * p[2] = 0x03
  48. * p[3] = 0x04
  49. *
  50. * _uli(p) would return 67305985
  51. *
  52. */
  53. unsigned short int _usi(void *p);
  54. unsigned long int _uli(void *p);
  55. unsigned long long int _ulli(void *p);
  56. void _usiw(void *p, unsigned short int usi);
  57. void _uliw(void *p, unsigned long int uli);
  58. void _ulliw(void *p, unsigned long long int ulli);
  59. #endif