Advertisement
Guest User

simos_rtas.c

a guest
Feb 24th, 2012
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.77 KB | None | 0 0
  1. /*
  2.  * simos_rtas.c
  3.  *
  4.  * Simulate the actions of RS/6000 RTAS (Run Time Abstraction Services)
  5.  * as appropriate for the simulated CPU(s) of SimOS-PPC
  6.  *
  7.  * The (simulated) operating system calls the single RTAS service routine
  8.  * with a pointer to a parameter list like this:
  9.  *
  10.  *     R3 points here ---->  Token (indicates function to be performed)
  11.  *                           No. of inputs, n
  12.  *                           No. of outputs, m
  13.  *               Input value 1
  14.  *               Input value 2
  15.  *               ...
  16.  *               Input value n
  17.  *               Output value 1
  18.  *               ...
  19.  *               Output value m
  20.  *
  21.  * The parameter list is 8-byte aligned in (simulated) REAL storage;
  22.  * the call is made with address translation off (MSR bits IR and DR
  23.  * are both 0) and in supervisor state (MSR bit PR is 0).
  24.  *
  25.  * Each "cell" in the parameter list is a 32-bit integer, even on a 64-bit
  26.  * simulated machine, because there is no 64-bit version of RTAS yet.
  27.  *
  28.  * Token values (for SimOS-PPC's RTAS) are defined in simos_rtas.h.
  29.  * All defined values are accepted, but many are treated here as no-ops.
  30.  *
  31.  * This routine, semantic_rtascall(), is the semantic routine for an
  32.  * undefined PowerPC instruction that is used to interface the simulated
  33.  * operating system with the RTAS functions provided by SimOS.
  34.  */
  35.  
  36. #include <stdlib.h>
  37. #include <unistd.h>
  38. #include <string.h>
  39. #include <time.h>
  40. #include <sys/types.h>
  41. #include <ctype.h>
  42. #include "ppc.h"
  43. #include "addr_layout.h"
  44. #include "sim_error.h"
  45. #include "simos_rtas.h"
  46.  
  47. typedef struct {
  48.     uint32 token;
  49.     uint32 num_inputs;
  50.     uint32 num_outputs;
  51.      int32 values[1];
  52. } RTAS_parms;
  53.  
  54. /*
  55.  * semantic_rtascall ()
  56.  */
  57. int semantic_rtascall (PowerPCState *P, Inst ins)
  58. {
  59.     PA parms_pa = P->gpr[3];
  60.     RTAS_parms *parms = (RTAS_parms *) PHYS_TO_MEMADDR (M_FROM_CPU (P->myNum), parms_pa);
  61.     int32 *in_parms = &parms->values[0];
  62.     int32 *out_parms = &parms->values[parms->num_inputs];
  63. #ifndef K42
  64. #if 1 /* PJB */
  65.     ASSERT(0); /* MAKE CACHE-ENABLED */
  66. #endif
  67. #endif
  68.     switch (parms->token) {
  69.  
  70.     /*
  71.      * Get UTC time of day
  72.      */
  73.     case RTAS_get_time_of_day: {
  74.         time_t curtim = time (NULL);
  75.         struct tm *gmt = gmtime (&curtim);
  76.         out_parms[1] = gmt->tm_year + 1900;  /* tm_year is year-1900 */
  77.         out_parms[2] = gmt->tm_mon + 1;      /* tm_mon is 0..11, output wants 1..12 */
  78.         out_parms[3] = gmt->tm_mday;         /* day of month 1..31 */
  79.         out_parms[4] = gmt->tm_hour;         /* hour 0..23 */
  80.         out_parms[5] = gmt->tm_min;          /* minute 0..59 */
  81.         out_parms[6] = gmt->tm_sec;          /* second 0..59 */
  82.         out_parms[7] = 0;                /* nanoseconds */
  83.        
  84.         CPUWarning ("cpu[%d] RTAS get-time-of-day\n", P->myNum);
  85.         out_parms[0] = 0;       /* success */
  86.         break;
  87.     }
  88.  
  89.     /*
  90.      * Set UTC time of day
  91.      * FIXME -- we'll need to do something with this
  92.      */
  93.     case RTAS_set_time_of_day:
  94.         CPUWarning ("cpu[%d] RTAS set-time-of-day\n", P->myNum);
  95.         out_parms[0] = 0;       /* success */
  96.         break;
  97.  
  98.     /*
  99.      * Scan for reasons for interrupting
  100.      */
  101.     case RTAS_event_scan:
  102.         CPUWarning ("cpu[%d] RTAS event-scan\n", P->myNum);
  103.         out_parms[0] = 1;       /* no errors found */
  104.         break;
  105.  
  106.     /*
  107.      * Scan for hardware errors
  108.      */
  109.     case RTAS_check_exception:
  110.         CPUWarning ("cpu[%d] RTAS check-exception\n", P->myNum);
  111.         out_parms[0] = 1;       /* no errors found */
  112.         break;
  113.  
  114.     /*
  115.      * Give detail on last error in RTAS' log
  116.      */
  117.     case RTAS_last_error:
  118.         CPUWarning ("cpu[%d] RTAS last-error\n", P->myNum);
  119.         out_parms[0] = 1;       /* no errors found */
  120.         break;
  121.  
  122.     /*
  123.      * Read PCI configuration register (need a real function here -- FIXME)
  124.      */
  125.     case RTAS_read_pci_config:
  126.         CPUWarning ("cpu[%d] RTAS read-pci-config\n", P->myNum);
  127.         out_parms[0] = 0;       /* success */
  128.         out_parms[1] = 0;       /* value read (bogus) */
  129.         break;
  130.  
  131.     /*
  132.      * Write PCI configuration register (need a real function here -- FIXME)
  133.      */
  134.     case RTAS_write_pci_config:
  135.         CPUWarning ("cpu[%d] RTAS write-pci-config\n", P->myNum);
  136.         out_parms[0] = 0;       /* success -- but we haven't written anything */
  137.         break;
  138.  
  139.     /*
  140.      * Write one character to alpha-numeric error/status display device
  141.      */
  142.     case RTAS_display_character: {
  143.         char c = in_parms[0];
  144.         char disp[8];
  145.         if (isprint (c)) {
  146.         disp[0] = c;
  147.         disp[1] = '\0';
  148.         }
  149.         else switch (c) {
  150.           case '\n':  strcpy (disp, "\\n");         break;
  151.           case '\t':  strcpy (disp, "\\t");         break;
  152.           case '\b':  strcpy (disp, "\\b");         break;
  153.           case '\f':  strcpy (disp, "\\f");         break;
  154.           case '\r':  strcpy (disp, "\\r");         break;
  155.           default:    sprintf (disp, "0x%.2X", c);  break;
  156.         }
  157.         CPUWarning ("cpu[%d] RTAS display-character '%s'\n", P->myNum, disp);
  158.         out_parms[0] = 0;       /* success */
  159.         break;
  160.     }
  161.  
  162.     /*
  163.      * Set indicator (hex display, output tone, disk light, etc.)
  164.      * We'll claim we don't have any of these.
  165.      */
  166.     case RTAS_set_indicator:
  167.         CPUWarning ("cpu[%d] RTAS set-indicator\n", P->myNum);
  168.         out_parms[0] = -3;      /* "no such indicator implemented" */
  169.         break;
  170.        
  171.     /*
  172.      * Get sensor state (fan speed, power supply voltage, etc.)
  173.      * If the requested sensor is the key switch, we'll reply "normal mode".
  174.      * For other sensors, we'll claim we have no such.
  175.      */
  176.     case RTAS_get_sensor_state:
  177.         CPUWarning ("cpu[%d] RTAS get-sensor-state (%d)\n", P->myNum, in_parms[0]);
  178.         if (1 == in_parms[0]) { /* test for key switch */
  179.         out_parms[0] = 0;   /* success */
  180.         out_parms[1] = 1;   /* normal mode */
  181.         }
  182.         else
  183.         out_parms[0] = -3;  /* "no such sensor implemented" */
  184.         break;
  185.  
  186.     /*
  187.      * Get current power level (highest speed, battery saver, etc.)
  188.      * We'll claim we can't find this out.
  189.      */
  190.     case RTAS_get_power_level:
  191.         CPUWarning ("cpu[%d] RTAS get-power-level\n", P->myNum);
  192.         out_parms[0] = -3;      /* "can't determine current level" */
  193.         break;
  194.  
  195.     /*
  196.      * Power-off:  Turn off the AC power.
  197.      * We'll claim we can't do this.
  198.      */
  199.     case RTAS_power_off:
  200.         CPUWarning ("cpu[%d] RTAS power-off\n", P->myNum);
  201.         out_parms[0] = -1;      /* "hardware error" */
  202.         break;
  203.  
  204.     /*
  205.      * Suspend, hibernate:  Save memory, power down.
  206.      * We'll claim we can't do this.
  207.      */
  208.     case RTAS_hibernate:
  209.         CPUWarning ("cpu[%d] RTAS hibernate\n", P->myNum);
  210.         out_parms[0] = -1;
  211.         break;
  212.  
  213.     case RTAS_suspend:
  214.         CPUWarning ("cpu[%d] RTAS suspend\n", P->myNum);
  215.         out_parms[0] = -1;      /* "hardware error" */
  216.         break;
  217.        
  218.     /*
  219.      * Reboot:  Re-IPL the system
  220.      */
  221.     case RTAS_system_reboot:
  222.         CPUWarning ("cpu[%d] RTAS reboot.............\n", P->myNum);
  223.         out_parms[0] = 0;       /* FIXME -- we need actually to reboot */
  224.         break;
  225.        
  226.     /*
  227.      * Update flash memory and optionally reboot
  228.      * Claim we can't do this.
  229.      */
  230.     case RTAS_update_flash:
  231.     case RTAS_update_flash_and_reboot:
  232.     case RTAS_ibm_update_flash_64_and_reboot:
  233.     case RTAS_ibm_update_flash_64:
  234.         CPUWarning ("cpu[%d] RTAS update-flash etc.\n", P->myNum);
  235.         out_parms[0] = -1;      /* "hardware error" covers a multitude of ills */
  236.         break;
  237.  
  238.     /*
  239.      * Cache control
  240.      * We'll need an actual function here; for now, just return "success"
  241.      */
  242.     case RTAS_cache_control:
  243.         CPUWarning ("cpu[%d] RTAS cache-control (cache %d, state %d)\n",
  244.             P->myNum, in_parms[0], in_parms[1]);
  245.         out_parms[0] = 0;       /* success */
  246.         break;
  247.  
  248.     /*
  249.      * Freeze time base (stop time base updates for all processors in SMP)
  250.      * We'll need an actual function here; for now, just return "success"
  251.      */
  252.     case RTAS_freeze_time_base:
  253.         CPUWarning ("cpu[%d] RTAS freeze-time-base\n", P->myNum);
  254.         out_parms[0] = 0;       /* success */
  255.         break;
  256.  
  257.     /*
  258.      * Thaw time base (restart time base updates for all processors in SMP)
  259.      * We'll need an actual function here; for now, just return "success"
  260.      */
  261.     case RTAS_thaw_time_base:
  262.         CPUWarning ("cpu[%d] RTAS thaw-time-base\n", P->myNum);
  263.         out_parms[0] = 0;       /* success */
  264.         break;
  265.  
  266.     /*
  267.      * Stop self -- stop this processor in SMP
  268.      * We'll need an actual function here; for now, just return "success"
  269.      */
  270.     case RTAS_stop_self:
  271.         CPUWarning ("cpu[%d] RTAS stop-self\n", P->myNum);
  272.         out_parms[0] = 0;       /* success */
  273.         break;
  274.  
  275.     /*
  276.      * Start CPU -- Start an SMP processor
  277.      * We'll need an actual function here; for now, just return "success"
  278.      */
  279.     case RTAS_start_cpu:
  280.         CPUWarning ("cpu[%d] RTAS start-cpu (cpu=%d, locn=0x%.8X, r3=0x%.8X\n",
  281.             P->myNum, in_parms[0], in_parms[1], in_parms[2]);
  282.         out_parms[0] = 0;       /* success */
  283.         break;
  284.  
  285.     /*
  286.      * Query CPU stopped state -- check run/stopped state of another processor in SMP
  287.      * We'll need an actual function here; for now, just return "hardware error"
  288.      * to indicate we don't know.
  289.      */
  290.     case RTAS_query_cpu_stopped_state:
  291.         CPUWarning ("cpu[%d] RTAS query-cpu-stopped-state (cpu=%d)\n",
  292.             P->myNum, in_parms[0]);
  293.         out_parms[0] = -1;      /* "hardware error" */
  294.         break;
  295.  
  296.     /*
  297.      * os-term:  OS is terminating.
  298.      * Print the string passed by the OS.
  299.      */
  300.     case RTAS_ibm_os_term: {
  301.         PA str_pa = in_parms[0];
  302.         char * str = (char *) PHYS_TO_MEMADDR (M_FROM_CPU (P->myNum), str_pa);
  303.         CPUWarning ("cpu[%d] RTAS os-term: \"%s\"\n", P->myNum, str);
  304.         out_parms[0] = 0;       /* success */
  305.         break;
  306.     }
  307.  
  308.     /*
  309.      * For each of these, do nothing but return a "success" indication (out_parms[0] <- 0)
  310.      */
  311.  
  312.         case RTAS_restart:
  313.         CPUWarning ("cpu[%d] RTAS restart-tras\n", P->myNum);
  314.         out_parms[0] = 0;       /* success */
  315.         break;
  316.  
  317.     case RTAS_nvram_fetch:
  318.         CPUWarning ("cpu[%d] RTAS nvram-fetch\n", P->myNum);
  319.         out_parms[0] = 0;       /* success */
  320.         break;
  321.  
  322.     case RTAS_nvram_store:
  323.         CPUWarning ("cpu[%d] RTAS nvram-store\n", P->myNum);
  324.         out_parms[0] = 0;       /* success */
  325.         break;
  326.  
  327.     case RTAS_set_time_for_power_on:
  328.         CPUWarning ("cpu[%d] RTAS set-time-for-power-on\n", P->myNum);
  329.         out_parms[0] = 0;       /* success */
  330.         break;
  331.  
  332.     case RTAS_set_power_level:
  333.         CPUWarning ("cpu[%d] RTAS set-power-level\n", P->myNum);
  334.         out_parms[0] = 0;       /* success */
  335.         break;
  336.  
  337.     case RTAS_assume_power_management:
  338.         CPUWarning ("cpu[%d] RTAS assume-power-management\n", P->myNum);
  339.         out_parms[0] = 0;       /* success */
  340.         break;
  341.  
  342.     case RTAS_relinquish_power_management:
  343.         CPUWarning ("cpu[%d] RTAS relinquish-power-management\n", P->myNum);
  344.         out_parms[0] = 0;       /* success */
  345.         break;
  346.  
  347.     case RTAS_ibm_exti2c:
  348.         CPUWarning ("cpu[%d] RTAS exti2c\n", P->myNum);
  349.         out_parms[0] = 0;       /* success */
  350.         break;
  351.  
  352.     case RTAS_ibm_refresh_firmware_parameters:
  353.         CPUWarning ("cpu[%d] RTAS refresh-firmware-parameters\n", P->myNum);
  354.         out_parms[0] = 0;       /* success */
  355.         break;
  356.     }
  357.  
  358.     P->PC += sizeof (Inst);
  359.     return TRUE;
  360. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement