/* The following example assumes a special machine with three hardware locations. There is an input data buffer at 0xFFFFFF20 There is an output data buffer at 0xFFFFFF24 There is a control data buffer at 0xFFFFFF28 The third-least-significant bit set in the control buffer indicates there is data in the input buffer. This bit is unset when the data is read out of the input buffer by the program. The second-least-significant bit set in the control buffer indicates the output device is ready to accept output data. This bit is unset when the data is placed in the output buffer and is read out. */ typedef unsigned long datatype, controltype, counttype; #define CONTROLLER ((const volatile controltype *const) 0xFFFFFF28) #define INPUT_BUF ((const volatile datatype *const) 0xFFFFFF20) #define OUTPUT_BUF ((volatile datatype *const) 0xFFFFFF24) #define INPUT_READY_BIT 0x4 #define OUTPUT_READY_BIT 0x2 #define INPUT_READY ((*CONTROLLER) & INPUT_READY_BIT) #define OUTPUT_READY ((*CONTROLLER) & OUTPUT_READY_BIT) /* The function copy_data copies data from the input buffer to the output buffer until an input value of 0 is seen. The number of characters copied is returned. */ /* Make count of the input global so that other CPUs can access it */ counttype volatile count=0; counttype copy_data() { datatype temp; for(;;) { while (!INPUT_READY); /* Wait for input */ temp=*INPUT_BUF; __iospace_eieio(); /* synchronize the I/O */ if (temp==0) return count; while (!OUTPUT_READY); /* Wait for output */ *OUTPUT_BUF=temp; __iospace_eieio(); /* synchronize the I/O */ count++; __iospace_sync(); /* synchronize the CPU */ /* for count to allow */ /* other CPUs to /* access it */ } }
Example of Multiple Writes to a Single
Register
Implementation Dependencies
Overview
Synchronization of Stores and Loads
to I/O Space