Port-atari archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Weird calculation for kernel L2 segment table



Izumi Tsutsui wrote:

> sys/arch/amiga/amiga/amiga_init.c (and recently sync'ed atari_init.c)
> has the following calculations to get the level2 segment table
> for the kernel Sysptmap:
> 
> ---
>       /*
>        * Kernel segment table at end of next level 2 table
>        */
>       /* XXX fix calculations XXX */
>       i = ((((ptsize >> PGSHIFT) + 3) & -2) - 1) * (NPTEPG / SG4_LEV3SIZE);
>       sg = &((st_entry_t *)(RELOC(Sysseg_pa, u_int)))[SG4_LEV1SIZE + i];
>       esg = &sg[NPTEPG / SG4_LEV3SIZE];
>       sg_proto = Sysptmap_pa | SG_U | SG_RW | SG_V;
>       while (sg < esg) {
>           *sg++ = sg_proto;
>           sg_proto += (SG4_LEV3SIZE * sizeof (st_entry_t));
>       }
> ---
> 
> I think this could be rewritten more meaningfully as following:
> 
> ---
>       nl2desc = (ptsize >> PGSHIFT) * (NPTEPG / SG4_LEV3SIZE);
>   :
>       nl1desc = roundup(nl2desc, SG4_LEV2SIZE) / SG4_LEV2SIZE;
>   :
>       /*
>        * Kernel segment table at end of next level 2 table
>        */
>       i = SG4_LEV1SIZE + (nl1desc * SG4_LEV2SIZE);
>       sg = (st_entry_t *)RELOC(Sysseg_pa, u_int);
>       sg = &sg[i + SG4_LEV2SIZE - (NPTEPG / SG4_LEV3SIZE)];
>       esg = &sg[NPTEPG / SG4_LEV3SIZE];
>   :
> ---
> 
> With a quick test program, both offset values against Sysseg_pa
> look identical.

Without rereading the 040/060 manuals and without knowing about the current
layout of segment and page tables (first lev1 tables, then lev2, etc.?) in both
ports, I only got headaches after 30 minutes, so I decided to make a test! :)

I patched the NetBSD/amiga 4.0 release kernel with your changes and tried it
for some time on my A3000 with 68060. Booting, starting X11, compiling pkgsrc.

Works fine for me!


> How about this patch? Comments?
> [...]
> -     RELOC(protostfree, u_int) =
> -         (-1 << (i + 2)) /* & ~(-1 << MAXKL2SIZE) */;

BTW, as you are already reworking the code, IMHO it looks nicer to use ~0
instead of -1, especially when dealing with unsigned numbers.


-- 
    _  Frank Wille (frank%phoenix.owl.de@localhost)
 _ //  http://sun.hasenbraten.de/~frank/
 \X/   Phx @ #AmigaGer



Home | Main Index | Thread Index | Old Index