I am making a fully custom x86 32 bit IA32 Operating System in Visual Studio Code 1.81 for Debian Linux. This will not be a linux based OS. It's also not posix, linux, unix, windows, bsd or any other derivitive thereof but does use the same concepts. The system I am developing on has a Intel i7-3770k and is an x86_64 bit and runs Debian 10 Buster Linux with Linux Kernel version 4.19.0-25-amd64 (supports UNIX 98 PTY) and Bash 5.0.3 and the drive has an ext4 partition and a tempfs partition. I have the extension ms-vscode.cpptools installed on VSCode. I also have both gcc 8.3.0 and clang 7.0.1-8+deb10u2 installed. All of my compilers, debuggers, linkers are in /usr/bin. I have Coreutils 8.30, Binutils 2.31.1, Bison 3.3.2, Diffutils 3.7, Findutils 4.6.0.225, Gawk 4.2.1, Grep 3.3, Gzip 1.9, M4 1.4.18, Make 4.2.1, Patch 2.7.6, Perl 5.28.1, Python 3.7.3, Sed 4.7, Tar 1.30, Texinfo 6.5, Xz 5.2.4. The operating system would run on any system that has a 386 CPU up to a 32 bit only Prescott Pentium 4 released in 2004 including i386, i486, i586 and i686. I am using gcc to compile, ld to link, gdb to debug, nasm to do the assembly and qemu to emulate the system. it has a two stage bootloader. The os should boot from floppy, hard drive and optical media.
Here is the system ,emory map
BIOS: The Basic Input/Output System often resides in the lower 64KB (first 65536 bytes) of memory.
MBR (Master Boot Record): The first sector of the boot disk (usually 512 bytes) is typically located at 0x00007C00.
VGA Memory: The memory used for graphics display might be mapped in this region (e.g., 0xB8000 for text mode).
Legacy Device Memory: Memory-mapped I/O (MMIO) regions for legacy devices like keyboard, mouse, or floppy controller could be present.
Lower 1GB of RAM: This is the main usable memory region for the kernel, applications, and data. The kernel might load itself here after being booted by the bootloader.
the kernel.c should be kernel_main() and
Kernel Stack Implementation:
Memory Allocation: The kernel reserves a dedicated memory region for the kernel stack during boot or early initialization. This region typically resides within the usable portion of memory allocated for the kernel itself (often within the first 1GB on IA32 systems).
Stack Pointer (ESP): The kernel maintains a stack pointer register (often ESP or RSP on x86 architectures) that points to the top of the kernel stack. Initially, this pointer is set to the end of the allocated stack memory region, indicating an empty stack.
Stack Growth: When a function is called in kernel space, the required data (arguments, local variables, return address) is pushed onto the stack. This decrements the stack pointer value, effectively "growing" the stack downwards in memory.
Stack Protection: The kernel sets up memory protection mechanisms to ensure the stack doesn't grow beyond its allocated region or overwrite other critical kernel data structures.
Stack Overflow Protection: The kernel might implement stack overflow protection mechanisms to detect and handle situations where the stack grows too large and threatens to overwrite other memory areas. This can involve setting up guard pages below the allocated stack space to trigger exceptions if accessed.