Pure FB Runtime Library (in progress)
Re: Pure FB Runtime Library (in progress)
Okay next issue:
in the file, win32/hinit.c
There is a lot of stuff I am not sure how to handle. It includes asm code, the float.h file which I can't find an analog to, and the _controlfb function from the float.h file.
Any suggestions?
in the file, win32/hinit.c
There is a lot of stuff I am not sure how to handle. It includes asm code, the float.h file which I can't find an analog to, and the _controlfb function from the float.h file.
Any suggestions?
Re: Pure FB Runtime Library (in progress)
Ajusting the FPUControlWord could be implemented like this:This should compile for both x86 and x64.
I'd say forget about the rest that does the same (float.h, _controlfp and related things; I'm not talking about the locking stuff).
For more information see:
x86/x68_64: https://sourceware.org/git/?p=glibc.git ... _control.h
ARM: https://sourceware.org/git/?p=glibc.git ... _control.h
Code: Select all
dim as ushort FPUControlWord
' Get FPU control word
asm fstcw [FPUControlWord]
' Set 64-bit and round to nearest
FPUControlWord = (FPUControlWord and &HF0FF) or &H0300
' Write back FPU control word
asm fldcw [FPUControlWord]
I'd say forget about the rest that does the same (float.h, _controlfp and related things; I'm not talking about the locking stuff).
For more information see:
x86/x68_64: https://sourceware.org/git/?p=glibc.git ... _control.h
ARM: https://sourceware.org/git/?p=glibc.git ... _control.h
Re: Pure FB Runtime Library (in progress)
But x86_64 codegens usually use SSE2 regs for floating point (as per abi). Afaik MXCSR handles exceptions for those.
Re: Pure FB Runtime Library (in progress)
Hmm...marcov wrote:But x86_64 codegens usually use SSE2 regs for floating point (as per abi). Afaik MXCSR handles exceptions for those.
For now I have done this:
Code: Select all
sub fb_hInit( )
#ifdef HOST_X86
dim as ushort FPUControlWord
' Get FPU control word
asm fstcw [FPUControlWord]
' Set 64-bit and round to nearest
FPUControlWord = (FPUControlWord and &HF0FF) or &H0300
' Write back FPU control word
asm fldcw [FPUControlWord]
#elseif defined(HOST_X86_64)
dim as ushort FPUControlWord
' Get FPU control word
asm fstcw [FPUControlWord]
' Set 64-bit and round to nearest
FPUControlWord = (FPUControlWord and &HF0FF) or &H0300
' Write back FPU control word
asm fldcw [FPUControlWord]
#endif
#ifdef ENABLE_MT
InitializeCriticalSection(@__fb_global_mutex)
InitializeCriticalSection(@__fb_string_mutex)
InitializeCriticalSection(@__fb_mtcore_mutex)
InitializeCriticalSection(@__fb_graphics_mutex)
#endif
memset( @__fb_con, 0, sizeof( FB_CONSOLE_CTX ) )
end sub
Thank you both for your insight!
Re: Pure FB Runtime Library (in progress)
So I am going to take a short break on my work on this. I have to work on some other projects to refill my enthusiasm meter. I will come back to this after a couple of weeks.
I really want to see this through, so it will not be a long break. If anyone wants to help out like TeeEmCee did, please feel free.
I really want to see this through, so it will not be a long break. If anyone wants to help out like TeeEmCee did, please feel free.
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Pure FB Runtime Library (in progress)
On that note, just to say, GitHub makes it really easy to fork the project, edit a file, and submit back a pull request.Imortis wrote:If anyone wants to help out like TeeEmCee did, please feel free.
I've just done one here, all with just a web browser*:
https://github.com/ImortisInglorian/fbrtLib/pull/3
(*I did do a quick paste/run of the changes locally, to ensure they compiled and ran.)
Re: Pure FB Runtime Library (in progress)
Thanks! I will merge the change shortly.counting_pine wrote:...I've just done one here, all with just a web browser* ...
Re: Pure FB Runtime Library (in progress)
Okay I am back and getting the following error:
Any suggestions?
I have no idea what is going on here, and the compiler crashes, which is also bad.\fbrtLib\win32\io_input.bas(320) error 57: Type mismatch, at parameter 1 of FB_STRALLOCTEMPDESCZEX() in 'fb_hConsolePostKey( KEY_QUIT, @rec )'
Aborting due to runtime error 12 ("segmentation violation" signal)
Any suggestions?
Re: Pure FB Runtime Library (in progress)
Code: Select all
#print typeof(@FB_STRALLOCTEMPDESCZEX)
Dim As String s = "function"
Print "'" & FB_STRALLOCTEMPDESCZEX(Strptr(s), 5) & "'"
Print "'" & FB_STRALLOCTEMPDESCZEX(s, 5) & "'"
Sleep
Re: Pure FB Runtime Library (in progress)
Okay. That did not show me the problem, but it did point me down the road to the problem. The KEY_QUIT constant was using a macro on a temporary string. Because of lots of things, that broke and I had to change it to the ASCII code for the character instead of using a temp string.
Re: Pure FB Runtime Library (in progress)
Also, does FB have a way to do something equivilant to C's "atexit"?
Re: Pure FB Runtime Library (in progress)
Module destructor?
Re: Pure FB Runtime Library (in progress)
A little bit off-topic here, but could you provide some sample code (or - ideally - some code pattern) that causes the compiler crash so that it could be debugged & fixed?Imortis wrote:[...] and the compiler crashes, which is also bad.
Note that the execution order is probably different, in case there are multiple uses of "atexit" (and in case the execution order matters).fxm wrote:Module destructor?
Re: Pure FB Runtime Library (in progress)
Hmmm... That could work, but the particular sub should only be called under a particular circumstance, and making a destructor module will make the code ALWAYS run.fxm wrote:Module destructor?
I am trying not to re-write any code right now, just translate, but that may need a simple re-write to BE translated.
If you grab the latest from git on this, you can reproduce the error. As to making a small snippet, I have no idea if that is even possible. It was happening when I compiled the project, so all of the source files at once. I CAN tell you that once I change it to no longer use temp strings there the crash stopped.St_W wrote:A little bit off-topic here, but could you provide some sample code (or - ideally - some code pattern) that causes the compiler crash so that it could be debugged & fixed?
Re: Pure FB Runtime Library (in progress)
New question: win32/sys_portio.c has these lines in it:
I understand that these are inline asm, but I am unfamiliar with syntax being used? What would the FB equivalent be?
Code: Select all
__asm__ volatile ("inb %1, %0" : "=a" (value) : "d" (port));
__asm__ volatile ("outb %0, %1" : : "a" (value), "d" (port));