Change file to support extensions to NNIX in the simple MMIX simulator (This change file is public domain) @x The |TRAP| instruction is not simulated, except for the system calls mentioned in the introduction. @y The |TRAP| instruction is not simulated, except for the system calls mentioned in the introduction, and extensions to the system calls that can be loaded from external files. @z @x case TRAP:@+if (xx!=0 || yy>max_sys_call) goto privileged_inst; @y case TRAP: if(xx) @@; if(yy>max_sys_call) goto privileged_inst; @z @x #include @y #include #include @z @x @* Index. @y @* Extensions. This chapter contains the stuff needed for loading extensions to the operating system interface. @ @= typedef int(*extension_func)(octa*g,int yy,int zz,int(*mmgetchars)(char*,int,octa,int),void(*mmputchars)(unsigned char*,int,octa)); @ @= { static extension_func ioext[256]; if(!ioext[xx]) { char s[128]; void*d; dlerror(); sprintf(s,"./mmix-ext%d.so",xx); d=dlopen(s,RTLD_NOW|RTLD_LOCAL); if(!d) { fprintf(stderr,"Extension error: %s\n",dlerror()?:"Unknown error"); goto privileged_inst; } ioext[xx]=dlsym(d,"mmix_extension"); if(!ioext[xx]) { fprintf(stderr,"Extension error: %s\n",dlerror()?:"Value of symbol 'mmix_extension' is NULL"); goto privileged_inst; } } g[rBB]=g[255]; g[255]=g[rJ]; g[rWW]=inst_ptr; g[rXX].h=sign_bit, g[rXX].l=inst; g[rYY]=y, g[rZZ]=z; z.h=0, z.l=zz; if(ioext[xx](g,yy,zz,mmgetchars,mmputchars)) goto privileged_inst; inst_ptr=g[rWW]; x=g[255]=g[rBB];@+break; } @* Index. @z Please add the following codes into a file named "mmix-ext.h": typedef unsigned int tetra; typedef struct {tetra h,l;} octa; int mmix_extension(octa*g,int yy,int zz,int(*mmgetchars)(char*,int,octa,int),void(*mmputchars)(unsigned char*,int,octa)); enum{ rB,rD,rE,rH,rJ,rM,rR,rBB, rC,rN,rO,rS,rI,rT,rTT,rK,rQ,rU,rV,rG,rL, rA,rF,rP,rW,rX,rY,rZ,rWW,rXX,rYY,rZZ, };