xref: /titanic_52/usr/src/grub/grub-0.97/netboot/segoff.h (revision fca4268092e9961ebb9b5e0098dcebc545023586)
1 /*
2  * Segment:offset types and macros
3  *
4  * Initially written by Michael Brown (mcb30).
5  */
6 
7 #ifndef SEGOFF_H
8 #define SEGOFF_H
9 
10 #include <stdint.h>
11 #include <io.h>
12 
13 /* Segment:offset structure.  Note that the order within the structure
14  * is offset:segment.
15  */
16 typedef struct {
17 	uint16_t offset;
18 	uint16_t segment;
19 } segoff_t;
20 
21 /* For PXE stuff */
22 typedef segoff_t SEGOFF16_t;
23 
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.
27  */
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" );
33 	}
34 	return phys >> 4;
35 }
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 ) ) )
42 
43 #endif /* SEGOFF_H */
44