Skip to content

Commit

Permalink
ebda: now possible to start with any number of vCPUs.
Browse files Browse the repository at this point in the history
Signed-off-by: Nobuhiro MIKI <[email protected]>
  • Loading branch information
bobuhiro11 committed Nov 20, 2021
1 parent 9a53099 commit c8d5459
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ bzImage: linux.config linux.tar.xz

.PHONY: run
run: initrd bzImage
go run . -p "console=ttyS0 earlyprintk=serial debug ignore_loglevel apic=debug show_lapic=all" -c 2
# refs: commit 1621292e73770aabbc146e72036de5e26f901e86 in kvmtool
go run . -p "console=ttyS0 earlyprintk=serial noapic noacpi notsc debug apic=debug show_lapic=all mitigations=off lapic dyndbg=\"file arch/x86/kernel/smpboot.c +plf\"" -c 4

.PHONY: run-system-kernel
run-system-kernel:
Expand Down
33 changes: 23 additions & 10 deletions ebda/ebda.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
"github.com/bobuhiro11/gokvm/bootparam"
)

// this must be fixed.
const NumCPUs = 2
const (
MaxVCPUs = 64
)

// Extended BIOS Data Area (EBDA).
type EBDA struct {
Expand All @@ -31,7 +32,7 @@ func (e *EBDA) Bytes() ([]byte, error) {
return buf.Bytes(), nil
}

func New() (*EBDA, error) {
func New(nCPUs int) (*EBDA, error) {
e := &EBDA{}

mpfIntel, err := NewMPFIntel()
Expand All @@ -41,7 +42,7 @@ func New() (*EBDA, error) {

e.mpfIntel = *mpfIntel

mpcTable, err := NewMPCTable()
mpcTable, err := NewMPCTable(nCPUs)
if err != nil {
return e, err
}
Expand Down Expand Up @@ -125,20 +126,29 @@ type MPCTable struct {
LAPIC uint32 // Local APIC addresss must be set.
Reserved uint32

mpcCPU [NumCPUs]MPCCpu
mpcCPU [MaxVCPUs]MPCCpu
}

const (
APICDefaultPhysBase = 0xfee00000
APICBaseAddrStep = 0x00400000
)

func apicAddr(apic uint32) uint32 {
return APICDefaultPhysBase + apic*APICBaseAddrStep
}

func NewMPCTable() (*MPCTable, error) {
func NewMPCTable(nCPUs int) (*MPCTable, error) {
m := &MPCTable{}
m.Signature = (('P' << 24) | ('M' << 16) | ('C' << 8) | 'P')
m.Length = uint16(unsafe.Sizeof(MPCTable{})) // this field must contain the size of entries.
// m.Length += uint16(unsafe.Sizeof(MPCCpu{})) * NumCPUs
m.Spec = 1
m.LAPIC = 0xFEE00000
m.Spec = 4
m.LAPIC = apicAddr(0)
m.OEMCount = MaxVCPUs // This must be the number of entries

var err error

for i := 0; i < NumCPUs; i++ {
for i := 0; i < nCPUs; i++ {
mpcCPU, err := NewMPCCpu(i)
if err != nil {
return m, err
Expand Down Expand Up @@ -204,5 +214,8 @@ func NewMPCCpu(i int) (*MPCCpu, error) {
m.CPUFlag |= 2 // boot processor
}

m.CPUFeature = 0x600 // STEPPING
m.FeatureFlag = 0x201 // CPU_FEATURE_APIC

return m, nil
}
2 changes: 1 addition & 1 deletion machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func New(nCpus int) (*Machine, error) {
return m, err
}

e, err := ebda.New()
e, err := ebda.New(nCpus)
if err != nil {
return m, err
}
Expand Down

0 comments on commit c8d5459

Please sign in to comment.