mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 19:03:15 +01:00
Previously we had changed the method of setting the ipc tag from l4_ipc() call argument to being passed as a message register. - This change was not reflected in l4_ipc() signature as it still had a 3rd argument, even though ignored. - l4_set_sender and _set_tag had their arguments wrong way around. - Previously 5 mrs were passed onto utcb instead of 6, relying on the fact that l4_ipc tag argument was being passed in r3 directly, this wasnt true anymore with new convention, but wasn't catered for. TODO: - MM0 shouldn't really allocate tids itself, but use ones supplied by C0. - Sender tid shouldn't really passed by the sender task, but rather by C0. Otherwise security can be easily breached by user tasks pretending to be other tasks. This would also save us a message register.
85 lines
1.8 KiB
C
85 lines
1.8 KiB
C
/*
|
|
* FS0. Filesystem implementation
|
|
*
|
|
* Copyright (C) 2007 Bahadir Balban
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <l4lib/arch/message.h>
|
|
#include <l4lib/arch/syscalls.h>
|
|
#include <l4lib/arch/syslib.h>
|
|
#include <l4lib/kip.h>
|
|
#include <l4lib/utcb.h>
|
|
#include <l4lib/ipcdefs.h>
|
|
#include <fs.h>
|
|
#include <init.h>
|
|
#include <kdata.h>
|
|
#include <syscalls.h>
|
|
#include <task.h>
|
|
|
|
/* Synchronise with pager via a `wait' tagged ipc with destination as pager */
|
|
void wait_pager(l4id_t partner)
|
|
{
|
|
l4_send(partner, L4_IPC_TAG_WAIT);
|
|
printf("%s: Pager synced with us.\n", __TASKNAME__);
|
|
}
|
|
|
|
void handle_fs_requests(void)
|
|
{
|
|
u32 mr[MR_UNUSED_TOTAL];
|
|
l4id_t sender;
|
|
int err;
|
|
u32 tag;
|
|
|
|
printf("%s: Listening requests.\n", __TASKNAME__);
|
|
|
|
if ((err = l4_receive(L4_ANYTHREAD)) < 0) {
|
|
printf("%s: %s: IPC Error: %d. Quitting...\n", __TASKNAME__,
|
|
__FUNCTION__, err);
|
|
BUG();
|
|
}
|
|
|
|
/* Read conventional ipc data */
|
|
tag = l4_get_tag();
|
|
sender = l4_get_sender();
|
|
|
|
/* Read mrs not used by syslib */
|
|
for (int i = 0; i < MR_UNUSED_TOTAL; i++)
|
|
mr[i] = read_mr(i);
|
|
|
|
switch(tag) {
|
|
case L4_IPC_TAG_WAIT:
|
|
printf("%s: Synced with waiting thread.\n", __TASKNAME__);
|
|
break;
|
|
case L4_IPC_TAG_OPEN:
|
|
sys_open(sender, (void *)mr[0], (int)mr[1], (u32)mr[2]);
|
|
break;
|
|
case L4_IPC_TAG_READ:
|
|
sys_read(sender, (int)mr[0], (void *)mr[1], (int)mr[2]);
|
|
break;
|
|
case L4_IPC_TAG_WRITE:
|
|
sys_write(sender, (int)mr[0], (void *)mr[1], (int)mr[2]);
|
|
break;
|
|
case L4_IPC_TAG_LSEEK:
|
|
sys_lseek(sender, (int)mr[0], (int)mr[1], (int)mr[2]);
|
|
break;
|
|
default:
|
|
printf("%s: Unrecognised ipc tag (%d)"
|
|
"received. Ignoring.\n", __TASKNAME__, mr[MR_TAG]);
|
|
}
|
|
}
|
|
|
|
void main(void)
|
|
{
|
|
printf("\n\n%s: Started with tid: %d\n", __TASKNAME__, self_tid());
|
|
|
|
initialise();
|
|
|
|
wait_pager(PAGER_TID);
|
|
|
|
while (1) {
|
|
handle_fs_requests();
|
|
}
|
|
}
|
|
|