Skip to content

Commit

Permalink
ELF file loaded with undefined symbols generates a notification
Browse files Browse the repository at this point in the history
  • Loading branch information
JetSetIlly committed Aug 21, 2024
1 parent 3522d2c commit 6aa2e5c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions debugger/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,11 @@ func (dbg *Debugger) Notify(notice notifications.Notice) error {
if err != nil {
return err
}
case notifications.NotifyElfUndefinedSymbols:
err := dbg.gui.SetFeature(gui.ReqNotification, notifications.NotifyElfUndefinedSymbols)
if err != nil {
return err
}
case notifications.NotifyMovieCartStarted:
return dbg.vcs.TV.Reset(true)
default:
Expand Down
43 changes: 43 additions & 0 deletions gui/sdlimgui/modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@

package sdlimgui

import (
"github.com/inkyblackness/imgui-go/v4"
)

type modal int

const (
modalNone modal = iota
modalPlusROMFirstInstallation
modalUnsupportedDWARF
modalElfUndefinedSymbols
)

func (img *SdlImgui) modalDraw() {
Expand All @@ -29,9 +34,47 @@ func (img *SdlImgui) modalDraw() {
img.modalDrawPlusROMFirstInstallation()
case modalUnsupportedDWARF:
img.modalDrawUnsupportedDWARF()
case modalElfUndefinedSymbols:
img.modalElfUndefinedSymbols()
}
}

func (img *SdlImgui) modalActive() bool {
return img.modal != modalNone
}

func (img *SdlImgui) modalElfUndefinedSymbols() {
const popupTitle = "Undefined Symbols in ELF file"

imgui.OpenPopup(popupTitle)
flgs := imgui.WindowFlagsAlwaysAutoResize
flgs |= imgui.WindowFlagsNoMove
flgs |= imgui.WindowFlagsNoSavedSettings
if imgui.BeginPopupModalV(popupTitle, nil, flgs) {
imgui.Text("The ELF ROM contains an undefined symbol. Rather than aborting")
imgui.Text("the loading process the symbol has been linked to the undefined")
imgui.Text("symbol handler")
imgui.Spacing()
imgui.Spacing()
imgui.Text("The ROM will progress as expected until the symbol is accessed")
imgui.Spacing()
imgui.Spacing()
imgui.Text("If the symbol is accessed during execution a memory fault will")
imgui.Text("be generated")

imgui.Spacing()
imgui.Separator()
imgui.Spacing()

sz := imgui.ContentRegionAvail()
sz.Y = img.fonts.guiSize
sz.Y += imgui.CurrentStyle().CellPadding().Y * 2
sz.Y += imgui.CurrentStyle().FramePadding().Y * 2
if imgui.ButtonV("Continue with undefined function handler", sz) {
imgui.CloseCurrentPopup()
img.modal = modalNone
}

imgui.EndPopup()
}
}
2 changes: 2 additions & 0 deletions gui/sdlimgui/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func (img *SdlImgui) serviceSetFeature(request featureRequest) {
img.modal = modalPlusROMFirstInstallation
case notifications.NotifyUnsupportedDWARF:
img.modal = modalUnsupportedDWARF
case notifications.NotifyElfUndefinedSymbols:
img.modal = modalElfUndefinedSymbols
default:
img.playScr.overlay.set(request.args[0].(notifications.Notice))
}
Expand Down
6 changes: 6 additions & 0 deletions hardware/memory/cartridge/elf/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/jetsetilly/gopher2600/hardware/memory/cartridge/mapper"
"github.com/jetsetilly/gopher2600/hardware/memory/cpubus"
"github.com/jetsetilly/gopher2600/hardware/memory/memorymap"
"github.com/jetsetilly/gopher2600/notifications"
)

// Elf implements the mapper.CartMapper interface.
Expand Down Expand Up @@ -155,6 +156,11 @@ func NewElf(env *environment.Environment, loader cartridgeloader.Loader, inACE b
return nil, fmt.Errorf("ELF: %w", err)
}

// notify emulator that some symbols in the ELF have
if cart.mem.unresolvedSymbols {
cart.env.Notifications.Notify(notifications.NotifyElfUndefinedSymbols)
}

return cart, nil
}

Expand Down
7 changes: 7 additions & 0 deletions hardware/memory/cartridge/elf/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ type elfMemory struct {

symbols []elf.Symbol

// this field will be true if some symbols could not be completely resolved
// during loading
unresolvedSymbols bool

// strongARM support. like the elf sections, the strongARM program is placed
// in flash memory
strongArmProgram []byte
Expand Down Expand Up @@ -530,6 +534,9 @@ func (mem *elfMemory) decode(ef *elf.File) error {
},
support: true,
})

// flag presence of unresolved symbols
mem.unresolvedSymbols = true
} else {
n := ef.Sections[sym.Section].Name
if idx, ok := mem.sectionsByName[n]; !ok {
Expand Down
3 changes: 3 additions & 0 deletions notifications/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const (
NotifyPlusROMNewInstall Notice = "NotifyPlusROMNewInstall"
NotifyPlusROMNetwork Notice = "NotifyPlusROMNetwork"

// notifications sent by ELF cartridges
NotifyElfUndefinedSymbols Notice = "NotifyElfUndefinedSymbols"

// moviecart has started
NotifyMovieCartStarted Notice = "NotifyMoveCartStarted"

Expand Down

0 comments on commit 6aa2e5c

Please sign in to comment.