setmach.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include <mach.h>
  13. /* table for selecting machine-dependent parameters */
  14. typedef struct machtab Machtab;
  15. struct machtab
  16. {
  17. char *name; /* machine name */
  18. int16_t type; /* executable type */
  19. int16_t boottype; /* bootable type */
  20. int asstype; /* disassembler code */
  21. Mach *mach; /* machine description */
  22. Machdata *machdata; /* machine functions */
  23. };
  24. extern Mach mmips, msparc, m68020, mi386, mamd64,
  25. marm, mmips2be, mmips2le, mpower, mpower64, malpha, msparc64;
  26. extern Machdata mipsmach, mipsmachle, sparcmach, m68020mach, i386mach,
  27. armmach, mipsmach2le, powermach, alphamach, sparc64mach;
  28. /*
  29. * machine selection table. machines with native disassemblers should
  30. * follow the plan 9 variant in the table; native modes are selectable
  31. * only by name.
  32. */
  33. Machtab machines[] =
  34. {
  35. { "amd64", /*amd64*/
  36. FAMD64,
  37. FAMD64B,
  38. AAMD64,
  39. &mamd64,
  40. &i386mach, },
  41. { 0 }, /*the terminator*/
  42. };
  43. /*
  44. * select a machine by executable file type
  45. */
  46. void
  47. machbytype(int type)
  48. {
  49. Machtab *mp;
  50. for (mp = machines; mp->name; mp++){
  51. if (mp->type == type || mp->boottype == type) {
  52. asstype = mp->asstype;
  53. machdata = mp->machdata;
  54. break;
  55. }
  56. }
  57. }
  58. /*
  59. * select a machine by name
  60. */
  61. int
  62. machbyname(char *name)
  63. {
  64. Machtab *mp;
  65. for (mp = machines; mp->name; mp++){
  66. if (strcmp(mp->name, name) == 0) {
  67. asstype = mp->asstype;
  68. machdata = mp->machdata;
  69. mach = mp->mach;
  70. return 1;
  71. }
  72. }
  73. return 0;
  74. }