import "io" export { find_free_pages } let find_free_pages() be { let begin = ((! 0x101) >> 11) + 1; // begin = first (whole) free page number. let end = (! 0x100) >> 11; // end = first non-existent page number. let num_free = end - begin - 1; let pages_needed = (end >> 11) + 1; // how many pages needed to store the entire list of free pages let free_list = begin << 11; // free_list = ptr to list of free pages let first_free_page = begin + pages_needed; let i, pn, num_entries = pages_needed << 11; out("free page list stored at %x to %x\n", free_list, free_list + num_free - 1); // next put addresses of free pages in free page list i := 0; while i < num_free do { free_list ! i := (first_free_page + i) << 11; i +:= 1 } pn := 1; while pn < begin do { free_list ! i := pn << 11; i +:= 1; pn +:= 1 } while i < num_entries do { free_list ! i := 0; i +:= 1 } resultis free_list } let start() be { let free_page_list = find_free_pages(); let i = 0; out("find_free_pages returned %x\n", free_page_list); out("These will be all the free pages: "); while free_page_list ! i <> 0 do { out(" %d/%x", (free_page_list ! i) >> 11, free_page_list ! i); i +:= 1 } outch('\n') }