1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

Detect hw and wire active console and TTY

This commit is contained in:
Achilleas Anagnostopoulos
2017-07-06 09:24:41 +01:00
parent eca1f6c26e
commit 562fae2028
10 changed files with 186 additions and 22 deletions

View File

@@ -0,0 +1,16 @@
package console
import "gopheros/device"
import "gopheros/kernel/hal/multiboot"
var (
getFramebufferInfoFn = multiboot.GetFramebufferInfo
)
// HWProbes returns a slice of device.ProbeFn that can be used by the hal
// package to probe for console device hardware.
func HWProbes() []device.ProbeFn {
return []device.ProbeFn{
probeForVgaTextConsole,
}
}

View File

@@ -1,8 +1,10 @@
package console
import (
"gopheros/device"
"gopheros/kernel"
"gopheros/kernel/cpu"
"gopheros/kernel/hal/multiboot"
"image/color"
"reflect"
"unsafe"
@@ -196,3 +198,15 @@ func (cons *VgaTextConsole) DriverVersion() (uint16, uint16, uint16) {
// DriverInit initializes this driver.
func (cons *VgaTextConsole) DriverInit() *kernel.Error { return nil }
// probeForVgaTextConsole checks for the presence of a vga text console.
func probeForVgaTextConsole() device.Driver {
var drv device.Driver
fbInfo := getFramebufferInfoFn()
if fbInfo.Type == multiboot.FramebufferTypeEGA {
drv = NewVgaTextConsole(uint16(fbInfo.Width), uint16(fbInfo.Height), uintptr(fbInfo.PhysAddr))
}
return drv
}

View File

@@ -3,7 +3,9 @@ package console
import (
"gopheros/device"
"gopheros/kernel/cpu"
"gopheros/kernel/hal/multiboot"
"image/color"
"reflect"
"testing"
"unsafe"
)
@@ -318,3 +320,39 @@ func TestVgaTextDriverInterface(t *testing.T) {
t.Fatal("DriverVersion() returned an invalid version number")
}
}
func TestVgaTextProbe(t *testing.T) {
defer func() {
getFramebufferInfoFn = multiboot.GetFramebufferInfo
}()
var (
expProbePtr = reflect.ValueOf(probeForVgaTextConsole).Pointer()
foundProbe bool
)
for _, probeFn := range HWProbes() {
if reflect.ValueOf(probeFn).Pointer() == expProbePtr {
foundProbe = true
break
}
}
if !foundProbe {
t.Fatal("expected probeForVgaTextConsole to be part of the probes returned by HWProbes")
}
getFramebufferInfoFn = func() *multiboot.FramebufferInfo {
return &multiboot.FramebufferInfo{
Width: 80,
Height: 25,
Pitch: 160,
PhysAddr: 0xb80000,
Type: multiboot.FramebufferTypeEGA,
}
}
if drv := probeForVgaTextConsole(); drv == nil {
t.Fatal("expected probeForVgaTextConsole to return a driver")
}
}