kvm tools: Add ivshmem device
[linux-2.6/next.git] / tools / kvm / bios / int10.c
blob22da9fa0f92857ee41f4624f8940cb0b14a29355
1 #include "kvm/segment.h"
2 #include "kvm/bios.h"
3 #include "kvm/util.h"
4 #include "kvm/vesa.h"
5 #include <stdint.h>
7 #define VESA_MAGIC ('V' + ('E' << 8) + ('S' << 16) + ('A' << 24))
9 /* VESA General Information table */
10 struct vesa_general_info {
11 u32 signature; /* 0 Magic number = "VESA" */
12 u16 version; /* 4 */
13 void *vendor_string; /* 6 */
14 u32 capabilities; /* 10 */
15 void *video_mode_ptr; /* 14 */
16 u16 total_memory; /* 18 */
17 u16 modes[2]; /* 20 */
18 char oem_string[11]; /* 24 */
20 u8 reserved[223]; /* 35 */
21 } __attribute__ ((packed));
23 struct vminfo {
24 u16 mode_attr; /* 0 */
25 u8 win_attr[2]; /* 2 */
26 u16 win_grain; /* 4 */
27 u16 win_size; /* 6 */
28 u16 win_seg[2]; /* 8 */
29 u32 win_scheme; /* 12 */
30 u16 logical_scan; /* 16 */
32 u16 h_res; /* 18 */
33 u16 v_res; /* 20 */
34 u8 char_width; /* 22 */
35 u8 char_height; /* 23 */
36 u8 memory_planes; /* 24 */
37 u8 bpp; /* 25 */
38 u8 banks; /* 26 */
39 u8 memory_layout; /* 27 */
40 u8 bank_size; /* 28 */
41 u8 image_planes; /* 29 */
42 u8 page_function; /* 30 */
44 u8 rmask; /* 31 */
45 u8 rpos; /* 32 */
46 u8 gmask; /* 33 */
47 u8 gpos; /* 34 */
48 u8 bmask; /* 35 */
49 u8 bpos; /* 36 */
50 u8 resv_mask; /* 37 */
51 u8 resv_pos; /* 38 */
52 u8 dcm_info; /* 39 */
54 u32 lfb_ptr; /* 40 Linear frame buffer address */
55 u32 offscreen_ptr; /* 44 Offscreen memory address */
56 u16 offscreen_size; /* 48 */
58 u8 reserved[206]; /* 50 */
61 static inline void outb(unsigned short port, unsigned char val)
63 asm volatile("outb %0, %1" : : "a"(val), "Nd"(port));
67 * It's probably much more useful to make this print to the serial
68 * line rather than print to a non-displayed VGA memory
70 static inline void int10_putchar(struct biosregs *args)
72 u8 al = args->eax & 0xFF;
74 outb(0x3f8, al);
77 static void vbe_get_mode(struct biosregs *args)
79 struct vminfo *info = (struct vminfo *) args->edi;
81 *info = (struct vminfo) {
82 .mode_attr = 0xd9, /* 11011011 */
83 .logical_scan = VESA_WIDTH*4,
84 .h_res = VESA_WIDTH,
85 .v_res = VESA_HEIGHT,
86 .bpp = VESA_BPP,
87 .memory_layout = 6,
88 .memory_planes = 1,
89 .lfb_ptr = VESA_MEM_ADDR,
90 .rmask = 8,
91 .gmask = 8,
92 .bmask = 8,
93 .resv_mask = 8,
94 .resv_pos = 24,
95 .bpos = 16,
96 .gpos = 8,
100 static void vbe_get_info(struct biosregs *args)
102 struct vesa_general_info *info = (struct vesa_general_info *) args->edi;
104 *info = (struct vesa_general_info) {
105 .signature = VESA_MAGIC,
106 .version = 0x102,
107 .vendor_string = &info->oem_string,
108 .capabilities = 0x10,
109 .video_mode_ptr = &info->modes,
110 .total_memory = (4 * VESA_WIDTH * VESA_HEIGHT) / 0x10000,
111 .oem_string = "KVM VESA",
112 .modes = { 0x0112, 0xffff },
116 #define VBE_STATUS_OK 0x004F
118 static void int10_vesa(struct biosregs *args)
120 u8 al;
122 al = args->eax & 0xff;
124 switch (al) {
125 case 0x00:
126 vbe_get_info(args);
127 break;
128 case 0x01:
129 vbe_get_mode(args);
130 break;
133 args->eax = VBE_STATUS_OK;
136 bioscall void int10_handler(struct biosregs *args)
138 u8 ah;
140 ah = (args->eax & 0xff00) >> 8;
142 switch (ah) {
143 case 0x0e:
144 int10_putchar(args);
145 break;
146 case 0x4f:
147 int10_vesa(args);
148 break;