daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*     +-------------------------------------------------------------+      
  2.        | This code is my own work, it was written without consulting |      
  3.        |  a tutor or code written by other students - Nikhil Murthy  |      
  4.        +-------------------------------------------------------------+     */
  5.  
  6. #include "../../h/const.h"
  7. #include "../../h/types.h"
  8. #include "../../h/procq.e"
  9. #include "../../h/asl.e"
  10.  
  11. /************************************************
  12.   Global Variables
  13. ************************************************/
  14. devreg_t *devregs = (devreg_t*)0x1400;
  15.  
  16. /***************************************************************************
  17.  *                           FUNCTION PROTOTYPES                           *
  18.  ***************************************************************************/
  19. /* main functions */
  20. void readfromterminal();
  21. void writetoterminal();
  22. void delay();
  23. void gettimeofday();
  24. void terminate();
  25. /* utility functions*/
  26. int vir2real_add(vad_t *vadd);
  27.  
  28. /* trap locations */
  29. state_t *sys_old = (state_t *) 0x930;
  30. state_t *sys_new = sys_old + 1;
  31.  
  32. /* Read_from_Terminal (SYS9) */
  33. void
  34. readfromterminal()
  35. {
  36.     char *data;
  37.     int *cnt;
  38.     int term;
  39.     int done = 0;
  40.     /* d3 = virtual address of buffer for data read */
  41.     data = (char*)vir2real_add((vad_t*)sys_old->s_r[3]);
  42.     /* d2 = return number of characters read */
  43.     cnt = &(sys_old->s_r[2]);
  44.     term = sys_old->s_tmp.tmp_sys.term_no;
  45.     /* do the term i/o */
  46.     devregs[term].d_stat = NULL;
  47.     devregs[term].d_badd = data;
  48.     devregs[term].d_op = IOREAD;
  49.     while (!done)
  50.         switch (devregs[term].d_stat) {
  51.         case NULL:
  52.             break;
  53.         case NORMAL:
  54.             *cnt = devregs[term].d_amnt;
  55.             done = 1;
  56.             break;
  57.         case ENDOFINPUT:
  58.             *cnt = -ENDOFINPUT;
  59.             done = 1;
  60.             break;
  61.         default:
  62.             *cnt = -devregs[term].d_stat;
  63.             done = 1;
  64.             break;
  65.         }
  66.     /* start the t-proc again */
  67.     LDST(sys_old);
  68. }
  69.  
  70. /* Write_to_Terminal (SYS10) */
  71. void
  72. writetoterminal()
  73. {
  74.     /* d3 = virtual address of data buffer to write */
  75.     char *data = (char*)vir2real_add((vad_t*)sys_old->s_r[3]);
  76.     /* d4 = count of number of characters to be written */
  77.     int *cnt = &(sys_old->s_r[4]);
  78.     int term = sys_old->s_tmp.tmp_sys.term_no;
  79.     int done = 0;
  80.  
  81.     /* do the i/o */
  82.     devregs[term].d_stat = NULL;
  83.     devregs[term].d_badd = data;
  84.     devregs[term].d_op = IOWRITE;
  85.     while (!done)
  86.         switch(devregs[term].d_stat) {
  87.         case NULL:
  88.             break;
  89.         case NORMAL:
  90.             *cnt = devregs[term].d_amnt;
  91.             done = 1;
  92.             break;
  93.         default:
  94.             *cnt = -devregs[term].d_stat;
  95.             done = 1;
  96.             break;
  97.         }
  98.     /* start up the t-proc again */
  99.     LDST(sys_old);
  100. }
  101.  
  102. /* Delay (SYS13) */
  103. void
  104. delay()
  105. {
  106. }
  107.  
  108. /* Get_Time_of_Day (SYS16) */
  109. void
  110. gettimeofday()
  111. {
  112.     /* d2 = time of day clock */
  113.     STCK(&(sys_old->s_r[2]));
  114.     /* start the process back up */
  115.     LDST(sys_old);
  116. }
  117.  
  118. /* Terminate (SYS17) */
  119. void
  120. terminate()
  121. {
  122. }
  123.  
  124. /************************************************
  125.   Utility Functions
  126. ************************************************/
  127.  
  128. int
  129. vir2real_add(vad_t *vadd)
  130. {
  131.     int segnum, pagenum, offset;
  132.     sd_t seg;
  133.     pd_t page;
  134.     int ret;
  135.  
  136.     segnum = vadd.v_seg; pagenum = vadd.v_page; offset = vadd.v_offset;
  137.  
  138.     seg = sys_old->s_crp + segnum;
  139.     page = seg.sd_pta + pagenum;
  140.     if (page.pd_p == 1)
  141.         /* page is present */
  142.         ret = ((int)page.pd_frame)*512 + offset;
  143.     else ret = -1;
  144.     return ret;
  145. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top