Library mcertikos.proc.PSleeperCSource

Require Import Coqlib.
Require Import AST.
Require Import Integers.
Require Import Values.
Require Import Cop.
Require Import Clight.
Require Import CDataTypes.
Require Import Ctypes.

#define num_proc 1024
#define num_chan 266137

#define TSTATE_READY 0
#define TSTATE_RUN 1
#define TSTATE_SLEEP 2
#define TSTATE_DEAD 3

struct TCB_node{
    unsigned int state;
    unsigned int cpu_id;
    unsigned int prev;
    unsigned int next;
};

struct TDQ_node{
    unsigned int head;
    unsigned int tail;
};

struct TCB{
    struct TCB_node TCB_pool[num_proc];
    struct TDQ_node TDQ_pool[num_chan];
};

extern struct TCB TCBPool_LOC;

void
tcb_init(unsigned int proc_index)
{
    TCBPool_LOC.TCB_pool[proc_index].state = TSTATE_DEAD;
    TCBPool_LOC.TCB_pool[proc_index].cpu_id = 0;
    TCBPool_LOC.TCB_pool[proc_index].prev = num_proc;
    TCBPool_LOC.TCB_pool[proc_index].next = num_proc;
}

void
tdq_init(unsigned int chan_index)
{
    TCBPool_LOC.TDQ_pool[chan_index].head = num_proc;
    TCBPool_LOC.TDQ_pool[chan_index].tail = num_proc;
}

unsigned int
tcb_get_state(unsigned int proc_index)
{
    return TCBPool_LOC.TCB_pool[proc_index].state;
}

void
tcb_set_state(unsigned int proc_index, unsigned int state)
{
    TCBPool_LOC.TCB_pool[proc_index].state = state;
}

unsigned int
tcb_get_CPU_ID_state(unsigned int proc_index)
{
    return TCBPool_LOC.TCB_pool[proc_index].cpu_id;
}

void
tcb_set_CPU_ID_state(unsigned int proc_index, unsigned int cpu_id)
{
    TCBPool_LOC.TCB_pool[proc_index].cpu_id = cpu_id;
}

unsigned int
tcb_get_prev(unsigned int proc_index)
{
    return TCBPool_LOC.TCB_pool[proc_index].prev;
}

void
tcb_set_prev(unsigned int proc_index, unsigned int prev)
{
    TCBPool_LOC.TCB_pool[proc_index].prev = prev;
}

unsigned int
tcb_get_next(unsigned int proc_index)
{
    return TCBPool_LOC.TCB_pool[proc_index].next;
}

void
tcb_set_next(unsigned int proc_index, unsigned int next)
{
    TCBPool_LOC.TCB_pool[proc_index].next = next;
}

unsigned int
tdq_get_head(unsigned int chan_index)
{
    return TCBPool_LOC.TDQ_pool[chan_index].head;
}

void
tdq_set_head(unsigned int chan_index, unsigned int head)
{
    TCBPool_LOC.TDQ_pool[chan_index].head = head;
}

unsigned int
tdq_get_tail(unsigned int chan_index)
{
    return TCBPool_LOC.TDQ_pool[chan_index].tail;
}

void
tdq_set_tail(unsigned int chan_index, unsigned int tail)
{
    TCBPool_LOC.TDQ_pool[chan_index].tail = tail;
}
Notation TSTATE_READY := 0.
Notation TSTATE_RUN := 1.
Notation TSTATE_SLEEP := 2.
Notation TSTATE_DEAD := 3.

Definition _proc_index : ident := 10%positive.
Definition _chan_index : ident := 11%positive.
Definition _state : ident := 12%positive.
Definition _cpu_id : ident := 13%positive.
Definition _prev : ident := 14%positive.
Definition _next :ident := 15%positive.
Definition _head : ident := 16%positive.
Definition _tail : ident := 17%positive.

tcb_init function

Definition f_tcb_init_body :=
  (Ssequence
     (Sassign
        (Efield
           (Ederef
              (Ebinop Oadd
                      (Efield (Evar TCBPool_LOC t_struct_TCB) TCB_pool
                              (tarray t_struct_TCB_node num_proc)) (Etempvar _proc_index tuint)
                      (tptr t_struct_TCB_node)) t_struct_TCB_node) state tuint)
        (Econst_int (Int.repr TSTATE_DEAD) tint))
     (Ssequence
        (Sassign
           (Efield
              (Ederef
                 (Ebinop Oadd
                         (Efield (Evar TCBPool_LOC t_struct_TCB) TCB_pool
                                 (tarray t_struct_TCB_node num_proc)) (Etempvar _proc_index tuint)
                         (tptr t_struct_TCB_node)) t_struct_TCB_node) cpu_id tuint)
           (Econst_int (Int.repr 0) tint))
        (Ssequence
           (Sassign
              (Efield
                 (Ederef
                    (Ebinop Oadd
                            (Efield (Evar TCBPool_LOC t_struct_TCB) TCB_pool
                                    (tarray t_struct_TCB_node num_proc)) (Etempvar _proc_index tuint)
                            (tptr t_struct_TCB_node)) t_struct_TCB_node) prev tuint)
              (Econst_int (Int.repr num_proc) tint))
           (Sassign
              (Efield
                 (Ederef
                    (Ebinop Oadd
                            (Efield (Evar TCBPool_LOC t_struct_TCB) TCB_pool
                                    (tarray t_struct_TCB_node num_proc)) (Etempvar _proc_index tuint)
                            (tptr t_struct_TCB_node)) t_struct_TCB_node) next tuint)
              (Econst_int (Int.repr num_proc) tint))))).

Definition f_tcb_init :=
  {|
    fn_return := tvoid;
    fn_callconv := cc_default;
    fn_params := ((_proc_index, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tcb_init_body
  |}.

tdq_init function

Definition f_tdq_init_body :=
  (Ssequence
     (Sassign
        (Efield
           (Ederef
              (Ebinop Oadd
                      (Efield (Evar TCBPool_LOC t_struct_TCB) TDQ_pool
                              (tarray t_struct_TDQ_node num_chan)) (Etempvar _chan_index tuint)
                      (tptr t_struct_TDQ_node)) t_struct_TDQ_node) head tuint)
        (Econst_int (Int.repr num_proc) tint))
     (Sassign
        (Efield
           (Ederef
              (Ebinop Oadd
                      (Efield (Evar TCBPool_LOC t_struct_TCB) TDQ_pool
                              (tarray t_struct_TDQ_node num_chan)) (Etempvar _chan_index tuint)
                      (tptr t_struct_TDQ_node)) t_struct_TDQ_node) tail tuint)
        (Econst_int (Int.repr num_proc) tint))).

Definition f_tdq_init :=
  {|
    fn_return := tvoid;
    fn_callconv := cc_default;
    fn_params := ((_chan_index, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tdq_init_body
  |}.

tcb_get_state

Definition f_tcb_get_state_body :=
  (Sreturn (Some (Efield
                    (Ederef
                       (Ebinop Oadd
                               (Efield (Evar TCBPool_LOC t_struct_TCB) TCB_pool
                                       (tarray t_struct_TCB_node num_proc))
                               (Etempvar _proc_index tuint) (tptr t_struct_TCB_node))
                       t_struct_TCB_node) state tuint))).

Definition f_tcb_get_state :=
  {|
    fn_return := tuint;
    fn_callconv := cc_default;
    fn_params := ((_proc_index, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tcb_get_state_body
  |}.

tcb_set_state function

Definition f_tcb_set_state_body :=
  (Sassign
     (Efield
        (Ederef
           (Ebinop Oadd
                   (Efield (Evar TCBPool_LOC t_struct_TCB) TCB_pool
                           (tarray t_struct_TCB_node num_proc)) (Etempvar _proc_index tuint)
                   (tptr t_struct_TCB_node)) t_struct_TCB_node) state tuint)
     (Etempvar _state tuint)).

Definition f_tcb_set_state :=
  {|
    fn_return := tvoid;
    fn_callconv := cc_default;
    fn_params := ((_proc_index, tuint) :: (_state, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tcb_set_state_body
  |}.

tcb_get_CPU_ID_state function

Definition f_tcb_get_CPU_ID_state_body :=
  (Sreturn (Some (Efield
                    (Ederef
                       (Ebinop Oadd
                               (Efield (Evar TCBPool_LOC t_struct_TCB) TCB_pool
                                       (tarray t_struct_TCB_node num_proc))
                               (Etempvar _proc_index tuint) (tptr t_struct_TCB_node))
                       t_struct_TCB_node) cpu_id tuint))).

Definition f_tcb_get_CPU_ID_state :=
  {|
    fn_return := tuint;
    fn_callconv := cc_default;
    fn_params := ((_proc_index, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tcb_get_CPU_ID_state_body
  |}.

tcb_set_CPU_ID_state function

Definition f_tcb_set_CPU_ID_state_body :=
  (Sassign
     (Efield
        (Ederef
           (Ebinop Oadd
                   (Efield (Evar TCBPool_LOC t_struct_TCB) TCB_pool
                           (tarray t_struct_TCB_node num_proc)) (Etempvar _proc_index tuint)
                   (tptr t_struct_TCB_node)) t_struct_TCB_node) cpu_id tuint)
     (Etempvar _cpu_id tuint)).

Definition f_tcb_set_CPU_ID_state :=
  {|
    fn_return := tvoid;
    fn_callconv := cc_default;
    fn_params := ((_proc_index, tuint) :: (_cpu_id, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tcb_set_CPU_ID_state_body
  |}.

tcb_get_prev function

Definition f_tcb_get_prev_body :=
  (Sreturn (Some (Efield
                    (Ederef
                       (Ebinop Oadd
                               (Efield (Evar TCBPool_LOC t_struct_TCB) TCB_pool
                                       (tarray t_struct_TCB_node num_proc))
                               (Etempvar _proc_index tuint) (tptr t_struct_TCB_node))
                       t_struct_TCB_node) prev tuint))).

Definition f_tcb_get_prev :=
  {|
    fn_return := tuint;
    fn_callconv := cc_default;
    fn_params := ((_proc_index, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tcb_get_prev_body
  |}.

tcb_set_prev function
Definition f_tcb_set_prev_body :=
  (Sassign
     (Efield
        (Ederef
           (Ebinop Oadd
                   (Efield (Evar TCBPool_LOC t_struct_TCB) TCB_pool
                           (tarray t_struct_TCB_node num_proc)) (Etempvar _proc_index tuint)
                   (tptr t_struct_TCB_node)) t_struct_TCB_node) prev tuint)
     (Etempvar _prev tuint)).

Definition f_tcb_set_prev :=
  {|
    fn_return := tvoid;
    fn_callconv := cc_default;
    fn_params := ((_proc_index, tuint) :: (_prev, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tcb_set_prev_body
  |}.

tcb_get_next function

Definition f_tcb_get_next_body :=
  (Sreturn (Some (Efield
                    (Ederef
                       (Ebinop Oadd
                               (Efield (Evar TCBPool_LOC t_struct_TCB) TCB_pool
                       (tarray t_struct_TCB_node num_proc))
                               (Etempvar _proc_index tuint) (tptr t_struct_TCB_node))
                       t_struct_TCB_node) next tuint))).

Definition f_tcb_get_next :=
  {|
    fn_return := tuint;
    fn_callconv := cc_default;
    fn_params := ((_proc_index, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tcb_get_next_body
  |}.

tcb_set_next function

Definition f_tcb_set_next_body :=
  (Sassign
     (Efield
        (Ederef
           (Ebinop Oadd
                   (Efield (Evar TCBPool_LOC t_struct_TCB) TCB_pool
                           (tarray t_struct_TCB_node num_proc)) (Etempvar _proc_index tuint)
                   (tptr t_struct_TCB_node)) t_struct_TCB_node) next tuint)
     (Etempvar _next tuint)).

Definition f_tcb_set_next :=
  {|
    fn_return := tvoid;
    fn_callconv := cc_default;
    fn_params := ((_proc_index, tuint) :: (_next, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tcb_set_next_body
  |}.

tdq_get_head function

Definition f_tdq_get_head_body :=
  (Sreturn (Some (Efield
                    (Ederef
                       (Ebinop Oadd
                               (Efield (Evar TCBPool_LOC t_struct_TCB) TDQ_pool
                                       (tarray t_struct_TDQ_node num_chan))
                               (Etempvar _chan_index tuint) (tptr t_struct_TDQ_node))
                       t_struct_TDQ_node) head tuint))).

Definition f_tdq_get_head :=
  {|
    fn_return := tuint;
    fn_callconv := cc_default;
    fn_params := ((_chan_index, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tdq_get_head_body
  |}.

tdq_set_head function

Definition f_tdq_set_head_body :=
  (Sassign
     (Efield
        (Ederef
           (Ebinop Oadd
                   (Efield (Evar TCBPool_LOC t_struct_TCB) TDQ_pool
                           (tarray t_struct_TDQ_node num_chan)) (Etempvar _chan_index tuint)
                   (tptr t_struct_TDQ_node)) t_struct_TDQ_node) head tuint)
     (Etempvar _head tuint)).

Definition f_tdq_set_head :=
  {|
    fn_return := tvoid;
    fn_callconv := cc_default;
    fn_params := ((_chan_index, tuint) :: (_head, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tdq_set_head_body
  |}.

tdq_get_tail function

Definition f_tdq_get_tail_body :=
  (Sreturn (Some (Efield
                    (Ederef
                       (Ebinop Oadd
                               (Efield (Evar TCBPool_LOC t_struct_TCB) TDQ_pool
                                       (tarray t_struct_TDQ_node num_chan))
                               (Etempvar _chan_index tuint) (tptr t_struct_TDQ_node))
                       t_struct_TDQ_node) tail tuint))).

Definition f_tdq_get_tail :=
  {|
    fn_return := tuint;
    fn_callconv := cc_default;
    fn_params := ((_chan_index, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tdq_get_tail_body
  |}.

tdq_set_tail function

Definition f_tdq_set_tail_body :=
  (Sassign
     (Efield
        (Ederef
           (Ebinop Oadd
        (Efield (Evar TCBPool_LOC t_struct_TCB) TDQ_pool
                (tarray t_struct_TDQ_node num_chan)) (Etempvar _chan_index tuint)
        (tptr t_struct_TDQ_node)) t_struct_TDQ_node) tail tuint)
     (Etempvar _tail tuint)).

Definition f_tdq_set_tail :=
  {|
    fn_return := tvoid;
    fn_callconv := cc_default;
    fn_params := ((_chan_index, tuint) :: (_tail, tuint) :: nil);
    fn_vars := nil;
    fn_temps := nil;
    fn_body := f_tdq_set_tail_body
  |}.