REGENERATINGSYSTEMSOFTWARE ForUNIX/32V ThomasB.London JohnF.Reiser Introduction ThisdocumentdiscusseshowtoassembleorcompilevariouspartsoftheUNIX/32V◯rsystem software.Thismaybenecessarybecauseacommandorlibraryisaccidentallydeletedorotherwisedestroyed;also,itmaybedesirabletoinstallamodifiedversionofsomecommandorlibrary routine.Afewcommandsdependtosomedegreeonthecurrentconfigurationofthesystem;thus inanynewsystemmodificationstosomecommandsareadvisable.Mostofthelikelymodificationsrelatetothestandarddiskdevicescontainedinthesystem.Forexample,thedf(1)(‘disk free’)commandhasbuiltintoitthenamesofthestandardlypresentdiskstoragedrives(e.g. ‘/dev/rf0’,‘/dev/rp0’).Df(1)takesanargumenttoindicatewhichdisktoexamine,butitisconvenientifitsdefaultargumentisadjustedtoreflecttheordinarilypresentdevices.Thecompaniondocument‘SettingupUNIX’discusseswhichcommandsarelikelytorequirechanges. WhereCommandsandSubroutinesLive Thesourcefilesforcommandsandsubroutinesresideinseveralsubdirectoriesofthedirectory/usr/src.Thesesubdirectories,andageneraldescriptionoftheircontents,are cmdSourcefilesforcommands. libc/stdioSourcefilesmakingupthe‘standardi/opackage’. libc/sysSourcefilesfortheCsystemcallinterfaces. libc/genSourcefilesformostoftheremainingroutinesdescribedinsection3ofthemanual. libc/crtSourcefilesmakinguptheCruntimesupportpackage,asincallsave-returnand longarithmetic. libc/csuSourcefortheCstartuproutines. gamesSourcefor(someof)thegames.Nogreatcarehasbeentakentotrytomakeit obvioushowtocompilethese;treatitasagame. libF77SourcefortheFortran77runtimelibrary,exclusiveofIO. libI77SourcefortheFortran77IOruntimeroutines. libdbmSourceforthe‘data-basemanager’packagedbm(3). libmSourceforthemathematicallibrary. libnmSourcefortheassemblerlanguagemathematicallibrary. libplotSourceforplottingroutines. Commands Theregenerationofmostcommandsisstraightforward.The‘cmd’directorywillcontain eitherasourcefileforthecommandorasubdirectorycontainingthesetoffilesthatmakeupthe command.Ifitisasinglefilethecommand -2-cd/usr/src/cmd/Admin Mkcmdname.c suffices.(Cmdnameisthenameofthecommandyouareplayingwith.)TheresultoftheMk commandwillbeanexecutableversion,copiedto/bin(orperhaps/etcorotherplacesifappropriate).Ifyouwanttheresultplacedsomewhereelse,thecommand cd/usr/src/cmd/Admin DESTDIR=mydirMkcmdname.c wheremydirisafullpathnameofsomedestinationdirectory(e.g./usr/tbl/newcmds),willcompilethecommandandplacetheresultinmydir/bin(orperhapsmydir/etcormydir/usr/bin, etc.). Ifthesourcefilesareinasubdirectorytherewillbea‘makefile’(seemake(1))tocontrolthe regeneration.Afterchangingtotheproperdirectory(cd(1))youtypeoneofthefollowing: makeTheprogramiscompiledandloaded;theexecutableisleftinthecurrentdirectory. makeinstallTheprogramiscompiledandloaded,andtheexecutableisinstalled. makecleanEverythingiscleanup;forexample.ofilesaredeleted. Someofthemakefileshaveotheroptions.Print(cat(1))theonesyouareinterestedinto findout. Alternately,tocompilerandinstallasubdirectorycommand,onemayperformthefollowing cd/usr/src/cmd/Admin Mkcmdname whichcombinesallthreeoftheabovemakeoptions. TheAssembler Theassemblerconsistsofoneexecutablefile:/bin/as.Thesourcefilesfor/bin/asare named‘/usr/src/cmd/as/as?.c’.Considerablecareshouldbeexercisedinreplacingtheassembler. Rememberthatiftheassemblerislost,theonlyrecourseistoreplaceitfromsomebackupstorage;abrokenassemblercannotassembleitself. TheCCompiler TheCcompilerconsistsofsixroutines:‘/bin/cc’,whichcallsthephasesofthecompiler proper,thecompilercontrollineexpander‘/lib/cpp’,theassembler(‘as’),andtheloader(‘ld’). TheCcompilerproperis‘/lib/ccom’;‘/lib/c2’istheoptionalassembler-languageoptimizer.The lossoftheCcompilerisasseriousasthatoftheassembler. Thesourcefor/bin/ccresidesin‘/usr/src/cmd/cc.c’.Itslossalone(orthatofc2)isnot fatal.Ifneeded,prog.ccanbecompiledby /lib/cppprog.c>temp0 /lib/ccomtemp0temp1 astemp3 ld/lib/crt0.oa.out−lc Thesourceforthecompilerproperisinthedirectories/usr/src/cmd/mipand /usr/src/cmd/pcc.The/usr/src/cmd/mipdirectorycontainsfileswhichare(relatively)machine independent;themachinedependentfilesresideinthedirectory/usr/src/cmd/pcc.Thecompiler is‘made’bythemakefile(seemake(1))inthedirectory/usr/src/cmd/pcc.Tomakeanew /lib/ccomuse cd/usr/src/cmd/pcc make -3-whichproducesthecompiler(named/usr/src/cmd/pcc/comp).Beforeinstallingthenewcom-piler,itisprudenttosavetheoldonesomeplace. Inasimilarmanner,theoptimizerphaseoftheCcompiler(/lib/c2)ismadeupfromthe filesc20.c,c21.c,andc22.ctogetherwithc2.h.Itslossisnotcriticalsinceitiscompletely optional. UNIX ThesourceandobjectprogramsforUNIXarekeptintwosubdirectoriesof/usr/src/sys.In thesubdirectoryhthereareseveralfilesendingin‘.h’;theseareheaderfileswhicharepickedup (via‘#include...’)asrequiredbyeachsystemmodule.Thesubdirectorysysistherestofthe system. Thefileconf.ccontainsthetableswhichcontroldeviceconfigurationofthesystem.Locore.s specifiesthecontentsoftheinterruptvectors,andallthemachine-languagecodeinthesystem. Torecreatethesystem,use cd/usr/src/sys/sys makeunix See‘SettingUpUNIX’forotherinformationaboutconfigurationandsuch. Whenthemakeisdone,thenewsystemispresentinthecurrentdirectoryas‘unix’.It shouldbetestedbeforedestroyingthecurrentlyrunning‘/unix’,thisisbestdonebydoingsomethinglike mv/unix/ounix mvunix/unix Ifthenewsystemdoesn’twork,youcanstillboot‘ounix’andcomeup(seeboot(8)).Whenyou havesatisfiedyourselfthatthenewsystemworks,remove/ounix. Toinstallanewdevicedriver,copyitssourceto/usr/src/sys/sys,andeditthe‘makefile’ andthefile‘loadall’ifnecessary(seemake(1)). Next,theI/Ointerruptfieldingmechanismmustbemodifiedtoproperlyhandlethenew device.IfthedeviceisconnectedviatheUNIBUS,thenoneonlyneedaddthedevice’sinterrupt handlingroutineaddress(s)intheproperpositioninthetable‘UNIvec’inthefile /usr/src/sys/sys/univec.c.‘UNIvec’shouldbemodifiedbyplacingapointertoacalloutroutine inthepropervector.Usesomeotherdevice(liketheDZ11)asaguide.Noticethattheentriesin ‘UNIvec’mustbeinorder.Bits27-31ofthevectoraddresswillbeavailableasthefirstargument oftheinterruptroutine.Thisstratagemisusedwhenseveralsimilardevicessharethesameinterruptroutine(asindz11’s). IfthedeviceisconnectedviatheMASSBUS,then/usr/src/sys/sys/univec.cisnottobe modifed.Instead,codemustbeaddedto/usr/src/sys/sys/locore.stoactuallytransfertothe interruptroutine.UsetheRP06interruptroutine‘Xmba0int’inlocore.sasaguide.Asanaside, notethatexternalnamesinCprogramshaveanunderscore(‘’)prependedtothem. Thesecondstepwhichmustbeperformedtoaddanewdeviceistoaddittotheconfigurationtable/usr/src/sys/sys/conf.c.Thisfilecontainstwosubtables,‘bdevsw’and‘cdevsw’,one forblock-typedevices,andoneforcharacter-typedevices.Blockdevicesincludedisks,andmag-tape.Allotherdevicesarecharacterdevices.Alineineachofthesetablesgivesalltheinforma-tionthesystemneedstoknowaboutthedevicehandler;theordinalpositionofthelineinthe tableimpliesitsmajordevicenumber,startingat0. Therearefoursubentriesperlineintheblockdevicetable,whichgiveitsopenroutine, closeroutine,strategyroutine,anddevicetable.Theopenandcloseroutinesmaybenonexistent, inwhichcasethename‘nulldev’isgiven;thisroutinemerelyreturns.Thestrategyroutineis calledtodoanyI/O,andthedevicetablecontainsstatusinformationforthedevice.

-4-Forcharacterdevices,eachlineinthetablespecifiesaroutineforopen,close,read,and write,andonewhichsetsandreturnsdevice-specificstatus(used,forexample,forsttyandgtty ontypewriters).Ifthereisnoopenorcloseroutine,‘nulldev’maybegiven;ifthereisnoread, write,orstatusroutine,‘nodev’maybegiven.Nodevsetsanerrorflagandreturns. Thefinalstepwhichmustbetakentoinstalladeviceistomakeaspecialfileforit.Thisis donebymknod(1),towhichyoumustspecifythedeviceclass(blockorcharacter),majordevice number(relativelineintheconfigurationtable)andminordevicenumber(whichismadeavailabletothedriveratappropriatetimes). Thedocuments‘SettingupUnix’and‘TheUnixIOsystem’mayaidincomprehending thesesteps. TheLibrarylibc.a Thelibrary/lib/libc.aiswheremostofthesubroutinesdescribedinsections2and3ofthe manualarekept.Thislibrarycanberemadeusingthefollowingcommands: cd/usr/src/libc makelibc.a makeinstall makeclean Ifsingleroutinesneedtoberecompiledandreplaced,use cc−c−Ox.c arvr/lib/libc.ax.o rmx.o Theabovecanalsobeusedtoputnewitemsintothelibrary.Seear(1),lorder(1),andtsort(1). Theroutinesin/usr/src/cmd/libc/csu(Cstartup)arenotinlibc.a.Theseareseparately assembledandputinto/lib.Thecommandstodothisare cd/usr/src/libc foriincsu/*.s do j=‘basename$i.s‘ as-o$j.o$i mv$j.o/lib done or,ifyouneedonlyredooneroutine, cd/usr/src/libc/csu as-ox.ox.s mvx.o/lib wherexistheroutineyouwant. OtherLibraries Likewise,thedirectoriescontainingthesourcefortheotherlibrarieshavemakefiles. SystemTuning Thereareseveraltunableparametersinthesystem.Thesesetthesizeofvarioustablesand limits.Theyarefoundinthefile/usr/sys/h/param.hasmanifests(‘#define’s).Theirvaluesare rathergenerousinthesystemasdistributed.Ourtypicalmaximumnumberofusersisabout20, buttherearemanydaemonprocesses. Whenanyparameterischanged,itisprudenttorecompiletheentiresystem,asdiscussed above.Abriefdiscussionofeachfollows:

-5-NBUFThissetsthesizeofthediskbuffercache.Eachbufferis512bytes.Thisnumber shouldbearound25plusNMOUNT,orasbigascanbeiftheabovenumberof bufferscausethesystemtonotfitinmemory. NFILEThissetsthemaximumnumberofopenfiles.Anentryismadeinthistableevery timeafileis‘opened’(seeopen(2),creat(2)).Processessharethesetableentries acrossforks(fork(2)).ThisnumbershouldbeaboutthesamesizeasNINODE below.(Itcanbeabitsmaller.) NMOUNTThisindicatesthemaximumnumberofmountedfilesystems.Makeitbigenough thatyoudon’trunoutatinconvenienttimes. MAXMEMThisspecifiesthenumberofpage-framesofrealmemoryatthisinstallation.Itis currentlysetat1024(512Kbytes),andshouldbeincreasedifyouhavemore(otherwisetheadditionalmemorywillnotbeutilized). MAXUMEM Thissetsanadministrativelimitontheamountofmemoryaprocessmayhave.It iscurrentlysetatMAXMEM-128(i.e.896).Itwillbeincreasedautomaticallyby increasingMAXMEM.Note,however,thatthecurrentupperboundonMAX-UMEMis128*12(i.e.1536)whichlimitsuserprocessspaceto768Kbytes. PHYSPAGES Thisindicatesthenumberofpageswhichcanberepresentedonthememoryfreelist. Itscurrentvalueis2048,andissufficientforsystemsofuptoonemegabyte.Ifthis valueistoosmall(i.e.morememorythanfreelist)thensystemwillonlyusePHYS-PAGESpageframes. MAXUPRCThissetsthemaximumnumberofprocessesthatanyoneusercanberunningat anyonetime.Thisshouldbesetjustlargeenoughthatpeoplecangetworkdone butnotsolargethatausercanhogalltheprocessesavailable(usuallybyaccident!). NPROCThissetsthemaximumnumberofprocessesthatcanbeactive.Itdependsonthe demandpatternofthetypicaluser;weseemtoneedabout8timesthenumberof terminals. NINODEThissetsthesizeoftheinodetable.Thereisoneentryintheinodetableforevery opendevice,currentworkingdirectory,stickytextsegment,openfile,andmounted device.Notethatiftwousershaveafileopenthereisstillonlyoneentryinthe inodetable.Areasonableruleofthumbforthesizeofthistableis NPROC+NMOUNT+(numberofterminals) SSIZETheinitialsizeofaprocessstack.Thismaybemadebiggerifcommonlyrunprocesseshavelargedataareasonthestack. SINCRThesizeofthestackgrowthincrement. NOFILEThissetsthemaximumnumberoffilesthatanyoneprocesscanhaveopen.20is plenty. CANBSIZThisisthesizeofthetypewritercanonicalizationbuffer.Itisinthisbufferthat eraseandkillprocessingisdone.Thusthisisthemaximumsizeofaninputtypewriterline.256isusuallyplenty. SMAPSIZThenumberoffragmentsthatsecondary(swap)memorycanbebrokeninto.This shouldbebigenoughthatitneverrunsout.Thetheoreticalmaximumistwicethe numberofprocesses,butthisisavastoverestimateinpractice.70seemsenough. NCALLThisisthesizeofthecallouttable.Calloutsareenteredinthistablewhensome sortofinternalsystemtimingmustbedone,asincarriagereturndelaysforterminals.Thenumbermustbebigenoughtohandleallsuchrequests.

-6-NTEXTThemaximumnumberofsimultaneouslyexecutingpureprograms.Thisshouldbe bigenoughsoastonotrunoutofspaceunderheavyload.Areasonableruleof thumbisabout (numberofterminals)+(numberofstickyprograms) NCLISTThenumberofclistsegments.Aclistsegmentis12characters.NCLISTshouldbe bigenoughsothatthelistdoesn’tbecomeexhaustedwhenthemachineisbusy.The charactersthathavearrivedfromaterminalandarewaitingtobegiventoaprocesslivehere.Thusenoughspaceshouldbeleftsothateveryterminalcanhaveat leastoneaveragelinepending(about30or40characters). TIMEZONEThenumberofminuteswestwardfromGreenwich.See‘SettingUpUNIX’. DSTFLAGSee‘SettingUpUNIX’sectionontimeconversion. MSGBUFSThemaximumnumberofcharactersofsystemerrormessagessaved.Thisisusedas acircularbuffer. NCARGSThemaximumnumberofcharactersinanexec(2)arglist.Thisnumbercontrolshow manyargumentscanbepassedintoaprocess.5120ispracticallyinfinite. HZSettothedesiredfrequencyofthesystemclock(e.g.,50fora50Hz.clock).The currentvalueis60(i.e.60Hz.clock).