123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- ## Copyright (C) 2021 Andrius Štikonas
- ## This file is part of stage0.
- ##
- ## stage0 is free software: you can redistribute it and/or modify
- ## it under the terms of the GNU General Public License as published by
- ## the Free Software Foundation, either version 3 of the License, or
- ## (at your option) any later version.
- ##
- ## stage0 is distributed in the hope that it will be useful,
- ## but WITHOUT ANY WARRANTY; without even the implied warranty of
- ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ## GNU General Public License for more details.
- ##
- ## You should have received a copy of the GNU General Public License
- ## along with stage0. If not, see <http://www.gnu.org/licenses/>.
- :_start
- RD_SP RS1_SP !-8 ADDI
- RS1_SP RS2_FP SD
- RD_FP RS1_SP MV ; Protect stack pointer
- RD_SP RS1_SP !-4180 ADDI
- RD_A0 ~GLOBAL___stdin AUIPC
- RD_A0 RS1_A0 !GLOBAL___stdin ADDI
- RS1_A0 SD
- RD_A0 ~GLOBAL___stdout AUIPC
- RD_A0 RS1_A0 !GLOBAL___stdout ADDI
- RD_T0 !1 ADDI
- RS1_A0 RS2_T0 SD
- RD_A0 ~GLOBAL___stderr AUIPC
- RD_A0 RS1_A0 !GLOBAL___stderr ADDI
- RD_T0 !2 ADDI
- RS1_A0 RS2_T0 SD
- RD_TP RS1_SP MV
- ; argc
- RD_A0 RS1_FP !8 ADDI
- RD_A0 RS1_A0 LD
- RD_SP RS1_SP !-8 ADDI
- RS1_SP RS2_A0 SD
- ; argv
- RD_A0 RS1_FP !16 ADDI
- RD_SP RS1_SP !-8 ADDI
- RS1_SP RS2_A0 SD
- ; Prepare envp
- RD_A0 RS1_FP !8 ADDI ; Address we need to load from
- RD_A0 RS1_A0 LD ; Get ARGC
- RD_A0 RS1_A0 !3 ADDI ; OFFSET = ARGC + 3
- RD_A0 RS1_A0 RS2_X3 SLLI ; OFFSET = OFFSET * WORDSIZE
- RD_A0 RS1_FP RS2_A0 ADD ; ENVP_address = RSP + OFFSET
- RD_T0 ~GLOBAL_environ AUIPC
- RD_T0 RS1_T0 !GLOBAL_environ ADDI
- RS1_T0 RS2_A0 SD
- RD_SP RS1_SP !-8 ADDI
- RS1_SP RS2_A0 SD
- RD_FP RS1_TP MV
- ; Call main function
- RD_RA $FUNCTION_main JAL
- ; Exit to kernel
- :FUNCTION_exit
- :FUNCTION__exit
- RD_A7 !93 ADDI ; Syscall for exit
- ECALL ; Exit with code in a0
|