[comp.sys.amiga.tech] Chip RAM

rokicki@polya.Stanford.EDU (Tomas G. Rokicki) (06/30/88)

This is more like it, folks, for checking whether a data structure
is in Chip RAM or not.  Sorry for giving you such bad code, Glenn,
but it was off the top of my head, on a machine without a compiler.
So, anyway, folks, stop linking with that option that puts the
entire data segment in Chip RAM; waste a byte or two and do
something like this.

#include "stdio.h"
#include "functions.h"
#include "exec/memory.h"
#include "intuition/intuition.h"
long TypeOfMem() ; /* why isn't this in functions.h? */
struct Image foo ;
struct Image *usefoo ;
void cleanup() { /* how to clean up after */
   if (usefoo != &foo)
      FreeMem(usefoo, (long)sizeof(struct Image)) ;
}
void error(s) /* how to die */
char *s ;
{
   printf("%s!\n", s) ;
   cleanup() ;
}
void *checkchip(data, len) /* this is the important function */
void *data ;
int len ;
{
   void *ptr ;

   if (TypeOfMem(data) & MEMF_CHIP)
      return(data) ;
   ptr = AllocMem((long)len, MEMF_CHIP) ;
   if (ptr == NULL)
      error("! out of core") ;
   CopyMem(data, ptr, (long)len) ;
   return(ptr) ;
}
void initialize() { /* how to use, might also check for 1.2 */
   usefoo = (struct Image *)checkchip(&foo, sizeof(struct Image)) ;
}
void main() {
   initialize() ;
   cleanup() ;
}

-- 
    /-- Tomas Rokicki         ///  Box 2081  Stanford, CA  94309
   / o  Radical Eye Software ///  (TAMU EE '85)   (415) 326-5312
\ /  |  . . . or I       \\\///Join CCFFAALW---Concerned Citzens
 V   |  won't get dressed \XX/Fighting For An Acronym-Less World

peter@sugar.UUCP (Peter da Silva) (07/03/88)

I don't understand all the hoopla over CHIP RAM. The Manx linker has long
allowed you to specify the type of memory each file should go in... The Amiga
executable format has provisions for this. Why not stick all your images
and other CHIP data in one module and link it with the +C flag?

Surely Lattice has some such provision...
-- 
-- `-_-' Peter (have you hugged your wolf today?) da Silva.
--   U   Mail to ...!uunet!sugar!peter, flames to /dev/null.
-- "Running DOS on a '386 is like driving an Indy car to the Stop-N-Go"

scott@applix.UUCP (Scott Evernden) (07/05/88)

In article <2242@sugar.UUCP> peter@sugar.UUCP (Peter da Silva) writes:
>I don't understand all the hoopla over CHIP RAM. The Manx linker has long
>allowed you to specify the type of memory each file should go in...

The Manx linker allows you to specify the type of memory each entire
*program section* (text,data,bss) should go in; there is no
per file/module control.

-scott

mwm@eris.berkeley.edu (Mike (I'm in love with my car) Meyer) (07/06/88)

In article <735@applix.UUCP> scott@applix.UUCP (Scott Evernden) writes:
<In article <2242@sugar.UUCP> peter@sugar.UUCP (Peter da Silva) writes:
<>I don't understand all the hoopla over CHIP RAM. The Manx linker has long
<>allowed you to specify the type of memory each file should go in...
<
<The Manx linker allows you to specify the type of memory each entire
<*program section* (text,data,bss) should go in; there is no
<per file/module control.

Perhaps Peter mis-spoke himself. That feature goes in the compiler,
not the linker. As an example, the Lattice 4 compiler allows you to
specify for each file compiled wether each of the three aformentioned
segments should be placed in chip, fast or whatever is available
memory.

So I take Peter's solution - whenver I have a file that needs a data
image in CHIP, I put the data in a seperate file, and compile it with
the -ad flag on. Viola - the data structure lands in chip memory. No
need to waste time testing to see if it's in chip, or allocating more
memory, etc.

	<mike
--
Must have walked those streets for hours,		Mike Meyer
In the dark and in the cold,				mwm@berkeley.edu
Before I really could accept,				ucbvax!mwm
There's no place called hope road.			mwm@ucbjade.BITNET

carolyn@cbmvax.UUCP (Carolyn Scheppner CATS) (07/15/88)

In article <4790@killer.UUCP> ltf@killer.UUCP (Lance Franklin) writes:
>Speaking of Chip RAM...just out of curiosity, does LoadSeg ever span CHIP and 
>FAST ram when loading hunks?  I.E. if I check the starting address of a
>structure to see if it's in CHIP or FAST ram, am I assured that the end of
>that structure will also be in the same ram, assuming it's all in the same
>chunk (a given, I think).

Since CHIP and FAST ram are in separate memlists, you don't have to worry
about any loaded segment spanning CHIP and FAST ram.  And since a
structure must be contiguous memory (else the offsets to its members
would not work), you should never have to worry about a structure being
split between 2 segments or two allocations.

>Oh, another thought...with the possibility, in the future, of machines with
>1 meg of CHIP ram, where do I go to find out the actual end of CHIP ram on
>any given machine.

The Exec MemList (ExecBase->MemList) is an exec List.  It's lh_Head
is the first MemHeader structure (whose ln_Succ is the next, etc).
One of the MemHeaders has the attribute bit for MEMF_CHIP set in its
mh_Attributes.  That's the CHIP memory MemHeader structure.  Its
member mh_Upper is the high address (+1) of the last byte.  Note that
there may actually be a bit more chip ram that this Upper value because
the system stack may be at the top of chip ram.

See the exec/memory.h include file.

-- 
==========================================================================
  Carolyn Scheppner -- CATS  Commodore Amiga Technical Support
  PHONE 215-431-9180   UUCP  ...{uunet,allegra,rutgers}!cbmvax!carolyn 

 "Toto, somehow I don't think we're in Kansas anymore"  -  Dorothy
==========================================================================

carolyn@cbmvax.UUCP (Carolyn Scheppner CATS) (07/16/88)

In article <4266@cbmvax.UUCP> carolyn@cbmvax.UUCP (Carolyn Scheppner CATS) writes:
>In article <4790@killer.UUCP> ltf@killer.UUCP (Lance Franklin) writes:
>[]
>>Oh, another thought...with the possibility, in the future, of machines with
>>1 meg of CHIP ram, where do I go to find out the actual end of CHIP ram on
>>any given machine.
>
>[I described scanning Exec mem list]

Dale points out that it's not a really great idea to depend on the
current format of the Exec memlists which should only be dealt with
via the provided system functions, since their exact format could change
in the future.  

So one other option would be to make some educated guesses about where
some chip mem should be and use the TypeOfMem() function to check those
addresses to see of they are CHIP ram.

Don't try to check the very top - if Exec puts its stack there, it removes
that memory from the memlist so that would probably be NO memory, not
CHIP memory.  

In addition, I believe there may be some 3rd-party ramdisks, etc, that
actually grab high memory and remove the memory from the Memlists
(not a good idea for future compatibility).

Currently, since all CHIP mem is mapped in 1st meg of address space,
ignoring the pieces Exec removes from the memlists at the start and 
end for its own devious purposes, the first 1/2 meg of CHIP is from
$0 to $7FFFF, and the second 1/2 meg is from $80000 to $FFFFF.

You'l have to pick some addresses within the second 1/2 meg range to
try TypeOfMem() on, low enough to avoid system stack and possible
3rd party high-chip memlist removals.

You could just check $80000, but remember that this will not tell
you if this RAM is free.  Just that it exists.

Why do you need to know the highest CHIP address they have ????
Wouldn't it be better to know how much CHIP ram they have FREE ??????

That's easy - AvailMem(MEMF_CHIP)
-- 
==========================================================================
  Carolyn Scheppner -- CATS  Commodore Amiga Technical Support
  PHONE 215-431-9180   UUCP  ...{uunet,allegra,rutgers}!cbmvax!carolyn 

 Oh I'm a numberjack and I'm OK, I code all night and I work all day...
==========================================================================

ltf@killer.UUCP (Lance Franklin) (07/16/88)

In article <4270@cbmvax.UUCP> carolyn@cbmvax.UUCP (Carolyn Scheppner CATS) writes:
>So one other option would be to make some educated guesses about where
>some chip mem should be and use the TypeOfMem() function to check those
>addresses to see of they are CHIP ram.
This is the first time I've ever heard of the TypeOfMem() function, except
for a mention in a previous message.  I couldn't find it in the RKM or Sybex's
Amiga Proggers Manual, so I assumed it was some function in Lattice (I use
Manx) or some subroutine another programmer did.  I just now checked in the
Developer's Ref Guide and found it, evidently a part of the exec.library...
could you describe the function for me?  Or tell me where I can find a
description?
>
>Why do you need to know the highest CHIP address they have ????
>Wouldn't it be better to know how much CHIP ram they have FREE ??????
>
>That's easy - AvailMem(MEMF_CHIP)
>
I was looking to create a quick and easy function that would check a passed
address (and size) of a structure and pass me back the original address (if
the structure is already in CHIP ram, or allocate the space in CHIP ram, copy
the structure into it and pass me back its address, keeping track of the
CHIP ram allocated so I can free it at the program's exit.  TypeOfMem() sounds
like just what I need to test the structures present location.

> Oh I'm a numberjack and I'm OK, I code all night and I work all day...
I Code B-Trees, I wear a dress, suspenders and a bra...
On Wednesdays I go Shopping, buy cokes and more twinkies!


Lance


-- 
+------------------+ +------------------------------------------------------+
| Lance T Franklin | |  Now accepting suggestions for clever, humourous or  |
|    ltf@killer    | |  incredibly insightful .signature quote.  Send Now!  |
+------------------+ +------------------------------------------------------+

dale@boing.UUCP (Dale Luck) (07/17/88)

In article <4270@cbmvax.UUCP> carolyn@cbmvax.UUCP (Carolyn Scheppner CATS) writes:
=Currently, since all CHIP mem is mapped in 1st meg of address space,
=ignoring the pieces Exec removes from the memlists at the start and 
=end for its own devious purposes, the first 1/2 meg of CHIP is from
=$0 to $7FFFF, and the second 1/2 meg is from $80000 to $FFFFF.
=
=You'l have to pick some addresses within the second 1/2 meg range to
=try TypeOfMem() on, low enough to avoid system stack and possible
=3rd party high-chip memlist removals.
=
=You could just check $80000, but remember that this will not tell
=you if this RAM is free.  Just that it exists.
=

However $80000 may in some future machine no longer be chip memory.
Moving the base address of chip memory from 0 tnd start it a 1m
would provide alot of benefits for 68000 users if we also put some
standard fast memory at location 0.
-- 
Dale Luck     Boing, Inc. {cbmvax|oliveb|pyramid}|!amiga!boing!dale
Although I do contract work for Amiga-LosGatos, my opinions probably
don't represent those of Commodore or its management or its engineers,
but I think the world would be a better place if they did.

cmcmanis%pepper@Sun.COM (Chuck McManis) (07/19/88)

In article <4790@killer.UUCP> ltf@killer.UUCP (Lance Franklin) writes:
> ...just out of curiosity, does LoadSeg ever span CHIP and FAST ram when 
> loading hunks? 

No, LoadSeg() can't know if there are internal relative references in the
chunk so it has to treat a chunk as an atomic unit. All languages for the
Amiga will not split data declarations across chunks.

> ...with the possibility, in the future, of machines with 1 meg of CHIP 
> ram, where do I go to find out the actual end of CHIP ram on any given 
> machine.

The beauty of this system is that this information is never needed. If 
you need to know how much chip RAM is available at a given time you can
call AvailMem(MEMF_CHIP) and if you want to know the biggest chunk of it
available you can call AvailMem(MEMF_CHIP+MEMF_LARGEST). Note that on 
future machines there is no restriction that Chip ram even start at 0!

--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.

carolyn@cbmvax.UUCP (Carolyn Scheppner CATS) (07/19/88)

In article <4811@killer.UUCP> ltf@killer.UUCP (Lance Franklin) writes:
>
>[RE TypeOfMem() function] ...                  I just now checked in the
>Developer's Ref Guide and found it, evidently a part of the exec.library...
>could you describe the function for me?  Or tell me where I can find a
>description?

TypeOfMem(address)
            a1

Described in the 1.2 Exec autodocs (as in the 1.2 Native Developer Update
disk set available from CATS for $20 US [+$5 shipping outside US]).

>I was looking to create a quick and easy function that would check a passed
>address (and size) of a structure and pass me back the original address (if
>the structure is already in CHIP ram, or allocate the space in CHIP ram, copy
>the structure into it and pass me back its address, keeping track of the
>CHIP ram allocated so I can free it at the program's exit.  TypeOfMem() sounds
>like just what I need to test the structures present location.

I thought I saw a couple of those come by here just recently.
Here's what I would try, off the top of my head (ie non-tested :-)

   - set up a null RememberKey (intuition thing)

     struct Remember *greallockey = NULL; /* Graphics realloc key */
     struct Remember **grkeyaddr = &greallockey;  /* we need addr of key */

   - pass your function address,size,and grkeyaddr

     maybeAlloc(addr,size,keyaddr)
     ULONG addr, size;
     struct Remember **keyaddr;
        {
        ULONG newaddr;

        if(TypeOfMem(addr) & MEMF_CHIP)  return(addr);
        else if(newaddr=AllocRemember(keyaddr,size,MEMF_CHIP))
           {
           CopyMem(addr,newaddr,size);
           return(newaddr);
           }
        else return(0);
        }

   - In your cleanup (after you are sure you are not displaying any
     of those images anymore). 

        if(greallockey)  FreeRemember(grkeyaddr,TRUE);


>> Oh I'm a numberjack and I'm OK, I code all night and I work all day...
>I Code B-Trees, I wear a dress, suspenders and a bra...
>On Wednesdays I go Shopping, buy cokes and more twinkies!

I like it.
-- 
==========================================================================
  Carolyn Scheppner -- CATS  Commodore Amiga Technical Support
  PHONE 215-431-9180   UUCP  ...{uunet,allegra,rutgers}!cbmvax!carolyn 

 I am fully operational and all of my circuits are funcTiOnINg pperrf...
==========================================================================