📄 main.uc
字号:
/****************************************************************************
* I N T E L P R O P R I E T A R Y
*
* COPYRIGHT (c) 2001-2002 BY INTEL CORPORATION. ALL RIGHTS
* RESERVED. NO PART OF THIS PROGRAM OR PUBLICATION MAY
* BE REPRODUCED, TRANSMITTED, TRANSCRIBED, STORED IN A
* RETRIEVAL SYSTEM, OR TRANSLATED INTO ANY LANGUAGE OR COMPUTER
* LANGUAGE IN ANY FORM OR BY ANY MEANS, ELECTRONIC, MECHANICAL,
* MAGNETIC, OPTICAL, CHEMICAL, MANUAL, OR OTHERWISE, WITHOUT
* THE PRIOR WRITTEN PERMISSION OF :
*
* INTEL CORPORATION
*
* 2200 MISSION COLLEGE BLVD
*
* SANTA CLARA, CALIFORNIA 95052-8119
*
*--------------------------------------------------------------------------
* File Name: main.uc
*
* Purpose: This file illustrates the sample usage for CAM Sharing APIs in
* microcode.
*
* History:
* Date Comment By
* --------------------------------------------------------------------
* 11/05/2003 Created
*
****************************************************************************/
//------------------------------------------------------------------------
// Consider the contents in this main_cam_sharing.uc file as part
// of one of the microblocks which is sharing CAM.
//
// This is a typical way the microblock running on one ME uses CAM.
//------------------------------------------------------------------------
#define CAM_SHARED // It should be defined before
// #include ixp_cam.uc
#include "dl_system.h" // Application dispatch loop header file
#include "cam_sharing.uc"
#define CAM_STATE_INIT 0 // used for initialization
#define CAM_STATE_VALID 1 // not used now
#define CAM_ENTRY_SHF_VAL 3 // shift value to get cam entry
// from the lookup result
#define RXC_LM_HANDLE 0 // LM Handle used to access RXC
#define RXC_INFO_LM_BASE 0 // RXC base in LM
//------------------------------------------------------------------------
// Register Declaration
//------------------------------------------------------------------------
.reg next_thread_sig_val // The value to signal the next thread
//------------------------------------------------------------------------
// Signal Declaration
//------------------------------------------------------------------------
.sig volatile next_thread_sig // Inter context signal, (volatile required
// as it is used for inter-context signalling)
//------------------------------------------------------------------------
// Internal microblock macros
//------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// aal2_rx_cam_init
//
// Description:
// Initialize CAM entries and their associated structures in LM for this block.
//
///////////////////////////////////////////////////////////////////////////
#macro aal2_rx_cam_init(in_bid, in_num_entries, in_first_entry)
.begin
.reg entry_num
.reg src_key
.reg tag
alu[entry_num, --, B, 0x0]
immed[src_key, 1]
// Initialize CAM entry and its associated structure in LM.
.while(entry_num < in_num_entries)
// Initialize CAM entry
cam_entry_write(entry_num, src_key, CAM_STATE_INIT, AAL2_RX_CAM_HANDLE)
alu[entry_num, entry_num, +, 1]
alu[src_key, src_key, +, 1]
// Initialize the LM ....
.endw
.end
#endm
//////////////////////////////////////////////////////////////////////////
// aal2_rx_set_nxt_thd_reg
//
// Description:
// Initialize the reg with the next thread signal value
//
///////////////////////////////////////////////////////////////////////////
#macro aal2_rx_set_nxt_thd_reg()
.begin
.reg tmp
// [7] = 1, next context 0->1...7->0, [6:3] = signal_number
immed[tmp, 0x80]
alu_shf[next_thread_sig_val, tmp, OR, &next_thread_sig, <<3]
.end
#endm
///////////////////////////////////////////////////////////////////////////
// aal2_rx_signal_ctx
//
// Description: Signals any context within the same ME. It takes
// the exact argument that will be used to write to the SAME_ME_SIGNAL CSR.
//
///////////////////////////////////////////////////////////////////////////
#macro aal2_rx_signal_ctx(in_sig_val)
local_csr_wr[SAME_ME_SIGNAL, in_sig_val]
#endm
//------------------------------------------------------------------------
// Main code
//------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////////
// Main: CAM API usage
//
// 1st iteration of while(1)
// Thd0 - CAM Miss
// others - CAM Hit
//
// 2nd iteration of while(1)
// Thd0 - CAM Hit (cam_tag matches but cam entry is free)
// others - CAM Hit
//
/////////////////////////////////////////////////////////////////////////////////
MAIN#:
.begin
.reg tmp
//------------------------------------------------------------------------
// Microblock Init
//------------------------------------------------------------------------
// Thread0 specific init
br!=ctx[0, NOT_THD_0#]
// Initialize CAM variables and clear all CAM entries.
cam_init()
// Initialize LM and CAM entries to some unique values.
aal2_rx_cam_init(AAL2_RX_CAM_HANDLE)
// Thread0 does self-signal to kick start
// [3-6] = signal num ; [0-2] = context num, which is 0 here.
alu_shf[tmp, --,B, &next_thread_sig, <<3]
local_csr_wr[same_me_signal, tmp]
NOT_THD_0#:
// Set up the value for next thread signalling
aal2_rx_set_nxt_thd_reg()
//------------------------------------------------------------------------
// Microblock Main Loop
//------------------------------------------------------------------------
.while(1)
.begin
.reg lookup_result
.reg src_key
.reg cam_entry
.reg cam_tag
.reg cam_state
// Form the src key
alu[src_key, --, B, 0xa]
// Do a cam lookup based on src key
// lookup_result has microblock specific cam entry number.
cam_entry_lookup(lookup_result, src_key, AAL2_RX_CAM_HANDLE)
// Following macro does the cam lookup and also sets the LM handle to point
// to the data structure in LM according to the cam entry
// cam_entry_lookup_with_lm(lookup_result, src_key, RXC_LM_HANDLE, RXC_INFO_LM_BASE, \
// AAL2_RX_CAM_HANDLE)
// Check for cam_hit or cam_miss.
br_bset[lookup_result, 7, CAM_HIT#], defer[1]
// Get the microblock specific cam entry.
alu_shf[cam_entry, 0xf, and, lookup_result, >>CAM_ENTRY_SHF_VAL]
CAM_MISS#:
// Update the CAM tag with src key.
cam_entry_write(cam_entry, src_key, CAM_STATE_VALID, AAL2_RX_CAM_HANDLE)
// Flush the old data structure from LM location pointed to by the
// the CAM entry
// Read in the new data structure in LM
// Do something and wait
ctx_arb[next_thread_sig]
// Signal the next thread.
aal2_rx_signal_ctx(next_thread_sig_val)
br[COMMON_CODE#]
CAM_HIT#:
// Do something and wait
ctx_arb[next_thread_sig]
// Signal the next thread.
aal2_rx_signal_ctx(next_thread_sig_val)
COMMON_CODE#:
// Common code for miss and hit
// Mark the end of critical section.
// So here the thread notifies that it is done using CAM entry.
cam_exit_using_entry(cam_entry, AAL2_RX_CAM_HANDLE)
/////////////////////////////////////////
// Usage for rest of the API
/////////////////////////////////////////
cam_entry_read_tag(cam_tag, cam_entry, AAL2_RX_CAM_HANDLE)
cam_entry_read_state(cam_state, cam_entry, AAL2_RX_CAM_HANDLE)
cam_entry_write_state(cam_entry, CAM_STATE_VALID, AAL2_RX_CAM_HANDLE)
// Clear the microblock specific bit_vector (if needed)
//br!=ctx[7, NOT_THD_7#]
// ixp_cam_clear(AAL2_RX_CAM_HANDLE)
//NOT_THD_7#:
// Do something and wait
ctx_arb[next_thread_sig]
// Signal the next thread.
aal2_rx_signal_ctx(next_thread_sig_val)
.end
.endw // End of while(1)
.end // MAIN#
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -