kernel

package
v0.0.0-...-62758f5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AT_NULL     = 0  /* end of vector */
	AT_IGNORE   = 1  /* entry should be ignored */
	AT_EXECFD   = 2  /* file descriptor of program */
	AT_PHDR     = 3  /* program headers for program */
	AT_PHENT    = 4  /* size of program header entry */
	AT_PHNUM    = 5  /* number of program headers */
	AT_PAGESZ   = 6  /* system page size */
	AT_BASE     = 7  /* base address of interpreter */
	AT_FLAGS    = 8  /* flags */
	AT_ENTRY    = 9  /* entry point of program */
	AT_NOTELF   = 10 /* program is not ELF */
	AT_UID      = 11 /* real uid */
	AT_EUID     = 12 /* effective uid */
	AT_GID      = 13 /* real gid */
	AT_EGID     = 14 /* effective gid */
	AT_PLATFORM = 15 /* string identifying CPU for optimizations */
	AT_HWCAP    = 16 /* arch dependent hints at CPU capabilities */
	AT_CLKTCK   = 17 /* frequency at which times() increments */
	/* values 18 through 22 are reserved */
	AT_SECURE        = 23 /* secure mode boolean */
	AT_BASE_PLATFORM = 24 /* string identifying real platform, may
	 * differ from AT_PLATFORM. */
	AT_RANDOM = 25 /* address of 16 random bytes */
	AT_HWCAP2 = 26 /* extension of AT_HWCAP */

	AT_EXECFN = 31 /* filename of program */
)
View Source
const (
	INTERRUPT_GATE        = 0xE
	PRINT_INTERRUPT_DEBUG = false
)
View Source
const (
	PAGE_DEBUG = false

	// Reserve memory below 50 MB for kernel image
	KERNEL_START      = 1 << 20
	KERNEL_RESERVED   = 50 << 20
	PAGE_SIZE         = 4 << 10
	ENTRIES_PER_TABLE = PAGE_SIZE / 4

	PAGE_PRESENT       = 1 << 0
	PAGE_RW            = 1 << 1
	PAGE_PERM_USER     = 1 << 2
	PAGE_PERM_KERNEL   = 0 << 2
	PAGE_WRITETHROUGH  = 1 << 3
	PAGE_DISABLE_CACHE = 1 << 4

	PAGE_FAULT_PRESENT           = 1 << 0
	PAGE_FAULT_WRITE             = 1 << 1
	PAGE_FAULT_USER              = 1 << 2
	PAGE_FAULT_INSTRUCTION_FETCH = 1 << 4

	MAX_ALLOC_VIRT_ADDR = 0xf0000000
	MIN_ALLOC_VIRT_ADDR = 0x8000000
)
View Source
const (
	PIC_PRINT_DEBUG = ENABLE_DEBUG

	PIC1Port uint16 = 0x20
	PIC1Data uint16 = PIC1Port + 1
	PIC2Port uint16 = 0xA0
	PIC2Data uint16 = PIC2Port + 1

	PIC1Offset byte = 0x20
	PIC2Offset byte = 0x28

	PIC_ICW1_ICW4 byte = 0x01 // ICW4 will be sent
	PIC_ICW1_Init byte = 0x10
	PIC_ICW4_8086 byte = 0x01 // Set 8086/88 mode. unset MCS-80/85 mode

	PIC_EOI     byte = 0x20 // End of interrupt
	PIC_ReadIRR byte = 0xa
	PIC_ReadISR byte = 0xb
)
View Source
const (
	PIT_PORT_DATA    = 0x40
	PIT_PORT_COMMAND = 0x43
)
View Source
const (
	KCS_INDEX = 1
	KDS_INDEX = 2
	KGS_INDEX = 3

	KCS_SELECTOR = KCS_INDEX * 8
	KDS_SELECTOR = KDS_INDEX * 8
	KGS_SELECTOR = KGS_INDEX * 8

	// flags
	SEG_GRAN_BYTE    = 0 << 7
	SEG_GRAN_4K_PAGE = 1 << 7

	// access
	SEG_NORW = 0 << 1
	SEG_R    = 1 << 1
	SEG_W    = 1 << 1

	SEG_SYSTEM = 0 << 4
	SEG_NORMAL = 1 << 4

	SEG_NOEXEC = 0 << 3
	SEG_EXEC   = 1 << 3

	PRIV_KERNEL = 0 << 5
	PRIV_USER   = 3 << 5

	SEG_BIG_MODE = 1 << 6

	PRESENT = 1 << 7

	// userDesc flags
	UDESC_32SEG           = 1 << 0 // I ignore this
	UDESC_CONTENTS        = 3 << 1 // don't know what those are
	UDESC_RX_ONLY         = 1 << 3
	UDESC_LIMIT_IN_PAGES  = 1 << 4
	UDESC_SEG_NOT_PRESENT = 1 << 5
	UDESC_USABLE          = 1 << 6

	// Misc
	GDT_ENTRIES = 256
	TLS_START   = 16
)
View Source
const (
	COM1_PORT uint16 = 0x3F8
	COM1_IRQ  uint8  = 0x4
)
View Source
const (
	TSS_IS_TSS = 1 << 0
	TSS_32MODE = 1 << 3

	EFLAGS_IF = 0x200 // interrupt flag. enable interrupts
	EFLAGS_R  = 0x2   // Reserved. always 1
)
View Source
const ENABLE_DEBUG = false
View Source
const ESUCCESS = syscall.Errno(0)

TODO: Move somewhere else?

View Source
const (
	MEM_MAP_AVAILABLE = 1
)

Variables

View Source
var (
	CurrentThread *Thread = &scheduleThread
	CurrentDomain *Domain = nil
)
View Source
var KeycodeTranslation = map[int]uint8{
	0:    42,
	0x1E: 0x41,
}
View Source
var (
	PerformSchedule = false
)

Functions

func AddDomain

func AddDomain(d *Domain)

func AddSegment

func AddSegment(base uintptr, limit uintptr, access uint8, flags uint8) int

func Block

func Block()

func BlockThread

func BlockThread(t *Thread)

func CreateNewPageDirectory

func CreateNewPageDirectory() mm.MemSpace

func CreateNewThread

func CreateNewThread(outThread *Thread, newStack uintptr, cloneThread *Thread, targetDomain *Domain)

func DisableIRQ

func DisableIRQ(irq uint8)

func DisableInterrupts

func DisableInterrupts()

func EnableIRQ

func EnableIRQ(irq uint8)

func EnableInterrupts

func EnableInterrupts()

func ExitDomain

func ExitDomain(d *Domain)

func ExitThread

func ExitThread(t *Thread)

func FindFreeTlsSlot

func FindFreeTlsSlot() uint32

func FlushTlsTable

func FlushTlsTable(table []GdtEntry)

func GetSegment

func GetSegment(index int, res *GdtSegment) int

func Hlt

func Hlt()

func Inb

func Inb(port uint16) uint8

func InitATA

func InitATA()

func InitInterrupts

func InitInterrupts()

func InitKeyboard

func InitKeyboard()

func InitMultiboot

func InitMultiboot(info *MultibootInfo)

func InitPIC

func InitPIC()

func InitPaging

func InitPaging()

func InitPit

func InitPit()

func InitScheduling

func InitScheduling()

func InitSegments

func InitSegments()

func InitSerialDevice

func InitSerialDevice()

func InitSerialDeviceInterrupt

func InitSerialDeviceInterrupt()

func InitUserMode

func InitUserMode(kernelStackStart uintptr, kernelStackEnd uintptr)

func Inw

func Inw(port uint16) uint16

func JumpUserMode

func JumpUserMode(regs RegisterState, info InterruptInfo)

func KernelThreadInit

func KernelThreadInit()

func LoadAuxVector

func LoadAuxVector(buf []auxVecEntry, elfHdr *elf.Header32, loadAddr uintptr) int

func LoadElfFile

func LoadElfFile(module *MultibootModule, space *mm.MemSpace) (*elf.Header32, uintptr, uintptr, syscall.Errno)

func Outb

func Outb(port uint16, value uint8)

func Outw

func Outw(port uint16, value uint16)

func PICInterruptHandler

func PICInterruptHandler()

func RegisterPICHandler

func RegisterPICHandler(irq uint8, f func())

func ResumeThread

func ResumeThread(t *Thread)

func Schedule

func Schedule()

func SetInterruptHandler

func SetInterruptHandler(irq uint8, f InterruptHandler, selector int, priv uint8)

func SetInterruptStack

func SetInterruptStack(addr uintptr)

func SetTlsSegment

func SetTlsSegment(index uint32, desc *UserDesc) bool

func Shutdown

func Shutdown()

func StartProgram

func StartProgram(path string, outDomain *Domain, outMainThread *Thread) syscall.Errno

Need pointer as this function should not do any memory allocations

func StartProgramUsr

func StartProgramUsr(path uintptr, argv uintptr, envp uintptr, outDomain *Domain, outMainThread *Thread) syscall.Errno

func TextModeFlushScreen

func TextModeFlushScreen()

func TextModeInit

func TextModeInit()

func TextModePrintLnCol

func TextModePrintLnCol(s string, attr uint8)

func UpdateSegment

func UpdateSegment(index int, base uintptr, limit uintptr, access uint8, flags uint8) bool

Types

type AtaDrive

type AtaDrive struct {
	IOBase         uint16
	ControlBase    uint16
	Initialized    bool
	IsSlave        bool
	IdentifyData   [512]byte
	IdentifyStruct AtaIdentify
}

func (*AtaDrive) Initialize

func (d *AtaDrive) Initialize()

func (*AtaDrive) ReadSectors

func (d *AtaDrive) ReadSectors(address int, count uint8, buffer []byte) syscall.Errno

func (*AtaDrive) Reset

func (d *AtaDrive) Reset() bool

func (*AtaDrive) WriteSectors

func (d *AtaDrive) WriteSectors(address int, buffer []byte)

TODO: Explicit length?

type AtaIdentify

type AtaIdentify struct {
	NumSectorsPerTrack [2]uint8
	// contains filtered or unexported fields
}

func (*AtaIdentify) InitFromBytes

func (i *AtaIdentify) InitFromBytes(data []byte)

type Domain

type Domain struct {
	Pid uint32

	Segments    SegmentList
	MemorySpace mm.MemSpace

	ProgramName string
	// contains filtered or unexported fields
}

func FindDomainByPid

func FindDomainByPid(pid uint32) *Domain

func (*Domain) AddThread

func (d *Domain) AddThread(t *Thread)

func (*Domain) RemoveThread

func (d *Domain) RemoveThread(t *Thread)

type GdtDescriptor

type GdtDescriptor struct {
	GdtSize        uint16
	GdtAddressLow  uint16
	GdtAddressHigh uint16
}

type GdtEntry

type GdtEntry struct {
	// contains filtered or unexported fields
}

func (*GdtEntry) Clear

func (e *GdtEntry) Clear()

func (*GdtEntry) Fill

func (e *GdtEntry) Fill(base uint32, limit uint32, access uint8, flags uint8)

func (*GdtEntry) IsPresent

func (e *GdtEntry) IsPresent() bool

type GdtSegment

type GdtSegment struct {
	// contains filtered or unexported fields
}

func (*GdtSegment) Clear

func (s *GdtSegment) Clear()

func (*GdtSegment) IsPresent

func (s *GdtSegment) IsPresent() bool

type GenericRing

type GenericRing struct {
	Cap int // Cannot use function as it requires memory allocation for a method reference
	// contains filtered or unexported fields
}

func (*GenericRing) Len

func (r *GenericRing) Len() int

func (*GenericRing) Pop

func (r *GenericRing) Pop() int

func (*GenericRing) Push

func (r *GenericRing) Push() int

type IdtDescriptor

type IdtDescriptor struct {
	IdtSize        uint16
	IdtAddressLow  uint16
	IdtAddressHigh uint16
}

type IdtEntry

type IdtEntry struct {
	// contains filtered or unexported fields
}

type InterruptHandler

type InterruptHandler func()

type InterruptInfo

type InterruptInfo struct {
	InterruptNumber uint32
	ExceptionCode   uint32
	EIP             uintptr
	CS              uint32
	EFLAGS          uint32
	ESP             uint32
	SS              uint32
}

type KeyboardRing

type KeyboardRing struct {
	Ring   GenericRing
	Buffer [32]Keystate
}

func (*KeyboardRing) Cap

func (r *KeyboardRing) Cap() int

func (*KeyboardRing) Init

func (r *KeyboardRing) Init()

func (*KeyboardRing) Len

func (r *KeyboardRing) Len() int

func (*KeyboardRing) Pop

func (r *KeyboardRing) Pop() *Keystate

func (*KeyboardRing) Push

func (r *KeyboardRing) Push(s Keystate)

type Keystate

type Keystate struct {
	Keycode uint8
}

type MemoryMap

type MemoryMap struct {
	BaseAddr uint64

	Length uint64

	Type uint32
	// contains filtered or unexported fields
}

type Module

type Module struct {
	Start   uint32
	End     uint32
	Cmdline string
}

type MultibootInfo

type MultibootInfo struct {
	TotalSize uint32
	// contains filtered or unexported fields
}

type MultibootMemoryMap

type MultibootMemoryMap struct {
	MultibootTag // Type is 6
	EntrySize    uint32
	EntryVersion uint32
	Entries      MemoryMap // Take pointer of it and use it as slice with
}

type MultibootModule

type MultibootModule struct {
	MultibootTag
	// Start is the inclusive start of the Module memory location
	Start uint32

	// End is the exclusive end of the Module memory location.
	End uint32
	// contains filtered or unexported fields
}

A module represents a module to be loaded along with the kernel.

func FindMultibootModule

func FindMultibootModule(multibootModuleName string) (*MultibootModule, syscall.Errno)

func FindMultibootModuleUsr

func FindMultibootModuleUsr(multibootModuleName uintptr) (*MultibootModule, syscall.Errno)

func (*MultibootModule) Cmdline

func (m *MultibootModule) Cmdline() string

type MultibootTag

type MultibootTag struct {
	Type uint32
	Size uint32
}

type RegisterState

type RegisterState struct {
	GS uint32
	FS uint32
	ES uint32
	DS uint32

	EDI       uint32
	ESI       uint32
	EBP       uint32
	KernelESP uint32
	EBX       uint32
	EDX       uint32
	ECX       uint32
	EAX       uint32
}

Reverse of stack pushing

type SegmentList

type SegmentList struct {
	// contains filtered or unexported fields
}

type TextModeErrorWriter

type TextModeErrorWriter struct {
}

func (TextModeErrorWriter) Write

func (e TextModeErrorWriter) Write(p []byte) (int, error)

type TextModeWriter

type TextModeWriter struct {
}

func (TextModeWriter) Write

func (e TextModeWriter) Write(p []byte) (int, error)

type Thread

type Thread struct {
	Next *Thread

	Domain *Domain
	Tid    uint32

	// Currently ignored '^^ I don't have to do it thanks to spurious wakeups
	IsBlocked   bool
	WaitAddress *uint32

	Regs RegisterState

	KernelRegs RegisterState

	IsKernelInterrupt bool
	// contains filtered or unexported fields
}

type TlsEntry

type TlsEntry struct {
	Desc    UserDesc
	Present bool
}

type UARTSerialDevice

type UARTSerialDevice struct {
	BasePort uint16
	// contains filtered or unexported fields
}
var (
	SerialDevice UARTSerialDevice
)

func (UARTSerialDevice) HasReceivedData

func (d UARTSerialDevice) HasReceivedData() bool

func (*UARTSerialDevice) Initialize

func (d *UARTSerialDevice) Initialize() syscall.Errno

func (UARTSerialDevice) Read

func (d UARTSerialDevice) Read() uint8

func (UARTSerialDevice) Write

func (d UARTSerialDevice) Write(arr []byte) (int, error)

func (UARTSerialDevice) WriteChar

func (d UARTSerialDevice) WriteChar(arg byte)

type UserDesc

type UserDesc struct {
	EntryNumber uint32
	BaseAddr    uint32
	Limit       uint32
	Flags       uint8
}

Directories

Path Synopsis
This package exists so that there is a main.main symbol This will cause the go compiler to emit an ELF file instead of a go archive I need an ELF file to build the kernel
This package exists so that there is a main.main symbol This will cause the go compiler to emit an ELF file instead of a go archive I need an ELF file to build the kernel

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL