forked from AbleOS/ableos
79 lines
2.3 KiB
Plaintext
79 lines
2.3 KiB
Plaintext
$PAGE_SIZE := 4096
|
|
$MAX_ALLOC := 0xFF
|
|
$MAX_FREE := 0xFF
|
|
|
|
$uninit := fn($Expr: type): Expr {
|
|
return idk
|
|
}
|
|
|
|
$nulled := fn($Expr: type): ?Expr {
|
|
return null
|
|
}
|
|
|
|
$dangling := fn($Expr: type): ^Expr {
|
|
return @bitcast(@alignof(Expr))
|
|
}
|
|
|
|
$calc_pages := fn($Expr: type, num: uint): uint {
|
|
return (num + PAGE_SIZE - 1) / PAGE_SIZE
|
|
}
|
|
|
|
// ! will be replaced, don't get attached
|
|
alloc := fn($Expr: type, num: uint): ^Expr {
|
|
return @bitcast(request_page(@intcast(calc_pages(Expr, num))))
|
|
}
|
|
|
|
// ! stub
|
|
$free := fn($Expr: type, ptr: ^Expr, num: uint): void {
|
|
release_page(@bitcast(ptr), @intcast(calc_pages(Expr, num)))
|
|
}
|
|
|
|
RqPageMsg := packed struct {a: u8, count: uint}
|
|
$request_page := fn(count: uint): ^u8 {
|
|
return @eca(3, 2, &RqPageMsg.(0, count), @sizeof(RqPageMsg))
|
|
}
|
|
|
|
RlPageMsg := packed struct {a: u8, count: uint, ptr: ^u8}
|
|
$release_page := fn(ptr: ^u8, count: uint): void {
|
|
return @eca(3, 2, &RlPageMsg.(1, count, ptr), @sizeof(RlPageMsg))
|
|
}
|
|
|
|
OutbMsg := packed struct {a: u8, b: u8, addr: u16, value: u8}
|
|
$outb := fn(addr: u16, value: u8): void {
|
|
return @eca(3, 3, &OutbMsg.(1, 0, addr, value), @sizeof(OutbMsg))
|
|
}
|
|
|
|
InbMsg := packed struct {a: u8, b: u8, addr: u16}
|
|
$inb := fn(addr: u16): u8 {
|
|
return @eca(3, 3, &InbMsg.(0, 0, addr), @sizeof(InbMsg))
|
|
}
|
|
|
|
OutlMsg := packed struct {a: u8, b: u8, addr: u16, value: u32}
|
|
$outl := fn(addr: u16, value: u32): void {
|
|
return @eca(3, 3, &OutlMsg.(1, 2, addr, value), @sizeof(OutlMsg))
|
|
}
|
|
|
|
InlMsg := packed struct {a: u8, b: u8, addr: u16}
|
|
$inl := fn(addr: u16): u32 {
|
|
return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg))
|
|
}
|
|
|
|
OutsMsg := packed struct {a: u8, b: u8, addr: u16, value: u16}
|
|
$outs := fn(addr: u16, value: u32): void {
|
|
return @eca(3, 3, &OutsMsg.(1, 1, addr, value), @sizeof(OutsMsg))
|
|
}
|
|
|
|
InsMsg := packed struct {a: u8, b: u8, addr: u16}
|
|
$ins := fn(addr: u16): u16 {
|
|
return @eca(3, 3, &InsMsg.(0, 1, addr), @sizeof(InsMsg))
|
|
}
|
|
|
|
CopyMsg := packed struct {a: u8, count: uint, src: ^u8, dest: ^u8}
|
|
$copy := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void {
|
|
return @eca(3, 2, &CopyMsg.(4, count * @sizeof(Expr), @bitcast(src), @bitcast(dest)), @sizeof(CopyMsg))
|
|
}
|
|
|
|
SetMsg := packed struct {a: u8, count: uint, size: uint, src: ^u8, dest: ^u8}
|
|
$set := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void {
|
|
return @eca(3, 2, &SetMsg.(5, count, @sizeof(Expr), @bitcast(src), @bitcast(dest)), @sizeof(SetMsg))
|
|
} |