Following James's Kernel Tutorials on Mac OS X
Posted: Thu Jan 10, 2013 1:54 pm
I just started with kernel development and James's kernel development tutorials are great, easy to read and easy to follow, many thanks for that. However, the makefiles, linker scripts etc.. are all designed to work on linux. I used to do the development on my linux virtual machine. However I no longer found that statisfying so I thought I'd try doing this on mac os x. It took a lot of work to make everything work but now I did. I here by share what I've learned. This might be useful for others.
The first problem is that Mac OS X executables have Mach-O header and Linux executables have an ELF header. Also, Mac OS X is a 64-bit operating system and James's tutorials are based on x86. The linker that is installed by default is not the GNU Linker and thus does not support various options such as -T.
To fix this we should first install Mac Ports to make installing some ports a bit easier. Mac ports can be found here:
http://www.macports.org/
Now we need to install i386-elf-gcc and i386-elf-ld by issuing the following command:
Note: These are installed to /opt/local/bin
We now need to modify the makefile:
The second problem is that the losetup command used in the two bash scripts is not available on Mac OS X. Update update_image.sh as following:
And run_bochs.sh:
Now you might have noticed the use of fuse-ext2. Mac OS X does not come with ext2 drivers by default (And the floppy from Jame's tutorial is formatted with ext2). I used fuse-ext2 from here:
Now there's another problem because read-write support is not enabled by default for fuse-ext2, to fix this open /System/Library/Filesystems/fuse-ext2.fs/fuse-ext2.util in any text editor and scroll down to line 207:
and change this to:
The final thing to do is update the bochsrc.txt:
However make sure you have BIOS-bochs-latest and VGABIOS-elpin-2.40 in those locations. Big chance you don't have them, you can download the them from git hub:
https://github.com/larsr/bochs/tree/master/bios
If you are using Mac OS X Mountain Lion (10. you should install XQuartz as a replacement for x-11:
I hope this information is useful to somebody. On a site note to James, the bochsrc.txt configuration used in your tutorial is a bit outdated.
Instead of using /dev/loop0 you could also refer directly to the floppy image. Also vgaromimage: must start with file=. And megs is outdated and is
replaced by memory.
The first problem is that Mac OS X executables have Mach-O header and Linux executables have an ELF header. Also, Mac OS X is a 64-bit operating system and James's tutorials are based on x86. The linker that is installed by default is not the GNU Linker and thus does not support various options such as -T.
To fix this we should first install Mac Ports to make installing some ports a bit easier. Mac ports can be found here:
http://www.macports.org/
Now we need to install i386-elf-gcc and i386-elf-ld by issuing the following command:
Code: Select all
sudo port install i386-elf-gcc i386-elf-ld
We now need to modify the makefile:
Code: Select all
SOURCES=boot.o main.o
CC=i386-elf-gcc-4.3.2
CFLAGS=-nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -c
LDFLAGS=-Tlink.ld -melf_i386
ASFLAGS=-felf
all: $(SOURCES) link
clean:
-rm *.o kernel
link:
i386-elf-ld $(LDFLAGS) -o kernel $(SOURCES)
.s.o:
nasm $(ASFLAGS) $<
Code: Select all
loc=`hdid -nomount ../bin/floppy.img`
`sudo mount -t fuse-ext2 $loc /mnt2`
cp ../bin/kernel /mnt2/kernel
umount /mnt2
Code: Select all
loc=`hdid -nomount ../bin/floppy.img`
`sudo mount -t fuse-ext2 $loc /mnt2`
sudo bochs -f bochsrc.txt
Code: Select all
http://sourceforge.net/projects/fuse-ext2/
Code: Select all
OPTIONS="auto_xattr,defer_permissions"
Code: Select all
OPTIONS="auto_xattr,defer_permissions,rw+"
Code: Select all
memory: guest=32, host=32
romimage: file=/usr/share/bochs/BIOS-bochs-latest
vgaromimage: file=/usr/share/bochs/VGABIOS-elpin-2.40
floppya: 1_44=floppy.img, status=inserted
boot: a
log: bochsout.txt
mouse: enabled=0
clock: sync=realtime
cpu: ips=500000
https://github.com/larsr/bochs/tree/master/bios
If you are using Mac OS X Mountain Lion (10. you should install XQuartz as a replacement for x-11:
Code: Select all
http://xquartz.macosforge.org/landing/
Instead of using /dev/loop0 you could also refer directly to the floppy image. Also vgaromimage: must start with file=. And megs is outdated and is
replaced by memory.