Re: [fpc-pascal] Interface with NASM
Strange, I took a look and no idea why it doesn't work with the linked .o file =) Maybe disassembling what nasm produces could show something, but I don't know which GNU tool could be used for that... The following program works for me: program driver; uses asmio; {$ASMMODE att} procedure tes2; pascal; begin printc(Char(65)); end; procedure tes; assembler; [alias:'tes']; asm movl $65,%eax push %eax call printc end; begin tes2; tes; end. And here is the assembler generated: fpc -s driver.pas edit driver.s .text .align 4 .globl _P$DRIVER_TES2 _P$DRIVER_TES2: pushl %ebp movl%esp,%ebp subl$24,%esp movl%ebx,-12(%ebp) movl%esi,-8(%ebp) movl%edi,-4(%ebp) movl$65,%eax movl%eax,(%esp) callL_ASMIO_PRINTC$CHAR$stub movl-12(%ebp),%ebx movl-8(%ebp),%esi movl-4(%ebp),%edi leave ret .text .align 4 .globl _P$DRIVER_TES _P$DRIVER_TES: .reference tes .globl tes tes: .reference _P$DRIVER_TES subl$12,%esp movl$65,%eax pushl %eax call_ASMIO_PRINTC$CHAR addl$12,%esp ret -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: Interface with NASM
> It crashes inside printc apparently when getting the parameter That's it! That's exactly what happened. > Maybe disassembling what nasm produces could show > something, but I don't know which GNU tool could be used for that... ndisasm from nasm package, or objdump can also do that. > The following program works for me Just by changing to ATT syntax? Weird... -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Interface-with-NASM-tp2838671p2841994.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] "Error: Impossible operator overload" ...why?
Hi, I'm using FPC 2.4.3 Why is the following operator overload not allowed? Sometimes TfpgColor can be a RRGGBB value (eg: clRed), and sometimes it is an index to a color palette (eg: clWindowBackground). So I want to do comparisons between two such colors. The compiler error I get: /programming/fpgui/src/corelib/fpg_main.pas(414,58) Error: Impossible operator overload The types are defined as follows: type TfpgColor = type longword; TFPColor = record Red: word; Green: word; Blue: word; Alpha: word; end; ... now the unit with the compiler error ... interface section: operator = (const AColor1, AColor2: TfpgColor) b: Boolean; implementation section: operator = (const AColor1, AColor2: TfpgColor) b: Boolean; var c1, c2: TFPColor; begin c1 := fpgColorToFPColor(AColor1); c2 := fpgColorToFPColor(AColor2); b := (c1.Red = c2.Red) and (c1.Green = c2.Green) and (c1.Blue = c2.Blue) and (c1.Alpha = c2.Alpha); end; -- Regards, - Graeme - ___ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] "Error: Impossible operator overload" ...why?
On 16 Sep 2010, at 11:26, Graeme Geldenhuys wrote: type TfpgColor = type longword; [snip] operator = (const AColor1, AColor2: TfpgColor) b: Boolean; You cannot overload (or rather change the meaning of) operators for operator/type combinations that are natively handled by the compiler. "type longword" is handled the same as a regular longword by the compiler as far as all operators are concerned. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: Interface with NASM
On Thu, Sep 16, 2010 at 11:10 AM, leledumbo wrote: > Just by changing to ATT syntax? Weird... No, I removed the function header: push ebp mov ebp,esp And function footer: leave ret Because FPC automatically adds them, putting another header was the cause of the crash in my code. But this doesn't seam to be the case with the nasm object file. -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface with NASM
On 14 Sep 2010, at 08:35, leledumbo wrote: segment .text global tes tes: push ebp mov ebp,esp push 65 Check that this puts a 32 bit value on the stack rather than an 8 bit or 16 bit one. You may need "push dword 65" or something like that. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] "Error: Impossible operator overload" ...why?
On 16 September 2010 11:31, Jonas Maebe wrote: > > You cannot overload (or rather change the meaning of) operators for > operator/type combinations that are natively handled by the compiler. "type > longword" is handled the same as a regular longword by the compiler as far > as all operators are concerned. OK, I thought the TfpgColor type will act as a new type, and operator overloading could be possible. I guess I was wrong. :-/ Is there any way to tell the compiler to treat TfpgColor as a new type? -- Regards, - Graeme - ___ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] "Error: Impossible operator overload" ...why?
On 16 Sep 2010, at 11:44, Graeme Geldenhuys wrote: Is there any way to tell the compiler to treat TfpgColor as a new type? Declare it as a record with a single longint field. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface with NASM
On Thu, Sep 16, 2010 at 11:44 AM, Jonas Maebe wrote: > Check that this puts a 32 bit value on the stack rather than an 8 bit or 16 > bit one. You may need "push dword 65" or something like that. I can add that my gdb said that the stack was missaligned, so this has a high probability of being the case. -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: Interface with NASM
> Check that this puts a 32 bit value on the stack rather than an 8 bit > or 16 bit one. You may need "push dword 65" or something like that. I've tried that. Even a (stupid) trick like this: section .data charA db 'A' section .text global tes tes: push ebp mov ebp,esp mov eax,charA mov dword eax,[eax] push eax call printc leave ret -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Interface-with-NASM-tp2838671p2842117.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface with NASM
Pushes/pops on x86/x86_64 are always word sized Den 16-09-2010 11:44, Jonas Maebe skrev: On 14 Sep 2010, at 08:35, leledumbo wrote: segment .text global tes tes: push ebp mov ebp,esp push 65 Check that this puts a 32 bit value on the stack rather than an 8 bit or 16 bit one. You may need "push dword 65" or something like that. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface with NASM
On 16 Sep 2010, at 13:26, Jeppe Johansen wrote: Pushes/pops on x86/x86_64 are always word sized push/pop can at least also be 16 bit in 32 bit mode (or 32 bit in 16 bit mode). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface with NASM
On 14 Sep 2010, at 08:35, leledumbo wrote: build command: nasm -f coff test.asm fpc asmio.pas fpc -o test driver.pas As you can see, I didn't use any optimizations because AFAIR FPC would change parameter passing mechanism when a certain optimizations are performed. That's not the case. The only situation in which the compiler would be allowed to do that is for routines defined in the main program or in the implementation section of a unit that are not manually declared as public/export either (in your case they're both in the interface of a unit and manually declared as public), and for safety that maybe also are not called from inline assembler blocks (but it doesn't do that at this time). Of course if it works I won't ask here, but it doesn't. I got access violation instead. It works fine under linux (if you replace the "-f coff" with "-f elf"). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface with NASM
On Thu, Sep 16, 2010 at 3:19 PM, Jonas Maebe wrote: > It works fine under linux (if you replace the "-f coff" with "-f elf"). For me it doesn't work in Mac OS X using -f macho -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface with NASM
On 16 Sep 2010, at 15:22, Felipe Monteiro de Carvalho wrote: On Thu, Sep 16, 2010 at 3:19 PM, Jonas Maebe > wrote: It works fine under linux (if you replace the "-f coff" with "-f elf"). For me it doesn't work in Mac OS X using -f macho That is normal, Mac OS X/i386 requires a different function calling model than other i386 platforms. Windows does not. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Basics of profiling -- some comments on fpprofiler bugs
On Mon, 2010-09-06 at 16:58 +0300, Žilvinas Ledas wrote: > On 2010-09-06 15:48, Darius Blaszyk wrote: > > On Mon, 2010-09-06 at 13:01 +0200, Graeme Geldenhuys wrote: > >> Recently I took a look at Darius's old project 'fpprofiler. Links > >> below. It was over 2 years since anybody worked on it, and riddled > >> with bugs. I fixed all memory leaks, added some improvements, and used > >> the new fcl-passrc code included with FPC Trunk (though it only uses > >> the tokenizer for speed reasons, so FPC 2.4.x should work to - maybe > >> with minor one line code change). > > I've tested fpprofiler on FPC 2.4 and it works, provided the fcl-passrc > > is from 2.5.1. I'll add this folder as external to the SVN repository. > Few notes (parts that need some improvement): > 1) fpp.pp needs at least tkAsm in "case tokenlist[i].token of" in > "procedure ModifyCode(AFileName: string; tokenlist: TPasTokenList);" > 2) it works wrong with ifdef's (it leaves only ELSE code) -- (I modified > my copy to output comments as well and had to "modify" pscanner.pp to > have directives as simple comments); > 3) in "procedure TPasTokenList.SaveToFile(const AFileName: string);" no > need for writeLN's - writes are enough; > 4) Asm procedures are handeled wrong (fpprof_exit_profile; is inserted > before end;) > function IsCPUID_Available : Boolean; register; assembler; > asm >... > end; > 5) records with cases (or some other type) is handeled wrong > (fpprof_exit_profile; is inserted before end;) -- I don't remember what > type it was exactly. > > In my opinion 2) is the biggest problem now :) I have added some tests for all the issues you describe above (asm / ifdef and case). According to me only asm seems to be not working correctly. Could you have a look and run the tests to see if you get the same issue? If confirmed I will work on fixing asm (and any other issue that pops up). Regards, Darius ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal