Skip to content

Commit b063579

Browse files
Improved source code, added doxygen docs, added new commands meminfo and heapinfo, added vnc for github actions, improved github actions.
1 parent e1301de commit b063579

File tree

11 files changed

+154
-38
lines changed

11 files changed

+154
-38
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ jobs:
3636
run: sudo pkill qemu
3737

3838
- name: Upload to file.io
39-
run: ls && curl -F "file=@./FrostWing.iso" https://file.io
39+
run: curl -F "file=@./FrostWing.iso" https://file.io

Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ run-x86-uefi:
7070
-device ide-hd,drive=disk,bus=ahci.0 \
7171
-m 512
7272

73+
run-x86-vnc:
74+
@qemu-system-x86_64 \
75+
-vga std \
76+
-debugcon stdio \
77+
-serial file:serial.log \
78+
-device rtl8139,netdev=eth0 \
79+
-netdev user,hostfwd=tcp::5555-:22,id=eth0 \
80+
-cdrom FrostWing.iso \
81+
-m 256 \
82+
-no-reboot \
83+
-vnc :1 -display none &
84+
7385
everything:
7486
@make clean all -C source && make iso tarball run-x86
7587

source/includes/idt.h

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
* @file idt.h
3+
* @author Pradosh ([email protected]) & GAMINGNOOB
4+
* @brief
5+
* @version 0.1
6+
* @date 2025-02-03
7+
*
8+
* @copyright Copyright Pradosh (c) 2025
9+
*
10+
*/
11+
12+
113
#ifndef IDT_H
214
#define IDT_H
315

source/includes/isr.h

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* @file isr.h
3+
* @author Pradosh ([email protected]) & GAMINGNOOB
4+
* @brief Interrupts handler header.
5+
* @version 0.1
6+
* @date 2025-02-03
7+
*
8+
* @copyright Copyright Pradosh (c) 2025
9+
*
10+
*/
111
#ifndef ISR_H
212
#define ISR_H
313

source/includes/memory2.h

+35-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@
99

1010
#include <basics.h>
1111

12+
#ifndef MEMORY_H
13+
#define MEMORY_H
14+
15+
struct memory_context {
16+
int64 total;
17+
int64 usable;
18+
int64 reserved;
19+
int64 acpi_reclaimable;
20+
int64 acpi_nvs;
21+
int64 bad;
22+
int64 bootloader_reclaimable;
23+
int64 kernel_modules;
24+
int64 framebuffer; // Mostly unneeded because frame buffer struct separately gives it,
25+
int64 unknown; // This value must be always 0.
26+
};
27+
28+
extern struct memory_context memory;
29+
1230
/**
1331
* @brief Copies a block of memory from a source location to a destination location.
1432
*
@@ -79,4 +97,20 @@ void memory_dump(const void* start, const void* end);
7997
* @param size Size of the memory to allocate.
8098
* @return Pointer to the allocated memory, or NULL if allocation fails.
8199
*/
82-
void* allocate_memory_at_address(int64 phys_addr, size_t size);
100+
void* allocate_memory_at_address(int64 phys_addr, size_t size);
101+
102+
/**
103+
* @brief Display the formatted memory context.
104+
*
105+
* @param memory The memory context to display.
106+
*/
107+
void display_memory_formatted(struct memory_context memory);
108+
109+
/**
110+
* @brief Returns the CR2 register.
111+
*
112+
* @return uint64_t value of CR2.
113+
*/
114+
uint64_t getCR2();
115+
116+
#endif // MEMORY_H

source/kernel/C/heap.c

+30-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <heap.h>
1313
#include <stddef.h>
1414
#include <graphics.h>
15+
#include <memory2.h>
1516

1617
uint32_t last_alloc = 0;
1718
uint32_t heap_end = 0;
@@ -47,6 +48,19 @@ void mm_extend(uint32_t additional_size)
4748
done("Heap extended.", __FILE__);
4849
}
4950

51+
void mm_constrict(uint32_t removal_size)
52+
{
53+
if (removal_size <= 0){
54+
warn("mm_extend: Invalid size.", __FILE__);
55+
return;
56+
}
57+
58+
info("Constricting heap.", __FILE__);
59+
heap_end -= removal_size;
60+
printf("Heap constricting by %d bytes. New heap end: 0x%x", removal_size, heap_end);
61+
done("Heap Constricted.", __FILE__);
62+
}
63+
5064
void mm_print_out()
5165
{
5266
printf("%sMemory used :%s %d bytes", yellow_color, reset_color, memory_used);
@@ -56,6 +70,11 @@ void mm_print_out()
5670

5771
void free(void *mem)
5872
{
73+
if(mem == 0){
74+
warn("free: Cannot free null pointer.", __FILE__);
75+
return;
76+
}
77+
5978
alloc_t *alloc = (mem - sizeof(alloc_t));
6079
memory_used -= alloc->size + sizeof(alloc_t);
6180
alloc->status = 0;
@@ -75,7 +94,11 @@ void pfree(void *mem)
7594

7695
char* pmalloc(size_t size)
7796
{
78-
/* Loop through the avail_list */
97+
if(size <= 0){
98+
warn("pmalloc: Cannot allocate 0 bytes.", __FILE__);
99+
return 0;
100+
}
101+
79102
for(int i = 0; i < MAX_PAGE_ALIGNED_ALLOCS; i++)
80103
{
81104
if(pheap_desc[i]) continue;
@@ -89,7 +112,10 @@ char* pmalloc(size_t size)
89112

90113
char* malloc(size_t size)
91114
{
92-
if(!size) return 0;
115+
if(size <= 0){
116+
warn("malloc: Cannot allocate 0 bytes.", __FILE__);
117+
return 0;
118+
}
93119

94120
/* Loop through blocks and find a block sized the same or bigger */
95121
uint8_t *mem = (uint8_t *)heap_begin;
@@ -134,7 +160,7 @@ char* malloc(size_t size)
134160
nalloc:;
135161
if(last_alloc+size+sizeof(alloc_t) >= heap_end)
136162
{
137-
meltdown_screen("Heap out of memory!", __FILE__, __LINE__, 0, 0, 0);
163+
meltdown_screen("Heap out of memory!", __FILE__, __LINE__, 0, getCR2(), 0);
138164
hcf();
139165
}
140166
alloc_t *alloc = (alloc_t *)last_alloc;
@@ -144,6 +170,7 @@ char* malloc(size_t size)
144170
last_alloc += size;
145171
last_alloc += sizeof(alloc_t);
146172
last_alloc += 4;
173+
147174
// printf("Allocated %d bytes from to 0x%x", size, (uint32_t)alloc + sizeof(alloc_t), last_alloc);
148175
memory_used += size + 4 + sizeof(alloc_t);
149176
memset((char *)((uint32_t)alloc + sizeof(alloc_t)), 0, size);

source/kernel/C/interrupts/idt.c

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* @file idt.c
3+
* @author Pradosh ([email protected]) & GAMINGNOOB
4+
* @brief Interrupt descriptor table code.
5+
* @version 0.1
6+
* @date 2025-02-03
7+
*
8+
* @copyright Copyright Pradosh (c) 2025
9+
*
10+
*/
11+
112
#include <idt.h>
213
#include <isr.h>
314
#include <keyboard.h>

source/kernel/C/interrupts/isr.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
/**
2+
* @file isr.c
3+
* @author Pradosh ([email protected])
4+
* @brief Interrupts handler code.
5+
* @version 0.1
6+
* @date 2025-02-03
7+
*
8+
* @copyright Copyright (c) 2025
9+
*
10+
*/
11+
112
#include <isr.h>
213
#include <keyboard.h>
14+
#include <memory2.h>
315

416
irq_handler interrupt_handlers[256];
517

6-
static inline uint64_t getCR2(void)
7-
{
8-
uint64_t val;
9-
__asm__ volatile ( "mov %%cr2, %0" : "=r"(val) );
10-
return val;
11-
}
12-
1318
void exceptionHandler(InterruptFrame* frame) {
1419
switch (frame->int_no) {
1520
case 0:

source/kernel/C/kernel.c

+5-26
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,10 @@ struct limine_module_request module_request = {
5858
LIMINE_MODULE_REQUEST, 0, null
5959
};
6060

61-
struct memory_context {
62-
int64 total;
63-
int64 usable;
64-
int64 reserved;
65-
int64 acpi_reclaimable;
66-
int64 acpi_nvs;
67-
int64 bad;
68-
int64 bootloader_reclaimable;
69-
int64 kernel_modules;
70-
int64 framebuffer; // Mostly unneeded because frame buffer struct separately gives it,
71-
int64 unknown; // This value must be always 0.
72-
};
73-
74-
7561
struct flanterm_context *ft_ctx = null;
7662
struct limine_framebuffer *framebuffer = null;
7763

7864
bool isBufferReady = no;
79-
// bool logoBoot = no;
8065

8166
int32 ctr = 0;
8267

@@ -140,6 +125,8 @@ void mouseButtonHandler(uint8_t button, uint8_t action)
140125
}
141126
}
142127

128+
struct memory_context memory;
129+
143130
void main(void) {
144131
if (framebuffer_request.response == null) {
145132
hcf2();
@@ -168,9 +155,10 @@ void main(void) {
168155

169156
mm_init(kend);
170157

158+
mm_extend(2 MiB);
159+
171160
RTL8139 = (struct rtl8139*)malloc(sizeof(struct rtl8139));
172161

173-
struct memory_context memory;
174162
memory.total = 0;
175163
memory.usable = 0;
176164
memory.reserved = 0;
@@ -254,16 +242,7 @@ void main(void) {
254242
printf("Display Resolution: %dx%d (%d) pixels. Pitch: %d", framebuffer->width, framebuffer->height, framebuffer->width*framebuffer->height, framebuffer->pitch);
255243

256244
info("Memory Values begin! ===", __FILE__);
257-
printf("Usable : %d KiB", memory.usable / 1024);
258-
printf("Reserved : %d KiB", memory.reserved / 1024);
259-
printf("ACPI Reclaimable : %d KiB", memory.acpi_reclaimable / 1024);
260-
printf("ACPI NVS : %d KiB", memory.acpi_nvs / 1024);
261-
printf("Bad : %d KiB", memory.bad / 1024);
262-
printf("Bootloader Reclaimable : %d KiB", memory.bootloader_reclaimable / 1024);
263-
printf("Kernel Modules : %d KiB", memory.kernel_modules / 1024);
264-
printf("Framebuffer : %d KiB", memory.framebuffer / 1024);
265-
printf("Unknown : %d KiB", memory.unknown / 1024); print(yellow_color);
266-
printf("Grand Total : %d MiB", ((memory.total / 1024)/1024)-3); // There is an error of 3MB always for some reason
245+
display_memory_formatted(memory);
267246
info(reset_color "Memory values end! =====", __FILE__);
268247

269248
if(memory.bad != 0){

source/kernel/C/memory.c

+21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*
1010
*/
1111
#include <memory2.h>
12+
#include <graphics.h>
1213

1314
// GCC and Clang reserve the right to generate calls to the following
1415
// 4 functions even if they are not directly called.
@@ -132,4 +133,24 @@ void* allocate_memory_at_address(int64 phys_addr, size_t size) {
132133
void* ptr = (void*)phys_addr;
133134

134135
return ptr;
136+
}
137+
138+
void display_memory_formatted(struct memory_context memory) {
139+
printf("Usable : %d KiB", memory.usable / 1024);
140+
printf("Reserved : %d KiB", memory.reserved / 1024);
141+
printf("ACPI Reclaimable : %d KiB", memory.acpi_reclaimable / 1024);
142+
printf("ACPI NVS : %d KiB", memory.acpi_nvs / 1024);
143+
printf("Bad : %d KiB", memory.bad / 1024);
144+
printf("Bootloader Reclaimable : %d KiB", memory.bootloader_reclaimable / 1024);
145+
printf("Kernel Modules : %d KiB", memory.kernel_modules / 1024);
146+
printf("Framebuffer : %d KiB", memory.framebuffer / 1024);
147+
printf("Unknown : %d KiB", memory.unknown / 1024); print(yellow_color);
148+
printf("Grand Total : %d MiB", ((memory.total / 1024)/1024)-3); // There is an error of 3MB always for some reason
149+
}
150+
151+
uint64_t getCR2()
152+
{
153+
uint64_t val;
154+
__asm__ volatile ( "mov %%cr2, %0" : "=r"(val) );
155+
return val;
135156
}

source/kernel/C/shell/sh.c

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <flanterm/flanterm.h>
2222
#include <filesystems/fwrfs.h>
2323
#include <fdlfcn.h>
24+
#include <heap.h>
2425

2526
void init_command_list(command_list* lst)
2627
{
@@ -311,6 +312,10 @@ void execute(const char* buffer, int argc, char** argv)
311312
list_contents(fs);
312313
} else if (strncmp(buffer, "frostedwm", 9) == 0 || strcmp(buffer, "frostedwm") == 0) {
313314
start_window_manager();
315+
} else if (strncmp(buffer, "meminfo", 7) == 0 || strcmp(buffer, "meminfo") == 0) {
316+
display_memory_formatted(memory);
317+
} else if (strncmp(buffer, "heapinfo", 7) == 0 || strcmp(buffer, "heapinfo") == 0) {
318+
mm_print_out();
314319
} else if (strncmp(buffer, "user ", 5) == 0 || strcmp(buffer, "user") == 0) {
315320
if(argv[1] != null)
316321
if((int)argv[1] == 1)

0 commit comments

Comments
 (0)