Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sw: Fixed wrong return value when using ocd semihosting #165

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sw/snRuntime/src/openocd.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

#include <stdint.h>

#pragma once

#define SEMIHOST_EXIT_SUCCESS 0x20026
#define SEMIHOST_EXIT_ERROR 0x20023

/* riscv semihosting standard:
* IN: a0 holds syscall number
* IN: a1 holds pointer to arg struct
Expand Down Expand Up @@ -32,3 +37,8 @@ static inline int __ocd_semihost_write(int fd, uint8_t *buffer, int len) {
__asm__ __volatile__("" : : : "memory");
return __ocd_semihost(0x05, (long)args);
}

static inline void __ocd_semihost_exit(int status) {
__ocd_semihost(0x18,
status == 0 ? SEMIHOST_EXIT_SUCCESS : SEMIHOST_EXIT_ERROR);
}
6 changes: 5 additions & 1 deletion sw/snRuntime/src/start.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#ifdef OPENOCD_SEMIHOSTING
#include "openocd.h"
#endif

#ifdef SNRT_INIT_CLS
static inline uint32_t snrt_cls_base_addr() {
extern volatile uint32_t __cdata_start, __cdata_end;
Expand Down Expand Up @@ -100,7 +104,7 @@ static inline void snrt_init_libs() { snrt_alloc_init(); }
static inline void snrt_exit_default(int exit_code) {
exit_code = snrt_global_all_to_all_reduction(exit_code);
#ifdef OPENOCD_SEMIHOSTING
if (snrt_global_core_idx() == 0) __ocd_semihost(0x18, (long)exit_code);
if (snrt_global_core_idx() == 0) __ocd_semihost_exit(exit_code);
#else
if (snrt_global_core_idx() == 0)
*(snrt_exit_code_destination()) = (exit_code << 1) | 1;
Expand Down
Loading