Skip to content

Commit

Permalink
tweak settings on fu540
Browse files Browse the repository at this point in the history
Also add a file, src/device/sifive/device_fu540.go, which
covers bits not in the fu540.svd.

With these changes, my simple GoSBI is running, though not correctly.

Signed-off-by: Ronald G Minnich <[email protected]>
  • Loading branch information
rminnich committed Feb 21, 2024
1 parent b90cd62 commit 7fba095
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 17 deletions.
14 changes: 14 additions & 0 deletions src/device/sifive/device_fu540.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
// as they were in the fe310.
package sifive

import (
"runtime/volatile"
"unsafe"
)

// Coreplex Local Interrupts
type CLINT_Type struct {
MSIP [5]volatile.Register32 // 0x0
_ [0x4000 - 5*32]byte
MTIMECMP [5]volatile.Register64 // 0x4000
_ [0xbff8 - (5*64 - 0x4000 - 5*32)]byte
MTIME volatile.Register64 // 0xBFF8
}

var (
// Coreplex Local Interrupts
CLINT = (*CLINT_Type)(unsafe.Pointer(uintptr(0x2000000)))
Expand Down
56 changes: 55 additions & 1 deletion src/machine/machine_fu540.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,67 @@
package machine

import (
"device/sifive"
"errors"
"unsafe"

"device/riscv"
"device/sifive"
"runtime/interrupt"
)

const deviceName = sifive.Device

// non-SVD-stuff.
// On the FE310, these are in the SVD. But not on the other
// parts, which is ... strange.

const (
MaxCore = 5
CLINTMSIP uintptr = 0x2000000
CLINTTimeCmp uintptr = 0x204000
CLINTTime uintptr = 0x20bff8
)

var (
// Coreplex Local Interrupts
)

// MSIPn returns the n'th MSIP.
// It is allowed to be called with a bad value, and will return
// 0, always.
func MSIPn(n uintptr) uint32 {
if n > MaxCore {
return 0
}
return *(*uint32)(unsafe.Pointer(CLINTMSIP + n*4))
}

// MSIP returns the MSIP for the current HART.
func MSIP() uint32 {
return MSIPn(riscv.MHARTID.Get())
}

// MTimeCmpN returns the n'th MTimeCmp.
// It is allowed to be called with a bad value, and will return
// 0, always.
func MTimeCmpN(n uintptr) uint64 {
if n > MaxCore {
return 0
}
return *(*uint64)(unsafe.Pointer(CLINTTimeCmp + n*8))
}

// MTimeCmp returns the MTimeCmp for the current HART.
func MTimeCmp() uint64 {
return MTimeCmpN(riscv.MHARTID.Get())
}

// MTimer returns the Mtime
func MTime() uint64 {
return *(*uint64)(unsafe.Pointer(CLINTTime))
}

// End non-SVD-stuff.
func CPUFrequency() uint32 {
return 390000000
}
Expand Down
20 changes: 5 additions & 15 deletions src/runtime/runtime_fu540.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package runtime

import (
"device/riscv"
_ "device/sifive"
"device/sifive"
"machine"
"runtime/volatile"
"unsafe"
Expand Down Expand Up @@ -135,23 +135,13 @@ func buffered() int {
var timerWakeup volatile.Register8

func ticks() timeUnit {
panic("ticks")
// highBits := uint32(sifive.CLINT.MTIME.Get() >> 32)
// for {
// lowBits := uint32(sifive.CLINT.MTIME.Get() & 0xffffffff)
// newHighBits := uint32(sifive.CLINT.MTIME.Get() >> 32)
// if newHighBits == highBits {
// return timeUnit(lowBits) | (timeUnit(highBits) << 32)
// }
// highBits = newHighBits
// }
return timeUnit(sifive.CLINT.MTIME.Get())
}

func sleepTicks(d timeUnit) {

panic("no sleep yet")
//target := uint64(ticks() + d)
//sifive.CLINT.MTIMECMP[0].Set(target)
hartID := riscv.MHARTID.Get()
target := uint64(ticks() + d)
sifive.CLINT.MTIMECMP[hartID].Set(target >> 32)
riscv.MIE.SetBits(1 << 7) // MTIE
for {
if timerWakeup.Get() != 0 {
Expand Down
2 changes: 1 addition & 1 deletion targets/unleashed.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

MEMORY
{
RAM (xrw) : ORIGIN = 0x80000000, LENGTH = 6M
RAM (xrw) : ORIGIN = 0x82000000, LENGTH = 6M
}

_stack_size = 2K;
Expand Down

0 comments on commit 7fba095

Please sign in to comment.