Page 1 of 1

Floating Point

Posted: Thu Aug 06, 2026 12:40 am
by Typan
Hi,

I have a problem withmy custom build OS based on XV6 with the floating point. If I divide for example 10 / 0.75 it is going to crash.

I have tried all the options on the gcc compiler with no success. Maybe it is a problem in qemu on a Mac with a silicon chip?

Has someone an idea how to fixed it?

Kind regards,
Rober

Re: Floating Point

Posted: Thu Aug 06, 2026 5:03 am
by bellezzasolo
What instruction set is it using, have you enabled the necessary CPU flags?

Re: Floating Point

Posted: Thu Aug 06, 2026 5:58 am
by Typan
These are my flags for QEMU .

QEMUOPTS = -net none -hda xv6.img -hdb fs.img -smp cpus=$(CPUS) -m 8G $(QEMUEXTRA) -vga std -rtc base=localtime -M pc -cpu qemu64,+sse4.1,+sse4.2

Re: Floating Point

Posted: Thu Aug 06, 2026 8:26 am
by bellezzasolo
In the OS to use SSE instructions you need to enable it in CR4 (OSFXSR), and likewise for X87 you need the right CR0 (!EM).

Re: Floating Point

Posted: Fri Aug 14, 2026 5:19 am
by Typan
Hi bellezzasolo,

Thank you for your answer and it is working now. I get only a crash when I pass a float to the printf routine!

Do you know what causes this?

Kind regards,
Robert

Re: Floating Point

Posted: Fri Aug 14, 2026 11:21 am
by Octocontrabass
It's hard to say for sure without more information about the faulting instruction, but the problem might be that your stack isn't correctly aligned.

Re: Floating Point

Posted: Sat Aug 15, 2026 2:30 am
by Typan
Hi,

Is it possible for you to look at my project to see what is wrong?

Maybe it is a linker or compiler option.

Thank you in advance.

Kind regards,
Robert

https://github.com/robert-krook/xv6-master

Re: Floating Point

Posted: Sat Aug 15, 2026 9:07 am
by Typan
Hi,

I think I found it. I have added the flag -mpreferred-stack-boundary=3 to the gcc compiler and it is working now.

Thank you for the tip :-)

Kind regards,

Robert