Add preliminary support for the x86emu backend.
[v86d.git] / v86_lrmi.c
bloba9903372d9c4b074659166a47f9fbd5b003900d1
1 #include <string.h>
2 #include <lrmi.h>
3 #include "v86.h"
5 #define addr(t) (((t & 0xffff0000) >> 12) + (t & 0x0000ffff))
7 void rconv_vm86_to_LRMI(struct vm86_regs *rs, struct LRMI_regs *rd)
9 memset(rd, 0, sizeof(*rd));
11 rd->eax = rs->eax;
12 rd->ebx = rs->ebx;
13 rd->ecx = rs->ecx;
14 rd->edx = rs->edx;
15 rd->edi = rs->edi;
16 rd->esi = rs->esi;
17 rd->ebp = rs->ebp;
18 rd->sp = rs->esp;
19 rd->flags = rs->eflags;
20 rd->ip = rs->eip;
21 rd->cs = rs->cs;
22 rd->ds = rs->ds;
23 rd->es = rs->es;
24 rd->fs = rs->fs;
25 rd->gs = rs->gs;
28 void rconv_LRMI_to_vm86(struct LRMI_regs *rs, struct vm86_regs *rd)
30 rd->eax = rs->eax;
31 rd->ebx = rs->ebx;
32 rd->ecx = rs->ecx;
33 rd->edx = rs->edx;
34 rd->edi = rs->edi;
35 rd->esi = rs->esi;
36 rd->ebp = rs->ebp;
37 rd->esp = rs->sp;
38 rd->eflags = rs->flags;
39 rd->eip = rs->ip;
40 rd->cs = rs->cs;
41 rd->ds = rs->ds;
42 rd->es = rs->es;
43 rd->fs = rs->fs;
44 rd->gs = rs->gs;
47 int v86_init() {
48 int err = LRMI_init();
50 ioperm(0, 1024, 1);
51 iopl(3);
53 return (err == 1) ? 0 : 1;
56 void v86_cleanup()
58 /* dummy function */
62 * Perform a simulated interrupt call.
64 int v86_int(int num, struct vm86_regs *regs)
66 struct LRMI_regs r;
67 int err;
69 rconv_vm86_to_LRMI(regs, &r);
70 err = LRMI_int(num, &r);
71 rconv_LRMI_to_vm86(&r, regs);
73 return (err == 1) ? 0 : 1;
76 #define vbeib_get_string(name) \
77 { \
78 t = addr(ib->name); \
79 ulog("%x %x\n", t, bufend); \
80 if (t < bufend) { \
81 ib->name = t - (u32)lbuf; \
82 } else { \
83 ib->name = 0; \
84 } \
87 int v86_task(struct uvesafb_task *tsk, u8 *buf)
89 u8 *lbuf;
91 /* Get the VBE Info Block */
92 if (tsk->flags & TF_VBEIB) {
93 struct vbe_ib *ib;
94 u32 t, bufend;
96 lbuf = LRMI_alloc_real(tsk->buf_len);
97 memcpy(lbuf, buf, tsk->buf_len);
98 tsk->regs.es = (u32)lbuf >> 4;
99 tsk->regs.edi = 0x0000;
101 if (v86_int(0x10, &tsk->regs) || (tsk->regs.eax & 0xffff) != 0x004f)
102 goto out_vbeib;
104 ib = (struct vbe_ib*)buf;
105 bufend = (u32)(lbuf + sizeof(struct vbe_ib));
106 memcpy(buf, lbuf, tsk->buf_len);
108 vbeib_get_string(oem_string_ptr);
109 vbeib_get_string(oem_vendor_name_ptr);
110 vbeib_get_string(oem_product_name_ptr);
111 vbeib_get_string(oem_product_rev_ptr);
112 vbeib_get_string(mode_list_ptr);
113 out_vbeib:
114 LRMI_free_real(lbuf);
115 } else {
116 if (tsk->buf_len) {
117 lbuf = LRMI_alloc_real(tsk->buf_len);
118 memcpy(lbuf, buf, tsk->buf_len);
121 if (tsk->flags & TF_BUF_ESDI) {
122 tsk->regs.es = (u32)lbuf >> 4;
123 tsk->regs.edi = 0x0000;
126 if (tsk->flags & TF_BUF_ESBX) {
127 tsk->regs.es = (u32)lbuf >> 4;
128 tsk->regs.ebx = 0x0000;
131 if (v86_int(0x10, &tsk->regs) || (tsk->regs.eax & 0xffff) != 0x004f)
132 goto out;
134 if (tsk->buf_len && tsk->flags & TF_BUF_RET) {
135 memcpy(buf, lbuf, tsk->buf_len);
137 out:
138 if (tsk->buf_len)
139 LRMI_free_real(lbuf);
142 return 0;