Various fixes and improvements.

This commit is contained in:
C. Guy Yarvin 2014-10-31 15:36:01 -07:00
parent ab98aeecdc
commit ff243f1280
8 changed files with 178 additions and 19 deletions

10
g/a.c
View File

@ -274,7 +274,7 @@ u3_ca_walloc(c3_w len_w)
{
void* ptr_v = _ca_walloc(len_w);
#if 1
#if 0
if ( (703 == u3_Code) &&
u3_co_botox(ptr_v) == (u3_cs_box*)(void *)0x200dfe3e4 ) {
static int xuc_i;
@ -1020,10 +1020,14 @@ c3_w
u3_ca_mark_ptr(void* ptr_v)
{
if ( u3_so(u3_co_is_north(u3R)) ) {
c3_assert((ptr_v >= (void*)u3R->rut_w) && (ptr_v < (void*)u3R->hat_w));
if ( !((ptr_v >= (void*)u3R->rut_w) && (ptr_v < (void*)u3R->hat_w)) ) {
return 0;
}
}
else {
c3_assert((ptr_v >= (void*)u3R->hat_w) && (ptr_v < (void*)u3R->rut_w));
if ( !((ptr_v >= (void*)u3R->hat_w) && (ptr_v < (void*)u3R->rut_w)) ) {
return 0;
}
}
{
u3_cs_box* box_u = u3_co_botox(ptr_v);

138
g/e.c
View File

@ -11,6 +11,68 @@
#include "all.h"
#if 0
/* Image check.
*/
struct {
c3_w nor_w;
c3_w sou_w;
c3_w mug_w[u3_cc_pages];
} u3K;
/* _ce_check_page(): checksum page.
*/
static c3_w
_ce_check_page(c3_w pag_w)
{
c3_w* mem_w = u3_Loom + (pag_w << u3_cc_page);
c3_w mug_w = u3_cr_mug_words(mem_w, (1 << u3_cc_page));
return mug_w;
}
/* u3_ce_check(): compute a checksum on all memory within the watermarks.
*/
void
u3_ce_check(c3_c* cap_c)
{
c3_w nor_w = 0;
c3_w sou_w = 0;
{
c3_w nwr_w, swu_w;
u3_cm_water(&nwr_w, &swu_w);
nor_w = (nwr_w + ((1 << u3_cc_page) - 1)) >> u3_cc_page;
sou_w = (swu_w + ((1 << u3_cc_page) - 1)) >> u3_cc_page;
}
/* Count dirty pages.
*/
{
c3_w i_w, sum_w, mug_w;
sum_w = 0;
for ( i_w = 0; i_w < nor_w; i_w++ ) {
mug_w = _ce_check_page(i_w);
if ( strcmp(cap_c, "boot") ) {
c3_assert(mug_w == u3K.mug_w[i_w]);
}
sum_w += mug_w;
}
for ( i_w = 0; i_w < sou_w; i_w++ ) {
mug_w = _ce_check_page((u3_cc_pages - (i_w + 1)));
if ( strcmp(cap_c, "boot") ) {
c3_assert(mug_w == u3K.mug_w[(u3_cc_pages - (i_w + 1))]);
}
sum_w += mug_w;
}
printf("%s: sum %x (%x, %x)\r\n", cap_c, sum_w, nor_w, sou_w);
}
}
#endif
/* u3_ce_fault(): handle a memory event with libsigsegv protocol.
*/
c3_i
@ -334,8 +396,9 @@ _ce_patch_save_page(u3_cs_patch* pat_u,
(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)));
u3K.mug_w[pag_w] = pat_u->con_u->mem_u[pgc_w].mug_w;
printf("save: page %d, mug %x\r\n",
pag_w, u3_cr_mug_words(mem_w, (1 << u3_cc_page)));
#endif
_ce_patch_write_page(pat_u, pgc_w, mem_w);
@ -345,7 +408,7 @@ _ce_patch_save_page(u3_cs_patch* pat_u,
{
c3_assert(0);
}
u3P.dit_w[blk_w] &= ~(1 << bit_w);
pgc_w += 1;
}
@ -389,6 +452,8 @@ _ce_patch_compose(void)
nor_w = (nwr_w + ((1 << u3_cc_page) - 1)) >> u3_cc_page;
sou_w = (swu_w + ((1 << u3_cc_page) - 1)) >> u3_cc_page;
}
// u3K.nor_w = nor_w;
// u3K.sou_w = sou_w;
/* Count dirty pages.
*/
@ -404,6 +469,7 @@ _ce_patch_compose(void)
}
if ( !pgs_w ) {
fprintf(stderr, "no dirty pages\r\n");
return 0;
}
else {
@ -514,6 +580,10 @@ _ce_patch_apply(u3_cs_patch* pat_u)
c3_assert(0);
}
else {
if ( -1 == lseek(fid_i, (off_w << (u3_cc_page + 2)), SEEK_SET) ) {
perror("apply: lseek");
c3_assert(0);
}
if ( -1 == write(fid_i, mem_w, (1 << (u3_cc_page + 2))) ) {
perror("apply: write");
c3_assert(0);
@ -553,6 +623,43 @@ _ce_image_blit(u3_cs_image* img_u,
}
}
#if 0
/* _ce_image_fine(): compare image to memory.
*/
static void
_ce_image_fine(u3_cs_image* img_u,
c3_w* ptr_w,
c3_ws stp_ws)
{
c3_w i_w;
c3_w buf_w[1 << u3_cc_page];
lseek(img_u->fid_i, 0, SEEK_SET);
for ( i_w=0; i_w < img_u->pgs_w; i_w++ ) {
c3_w mem_w, fil_w;
if ( -1 == read(img_u->fid_i, buf_w, (1 << (u3_cc_page + 2))) ) {
perror("read");
c3_assert(0);
}
mem_w = u3_cr_mug_words(ptr_w, (1 << u3_cc_page));
fil_w = u3_cr_mug_words(buf_w, (1 << u3_cc_page));
if ( mem_w != fil_w ) {
c3_w pag_w = (ptr_w - u3_Loom) >> u3_cc_page;
fprintf(stderr, "mismatch: page %d, mem_w %x, fil_w %x, K %x\r\n",
pag_w,
mem_w,
fil_w,
u3K.mug_w[pag_w]);
abort();
}
ptr_w += stp_ws;
}
}
#endif
/* u3_ce_save(): save current changes.
*/
void
@ -565,7 +672,7 @@ u3_ce_save(void)
// This has to block the main thread. All further processing can happen
// in a separate thread, though we can't save again till this completes.
//
// printf("_ce_patch_compose\r\n");
if ( !(pat_u = _ce_patch_compose()) ) {
return;
}
@ -585,6 +692,21 @@ u3_ce_save(void)
// printf("_ce_patch_apply\r\n");
_ce_patch_apply(pat_u);
#if 0
{
_ce_image_fine(&u3P.nor_u,
u3_Loom,
(1 << u3_cc_page));
_ce_image_fine(&u3P.sou_u,
(u3_Loom + (1 << u3_cc_bits) - (1 << u3_cc_page)),
-(1 << u3_cc_page));
c3_assert(u3P.nor_u.pgs_w == u3K.nor_w);
c3_assert(u3P.sou_u.pgs_w == u3K.sou_w);
}
#endif
// Sync the image file.
//
// printf("_ce_image_sync\r\n");
@ -792,12 +914,17 @@ u3_ce_boot(c3_o nuu_o, c3_o bug_o, c3_c* cpu_c)
(u3_Loom + (1 << u3_cc_bits) - (1 << u3_cc_page)),
-(1 << u3_cc_page));
mprotect(u3_Loom, (1 << (u3_cc_bits + 2)), PROT_READ);
if ( 0 != mprotect((void *)u3_Loom, u3_cc_bytes, PROT_READ) ) {
perror("protect");
c3_assert(0);
}
printf("protected loom\r\n");
}
/* If the images were empty, we are logically booting.
*/
if ( (0 == u3P.nor_u.pgs_w) && (0 == u3P.sou_u.pgs_w) ) {
printf("logical boot\r\n");
nuu_o = u3_yes;
}
}
@ -822,6 +949,7 @@ u3_ce_boot(c3_o nuu_o, c3_o bug_o, c3_c* cpu_c)
u3_cv_jack();
}
else {
u3_cv_hose();
u3_cj_ream();
}
}

28
g/v.c
View File

@ -46,6 +46,26 @@ u3_cv_jack(void)
u3z(cor);
}
/* u3_cv_hose(): clear initial ovum queue.
*/
void
u3_cv_hose(void)
{
u3_cs_cart* egg_u = u3A->ova.egg_u;
while ( egg_u ) {
u3_cs_cart* nex_u = egg_u->nex_u;
u3_ca_lose(egg_u->vir);
u3_ca_free(egg_u);
egg_u = nex_u;
}
u3A->ova.egg_u = u3A->ova.geg_u = 0;
u3z(u3A->roe);
u3A->roe = u3_nul;
}
/* u3_cv_start(): start time.
*/
void
@ -190,7 +210,7 @@ _cv_nock_poke(u3_noun ovo)
u3_noun tox = u3_do("spat", u3k(u3h(ovo)));
c3_c* tox_c = u3_cr_string(tox);
printf("poke: %%%s on %s\r\n", ovi_c, tox_c);
printf("poke: %%%s (%x) on %s\r\n", ovi_c, u3_cr_mug(ovo), tox_c);
free(tox_c); free(ovi_c); u3z(tox);
}
#endif
@ -449,12 +469,14 @@ u3_cv_louse(c3_m how_m)
#endif
}
/* _cv_mark_ova(): mark queued ovum.
/* _cv_mark_ova(): mark ova queue.
*/
static void
_cv_mark_ova(u3_cs_cart* egg_u)
{
while ( egg_u ) {
u3_ca_mark_ptr(egg_u);
u3_ca_mark_noun(egg_u->vir);
egg_u = egg_u->nex_u;
}
@ -479,5 +501,5 @@ u3_cv_mark(void)
u3_ca_mark_noun(arv_u->ken);
u3_ca_mark_noun(arv_u->roc);
_cv_mark_ova(arv_u->ova.geg_u);
_cv_mark_ova(arv_u->ova.egg_u);
}

View File

@ -28,3 +28,4 @@
*/
void
u3_ce_grab(c3_c* cap_c, u3_noun som, ...); // terminate with u3_none

View File

@ -111,6 +111,11 @@
void
u3_cv_plow(u3_noun ova);
/* u3_cv_hose(): clear initial ovum queue.
*/
void
u3_cv_hose(void);
/* u3_cv_louse(): last-minute deviltry upon a bail.
*/
void

View File

@ -6,7 +6,7 @@
**/
# define u3_cc_fbox_no 28
# define U3_MEMORY_DEBUG
# undef U3_MEMORY_DEBUG
# ifdef U3_MEMORY_DEBUG
# define u3_leak_on(x) (u3_Code = x)
# define u3_leak_off (u3_Code = 0)
@ -16,4 +16,4 @@
# 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))
# define u3_cc_bytes (c3_w)((1 << (2 + u3_cc_bits)))

View File

@ -172,7 +172,7 @@ _lo_init()
u3_term_io_init();
u3_http_io_init();
u3_cttp_io_init();
// u3_save_io_init();
u3_save_io_init();
u3_batz_io_init();
}
@ -197,7 +197,7 @@ u3_lo_exit(void)
u3_term_io_exit();
u3_http_io_exit();
u3_cttp_io_exit();
// u3_save_io_exit();
u3_save_io_exit();
u3_batz_io_exit();
}
@ -209,7 +209,7 @@ _lo_poll(void)
u3_ames_io_poll();
u3_http_io_poll();
u3_term_io_poll();
// u3_save_io_poll();
u3_save_io_poll();
u3_unix_io_poll();
u3_batz_io_poll();
}
@ -395,7 +395,6 @@ u3_lo_shut(u3_bean inn)
//
_lo_poll();
}
u3_leak_off;
}
#if 0

View File

@ -1719,7 +1719,7 @@ u3_raft_work(void)
}
egg_u->cit = u3_yes;
free(egg_u);
u3_ca_free(egg_u);
}
else break;
}
@ -1761,7 +1761,7 @@ u3_raft_work(void)
u3z(ova); ova = nex;
if ( u3_nul != ovo ) {
egg_u = c3_malloc(sizeof(*egg_u));
egg_u = u3_ca_malloc(sizeof(*egg_u));
egg_u->nex_u = 0;
egg_u->cit = u3_no;
egg_u->did = u3_no;