UbixOS  2.0
bioscall.c
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2002-2018 The UbixOS Project.
3  * All rights reserved.
4  *
5  * This was developed by Christopher W. Olsen for the UbixOS Project.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted
8  * provided that the following conditions are met:
9  *
10  * 1) Redistributions of source code must retain the above copyright notice, this list of
11  * conditions, the following disclaimer and the list of authors.
12  * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13  * conditions, the following disclaimer and the list of authors in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16  * endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/_null.h>
30 #include <sys/tss.h>
31 #include <ubixos/sched.h>
32 #include <vmm/vmm.h>
33 #include <lib/bioscall.h>
34 #include <string.h>
35 #include <sys/video.h>
36 #include <assert.h>
37 #include <lib/kprintf.h>
38 #include <vmm/paging.h>
39 
40 void biosCall(int biosInt, int eax, int ebx, int ecx, int edx, int esi, int edi, int es, int ds) {
41  short segment = 0x0, offset = 0x0;
42  uint32_t tmpAddr = (uint32_t) &bios16Code;
43  kTask_t *newProcess = 0x0;
44 
45  offset = tmpAddr & 0xF; // lower 4 bits
46  segment = tmpAddr >> 4;
47 
48  newProcess = schedNewTask();
49  assert(newProcess);
50 
51  newProcess->tss.back_link = 0x0;
52  newProcess->tss.esp0 = (uint32_t) vmm_getFreeKernelPage(newProcess->id, 2) + (0x2000 - 0x4); // XXX I had 0xDEADBEEF I'm not sure why
53  newProcess->tss.ss0 = 0x10;
54  newProcess->tss.esp1 = 0x0;
55  newProcess->tss.ss1 = 0x0;
56  newProcess->tss.esp2 = 0x0;
57  newProcess->tss.ss2 = 0x0;
58  newProcess->tss.cr3 = kernelPageDirectory; //vmm_createVirtualSpace(newProcess->id); //(uint32_t)_current->tss.cr3;
59  newProcess->tss.eip = offset & 0xFFFF;
60  newProcess->tss.eflags = 2 | EFLAG_IF | EFLAG_VM;
61  newProcess->tss.eax = eax & 0xFFFF;
62  newProcess->tss.ebx = ebx & 0xFFFF;
63  newProcess->tss.ecx = ecx & 0xFFFF;
64  newProcess->tss.edx = edx & 0xFFFF;
65  newProcess->tss.esp = 0x1000 & 0xFFFF;
66  newProcess->tss.ebp = 0x1000 & 0xFFFF;
67  newProcess->tss.esi = esi & 0xFFFF;
68  newProcess->tss.edi = edi & 0xFFFF;
69  newProcess->tss.es = es & 0xFFFF;
70  newProcess->tss.cs = segment & 0xFFFF;
71  newProcess->tss.ss = 0x1000 & 0xFFFF;
72  newProcess->tss.ds = ds & 0xFFFF;
73  newProcess->tss.fs = 0x0 & 0xFFFF;
74  newProcess->tss.gs = 0x0 & 0xFFFF;
75  newProcess->tss.ldt = 0x0 & 0xFFFF;
76  newProcess->tss.trace_bitmap = 0x0 & 0xFFFF;
77  newProcess->tss.io_map = 0x0 & 0xFFFF;
78  newProcess->tss.io_map = sizeof(struct tssStruct) - 8192;
79  newProcess->oInfo.v86Task = 0x1;
80 
81  kprintf("EIP: [0x%X] 0x%X:0x%X", tmpAddr, newProcess->tss.eip, newProcess->tss.cs);
82 
83  newProcess->state = READY;
84  while (newProcess->state > 0)
85  sched_yield();
86 
87  kprintf("EIP: [0x%X] 0x%X:0x%X!", tmpAddr, newProcess->tss.eip, newProcess->tss.cs);
88  kprintf("CALL DONE: %i 0x%X 0x%X!", newProcess->state, newProcess->tss.esp, newProcess->tss.ss);
89 
90  return;
91 }
taskStruct
Definition: sched.h:62
tssStruct::eip
long eip
Definition: tss.h:47
tssStruct::ebx
long ebx
Definition: tss.h:49
string.h
tssStruct::edx
long edx
Definition: tss.h:49
tssStruct::ss1
short ss1
Definition: tss.h:41
video.h
tssStruct::ldt
short ldt
Definition: tss.h:66
tssStruct::ds
short ds
Definition: tss.h:60
assert
#define assert(e)
Definition: assert.h:64
assert.h
tssStruct::eflags
long eflags
Definition: tss.h:48
vmm.h
tssStruct::esp0
long esp0
Definition: tss.h:37
tssStruct::back_link
short back_link
Definition: tss.h:35
taskStruct::tss
struct tssStruct tss
Definition: sched.h:67
tssStruct::ss0
short ss0
Definition: tss.h:38
sched.h
biosCall
void biosCall(int biosInt, int eax, int ebx, int ecx, int edx, int esi, int edi, int es, int ds)
Definition: bioscall.c:49
tssStruct::ss2
short ss2
Definition: tss.h:44
tssStruct::esp
long esp
Definition: tss.h:50
taskStruct::id
pidType id
Definition: sched.h:63
kprintf.h
kernelPageDirectory
uint32_t * kernelPageDirectory
Definition: paging.c:41
EFLAG_IF
#define EFLAG_IF
Definition: bioscall.h:35
tssStruct::ss
short ss
Definition: tss.h:58
tssStruct::esp1
long esp1
Definition: tss.h:40
paging.h
uint32_t
__uint32_t uint32_t
Definition: types.h:46
osInfo::v86Task
uInt8 v86Task
Definition: sched.h:52
tssStruct
Definition: tss.h:34
tssStruct::es
short es
Definition: tss.h:54
tssStruct::cs
short cs
Definition: tss.h:56
schedNewTask
kTask_t * schedNewTask()
Definition: sched.c:135
tssStruct::fs
short fs
Definition: tss.h:62
tssStruct::edi
long edi
Definition: tss.h:53
tssStruct::ecx
long ecx
Definition: tss.h:49
tssStruct::io_map
short io_map
Definition: tss.h:69
tssStruct::ebp
long ebp
Definition: tss.h:51
taskStruct::state
tState state
Definition: sched.h:72
tssStruct::esi
long esi
Definition: tss.h:52
vmm_getFreeKernelPage
void * vmm_getFreeKernelPage(pidType pid, uint16_t count)
Definition: paging.c:291
READY
Definition: sched.h:47
_null.h
tssStruct::trace_bitmap
short trace_bitmap
Definition: tss.h:68
bioscall.h
bios16Code
void bios16Code()
kprintf
int kprintf(const char *,...)
Definition: kprintf.c:259
tssStruct::cr3
long cr3
Definition: tss.h:46
tssStruct::esp2
long esp2
Definition: tss.h:43
tssStruct::gs
short gs
Definition: tss.h:64
EFLAG_VM
#define EFLAG_VM
Definition: bioscall.h:37
tss.h
taskStruct::oInfo
struct osInfo oInfo
Definition: sched.h:69
tssStruct::eax
long eax
Definition: tss.h:49
sched_yield
void sched_yield()
Definition: sched.c:244