matos/drivers/zero.c
2024-02-08 23:15:29 +01:00

58 lines
1.3 KiB
C

#include "alloc.h"
#include "klibc.h"
#include "zero.h"
struct zeroMappedEntry {
int refCnt;
};
static int zeroOpen(struct uAddrVirtualReg *vreg)
{
(void)vreg;
return 0;
}
static int zeroClose(struct uAddrVirtualReg *vreg)
{
(void)vreg;
return 0;
}
static int zeroNoPage(struct uAddrVirtualReg *vreg, uaddr_t addr, int right)
{
(void)vreg;
(void)addr;
(void)right;
return 0;
}
static struct mappedRessourceOps zeroOps = {
.open = zeroOpen,
.close = zeroClose,
.unmap = NULL,
.nopage = zeroNoPage,
};
int zeroOnMapped(struct uAddrVirtualReg *vreg)
{
(void)vreg;
printf("ZERO MAPPED !!\n");
return 0;
}
int zeroMmap(struct uAddrSpace *as, uaddr_t *uaddr, size_t size, uint32_t rights,
uint32_t flags)
{
struct mappedRessource *res =
(struct mappedRessource *)zalloc(sizeof(struct mappedRessource));
struct zeroMappedEntry *cust =
(struct zeroMappedEntry *)zalloc(sizeof(struct zeroMappedEntry));
res->allowedRight = PAGING_MEM_READ | PAGING_MEM_WRITE | PAGING_MEM_EXEC | PAGING_MEM_USER;
res->ops = &zeroOps;
res->customData = cust;
res->onResMapped = zeroOnMapped;
return uAddrSpaceMmap(as, uaddr, size, rights, flags, res, 0);
}