reserve memory blocks?

Discuss the Firewing language

reserve memory blocks?

Postby Jerry Messina » Wed Aug 21, 2013 11:20 am

Is there anyway to reserve a block of memory at a specific address and range, such as the DMA ram region?
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Re: reserve memory blocks?

Postby David John Barker » Wed Aug 21, 2013 11:52 am

No, it doesn't at the moment. I seem to recall Swordfish had RAM banking, where you could "protect" a region of RAM during variable allocation and alias to it - do you think a similar mechanism would work? If not, how would you see it working?
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: reserve memory blocks?

Postby David John Barker » Wed Aug 21, 2013 12:42 pm

After looking at the datasheet in more detail, i looks like DMA RAM is mapped at the end of data RAM? Could you not just alias to that address?
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: reserve memory blocks?

Postby Jerry Messina » Wed Aug 21, 2013 1:15 pm

While the parts I've looked at have the DMA ram at the end, knowing Mchip I'm sure there are parts where this isn't true (or there will be).

The SF mechanism worked well from what I recall. In SF, you could mark a region as protected and the compiler would skip this range when allocating memory
Code: Select all
#define _protected_a_start = $100
#define _protected_a_end = $1ff

There were two regions, a and b.

After that, you could locate variables in the reserved region using something like
Code: Select all
dim b(100) as byte absolute _protected_a_start
dim c(100) as byte absolute (_protected_a_start + 100)


That ended up being useful for other things as well. In typical Microchip fashion, they have parts where the memory map has 'holes' in it, like the 18F13K50. You could use the protected region to regain memory...
Code: Select all
device=18F13K50

//
// 13K50 non-usb application using reserved blocks
//
// the 13K50 has ram at $000-0FF and a DPRAM block at $200-2FF
// since the memory map skips the $100-1FF block, normally the
// ram in the upper 200-2FF block is unavailable to SF.
// here we extend the ram size to the entire 768 byte space and
// then just mark the unimplemented block as reserved
//
#variable _maxram = $0100 * 3            // 768 bytes total user RAM
#define _protected_a_start = $100       // reserve the non-existent block
#define _protected_a_end = $1ff

// normally, this would be the limit of available ram
const SYS_VAR_SIZE = 25
dim b(256-SYS_VAR_SIZE) as byte

// newly available ram
dim c(256) as byte

clear(b)
clear(c)


Off the top of my head I would think the same type of scheme would work ok for the 24F.
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Re: reserve memory blocks?

Postby Jerry Messina » Thu Aug 29, 2013 12:01 pm

I see that in one of the recent betas you added
NEW - Added _ram_protect and _ram_protect_length options.


How do you use these?
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Re: reserve memory blocks?

Postby David John Barker » Thu Aug 29, 2013 12:57 pm

I was just putting together a little example when I noticed that the system ram offset was missing from module level variables (I had disabled during debugging). Sigh. Anyway, download beta (H) to fix. Here is the sample I put together to answer your question:
Code: Select all
#define _ram_protect = $804
#define _ram_protect_length = $100

private mval0 as byte = 0
private mval1 as byte = 0
private mval2 as byte = 0
private mval3 as byte = 0
private mval4 as byte = 0
   
sub main()
end sub

In the above mvals 0..3 will be located at $800..$803 and mval4 at $904. With sub and functions, if the whole frame cannot fit within a block then the whole frame is moved. For example,
Code: Select all
sub main()
   dim val0 as byte = 0
   dim val1 as byte = 0
   dim val2 as byte = 0
   dim val3 as byte = 0
end sub

while locate at $800..$803 but
Code: Select all
sub main()
   dim val0 as byte = 0
   dim val1 as byte = 0
   dim val2 as byte = 0
   dim val3 as byte = 0
   dim val4 as byte = 0 
end sub

will locate at $904 onwards. You can also use the following syntax:
Code: Select all
#define _ram_protect_a = $804
#define _ram_protect_a_length = $100

using "a".."z" enables you to define multiple blocks.
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: reserve memory blocks?

Postby Jerry Messina » Mon Sep 02, 2013 1:06 pm

I updated to 1002H and tried the first example, but I can't seem to get this to work.

from .idf
Code: Select all
   .var PRI $0800 00 0000 0000 U08    mval0
   .var PRI $0801 00 0000 0000 U08    mval1
   .var PRI $0802 00 0000 0000 U08    mval2
   .var PRI $0803 00 0000 0000 U08    mval3
   .var PRI $0804 00 0000 0000 U08    mval4
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Re: reserve memory blocks?

Postby Jerry Messina » Mon Sep 02, 2013 1:24 pm

also, if I combine the first and last examples it skips over the initial $800 region...
Code: Select all
#define _ram_protect = $804
#define _ram_protect_length = $100

private mval0 as byte = 0
private mval1 as byte = 0
private mval2 as byte = 0
private mval3 as byte = 0
private mval4 as byte = 0
   
sub main()
#if (true)
   dim val0 as byte = 0
   dim val1 as byte = 0
   dim val2 as byte = 0
   dim val3 as byte = 0
   dim val4 as byte = 0
#endif
end sub


results in
Code: Select all
   .proc PRI 00127 $00294 00046 $0904 0006 00034 00041 main
   .var PRI $0904 00 0000 0000 U08    val0
   .var PRI $0905 00 0000 0000 U08    val1
   .var PRI $0906 00 0000 0000 U08    val2
   .var PRI $0907 00 0000 0000 U08    val3
   .var PRI $0908 00 0000 0000 U08    val4
   .end
   .var PRI $090A 00 0000 0000 U08    mval0
   .var PRI $090B 00 0000 0000 U08    mval1
   .var PRI $090C 00 0000 0000 U08    mval2
   .var PRI $090D 00 0000 0000 U08    mval3
   .var PRI $090E 00 0000 0000 U08    mval4


Probably not what's desired
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Re: reserve memory blocks?

Postby David John Barker » Mon Sep 02, 2013 2:04 pm

The IDF looks incorrect, that's for sure. However, the code generated is correct if you examine the IMC file
Code: Select all
asm("USER_RAM   = 0x0800;");
asm("_mval0_M0_U08 = USER_RAM + 0x000000;"); extern BYTE mval0_M0_U08;
asm("_mval1_M1_U08 = USER_RAM + 0x000001;"); extern BYTE mval1_M1_U08;
asm("_mval2_M2_U08 = USER_RAM + 0x000002;"); extern BYTE mval2_M2_U08;
asm("_mval3_M3_U08 = USER_RAM + 0x000003;"); extern BYTE mval3_M3_U08;
asm("_mval4_M4_U08 = USER_RAM + 0x000104;"); extern BYTE mval4_M4_U08;

For the second example you show, the IMC is:
Code: Select all
asm("USER_RAM   = 0x0800;");
asm("_val0_F260_U08 = USER_RAM + 0x000104;"); extern BYTE val0_F260_U08;
asm("_val1_F261_U08 = USER_RAM + 0x000105;"); extern BYTE val1_F261_U08;
asm("_val2_F262_U08 = USER_RAM + 0x000106;"); extern BYTE val2_F262_U08;
asm("_val3_F263_U08 = USER_RAM + 0x000107;"); extern BYTE val3_F263_U08;
asm("_val4_F264_U08 = USER_RAM + 0x000108;"); extern BYTE val4_F264_U08;
asm("_mval0_M0_U08 = USER_RAM + 0x00010A;"); extern BYTE mval0_M0_U08;
asm("_mval1_M1_U08 = USER_RAM + 0x00010B;"); extern BYTE mval1_M1_U08;
asm("_mval2_M2_U08 = USER_RAM + 0x00010C;"); extern BYTE mval2_M2_U08;
asm("_mval3_M3_U08 = USER_RAM + 0x00010D;"); extern BYTE mval3_M3_U08;
asm("_mval4_M4_U08 = USER_RAM + 0x00010E;"); extern BYTE mval4_M4_U08;

As previously mentioned:
With sub and functions, if the whole frame cannot fit within a block then the whole frame is moved

you can see this if you comment out:
Code: Select all
   dim val4 as byte = 0

you will see the frame fits. In summary, the IDF file looks in error but the actual code generated is correct and as previously described.
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: reserve memory blocks?

Postby Jerry Messina » Mon Sep 02, 2013 2:27 pm

>> However, the code generated is correct if you examine the IMC file

Ahhh, I see that. I was looking for the data using MPLAB, and it appears that the DEBUG symbols are incorrect... they match the IDF file.


>> if the whole frame cannot fit within a block then the whole frame is moved

I didn't realize that would effect the module level vars 'mval', but since they're located after the locals I suppose that makes sense now. If the locals get moved then the module level ones do as well.

>>if you examine the IMC file

By that I take it you mean the .C file? I don't see an .IMC file anywhere.
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Next

Return to Language

Who is online

Users browsing this forum: No registered users and 2 guests

x