]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - marte_non_local_jump/non_local_jump_test.adb
aa88188b3c57dede2f95642a9abc2deccdc4f607
[frescor/fosa.git] / marte_non_local_jump / non_local_jump_test.adb
1 ------------------------------------------------------------------------------\r
2 --  ------------------         M a R T E   O S         -------------------  --\r
3 ------------------------------------------------------------------------------\r
4 --                                                             {MARTE_VERSION}\r
5 --\r
6 --                      'N o n _ L o c a l _ J u m p'\r
7 --\r
8 --                                  Spec\r
9 --\r
10 --  File 'non_local_jump.ads'                                          By MAR\r
11 --\r
12 --  Non-local jumps for preempted tasks.\r
13 --\r
14 --  IMPORTANT: it must be compiled without any optimization!!\r
15 --\r
16 --  {MARTE_COPYRIGHT}\r
17 --\r
18 ------------------------------------------------------------------------------\r
19 --  {<MAR}\r
20 --\r
21 --  02-08-07:version operativa.\r
22 --\r
23 --  {MAR>} -------------------------------------------------------------------\r
24 pragma Task_Dispatching_Policy (FIFO_Within_Priorities);\r
25 with MaRTE_OS;\r
26 with Text_IO; use Text_IO;\r
27 with Ada.Unchecked_Conversion;\r
28 with System;\r
29 with Basic_Integer_Types; use Basic_Integer_Types;\r
30 --  with Processor_Registers;\r
31 with Non_Local_Jump;\r
32 with System.Machine_Code; use System.Machine_Code;\r
33 \r
34 procedure Non_Local_Jump_Test is\r
35 \r
36    pragma Linker_Options("eat_20.o");\r
37 \r
38    procedure Eat_20;\r
39    pragma Import (C, Eat_20, "eat_20");\r
40 \r
41    pragma Priority (10);\r
42 \r
43    --  package PR renames Processor_Registers;\r
44    package PR renames Non_Local_Jump;\r
45 \r
46    Cont : Integer := 0;\r
47    pragma Volatile (Cont);\r
48 \r
49    TCB : System.Address := System.Null_Address;\r
50    pragma Volatile (TCB);\r
51 \r
52    function Pthread_Self return System.Address;\r
53    pragma Import (C, Pthread_Self, "pthread_self");\r
54 \r
55    Jmp_Buff : aliased PR.Jmp_Context;\r
56    pragma Volatile (Jmp_Buff);\r
57 \r
58    procedure Por_Fastidiar2 (C : Integer) is\r
59    begin\r
60       loop\r
61 \r
62          Put_Line (Integer'Image (C));\r
63          Eat_20;\r
64          --for I in 1 .. 20_000_000 loop\r
65          --   null;\r
66          --end loop;\r
67       end loop;\r
68    end Por_Fastidiar2;\r
69 \r
70    procedure Por_Fastidiar1 (C : Integer) is\r
71    begin\r
72       Por_Fastidiar2 (C);\r
73    end Por_Fastidiar1;\r
74 \r
75    --  tarea q se cambia su dirección de retorno\r
76    task Saltarina is\r
77       pragma Priority (5);\r
78    end Saltarina;\r
79 \r
80    task body Saltarina is\r
81    begin\r
82       Put_Line ("hola2");\r
83       TCB := Pthread_Self;\r
84       loop\r
85          PR.Save_Context(Jmp_Buff'Access);\r
86          --  Asm ("int $3", No_Output_Operands, No_Input_Operands, "", True);\r
87          if PR.After_Jump (Jmp_Buff'Access) = 1 then\r
88             Put_Line ("---After Jump---");\r
89          else\r
90             Por_Fastidiar1 (Cont);\r
91             Put_Line ("---Not After Jump---");\r
92          end if;\r
93          Cont := Cont + 1;\r
94          Put_Line(" Cont:" & Integer'Image (Cont));\r
95       end loop;\r
96 \r
97    exception\r
98       when E:others =>\r
99          Put_Line ("Exception in Saltarina");\r
100    end Saltarina;\r
101 \r
102 begin\r
103    loop\r
104       delay 2.0;\r
105       exit when Cont >= 5;\r
106 \r
107       Put_Line ("Antes de cambiar retorno 3");\r
108       PR.Restore_Context (TCB, Jmp_Buff'Access);\r
109       Put_Line ("Desp de cambiar retorno 3");\r
110       --delay 1000000.0;\r
111    end loop;\r
112    Put_Line (Integer'Image (Jmp_Buff'Size/8));\r
113 \r
114 end Non_Local_Jump_Test;\r