Added CPU type

This commit is contained in:
2024-06-21 22:16:42 +02:00
parent 1058970be3
commit 4faa1641c6
10 changed files with 92 additions and 28 deletions

31
src/build/cpu/CPU.go Normal file
View 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
}