mirror of
https://github.com/BertoldVdb/ms-tools.git
synced 2025-12-10 07:44:46 +01:00
Allow external use of call function
This commit is contained in:
parent
0323a58f1d
commit
2d0f52971b
6 changed files with 50 additions and 32 deletions
|
|
@ -11,8 +11,9 @@ type HAL struct {
|
||||||
deviceTypeExtra int
|
deviceTypeExtra int
|
||||||
eepromSize int
|
eepromSize int
|
||||||
|
|
||||||
patchAllocAddr int
|
patchAllocAddr int
|
||||||
patchCallAddrs []int
|
patchCallAddrsExternalStart int
|
||||||
|
patchCallAddrs []int
|
||||||
|
|
||||||
patchInstalled bool
|
patchInstalled bool
|
||||||
|
|
||||||
|
|
@ -27,6 +28,7 @@ type HALConfig struct {
|
||||||
PatchTryInstall bool
|
PatchTryInstall bool
|
||||||
PatchIgnoreUserFirmware bool
|
PatchIgnoreUserFirmware bool
|
||||||
PatchProbeEEPROM bool
|
PatchProbeEEPROM bool
|
||||||
|
PatchBlobs []CodeBlob
|
||||||
|
|
||||||
LogFunc LogFunc
|
LogFunc LogFunc
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ func (h *HAL) patchExchangeReport(out [9]byte) ([9]byte, error) {
|
||||||
return in, err
|
return in, err
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout := time.Now().Add(time.Second)
|
timeout := time.Now().Add(3 * time.Second)
|
||||||
|
|
||||||
for time.Now().Before(timeout) {
|
for time.Now().Before(timeout) {
|
||||||
_, err := h.dev.GetFeatureReport(in[:])
|
_, err := h.dev.GetFeatureReport(in[:])
|
||||||
|
|
@ -37,7 +37,7 @@ func (h *HAL) patchExchangeReport(out [9]byte) ([9]byte, error) {
|
||||||
return in, ErrorTimeout
|
return in, ErrorTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
type patchExecFuncResponse struct {
|
type PatchExecFuncResponse struct {
|
||||||
A byte
|
A byte
|
||||||
R2 byte
|
R2 byte
|
||||||
R3 byte
|
R3 byte
|
||||||
|
|
@ -48,7 +48,7 @@ type patchExecFuncResponse struct {
|
||||||
C bool
|
C bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type patchExecFuncRequest struct {
|
type PatchExecFuncRequest struct {
|
||||||
DPTR uint16
|
DPTR uint16
|
||||||
R3 byte
|
R3 byte
|
||||||
R4 byte
|
R4 byte
|
||||||
|
|
@ -57,8 +57,8 @@ type patchExecFuncRequest struct {
|
||||||
R7_A byte
|
R7_A byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HAL) patchExecFunc(inIRQ bool, addr int, req patchExecFuncRequest) (patchExecFuncResponse, error) {
|
func (h *HAL) PatchExecFunc(inIRQ bool, addr int, req PatchExecFuncRequest) (PatchExecFuncResponse, error) {
|
||||||
var response patchExecFuncResponse
|
var response PatchExecFuncResponse
|
||||||
|
|
||||||
if !h.patchInstalled {
|
if !h.patchInstalled {
|
||||||
return response, ErrorMissingFunction
|
return response, ErrorMissingFunction
|
||||||
|
|
@ -101,3 +101,16 @@ func (h *HAL) patchExecFunc(inIRQ bool, addr int, req patchExecFuncRequest) (pat
|
||||||
response.C = in[1]&1 > 0
|
response.C = in[1]&1 > 0
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *HAL) PatchCodeBlobGetAddress(index int) int {
|
||||||
|
if index < 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
index += h.patchCallAddrsExternalStart
|
||||||
|
if index >= len(h.patchCallAddrs) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return h.patchCallAddrs[index]
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@ func (h *HAL) GPIOUpdate(stateSet byte, stateClear byte, outputSet byte, outputC
|
||||||
return 0, 0, ErrorMissingFunction
|
return 0, 0, ErrorMissingFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
var req patchExecFuncRequest
|
var req PatchExecFuncRequest
|
||||||
req.R4 = stateSet
|
req.R4 = stateSet
|
||||||
req.R5 = ^stateClear
|
req.R5 = ^stateClear
|
||||||
req.R6 = outputClear
|
req.R6 = outputClear
|
||||||
req.R7_A = ^outputSet
|
req.R7_A = ^outputSet
|
||||||
resp, err := h.patchExecFunc(true, h.patchCallAddrs[1], req)
|
resp, err := h.PatchExecFunc(true, h.patchCallAddrs[1], req)
|
||||||
|
|
||||||
return resp.R2, ^resp.R3, err
|
return resp.R2, ^resp.R3, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ func (h *HAL) patchI2CStart() error {
|
||||||
addr = 0x6a8c
|
addr = 0x6a8c
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := h.patchExecFunc(true, addr, patchExecFuncRequest{})
|
_, err := h.PatchExecFunc(true, addr, PatchExecFuncRequest{})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -15,7 +15,7 @@ func (h *HAL) patchI2CStop() error {
|
||||||
if h.deviceType == 2109 {
|
if h.deviceType == 2109 {
|
||||||
addr = 0x6aba
|
addr = 0x6aba
|
||||||
}
|
}
|
||||||
_, err := h.patchExecFunc(true, addr, patchExecFuncRequest{})
|
_, err := h.PatchExecFunc(true, addr, PatchExecFuncRequest{})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ func (h *HAL) patchI2CRead(ack bool) (uint8, error) {
|
||||||
if ack {
|
if ack {
|
||||||
r7 = 0
|
r7 = 0
|
||||||
}
|
}
|
||||||
resp, err := h.patchExecFunc(true, addr, patchExecFuncRequest{R7_A: r7})
|
resp, err := h.PatchExecFunc(true, addr, PatchExecFuncRequest{R7_A: r7})
|
||||||
return resp.R7, err
|
return resp.R7, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ func (h *HAL) patchI2CWrite(value uint8) (bool, error) {
|
||||||
if h.deviceType == 2109 {
|
if h.deviceType == 2109 {
|
||||||
addr = 0x4648
|
addr = 0x4648
|
||||||
}
|
}
|
||||||
resp, err := h.patchExecFunc(true, addr, patchExecFuncRequest{R7_A: value})
|
resp, err := h.PatchExecFunc(true, addr, PatchExecFuncRequest{R7_A: value})
|
||||||
if h.deviceType == 2109 {
|
if h.deviceType == 2109 {
|
||||||
return resp.C, err
|
return resp.C, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,9 +103,9 @@ func (h *HAL) patchTrampolineInstall(ram MemoryRegion, replaceCode bool, addr in
|
||||||
return h.patchWriteWithRET(ram, addr, []byte{0x02, byte(trampolineAddr >> 8), byte(trampolineAddr)})
|
return h.patchWriteWithRET(ram, addr, []byte{0x02, byte(trampolineAddr >> 8), byte(trampolineAddr)})
|
||||||
}
|
}
|
||||||
|
|
||||||
type blob struct {
|
type CodeBlob struct {
|
||||||
data []byte
|
Data []byte
|
||||||
reloc func(dataCopy []byte, addr int) (int, []byte)
|
Relocate func(dataCopy []byte, addr int) (int, []byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:embed asm/hook_2106.bin
|
//go:embed asm/hook_2106.bin
|
||||||
|
|
@ -135,26 +135,26 @@ var codeMOVC []byte
|
||||||
//go:embed asm/i2cRead2109.bin
|
//go:embed asm/i2cRead2109.bin
|
||||||
var codei2cRead []byte
|
var codei2cRead []byte
|
||||||
|
|
||||||
var installBlobs2106 = []blob{
|
var installBlobs2106 = []CodeBlob{
|
||||||
{
|
{
|
||||||
data: codeCallgate2106,
|
Data: codeCallgate2106,
|
||||||
reloc: relocateCallgate,
|
Relocate: relocateCallgate,
|
||||||
}, {
|
}, {
|
||||||
data: codeGpio,
|
Data: codeGpio,
|
||||||
}, {
|
}, {
|
||||||
data: codeMOVC,
|
Data: codeMOVC,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
var installBlobs2109 = []blob{
|
var installBlobs2109 = []CodeBlob{
|
||||||
{
|
{
|
||||||
data: codeCallgate2109,
|
Data: codeCallgate2109,
|
||||||
reloc: relocateCallgate,
|
Relocate: relocateCallgate,
|
||||||
}, {
|
}, {
|
||||||
data: codeGpio,
|
Data: codeGpio,
|
||||||
}, {
|
}, {
|
||||||
data: codeMOVC,
|
Data: codeMOVC,
|
||||||
}, {
|
}, {
|
||||||
data: codei2cRead,
|
Data: codei2cRead,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -308,6 +308,9 @@ func (h *HAL) patchInstall() (bool, error) {
|
||||||
installBlobs = installBlobs2109
|
installBlobs = installBlobs2109
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.patchCallAddrsExternalStart = len(installBlobs)
|
||||||
|
installBlobs = append(installBlobs, h.config.PatchBlobs...)
|
||||||
|
|
||||||
ram := h.MemoryRegionGet(MemoryRegionRAM)
|
ram := h.MemoryRegionGet(MemoryRegionRAM)
|
||||||
userConfig := h.MemoryRegionGet(MemoryRegionUserConfig)
|
userConfig := h.MemoryRegionGet(MemoryRegionUserConfig)
|
||||||
|
|
||||||
|
|
@ -316,7 +319,7 @@ func (h *HAL) patchInstall() (bool, error) {
|
||||||
/* Calculate checksum of blobs */
|
/* Calculate checksum of blobs */
|
||||||
crc := crc32.New(crc32.IEEETable)
|
crc := crc32.New(crc32.IEEETable)
|
||||||
for _, m := range installBlobs {
|
for _, m := range installBlobs {
|
||||||
crc.Write(m.data)
|
crc.Write(m.Data)
|
||||||
}
|
}
|
||||||
sum := crc.Sum(nil)
|
sum := crc.Sum(nil)
|
||||||
|
|
||||||
|
|
@ -369,15 +372,15 @@ func (h *HAL) patchInstall() (bool, error) {
|
||||||
|
|
||||||
/* Install all blobs */
|
/* Install all blobs */
|
||||||
for i, m := range installBlobs {
|
for i, m := range installBlobs {
|
||||||
data := m.data
|
data := m.Data
|
||||||
|
|
||||||
loadAddr := h.patchAlloc(len(data))
|
loadAddr := h.patchAlloc(len(data))
|
||||||
callAddr := loadAddr
|
callAddr := loadAddr
|
||||||
|
|
||||||
if m.reloc != nil {
|
if m.Relocate != nil {
|
||||||
dataCopy := make([]byte, len(data))
|
dataCopy := make([]byte, len(data))
|
||||||
copy(dataCopy, data)
|
copy(dataCopy, data)
|
||||||
callAddr, data = m.reloc(dataCopy, loadAddr)
|
callAddr, data = m.Relocate(dataCopy, loadAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.config.LogFunc != nil {
|
if h.config.LogFunc != nil {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package mshal
|
package mshal
|
||||||
|
|
||||||
func (h *HAL) patchReadCode(addr int) (byte, error) {
|
func (h *HAL) patchReadCode(addr int) (byte, error) {
|
||||||
resp, err := h.patchExecFunc(true, h.patchCallAddrs[2], patchExecFuncRequest{DPTR: uint16(addr)})
|
resp, err := h.PatchExecFunc(true, h.patchCallAddrs[2], PatchExecFuncRequest{DPTR: uint16(addr)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue