aboutsummaryrefslogtreecommitdiff
path: root/kernel/bootinfo/multiboot.dats
diff options
context:
space:
mode:
authorXander <xander@biltopia.org>2023-07-21 21:36:54 +0200
committerXander <xander@biltopia.org>2023-07-21 21:36:54 +0200
commit1d25d9783127c181f79732eb5c20c680444af414 (patch)
tree5550f40b25af3e2722b5aaf6194f6df37ca9e092 /kernel/bootinfo/multiboot.dats
parent9226c8bb581c363a552998663704c483f35f6aae (diff)
downloadats-os-1d25d9783127c181f79732eb5c20c680444af414.tar.xz
ats-os-1d25d9783127c181f79732eb5c20c680444af414.zip
Mainly refactoring
Diffstat (limited to 'kernel/bootinfo/multiboot.dats')
-rw-r--r--kernel/bootinfo/multiboot.dats62
1 files changed, 40 insertions, 22 deletions
diff --git a/kernel/bootinfo/multiboot.dats b/kernel/bootinfo/multiboot.dats
index 6ea7b00..96d7f84 100644
--- a/kernel/bootinfo/multiboot.dats
+++ b/kernel/bootinfo/multiboot.dats
@@ -49,24 +49,25 @@ extern castfn ui2sz (n : uint) : [n : nat] size_t n
//------------Memory------------------------
-implement get_memory_mappings_n(p) = let
- val size = p.2->memory_map.tag.size
- val n_entries = (if(size >= 16u) then (size - 16u) / p.2->memory_map.entry_size else 0u) : uint
+implement get_memory_mappings_n(pf | p) = let
+ val size = p->memory_map.tag.size
+ val n_entries = (if(size >= 16u) then (size - 16u) / p->memory_map.entry_size else 0u) : uint
in
ui2sz n_entries
end
// TODO: here use optional datatype (fix runtime alloc)
-implement get_memory_mapping(p,n) = (
- assertloc(n < get_memory_mappings_n(p));
- $UN.ptr0_get<memory_area_t>(ptr_add<memory_area_t>(p.2->memory_map.entries,n))
+implement get_memory_mapping(pf | p,n) = (
+ assertloc(n < get_memory_mappings_n(pf | p));
+ $UN.ptr0_get<memory_area_t>(ptr_add<memory_area_t>(p->memory_map.entries,n))
)
+//TODO: use foreach with fwork to loop through memory maps
implement print_memory_mappings(p) = let
- val length = get_memory_mappings_n(p)
+ val length = get_memory_mappings_n(p.0 | p.2)
fun loop {n,i : nat | i < n} .<n-i>. (p : !bootptr, i : size_t i, n : size_t n) : void = let
- val entry = get_memory_mapping(p,i)
+ val entry = get_memory_mapping(p.0 | p.2 ,i)
in
if (entry.type = 1) then (
print(" Start Address: ");
@@ -96,13 +97,37 @@ implement get_elf_header (p,n) = (
$UN.ptr0_get<elf64_shdr_t>(ptr_add<elf64_shdr_t>(p.2->elf_tag.headers,n))
)
+implement get_kernel_ranges(p) = let
+ val length = get_elf_headers_n(p)
+ fun loop {n,i : nat | i < n} .<n-i>. (p : !bootptr, i : size_t i,n : size_t n, min : Ptr, max : Ptr) : (Ptr,Ptr) = let
+ val header = get_elf_header(p,i)
+ val new_min = (if ((header.addr < min || min = the_null_ptr) && header.size != 0) then header.addr else min)
+ val end_p = ptr_add<uint8>(header.addr,header.size)
+ val new_max = (
+ if (end_p > max && header.size != 0)
+ then $UN.cast2Ptr1(end_p)
+ else max
+ )
+ in
+ if (i < n - 1) then
+ loop(p,succ(i),n,new_min,new_max)
+ else
+ (new_min,new_max)
+ end
+
+in
+ if (length > 0) then
+ loop(p,i2sz(0),length,the_null_ptr,the_null_ptr)
+ else
+ (the_null_ptr,the_null_ptr)
+end
+
+implement get_bootinfo_ranges(p) = (p.2, ptr_add<uint8>(p.2,p.2->total_size))
+
implement print_elf_headers(p) = let
val length = get_elf_headers_n(p)
- fun loop {n,i : nat | i < n} .<n-i>. (p : !bootptr, i : size_t i, n : size_t n, min : size_t, max : size_t) : void = let
+ fun loop {n,i : nat | i < n} .<n-i>. (p : !bootptr, i : size_t i, n : size_t n) : void = let
val header = get_elf_header(p,i)
- val a = $UN.cast{size_t}(header.addr)
- val new_min = (if (a < min && header.size != 0) then a else min) : size_t
- val new_max = (if (a + header.size > max && header.size != 0) then a + header.size else max) : size_t
in
print(" addr: ");
print_hex(header.addr);
@@ -112,20 +137,13 @@ implement print_elf_headers(p) = let
println_hex(header.flags);
if (i < n - 1) then
- loop(p,succ(i),n,new_min,new_max)
- else (
- print("Kernel start: ");
- print_hex(new_min);
- print(" end: ");
- print_hex(new_max);
- print(" size: ");
- println!(new_max - new_min)
- )
+ loop(p,succ(i),n)
+
end
in
if (length > 0) then (
println!("Elf section headers: ");
- loop(p,i2sz(0),length,i2sz(0xFFFFFF),i2sz(0)))
+ loop(p,i2sz(0),length))
else
println!("No elf section headers")
end