Port-amiga archive

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

Re: amigappc test kernel for CSPPC and BPPC



On Sat, 18 Dec 2010 22:58:31 +0100, Frank Wille <frank%phoenix.owl.de@localhost>
wrote:
> Radoslaw Kujawa wrote:
>>
>> Looks like I have to do the mftb asm magic. I checked arch/powerpc/ and
>> it seems we don't have any generic functions to access timebase
>> register.
> 
> Yes. Usually you will access the timebase only in few situations, until
> timecounter(9) is set up.

At first I read the datasheets, and tried to implement it myself. I
came up with following code:

static uint64_t
amigappc_gettimebase(void)
{
        uint64_t tbr;
        register uint32_t tbu, tbl;
        tbu = 0; tbl = 0;

        /* TBR register contains 64-bit value, which must
           be read as two 32-bit values on non 64-bit PowerPC */
        __asm ("mftbl %0; mftbu %1" : "=r"(tbl), "=r"(tbu));

        return (uint64_t)tbu << 32 | tbl;
}

Suspicious about my fast success, I looked again at the arch/powerpc
source, and after all, I've found mftb() in arch/powerpc/include/cpu.h.
If you read it, you'll see it's more complicated than my example. What I
didn't understand is why upper part of timebase is read twice, then
compared, then everything is looped if it's different. I googled for
some other implementations, and everybody is doing it that way. Of
course, nothing in "PowerPC Virtual Environment Architecture" or
"PowerPC Operationg Environment Architecture" document justifies the
need to execute mftbu twice.

I dug out really outdated (dated 1997) "PowerPC Microprocessor Family:
The Programming Environments For 32-Bit Microprocessors". Section "2.2.1
Reading the Time Base" states that: "Because of the possibility of a
carry from TBL to TBU occurring between reads of the TBL and TBU (...)
comparison and loop are necessary to ensure that a consistent pair of
values has been obtained".

Why is this information absent from newer documents (rhetorical
question)? Maybe it was needed only on older CPUs, maybe IBM already
forgot about 32-bit CPUs. Nevermind, I'll just use mftb() as implemented
in cpu.h. Just a "fun" fact.

>> Sounds good, but... how does one reset the timebase? I thought that
>> it's only possible to read from it.
> 
> In user mode. But in OEA mode you can also write to it.

Great, looks like it's possible with mtspr instruction. 
 
> Fortunately (or unfortunately?) not. I have just updated an hour ago and a
> generic kernel still boots on my CSPPC.
> 
> Do not update while in the middle of some development! ;)

Yes, after all, problem was with my tree. Checking out everything again
and then merging by hand fixed it, now kernel boots fine. 

-- 
Best regards,
RadosÅaw Kujawa


Home | Main Index | Thread Index | Old Index