USF CS 630 - CS 630: Advanced Microcomputer Programming

Unformatted text preview:

CS 630: Advanced Microcomputer ProgrammingCourse SynopsisMethodologyCourse prerequisitesSimplified component diagramReview of the legacy x86 APIReview of Instruction-SetReview “Fetch-Execute” CycleSteps in ‘Fetch-Execute Cycle’Review of operand addressingCourse TextbookInstructor Contact InformationCPU Execution ModesThe ‘pre-boot’ environment64KB Memory-SegmentsReal-Mode Address-TranslationUsing ROM-BIOS functionsA valuable Online ReferencePower-OnSlide 20Slide 21A very short exampleAssemble, link, and installOur ‘fileview’ utilityObservationsExampleSymbolic addressesExample that uses symbolsEffect of the long-jumpIn-class exercise #1In-class exercises #2, #3, #4CS 630: Advanced Microcomputer ProgrammingFall 2008Professor Allan B. CruseUniversity of San FranciscoCourse Synopsis•We study Intel-64 processor architecture•It’s implemented in our Core-2 Quad CPU•We pretend we’re using a ‘bare machine’ (i.e. no operating system to ‘hide’ what’s going on, just standard PC hardware and accompanying vendor-supplied firmware)•So we get to build our own miniature OS•Doing this will bring us face-to-face with the CPU’s most fundamental capabilitiesMethodology•Our interactive computer classroom lets us take a ‘hands on’ approach to our studies (i.e., we combine ‘theory’ with ‘practice’)•Typically we’ll devote first part each class to a ‘lecture’ about aspects of x86 theory •Then we’ll take time in the second part of class for ‘laboratory exercises’ that put the newly learned ideas into ‘working code’Course prerequisites•Experience with C / C++ programming•Familiarity with use of Linux / UNIX OS•Acquaintance with x86 assembly language–Knowledge of the x86 general registers–Awareness of the x86’s instruction-set•Understand the CPU’s fetch-execute cycle•Recall the ways memory is addressedSimplified component diagramCentralProcessingUnitMainMemoryI/OdeviceI/OdeviceI/OdeviceI/Odevicesystem bus…Review of the legacy x86 APIEAXEBXECXEDXESIEDIEBPESPGeneral Registers (32-bits)CSDSESFSGSSSSegment Registers (16-bits)EIPEFLAGSProgram Control and Status Registers (32-bits)Review of Instruction-Set•Data-transfer instructions (mov, xchg, …)•Control-transfer instructions (jmp, call, …)•Arithmetic/Logic instructions (add, or, …)•Shift/Rotate instructions (shr, rol, …)•String-manipulation instructions (movs, …)•Processor-control instructions (cli, hlt, …)•Floating-point instructions (fldpi, fmul, …)Review “Fetch-Execute” CycleESPEIPProgramInstructions(TEXT)ProgramVariables(DATA)TemporaryStorage(STACK)main memorycentral processorEAXEAXEAXEAXthe system busSteps in ‘Fetch-Execute Cycle’ INTR?Fetch next instructionAdvance instruction-pointerDecode fetched instructionExecute decoded instructionnoInterruptServiceRoutineyesReview of operand addressing•Implicit addressing (e.g. pushf, cbw, scasb, cli, xlat, …)•Register addressing(e.g., mov %ax, %bx)•Direct addressing(e.g., incl salary, movw $0, counter, …)•Indirect addressing(e.g., add %dx, 0x14(%ebx, %esi, 2) )Course Textbook•Tom Shanley, Protected Mode Software Architecture, Addison-Wesley (1996)Initial reading assignment:Week 1: Read Part One (Chapters 1-3)Week 2: Read Part Two (Chapters 4-5)Instructor Contact Information•Office: Harney Science Center – 212•Hours: Mon-Wed-Fri 12:30pm-1:15pm and Tues-Thurs 6:30pm-7:15pm•Phone: (415) 422-6562•Email: [email protected]•Webpage: <http://cs.usfca.edu/~cruse>CPU Execution Modes REALMODEPROTECTEDMODEVIRTUAL8086MODESYSTEMMANAGEMENTMODEPOWER-ON / RESETThe ‘pre-boot’ environment•None of the normal library functions•No graphical desktop, no file-system •No editors, compilers, debuggers•No network-access, no mouse, no printer•Only one of the four processors is active•Only a tiny fraction of the system memory is accessible (only 1-MB, out of 4096-MB)•The method of addressing memory is very different from what we’re accustomed to!64KB Memory-Segments•Fixed-size segments (can be overlapping) •Segments start on paragraph boundaries•Segment-registers serve as “selectors”codedatastackCSDSSSReal-Mode Address-Translation0x1234 0x6789Logical address:16-bit segment-address 16-bit offset-addressx 16+0x18AC920-bit bus-addressPhysical address: 0x12340+ 0x06789---------------- 0x18AC9Using ROM-BIOS functions•Our system firmware provides many basic service-functions that real mode programs can invoke (this includes ‘boot-loaders’):–Video display functions–Keyboard input functions–Disk access functions –System query functions–A machine ‘re-boot’ functionA valuable Online Reference•Professor Ralf Brown’s Interrupt List(see webpage link under ‘Resources’)•It tells how to make BIOS system-calls, to perform numerous low-level services from within Real-Mode 8086 applications (such as ‘boot loader’ programs)Power-OnDRAMROM-BIOSExpansion ROMsVideo BIOSVRAM1-MBCS:IPuninitialized memory areaSystem setupDRAMROM-BIOSExpansion ROMsVideo BIOSVRAM1-MBCS:IPInterruptVectorTableIVTRBDA ROM-BIOSDATA AREAEBDAExtended BIOS Data AreaBootstrap LoaderDRAMROM-BIOSExpansion ROMsVideo BIOSVRAM1-MBCS:IPInterruptVectorTableIVTRBDA ROM-BIOSDATA AREAEBDAExtended BIOS Data AreaBOOT_LOCNDisk StorageA very short example// smile.s.section .text # our linker needs this namemov $0x0E, %ah # BIOS function-selectormov $0x01, %al # character-glyph selectormov $0x00, %bh # display-page selectorint $0x10 # invoke ROM-BIOS servicefreeze: jmp freeze # enter an infinite loop.org 510 # offset to boot-signature.byte 0x55, 0xAA # value for boot-signature,end # nothing more to assembleAssemble, link, and install# Use the GNU/linux assembler to translate source-code to object-code: $ as smile.s -o smile.o# Use the GNU/Linux linker to convert object-code to binary-format:$ ld smile.o -T ldscript -o smile.b# NOTE: This linking step requires using a special ‘linker-script’ in order# to override the default ELF-format output-file (the customary format of# a file that the Linux operating system knows how to load and execute)# Copy the binary-executable to the place on our CS630 disk-partition # where the GRUB boot-loader will expect to find it: $ dd if=smile.b of=/dev/sda4Our ‘fileview’ utility•You can use the ‘fileview.cpp’ program (on our cs630 course-website) as a convenient tool for viewing files: $ ./fileview smile.b•Since


View Full Document

USF CS 630 - CS 630: Advanced Microcomputer Programming

Documents in this Course
Load more
Download CS 630: Advanced Microcomputer Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS 630: Advanced Microcomputer Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS 630: Advanced Microcomputer Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?