]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - marte_non_local_jump/non_local_jump_test.adb
17282cdb33f25e42740dfd6d58c4e59e9e644d62
[frescor/fosa.git] / marte_non_local_jump / non_local_jump_test.adb
1 pragma Task_Dispatching_Policy (FIFO_Within_Priorities);\r
2 with MaRTE_OS;\r
3 with Text_IO; use Text_IO;\r
4 with Ada.Unchecked_Conversion;\r
5 with System;\r
6 with Basic_Integer_Types; use Basic_Integer_Types;\r
7 --  with Processor_Registers;\r
8 with Non_Local_Jump;\r
9 with System.Machine_Code; use System.Machine_Code;\r
10 \r
11 procedure Non_Local_Jump_Test is\r
12 \r
13    pragma Linker_Options("eat_20.o");\r
14 \r
15    procedure Eat_20;\r
16    pragma Import (C, Eat_20, "eat_20");\r
17 \r
18    pragma Priority (10);\r
19 \r
20    --  package PR renames Processor_Registers;\r
21    package PR renames Non_Local_Jump;\r
22 \r
23    Cont : Integer := 0;\r
24    pragma Volatile (Cont);\r
25 \r
26    TCB : System.Address := System.Null_Address;\r
27    pragma Volatile (TCB);\r
28 \r
29    function Pthread_Self return System.Address;\r
30    pragma Import (C, Pthread_Self, "pthread_self");\r
31 \r
32    Jmp_Buff : aliased PR.Jmp_Context;\r
33    pragma Volatile (Jmp_Buff);\r
34 \r
35    procedure Por_Fastidiar2 (C : Integer) is\r
36    begin\r
37       loop\r
38 \r
39          Put_Line (Integer'Image (C));\r
40          Eat_20;\r
41          --for I in 1 .. 20_000_000 loop\r
42          --   null;\r
43          --end loop;\r
44       end loop;\r
45    end Por_Fastidiar2;\r
46 \r
47    procedure Por_Fastidiar1 (C : Integer) is\r
48    begin\r
49       Por_Fastidiar2 (C);\r
50    end Por_Fastidiar1;\r
51 \r
52    --  tarea q se cambia su dirección de retorno\r
53    task Saltarina is\r
54       pragma Priority (5);\r
55    end Saltarina;\r
56 \r
57    task body Saltarina is\r
58    begin\r
59       Put_Line ("hola2");\r
60       TCB := Pthread_Self;\r
61       loop\r
62          PR.Save_Context(Jmp_Buff'Access);\r
63          --  Asm ("int $3", No_Output_Operands, No_Input_Operands, "", True);\r
64          if PR.After_Jump (Jmp_Buff'Access) = 1 then\r
65             Put_Line ("---After Jump---");\r
66          else\r
67             Por_Fastidiar1 (Cont);\r
68             Put_Line ("---Not After Jump---");\r
69          end if;\r
70          Cont := Cont + 1;\r
71          Put_Line(" Cont:" & Integer'Image (Cont));\r
72       end loop;\r
73 \r
74    exception\r
75       when E:others =>\r
76          Put_Line ("Exception in Saltarina");\r
77    end Saltarina;\r
78 \r
79 begin\r
80    loop\r
81       delay 2.0;\r
82       exit when Cont >= 5;\r
83 \r
84       Put_Line ("Antes de cambiar retorno 3");\r
85       PR.Restore_Context (TCB, Jmp_Buff'Access);\r
86       Put_Line ("Desp de cambiar retorno 3");\r
87       --delay 1000000.0;\r
88    end loop;\r
89    Put_Line (Integer'Image (Jmp_Buff'Size/8));\r
90 \r
91 end Non_Local_Jump_Test;\r