summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--include/software_panic.h1
-rw-r--r--libc/build.mk5
-rw-r--r--libc/syscalls.c29
4 files changed, 41 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 4c9d98c2f6..065747c017 100644
--- a/Makefile
+++ b/Makefile
@@ -268,6 +268,8 @@ include $(BDIR)/build.mk
endif
ifeq ($(USE_BUILTIN_STDLIB), 1)
include builtin/build.mk
+else
+include libc/build.mk
endif
include chip/$(CHIP)/build.mk
include core/$(CORE)/build.mk
@@ -310,6 +312,8 @@ endif
all-obj-$(1)+=$(call objs_from_dir_p,common,common,$(1))
ifeq ($(USE_BUILTIN_STDLIB), 1)
all-obj-$(1)+=$(call objs_from_dir_p,builtin,builtin,$(1))
+else
+all-obj-$(1)+=$(call objs_from_dir_p,libc,libc,$(1))
endif
all-obj-$(1)+=$(call objs_from_dir_p,driver,driver,$(1))
all-obj-$(1)+=$(call objs_from_dir_p,power,power,$(1))
@@ -364,6 +368,8 @@ dirs+=$(shell find common -type d)
dirs+=$(shell find driver -type d)
ifeq ($(USE_BUILTIN_STDLIB), 1)
dirs+=builtin
+else
+dirs+=libc
endif
common_dirs=util
diff --git a/include/software_panic.h b/include/software_panic.h
index d5eb8685b3..ad17e2ea5d 100644
--- a/include/software_panic.h
+++ b/include/software_panic.h
@@ -22,6 +22,7 @@
#define PANIC_SW_WATCHDOG (PANIC_SW_BASE + 4)
#define PANIC_SW_BAD_RNG (PANIC_SW_BASE + 5)
#define PANIC_SW_PMIC_FAULT (PANIC_SW_BASE + 6)
+#define PANIC_SW_EXIT (PANIC_SW_BASE + 7)
#ifndef __ASSEMBLER__
extern const char *const panic_sw_reasons[];
diff --git a/libc/build.mk b/libc/build.mk
new file mode 100644
index 0000000000..594f3061d6
--- /dev/null
+++ b/libc/build.mk
@@ -0,0 +1,5 @@
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+libc-y=syscalls.o
diff --git a/libc/syscalls.c b/libc/syscalls.c
new file mode 100644
index 0000000000..9c683a2732
--- /dev/null
+++ b/libc/syscalls.c
@@ -0,0 +1,29 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ *@brief Provides implementations of syscalls needed by libc. The newlib
+ * documentation provides a list of the required syscalls:
+ * https://sourceware.org/newlib/libc.html#Syscalls and minimal implementations
+ * can be found in newlib's "nosys" library:
+ * https://sourceware.org/git/?p=newlib-cygwin.git;a=tree;f=libgloss/libnosys.
+ */
+
+#include "panic.h"
+#include "software_panic.h"
+#include "task.h"
+
+/**
+ * Reboot the system.
+ *
+ * This function is called from libc functions such as abort() or exit().
+ *
+ * @param rc exit code
+ */
+void _exit(int rc)
+{
+ panic_printf("%s called with rc: %d\n", __func__, rc);
+ software_panic(PANIC_SW_EXIT, task_get_current());
+}