changeset 8:96a067cf4c4f

level2 rom done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 05 Jul 2018 12:07:06 +0900
parents a6db579d8c11
children cb7aa75418b8
files a09.c os9/level2/Makefile os9/level2/init.asm os9/level2/vector.asm os9/makerom.c os9/os9disass.c
diffstat 6 files changed, 143 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/a09.c	Thu Jul 05 02:00:14 2018 +0900
+++ b/a09.c	Thu Jul 05 12:07:06 2018 +0900
@@ -181,21 +181,31 @@
 int os9 = 0;   // os9 flag
 int prevloc = 0;
 
-/* Symbol categories.
-   0 Constant value (from equ).
-   1 Variable value (from set)
-   2 Address within program module (label).
-   3 Variable containing address.
-   4 Adress in other program module (extern)
-   5 Variable containing external address.
-   6 Unresolved address.
-   7 Variable containing unresolved address.
-   8 Public label.
-   9 Macro definition.
-  10 Public label (yet undefined).
-  11 parameter name.
-  12 local label.
-  13 empty.
+/* expression categories...
+   ECORD   all zeros is ordinary constant.
+   ECADR   bit 1 indicates address within module.
+   ECEXT   bit 2 indicates external address.
+   ECLBL   bit 3 public label
+   ECABS   bit 4 indicates this can't be relocated if it's an address.
+   ECNEG   bit 5 indicates address (if any) is negative.
+*/
+
+
+/* Symbol categories.                               exprcat ( symcat & 0xe )
+   0 SCC      Constant value (from equ).                     ECORD
+   1 SCV      Variable value (from set)                      ECORD
+   2 SCC__ADR Address within program module (label).         ECADR
+   3 SCV__ADR Variable containing address.                   ECADR
+   4 SC_E_ADR Adress in other program module (extern)        ECEXT
+   5 SCVE_ADR Variable containing external address.          ECEXT
+   6 SCU _ADR Unresolved address.                            ECEXT+ECADR
+   7 SCV_UADR Variable containing unresolved address.        ECEXT+ECADR
+   8 SC___LBL Public label.                                  ECLBL
+   9 SCMACRO  Macro definition.                              xxx
+  10 SCU__LBL Public label (yet undefined).                  ECADR+ECLBL
+  11 SCPARAM  parameter name.                                ECADR+ECLBL
+  12 SCLOCAL  local label.                                   ECEXT+ECLBL
+  13 SCEMPTY  empty.                                         xxx
 */
 
 struct symrecord symtable[NLABELS];
@@ -431,15 +441,6 @@
  return p->value;
 }
 
-/* expression categories...
-   all zeros is ordinary constant.
-   bit 1 indicates address within module.
-   bit 2 indicates external address.
-   bit 4 indicates this can't be relocated if it's an address.
-   bit 5 indicates address (if any) is negative.
-*/
-
-
 
 short scanfactor()
 {
@@ -934,9 +935,9 @@
                 if(offs<-128||offs>=128||opsize==3||unknown||!certain) {
                  if((!unknown)&&opsize==2&&(offs<-128||offs>=128) )
                    error|=16;
-                 offs--;
-                 opsize=3;
-                 postbyte++;
+                 // offs--;
+                 // opsize=3;
+                 // postbyte++;
                 }
                 putbyte(postbyte);
                 if (debug) fprintf(stderr,"DEBUG: doaddress: mode=%d, opsize=%d, error=%d, postbyte=%02X, operand=%04X offs=%d\n",mode,opsize,error,postbyte,operand,offs);
--- a/os9/level2/Makefile	Thu Jul 05 02:00:14 2018 +0900
+++ b/os9/level2/Makefile	Thu Jul 05 12:07:06 2018 +0900
@@ -3,17 +3,17 @@
 
 SRCDIR=../../CoCoOS9/level2v3/MODULES
 
-all : ioman pdisk init os9p1 os9p2 os9p3_perr os9p4_regdump pipe pipeman pipeman_named piper rbf scf term pty d0 d1 clock
+all : ioman pdisk init os9p1 os9p2 os9p3_perr os9p4_regdump pipe pipeman pipeman_named piper rbf scf term pty d0 d1 clock vector
 
 clean : 
-	rm -f ioman pdisk init os9p1 os9p2 os9p3_perr os9p4_regdump pipe pipeman pipeman_named piper rbf scf term pty d0 d1 clock
+	rm -f ioman pdisk init os9p1 os9p2 os9p3_perr os9p4_regdump pipe pipeman pipeman_named piper rbf scf term pty d0 d1 clock vector
 
 
-pdisk :
+pdisk : ../modules/pdisk.asm
 	$(A09) ../modules/pdisk.asm -o pdisk
 
-init :
-	$(A09) ../modules/init.asm -o init
+init : init.asm
+	$(A09) init.asm -o init
 
 term :
 	$(A09) pty-dd.asm -o term
@@ -30,6 +30,8 @@
 pty :
 	$(A09) ../modules/pty.asm -o pty
 
+vector : vector.asm
+	$(A09) vector.asm -o vector
 
 os9p1 :
 	$(A09) ${SRCDIR}/os9p1.asm -o os9p1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/os9/level2/init.asm	Thu Jul 05 12:07:06 2018 +0900
@@ -0,0 +1,28 @@
+* OS9 standard init modul.
+         nam   Init
+         ttl   os9 system module
+
+         ifp1
+         use   os9defs
+         endc
+null     set   $0000
+tylg     set   Systm+$00
+atrv     set   ReEnt+rev
+rev      set   $01
+         mod   eom,initnam,tylg,atrv
+         fcb   0
+         fdb   $D000
+         fcb   $0C
+         fcb   $0C
+         fdb   sysgo
+         fdb   null      system device (sysdev)
+         fdb   systerm
+         fdb   null      bootstrap module (bootst)
+initnam  fcs   "Init"
+sysgo    fcs   "SysGo"
+sysdev   fcs   "/D0"
+systerm  fcs   "/Term"
+bootst   fcs   "Boot"
+         emod
+eom      equ   *
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/os9/level2/vector.asm	Thu Jul 05 12:07:06 2018 +0900
@@ -0,0 +1,25 @@
+        org      $ffd0
+entry   equ      $f100
+
+reset   clra
+        tfr      a,dp
+        ldx      $ff90
+        sta      $10,x
+        lda      #$3f
+        sta      $17,x
+        lda      #1
+        sta      1,x
+        jmp      [<vector,pcr]
+
+        org      $fff0
+vector  
+        fdb      $ff1f     os9entry
+        fdb      $ff03     SWI3
+        fdb      $ff06     SWI2
+        fdb      $ff09     FIRQ
+        fdb      $ff0c     IRQ
+        fdb      $ff0f     SWI
+        fdb      $ff1f     NMI
+vreset
+        fdb      reset
+
--- a/os9/makerom.c	Thu Jul 05 02:00:14 2018 +0900
+++ b/os9/makerom.c	Thu Jul 05 12:07:06 2018 +0900
@@ -12,6 +12,8 @@
 int IOSIZE = 0x100;
 char * outfile ;
 
+// #define DEBUG
+
 typedef struct os9module {
    int size;
    int location;
@@ -71,18 +73,28 @@
        else
           top = 0x10000-(m->size+0x80);
    }
-   if (!(( top+m->size < IOBASE )  || ( IOBASE+IOSIZE < top)) ) {
+   if (level==1 && !(( top+m->size < IOBASE )  || ( IOBASE+IOSIZE < top)) ) {
       top = IOBASE-m->size-1;
       m->ioflag = 1;
-      // printf("*");
+#ifdef DEBUG
+      printf("*");
+#endif 
    }
    m->location = top;
-   // printf("mod ");
-   // printOs9Str(m->name);
-   // printf(" \t: 0x%x - 0x%x\n",top, top + m->size);
+#ifdef DEBUG
+    printf("mod ");
+    printOs9Str(m->name);
+    printf(" \t: 0x%x - 0x%x\n",top, top + m->size);
+#endif 
    return top;
 }
 
+unsigned short
+getword(unsigned char *ptr)
+{
+    return (ptr[0]<<8)+ptr[1];
+}
+
 int
 main(int ac, char *av[])
 {
@@ -127,9 +139,11 @@
  printf("\n\n");
 
  pos = start;
+ struct os9module *os9p1 = 0;
  for(struct os9module *cur = root.next; cur ; cur = cur->next ) {
     // last module have to os9p1
     if ( cur->next == 0 ) {
+        os9p1 = cur;
         if ( level==1 ) { 
            for(; pos < 0xf800 ; pos++) {   // os9p1 begins at 0xf800
               fputc(0xff,romfile);
@@ -145,7 +159,10 @@
     printOs9Str(cur->name);
     fwrite(cur->mod, cur->size, 1, romfile);
     printf(" \t: 0x%x - 0x%x\n",pos, pos + cur->size-1);
-    // printf(" \t: 0x%x - 0x%x : 0x%lx \n",pos, pos + cur->size, ftell(romfile)+start);
+#ifdef DEBUG
+    printf(" \t: 0x%x \n",cur->location);
+    printf(" \t: 0x%x - 0x%x : 0x%lx \n",pos, pos + cur->size, ftell(romfile)+start);
+#endif 
     pos = pos+cur->size;
     if (cur->ioflag) {
        if (level==1) {
@@ -153,11 +170,7 @@
               fputc(0xff,romfile);
            }
            printf("*");
-       } else {
-           for(; pos < IOBASE + IOSIZE - 2*7 ; pos++) {
-              fputc(0xff,romfile);
-           }
-       }
+       } 
     } 
  }
  printf("os9 end %x\n",pos);
@@ -173,15 +186,31 @@
      fputword(0xF841,romfile);
      fputword(0xF876,romfile);
  } else {
-     vectable  = 0x10000 - 2*6;
-     for( ; pos<vectable; pos++) fputc(0xff,romfile);
+     char vector[] = "level2/vector";
+     FILE *fp = fopen(vector,"rb");
+     if (fp==0) {
+        fprintf(stderr,"cannot read %s\n",vector);
+        exit(1);
+     }
+     for( ; pos<0xffd0; pos++) fputc(0xff,romfile);
      printf("vectbl %x\n",pos);
-     fputword(0xff6e,romfile);
-     fputword(0xff71,romfile);
-     fputword(0xff74,romfile);
-     fputword(0xff7a,romfile);
-     fputword(0xff7d,romfile);
-     fputword(0xff7d,romfile);
+     for( ; pos<0xfff0; pos++) fputc(fgetc(fp),romfile);
+
+#ifdef DEBUG
+     printf("os9entry %x\n",os9p1->location);
+#endif 
+     printf("os9entry %x\n",os9p1->location+getword(os9p1->mod+9));
+
+     fputword(os9p1->location+getword(os9p1->mod+9),romfile);     // os9p1 entry point 
+     unsigned short vec = os9p1->location+os9p1->size + 15;
+     fputword(vec,romfile);
+     fputword(vec+3,romfile);
+     fputword(vec+6,romfile);
+
+     fputword(vec+9,romfile);
+     fputword(vec+12,romfile);
+     fputword(vec+15,romfile);
+     fputword(0xffe0,romfile);
  }
  if (level==1) 
      printf("boot rom from 0x%lx\n",0x10000-ftell(romfile)); 
--- a/os9/os9disass.c	Thu Jul 05 02:00:14 2018 +0900
+++ b/os9/os9disass.c	Thu Jul 05 12:07:06 2018 +0900
@@ -1110,7 +1110,7 @@
   int offset;
 
   offset = prog[pc+1];
-  fprintf(fp,"%0.2X %0.2X       %s%s       $%0.2X",
+  fprintf(fp,"%0.2X %0.2X       %s%s       <$%0.2X",
 	code, offset, suffix, op->name, offset);
   return op->bytes;
 }
@@ -1307,14 +1307,14 @@
 		offset = (prog[pc+2]+pc+3) & 0xFFFF;
 		s = "<";
 		fprintf(fp,"%0.2X %0.2X %0.2X    %s%s       %s$%0.2X,PCR",
-				  code, postbyte, prog[pc+2], suffix, op->name, s, pc+3+offset+adoffset);
+				  code, postbyte, prog[pc+2], suffix, op->name, s, offset+adoffset);
 		extrabytes = 1;
 		break;
 	 case 0x0d :
 		offset = (prog[pc+2] * 256 + prog[pc+3]+pc+4) & 0xFFFF;
 		s = ">";
 		fprintf(fp,"%0.2X %0.2X %0.2X %0.2X %s%s       %s$%0.4X,PCR",
-				  code, postbyte, prog[pc+2], prog[pc+3], suffix, op->name, s, offset+pc+4+adoffset);
+				  code, postbyte, prog[pc+2], prog[pc+3], suffix, op->name, s, offset+adoffset);
 		extrabytes = 2;
 		break;
 	 case 0x0e :
@@ -1387,14 +1387,14 @@
 		offset = (prog[pc+2]+pc+3) & 0xFFFF;
 		s = "<";
 		fprintf(fp,"%0.2X %0.2X %0.2X    %s%s       [%s$%0.2X,PCR]",
-				  code, postbyte, prog[pc+2], suffix, op->name, s, offset+pc+2+adoffset);
+				  code, postbyte, prog[pc+2], suffix, op->name, s, offset+adoffset);
 		extrabytes = 1;
 		break;
 	 case 0x1d :
 		offset = (prog[pc+2] * 256 + prog[pc+3]+pc+4) & 0xFFFF;
 		s = ">";
 		fprintf(fp,"%0.2X %0.2X %0.2X %0.2X %s%s       [%s$%0.4X,PCR]",
-				  code, postbyte, prog[pc+2], prog[pc+3], suffix, op->name, s, offset+pc+3+adoffset);
+				  code, postbyte, prog[pc+2], prog[pc+3], suffix, op->name, s, offset+adoffset);
 		extrabytes = 2;
 		break;
 	 case 0x1e :
@@ -1639,7 +1639,8 @@
   }
 
   sscanf(argv[2],"%x",&start); start -= adoffset;
-  sscanf(argv[3],"%x",&end); end -= adoffset;
+  sscanf(argv[3],"%x",&end); end     -= adoffset;
+  printf("disass %x - %x\n",start,end);
 
   fp = stdout;