Subversion Repositories shark

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/* Project:     OSLib
2
 * Description: The OS Construction Kit
3
 * Date:                1.6.2000
4
 * Idea by:             Luca Abeni & Gerardo Lamastra
5
 *
6
 * OSLib is an SO project aimed at developing a common, easy-to-use
7
 * low-level infrastructure for developing OS kernels and Embedded
8
 * Applications; it partially derives from the HARTIK project but it
9
 * currently is independently developed.
10
 *
11
 * OSLib is distributed under GPL License, and some of its code has
12
 * been derived from the Linux kernel source; also some important
13
 * ideas come from studying the DJGPP go32 extender.
14
 *
15
 * We acknowledge the Linux Community, Free Software Foundation,
16
 * D.J. Delorie and all the other developers who believe in the
17
 * freedom of software and ideas.
18
 *
19
 * For legalese, check out the included GPL license.
20
 */
21
 
22
/*      VM86 demo: tries to call BIOS services in vm86 mode... */
23
 
24
#include <ll/i386/hw-func.h>
25
#include <ll/i386/tss-ctx.h>
26
#include <ll/i386/x-bios.h>
27
#include <ll/i386/cons.h>
28
#include <ll/i386/error.h>
29
#include <ll/stdlib.h>
30
 
31
#define T  1000
40 pj 32
#if 1
2 pj 33
#define WAIT()  for (w = 0; w < 0xFFFFFFFF; w++)
40 pj 34
#else
35
#define WAIT()  for (w = 0; w < 0xFFFFF; w++)
36
#endif
2 pj 37
static unsigned long int w;
38
 
39
#define __VM86__
40
 
41
#ifdef __VM86__
40 pj 42
 
43
//void emulate(void)
44
void emulate(DWORD intnum, struct registers r)
45
{
46
    TSS *vm86_tss;
47
    DWORD *bos;
48
    DWORD isr_cs, isr_eip;
49
    WORD *old_esp;
50
    DWORD *IRQTable_entry;
51
    CONTEXT c = get_TR();
52
 
53
    vm86_tss = vm86_get_tss();
54
    bos = (DWORD *)vm86_tss->esp0;
55
    if (c == X_VM86_TSS) {
56
            /*
57
        message("Entering ESP: %lx (= 0x%lx?)\n",
58
                (DWORD)(tos + 9), vm86_tss->esp0);
59
        message("Old EIP: 0x%lx    0x%lx\n", *(tos + 9), *(bos - 9));
60
        message("Old CS: 0x%x    0x%x\n", (WORD)(*(tos + 10)), (WORD)*(bos - 8));
61
        message("Old EFlags: 0x%lx    0x%lx\n", *(tos + 11), *(bos - 7));
62
        message("Old ESP: 0x%lx    0x%lx\n", *(tos + 12), *(bos - 6));
63
        message("Emulate, please!!!\n");
64
*/     
65
        old_esp = (WORD *)(*(bos - 6) + (*(bos - 5) << 4));
66
//      *(old_esp - 1) = /*(WORD)(*(bos - 7))*/ CPU_FLAG_VM | CPU_FLAG_IOPL;
67
        r.flags = CPU_FLAG_VM | CPU_FLAG_IOPL;
68
        *(old_esp - 2) = (WORD)(*(bos - 8));
69
        *(old_esp - 3) = (WORD)(*(bos - 9));
70
        *(bos - 6) -= 6;
71
        /* We are emulating INT 0x6d */
72
        IRQTable_entry = (void *)(0L);
73
        isr_cs= ((IRQTable_entry[0x6d]) & 0xFFFF0000) >> 16;
74
        isr_eip = ((IRQTable_entry[0x6d]) & 0x0000FFFF);
75
        /*
76
        message("I have to call 0x%lx:0x%lx\n", isr_cs, isr_eip);
77
        */
78
        *(bos - 8) = isr_cs;
79
        *(bos - 9) = isr_eip;
80
    }
81
}
82
 
2 pj 83
void vm86BIOSDemo(void)
84
{
85
    X_REGS16 ir,or;
86
    X_SREGS16 sr;
87
    /* Print ASCII character */
88
    ir.h.ah = 9;
89
    /* AL = character to display */
90
    ir.h.al = '+';
91
    /* BH = page number, BL = attribute */
92
    ir.x.bx = 3;
93
    /* Count number */
94
    ir.x.cx = 3;
95
    vm86_callBIOS(0x10,&ir,&or,&sr);
96
}
97
#else
98
 
99
void XBIOSDemo(void)
100
{
101
    X_REGS16 ir,or;
102
    X_SREGS16 sr;
103
    /* Set video mode */
104
    ir.h.ah = 9;
105
    ir.h.al = '+';
106
    ir.x.bx = 3;
107
    ir.x.cx = 3;
108
    X_callBIOS(0x10,&ir,&or,&sr);
109
}                                                                            
110
#endif
111
 
112
void BIOSDemo(void)
113
{
114
    X_REGS16 ir,or;
115
    X_SREGS16 sr;
116
    register int i;
117
    /* Set video mode */
118
    ir.h.ah = 0;
40 pj 119
 
120
#if 0
121
    ir.h.al = 0x03;
122
    vm86_callBIOS(0x10,&ir,&or,&sr);
123
 
124
        ir.h.ah = 0x0C;
125
        ir.h.al = i % 16;
126
        ir.x.bx = 0;
127
        ir.x.dx = i+40;
128
        ir.x.cx = i+100;
129
        vm86_callBIOS(0x10,&ir,&or,&sr);
130
 
131
 
132
#else
2 pj 133
    ir.h.al = 0x12;
134
    vm86_callBIOS(0x10,&ir,&or,&sr);
135
    /* Put some pixels */
136
    for (i = 0; i < 200; i++) {
137
        ir.h.ah = 0x0C;
138
        ir.h.al = i % 16;
139
        ir.x.bx = 0;
140
        ir.x.dx = i+40;
141
        ir.x.cx = i+100;
142
        vm86_callBIOS(0x10,&ir,&or,&sr);
143
    }
144
#endif
145
    WAIT();
146
    /* Set video mode */
147
    ir.h.ah = 0;
148
    ir.h.al = 0x03;    
149
    vm86_callBIOS(0x10,&ir,&or,&sr);
150
}
151
 
152
int main (int argc, char *argv[])
153
{
154
    DWORD sp1, sp2;
155
    WORD c;
156
    int i;
157
    struct multiboot_info *mbi;
158
 
159
    sp1 = get_SP();
160
    mbi = l1_init();
161
 
162
    if (mbi == NULL) {
163
            message("Error in LowLevel initialization code...\n");
164
            l1_exit(-1);
165
    }
166
 
167
    message("Starting...");
168
    c = ll_context_save();
169
    message("CX=%x\n",c);
170
    for (i = 0; i < 0x4F000; i++);
171
#ifdef __VM86__
40 pj 172
    vm86_init();
173
 
174
    l1_int_bind(0x6d, emulate);
175
    /*
176
    l1_irq_bind(0x6d, emulate);
177
    */
178
 
2 pj 179
    BIOSDemo();
180
#else
181
    XBIOSDemo();
182
#endif
183
    sp2 = get_SP();
184
    message("End reached!\n");
185
    message("Actual stack : %lx - ", sp2);
186
    message("Begin stack : %lx\n", sp1);
187
    message("Check if same : %s\n",sp1 == sp2 ? "Ok :-)" : "No :-(");
188
 
189
    l1_end();
190
    return 1;
191
}