Your tasks
Read the document completely. Don’t just attempt to do the lab my reading the summary.
Summary
- Setup and test HCLRS as described below.
- To learn how to use HCLRS and the accompanying Y86 tools for future labs:
- Run the supplied
tiny.hclfile on a.yofile (Y86 program) - Assemble a
.ysinto a.yofile - Run the supplied Y86 simulator on a yo file
- Run the supplied
- Write a
pc.hclbased on the suppliedtiny.hclthat:- advances the PC properly for Y86 instructions that are not jumps, call, or ret,
- sets
StattoSTAT_INS(invalid instruction) for any unimplemented or unrecognizedicode.
- Test your
pc.hclusingmake test-pc(many automated tests) and/or by manually running it
on input files and comparing to the outputs shown below. On department machines, you will need to runmodule load python3beforemake test-pcwill work; on other machines, you will need python3 installed. - Submit your
pc.hclto kytos
Setup and test HCLRS
- Get a copy of the hclrs.tar from the hclrs README page.
- Build
hclrsand the accompanying Y86 tools withmake - Build the supplied example
tinysimulator and run it ony86/prog3.yowith./tools/hclrs tiny.hcl y86/prog3.yo -qThis should result in output like:
+----------------------- halted in state: ------------------------------+ | RAX: ffffffffffffd2b4 RCX: 0 RDX: 0 | | RBX: 0 RSP: 0 RBP: 0 | | RSI: 0 RDI: 0 R8: 0 | | R9: 0 R10: 0 R11: 0 | | R12: 0 R13: 0 R14: 0 | | register pP(N) { pc=0000000000000003 } | | used memory: _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f | | 0x0000000_: 30 f2 0a 00 00 00 00 00 00 00 30 f0 03 00 00 00 | | 0x0000001_: 00 00 00 00 10 60 20 00 | +--------------------- (end of halted state) ---------------------------+ Cycles run: 3showing the values of the built-in registers, memory, and the
pcregister declared
bytiny.hcl.
Assemble a .ys file into .yo file
- Create a file
toy.yswithirmovq $6552,%rdx rrmovq %rdx,%rax addq %rax,%rdx halt - Assemble
toy.ysintotoy.yousing the supplied assemblertools/yasmake toy.yoor
tools/yas toy.ys - Examine
toy.yoin a text editor
Use the yis Y86 simulator
tools/yisis a Y86 simulator you can use to see what.yofiles are supposed to do. For example
tools/yis toy.yoshould give:Stopped in 4 steps at PC = 0xe. Status 'HLT', CC Z=0 S=0 O=0 Changes to registers: %rax: 0x0000000000000000 0x0000000000001998 %rdx: 0x0000000000000000 0x0000000000003330 Changes to memory:The hclrs README provides more detail about inteprreting this output under the heading
“Seeing what a.yofile is supposed to do”.
Write pc.hcl
- Copy
tiny.hcltopc.hcl. Alternately, you can make an HCL file from scratch and with apcregister declared like intiny.hcl. - Edit
pc.hclso that the pc updates work in the case where there are not jump, call, or return statements. You’ll almost certainly want to consult the Y86-64 instruction set described in figure 4.2 (page 357) to do this.- If you started with
tiny.hcl, we won’t be needing to use the register file in this assignment, so remove the block of hcl that starts with the comment# let's also read and write a register… (but keep the line that updatesp_pc) - Have the hcl read each instruction and get it’s
icode(tiny.hcldoes this already) - Set the
Statoutput toSTAT_INS(invalid instruction error) if there is ajXX,call, orreticode; also toSTAT_INSfor any icode greater than 11 (unused icodes); toSTAT_HLTif there is ahalticode; and toSTAT_AOKfor all othericode.Intiny.hcl, there was already a lineStat = [that set theStatto eitherSTAT_AOKorSTAT_HLT. You’ll need to change it to also setSTAT_INSfor some icodes. - When parsing an icode use constants for the comparison. For example:
JXXorIRMOVQ.See the hclrs README for a complete list of constants. - Update the
p_pcto beP_pc +an appropriate offset (1, 2, 9, or 10, depending on theicode).There is a linep_pc = P_pc + 1;– you will need to change it so that uses a mux to select what number is added topc.
- If you started with
Testing pc.hcl manually
Here are some example outputs from running a command like
./tools/hclrs pc.hcl y86/FILE.yo -q
y86/prog1.yoshould give+----------------------- halted in state: ------------------------------+ | RAX: 0 RCX: 0 RDX: 0 | | RBX: 0 RSP: 0 RBP: 0 | | RSI: 0 RDI: 0 R8: 0 | | R9: 0 R10: 0 R11: 0 | | R12: 0 R13: 0 R14: 0 | | register pP(N) { pc=000000000000001a } | | used memory: _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f | | 0x0000000_: 30 f2 0a 00 00 00 00 00 00 00 30 f0 03 00 00 00 | | 0x0000001_: 00 00 00 00 10 10 10 60 20 00 | +--------------------- (end of halted state) ---------------------------+ Cycles run: 7y86/prog7.yoshould give+------------------- error caused in state: ----------------------------+ | RAX: 0 RCX: 0 RDX: 0 | | RBX: 0 RSP: 0 RBP: 0 | | RSI: 0 RDI: 0 R8: 0 | | R9: 0 R10: 0 R11: 0 | | R12: 0 R13: 0 R14: 0 | | register pP(N) { pc=000000000000000b } | | used memory: _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f | | 0x0000000_: 63 00 74 16 00 00 00 00 00 00 00 30 f0 01 00 00 | | 0x0000001_: 00 00 00 00 00 00 30 f2 02 00 00 00 00 00 00 00 | | 0x0000002_: 30 f3 03 00 00 00 00 00 00 00 00 | +-------------------- (end of error state) -----------------------------+ Cycles run: 2 Error code: 4 (Invalid Instruction)y86/poptest.yoshould give+----------------------- halted in state: ------------------------------+ | RAX: 0 RCX: 0 RDX: 0 | | RBX: 0 RSP: 0 RBP: 0 | | RSI: 0 RDI: 0 R8: 0 | | R9: 0 R10: 0 R11: 0 | | R12: 0 R13: 0 R14: 0 | | register pP(N) { pc=0000000000000019 } | | used memory: _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f | | 0x0000000_: 30 f4 00 01 00 00 00 00 00 00 30 f0 cd ab 00 00 | | 0x0000001_: 00 00 00 00 a0 0f b0 4f 00 | +--------------------- (end of halted state) ---------------------------+ Cycles run: 5- Other files. Look in the
testdata/pc-referencedirectory to see what our
output shows for each of the supplied.yofiles in they86directory.
The outputs in thetestdata/pc-referencedirectory omit the final
value of the PC register, but yourpc.hclshould match them in the
number of cycles run and error code (if any).
Testing pc.hcl using make test-pc
make test-pcwill runpc.hcland compare the results to a set of outputs
in thetestdata/pc-referencedirectory.- When a test fails, the testing program will display the difference between your
output and the expected output. This output is a bit hard to understand.
The hclrs README has a description of how to read it under the
heading “suplied testing scripts”.
Hints
tiny.hclhas many comments which may be helpful.