issue printing hello world in part 3 of james molly tutorial

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
gideond
Posts: 17
Joined: Wed Oct 23, 2013 9:02 am

issue printing hello world in part 3 of james molly tutorial

Post by gideond »

So I'm following the tutorial here:
http://www.jamesmolloy.co.uk/tutorial_h ... creen.html

The toolchains and environment are in place, I'm on a CentOS machine. I am totally new conceptually to kernel development. I just need clues about the errors and I can dig up on what to do.

So uptill lesson 2 everything is all Ok. On lesson 3 - The Screen I can compile the code fine, but when I run it, there is nothing on the bochs screen. Just a blank bochs screen. No Hello World

Inside my bochsout.txt the following stick out to me, the file has a lot of repeat lines.
Here is the full file content: https://gist.github.com/gideondsouza/7120920

Code: Select all

00000032737i[CPU0 ] LOCK prefix unallowed (op1=0x2, modrm=0x00)

00012032756i[CPU0 ] math_abort: MSDOS compatibility FPU exception
00012041592i[CPU0 ] math_abort: MSDOS compatibility FPU exception
00012050689e[DEV  ] read from port 0x0000 with len 2 returns 0xffff
00012051026i[CPU0 ] math_abort: MSDOS compatibility FPU exception
00577823000i[     ] cpu loop quit, shutting down simulator
00577823000i[CPU0 ] CPU is in real mode (active)
00577823000i[CPU0 ] CS.mode = 16 bit
To get the code to compile and run till chapter 2 I changed my bochrc.txt like this (changed address and path to images):

Code: Select all

megs: 32
romimage: file=/usr/local/share/bochs/BIOS-bochs-latest, address=0xe0000
vgaromimage: file=/usr/local/share/bochs/VGABIOS-elpin-2.40
floppya: 1_44=/dev/loop0, status=inserted
boot: a
log: bochsout.txt
mouse: enabled=0
clock: sync=realtime
cpu: ips=1000001
Also, I changed this line in the Makefile since I'm on a x64 machine:

Code: Select all

ASFLAGS=-felf64
Any pointers would be extremely appreciated.
kfreezen
Member
Member
Posts: 46
Joined: Tue Jul 21, 2009 11:36 am

Re: issue printing hello world in part 3 of james molly tuto

Post by kfreezen »

AFAIK, probably the main reason it isn't working for you is the fact that you are compiling for x86_64, when you should be compiling for i386.

Try changing your ASFLAGS to

Code: Select all

-felf32
Add this to your CFLAGS

Code: Select all

-m32
And add this to your linker flags (LDFLAGS, I believe it is)

Code: Select all

-melf_i386
The -felf32 and -m32 tell your assembler and your compiler to compile your code into 32-bit ELF objects.
The -melf_i386 tells your linker to expect 32-bit ELF objects, and to link them into a 32-bit ELF binary.
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: issue printing hello world in part 3 of james molly tuto

Post by sortie »

Better yet - realize that whatever 'gcc' you are using doesn't produce executables for your OS, but rather executables for CentOS. This causes all sorts of problems as your build environment leaks into your OS and you often need all sorts of weird compilation switches to fruitlessly beat it into submission.

The real solution is to use a special gcc that understands it is doing something special and that the platform it targets is not the current one, but rather something new and special you are about to create. This cross-compiler will run on your CentOS machine, but produce executables for your custom operating system (which possibly even uses another CPU type than you do).

The osdev wiki has a good tutorial how to make an absolutely minimal kernel using a cross-compiler and I strongly recommend you use it rather than JamesM's old tutorial as it has been community reviewed and has the current recommendations. You can view the tutorial here: http://wiki.osdev.org/Bare_Bones. You'll need to compile a cross-compiler first, which may take some time, but which is a very valuable experience.

Note that JamesM's old tutorial has some really bad advise at some times (unless it has been fixed), but if you remain sceptical, I recommend you follow it using Bare Bones as a base.
gideond
Posts: 17
Joined: Wed Oct 23, 2013 9:02 am

Re: issue printing hello world in part 3 of james molly tuto

Post by gideond »

Thank you guys for your replies.

@kfreezen I made changes like you suggested, and it still just shows a plain black screen.

@sortie What you said makes a lot of sense. I will read the Bare Bones tutorial you linked to right away.

The specific reason I choose James Molly's tutorial was because it's a get your hands dirty tutorial but doesn't stop at Hello World. I really want o go upto the point of memory management and schedulers. It's hard to then switch to an entirely new tutorial when you're a beginner.

I started reading the Tanenbaum book, but it's much more conceptual and doesn't let you get your hands dirty.

So I'm thinking :
-- Bare Bones Tutorial
-- Study MikeOS? Then move to the Tanenbaum book and Minix3? (Should I maybe get minix2?)
-- OR get better at nasm (This is quite a weak point for me)
kfreezen
Member
Member
Posts: 46
Joined: Tue Jul 21, 2009 11:36 am

Re: issue printing hello world in part 3 of james molly tuto

Post by kfreezen »

Come to think of it: Does bochs throw any errors? It seems like either bochs or grub should display some sort of error if your kernel file was the problem.

Also, if you have qemu installed, you could do

Code: Select all

qemu-system-i386 -kernel your_kernel_name_here
and see if anything comes up.
gideond
Posts: 17
Joined: Wed Oct 23, 2013 9:02 am

Re: issue printing hello world in part 3 of james molly tuto

Post by gideond »

thanks for your reply @kfreezen
-kernel your_kernel_name_here
Do you mean

Code: Select all

your_kernel_name
should be my executable file that I generate right?
kfreezen
Member
Member
Posts: 46
Joined: Tue Jul 21, 2009 11:36 am

Re: issue printing hello world in part 3 of james molly tuto

Post by kfreezen »

Yes, that's right.
gideond
Posts: 17
Joined: Wed Oct 23, 2013 9:02 am

Re: issue printing hello world in part 3 of james molly tuto

Post by gideond »

Hey @kfreezen it worked.

I started building a cross compiler and got side tracked. But finally enough, running it inside qemu-system-i386 worked.

Thanks very much.
Post Reply