Checkpointing sorta works.

This commit is contained in:
C. Guy Yarvin 2014-09-24 00:38:37 -07:00
parent 4a7f146b4a
commit 3ae8f14c9c
11 changed files with 305 additions and 165 deletions

311
g/e.c
View File

@ -1,11 +1,13 @@
/* g/m.c
/* g/e.c
**
** This file is in the public domain.
*/
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <ctype.h>
#include <sigsegv.h>
#include <pmmintrin.h>
#include <xmmintrin.h>
#include "all.h"
@ -15,10 +17,11 @@ c3_i
u3_ce_fault(void* adr_v, c3_i ser_i)
{
if ( ser_i ) {
c3_w* adr_w = (c3_w*) adr_v;
c3_w* adr_w = (c3_w*) adr_v;
if ( (adr_w < u3_Loom) || (adr_w > (u3_Loom + u3_cc_pages)) ) {
if ( (adr_w < u3_Loom) || (adr_w > (u3_Loom + u3_cc_words)) ) {
fprintf(stderr, "address %p out of loom!\r\n", adr_v);
c3_assert(0);
return 0;
}
else {
@ -27,7 +30,8 @@ u3_ce_fault(void* adr_v, c3_i ser_i)
c3_w blk_w = (pag_w >> 5);
c3_w bit_w = (pag_w & 31);
c3_assert(0 == (u3P.dit_w[blk_w] & bit_w));
// printf("dirty page %d\r\n", pag_w);
c3_assert(0 == (u3P.dit_w[blk_w] & (1 << bit_w)));
u3P.dit_w[blk_w] |= (1 << bit_w);
if ( -1 == mprotect((void *)(u3_Loom + (pag_w << u3_cc_page)),
@ -35,6 +39,7 @@ u3_ce_fault(void* adr_v, c3_i ser_i)
(PROT_READ | PROT_WRITE)) )
{
perror("mprotect");
c3_assert(0);
return 0;
}
}
@ -42,11 +47,12 @@ u3_ce_fault(void* adr_v, c3_i ser_i)
return 1;
}
/* _ce_image_open(): open or create image. yes if it already exists.
/* _ce_image_open(): open or create image.
*/
static c3_o
_ce_image_open(u3_cs_image* img_u)
_ce_image_open(u3_cs_image* img_u, c3_o nuu_o)
{
c3_i mod_i = u3_so(nuu_o) ? (O_RDWR | O_CREAT) : O_RDWR;
c3_c ful_c[8193];
snprintf(ful_c, 8192, "%s", u3P.cpu_c);
@ -59,7 +65,11 @@ _ce_image_open(u3_cs_image* img_u)
mkdir(ful_c, 0700);
snprintf(ful_c, 8192, "%s/.urb/chk/%s.bin", u3P.cpu_c, img_u->nam_c);
if ( -1 != (img_u->fid_i = open(ful_c, O_RDWR)) ) {
if ( -1 == (img_u->fid_i = open(ful_c, mod_i, 0666)) ) {
perror(ful_c);
return u3_no;
}
else {
struct stat buf_u;
if ( -1 == fstat(img_u->fid_i, &buf_u) ) {
@ -71,26 +81,24 @@ _ce_image_open(u3_cs_image* img_u)
c3_d siz_d = buf_u.st_size;
c3_d pgs_d = (siz_d + (c3_d)((1 << (u3_cc_page + 2)) - 1)) >>
(c3_d)(u3_cc_page + 2);
if ( siz_d != (pgs_d << (c3_d)(u3_cc_page + 2)) ) {
fprintf(stderr, "%s: corrupt size %llx\r\n", ful_c, siz_d);
c3_assert(0);
return u3_no;
}
img_u->pgs_w = (c3_w) pgs_d;
c3_assert(pgs_d == (c3_d)img_u->pgs_w);
return u3_yes;
}
}
else {
if ( -1 == (img_u->fid_i = open(ful_c, O_RDWR | O_CREAT)) ) {
perror(ful_c);
c3_assert(0);
}
else {
img_u->pgs_w = 0;
return u3_no;
if ( u3_yes == nuu_o ) {
if ( siz_d ) {
c3_assert(0);
return u3_no;
}
return u3_yes;
}
else {
if ( siz_d != (pgs_d << (c3_d)(u3_cc_page + 2)) ) {
fprintf(stderr, "%s: corrupt size %llx\r\n", ful_c, siz_d);
return u3_no;
}
img_u->pgs_w = (c3_w) pgs_d;
c3_assert(pgs_d == (c3_d)img_u->pgs_w);
return u3_yes;
}
}
}
}
@ -151,12 +159,12 @@ _ce_patch_create(u3_cs_patch* pat_u)
snprintf(ful_c, 8192, "%s/.urb", u3P.cpu_c);
mkdir(ful_c, 0700);
snprintf(ful_c, 8192, "%s/.urb/control.bin", u3P.cpu_c);
snprintf(ful_c, 8192, "%s/.urb/chk/control.bin", u3P.cpu_c);
if ( -1 == (pat_u->ctl_i = open(ful_c, O_RDWR | O_CREAT | O_EXCL, 0666)) ) {
c3_assert(0);
}
snprintf(ful_c, 8192, "%s/.urb/memory.bin", u3P.cpu_c);
snprintf(ful_c, 8192, "%s/.urb/chk/memory.bin", u3P.cpu_c);
if ( -1 == (pat_u->mem_i = open(ful_c, O_RDWR | O_CREAT | O_EXCL, 0666)) ) {
c3_assert(0);
}
@ -169,10 +177,10 @@ _ce_patch_delete(void)
{
c3_c ful_c[8193];
snprintf(ful_c, 8192, "%s/.urb/control.bin", u3P.cpu_c);
snprintf(ful_c, 8192, "%s/.urb/chk/control.bin", u3P.cpu_c);
unlink(ful_c);
snprintf(ful_c, 8192, "%s/.urb/memory.bin", u3P.cpu_c);
snprintf(ful_c, 8192, "%s/.urb/chk/memory.bin", u3P.cpu_c);
unlink(ful_c);
}
@ -184,24 +192,34 @@ _ce_patch_verify(u3_cs_patch* pat_u)
c3_w i_w;
for ( i_w = 0; i_w < pat_u->con_u->pgs_w; i_w++ ) {
c3_w pag_w = pat_u->con_u->mem_u[i_w].pag_w;
c3_w mug_w = pat_u->con_u->mem_u[i_w].mug_w;
c3_w mem_w[u3_cc_page];
c3_w mem_w[1 << u3_cc_page];
if ( -1 == lseek(pat_u->mem_i, (i_w << (u3_cc_page + 2)), SEEK_SET) ) {
perror("seek");
c3_assert(0);
return u3_no;
}
if ( -1 == read(pat_u->mem_i, mem_w, (1 << (u3_cc_page + 2))) ) {
perror("read");
c3_assert(0);
return u3_no;
}
{
c3_w nug_w = u3_cr_mug_words(mem_w, u3_cc_page);
c3_w nug_w = u3_cr_mug_words(mem_w, (1 << u3_cc_page));
if ( mug_w != nug_w ) {
printf("_ce_patch_verify: mug mismatch (%x, %x)\r\n", mug_w, nug_w);
printf("_ce_patch_verify: mug mismatch %d/%d; (%x, %x)\r\n",
pag_w, i_w, mug_w, nug_w);
c3_assert(0);
return u3_no;
}
#if 0
else {
printf("verify: patch %d/%d, %x\r\n", pag_w, i_w, mug_w);
}
#endif
}
}
return u3_yes;
@ -233,12 +251,12 @@ _ce_patch_open(void)
snprintf(ful_c, 8192, "%s/.urb", u3P.cpu_c);
mkdir(ful_c, 0700);
snprintf(ful_c, 8192, "%s/.urb/control.bin", u3P.cpu_c);
snprintf(ful_c, 8192, "%s/.urb/chk/control.bin", u3P.cpu_c);
if ( -1 == (ctl_i = open(ful_c, O_RDWR)) ) {
return 0;
}
snprintf(ful_c, 8192, "%s/.urb/memory.bin", u3P.cpu_c);
snprintf(ful_c, 8192, "%s/.urb/chk/memory.bin", u3P.cpu_c);
if ( -1 == (mem_i = open(ful_c, O_RDWR)) ) {
close(ctl_i);
@ -312,8 +330,13 @@ _ce_patch_save_page(u3_cs_patch* pat_u,
c3_w* mem_w = u3_Loom + (pag_w << u3_cc_page);
pat_u->con_u->mem_u[pgc_w].pag_w = pag_w;
pat_u->con_u->mem_u[pgc_w].mug_w = u3_cr_mug_words(mem_w, u3_cc_page);
pat_u->con_u->mem_u[pgc_w].mug_w = u3_cr_mug_words(mem_w,
(1 << u3_cc_page));
#if 0
printf("patch: %d/%d, mug %x %p\n",
pag_w, pgc_w, u3_cr_mug_words(mem_w, (1 << u3_cc_page)));
#endif
_ce_patch_write_page(pat_u, pgc_w, mem_w);
if ( -1 == mprotect(u3_Loom + (pag_w << u3_cc_page),
@ -391,11 +414,15 @@ _ce_patch_compose(void)
pgc_w = _ce_patch_save_page(pat_u, i_w, pgc_w);
}
for ( i_w = 0; i_w < sou_w; i_w++ ) {
pgc_w = _ce_patch_save_page(pat_u, (u3_cc_pages - (i_w + 1)), pgs_w);
pgc_w = _ce_patch_save_page(pat_u, (u3_cc_pages - (i_w + 1)), pgc_w);
}
for ( i_w = nor_w; i_w < (u3_cc_pages - sou_w); i_w++ ) {
_ce_patch_junk_page(pat_u, i_w);
}
pat_u->con_u->nor_w = nor_w;
pat_u->con_u->sou_w = sou_w;
pat_u->con_u->pgs_w = pgc_w;
_ce_patch_write_control(pat_u);
return pat_u;
@ -442,15 +469,30 @@ _ce_patch_apply(u3_cs_patch* pat_u)
{
c3_w i_w;
printf("image: nor_w %d, new %d\r\n", u3P.nor_u.pgs_w, pat_u->con_u->nor_w);
printf("image: sou_w %d, new %d\r\n", u3P.sou_u.pgs_w, pat_u->con_u->sou_w);
if ( u3P.nor_u.pgs_w > pat_u->con_u->nor_w ) {
ftruncate(u3P.nor_u.fid_i, u3P.nor_u.pgs_w << (u3_cc_page + 2));
}
u3P.nor_u.pgs_w = pat_u->con_u->nor_w;
ftruncate(u3P.nor_u.fid_i, u3P.nor_u.pgs_w << (u3_cc_page + 2));
if ( u3P.sou_u.pgs_w > pat_u->con_u->sou_w ) {
ftruncate(u3P.sou_u.fid_i, u3P.sou_u.pgs_w << (u3_cc_page + 2));
}
u3P.sou_u.pgs_w = pat_u->con_u->sou_w;
ftruncate(u3P.sou_u.fid_i, u3P.sou_u.pgs_w << (u3_cc_page + 2));
if ( (-1 == lseek(pat_u->mem_i, 0, SEEK_SET)) ||
(-1 == lseek(u3P.nor_u.fid_i, 0, SEEK_SET)) ||
(-1 == lseek(u3P.sou_u.fid_i, 0, SEEK_SET)) )
{
perror("apply: seek");
c3_assert(0);
}
for ( i_w = 0; i_w < pat_u->con_u->pgs_w; i_w++ ) {
c3_w pag_w = pat_u->con_u->mem_u[i_w].pag_w;
c3_w mem_w[u3_cc_page];
c3_w mem_w[1 << u3_cc_page];
c3_i fid_i;
c3_w off_w;
@ -464,13 +506,18 @@ _ce_patch_apply(u3_cs_patch* pat_u)
}
if ( -1 == read(pat_u->mem_i, mem_w, (1 << (u3_cc_page + 2))) ) {
perror("apply: read");
c3_assert(0);
}
else {
if ( -1 == write(fid_i, mem_w, (1 << (u3_cc_page + 2))) ) {
perror("apply: write");
c3_assert(0);
}
}
#if 0
printf("apply: %d, %x\n", pag_w, u3_cr_mug_words(mem_w, (1 << u3_cc_page)));
#endif
}
}
@ -486,8 +533,18 @@ _ce_image_blit(u3_cs_image* img_u,
lseek(img_u->fid_i, 0, SEEK_SET);
for ( i_w=0; i_w < img_u->pgs_w; i_w++ ) {
if ( -1 == read(img_u->fid_i, ptr_w, (1 << (u3_cc_page + 2))) ) {
perror("read");
c3_assert(0);
}
#if 0
{
c3_w off_w = (ptr_w - u3_Loom);
c3_w pag_w = (off_w >> u3_cc_page);
printf("blit: page %d, mug %x\r\n", pag_w,
u3_cr_mug_words(ptr_w, (1 << u3_cc_page)));
}
#endif
ptr_w += stp_ws;
}
}
@ -505,14 +562,23 @@ u3_ce_save(void)
// in a separate thread, though we can't save again till this completes.
//
printf("_ce_patch_compose\r\n");
pat_u = _ce_patch_compose();
if ( !(pat_u = _ce_patch_compose()) ) {
return;
}
// Sync the patch files.
//
printf("_ce_patch_sync\r\n");
_ce_patch_sync(pat_u);
// Copy the patch files into the image file.
// Verify the patch - because why not?
//
printf("_ce_patch_verify\r\n");
_ce_patch_verify(pat_u);
exit(0);
// Write the patch data into the image file. Idempotent.
//
printf("_ce_patch_apply\r\n");
_ce_patch_apply(pat_u);
@ -531,7 +597,7 @@ u3_ce_save(void)
_ce_patch_free(pat_u);
}
/* _ce_limits(): set up file and stack limits.
/* _ce_limits(): set up global modes and limits.
*/
static void
_ce_limits(void)
@ -539,33 +605,51 @@ _ce_limits(void)
struct rlimit rlm;
c3_i ret_i;
#define LOOM_STACK (65536 << 10)
ret_i = getrlimit(RLIMIT_STACK, &rlm);
c3_assert(0 == ret_i);
rlm.rlim_cur = rlm.rlim_max > LOOM_STACK ? LOOM_STACK : rlm.rlim_max;
if ( 0 != setrlimit(RLIMIT_STACK, &rlm) ) {
perror("stack");
exit(1);
}
#undef LOOM_STACK
ret_i = getrlimit(RLIMIT_NOFILE, &rlm);
c3_assert(0 == ret_i);
rlm.rlim_cur = 4096;
if ( 0 != setrlimit(RLIMIT_NOFILE, &rlm) ) {
perror("file limit");
// no exit, not a critical limit
/* Set compatible floating-point modes.
*/
{
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
}
getrlimit(RLIMIT_CORE, &rlm);
rlm.rlim_cur = RLIM_INFINITY;
if ( 0 != setrlimit(RLIMIT_CORE, &rlm) ) {
perror("core limit");
// no exit, not a critical limit
/* Moar stack.
*/
{
ret_i = getrlimit(RLIMIT_STACK, &rlm);
c3_assert(0 == ret_i);
rlm.rlim_cur = (rlm.rlim_max > (65536 << 10))
? (65536 << 10)
: rlm.rlim_max;
if ( 0 != setrlimit(RLIMIT_STACK, &rlm) ) {
perror("stack");
exit(1);
}
}
/* Moar filez.
*/
{
ret_i = getrlimit(RLIMIT_NOFILE, &rlm);
c3_assert(0 == ret_i);
rlm.rlim_cur = 4096;
if ( 0 != setrlimit(RLIMIT_NOFILE, &rlm) ) {
perror("file limit");
// no exit, not a critical limit
}
}
/* Moar core.
*/
{
getrlimit(RLIMIT_CORE, &rlm);
rlm.rlim_cur = RLIM_INFINITY;
if ( 0 != setrlimit(RLIMIT_CORE, &rlm) ) {
perror("core limit");
// no exit, not a critical limit
}
}
}
#if 0
/* _ce_signals(): set up interrupts, etc.
*/
static void
@ -575,53 +659,77 @@ _ce_signals(void)
fprintf(stderr, "sigsegv install failed\n");
exit(1);
}
signal(SIGINT, _loom_stop);
// signal(SIGINT, _loom_stop);
}
#endif
/* u3_ce_boot(): start the memory system.
/* u3_ce_boot(): start the u3 system.
*/
void
u3_ce_boot(c3_c* cpu_c)
void
u3_ce_boot(c3_o nuu_o, c3_c* cpu_c)
{
u3P.cpu_c = cpu_c;
u3P.nor_u.nam_c = "north";
u3P.sou_u.nam_c = "south";
_ce_limits();
_ce_signals();
/* Map at fixed address.
*/
u3_Loom = (void *)U2_OS_LoomBase;
{
c3_w len_w = (1 << (u3_cc_bits + 2));
c3_w len_w = u3_cc_bytes;
void* map_v;
map_v = mmap((void *)u3_Loom,
len_w,
// PROT_READ,
PROT_READ | PROT_WRITE,
u3_so(nuu_o) ? PROT_READ : (PROT_READ | PROT_WRITE),
(MAP_ANON | MAP_FIXED | MAP_PRIVATE),
-1, 0);
if ( -1 == (c3_ps)map_v ) {
map_v = mmap((void *)0,
len_w,
PROT_READ | PROT_WRITE,
PROT_READ,
MAP_ANON | MAP_PRIVATE,
-1, 0);
if ( -1 == (c3_ps)map_v ) {
fprintf(stderr, "map failed twice\n");
fprintf(stderr, "boot: map failed twice\r\n");
} else {
fprintf(stderr, "map failed - try U2_OS_LoomBase %p\n", map_v);
fprintf(stderr, "boot: map failed - try U2_OS_LoomBase %p\r\n", map_v);
}
exit(1);
}
printf("loom: mapped %dMB\n", len_w >> 20);
printf("loom: mapped %dMB\r\n", len_w >> 20);
}
/* Open and apply any patches.
*/
{
if ( u3_so(nuu_o) ) {
if ( (u3_no == _ce_image_open(&u3P.nor_u, u3_yes)) ||
(u3_no == _ce_image_open(&u3P.sou_u, u3_yes)) )
{
printf("boot: image failed\r\n");
exit(1);
}
}
else {
u3_cs_patch* pat_u;
/* Open image files.
*/
{
if ( (u3_no == _ce_image_open(&u3P.nor_u, u3_no)) ||
(u3_no == _ce_image_open(&u3P.sou_u, u3_no)) )
{
fprintf(stderr, "boot: no image\r\n");
exit(1);
}
}
/* Load any patch files; apply them to images.
*/
if ( 0 != (pat_u = _ce_patch_open()) ) {
printf("_ce_patch_apply\r\n");
_ce_patch_apply(pat_u);
@ -635,22 +743,41 @@ u3_ce_boot(c3_c* cpu_c)
printf("_ce_patch_free\r\n");
_ce_patch_free(pat_u);
}
}
/* Open and load, or create, image files.
*/
{
u3P.cpu_c = cpu_c;
u3P.nor_u.nam_c = "north";
u3P.sou_u.nam_c = "south";
/* Write image files to memory; reinstate protection.
*/
{
_ce_image_blit(&u3P.nor_u,
u3_Loom,
(1 << u3_cc_page));
if ( u3_yes == _ce_image_open(&u3P.nor_u) ) {
_ce_image_blit(&u3P.nor_u, u3_Loom, (1 << u3_cc_page));
}
if ( u3_yes == _ce_image_open(&u3P.sou_u) ) {
_ce_image_blit(&u3P.sou_u,
(u3_Loom + (1 << u3_cc_bits) - (1 << u3_cc_page)),
-(1 << u3_cc_page));
mprotect(u3_Loom, (1 << (u3_cc_bits + 2)), PROT_READ);
}
}
/* Construct or activate the allocator.
*/
u3_cm_boot(nuu_o);
/* Initialize the jet system.
*/
u3_cj_boot();
/* Install the kernel.
*/
if ( u3_so(nuu_o) ) {
c3_c pas_c[2049];
snprintf(pas_c, 2048, "%s/.urb/urbit.pill", cpu_c);
printf("boot: loading %s\r\n", pas_c);
u3_cv_make(pas_c);
}
else {
u3_cj_clear();
}
u3_cv_jack();
}

37
g/j.c
View File

@ -50,15 +50,16 @@ u3_cj_boot(void)
c3_w jax_l;
u3D.len_l =_cj_count(0, u3D.dev_u);
u3D.all_l = (2 * u3D.len_l) + 64; // horrid heuristic
u3D.ray_u = (u3_cs_core*) malloc((1 + u3D.len_l) * sizeof(u3_cs_core));
memset(u3D.ray_u, 0, ((1 + u3D.len_l) * sizeof(u3_cs_core)));
u3D.ray_u = (u3_cs_core*) malloc(u3D.all_l * sizeof(u3_cs_core));
memset(u3D.ray_u, 0, (u3D.all_l * sizeof(u3_cs_core)));
jax_l = _cj_install(u3D.ray_u, 1, u3D.dev_u);
printf("boot: installed %d jets\n", jax_l);
}
/* _cj_insert(): append copy of core driver to jet table.
/* _cj_insert(): append copy of core driver to jet table. For dummies.
*/
static c3_l
_cj_insert(u3_cs_core* cop_u)
@ -66,7 +67,7 @@ _cj_insert(u3_cs_core* cop_u)
c3_l jax_l = u3D.len_l;
u3D.len_l += 1;
u3D.ray_u = realloc(u3D.ray_u, u3D.len_l * sizeof(u3_cs_core));
c3_assert(u3D.len_l < u3D.all_l);
memcpy(&u3D.ray_u[jax_l], cop_u, sizeof(u3_cs_core));
cop_u->jax_l = jax_l;
@ -468,6 +469,15 @@ _cj_chum(u3_noun chu)
}
}
/* u3_cj_clear(): clear jet table to re-register.
*/
void
u3_cj_clear(void)
{
u3_ch_free(u3R->jed.har_u);
u3R->jed.har_u = u3_ch_new();
}
/* u3_cj_mine(): register core for jets.
*/
u3_noun
@ -579,16 +589,7 @@ u3_cj_mine(u3_noun clu,
c3_assert(0 != jax_l);
free(nam_c);
printf("mine: bound jet %s, %d\r\n", cop_u->cos_c, cop_u->jax_l);
if ( 159 == jax_l ) {
printf("at 159, parent is %p %p %s %d %p\r\n",
u3D.ray_u[jax_l].par_u,
par_u,
par_u->cos_c,
par_l,
&u3D.ray_u[par_l]);
}
// printf("mine: bound jet %s, %d\r\n", cop_u->cos_c, cop_u->jax_l);
break;
}
i_l++;
@ -603,18 +604,14 @@ u3_cj_mine(u3_noun clu,
fak_u.par_u = par_u;
fak_u.axe_l = axe_l;
jax_l =_cj_insert(&fak_u);
printf("mine: dummy %s %d\r\n", fak_u.cos_c, jax_l);
jax_l = _cj_insert(&fak_u);
// printf("mine: dummy %s %d\r\n", fak_u.cos_c, jax_l);
}
u3_ch_put(u3R->jed.har_u, u3h(cor), jax_l);
u3z(clu);
_cj_activate(&u3D.ray_u[jax_l], hud_u);
if ( 159 == jax_l ) {
printf("at 159, parent is %p\r\n",
u3D.ray_u[jax_l].par_u);
}
#if 0
{
u3_cs_core* cop_u = &u3D.ray_u[jax_l];

29
g/m.c
View File

@ -116,28 +116,21 @@ _boot_parts(void)
u3R->jed.har_u = u3_ch_new();
}
/* u3_cm_load(): load u3H in existing
/* u3_cm_boot(): instantiate or activate image.
*/
void
u3_cm_boot(void)
u3_cm_boot(c3_o nuu_o)
{
c3_w len_w = (1 << u3_cc_bits);
if ( u3_yes == nuu_o ) {
u3H = (void *)_boot_north(u3_Loom, c3_wiseof(u3_cs_home), u3_cc_words);
u3R = &u3H->rod_u;
u3H = (u3_cs_home *)_boot_north(u3_Loom, c3_wiseof(u3_cs_home), len_w);
u3R = &u3H->rod_u;
_boot_parts();
}
/* u3_cm_load(): make u3R and u3H from nothing.
*/
void
u3_cm_load(void)
{
c3_w len_w = (1 << u3_cc_bits);
u3H = (u3_cs_home *)_find_north(u3_Loom, c3_wiseof(u3_cs_home), len_w);
u3R = &u3H->rod_u;
_boot_parts();
}
else {
u3H = (void *)_find_north(u3_Loom, c3_wiseof(u3_cs_home), u3_cc_words);
u3R = &u3H->rod_u;
}
}
/* u3_cm_clear(): clear all allocated data in road.

36
g/v.c
View File

@ -18,33 +18,45 @@ _cv_nock_wish(u3_noun txt)
/* u3_cv_make(): make a new pier and instantiate pill.
*/
void
u3_cv_make(c3_c* pas_c, u3_noun now)
u3_cv_make(c3_c* pas_c)
{
u3_noun sys = u3_cke_cue(u3_cm_file(pas_c));
printf("cv_make: loaded pill %s, as %x\n", pas_c, u3_cr_mug(sys));
u3A->ken = u3k(u3h(sys));
printf("cv_make: kernel %x, mug %x\n", u3A->ken, u3_cr_mug(u3A->ken));
{
u3_noun cor = u3_cn_nock_on(0, u3k(u3A->ken));
printf("cv_make: activated kernel\n");
u3z(cor);
}
u3A->roc = u3k(u3t(sys));
u3z(sys);
printf("cv_make: core mug %x\n", u3_cr_mug(u3A->roc));
printf("cv_make: kernel %x, core %x\n",
u3_cr_mug(u3A->ken), u3_cr_mug(u3A->roc));
}
/* u3_cv_jack(): execute kernel formula to bind jets.
*/
void
u3_cv_jack(void)
{
u3_noun cor;
printf("cv_jack: activating kernel %x\n", u3_cr_mug(u3A->ken));
cor = u3_cn_nock_on(0, u3k(u3A->ken));
printf("cv_jack: activated\n");
u3z(cor);
}
/* u3_cv_start(): start time.
*/
void
u3_cv_start(u3_noun now)
{
u3_cv_time(now);
u3_cv_numb();
{
c3_c* wen_c = u3_cr_string(u3A->wen);
printf("cv_make: time: %s\n", wen_c);
printf("cv_start: time: %s\n", wen_c);
free(wen_c);
}
}

View File

@ -17,4 +17,4 @@
/* u3_ce_boot(): start the memory system.
*/
void
u3_ce_boot(c3_c* cpu_c);
u3_ce_boot(c3_o nuu_o, c3_c* cpu_c);

View File

@ -9,6 +9,11 @@
void
u3_cj_boot(void);
/* u3_cj_clear(): clear jet table to re-register.
*/
void
u3_cj_clear(void);
/* u3_cj_hook():
**
** Execute hook from core.

View File

@ -7,7 +7,7 @@
/* u3_cm_boot(): set up top-level road.
*/
void
u3_cm_boot();
u3_cm_boot(c3_o nuu_o);
/* u3_cm_trap(): setjmp within road.
*/

View File

@ -19,7 +19,17 @@
/* u3_cv_make(): make a new pier by loading a pill.
*/
void
u3_cv_make(c3_c* pas_c, u3_noun now);
u3_cv_make(c3_c* pas_c);
/* u3_cv_jack(): execute kernel formula to bind jets.
*/
void
u3_cv_jack(void);
/* u3_cv_start(): start time.
*/
void
u3_cv_start(u3_noun now);
/* u3_cv_gate(): load a kernel function.
*/

View File

@ -52,5 +52,6 @@
typedef struct _u3_cs_dash {
u3_cs_core* dev_u; // null-terminated static list
c3_l len_l; // dynamic array length
c3_l all_l; // allocated length
u3_cs_core* ray_u; // dynamic array by axis
} u3_cs_dash;

View File

@ -15,3 +15,5 @@
# define u3_cc_bits U2_OS_LoomBits // 28, max 29
# define u3_cc_page 12 // 16Kbyte pages
# define u3_cc_pages (1 << (u3_cc_bits - u3_cc_page)) // 2^16 pages
# define u3_cc_words (1 << u3_cc_bits)
# define u3_cc_bytes (1 << (2 + u3_cc_bits))

View File

@ -18,8 +18,6 @@
#include <termios.h>
#include <term.h>
#include <dirent.h>
#include <pmmintrin.h>
#include <xmmintrin.h>
#define U2_GLOBAL
#define C3_GLOBAL
@ -244,9 +242,6 @@ c3_i
main(c3_i argc,
c3_c** argv)
{
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
// Parse options.
//
if ( u3_no == _main_getopt(argc, argv) ) {
@ -262,7 +257,7 @@ main(c3_i argc,
printf("vere: hostname is %s\n", u3_Host.ops_u.nam_c);
if ( u3_yes == u3_Host.ops_u.dem && u3_no == u3_Host.ops_u.bat ) {
printf("Starting daemon\n");
printf("vere: running as daemon\n");
}
// Seed prng. Don't panic -- just for fuzz testing.
@ -273,29 +268,27 @@ main(c3_i argc,
{
/* Boot the image and checkpoint.
*/
u3_ce_boot(u3_Host.cpu_c);
u3_ce_boot(u3_Host.ops_u.nuu, u3_Host.cpu_c);
/* Boot the allocator.
*/
u3_cm_boot();
/* Boot jets.
*/
u3_cj_boot();
/* Boot arvo kernel.
/* Start Arvo.
*/
{
struct timeval tim_tv;
u3_noun now;
c3_c pas_c[2049];
// snprintf(pas_c, 2048, "%s/.urb/dummy.pill", u3_Host.cpu_c);
snprintf(pas_c, 2048, "%s/.urb/urbit.pill", u3_Host.cpu_c);
gettimeofday(&tim_tv, 0);
now = u3_time_in_tv(&tim_tv);
u3_cv_make(pas_c, now);
u3_cv_start(now);
}
/* Initial checkpoint.
*/
if ( u3_so(u3_Host.ops_u.nuu) ) {
printf("about to save.\r\n");
u3_ce_save();
printf("saved.\r\n");
exit(1);
}
}