{ $Id$ This file is part of the Free Pascal simulator environment Copyright (c) 1999-2000 by Florian Klaempfl This unit implemements a memory manager for 64 bit processor simulations, it works also with TP See the file COPYING.FPC, included in this distribution, for details about the copyright. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. **********************************************************************} { a simple 64 bit simulator memory manager, also running with TP } {$N+} unit mm64; interface uses simbase; const memoryblocksize = 32768; type taddr = qword; tmemoryblock = array[0..memoryblocksize-1] of byte; pmemoryblock = ^tmemoryblock; pmemoryarea = ^tmemoryarea; tmemoryarea = record addr : qword; memory : pmemoryblock; size : dword; next : pmemoryarea; end; tmemorymanager = object mem : pmemoryarea; constructor init; { "memory" access routines } function readalignedq(addr : taddr) : qword; function readq(addr : taddr) : qword; function readalignedd(addr : taddr) : dword; function readd(addr : taddr) : dword; function readb(addr : taddr) : dword; procedure writeb(addr : taddr;b : byte); procedure writealignedd(addr : taddr;d : dword); procedure writed(addr : taddr;d : dword); procedure writeq(addr : taddr;q : qword); procedure allocate(addr : taddr;size : qword); end; var { address of the currently executed instruction, } { necessary for correct output of exception } instructionpc : taddr; implementation procedure exception(const s : string;addr : taddr); begin writeln; writeln('Exception: ',s,' at $',qword2str(addr)); stopsim; end; constructor tmemorymanager.init; begin mem:=nil; end; procedure tmemorymanager.allocate(addr : taddr;size : qword); var ma : pmemoryarea; asize : qword; begin while size>0 do begin if size>32768 then asize:=32768 else asize:=size; size:=size-asize; new(ma); getmem(ma^.memory,trunc(asize)); fillchar(ma^.memory^,trunc(asize),0); ma^.size:=trunc(asize); ma^.addr:=addr; addr:=addr+asize; ma^.next:=mem; mem:=ma; end; end; function tmemorymanager.readq(addr : taddr) : qword; var h : qword; ma : pmemoryarea; qw : tqwordrec; begin ma:=mem; while assigned(ma) do begin if (addr>=ma^.addr) and (addr0 then exception('Alignment violation (dword) to $'+qword2str(addr),instructionpc); ma:=mem; while assigned(ma) do begin if (addr>=ma^.addr) and (addr=ma^.addr) and (addr0 then exception('Alignment violation (dword) to $'+qword2str(addr),instructionpc); ma:=mem; while assigned(ma) do begin if (addr>=ma^.addr) and (addr=ma^.addr) and (addr=ma^.addr) and (addr=ma^.addr) and (addr=ma^.addr) and (addr