Searching \ for '[PIC]: some questions about the linker.' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/devices.htm?key=pic
Search entire site for: 'some questions about the linker.'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: some questions about the linker.'
2001\11\06@185647 by juan manuel garofalo

flavicon
face
I'm using the mplab linker and am creating some modules. I'm writing for the
16f627.

First, when using the UDATA directive, am i supposed to specify the starting
address for the section ? Looks like i am because if i don't, the linker
chooses 0x120, wich is not a  very clever decision....

So, in module_one.asm

UDATA 0x20

var_a   res 1
var_b   res 1


now, i want to create another module wich uses some more variables. var_c
and var_d.

How do i manage to get the linker to allocate ram for these registers ?
Specifically  i want them to be at addresses 0x22 and 0x23.

if i say

module_two.asm

UDATA
var_c   res 1
var_d   res 1

the registers end up in 0x120 and 0x121.

if i say:

UDATA 0x20
var_c   res 1
var_d   res 1

var_c and var_d overwrite var_a and var_b.

What's the trick to get the linker to allocate registers wich belong to
different modules in a contiguos fashion ?


Thanks.

jm

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2001\11\07@075929 by Olin Lathrop

face picon face
> First, when using the UDATA directive, am i supposed to specify the
starting
> address for the section ? Looks like i am because if i don't, the linker
> chooses 0x120, wich is not a  very clever decision....

I use UDATA with explicitly named sections, one section for each RAM bank.
Here is the appropriate snippet from my default linker control file for the
16F876:


//   Linker control file for the PIC 16F876 processor.
//
CODEPAGE NAME=config START=0x2007  END=0x2007 //special processor config word

CODEPAGE NAME=code0      START=0  END=0x7FF //code page 0
CODEPAGE NAME=code1  START=0x800  END=0xFFF //code page 1
CODEPAGE NAME=code2 START=0x1000 END=0x17FF //code page 2
CODEPAGE NAME=code3 START=0x1800 END=0x1FFF //code page 3

DATABANK NAME=bank0  START=0x20  END=0x6F //register bank 0
DATABANK NAME=bank1  START=0xA0  END=0xEF //register bank 1
DATABANK NAME=bank2 START=0x110 END=0x16F //register bank 2
DATABANK NAME=bank3 START=0x190 END=0x1EF //register bank 3

SHAREBANK NAME=globalram  START=0x70  END=0x7F PROTECTED //global regs, bank 0
SHAREBANK NAME=globalram  START=0xF0  END=0xFF PROTECTED //global regs, bank 1
SHAREBANK NAME=globalram START=0x170 END=0x17F PROTECTED //global regs, bank 2
SHAREBANK NAME=globalram START=0x1F0 END=0x1FF PROTECTED //global regs, bank 3

SECTION NAME=.udata_shr RAM=globalram //global memory mapped to all register banks
SECTION NAME=.BANK0 RAM=bank0 //for registers explicitly in bank 0
SECTION NAME=.BANK1 RAM=bank1 //for registers explicitly in bank 1
SECTION NAME=.BANK2 RAM=bank2 //for registers explicitly in bank 2
SECTION NAME=.BANK3 RAM=bank3 //for registers explicitly in bank 3


To get variables in bank 0 for example, I do:

.bank0   udata

This can be done in as many modules as you like, and the variables will be
allocated sequentially.  Most of the time you don't care where a variable is
within a bank, but knowing the bank at assembly time allows for a number of
optimizations.  In the rare event when a variable needs to be at a
particular address, you can put a starting address after UDATA.  If you want
to see all this in action, take a look at my standard project templates and
the HAL project at http://www.embedinc.com/pic.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, .....olinKILLspamspam@spam@embedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu


2001\11\08@195731 by juan manuel garofalo

flavicon
face
>I use UDATA with explicitly named sections, one section for each RAM bank.
>Here is the appropriate snippet from my default linker control file for the
>16F876:



Thanks for answering Olin.

I took a more careful look at the linker file and the ram banks have already
been named by microchip.


So the first ram bank appears as
DATABANK   NAME=gpr0      START=0x20     END=0x6F

in the linker file, but if i say in my asm module

gpr0   UDATA
var_1

var_1 ends up at 0x120, wich is the third bank! something is missing here.

There actually are three entries in the liner file

DATABANK   NAME=gpr0      START=0x20     END=0x6F
DATABANK   NAME=gpr1      START=0xA0     END=0xEF
DATABANK   NAME=gpr2      START=0x120    END=0x14F

and if i comment out this one (the third bank)

//DATABANK   NAME=gpr2      START=0x120    END=0x14F

then var_1 gets put at 0x20, just as it should! Looks like some kind of bug.
Either on my side or the linker...

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\11\09@020449 by Kari Lehikko

flavicon
face
> I took a more careful look at the linker file and the ram banks have already
> been named by microchip.
>
> So the first ram bank appears as
> DATABANK   NAME=gpr0      START=0x20     END=0x6F

Yes, this is the name of the _memory_area_
This is used to tell the linker where can it locate variables.

> in the linker file, but if i say in my asm module
>
> gpr0   UDATA
> var_1

Here you use gpr0 as _section_name_

By defining the section name in linker script, you can _force_ the
linker to place a certain section in a certain memory area. For example:

In your code you name a ram section and define variables:

Var_example     udata
an_example_variable     res     1

In linker file you tell the linker to locate this section to area
0x20-0x6f, previously named as gpr0:

SECTION NAME=Var_example RAM=gpr0



HTH,

- Kari -

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics



'[PIC]: some questions about the linker.'
2003\01\16@133921 by Olin Lathrop
face picon face
From: "Benny Schroeder" <.....bennyKILLspamspam.....micro-trak.com>
> Hi Olin,
>
> Hope I'm not out of line here.  Just thought I'd go direct email.

This isn't a private issue, and should have been sent to the PIClist.

{Quote hidden}

No.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu>

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...