Floating Point

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
Typan
Posts: 17
Joined: Mon Sep 29, 2025 10:12 am
Libera.chat IRC: Typan

Floating Point

Post 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
User avatar
bellezzasolo
Member
Member
Posts: 163
Joined: Sun Feb 20, 2011 2:01 pm

Re: Floating Point

Post by bellezzasolo »

What instruction set is it using, have you enabled the necessary CPU flags?
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS
Typan
Posts: 17
Joined: Mon Sep 29, 2025 10:12 am
Libera.chat IRC: Typan

Re: Floating Point

Post 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
User avatar
bellezzasolo
Member
Member
Posts: 163
Joined: Sun Feb 20, 2011 2:01 pm

Re: Floating Point

Post 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).
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS
Typan
Posts: 17
Joined: Mon Sep 29, 2025 10:12 am
Libera.chat IRC: Typan

Re: Floating Point

Post 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
Octocontrabass
Member
Member
Posts: 6275
Joined: Mon Mar 25, 2013 7:01 pm

Re: Floating Point

Post 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.
Typan
Posts: 17
Joined: Mon Sep 29, 2025 10:12 am
Libera.chat IRC: Typan

Re: Floating Point

Post 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
Typan
Posts: 17
Joined: Mon Sep 29, 2025 10:12 am
Libera.chat IRC: Typan

Re: Floating Point

Post 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
Post Reply