/**********
 * Copyright (c) 2003-2004 Greg Parker.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY GREG PARKER ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 **********/

#ifndef ARMSTUBS_H
#define ARMSTUBS_H

#define MAX_PARAMS 6
#define MAX_GLOBALS 10

// 6 parameters for some BN functions
// 10 globals for AES

#include <stdint.h>


typedef struct {
    void *emulState;     // set on ARM side
    void *call68K;       // set on ARM side
    uint32_t global[MAX_GLOBALS];
} pace_globals;

typedef struct {
    pace_globals *globals;
    uint32_t fn;
    uint32_t param[MAX_PARAMS];
} pace_args;

int init_arm(void);

uint32_t dispatch_to_arm(uint32_t fn, pace_globals *globals, uint32_t *param, int paramCount);

enum {
    BN_FIRST_ID = 0, 
    BN_is_negative_id, 
    BN_CTX_new_id, 
    BN_CTX_free_id, 
    BN_CTX_start_id, 
    BN_CTX_get_id, 
    BN_CTX_end_id, 
    BN_rand_id, 
    BN_num_bits_id, 
    BN_new_id, 
    BN_clear_free_id, 
    BN_bin2bn_id, 
    BN_bn2bin_id, 
    BN_cmp_id, 
    BN_free_id, 
    BN_is_bit_set_id, 
    BN_mod_exp_mont_id, 
    BN_mod_exp_mont_word_id, 
    BN_bn2hex_id, 
    BN_hex2bn_id, 
    BN_MONT_CTX_new_id, 
    BN_MONT_CTX_free_id, 
    BN_MONT_CTX_set_id, 
    BN_is_zero_id, 
    BN_mod_mul_id, 
    BN_ucmp_id, 
    BN_mod_inverse_id, 
    BN_div_id, 
    BN_add_id, 
    BN_sub_id, 
    BN_rand_range_id, 

#ifdef BNTEST
    BN_set_negative_id, 
    BN_bntest_rand_id, 
    BN_copy_id, 
    BN_set_bit_id, 
    BN_add_word_id, 
    BN_lshift_id, 
    BN_mul_id, 
    BN_RECP_CTX_new_id, 
    BN_sqr_id, 
    BN_nnmod_id, 
    BN_to_montgomery_id, 
    BN_from_montgomery_id, 
    BN_mod_mul_montgomery_id, 
    BN_mod_exp_id, 
    BN_exp_id, 
    BN_RECP_CTX_set_id, 
    BN_div_recp_id, 
    BN_RECP_CTX_free_id, 
    BN_set_word_id, 
#endif

    BN_time_id, // fixme
    BN_LAST_ID, 

    AES_FIRST_ID, 
    AES_set_encrypt_key_id, 
    AES_set_decrypt_key_id, 
    AES_cbc_encrypt_id, 
    AES_encrypt_id, 
    AES_LAST_ID
    
    
};

#endif

