a84336436fd36dc8d9cec0cf0035c6e73ac73cb9
[sbcl.git] / src / runtime / x86-bsd-os.c
1 #include <signal.h>
2 #include "sbcl.h"
3 #include "runtime.h"
4 #include "target-os.h"
5
6 /* KLUDGE: There is strong family resemblance in the signal context
7  * stuff in FreeBSD and OpenBSD, but in detail they're different in
8  * almost every line of code. It would be nice to find some way to
9  * factor out the commonality better; failing that, it might be best
10  * just to split this generic-BSD code into one variant for each BSD.
11  *
12  * KLUDGE II: this split has begun with the addition of the Darwin BSD
13  * flavour, with the cross-architecture complications that this
14  * entails; unfortunately, currently the situation is worse, not
15  * better, than in the above paragraph. */
16
17 #if defined(__FreeBSD__) || defined(__OpenBSD__)
18 int *
19 os_context_register_addr(os_context_t *context, int offset)
20 {
21     switch(offset) {
22     case  0:
23         return CONTEXT_ADDR_FROM_STEM(eax);
24     case  2:
25         return CONTEXT_ADDR_FROM_STEM(ecx);
26     case  4:
27         return CONTEXT_ADDR_FROM_STEM(edx);
28     case  6:
29         return CONTEXT_ADDR_FROM_STEM(ebx);
30     case  8:
31         return CONTEXT_ADDR_FROM_STEM(esp);
32     case 10:
33         return CONTEXT_ADDR_FROM_STEM(ebp);
34     case 12:
35         return CONTEXT_ADDR_FROM_STEM(esi);
36     case 14:
37         return CONTEXT_ADDR_FROM_STEM(edi);
38     default:
39         return 0;
40     }
41 }
42
43 int *
44 os_context_sp_addr(os_context_t *context)
45 {
46     return CONTEXT_ADDR_FROM_STEM(esp);
47 }
48
49 #endif /* __FreeBSD__ || __OpenBSD__ */
50
51 #ifdef __NetBSD__
52 int *
53 os_context_register_addr(os_context_t *context, int offset)
54 {
55     switch(offset) {
56     case  0:
57         return CONTEXT_ADDR_FROM_STEM(EAX);
58     case  2:
59         return CONTEXT_ADDR_FROM_STEM(ECX);
60     case  4:
61         return CONTEXT_ADDR_FROM_STEM(EDX);
62     case  6:
63         return CONTEXT_ADDR_FROM_STEM(EBX);
64     case  8:
65         return CONTEXT_ADDR_FROM_STEM(ESP);
66     case 10:
67         return CONTEXT_ADDR_FROM_STEM(EBP);
68     case 12:
69         return CONTEXT_ADDR_FROM_STEM(ESI);
70     case 14:
71         return CONTEXT_ADDR_FROM_STEM(EDI);
72     case 16:
73         return CONTEXT_ADDR_FROM_STEM(UESP);
74     default:
75         return 0;
76     }
77 }
78
79 int *
80 os_context_sp_addr(os_context_t *context)
81 {
82     return &(_UC_MACHINE_SP(context));
83 }
84
85 #endif  /* __NetBSD__ */
86
87
88
89 /* FIXME: If this can be a no-op on BSD/x86, then it
90  * deserves a more precise name.
91  *
92  * (Perhaps os_prepare_data_area_to_be_executed()?) */
93 void
94 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
95 {
96 }