Mercurial > hg > Members > kono > os9 > sbc09
changeset 9:cb7aa75418b8
mmu and io
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 05 Jul 2018 16:00:19 +0900 |
parents | 96a067cf4c4f |
children | 2a1338b218bf |
files | Makefile engine.c io.c os9/level2/init.asm os9/level2/vector.asm os9/makerom.c v09.c |
diffstat | 7 files changed, 96 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Thu Jul 05 12:07:06 2018 +0900 +++ b/Makefile Thu Jul 05 16:00:19 2018 +0900 @@ -36,7 +36,7 @@ $(CC) -o v09 $(CFLAGS) v09.o engine.o io.o os9disass.o v09c: v09.c engine.c io.c os9disass.o - $(CC) -o v09c $(CFLAGS) $(V09FLAGS) -DIOBASE=0xff80 -DUSE_MMU=1 v09.c engine.c io.c os9disass.o + $(CC) -o v09c $(CFLAGS) $(V09FLAGS) -DIOPAGE=0xff80 -DUSE_MMU=1 v09.c engine.c io.c os9disass.o v09.o: v09.c v09.h $(CC) -c $(CFLAGS) $(V09FLAGS) v09.c
--- a/engine.c Thu Jul 05 12:07:06 2018 +0900 +++ b/engine.c Thu Jul 05 16:00:19 2018 +0900 @@ -37,19 +37,30 @@ Byte aca,acb; Byte *breg=&aca,*areg=&acb; static int tracetrick=0; -extern int romstart; +extern long romstart; #ifdef USE_MMU -static inline Byte * mem0(Byte *iphymem, Word adr, Byte *immu) { return & iphymem[ ( immu[ (adr) >> 13 ] <<13 ) + ((adr) & 0x1fff )]; }; +static inline Byte * mem0(Byte *iphymem, Word adr, Byte *immu) { + if (adr>=0xff00) return iphymem + memsize - 0x10000 + adr; // fixed area + return & iphymem[ ( immu[ (adr) >> 13 ] <<13 ) + ((adr) & 0x1fff )]; +}; #define mem(adr) (*mem0(iphymem, adr,immu)) +#define GETWORD(a) ({Byte *phy = mem0(iphymem, a,immu); phy[0]<<8|phy[1];}) +#define SETBYTE(a,n) {Byte *phy = mem0(iphymem, a,immu); if(!(phy-iphymem>=romstart)) phy[0]=n;} +#define SETWORD(a,n) {Byte *phy = mem0(iphymem, a,immu); if(!(phy-iphymem>=romstart)){phy[0]=(n)>>8;phy[1]=n;}} + +Byte * mem1(Byte *iphymem, Word adr, Byte *immu) { return mem0(iphymem,adr,immu); } + #else + #define mem(adr) mem[adr] -#endif - #define GETWORD(a) (mem(a)<<8|mem((a)+1)) #define SETBYTE(a,n) {if(!(a>=romstart))mem(a)=n;} #define SETWORD(a,n) if(!(a>=romstart)){mem(a)=(n)>>8;mem((a)+1)=n;} + +#endif + /* Two bytes of a word are fetched separately because of the possible wrap-around at address $ffff and alignment */ @@ -170,6 +181,8 @@ /*F*/ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, }; +extern char *prog ; + void interpr(void) { Word ixreg,iyreg,iureg,isreg,ipcreg; @@ -189,8 +202,14 @@ LOADREGS for(;;){ if(attention) { - if(tracing && ipcreg>=tracelo && ipcreg<=tracehi) - {SAVEREGS do_trace(tracefile); } + if(tracing && ipcreg>=tracelo && ipcreg<=tracehi) { + SAVEREGS +#ifdef USE_MMU + Byte *phyadr = &mem(pcreg); + prog = (char *)(phyadr - pcreg); +#endif + do_trace(tracefile); + } if(escape){ SAVEREGS do_escape(); LOADREGS } if(irq) { if(irq==1&&!(iccreg&0x10)) { /* standard IRQ */
--- a/io.c Thu Jul 05 12:07:06 2018 +0900 +++ b/io.c Thu Jul 05 16:00:19 2018 +0900 @@ -1,8 +1,8 @@ -/* 6808 Simulator V09. - - created 1993,1994 by L.C. Benschop. - copyleft (c) 1994-2014 by the sbc09 team, see AUTHORS for more details. - license: GNU General Public License version 2, see LICENSE for more details. +/* 6808 Simulator V092 + created 1993,1994 by L.C. Benschop. copyleft (c) 1994-2014 +by the sbc09 team, see AUTHORS for more details. license: +GNU General Public License version 2, see LICENSE for more +details. This program simulates a 6809 processor. @@ -99,6 +99,11 @@ extern void hexadump( unsigned char *b, int l, int loc, int w); extern void disasm(int,int); +#ifdef USE_MMU +extern char *prog ; // for disass +extern Byte * mem1(Byte *iphymem, Word adr, Byte *immu) ; +#endif + void do_timer(int,int); void do_disk(int,int); @@ -180,7 +185,7 @@ } } -int do_input( a) { +int do_input(int a) { static int c, f = EOF; if (a == 0+(IOPAGE&0xff)) { if (f == EOF) @@ -197,7 +202,7 @@ } return c; } - return mem[IOPAGE + a]; + return mem[(IOPAGE&0xff00) + a]; } void do_output(int a, int c) { @@ -270,17 +275,17 @@ void do_timer(int a, int c) { struct itimerval timercontrol; - if (a==0x30 && c==0x8f) { + if (a==0x30+(IOPAGE&0xff) && c==0x8f) { timercontrol.it_interval.tv_sec = 0; timercontrol.it_interval.tv_usec = 20000; timercontrol.it_value.tv_sec = 0; timercontrol.it_value.tv_usec = 20000; setitimer(ITIMER_REAL, &timercontrol, NULL); - } else if (a==0x30 && c==0x80) { + } else if (a==0x30+(IOPAGE&0xff) && c==0x80) { timercontrol.it_interval.tv_sec = 0; timercontrol.it_interval.tv_usec = 0; setitimer(ITIMER_REAL, &timercontrol, NULL); - } else if (a==0x30 && c==0x04) { + } else if (a==0x30+(IOPAGE&0xff) && c==0x04) { time_t tm = time(0); struct tm *t = localtime(&tm); mem[IOPAGE+0x31] = t->tm_year; @@ -290,13 +295,13 @@ mem[IOPAGE+0x35] = t->tm_min; mem[IOPAGE+0x36] = t->tm_sec; } else { - mem[IOPAGE+a]=c; + mem[(IOPAGE&0xff00)+a]=c; } } void do_disk(int a, int c) { - if (a!=0x40) { - mem[IOPAGE+a]=c; + if (a!=0x40+(IOPAGE&0xff)) { + mem[(IOPAGE&0xff00)+a]=c; return; } int drv = mem[IOPAGE+0x41]; @@ -320,15 +325,15 @@ { #ifdef USE_MMU - if (a==0x11) { + if (a==0x11+(IOPAGE&0xff)) { if (c&0) { mmu = phymem+memsize-0x10000+0xffa0; } else { mmu = phymem+memsize-0x10000+0xffa8; } - mem[IOPAGE+a] = c; - } if (0x20 <= a && a <= 0x2f) { - mem[IOPAGE+a] = c; + mem[(IOPAGE&0xff00)+a] = c; + } if (0x20+(IOPAGE&0xff) <= a && a <= 0x2f+(IOPAGE&0xff)) { + mem[(IOPAGE&0xff00)+a] = c; } #endif @@ -360,6 +365,9 @@ " d [n] delte break point list\n" " c [count] continue;\n" " x [adr] dump\n" +#ifdef USE_MMU + " xp [adr] dump physical memory\n" +#endif " xi [adr] disassemble\n" " 0 file disk drive 0 image\n" " 1 file disk drive 1 image\n" @@ -395,6 +403,10 @@ restart0: stkskip = 0; restore_term(); +#ifdef USE_MMU + Byte *phyadr = mem1(phymem,pcreg,mmu); + prog = (char*)phyadr - pcreg; +#endif do_trace(stdout); if (trskip>1) { // show trace and step trskip--; @@ -471,6 +483,7 @@ case 'x': // dump skip = 1; if (s[1]=='i') skip=2; + if (s[1]=='p') skip=2; if (s[skip]) { char *next; int adr = getarg(s+skip,&next); @@ -478,12 +491,31 @@ if (next[0]) { len = getarg(next,&next); } - if (skip==2) { - disasm(adr,adr+len); + if (skip==2 && s[1]=='i') { + for(int i=0; len > 0 ; i+=16, len-=16) { +#ifdef USE_MMU + Byte *phyadr = mem1(phymem,adr+i,mmu); + prog = (char*)phyadr - adr; +#endif + disasm(adr,adr+((i>len)?len:i)); + } } else { +#ifdef USE_MMU + for(int i=0; len > 0 ; i+=16, len-=16) { + if (skip==2 && s[1]=='p') { + if (adr+i > memsize) goto restart; + hexadump(phymem+adr+i,len>16?16:len,adr+i,16); + } else { + Byte *phyadr = mem1(phymem,adr+i,mmu); + if (phyadr > phymem+memsize) goto restart; + hexadump(phyadr,len>16?16:len,adr+i,16); + } + } +#else for(int i=0; len > 0 ; i+=16, len-=16) { hexadump(mem+adr+i,len>16?16:len,adr+i,16); } +#endif } } else disasm(pcreg,pcreg+32);
--- a/os9/level2/init.asm Thu Jul 05 12:07:06 2018 +0900 +++ b/os9/level2/init.asm Thu Jul 05 16:00:19 2018 +0900 @@ -10,8 +10,8 @@ atrv set ReEnt+rev rev set $01 mod eom,initnam,tylg,atrv - fcb 0 - fdb $D000 + fcb 7 + fdb $b800 fcb $0C fcb $0C fdb sysgo
--- a/os9/level2/vector.asm Thu Jul 05 12:07:06 2018 +0900 +++ b/os9/level2/vector.asm Thu Jul 05 16:00:19 2018 +0900 @@ -3,7 +3,7 @@ reset clra tfr a,dp - ldx $ff90 + ldx #$ff90 sta $10,x lda #$3f sta $17,x
--- a/os9/makerom.c Thu Jul 05 12:07:06 2018 +0900 +++ b/os9/makerom.c Thu Jul 05 16:00:19 2018 +0900 @@ -12,6 +12,8 @@ int IOSIZE = 0x100; char * outfile ; +#define LV2START 0xffd0 + // #define DEBUG typedef struct os9module { @@ -192,7 +194,7 @@ fprintf(stderr,"cannot read %s\n",vector); exit(1); } - for( ; pos<0xffd0; pos++) fputc(0xff,romfile); + for( ; pos<LV2START; pos++) fputc(0xff,romfile); printf("vectbl %x\n",pos); for( ; pos<0xfff0; pos++) fputc(fgetc(fp),romfile); @@ -210,7 +212,7 @@ fputword(vec+9,romfile); fputword(vec+12,romfile); fputword(vec+15,romfile); - fputword(0xffe0,romfile); + fputword(LV2START,romfile); } if (level==1) printf("boot rom from 0x%lx\n",0x10000-ftell(romfile));
--- a/v09.c Thu Jul 05 12:07:06 2018 +0900 +++ b/v09.c Thu Jul 05 16:00:19 2018 +0900 @@ -59,7 +59,7 @@ } char *romfile = "v09.rom"; -int romstart = 0x8000; +long romstart = 0x8000; long filesize(FILE *image) @@ -81,13 +81,20 @@ exit(2); } long len = filesize(image); - fread(mem+romstart,len,1,image); + if (romstart==0x8000) { +#ifdef USE_MMU + romstart = memsize - len; +#else + romstart = 0x10000 - len; +#endif + } + fread(mem+(romstart&0xffff),len,1,image); fclose(image); } void usage(void) { - fprintf(stderr,"Usage: v09 [-l romstart] [-rom rom-image] [-t tracefile [-tl addr] [-nt]" + fprintf(stderr,"Usage: v09 [-rom rom-image] [-l romstart] [-t tracefile [-tl addr] [-nt]" "[-th addr] ]\n[-e escchar] \n"); exit(1); } @@ -116,6 +123,7 @@ i++; timer = 0; // non standard rom image, don't start timer romfile = argv[i]; + } else if (strcmp(argv[i],"-0")==0) { i++; disk[0] = fopen(argv[i],"r+"); @@ -146,6 +154,7 @@ #ifdef USE_MMU phymem = malloc(memsize); mem = phymem + memsize - 0x10000 ; + mmu = mem + 0xffa0; #else #ifdef MSDOS if((mem=farmalloc(65535))==0) {