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

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

unix.superglobalmegacorp.com

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