Picoblaze enhencement and assembler

Hi,

I wasn't very satisfied with the available assembler, so a few month ago I wrote a new compiler for the Picobaze during my spare weekends ...

I just though I'd share it if anyone is interested ....

It's available there :

formatting link

Example usage: python ./Codegen.py example.S out.mem

WARNING: The last file on the command line is the output ... so if you forget it, it will overwrite your last source file ...

What are the pro and cons:

pros: - Cross platform - It supports local label, so for labels that don't really deserve a name you can do things like

load s0, 15

1: sub s0, 1 jump nz, 1b

And the '1b' reference says to find the first label named 1 when going 'back' (1f would be forward...). Local labels are just a single digit.

- It supports initialized data, and reference to the "data" sections. Like

.data var1: .byte 0xa5

.text load s0, var1 fetch s0, (s0)

- It supports evaluating expression like "load s0, 15 / 5 * 8" - It supports some advanced hw feature not in the original picoblaze like offset during fetches / store / input / output :

fetch s0, (s1)8

equivalent to

add s1, 8 fetch s0, (s1) sub s1, 8

but in 1 cycle and at no hw cost ... (just need to change a LUT3 to a LUT4 and change it's INIT string)

cons:

- Incompatible syntax with the official one ... - I haven't tested interrupt stuff - The registers are now s0 -> s15 and not s0 -> sF ... (easier to parse) - To use all the features you need a hw modified picoblaze - It has terrible error reporting ... basically just throws an exception with a not always helpful message.

It could use cleanup, an optimizer, a C front-end, a macro preprocessor .... but ... it works :)

About the hw mods to the hw : - I removed the ScratchPad distributed RAM and used the second port on the BRAM as scratch pad. The second port is configured as 8 bit width and with upper address lines mapped to 1 so that the SP is located at the end of the BRAM. (Be careful when playing with this and interruptions, the last 2 bytes of the scratch pad is the interrupt vector ...) And the bonus is a 256 byte scratch pad, just sacrificing

128 instruction words ... (adjust mapping for other tradeoffs)

This mod is not absolutely needed. But if you want to use the pre- initialized memory without it, you'll have to change the main function to output two independent .mem file instead of just 1 merged one ... (pretty easy, juste look at the end of CodeGen.py )

- I changed a lut to allow for having an offset in fetch/store/input/ output ... I can post the exact patch if it's to interest to anyone. (I don't have it handy right here ...) But it doesn't cost any slice ... It might prolong the critical path a bit. But for me, the critical path was somewhere else anyway so I didn't mind ...

Sylvain

Reply to
Sylvain Munaut
Loading thread data ...

I forgot to say you need Python and also the Ply (Python Lex Yacc) library ...

Reply to
Sylvain Munaut

Hi Sylvain,

Nothing to add but encouragement really. The software offerings for picoblaze are limited, especially in the non-windows world. Both picoasm and kpicosim are very good, but their development seems to have stopped.

If you can get a polished version of your assembler finished, it sounds like it would be a great tool.

Andy

Reply to
Andrew Greensted

Of course, you're working on the simulator now, right? :)

Reply to
Paul Urbanus

I think you mean a New Assembler ?

Hmmm - could be dangerous for maintenance. Another scheme is to use '?' or similar prefix to mean local label.

Have you looked at the Lattice Mico8 - Quite similar to the Picoblaze, but more formally opensource, and they have just extended it to make it more 'HLL ready'.

Have a look and see if your opcode extensions can fit into their decode ?

-jg

Reply to
Jim Granville

Yes :) I was careful in the subject but that one slipped.

I've used the same convention as the GNU assembler. I've modelled the syntax after theirs, but making sure it's easy to parse with Lex / YACC. As it was my first lex/yacc experience I didn't want to take too much time to make it work.

Especially since I needed that compiler to ease my work for a commercial project with an approaching dead line :)

I had a look at the Lattrice Mico8. But since my target was Xilinx, the picoblaze seemed like a better choice (smaller and faster ...) I didn't investigate further and just coded this assembler to have an easier time when programming it.

I'm not that interested in HLL because when I uses theses. But a macro preprocessor would be nice :)

Sylvain

Reply to
Sylvain Munaut

I don't think so ... I rarely used the one that are available because the code on the picoblaze is often so dependent on the hw around it that it just doesn't do anything meaning full without it ...

What I did is that my assembler output a symbol table and so in the modelsim you can get it to display :

uart_print_str + 0x00, uart_print_str + 0x01 .... instead of the addesses in the code, and also the variable name instead of address in the scratch pad. Very useful to trace what's going on.

Sylvain

Reply to
Sylvain Munaut

Yes they did a great job and I used those for a some time. But since they respected the Xilinx 'standard' assembly format, they were limited ...

I choose to break compatibility so that I could extend easily. But even without the compatibility, it's pretty easy to convert old software. Mostly a few subsitute with regexp and adding a .text at the start and that should do it :)

Thanks.

I'll try to polish things up a little and maybe write some documentation and so forth.

But I probably won't do a lot of work on it since I changed job and this new one is not related to fpga (nor hw dev) in any way ...

Sylvain

Reply to
Sylvain Munaut

You can use plain old cpp for that purpose. A few months ago I wrote a PLC compiler thingy. I used cpp as a preprocessor for it.

--
Programmeren in Almere?
E-mail naar nico@nctdevpuntnl (punt=.)
Reply to
Nico Coesel

Mmm, I hadn't tought of that. That's a nice easy way to get a well known syntax.

However for an assembler it's nice to have more 'advanced' things. I'm not an expert in the C preprocessor but making a macro that would expand :

STACK_PUSH(s0, s1, s2, s3)

into

store s0, (sp)0 store s1, (sp)1 store s2, (sp)2 store s3, (sp)3 add sp, 4

Seems kinda hard ...

Sylvain

Reply to
Sylvain Munaut

You shouldn't push the limits too far... Your example smells more like assembler extensions than macro's.

--
Programmeren in Almere?
E-mail naar nico@nctdevpuntnl (punt=.)
Reply to
Nico Coesel

You mean something like this -

#define STACK_PUSH(a,b,c,d) store a, (sp)0 store b, (sp)1 store c, (sp)2 store d, (sp)3 add sp, 4

STACK_PUSH(s0, s1, s2, s3)

Mark

Reply to
Mark

:) I meant with a variable number of argument, autoadapting itself.

Sylvain

Reply to
Sylvain Munaut

Yes ... I seem to recall the Microchip PIC assembler supported things like that ...

Sylvain

Reply to
Sylvain Munaut

I don't know the picoblaze procedure/interrupt conventions, but getting an interrupt between store s1 & store s2 or so looks like trouble.

regards, Gerhard

Reply to
Gerhard Hoffmann

There is no convention ... you just fix what you want for yourself. But indeed, with a classic one, this would be a problem. Solution is to either

- Don't use interrupts :) That actually my case for the sw where this snippet comes from

- Make it a critical zone :

cli store s0, (sp)0 store s1, (sp)1 store s2, (sp)2 store s3, (sp)3 add sp, 4 sti

- Use dual pointer :

add sp, 4 sub bp, sp, 4 store s0, (bp)0 store s1, (bp)1 store s2, (bp)2 store s3, (bp)3

- Have the interrupts with their own dedicated stack and a dedicated reg used only by them. So the interrupt handler would start by .equ si, s14 .bss __isr_stack: .space 32 .text __isr: load si, __isr_stack store sp, (si) load sp, si add sp, 1 store s0, sp(0) ... ...

- Reserve the space 'before' :

add sp, 4 store s0, sp(-4) store s1, sp(-3) store s2, sp(-2) store s3, sp(-1)

Unfortunatly, I don't think my hw mod can extend to allow negative offset without adding some slices ... I'd have to recheck.

Sylvain

Reply to
Sylvain Munaut

This may seem like a minor annoyance to you, but it is one of those things that a user will tire of very quickly... after about one lost file in fact.

Couldn't you fix that so the output file is first or use option flags to indicate the output file such as -o name?

Reply to
rickman

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.