Benamrouche Abdel email : draconux _at_ gmail _point_ com 2006/12/10 Note: ======== How to build linux 0.01 with gcc 1.40 ? Note : I have not tested it in a real computer, because I d'ont have an empty HDD. I use qemu, and I will explain how to run linux 0.01 in qemu. If you want to try it in directly in your HDD, then do it at your own risk. Also note : it's probably more interessant to build linux 0.01 in newer gcc 3.x or 4.x Please read documentation LINUX_0.01_GCC_4.x Needed software : =================== They are all in http://draconux.free.fr/download/os-dev/linux0.01/gcc-1.4/ gcc-1.40_patched.tgz : patched version of gcc 1.40 to be build with newer gcc patch_gcc1.40_backport : diff file, if you want to see what I have changed. gas-1.38_patched.tgz : patched version of gas patch_gas : the patch binutils-1.9-patched.tgz : needed for ld patch_binutils : the patch linux-0.01-gcc1.40.tgz : patched kernel patch_linux-0.01_gcc-1.40 userspace_l001_gcc1.40.tgz : simple program which print "bonjour" (hello in french). It's a userland program, for testing our kernel. You also need : - qemu (or bochs) (if you want to run the kernel in an emulator) , - minix fs support in your linux kernel (if you want to mount the hdd and copy on it some program) Create your virtual HDD : ========================= create a 40 MB file > dd if=/dev/zero of=hdb.img bs=1M count=40 setup Cyls, Heads, Sects and create 1 partition > losetup /dev/loop0 hdb.img > fdisk -H 4 -S 20 -C 1024 /dev/loop0 with fisk create a primary partition. Also note where begin the first partition. it's should be 20 x 512 = 10240 > losetup -d /dev/loop0 create old minix partition > losetup -o 10240 /dev/loop0 hdb.img > mkfs.minix -n 14 /dev/loop0 mount your virtual hdd > mount /dev/loop0 /mnt/mnt_hdb_img in your hdd create directory bin and usr you can write some txt file, if you want to try to read it Later you you will be able to create copy some userspace program. before executing qemu don't forget to umount first your hdd NOTE !!! : ============= linux-0.01 use old CHS : head value is coded in 6 bit so you can't have more than 64 head (1024 for cylinder, and 64 for sector) Gcc 1.40 and other old tools ============================= We need gcc 1.40 ad we don't want to conflict with newer gcc. So I sugest to create somewhere a bin and lib directory. you need gcc-1.40_patched.tgz. extract it and update Makefile to set your temporary lib and bin directory. then run : > make > make install gas-1.38_patched.tgz : update your Makefile > make a386 binutils-1.9-patched.tgz : update your makefile and execute make and make install >ls in my temporary bin directory : a386 ar as gar gas gcc gld gprof ld libconvert nm ranlib size strip as, gas, gar,gld are symlinks to a386,a386,at,ld >ls in my lib directory : gcc-cc1 gcc-cpp gcc-gnulib gcc-include Linux 0.01 kernel : ==================== In the main Makefile : --------------------- You will find (echo -n "SYSSIZE = (";ls -l tools/system | grep system \ | cut -c25-31 | tr '\012' ' '; echo "+ 15 ) / 16") > tmp.s Well the cut -c25-31 is not beautifull : it's depend on your user name !!! here it's work if your username is 5 letters (as abdel or linus) if it's not 5 letters execute ls -l tools/system | grep system and see the value you need I added 1 line OLD_BIN = /prog/osdev/linux-0.01-upd3_b/binbuild/bin Update it : this is your temporary bin directory which contain your gcc 1.40 In build_tools : ----------------- they are 2 line to update : > export PATH=/usr/bin:/usr/local/bin set here your PATH, because we will compile build.c with newer gcc > gcc-4.1 -o tools/build tools/build.c use gcc-4.1 or any other version og gcc (but not gcc 1.40) In include/linux/config.h and include/linux/hdreg.h: ---------------------------------------------------- change the HDD parameters to match with your virtual HDD In kernel/hd.c : ---------------- change this line if your HDD is master > /*0xB0 for slave, 0xA0 for master*/ > outb_p(0xB0|(drive<<4)|head,++port); I think that's all. Build your kernel with make. You should have a file Image, it's your linux 0.01 Userland program: ================= We will try to build a simple program to test our kernel print_prog.c ------------------------------------- #include #include #include void main(int argc,char* argv[]){ setsid(); (void) open("/dev/tty0",O_RDWR,0); (void) dup(0); (void) dup(0); write(1,"bonjour\n",strlen("bonjour\n")); _exit(2); } -------------------------------------- to build it, add your temporary bin directory to your PATH and then execute > gcc -o print_prog.bin print_prog.c ../../lib/lib.a -I../../include -nostdinc -nostdlib -Wall (ps : gcc -v should print 1.40) copy this file to /usr/print_prog.bin in your virtual HDD Execute your kernel: ================= qemu -fda Image -hdb hdb.img -boot a -m 8 voila, that's all. happy hacking Abdel