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