Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 2 → Rev 392

/shark/tags/rel_0_4/oslib/examples/biosdemo.c
29,13 → 29,57
#include <ll/stdlib.h>
 
#define T 1000
#if 1
#define WAIT() for (w = 0; w < 0xFFFFFFFF; w++)
 
#else
#define WAIT() for (w = 0; w < 0xFFFFF; w++)
#endif
static unsigned long int w;
 
#define __VM86__
 
#ifdef __VM86__
 
//void emulate(void)
void emulate(DWORD intnum, struct registers r)
{
TSS *vm86_tss;
DWORD *bos;
DWORD isr_cs, isr_eip;
WORD *old_esp;
DWORD *IRQTable_entry;
CONTEXT c = get_TR();
vm86_tss = vm86_get_tss();
bos = (DWORD *)vm86_tss->esp0;
if (c == X_VM86_TSS) {
/*
message("Entering ESP: %lx (= 0x%lx?)\n",
(DWORD)(tos + 9), vm86_tss->esp0);
message("Old EIP: 0x%lx 0x%lx\n", *(tos + 9), *(bos - 9));
message("Old CS: 0x%x 0x%x\n", (WORD)(*(tos + 10)), (WORD)*(bos - 8));
message("Old EFlags: 0x%lx 0x%lx\n", *(tos + 11), *(bos - 7));
message("Old ESP: 0x%lx 0x%lx\n", *(tos + 12), *(bos - 6));
message("Emulate, please!!!\n");
*/
old_esp = (WORD *)(*(bos - 6) + (*(bos - 5) << 4));
// *(old_esp - 1) = /*(WORD)(*(bos - 7))*/ CPU_FLAG_VM | CPU_FLAG_IOPL;
r.flags = CPU_FLAG_VM | CPU_FLAG_IOPL;
*(old_esp - 2) = (WORD)(*(bos - 8));
*(old_esp - 3) = (WORD)(*(bos - 9));
*(bos - 6) -= 6;
/* We are emulating INT 0x6d */
IRQTable_entry = (void *)(0L);
isr_cs= ((IRQTable_entry[0x6d]) & 0xFFFF0000) >> 16;
isr_eip = ((IRQTable_entry[0x6d]) & 0x0000FFFF);
/*
message("I have to call 0x%lx:0x%lx\n", isr_cs, isr_eip);
*/
*(bos - 8) = isr_cs;
*(bos - 9) = isr_eip;
}
}
 
void vm86BIOSDemo(void)
{
X_REGS16 ir,or;
72,9 → 116,22
register int i;
/* Set video mode */
ir.h.ah = 0;
 
#if 0
ir.h.al = 0x03;
vm86_callBIOS(0x10,&ir,&or,&sr);
 
ir.h.ah = 0x0C;
ir.h.al = i % 16;
ir.x.bx = 0;
ir.x.dx = i+40;
ir.x.cx = i+100;
vm86_callBIOS(0x10,&ir,&or,&sr);
 
 
#else
ir.h.al = 0x12;
vm86_callBIOS(0x10,&ir,&or,&sr);
#if 1
/* Put some pixels */
for (i = 0; i < 200; i++) {
ir.h.ah = 0x0C;
112,7 → 169,13
message("CX=%x\n",c);
for (i = 0; i < 0x4F000; i++);
#ifdef __VM86__
vm86_init();
vm86_init();
 
l1_int_bind(0x6d, emulate);
/*
l1_irq_bind(0x6d, emulate);
*/
 
BIOSDemo();
#else
XBIOSDemo();
/shark/tags/rel_0_4/oslib/examples/mbdemo.c
36,6 → 36,7
struct multiboot_info *mbi;
DWORD lbase, hbase;
DWORD lsize, hsize;
int eXtender = 0;
 
sp1 = get_SP();
cli();
54,6 → 55,12
message("LowLevel started...\n");
message("MultiBoot informations:\n");
if (mbi->flags & MB_INFO_BOOT_LOADER_NAME) {
message("Loader Name provided: %s\n", (char *)mbi->boot_loader_name);
if (*((char *)(mbi->boot_loader_name)) == 'X') {
eXtender = 1;
}
}
if (mbi->flags & MB_INFO_MEMORY) {
message("\tMemory informations OK\n");
lsize = mbi->mem_lower * 1024;
60,7 → 67,7
hsize = mbi->mem_upper * 1024;
message("Mem Lower: %lx %lu\n", lsize, lsize);
message("Mem Upper: %lx %lu\n", hsize, hsize);
if (mbi->flags & MB_INFO_USEGDT) {
if (eXtender) {
lbase = mbi->mem_lowbase;
hbase = mbi->mem_upbase;
} else {
92,7 → 99,7
if (mbi->flags & MB_INFO_MEM_MAP) {
message("\tMemory map provided\n");
}
if (mbi->flags & MB_INFO_USEGDT) {
if (eXtender) {
message("\tLoaded through X\n");
}
cli();
/shark/tags/rel_0_4/oslib/examples/vmdemo.c
24,6 → 24,9
#include <ll/ll.h>
 
#define T 1000
int a; /* This must be global, otherwise the compiler optimization will
remove the division by 0...
*/
 
int main (int argc, char *argv[])
{
53,6 → 56,7
return 1;
*/
l1_init();
a = 1 / 0; /* Test the exception handler... */
l1_end();
 
return 1;
/shark/tags/rel_0_4/oslib/examples/makefile
10,7 → 10,7
 
all: mbdemo.xtn timetest.xtn eventdem.xtn vmdemo.xtn \
ctxswdem.xtn scheddem.xtn cpudemo.xtn biosdemo.xtn \
asdemo.xtn
asdemo.xtn kerndem.xtn
 
%.ftp: %.xtn
ncftpput -u ll -p example thorin . $<
26,6 → 26,10
# Demo
#
 
kerndem.xtn: syscalls.o $(LIB_PATH)/libhc.a $(LIB_PATH)/libhm.a $(LIB_PATH)/libhx.a $(LIB_PATH)/libkl.a
$(LD) $(LINK_OPT) $(LIB_PATH)x0.o syscalls.o --start-group -lhc -lhm -lhx -lkl -lcons --end-group -o $@
 
 
%.xtn : %.o $(LIB_PATH)/libhc.a $(LIB_PATH)/libhm.a $(LIB_PATH)/libhx.a $(LIB_PATH)/libkl.a
$(LD) $(LINK_OPT) $(LIB_PATH)x0.o $< --start-group -lhc -lhm -lhx -lkl --end-group -o $@
$(LD) $(LINK_OPT) $(LIB_PATH)x0.o $< --start-group -lhc -lhm -lhx -lkl -lcons --end-group -o $@
# $(LD) $(LINK_OPT) $(LIB_PATH)x0.o $< --start-group -lhc -lhx -lkl --end-group -o $@
/shark/tags/rel_0_4/oslib/examples/syscalls.c
0,0 → 1,203
/* Project: OSLib
* Description: The OS Construction Kit
* Date: 1.6.2000
* Idea by: Luca Abeni & Gerardo Lamastra
*
* OSLib is an SO project aimed at developing a common, easy-to-use
* low-level infrastructure for developing OS kernels and Embedded
* Applications; it partially derives from the HARTIK project but it
* currently is independently developed.
*
* OSLib is distributed under GPL License, and some of its code has
* been derived from the Linux kernel source; also some important
* ideas come from studying the DJGPP go32 extender.
*
* We acknowledge the Linux Community, Free Software Foundation,
* D.J. Delorie and all the other developers who believe in the
* freedom of software and ideas.
*
* For legalese, check out the included GPL license.
*/
 
/* Address Spaces test file */
 
#include <ll/i386/stdlib.h>
#include <ll/i386/error.h>
#include <ll/i386/mem.h>
#include <ll/i386/hw-arch.h>
#include <ll/i386/farptr.h>
#include <ll/sys/ll/ll-func.h>
#include <ll/sys/ll/aspace.h>
#include <ll/sys/ll/event.h>
#include <ll/string.h>
 
#define USE_NEW_HANDLERS
#define T 1000
#define WAIT() for (w = 0; w < 0x5FFFFF; w++)
 
extern DWORD GDT_base;
extern void int0x31(void);
 
#ifndef USE_NEW_HANDLERS
struct regs {
DWORD flags;
DWORD egs;
DWORD efs;
DWORD ees;
DWORD eds;
DWORD edi;
DWORD esi;
DWORD ebp;
DWORD esp;
DWORD ebx;
DWORD edx;
DWORD ecx;
DWORD eax;
};
#endif
 
BYTE space[2048];
WORD th1, th2, thm;
 
char outstring[] = "Hi there!!!\n";
 
#ifdef USE_NEW_HANDLERS
void chandler(DWORD intnum, struct registers r)
#else
void chandler(struct regs r, DWORD intnum)
#endif
{
message("[System Call] EAX = 0x%lx EBX = 0x%lx ECX = 0x%lx...\n",
r.eax, r.ebx, r.ecx);
 
if (r.eax == 1) {
message("Exit!!!\n");
ll_context_load(thm);
}
 
if (r.eax == 2) {
char string[20];
DWORD p;
unsigned int size;
 
p = GDT_read(r.eds, NULL, NULL, NULL);
p += r.ebx;
size = r.ecx;
if (size > 20) {
size = 20;
}
#if 0
message("Buffer @0x%lx, len %u\n", p, size);
l1_end();
sti();
l1_exit(0);
#endif
 
memcpy(string, (void *)p, size);
string[19] = 0;
message("Write...\n");
message("%s", string);
return;
}
 
message("Unsupported System Call!!!\n");
}
 
 
/* For now, this is not called */
void killer(void)
{
cli();
message("Killer!!!\n");
ll_context_load(thm);
}
 
/*
And this is the thread that runs in the new AS... It cannot call
any function (it is alone in its AS), so it simply plots a star
on the screen and loops waiting for an event that switches to the
main thread.
*/
void nullfun(void *p)
{
/* Some asm to write on the screen (we cannot use libc... it is not
linked in this AS */
__asm__ __volatile__ ("movl $2, %eax");
__asm__ __volatile__ ("movl $1000, %ebx");
__asm__ __volatile__ ("movl $16, %ecx");
__asm__ __volatile__ ("int $0x31");
__asm__ __volatile__ ("movl $1, %eax");
__asm__ __volatile__ ("int $0x31");
 
/* should not arrive here... */
for(;;);
halt();
}
 
int main (int argc, char *argv[])
{
DWORD sp1, sp2;
void *res;
AS as, ds;
int ok;
sp1 = get_SP();
cli();
res = ll_init();
 
if (res == NULL) {
message("Error in LowLevel initialization code...\n");
sti();
l1_exit(-1);
}
message("LowLevel started...\n");
#ifdef USE_NEW_HANDLERS
l1_int_bind(0x31, chandler);
#else
IDT_place(0x31, int0x31);
#endif
as_init();
 
message("Creating an Address Space\n");
as = as_create();
message("Created: ID = %d %x\n", as, as);
message("Binding array @ 0x%lx\n", (DWORD)space);
ok = as_bind(as, (DWORD)space, 0, sizeof(space));
 
if (ok < 0) {
message("Error in as_bind!!!\n");
} else {
message("Bound\n");
}
 
ds = get_DS();
/* Let's create the image of the process...
* 0 --> 1000 : text
* 1000 --> 1000 + strlen(outstring) : initialized data
* ? <-- 2048 : stack
*/
fmemcpy(as, 0, ds, (DWORD)nullfun, 1000);
fmemcpy(as, 1000, ds, (DWORD)outstring, strlen(outstring));
/* Create a thread (in our AS) and a task (in a different AS) */
th1 = ll_context_create(0, (void *)2048, NULL,killer, 0);
ll_context_setspace(th1, as);
/* Save our context, in order to permit to switch back to main */
thm = ll_context_save();
message("I am thread %x\n", thm);
message("Thread 1 created\n");
message("Switching to it...\n");
ll_context_load(th1);
message("Back to Main\n");
 
cli();
ll_end();
sp2 = get_SP();
message("End reached!\n");
message("Actual stack : %lx - ", sp2);
message("Begin stack : %lx\n", sp1);
message("Check if same : %s\n",sp1 == sp2 ? "Ok :-)" : "No :-(");
return 1;
}