Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/cahirwpz/mimiker into vcache
Browse files Browse the repository at this point in the history
  • Loading branch information
mohrcore committed Jan 11, 2022
2 parents fd5721d + ed70113 commit 58742a1
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 77 deletions.
4 changes: 4 additions & 0 deletions build/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ assym.h: genassym.cf
@echo "[ASSYM] $(DSTPATH)"
$(GENASSYM) $(CC) $(ASSYM_CFLAGS) $(CFLAGS) $(CPPFLAGS) < $^ > $@

%.ld: %.ld.in
@echo "[CPP] $(SRCPATH) -> $(DSTPATH)"
$(CPP) $(CPPFLAGS) -I$(TOPDIR)/include -P -o $@ $<

include $(TOPDIR)/config.mk
include $(TOPDIR)/build/arch.$(ARCH).mk
include $(TOPDIR)/build/tools.mk
Expand Down
1 change: 1 addition & 0 deletions build/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ endif
CC = $(TARGET_CC)
AS = $(TARGET_CC)
LD = $(TARGET)-gcc $(GCC_ABIFLAGS) -g
CPP = $(TARGET)-cpp
AR = $(TARGET)-ar
NM = $(TARGET)-nm
GDB = $(TARGET)-gdb
Expand Down
7 changes: 0 additions & 7 deletions include/aarch64/mcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,4 @@ typedef struct ctx {
#define _UC_SETSTACK 0x00020000
#define _UC_CLRSTACK 0x00040000

#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_FP])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_RV])

#define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc)

#endif /* !_AARCH64_MCONTEXT_H_ */
8 changes: 0 additions & 8 deletions include/mips/mcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,5 @@ typedef struct ctx {

#define _UC_SETSTACK 0x00010000
#define _UC_CLRSTACK 0x00020000
#define _UC_TLSBASE 0x00040000

#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_S8])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_EPC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_V0])

#define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc)

#endif /* _MIPS_MCONTEXT_H_ */
4 changes: 2 additions & 2 deletions include/sys/interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ intr_handler_t *intr_event_add_handler(intr_event_t *ie, ih_filter_t *filter,
void intr_event_remove_handler(intr_handler_t *ih);
void intr_event_run_handlers(intr_event_t *ie);

typedef void (*intr_root_filter_t)(ctx_t *ctx, device_t *dev, void *arg);
typedef void (*intr_root_filter_t)(ctx_t *ctx, device_t *dev);

void intr_root_claim(intr_root_filter_t filter, device_t *dev, void *arg);
void intr_root_claim(intr_root_filter_t filter, device_t *dev);
void intr_root_handler(ctx_t *ctx) __no_profile;

#endif /* !_SYS_INTERRUPT_H_ */
78 changes: 59 additions & 19 deletions launch
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ CONFIG = {
'board': {
'malta': {
'kernel': 'sys/mimiker.elf',
'simulator': 'qemu'
},
'rpi3': {
'kernel': 'sys/mimiker.img.gz',
'simulator': 'qemu'
},
},
},
Expand Down Expand Up @@ -89,8 +91,8 @@ CONFIG = {
'-object', 'filter-dump,id=net0,netdev=net0,file=rtl.pcap'
],
'uarts': [
dict(name='/dev/tty1', port=RandomPort(), raw=True),
dict(name='/dev/tty2', port=RandomPort()),
dict(name='/dev/tty0', port=RandomPort(), raw=True),
dict(name='/dev/tty1', port=RandomPort()),
dict(name='/dev/cons', port=RandomPort())
]
},
Expand All @@ -103,11 +105,18 @@ CONFIG = {
'-cpu', 'cortex-a53'],
'network_options': [],
'uarts': [
dict(name='/dev/cons', port=RandomPort(), raw=True)
dict(name='/dev/tty0', port=RandomPort(), raw=True)
]
}
}
},
'renode': {
'options': {
'--console',
},
'board': {
}
},
'gdb': {
'pre-options': [
'-n',
Expand Down Expand Up @@ -242,6 +251,34 @@ class QEMU(Launchable):
self.options += getopts('qemu.network_options')


class RENODE(Launchable):
def __init__(self):
super().__init__('renode', 'renode')

self.options = getopts('renode.options')

script = getvar('renode.script', failok=False)
self.options += [f'-e include @scripts/single-node/{script}']

for i, uart in enumerate(getvar('renode.uarts')):
port = uart['port']
dev = f'uart{i}'
self.options += ['-e emulation CreateServerSocketTerminal ' +
f'{port} "{dev}" False']
self.options += [f'-e connector Connect sysbus.{dev} {dev}']

if getvar('config.debug'):
gdbport = getvar('config.gdbport', failok=False)
self.options += [f'-e machine StartGdbServer {gdbport}']

# TODO(MichalBlk): we should enable passing kernel args through
# the launch script by introducing parameterizable DTS files.
if getvar('config.args'):
raise Exception('kernel args for renode must be passed via dtb')

self.options += ['-e start']


class GDB(Launchable):
def __init__(self):
super().__init__('gdb', getvar('gdb.binary'))
Expand Down Expand Up @@ -274,24 +311,24 @@ def PostMortem(gdb):


def TestRun(sim, dbg, timeout):
qemu = sim.spawn(cpulimit=timeout)
gdb = dbg.spawn(dimensions=(int(os.environ['LINES']),
int(os.environ['COLUMNS'])))
sim_proc = sim.spawn(cpulimit=timeout)
gdb_proc = dbg.spawn(dimensions=(int(os.environ['LINES']),
int(os.environ['COLUMNS'])))

try:
# No need to wait for QEmu, GDB will terminate it!
rc = gdb.expect_exact([pexpect.EOF, '(gdb) '], timeout=None)
# No need to wait for the simulator, GDB will terminate it!
rc = gdb_proc.expect_exact([pexpect.EOF, '(gdb) '], timeout=None)

if rc == 1:
timed_out = b'Program received signal SIGINT' in gdb.before
PostMortem(gdb)
timed_out = b'Program received signal SIGINT' in gdb_proc.before
PostMortem(gdb_proc)
print('Test run %s!' % ('timeout' if timed_out else 'failed'))
if timed_out:
rc = 2
except KeyboardInterrupt:
signal.signal(signal.SIGINT, signal.SIG_IGN)
gdb.terminate()
qemu.terminate()
gdb_proc.terminate()
sim_proc.terminate()
rc = 3
sys.exit(rc)

Expand All @@ -310,7 +347,7 @@ def DevelRun(sim, dbg):
window_name=':0', window_command='sleep 1')

uarts = [SOCAT(uart['name'], uart['port'], uart.get('raw', False))
for uart in getvar('qemu.uarts')]
for uart in getvar(f'{sim.name}.uarts')]

try:
sim.start(session)
Expand All @@ -320,12 +357,12 @@ def DevelRun(sim, dbg):
dbg.start(session)

session.kill_window(':0')
session.select_window(dbg.name if dbg else '/dev/tty1')
session.select_window(dbg.name if dbg else '/dev/tty0')
session.attach_session()
finally:
server.kill_server()

# Give QEMU a chance to exit gracefully
# Give the simulator a chance to exit gracefully
sim.stop()


Expand All @@ -343,7 +380,7 @@ if __name__ == '__main__':
setup_terminal()

parser = argparse.ArgumentParser(
description='Launch kernel in Malta board simulator.')
description='Launch kernel in a board simulator.')
parser.add_argument('args', metavar='ARGS', type=str,
nargs=argparse.REMAINDER, help='Kernel arguments.')
parser.add_argument('-d', '--debug', action='store_true',
Expand All @@ -357,7 +394,8 @@ if __name__ == '__main__':
parser.add_argument('-g', '--graphics', action='store_true',
help='Enable VGA output.')
parser.add_argument('-b', '--board', default='malta',
choices=['malta', 'rpi3'], help='Emulated board.')
choices=['malta', 'rpi3'],
help='Emulated board.')
args = parser.parse_args()

# Used by tmux to override ./.tmux.conf with ./.tmux.conf.local
Expand All @@ -373,11 +411,13 @@ if __name__ == '__main__':
if not os.path.isfile(getvar('config.kernel')):
raise SystemExit('%s: file does not exist!' % getvar('config.kernel'))

sim_name = getvar('config.simulator', failok=False)

# Create simulator launcher
if args.test_run:
setvar('qemu.uarts', [])
setvar(f'{sim_name}.uarts', [])

sim = QEMU()
sim = QEMU() if sim_name == 'qemu' else RENODE()

# Create debugger launcher
if args.debug:
Expand Down
13 changes: 0 additions & 13 deletions lib/libc/sys/getgroups.c

This file was deleted.

5 changes: 3 additions & 2 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ CLEAN-FILES += mimiker.elf.map

include $(TOPDIR)/build/build.kern.mk

LDFLAGS += -T $(TOPDIR)/sys/$(ARCH)/$(ARCH).ld
LDSCRIPT = $(ARCH)/$(ARCH).ld
LDFLAGS += -T $(TOPDIR)/sys/$(LDSCRIPT)
LDLIBS = -Wl,--start-group \
-Wl,--whole-archive $(KLIBLIST) -Wl,--no-whole-archive \
-lgcc \
-Wl,--end-group

mimiker.elf: $(KLIBDEPS)
mimiker.elf: $(KLIBDEPS) $(LDSCRIPT)
@echo "[LD] Linking kernel image: $@"
$(LD) $(LDFLAGS) -Wl,-Map=$@.map $(LDLIBS) -o $@

Expand Down
6 changes: 3 additions & 3 deletions sys/drv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ TOPDIR = $(realpath ../..)

SOURCES = \
dev_cons.c \
uart.c
uart.c \
usb.c

SOURCES-MIPS = \
82371AB.c \
Expand All @@ -23,8 +24,7 @@ SOURCES-MIPS = \
pit.c \
stdvga.c \
uart_cbus.c \
uhci.c \
usb.c
uhci.c

SOURCES-AARCH64 = \
bcm2835_gpio.c \
Expand Down
4 changes: 2 additions & 2 deletions sys/drv/bcm2835_rootdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static void bcm2835_intr_handle(bus_space_handle_t irq_base, bus_size_t offset,
}
}

static void rootdev_intr_handler(ctx_t *ctx, device_t *dev, void *arg) {
static void rootdev_intr_handler(ctx_t *ctx, device_t *dev) {
assert(dev != NULL);
rootdev_t *rd = dev->state;

Expand Down Expand Up @@ -215,7 +215,7 @@ static int rootdev_attach(device_t *bus) {
kmem_map_contig(BCM2835_PERIPHERALS_BUS_TO_PHYS(BCM2835_ARM_BASE),
BCM2835_ARM_SIZE, PMAP_NOCACHE);

intr_root_claim(rootdev_intr_handler, bus, NULL);
intr_root_claim(rootdev_intr_handler, bus);

device_t *dev;

Expand Down
4 changes: 2 additions & 2 deletions sys/drv/malta_rootdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static void rootdev_deactivate_resource(device_t *dev, resource_t *r) {
/* TODO: unmap mapped resources. */
}

static void rootdev_intr_handler(ctx_t *ctx, device_t *dev, void *arg) {
static void rootdev_intr_handler(ctx_t *ctx, device_t *dev) {
rootdev_t *rd = dev->state;
unsigned pending = (_REG(ctx, CAUSE) & _REG(ctx, SR)) & CR_IP_MASK;

Expand Down Expand Up @@ -144,7 +144,7 @@ static int rootdev_attach(device_t *bus) {
rman_init(&rd->irq, "MIPS interrupts");
rman_manage_region(&rd->irq, 0, MIPS_NIRQ);

intr_root_claim(rootdev_intr_handler, bus, NULL);
intr_root_claim(rootdev_intr_handler, bus);

/* Create MIPS timer device and assign resources to it. */
device_t *dev = device_add_child(bus, 0);
Expand Down
22 changes: 4 additions & 18 deletions sys/kern/interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ typedef struct intr_handler {
intr_event_t *ih_event; /* event we are connected to */
void *ih_argument; /* argument to pass to filter/service routines */
const char *ih_name; /* name of the handler */
/* XXX: do we really need ih_prio? it has no real use cases so far... */
prio_t ih_prio; /* handler's priority (sort key for ie_handlers) */
ih_flags_t ih_flags; /* refer to IH_* flags description above */
ih_flags_t ih_flags; /* refer to IH_* flags description above */
} intr_handler_t;

static void intr_thread(void *arg);
Expand Down Expand Up @@ -91,20 +89,11 @@ static void ie_disable(intr_event_t *ie) {
static void intr_event_insert_handler(intr_event_t *ie, intr_handler_t *ih) {
SCOPED_SPIN_LOCK(&ie->ie_lock);

/* Add new handler according to it's priority */
intr_handler_t *it;
TAILQ_FOREACH (it, &ie->ie_handlers, ih_link)
if (ih->ih_prio > it->ih_prio)
break;

/* Enable interrupt if this is the first handler. */
if (TAILQ_EMPTY(&ie->ie_handlers))
ie_enable(ie);

if (it)
TAILQ_INSERT_BEFORE(it, ih, ih_link);
else
TAILQ_INSERT_TAIL(&ie->ie_handlers, ih, ih_link);
TAILQ_INSERT_TAIL(&ie->ie_handlers, ih, ih_link);
}

static void intr_thread_maybe_attach(intr_event_t *ie, intr_handler_t *ih) {
Expand All @@ -131,7 +120,6 @@ intr_handler_t *intr_event_add_handler(intr_event_t *ie, ih_filter_t *filter,
ih->ih_event = ie;
ih->ih_argument = arg;
ih->ih_name = name;
ih->ih_prio = 0;
ih->ih_flags = 0;
intr_event_insert_handler(ie, ih);
intr_thread_maybe_attach(ie, ih);
Expand All @@ -156,14 +144,12 @@ void intr_event_remove_handler(intr_handler_t *ih) {

static intr_root_filter_t ir_filter;
static device_t *ir_dev;
static void *ir_arg;

void intr_root_claim(intr_root_filter_t filter, device_t *dev, void *arg) {
void intr_root_claim(intr_root_filter_t filter, device_t *dev) {
assert(filter != NULL);

ir_filter = filter;
ir_dev = dev;
ir_arg = arg;
}

__no_profile void intr_root_handler(ctx_t *ctx) {
Expand All @@ -179,7 +165,7 @@ __no_profile void intr_root_handler(ctx_t *ctx) {
/* Explicitely disallow switching out to another thread. */
PCPU_SET(no_switch, true);
if (ir_filter != NULL)
ir_filter(ctx, ir_dev, ir_arg);
ir_filter(ctx, ir_dev);
PCPU_SET(no_switch, false);

/* If filter routine requested a context switch it's now time to handle it. */
Expand Down
2 changes: 1 addition & 1 deletion sys/kern/vm_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static POOL_DEFINE(P_VM_MAPENT, "vm_map_entry", sizeof(vm_map_entry_t));
static vm_map_t *kspace = &(vm_map_t){};

void vm_map_activate(vm_map_t *map) {
assert(map != kspace);
SCOPED_NO_PREEMPTION();

PCPU_SET(uspace, map);
Expand Down Expand Up @@ -108,7 +109,6 @@ static void vm_map_setup(vm_map_t *map) {
void init_vm_map(void) {
vm_map_setup(kspace);
kspace->pmap = pmap_kernel();
vm_map_activate(kspace);
}

vm_map_t *vm_map_new(void) {
Expand Down

0 comments on commit 58742a1

Please sign in to comment.