PNut Problem with CALLD when calling from a cog address to another cog address
Dave Hein
Posts: 6,347
in Propeller 2
If I assemble the following program with PNut I get the wrong instruction encoding for CALLD.
dat orgh 0 org 0 entry 'jmp #start calld adra, #start 'long $fe100004 jmp #entry start or dirb, #1 .loop waitx ##50000000 xor outb, #1 jmp #.loopPNut generates the code $fe0ffffe, which is an absolute jump to location $ffffe. If I comment out the CALLD and uncomment the JMP I get $fd900004, which is a relative jump to the correct address. I believe the CALLD should be generating $fe100004. If I comment out the CALLD and the JMP, and uncomment the LONG the program seems to work correctly.
Comments
Your examples of "calld myret,#@sx" also use the first form of CALLD since myret is $123, and is outside of the range of $1f6 to $1f9. In my case I'm using ADRA for the destination register, so PNut uses the second form of CALLD to provide a larger range. I tried "calld adra, #@start" in my code, and it does give the correct encoding. However, I don't feel that the "@" should be use. It is not used in the case of "jmp #start", which encodes correctly. It also doesn't make sense if I were to do "calld adra, #\@start", which forces an absolute address. If my cog code was not located starting at hub address zero this would give the wrong address.
It works for me too but note the ORGH $400 in the following code was needed.
The absolute address needs to be $400 or higher.
I've noticed a couple of issues when trying to use the CALLD instruction (rel9) variant (Pnut_v11a).
The first issue simply that the WC and WZ effects are not allowed according to Pnut yet
the opcode has these bits defined.
Other instructions that support "rel9" addressing don't require then "@" symbol (i.e DJNZ).
The second issue is that depending on the code being defined as COGEXEC or HUBEXEC
returns different results from Pnut.
Here are three different program configurations and their responses from Pnut.
I've been going over this addressing stuff today. There were some problems with the assembler which I'm still working on. It's going to take me a day, or so, to get this straightened out.
and earlier ....
I have to mention, these issues around P2 Assembler syntax confusing even the creator, do worry me...
Is it a good time to do a clean up pass on the Assembler, so it is less way-out-in-left-field, and easier to work in ?
Seems P2 is complex enough, without adding the confusion of non-standard assembler on top ?
<goes offline for cover>
NASM - looks active, but is rather x86 centric
FASM - has an interesting new direction, called FASMG
https://flatassembler.net/download.php
The flat assembler g is the new assembly engine designed to become a successor of the one used by flat assembler 1. It does not have a built-in support for x86 instructions. It is a generic assembler that can be used in place of flat assembler 1 in applications where only the pure macroinstruction engine is needed instead of x86 encoder, for example when an instruction set for a different architecture is defined through macroinstructions. However it still has the ability of self-hosting, thanks to the included set of macroinstructions implementing basic x86 instructions and formats.
flat assembler g 0.98 size: 235 kilobytes last update: 14 Sep 2016 13:13:53 UTC
This release contains executables for 32-bit Linux and Windows. It contains examples of macroinstructions that allow assembly of simple programs for the architectures like x86, x64, 8052, AVR, or Java Virtual Machine.
The multiple targets angle of this, has real appeal. It's not large, I'll download and have a play around...
Downloaded what is a very small assembler exe - fasmg.exe is 47.5k + examples = just 236k
Ran tests on examples for 8051, 8048, ez80, x86
Speed indication is largest eZ80 test file of 240k, 8912 lines, reports 1.0s
(plus that reads 1097 lines of macro defines, via simple include 'ez80.inc' )
eg This source code from 8051 test
uses this part of '8051.inc' Macro definition file,
to give this DisAsm hex
Note that all of those macro scripts are available to your Assembler source too, because this is just a simple include step.
Conditional assembler on steriods...
Addit:
Default output is Binary, and if you want intel hex you
include 'hex.inc'
Looking into how to generate a Listing file, that is similar, no command switch, another
include 'listing.inc'
with the script code from 3rd forum post here,
https://board.flatassembler.net/topic.php?p=190446#190446
simply pasted into listing.inc
and you get a flat/absolute-listing file (ie addresses resolved), on console like this...
Seems to nicely manage Generic Any-MCU.ASM -> .BIN and .LST quite easily
https://drive.google.com/file/d/0B9NbgkdrupkHbkNRcnRmT19YUUU/view?usp=sharing
I think I got the assembler fixed, as it seems to assemble every case of CALLD correctly now.
CALLD all working now, thanks .
Oops, BMASKN appears to missing from the keywords now.
Thanks for testing CALLD. I need to improve the error reporting on it, still.
In the current Verilog, BMASKN is now MOVINT, which moves S into D and triggers INT3. It's not an ideal software interrupt, since the interrupt doesn't occur until after the next instruction. I might change it into something else, or maybe leave it that way. Any better ideas?
We now haveTRGINT1,TRGINT2 and TRGINT3 for software triggering of interrupts, do we need one more variant?
Looking at BMASK and BTRIM a little deeper I have the following thoughts.
I think BTRIM is a very useful instruction and maybe it could be called LTRIM (Left trim) instead.
Maybe BMASK could then be replaced with a RTRIM (right trim) variant.
The combination of the two makes for easy MASK/OR operations in 3 ops.
Such a structure has been used for Single-Step of code on other MCUs - could it be used for that on P2 ?
FYI The P2 can support single-step now through the SETBRK instruction.
I like LTRIM and RTRIM. I'll implement those.
We have pretty comprehensive debugging, already. I've always thought it would be nice to be able to write a register and have an implied CALL take place. For example, sending a serial byte.