Lab 11, _div, testing print

Interesting point we missed in lab10. Those are stubs that we have in main():
_div, _divu, _mod, _modu

Amazingly, I do not know what it is :),

Plan9/Inferno people, can you give a help regarding purpose of these references and way how they affect?
(I will update the lab as I get more info about this)

It is clear that without them fixed you can not have print() call working and other stuff in the kernel.
By checking/compiling/running/checking, we reveal that in other arm ports it is fixed in next way in l.s(load.s):

	...
	BL      ,main(SB)
dead:
	B       dead
	B       ,0(PC)
	BL      _div(SB)    /* hack to load _div, etc. */

As we have such code in load.s, then print() call can be used after we initialize serwrite variable. Also let’s add little more tracing to main() call to see more information:

	pl011_puts("Entered main() at ");
	pl011_addr(&main, 0);
	pl011_puts(" with SP=");
	pl011_addr((void *)getsp(), 1.);

	pl011_puts("Clearing Mach:  ");
	memset(m, 0, sizeof(Mach));
	pl011_addr((char *)m,		0); pl011_puts("-");
	pl011_addr((char *)(m+1),	1);

	pl011_puts("Clearing edata: ");
	memset(edata, 0, end-edata);
	pl011_addr((char *)&edata,	0); pl011_puts("-");
	pl011_addr((char *)&end,	1);

	conf.nmach = 1;
	serwrite = &pl011_serputs;

	confinit();
	xinit();
	poolinit();
	poolsizeinit();

	pl011_puts("to inifinite loop\n\n");
	for (;;);

Function pl011_addr() was created in the way that it can print address even when you have data segment broken (would be useful in debugging/tracing):

void
pl011_addr(void *a, int nl)
{
	int i;
	unsigned char *ca = (unsigned char *)&a;
	unsigned char h,l;

	for (i=3;i>=0;--i) {
		h = ca[i]/16;
		l = ca[i]%16;
		pl011_putc(h<10 ? h+0x30 : h-10+0x41);
		pl011_putc(l<10 ? l+0x30 : l-10+0x41);
	}
	if (nl) {
		pl011_putc(13);
		pl011_putc(10);
	}
}

So, that was a small lab to test everything that coded before with some small polishing.

Executing:

...
TFTP from server 10.0.55.112; our IP address is 10.0.55.105
Filename 'irpi'.
Load address: 0x7fe0
Loading: T #T #####################################
done
Bytes transferred = 543966 (84cde hex)
## Starting application at 0x00008000 ...
Entered main() at 00008404 with SP=00002FEC
Clearing Mach:  00002000-00002018
Clearing edata: 00064638-0006B760
Conf: top=134217728, npage0=32660, ialloc=26755072, nproc=735
to inifinite loop

FILES:
rpi
mkfile
fns.h
mem.h
load.s
armv6.s
main.c
pl011.c

This entry was posted in Blog, Inferno OS, Raspberry Pi, Research. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>