Annotation of MiNT/src/mem.h, revision 1.1.1.5

1.1       root        1: /*
                      2: 
1.1.1.3   root        3: Copyright 1990,1991,1992 Eric R. Smith.
                      4: 
1.1.1.5 ! root        5: Copyright 1992,1993,1994 Atari Corporation.
1.1.1.3   root        6: 
                      7: All rights reserved.
1.1       root        8: 
                      9: */
                     10: 
                     11: 
                     12: 
                     13: #ifndef _mem_h
                     14: 
                     15: #define _mem_h
                     16: 
                     17: 
                     18: 
1.1.1.2   root       19: #include "file.h"
                     20: 
                     21: 
                     22: 
1.1       root       23: typedef struct memregion {
                     24: 
                     25:        long    loc;            /* base of memory region */
                     26: 
                     27:        ulong   len;            /* length of memory region */
                     28: 
                     29:        ushort  links;          /* number of users of region */
                     30: 
                     31:        ushort  mflags;         /* e.g. which map this came from */
                     32: 
                     33:        struct memregion *next; /* next region in memory map */
                     34: 
                     35: } MEMREGION;
                     36: 
                     37: 
                     38: 
1.1.1.4   root       39: /* flags for memory regions: these are used only in MEMREGION struct */
1.1       root       40: 
1.1.1.4   root       41: #define M_CORE         0x01    /* region came from core map */
1.1       root       42: 
1.1.1.4   root       43: #define M_ALT          0x02    /* region came from alt map */
1.1       root       44: 
1.1.1.4   root       45: #define M_SWAP         0x04    /* region came from swap map */
1.1       root       46: 
1.1.1.4   root       47: #define M_KER          0x08    /* region came from kernel map */
1.1       root       48: 
1.1.1.4   root       49: #define M_MAP          0x0f    /* and with this to pick out map */
1.1       root       50: 
1.1.1.3   root       51: 
                     52: 
1.1.1.4   root       53: #define M_SHTEXT       0x10    /* region is a shared text region */
1.1.1.3   root       54: 
1.1.1.5 ! root       55: #define M_SHTEXT_T     0x20    /* `sticky bit' for shared text regions */
        !            56: 
        !            57: #define M_FSAVED       0x40    /* region is saved memory of a forked process */
        !            58: 
1.1.1.4   root       59: #define M_KEEP         0x0100  /* don't free on process termination */
1.1.1.3   root       60: 
1.1.1.5 ! root       61: #define M_SEEN         0x8000  /* for memused() to find links */
        !            62: 
1.1.1.3   root       63: 
                     64: 
1.1.1.4   root       65: /* dummy type for virtual addresses */
1.1.1.3   root       66: 
1.1.1.4   root       67: typedef struct vaddr {
1.1.1.3   root       68: 
1.1.1.4   root       69:        char dummy;
1.1.1.3   root       70: 
1.1.1.4   root       71: } *virtaddr;
1.1.1.3   root       72: 
                     73: 
                     74: 
1.1.1.4   root       75: /* structure for shared text regions */
1.1.1.3   root       76: 
                     77: 
                     78: 
1.1.1.4   root       79: typedef struct shtextreg {
1.1.1.3   root       80: 
1.1.1.4   root       81:        FILEPTR *f;             /* what file did this come from? */
1.1.1.3   root       82: 
1.1.1.4   root       83:        MEMREGION *text;        /* pointer to shared text region */
1.1       root       84: 
1.1.1.4   root       85:        short mtime, mdate;     /* date & time for file */
1.1.1.2   root       86: 
1.1.1.4   root       87:        struct shtextreg *next;
1.1.1.2   root       88: 
1.1.1.4   root       89: } SHTEXT;
1.1.1.2   root       90: 
                     91: 
                     92: 
1.1.1.4   root       93: /*
1.1.1.2   root       94: 
1.1.1.4   root       95:  * Here's the deal with memory bits:
1.1.1.2   root       96: 
1.1.1.4   root       97:  *
1.1.1.2   root       98: 
1.1.1.4   root       99:  * Mxalloc(long size, int mode) takes these fields in 'mode': BITS 0-2 hold
1.1.1.2   root      100: 
1.1.1.4   root      101:  * values 0-3 for the old GEMDOS mode argument.  If bit 3 is on, then only
1.1.1.2   root      102: 
1.1.1.4   root      103:  * F_PROTMODE (bits 4-7) counts, and it encodes the desired protection mode
1.1.1.2   root      104: 
1.1.1.4   root      105:  * to change a block to. Else F_PROTMODE is the desired protection mode for
1.1.1.2   root      106: 
1.1.1.4   root      107:  * the new block you're allocating.  In either case, F_PROTMODE turns into
1.1.1.2   root      108: 
1.1.1.4   root      109:  * a PROT_* thusly: if it's zero, you get the F_PROTMODE value from curproc's
1.1.1.2   root      110: 
1.1.1.4   root      111:  * prgflags. Else you get (F_PROTMODE >> F_PROTSHIFT)-1.
1.1.1.2   root      112: 
1.1.1.4   root      113:  *
1.1.1.2   root      114: 
1.1.1.4   root      115:  * The 0x4000 bit is carried along into get_region (but not from there into
1.1.1.2   root      116: 
1.1.1.4   root      117:  * mark_region) and, if set, causes M_KEEP to be set in the region's
1.1.1.2   root      118: 
1.1.1.4   root      119:  * mflags.
1.1       root      120: 
1.1.1.4   root      121:  */
1.1       root      122: 
                    123: 
                    124: 
1.1.1.2   root      125: /* structure of exectuable program headers */
1.1       root      126: 
1.1.1.2   root      127: typedef struct fileheader {
1.1       root      128: 
1.1.1.2   root      129:        short   fmagic;
1.1       root      130: 
1.1.1.2   root      131:        long    ftext;
                    132: 
                    133:        long    fdata;
                    134: 
                    135:        long    fbss;
                    136: 
                    137:        long    fsym;
                    138: 
                    139:        long    reserved;
                    140: 
                    141:        long    flag;
                    142: 
                    143:        short   reloc;
                    144: 
                    145: } FILEHEAD;
                    146: 
                    147: 
                    148: 
                    149: #define GEMDOS_MAGIC 0x601a
1.1       root      150: 
                    151: 
                    152: 
                    153: /* flags for curproc->memflags */
                    154: 
1.1.1.3   root      155: /* also used for program headers PRGFLAGS */
1.1.1.2   root      156: 
1.1       root      157: #define F_FASTLOAD     0x01            /* don't zero heap */
                    158: 
                    159: #define F_ALTLOAD      0x02            /* OK to load in alternate ram */
                    160: 
                    161: #define F_ALTALLOC     0x04            /* OK to malloc from alt. ram */
                    162: 
1.1.1.2   root      163: #define F_RESERVED     0x08            /* reserved for future use */
                    164: 
                    165: #define F_MEMFLAGS     0xf0            /* reserved for future use */
                    166: 
                    167: #define F_SHTEXT       0x800           /* program's text may be shared */
                    168: 
                    169: 
                    170: 
                    171: #define F_MINALT       0xf0000000L     /* used to decide which type of RAM to load in */
                    172: 
1.1       root      173: 
                    174: 
1.1.1.3   root      175: /* Bit in Mxalloc's arg for "don't auto-free this memory" */
                    176: 
                    177: #define F_KEEP         0x4000
                    178: 
                    179: 
                    180: 
                    181: #define F_OS_SPECIAL   0x8000          /* mark as a special process */
                    182: 
                    183: 
                    184: 
                    185: /* flags for curproc->memflags (that is, PRGFLAGS) and also Mxalloc mode.  */
                    186: 
                    187: /* (Actually, when users call Mxalloc, they add 0x10 to what you see here) */
                    188: 
                    189: #define        F_PROTMODE      0xf0            /* protection mode bits */
                    190: 
                    191: #define F_PROT_P       0x00            /* no read or write */
                    192: 
                    193: #define F_PROT_G       0x10            /* any access OK */
1.1       root      194: 
1.1.1.3   root      195: #define F_PROT_S       0x20            /* any super access OK */
                    196: 
                    197: #define F_PROT_PR      0x30            /* any read OK, no write */
                    198: 
                    199: #define F_PROT_I       0x40            /* invalid page */
                    200: 
                    201: 
                    202: 
                    203: /* actual values found in page_mode_table and used as args to alloc_region */
                    204: 
                    205: #define PROT_P 0
                    206: 
                    207: #define PROT_G 1
                    208: 
                    209: #define PROT_S 2
                    210: 
                    211: #define PROT_PR        3
                    212: 
                    213: #define PROT_I 4
                    214: 
1.1.1.4   root      215: #define PROT_MAX_MODE 4
                    216: 
1.1.1.3   root      217: #define PROT_PROTMODE 0xf   /* these bits are the prot mode */
                    218: 
                    219: #define PROT_NOCHANGE -1
                    220: 
                    221: 
                    222: 
                    223: #define F_PROTSHIFT    4
1.1       root      224: 
                    225: 
                    226: 
                    227: typedef MEMREGION **MMAP;
                    228: 
1.1.1.2   root      229: 
                    230: 
                    231: #ifndef GENMAGIC
                    232: 
1.1       root      233: extern MMAP core, alt, ker, swap;
                    234: 
1.1.1.2   root      235: #endif
                    236: 
1.1       root      237: 
                    238: 
                    239: /* compilers differ on what "sizeof" returns */
                    240: 
                    241: #define SIZEOF         (long)sizeof
                    242: 
                    243: 
                    244: 
1.1.1.3   root      245: /* QUANTUM: the page size for the mmu: 8K.  This is hard-coded elsewhere. */
                    246: 
                    247: #define QUANTUM 0x2000L
                    248: 
                    249: 
                    250: 
                    251: /* MiNT leaves this much memory for TOS to use (8K)
1.1       root      252: 
                    253:  */
                    254: 
1.1.1.3   root      255: #define TOS_MEM                (QUANTUM)
1.1       root      256: 
                    257: 
                    258: 
                    259: /* MiNT tries to keep this much memory available for the kernel and other
                    260: 
1.1.1.3   root      261:  * programs when a program is launched (8K)
1.1       root      262: 
                    263:  */
                    264: 
1.1.1.3   root      265: #define KEEP_MEM       (QUANTUM)
1.1       root      266: 
                    267: 
                    268: 
                    269: /*
                    270: 
1.1.1.3   root      271:  * how much memory should be allocated to the kernel? (24K)
                    272: 
                    273:  */
                    274: 
                    275: #define KERNEL_MEM     (3*QUANTUM)
                    276: 
                    277: 
                    278: 
                    279: /* macro for rounding off region sizes to QUANTUM (page) boundaries */
                    280: 
                    281: /* there is code in mem.c that assumes it's OK to put the screen
                    282: 
                    283:  * in any region, so this should be at least 256 for STs (16 is OK for
                    284: 
                    285:  * STes, TTs, and Falcons). We actually set a variable in main.c
                    286: 
                    287:  * that holds the screen boundary stuff.
1.1       root      288: 
                    289:  */
                    290: 
1.1.1.3   root      291: extern int no_mem_prot;
1.1       root      292: 
1.1.1.3   root      293: extern int screen_boundary;
1.1       root      294: 
                    295: 
                    296: 
1.1.1.3   root      297: #define MASKBITS       (no_mem_prot ? screen_boundary : (QUANTUM-1))
1.1       root      298: 
                    299: #define ROUND(size) ((size + MASKBITS) & ~MASKBITS)
                    300: 
                    301: 
                    302: 
1.1.1.3   root      303: /* interesting memory constants */
                    304: 
                    305: 
                    306: 
                    307: #define EIGHT_K (0x400L*8L)
                    308: 
                    309: #define ONE_MEG 0x00100000L
                    310: 
                    311: #define LOG2_ONE_MEG 20
                    312: 
                    313: #define LOG2_16_MEG 24
                    314: 
                    315: #define LOG2_EIGHT_K 13
                    316: 
                    317: #define SIXTEEN_MEG (0x400L*0x400L*16L)
                    318: 
                    319: 
                    320: 
                    321: /* macro for turning a curproc->base_table pointer into a 16-byte boundary */
                    322: 
                    323: #define ROUND16(ld) ((long_desc *)(((ulong)(ld) + 15) & ~15))
                    324: 
                    325: 
                    326: 
                    327: /* TBL_SIZE is the size in entries of the A, B, and C level tables */
                    328: 
                    329: #define TBL_SIZE (16)
                    330: 
                    331: #define TBL_SIZE_BYTES (TBL_SIZE * sizeof(long_desc))
                    332: 
                    333: 
                    334: 
                    335: typedef struct {
                    336: 
                    337:        short limit;
                    338: 
                    339:        unsigned zeros:14;
                    340: 
                    341:        unsigned dt:2;
                    342: 
                    343:        struct long_desc *tbl_address;
                    344: 
                    345: } crp_reg;
                    346: 
                    347: 
                    348: 
                    349: /* format of long descriptors, both page descriptors and table descriptors */
                    350: 
                    351: 
                    352: 
                    353: typedef struct {
                    354: 
                    355:     unsigned limit;            /* set to $7fff to disable */
                    356: 
                    357:     unsigned unused1:6;
                    358: 
                    359:     unsigned unused2:1;
                    360: 
                    361:     unsigned s:1;              /* 1 grants supervisor access only */
                    362: 
                    363:     unsigned unused3:1;
                    364: 
                    365:     unsigned ci:1;             /* cache inhibit: used in page desc only */
                    366: 
                    367:     unsigned unused4:1;
                    368: 
                    369:     unsigned m:1;              /* modified: used in page desc only */
                    370: 
                    371:     unsigned u:1;              /* accessed */
                    372: 
                    373:     unsigned wp:1;             /* write-protected */
                    374: 
                    375:     unsigned dt:2;             /* type */
                    376: 
                    377: } page_type;
                    378: 
                    379: 
                    380: 
                    381: typedef struct long_desc {
                    382: 
                    383:     page_type page_type;
                    384: 
                    385:     struct long_desc *tbl_address;
                    386: 
                    387: } long_desc;
                    388: 
                    389: 
                    390: 
                    391: typedef struct {
                    392: 
                    393:     unsigned enable:1;
                    394: 
                    395:     unsigned zeros:5;
                    396: 
                    397:     unsigned sre:1;
                    398: 
                    399:     unsigned fcl:1;
                    400: 
                    401:     unsigned ps:4;
                    402: 
                    403:     unsigned is:4;
                    404: 
                    405:     unsigned tia:4;
                    406: 
                    407:     unsigned tib:4;
                    408: 
                    409:     unsigned tic:4;
                    410: 
                    411:     unsigned tid:4;
                    412: 
                    413: } tc_reg;
                    414: 
                    415: 
                    416: 
1.1       root      417: #endif /* _mem_h */
                    418: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.