Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS uses appropriate wakeHandler for applet runtime #285

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions trusted_os/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"log"

"github.com/coreos/go-semver/semver"
"github.com/usbarmory/tamago/arm"
"github.com/usbarmory/tamago/bits"
"github.com/usbarmory/tamago/soc/nxp/imx6ul"
Expand All @@ -38,14 +39,33 @@ var irqHandler = make(map[int]func())
func wakeHandler(g uint32, p uint32)
func wakeHandlerPreGo123(g uint32, p uint32)

// handlerCutover is the semver representation of the cut over between wakeHandler implementations above.
// Anything less that this should use the legacy PreGo123 version.
const handlerCutover = "1.23.0"

var (
// wHandler is the wakeHandler implementation to be used, 1.23+ by default.
wHandler = wakeHandler
wHandlerCutover = *semver.New(handlerCutover)
)

func configureWakeHandler(rtVersion semver.Version) {
if rtVersion.LessThan(wHandlerCutover) {
wHandler = wakeHandlerPreGo123
log.Printf("SM Using legacy pre-%s wakeHandler", wHandlerCutover.String())
} else {
wHandler = wakeHandler
}
}

func isr() {
irq := imx6ul.GIC.GetInterrupt(true)

if handle, ok := irqHandler[irq]; ok {
handle()
return
}
log.Printf("unexpected IRQ %d", irq)
log.Printf("SM unexpected IRQ %d", irq)
}

func fiqHandler(ctx *monitor.ExecCtx) (_ error) {
Expand All @@ -67,7 +87,7 @@ func fiqHandler(ctx *monitor.ExecCtx) (_ error) {
// mask FIQs, applet handler will request unmasking when done
bits.Set(&ctx.SPSR, CPSR_FIQ)

wakeHandler(appletHandlerG, appletHandlerP)
wHandler(appletHandlerG, appletHandlerP)

return
}
Expand Down
5 changes: 4 additions & 1 deletion trusted_os/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ func main() {
log.Printf("SM applet verification error, %v", err)
}
loadedAppletVersion = manifest.Git.TagName
log.Printf("SM Loaded applet version %s", loadedAppletVersion.String())
loadedAppletRuntime := manifest.Build.TamagoVersion
log.Printf("SM Loaded applet version %s (with TamaGo runtime %s)", loadedAppletVersion.String(), loadedAppletRuntime.String())

configureWakeHandler(loadedAppletRuntime)

usbarmory.LED("white", true)

Expand Down