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.


Lots of pedantic error checking in Palacios proper, especially for memory
[palacios.git] / palacios / src / devices / 8254.c
index fcde0a1..d7659f8 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;
@@ -608,11 +609,6 @@ static int pit_write_command(struct guest_info * core, ushort_t port, void * src
        return -1;
     }
 
-    if (cmd->op_mode == 0) {
-      V3_Print("SETTING PIT MODE TO 0!!!!!\n");
-      v3_print_guest_state(core);
-    }
-
     switch (cmd->channel) {
        case 0:
            if (handle_channel_cmd(&(state->ch_0), *cmd) == -1) {
@@ -687,65 +683,39 @@ static int pit_free(void * private_data) {
     return 0;
 }
 
-#ifdef V3_CONFIG_KEYED_STREAMS
-static int pit_checkpoint(struct vm_device *dev, v3_keyed_stream_t stream)
-{
-    struct pit *p = (struct pit *) (dev->private_data);
+#ifdef V3_CONFIG_CHECKPOINT
+static int pit_save(struct v3_chkpt_ctx * ctx, void * private_data) {
+    struct pit * pit_state = (struct pit *)private_data; 
 
-    v3_keyed_stream_key_t ks;
-
-    ks = v3_keyed_stream_open_key(stream,dev->name);
-
-    if (!ks) { 
-       return -1;
-    }
-
-    STD_SAVE(stream,ks,p->pit_counter);
-    STD_SAVE(stream,ks,p->pit_reload);
-    STD_SAVE(stream,ks,p->ch_0);
-    STD_SAVE(stream,ks,p->ch_1);
-    STD_SAVE(stream,ks,p->ch_2);
-    STD_SAVE(stream,ks,p->speaker);
-
-    v3_keyed_stream_close_key(stream,ks);
+    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);
     
     return 0;
-
-
 }
 
-static int pit_restore(struct vm_device *dev, v3_keyed_stream_t stream)
-{
-    struct pit *p = (struct pit *) (dev->private_data);
+static int pit_load(struct v3_chkpt_ctx * ctx, void * private_data) {
+    struct pit * pit_state = (struct pit *)private_data;
 
-    v3_keyed_stream_key_t ks;
+    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);
 
-    ks = v3_keyed_stream_open_key(stream,dev->name);
-
-    if (!ks) { 
-       return -1;
-    }
-
-    STD_LOAD(stream,ks,p->pit_counter);
-    STD_LOAD(stream,ks,p->pit_reload);
-    STD_LOAD(stream,ks,p->ch_0);
-    STD_LOAD(stream,ks,p->ch_1);
-    STD_LOAD(stream,ks,p->ch_2);
-    STD_LOAD(stream,ks,p->speaker);
-
-    v3_keyed_stream_close_key(stream,ks);
-    
     return 0;
-
-
 }
 #endif
 
 static struct v3_device_ops dev_ops = {
     .free = (int (*)(void *))pit_free,
-#ifdef V3_CONFIG_KEYED_STREAMS
-    .checkpoint = pit_checkpoint,
-    .restore = pit_restore,
+#ifdef V3_CONFIG_CHECKPOINT
+    .save = pit_save,
+    .load = pit_load,
 #endif
 };
 
@@ -766,7 +736,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;