+++ /dev/null
-------------------------------------------------------------------------------\r
--- ------------------ M a R T E O S ------------------- --\r
-------------------------------------------------------------------------------\r
--- {MARTE_VERSION}\r
---\r
--- 'C o n t e x t'\r
---\r
--- Body\r
---\r
--- File 'context.adb' By MAR\r
---\r
--- Processor context for non-local jumps\r
---\r
--- IMPORTANT: it must be compiled without any optimization!!\r
---\r
--- {MARTE_COPYRIGHT}\r
---\r
-------------------------------------------------------------------------------\r
--- {<MAR}\r
---\r
--- 02-08-07:version operativa.\r
---\r
--- {MAR>} -------------------------------------------------------------------\r
-with Text_IO; use Text_IO;\r
-with Marte.Integer_Types;\r
-with Non_Local_Jump;\r
-with System;\r
-\r
-use type Marte.Integer_Types.Unsigned_32;\r
-\r
-package body Context is\r
-\r
- Jmp_Buff : aliased Non_Local_Jump.Jmp_Context;\r
- pragma Volatile (Jmp_Buff);\r
-\r
- TCB : System.Address := System.Null_Address;\r
- pragma Volatile (TCB);\r
-\r
- function Pthread_Self return System.Address;\r
- pragma Import (C, Pthread_Self, "pthread_self");\r
-\r
- function Execute_Work(Work : Work_Acc) return Integer is\r
- begin\r
- Put_Line ("Start work");\r
- TCB := Pthread_Self;\r
- Non_Local_Jump.Save_Context(Jmp_Buff'Access);\r
- if Non_Local_Jump.After_Jump (Jmp_Buff'Access) = 0 then\r
- Put_Line ("---Not After Jump---");\r
- Work.all;\r
- return 0;\r
- else\r
- Put_Line ("---After Jump---");\r
- return 1;\r
- end if;\r
- end Execute_Work;\r
-\r
- procedure Restore_Work is\r
- begin\r
- Non_Local_Jump.Restore_Context (TCB, Jmp_Buff'Access);\r
- end Restore_Work;\r
-\r
-end Context;\r
+++ /dev/null
-------------------------------------------------------------------------------\r
--- ------------------ M a R T E O S ------------------- --\r
-------------------------------------------------------------------------------\r
--- {MARTE_VERSION}\r
---\r
--- 'C o n t e x t'\r
---\r
--- Spec\r
---\r
--- File 'context.ads' By MAR\r
---\r
--- Processor context for non-local jumps\r
---\r
--- IMPORTANT: it must be compiled without any optimization!!\r
---\r
--- {MARTE_COPYRIGHT}\r
---\r
-------------------------------------------------------------------------------\r
--- {<MAR}\r
---\r
--- 02-08-07:version operativa.\r
---\r
--- {MAR>} -------------------------------------------------------------------\r
-package Context is\r
-\r
- type Work_Acc is access procedure;\r
- pragma Convention (C, Work_Acc);\r
-\r
- function Execute_Work(Work : Work_Acc) return Integer;\r
- pragma export(C,Execute_Work, "execute_work");\r
-\r
- procedure Restore_Work;\r
- pragma export(C,Restore_Work, "restore_work");\r
-\r
-end Context;\r
+++ /dev/null
-------------------------------------------------------------------------------\r
--- ------------------ M a R T E O S ------------------- --\r
-------------------------------------------------------------------------------\r
--- {MARTE_VERSION}\r
---\r
--- 'N o n _ L o c a l _ J u m p'\r
---\r
--- Spec\r
---\r
--- File 'non_local_jump.ads' By MAR\r
---\r
--- Non-local jumps for preempted tasks.\r
---\r
--- IMPORTANT: it must be compiled without any optimization!!\r
---\r
--- {MARTE_COPYRIGHT}\r
---\r
-------------------------------------------------------------------------------\r
--- {<MAR}\r
---\r
--- 02-08-07:version operativa.\r
---\r
--- {MAR>} -------------------------------------------------------------------\r
-pragma Task_Dispatching_Policy (FIFO_Within_Priorities);\r
-with Text_IO; use Text_IO;\r
-with Ada.Unchecked_Conversion;\r
-with System;\r
-with Marte.Integer_Types; use Marte.Integer_Types;\r
-with Marte.HAL.Processor_Registers;\r
-with Non_Local_Jump;\r
-with System.Machine_Code; use System.Machine_Code;\r
-with Execution_Load;\r
-\r
-procedure Non_Local_Jump_Test is\r
-\r
- --pragma Linker_Options("eat_20.o");\r
-\r
- --procedure Eat_20;\r
- --pragma Import (C, Eat_20, "eat_20");\r
-\r
- pragma Priority (10);\r
-\r
- -- package PR renames Processor_Registers;\r
- package PR renames Non_Local_Jump;\r
-\r
- Cont : Integer := 0;\r
- pragma Volatile (Cont);\r
-\r
- TCB : System.Address := System.Null_Address;\r
- pragma Volatile (TCB);\r
-\r
- function Pthread_Self return System.Address;\r
- pragma Import (C, Pthread_Self, "pthread_self");\r
-\r
- Jmp_Buff : aliased PR.Jmp_Context;\r
- pragma Volatile (Jmp_Buff);\r
-\r
- procedure Por_Fastidiar2 (C : Integer) is\r
- begin\r
- loop\r
-\r
- Put_Line (Integer'Image (C));\r
- Execution_Load.Eat (20.0);\r
- --for I in 1 .. 20_000_000 loop\r
- -- null;\r
- --end loop;\r
- end loop;\r
- end Por_Fastidiar2;\r
-\r
- procedure Por_Fastidiar1 (C : Integer) is\r
- begin\r
- Por_Fastidiar2 (C);\r
- end Por_Fastidiar1;\r
-\r
- -- tarea q se cambia su dirección de retorno\r
- task Saltarina is\r
- pragma Priority (5);\r
- end Saltarina;\r
-\r
- task body Saltarina is\r
- begin\r
- Put_Line ("hola2");\r
- TCB := Pthread_Self;\r
- loop\r
- PR.Save_Context(Jmp_Buff'Access);\r
- -- Asm ("int $3", No_Output_Operands, No_Input_Operands, "", True);\r
- if PR.After_Jump (Jmp_Buff'Access) = 1 then\r
- Put_Line ("---After Jump---");\r
- else\r
- Put_Line ("---Not After Jump 1---");\r
- Por_Fastidiar1 (Cont);\r
- Put_Line ("---Not After Jump 2---");\r
- end if;\r
- Cont := Cont + 1;\r
- Put_Line(" Cont:" & Integer'Image (Cont));\r
- end loop;\r
-\r
- exception\r
- when E:others =>\r
- Put_Line ("Exception in Saltarina");\r
- end Saltarina;\r
-\r
-begin\r
- loop\r
- delay 2.0;\r
- exit when Cont >= 5;\r
-\r
- Put_Line ("Antes de cambiar retorno 3");\r
- PR.Restore_Context (TCB, Jmp_Buff'Access);\r
- Put_Line ("Desp de cambiar retorno 3");\r
- --delay 1000000.0;\r
- end loop;\r
- Put_Line (Integer'Image (Jmp_Buff'Size/8));\r
-\r
-end Non_Local_Jump_Test;\r