17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Segment:offset types and macros 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * Initially written by Michael Brown (mcb30). 57c478bd9Sstevel@tonic-gate */ 67c478bd9Sstevel@tonic-gate 77c478bd9Sstevel@tonic-gate #ifndef SEGOFF_H 87c478bd9Sstevel@tonic-gate #define SEGOFF_H 97c478bd9Sstevel@tonic-gate 107c478bd9Sstevel@tonic-gate #include <stdint.h> 117c478bd9Sstevel@tonic-gate #include <io.h> 127c478bd9Sstevel@tonic-gate 137c478bd9Sstevel@tonic-gate /* Segment:offset structure. Note that the order within the structure 147c478bd9Sstevel@tonic-gate * is offset:segment. 157c478bd9Sstevel@tonic-gate */ 167c478bd9Sstevel@tonic-gate typedef struct { 177c478bd9Sstevel@tonic-gate uint16_t offset; 187c478bd9Sstevel@tonic-gate uint16_t segment; 197c478bd9Sstevel@tonic-gate } segoff_t; 207c478bd9Sstevel@tonic-gate 217c478bd9Sstevel@tonic-gate /* For PXE stuff */ 227c478bd9Sstevel@tonic-gate typedef segoff_t SEGOFF16_t; 237c478bd9Sstevel@tonic-gate 247c478bd9Sstevel@tonic-gate /* Macros for converting from virtual to segment:offset addresses, 257c478bd9Sstevel@tonic-gate * when we don't actually care which of the many isomorphic results we 267c478bd9Sstevel@tonic-gate * get. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate #ifdef DEBUG_SEGMENT SEGMENT(const void * const ptr)297c478bd9Sstevel@tonic-gateuint16_t SEGMENT ( const void * const ptr ) { 307c478bd9Sstevel@tonic-gate uint32_t phys = virt_to_phys ( ptr ); 317c478bd9Sstevel@tonic-gate if ( phys > 0xfffff ) { 327c478bd9Sstevel@tonic-gate printf ( "FATAL ERROR: segment address out of range\n" ); 337c478bd9Sstevel@tonic-gate } 347c478bd9Sstevel@tonic-gate return phys >> 4; 357c478bd9Sstevel@tonic-gate } 367c478bd9Sstevel@tonic-gate #else 377c478bd9Sstevel@tonic-gate #define SEGMENT(x) ( virt_to_phys ( x ) >> 4 ) 387c478bd9Sstevel@tonic-gate #endif 397c478bd9Sstevel@tonic-gate #define OFFSET(x) ( virt_to_phys ( x ) & 0xf ) 407c478bd9Sstevel@tonic-gate #define SEGOFF(x) { OFFSET(x), SEGMENT(x) } 417c478bd9Sstevel@tonic-gate #define VIRTUAL(x,y) ( phys_to_virt ( ( ( x ) << 4 ) + ( y ) ) ) 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #endif /* SEGOFF_H */ 44