1N/A/*
1N/A * Segment:offset types and macros
1N/A *
1N/A * Initially written by Michael Brown (mcb30).
1N/A */
1N/A
1N/A#ifndef SEGOFF_H
1N/A#define SEGOFF_H
1N/A
1N/A#include <stdint.h>
1N/A#include <io.h>
1N/A
1N/A/* Segment:offset structure. Note that the order within the structure
1N/A * is offset:segment.
1N/A */
1N/Atypedef struct {
1N/A uint16_t offset;
1N/A uint16_t segment;
1N/A} segoff_t;
1N/A
1N/A/* For PXE stuff */
1N/Atypedef segoff_t SEGOFF16_t;
1N/A
1N/A/* Macros for converting from virtual to segment:offset addresses,
1N/A * when we don't actually care which of the many isomorphic results we
1N/A * get.
1N/A */
1N/A#ifdef DEBUG_SEGMENT
1N/Auint16_t SEGMENT ( const void * const ptr ) {
1N/A uint32_t phys = virt_to_phys ( ptr );
1N/A if ( phys > 0xfffff ) {
1N/A printf ( "FATAL ERROR: segment address out of range\n" );
1N/A }
1N/A return phys >> 4;
1N/A}
1N/A#else
1N/A#define SEGMENT(x) ( virt_to_phys ( x ) >> 4 )
1N/A#endif
1N/A#define OFFSET(x) ( virt_to_phys ( x ) & 0xf )
1N/A#define SEGOFF(x) { OFFSET(x), SEGMENT(x) }
1N/A#define VIRTUAL(x,y) ( phys_to_virt ( ( ( x ) << 4 ) + ( y ) ) )
1N/A
1N/A#endif /* SEGOFF_H */