mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-21 00:46:47 +00:00
Initial commit of NetBSD port
This commit is contained in:
@@ -18,6 +18,7 @@ enum TargetOsKind : u16 {
|
||||
TargetOs_essence,
|
||||
TargetOs_freebsd,
|
||||
TargetOs_openbsd,
|
||||
TargetOs_netbsd,
|
||||
TargetOs_haiku,
|
||||
|
||||
TargetOs_wasi,
|
||||
@@ -79,6 +80,7 @@ gb_global String target_os_names[TargetOs_COUNT] = {
|
||||
str_lit("essence"),
|
||||
str_lit("freebsd"),
|
||||
str_lit("openbsd"),
|
||||
str_lit("netbsd"),
|
||||
str_lit("haiku"),
|
||||
|
||||
str_lit("wasi"),
|
||||
@@ -549,6 +551,14 @@ gb_global TargetMetrics target_openbsd_amd64 = {
|
||||
str_lit("e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"),
|
||||
};
|
||||
|
||||
gb_global TargetMetrics target_netbsd_amd64 = {
|
||||
TargetOs_netbsd,
|
||||
TargetArch_amd64,
|
||||
8, 8, 8, 16,
|
||||
str_lit("x86_64-unknown-netbsd-elf"),
|
||||
str_lit("e-m:w-i64:64-f80:128-n8:16:32:64-S128"),
|
||||
};
|
||||
|
||||
gb_global TargetMetrics target_haiku_amd64 = {
|
||||
TargetOs_haiku,
|
||||
TargetArch_amd64,
|
||||
@@ -655,6 +665,7 @@ gb_global NamedTargetMetrics named_targets[] = {
|
||||
{ str_lit("freebsd_amd64"), &target_freebsd_amd64 },
|
||||
|
||||
{ str_lit("openbsd_amd64"), &target_openbsd_amd64 },
|
||||
{ str_lit("netbsd_amd64"), &target_netbsd_amd64 },
|
||||
{ str_lit("haiku_amd64"), &target_haiku_amd64 },
|
||||
|
||||
{ str_lit("freestanding_wasm32"), &target_freestanding_wasm32 },
|
||||
@@ -1410,6 +1421,8 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta
|
||||
metrics = &target_freebsd_amd64;
|
||||
#elif defined(GB_SYSTEM_OPENBSD)
|
||||
metrics = &target_openbsd_amd64;
|
||||
#elif defined(GB_SYSTEM_NETBSD)
|
||||
metrics = &target_netbsd_amd64;
|
||||
#elif defined(GB_SYSTEM_HAIKU)
|
||||
metrics = &target_haiku_amd64;
|
||||
#elif defined(GB_CPU_ARM)
|
||||
@@ -1523,6 +1536,9 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta
|
||||
case TargetOs_openbsd:
|
||||
bc->link_flags = str_lit("-arch x86-64 ");
|
||||
break;
|
||||
case TargetOs_netbsd:
|
||||
bc->link_flags = str_lit("-arch x86-64 ");
|
||||
break;
|
||||
case TargetOs_haiku:
|
||||
bc->link_flags = str_lit("-arch x86-64 ");
|
||||
break;
|
||||
@@ -2002,6 +2018,7 @@ gb_internal bool init_build_paths(String init_filename) {
|
||||
case TargetOs_essence:
|
||||
case TargetOs_freebsd:
|
||||
case TargetOs_openbsd:
|
||||
case TargetOs_netbsd:
|
||||
case TargetOs_haiku:
|
||||
gb_printf_err("-no-crt on unix systems requires either -default-to-nil-allocator or -default-to-panic-allocator to also be present because the default allocator requires crt\n");
|
||||
return false;
|
||||
|
||||
@@ -1010,6 +1010,7 @@ gb_internal void init_universal(void) {
|
||||
{"FreeBSD", TargetOs_freebsd},
|
||||
{"Haiku", TargetOs_haiku},
|
||||
{"OpenBSD", TargetOs_openbsd},
|
||||
{"NetBSD", TargetOs_netbsd},
|
||||
{"WASI", TargetOs_wasi},
|
||||
{"JS", TargetOs_js},
|
||||
{"Freestanding", TargetOs_freestanding},
|
||||
|
||||
+42
-1
@@ -83,6 +83,10 @@ extern "C" {
|
||||
#ifndef GB_SYSTEM_OPENBSD
|
||||
#define GB_SYSTEM_OPENBSD 1
|
||||
#endif
|
||||
#elif defined(__NetBSD__)
|
||||
#ifndef GB_SYSTEM_NETBSD
|
||||
#define GB_SYSTEM_NETBSD 1
|
||||
#endif
|
||||
#elif defined(__HAIKU__) || defined(__haiku__)
|
||||
#ifndef GB_SYSTEM_HAIKU
|
||||
#define GB_SYSTEM_HAIKU 1
|
||||
@@ -208,7 +212,7 @@ extern "C" {
|
||||
#endif
|
||||
#include <stdlib.h> // NOTE(bill): malloc on linux
|
||||
#include <sys/mman.h>
|
||||
#if !defined(GB_SYSTEM_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__HAIKU__)
|
||||
#if !defined(GB_SYSTEM_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__HAIKU__)
|
||||
#include <sys/sendfile.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
@@ -250,6 +254,11 @@ extern "C" {
|
||||
#define lseek64 lseek
|
||||
#endif
|
||||
|
||||
#if defined(GB_SYSTEM_NETBSD)
|
||||
#include <stdio.h>
|
||||
#define lseek64 lseek
|
||||
#endif
|
||||
|
||||
#if defined(GB_SYSTEM_HAIKU)
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
@@ -817,6 +826,13 @@ typedef struct gbAffinity {
|
||||
isize thread_count;
|
||||
isize threads_per_core;
|
||||
} gbAffinity;
|
||||
#elif defined(GB_SYSTEM_NETBSD)
|
||||
typedef struct gbAffinity {
|
||||
b32 is_accurate;
|
||||
isize core_count;
|
||||
isize thread_count;
|
||||
isize threads_per_core;
|
||||
} gbAffinity;
|
||||
#elif defined(GB_SYSTEM_HAIKU)
|
||||
typedef struct gbAffinity {
|
||||
b32 is_accurate;
|
||||
@@ -3267,6 +3283,31 @@ isize gb_affinity_thread_count_for_core(gbAffinity *a, isize core) {
|
||||
GB_ASSERT(0 <= core && core < a->core_count);
|
||||
return a->threads_per_core;
|
||||
}
|
||||
|
||||
#elif defined(GB_SYSTEM_NETBSD)
|
||||
#include <unistd.h>
|
||||
|
||||
void gb_affinity_init(gbAffinity *a) {
|
||||
a->core_count = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
a->threads_per_core = 1;
|
||||
a->is_accurate = a->core_count > 0;
|
||||
a->core_count = a->is_accurate ? a->core_count : 1;
|
||||
a->thread_count = a->core_count;
|
||||
}
|
||||
|
||||
void gb_affinity_destroy(gbAffinity *a) {
|
||||
gb_unused(a);
|
||||
}
|
||||
|
||||
b32 gb_affinity_set(gbAffinity *a, isize core, isize thread_index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
isize gb_affinity_thread_count_for_core(gbAffinity *a, isize core) {
|
||||
GB_ASSERT(0 <= core && core < a->core_count);
|
||||
return a->threads_per_core;
|
||||
}
|
||||
|
||||
#elif defined(GB_SYSTEM_HAIKU)
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
+1
-1
@@ -341,7 +341,7 @@ gb_internal ReadDirectoryError read_directory(String path, Array<FileInfo> *fi)
|
||||
|
||||
return ReadDirectory_None;
|
||||
}
|
||||
#elif defined(GB_SYSTEM_LINUX) || defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_FREEBSD) || defined(GB_SYSTEM_OPENBSD) || defined(GB_SYSTEM_HAIKU)
|
||||
#elif defined(GB_SYSTEM_LINUX) || defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_FREEBSD) || defined(GB_SYSTEM_OPENBSD) || defined(GB_SYSTEM_NETBSD) || defined(GB_SYSTEM_HAIKU)
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
+8
-3
@@ -627,8 +627,12 @@ gb_internal void thread_set_name(Thread *t, char const *name) {
|
||||
#elif defined(GB_SYSTEM_FREEBSD) || defined(GB_SYSTEM_OPENBSD)
|
||||
pthread_set_name_np(t->posix_handle, name);
|
||||
#else
|
||||
// TODO(bill): Test if this works
|
||||
pthread_setname_np(t->posix_handle, name);
|
||||
#ifdef GB_SYSTEM_NETBSD
|
||||
// TODO(phix): Could be that libs are to old on NetBSD? Just ignore for now.
|
||||
#else
|
||||
// TODO(bill): Test if this works
|
||||
pthread_setname_np(t->posix_handle, name);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -901,10 +905,11 @@ gb_internal void futex_wait(Futex *f, Footex val) {
|
||||
} while (f->load() == val);
|
||||
}
|
||||
|
||||
#elif defined(GB_SYSTEM_HAIKU)
|
||||
#elif defined(GB_SYSTEM_HAIKU) || defined(GB_SYSTEM_NETBSD)
|
||||
|
||||
// Futex implementation taken from https://tavianator.com/2023/futex.html
|
||||
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <atomic>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user