Note that for this session, there are some Preparation Exercises. Also for this session, there is a submitable laboratory exercise which is due by 10 am Monday 14 May (week 10), which will contribute up to 1% of your assessment (in the Tute/Lab mark).
There are several objectives in this exercise:
Preparation Exercises
Complete the following questions on a separate sheet of paper, with your
name and student number clearly written. Please ensure your writing is
legible. Hand in to your tutor at the beginning of your tutorial /
laboratory session.
It is expected that you work through Part 1 as well as Part 2 (up to at least Part 2a) in the supervised lab in week 9, and that you continue with Parts 2 and 3 in the unsupervised lab in week 10 (no new lab sheet will be distributed in week 10). It is also a (possibly the last!) chance to get some help from your tutor for Assignment 2, although it is not the intention for your to spend much of the session on this.
assemble vmfifo.ass
join vmfifo.rel
The page fault service routine in vmfifo.ass is rather simplistic in a number of ways. There are a number of steps that can be taken to improve the page fault service routine.
One of the limitations of the page fault service routine of vmfifo.ass is that it only has 26 memory cells of page one to fit into (the first six cells of page one are used to store registers and the number of the page to be swapped in). This space restriction means that the routine must be kept simple.
The dirty bit is provided for just this reason. If a page is dirty it should be written back to main memory, otherwise it can be discarded (because the copy in main memory is identical). Now that page three is locked in, you should have enough space to add lines to the page fault service routine that check the dirty bit before writing the page back.
Your routine should not write pages back unless it is dirty. Note that a loadxr instruction may now be needed in the code before putchar('A'+XR);. Note also that if the page is dirty, the putchar('*'); occurs before this. Also note that iftrap #13 is not called, PT[XR] must be explicitly zeroed by the handler (to signify it has been swapped out).
Note that it does not matter what values you write or where
in the page you write them (for the purpose of this exercise
or its automated marking). It is important though
that only the hander routine produces any output (
submit comp2300 lab8 vmfifoa.ass vmfifob.ass
This is due by 10am Monday May 14 (the deadline is strict)
and will contribute up to 1% of your Tute/Lab mark.
previewAutoMark lab8 vmfifoa.ass vmfifob.ass
Note that the previewAutoMark command is only available
on DCS Linux hosts, i.e. do not try to run this command from iwaki$
When satisfied, submit it using the submit command:
; vmfifo.ass: PeANUt assembler file for COMP2300 Lab 8, 2007
;
; This file demonstrates PeANUt Virtual Memory in operation. The paging
; algorithm here is a *basic* FIFO algorithm. This algorithm has the following
; weaknesses:
; i) It relies on all page frames being pre-loaded.
; ii) It always writes back (no Dirty bit check).
; The program included here accesses each page in memory.
; As it accesses pages not swapped in, page faults occur.
; As each page fault occurs, two characters are printed, a character corres-
; ponding to the page to be swapped out, and a character corresponding to the
; page to be swapped in. Page 0 is represented by "A", Page 1 "B" and
; Page 31 by "`".
;
; The page-fault handling routine starts at a46 (as it must). The test program
; starts at page 2.
; /* Define initial page table contents (pages 0-7 swapped in, remainder out) */
; /* PT must be at address 0 */
; volatile short int PT[] = {
PT: data %00000 000 111 0 1 000 ; 0x00e8,
data %00000 000 110 0 1 001 ; 0x00c9,
data %00000 000 101 0 1 010 ; 0x00aa,
data %00000 000 100 0 1 011 ; 0x008b,
data %00000 000 011 0 1 100 ; 0x006c,
data %00000 000 010 0 1 101 ; 0x004d,
data %00000 000 001 0 1 110 ; 0x002e,
data %00000 000 000 0 1 111 ; 0x000f,
;
block 24 ; 0,0,0,0, 0,0,0,0, 0,0,0,0,
; 0,0,0,0, 0,0,0,0, 0,0,0,0
; } /* PT */
; /* next 6 memory loc. are reserved for the OS*/
block 5 ; /* for saving registers on page faults*/
; /* PgFtNum must be at address 37 = a45*/
PgFtNum:block 1 ; volatile short int PgFtNum;
; /*on trap #11, OS puts # of page causing fault*/
; /* VM-related macros for PeANUt */
PageSz = 32 ; #define PageSz 32 /* page size */
LastPg = 31 ; #define LastPg 31 /* number of last page*/
SwapOut = 13 ; #define SwapOut 13 /* trap # to swap out */
SwapIn = 12 ; #define SwapIn 12 /* trap # to swap in */
; /* FIFOPgSwap() must be at address 38 = a46 */
FIFOPgSwap: ; void FIFOPgSwap(void) {
; /* post: implements a FIFO page swap algorithm */
FstULPg = 2 ; #define FstULPg 2 /* # of 1st unlocked page */
setxr #FstULPg; short int XR = FstULPg;
FIFOwh: load *PT ; while ( (PT[XR]
and SwPrMsk ; & SwPrMsk)
cmp SwCtOPr ; != SwCtOPr ) {
beq FIFOewh ; /* seek PT entry with Swap Count=5 & Present=1 */
incxr #1 ; XR = XR + 1;
load #LastPg ; if (XR > LastPg)
cmpxr ; break; /* an error, to be trapped later;... */
ble FIFOwh ; /* ... prevents an inf. loop here */
FIFOewh: ; } /* while */
load *PT ; PT[PgFtNum] = (PT[XR] & FramMsk);
and FramMsk ; /* fill in frame # of PT entry for new page */
store @PgFtNum; /* new page goes to same frame as page to be swapped out */
loadxr ; <swap out page XR>;
trap #SwapOut;
add #'A' ; putchar('A'+XR);
trap #3 ; /*letter corresp. to this page*/
load PgFtNum ; <swap in page PgFtNum>;
trap #SwapIn ;
add #'A' ; putchar('A'+PgFtNum);
trap #3 ;
load #'\n' ; putchar("\n');
trap #3 ;
ret ; } /* FIFOPgSw() */
; Bit masks used in page fault service routine.
SwPrMsk:data %00000 000 111 0 1 000 ; const short int SwPrMsk = 0x00e8,
; /*Swap count & Present bit mask*/
SwCtOPr:data %00000 000 101 0 1 000 ; SwCtOPr = 0x00a8,
; /*Swap count=5 (Oldest), Present=1 */
FramMsk:data %00000 000 000 0 0 111 ; FramMsk = 0x0007;
; /* frame number mask */
LstPg: data 991 ; const int LstPg = 991; /*addr. of start last page-1*/
; int main() {
main: setxr #0 ; short int *XR = NULL; /* implement via XR*/
; do {
mloop: load *0 ; <access *XR>;
incxr #PageSz ; XR += PageSz;
load LstPg ;
cmpxr ; } while (XR <= (int *) LstPg);
ble mloop ;
trap #1 ; exit(0);
end main ; } /* main() */
Last modified:
Mon Apr 30 10:42:51 EST 2007