setmach.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 mamd64;
  25. extern Machdata i386mach;
  26. /*
  27. * machine selection table. machines with native disassemblers should
  28. * follow the plan 9 variant in the table; native modes are selectable
  29. * only by name.
  30. */
  31. Machtab machines[] =
  32. {
  33. { "amd64", /*amd64*/
  34. FAMD64,
  35. FAMD64B,
  36. AAMD64,
  37. &mamd64,
  38. &i386mach, },
  39. { 0 }, /*the terminator*/
  40. };
  41. /*
  42. * select a machine by executable file type
  43. */
  44. void
  45. machbytype(int type)
  46. {
  47. Machtab *mp;
  48. for (mp = machines; mp->name; mp++){
  49. if (mp->type == type || mp->boottype == type) {
  50. asstype = mp->asstype;
  51. machdata = mp->machdata;
  52. break;
  53. }
  54. }
  55. }
  56. /*
  57. * select a machine by name
  58. */
  59. int
  60. machbyname(char *name)
  61. {
  62. Machtab *mp;
  63. for (mp = machines; mp->name; mp++){
  64. if (strcmp(mp->name, name) == 0) {
  65. asstype = mp->asstype;
  66. machdata = mp->machdata;
  67. mach = mp->mach;
  68. return 1;
  69. }
  70. }
  71. return 0;
  72. }