Pure FB Runtime Library (in progress)

User projects written in or related to FreeBASIC.
Post Reply
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Post by Imortis »

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?
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Pure FB Runtime Library (in progress)

Post by St_W »

Ajusting the FPUControlWord could be implemented like this:

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]
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
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Pure FB Runtime Library (in progress)

Post by marcov »

But x86_64 codegens usually use SSE2 regs for floating point (as per abi). Afaik MXCSR handles exceptions for those.
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Post by Imortis »

marcov wrote:But x86_64 codegens usually use SSE2 regs for floating point (as per abi). Afaik MXCSR handles exceptions for those.
Hmm...

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
If a better way to handle 64bit is proposed, I can just replace the current block.

Thank you both for your insight!
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Post by Imortis »

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.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Pure FB Runtime Library (in progress)

Post by counting_pine »

Imortis wrote:If anyone wants to help out like TeeEmCee did, please feel free.
On that note, just to say, GitHub makes it really easy to fork the project, edit a file, and submit back a pull request.
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.)
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Post by Imortis »

counting_pine wrote:...I've just done one here, all with just a web browser* ...
Thanks! I will merge the change shortly.
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Post by Imortis »

Okay I am back and getting the following error:
\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)
I have no idea what is going on here, and the compiler crashes, which is also bad.

Any suggestions?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Pure FB Runtime Library (in progress)

Post by fxm »

Code: Select all

#print typeof(@FB_STRALLOCTEMPDESCZEX)

Dim As String s = "function"
Print "'" & FB_STRALLOCTEMPDESCZEX(Strptr(s), 5) & "'"
Print "'" & FB_STRALLOCTEMPDESCZEX(s, 5) & "'"

Sleep
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Post by Imortis »

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.
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Post by Imortis »

Also, does FB have a way to do something equivilant to C's "atexit"?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Pure FB Runtime Library (in progress)

Post by fxm »

Module destructor?
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Pure FB Runtime Library (in progress)

Post by St_W »

Imortis wrote:[...] and the compiler crashes, which is also bad.
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?
fxm wrote:Module destructor?
Note that the execution order is probably different, in case there are multiple uses of "atexit" (and in case the execution order matters).
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Post by Imortis »

fxm wrote:Module destructor?
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.

I am trying not to re-write any code right now, just translate, but that may need a simple re-write to BE translated.
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?
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.
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Pure FB Runtime Library (in progress)

Post by Imortis »

New question: win32/sys_portio.c has these lines in it:

Code: Select all

__asm__ volatile ("inb %1, %0" : "=a" (value) : "d" (port));
__asm__ volatile ("outb %0, %1" : : "a" (value), "d" (port));
I understand that these are inline asm, but I am unfamiliar with syntax being used? What would the FB equivalent be?
Post Reply