From 7fbf44a4719853ce8a26d89a06af911949823b95 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Mon, 10 Oct 2022 10:44:50 -0700 Subject: [PATCH] Match and link Gecko_ExceptionPPC and uart_console_write Former-commit-id: 0e8b7c5637c379b9dcdca42b23b49cd411f84794 --- .vscode/settings.json | 2 ++ configure.py | 4 ++-- libc/console_io.h | 17 ++++++++++++++ libc/file_struc.h | 22 ++++++++++++++++++ obj_files.mk | 4 ++-- src/Runtime/Gecko_ExceptionPPC.cpp | 36 ++++++++++++++++++++++++++++++ src/Runtime/uart_console_io.c | 34 ++++++++++++++++++++++++++++ 7 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 libc/console_io.h create mode 100644 libc/file_struc.h create mode 100644 src/Runtime/Gecko_ExceptionPPC.cpp create mode 100644 src/Runtime/uart_console_io.c diff --git a/.vscode/settings.json b/.vscode/settings.json index 97ba01ec..4ed827ec 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,6 +10,8 @@ "editor.tabSize": 2, "files.associations": { "source_location": "cpp", + "console_io.h": "c", + "file_struc.h": "c" }, "files.autoSave": "onFocusChange", "files.insertFinalNewline": true, diff --git a/configure.py b/configure.py index 8cd3e130..519cfd3e 100755 --- a/configure.py +++ b/configure.py @@ -849,7 +849,7 @@ LIBS = [ ["Runtime/ptmf", True], "Runtime/runtime", ["Runtime/__init_cpp_exceptions", True], - "Runtime/Gecko_ExceptionPPC", + ["Runtime/Gecko_ExceptionPPC", True], ["Runtime/abort_exit", True], "Runtime/alloc", "Runtime/ansi_files", @@ -872,7 +872,7 @@ LIBS = [ "Runtime/string", "Runtime/float", "Runtime/strtold", - "Runtime/uart_console_io", + ["Runtime/uart_console_io", True], ["Runtime/wchar_io", True], ["Runtime/e_acos", True], ["Runtime/e_asin", True], diff --git a/libc/console_io.h b/libc/console_io.h new file mode 100644 index 00000000..2399e980 --- /dev/null +++ b/libc/console_io.h @@ -0,0 +1,17 @@ +#ifndef _CONSOLE_IO +#define _CONSOLE_IO + +#include "stddef.h" +#include "file_struc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int __write_console(__file_handle handle, unsigned char * buffer, size_t * count, __idle_proc idle_proc); + +#ifdef __cplusplus +} +#endif + +#endif // _CONSOLE_IO diff --git a/libc/file_struc.h b/libc/file_struc.h new file mode 100644 index 00000000..b347543b --- /dev/null +++ b/libc/file_struc.h @@ -0,0 +1,22 @@ +#ifndef _FILE_STRUC +#define _FILE_STRUC + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned long __file_handle; +typedef unsigned long fpos_t; + +typedef void (*__idle_proc)(void); +typedef int (*__pos_proc)(__file_handle file, fpos_t* position, int mode, __idle_proc idle_proc); +typedef int (*__io_proc)(__file_handle file, unsigned char* buff, size_t* count, + __idle_proc idle_proc); +typedef int (*__close_proc)(__file_handle file); + +#ifdef __cplusplus +} +#endif +#endif // _FILE_STRUC diff --git a/obj_files.mk b/obj_files.mk index 69c0445e..5b13593e 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -724,7 +724,7 @@ MSL_PPCEABI_BARE_H :=\ $(BUILD_DIR)/src/Runtime/ptmf.o\ $(BUILD_DIR)/asm/Runtime/runtime.o\ $(BUILD_DIR)/src/Runtime/__init_cpp_exceptions.o\ - $(BUILD_DIR)/asm/Runtime/Gecko_ExceptionPPC.o\ + $(BUILD_DIR)/src/Runtime/Gecko_ExceptionPPC.o\ $(BUILD_DIR)/src/Runtime/abort_exit.o\ $(BUILD_DIR)/asm/Runtime/alloc.o\ $(BUILD_DIR)/asm/Runtime/ansi_files.o\ @@ -747,7 +747,7 @@ MSL_PPCEABI_BARE_H :=\ $(BUILD_DIR)/asm/Runtime/string.o\ $(BUILD_DIR)/asm/Runtime/float.o\ $(BUILD_DIR)/asm/Runtime/strtold.o\ - $(BUILD_DIR)/asm/Runtime/uart_console_io.o\ + $(BUILD_DIR)/src/Runtime/uart_console_io.o\ $(BUILD_DIR)/src/Runtime/wchar_io.o MSL_COMMON_MATH :=\ diff --git a/src/Runtime/Gecko_ExceptionPPC.cpp b/src/Runtime/Gecko_ExceptionPPC.cpp new file mode 100644 index 00000000..6e61f2f1 --- /dev/null +++ b/src/Runtime/Gecko_ExceptionPPC.cpp @@ -0,0 +1,36 @@ +#include "__ppc_eabi_linker.h" +#include "NMWException.h" + +typedef struct ProcessInfo { + __eti_init_info* exception_info; + char* TOC; + int active; +} ProcessInfo; + +static ProcessInfo fragmentinfo[1]; + +int __register_fragment(struct __eti_init_info* info, char* TOC) { + ProcessInfo* f; + int i; + + for (i = 0, f = fragmentinfo; i < 1; ++i, ++f) { + if (f->active == 0) { + f->exception_info = info; + f->TOC = TOC; + f->active = 1; + return (i); + } + } + + return (-1); +} + +void __unregister_fragment(int fragmentId) { + ProcessInfo* f; + if (fragmentId >= 0 && fragmentId < 1) { + f = &fragmentinfo[fragmentId]; + f->exception_info = 0; + f->TOC = 0; + f->active = 0; + } +} diff --git a/src/Runtime/uart_console_io.c b/src/Runtime/uart_console_io.c new file mode 100644 index 00000000..1aff7dc8 --- /dev/null +++ b/src/Runtime/uart_console_io.c @@ -0,0 +1,34 @@ +#include "console_io.h" + +int __TRK_write_console(__file_handle handle, unsigned char* buffer, size_t* count, + __idle_proc idle_proc); + +static inline int __init_uart_console(void) { + int err = 0; + static int initialized = 0; + + if (initialized == 0) { + err = InitializeUART(57600); + + if (err == 0) + initialized = 1; + } + + return (err); +} +int __write_console(__file_handle handle, unsigned char* buffer, size_t* count, + __idle_proc idle_proc) { + if (__init_uart_console() != 0) { + return 1; + } + + if (WriteUARTN(buffer, *count) != 0) { + *count = 0; + return 1; + } + + __TRK_write_console(handle, buffer, count, idle_proc); + return 0; +} + +int __close_console() { return 0; }