2018-06-22 02:33:50 +01:00
|
|
|
#! /usr/bin/env bash
|
2018-10-18 00:27:06 +01:00
|
|
|
## Copyright (C) 2017 Jeremiah Orians
|
|
|
|
## This file is part of M2-Planet.
|
|
|
|
##
|
|
|
|
## M2-Planet 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.
|
|
|
|
##
|
|
|
|
## M2-Planet 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 M2-Planet. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2018-09-01 00:02:55 +01:00
|
|
|
set -eux
|
|
|
|
stage0_PREFIX=${stage0_PREFIX-../stage0}
|
|
|
|
|
2019-02-23 16:05:20 +00:00
|
|
|
[ -e bin/M2-Planet ] && rm bin/M2-Planet
|
|
|
|
|
2018-09-01 00:02:55 +01:00
|
|
|
# Refresh stage0's M2-Planet_x86.c
|
|
|
|
# To execute this block ./bootstrap.sh refresh
|
|
|
|
if [ "refresh" = "${1-NOPE}" ]
|
|
|
|
then
|
|
|
|
# Create header to prevent confusion
|
|
|
|
{
|
|
|
|
cat <<-EOF
|
|
|
|
## This file was generated by running:
|
2019-02-23 20:08:59 +00:00
|
|
|
## cat functions/file.c functions/malloc.c functions/calloc.c functions/exit.c functions/match.c -f functions/in_set.c functions/numerate_number.c functions/file_print.c functions/string.c cc.h cc_reader.c cc_strings.c cc_types.c cc_core.c cc.c >| ../stage0/stage3/M2-Planet_x86.c
|
2018-09-01 00:02:55 +01:00
|
|
|
## inside M2-Planet's repo
|
|
|
|
|
|
|
|
EOF
|
|
|
|
} >| header
|
|
|
|
|
|
|
|
# Update the C code in stage0's x86 bootstrap
|
|
|
|
cat header \
|
|
|
|
functions/file.c \
|
|
|
|
functions/malloc.c \
|
|
|
|
functions/calloc.c \
|
|
|
|
functions/exit.c \
|
|
|
|
functions/match.c \
|
2019-02-23 20:08:59 +00:00
|
|
|
functions/in_set.c \
|
2018-09-01 00:02:55 +01:00
|
|
|
functions/numerate_number.c \
|
|
|
|
functions/file_print.c \
|
|
|
|
functions/string.c \
|
|
|
|
cc.h \
|
|
|
|
cc_reader.c \
|
|
|
|
cc_strings.c \
|
|
|
|
cc_types.c \
|
|
|
|
cc_core.c \
|
|
|
|
cc.c >| $stage0_PREFIX/stage3/M2-Planet_x86.c
|
|
|
|
|
|
|
|
# Clean up temp header
|
|
|
|
rm header
|
|
|
|
|
|
|
|
{
|
|
|
|
# Create header to prevent confusion
|
|
|
|
cat <<-EOF
|
|
|
|
# This file was generated by running:
|
|
|
|
# ./bin/vm --rom roms/cc_x86 --memory 4M --tape_01 stage3/M2-Planet_x86.c --tape_02 ../M2-Planet/seed.M1
|
|
|
|
# In stage0
|
|
|
|
EOF
|
|
|
|
} >| preseed1
|
|
|
|
|
|
|
|
# Create the seed
|
|
|
|
$stage0_PREFIX/bin/vm --rom $stage0_PREFIX/roms/cc_x86 \
|
|
|
|
--memory 4M \
|
|
|
|
--tape_01 $stage0_PREFIX/stage3/M2-Planet_x86.c \
|
|
|
|
--tape_02 preseed2
|
|
|
|
|
|
|
|
# Combine to final seed
|
|
|
|
cat preseed1 preseed2 >| seed.M1
|
|
|
|
|
|
|
|
# Cleanup preseed values
|
|
|
|
rm preseed1 preseed2
|
|
|
|
fi
|
|
|
|
|
2018-06-22 02:33:50 +01:00
|
|
|
|
|
|
|
# Make the required bin directry
|
|
|
|
[ -d bin ] || mkdir bin
|
|
|
|
|
2018-08-26 21:34:31 +01:00
|
|
|
# Build debug footer
|
|
|
|
blood-elf -f seed.M1 \
|
|
|
|
-o bin/seed-footer.M1 || exit 1
|
|
|
|
|
2018-06-22 02:33:50 +01:00
|
|
|
# Macro assemble with libc written in M1-Macro
|
|
|
|
M1 -f test/common_x86/x86_defs.M1 \
|
2019-03-09 16:56:16 +00:00
|
|
|
-f test/common_x86/libc-core.M1 \
|
2018-06-22 02:33:50 +01:00
|
|
|
-f seed.M1 \
|
2018-08-26 21:34:31 +01:00
|
|
|
-f bin/seed-footer.M1 \
|
2018-06-22 02:33:50 +01:00
|
|
|
--LittleEndian \
|
2019-02-23 16:05:20 +00:00
|
|
|
--architecture x86 \
|
2018-08-26 21:34:31 +01:00
|
|
|
-o bin/seed.hex2 || exit 2
|
2018-06-22 02:33:50 +01:00
|
|
|
|
|
|
|
# Resolve all linkages
|
2018-08-26 21:34:31 +01:00
|
|
|
hex2 -f test/common_x86/ELF-i386-debug.hex2 \
|
2018-06-22 02:33:50 +01:00
|
|
|
-f bin/seed.hex2 \
|
|
|
|
--LittleEndian \
|
2019-02-23 16:05:20 +00:00
|
|
|
--architecture x86 \
|
2018-06-22 02:33:50 +01:00
|
|
|
--BaseAddress 0x8048000 \
|
2019-02-23 16:05:20 +00:00
|
|
|
-o bin/M2-Planet-seed \
|
2018-06-22 02:33:50 +01:00
|
|
|
--exec_enable || exit 2
|
2019-02-23 16:05:20 +00:00
|
|
|
|
|
|
|
# self-host
|
2019-03-10 01:22:29 +00:00
|
|
|
./test/test100/hello.sh
|