CS 630: Advanced Microcomputer Programming (Spring 2004)
Lecture: Monday-Wednesday 5:15pm-7:00pm (235 Harney Science Center)
Instructor:
Allan Cruse
Email:
cruse@usfca.edu
Phone: (415) 422-6562
Office: 212 Harney Science Center
Office Hours: (see my homepage)
Synopsis:
This course explores fundamental capabilities of Intel's Pentium
microprocessor, regarded as a "bare machine" for which the basic
software components of an operating system are to be constructed
in a context of standard PC-BIOS firmware and peripheral devices.
Topics appropriate to this goal include:
- crafting a bootstrap loader
- identifying the processor model and stepping
- segmented real-mode memory-addressing
- device detection and initialization
- the CMOS memory and real-time clock
- keyboard, monitor, and interval-timers
- the programmable interrupt controllers
- floating-point, mmx, and simd instructions
- building protected-mode segment-descriptors
- entering and leaving 16-bit or 32-bit protected-mode
- creating exception-handlers and interrupt-descriptors
- building page-tables for virtual-memory support
- processor mechanisms for multitasking and debugging
- emulation of the legacy 8086 execution environment
- initialization and communication among multiple CPUs
- system management mode and performance monitoring counters
Throughout the course small software-component prototypes will be
written using the GNU/Linux program development tools (including
assemblers and C/C++ compilers). The course is open to graduate
students in computer science (and to qualified undergraduates if
the Instructor has granted permission). Students are assumed to be
familiar with Linux or UNIX, and with programming in C and in
x86 assembly language.
Learning Outcomes:
- You will broaden your knowledge of standard 32-bit Intel Architectures.
- You will become aware of the Intel processors' seldom-used capabilities.
- You will increase your proficiency with using C and assembler language.
- You will know how to access service-functions provided in BIOS firmware.
- You will gain practical experience in programming peripheral I/O devices.
- You will acquire the background for understanding next-generation CPUs.
- You will lay a foundation for pursuing some additional career options.
Class meetings will be held in the
Michael D. Kudlick computer classroom
(Room 235, Harney Science Center) which affords convenient opportunities
for combining formal instruction with "hands-on" programming exercises.
This facility, a gift of USF alumnus
Alfred S. Chuang ('82), opened in Fall 2002.
Textbook(s):
Resources
Handouts
- Preview demo: bootdemo.s
(a diskette boot-sector replacement, written in as86 assembly language)
- 0203-630-01: Course syllabus (.PDF)
- lesson1.ppt (PowerPoint Slides)
- Demo program: showmsw.cpp
an application that displays the CPU's Machine Status Word
- Demo program: bootmsw.s
(a boot-sector program that also displays the MSW register)
- Author's commentary on
the 'bootmsw.s' demo program
- lesson2.ppt (PowerPoint Slides)
- Demo program: showivt.cpp
an application that displays the real-mode Interrupt Vector Table
- Device-driver module: dos.c
(needed for running the preceeding 'showivt' demo-program)
- Demo program: showrbda.cpp
an aplication that displays parameters in the ROM-BIOS DATA-AREA
- Demo program: memsize.s
(a boot-sector program that shows the size of real-mode memory)
- lesson3.ppt (PowerPoint Slides)
- Demo program: regdump.s
(a bootsector program that shows initial values in the 8086 registers)
- lesson4.ppt (PowerPoint Slides)
- Demo program: sysregs.s
(for in-class exercise) to show values in descriptor-table registers
- lesson5.ppt (PowerPoint Slides)
- Demo program: pmhello.s
(showing how to set up segment-descriptors for protected-mode)
- lesson6.ppt (PowerPoint Slides)
- CS630 utility: newipl86.cpp
(creates 'boilerplate' source-text for a new bootsector program)
- CS630 utility: dump.cpp
(shows the contents of a named file in hex and ascii formats)
- Demo program: trackldr.s
(a bootsector program to read multiple diskette-sectors into ram)
- Demo program: usertick.s
(illustrates temporary installation of a custom interrupt-handler)
- lesson7.ppt (PowerPoint Slides)
- Demo program: tryring1.s
(shows how a processor privilege-level transition is accomplished)
- solution to in-class exercise #1
(modifying 'tryring1.s' to use a 32-bit TASKGATE and TSS)
- lesson8.ppt (PowerPoint Slides)
- Demo program: tickdemo.s
(shows how to handle the timer-tick interrupt in protected-mode)
- CS630 utility: newapp86.cpp
(creates 'boilerplate' source-text for a new as86 application)
<-- revised on 5/27/04
- lesson9.ppt (PowerPoint Slides)
- Demo program: twotasks.s
(illustrates x86 context-switching among two program-threads)
- Demo program: showgdt.cpp
(this application shows Linux's Table of Global Descriptors)
- Device-driver module: dram.c
(needed for running the preceeding 'showgdt' demo-program)
- Demo program: showtss.s
(new version of 'twotasks.s' that displays Task-State Segments)
- lesson10.ppt (PowerPoint Slides)
- Demo program: whycrash.s
(uses a fault-handler to show some system-crash diagnostic info)
- lesson11.ppt (PowerPoint Slides)
- Demo program: reporter.s
(illustrates reprogramming of the two 8259A Interrupt Controllers)
- lesson12.ppt (PowerPoint Slides)
- Demo program: minikybd.s
(illustrates handling of interrupts from the Keyboard Controller)
<-- revised on 4/6/04
- lesson13.ppt (PowerPoint Slides)
- Demo program: arrows.s
(illustrates "polled-mode" programming and CRT cursor movements)
- solution to question V on midterm I
(modifying 'showtss.s' to use a 32-bit TASKGATE and TSS)
- lesson14.ppt (PowerPoint Slides)
- Demo program: manydots.s
(a Linux application that we want to execute without using Linux)
- Demo printout: manydots.opd
(dump of the 'manydots.o' object-file, showing its ELF sections)
- CS630 utility: loadmap.cpp
(a tool for studying the sections in a relocatable ELF object-file)
- Demo program: try32bit.s
(executes the 32-bit code in a linkable ELF-file named 'hello.o')
<-- revised on 5/10/04
- Demo program: hello.s
(source-text for the Linux program used with the 'try32bit.s' demo)
- lesson15.ppt (PowerPoint Slides)
- CS630 utility: elfinfo.cpp
(a tool for studying sections in a relocatable or executable ELF file)
- Exercise solution: tryexec.s
(modifies 'try32bit.s' to run an ELF executable file named 'hello')
<-- revised on 5/10/04
- lesson16.ppt (PowerPoint Slides)
- Exercise solution: ondemand.s
('tryexec.s' modified to simulate 'load-on-demand' mechanism)
<-- revised on 5/10/04
- lesson17.ppt (PowerPoint Slides)
- Demo program: cmosdump.cpp
(displays contents of the Real-Time Clock's nonvolatile memory)
- Demo program: rtcdemo.s
(illustrates programming of the Real-Time Clock's 'update' interrupt)
<-- revised on 4/8/04
- Demo program: showidt.cpp
a Linux application program that shows the Interrupt Vector Table
- Demo program: trydebug.s
(illustrates single-stepping through an executable ELF application)
<-- revised 5/10/04
- solution to question V on midterm II
(modifies 'trydebug.s' to add display of FS and GS)
<-- revised 5/10/04
- lesson18.ppt (PowerPoint Slides)
- Exercise solution: trydebug3.s
(illustrates setting a breakpoint-trap after a software interrupt)
<-- revised 5/10/04
- lesson19.ppt (PowerPoint Slides)
- Demo program: trymouse.s
(uses ROM-BIOS services to enable PS/2 mouse-event interrupts)
- lesson20.ppt (PowerPoint Slides)
- Demo program: trypages.s
(builds and activates a page-directory with one page-table entry)
- Exercise solution: trypages2.s
(illustrates remapping video memory to virtual address 0x80000000)
- Demo program: showpdir.cpp
(a Linux application that displays the current task's page-directory)
- Source for the kernel modules cr3.c
and dram.c
(needed by the above 'showpdir' application)
- Demo program: alphabet.s
(source-text for a Linux application to be used with Project 3)
- lesson21.ppt (PowerPoint Slides)
- Demo program: tryvm86.s
(executes a "real-mode" procedure in virtual-8086 emulation mode)
- lesson22.ppt (PowerPoint Slides)
- Demo program: emulate.s
(executes ROM-BIOS routines in virtual-8086 mode, but with IOPL<3)
- Exercise solution: emulate2.s
(it adds emulations for the PUSHFD/POPFF/IRETD instructions)
- GNU linker-script demo: use
ldscript
to link mymain.s
with mysub.s
(reply to a query by Toshi Uchino)
- lesson23.ppt (PowerPoint Slides)
- Demo program: refresh.s
(illustrates PC's use of the 8254 Timer-Counter for memory-refresh)
- Demo program: cpuspeed.s
(uses the 8254 Timer-Counter to measure the processor's clock-speed)
- Exercise solution: rtupdate.s
(measures the duration of the Real-Time Clock's update-cycle)
- lesson24.ppt (PowerPoint Slides)
- Demo program: apictick.s
(illustrates programming of the cpu's Local-APIC timer interrupt)
- Demo program: cpuid.cpp
illustrates use of the 'cpuid' instruction (to learn cpu's capabilities)
- Demo program: smpinfo.cpp
(shows the MP Floating Pointer Structure and Base Configuration entries)
- lesson25.ppt (PowerPoint Slides)
- Demo program: cpuslice.s
(uses APIC Timer to implement processor timesharing among several tasks)
- Demo program: mphello.s
(illustrates the MP protocol for awakening auxilliary processors)
- Email from Alex Fedosov
(identifies a "bug" in our 'try32bit.s' demo-program,
and proposes an easy fix)
- Linux kernel-module: mch.c
(provides a '/proc' interface to the Memory Controller Host-to-PCI Hub)
- Demo program: showdate.s
(source-text for a Linux program that invokes the 'iopl' system-call)
- Exam-question solution: tryexec2.s
(adds an implementation for 'iopl' system-call to our 'tryexec.s' demo)
- Project solution: myos.s
(a working version of the 'project 3' round-robin task-switching demo)
Readings
- Week 1: Part One (Chapters 1-3) in textbook by Shanley
- Week 2: Part Two (Chapters 4-5) in textbook by Shanley
- Week 3: Part Three (Chapters 6-7) in textbook by Shanley
- Week 4: Part Three (Chapters 8-9) in textbook by Shanley
- Week 5: Part Three (Chapters 10-11) in textbook by Shanley
- Week 6: Part Three (Chapter 12) in textbook by Shanley.
- Week 7: Data Sheet for 8259A Programmable Interrupt Controller.
- Week 8: Official Documentation for ELF files (Chapter One).
- Week 9: Official Documentation for ELF files (Chapters 2-3).
- Week 10: No new assignment (work on Project 2 and midterm review).
- Week 11: Part Three (Chapters 13-14) in textbook by Shanley.
- Week 12: Part Three (Chapter 15) in textbook by Shanley.
- Weeks 13-15: No new assignment (work on Project 3 and course review).
Announcements
- Project 1:
Due by Noon Tuesday, 17 February 2004.
- Midterm Exam 1: Monday, March 1.
- Project 2:
Due by Noon Tuesday, 6 April 2004.
- Note: one-week extension is granted (for FlashMob event)
- Midterm Exam 2: Wednesday, April 7.
- Project 3:
Due by Noon Friday, 14 May 2004.
- FINAL EXAMINATION: Monday, May 17, 6pm-8pm.
- Posted an enhanced version of our
newapp86.cpp utility.
Last updated on 08/17/2004