ARM Hack crt1

This commit is contained in:
Jan (janneke) Nieuwenhuizen 2022-05-01 13:29:59 +02:00 committed by Jan Nieuwenhuizen
parent ef72357720
commit 5a2ec3a25d
1 changed files with 36 additions and 1 deletions

View File

@ -18,7 +18,7 @@
### You should have received a copy of the GNU General Public License
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
:_start
:XXX_start
'0' SP BP NO_SHIFT MOVE_ALWAYS ; Setup Base Pointer
push___%lr
push___%ebp
@ -54,6 +54,41 @@
pop____%ebp
ret
:_start
'0' SP BP NO_SHIFT MOVE_ALWAYS ; Setup Base Pointer
;; Prepare argv
!4 R0 ADD BP ARITH_ALWAYS ; ARGV_address = BP + 4
{R0} PUSH_ALWAYS ; Put argv on the stack
;; Prepare envp
'0' BP R0 NO_SHIFT MOVE_ALWAYS ; Address we need to load from
!0 R0 LOAD32 R0 MEMORY ; Get ARGC
!2 R0 ADD R0 ARITH_ALWAYS ; OFFSET = ARGC + 2
'0' R0 R0 '1' MOVE_ALWAYS ; OFFSET = OFFSET * WORDSIZE
'0' R0 R0 ADD BP ARITH2_ALWAYS ; ENVP_address = BP + OFFSET
{R0} PUSH_ALWAYS ; Put envp on the stack
mov____%r0,0x32 &GLOBAL_environ
;; Stack offset
!4 BP ADD BP ARITH_ALWAYS ; Fix BP
;;^~FUNCTION___init_io CALL_ALWAYS ; Setup for FILE*
!0 mov____$i8,%r0
mov____%r0,0x32 &GLOBAL___stdin
!1 mov____$i8,%r0
mov____%r0,0x32 &GLOBAL___stdout
!2 mov____$i8,%r0
mov____%r0,0x32 &GLOBAL___stderr
^~FUNCTION_main CALL_ALWAYS ; Jump right into main
SYS_exit mov____$i8,%r7
swi____$0
# Unsigned Divide
:divide
{R4} PUSH_ALWAYS ; Protect R4