Zynq.Processors.Mod 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. (* Runtime support for Zynq *)
  2. (* Copyright (C) Florian Negele *)
  3. (** The Processors module represents all logical processors of the system. *)
  4. MODULE Processors;
  5. IMPORT SYSTEM, Counters, CPU;
  6. (** Indicates the maximal number of logical processors that are supported by the system. *)
  7. CONST Maximum* = 2 + CPU.Interrupts;
  8. (** Holds the actual number of processors in the system. *)
  9. VAR count-: SIZE;
  10. VAR running: Counters.AlignedCounter; (* counts the number of application processors currently running *)
  11. (** Returns the unique index of the processor executing this procedure call. *)
  12. PROCEDURE GetCurrentIndex- EXTERN "Activities.GetCurrentProcessorIndex" (): SIZE;
  13. (** Suspends the execution of the current processor. *)
  14. (** A suspended processor must be resumed by a call to the Processors.ResumeAnyProcessor procedure. *)
  15. (** @topic Scheduling *)
  16. PROCEDURE SuspendCurrentProcessor-;
  17. CODE
  18. WFE
  19. END SuspendCurrentProcessor;
  20. (** Resumes the execution of a single suspended processor. *)
  21. (** @topic Scheduling *)
  22. PROCEDURE ResumeAllProcessors-;
  23. CODE
  24. SEV
  25. END ResumeAllProcessors;
  26. (** Starts the execution of all available processors. *)
  27. (** @topic Scheduling *)
  28. PROCEDURE StartAll-;
  29. CODE
  30. SEV
  31. END StartAll;
  32. PROCEDURE {NORETURN, NOPAF} Boot;
  33. PROCEDURE Idle EXTERN "Activities.Idle";
  34. PROCEDURE Execute EXTERN "Activities.Execute" (procedure: PROCEDURE);
  35. BEGIN {UNCOOPERATIVE, UNCHECKED}
  36. Counters.Inc (running);
  37. SuspendCurrentProcessor;
  38. SuspendCurrentProcessor;
  39. Execute (Idle);
  40. Counters.Dec (running);
  41. CPU.Halt;
  42. END Boot;
  43. (** Initializes the module by enumerating all available processors. *)
  44. (** @topic Runtime Call *)
  45. PROCEDURE Initialize-;
  46. BEGIN {UNCOOPERATIVE, UNCHECKED}
  47. ResumeAllProcessors;
  48. REPEAT UNTIL Counters.Read (running) = 1;
  49. count := 2;
  50. END Initialize;
  51. (** Terminates the module and waits for all other processors to stop their execution. *)
  52. (** @topic Runtime Call *)
  53. PROCEDURE Terminate-;
  54. BEGIN {UNCOOPERATIVE, UNCHECKED}
  55. REPEAT UNTIL Counters.Read (running) = 0;
  56. END Terminate;
  57. END Processors.