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:
@@ -1,23 +1,67 @@
|
||||
package hal
|
||||
|
||||
import (
|
||||
"gopheros/kernel/driver/tty"
|
||||
"gopheros/kernel/driver/video/console"
|
||||
"gopheros/kernel/hal/multiboot"
|
||||
"gopheros/device"
|
||||
"gopheros/device/tty"
|
||||
"gopheros/device/video/console"
|
||||
"gopheros/kernel/kfmt"
|
||||
)
|
||||
|
||||
var (
|
||||
egaConsole = &console.Ega{}
|
||||
|
||||
// ActiveTerminal points to the currently active terminal.
|
||||
ActiveTerminal = &tty.Vt{}
|
||||
)
|
||||
|
||||
// InitTerminal provides a basic terminal to allow the kernel to emit some output
|
||||
// till everything is properly setup
|
||||
func InitTerminal() {
|
||||
fbInfo := multiboot.GetFramebufferInfo()
|
||||
|
||||
egaConsole.Init(uint16(fbInfo.Width), uint16(fbInfo.Height), uintptr(fbInfo.PhysAddr))
|
||||
ActiveTerminal.AttachTo(egaConsole)
|
||||
// managedDevices contains the devices discovered by the HAL.
|
||||
type managedDevices struct {
|
||||
activeConsole console.Device
|
||||
activeTTY tty.Device
|
||||
}
|
||||
|
||||
var devices managedDevices
|
||||
|
||||
// ActiveTTY returns the currently active TTY
|
||||
func ActiveTTY() tty.Device {
|
||||
return devices.activeTTY
|
||||
}
|
||||
|
||||
// DetectHardware probes for hardware devices and initializes the appropriate
|
||||
// drivers.
|
||||
func DetectHardware() {
|
||||
consoles := probe(console.HWProbes())
|
||||
if len(consoles) != 0 {
|
||||
devices.activeConsole = consoles[0].(console.Device)
|
||||
}
|
||||
|
||||
ttys := probe(tty.HWProbes())
|
||||
if len(ttys) != 0 {
|
||||
devices.activeTTY = ttys[0].(tty.Device)
|
||||
devices.activeTTY.AttachTo(devices.activeConsole)
|
||||
kfmt.SetOutputSink(devices.activeTTY)
|
||||
|
||||
// Sync terminal contents with console
|
||||
devices.activeTTY.SetState(tty.StateActive)
|
||||
}
|
||||
}
|
||||
|
||||
// probe executes the supplied hw probe functions and attempts to initialize
|
||||
// each detected device. The function returns a list of device drivers that
|
||||
// were successfully initialized.
|
||||
func probe(hwProbeFns []device.ProbeFn) []device.Driver {
|
||||
var drivers []device.Driver
|
||||
|
||||
for _, probeFn := range hwProbeFns {
|
||||
drv := probeFn()
|
||||
if drv == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
major, minor, patch := drv.DriverVersion()
|
||||
|
||||
kfmt.Printf("[hal] %s(%d.%d.%d): ", drv.DriverName(), major, minor, patch)
|
||||
if err := drv.DriverInit(); err != nil {
|
||||
kfmt.Printf("init failed: %s\n", err.Message)
|
||||
continue
|
||||
}
|
||||
|
||||
drivers = append(drivers, drv)
|
||||
kfmt.Printf("initialized\n")
|
||||
}
|
||||
|
||||
return drivers
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user