Jump to content
Sign in to follow this  
rlang

Memory Allocation Question

Recommended Posts

Memory allocation

 

I have used the following statements

 

unsigned char * tobuffer;

tobuffer = (unsigned char *) (0x550);

 

in a subroutine to to allocate a buffer at 0x550 in

General Purpose Register/USB Ram for use by USB.

 

I would like to globally allocate a buffer at 0x600 to be used as a

serial buffer by all the subroutines in a program. Do I have to allocate

the same buffer and address in every subroutine that uses it?

 

A more general question is if I just allocate a global buffer with

unsigned char * mybuffer;

 

at the beginning of the program what prevents mybuffer from

being allocated memory locations like 0x551 to store its data?

Share this post


Link to post
Share on other sites

Rob,

 

I have used the following statements

 

unsigned char * tobuffer;

tobuffer = (unsigned char *) (0x550);

 

This code only causes memory allocation for storage of the pointer.

The address of this pointer could be anywhere.

 

To reserve a whole block of memory space use:

 

char tobuffer[ 0x100 ] @ 0x550; // memory at address 0x550 to 0x650 is now reserved for my buffer.

 

This only needs doing in one of your source files, then linker will not touch this area for the software stack that is created for all local auto declarations.

 

Regards

Dave

Share this post


Link to post
Share on other sites
To reserve a whole block of memory space use:

 

char tobuffer[ 0x100 ] @ 0x550; // memory at address 0x550 to 0x650 is now reserved for my buffer.

 

This only needs doing in one of your source files, then linker will not touch this area for the software stack that is created for all local auto declarations.

 

Regards

Dave

 

(newbie)

Is this a way, or the way to "protect" a section of program memory? I am not clear how to protect a bootloader from getting overwritten by things from the compiler and linker. In other words, can one specifiy a lower memory ceiling for the compiler and/or linker (so they leave a section alone)?

 

In piclite you set the icd switch and which leaves the least 256 bytes alone (think).

 

Does the linker alway try to fill program memory continuously low to high (unless -rb, or as directed above)? I guess constants go in there someplace too..

Share this post


Link to post
Share on other sites

zzjoki,

 

Two thing a bootloader will need:

1) RAM

2) ROM

 

1) An area of ROM can be left at the top or bottom of memory using -rt and -rb linker options.

 

2) Normally a bootloader doesn't need to have RAM allocated, because either the user program is running, or the bootloader. They never both run at the same time.

 

If you did want to reserve some memory for whatever reason, using:

char myReservedMem [100] @ 0x123;

 

which allocates an area of memory 100 bytes long at address 0x123, will prevent the linker using this for the software stack and heap.

 

Regards

Dave

Share this post


Link to post
Share on other sites
1) An area of ROM can be left at the top or bottom of memory using -rt and -rb linker options.

 

2) Normally a bootloader doesn't need to have RAM allocated, because either the user program is running, or the bootloader. They never both run at the same time.

 

If you did want to reserve some memory for whatever reason, using:

char myReservedMem [100] @ 0x123;

 

which allocates an area of memory 100 bytes long at address 0x123, will prevent the linker using this for the software stack and heap.

 

Regards

Dave

 

I was going to guess -rt. This answers my question. Thank you.

 

Is 'end user' documentation for the linker available?

Share this post


Link to post
Share on other sites

zzjoki,

 

Is 'end user' documentation for the linker available?

 

Not as such, there aren't so many options there. If you run linker from the command line with no arguments you get a little help page.

 

Useage: linker.exe [options] files
Options:
-t name     target processor
-On         optimization level 0-1 (default n=1)
            n=0 - no optimization
            n=1 - pattern matching and bank switching optimization on
-v          verbose mode
-d path     directory for project output
-p name     project (output) name for multiple .obj file linking
-ld path    directory for library search
-rb address ROM bottom address to use
-rt address ROM top address to use

Switches for making libraries:
-lib        make library file from supplied .obj and .lib files
-p name     project (library output file) name

 

In the future more details will be added to the BoostC help file or another help file created.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...