root / hw / vmport.c @ c171148c
History | View | Annotate | Download (2.8 kB)
1 | 0975c304 | ths | /*
|
---|---|---|---|
2 | 0975c304 | ths | * QEMU VMPort emulation
|
3 | 0975c304 | ths | *
|
4 | 0975c304 | ths | * Copyright (C) 2007 Herv? Poussineau
|
5 | 0975c304 | ths | *
|
6 | 0975c304 | ths | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 0975c304 | ths | * of this software and associated documentation files (the "Software"), to deal
|
8 | 0975c304 | ths | * in the Software without restriction, including without limitation the rights
|
9 | 0975c304 | ths | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 0975c304 | ths | * copies of the Software, and to permit persons to whom the Software is
|
11 | 0975c304 | ths | * furnished to do so, subject to the following conditions:
|
12 | 0975c304 | ths | *
|
13 | 0975c304 | ths | * The above copyright notice and this permission notice shall be included in
|
14 | 0975c304 | ths | * all copies or substantial portions of the Software.
|
15 | 0975c304 | ths | *
|
16 | 0975c304 | ths | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 0975c304 | ths | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 0975c304 | ths | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 0975c304 | ths | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 0975c304 | ths | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 0975c304 | ths | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 0975c304 | ths | * THE SOFTWARE.
|
23 | 0975c304 | ths | */
|
24 | 87ecb68b | pbrook | #include "hw.h" |
25 | 87ecb68b | pbrook | #include "isa.h" |
26 | 87ecb68b | pbrook | #include "pc.h" |
27 | 87ecb68b | pbrook | #include "sysemu.h" |
28 | 0975c304 | ths | |
29 | 0975c304 | ths | #define VMPORT_CMD_GETVERSION 0x0a |
30 | 0975c304 | ths | #define VMPORT_CMD_GETRAMSIZE 0x14 |
31 | 0975c304 | ths | |
32 | 0975c304 | ths | #define VMPORT_ENTRIES 0x2c |
33 | 0975c304 | ths | #define VMPORT_MAGIC 0x564D5868 |
34 | 0975c304 | ths | |
35 | 0975c304 | ths | typedef struct _VMPortState |
36 | 0975c304 | ths | { |
37 | 0975c304 | ths | IOPortReadFunc *func[VMPORT_ENTRIES]; |
38 | 0975c304 | ths | void *opaque[VMPORT_ENTRIES];
|
39 | 0975c304 | ths | } VMPortState; |
40 | 0975c304 | ths | |
41 | 0975c304 | ths | static VMPortState port_state;
|
42 | 0975c304 | ths | |
43 | 0975c304 | ths | void vmport_register(unsigned char command, IOPortReadFunc *func, void *opaque) |
44 | 0975c304 | ths | { |
45 | 0975c304 | ths | if (command >= VMPORT_ENTRIES)
|
46 | 0975c304 | ths | return;
|
47 | 0975c304 | ths | |
48 | 0975c304 | ths | port_state.func[command] = func; |
49 | 0975c304 | ths | port_state.opaque[command] = opaque; |
50 | 0975c304 | ths | } |
51 | 0975c304 | ths | |
52 | 0975c304 | ths | static uint32_t vmport_ioport_read(void *opaque, uint32_t addr) |
53 | 0975c304 | ths | { |
54 | 0975c304 | ths | VMPortState *s = opaque; |
55 | 26fb5e48 | aurel32 | CPUState *env = cpu_single_env; |
56 | 0975c304 | ths | unsigned char command; |
57 | 6dab28d5 | ths | uint32_t eax; |
58 | 0975c304 | ths | |
59 | 26fb5e48 | aurel32 | eax = env->regs[R_EAX]; |
60 | 0975c304 | ths | if (eax != VMPORT_MAGIC)
|
61 | 0975c304 | ths | return eax;
|
62 | 0975c304 | ths | |
63 | 26fb5e48 | aurel32 | command = env->regs[R_ECX]; |
64 | 0975c304 | ths | if (command >= VMPORT_ENTRIES)
|
65 | 0975c304 | ths | return eax;
|
66 | 0975c304 | ths | if (!s->func[command])
|
67 | 0975c304 | ths | { |
68 | 0975c304 | ths | printf("vmport: unknown command %x\n", command);
|
69 | 0975c304 | ths | return eax;
|
70 | 0975c304 | ths | } |
71 | 0975c304 | ths | |
72 | 0975c304 | ths | return s->func[command](s->opaque[command], addr);
|
73 | 0975c304 | ths | } |
74 | 0975c304 | ths | |
75 | 0975c304 | ths | static uint32_t vmport_cmd_get_version(void *opaque, uint32_t addr) |
76 | 0975c304 | ths | { |
77 | 26fb5e48 | aurel32 | CPUState *env = cpu_single_env; |
78 | 0975c304 | ths | env->regs[R_EBX] = VMPORT_MAGIC; |
79 | 0975c304 | ths | return 6; |
80 | 0975c304 | ths | } |
81 | 0975c304 | ths | |
82 | 0975c304 | ths | static uint32_t vmport_cmd_ram_size(void *opaque, uint32_t addr) |
83 | 0975c304 | ths | { |
84 | 26fb5e48 | aurel32 | CPUState *env = cpu_single_env; |
85 | 0975c304 | ths | env->regs[R_EBX] = 0x1177;
|
86 | 0975c304 | ths | return ram_size;
|
87 | 0975c304 | ths | } |
88 | 0975c304 | ths | |
89 | 26fb5e48 | aurel32 | void vmport_init(void) |
90 | 0975c304 | ths | { |
91 | 0975c304 | ths | register_ioport_read(0x5658, 1, 4, vmport_ioport_read, &port_state); |
92 | 0975c304 | ths | |
93 | 0975c304 | ths | /* Register some generic port commands */
|
94 | 26fb5e48 | aurel32 | vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, NULL);
|
95 | 26fb5e48 | aurel32 | vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, NULL);
|
96 | 0975c304 | ths | } |