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

285 Commits

Author SHA1 Message Date
Achilleas Anagnostopoulos
6ca86e55f8 Reserve kernel image pages and decomission early allocator 2017-06-18 09:49:51 +01:00
Achilleas Anagnostopoulos
8b22862784 Support looking up pools by frame and flagging bitmap entries as
reserved/free
2017-06-18 09:49:51 +01:00
Achilleas Anagnostopoulos
bc44151c93 Reserve and initialize the BitmapAllocator frame pools 2017-06-18 09:49:51 +01:00
Achilleas Anagnostopoulos
1c3bfcd58d Implement early virtual address space reservation helper
Function EarlyReserveRegion reserves contiguous virtual address space
regions beginning at the end of the available kernel space and moving
towards lower virtual addresses. The only state that is tracked by this
function is the last allocated virtual page address which is adjusted
after each reservation request.

Starting at the end of the kernel address space ensures that we will not
step on the virtual addresses used by the kernel code and data sections.
2017-06-18 09:49:51 +01:00
Achilleas Anagnostopoulos
dbdf686d27 Provide helper for setting the active frame allocator
This allows us to remove the allocFn argument from the vmm functions
which causes the compiler's escape analysis to sometimes incorectly flag
it as escaping to the heap.
2017-06-18 09:49:47 +01:00
Achilleas Anagnostopoulos
1b88764676 Enable support for the no-execute (NX) bit 2017-06-18 09:46:04 +01:00
Achilleas Anagnostopoulos
886c7b10fa Merge pull request #24 from achilleasa/refactor-bootmem-allocator
Refactor bootmem allocator
2017-06-18 09:36:56 +01:00
Achilleas Anagnostopoulos
8698e7bc93 Exclude the region where the kernel is loaded when allocating frames
The linked.ld script is extended to include the _kernel_start and
_kernel_end symbols which are passed by the rt0 code to Kmain. The
allocator converts these addresses to a start/end frame index by
rounding down the kernel start address to the nearest page and rounding
up the kernel end address to the nearest page.

When allocating frames, the allocator will treat the region defined by
these 2 indices as reserved and skip over it.
2017-06-18 09:15:51 +01:00
Achilleas Anagnostopoulos
c81fd8b758 Pass kernel start/end physical address to Kmain 2017-06-18 09:15:51 +01:00
Achilleas Anagnostopoulos
ad0bf0a4ca Refactor allocator and unexport it
AllocFrame now rounds up the region start address to the nearest page
multiple and rounds down the region end address to the nearest page
multiple. It also ignores memory regions with size smaller than a page.

Instead of using frame indices and converting them to a pmm.Frame, the
allocator now just keeps track of the last allocated pmm.Frame.

As the allocator is now unexported, a package-exported Init() method is
now provided whose purpose is to initialize the physical allocator
sub-system.
2017-06-18 09:15:50 +01:00
Achilleas Anagnostopoulos
c0a9e07e83 Remove mem.PageOrder
Since the goal is to bootstrap the runtime's slab-like allocator the kernel
should only deal with managing allocations at a single page level.
2017-06-18 09:14:53 +01:00
Achilleas Anagnostopoulos
1d11af21c2 Move bootmem allocator in a sub-pkg 2017-06-18 09:13:19 +01:00
Achilleas Anagnostopoulos
0e96d9c5e2 Merge pull request #26 from tw4452852/25
fix build failure because of _cgo_yield
2017-06-17 20:34:18 +01:00
Tw
533ce2f2ea fix build failure because of _cgo_yield
Signed-off-by: Tw <tw19881113@gmail.com>
2017-06-17 20:16:31 +08:00
Achilleas Anagnostopoulos
2f56d78629 Make the GO variable visible on non-linux hosts 2017-06-17 11:08:02 +01:00
Achilleas Anagnostopoulos
45fb719d04 Merge pull request #19 from jeffallen/fix-makefile
Fix several usability problems in the Makefile
2017-06-15 18:57:58 +01:00
Jeff Allen
7f3db2235d Added another missing check before generating ISOs. 2017-06-14 11:53:44 +02:00
Jeff Allen
e428d6c672 Fix several usability problems in the Makefile
Allow "make run" and "make gdb" to be used on Linux, not just
non-Linux.

Allow the user to set the go binary from the commandline.

Pass GOROOT in to make different Go installs use the right
Go root.

Check that xorriso is installed, because if it is not, grub-mkrescue
will silently exit.
2017-06-14 11:33:12 +02:00
Achilleas Anagnostopoulos
d8c040cf27 Merge pull request #17 from kofiasare/master
fix typo
2017-06-14 09:10:50 +01:00
Kofi Asare
29c69f26f6 fix typo 2017-06-13 10:12:23 +00:00
Achilleas Anagnostopoulos
a5be59e411 Merge pull request #14 from achilleasa/page-table-support
Add support for page tables and virtual -> physical mapping
2017-06-07 07:38:17 +01:00
Achilleas Anagnostopoulos
76532089c5 Define PageDirectoryTable and helpers that support inactive tables
The Map/Unmap methods of PageDirectoryTable operate similar to the
global Map/Unmap functions. While the global functions work with the
currently active PDT, the PageDirectoryTable methods can also
work with inactive page tables by temporarily modifying the recursive
mapping of the active PDT to point to the inactive PDT frame before
delegating the mapping/unmapping to the global Map/Unmap functions.
2017-06-06 19:35:07 +01:00
Achilleas Anagnostopoulos
8e38ff969d Implement API for mapping virtual addresses to physical frames
The API provides the Map() and MapTemporary() functions that establish
virtual -> physical address mappings using the currently active page
directory table.

Mapped pages can be unmapped using the Unmap() function. When unmapping
virtual addresses, the page tables leading to them will not be
automatically released even if they are empty. This will be addressed by
a future commit.
2017-06-06 11:02:48 +01:00
Achilleas Anagnostopoulos
6e03af069a Add support for virtual -> physical address translation 2017-06-06 07:30:13 +01:00
Achilleas Anagnostopoulos
319f868a14 Implement page table entry walker
The page table walker provides a mechanism for accessing the individual
page table entries that correspond to a particular virtual memory
address. This implementation will serve as the basis for implementing
page mapping/unmapping and virtual to physical address translation.
2017-06-06 07:30:13 +01:00
Achilleas Anagnostopoulos
35eaa1a13c Define page table entry type 2017-06-06 07:30:07 +01:00
Achilleas Anagnostopoulos
b67a2045b9 Define virtual memory page type
This is equivalent to pmm.Frame (also a uintptr) but having different
types for physical and virtual frames serves as an additional layer of
protection for functions/methods that receive physical and/or virtual
page arguments.
2017-06-04 21:48:21 +01:00
Achilleas Anagnostopoulos
c596bc96c3 Define paging-related constants for the amd64 architecture 2017-06-04 21:48:15 +01:00
Achilleas Anagnostopoulos
99e4bedb74 Recursively map last P4 entry to itself
This allows us to use specially-crafted virtual memory addresses to
remove indirection levels and access the actual page table entries.
2017-05-31 17:02:56 +01:00
Achilleas Anagnostopoulos
1a6ade8ced Cleanup Frame tests and rename Frame.IsValid to Frame.Valid 2017-05-31 17:02:34 +01:00
Achilleas Anagnostopoulos
ff8aabe51f Merge pull request #13 from achilleasa/boot-allocator-tweaks
Boot allocator tweaks
2017-05-31 15:25:52 +01:00
Achilleas Anagnostopoulos
7156b09656 Change boot allocator signature so it returns a kernel error 2017-05-31 15:24:41 +01:00
Achilleas Anagnostopoulos
d7eb2547dd Change the Frame type to uintptr and remove Size/Order methods
To keep the implementation portable, the Frame type had to be changed
from uint64 to uintptr. Using uintptr ensures that the frame will always
match the pointer size of the platform.
2017-05-31 15:07:09 +01:00
Achilleas Anagnostopoulos
ec6ce4b70e Move Kmain into its own package
This allows us to keep the error definition in the kernel package
without causing circular import errors
2017-05-31 15:07:02 +01:00
Achilleas Anagnostopoulos
d5a4c43406 Define type for kernel error messages
Since the Go memory allocator is not available to us we need to define
our own error type.
2017-05-31 14:59:47 +01:00
Achilleas Anagnostopoulos
13d5f494e2 Rename pfn pkg to pmm and export boot allocator Init method 2017-05-31 14:16:51 +01:00
Achilleas Anagnostopoulos
412bcf8402 Merge pull request #12 from achilleasa/early-physical-page-allocator
Early physical page allocator
2017-05-15 07:45:06 +01:00
Achilleas Anagnostopoulos
8c619e38e1 Implement early page allocator 2017-05-15 07:35:58 +01:00
Achilleas Anagnostopoulos
e1ada1ac8a Allow mem region visitors to abort the scan by returning false 2017-05-15 07:30:49 +01:00
Achilleas Anagnostopoulos
61314a9c33 Define memory Size and implement optimized memset 2017-05-15 07:30:49 +01:00
Achilleas Anagnostopoulos
ca36793782 Add test Makefile target 2017-05-15 07:30:49 +01:00
Achilleas Anagnostopoulos
52266c9f66 Make %x formatting verb in early.Printf behave like fmt.Printf
The %x verb in fmt.Printf does not add the "0x" prefix automatically so
early.Printf has been changed to match this behavior.
2017-05-15 07:05:07 +01:00
Achilleas Anagnostopoulos
1d8d81095c Merge pull request #11 from achilleasa/use-linter
Use linter and fix linter warnings
2017-05-15 06:59:01 +01:00
Achilleas Anagnostopoulos
cb0975c9c4 Fix linter errors 2017-05-15 06:55:31 +01:00
Achilleas Anagnostopoulos
1c17562f07 Add lint Makefile target 2017-05-15 06:55:14 +01:00
Achilleas Anagnostopoulos
be529349bb Merge pull request #10 from achilleasa/improve-tty-and-fix-fmt-bugs
Improve tty and fix fmt bugs
2017-05-12 08:16:33 +01:00
Achilleas Anagnostopoulos
6d3c463ee8 Prevent early_fmt code from triggering Go's allocator
When converting strings to []byte so that they can be used with the tty
io.Writer interface Go calls a runtime method called
"stringtoslicebyte". If the input length exceeds a particular size then
this method will allocate a new []byte and copy the data into it. This
obviously causes our kernel to crash.

To fix this, all early_fmt functions have been changed to iterate any
string arguments and output them to the active TTY one byte at a time.
2017-05-12 08:00:18 +01:00
Achilleas Anagnostopoulos
d7028cee00 Make TTYs implement io.ByteWriter and add support for TAB/BS chars 2017-05-12 07:54:42 +01:00
Achilleas Anagnostopoulos
0154c132ea Merge pull request #9 from achilleasa/enter-longmode-and-setup-paging
Switch to a 64-bit version of the kernel and rt0 code
2017-05-03 21:39:48 +01:00
Achilleas Anagnostopoulos
2558f79fbf Switch to a 64-bit version of the kernel and rt0 code
The switch to 64-bit mode allows us to use 48-bit addressing and to
relocate the kernel to virtual address 0xffff800000000000 + 1M. The
actual kernel is loaded by the bootloader at physical address 1M.

The rt0 code has been split in two parts. The 32-bit part provides the
entrypoint that the bootloader jumps to after loading the kernel. Its
purpose is to make sure that:
- the kernel was booted by a multiboot-compliant bootloader
- the multiboot info structures are copied to a reserved memory block
  where they can be accessed after enabling paging
- the CPU meets the minimum requirements for the kernel (CPUID, SSE,
  support for long-mode)

Since paging is not enabled when the 32-bit code runs, it needs to
translate all memory addresses it accesses to physical memory addresses
by subtracting PAGE_OFFSET. The 32-bit rt0 code will set up a page table
that identity-maps region: 0 to 8M and region: PAGE_OFFSET to
PAGE_OFFSET+8M. This ensures that when paging gets enabled, we will still
be able to access the kernel using both physical and virtual memory
addresses. After enabling paging, the 32-bit rt0 will jump to a small
64-bit trampoline function that updates the stack pointer to use the
proper virtual address and jumps to the virtual address of the 64-bit
entry point.

The 64-bit entrypoint sets up the minimal g0 structure required by the
go function prologue for stack checks and sets up the FS register to
point to it. The principle is the same as with 32-bit code (a segment
register has the address of a pointer to the active g) with the
difference that in 64-bit mode, the FS register is used instead of GS
and that in order to set its value we need to write to a MSR.
2017-05-03 21:37:53 +01:00