embedded systems developers tools, cross compilers
  Home  |   SwiftX Archive  |   SwiftForth Archive  |

Sections and section types (was Re: Data storage in paged memory (was DOES>Woes))

From: Ron Oliver <roliver_at_openesque.com>
Date: Sat, 10 Jan 2004 23:33:40 -0500 (EST)

On Sat, 10 Jan 2004, David Graham wrote:

> OK, I think it is sinking in. Is it as simple as sections control where
> code is stored, and section types control where data is stored?

No, but nice try. ;-)

Don't feel bad about not getting it right away; I had to have a nice
long chat with Elizabeth before I really got it.

A SECTION is simply a contiguous range of memory, be it code or data.
When defined, it is either of type CDATA, IDATA, or UDATA.
Here's an example setup (you should see something similar in your
config.f):

HEX
    0000 BFFFF CDATA SECTION PROG
   C0000 CFFFF CDATA SECTION FONTS
   D0000 DFFFF IDATA SECTION IRAM
   E0000 3FFFFF UDATA SECTION URAM
FFB02000 FFB3FFFF UDATA SECTION NVRAM

Each section keeps track of its own "HERE", so you don't have to.
In chipFORTH, by contrast, if you wanted to have a font table
somewhere in ROM, you'd have to have something to keep track of how
much of the table is used up, and you couldn't use , (comma), ALLOT,
etc. Here, you can.

SwiftX keeps track of which section is currently selected for each
section type. So, when we do

PROG IRAM URAM CDATA \ Establish defaults

that means that if we execute CDATA, we'll ALLOT from and comma to PROG.

If we execute IDATA, we'll ALLOT from and comma to IRAM.

If we execute UDATA, we'll ALLOT from URAM. We can't comma to a
UDATA section...it's uninitialized data.

If we execute FONTS, then we'll ALLOT from FONTS instead of
PROG...but only if the current section type is CDATA.

If we execute NVRAM, then we'll ALLOT from NVRAM instead of
URAM...but only if the current section type is UDATA.

Certain words, such as RESERVE, always allot from the current UDATA
section, even if you execute IDATA or CDATA first.

:(colon) always compiles into the current CDATA section, regardless
of which section type is currently in effect.

Here's an example session that I ran here. Backup your config.f, then
edit your SECTION definitions to have the ones above. You don't need
much space in each section to run this. I suggest you run this one
line at a time on your system; it'll be easier to follow. You don't
need a target connected.

----- Begin section demonstration -----
PROG IRAM URAM CDATA \ Establish defaults
HEX
.ALLOCATION
HERE . .SECTIONS
4 ALLOT HERE . .SECTIONS
FONTS HERE . .SECTIONS
4 ALLOT HERE . .SECTIONS
IDATA
4 ALLOT HERE . .SECTIONS
CDATA
4 ALLOT HERE . .SECTIONS
PROG
4 ALLOT .SECTIONS
4 RESERVE . .SECTIONS
NVRAM .SECTIONS
4 RESERVE . .SECTIONS
CDATA .SECTIONS
1 , 2 , .SECTIONS
IDATA .SECTIONS
3 , 4 , .SECTIONS
FONTS .SECTIONS
5 , 6 , .SECTIONS
CDATA .SECTIONS
7 , 8 , .SECTIONS
----- End section demonstration -----

And here's the annotated run:

PROG IRAM URAM CDATA \ Establish defaults ok
HEX ok
.ALLOCATION
   Start End Size Used Unused Type Name
    0000 BFFFF C0000 12558 ADAA8 CDATA PROG
   C0000 CFFFF 10000 0 10000 CDATA FONTS
   D0000 DFFFF 10000 2E FFD2 IDATA IRAM
   E0000 3FFFFF 320000 179A 31E866 UDATA URAM
FFB02000 FFB3FFFF 3E000 0 3E000 UDATA NVRAM ok

\ .SECTIONS highlights the current section; I'll put a dashed line
\ underneath the highlighted section.

HERE . .SECTIONS 12558
CDATA PROG 12558 | IDATA IRAM D002E | UDATA URAM E179A | ok
-----------------
\ just like we saw in .ALLOCATION above.

4 ALLOT HERE . .SECTIONS 1255C
CDATA PROG 1255C | IDATA IRAM D002E | UDATA URAM E179A | ok
-----------------
\ As you can see, HERE . returned 1255C; what we're seeing in
\ .SECTIONS output is the HERE value for each of the current
\ sections.

FONTS HERE . .SECTIONS C0000
CDATA FONTS C0000 | IDATA IRAM D002E | UDATA URAM E179A | ok
------------------

4 ALLOT HERE . .SECTIONS C0004
CDATA FONTS C0004 | IDATA IRAM D002E | UDATA URAM E179A | ok
------------------
\ So we ALLOTted 4 bytes from the current section of the
\ current section type, which is FONTS, in CDATA.

IDATA ok
4 ALLOT HERE . .SECTIONS D0032
CDATA FONTS C0004 | IDATA IRAM D0032 | UDATA URAM E179A | ok
                   ------------------
\ then 4 bytes from the current section of the
\ current section type, which is IRAM, in IDATA.

CDATA ok
4 ALLOT HERE . .SECTIONS C0008
CDATA FONTS C0008 | IDATA IRAM D0032 | UDATA URAM E179A | ok
------------------
\ still in FONTS; that's where we left CDATA.

\ By now, you hopefully get that HERE returns the next free byte
\ in the current section for the current section type. .SECTIONS
\ is showing HERE for the current section in each section type.
\ So I'll stop doing HERE . after each one.

PROG ok
4 ALLOT .SECTIONS
CDATA PROG 12560 | IDATA IRAM D0032 | UDATA URAM E179A | ok
-----------------
\ In case you lost it back there, HERE was at 1255C.

4 RESERVE . .SECTIONS E179A ( <-- value printed by '.' after RESERVE)
CDATA PROG 12560 | IDATA IRAM D0032 | UDATA URAM E179E | ok
-----------------
\ RESERVE always ALLOTs from the current UDATA section.

NVRAM .SECTIONS
CDATA PROG 12560 | IDATA IRAM D0032 | UDATA NVRAM FFB02000 | ok
-----------------
\ We don't need to change section type, because RESERVE always
\ uses UDATA.

4 RESERVE . .SECTIONS -4FE000
CDATA PROG 12560 | IDATA IRAM D0032 | UDATA NVRAM FFB02004 | ok
-----------------

\ This is a 32-bit target, so each comma uses 4 bytes.

1 , 2 , .SECTIONS
CDATA PROG 12568 | IDATA IRAM D0032 | UDATA NVRAM FFB02004 | ok
-----------------

IDATA .SECTIONS
CDATA PROG 12568 | IDATA IRAM D0032 | UDATA NVRAM FFB02004 | ok
                  ------------------

3 , 4 , .SECTIONS
CDATA PROG 12568 | IDATA IRAM D003A | UDATA NVRAM FFB02004 | ok
                  ------------------

FONTS .SECTIONS
CDATA FONTS C0008 | IDATA IRAM D003A | UDATA NVRAM FFB02004 | ok
                   ------------------

5 , 6 , .SECTIONS
CDATA FONTS C0008 | IDATA IRAM D0042 | UDATA NVRAM FFB02004 | ok
                   ------------------
\ Not what you expected? ,(comma) compiles the value into the
\ current section of the current section type. We changed
\ CDATA's current section...but our current section *type* is
\ still IDATA, so the 5 and 6 went into IDATA.

CDATA .SECTIONS
CDATA FONTS C0008 | IDATA IRAM D0042 | UDATA NVRAM FFB02004 | ok
------------------

7 , 8 , .SECTIONS
CDATA FONTS C0010 | IDATA IRAM D0042 | UDATA NVRAM FFB02004 | ok
------------------
\ Now they went into the font table.

UDATA .SECTIONS
CDATA FONTS C0010 | IDATA IRAM D0042 | UDATA NVRAM FFB02004 | ok
9 , , Not available for this section type
\ You can't comma into UDATA.

Hope that helps...because I spent way too much time writing it!

-- 
Ron Oliver <roliver_at_openesque.com>
----------------------------------------------------------------------
swiftx_at_forth.com          The SwiftX programming discussion email list
To unsubscribe, send subject "unsubscribe" to swiftx-request_at_forth.com
For list command help, send subject "help" to swiftx-request_at_forth.com
Message archives are located at http://www.forth.com/archive/swiftx
----------------------------------------------------------------------
This list is a forum for SwiftX users.  For product support and bug 
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Sat Jan 10 2004 - 20:35:52 PST

This archive was generated by hypermail 2.2.0 : Fri Dec 05 2008 - 03:04:22 PST