mirror of
https://github.com/taigrr/gopher-os
synced 2026-03-26 20:12:23 -07:00
Change early.Printf calls to kfmt.Printf
This commit is contained in:
@@ -3,7 +3,7 @@ package allocator
|
||||
import (
|
||||
"gopheros/kernel"
|
||||
"gopheros/kernel/hal/multiboot"
|
||||
"gopheros/kernel/kfmt/early"
|
||||
"gopheros/kernel/kfmt"
|
||||
"gopheros/kernel/mem"
|
||||
"gopheros/kernel/mem/pmm"
|
||||
"gopheros/kernel/mem/vmm"
|
||||
@@ -234,7 +234,7 @@ func (alloc *BitmapAllocator) reserveEarlyAllocatorFrames() {
|
||||
}
|
||||
|
||||
func (alloc *BitmapAllocator) printStats() {
|
||||
early.Printf(
|
||||
kfmt.Printf(
|
||||
"[bitmap_alloc] page stats: free: %d/%d (%d reserved)\n",
|
||||
alloc.totalPages-alloc.reservedPages,
|
||||
alloc.totalPages,
|
||||
|
||||
@@ -406,7 +406,6 @@ func TestAllocatorPackageInit(t *testing.T) {
|
||||
return uintptr(unsafe.Pointer(&physMem[0])), nil
|
||||
}
|
||||
|
||||
mockTTY()
|
||||
if err := Init(0x100000, 0x1fa7c8); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package allocator
|
||||
import (
|
||||
"gopheros/kernel"
|
||||
"gopheros/kernel/hal/multiboot"
|
||||
"gopheros/kernel/kfmt/early"
|
||||
"gopheros/kernel/kfmt"
|
||||
"gopheros/kernel/mem"
|
||||
"gopheros/kernel/mem/pmm"
|
||||
)
|
||||
@@ -117,19 +117,19 @@ func (alloc *bootMemAllocator) AllocFrame() (pmm.Frame, *kernel.Error) {
|
||||
// printMemoryMap scans the memory region information provided by the
|
||||
// bootloader and prints out the system's memory map.
|
||||
func (alloc *bootMemAllocator) printMemoryMap() {
|
||||
early.Printf("[boot_mem_alloc] system memory map:\n")
|
||||
kfmt.Printf("[boot_mem_alloc] system memory map:\n")
|
||||
var totalFree mem.Size
|
||||
multiboot.VisitMemRegions(func(region *multiboot.MemoryMapEntry) bool {
|
||||
early.Printf("\t[0x%10x - 0x%10x], size: %10d, type: %s\n", region.PhysAddress, region.PhysAddress+region.Length, region.Length, region.Type.String())
|
||||
kfmt.Printf("\t[0x%10x - 0x%10x], size: %10d, type: %s\n", region.PhysAddress, region.PhysAddress+region.Length, region.Length, region.Type.String())
|
||||
|
||||
if region.Type == multiboot.MemAvailable {
|
||||
totalFree += mem.Size(region.Length)
|
||||
}
|
||||
return true
|
||||
})
|
||||
early.Printf("[boot_mem_alloc] available memory: %dKb\n", uint64(totalFree/mem.Kb))
|
||||
early.Printf("[boot_mem_alloc] kernel loaded at 0x%x - 0x%x\n", alloc.kernelStartAddr, alloc.kernelEndAddr)
|
||||
early.Printf("[boot_mem_alloc] size: %d bytes, reserved pages: %d\n",
|
||||
kfmt.Printf("[boot_mem_alloc] available memory: %dKb\n", uint64(totalFree/mem.Kb))
|
||||
kfmt.Printf("[boot_mem_alloc] kernel loaded at 0x%x - 0x%x\n", alloc.kernelStartAddr, alloc.kernelEndAddr)
|
||||
kfmt.Printf("[boot_mem_alloc] size: %d bytes, reserved pages: %d\n",
|
||||
uint64(alloc.kernelEndAddr-alloc.kernelStartAddr),
|
||||
uint64(alloc.kernelEndFrame-alloc.kernelStartFrame+1),
|
||||
)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package allocator
|
||||
|
||||
import (
|
||||
"gopheros/kernel/driver/video/console"
|
||||
"gopheros/kernel/hal"
|
||||
"gopheros/kernel/hal/multiboot"
|
||||
"testing"
|
||||
"unsafe"
|
||||
@@ -118,13 +116,3 @@ var (
|
||||
24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
}
|
||||
)
|
||||
|
||||
func mockTTY() []byte {
|
||||
// Mock a tty to handle early.Printf output
|
||||
mockConsoleFb := make([]byte, 160*25)
|
||||
mockConsole := &console.Ega{}
|
||||
mockConsole.Init(80, 25, uintptr(unsafe.Pointer(&mockConsoleFb[0])))
|
||||
hal.ActiveTerminal.AttachTo(mockConsole)
|
||||
|
||||
return mockConsoleFb
|
||||
}
|
||||
|
||||
@@ -61,12 +61,3 @@ func TestTranslateAmd64(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
phys, err := vmm.Translate(uintptr(100 * mem.Mb))
|
||||
if err != nil {
|
||||
early.Printf("err: %s\n", err.Error())
|
||||
} else {
|
||||
early.Printf("phys: 0x%x\n", phys)
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"gopheros/kernel"
|
||||
"gopheros/kernel/cpu"
|
||||
"gopheros/kernel/irq"
|
||||
"gopheros/kernel/kfmt/early"
|
||||
"gopheros/kernel/kfmt"
|
||||
"gopheros/kernel/mem"
|
||||
"gopheros/kernel/mem/pmm"
|
||||
)
|
||||
@@ -83,27 +83,27 @@ func pageFaultHandler(errorCode uint64, frame *irq.Frame, regs *irq.Regs) {
|
||||
}
|
||||
|
||||
func nonRecoverablePageFault(faultAddress uintptr, errorCode uint64, frame *irq.Frame, regs *irq.Regs, err *kernel.Error) {
|
||||
early.Printf("\nPage fault while accessing address: 0x%16x\nReason: ", faultAddress)
|
||||
kfmt.Printf("\nPage fault while accessing address: 0x%16x\nReason: ", faultAddress)
|
||||
switch {
|
||||
case errorCode == 0:
|
||||
early.Printf("read from non-present page")
|
||||
kfmt.Printf("read from non-present page")
|
||||
case errorCode == 1:
|
||||
early.Printf("page protection violation (read)")
|
||||
kfmt.Printf("page protection violation (read)")
|
||||
case errorCode == 2:
|
||||
early.Printf("write to non-present page")
|
||||
kfmt.Printf("write to non-present page")
|
||||
case errorCode == 3:
|
||||
early.Printf("page protection violation (write)")
|
||||
kfmt.Printf("page protection violation (write)")
|
||||
case errorCode == 4:
|
||||
early.Printf("page-fault in user-mode")
|
||||
kfmt.Printf("page-fault in user-mode")
|
||||
case errorCode == 8:
|
||||
early.Printf("page table has reserved bit set")
|
||||
kfmt.Printf("page table has reserved bit set")
|
||||
case errorCode == 16:
|
||||
early.Printf("instruction fetch")
|
||||
kfmt.Printf("instruction fetch")
|
||||
default:
|
||||
early.Printf("unknown")
|
||||
kfmt.Printf("unknown")
|
||||
}
|
||||
|
||||
early.Printf("\n\nRegisters:\n")
|
||||
kfmt.Printf("\n\nRegisters:\n")
|
||||
regs.Print()
|
||||
frame.Print()
|
||||
|
||||
@@ -112,8 +112,8 @@ func nonRecoverablePageFault(faultAddress uintptr, errorCode uint64, frame *irq.
|
||||
}
|
||||
|
||||
func generalProtectionFaultHandler(_ uint64, frame *irq.Frame, regs *irq.Regs) {
|
||||
early.Printf("\nGeneral protection fault while accessing address: 0x%x\n", readCR2Fn())
|
||||
early.Printf("Registers:\n")
|
||||
kfmt.Printf("\nGeneral protection fault while accessing address: 0x%x\n", readCR2Fn())
|
||||
kfmt.Printf("Registers:\n")
|
||||
regs.Print()
|
||||
frame.Print()
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@ import (
|
||||
"fmt"
|
||||
"gopheros/kernel"
|
||||
"gopheros/kernel/cpu"
|
||||
"gopheros/kernel/driver/video/console"
|
||||
"gopheros/kernel/hal"
|
||||
"gopheros/kernel/irq"
|
||||
"gopheros/kernel/kfmt"
|
||||
"gopheros/kernel/mem"
|
||||
"gopheros/kernel/mem/pmm"
|
||||
"strings"
|
||||
@@ -54,8 +53,6 @@ func TestRecoverablePageFault(t *testing.T) {
|
||||
{FlagPresent | FlagCopyOnWrite, nil, nil, false},
|
||||
}
|
||||
|
||||
mockTTY()
|
||||
|
||||
ptePtrFn = func(entry uintptr) unsafe.Pointer { return unsafe.Pointer(&pageEntry) }
|
||||
readCR2Fn = func() uint64 { return uint64(uintptr(unsafe.Pointer(&origPage[0]))) }
|
||||
unmapFn = func(_ Page) *kernel.Error { return nil }
|
||||
@@ -102,6 +99,10 @@ func TestRecoverablePageFault(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNonRecoverablePageFault(t *testing.T) {
|
||||
defer func() {
|
||||
kfmt.SetOutputSink(nil)
|
||||
}()
|
||||
|
||||
specs := []struct {
|
||||
errCode uint64
|
||||
expReason string
|
||||
@@ -143,19 +144,21 @@ func TestNonRecoverablePageFault(t *testing.T) {
|
||||
var (
|
||||
regs irq.Regs
|
||||
frame irq.Frame
|
||||
buf bytes.Buffer
|
||||
)
|
||||
|
||||
kfmt.SetOutputSink(&buf)
|
||||
for specIndex, spec := range specs {
|
||||
t.Run(fmt.Sprint(specIndex), func(t *testing.T) {
|
||||
buf.Reset()
|
||||
defer func() {
|
||||
if err := recover(); err != errUnrecoverableFault {
|
||||
t.Errorf("expected a panic with errUnrecoverableFault; got %v", err)
|
||||
}
|
||||
}()
|
||||
fb := mockTTY()
|
||||
|
||||
nonRecoverablePageFault(0xbadf00d000, spec.errCode, &frame, ®s, errUnrecoverableFault)
|
||||
if got := readTTY(fb); !strings.Contains(got, spec.expReason) {
|
||||
if got := buf.String(); !strings.Contains(got, spec.expReason) {
|
||||
t.Errorf("expected reason %q; got output:\n%q", spec.expReason, got)
|
||||
}
|
||||
})
|
||||
@@ -182,7 +185,6 @@ func TestGPtHandler(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
mockTTY()
|
||||
generalProtectionFaultHandler(0, &frame, ®s)
|
||||
}
|
||||
|
||||
@@ -252,30 +254,3 @@ func TestInit(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func readTTY(fb []byte) string {
|
||||
var buf bytes.Buffer
|
||||
for i := 0; i < len(fb); i += 2 {
|
||||
ch := fb[i]
|
||||
if ch == 0 {
|
||||
if i+2 < len(fb) && fb[i+2] != 0 {
|
||||
buf.WriteByte('\n')
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
buf.WriteByte(ch)
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func mockTTY() []byte {
|
||||
// Mock a tty to handle early.Printf output
|
||||
mockConsoleFb := make([]byte, 160*25)
|
||||
mockConsole := &console.Ega{}
|
||||
mockConsole.Init(80, 25, uintptr(unsafe.Pointer(&mockConsoleFb[0])))
|
||||
hal.ActiveTerminal.AttachTo(mockConsole)
|
||||
|
||||
return mockConsoleFb
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user