EECS 388 Laboratory

Welcome to EECS 388: Computer Systems and Assembly Language. In this class you will learn how computer systems are constructed and how to program those computer systems using assembly language. Learning will focus on internal microprocessor organization, programming in assembly language, performing input and output, and controlling external devices. The interaction of these four basic computing elements is at the core of effective embedded system design and is important knowledge in general purpose computing as well.

The laboratory for this class makes use of the Xilinxi XUPi development board pictured on the right. This development board is built around the Virtex-II Pro FPGAi. These FPGAsi are high-performance, high-density reconfigurable devices which students will use for system-on-chipi development. Students will use these devices and their associated development environments to develop fully functional embedded system designs which they will program using a combination of assembly language and C.

In addition to the FPGAi, the XUPi development boards contain many integrated peripherals which will be used by the students. Using peripherals such as serial ports, LEDs, push buttons, and switches, students will learn the basic mechanisms of I/O and external device control.

The system designs in this class will all make use of the MicroBlazei microprocessor; a 32-bit soft-processori core developed by Xilinxi for use in their FPGAsi. This processor is a simple but modern 3 or 5 stage pipelined microprocessor which is based on the DLXi architecture described by Patterson and Hennessy in their computer architecture book. The instruction set architecture (ISAi) of the MicroBlazei will be studied in depth and will be used by students in most of the laboratory exercises.

Students in this course should leave the class with knowledge of computer system design and assembly programming. Students should also leave with understanding of the basic relationships between high-level languages, assembly level programming, and hardware level system design.

Syllabus

Contact Information

Wesley Peck
2045 Eaton Hall
peckw@ittc.ku.edu
Cenk Sahin
2045 Eaton Hall
cenksahin@ku.edu
 

Lab Schedule

Tuesday
2:30 - 4:45 PM
3002 Eaton Hall
Wednesday
2:00 - 4:15 PM
3002 Eaton Hall
Thursday
2:30 - 4:45 PM
3002 Eaton Hall
 

Office Hours

Wesley Peck
Tuesday
12:00 - 2:30 PM
2045 Eaton Hall
Wesley Peck
Wednesday
12:00 - 2:00 PM
2045 Eaton Hall
Cenk Sahin
Tuesday
2:30 - 4:30 PM
3002 Eaton Hall
 

Reference Materials

In addition to the reading materials required in the lecture, the laboratory part of this class will require the use of many of the reference documents provided by Xilinxi for their products. These reference materials give details information on the design of Xilinxi hardware components and will be invaluable to completing the projects in this class. A list of interesting reference materials can be found on the website on the Reference Materials page.

Expectations

During this course students will be expected to learn basic concepts in computer systems design and assembly level programming. This course is FPGAi based and makes use of the Xilinxi XUPi development board. As such, students will learn to be proficient with the Xilinxi development environment and Xilinxi FPGAsi. By the end of the course students will be expected to design and program simple embedded systems using these tools.

This is not an introductory level course. While the TAs in your class are more than happy to answer your questions, they will not do your projects for you. This means that they will help you to understand the general concepts in the class, they will help you with problems that you encounter with the Xilinxi tools, and they will help you debug and fix specific problems in your project. They will not, however, repeat lectures for students that missed class or answer questions which are general or vague, such as "What is wrong with my code?". As an upper-level course, you are expected to work outside of class on your project and come to class prepared with questions.

Grading

Students are also expected to demonstrate their working designs on the due date for the given laboratory. Demonstrations are done in class with your TA and they must be completed by the end of that lab. If you fail to demonstrate your project by the due date you can demonstrate your project the next laboratory period for a 25% penalty. Laboratory projects will receive a grade of 0% if they are more than one week late. There are no exceptions to these rules unless you have received special permission from your TA before the due date.

In addition to the in-class demonstration, students will be expected to turn in a project report for every laboratory. These project reports should follow the guidelines established in the Project Reports documentation. These project reports are worth 25% of your overall project score and will be graded thoroughly. If you fail to turn in a report for your project you will be penalized 50% on your overall project score. Project reports along with all other laboratory submission materials are due Friday on the week that the project is demonstrated to your TA.

Grading Disputes

Questions about grading and grading disputes will not be answered during the laboratory period. If you have a question about your grade or think that you deserve more points then you should visit your TA during their office hours. If you feel that you deserve more points on your grade then you must demonstrate to your TA exactly why you deserve more points. Vague requests for more points will not be successful. Additionally, the TAs reserve the following rights when reassessing a grade:

  1. The entire project or homework will be regraded, not just the problem which you feel you deserve more points on. This means that you could lose or gain points on any problem.
  2. If you compare your work to another student's work then both student's will have their work regraded. This means that your friend could lose points on their work if we graded it incorrectly the first time.
  3. Grades will not be reassessed more than two weeks after they are returned. Do not try to get more points on all of your projects and homeworks at the end of the semester, it will not work.

 

Deliverables

For each laboratory project in this class you will be required to demonstrate a working design on the due date in class and turn in your project materials to the TA by Friday on the week that the project was demonstrated. Thus, the deliverables for each laboratory is the following:

  1. Demonstration of a working design
    At the end of your laboratory period during the week in which the project is due students will demonstrate a working design to their TA. This demonstration will account for the majority of your grade for the project, 65%. The quality of a students solution will be a factor in the student's grade as well as the correctness. A project which is correct technically but is of poor quality will lose points.
     
  2. Project system design files
    Each project in this class will require students to design and implement a system-on-chipi design using the Xilinxi development environment. Students will submit these design files as part of their projects. Each design must have the names of all the students who contributed to the design. The project design is worth 5% of your project grade with points determined largely by how well the design is commented.
     
  3. Project source code
    Most projects in this class will require that the student develop a program in C or assembly language to control their system-on-chipi design. Students will submit these source files as part of their projects. Each source code file must be thoroughly documented and must include the names of all students which contributed to the source code. The project source code is worth 5% of your project grade with points determined largely by how well the source code is commented.
     
  4. Project report
    The report for each lab is due by Friday on the week that the project is demonstrated to your TA. Each report must follow the guidelines established in the project report format. Failure to do so will result in a loss of points. The project reports are worth 25% of the overall project grade.

Project materials must be submitted to your TA in electronic format, including the project report. Project reports must be submitted as either a Word Document or as a PDF. All project materials must be submitted to your TA in a single zip file. Project submissions which consist of multiple files or submissions which are not in zip format will not be accepted. Additionally, your project submission must follow these guidelines:

  1. Project submission file name
    Projects submissions to your TA must be named "lab<number>_<lastname>.zip". For instance lab0_peckw.zip or lab3_sahin.zip are both valid names for submission to your TA. File names such as lab0.zip, wesley.zip, or lab0_peckw.7z are not valid and will not be accepted. Failure to use a valid name for your project submissions will result in a loss of points.
     
  2. Project submission directory structure
    The zip file that you submit for your project should contain a directory named "design" which contains your project's system-on-chipi design files, a directory named "source" which contains your project's source files, and a file named "<lastname>.pdf " or "<lastname>.doc" which should be your project report. Failure to follow these guidelines may result in a loss of points. As an example, your zip file should look like the following:
    • lab0_peckw.zip
      • design
        • system.mhs
        • system.mss
        • system.xmp
        • ...
      • source
        • lab0.c
        • lab0.S
        • ...
      • peckw.pdf

Additionally, please clean up your system-on-chipi design before submitting them to your TA as instructed in laboratory 1. In the past failure to perform this step has resulted in projects not be received correctly by the TAs due to limitations of email.

Report Format

Each laboratory project requires the submission of a report along with the design and source files. Every report should contain all of the information described below. Failure to include any of this information will result in a loss of points.

Abstract

This section should contain one short paragraph which summarizes the work that your performed for the laboratory and describes the results that you ended with. The abstract should be no more than five to ten sentences but should still be informative.

Introduction

This section should contain several paragraphs which discuss any background information which is pertinent to the laboratory. Additionally, it should describe what the purpose of the laboratory was and what the expected results of the laboratory are. Diagrams should be used to illustrate the system-on-chipi and software designs. Ensure that all diagrams are correctly labeled.

Design and Implementation

This section section should contain many paragraphs which describe the system that was designed and implemented. You should detail exactly what was built as part of the laboratory, how it was built, and why it was built. Block diagrams, figures, source code, and screen shots are all highly effective and consise ways of communicating your design and implementation.

Results

This section should contain several paragraphs which describe the results of the laboratory. Describe the functionality of the resulting design and discuss how well your design and implementation solved the original problem. Provide any useful system metrics such as the amount of code or the amount of time which was required to solve the problem. Also be sure to mention any problems which were encountered during your design and implementation.

Question Answers

This section should contain the answers to all of the questions which are part of the laboratory. The length of your answer is dependent on the question being asked, however, generally speaking answers should be between two sentences and two paragraphs. Answers should get to the core of the question without being overly verbose.

Conclusion

This section should contain one or two paragraphs which finish the report. Reiterate the original problem and quickly reason about how and why your design and implementation solve the problem. Provide any insight you might have about possible future work related to the project and provide any interesting extensions to the project that could be explored.

References

This section should list all of the reference material which was used during your design and implementation. As engineers you are accountable for your actions and reports. Providing references establishes credibility as to the design and provides a path of reasoning for you decisions and ideas. References should be cited in your report using the appropriate reference number as show below:

...
...
The Hthreads operating system established the effectiveness of hardware components in operating system design [1].
...
...

[1] J. Agron, W. Peck, E. Anderson, D. Andrews, E. Komp, R. Sass, F. Baijot, and J. Stevens, “Run-Time Services for Hybrid CPU/FPGAi Systems On Chip,” in Proceedings of the 27th IEEE International Real-Time Systems Symposium (RTSS), December 2006.

[2] MicroBlazei Processor Reference Guide - http://www.xilinx.com/ise/embedded/mb_ref_guide.pdf.

Reference Materials

Xilinxi MicroBlazei Reference

The MicroBlazei reference guide is invaluable for anyone making use of the microprocessor. The reference guide contains a detailed description of the MicroBlazei architecture including information about the register set, pipelining, memory systems, and data types. The guide also contains a comprehensive list of all instructions supports by the MicroBlazei ISAi.

MicroBlaze Reference Guide

Xilinxi GPIOi Reference

The GPIOi reference guide describes the hardware specifications for the OPB GPIOi peripheral. The Xilinxi GPIOi peripheral is a design time configurable general purpose I/O device which gives software the ability to inspect and control wires within the FPGAi. This is done through a register set which is exposed by the GPIOi peripheral as a memory mapped region on the OPB bus. Software is able to read and write to this register set using standard load and store operations from the processors ISAi.

GPIO Reference Guide

Xilinxi Interrupt Controller Reference

The Xilinxi interrupt controller reference guide describes the hardware specifications for the OPB INTC peripheral. This peripheral is a design-time configurable programmable interrupt controller. Modern processors are only capable of responding to one or two difference external interrupt sources. The programmable interrupt controller is a hardware peripheral which give more flexibility to system-on-chipi designers by taking an arbitrary number of interrupts sources and condensing them into a single interrupt source, the PIC itself. The PIC then exposes, as registers, the original sources of the interrupts. Thus, software is able to respond to an arbitrary number of interrupt sources by examining the PIC registers.

Interrupt Controller Reference Guide

Laboratory 1

In laboratory 1 you will design a system-on-chipi using the Xilinxi development suite and targeted at the XUPi development board. Your design will contain a MicroBlazei soft-processori, a serial port, and three GPIOi devices. The processor will be connected to the serial port and GPIOi peripherals in a shared-bus architecture. You will then program this system-on-chipi, using the C programming language, to print out your name five times to the screen of a desktop computer which is connected to the XUPi development board using the serial port.

In this laboratory your system-on-chipi design will consist of three major components:

  1. A MicroBlazei soft-processori
    The MicroBlazei will be the processor in your system-on-chipi design. The program that you design in this laboratory will be compiled to the MicroBlazei ISAi and then executed by the processor that you instantiate within your design. Compilation is done inside of the Xilinxi development suite and makes use of the GCC compiler contained within.
     
  2. A serial port
    The serial port in this system-on-chipi design provides communication between the XUPi development board and the desktop computer connected to it. In this laboratory your program will print out a message by sending characters one at a time from the XUPi to the desktop computer. These characters will be received on the desktop computer and printed out to the screen.
     
  3. Three GPIOi devices
    The three GPIOi devices in your system-on-chipi design will control the LEDi, push button, and DIP switch peripherals contained on the XUPi development board. In this laboratory these hardware peripherals will not be used by the software program, however, in future laboratories these peripherals will be used and it is beneficial to learn how to instantiate them in your system-on-chipi design.

Before you begin this laboratory we suggest that you become familiar with the Xilinxi development suite. Please read the Introduction to EDK, Base System Builder, and XPS Interface tutorials before you begin. 

Project Assignment

  1. Use the base system builder to create a basic system-on-chipi
  2. Create a software project and make it print out your name five times
  3. Synthesize your system-on-chipi, compile your software project, and combine them into a bitstream
  4. Download your bitstream onto the XUPi development board and execute it

This may not seem like much, but, at the end of this laboratory you will have created a system-on-chipi and executed a program on top of it in a bare metal environment. This represents a very basic but fully functional embedded system.

Project Directions

The directions for completing this project can be found on the Laboratory 1 Directions page. This page contains step-by-step directions on how to build your system-on-chipi design and software application. Additionally, there is a screencast of the entire project which shows how the project is completed.

It will be to your benefit to either print out the project directions or to have the project directions page open while you are doing this laboratory.

Project Questions

  1. What is an FPGAi?
  2. What is a system-on-chipi? Why is it different from your desktop computer system?
  3. What does soft-core IP mean?
  4. What is are MHS, MSS, and UCF files?
  5. What does it mean to cross-compile a program?
  6. Why does it take so long to build the HW portion of your system?
  7. How does the desktop computer program the FPGAi, how does it monitor the FPGAi?

Directions

[video file=/sites/default/files/video/lab1.flv]
Lab 1 Screen Cast
Click to Play

Creating a new Project

  1. Open the Xilinxi Platform Studio Application (XPS)
    • Start -> All Programs -> Xilinxi Platform Studio 9.1i -> Xilinxi Platform Studio
  2. Select "Base System Builder wizard"
    • Then Click OK
  3. Enter "H:\eecs388\lab1\system.xmp" as the project file
    • Then click OK
    • Select "Yes" to create the folder if necessary
  4. Select "I would like to create a new design"
    • Then click Next
  5. Select "I would like to create a system for the following development board"
    • Select "Xilinxi" as the board vendor
    • Select "XUPi Virtex-II Pro Development System" as the board name
    • Select "C" as the board revision
    • Then click on Next
  6. Select "MicroBlazei"
    • Then click on Next
  7. Use "100MHz" as the processor frequency
    • Use "On-chip HW debug module"
    • Select "64KB" for the data and instruction size
    • Then click on Next
  8. Enable "RS232_Uart_1"
    • Use "OPB UARTLITE" at the peripheral
    • Use 9600 as the baud rate
    • Use 8 as the data bits value
    • Use NONE as the parity
    • Ensure that interrupts are not enabled
    • Ensure "Ethernet_MAC" is unselected
    • Ensure "SysAce_CompactFlash" is unselected
    • Then click on Next
  9. Enable LEDs_4Bit, DIPSWs_4Bit, and PushButtons_5Bit
    • Use OPB GPIOi for all of them
    • Ensure interrupts are not enabled for all of them
    • Ensure DDR_512MB_64Mx64_rank2_row13_col10_cl2_5 is not enabled
    • Ensure DDR_512MB_64Mx64_rank1_row13_col11_cl2_5 is not enabled
    • Then click on Next
  10. Ensure DDR_256MB_32Mx64_rank1_row13_col1_cl2_5 is not enabled
    • Ensure DDR_128MB_16Mx64_rank1_row13_col9_cl2_5 is not enabled
    • Then click on Next
  11. Ensure there are no other peripherals listed
    • Then click on Next
  12. Ensure STDIN is RS232_Uart_1
    • Ensure STDOUT is RS232_Uart_1
    • Ensure boot memory is ilmb_cntlr
    • Ensure Memory test is enabled
    • Ensure Peripheral self test is enabled
    • Then click on Next
  13. Ensure that ilmb_cntrl is the intruction memory
    • Ensure that dlmb_cntlr is the data, stack, and heap memory
    • Then click on Next
  14. Ensure that ilmb_cntrl is the instruction memory
    • Ensure that dlmb_cntlr is the data, stack, and heap memory
    • Then click on Next
  15. Look over the information screen
    • Click on Generate to create your system
  16. Ensure "Save settings file" is selected
    • Click on Finish

Adding the Software Application

  1. Ensure that the Applications tab is active in the Project Information Area on the left of the window
  2. Double click on "Add Software Application Project..."
  3. In the Software Application Project dialog enter "lab1" as the name
    • Ensure microblaze_0 is selected as the processor
    • Ensure "Project is an ELF-only Project" is not selected
    • Click on OK
  4. Locate "Project: lab1" in the software application list
    • Right click on "sources" and select "Add new file"
    • Create a new folder named "lab1" in the file dialog
    • Enter the lab1 folder
    • Enter lab1.c as the file name
    • Click save
  5. Click on the "+" next to "sources"
    • Double click on lab1.c
    • Enter the following into the source file

      /* <comments with your name and KUID> */
      /* <comments with a description of this source file> */

      #include <stdio.h>
      int main(void)
      {
          <your code here>
          return 0;
      }
       

    • Fill in the main function to print out your name and KUID five times
    • Hint: the printf function and a for loop would be useful for this
  6. Right click on "Project: lab1" and select "Mark to initialize BRAMs"
    • Right click on "Project: TestApp_Memory" and click on "Mark to initialize BRAMs" to unselect it

Testing the Design

  1. Select "Update Bitstream" to synthesize your hardware and compile your software
    • Menu: Device Configuration -> Update Bitstream
    • This takes a while
  2. Open up HyperTerminal
    • Menu: Start -> All Programs -> Accessories -> Communications -> HyperTerminal
    • Enter an area code if needed and click on OK until you have the main window
    • Create a new connection using COM1, a 9600 baud rate, 8 data bits, 1 stop bit, no parity, and no flow control
  3. Select "Download Bitstream" to download your design to the board for execution
    • Menu: Device Configuration -> Download Bitstream
    • This takes a while
  4. You should see you name output in the HyperTerminal window that you opened

Cleaning up for Submission

Before you submit a project to your TA you will need to clean out all of the XPS generated files. You can do this by selecting "Project -> Clean All Generated Files" from the menu. Please do this before submitting all projects.

Laboratory 2

In laboratory 2 you will design a system-on-chipi which includes one Microblaze soft-processori and several General Purpose I/O peripherals (GPIOs). Just like laboratory 1, the system-on-chipi will be created using the Base System Builder supplied by the Xilinxi tool suite. Once your system-on-chipi has been created, you will write a custom software application to take input from the push button and produce output on the LEDs. In order to complete this laboratory successfully, you will need to understand the workings of the GPIOi peripheral by reading the GPIOi reference manual which can be found in the references section.

Project Assignment

  1. Create a system-on-chipi design which includes only the following components:
    • A Microblaze soft-processori
    • A serial port for debug output
    • A GPIOi for the LEDs
    • A GPIOi for the Push Buttons
  2. Create a new software application which performs the following:
    • When the left push button is depressed the left most LEDi is lit
    • When the top push button is depressed the second from the left LEDi is lit
    • When the bottom push button is depressed the second from the right LEDi is lit
    • When the right push button is depressed the right most LEDi is lit
    • When the center push button is depressed all LEDs are lit
  3. Synthesize your system-on-chipi, compile your software project, and combine them into a bitstream
  4. Download your bitstream onto the XUPi development board, execute it, and demonstrate your design to your TA

This project will be a due during the week of September 8, 2008 through September 12, 2008. Please allocate enough time outside of class to read and understand the project and the workings of the GPIOi.

Project Directions

Before proceeding with this laboratory please read at least the OPB GPIOi Registers and OPB  GPIOi Operation sections of the GPIOi reference manual. In future labs is will be your responsibility to implement application software to control an FPGAi peripheral. In this lab you will be expected to understand how the provided software application implements the operational specification provided by the reference manual.

[video file=/sites/default/files/video/lab2.flv]
Lab 2 Screen Cast
Click to Play

For this laboratory you will be creating a system-on-chipi design, containing the peripherals mentioned above, using the BSB as described in laboratory 1. Once you have the system-on-chipi design created you will need to create a new software application named "lab2" which contains one source code file named "lab2.c". After this, copy and paste the source code template into your source file.

Read the comments in the source code template and try to understand how the source code provided implements the GPIOi hardware protocol described in the GPIOi reference manual. Once you understand what the source code template is doing, modify the main function to implement the project requirements described in the project assignment given above.

Project Questions

Answers to the questions for this laboratory can be found in either the Memory-Mapped I/O Tutorial or the GPIO reference manual.

  1. What register set is exposed by the GPIOi peripheral? Describe each register.
  2. What is an address space?
  3. What is memory-mapped I/O?
  4. How does a processor perform memory-mapped I/O?
  5. How does software perform memory-mapped I/O?
  6. What steps does software need to perform in order to read from the GPIOi data register? Explain each step.

 

Laboratory 3

In laboratory 3 you will design a system-on-chipi which includes one Microblaze soft-processori, several IP cores, and an OPB bus which connects all of the components in the system. Like the previous laboratories, you will be using the Xilinxi BSB wizard to create a basic hardware design for your system. Unlike previous laboratories, however, you will be modifying the basic design by adding a custom peripheral. This custom peripheral, which will be provided for you, performs 128-bit encryption and decryption using the Blowfish algorithm. Using this Blowfish hardware peripheral, you will design and implement a software application which will encrypt and decrypt data. Additionally, your software will be responsible for retrieving data from a host computer using the RS-232 serial port.

Project Assignment

  1. Create a system-on-chipi design which includes the following components:
    • A Microblaze soft-processori
    • A serial port for debug output
  2. Add the custom blowfish hardware core to your system-on-chipi
    • Download the hardware design
    • Unzip the design into the "pcores" directory inside of your project
    • Add the "OPB_BLOWFISH" hardware core to your system
    • Assign a base address to the blowfish core
  3. Create a software application which performs the following
    • Read a pass phrase using the serial port and use it to initialize the hardware encryption key
    • Read input from the serial port and store it in an array
    • Encrypt the data input from the serial port and print the encrypted array
    • Decrypt the encrypted data and print the decrypted array
    • Continue reading input, encrypting, and decrypting in an infinite loop
  4. Synthesize your system-on-chipi, compile your software project, and combine them into a bitstream
  5. Download your bitstream onto the XUPi development board, execute it, and demonstrate your design to your TA

The due date for this project will be the week of September 29, 2008 through October 3, 2008. The project reports will be due on Friday, October 3, 2008. Ensure that you demonstrate your project to your TA during your laboratory period and turn in your complete project submission, including the project report, by the Friday due date.

Project Directions: First Week

For the first week of this laboratory you should concentrate on getting a basic "read-eval-print" loop working. To accomplish this you will first need to get a basic system-on-chipi design working using the BSB. Refer to laboratory 1 if you do not remember how to use the BSB. At this point, do not worry about adding the custom blowfish encryption core. All you will need is a Microblaze processor and a RS-232 serial port for communicating with the host computer.

Once you have created, downloaded and tested your hardware design you should build a basic skeleton for the software. The software for this laboratory should consist of two basic phases: initialization and a "read-eval-print" loop. In the initialization phase you will read in a 128-bit pass phrase to use for encryption/decryption. In the "read-eval-print" loop you will read in a string, encrypt that string, decrypt the encrypted string, and then print the original, encrypted, and decrypted strings. For the first week, just get the reading and printing working for skeleton application. We will learn how to encrypt and decrypt with the blowfish hardware next week.

There are two special things to note about the software for this laboratory. First, for this laboratory we would like you to use the low-level function inbyte() to read values from the serial port. This function, which has the signature "char inbyte()", will read a single character from the serial port and return it to the caller. You should make wrapper functions for inbyte() as necessary. For instance, it would be wise to write a wrapper function which reads in a 128-bit string one character at a time using the inbyte() function.

The second special thing to note is that the blowfish hardware requires data in 64-bit blocks. The software, however, will be reading input strings to encrypt and decrypt 8-bits at a time. Thus, it will be necessary for you to pad input strings to be a multiple of 64-bits by appending 0's as necessary. For instance, if the user enters "encryptthis" as the content to encrypt then the input string will be 88-bits which is not a multiple of 64-bits. In this case your software will need to append 40-bits of zero to the input string before encrypting and decrypting. You can do this in any way that is convenient for your design.

For this project you do not need to do any sort of dynamic memory management. It is fine for your software to limit the size of the user input to some maximum value. This way you can simply use statically declared arrays for reading input data and storing encrypted and decrypted values. We advise that doing this will substantially reduce the complexity of your software.

Project Directions: Second Week

[video file=/sites/default/files/video/lab3.flv]

Adding Blowfish Hardware
Click to Play

For the second week of this project you will be adding a custom Blowfish encryption hardware core to the basic system-on-chipi design that you created during the first week. You will then be modifying the "read-eval-print" loop that you created during the first week to add support for performing encryption. To begin this project you will need to download the Blowfish Encryption Hardware. Once you have this file downloaded, you will need to unzip the file into the "pcores" directory inside of your existing system-on-chipi design. For instance, if your system-on-chipi design is located in the directory "H:\eecs388\lab3" then you will unzip the Blowfish encryption hardware into the directory "H:\eecs388\lab3\pcores" (this directory should already exist).

Once you have done this, the Blowfish hardware will be available for addition to your design. First, open up your existing system-on-chipi design. Once the design is open, click on the "IP Catalog" button in the upper left quadrant of the XPS window; also ensure that the "System Assembly View" tab is selected near the middle of the window. In the "IP Catalog" panel you should see a entry named "Project Local Pcores". Click on the plus sign next to this entry and then double click on "OPB_BLOWFISH" to add the Blowfish hardware to your design. You now need to attach the Blowfish hardware to the sytem bus. Do this by looking in the main window for the "opb_blowfish_0" entry. If you do not see this entry then ensure that "Bus Interface" is the selected filter near the top middle of the window. Click on the plus sign next to the "opb_blowfish_0" entry. You should see a green line extending out to the left from the entry and connecting to another line which goes up to the label "OPB". The empty bubble at the intersection of the two lines indicates that the "opb_blowfish_0" core is not yet connected to the OPB bus. Clicking on the bubble will connect it to the bus and fill in the bubble to indicate that the core is now connected to the bus.

Once the Blowfish hardware is connected to the bus, you will need to assign an address space to it. Click on the "Addresses" filter in the top middle of the screen to view the current system memory-map. Locate the entry for "opb_blowfish_0" and give it a "base address", typically "0x42000000" will be an available address. Once the base address had been selected you can click on the "Size" drop down menu and select the size of the address space, typically 64K is a good value. Doing this will automatically setup the "high address" for you. Note: Instead of doing this manually each time you can also simply click on the "Generate Addresses" button near the top middle of the screen. This will let the tools automatically create a memory-map for you.

At this point your system-on-chipi design for this lab should be complete. The only remaining step is to control the Blowfish encryption hardware from your software design in order to encrypt and decrypt data with it. In this laboratory you will need to write your own software from scratch to do this.

The register set for the Blowfish hardware is show in the picture to the right. There are nine 32-bit memory-mapped registers which are organized into four logical registers. The following describes the registers:

  1. Control Register
    This is a write-only 32-bit register located at offset +0 from the base address. Writing the value 0x00000000 to the control register will initialize the hardware with the encryption key stored in the key register. Writing 0x00000001 will encrypt the value in the data register and store the outcome in the results register. Likewise, writing 0x00000002 wil decrypt the value in the data register and store the outcome in the results register.
     
  2. Data Register
    This is a logical 64-bit read/write register located at offset +4 and +8 from the base address. The register is composed of two 32-bit registers allowing 32-bit processors access to the 64-bit data one DWORD at a time. The high 32-bits of the data is stored at offset +4 while the low 32-bits of the data is stored at offset +8. The data register is used to store the data to operate on before either the encrypt or the decrypt command is written to the control register.
     
  3. Key Register
    This is a logical 128-bit read/write register located at offsets +12, +16, +20, and +24 from the base address. The operation of this register is the same as the data register with the highest 32-bits located at offset +12 and the lowest 32-bits located at offset +24. The key register is used to store the encryption / decryption key before the initialize key command is written to the control register.
     
  4. Results Register
    This is a logical 64-bit read/write register located at offset +28 and +32 from the base address. This register operates similarly to the data register with the high 32-bits located at offset +28 and the low 32-bits located at offset +32. The results register is used to store either the encrypted outcome when the encrypt command is written to the control register or the decrypted outcome when the decrypt command is written to the control register. 

The Blowfish encryption core supports three operations: initializing the key, encrypting data, and decrypting data. All of these operations are controlled by the software through the control register in the hardware. The software steps required to interact with the Blowfish hardware are described below:

To complete this project sucessfully you will need to read in a 128-bit key from the serial port and then initialize the Blowfish hardware using the key. Once the hardware has been initialized, you will then encrypt and decrypt additional data read in from the serial port using the Blowfish hardware. Data input, encryption and decryption should be performed infinitely while your application is running. Additionally, your application should output the original input data, the encrypted data, and the decrypted data every time new input is read and encrypted / decrypted. To get full points on this project the original input data and decrypted data must be the same.

Project Questions

  1. What register set is exposed by the blowfish encryption peripheral? Describe each register.
  2. How do values get read by the software from the host computer which is attached to the FPGAi? Describe the necessary hardware, the FPGAi side software mechanisms, and the required software on the host computer.
  3. Describe the steps required to initialize the Blowfish hardware key.
  4. Describe the steps required to encrypt or decrypt a 64-bit data block using the Blowfish hardware.
  5. Describe any additional steps needed when encrypting variable length byte arrays with the Blowfish hardware.

Laboratory 4

In laboratory 4 you will be using your system-on-chipi design from laboratory 3. In laboratory 3 you were required to write a C program which encrypted 64-bit data blocks using the OPB BlowFish hardware which was provided to you. In this laboratory you will be rewriting your C program in Microblaze assembly. Like in laboratory 3, at the end of this laboratory you should have a system-on-chipi design which is capable of encrypting and decrypting 64-bit data blocks with a 128-bit encryption key. The encryption and decryption itself is performed by the hardware.

Project Directions

The basic project directions for this laboratory are the same as for laboratory 3. For the hardware part of the lab you can simply reuse your existing design from laboratory 3. You can also use the laboratory 3 solution provided by your TA. For this laboratory you will need to create another software application using the Xilinxi tools and then implement that software application in MicroBlazei assembly. The MicroBlaze Assembly Tutorials provide a lot of useful and practical information and reading them will be invaluable towards completing this project. Additionally, the MicroBlaze Reference provides detailed information about all of the instructions supported by the MicroBlazei processor.

The steps required to complete this project are as follows:

  1. Make a copy of your laboratory 3 project or the reference solution provided by the TA
  2. Open the copy using Xilinxi Platform Studio
  3. Create a new software application
  4. Add a new source file named "lab4.S" to the software application
    The actual file name "lab4" is not important, you can name the file anything you like. However, the file must have ".S" (a capital S) as the file extension to indicate that it is an assembly file.
  5. Create a subroutine named "readline" in assembly
    The readline subroutine will be used to read a line of input from the serial port into an array of bytes. Your read line routine should take as parameters a pointer to an array to fill with the data, an unsigned integer specifying the maximum number of bytes to read from the serial port, and a pointer to a string. The subroutine should then print out the string by calling the "xil_printf" C function. Afterward, the program should read input from the serial port until either the maximum number of bytes has been read or the user pressed the return key.
  6. Create a subroutine named "printline" in assembly
    The printline subroutine should take the same three parameters as the readline subroutine: an array pointer, the maximum bytes to output, and a string. The subroutine should first print out the string by calling the C function "xil_printf". After that the subroutine should print out the data in the array using the C function "xil_printf" until the maximum number of bytes to output has been reached.
  7. Create a subroutine named "setkey" in assembly
    The setkey subroutine should take a single parameters: a pointer to a 128-bit (16 byte) array of data. The subroutine should initialize the Blowfish hardware with this key in the same way as the hardware was initialized in laboratory 3.
  8. Create a subroutine named "processblock" in assembly
    The processblock subroutine should take two parameters: a pointer to a 64-bit (8 byte) array of data and an integer indicating whether encryption or decryption should be performed. The processblock routine should then place the data into the hardware registers, encrypt or decrypt the data, read the results out, and then place the results back into the data array.
  9. Create a subroutine named "process" in assembly
    The process subroutine should take four parameters: a pointer to an array of data, a pointer to an array of resulting data, an unsigned integer specifying the number of bytes to encrypt, and an unsigned integer which indicated encryption or decryption. The process subroutine will then need to encrypt or decrypt the contents of the data array, placing the results into the result array. The contents of the data array should not be changed during the encryption and decryption process. This subroutine should invoke processblock as part of its operation.
  10. Create a subroutine named "main" in assembly
    The main subroutine is the entry point of your program. The basic steps for successful completion of this project are the same as in laboratory 3. First, you should read a 128-bit key from the serial port using your readline subroutine and then initialize the hardware using that key with your setkey subroutine. Then you will, in an infinite loop, read up to 64-bytes of data from the serial port using your readline subroutine and encrypt that data using your process subroutine. After that you will decrypt the encrypted data, again using your process subroutine. Lastly, your will print your original data, the encrypted data, and the decrypted data using your printline subroutine.

Project Questions

  1. How is a C style string declared and initialized in MicroBlazei assembly?
  2. How are C style arrays declared in MicroBlazei assembly?

Laboratory 5

In laboratory 5 you will be creating a simple, interrupt-based system-on-chipi design. You will be instantiating three GPIOi devices in your system-on-chipi design and will write software which will respond to interrupts generated by those GPIOi devices. The software that you write for this laboratory will be a mixture of high-level C code and low-level assembly. Additionally, you will make use of some Xilinxi provided low-level interrupt routines. Reading and understanding the interrupt handling tutorial will help you complete this project.

Project Description

This purpose of this project is two fold. First, students should learn how to use functions written in assembly in C programs and how to use functions written in C in assembly programs. Second, students should learn how hardware interrupts are handled at the processor level, the assembly level, and the C level. Additionally, the software developed in this laboratory project should demonstrate how a running program can be interrupted by the processor so that another function can be executed. Because interrupts represent asynchronous, non-standard control flow in software programs the description of this project is complex, however, the developed software should be relatively simple.

The software for this project should consist of at least six functions. You are required to have these six functions in your demonstrated project. First, you should have a main function which enables interrupts in the system and then calls the main_loop function. The main_loop function should infinitely loop. Each loop should prompt the user for two numbers using the serial port, add the two numbers together, and then print out all of the prime numbers less than the result. This represents the main processing of the application.

You will also have four functions which perform auxiliary processing when interrupts occur. The first function should be intr_handler. This function, which should be written in assembly, will need to query the programmable interrupt controller to determine what interrupt occurs. If the interrupt was from the DIPSW GPIOi then the function handle_dipsw should be called and if the interrupt was from the push button GPIOi then the function handle_pb should be called. These two functions should be written in C and should perform the processing described below. The last function you will write is the write_leds functions, which should be written in assembly. This function will be used by the handle_dipsw and handle_pb functions and it used to illuminate certain LEDs.

Project Directions

  1. Create a system-on-chipi design using the BSB wizard
    Your system-on-chipi design needs to include a MicroBlazei soft-processori and RS-232 Serial port as is standard for the designs in this class. Additionally, for this project you should include the LEDi, DIPSW, and Push Button GPIOs. When enabling these devices make sure to select the "Use Interrupt" option. Otherwise your system will not include the necessary programmable interrupt controller (PIC).
  2. Write your high-level C functions
    Your high-level C function will comprise most of the software for this project. Any functionality you need for this project, except the functionality explicitly mentioned in the low-level assembly functions, can be code in C. You will most likely need to read the GPIOi and interrupt controller reference manuals to figure out exactly how to enable interrupts on the system. These manuals can be found in the reference materials. At a minimum you will need to do the following:
    1. Write your main function
      • Register your assembly level interrupt handler using the Xilinxi libraries
      • Enable interrupts on all of the GPIOi devices
      • Enable interrupts on the programmable interrupt controller
      • Enable interrupts on the MicroBlazei soft-processori.
    2. Write the handle_dipsw function
      • If the left-most switch is active then light the left-most LEDi
      • If the second-to-left switch is active then light the second-to-left LEDi
      • If the second-to-right switch is active then light the second-to-right LEDi
      • If the right-most switch is active then light the right-most LEDi
    3. Write the handle_pb function
      • If the up or right button is pressed then shift the LEDs to the right
      • If the down or left button is pressed then shift the LEDs to the left
      • If the middle button is pressed then restore the LEDs to the state of the DIPSWs
    4. Write the main_loop function
      • Prompt the user to enter two numbers using the serial port
      • Add the two number together
      • Print out all of the prime numbers less than the addition result
  3. Write your low-level assembly functions
    For this project you will be writing two assembly level functions. The first function will be your low-level interrupt handler. This function should be called intr_handler and it should be a function with no parameters and no return value. The function itself will need to examine the programmable interrupt controller and determine which interrupt occurred. If the interrupt was from the DIPSW peripheral then you will need to call the C function handle_dipsw. If the interrupt was from the push button peripheral then you will need to call the C function handle_pb. If the interrupt was from neither of these two sources then your system has not been properly configured as you should be masking out any unimportant interrupts.

    The second function that you will write in assembly will be a function called write_leds. This function should be a function of two parameters. The first parameter should be the base address of the LEDi GPIOi and the second parameter should be an unsigned integer value which indicates which light on the LEDi to illuminate. This function must be called by your handle_dipsw and handle_pb C functions.

  4. Synthesize your system-on-chipi design, compile your software, and combine them into a bitstream.
  5. Download your bitstream onto the XUPi development board, execute it, and demonstrate your working design to your TA.

Project Questions

  1. How do you call a C function from assembly language?
  2. How do you call an assembly function from C?
  3. How do you register an interrupt handler using the Xilinxi libraries?
  4. What does the programmable interrupt controller (PIC) do? What registers are exposed to the software?
  5. When a hardware device generated an interrupt what happens in the rest of the system? Describe what happens in the PIC, what happens in the CPU, and what the software does.

Laboratory 6

Laboratory 6 will be the final project in the EECS 388 laboratory. Students have the option to choose their own project for this laboratory. If you elect to take this option then please tell your project idea to the laboratory TA before you begin. This will allow the TA to determine if your project is of the appropriate difficulty. If you do not wish to come up with your own idea then you can do the project described below.

Simple Simon Game

For the Simple Simon game you will develop a system-on-chipi using the Xilinxi XUPi FPGAi that we have been using all semester. You will need to include a RS-232 serial port, the LEDs, and the push buttons in your hardware design. You will then create a software application which blinks the LEDs in a random pattern.The user will then attempt to repeat the pattern using the push buttons. If the user correctly enters the random sequence then they will be awarded a point, otherwise a point will be deducted.

The student will have a greater amount of leeway in determining how to implement this project. There are, however, a few requirements that your implmentation must meet:

  1. Your software application must use the push buttons in interrupt driven mode.
  2. Your software application must include a non-trivial amount of MicroBlazei assembly (30-50 instructions and at least 3 functions).
  3. Your software application must call at least one assembly function from C and at least one C function from assembly.

In addition to these requirements your software application must present a reasonable user interface using the RS-232 serial port. The user should be able to determine what their score is at any given time, and the correct solution to the random sequence should be shown to the user once one of the rounds of play has finished. Additionally, the user interface should indicate button presses as the user presses them.