1616#include <phoenix/kernel.h>
1717#include <phoenix/stivale2.h>
1818#include <phoenix/serial.h>
19- #include <phoenix/pmm.h>
20- #include <phoenix/vga.h>
2119#include <stivale2.h>
2220#include <stdint.h>
2321#include <stddef.h>
2422
2523/* Stack required by the stivale2 specifications */
26- static uint8_t stack [4096 ];
24+ static u8 stack [4096 ];
2725
2826/*
2927static struct stivale2_header_tag_framebuffer framebuffer_tag = {
@@ -41,20 +39,20 @@ static struct stivale2_header_tag_smp smp_tag = {
4139 .tag = {
4240 .identifier = STIVALE2_HEADER_TAG_SMP_ID,
4341 .next = 0,
44- //.next = (uint64_t )&framebuffer_tag,
42+ //.next = (u64 )&framebuffer_tag,
4543 },
4644 .flags = 0
4745};
4846*/
4947
5048/* Base Stivale2 header */
51- __attribute__(( section ( ".stivale2hdr" ), used ) )
49+ SECTION ( ".stivale2hdr" )
5250struct stivale2_header stivale_hdr = {
53- .entry_point = (uintptr_t )& init ,
54- .stack = (uintptr_t )stack + sizeof (stack ),
51+ .entry_point = (uptr )& init ,
52+ .stack = (uptr )stack + sizeof (stack ),
5553 .flags = 0 ,
5654 .tags = 0 ,
57- /*.tags = (uint64_t )&smp_tag, */
55+ /*.tags = (u64 )&smp_tag, */
5856};
5957
6058void stivale2_print_fb_tag (struct stivale2_struct_tag_framebuffer * fb_tag )
@@ -94,7 +92,7 @@ void stivale2_print_smp_tag(struct stivale2_struct_tag_smp* smp_tag)
9492void stivale2_print_memmap (struct stivale2_struct_tag_memmap * memmap_tag )
9593{
9694 info ("Memmap Entries: %d\n" , memmap_tag -> entries );
97- for (uint64_t i = 0 ; i < memmap_tag -> entries ; i ++ ) {
95+ for (u64 i = 0 ; i < memmap_tag -> entries ; i ++ ) {
9896 struct stivale2_mmap_entry * current_entry = & memmap_tag -> memmap [i ];
9997 switch (current_entry -> type ) {
10098
@@ -140,7 +138,7 @@ void stivale2_print_memmap(struct stivale2_struct_tag_memmap* memmap_tag)
140138 info ("\n" );
141139}
142140
143- void * stivale2_get_tag (struct stivale2_struct * hdr , uint64_t id )
141+ void * stivale2_get_tag (struct stivale2_struct * hdr , u64 id )
144142{
145143 struct stivale2_tag * current_tag = (void * )hdr -> tags ;
146144 for (;;) {
@@ -159,8 +157,8 @@ void* stivale2_get_tag(struct stivale2_struct* hdr, uint64_t id)
159157 }
160158}
161159
162- struct usable_memory_hdr
163- stivale2_get_usable_memory (struct stivale2_struct * hdr )
160+ struct free_memory_hdr
161+ stivale2_get_free_memory (struct stivale2_struct * hdr )
164162{
165163 /* Get memmap tag */
166164 struct stivale2_struct_tag_memmap * memmap_tag ;
@@ -172,39 +170,46 @@ stivale2_get_usable_memory(struct stivale2_struct* hdr)
172170 panic ("No stivale2 memmap tag has been found !\n" );
173171 }
174172
175- /* Get Usable Entries */
176- struct usable_memory_hdr usable_hdr ;
177- struct usable_memory entry ;
178- usable_hdr .entries = 0 ;
179- uint64_t i ;
180- for (i = 0 ; i < memmap_tag -> entries ; i ++ ) {
173+ /* Get free entries */
174+ struct free_memory_hdr free_hdr ;
175+ struct free_memory entry ;
176+ uptr highest_memory = 0 ;
177+ free_hdr .entries = 0 ;
178+
179+ for (u64 i = 0 ; i < memmap_tag -> entries ; i ++ ) {
181180 struct stivale2_mmap_entry * current_entry = & memmap_tag -> memmap [i ];
182181
183- usable_hdr .total_memory += entry .length ;
182+ free_hdr .total_memory += entry .length ;
184183
185184 if (current_entry -> type == STIVALE2_MMAP_USABLE ||
186185 current_entry -> type == STIVALE2_MMAP_KERNEL_AND_MODULES ||
187- current_entry -> type == STIVALE2_MMAP_BOOTLOADER_RECLAIMABLE ) {
186+ current_entry -> type == STIVALE2_MMAP_BOOTLOADER_RECLAIMABLE ) {
188187
189188 /* Found an Usable Entry */
190189 entry .base = current_entry -> base ;
191190 entry .length = current_entry -> length ;
192- entry .type = current_entry -> type ;
193- usable_hdr .segments [usable_hdr .entries ] = entry ;
191+ entry .type = current_entry -> type ;
192+ free_hdr .segments [free_hdr .entries ] = entry ;
193+
194+ debug ("[STIVALE2_MEMMAP] Stored a free memory entry\n" );
195+
196+ highest_memory = entry .base + entry .length ;
194197
195- debug ("[STIVALE2_MEMMAP] Found an usable entry\n" );
198+ /* Store the highest free memory */
199+ if (highest_memory > free_hdr .highest_memory )
200+ free_hdr .highest_memory = highest_memory ;
196201
197- usable_hdr . usable_memory += entry .length ;
198- usable_hdr .entries ++ ;
202+ free_hdr . free_memory += entry .length ;
203+ free_hdr .entries ++ ;
199204 }
200205 }
201206
202207 /* Panic if no entries are found */
203- if (usable_hdr .entries <= 0 ) {
204- panic ("No usable memory has been found !\n" );
208+ if (free_hdr .entries <= 0 ) {
209+ panic ("No free memory has been found !\n" );
205210 }
206211
207- return usable_hdr ;
212+ return free_hdr ;
208213}
209214
210215char * stivale2_get_cmdline (struct stivale2_struct * hdr )
0 commit comments