2024-10-13 17:38:43 -05:00
|
|
|
PAGE_SIZE := 4096
|
|
|
|
MAX_ALLOC := 0xFF
|
2024-10-23 15:22:28 -05:00
|
|
|
MAX_FREE := 0xFF
|
|
|
|
|
2024-11-10 19:03:01 -06:00
|
|
|
uninit := fn($Expr: type): ?Expr {
|
|
|
|
return null
|
2024-11-10 12:57:48 -06:00
|
|
|
}
|
|
|
|
|
2024-11-08 07:47:24 -06:00
|
|
|
dangling := fn($Expr: type): ^Expr {
|
|
|
|
return @bitcast(@alignof(Expr))
|
2024-11-03 16:31:53 -06:00
|
|
|
}
|
|
|
|
|
2024-10-25 10:37:38 -05:00
|
|
|
calc_pages := fn($Expr: type, num: uint): uint {
|
|
|
|
return 1 + @sizeof(Expr) * num / PAGE_SIZE
|
2024-10-23 15:22:28 -05:00
|
|
|
}
|
2024-10-13 17:38:43 -05:00
|
|
|
|
2024-10-25 10:37:38 -05:00
|
|
|
alloc := fn($Expr: type, num: uint): ^Expr {
|
2024-10-23 15:22:28 -05:00
|
|
|
pages := @inline(calc_pages, Expr, num)
|
2024-10-13 17:38:43 -05:00
|
|
|
if pages <= MAX_ALLOC {
|
2024-10-23 15:22:28 -05:00
|
|
|
return @bitcast(request_page(@intcast(pages)))
|
2024-10-13 17:38:43 -05:00
|
|
|
}
|
2024-10-23 15:22:28 -05:00
|
|
|
ptr := request_page(0xFF)
|
2024-10-13 17:38:43 -05:00
|
|
|
remaining := pages - MAX_ALLOC
|
2024-10-25 10:37:38 -05:00
|
|
|
loop if remaining < MAX_ALLOC break else {
|
2024-11-03 16:31:53 -06:00
|
|
|
_ = request_page(@intcast(MAX_ALLOC))
|
2024-10-13 17:38:43 -05:00
|
|
|
remaining -= MAX_ALLOC
|
|
|
|
}
|
2024-11-03 16:31:53 -06:00
|
|
|
_ = request_page(@intcast(remaining))
|
2024-10-13 17:38:43 -05:00
|
|
|
return @bitcast(ptr)
|
|
|
|
}
|
|
|
|
|
2024-10-25 10:37:38 -05:00
|
|
|
// ! stub
|
|
|
|
free := fn($Expr: type, ptr: ^Expr, num: uint, nullify: bool): void {
|
2024-10-17 09:31:42 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-10-23 15:22:28 -05:00
|
|
|
RqPageMsg := packed struct {a: u8, count: u8}
|
|
|
|
request_page := fn(count: u8): ^u8 {
|
|
|
|
return @eca(3, 2, &RqPageMsg.(0, count), @sizeof(RqPageMsg))
|
2024-07-07 08:35:07 -05:00
|
|
|
}
|
|
|
|
|
2024-10-23 15:22:28 -05:00
|
|
|
RlPageMsg := packed struct {a: u8, count: u8, ptr: ^u8}
|
|
|
|
release_page := fn(ptr: ^u8, count: u8): void {
|
|
|
|
return @eca(3, 2, &RlPageMsg.(1, count, ptr), @sizeof(RlPageMsg))
|
2024-07-23 19:37:43 -05:00
|
|
|
}
|
|
|
|
|
2024-09-30 15:45:57 -05:00
|
|
|
OutbMsg := packed struct {a: u8, b: u8, addr: u16, value: u8}
|
2024-08-31 09:38:15 -05:00
|
|
|
outb := fn(addr: u16, value: u8): void {
|
2024-09-17 12:08:19 -05:00
|
|
|
return @eca(3, 3, &OutbMsg.(1, 0, addr, value), @sizeof(OutbMsg))
|
2024-08-31 09:38:15 -05:00
|
|
|
}
|
|
|
|
|
2024-10-23 15:22:28 -05:00
|
|
|
InbMsg := packed struct {a: u8, b: u8, addr: u16}
|
2024-08-31 09:38:15 -05:00
|
|
|
inb := fn(addr: u16): u8 {
|
2024-09-17 19:26:37 -05:00
|
|
|
return @eca(3, 3, &InbMsg.(0, 0, addr), @sizeof(InbMsg))
|
2024-08-31 09:38:15 -05:00
|
|
|
}
|
|
|
|
|
2024-10-23 15:22:28 -05:00
|
|
|
OutlMsg := packed struct {a: u8, b: u8, addr: u16, value: u32}
|
2024-08-31 09:38:15 -05:00
|
|
|
outl := fn(addr: u16, value: u32): void {
|
2024-09-17 12:08:19 -05:00
|
|
|
return @eca(3, 3, &OutlMsg.(1, 2, addr, value), @sizeof(OutlMsg))
|
2024-07-23 19:37:43 -05:00
|
|
|
}
|
|
|
|
|
2024-10-23 15:22:28 -05:00
|
|
|
InlMsg := packed struct {a: u8, b: u8, addr: u16}
|
2024-08-31 09:38:15 -05:00
|
|
|
inl := fn(addr: u16): u32 {
|
2024-09-17 12:08:19 -05:00
|
|
|
return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg))
|
2024-10-13 17:38:43 -05:00
|
|
|
}
|
|
|
|
|
2024-10-25 10:37:38 -05:00
|
|
|
CopyMsg := packed struct {a: u8, count: u32, src: ^u8, dest: ^u8}
|
2024-10-13 17:38:43 -05:00
|
|
|
copy := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void {
|
2024-10-25 10:37:38 -05:00
|
|
|
return @eca(3, 2, &CopyMsg.(4, @intcast(count * @sizeof(Expr)), @bitcast(src), @bitcast(dest)), @sizeof(CopyMsg))
|
2024-10-13 17:38:43 -05:00
|
|
|
}
|
|
|
|
|
2024-10-25 10:37:38 -05:00
|
|
|
SetMsg := packed struct {a: u8, count: u32, size: u32, src: ^u8, dest: ^u8}
|
2024-10-13 17:38:43 -05:00
|
|
|
set := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void {
|
2024-10-25 10:37:38 -05:00
|
|
|
return @eca(3, 2, &SetMsg.(5, @intcast(count), @intcast(@sizeof(Expr)), @bitcast(src), @bitcast(dest)), @sizeof(SetMsg))
|
2024-07-20 12:54:58 -05:00
|
|
|
}
|