Simple ObjASM LDR question
Tristan M. (2946) 1036 posts |
I’ve been getting stuck on some really simple things recently. I just need a nudge here because I’m a bit stuck and can’t seem to find a good example. I have a couple of things like this:
What’s the correct way to load the values into a register? In this case they are addresses I want to read / write to, but I have another with bit patterns to be written to these addresses. I’m trying some different ideas to detect the amount of RAM on the AllWinner SoCs. This particular test involves writing a test value to the top word of the first 256MiB block of DRAM, and then checking for mirroring at the other addresses. Between still learning, the relative lack of info using ObjASM, and probably coughing away a decent chunk of brain cells I’m finding myself needing to reach out and ask for help. Could someone please ster me in the right direction? |
Rick Murray (539) 13405 posts |
Sorry terse at work forum likes to not bother responding. Hmm. Is it not just a matter of ADR to the “addrs” location, then LDMIA to load them? LDMFD load multiple, I for increment (addresses count up), A for after (do the address increment after each load)? |
Colin Ferris (399) 1748 posts |
Something like:- addrs or inline – for large number. ;Your code LDR,R0,[PC] |
Clive Semmens (2335) 3130 posts |
If those are really the only four values you’re trying to load to registers, why use LDR at all? They’re all values that can simply be MVNed into registers, since all the bits are set except four at each end. |
Jeffrey Lee (213) 6046 posts |
As you’ve seen by the replies so far, there is no single “correct” way. Just multiple valid ways, some of which are more useful than others depending on how/where you want to use the values. I’m assuming you’re going to be iterating over the values in a loop, so you’ll probably want an approach that makes use of a pointer to the ADR R0,addrs MOV R1,#4 loop LDR R2,[R0],#4 ; .. do something with R2 .. SUBS R1,R1,#1 BNE loop If you’re not looping through values, then the Constants and literal pools section of my ObjASM guide provides some examples of the standard ways of loading constant values into registers. For example, |
Willard Goosey (5119) 257 posts |
That looks very useful! |
Tristan M. (2946) 1036 posts |
It is. I use it for reference, and was actually doing so before I gave up and asked my question. I’ll reply properly once I’ve altered my code and tried it. Clive, while what you say makes sense, I need it to be flexible. I’m throwing code at it and seeing what sticks, because I can’t find enough information to detect the RAM in a smarter way or get hold of the information from U-Boot without modifying it. This all came about because I went to write some code and realised I had absolutely no idea how to do it, and couldn’t work out how. Accessing the first element is of course easy, but I had no idea how to apply an offset. Normally I’d do it like LDR a1, =&12345678 or LDR a1, =PREDEFINED_NUMBER for example, but I just wanted to know how to do it a different way. Especially because lookup tables, and also jump tables would be super useful to me. I just haven’t been able to work out how to do them with ObjAsm. Just a simple table which doesn’t require tying up a register as a base register like a storage map or whatever. |
Rick Murray (539) 13405 posts |
The same sort of method as otherwise? ADR Rx, table LDR Ry, [Rx] LDR Rz, [Rx, #4]
??? Isn’t there a clever way to enquire from the memory itself its type, manufacturer, refresh speeds, etc? |
Martin A (2050) 6 posts |
In a loop LDR Ry,[Rx],#4 will walk through the table. For your memory problem, you could try writing the address each of the 4 possible addresses, ie STR Ry,[Ry]. Start with the highest address and work down to the lowest. Then read the highest address, the value returned will be your highest available address as all the mirrored writes will be over-written. |
Tristan M. (2946) 1036 posts |
I just wanted to say thanks for your help everyone. Martin, That’s an interesting idea. I’ve just been using some accepted patterns for helping avoid a false positive. Your idea would also help me work out why I’m not getting expected results. |