Added CPU type
This commit is contained in:
31
src/build/cpu/CPU.go
Normal file
31
src/build/cpu/CPU.go
Normal file
@ -0,0 +1,31 @@
|
||||
package cpu
|
||||
|
||||
// CPU represents the processor.
|
||||
type CPU struct {
|
||||
General []Register
|
||||
Syscall []Register
|
||||
Return []Register
|
||||
usage uint64
|
||||
}
|
||||
|
||||
func (c *CPU) Use(reg Register) {
|
||||
c.usage |= (1 << reg)
|
||||
}
|
||||
|
||||
func (c *CPU) Free(reg Register) {
|
||||
c.usage &= ^(1 << reg)
|
||||
}
|
||||
|
||||
func (c *CPU) IsFree(reg Register) bool {
|
||||
return c.usage&(1<<reg) == 0
|
||||
}
|
||||
|
||||
func (c *CPU) FindFree() (Register, bool) {
|
||||
for _, reg := range c.General {
|
||||
if c.IsFree(reg) {
|
||||
return reg, true
|
||||
}
|
||||
}
|
||||
|
||||
return 0, false
|
||||
}
|
Reference in New Issue
Block a user