2008-04-09 18:21:06 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2005-2008, Haiku Inc. All Rights Reserved.
|
2005-04-27 05:08:35 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-09-20 02:33:58 +04:00
|
|
|
#ifndef _KERNEL_EXPORT_H
|
|
|
|
#define _KERNEL_EXPORT_H
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
|
2002-09-20 02:33:58 +04:00
|
|
|
#include <SupportDefs.h>
|
|
|
|
#include <OS.h>
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
|
2005-04-27 05:08:35 +04:00
|
|
|
/* interrupts and spinlocks */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
typedef ulong cpu_status;
|
2008-06-02 06:04:12 +04:00
|
|
|
|
|
|
|
// WARNING: For Haiku debugging only! This changes the spinlock type in a
|
|
|
|
// binary incompatible way!
|
|
|
|
//#define B_DEBUG_SPINLOCK_CONTENTION 1
|
|
|
|
|
|
|
|
#if B_DEBUG_SPINLOCK_CONTENTION
|
|
|
|
typedef struct {
|
|
|
|
vint32 lock;
|
|
|
|
vint32 count_low;
|
|
|
|
vint32 count_high;
|
|
|
|
} spinlock;
|
|
|
|
|
|
|
|
# define B_SPINLOCK_INITIALIZER { 0, 0, 0 }
|
|
|
|
# define B_INITIALIZE_SPINLOCK(spinlock) do { \
|
|
|
|
(spinlock)->lock = 0; \
|
|
|
|
(spinlock)->count_low = 0; \
|
|
|
|
(spinlock)->count_high = 0; \
|
|
|
|
} while (false)
|
|
|
|
# define B_SPINLOCK_IS_LOCKED(spinlock) ((spinlock)->lock > 0)
|
|
|
|
#else
|
|
|
|
typedef vint32 spinlock;
|
|
|
|
|
|
|
|
# define B_SPINLOCK_INITIALIZER 0
|
|
|
|
# define B_INITIALIZE_SPINLOCK(lock) do { *(lock) = 0; } while (false)
|
|
|
|
# define B_SPINLOCK_IS_LOCKED(lock) (*(lock) > 0)
|
|
|
|
#endif
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* interrupt handling support for device drivers */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2005-04-27 05:08:35 +04:00
|
|
|
typedef int32 (*interrupt_handler)(void *data);
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* Values returned by interrupt handlers */
|
|
|
|
#define B_UNHANDLED_INTERRUPT 0 /* pass to next handler */
|
|
|
|
#define B_HANDLED_INTERRUPT 1 /* don't pass on */
|
|
|
|
#define B_INVOKE_SCHEDULER 2 /* don't pass on; invoke the scheduler */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2005-04-27 05:08:35 +04:00
|
|
|
/* Flags that can be passed to install_io_interrupt_handler() */
|
|
|
|
#define B_NO_ENABLE_COUNTER 1
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* timer interrupts services */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
typedef struct timer timer;
|
|
|
|
typedef int32 (*timer_hook)(timer *);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
struct timer {
|
2008-04-09 18:21:06 +04:00
|
|
|
struct timer *next;
|
|
|
|
int64 schedule_time;
|
|
|
|
void *user_data;
|
2003-01-27 16:48:39 +03:00
|
|
|
uint16 flags;
|
|
|
|
uint16 cpu;
|
|
|
|
timer_hook hook;
|
|
|
|
bigtime_t period;
|
2002-09-20 02:33:58 +04:00
|
|
|
};
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
#define B_ONE_SHOT_ABSOLUTE_TIMER 1
|
|
|
|
#define B_ONE_SHOT_RELATIVE_TIMER 2
|
|
|
|
#define B_PERIODIC_TIMER 3
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
|
|
|
|
/* virtual memory buffer functions */
|
|
|
|
|
|
|
|
#define B_DMA_IO 0x00000001
|
|
|
|
#define B_READ_DEVICE 0x00000002
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
typedef struct {
|
2003-01-27 16:48:39 +03:00
|
|
|
void *address; /* address in physical memory */
|
|
|
|
ulong size; /* size of block */
|
2002-09-20 02:33:58 +04:00
|
|
|
} physical_entry;
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* address specifications for mapping physical memory */
|
|
|
|
#define B_ANY_KERNEL_BLOCK_ADDRESS (B_ANY_KERNEL_ADDRESS + 1)
|
2008-07-17 03:32:25 +04:00
|
|
|
#define B_PHYSICAL_BASE_ADDRESS (B_ANY_KERNEL_ADDRESS + 2)
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2004-12-14 01:00:23 +03:00
|
|
|
/* area protection flags for the kernel */
|
|
|
|
#define B_KERNEL_READ_AREA 16
|
|
|
|
#define B_KERNEL_WRITE_AREA 32
|
2005-01-26 01:55:13 +03:00
|
|
|
#define B_USER_CLONEABLE_AREA 256
|
2004-12-14 01:00:23 +03:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* MTR attributes for mapping physical memory (Intel Architecture only) */
|
2008-04-09 18:21:06 +04:00
|
|
|
// TODO: rename those to something more meaningful
|
2002-09-20 02:33:58 +04:00
|
|
|
#define B_MTR_UC 0x10000000
|
|
|
|
#define B_MTR_WC 0x20000000
|
|
|
|
#define B_MTR_WT 0x30000000
|
|
|
|
#define B_MTR_WP 0x40000000
|
|
|
|
#define B_MTR_WB 0x50000000
|
|
|
|
#define B_MTR_MASK 0xf0000000
|
|
|
|
|
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
/* kernel daemon service */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
typedef void (*daemon_hook)(void *arg, int iteration);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
/* kernel debugging facilities */
|
|
|
|
|
|
|
|
/* special return codes for kernel debugger */
|
|
|
|
#define B_KDEBUG_CONT 2
|
|
|
|
#define B_KDEBUG_QUIT 3
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
typedef int (*debugger_command_hook)(int argc, char **argv);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
2002-09-20 02:33:58 +04:00
|
|
|
#endif
|
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
/* interrupts, spinlock, and timers */
|
|
|
|
extern cpu_status disable_interrupts(void);
|
|
|
|
extern void restore_interrupts(cpu_status status);
|
2006-07-25 23:46:36 +04:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
extern void acquire_spinlock(spinlock *lock);
|
|
|
|
extern void release_spinlock(spinlock *lock);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
extern status_t install_io_interrupt_handler(long interrupt_number,
|
|
|
|
interrupt_handler handler, void *data, ulong flags);
|
|
|
|
extern status_t remove_io_interrupt_handler(long interrupt_number,
|
|
|
|
interrupt_handler handler, void *data);
|
2003-01-27 16:48:39 +03:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
extern status_t add_timer(timer *t, timer_hook hook, bigtime_t period,
|
|
|
|
int32 flags);
|
|
|
|
extern bool cancel_timer(timer *t);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
/* kernel threads */
|
|
|
|
extern thread_id spawn_kernel_thread(thread_func function,
|
|
|
|
const char *name, int32 priority, void *arg);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
/* signal functions */
|
|
|
|
extern int send_signal_etc(pid_t thread, uint signal, uint32 flags);
|
2003-01-27 16:48:39 +03:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
/* virtual memory */
|
2008-07-17 02:55:17 +04:00
|
|
|
extern status_t lock_memory_etc(team_id team, void *buffer, size_t numBytes,
|
|
|
|
uint32 flags);
|
|
|
|
extern status_t lock_memory(void *buffer, size_t numBytes, uint32 flags);
|
|
|
|
extern status_t unlock_memory_etc(team_id team, void *address,
|
|
|
|
size_t numBytes, uint32 flags);
|
|
|
|
extern status_t unlock_memory(void *buffer, size_t numBytes, uint32 flags);
|
2008-07-24 08:07:14 +04:00
|
|
|
extern status_t get_memory_map_etc(team_id team, const void *address,
|
|
|
|
size_t numBytes, physical_entry *table,
|
|
|
|
uint32* _numEntries);
|
2008-04-09 18:21:06 +04:00
|
|
|
extern long get_memory_map(const void *buffer, ulong size,
|
|
|
|
physical_entry *table, long numEntries);
|
|
|
|
extern area_id map_physical_memory(const char *areaName,
|
|
|
|
void *physicalAddress, size_t size, uint32 flags,
|
|
|
|
uint32 protection, void **_mappedAddress);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
/* kernel debugging facilities */
|
|
|
|
extern void dprintf(const char *format, ...) _PRINTFLIKE(1, 2);
|
|
|
|
extern void kprintf(const char *fmt, ...) _PRINTFLIKE(1, 2);
|
2003-02-10 00:05:37 +03:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
extern void dump_block(const char *buffer, int size, const char *prefix);
|
|
|
|
/* TODO: temporary API: hexdumps given buffer */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
extern bool set_dprintf_enabled(bool new_state);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
extern void panic(const char *format, ...) _PRINTFLIKE(1, 2);
|
2003-01-27 16:48:39 +03:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
extern void kernel_debugger(const char *message);
|
|
|
|
extern uint64 parse_expression(const char *string);
|
|
|
|
|
2009-02-01 23:48:02 +03:00
|
|
|
extern int add_debugger_command(const char *name,
|
|
|
|
debugger_command_hook hook, const char *help);
|
|
|
|
extern int remove_debugger_command(const char *name,
|
|
|
|
debugger_command_hook hook);
|
2008-04-09 18:21:06 +04:00
|
|
|
|
|
|
|
/* Miscellaneous */
|
|
|
|
extern void spin(bigtime_t microseconds);
|
2003-01-27 16:48:39 +03:00
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
extern status_t register_kernel_daemon(daemon_hook hook, void *arg,
|
|
|
|
int frequency);
|
2003-01-27 16:48:39 +03:00
|
|
|
extern status_t unregister_kernel_daemon(daemon_hook hook, void *arg);
|
|
|
|
|
2008-04-09 18:21:06 +04:00
|
|
|
extern void call_all_cpus(void (*func)(void *, int), void *cookie);
|
|
|
|
extern void call_all_cpus_sync(void (*func)(void *, int), void *cookie);
|
2008-04-26 19:18:04 +04:00
|
|
|
extern void memory_read_barrier(void);
|
|
|
|
extern void memory_write_barrier(void);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2004-09-29 14:22:34 +04:00
|
|
|
/* safe methods to access user memory without having to lock it */
|
|
|
|
extern status_t user_memcpy(void *to, const void *from, size_t size);
|
|
|
|
extern ssize_t user_strlcpy(char *to, const char *from, size_t size);
|
|
|
|
extern status_t user_memset(void *start, char c, size_t count);
|
|
|
|
|
2002-09-20 02:33:58 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
#endif /* _KERNEL_EXPORT_H */
|