Newlib _exit will not be executed, replaced by a dead loop.

This commit is contained in:
imi415 2022-08-10 01:21:53 +08:00
parent c6c633655d
commit 836a9d3add
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
4 changed files with 50 additions and 12 deletions

View File

@ -31,7 +31,7 @@ set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-flto")
set(CMAKE_C_FLAGS "${TARGET_FLAGS_HARDWARE} -Wall -ffunction-sections -fdata-sections")
set(CMAKE_CXX_FLAGS "${TARGET_FLAGS_HARDWARE} -Wall -ffunction-sections -fdata-sections")
set(CMAKE_EXE_LINKER_FLAGS "${TARGET_FLAGS_HARDWARE} -Wall -lc -lm -nostartfiles -Wl,--print-memory-usage -Wl,--gc-sections")
set(CMAKE_EXE_LINKER_FLAGS "${TARGET_FLAGS_HARDWARE} -Wall -specs=nosys.specs -lc -lm -nostartfiles -Wl,--print-memory-usage -Wl,--gc-sections")
add_compile_definitions(${TARGET_DEFS})
include_directories(${TARGET_INCLUDES})

View File

@ -16,6 +16,9 @@
#define SYSTEM_CONFIG34 (0xFE001188U) /* PIO4 */
#define SYSTEM_CONFIG7 (0xFE00111CU) /* RXSEL */
#define MEMTEST_START 0x80010000
#define MEMTEST_END 0x8FFE0000
void uart_init(void) {
PIO4->CLR_PC0 = 1U; /* PC = 110, AFOUT, PP */
PIO4->SET_PC1 = 1U;
@ -31,6 +34,28 @@ void uart_init(void) {
CONSOLE_ASC->CTRL = 0x1589UL; /* 8N1, RX enable, FIFO enable, Baud mode 1 */
}
static void memory_test(void) {
for (uint32_t i = MEMTEST_START; i < MEMTEST_END; i += 4) {
*(uint32_t *)i = i;
if (i % 0x10000 == 0U) {
printf("Write to 0x%08x...\r\n", i);
}
}
for (uint32_t i = MEMTEST_START; i < MEMTEST_END; i += 4) {
if (*(uint32_t *)i != i) {
printf("Read back error at 0x%08x\r\n", i);
return;
}
if (i % 0x10000 == 0U) {
printf("Read from 0x%08x...\r\n", i);
}
}
}
int main(void) {
init_led(LED_RED_GPIO, LED_RED_PIN, 0U);
init_led(LED_BLUE_GPIO, LED_BLUE_PIN, 0U);
@ -39,10 +64,22 @@ int main(void) {
printf("Hello world\r\n");
printf("Size of int: %d\r\n", sizeof(int));
printf("Size of short: %d\r\n", sizeof(short));
printf("Size of char: %d\r\n", sizeof(char));
printf("Size of long: %d\r\n", sizeof(long));
printf("Size of pointer: %d\r\n", sizeof(uint8_t *));
printf("Size of uint8_t: %d\r\n", sizeof(uint8_t));
printf("Size of uint16_t: %d\r\n", sizeof(uint16_t));
printf("Size of uint32_t: %d\r\n", sizeof(uint32_t));
delay_ms(5000);
memory_test();
for (;;) {
set_led(LED_BLUE_GPIO, LED_BLUE_PIN, 1U);
delay_ms(500);
printf("Hello ?\r\n");
set_led(LED_BLUE_GPIO, LED_BLUE_PIN, 0U);
delay_ms(500);
}
@ -51,7 +88,7 @@ int main(void) {
}
void _putchar(char ch) {
while(CONSOLE_ASC->STA & 1 << 9U) {
while (CONSOLE_ASC->STA & 1 << 9U) {
// wait for TX FIFO slot.
}
CONSOLE_ASC->TX_BUF = ch;

View File

@ -24,10 +24,10 @@ void set_led(PIO_TypeDef *gpiox, uint8_t pin, uint8_t val) {
void delay_ms(uint32_t msec) {
/* Initialize TMU and count to zero */
/* TMU clock is from Peripheral clock, approx. 66MHz */
/* Prescale to 66kHz for convenience (TMUs can only divide by max. 1024) */
/* TMU clock is from Peripheral clock, approx. 100MHz */
/* Prescale to 100kHz for convenience (TMUs can only divide by max. 1024) */
uint32_t reload_value = msec * 66 - 1;
uint32_t reload_value = msec * 100 - 1;
TMU->TSTR &= ~TMU_TSTR_STR0_Msk; /* Stop counter */
TMU->TCR0 = 0x04U | TMU_TCR_UNIE_Msk; /* 1024 prescale, enable interrupt */

View File

@ -63,10 +63,11 @@ _main_entry:
jsr @r0
or r0, r0
mov r0, r4
mov.l _exit_k, r0
jsr @r0
or r0, r0
mov.l _exit_loop_k, r0
_exit_loop:
sleep
jmp @r0
nop
.balign 4
/* libc FPU routine */
@ -88,8 +89,8 @@ _end_k:
/* Function pointers */
_main_k:
.long _main /* Same address as main */
_exit_k:
.long _exit
_exit_loop_k:
.long _exit_loop
_exc_base_k:
.long _exc_base
_exc_imask_k: