Download presentation
Presentation is loading. Please wait.
1
Discussion on mp1
2
Homework mp1 Get assignment file from my web page and study it
Make and populate your UNIX mp1 subdirectory Study the source code for mp1
3
Analysis of the test Program
For UNIX or SAPCs, basic process to develop programs is the same - only different in the details “Cross-compilation” is defined as the compilation of a program on one computer (Sun development host) for execution on another computer (SAPC target machine) We used gcc to generate an executable file that will run on the Sun-based UNIX system We used i386-gcc to generate an executable file that would NOT run on UNIX but will run on an SAPC
4
Analysis of the test Program(cont’d)
Portability Defined as ability to write source code so that it can run on two or more types of machines Requires use of a different compiler/loader and library for each type of machine Notice that the library functions called by the test program worked slightly differently on the two types of machines (as noted in the text produced by the test program)
5
Analysis of the test Program (cont’d)
Another difference between the Unix system and the SAPC is the presence/ absence of an operating system UNIX is an operating system that runs programs in a protected environment. Our code can not do some things such as access hardware directly Tutor is a debug monitor only and does not run programs in a protected environment. Our code can access hardware directly as you’ll see later
6
Machine Project 1 In mp1, you will add commands to a program that is a simple version of the Tutor program that we just used on the SAPC The program is “portable” so that it can be run on both the UNIX system and an SAPC You will learn about some things about the differences between the UNIX environment and the SAPC environment
7
Two Different Environments
How is our program loaded into memory? UNIX SAPC 0x 0x Reserved Reserved 0x Code 0x Data 0x Tutor 0x000A0000 Video Memory Reserved 0x000F0000 BIOS (ROM) 0x code data stack 0x003FFFFF Not Implemented Stack 0xFFFFFFFF 0xFFFFFFFF
8
Review of C Data Types Watch out for garbage pointers created using: typedef struct rect { int x1, y1, x2, y2; } Rectangle; Rectangle *recp; recp->x1 = 10; What is wrong with the above code? Answer: no memory pointed to by recp recp->x1 causes segmentation violation on UNIX, but writes into a random location in SAPC
9
malloc() in SAPC malloc() not supported in SAPC
just define the variable Rectangle rect; rect.x1 = 10; Similarly, we can set up typedef struct view{ Rectangle first, last; } View; View v; v.first.x1 = 10; v.first = rect;
10
struct Cmd{…} Declaration
Key to understanding “tutor” is the struct Cmd: typedef struct { char *cmdtoken; /* char string to invoke Cmd */ int (*cmdfn)(); /* function to call for this Cmd */ char *help; /* helpstring for Cmd */ } Cmd; Cmd *cmdtoken ‘m’ ‘d’ ‘\0’ (*cmdfn) ( ) Function to process command *help ‘h’ ‘e’ ‘l’ ‘p’ ‘ ’ ‘t’ ‘e’ ‘x’ ‘t’ ‘\0’
11
struct Cmd{…} Instantiation
Cmd cmds[] = { {"md", mem_display, "Memory display: MD <addr>"}, {"ms", mem_set, "Memory set: MS <addr> <value>"}, {"h", help, "Help: H <command>"}, {"s", stop, "Stop" }, {NULL, NULL, NULL}}; Cmd * cp= cmds; /* or &cmds */ what is cp->cmdtoken? what is cp->cmdfn? what is cp->help? cp++; /* where is cp? */ what is cp->cmdtoken? cp->cmdfn? cp_->help?
12
Machine Project 1 Your job entails
Replacing the stub for the md command to: Convert the character string to an integer Use that integer as an address (a pointer to memory) Find the contents of that address Display the contents of that address to the terminal Adding commands to the command table and writing code to make both of them work Memory Set - ms Help - h
13
makefile Go over the makefile in mp1 How to make the UNIX version?
% make tutor # creates tutor executable on UNIX # and usyms symbol table How to make the SAPC version? % make tutor.lnx # creates tutor executable on SAPC # and syms symbol table
14
What Needs to be Done tutor.c It has the main()
Get cmd token from user by parsing : getcmd() The actual parsing is done by slex() No need to modify tutor.c in mp1
15
What Needs to be Done (cont’d)
cmds.c Need to modify the Cmd struct to include: “ms” and “h” Add code in mem_display(), help(), mem_set() functions Command routine calls with 2 arguments, e.g. mem_display(Cmd *cp, char *arguments) If we enter a command “md 10000” to display the contents of 16 locations starting with 10000, the arguments passed are: Address of the string “10000” &cmds[0]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.