RPI.Processors.Mod 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. (* Runtime support for Raspberry Pi *)
  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* = 4 + 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. CODE
  37. MOV SP, #0x8000
  38. MRC P15, 0, R0, C0, C0, 5
  39. AND R0, R0, #0x3
  40. SUB SP, SP, R0, LSL #13
  41. END;
  42. CPU.EnableMemoryManagementUnit;
  43. Counters.Inc (running);
  44. SuspendCurrentProcessor;
  45. SuspendCurrentProcessor;
  46. Execute (Idle);
  47. Counters.Dec (running);
  48. CPU.Halt;
  49. END Boot;
  50. (** Initializes the module by enumerating all available processors. *)
  51. (** @topic Runtime Call *)
  52. PROCEDURE Initialize-;
  53. PROCEDURE Boot EXTERN "Processors.Boot";
  54. CONST Core1Mailbox = 04000009CH; Core2Mailbox = 0400000ACH; Core3Mailbox = 0400000BCH;
  55. BEGIN {UNCOOPERATIVE, UNCHECKED}
  56. CPU.WriteWord (Core1Mailbox, ADDRESS OF Boot);
  57. CPU.WriteWord (Core2Mailbox, ADDRESS OF Boot);
  58. CPU.WriteWord (Core3Mailbox, ADDRESS OF Boot);
  59. REPEAT UNTIL Counters.Read (running) = 3;
  60. count := 4;
  61. END Initialize;
  62. (** Terminates the module and waits for all other processors to stop their execution. *)
  63. (** @topic Runtime Call *)
  64. PROCEDURE Terminate-;
  65. BEGIN {UNCOOPERATIVE, UNCHECKED}
  66. REPEAT UNTIL Counters.Read (running) = 0;
  67. END Terminate;
  68. END Processors.