Skip to content

Commit

Permalink
DOS: Invert ABI map for conciseness
Browse files Browse the repository at this point in the history
  • Loading branch information
Grazfather committed May 15, 2017
1 parent 7ade2c9 commit 9e93bf4
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions go/arch/x86_16/dos.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,18 @@ var dosSysNum = map[int]string{
0x4C: "terminate_with_code",
}

// TODO: Create a reverse map of this for conciseness
var abiMap = map[int][]int{
0x00: {},
0x01: {DX},
0x02: {DX},
0x09: {DX},
0x30: {},
0x3C: {DX, CX},
0x3D: {DX, AL},
0x3E: {BX},
0x3F: {BX, DX, CX},
0x40: {BX, DX, CX},
0x41: {DX, CX},
0x4C: {AL},
type abi []int

// ABI to syscall number mapping
var abiMap = map[*abi][]int{
&abi{BX, DX, CX}: {0x00, 0x30, 0x3E, 0x3F, 0x40},
&abi{DX, CX}: {0x01, 0x02, 0x09, 0x3C, 0x41},
&abi{DX, AL}: {0x3D},
&abi{AL}: {0x4C},
}

var syscallAbis = map[int][]int{}

type PSP struct {
CPMExit [2]byte
FirstFreeSegment uint16
Expand Down Expand Up @@ -315,6 +311,13 @@ func NewKernel() *DosKernel {
k.fds[1] = 1
k.fds[2] = 2

// Invert the syscall map
for abi, syscalls := range abiMap {
for _, syscall := range syscalls {
syscallAbis[syscall] = *abi
}
}

k.Argjoy.Register(k.getDosArgCodec())
return k
}
Expand Down Expand Up @@ -366,7 +369,8 @@ func (k *DosKernel) getDosArgCodec() func(interface{}, []interface{}) error {
}

func dosArgs(u models.Usercorn, num int) func(int) ([]uint64, error) {
return co.RegArgs(u, abiMap[num])
// Return a closure over the correct arglist based on the syscall number
return co.RegArgs(u, syscallAbis[num])
}

func DosInterrupt(u models.Usercorn, cause uint32) {
Expand Down

0 comments on commit 9e93bf4

Please sign in to comment.