/* * xmfree - Function 0x49 (Mfree) */ long xmfree(void *addr) { MD *p,**q; MPB *mpb; KDEBUG(("BDOS: Mfree(0x%08lx)\n",(ULONG)addr)); if (((UBYTE *)addr >= start_stram) && ((UBYTE *)addr <= end_stram)) { mpb = &pmd; #if CONF_WITH_ALT_RAM } else if (has_alt_ram) { mpb = &pmdalt; #endif } else { return EIMBA; } for (p = *(q = &mpb->mp_mal); p; p = *(q = &p->m_link)) if ((UBYTE *)addr == p->m_start) break; if (!p) return EIMBA; *q = p->m_link; freeit(p,mpb); dump_mem_map(); return E_OK; }
long xmxalloc(long amount, int mode) { MD *m; long ret_value; #if DBGUMEM kprintf("BDOS: xmxalloc(%ld, %d)\n", amount, mode); #endif /* * if amount == -1L, return the size of the biggest block * */ if(amount == -1L) { switch(mode) { case MX_STRAM: ret_value = (long) ffit(-1L,&pmd); break; #if CONF_WITH_ALT_RAM case MX_TTRAM: ret_value = (long) ffit(-1L,&pmdalt); break; #endif case MX_PREFSTRAM: case MX_PREFTTRAM: /* TODO - I assume that the correct behaviour is to return * the biggest size in either pools. The documentation is unclear. */ { ret_value = (long) ffit(-1L,&pmd); #if CONF_WITH_ALT_RAM { long tmp = (long) ffit(-1L,&pmdalt); if(ret_value < tmp) ret_value = tmp; } #endif } break; default: /* unknown mode */ ret_value = 0; } goto ret; } /* * return NULL if asking for a negative or null amount */ if( amount <= 0 ) { ret_value = 0; goto ret; } /* * Pass the request on to the internal routine. */ switch(mode) { case MX_STRAM: m = ffit(amount,&pmd); break; #if CONF_WITH_ALT_RAM case MX_TTRAM: m = ffit(amount,&pmdalt); break; #endif case MX_PREFSTRAM: m = ffit(amount,&pmd); #if CONF_WITH_ALT_RAM if(m == NULL) m = ffit(amount,&pmdalt); #endif break; case MX_PREFTTRAM: #if CONF_WITH_ALT_RAM m = ffit(amount,&pmdalt); if(m == NULL) #endif m = ffit(amount,&pmd); break; default: /* unknown mode */ m = 0; } /* * The internal routine returned a pointer to a memory descriptor, or NULL * Return its pointer to the start of the block. */ if(m == NULL) { ret_value = 0; } else { ret_value = (long) m->m_start; } ret: #if DBGUMEM kprintf("BDOS: xmxalloc returns 0x%08lx\n", ret_value); dump_mem_map(); #endif return(ret_value); }
/* * xmxalloc - Function 0x44 (Mxalloc) */ void *xmxalloc(long amount, int mode) { MD *m; void *ret_value; KDEBUG(("BDOS: xmxalloc(%ld,0x%04x)\n",amount,mode)); mode &= MX_MODEMASK; /* ignore unsupported bits */ /* * if amount == -1L, return the size of the biggest block * */ if (amount == -1L) { switch(mode) { case MX_STRAM: ret_value = ffit(-1L,&pmd); break; #if CONF_WITH_ALT_RAM case MX_TTRAM: ret_value = ffit(-1L,&pmdalt); break; #endif case MX_PREFSTRAM: case MX_PREFTTRAM: /* * for the "preferred" options, the correct behaviour is to * return the biggest size in either pool - verified on TOS3 */ { ret_value = ffit(-1L,&pmd); #if CONF_WITH_ALT_RAM { void *tmp = ffit(-1L,&pmdalt); if (ret_value < tmp) ret_value = tmp; } #endif } break; default: /* unknown mode */ ret_value = NULL; } goto ret; } /* * return NULL if asking for a negative or null amount */ if (amount <= 0) { ret_value = NULL; goto ret; } /* * Pass the request on to the internal routine. */ switch(mode) { case MX_STRAM: m = ffit(amount,&pmd); break; #if CONF_WITH_ALT_RAM case MX_TTRAM: m = ffit(amount,&pmdalt); break; #endif case MX_PREFSTRAM: m = ffit(amount,&pmd); #if CONF_WITH_ALT_RAM if (m == NULL) m = ffit(amount,&pmdalt); #endif break; case MX_PREFTTRAM: #if CONF_WITH_ALT_RAM m = ffit(amount,&pmdalt); if (m == NULL) #endif m = ffit(amount,&pmd); break; default: /* unknown mode */ m = NULL; } /* * The internal routine returned a pointer to a memory descriptor, or NULL * Return its pointer to the start of the block. */ if (m == NULL) { ret_value = NULL; } else { ret_value = m->m_start; } ret: KDEBUG(("BDOS xmxalloc: returns 0x%08lx\n",(ULONG)ret_value)); dump_mem_map(); return ret_value; }
/* * xsetblk - Function 0x4A (Mshrink) * * Arguments: * n - dummy, not used * blk - addr of block to free * len - length of block to free */ long xsetblk(int n, void *blk, long len) { MD *m,*p; MPB *mpb; KDEBUG(("BDOS: Mshrink(0x%08lx,%ld)\n",(long)blk,len)); if (((UBYTE*)blk >= start_stram) && ((UBYTE*)blk <= end_stram)) { mpb = &pmd; KDEBUG(("BDOS xsetblk: mpb=&pmd\n")); #if CONF_WITH_ALT_RAM } else if (has_alt_ram) { mpb = &pmdalt; KDEBUG(("BDOS xsetblk: mpb=&pmdalt\n")); #endif /* CONF_WITH_ALT_RAM */ } else { return EIMBA; } /* * Traverse the list of memory descriptors looking for this block. */ for (p = mpb->mp_mal; p; p = p->m_link) if ((UBYTE *)blk == p->m_start) break; /* * If block address doesn't match any memory descriptor, then abort. */ if (!p) return EIMBA; /* * Round the size to a multiple of 4 bytes to keep alignment. * Alignment on long boundaries matters in FastRAM. */ len = (len + 3) & ~3; KDEBUG(("BDOS xsetblk: new length=%ld\n",len)); /* * If the caller is not shrinking the block size, then abort. */ if (p->m_length < len) return EGSBF; /* * Create a memory descriptor for the freed portion of memory. */ m = xmgetmd(); #ifdef ENABLE_KDEBUG /* what if 0? */ if (m == 0) panic("umem.c/xsetblk: Null Return From MGET\n"); #endif m->m_start = p->m_start + len; m->m_length = p->m_length - len; p->m_length = len; freeit(m,mpb); dump_mem_map(); return E_OK; }