seperate function for getting the stack pointer. moving towards a platform-specific...
[cake.git] / arch / all-unix / kernel / kernel_intern.h
blobeae3ba12cd6833c8bff1a879fd5bc136ea86207c
1 #ifndef KERNEL_INTERN_H_
2 #define KERNEL_INTERN_H_
4 #include <aros/libcall.h>
5 #include <inttypes.h>
6 #include <exec/lists.h>
7 #include <exec/execbase.h>
8 #include <exec/memory.h>
9 #include <utility/tagitem.h>
10 #include <stdio.h>
11 #include <stdarg.h>
12 #include "hostinterface.h"
13 #include "syscall.h"
15 #define STACK_SIZE 4096
17 /* In Windows-hosted kernel exceptions and IRQs work in the following way:
19 Exceptions are currently not used. They are reserved for implementing CPU
20 exceptions handling (access violation, division by zero, etc).
22 IRQs are used to receive events from emulated hardware. Hardware is mostly
23 emulated using Windows threads running asynchronously to AROS. When the
24 thread finishes its job it calls host-size KrnCauseIRQ() function in order
25 to initiate an IRQ in AROS.
27 Currently number of IRQs are fixed and they are used as following:
28 IRQ 0 - main system periodic timer (50 Hz). Used internally by kernel.resource
29 for task switching and VBlank emulation. Exec uses it as a VBLANK source.
30 In current implementation it can not be caused manually using KernelCauseIRQ().
31 IRQ 1 - Used by emul.handler to serve input from host's console.
32 IRQ 2 - Used by graphics HIDD.
33 IRQ 3 - Used by mouse HIDD.
34 IRQ 4 - Used by keyboard HIDD.
36 In future there can be much more drivers many of which would need an IRQ. In order to manage
37 this i have an idea of implementing dynamic allocation of IRQs in some way.
39 The whole described thing is experimental and subject to change.
42 #define EXCEPTIONS_NUM 1
43 #define INTERRUPTS_NUM 5
45 #define INT_TIMER 0
46 #define INT_IO 1
47 #define INT_GFX 2
48 #define INT_MOUSE 3
49 #define INT_KBD 4
51 struct KernelBase {
52 struct Node kb_Node;
53 void * kb_MemPool;
54 struct List kb_Exceptions[EXCEPTIONS_NUM];
55 struct List kb_Interrupts[INTERRUPTS_NUM];
58 enum intr_types {
59 it_exception = 0xe0,
60 it_interrupt = 0xf0
63 struct IntrNode {
64 struct MinNode in_Node;
65 void (*in_Handler)(void *, void *);
66 void *in_HandlerData;
67 void *in_HandlerData2;
68 uint8_t in_type;
69 uint8_t in_nr;
72 #ifdef bug
73 #undef bug
74 #endif
76 #ifdef __AROS__
77 struct KernelInterface {
78 long (*core_init)(unsigned long TimerPeriod, struct ExecBase **SysBasePointer, APTR *KernelBasePointer);
79 long (*core_intr_disable)(void);
80 long (*core_intr_enable)(void);
81 unsigned char (*core_is_super)(void);
82 void (*core_syscall)(syscall_id_t n);
83 int (*core_get_context_size)(void);
84 void (*core_print_context)(void *vctx);
85 void (*core_prepare_context)(void *vctx, void *sp, void *pc);
88 extern struct HostInterface *HostIFace;
89 extern struct KernelInterface KernelIFace;
90 extern APTR KernelBase;
92 IPTR krnGetTagData(Tag tagValue, intptr_t defaultVal, const struct TagItem *tagList);
93 struct TagItem *krnFindTagItem(Tag tagValue, const struct TagItem *tagList);
94 struct TagItem *krnNextTagItem(const struct TagItem **tagListPtr);
96 AROS_LD2(int, KrnBug,
97 AROS_LDA(const char *, format, A0),
98 AROS_LDA(va_list, args, A1),
99 struct KernelBase *, KernelBase, 11, Kernel);
101 static inline void bug(const char *format, ...)
103 va_list args;
104 va_start(args, format);
105 AROS_SLIB_ENTRY(KrnBug, Kernel)(format, args, KernelBase);
106 va_end(args);
109 #else
111 enum {
112 ss_RUNNING,
113 ss_SLEEP_PENDING,
114 ss_SLEEPING
117 extern int sleep_state;
118 extern struct ExecBase **SysBasePtr;
119 extern struct KernelBase **KernelBasePtr;
121 void core_Dispatch(void);
122 void core_Switch(void);
123 void core_Schedule(void);
124 void core_ExitInterrupt(void);
125 void core_Cause(struct ExecBase *SysBase);
126 void core_intr_enable(void);
128 void *get_stack_pointer (void *vctx);
130 #endif
132 #endif /*KERNEL_INTERN_H_*/