MNRS-BM-BSP/libwrap/sys/_exit.c

38 lines
863 B
C
Raw Normal View History

2020-06-18 12:15:52 +02:00
/* See LICENSE of license details. */
#include "platform.h"
2023-11-23 18:29:26 +01:00
#include "weak_under_alias.h"
2024-05-31 09:21:57 +02:00
#include <unistd.h>
#if defined(SEMIHOSTING)
2024-04-08 14:36:22 +02:00
#include "semihosting.h"
2024-05-31 09:21:57 +02:00
#endif
2020-06-18 12:15:52 +02:00
2023-11-24 11:39:23 +01:00
#if defined(BOARD_hifive1)
static volatile uint32_t tohost;
static volatile uint32_t fromhost;
#else
2023-08-20 15:00:51 +02:00
extern volatile uint32_t tohost;
extern volatile uint32_t fromhost;
2023-11-24 11:39:23 +01:00
#endif
2023-09-30 20:31:58 +02:00
void write_hex(int fd, uint32_t hex);
2023-08-20 15:00:51 +02:00
2024-05-31 09:21:57 +02:00
void __wrap_exit(int code) {
/*#if defined(SEMIHOSTING)
sh_exit();
return;
#endif*/
// volatile uint32_t* leds = (uint32_t*) (GPIO_BASE_ADDR + GPIO_OUT_OFFSET);
2020-06-18 12:15:52 +02:00
const char message[] = "\nProgam has exited with code:";
2024-05-31 09:21:57 +02:00
//*leds = (~(code));
2020-06-18 12:15:52 +02:00
write(STDERR_FILENO, message, sizeof(message) - 1);
write_hex(STDERR_FILENO, code);
write(STDERR_FILENO, "\n", 1);
2024-05-31 09:21:57 +02:00
tohost = code + 1;
2023-08-20 15:00:51 +02:00
write(STDERR_FILENO, "\x04", 1);
2024-05-31 09:21:57 +02:00
for (;;)
;
2020-06-18 12:15:52 +02:00
}
2023-11-23 18:29:26 +01:00
weak_under_alias(exit);