ref: fafd156dc3e294ae0952cbff110c2cf79587db02
parent: 207a4bb4a39ff7eac23018e5b8b9734a6d00171b
author: Ori Bernstein <[email protected]>
date: Fri Jul 20 21:55:56 EDT 2012
Work towards making the allocator compile.
--- a/alloc.myr
+++ b/alloc.myr
@@ -1,8 +1,7 @@
use "sys.use"
+use "types.use"
pkg std =
- type size = uint
-
generic alloc : ( -> @a*)
generic free : (v:@a* -> void)
@@ -27,7 +26,7 @@
type slab = struct
freehd : bin*
next : slab*
- nfree : int
+ nfree : size
;;
type bin = struct
@@ -46,10 +45,12 @@
var p
var s
- p = mmap(Zbyte, Mprotrw, Mpriv | Manon, -1, 0)
+ p = mmap(Zbyte, Pagesz, Mprotrw, Mpriv | Manon, -1, 0)
+ /*
if p == Mapbad
die("Unable to mmap")
;;
+ */
s = p castto(slab*)
s.nfree = b.nper
--- a/bld.sh
+++ b/bld.sh
@@ -28,8 +28,9 @@
$CC $ASOPT -m32 -c $1
}
-assem syscall.s
use sys.myr
+use types.myr
+assem syscall.s
build sys.myr
build hello.myr
build alloc.myr
--- a/sys.myr
+++ b/sys.myr
@@ -1,3 +1,5 @@
+use "types.use"
+
pkg std =
type scno = int
type fdopt = int
@@ -79,7 +81,7 @@
const lseek : (fd:int, off:uint, whence:int -> int)
const fstat : (fd:int, sb:statbuf* -> int)
const munmap : (addr:byte*, len:uint -> int)
- const mmap : (addr:byte*, len:uint, prot:uint, flags:uint, fd:int, off:uint)
+ const mmap : (addr:byte*, len:size, prot:mprot, flags:mopt, fd:int, off:off -> byte*)
;;
const exit = {status; -> syscall(Sysexit, 1);}
@@ -93,4 +95,4 @@
const lseek = {fd, off, whence; -> syscall(Syslseek, 2, fd, off, whence);}
const fstat = {fd, sb; -> syscall(Sysfstat, 2, fd, sb);}
const munmap = {addr, len; -> syscall(Sysmunmap, 2, addr, len);}
-const mmap = {addr, len, prot, flags, fd, off; -> syscall(Sysmmap2, 6, addr, len, prot, flags, fd, off);}
+const mmap = {addr, len, prot, flags, fd, off; -> syscall(Sysmmap2, 6, addr, len, prot, flags, fd, off) castto(byte*);}
--- /dev/null
+++ b/types.myr
@@ -1,0 +1,4 @@
+pkg std =
+ type size = uint32 /* spans entire address space */
+ type off = uint32 /* file offsets */
+;;