Porting gcc :SSE2 problems (invalid opcode): How to disable?

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
Haoud
Member
Member
Posts: 31
Joined: Wed Aug 10, 2016 3:07 am
Libera.chat IRC: Haoud

Porting gcc :SSE2 problems (invalid opcode): How to disable?

Post by Haoud »

Hello every one,
I'm ported GCC to my OS with my toolchain i386-haoudos. GCC seems to work correctly( i can use gcc --version in my os).But when i try to compile a file, cc1 throws an invalid opcode because it try to use sse2 instructions.My OS doesn't support sse2, only i387 fpu. How i can disable sse2 instruction for all gcc code?
The invalide opcode is in libcpp/lex.c/search-line-sse2
If you need more informations, don't hesitate to ask me.
Thank you

Sorry for my english but i'm french
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Porting gcc :SSE2 problems (invalid opcode): How to disa

Post by Korona »

Supporting SSE in your OS probably requires less SLoC than your post. Instead of figuring out how to disable SSE in gcc (and all of its libraries) just enable SSE.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
Haoud
Member
Member
Posts: 31
Joined: Wed Aug 10, 2016 3:07 am
Libera.chat IRC: Haoud

Re: Porting gcc :SSE2 problems (invalid opcode): How to disa

Post by Haoud »

OK. How i can enable SSE and support them (especially for the scheduler) ?
User avatar
Mikaku
Member
Member
Posts: 43
Joined: Sat Jun 25, 2016 8:29 am
Libera.chat IRC: Mikaku
Location: Catalonia
Contact:

Re: Porting gcc :SSE2 problems (invalid opcode): How to disa

Post by Mikaku »

I was also porting (now already successfully ported) GCC and Binutils to my OS, and I had _exactly_ the same problem, it took me some weeks to fix it.

Indeed the problem is in libcpp/lex.c file, and I solved it just including an exception for my OS (fiwix) in the line 277. I'm using GCC v4.7.1 so if you are using a different version the line number might vary.

Original line:

Code: Select all

#if (GCC_VERSION >= 4005) && (defined(__i386__) || defined(__x86_64__)) && !(defined(__sun__) && defined(__svr4__))
Patched line which includes my OS:

Code: Select all

#if (GCC_VERSION >= 4005) && (defined(__i386__) || defined(__x86_64__)) && !(defined(__sun__) && defined(__svr4__)) && !defined(__fiwix__)
So now, ported GCC v4.7.1 is able to compile natively in my OS and produce pure i386 executables:

Code: Select all

$ gcc -v
Using built-in specs.
COLLECT_GCC=./gcc
COLLECT_LTO_WRAPPER=./../libexec/gcc/i386-fiwix/4.7.1/lto-wrapper
Target: i386-fiwix
Configured with: ../gcc-4.7.1/configure --host=i386-fiwix --target=i386-fiwix --prefix=/usr --with-arch=i386 -with-buid-sysroot=/home/mikaku/fiwix/sysroot --with-sysroot=/ --with-gmp=/home/mikaku/fiwix/sysroot --with-mpfr=/home/mikaku/fiwix/sysroot --with-mpc=/home/mikaku/fiwix/sysroot --enable-languages=c,c++ --disable-lto --disable-shared --disable-multilib --with-newlib --disable-nls --disable-werror
Thread model: single
gcc version 4.7.1 (GCC) 
I hope that helped you.
Last edited by Mikaku on Fri Nov 24, 2017 5:37 pm, edited 1 time in total.
Haoud
Member
Member
Posts: 31
Joined: Wed Aug 10, 2016 3:07 am
Libera.chat IRC: Haoud

Re: Porting gcc :SSE2 problems (invalid opcode): How to disa

Post by Haoud »

Yes, it's work !! (But i have an another problem :( ).
Thank you very much
Post Reply