1*426d2b71SDavid du Colombier.HTML "Adding Application Support for a New Architecture in Plan 9 2219b2ee8SDavid du Colombier.TL 3219b2ee8SDavid du ColombierAdding Application Support for a New Architecture in Plan 9 4219b2ee8SDavid du Colombier.AU 5219b2ee8SDavid du ColombierBob Flandrena 67dd7cddfSDavid du Colombierbobf@plan9.bell-labs.com 7219b2ee8SDavid du Colombier.SH 8219b2ee8SDavid du ColombierIntroduction 9219b2ee8SDavid du Colombier.LP 10219b2ee8SDavid du ColombierPlan 9 has five classes of architecture-dependent software: 11219b2ee8SDavid du Colombierheaders, kernels, compilers and loaders, the 12219b2ee8SDavid du Colombier.CW libc 13219b2ee8SDavid du Colombiersystem library, and a few application programs. In general, 14219b2ee8SDavid du Colombierarchitecture-dependent programs 15219b2ee8SDavid du Colombierconsist of a portable part shared by all architectures and a 16219b2ee8SDavid du Colombierprocessor-specific portion for each supported architecture. 17219b2ee8SDavid du ColombierThe portable code is often compiled and stored in a library 18219b2ee8SDavid du Colombierassociated with 19219b2ee8SDavid du Colombiereach architecture. A program is built by 20219b2ee8SDavid du Colombiercompiling the architecture-specific code and loading it with the 21219b2ee8SDavid du Colombierlibrary. Support for a new architecture is provided 22219b2ee8SDavid du Colombierby building a compiler for the architecture, using it to 23219b2ee8SDavid du Colombiercompile the portable code into libraries, 24219b2ee8SDavid du Colombierwriting the architecture-specific code, and 25219b2ee8SDavid du Colombierthen loading that code with 26219b2ee8SDavid du Colombierthe libraries. 27219b2ee8SDavid du Colombier.LP 28219b2ee8SDavid du ColombierThis document describes the organization of the architecture-dependent 29219b2ee8SDavid du Colombiercode and headers on Plan 9. 30219b2ee8SDavid du ColombierThe first section briefly discusses the layout of 31219b2ee8SDavid du Colombierthe headers and the source code for the kernels, compilers, loaders, and the 32219b2ee8SDavid du Colombiersystem library, 33219b2ee8SDavid du Colombier.CW libc . 34219b2ee8SDavid du ColombierThe second section provides a detailed 35219b2ee8SDavid du Colombierdiscussion of the structure of 36219b2ee8SDavid du Colombier.CW libmach , 37219b2ee8SDavid du Colombiera library containing almost 38219b2ee8SDavid du Colombierall architecture-dependent code 39219b2ee8SDavid du Colombierused by application programs. 40219b2ee8SDavid du ColombierThe final section describes the steps required to add 41219b2ee8SDavid du Colombierapplication program support for a new architecture. 42219b2ee8SDavid du Colombier.SH 43219b2ee8SDavid du ColombierDirectory Structure 44219b2ee8SDavid du Colombier.PP 45219b2ee8SDavid du ColombierArchitecture-dependent information for the new processor 465d459b5aSDavid du Colombieris stored in the directory tree rooted at \f(CW/\fP\fIm\fP 47219b2ee8SDavid du Colombierwhere 48219b2ee8SDavid du Colombier.I m 49219b2ee8SDavid du Colombieris the name of the new architecture (e.g., 50219b2ee8SDavid du Colombier.CW mips ). 51219b2ee8SDavid du ColombierThe new directory should be initialized with several important 52219b2ee8SDavid du Colombiersubdirectories, notably 53219b2ee8SDavid du Colombier.CW bin , 54219b2ee8SDavid du Colombier.CW include , 55219b2ee8SDavid du Colombierand 56219b2ee8SDavid du Colombier.CW lib . 57219b2ee8SDavid du ColombierThe directory tree of an existing architecture 58219b2ee8SDavid du Colombierserves as a good model for the new tree. 59219b2ee8SDavid du ColombierThe architecture-dependent 60219b2ee8SDavid du Colombier.CW mkfile 61219b2ee8SDavid du Colombiermust be stored in the newly created root directory 62219b2ee8SDavid du Colombierfor the architecture. It is easiest to copy the 63219b2ee8SDavid du Colombiermkfile for an existing architecture and modify 64219b2ee8SDavid du Colombierit for the new architecture. When the mkfile 65219b2ee8SDavid du Colombieris correct, change the 66219b2ee8SDavid du Colombier.CW OS 67219b2ee8SDavid du Colombierand 68219b2ee8SDavid du Colombier.CW CPUS 697dd7cddfSDavid du Colombiervariables in the 707dd7cddfSDavid du Colombier.CW /sys/src/mkfile.proto 71219b2ee8SDavid du Colombierto reflect the addition of the new architecture. 72219b2ee8SDavid du Colombier.SH 73219b2ee8SDavid du ColombierHeaders 74219b2ee8SDavid du Colombier.LP 75219b2ee8SDavid du ColombierArchitecture-dependent headers are stored in directory 76219b2ee8SDavid du Colombier.CW /\fIm\fP/include 77219b2ee8SDavid du Colombierwhere 78219b2ee8SDavid du Colombier.I m 79219b2ee8SDavid du Colombieris the name of the architecture (e.g., 80219b2ee8SDavid du Colombier.CW mips ). 817dd7cddfSDavid du ColombierTwo header files are required: 827dd7cddfSDavid du Colombier.CW u.h 83219b2ee8SDavid du Colombierand 847dd7cddfSDavid du Colombier.CW ureg.h . 857dd7cddfSDavid du ColombierThe first defines fundamental data types, 867dd7cddfSDavid du Colombierbit settings for the floating point 877dd7cddfSDavid du Colombierstatus and control registers, and 887dd7cddfSDavid du Colombier.CW va_list 897dd7cddfSDavid du Colombierprocessing which depends on the stack 907dd7cddfSDavid du Colombiermodel for the architecture. This file 917dd7cddfSDavid du Colombieris best built by copying and modifying the 927dd7cddfSDavid du Colombier.CW u.h 937dd7cddfSDavid du Colombierfile from an architecture 947dd7cddfSDavid du Colombierwith a similar stack model. 95219b2ee8SDavid du ColombierThe 96219b2ee8SDavid du Colombier.CW ureg.h 97219b2ee8SDavid du Colombierfile 98219b2ee8SDavid du Colombiercontains a structure describing the layout 99219b2ee8SDavid du Colombierof the saved register set for 100219b2ee8SDavid du Colombierthe architecture; it is defined by the kernel. 101219b2ee8SDavid du Colombier.LP 102219b2ee8SDavid du ColombierHeader file 103219b2ee8SDavid du Colombier.CW /sys/include/a.out.h 104219b2ee8SDavid du Colombiercontains the definitions of the magic 105219b2ee8SDavid du Colombiernumbers used to identify executables for 106219b2ee8SDavid du Colombiereach architecture. When support for a new 107219b2ee8SDavid du Colombierarchitecture is added, the magic number 1087dd7cddfSDavid du Colombierfor the architecture must be added to this file. 109219b2ee8SDavid du Colombier.LP 110219b2ee8SDavid du ColombierThe header format of a bootable executable is defined by 111219b2ee8SDavid du Colombiereach manufacturer. Header file 112219b2ee8SDavid du Colombier.CW /sys/include/bootexec.h 113219b2ee8SDavid du Colombiercontains structures describing the headers currently 114219b2ee8SDavid du Colombiersupported. If the new architecture uses a common header 115219b2ee8SDavid du Colombiersuch as COFF, 116219b2ee8SDavid du Colombierthe header format is probably already defined, 117219b2ee8SDavid du Colombierbut if the bootable header format is non-standard, 118219b2ee8SDavid du Colombiera structure defining the format must be added to this file. 119219b2ee8SDavid du Colombier.LP 120219b2ee8SDavid du Colombier.SH 121219b2ee8SDavid du ColombierKernel 122219b2ee8SDavid du Colombier.LP 123219b2ee8SDavid du ColombierAlthough the kernel depends critically on the properties of the underlying 124219b2ee8SDavid du Colombierhardware, most of the 125219b2ee8SDavid du Colombierhigher-level kernel functions, including process 126219b2ee8SDavid du Colombiermanagement, paging, pseudo-devices, and some 127219b2ee8SDavid du Colombiernetworking code, are independent of processor 128219b2ee8SDavid du Colombierarchitecture. The portable kernel code 129219b2ee8SDavid du Colombieris divided into two parts: that implementing kernel 130219b2ee8SDavid du Colombierfunctions and that devoted to the boot process. 131219b2ee8SDavid du ColombierCode in the first class is stored in directory 132219b2ee8SDavid du Colombier.CW /sys/src/9/port 133219b2ee8SDavid du Colombierand the portable boot code is stored in 134219b2ee8SDavid du Colombier.CW /sys/src/9/boot . 135219b2ee8SDavid du ColombierArchitecture-dependent kernel code is stored in the 136219b2ee8SDavid du Colombiersubdirectories of 137219b2ee8SDavid du Colombier.CW /sys/src/9 138219b2ee8SDavid du Colombiernamed for each architecture. 139219b2ee8SDavid du Colombier.LP 140219b2ee8SDavid du ColombierThe relationship between the kernel code and the boot code 141219b2ee8SDavid du Colombieris convoluted and subtle. The portable boot code 142219b2ee8SDavid du Colombieris compiled into a library for each architecture. An architecture-specific 143219b2ee8SDavid du Colombiermain program is loaded with the appropriate library and the resulting 144219b2ee8SDavid du Colombierexecutable is compiled into the kernel where it is executed as 1457dd7cddfSDavid du Colombiera user process during the final stages of kernel initialization. The boot process 146219b2ee8SDavid du Colombierperforms authentication, attaches the name space root to the appropriate 147219b2ee8SDavid du Colombierfile system and starts the 148219b2ee8SDavid du Colombier.CW init 149219b2ee8SDavid du Colombierprocess. 150219b2ee8SDavid du Colombier.LP 151219b2ee8SDavid du ColombierThe organization of the portable kernel source code differs from that 152219b2ee8SDavid du Colombierof most other architecture-specific code. 153219b2ee8SDavid du ColombierInstead of storing the portable code in a library 1547dd7cddfSDavid du Colombierand loading it with the architecture-specific 1557dd7cddfSDavid du Colombiercode, the portable code is compiled directly into 1567dd7cddfSDavid du Colombierthe directory containing the architecture-specific code 1577dd7cddfSDavid du Colombierand linked with the object files built from the source in that directory. 158219b2ee8SDavid du Colombier.LP 159219b2ee8SDavid du Colombier.SH 160219b2ee8SDavid du ColombierCompilers and Loaders 161219b2ee8SDavid du Colombier.LP 162219b2ee8SDavid du ColombierThe compiler source code conforms to the usual 163219b2ee8SDavid du Colombierorganization: portable code is compiled into a library 164219b2ee8SDavid du Colombierfor each architecture 165219b2ee8SDavid du Colombierand the architecture-dependent code is loaded with 166219b2ee8SDavid du Colombierthat library. 167219b2ee8SDavid du ColombierThe common compiler code is stored in 168219b2ee8SDavid du Colombier.CW /sys/src/cmd/cc . 169219b2ee8SDavid du ColombierThe 170219b2ee8SDavid du Colombier.CW mkfile 171219b2ee8SDavid du Colombierin this directory compiles the portable source and 172219b2ee8SDavid du Colombierarchives the objects in a library for each architecture. 173219b2ee8SDavid du ColombierThe architecture-specific compiler source 174219b2ee8SDavid du Colombieris stored in a subdirectory of 175219b2ee8SDavid du Colombier.CW /sys/src/cmd 176219b2ee8SDavid du Colombierwith the same name as the compiler (e.g., 177219b2ee8SDavid du Colombier.CW /sys/src/cmd/vc ). 178219b2ee8SDavid du Colombier.LP 179219b2ee8SDavid du ColombierThere is no portable code shared by the loaders. 180219b2ee8SDavid du ColombierEach directory of loader source 181219b2ee8SDavid du Colombiercode is self-contained, except for 182219b2ee8SDavid du Colombiera header file and an instruction name table 183219b2ee8SDavid du Colombierincluded from the 184219b2ee8SDavid du Colombierdirectory of the associated 185219b2ee8SDavid du Colombiercompiler. 186219b2ee8SDavid du Colombier.LP 187219b2ee8SDavid du Colombier.SH 188219b2ee8SDavid du ColombierLibraries 189219b2ee8SDavid du Colombier.LP 190219b2ee8SDavid du ColombierMost C library modules are 191219b2ee8SDavid du Colombierportable; the source code is stored in 192219b2ee8SDavid du Colombierdirectories 193219b2ee8SDavid du Colombier.CW /sys/src/libc/port 194219b2ee8SDavid du Colombierand 195219b2ee8SDavid du Colombier.CW /sys/src/libc/9sys . 196219b2ee8SDavid du ColombierArchitecture-dependent library code 197219b2ee8SDavid du Colombieris stored in the subdirectory of 198219b2ee8SDavid du Colombier.CW /sys/src/libc 199219b2ee8SDavid du Colombiernamed the same as the target processor. 200219b2ee8SDavid du ColombierNon-portable functions not only 201219b2ee8SDavid du Colombierimplement architecture-dependent operations 202219b2ee8SDavid du Colombierbut also supply assembly language implementations 203219b2ee8SDavid du Colombierof functions where speed is critical. 204219b2ee8SDavid du ColombierDirectory 205219b2ee8SDavid du Colombier.CW /sys/src/libc/9syscall 206219b2ee8SDavid du Colombieris unusual because it 207219b2ee8SDavid du Colombiercontains architecture-dependent information 208219b2ee8SDavid du Colombierfor all architectures. 209219b2ee8SDavid du ColombierIt holds only a header file defining 210219b2ee8SDavid du Colombierthe names and numbers of system calls 211219b2ee8SDavid du Colombierand a 212219b2ee8SDavid du Colombier.CW mkfile . 213219b2ee8SDavid du ColombierThe 214219b2ee8SDavid du Colombier.CW mkfile 215219b2ee8SDavid du Colombierexecutes an 216219b2ee8SDavid du Colombier.CW rc 217219b2ee8SDavid du Colombierscript that parses the header file, constructs 218219b2ee8SDavid du Colombierassembler language functions implementing the system 219219b2ee8SDavid du Colombiercall for each architecture, assembles the code, 220219b2ee8SDavid du Colombierand archives the object files in 221219b2ee8SDavid du Colombier.CW libc . 222219b2ee8SDavid du ColombierThe assembler language syntax and the system interface 223219b2ee8SDavid du Colombierdiffer for each architecture. 224219b2ee8SDavid du ColombierThe 225219b2ee8SDavid du Colombier.CW rc 226219b2ee8SDavid du Colombierscript in this 227219b2ee8SDavid du Colombier.CW mkfile 228219b2ee8SDavid du Colombiermust be modified to support a new architecture. 229219b2ee8SDavid du Colombier.LP 230219b2ee8SDavid du Colombier.SH 231219b2ee8SDavid du ColombierApplications 232219b2ee8SDavid du Colombier.LP 233219b2ee8SDavid du ColombierApplication programs process two forms of architecture-dependent 234219b2ee8SDavid du Colombierinformation: executable images and intermediate object files. 235219b2ee8SDavid du ColombierAlmost all processing is on executable files. 236219b2ee8SDavid du ColombierSystem library 237219b2ee8SDavid du Colombier.CW libmach 2387dd7cddfSDavid du Colombierprovides functions that convert 239219b2ee8SDavid du Colombierarchitecture-specific data 2407dd7cddfSDavid du Colombierto a portable format so application programs 2417dd7cddfSDavid du Colombiercan process this data independent of its 242219b2ee8SDavid du Colombierunderlying representation. 243219b2ee8SDavid du ColombierFurther, when a new architecture is implemented 244219b2ee8SDavid du Colombieralmost all code changes 245219b2ee8SDavid du Colombierare confined to the library; 246219b2ee8SDavid du Colombiermost affected application programs need only be reloaded. 247219b2ee8SDavid du ColombierThe source code for the library is stored in 248219b2ee8SDavid du Colombier.CW /sys/src/libmach . 249219b2ee8SDavid du Colombier.LP 250219b2ee8SDavid du ColombierAn application program running on one type of 251219b2ee8SDavid du Colombierprocessor must be able to interpret 252219b2ee8SDavid du Colombierarchitecture-dependent information for all 253219b2ee8SDavid du Colombiersupported processors. 254219b2ee8SDavid du ColombierFor example, a debugger must be able to debug 255219b2ee8SDavid du Colombierthe executables of 256219b2ee8SDavid du Colombierall architectures, not just the 257219b2ee8SDavid du Colombierarchitecture on which it is executing, since 258219b2ee8SDavid du Colombier.CW /proc 259219b2ee8SDavid du Colombiermay be imported from a different machine. 260219b2ee8SDavid du Colombier.LP 261219b2ee8SDavid du ColombierA small part of the application library 262219b2ee8SDavid du Colombierprovides functions to 263219b2ee8SDavid du Colombierextract symbol references from object files. 264219b2ee8SDavid du ColombierThe remainder provides the following processing 265219b2ee8SDavid du Colombierof executable files or memory images: 266219b2ee8SDavid du Colombier.IP \(bu 267219b2ee8SDavid du ColombierHeader interpretation. 268219b2ee8SDavid du Colombier.IP \(bu 269219b2ee8SDavid du ColombierSymbol table interpretation. 270219b2ee8SDavid du Colombier.IP \(bu 271219b2ee8SDavid du ColombierExecution context interpretation, such as stack traces 272219b2ee8SDavid du Colombierand stack frame location. 273219b2ee8SDavid du Colombier.IP \(bu 274219b2ee8SDavid du ColombierInstruction interpretation including disassembly and 275219b2ee8SDavid du Colombierinstruction size and follow-set calculations. 276219b2ee8SDavid du Colombier.IP \(bu 277219b2ee8SDavid du ColombierException and floating point number interpretation. 278219b2ee8SDavid du Colombier.IP \(bu 279219b2ee8SDavid du ColombierArchitecture-independent read and write access through a 280219b2ee8SDavid du Colombierrelocation map. 281219b2ee8SDavid du Colombier.LP 282219b2ee8SDavid du ColombierHeader file 283219b2ee8SDavid du Colombier.CW /sys/include/mach.h 284219b2ee8SDavid du Colombierdefines the interfaces to the 285219b2ee8SDavid du Colombierapplication library. Manual pages 286219b2ee8SDavid du Colombier.I mach (2), 287219b2ee8SDavid du Colombier.I symbol (2), 288219b2ee8SDavid du Colombierand 289219b2ee8SDavid du Colombier.I object (2) 290219b2ee8SDavid du Colombierdescribe the details of the 291219b2ee8SDavid du Colombierlibrary functions. 292219b2ee8SDavid du Colombier.LP 293219b2ee8SDavid du ColombierTwo data structures, called 294219b2ee8SDavid du Colombier.CW Mach 295219b2ee8SDavid du Colombierand 296219b2ee8SDavid du Colombier.CW Machdata , 297219b2ee8SDavid du Colombiercontain architecture-dependent parameters and 298219b2ee8SDavid du Colombiera jump table of functions. 299219b2ee8SDavid du ColombierGlobal variables 300219b2ee8SDavid du Colombier.CW mach 301219b2ee8SDavid du Colombierand 302219b2ee8SDavid du Colombier.CW machdata 303219b2ee8SDavid du Colombierpoint to the 304219b2ee8SDavid du Colombier.CW Mach 305219b2ee8SDavid du Colombierand 306219b2ee8SDavid du Colombier.CW Machdata 307219b2ee8SDavid du Colombierdata structures associated with the target architecture. 308219b2ee8SDavid du ColombierAn application determines the target architecture of 309219b2ee8SDavid du Colombiera file or executable image, sets the global pointers 310219b2ee8SDavid du Colombierto the data structures associated with that architecture, 311219b2ee8SDavid du Colombierand subsequently performs all references indirectly through the 312219b2ee8SDavid du Colombierpointers. 313219b2ee8SDavid du ColombierAs a result, direct references to the tables for each 314219b2ee8SDavid du Colombierarchitecture are avoided and the application code intrinsically 315219b2ee8SDavid du Colombiersupports all architectures (though only one at a time). 316219b2ee8SDavid du Colombier.LP 317219b2ee8SDavid du ColombierObject file processing is handled similarly: architecture-dependent 318219b2ee8SDavid du Colombierfunctions identify and 319219b2ee8SDavid du Colombierdecode the intermediate files for the processor. 320219b2ee8SDavid du ColombierThe application indirectly 321219b2ee8SDavid du Colombierinvokes a classification function to identify 3227dd7cddfSDavid du Colombierthe architecture of the object code and to select the 323219b2ee8SDavid du Colombierappropriate decoding function. Subsequent calls 324219b2ee8SDavid du Colombierthen use that function to decode each record. Again, 325219b2ee8SDavid du Colombierthe layer of indirection allows the application code 326219b2ee8SDavid du Colombierto support all architectures without modification. 327219b2ee8SDavid du Colombier.LP 328219b2ee8SDavid du ColombierSplitting the architecture-dependent information 329219b2ee8SDavid du Colombierbetween the 330219b2ee8SDavid du Colombier.CW Mach 331219b2ee8SDavid du Colombierand 332219b2ee8SDavid du Colombier.CW Machdata 333219b2ee8SDavid du Colombierdata structures 3347dd7cddfSDavid du Colombierallows applications to choose 335219b2ee8SDavid du Colombieran appropriate level of service. Even though an application 336219b2ee8SDavid du Colombierdoes not directly reference the architecture-specific data structures, 337219b2ee8SDavid du Colombierit must load the 338219b2ee8SDavid du Colombierarchitecture-dependent tables and code 339219b2ee8SDavid du Colombierfor all architectures it supports. The size of this data 340219b2ee8SDavid du Colombiercan be substantial and many applications do not require 341219b2ee8SDavid du Colombierthe full range of architecture-dependent functionality. 342219b2ee8SDavid du ColombierFor example, the 343219b2ee8SDavid du Colombier.CW size 344219b2ee8SDavid du Colombiercommand does not require the disassemblers for every architecture; 345219b2ee8SDavid du Colombierit only needs to decode the header. 346219b2ee8SDavid du ColombierThe 347219b2ee8SDavid du Colombier.CW Mach 348219b2ee8SDavid du Colombierdata structure contains a few architecture-specific parameters 349219b2ee8SDavid du Colombierand a description of the processor register set. 350219b2ee8SDavid du ColombierThe size of the structure 351219b2ee8SDavid du Colombiervaries with the size of the register 352219b2ee8SDavid du Colombierset but is generally small. 353219b2ee8SDavid du ColombierThe 354219b2ee8SDavid du Colombier.CW Machdata 355219b2ee8SDavid du Colombierdata structure contains 356219b2ee8SDavid du Colombiera jump table of architecture-dependent functions; 357219b2ee8SDavid du Colombierthe amount of code and data referenced by this table 358219b2ee8SDavid du Colombieris usually large. 359219b2ee8SDavid du Colombier.SH 360219b2ee8SDavid du ColombierLibmach Source Code Organization 361219b2ee8SDavid du Colombier.LP 362219b2ee8SDavid du ColombierThe 363219b2ee8SDavid du Colombier.CW libmach 364219b2ee8SDavid du Colombierlibrary provides four classes of functionality: 365219b2ee8SDavid du Colombier.LP 366219b2ee8SDavid du Colombier.IP "Header and Symbol Table Decoding\ -\ " 367219b2ee8SDavid du ColombierFiles 368219b2ee8SDavid du Colombier.CW executable.c 369219b2ee8SDavid du Colombierand 370219b2ee8SDavid du Colombier.CW sym.c 371219b2ee8SDavid du Colombiercontain code to interpret the header and 372219b2ee8SDavid du Colombiersymbol tables of 373219b2ee8SDavid du Colombieran executable file or executing image. 374219b2ee8SDavid du ColombierFunction 375219b2ee8SDavid du Colombier.CW crackhdr 376219b2ee8SDavid du Colombierdecodes the header, 377219b2ee8SDavid du Colombierreformats the 378219b2ee8SDavid du Colombierinformation into an 379219b2ee8SDavid du Colombier.CW Fhdr 380219b2ee8SDavid du Colombierdata structure, and points 381219b2ee8SDavid du Colombierglobal variable 382219b2ee8SDavid du Colombier.CW mach 383219b2ee8SDavid du Colombierto the 384219b2ee8SDavid du Colombier.CW Mach 385219b2ee8SDavid du Colombierdata structure of the target architecture. 386219b2ee8SDavid du ColombierThe symbol table processing 387219b2ee8SDavid du Colombieruses the data in the 388219b2ee8SDavid du Colombier.CW Fhdr 389219b2ee8SDavid du Colombierstructure to decode the symbol table. 3907dd7cddfSDavid du ColombierA variety of symbol table access functions then support 391219b2ee8SDavid du Colombierqueries on the reformatted table. 392219b2ee8SDavid du Colombier.IP "Debugger Support\ -\ " 393219b2ee8SDavid du ColombierFiles named 394219b2ee8SDavid du Colombier.CW \fIm\fP.c , 395219b2ee8SDavid du Colombierwhere 396219b2ee8SDavid du Colombier.I m 397219b2ee8SDavid du Colombieris the code letter assigned to the architecture, 398219b2ee8SDavid du Colombiercontain the initialized 399219b2ee8SDavid du Colombier.CW Mach 400219b2ee8SDavid du Colombierdata structure and the definition of the register 401219b2ee8SDavid du Colombierset for each architecture. 402219b2ee8SDavid du ColombierArchitecture-specific debugger support functions and 403219b2ee8SDavid du Colombieran initialized 404219b2ee8SDavid du Colombier.CW Machdata 405219b2ee8SDavid du Colombierstructure are stored in 406219b2ee8SDavid du Colombierfiles named 407219b2ee8SDavid du Colombier.CW \fIm\fPdb.c . 408219b2ee8SDavid du ColombierFiles 409219b2ee8SDavid du Colombier.CW machdata.c 410219b2ee8SDavid du Colombierand 411219b2ee8SDavid du Colombier.CW setmach.c 412219b2ee8SDavid du Colombiercontain debugger support functions shared 413219b2ee8SDavid du Colombierby multiple architectures. 414219b2ee8SDavid du Colombier.IP "Architecture-Independent Access\ -\ " 415219b2ee8SDavid du ColombierFiles 416219b2ee8SDavid du Colombier.CW map.c , 417219b2ee8SDavid du Colombier.CW access.c , 418219b2ee8SDavid du Colombierand 419219b2ee8SDavid du Colombier.CW swap.c 420219b2ee8SDavid du Colombierprovide accesses through a relocation map 421219b2ee8SDavid du Colombierto data in an executable file or executing image. 422219b2ee8SDavid du ColombierByte-swapping is performed as needed. Global variables 423219b2ee8SDavid du Colombier.CW mach 424219b2ee8SDavid du Colombierand 425219b2ee8SDavid du Colombier.CW machdata 426219b2ee8SDavid du Colombiermust point to the 427219b2ee8SDavid du Colombier.CW Mach 428219b2ee8SDavid du Colombierand 429219b2ee8SDavid du Colombier.CW Machdata 430219b2ee8SDavid du Colombierdata structures of the target architecture. 431219b2ee8SDavid du Colombier.IP "Object File Interpretation\ -\ " 432219b2ee8SDavid du ColombierThese files contain functions to identify the 433219b2ee8SDavid du Colombiertarget architecture of an 434219b2ee8SDavid du Colombierintermediate object file 435219b2ee8SDavid du Colombierand extract references to symbols. File 436219b2ee8SDavid du Colombier.CW obj.c 437219b2ee8SDavid du Colombiercontains code common to all architectures; 438219b2ee8SDavid du Colombierfile 439219b2ee8SDavid du Colombier.CW \fIm\fPobj.c 440219b2ee8SDavid du Colombiercontains the architecture-specific source code 441219b2ee8SDavid du Colombierfor the machine with code character 442219b2ee8SDavid du Colombier.I m . 443219b2ee8SDavid du Colombier.LP 444219b2ee8SDavid du ColombierThe 445219b2ee8SDavid du Colombier.CW Machdata 446219b2ee8SDavid du Colombierdata structure is primarily a jump 447219b2ee8SDavid du Colombiertable of architecture-dependent debugger support 448219b2ee8SDavid du Colombierfunctions. Functions select the 449219b2ee8SDavid du Colombier.CW Machdata 450219b2ee8SDavid du Colombierstructure for a target architecture based 451219b2ee8SDavid du Colombieron the value of the 452219b2ee8SDavid du Colombier.CW type 453219b2ee8SDavid du Colombiercode in the 454219b2ee8SDavid du Colombier.CW Fhdr 455219b2ee8SDavid du Colombierstructure or the name of the architecture. 456219b2ee8SDavid du ColombierThe jump table provides functions to swap bytes, interpret 457219b2ee8SDavid du Colombiermachine instructions, 458219b2ee8SDavid du Colombierperform stack 459219b2ee8SDavid du Colombiertraces, find stack frames, format floating point 460219b2ee8SDavid du Colombiernumbers, and decode machine exceptions. Some functions, such as 461219b2ee8SDavid du Colombiermachine exception decoding, are idiosyncratic and must be 462219b2ee8SDavid du Colombiersupplied for each architecture. Others depend 463219b2ee8SDavid du Colombieron the compiler run-time model and several 464219b2ee8SDavid du Colombierarchitectures may share code common to a model. For 465219b2ee8SDavid du Colombierexample, many architectures share the code to 466219b2ee8SDavid du Colombierprocess the fixed-frame stack model implemented by 467219b2ee8SDavid du Colombierseveral of the compilers. 468219b2ee8SDavid du ColombierFinally, some 469219b2ee8SDavid du Colombierfunctions, such as byte-swapping, provide a general capability and 470219b2ee8SDavid du Colombierthe jump table need only select an implementation appropriate 471219b2ee8SDavid du Colombierto the architecture. 472219b2ee8SDavid du Colombier.LP 473219b2ee8SDavid du Colombier.SH 474219b2ee8SDavid du ColombierAdding Application Support for a New Architecture 475219b2ee8SDavid du Colombier.LP 476219b2ee8SDavid du ColombierThis section describes the 477219b2ee8SDavid du Colombiersteps required to add application-level 478219b2ee8SDavid du Colombiersupport for a new architecture. 479219b2ee8SDavid du ColombierWe assume 480219b2ee8SDavid du Colombierthe kernel, compilers, loaders and system libraries 481219b2ee8SDavid du Colombierfor the new architecture are already in place. This 4827dd7cddfSDavid du Colombierimplies that a code-character has been assigned and 483219b2ee8SDavid du Colombierthat the architecture-specific headers have been 484219b2ee8SDavid du Colombierupdated. 485219b2ee8SDavid du ColombierWith the exception of two programs, 486219b2ee8SDavid du Colombierapplication-level changes are confined to header 487219b2ee8SDavid du Colombierfiles and the source code in 488219b2ee8SDavid du Colombier.CW /sys/src/libmach . 489219b2ee8SDavid du Colombier.LP 490219b2ee8SDavid du Colombier.IP 1. 491219b2ee8SDavid du ColombierBegin by updating the application library 492219b2ee8SDavid du Colombierheader file in 493219b2ee8SDavid du Colombier.CW /sys/include/mach.h . 494219b2ee8SDavid du ColombierAdd the following symbolic codes to the 495219b2ee8SDavid du Colombier.CW enum 496219b2ee8SDavid du Colombierstatement near the beginning of the file: 497219b2ee8SDavid du Colombier.RS 498219b2ee8SDavid du Colombier.IP \(bu 499219b2ee8SDavid du ColombierThe processor type code, e.g., 500219b2ee8SDavid du Colombier.CW MSPARC . 501219b2ee8SDavid du Colombier.IP \(bu 502219b2ee8SDavid du ColombierThe type of the executable. There are usually 503219b2ee8SDavid du Colombiertwo codes needed: one for a bootable 504219b2ee8SDavid du Colombierexecutable (i.e., a kernel) and one for an 505219b2ee8SDavid du Colombierapplication executable. 506219b2ee8SDavid du Colombier.IP \(bu 507219b2ee8SDavid du ColombierThe disassembler type code. Add one entry for 508219b2ee8SDavid du Colombiereach supported disassembler for the architecture. 509219b2ee8SDavid du Colombier.IP \(bu 510219b2ee8SDavid du ColombierA symbolic code for the object file. 511219b2ee8SDavid du Colombier.RE 512219b2ee8SDavid du Colombier.LP 513219b2ee8SDavid du Colombier.IP 2. 514219b2ee8SDavid du ColombierIn a file name 515219b2ee8SDavid du Colombier.CW /sys/src/libmach/\fIm\fP.c 516219b2ee8SDavid du Colombier(where 517219b2ee8SDavid du Colombier.I m 518219b2ee8SDavid du Colombieris the identifier character assigned to the architecture), 519219b2ee8SDavid du Colombierinitialize 520219b2ee8SDavid du Colombier.CW Reglist 521219b2ee8SDavid du Colombierand 522219b2ee8SDavid du Colombier.CW Mach 523219b2ee8SDavid du Colombierdata structures with values defining 524219b2ee8SDavid du Colombierthe register set and various system parameters. 5257dd7cddfSDavid du ColombierThe source file for a similar architecture 526219b2ee8SDavid du Colombiercan serve as template. 527219b2ee8SDavid du ColombierMost of the fields of the 528219b2ee8SDavid du Colombier.CW Mach 529219b2ee8SDavid du Colombierdata structure are obvious 530219b2ee8SDavid du Colombierbut a few require further explanation. 531219b2ee8SDavid du Colombier.RS 532219b2ee8SDavid du Colombier.IP "\f(CWkbase\fP\ -\ " 533219b2ee8SDavid du ColombierThis field 534219b2ee8SDavid du Colombiercontains the address of the kernel 535219b2ee8SDavid du Colombier.CW ublock . 536219b2ee8SDavid du ColombierThe debuggers 537219b2ee8SDavid du Colombierassume the first entry of the kernel 538219b2ee8SDavid du Colombier.CW ublock 539219b2ee8SDavid du Colombierpoints to the 540219b2ee8SDavid du Colombier.CW Proc 541219b2ee8SDavid du Colombierstructure for a kernel thread. 542219b2ee8SDavid du Colombier.IP "\f(CWktmask\fP\ -\ " 543219b2ee8SDavid du ColombierThis field 544219b2ee8SDavid du Colombieris a bit mask used to calculate the kernel text address from 545219b2ee8SDavid du Colombierthe kernel 546219b2ee8SDavid du Colombier.CW ublock 547219b2ee8SDavid du Colombieraddress. 548219b2ee8SDavid du ColombierThe first page of the 549219b2ee8SDavid du Colombierkernel text segment is calculated by 550219b2ee8SDavid du ColombierANDing 551219b2ee8SDavid du Colombierthe negation of this mask with 552219b2ee8SDavid du Colombier.CW kbase . 553219b2ee8SDavid du Colombier.IP "\f(CWkspoff\fP\ -\ " 554219b2ee8SDavid du ColombierThis field 555219b2ee8SDavid du Colombiercontains the byte offset in the 556219b2ee8SDavid du Colombier.CW Proc 557219b2ee8SDavid du Colombierdata structure to the saved kernel 558219b2ee8SDavid du Colombierstack pointer for a suspended kernel thread. This 559219b2ee8SDavid du Colombieris the offset to the 560219b2ee8SDavid du Colombier.CW sched.sp 561219b2ee8SDavid du Colombierfield of a 562219b2ee8SDavid du Colombier.CW Proc 563219b2ee8SDavid du Colombiertable entry. 564219b2ee8SDavid du Colombier.IP "\f(CWkpcoff\fP\ -\ " 565219b2ee8SDavid du ColombierThis field contains the byte offset into the 566219b2ee8SDavid du Colombier.CW Proc 567219b2ee8SDavid du Colombierdata structure 568219b2ee8SDavid du Colombierof 569219b2ee8SDavid du Colombierthe program counter of a suspended kernel thread. 570219b2ee8SDavid du ColombierThis is the offset to 571219b2ee8SDavid du Colombierfield 572219b2ee8SDavid du Colombier.CW sched.pc 573219b2ee8SDavid du Colombierin that structure. 574219b2ee8SDavid du Colombier.IP "\f(CWkspdelta\fP and \f(CWkpcdelta\fP\ -\ " 575219b2ee8SDavid du ColombierThese fields 576219b2ee8SDavid du Colombiercontain corrections to be added to 577219b2ee8SDavid du Colombierthe stack pointer and program counter, respectively, 578219b2ee8SDavid du Colombierto properly locate the stack and next 579219b2ee8SDavid du Colombierinstruction of a kernel thread. These 580219b2ee8SDavid du Colombiervalues bias the saved registers retrieved 581219b2ee8SDavid du Colombierfrom the 582219b2ee8SDavid du Colombier.CW Label 583219b2ee8SDavid du Colombierstructure named 584219b2ee8SDavid du Colombier.CW sched 585219b2ee8SDavid du Colombierin the 586219b2ee8SDavid du Colombier.CW Proc 587219b2ee8SDavid du Colombierdata structure. 588219b2ee8SDavid du ColombierMost architectures require no bias 589219b2ee8SDavid du Colombierand these fields contain zeros. 590219b2ee8SDavid du Colombier.IP "\f(CWscalloff\fP\ -\ " 591219b2ee8SDavid du ColombierThis field 592219b2ee8SDavid du Colombiercontains the byte offset of the 593219b2ee8SDavid du Colombier.CW scallnr 594219b2ee8SDavid du Colombierfield in the 595219b2ee8SDavid du Colombier.CW ublock 596219b2ee8SDavid du Colombierdata structure associated with a process. 597219b2ee8SDavid du ColombierThe 598219b2ee8SDavid du Colombier.CW scallnr 599219b2ee8SDavid du Colombierfield contains the number of the 600219b2ee8SDavid du Colombierlast system call executed by the process. 601219b2ee8SDavid du ColombierThe location of the field varies depending on 602219b2ee8SDavid du Colombierthe size of the floating point register set 603219b2ee8SDavid du Colombierwhich precedes it in the 604219b2ee8SDavid du Colombier.CW ublock . 605219b2ee8SDavid du Colombier.RE 606219b2ee8SDavid du Colombier.LP 607219b2ee8SDavid du Colombier.IP 3. 6087dd7cddfSDavid du ColombierAdd an entry to the initialization of the 609219b2ee8SDavid du Colombier.CW ExecTable 610219b2ee8SDavid du Colombierdata structure at the beginning of file 6117dd7cddfSDavid du Colombier.CW /sys/src/libmach/executable.c . 612219b2ee8SDavid du ColombierMost architectures 613219b2ee8SDavid du Colombierrequire two entries: one for 614219b2ee8SDavid du Colombiera normal executable and 615219b2ee8SDavid du Colombierone for a bootable 616219b2ee8SDavid du Colombierimage. Each table entry contains: 617219b2ee8SDavid du Colombier.RS 618219b2ee8SDavid du Colombier.IP \(bu 619219b2ee8SDavid du ColombierMagic Number\ \-\ 620219b2ee8SDavid du ColombierThe big-endian magic number assigned to the architecture in 621219b2ee8SDavid du Colombier.CW /sys/include/a.out.h . 622219b2ee8SDavid du Colombier.IP \(bu 623219b2ee8SDavid du ColombierName\ \-\ 624219b2ee8SDavid du ColombierA string describing the executable. 625219b2ee8SDavid du Colombier.IP \(bu 626219b2ee8SDavid du ColombierExecutable type code\ \-\ 627219b2ee8SDavid du ColombierThe executable code assigned in 628219b2ee8SDavid du Colombier.CW /sys/include/mach.h . 629219b2ee8SDavid du Colombier.IP \(bu 630219b2ee8SDavid du Colombier\f(CWMach\fP pointer\ \-\ 631219b2ee8SDavid du ColombierThe address of the initialized 632219b2ee8SDavid du Colombier.CW Mach 633219b2ee8SDavid du Colombierdata structure constructed in Step 2. 634219b2ee8SDavid du ColombierYou must also add the name of this table to the 635219b2ee8SDavid du Colombierlist of 636219b2ee8SDavid du Colombier.CW Mach 637219b2ee8SDavid du Colombiertable definitions immediately preceding the 638219b2ee8SDavid du Colombier.CW ExecTable 639219b2ee8SDavid du Colombierinitialization. 640219b2ee8SDavid du Colombier.IP \(bu 641219b2ee8SDavid du ColombierHeader size\ \-\ 642219b2ee8SDavid du ColombierThe number of bytes in the executable file header. 643219b2ee8SDavid du ColombierThe size of a normal executable header is always 644219b2ee8SDavid du Colombier.CW sizeof(Exec) . 645219b2ee8SDavid du ColombierThe size of a bootable header is 646219b2ee8SDavid du Colombierdetermined by the size of the structure 647219b2ee8SDavid du Colombierfor the architecture defined in 648219b2ee8SDavid du Colombier.CW /sys/include/bootexec.h . 649219b2ee8SDavid du Colombier.IP \(bu 650219b2ee8SDavid du ColombierByte-swapping function\ \-\ 651219b2ee8SDavid du ColombierThe address of 652219b2ee8SDavid du Colombier.CW beswal 653219b2ee8SDavid du Colombieror 654219b2ee8SDavid du Colombier.CW leswal 655219b2ee8SDavid du Colombierfor big-endian and little-endian 656219b2ee8SDavid du Colombierarchitectures, respectively. 657219b2ee8SDavid du Colombier.IP \(bu 658219b2ee8SDavid du ColombierDecoder function\ -\ 659219b2ee8SDavid du ColombierThe address of a function to decode the header. 660219b2ee8SDavid du ColombierFunction 661219b2ee8SDavid du Colombier.CW adotout 662219b2ee8SDavid du Colombierdecodes the common header shared by all normal 663219b2ee8SDavid du Colombier(i.e., non-bootable) executable files. 664219b2ee8SDavid du ColombierThe header format of bootable 665219b2ee8SDavid du Colombierexecutable files is defined by the manufacturer and 666219b2ee8SDavid du Colombiera custom function is almost always 667219b2ee8SDavid du Colombierrequired to decode it. 668219b2ee8SDavid du ColombierHeader file 669219b2ee8SDavid du Colombier.CW /sys/include/bootexec.h 670219b2ee8SDavid du Colombiercontains data structures defining the bootable 671219b2ee8SDavid du Colombierheaders for all architectures. If the new architecture 672219b2ee8SDavid du Colombieruses an existing format, the appropriate 673219b2ee8SDavid du Colombierdecoding function should already be in 674219b2ee8SDavid du Colombier.CW executable.c . 675219b2ee8SDavid du ColombierIf the header format is unique, then 676219b2ee8SDavid du Colombiera new function must be added to this file. 677219b2ee8SDavid du ColombierUsually the decoding function for an existing 678219b2ee8SDavid du Colombierarchitecture can be adopted with minor modifications. 679219b2ee8SDavid du Colombier.RE 680219b2ee8SDavid du Colombier.LP 681219b2ee8SDavid du Colombier.IP 4. 682219b2ee8SDavid du ColombierWrite an object file parser and 683219b2ee8SDavid du Colombierstore it in file 684219b2ee8SDavid du Colombier.CW /sys/src/libmach/\fIm\fPobj.c 685219b2ee8SDavid du Colombierwhere 686219b2ee8SDavid du Colombier.I m 687219b2ee8SDavid du Colombieris the identifier character assigned to the architecture. 688219b2ee8SDavid du ColombierTwo functions are required: a predicate to identify an 689219b2ee8SDavid du Colombierobject file for the architecture and a function to extract 690219b2ee8SDavid du Colombiersymbol references from the object code. 691219b2ee8SDavid du ColombierThe object code format is obscure but 692219b2ee8SDavid du Colombierit is often possible to adopt the 693219b2ee8SDavid du Colombiercode of an existing architecture 694219b2ee8SDavid du Colombierwith minor modifications. 695219b2ee8SDavid du ColombierWhen these 696219b2ee8SDavid du Colombierfunctions are in hand, insert their addresses 697219b2ee8SDavid du Colombierin the jump table at the beginning of file 698219b2ee8SDavid du Colombier.CW /sys/src/libmach/obj.c . 699219b2ee8SDavid du Colombier.LP 700219b2ee8SDavid du Colombier.IP 5. 701219b2ee8SDavid du ColombierImplement the required debugger support functions and 702219b2ee8SDavid du Colombierinitialize the parameters and jump table of the 703219b2ee8SDavid du Colombier.CW Machdata 704219b2ee8SDavid du Colombierdata structure for the architecture. 7057dd7cddfSDavid du ColombierThis code is conventionally stored in 706219b2ee8SDavid du Colombiera file named 707219b2ee8SDavid du Colombier.CW /sys/src/libmach/\fIm\fPdb.c 708219b2ee8SDavid du Colombierwhere 709219b2ee8SDavid du Colombier.I m 710219b2ee8SDavid du Colombieris the identifier character assigned to the architecture. 711219b2ee8SDavid du ColombierThe fields of the 712219b2ee8SDavid du Colombier.CW Machdata 713219b2ee8SDavid du Colombierstructure are: 714219b2ee8SDavid du Colombier.RS 715219b2ee8SDavid du Colombier.IP "\f(CWbpinst\fP and \f(CWbpsize\fP\ -\ " 716219b2ee8SDavid du ColombierThese fields 717219b2ee8SDavid du Colombiercontain the breakpoint instruction and the size 718219b2ee8SDavid du Colombierof the instruction, respectively. 719219b2ee8SDavid du Colombier.IP "\f(CWswab\fP\ -\ " 720219b2ee8SDavid du ColombierThis field 721219b2ee8SDavid du Colombiercontains the address of a function to 722219b2ee8SDavid du Colombierbyte-swap a 16-bit value. Choose 723219b2ee8SDavid du Colombier.CW leswab 724219b2ee8SDavid du Colombieror 725219b2ee8SDavid du Colombier.CW beswab 726219b2ee8SDavid du Colombierfor little-endian or big-endian architectures, respectively. 727219b2ee8SDavid du Colombier.IP "\f(CWswal\fP\ -\ " 728219b2ee8SDavid du ColombierThis field 729219b2ee8SDavid du Colombiercontains the address of a function to 730219b2ee8SDavid du Colombierbyte-swap a 32-bit value. Choose 731219b2ee8SDavid du Colombier.CW leswal 732219b2ee8SDavid du Colombieror 733219b2ee8SDavid du Colombier.CW beswal 734219b2ee8SDavid du Colombierfor little-endian or big-endian architectures, respectively. 735219b2ee8SDavid du Colombier.IP "\f(CWctrace\fP\ -\ " 736219b2ee8SDavid du ColombierThis field 737219b2ee8SDavid du Colombiercontains the address of a function to perform a 738219b2ee8SDavid du ColombierC-language stack trace. Two general trace functions, 739219b2ee8SDavid du Colombier.CW risctrace 740219b2ee8SDavid du Colombierand 741219b2ee8SDavid du Colombier.CW cisctrace , 742219b2ee8SDavid du Colombiertraverse fixed-frame and relative-frame stacks, 743219b2ee8SDavid du Colombierrespectively. If the compiler for the 744219b2ee8SDavid du Colombiernew architecture conforms to one of 745219b2ee8SDavid du Colombierthese models, select the appropriate function. If the 746219b2ee8SDavid du Colombierstack model is unique, 747219b2ee8SDavid du Colombiersupply a custom stack trace function. 748219b2ee8SDavid du Colombier.IP "\f(CWfindframe\fP\ -\ " 749219b2ee8SDavid du ColombierThis field 750219b2ee8SDavid du Colombiercontains the address of a function to locate the stack 751219b2ee8SDavid du Colombierframe associated with a text address. 752219b2ee8SDavid du ColombierGeneric functions 753219b2ee8SDavid du Colombier.CW riscframe 754219b2ee8SDavid du Colombierand 755219b2ee8SDavid du Colombier.CW ciscframe 756219b2ee8SDavid du Colombierprocess fixed-frame and relative-frame stack 757219b2ee8SDavid du Colombiermodels. 758219b2ee8SDavid du Colombier.IP "\f(CWufixup\fP\ -\ " 759219b2ee8SDavid du ColombierThis field 760219b2ee8SDavid du Colombiercontains the address of a function to adjust 761219b2ee8SDavid du Colombierthe base address of the register save area. 762219b2ee8SDavid du ColombierCurrently, only the 763219b2ee8SDavid du Colombier68020 requires this bias 764219b2ee8SDavid du Colombierto offset over the active 765219b2ee8SDavid du Colombierexception frame. 766219b2ee8SDavid du Colombier.IP "\f(CWexcep\fP\ -\ " 767219b2ee8SDavid du ColombierThis field 768219b2ee8SDavid du Colombiercontains the address of a function to produce a 769219b2ee8SDavid du Colombiertext 770219b2ee8SDavid du Colombierstring describing the 771219b2ee8SDavid du Colombiercurrent exception. 772219b2ee8SDavid du ColombierEach architecture stores exception 773219b2ee8SDavid du Colombierinformation uniquely, so this code must always be supplied. 774219b2ee8SDavid du Colombier.IP "\f(CWbpfix\fP\ -\ " 775219b2ee8SDavid du ColombierThis field 776219b2ee8SDavid du Colombiercontains the address of a function to adjust an 777219b2ee8SDavid du Colombieraddress prior to laying down a breakpoint. 778219b2ee8SDavid du Colombier.IP "\f(CWsftos\fP\ -\ " 779219b2ee8SDavid du ColombierThis field 780219b2ee8SDavid du Colombiercontains the address of a function to convert a single 781219b2ee8SDavid du Colombierprecision floating point value 782219b2ee8SDavid du Colombierto a string. Choose 783219b2ee8SDavid du Colombier.CW leieeesftos 784219b2ee8SDavid du Colombierfor little-endian 785219b2ee8SDavid du Colombieror 786219b2ee8SDavid du Colombier.CW beieeesftos 787219b2ee8SDavid du Colombierfor big-endian architectures. 788219b2ee8SDavid du Colombier.IP "\f(CWdftos\fP\ -\ " 789219b2ee8SDavid du ColombierThis field 790219b2ee8SDavid du Colombiercontains the address of a function to convert a double 791219b2ee8SDavid du Colombierprecision floating point value 792219b2ee8SDavid du Colombierto a string. Choose 793219b2ee8SDavid du Colombier.CW leieeedftos 794219b2ee8SDavid du Colombierfor little-endian 795219b2ee8SDavid du Colombieror 796219b2ee8SDavid du Colombier.CW beieeedftos 797219b2ee8SDavid du Colombierfor big-endian architectures. 798219b2ee8SDavid du Colombier.IP "\f(CWfoll\fP, \f(CWdas\fP, \f(CWhexinst\fP, and \f(CWinstsize\fP\ -\ " 799219b2ee8SDavid du ColombierThese fields point to functions that interpret machine 800219b2ee8SDavid du Colombierinstructions. 801219b2ee8SDavid du ColombierThey rely on disassembly of the instruction 802219b2ee8SDavid du Colombierand are unique to each architecture. 803219b2ee8SDavid du Colombier.CW Foll 804219b2ee8SDavid du Colombiercalculates the follow set of an instruction. 805219b2ee8SDavid du Colombier.CW Das 806219b2ee8SDavid du Colombierdisassembles a machine instruction to assembly language. 807219b2ee8SDavid du Colombier.CW Hexinst 808219b2ee8SDavid du Colombierformats a machine instruction as a text 809219b2ee8SDavid du Colombierstring of 810219b2ee8SDavid du Colombierhexadecimal digits. 811219b2ee8SDavid du Colombier.CW Instsize 812219b2ee8SDavid du Colombiercalculates the size in bytes, of an instruction. 813219b2ee8SDavid du ColombierOnce the disassembler is written, the other functions 814219b2ee8SDavid du Colombiercan usually be implemented as trivial extensions of it. 815219b2ee8SDavid du Colombier.LP 816219b2ee8SDavid du ColombierIt is possible to provide support for a new architecture 817219b2ee8SDavid du Colombierincrementally by filling the jump table entries 818219b2ee8SDavid du Colombierof the 819219b2ee8SDavid du Colombier.CW Machdata 820219b2ee8SDavid du Colombierstructure as code is written. In general, if 821219b2ee8SDavid du Colombiera jump table entry contains a zero, application 822219b2ee8SDavid du Colombierprograms requiring that function will issue an 823219b2ee8SDavid du Colombiererror message instead of attempting to 824219b2ee8SDavid du Colombiercall the function. For example, 825219b2ee8SDavid du Colombierthe 826219b2ee8SDavid du Colombier.CW foll , 827219b2ee8SDavid du Colombier.CW das , 828219b2ee8SDavid du Colombier.CW hexinst , 829219b2ee8SDavid du Colombierand 830219b2ee8SDavid du Colombier.CW instsize 831219b2ee8SDavid du Colombierjump table slots can be zeroed until a 832219b2ee8SDavid du Colombierdisassembler is written. 833219b2ee8SDavid du ColombierOther capabilities, such as 834219b2ee8SDavid du Colombierstack trace or variable inspection, 835219b2ee8SDavid du Colombiercan be supplied and will be available to 836219b2ee8SDavid du Colombierthe debuggers but attempts to use the 837219b2ee8SDavid du Colombierdisassembler will result in an error message. 838219b2ee8SDavid du Colombier.RE 839219b2ee8SDavid du Colombier.IP 6. 840219b2ee8SDavid du ColombierUpdate the table named 841219b2ee8SDavid du Colombier.CW machines 842219b2ee8SDavid du Colombiernear the beginning of 843219b2ee8SDavid du Colombier.CW /sys/src/libmach/setmach.c . 844219b2ee8SDavid du ColombierThis table binds the 845219b2ee8SDavid du Colombierfile type code and machine name to the 846219b2ee8SDavid du Colombier.CW Mach 847219b2ee8SDavid du Colombierand 848219b2ee8SDavid du Colombier.CW Machdata 849219b2ee8SDavid du Colombierstructures of an architecture. 850219b2ee8SDavid du ColombierThe names of the initialized 851219b2ee8SDavid du Colombier.CW Mach 852219b2ee8SDavid du Colombierand 853219b2ee8SDavid du Colombier.CW Machdata 854219b2ee8SDavid du Colombierstructures built in steps 2 and 5 855219b2ee8SDavid du Colombiermust be added to the list of 856219b2ee8SDavid du Colombierstructure definitions immediately 857219b2ee8SDavid du Colombierpreceding the table initialization. 858219b2ee8SDavid du ColombierIf both Plan 9 and 859219b2ee8SDavid du Colombiernative disassembly are supported, add 860219b2ee8SDavid du Colombieran entry for each disassembler to the table. The 861219b2ee8SDavid du Colombierentry for the default disassembler (usually 862219b2ee8SDavid du ColombierPlan 9) must be first. 863219b2ee8SDavid du Colombier.IP 7. 864219b2ee8SDavid du ColombierAdd an entry describing the architecture to 865219b2ee8SDavid du Colombierthe table named 866219b2ee8SDavid du Colombier.CW trans 867219b2ee8SDavid du Colombiernear the end of 868219b2ee8SDavid du Colombier.CW /sys/src/cmd/prof.c . 869219b2ee8SDavid du Colombier.RE 870219b2ee8SDavid du Colombier.IP 8. 871219b2ee8SDavid du ColombierAdd an entry describing the architecture to 872219b2ee8SDavid du Colombierthe table named 873219b2ee8SDavid du Colombier.CW objtype 874219b2ee8SDavid du Colombiernear the start of 875219b2ee8SDavid du Colombier.CW /sys/src/cmd/pcc.c . 876219b2ee8SDavid du Colombier.RE 877219b2ee8SDavid du Colombier.IP 9. 878219b2ee8SDavid du ColombierRecompile and install 879219b2ee8SDavid du Colombierall application programs that include header file 880219b2ee8SDavid du Colombier.CW mach.h 881219b2ee8SDavid du Colombierand load with 882219b2ee8SDavid du Colombier.CW libmach.a . 883