Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Explictly tags in saves for PIT, APIC, IOAPIC, SVM, and CORE
[palacios.git] / palacios / src / devices / 8254.c
index 1a44399..58b66b6 100644 (file)
@@ -177,10 +177,11 @@ static int handle_crystal_tics(struct pit * pit, struct channel * ch, uint_t osc
            reload_val -= reload_val % 2;
        }
 
-       // TODO: Check this....
-       // Is this correct???
        if (reload_val == 0) {
-           reload_val = 1;
+           // This means the value is being set to 0x10000
+           // but due to the tick after the reload, it wraps
+           // down to 0xffff
+           reload_val = 0xffff;
        }
 
        channel_cycles += oscillations / reload_val;
@@ -683,30 +684,112 @@ static int pit_free(void * private_data) {
 }
 
 #ifdef V3_CONFIG_CHECKPOINT
+
+#include <palacios/vmm_sprintf.h>
+
+#define KEY_MAX 128
+#define MAKE_KEY(x) snprintf(key,KEY_MAX,"PIT_CH%d_%s",i,x)
+
 static int pit_save(struct v3_chkpt_ctx * ctx, void * private_data) {
     struct pit * pit_state = (struct pit *)private_data; 
-
-    V3_CHKPT_STD_SAVE(ctx, pit_state->pit_counter);
-    V3_CHKPT_STD_SAVE(ctx, pit_state->pit_reload);
-    V3_CHKPT_STD_SAVE(ctx, pit_state->ch_0);
-    V3_CHKPT_STD_SAVE(ctx, pit_state->ch_1);
-    V3_CHKPT_STD_SAVE(ctx, pit_state->ch_2);
-    V3_CHKPT_STD_SAVE(ctx, pit_state->speaker);
+    int i;
+    char key[KEY_MAX];
+
+    V3_CHKPT_SAVE(ctx, "PIT_COUNTER", pit_state->pit_counter,savefailout);
+    V3_CHKPT_SAVE(ctx, "PIT_RELOAD", pit_state->pit_reload,savefailout);
+
+    for (i=0;i<3;i++) {
+      struct channel *c;
+      uint8_t pins;
+
+      if (i==0) { 
+       c=&(pit_state->ch_0);
+      } else if (i==1) { 
+       c=&(pit_state->ch_1);
+      } else {
+       c=&(pit_state->ch_2);
+      }
+      
+      MAKE_KEY("ACCESS_MODE");
+      V3_CHKPT_SAVE(ctx, key, c->access_mode, savefailout);
+      MAKE_KEY("ACCESS_STATE");
+      V3_CHKPT_SAVE(ctx, key, c->access_state, savefailout);
+      MAKE_KEY("RUN_STATE");
+      V3_CHKPT_SAVE(ctx, key, c->run_state, savefailout);
+      MAKE_KEY("OP_MODE");
+      V3_CHKPT_SAVE(ctx, key, c->op_mode, savefailout);
+      MAKE_KEY("COUNTER");
+      V3_CHKPT_SAVE(ctx, key, c->counter, savefailout);
+      MAKE_KEY("RELOAD_VALUE");
+      V3_CHKPT_SAVE(ctx, key, c->reload_value, savefailout);
+      MAKE_KEY("LATCH_STATE");
+      V3_CHKPT_SAVE(ctx, key, c->latch_state, savefailout);
+      MAKE_KEY("READ_STATE");
+      V3_CHKPT_SAVE(ctx, key, c->read_state, savefailout);
+      
+      pins = (c->output_pin) | (c->gate_input_pin << 1);
+      MAKE_KEY("PINS");
+      V3_CHKPT_SAVE(ctx, key, pins, savefailout);
+    }
+    
+    V3_CHKPT_SAVE(ctx, "PIT_SPEAKER", pit_state->speaker,savefailout);
     
     return 0;
+
+ savefailout:
+    PrintError("Failed to save pit\n");
+    return -1;
 }
 
 static int pit_load(struct v3_chkpt_ctx * ctx, void * private_data) {
     struct pit * pit_state = (struct pit *)private_data;
-
-    V3_CHKPT_STD_LOAD(ctx, pit_state->pit_counter);
-    V3_CHKPT_STD_LOAD(ctx, pit_state->pit_reload);
-    V3_CHKPT_STD_LOAD(ctx, pit_state->ch_0);
-    V3_CHKPT_STD_LOAD(ctx, pit_state->ch_1);
-    V3_CHKPT_STD_LOAD(ctx, pit_state->ch_2);
-    V3_CHKPT_STD_LOAD(ctx, pit_state->speaker);
+    int i;
+    char key[KEY_MAX];
+
+    V3_CHKPT_LOAD(ctx, "PIT_COUNTER", pit_state->pit_counter,loadfailout);
+    V3_CHKPT_LOAD(ctx, "PIT_RELOAD", pit_state->pit_reload,loadfailout);
+
+    for (i=0;i<3;i++) {
+      struct channel *c;
+      uint8_t pins;
+
+      if (i==0) { 
+       c=&(pit_state->ch_0);
+      } else if (i==1) { 
+       c=&(pit_state->ch_1);
+      } else {
+       c=&(pit_state->ch_2);
+      }
+      
+      MAKE_KEY("ACCESS_MODE");
+      V3_CHKPT_LOAD(ctx, key, c->access_mode, loadfailout);
+      MAKE_KEY("ACCESS_STATE");
+      V3_CHKPT_LOAD(ctx, key, c->access_state, loadfailout);
+      MAKE_KEY("RUN_STATE");
+      V3_CHKPT_LOAD(ctx, key, c->run_state, loadfailout);
+      MAKE_KEY("OP_MODE");
+      V3_CHKPT_LOAD(ctx, key, c->op_mode, loadfailout);
+      MAKE_KEY("COUNTER");
+      V3_CHKPT_LOAD(ctx, key, c->counter, loadfailout);
+      MAKE_KEY("RELOAD_VALUE");
+      V3_CHKPT_LOAD(ctx, key, c->reload_value, loadfailout);
+      MAKE_KEY("LATCH_STATE");
+      V3_CHKPT_LOAD(ctx, key, c->latch_state, loadfailout);
+      MAKE_KEY("READ_STATE");
+      V3_CHKPT_LOAD(ctx, key, c->read_state, loadfailout);
+      
+      pins = (c->output_pin) | (c->gate_input_pin << 1);
+      MAKE_KEY("PINS");
+      V3_CHKPT_LOAD(ctx, key, pins, loadfailout);
+    }
+    
+    V3_CHKPT_LOAD(ctx, "PIT_SPEAKER", pit_state->speaker,loadfailout);
 
     return 0;
+
+ loadfailout:
+    PrintError("Failed to load pit\n");
+    return -1;
 }
 #endif
 
@@ -735,7 +818,11 @@ static int pit_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
 
     pit_state = (struct pit *)V3_Malloc(sizeof(struct pit));
 
-    V3_ASSERT(pit_state != NULL);
+    if (!pit_state) {
+       PrintError("Cannot allocate in init\n");
+       return -1;
+    }
+
     pit_state->speaker = 0;
     pit_state->vm = vm;