Merge branch 'master' of git://github.com/illumos/illumos-gate
[unleashed.git] / usr / src / grub / grub-0.97 / netboot / segoff.h
blob958de63f4325b1498b049f1ee3726e1bf82a52c7
1 /*
2 * Segment:offset types and macros
4 * Initially written by Michael Brown (mcb30).
5 */
7 #ifndef SEGOFF_H
8 #define SEGOFF_H
10 #include <stdint.h>
11 #include <io.h>
13 /* Segment:offset structure. Note that the order within the structure
14 * is offset:segment.
16 typedef struct {
17 uint16_t offset;
18 uint16_t segment;
19 } segoff_t;
21 /* For PXE stuff */
22 typedef segoff_t SEGOFF16_t;
24 /* Macros for converting from virtual to segment:offset addresses,
25 * when we don't actually care which of the many isomorphic results we
26 * get.
28 #ifdef DEBUG_SEGMENT
29 uint16_t SEGMENT ( const void * const ptr ) {
30 uint32_t phys = virt_to_phys ( ptr );
31 if ( phys > 0xfffff ) {
32 printf ( "FATAL ERROR: segment address out of range\n" );
34 return phys >> 4;
36 #else
37 #define SEGMENT(x) ( virt_to_phys ( x ) >> 4 )
38 #endif
39 #define OFFSET(x) ( virt_to_phys ( x ) & 0xf )
40 #define SEGOFF(x) { OFFSET(x), SEGMENT(x) }
41 #define VIRTUAL(x,y) ( phys_to_virt ( ( ( x ) << 4 ) + ( y ) ) )
43 #endif /* SEGOFF_H */