diff --git a/src/libs/compat/freebsd_iflib/compat/device_if.h b/src/libs/compat/freebsd_iflib/compat/device_if.h new file mode 100644 index 0000000000..acd70b6aa0 --- /dev/null +++ b/src/libs/compat/freebsd_iflib/compat/device_if.h @@ -0,0 +1,10 @@ +/* + * Copyright 2018, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _device_if_h_ +#define _device_if_h_ + +void* DEVICE_REGISTER(device_t dev); + +#endif /* _device_if_h_ */ diff --git a/src/libs/compat/freebsd_iflib/compat/sys/kobj.h b/src/libs/compat/freebsd_iflib/compat/sys/kobj.h new file mode 100644 index 0000000000..63428c6132 --- /dev/null +++ b/src/libs/compat/freebsd_iflib/compat/sys/kobj.h @@ -0,0 +1,64 @@ +/* + * Copyright 2018, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _SYS_KOBJ_H_ +#define _SYS_KOBJ_H_ + + +typedef struct kobj* kobj_t; +typedef driver_t* kobj_class_t; +typedef const struct device_method kobj_method_t; +typedef device_method_signature_t kobjop_t; +typedef void* kobj_ops_t; +typedef struct kobjop_desc* kobjop_desc_t; + +struct kobjop_desc { + int32 id; + kobj_method_t deflt; /* default implementation */ +}; + + +/* kobj */ +struct kobj_ops { + kobj_class_t cls; +}; + +#define KOBJ_FIELDS \ + struct kobj_ops ops + +struct kobj { + KOBJ_FIELDS; +}; + + +/* this *must* be kept in sync with driver_t as defined in haiku-module.h */ +#define KOBJ_CLASS_FIELDS \ + const char* name; \ + kobj_method_t* methods; \ + size_t size; /* object size */ + + +#define KOBJOPLOOKUP(OPS,OP) do { \ + kobjop_desc_t _desc = &OP##_##desc; \ + kobj_method_t* _ce = NULL; \ + _ce = kobj_lookup_method(OPS.cls, \ + NULL, _desc); \ + _m = _ce->method; \ +} while(0) + + +void kobj_init(kobj_t obj, kobj_class_t cls); +kobj_method_t* kobj_lookup_method(kobj_class_t cls, kobj_method_t **cep, + kobjop_desc_t desc); +int kobj_error_method(void); + + +/* we don't need these functions */ +static inline void kobj_class_compile(kobj_class_t cls) {} +static inline void kobj_class_compile_static(kobj_class_t cls, kobj_ops_t ops) {} +static inline void kobj_class_free(kobj_class_t cls) {} +static inline void kobj_init_static(kobj_t obj, kobj_class_t cls) {} + + +#endif /* !_SYS_KOBJ_H_ */ diff --git a/src/libs/compat/freebsd_iflib/compat/sys/kthread.h b/src/libs/compat/freebsd_iflib/compat/sys/kthread.h new file mode 100644 index 0000000000..416289a6f9 --- /dev/null +++ b/src/libs/compat/freebsd_iflib/compat/sys/kthread.h @@ -0,0 +1,27 @@ +/* + * Copyright 2018, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_IFLIB_SYS_KTHREAD_H_ +#define _FBSD_COMPAT_IFLIB_SYS_KTHREAD_H_ + +/* include the real sys/kthread.h */ +#include_next + +#include + + +#define SRQ_BORING 0 + +void sched_prio(struct thread* td, u_char prio); +void sched_add(struct thread* td, int flags); + +int kthread_add(void (*func)(void *), void *arg, void* p, + struct thread** newtdp, int flags, int pages, const char* fmt, ...); +void kthread_exit(); + +#define thread_lock(td) +#define thread_unlock(td) + + +#endif /* _FBSD_COMPAT_IFLIB_SYS_KTHREAD_H_ */ diff --git a/src/libs/compat/freebsd_iflib/device_if.c b/src/libs/compat/freebsd_iflib/device_if.c new file mode 100644 index 0000000000..f4d6f55e4a --- /dev/null +++ b/src/libs/compat/freebsd_iflib/device_if.c @@ -0,0 +1,18 @@ +/* + * Copyright 2018, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include +#include +#include +#include + +#include "../freebsd_network/shared.h" + + +void* +DEVICE_REGISTER(device_t dev) +{ + return dev->methods.device_register(dev); +} diff --git a/src/libs/compat/freebsd_iflib/kobj.c b/src/libs/compat/freebsd_iflib/kobj.c new file mode 100644 index 0000000000..448628a7c3 --- /dev/null +++ b/src/libs/compat/freebsd_iflib/kobj.c @@ -0,0 +1,60 @@ +/* + * Copyright 2018-2019, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include +#include +#include +#include +#include +#include + + +static kobj_method_t kobj_default_method = { + "kobj_default_method", 0, (kobjop_t)kobj_error_method +}; + + +void +kobj_init(kobj_t obj, kobj_class_t cls) +{ + obj->ops.cls = cls; +} + + +kobj_method_t* +kobj_lookup_method(kobj_class_t class, kobj_method_t** cep, + kobjop_desc_t desc) +{ + int32 i, id; + kobj_method_t* ret = NULL; + + id = desc->id; + if (id == 0) + id = desc->deflt.id; + + for (i = 0; class->methods[i].name != NULL; i++) { + kobj_method_t* mth = &class->methods[i]; + if (mth->id != id) + continue; + + ret = mth; + break; + } + if (ret == NULL || ret->method == NULL) + ret = &desc->deflt; + if (ret == NULL || ret->method == NULL) + ret = &kobj_default_method; + + if (cep != NULL) + *cep = ret; + return ret; +} + + +int +kobj_error_method(void) +{ + return ENXIO; +} diff --git a/src/libs/compat/freebsd_iflib/kthread.cpp b/src/libs/compat/freebsd_iflib/kthread.cpp new file mode 100644 index 0000000000..c60ebe2a26 --- /dev/null +++ b/src/libs/compat/freebsd_iflib/kthread.cpp @@ -0,0 +1,54 @@ +/* + * Copyright 2018, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +extern "C" { +#include +#include +} + +#include + + +int +kthread_add(void (*func)(void *), void *arg, void* p, + struct thread **newtdp, int flags, int pages, const char *fmt, ...) +{ + va_list ap; + char name[B_OS_NAME_LENGTH]; + va_start(ap, fmt); + vsnprintf(name, sizeof(name), fmt, ap); + va_end(ap); + + thread_id id = spawn_kernel_thread((status_t (*)(void *))func, /* HACK! */ + name, B_NORMAL_PRIORITY, arg); + if (id < 0) + return id; + if (newtdp != NULL) { + intptr_t thread = id; + *newtdp = (struct thread*)thread; + } + return 0; +} + + +void +sched_prio(struct thread* td, u_char prio) +{ + set_thread_priority((thread_id)td, prio); +} + + +void +sched_add(struct thread* td, int /* flags */) +{ + resume_thread((thread_id)td); +} + + +void +kthread_exit() +{ + thread_exit(); +}