Annotation of uae/src/expansion.c, revision 1.1.1.2

1.1       root        1:  /* 
                      2:   * UAE - The Un*x Amiga Emulator
                      3:   * 
                      4:   *  Expansion Slots
                      5:   *
1.1.1.2 ! root        6:   * Copyright 1996 Stefan Reinauer <[email protected]>
1.1       root        7:   */
                      8: 
                      9: #include "sysconfig.h"
                     10: #include "sysdeps.h"
                     11: 
                     12: #include "config.h"
                     13: #include "options.h"
                     14: #include "memory.h"
                     15: #include "custom.h"
1.1.1.2 ! root       16: #include "readcpu.h"
1.1       root       17: #include "newcpu.h"
                     18: #include "autoconf.h"
                     19: 
                     20: #define MAX_EXPANSION_BOARDS 5
                     21: 
                     22: /* 00 / 02 */
                     23: 
                     24: #define MEM_8MB    0x00        /* Size of Memory Block           */
                     25: #define MEM_4MB    0x07
                     26: #define MEM_2MB    0x06
                     27: #define MEM_1MB    0x05
                     28: #define MEM_512KB  0x04
                     29: #define MEM_256KB  0x03
                     30: #define MEM_128KB  0x02
                     31: #define MEM_64KB   0x01
                     32:  
                     33: #define same_slot  0x08     /* Next card is in the same Slot  */
                     34: #define rom_card   0x10     /* Card has valid ROM             */
                     35: #define add_memory 0x20     /* Add Memory to List of Free Ram */
                     36: 
                     37: #define generic    0xc0     /* Type of Expansion Card         */
                     38: #define future1    0x00
                     39: #define future2    0x40
                     40: #define future3    0x80
                     41: 
                     42: /* ********************************************************** */
                     43: 
1.1.1.2 ! root       44: /* Card Data */
1.1       root       45: 
                     46: /* 04 - 06 & 10-16 */
                     47: #define commodore_g   513  /* Commodore Braunschweig (Germany) */
                     48: #define commodore     514  /* Commodore West Chester           */
                     49: #define gvp         2017  /* GVP */
                     50: #define hackers_id   2011
                     51: 
                     52: #define   commodore_a2091         3  /* A2091 / A590 Card from C=   */
                     53: #define   commodore_a2091_ram    10  /* A2091 / A590 Ram on HD-Card */
                     54: #define   commodore_a2232        70  /* A2232 Multiport Expansion   */
                     55: 
                     56: #define   gvp_series_2_scsi      11
                     57: #define   gvp_iv_24_gfx          32
                     58: 
                     59: /* ********************************************************** */
                     60: /* 08-0A */
                     61: 
                     62: #define no_shutup  64  /* Card cannot receive Shut_up_forever */
                     63: #define care_addr 128  /* Adress HAS to be $200000-$9fffff    */
                     64: 
                     65: /* ********************************************************** */
                     66: 
                     67: /* 40-42 */
                     68: #define enable_irq   1  /* enable Interrupt                   */ 
                     69: #define reset_card   4  /* Reset of Expansion Card            */
                     70: #define card_int2   16  /* READ ONLY: IRQ 2 occured           */
                     71: #define card_irq6   32  /* READ ONLY: IRQ 6 occured           */
                     72: #define card_irq7   64  /* READ ONLY: IRQ 7 occured           */
                     73: #define does_irq   128  /* READ ONLY: Karte loest ger. IRQ aus*/
                     74: 
                     75: /* ********************************************************** */
                     76: 
                     77: /* ROM defines */
                     78: 
                     79: #define rom_4bit    (0x00<<14) /* ROM width */
                     80: #define rom_8bit    (0x01<<14)
                     81: #define rom_16bit   (0x02<<14)
                     82: 
                     83: #define rom_never   (0x00<<12) /* Never run Boot Code       */
                     84: #define rom_install (0x01<<12) /* run code at install time  */
                     85: #define rom_binddrv (0x02<<12) /* run code with binddrivers */
                     86: 
                     87: CPTR ROM_filesys_resname = 0, ROM_filesys_resid = 0;
                     88: CPTR ROM_filesys_diagentry = 0;
                     89: CPTR ROM_hardfile_resname = 0, ROM_hardfile_resid = 0;
                     90: CPTR ROM_hardfile_init = 0;
                     91: 
                     92: /* ********************************************************** */
                     93: 
                     94: static void expamem_init_clear(void);
                     95: static void expamem_map_clear(void);
                     96: static void expamem_init_fastcard(void);
                     97: static void expamem_map_fastcard(void);
                     98: static void expamem_init_filesys(void);
                     99: static void expamem_map_filesys(void);
                    100: 
                    101: void (*card_init[MAX_EXPANSION_BOARDS])(void);
                    102: void (*card_map[MAX_EXPANSION_BOARDS])(void);
                    103: 
                    104: int ecard = 0;
                    105: 
1.1.1.2 ! root      106: /*
1.1       root      107:  *  Fast Memory
1.1.1.2 ! root      108:  */
1.1       root      109: 
                    110: static ULONG fastmem_mask;
                    111: 
                    112: static ULONG fastmem_alget(CPTR) REGPARAM;
1.1.1.2 ! root      113: static ULONG fastmem_awget(CPTR) REGPARAM;
1.1       root      114: static ULONG fastmem_lget(CPTR) REGPARAM;
1.1.1.2 ! root      115: static ULONG fastmem_wget(CPTR) REGPARAM;
        !           116: static ULONG fastmem_bget(CPTR) REGPARAM;
1.1       root      117: static void  fastmem_lput(CPTR, ULONG) REGPARAM;
1.1.1.2 ! root      118: static void  fastmem_wput(CPTR, ULONG) REGPARAM;
        !           119: static void  fastmem_bput(CPTR, ULONG) REGPARAM;
1.1       root      120: static int   fastmem_check(CPTR addr, ULONG size) REGPARAM;
                    121: static UBYTE *fastmem_xlate(CPTR addr) REGPARAM;
                    122: 
                    123: static ULONG fastmem_start; /* Determined by the OS */
                    124: static UBYTE *fastmemory = NULL;
                    125: 
1.1.1.2 ! root      126: ULONG REGPARAM2 fastmem_alget(CPTR addr)
1.1       root      127: {
                    128:     UBYTE *m;
                    129:     addr -= fastmem_start & fastmem_mask;
                    130:     addr &= fastmem_mask;
                    131:     m = fastmemory + addr;
                    132:     return (((ULONG)m[0] << 24) + ((ULONG)m[1] << 16) 
                    133:            + ((ULONG)m[2] << 8) + ((ULONG)m[3]));
                    134: }
                    135: 
1.1.1.2 ! root      136: ULONG REGPARAM2 fastmem_awget(CPTR addr)
1.1       root      137: {
                    138:     UBYTE *m;
                    139:     addr -= fastmem_start & fastmem_mask;
                    140:     addr &= fastmem_mask;
                    141:     m = fastmemory + addr;
                    142:     return ((UWORD)m[0] << 8) + m[1];
                    143: }
                    144: 
1.1.1.2 ! root      145: ULONG REGPARAM2 fastmem_lget(CPTR addr)
1.1       root      146: {
                    147:     UBYTE *m;
                    148:     addr -= fastmem_start & fastmem_mask;
                    149:     addr &= fastmem_mask;
                    150:     m = fastmemory + addr;
                    151:     return (((ULONG)m[0] << 24) + ((ULONG)m[1] << 16) 
                    152:            + ((ULONG)m[2] << 8) + ((ULONG)m[3]));
                    153: }
                    154: 
1.1.1.2 ! root      155: ULONG REGPARAM2 fastmem_wget(CPTR addr)
1.1       root      156: {
                    157:     UBYTE *m;
                    158:     addr -= fastmem_start & fastmem_mask;
                    159:     addr &= fastmem_mask;
                    160:     m = fastmemory + addr;
                    161:     return ((UWORD)m[0] << 8) + m[1];
                    162: }
                    163: 
1.1.1.2 ! root      164: ULONG REGPARAM2 fastmem_bget(CPTR addr)
1.1       root      165: {
                    166:     addr -= fastmem_start & fastmem_mask;
                    167:     addr &= fastmem_mask;
                    168:     return fastmemory[addr];
                    169: }
                    170: 
1.1.1.2 ! root      171: void REGPARAM2 fastmem_lput(CPTR addr, ULONG l)
1.1       root      172: {
                    173:     UBYTE *m;
                    174:     addr -= fastmem_start & fastmem_mask;
                    175:     addr &= fastmem_mask;
                    176:     m = fastmemory + addr;
                    177:     m[0] = l >> 24;
                    178:     m[1] = l >> 16;
                    179:     m[2] = l >> 8;
                    180:     m[3] = l;
                    181: }
                    182: 
1.1.1.2 ! root      183: void REGPARAM2 fastmem_wput(CPTR addr, ULONG w)
1.1       root      184: {
                    185:     UBYTE *m;
                    186:     addr -= fastmem_start & fastmem_mask;
                    187:     addr &= fastmem_mask;
                    188:     m = fastmemory + addr;
                    189:     m[0] = w >> 8;
                    190:     m[1] = w;
                    191: }
                    192: 
1.1.1.2 ! root      193: void REGPARAM2 fastmem_bput(CPTR addr, ULONG b)
1.1       root      194: {
                    195:     addr -= fastmem_start & fastmem_mask;
                    196:     addr &= fastmem_mask;
                    197:     fastmemory[addr] = b;
                    198: }
                    199: 
1.1.1.2 ! root      200: static int REGPARAM2 fastmem_check(CPTR addr, ULONG size)
1.1       root      201: {
                    202:     addr -= fastmem_start & fastmem_mask;
                    203:     addr &= fastmem_mask;
                    204:     return (addr + size) < fastmem_size;
                    205: }
                    206: 
1.1.1.2 ! root      207: static UBYTE REGPARAM2 *fastmem_xlate(CPTR addr)
1.1       root      208: {
                    209:     addr -= fastmem_start & fastmem_mask;
                    210:     addr &= fastmem_mask;
                    211:     return fastmemory + addr;
                    212: }
                    213: 
                    214: addrbank fastmem_bank = {
                    215:     fastmem_alget, fastmem_awget,
                    216:     fastmem_lget, fastmem_wget, fastmem_bget,
                    217:     fastmem_lput, fastmem_wput, fastmem_bput,
                    218:     fastmem_xlate, fastmem_check
                    219: };
                    220: 
                    221: 
                    222: /*
                    223:  * Filesystem device ROM
1.1.1.2 ! root      224:  * This is very simple, the Amiga shouldn't be doing things with it. 
1.1       root      225:  */
                    226: 
                    227: static ULONG filesys_lget(CPTR) REGPARAM;
1.1.1.2 ! root      228: static ULONG filesys_wget(CPTR) REGPARAM;
        !           229: static ULONG filesys_bget(CPTR) REGPARAM;
1.1       root      230: static void  filesys_lput(CPTR, ULONG) REGPARAM;
1.1.1.2 ! root      231: static void  filesys_wput(CPTR, ULONG) REGPARAM;
        !           232: static void  filesys_bput(CPTR, ULONG) REGPARAM;
1.1       root      233: 
                    234: static ULONG filesys_start; /* Determined by the OS */
                    235: static UBYTE filesysory[65536];
                    236: 
1.1.1.2 ! root      237: ULONG REGPARAM2 filesys_lget(CPTR addr)
1.1       root      238: {
                    239:     UBYTE *m;
                    240:     addr -= filesys_start & 65535;
                    241:     addr &= 65535;
                    242:     m = filesysory + addr;
                    243:     return (((ULONG)m[0] << 24) + ((ULONG)m[1] << 16) 
                    244:            + ((ULONG)m[2] << 8) + ((ULONG)m[3]));
                    245: }
                    246: 
1.1.1.2 ! root      247: ULONG REGPARAM2 filesys_wget(CPTR addr)
1.1       root      248: {
                    249:     UBYTE *m;
                    250:     addr -= filesys_start & 65535;
                    251:     addr &= 65535;
                    252:     m = filesysory + addr;
                    253:     return ((UWORD)m[0] << 8) + m[1];
                    254: }
                    255: 
1.1.1.2 ! root      256: ULONG REGPARAM2 filesys_bget(CPTR addr)
1.1       root      257: {
                    258:     addr -= filesys_start & 65535;
                    259:     addr &= 65535;
                    260:     return filesysory[addr];
                    261: }
                    262: 
1.1.1.2 ! root      263: static void REGPARAM2 filesys_lput(CPTR addr, ULONG l)
1.1       root      264: {
                    265:     fprintf(stderr, "filesys_lput called\n");
                    266: }
                    267: 
1.1.1.2 ! root      268: static void REGPARAM2 filesys_wput(CPTR addr, ULONG w)
1.1       root      269: {
                    270:     fprintf(stderr, "filesys_wput called\n");
                    271: }
                    272: 
1.1.1.2 ! root      273: static void REGPARAM2 filesys_bput(CPTR addr, ULONG b)
1.1       root      274: {
                    275:     fprintf(stderr, "filesys_bput called\n");
                    276: }
                    277: 
                    278: addrbank filesys_bank = {
                    279:     default_alget, default_awget,
                    280:     filesys_lget, filesys_wget, filesys_bget,
                    281:     filesys_lput, filesys_wput, filesys_bput,
                    282:     default_xlate, default_check
                    283: };
                    284: 
                    285: /* Autoconfig address space at 0xE80000 */
                    286: static UBYTE expamem[65536];
                    287: 
                    288: static UBYTE expamem_lo;
                    289: static UBYTE expamem_hi;
                    290: 
                    291: static ULONG expamem_lget(CPTR) REGPARAM;
1.1.1.2 ! root      292: static ULONG expamem_wget(CPTR) REGPARAM;
        !           293: static ULONG expamem_bget(CPTR) REGPARAM;
1.1       root      294: static void  expamem_lput(CPTR, ULONG) REGPARAM;
1.1.1.2 ! root      295: static void  expamem_wput(CPTR, ULONG) REGPARAM;
        !           296: static void  expamem_bput(CPTR, ULONG) REGPARAM;
1.1       root      297: 
                    298: addrbank expamem_bank = {
                    299:     expamem_lget, expamem_wget,
                    300:     expamem_lget, expamem_wget, expamem_bget,
                    301:     expamem_lput, expamem_wput, expamem_bput,
                    302:     default_xlate, default_check
                    303: };
                    304: 
1.1.1.2 ! root      305: static ULONG REGPARAM2 expamem_lget(CPTR addr)
1.1       root      306: {
                    307:     fprintf(stderr,"warning: READ.L from address $%lx \n",addr);
1.1.1.2 ! root      308:     return 0xfffffffful;
1.1       root      309: }
                    310: 
1.1.1.2 ! root      311: static ULONG REGPARAM2 expamem_wget(CPTR addr)
1.1       root      312: {
                    313:     fprintf(stderr,"warning: READ.W from address $%lx \n",addr);
                    314:     return 0xffff;
                    315: }
                    316: 
1.1.1.2 ! root      317: static ULONG REGPARAM2 expamem_bget(CPTR addr)
1.1       root      318: {
                    319:     UBYTE value;
                    320:     addr &= 0xFFFF;
                    321:     return expamem[addr];
                    322: }
                    323: 
1.1.1.2 ! root      324: static void  REGPARAM2 expamem_write(CPTR addr, ULONG value)
1.1       root      325: {
                    326:     addr &= 0xffff;
                    327:     if (addr==00 || addr==02 || addr==0x40 || addr==0x42) {
                    328:        expamem[addr] = (value & 0xf0);
                    329:        expamem[addr+2] = (value & 0x0f) << 4;
                    330:     } else {
                    331:        expamem[addr] = ~(value & 0xf0);
                    332:        expamem[addr+2] = ~((value & 0x0f) << 4);
                    333:     }
                    334: }
                    335: 
1.1.1.2 ! root      336: static void REGPARAM2 expamem_lput(CPTR addr, ULONG value)
1.1       root      337: {
                    338:     fprintf(stderr,"warning: WRITE.L to address $%lx : value $%lx\n",addr,value);
                    339: }
                    340: 
1.1.1.2 ! root      341: static void REGPARAM2 expamem_wput(CPTR addr, ULONG value)
1.1       root      342: {
                    343:     fprintf(stderr,"warning: WRITE.W to address $%lx : value $%x\n",addr,value);
                    344: }
                    345: 
1.1.1.2 ! root      346: static void REGPARAM2 expamem_bput(CPTR addr, ULONG value)
1.1       root      347: {
                    348:     switch (addr&0xff) {
                    349:      case 0x30:
                    350:      case 0x32:
                    351:        expamem_hi = 0;
                    352:        expamem_lo = 0;
                    353:        expamem_write (0x48, 0x00);
                    354:        break;
                    355: 
                    356:      case 0x48:    
                    357:        expamem_hi = value;
                    358:         (*card_map[ecard])();
                    359:         fprintf (stderr,"   Card %d done.\n",ecard+1);
                    360:         ++ecard;
                    361:         if (ecard <= MAX_EXPANSION_BOARDS)
                    362:            (*card_init[ecard])();
                    363:        else
                    364:            expamem_init_clear();
                    365:                break;
                    366:     
                    367:      case 0x4a:        
                    368:        expamem_lo = value;
                    369:        break;
                    370:        
                    371:      case 0x4c:
                    372:         fprintf (stderr,"   Card %d had no success.\n",ecard+1);
                    373:         ++ecard;
                    374:         if (ecard <= MAX_EXPANSION_BOARDS) 
                    375:            (*card_init[ecard])();
                    376:        else  
                    377:            expamem_init_clear();
                    378:         break;
                    379:     }
                    380: }
                    381: 
                    382: void expamem_reset()
                    383: {
                    384:     int cardno = 0;
                    385: 
                    386:     ecard = 0;
                    387:     
                    388:     if (fastmemory != NULL) {
                    389:        card_init[cardno] = expamem_init_fastcard;
                    390:        card_map[cardno++] = expamem_map_fastcard;
                    391:     }
                    392: 
                    393:     if (automount_uaedev && !ersatzkickfile) {
                    394:        card_init[cardno] = expamem_init_filesys;
                    395:        card_map[cardno++] = expamem_map_filesys;
                    396:     }
                    397: 
                    398:     while (cardno < MAX_EXPANSION_BOARDS) {
                    399:        card_init[cardno] = expamem_init_clear;
                    400:        card_map[cardno++] = expamem_map_clear;
                    401:     }
                    402:     
                    403:     (*card_init[0])();
                    404: }
                    405: 
                    406: void expansion_init(void)
                    407: {
                    408:     if (fastmem_size > 0) {
                    409:        fastmem_mask = fastmem_size - 1;
                    410:        fastmemory = (UBYTE *)calloc(fastmem_size,1);
                    411:        if (fastmemory == NULL) {
                    412:            fprintf (stderr,"Out of memory for fastmem card.\n");
                    413:        }
                    414:     }
                    415: }
                    416: 
1.1.1.2 ! root      417: /*
1.1       root      418:  *     Expansion Card (ZORRO II) for 1/2/4/8 MB of Fast Memory
1.1.1.2 ! root      419:  */
1.1       root      420: 
                    421: void expamem_map_fastcard()
                    422: {
                    423:     fastmem_start = ((expamem_hi|(expamem_lo>>4)) << 16);
                    424:     map_banks (&fastmem_bank, fastmem_start >> 16, fastmem_size >> 16);
                    425:     fprintf (stderr,"Fastcard: mapped @$%lx: %dMB fast memory\n",fastmem_start, fastmem_size >>20);
                    426: }
                    427: 
                    428: void expamem_init_fastcard()
                    429: {
                    430:     expamem_init_clear();
                    431:     if (fastmem_size==0x100000)
                    432:        expamem_write (0x00, MEM_1MB+add_memory+generic);
                    433:     else if (fastmem_size==0x200000)
                    434:        expamem_write (0x00, MEM_2MB+add_memory+generic);
                    435:     else if (fastmem_size==0x400000)
                    436:        expamem_write (0x00, MEM_4MB+add_memory+generic);
                    437:     else if (fastmem_size==0x800000)
                    438:        expamem_write (0x00, MEM_8MB+add_memory+generic);
                    439: 
                    440:     expamem_write (0x08, care_addr);
                    441: 
                    442:     expamem_write (0x04, 1);
                    443:     expamem_write (0x10, hackers_id >> 8);
                    444:     expamem_write (0x14, hackers_id & 0x0f);
                    445: 
                    446:     expamem_write (0x18, 0x00); /* ser.no. Byte 0 */
                    447:     expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */
                    448:     expamem_write (0x20, 0x00); /* ser.no. Byte 2 */
                    449:     expamem_write (0x24, 0x01); /* ser.no. Byte 3 */
                    450: 
                    451:     expamem_write (0x28, 0x00); /* Rom-Offset hi  */
                    452:     expamem_write (0x2c, 0x00); /* ROM-Offset lo  */
                    453: 
                    454:     expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/
                    455: }
                    456: 
                    457: /* 
                    458:  * Filesystem device
                    459:  */
                    460: 
                    461: void expamem_map_filesys()
                    462: {
                    463:     filesys_start=((expamem_hi | (expamem_lo >> 4)) << 16);
                    464:     map_banks(&filesys_bank, filesys_start >> 16, 1);
                    465: }
                    466: 
                    467: void expamem_init_filesys()
                    468: {
                    469:     UBYTE diagarea[] = { 0x90, 0x00, 0x01, 0x0C, 0x01, 0x00, 0x01, 0x06 };
                    470: 
                    471:     expamem_init_clear();
                    472:     expamem_write (0x00, MEM_64KB | rom_card | generic);
                    473: 
                    474:     expamem_write (0x08, care_addr | no_shutup);
                    475: 
                    476:     expamem_write (0x04, 2);
                    477:     expamem_write (0x10, hackers_id >> 8);
                    478:     expamem_write (0x14, hackers_id & 0x0f);
                    479: 
                    480:     expamem_write (0x18, 0x00); /* ser.no. Byte 0 */
                    481:     expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */
                    482:     expamem_write (0x20, 0x00); /* ser.no. Byte 2 */
                    483:     expamem_write (0x24, 0x01); /* ser.no. Byte 3 */
                    484: 
                    485:     expamem_write (0x28, 0x10); /* Rom-Offset hi  */
                    486:     expamem_write (0x2c, 0x00); /* ROM-Offset lo  */
                    487: 
                    488:     expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/
                    489: 
                    490:     /* Build a DiagArea */
                    491:     memcpy(expamem + 0x1000, diagarea, sizeof diagarea);
                    492:     
                    493:     /* Call DiagEntry */
                    494:     expamem[0x1100] = 0x4E;
                    495:     expamem[0x1101] = 0xF9; /* JMP */
                    496:     expamem[0x1102] = ROM_filesys_diagentry>>24;
                    497:     expamem[0x1103] = ROM_filesys_diagentry>>16;
                    498:     expamem[0x1104] = ROM_filesys_diagentry>>8;
                    499:     expamem[0x1105] = ROM_filesys_diagentry;
                    500:     
                    501:     /* What comes next is a plain bootblock */
                    502:     expamem[0x1106] = 0x4E;
                    503:     expamem[0x1107] = 0xF9; /* JMP */
                    504:     expamem[0x1108] = EXPANSION_bootcode>>24;
                    505:     expamem[0x1109] = EXPANSION_bootcode>>16;
                    506:     expamem[0x110A] = EXPANSION_bootcode>>8;
                    507:     expamem[0x110B] = EXPANSION_bootcode;
                    508:     memcpy(filesysory, expamem, 0x2000);
                    509: }
                    510: 
1.1.1.2 ! root      511: /*
1.1       root      512:  *  Dummy Entries to show that there's no card in a slot
1.1.1.2 ! root      513:  */
1.1       root      514: 
                    515: void expamem_map_clear()
                    516: {
                    517:     fprintf(stderr, "expamem_map_clear() got called. Shouldn't happen.\n");
                    518: }
                    519: 
                    520: void expamem_init_clear()
                    521: {
                    522:     memset (expamem,0xff,sizeof expamem);
                    523: }

unix.superglobalmegacorp.com

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