[eros-cvs] cvs commit: eros/src/base/tests/func/memmap Makefile driver.c memmap.h referencer.c test.imgmap.i486

Charlie Landau clandau@eros.cs.jhu.edu
Sat, 10 Mar 2001 00:34:36 -0500


clandau     01/03/10 00:34:36

  Added:       src/base/tests/func/memmap Makefile driver.c memmap.h
                        referencer.c test.imgmap.i486
  Log:
  Add new test memmap for testing memory mapping.

Revision  Changes    Path
1.1                  eros/src/base/tests/func/memmap/Makefile

Index: Makefile
===================================================================
#
# Copyright (C) 1998, 1999, 2001, The EROS Group.
#
# This file is part of the EROS Operating System.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#


default: install

CROSS_BUILD=yes

EROS_SRC=../../../..
include $(EROS_SRC)/build/lib/make/makevars.mk

TARGETS=referencer driver
OPTIM=-O -g
OBJECTS=referencer.o driver.o
CLEANLIST=test.sysimg test.sysvol
INC=-I$(EROS_ROOT)/include

BOOT=$(EROS_ROOT)/lib/$(EROS_TARGET)/image/boot
VOLMAP=../test.volmap

include $(EROS_SRC)/build/lib/make/makerules.mk
include ../test.makeinc

driver: driver.o $(DOMLIB) $(DOMCRT0)
	$(DOMLINK) $(DOMLINKOPT) -o driver $(DOMCRT0) driver.o $(DOMLIB)

referencer: referencer.o $(DOMLIB) $(DOMCRT0)
	$(DOMLINK) $(DOMLINKOPT) -o referencer $(DOMCRT0) referencer.o $(DOMLIB)

-include .*.m



1.1                  eros/src/base/tests/func/memmap/driver.c

Index: driver.c
===================================================================
/*
 * Copyright (C) 1998, 1999, 2001, The EROS Group.
 *
 * This file is part of the EROS Operating System.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */


/*
 * Test of EROS memory mapping.
 */

#include <eros/target.h>
#include <eros/Invoke.h>
#include <eros/ProcessKey.h>
#include <eros/Key.h>
#include <domain/domdbg.h>
#include "memmap.h"

/**Handle the stack stuff**/
const uint32_t __rt_stack_pages = 0;
const uint32_t __rt_stack_pointer = 0x10000;

/* Key Registers: */
#define KR_ZERO 0
#define KR_OSTREAM 1
#define KR_REFERENCER 2
#define KR_DriverStart0 3
#define KR_DriverStart1 4
#define KR_DriverStartN 5 /* 5 through 8 have keyData 2 through 5 */
#define KR_ReferencerStartAddr 16 /* number key with start addr of referencer */
#define KR_ReferencerProcess 17 /* process key to referencer */

#define KR_RK0   12
#define KR_RK1   13
#define KR_RK2   14
#define KR_RESUME  15		/* so don't use it for anything else! */

uint8_t buf[EROS_PAGE_SIZE];

int
DoReference(enum refType type,
            uint32_t addr)
{
  Message msg;
  
  msg.snd_invKey = KR_REFERENCER;
  msg.snd_key0 = KR_ZERO;
  msg.snd_key1 = KR_ZERO;
  msg.snd_key2 = KR_ZERO;
  msg.snd_key3 = KR_DriverStart0;
  msg.snd_data = 0;
  msg.snd_len = 0;
  msg.snd_code = type;
  msg.snd_w1 = addr;
  msg.snd_w2 = 0;
  msg.snd_w3 = 0;

  msg.rcv_key0 = KR_RK0;
  msg.rcv_key1 = KR_RK1;
  msg.rcv_key2 = KR_RK2;
  msg.rcv_key3 = KR_RESUME;
  msg.rcv_data = 0;
  msg.rcv_len = 0;

  kprintf(KR_OSTREAM, "driver: requesting %d 0x%08x\n", type, addr);
  RETURN(&msg);
  kprintf(KR_OSTREAM, "driver: got keyInfo %d.\n", msg.rcv_keyInfo);
  /* msg.rcv_keyInfo == 0 is a normal return.
     Any other value means the referencer called a keeper,
     in which case we must restart the referencer. */
  if (msg.rcv_keyInfo != 0) {
    uint32_t ret = process_swap(KR_ReferencerProcess,
                                ProcPCandSP,
                                KR_ReferencerStartAddr,
                                KR_ZERO);
    if (!ret) kdprintf(KR_OSTREAM, "driver: process_swap ret %d\n", ret);
    msg.snd_invKey = KR_RESUME;
    SEND(&msg);
  }
  return msg.rcv_keyInfo;
}

int
main()
{
  DoReference(refReadDirect, 0);
  DoReference(refReadDirect, 0x1004);
  DoReference(refReadDirect, 0);
  DoReference(refReadDirect, 0x1004);
  return 0;
}



1.1                  eros/src/base/tests/func/memmap/memmap.h

Index: memmap.h
===================================================================
/*
 * Copyright (C) 2001, The EROS Group.
 *
 * This file is part of the EROS Operating System.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */


#include <eros/target.h>

/* Request codes */
enum refType {
  refReadDirect,
  refReadIPC,
  refWriteDirect,
  refWriteIPC
};




1.1                  eros/src/base/tests/func/memmap/referencer.c

Index: referencer.c
===================================================================
/*
 * Copyright (C) 1998, 1999, 2001, The EROS Group.
 *
 * This file is part of the EROS Operating System.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */


#include <eros/target.h>
#include <eros/Invoke.h>
#include <domain/domdbg.h>
#include "memmap.h"

/* 
 * In order to simplify the requirements for building this process's
 * address space, the code and the stack are in the same page,
 * which is mapped at address 0.
 * So this program is carefully constructed to fit in less than one page.
 */
extern uint8_t _end;
const uint32_t __rt_stack_pages = 0;
const uint32_t __rt_stack_pointer = 0x1000;

#define KR_ZERO 0
#define KR_OSTREAM 1
#define KR_CALLER 15

uint8_t b;

int
main()
{
  Message msg;

  /* If this program doesn't fit in a page, with room for a stack,
     we are in trouble. */
  if ((unsigned long)&_end + 100 > __rt_stack_pointer) return 8;

  msg.snd_invKey = KR_ZERO;
  msg.snd_key0 = KR_ZERO;
  msg.snd_key1 = KR_ZERO;
  msg.snd_key2 = KR_ZERO;
  msg.snd_key3 = KR_ZERO;
  msg.snd_data = 0;
  msg.snd_len = 0;
  msg.snd_code = 0;
  msg.snd_w1 = 0;
  msg.snd_w2 = 0;
  msg.snd_w3 = 0;

  msg.rcv_key0 = KR_ZERO;
  msg.rcv_key1 = KR_ZERO;
  msg.rcv_key2 = KR_ZERO;
  msg.rcv_key3 = KR_CALLER;
  msg.rcv_len = 0;
  msg.rcv_data = 0;

  for(;;) {
    uint8_t * ptr;

    RETURN(&msg);
    /* Process the request. 
       The driver has set up our address space.
       msg.rcv_w1 has the address to read or write.
       If the reference is successful, we will return to the caller
       (the driver) with return code 0.
       If the reference is unsuccessful, we will invoke the driver
       via a segment keeper or process keeper. 
     */
    ptr = (uint8_t *)msg.rcv_w1;
    msg.snd_code = 0; /* default return code */
    switch (msg.rcv_code) {
    case refReadDirect:
      b = *ptr;
      break;

    default:
      msg.snd_code = 1;
    }
    msg.snd_invKey = KR_CALLER;
  }
  return 0; /* never executed */
}



1.1                  eros/src/base/tests/func/memmap/test.imgmap.i486

Index: test.imgmap.i486
===================================================================
/* -*- C -*- */
/*
# Copyright (C) 1998, 1999, 2001, The EROS Group.
#
# This file is part of the EROS Operating System.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

arch i486;

referencer = new domain;
referencer.seg = program segment "referencer";
referencer.pc = symbol "referencer" _start;
referencer.seg = referencer.seg with page at 0xf000;

referencer pc= referencer.pc;
referencer space = referencer.seg;
referencer priority = sched(8); /* normal */

driver = new domain;
driver.seg = program segment "driver";
driver.pc = symbol "driver" _start;
driver.seg = driver.seg with page at 0xf000;

driver pc= driver.pc;
driver space = driver.seg;
driver priority = sched(8); /* normal */

driver key reg 1 = misc ConsoleCreator;
driver key reg 2 = start referencer 0;
driver key reg 3 = start driver 0;
driver key reg 4 = start driver 1;
driver key reg 5 = start driver 2;
driver key reg 6 = start driver 3;
driver key reg 7 = start driver 4;
driver key reg 8 = start driver 5;
driver key reg 16 = referencer.pc;
driver key reg 17 = referencer;

referencer key reg 1 = misc ConsoleCreator;
referencer domain keeper = start driver 1;

run referencer;
run driver;