My system is Windows XP ( yeah, I know that it's old but my computer can't run newer software ).
I have two VM's (on Virtual Box): first with Linux and second with my OS.
I write code on Windows, save it into shared folder with Linux VM. Next I compile it on first VM using bash script (look down) and I create bootable image using
grub-mkrescue. Finally I mount it to second VM and run it.
It was working properly until I upgraded binutils (to v2.22). When I try to link everything into one binary ld crashes with segfault. But when I link to elf format, it doesn't crash
I also tried to linkage to elf format and later convert it into binary using objcopy, but when run it i does nothing (black screen) (earlier it shows messages from system loading)
My script:
Code: Select all
#!/bin/bash
#### data
# kod C++
cppSrc=( "kernel.cpp" "Driv/interrupt.cpp" "Driv/textmode.cpp" "API/string.cpp" "Driv/keyboard.cpp" "Driv/memory.cpp" "Driv/ata.cpp" "Shell/shell.cpp" "Int/systemInts.cpp" "Int/exc.cpp" "gdt.cpp" "Driv/PIT.cpp" "Driv/filesystem.cpp" "Driv/fatFs/ff.c" "Driv/bget/bget.c" )
cppOut=( "kernel.o" "Driv/interrupt.o" "Driv/textmode.o" "API/string.o" "Driv/keyboard.o" "Driv/memory.o" "Driv/ata.o" "Shell/shell.o" "Int/systemInts.o" "Int/exc.o" "gdt.o" "Driv/PIT.o" "Driv/filesystem.o" "Driv/fatFs/ff.o" "Driv/bget/bget.o" )
gccOpts="-c -nostdinc -fomit-frame-pointer -O2 -std=c++11 -I API/"
# asm
asmSrc=("boot.asm" "API/asmAPI.asm" "Int/intDefs.asm" "Int/exc.asm" )
asmOut=("boot.o" "API/asmAPI.o" "Int/intDefs.o" "Int/excasm.o" )
# linking
linkScript="link.ld"
# wyjście
isoFolder="distr"
out="distr/boot/grub/myos.bin"
outIso="MyOS.iso"
temp="temp.run"
#### executing
# asm
for((count=0; count<${#asmSrc[*]}; count++))
do
if [ -f ${asmOut[$count]} ]
then
# skipping
else
nasm -f elf -o ${asmOut[$count]} ${asmSrc[$count]}
fi
done
# c++
for((count=0; count<${#cppSrc[*]}; count++))
do
if [ -f ${cppOut[$count]} ]
then
echo -e "\e[34mAlready compiled. Skipping\e[1m" ${cppSrc[$count]} "\e[0m"
else
echo -e "Kompilacja: \e[1m" ${cppSrc[$count]} "\e[0m"
if g++ -o ${cppOut[$count]} ${cppSrc[$count]} $gccOpts; then
echo -e "\e[34mCompiled\e[1m" ${cppSrc[$count]} "\e[0m"
else
exit 1;
fi
fi
done
ld -T $linkScript -o $temp ${asmOut[*]} ${cppOut[*]}
objcopy -O binary -j .text $temp $out
# clean objs
for((count=0; count<${#asmOut[*]}; count++))
do
rm ${asmOut[$count]}
done
for((count=0; count<${#cppOut[*]}; count++))
do
rm ${cppOut[$count]}
done
grub-mkrescue --output=$outIso $isoFolder