Compare commits
2 Commits
97357f3170
...
5983212da0
| Author | SHA1 | Date | |
|---|---|---|---|
| 5983212da0 | |||
| 432d160b7a |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,6 +4,8 @@
|
|||||||
*.bin
|
*.bin
|
||||||
*.elf
|
*.elf
|
||||||
|
|
||||||
|
.cache
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,21 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"arguments": [
|
||||||
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
|
"-c",
|
||||||
|
"-ffreestanding",
|
||||||
|
"-O2",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Ikernel",
|
||||||
|
"-o",
|
||||||
|
"obj/kernel/initrd.c.o",
|
||||||
|
"kernel/initrd.c"
|
||||||
|
],
|
||||||
|
"directory": "/home/slinky/source/RockOS",
|
||||||
|
"file": "/home/slinky/source/RockOS/kernel/initrd.c",
|
||||||
|
"output": "/home/slinky/source/RockOS/obj/kernel/initrd.c.o"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
@@ -26,12 +43,12 @@
|
|||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Ikernel",
|
"-Ikernel",
|
||||||
"-o",
|
"-o",
|
||||||
"obj/kernel/kmain.c.o",
|
"obj/kernel/gdt.c.o",
|
||||||
"kernel/kmain.c"
|
"kernel/gdt.c"
|
||||||
],
|
],
|
||||||
"directory": "/home/slinky/source/RockOS",
|
"directory": "/home/slinky/source/RockOS",
|
||||||
"file": "/home/slinky/source/RockOS/kernel/kmain.c",
|
"file": "/home/slinky/source/RockOS/kernel/gdt.c",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/kmain.c.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/gdt.c.o"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
@@ -50,40 +67,6 @@
|
|||||||
"file": "/home/slinky/source/RockOS/kernel/drivers/pic/pic.c",
|
"file": "/home/slinky/source/RockOS/kernel/drivers/pic/pic.c",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/drivers/pic/pic.c.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/drivers/pic/pic.c.o"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"arguments": [
|
|
||||||
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
|
||||||
"-c",
|
|
||||||
"-ffreestanding",
|
|
||||||
"-O2",
|
|
||||||
"-Wall",
|
|
||||||
"-Wextra",
|
|
||||||
"-Ikernel",
|
|
||||||
"-o",
|
|
||||||
"obj/kernel/drivers/vga/vga.c.o",
|
|
||||||
"kernel/drivers/vga/vga.c"
|
|
||||||
],
|
|
||||||
"directory": "/home/slinky/source/RockOS",
|
|
||||||
"file": "/home/slinky/source/RockOS/kernel/drivers/vga/vga.c",
|
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/drivers/vga/vga.c.o"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"arguments": [
|
|
||||||
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
|
||||||
"-c",
|
|
||||||
"-ffreestanding",
|
|
||||||
"-O2",
|
|
||||||
"-Wall",
|
|
||||||
"-Wextra",
|
|
||||||
"-Ikernel",
|
|
||||||
"-o",
|
|
||||||
"obj/kernel/drivers/ide/ide.c.o",
|
|
||||||
"kernel/drivers/ide/ide.c"
|
|
||||||
],
|
|
||||||
"directory": "/home/slinky/source/RockOS",
|
|
||||||
"file": "/home/slinky/source/RockOS/kernel/drivers/ide/ide.c",
|
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/drivers/ide/ide.c.o"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
@@ -128,12 +111,12 @@
|
|||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Ikernel",
|
"-Ikernel",
|
||||||
"-o",
|
"-o",
|
||||||
"obj/kernel/gdt.c.o",
|
"obj/kernel/drivers/ide/ide.c.o",
|
||||||
"kernel/gdt.c"
|
"kernel/drivers/ide/ide.c"
|
||||||
],
|
],
|
||||||
"directory": "/home/slinky/source/RockOS",
|
"directory": "/home/slinky/source/RockOS",
|
||||||
"file": "/home/slinky/source/RockOS/kernel/gdt.c",
|
"file": "/home/slinky/source/RockOS/kernel/drivers/ide/ide.c",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/gdt.c.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/drivers/ide/ide.c.o"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
@@ -145,12 +128,29 @@
|
|||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Ikernel",
|
"-Ikernel",
|
||||||
"-o",
|
"-o",
|
||||||
"obj/kernel/memory/mm.c.o",
|
"obj/kernel/drivers/vga/vga.c.o",
|
||||||
"kernel/memory/mm.c"
|
"kernel/drivers/vga/vga.c"
|
||||||
],
|
],
|
||||||
"directory": "/home/slinky/source/RockOS",
|
"directory": "/home/slinky/source/RockOS",
|
||||||
"file": "/home/slinky/source/RockOS/kernel/memory/mm.c",
|
"file": "/home/slinky/source/RockOS/kernel/drivers/vga/vga.c",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/memory/mm.c.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/drivers/vga/vga.c.o"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"arguments": [
|
||||||
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
|
"-c",
|
||||||
|
"-ffreestanding",
|
||||||
|
"-O2",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Ikernel",
|
||||||
|
"-o",
|
||||||
|
"obj/kernel/scheduler.c.o",
|
||||||
|
"kernel/scheduler.c"
|
||||||
|
],
|
||||||
|
"directory": "/home/slinky/source/RockOS",
|
||||||
|
"file": "/home/slinky/source/RockOS/kernel/scheduler.c",
|
||||||
|
"output": "/home/slinky/source/RockOS/obj/kernel/scheduler.c.o"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
@@ -196,46 +196,12 @@
|
|||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Ikernel",
|
"-Ikernel",
|
||||||
"-o",
|
"-o",
|
||||||
"obj/kernel/lib/stream.c.o",
|
"obj/kernel/kmain.c.o",
|
||||||
"kernel/lib/stream.c"
|
"kernel/kmain.c"
|
||||||
],
|
],
|
||||||
"directory": "/home/slinky/source/RockOS",
|
"directory": "/home/slinky/source/RockOS",
|
||||||
"file": "/home/slinky/source/RockOS/kernel/lib/stream.c",
|
"file": "/home/slinky/source/RockOS/kernel/kmain.c",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/lib/stream.c.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/kmain.c.o"
|
||||||
},
|
|
||||||
{
|
|
||||||
"arguments": [
|
|
||||||
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
|
||||||
"-c",
|
|
||||||
"-ffreestanding",
|
|
||||||
"-O2",
|
|
||||||
"-Wall",
|
|
||||||
"-Wextra",
|
|
||||||
"-Ikernel",
|
|
||||||
"-o",
|
|
||||||
"obj/kernel/lib/memory.c.o",
|
|
||||||
"kernel/lib/memory.c"
|
|
||||||
],
|
|
||||||
"directory": "/home/slinky/source/RockOS",
|
|
||||||
"file": "/home/slinky/source/RockOS/kernel/lib/memory.c",
|
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/lib/memory.c.o"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"arguments": [
|
|
||||||
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
|
||||||
"-c",
|
|
||||||
"-ffreestanding",
|
|
||||||
"-O2",
|
|
||||||
"-Wall",
|
|
||||||
"-Wextra",
|
|
||||||
"-Ikernel",
|
|
||||||
"-o",
|
|
||||||
"obj/kernel/lib/print.c.o",
|
|
||||||
"kernel/lib/print.c"
|
|
||||||
],
|
|
||||||
"directory": "/home/slinky/source/RockOS",
|
|
||||||
"file": "/home/slinky/source/RockOS/kernel/lib/print.c",
|
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/lib/print.c.o"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
@@ -264,12 +230,12 @@
|
|||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Ikernel",
|
"-Ikernel",
|
||||||
"-o",
|
"-o",
|
||||||
"obj/kernel/scheduler.c.o",
|
"obj/kernel/lib/stream.c.o",
|
||||||
"kernel/scheduler.c"
|
"kernel/lib/stream.c"
|
||||||
],
|
],
|
||||||
"directory": "/home/slinky/source/RockOS",
|
"directory": "/home/slinky/source/RockOS",
|
||||||
"file": "/home/slinky/source/RockOS/kernel/scheduler.c",
|
"file": "/home/slinky/source/RockOS/kernel/lib/stream.c",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/scheduler.c.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/lib/stream.c.o"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
@@ -281,12 +247,12 @@
|
|||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Ikernel",
|
"-Ikernel",
|
||||||
"-o",
|
"-o",
|
||||||
"obj/kernel/syscall.S.o",
|
"obj/kernel/lib/print.c.o",
|
||||||
"kernel/syscall.S"
|
"kernel/lib/print.c"
|
||||||
],
|
],
|
||||||
"directory": "/home/slinky/source/RockOS",
|
"directory": "/home/slinky/source/RockOS",
|
||||||
"file": "/home/slinky/source/RockOS/kernel/syscall.S",
|
"file": "/home/slinky/source/RockOS/kernel/lib/print.c",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/syscall.S.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/lib/print.c.o"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
@@ -298,12 +264,46 @@
|
|||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Ikernel",
|
"-Ikernel",
|
||||||
"-o",
|
"-o",
|
||||||
"obj/kernel/common.S.o",
|
"obj/kernel/lib/memory.c.o",
|
||||||
"kernel/common.S"
|
"kernel/lib/memory.c"
|
||||||
],
|
],
|
||||||
"directory": "/home/slinky/source/RockOS",
|
"directory": "/home/slinky/source/RockOS",
|
||||||
"file": "/home/slinky/source/RockOS/kernel/common.S",
|
"file": "/home/slinky/source/RockOS/kernel/lib/memory.c",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/common.S.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/lib/memory.c.o"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"arguments": [
|
||||||
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
|
"-c",
|
||||||
|
"-ffreestanding",
|
||||||
|
"-O2",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Ikernel",
|
||||||
|
"-o",
|
||||||
|
"obj/kernel/vfs.c.o",
|
||||||
|
"kernel/vfs.c"
|
||||||
|
],
|
||||||
|
"directory": "/home/slinky/source/RockOS",
|
||||||
|
"file": "/home/slinky/source/RockOS/kernel/vfs.c",
|
||||||
|
"output": "/home/slinky/source/RockOS/obj/kernel/vfs.c.o"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"arguments": [
|
||||||
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
|
"-c",
|
||||||
|
"-ffreestanding",
|
||||||
|
"-O2",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Ikernel",
|
||||||
|
"-o",
|
||||||
|
"obj/kernel/memory/mm.c.o",
|
||||||
|
"kernel/memory/mm.c"
|
||||||
|
],
|
||||||
|
"directory": "/home/slinky/source/RockOS",
|
||||||
|
"file": "/home/slinky/source/RockOS/kernel/memory/mm.c",
|
||||||
|
"output": "/home/slinky/source/RockOS/obj/kernel/memory/mm.c.o"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
@@ -322,23 +322,6 @@
|
|||||||
"file": "/home/slinky/source/RockOS/kernel/drivers/pic/pic.S",
|
"file": "/home/slinky/source/RockOS/kernel/drivers/pic/pic.S",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/drivers/pic/pic.S.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/drivers/pic/pic.S.o"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"arguments": [
|
|
||||||
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
|
||||||
"-c",
|
|
||||||
"-ffreestanding",
|
|
||||||
"-O2",
|
|
||||||
"-Wall",
|
|
||||||
"-Wextra",
|
|
||||||
"-Ikernel",
|
|
||||||
"-o",
|
|
||||||
"obj/kernel/drivers/pit/pit.S.o",
|
|
||||||
"kernel/drivers/pit/pit.S"
|
|
||||||
],
|
|
||||||
"directory": "/home/slinky/source/RockOS",
|
|
||||||
"file": "/home/slinky/source/RockOS/kernel/drivers/pit/pit.S",
|
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/drivers/pit/pit.S.o"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
@@ -366,12 +349,46 @@
|
|||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Ikernel",
|
"-Ikernel",
|
||||||
"-o",
|
"-o",
|
||||||
"obj/kernel/memory/mm_stubs.S.o",
|
"obj/kernel/drivers/pit/pit.S.o",
|
||||||
"kernel/memory/mm_stubs.S"
|
"kernel/drivers/pit/pit.S"
|
||||||
],
|
],
|
||||||
"directory": "/home/slinky/source/RockOS",
|
"directory": "/home/slinky/source/RockOS",
|
||||||
"file": "/home/slinky/source/RockOS/kernel/memory/mm_stubs.S",
|
"file": "/home/slinky/source/RockOS/kernel/drivers/pit/pit.S",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/memory/mm_stubs.S.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/drivers/pit/pit.S.o"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"arguments": [
|
||||||
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
|
"-c",
|
||||||
|
"-ffreestanding",
|
||||||
|
"-O2",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Ikernel",
|
||||||
|
"-o",
|
||||||
|
"obj/kernel/syscall.S.o",
|
||||||
|
"kernel/syscall.S"
|
||||||
|
],
|
||||||
|
"directory": "/home/slinky/source/RockOS",
|
||||||
|
"file": "/home/slinky/source/RockOS/kernel/syscall.S",
|
||||||
|
"output": "/home/slinky/source/RockOS/obj/kernel/syscall.S.o"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"arguments": [
|
||||||
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
|
"-c",
|
||||||
|
"-ffreestanding",
|
||||||
|
"-O2",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Ikernel",
|
||||||
|
"-o",
|
||||||
|
"obj/kernel/interrupts.S.o",
|
||||||
|
"kernel/interrupts.S"
|
||||||
|
],
|
||||||
|
"directory": "/home/slinky/source/RockOS",
|
||||||
|
"file": "/home/slinky/source/RockOS/kernel/interrupts.S",
|
||||||
|
"output": "/home/slinky/source/RockOS/obj/kernel/interrupts.S.o"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
@@ -390,6 +407,23 @@
|
|||||||
"file": "/home/slinky/source/RockOS/kernel/boot/boot.S",
|
"file": "/home/slinky/source/RockOS/kernel/boot/boot.S",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/boot/boot.S.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/boot/boot.S.o"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"arguments": [
|
||||||
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
|
"-c",
|
||||||
|
"-ffreestanding",
|
||||||
|
"-O2",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Ikernel",
|
||||||
|
"-o",
|
||||||
|
"obj/kernel/common.S.o",
|
||||||
|
"kernel/common.S"
|
||||||
|
],
|
||||||
|
"directory": "/home/slinky/source/RockOS",
|
||||||
|
"file": "/home/slinky/source/RockOS/kernel/common.S",
|
||||||
|
"output": "/home/slinky/source/RockOS/obj/kernel/common.S.o"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
@@ -417,12 +451,12 @@
|
|||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Ikernel",
|
"-Ikernel",
|
||||||
"-o",
|
"-o",
|
||||||
"obj/kernel/gdt.S.o",
|
"obj/kernel/memory/mm_stubs.S.o",
|
||||||
"kernel/gdt.S"
|
"kernel/memory/mm_stubs.S"
|
||||||
],
|
],
|
||||||
"directory": "/home/slinky/source/RockOS",
|
"directory": "/home/slinky/source/RockOS",
|
||||||
"file": "/home/slinky/source/RockOS/kernel/gdt.S",
|
"file": "/home/slinky/source/RockOS/kernel/memory/mm_stubs.S",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/gdt.S.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/memory/mm_stubs.S.o"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
@@ -434,11 +468,11 @@
|
|||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Ikernel",
|
"-Ikernel",
|
||||||
"-o",
|
"-o",
|
||||||
"obj/kernel/interrupts.S.o",
|
"obj/kernel/gdt.S.o",
|
||||||
"kernel/interrupts.S"
|
"kernel/gdt.S"
|
||||||
],
|
],
|
||||||
"directory": "/home/slinky/source/RockOS",
|
"directory": "/home/slinky/source/RockOS",
|
||||||
"file": "/home/slinky/source/RockOS/kernel/interrupts.S",
|
"file": "/home/slinky/source/RockOS/kernel/gdt.S",
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/interrupts.S.o"
|
"output": "/home/slinky/source/RockOS/obj/kernel/gdt.S.o"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
3
grub.cfg
3
grub.cfg
@@ -1,3 +1,4 @@
|
|||||||
menuentry "RockOS" {
|
menuentry "RockOS" {
|
||||||
multiboot /boot/rockos
|
multiboot /boot/rockos/
|
||||||
|
module /boot/initrd.img
|
||||||
}
|
}
|
||||||
34
kernel/initrd.c
Normal file
34
kernel/initrd.c
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include "initrd.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <lib/print.h>
|
||||||
|
#include <lib/memory.h>
|
||||||
|
|
||||||
|
void parse_cpio(void *initrd_start) {
|
||||||
|
cpio_header_t *head = (cpio_header_t *)initrd_start;
|
||||||
|
|
||||||
|
while (strncmp(head->c_magic, "070701", 6) == 0) {
|
||||||
|
// If we hit the trailer, we are done
|
||||||
|
char *filename = (char *)(head + 1);
|
||||||
|
if (strncmp(filename, "TRAILER!!!", 10) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t filesize = parse_hex(head->c_filesize);
|
||||||
|
uint32_t namesize = parse_hex(head->c_namesize);
|
||||||
|
|
||||||
|
kprintf("found file of size %d\n", filesize);
|
||||||
|
|
||||||
|
// Calculate where the data begins (accounting for 4-byte padding)
|
||||||
|
uint32_t header_plus_name = 110 + namesize;
|
||||||
|
header_plus_name = (header_plus_name + 3) & ~3; // Align to 4 bytes
|
||||||
|
|
||||||
|
char *file_data = (char *)head + header_plus_name;
|
||||||
|
|
||||||
|
uint32_t total_record_size = header_plus_name + filesize;
|
||||||
|
total_record_size = (total_record_size + 3) & ~3; // Align to 4 bytes
|
||||||
|
|
||||||
|
head = (cpio_header_t *)((char *)head + total_record_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
kernel/initrd.h
Normal file
36
kernel/initrd.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#ifndef KINITRD_H
|
||||||
|
#define KINITRD_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char c_magic[6];
|
||||||
|
char c_ino[8];
|
||||||
|
char c_mode[8];
|
||||||
|
char c_uid[8];
|
||||||
|
char c_gid[8];
|
||||||
|
char c_nlink[8];
|
||||||
|
char c_mtime[8];
|
||||||
|
char c_filesize[8];
|
||||||
|
char c_devmajor[8];
|
||||||
|
char c_devminor[8];
|
||||||
|
char c_rdevmajor[8];
|
||||||
|
char c_rdevminor[8];
|
||||||
|
char c_namesize[8];
|
||||||
|
char c_check[8];
|
||||||
|
} cpio_header_t;
|
||||||
|
|
||||||
|
static inline uint32_t parse_hex(const char *s) {
|
||||||
|
uint32_t val = 0;
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
val <<= 4;
|
||||||
|
if (s[i] >= '0' && s[i] <= '9') val += (s[i] - '0');
|
||||||
|
else if (s[i] >= 'A' && s[i] <= 'F') val += (s[i] - 'A' + 10);
|
||||||
|
else if (s[i] >= 'a' && s[i] <= 'f') val += (s[i] - 'a' + 10);
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_cpio(void *initrd_start);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "gdt.h"
|
#include "gdt.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "initrd.h"
|
||||||
|
|
||||||
#include <lib/print.h>
|
#include <lib/print.h>
|
||||||
#include <lib/stream.h>
|
#include <lib/stream.h>
|
||||||
@@ -23,15 +24,32 @@
|
|||||||
extern char __kernel_start;
|
extern char __kernel_start;
|
||||||
extern char __kernel_end;
|
extern char __kernel_end;
|
||||||
|
|
||||||
void first_task() {
|
void parse_multiboot_modules(uint32_t mbi_vaddr) {
|
||||||
kprintf("task started\n");
|
// find where grub put the boot module containing initrd
|
||||||
int i = 5;
|
multiboot_info* mbi = (multiboot_info*)mbi_vaddr;
|
||||||
while (i--) {
|
|
||||||
sleep(1000);
|
uint32_t mod_count = mbi->mods_count;
|
||||||
kprintf("task awake [%d]\n", i);
|
multiboot_module_t* mod = (multiboot_module_t*)((uint32_t)mbi->mods_addr + 0xC0000000);
|
||||||
|
|
||||||
|
kprintf("found %d mods starting @ [v]0x%x\n", mod_count, (uint32_t)mod);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < mod_count; i++) {
|
||||||
|
uint32_t start = mod[i].mod_start;
|
||||||
|
uint32_t end = mod[i].mod_end;
|
||||||
|
uint32_t cmdline = mod[i].cmdline;
|
||||||
|
|
||||||
|
multiboot_module_info_table[i].mod_start = start + 0xC0000000;
|
||||||
|
multiboot_module_info_table[i].mod_end = end + 0xC0000000;
|
||||||
|
multiboot_module_info_table[i].cmdline = cmdline + 0xC0000000;
|
||||||
}
|
}
|
||||||
kprintf("exiting\n");
|
}
|
||||||
exit();
|
|
||||||
|
void load_initrd() {
|
||||||
|
multiboot_module_t* initrd_module = &multiboot_module_info_table[0];
|
||||||
|
kprintf("initrd found @ [v] 0x%x\n", initrd_module->mod_start);
|
||||||
|
kprintf("reading initrd\n");
|
||||||
|
|
||||||
|
parse_cpio((void*)initrd_module->mod_start);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kmain(uint32_t magic, multiboot_info* mbi) {
|
void kmain(uint32_t magic, multiboot_info* mbi) {
|
||||||
@@ -53,16 +71,13 @@ void kmain(uint32_t magic, multiboot_info* mbi) {
|
|||||||
|
|
||||||
init_page_tables();
|
init_page_tables();
|
||||||
|
|
||||||
|
parse_multiboot_modules((uint32_t)mbi);
|
||||||
|
|
||||||
|
load_initrd();
|
||||||
|
|
||||||
kprintf("basic initializations complete\n");
|
kprintf("basic initializations complete\n");
|
||||||
|
|
||||||
disable_interrupts(); // just paranoid... do it again
|
disable_interrupts(); // just paranoid... do it again
|
||||||
init_scheduler();
|
init_scheduler();
|
||||||
enable_interrupts();
|
enable_interrupts();
|
||||||
|
|
||||||
create_task((uint32_t)first_task, fetch_cr3());
|
|
||||||
|
|
||||||
while(1) {
|
|
||||||
sleep(5000);
|
|
||||||
kprintf("kernel awake\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,26 @@ int strlen(const char* str) {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int strncmp(const char *s1, const char *s2, size_t n) {
|
||||||
|
// If n is 0, we don't compare anything and strings are "equal"
|
||||||
|
while (n > 0) {
|
||||||
|
// If characters don't match, or we hit the null-terminator of s1
|
||||||
|
if (*s1 != *s2) {
|
||||||
|
return *(unsigned char *)s1 - *(unsigned char *)s2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we reached the end of the strings simultaneously
|
||||||
|
if (*s1 == '\0') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
s1++;
|
||||||
|
s2++;
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void* kernel_heap_start = (void*)KHEAP_START;
|
static void* kernel_heap_start = (void*)KHEAP_START;
|
||||||
static void* kernel_heap_end = (void*)KHEAP_START;
|
static void* kernel_heap_end = (void*)KHEAP_START;
|
||||||
alloc_header_t* blk_list = NULL;
|
alloc_header_t* blk_list = NULL;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ void memcpy(const void* src, void* dst, size_t sz);
|
|||||||
void memset(const uint8_t* dst, uint8_t val, size_t sz);
|
void memset(const uint8_t* dst, uint8_t val, size_t sz);
|
||||||
|
|
||||||
int strcmp(const char *s1, const char *s2);
|
int strcmp(const char *s1, const char *s2);
|
||||||
|
int strncmp(const char *s1, const char *s2, size_t n);
|
||||||
int strlen(const char* str);
|
int strlen(const char* str);
|
||||||
|
|
||||||
void kgrow(size_t pages);
|
void kgrow(size_t pages);
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ void* p_alloc_frame() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void p_free_frame(void* addr) {
|
void p_free_frame(void* addr) {
|
||||||
mark_free((uint32_t)addr);
|
mark_free((uint32_t)addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
kernel/multiboot.c
Normal file
3
kernel/multiboot.c
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#include "multiboot.h"
|
||||||
|
|
||||||
|
multiboot_module_t multiboot_module_info_table[32];
|
||||||
@@ -31,6 +31,8 @@ typedef struct {
|
|||||||
uint32_t mod_end; // Physical end address of user.elf
|
uint32_t mod_end; // Physical end address of user.elf
|
||||||
uint32_t cmdline; // Pointer to a string (e.g., "/boot/user.elf")
|
uint32_t cmdline; // Pointer to a string (e.g., "/boot/user.elf")
|
||||||
uint32_t pad;
|
uint32_t pad;
|
||||||
} __attribute__((packed)) multiboot_module_entry;
|
} __attribute__((packed)) multiboot_module_t;
|
||||||
|
|
||||||
|
extern multiboot_module_t multiboot_module_info_table[32];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -17,6 +17,7 @@ typedef struct {
|
|||||||
process_state_t state;
|
process_state_t state;
|
||||||
uint32_t sleep;
|
uint32_t sleep;
|
||||||
void* next;
|
void* next;
|
||||||
|
uint32_t heap_end;
|
||||||
} __attribute__((packed)) process_t;
|
} __attribute__((packed)) process_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -137,6 +137,13 @@ int create_task(uint32_t entry_point, uint32_t cr3) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process_t* current_task() {
|
||||||
|
lock_scheduler();
|
||||||
|
process_t* rtn = &process_table[current_process];
|
||||||
|
unlock_scheduler();
|
||||||
|
return rtn;
|
||||||
|
}
|
||||||
|
|
||||||
void sleep(uint32_t ms) {
|
void sleep(uint32_t ms) {
|
||||||
if (ms == 0) return;
|
if (ms == 0) return;
|
||||||
lock_scheduler();
|
lock_scheduler();
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
#ifndef KSCHEDULER_H
|
#ifndef KSCHEDULER_H
|
||||||
#define KSCHEDULER_H
|
#define KSCHEDULER_H
|
||||||
|
|
||||||
|
#include "process.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void init_scheduler();
|
void init_scheduler();
|
||||||
|
|
||||||
int create_task(uint32_t entry_point, uint32_t cr3);
|
int create_task(uint32_t entry_point, uint32_t cr3);
|
||||||
|
process_t* current_task();
|
||||||
|
|
||||||
void sleep(uint32_t ms);
|
void sleep(uint32_t ms);
|
||||||
void yield();
|
void yield();
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "memory/mm.h"
|
||||||
|
#include "process.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
|
||||||
|
#include <drivers/vga/vga.h>
|
||||||
|
|
||||||
typedef struct registers {
|
typedef struct registers {
|
||||||
uint32_t gs, fs, es, ds; // Pushed manually
|
uint32_t gs, fs, es, ds; // Pushed manually
|
||||||
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha
|
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha
|
||||||
@@ -9,35 +14,81 @@ typedef struct registers {
|
|||||||
uint32_t eip, cs, eflags, useresp, ss; // Pushed automatically by CPU
|
uint32_t eip, cs, eflags, useresp, ss; // Pushed automatically by CPU
|
||||||
} registers_t;
|
} registers_t;
|
||||||
|
|
||||||
int32_t sys_exit();
|
|
||||||
int32_t sys_read();
|
|
||||||
int32_t sys_write();
|
|
||||||
int32_t sys_open();
|
|
||||||
int32_t sys_close();
|
|
||||||
int32_t sys_brk();
|
|
||||||
|
|
||||||
int32_t syscall(registers_t* regs) {
|
static int32_t sys_exit(int status) {
|
||||||
switch(regs->eax) {
|
|
||||||
case 1: return sys_exit();
|
|
||||||
case 3: return sys_read();
|
|
||||||
case 4: return sys_write();
|
|
||||||
case 5: return sys_open();
|
|
||||||
case 6: return sys_close();
|
|
||||||
case 12: return sys_brk();
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t sys_exit() {
|
|
||||||
exit();
|
exit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sys_read() {
|
static int32_t sys_write(int fd, const void* buf, size_t count) {
|
||||||
return 0;
|
if (fd == 1 || fd == 2) { // stdout or stderr
|
||||||
|
const char* cbuf = (const char*)buf;
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
vga_putchar(cbuf[i]);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sys_write() {
|
static int32_t sys_read(int fd, void* buf, size_t count) {
|
||||||
return 0;
|
if (fd == 0) { // stdin
|
||||||
|
char* cbuf = (char*)buf;
|
||||||
|
size_t bytes_read = 0;
|
||||||
|
while (bytes_read < count) {
|
||||||
|
char c = 'r';
|
||||||
|
cbuf[bytes_read++] = c;
|
||||||
|
if (c == '\n') break;
|
||||||
|
}
|
||||||
|
return bytes_read;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t sys_open(const char* filename, int flags) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t sys_close(int fd) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t sys_brk(uint32_t new_break) {
|
||||||
|
process_t* current = current_task();
|
||||||
|
|
||||||
|
if (new_break == 0) {
|
||||||
|
return current->heap_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new_break < current->heap_end) {
|
||||||
|
current->heap_end = new_break;
|
||||||
|
return current->heap_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t page_start = (current->heap_end + 4095) & ~4095;
|
||||||
|
uint32_t page_end = (new_break + 4095) & ~4095;
|
||||||
|
|
||||||
|
for (uint32_t addr = page_start; addr < page_end; addr += 4096) {
|
||||||
|
// 1. Allocate a physical frame using your PMM (Physical Memory Manager)
|
||||||
|
void* phys = p_alloc_frame();
|
||||||
|
|
||||||
|
// 2. Map it into the current page directory using your VMM (Virtual Memory Manager)
|
||||||
|
map_page(addr, (uint32_t)phys, PAGE_PRESENT | PAGE_WRITABLE | PAGE_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
current->heap_end = new_break;
|
||||||
|
return current->heap_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t syscall(registers_t* regs) {
|
||||||
|
switch(regs->eax) {
|
||||||
|
case 1: return sys_exit(regs->ebx);
|
||||||
|
case 3: return sys_read(regs->ebx, (void*)regs->ecx, regs->edx);
|
||||||
|
case 4: return sys_write(regs->ebx, (const void*)regs->ecx, regs->edx);
|
||||||
|
case 5: return sys_open((const char*)regs->ebx, regs->ecx);
|
||||||
|
case 6: return sys_close(regs->ebx);
|
||||||
|
case 12: return sys_brk(regs->ebx);
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
12
kernel/vfs.c
Normal file
12
kernel/vfs.c
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "vfs.h"
|
||||||
|
#include "lib/memory.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
vfs_node_t* root = NULL;
|
||||||
|
|
||||||
|
void vfs_create_root() {
|
||||||
|
root = kalloc(sizeof(vfs_node_t));
|
||||||
|
memset((uint8_t*)root->name, 0, 128);
|
||||||
|
memcpy("root", root->name, 4);
|
||||||
|
root->flags |= VFS_DIRECTORY;
|
||||||
|
}
|
||||||
30
kernel/vfs.h
Normal file
30
kernel/vfs.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef KVFS_H
|
||||||
|
#define KVFS_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define VFS_FILE 0x01
|
||||||
|
#define VFS_DIRECTORY 0x02
|
||||||
|
|
||||||
|
struct vfs_node;
|
||||||
|
|
||||||
|
typedef uint32_t (*read_type_t)(struct vfs_node* node, uint32_t offset, uint32_t size, uint8_t* buffer);
|
||||||
|
typedef uint32_t (*write_type_t)(struct vfs_node* node, uint32_t offset, uint32_t size, uint8_t* buffer);
|
||||||
|
typedef struct vfs_node* (*finddir_type_t)(struct vfs_node* node, const char* name);
|
||||||
|
|
||||||
|
typedef struct vfs_node {
|
||||||
|
char name[128];
|
||||||
|
uint32_t flags; // File, directory, device, etc.
|
||||||
|
uint32_t size; // Size of file in bytes
|
||||||
|
uint32_t inode; // Unique identifier managed by the specific filesystem
|
||||||
|
|
||||||
|
read_type_t read;
|
||||||
|
write_type_t write;
|
||||||
|
finddir_type_t finddir;
|
||||||
|
|
||||||
|
struct vfs_node* mount;
|
||||||
|
} vfs_node_t;
|
||||||
|
|
||||||
|
void vfs_create_root();
|
||||||
|
|
||||||
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -14,18 +14,29 @@ static inline int32_t inline_syscall(uint32_t num, uint32_t arg1, uint32_t arg2,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _PDCLIB_exit(int status) {
|
void _exit(int status) {
|
||||||
inline_syscall(1, (uint32_t)status, 0, 0);
|
inline_syscall(1, (uint32_t)status, 0, 0);
|
||||||
while(1); // Halt if exit fails to yield
|
while(1) { asm volatile("hlt"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
void _PDCLIB_exit(int status) {
|
||||||
|
_exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _PDCLIB_read(_PDCLIB_fd_t fd, void *buf, size_t count) {
|
int _PDCLIB_read(_PDCLIB_fd_t fd, void *buf, size_t count) {
|
||||||
return inline_syscall(3, (uint32_t)fd, (uint32_t)buf, (uint32_t)count);
|
int32_t ret = inline_syscall(3, (uint32_t)fd, (uint32_t)buf, (uint32_t)count);
|
||||||
|
if (ret < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. sys_write (eax = 4)
|
|
||||||
int _PDCLIB_write(_PDCLIB_fd_t fd, const void *buf, size_t count) {
|
int _PDCLIB_write(_PDCLIB_fd_t fd, const void *buf, size_t count) {
|
||||||
return inline_syscall(4, (uint32_t)fd, (uint32_t)buf, (uint32_t)count);
|
int32_t ret = inline_syscall(4, (uint32_t)fd, (uint32_t)buf, (uint32_t)count);
|
||||||
|
if (ret < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
_PDCLIB_fd_t _PDCLIB_open(const char *filename, unsigned int mode) {
|
_PDCLIB_fd_t _PDCLIB_open(const char *filename, unsigned int mode) {
|
||||||
@@ -38,21 +49,24 @@ int _PDCLIB_close(_PDCLIB_fd_t fd) {
|
|||||||
return inline_syscall(6, (uint32_t)fd, 0, 0);
|
return inline_syscall(6, (uint32_t)fd, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * _PDCLIB_allocpages(size_t n) {
|
void * _PDCLIB_allocpages( size_t n ) {
|
||||||
// n is the number of PAGES PDCLib wants (usually 4096 bytes per page)
|
// 1. Get the current page break
|
||||||
size_t bytes_requested = n * 4096;
|
|
||||||
|
|
||||||
// Call your sys_brk with 0 to find the current break address
|
|
||||||
uint32_t current_break = inline_syscall(12, 0, 0, 0);
|
uint32_t current_break = inline_syscall(12, 0, 0, 0);
|
||||||
|
if (current_break == (uint32_t)-1) {
|
||||||
// Request the new break point
|
return NULL;
|
||||||
uint32_t new_break = current_break + bytes_requested;
|
|
||||||
uint32_t result = inline_syscall(12, new_break, 0, 0);
|
|
||||||
|
|
||||||
if (result == 0) {
|
|
||||||
return (void *)current_break; // Return the start of the newly allocated region
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. PDCLib requests memory in multiples of PAGES (typically 4096 bytes)
|
||||||
|
uint32_t new_break = current_break + (n * 4096);
|
||||||
|
|
||||||
|
// 3. Request kernel to move the break
|
||||||
|
uint32_t result = inline_syscall(12, new_break, 0, 0);
|
||||||
|
if (result != new_break) {
|
||||||
return NULL; // Allocation failed
|
return NULL; // Allocation failed
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the start of the newly allocated region
|
||||||
|
return (void *)current_break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _PDCLIB_remove(const char *filename) { return -1; }
|
int _PDCLIB_remove(const char *filename) { return -1; }
|
||||||
@@ -60,7 +74,6 @@ int _PDCLIB_rename(const char *old, const char *new) { return -1; }
|
|||||||
long _PDCLIB_lseek(_PDCLIB_fd_t fd, long offset, int whence) { return -1; }
|
long _PDCLIB_lseek(_PDCLIB_fd_t fd, long offset, int whence) { return -1; }
|
||||||
|
|
||||||
int open(const char *pathname, int flags, ...) {
|
int open(const char *pathname, int flags, ...) {
|
||||||
// Wrap to your internal _PDCLIB_open or inline_syscall directly
|
|
||||||
_PDCLIB_fd_t fd = _PDCLIB_open(pathname, (unsigned int)flags);
|
_PDCLIB_fd_t fd = _PDCLIB_open(pathname, (unsigned int)flags);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
@@ -79,19 +92,23 @@ int close(int fd) {
|
|||||||
return _PDCLIB_close(file_desc);
|
return _PDCLIB_close(file_desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _exit(int status) {
|
|
||||||
_PDCLIB_exit(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
void * sbrk(intptr_t increment) {
|
void * sbrk(intptr_t increment) {
|
||||||
// If increment is 0, dlmalloc is querying the current boundary.
|
uint32_t current_break = inline_syscall(12, 0, 0, 0);
|
||||||
// For a simple implementation, let's look up memory by pages.
|
if (current_break == (uint32_t)-1) {
|
||||||
if (increment == 0) {
|
return (void *)-1;
|
||||||
return _PDCLIB_allocpages(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert bytes requested by sbrk into page increments (4KB blocks)
|
if (increment == 0) {
|
||||||
// You can also change your syscall wrapper to use regular byte increments
|
return (void *)current_break;
|
||||||
size_t pages_needed = ((size_t)increment + 4095) / 4096;
|
}
|
||||||
return _PDCLIB_allocpages(pages_needed);
|
|
||||||
|
uint32_t new_break = (uint32_t)((intptr_t)current_break + increment);
|
||||||
|
|
||||||
|
uint32_t result = inline_syscall(12, new_break, 0, 0);
|
||||||
|
|
||||||
|
if (result == new_break) {
|
||||||
|
return (void *)current_break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (void *)-1;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user