[PATCH] H8/300: Start-up code cleanup for H8/300H and newer
Jan Dubiec
jdx@o2.pl
Sat Jul 19 09:56:17 GMT 2025
This patch has been started as an attempt to fix assembler message about
missing stack section attributes:
CPPAS libc/sys/h8300hms/crt0.o
../../../combosrc/newlib/libc/sys/h8300hms/crt0.S: Assembler messages:
../../../combosrc/newlib/libc/sys/h8300hms/crt0.S:64: Warning: new
section '.stack' defined without attributes - this might cause problems
In the process I have noticed that H8/300H, H8/300S and H8SX code does
not support normal mode. So the patch does a few things: declares stack
section in a proper way, merges H8/300H and H8/300S/SX parts of code
into one and adds support for normal mode.
2025-07-19 Jan Dubiec <jdx@o2.pl>
newlib/ChangeLog:
* libc/sys/h8300hms/crt0.S: General cleanup: declare stack section
in a proper way, merge H8/300H and H8/300S/SX parts of code into
one, add support for normal mode.
-------------- next part --------------
newlib/libc/sys/h8300hms/crt0.S | 80 +++++++++++++++++------------------------
1 file changed, 32 insertions(+), 48 deletions(-)
diff --git a/newlib/libc/sys/h8300hms/crt0.S b/newlib/libc/sys/h8300hms/crt0.S
index 05634113c..757fb0477 100644
--- a/newlib/libc/sys/h8300hms/crt0.S
+++ b/newlib/libc/sys/h8300hms/crt0.S
@@ -1,4 +1,4 @@
-; h8/300 and h8/300h start up file.
+; H8/300, H8/300H, H8/300S and H8SX start up file.
#include "setarch.h"
@@ -10,90 +10,74 @@ _start:
mov.w #_stack,sp
mov.w #_edata,r0
mov.w #_end,r2
- sub.w r1,r1
+ sub.w r1,r1
sub.w r0,r2
jsr @_memset
#ifdef __ELF__
- mov.l #__fini,r0
- jsr @_atexit
+ mov.w #__fini,r0
+ jsr @_atexit
#ifdef __SIMULATOR__
- jsr @0xcc
+ jsr @0xcc
#endif
- jsr @__init
+ jsr @__init
#else
#ifdef __SIMULATOR__
- jsr @0xcc
+ jsr @0xcc
#endif
jsr @___main
#endif
jsr @_main
jsr @_exit
- .section .stack
-_stack: .word 1
+ .section .stack, "aw", @nobits
+_stack: .space 2
#endif
-#ifdef __H8300H__
+#if defined (__H8300H__) || defined (__H8300S__) || defined (__H8300SX__)
.section .text
.global _start
_start:
+#ifdef __NORMAL_MODE__
+ mov.w #_stack,sp
+ mov.w #_edata,r0
+ mov.w #_end,r2
+ sub.l er1,er1
+ sub.w r0,r2
+#else
mov.l #_stack,sp
mov.l #_edata,er0
mov.l #_end,er2
- sub.w r1,r1
+ sub.l er1,er1
sub.l er0,er2
+#endif
jsr @_memset
#ifdef __ELF__
- mov.l #__fini,er0
- jsr @_atexit
-#ifdef __SIMULATOR__
- jsr @0xcc
-#endif
- jsr @__init
+#ifdef __NORMAL_MODE__
+ mov.w #__fini,r0
#else
-#ifdef __SIMULATOR__
- jsr @0xcc
-#endif
- jsr @___main
+ mov.l #__fini,er0
#endif
- jsr @_main
- jsr @_exit
-
- .section .stack
-_stack: .long 1
-
-#endif
-
-#if defined (__H8300S__) || defined (__H8300SX__)
-
- .section .text
- .global _start
-_start:
- mov.l #_stack,sp
- mov.l #_edata,er0
- mov.l #_end,er2
- sub.w r1,r1
- sub.l er0,er2
- jsr @_memset
-#ifdef __ELF__
- mov.l #__fini,er0
- jsr @_atexit
+ jsr @_atexit
#ifdef __SIMULATOR__
- jsr @0xcc
+ jsr @0xcc
#endif
- jsr @__init
+ jsr @__init
#else
#ifdef __SIMULATOR__
- jsr @0xcc
+ jsr @0xcc
#endif
jsr @___main
#endif
jsr @_main
jsr @_exit
- .section .stack
-_stack: .long 1
+ .section .stack, "aw", @nobits
+#ifdef __NORMAL_MODE__
+_stack: .space 2
+#else
+_stack: .space 4
+#endif
#endif
More information about the Newlib
mailing list