Skip to content

Commit

Permalink
kernel Update libfdt, update from template
Browse files Browse the repository at this point in the history
  • Loading branch information
suhas-pai committed Oct 12, 2024
1 parent 3a1d711 commit 0362ca5
Show file tree
Hide file tree
Showing 14 changed files with 618 additions and 303 deletions.
26 changes: 8 additions & 18 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ VIRTIO_HDD_QEMU_ARG=""

QEMU_CDROM_ARGS=\
-drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-$(KARCH).fd,readonly=on \
-drive if=pflash,unit=1,format=raw,file=ovmf/ovmf-vars-$(KARCH).fd

QEMU_HDD_ARGS=\
-drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-$(KARCH).fd,readonly=on \
-drive if=pflash,unit=1,format=raw,file=ovmf/ovmf-vars-$(KARCH).fd

ifeq ($(DRIVE_KIND),block)
ifeq ($(KARCH),riscv64)
Expand Down Expand Up @@ -138,23 +136,23 @@ run: run-$(KARCH)
run-hdd: run-hdd-$(KARCH)

.PHONY: run-x86_64
run-x86_64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_NAME).iso
run-x86_64: ovmf/ovmf-code-$(KARCH).fd $(IMAGE_NAME).iso
qemu-system-$(KARCH) \
-cpu max \
$(QEMUFLAGS) \
$(QEMU_CDROM_ARGS) \
$(EXTRA_QEMU_ARGS)

.PHONY: run-hdd-x86_64
run-hdd-x86_64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_NAME).hdd
run-hdd-x86_64: ovmf/ovmf-code-$(KARCH).fd $(IMAGE_NAME).hdd
qemu-system-$(KARCH) \
-cpu max \
$(QEMUFLAGS) \
$(QEMU_HDD_ARGS) \
$(EXTRA_QEMU_ARGS)

.PHONY: run-aarch64
run-aarch64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_NAME).iso
run-aarch64: ovmf/ovmf-code-$(KARCH).fd $(IMAGE_NAME).iso
qemu-system-$(KARCH) \
-cpu max \
-device ramfb \
Expand All @@ -166,7 +164,7 @@ run-aarch64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_NAME)
$(EXTRA_QEMU_ARGS)

.PHONY: run-hdd-aarch64
run-hdd-aarch64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_NAME).hdd
run-hdd-aarch64: ovmf/ovmf-code-$(KARCH).fd $(IMAGE_NAME).hdd
qemu-system-$(KARCH) \
-cpu max \
-device ramfb \
Expand All @@ -178,7 +176,7 @@ run-hdd-aarch64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_N
$(EXTRA_QEMU_ARGS)

.PHONY: run-riscv64
run-riscv64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_NAME).iso
run-riscv64: ovmf/ovmf-code-$(KARCH).fd $(IMAGE_NAME).iso
qemu-system-$(KARCH) \
-cpu max \
-device ramfb \
Expand All @@ -190,7 +188,7 @@ run-riscv64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_NAME)
$(EXTRA_QEMU_ARGS)

.PHONY: run-hdd-riscv64
run-hdd-riscv64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_NAME).hdd
run-hdd-riscv64: ovmf/ovmf-code-$(KARCH).fd $(IMAGE_NAME).hdd
qemu-system-$(KARCH) \
-cpu max \
-device ramfb \
Expand All @@ -202,7 +200,7 @@ run-hdd-riscv64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_N
$(EXTRA_QEMU_ARGS)

.PHONY: run-loongarch64
run-loongarch64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_NAME).iso
run-loongarch64: ovmf/ovmf-code-$(KARCH).fd $(IMAGE_NAME).iso
qemu-system-$(KARCH) \
-device ramfb \
-device qemu-xhci \
Expand All @@ -213,7 +211,7 @@ run-loongarch64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_N
$(EXTRA_QEMU_ARGS)

.PHONY: run-hdd-loongarch64
run-hdd-loongarch64: ovmf/ovmf-code-$(KARCH).fd ovmf/ovmf-vars-$(KARCH).fd $(IMAGE_NAME).hdd
run-hdd-loongarch64: ovmf/ovmf-code-$(KARCH).fd $(IMAGE_NAME).hdd
qemu-system-$(KARCH) \
-device ramfb \
-device qemu-xhci \
Expand Down Expand Up @@ -248,14 +246,6 @@ ovmf/ovmf-code-$(KARCH).fd:
riscv64) dd if=/dev/zero of=$@ bs=1 count=0 seek=33554432 2>/dev/null;; \
esac

ovmf/ovmf-vars-$(KARCH).fd:
mkdir -p ovmf
curl -Lo $@ https://github.com/osdev0/edk2-ovmf-nightly/releases/latest/download/ovmf-vars-$(KARCH).fd
case "$(KARCH)" in \
aarch64) dd if=/dev/zero of=$@ bs=1 count=0 seek=67108864 2>/dev/null;; \
riscv64) dd if=/dev/zero of=$@ bs=1 count=0 seek=33554432 2>/dev/null;; \
esac

limine/limine:
rm -rf limine
git clone https://github.com/limine-bootloader/limine.git --branch=v8.x-binary --depth=1
Expand Down
34 changes: 16 additions & 18 deletions kernel/get-deps
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,22 @@ download_by_hash() {
fi
}

if ! test -f version; then
clone_repo_commit \
https://github.com/osdev0/freestnd-c-hdrs-0bsd.git \
freestnd-c-hdrs-0bsd \
0353851fdebe0eb6a4d2c608c5393040d310bf35
clone_repo_commit \
https://github.com/osdev0/freestnd-c-hdrs-0bsd.git \
freestnd-c-hdrs-0bsd \
0353851fdebe0eb6a4d2c608c5393040d310bf35

download_by_hash \
https://github.com/osdev0/cc-runtime/raw/dcdf5d82973e77edee597a047a3ef66300903de9/cc-runtime.c \
src/cc-runtime.c \
199907f5303ab15a963377fabcc1f2ee736e4ed18d54c59aab08345aa5485e8a
download_by_hash \
https://github.com/osdev0/cc-runtime/raw/dcdf5d82973e77edee597a047a3ef66300903de9/cc-runtime.c \
src/cc-runtime.c \
199907f5303ab15a963377fabcc1f2ee736e4ed18d54c59aab08345aa5485e8a

download_by_hash \
https://github.com/limine-bootloader/limine/raw/97c31196a9aec28b36ed9ff64d6df77a061c3d9b/limine.h \
src/limine.h \
3a018a8326adb5e6cff14a8595c775fd88235eb3e5fde4a135132b6398d165d5
download_by_hash \
https://github.com/limine-bootloader/limine/raw/97c31196a9aec28b36ed9ff64d6df77a061c3d9b/limine.h \
src/limine.h \
3a018a8326adb5e6cff14a8595c775fd88235eb3e5fde4a135132b6398d165d5

download_by_hash \
https://gist.githubusercontent.com/suhas-pai/2a6c1c4d32491aaf363ee3b1b3884390/raw/541482dbc61862bba8a156edaae57faa2995d791/stdatomic.h \
freestnd-c-hdrs-0bsd/stdatomic.h \
5e5d78080b2126535ee724a03082fea398dd5afb98548d95177c738a1fc17abe
fi
download_by_hash \
https://gist.githubusercontent.com/suhas-pai/2a6c1c4d32491aaf363ee3b1b3884390/raw/541482dbc61862bba8a156edaae57faa2995d791/stdatomic.h \
freestnd-c-hdrs-0bsd/stdatomic.h \
5e5d78080b2126535ee724a03082fea398dd5afb98548d95177c738a1fc17abe
6 changes: 3 additions & 3 deletions kernel/src/fdt/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
if (!can_assume(VALID_DTB) && !tagp)
return FDT_END; /* premature end */
tag = fdt32_to_cpu(*tagp);
offset += (int)FDT_TAGSIZE;
offset += FDT_TAGSIZE;

*nextoffset = -FDT_ERR_BADSTRUCTURE;
switch (tag) {
Expand All @@ -197,7 +197,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
return FDT_END; /* premature end */

/* skip-name offset, length and value */
offset += (int)(sizeof(struct fdt_property) - FDT_TAGSIZE + len);
offset += sizeof(struct fdt_property) - FDT_TAGSIZE + len;

if (!can_assume(LATEST) &&
fdt_version(fdt) < 0x10 && len >= 8 &&
Expand All @@ -217,7 +217,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
if (!fdt_offset_ptr(fdt, startoffset, (unsigned)(offset - startoffset)))
return FDT_END; /* premature end */

*nextoffset = FDT_TAGALIGN((unsigned long)offset);
*nextoffset = (int)FDT_TAGALIGN((unsigned long)offset);
return tag;
}

Expand Down
70 changes: 35 additions & 35 deletions kernel/src/fdt/fdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,57 @@
#ifndef __ASSEMBLY__

struct fdt_header {
fdt32_t magic; /* magic word FDT_MAGIC */
fdt32_t totalsize; /* total size of DT block */
fdt32_t off_dt_struct; /* offset to structure */
fdt32_t off_dt_strings; /* offset to strings */
fdt32_t off_mem_rsvmap; /* offset to memory reserve map */
fdt32_t version; /* format version */
fdt32_t last_comp_version; /* last compatible version */
fdt32_t magic; /* magic word FDT_MAGIC */
fdt32_t totalsize; /* total size of DT block */
fdt32_t off_dt_struct; /* offset to structure */
fdt32_t off_dt_strings; /* offset to strings */
fdt32_t off_mem_rsvmap; /* offset to memory reserve map */
fdt32_t version; /* format version */
fdt32_t last_comp_version; /* last compatible version */

/* version 2 fields below */
fdt32_t boot_cpuid_phys; /* Which physical CPU id we're
booting on */
/* version 3 fields below */
fdt32_t size_dt_strings; /* size of the strings block */
/* version 2 fields below */
fdt32_t boot_cpuid_phys; /* Which physical CPU id we're
booting on */
/* version 3 fields below */
fdt32_t size_dt_strings; /* size of the strings block */

/* version 17 fields below */
fdt32_t size_dt_struct; /* size of the structure block */
/* version 17 fields below */
fdt32_t size_dt_struct; /* size of the structure block */
};

struct fdt_reserve_entry {
fdt64_t address;
fdt64_t size;
fdt64_t address;
fdt64_t size;
};

struct fdt_node_header {
fdt32_t tag;
char name[];
fdt32_t tag;
char name[];
};

struct fdt_property {
fdt32_t tag;
fdt32_t len;
fdt32_t nameoff;
char data[];
fdt32_t tag;
fdt32_t len;
fdt32_t nameoff;
char data[];
};

#endif /* !__ASSEMBLY */

#define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */
#define FDT_TAGSIZE sizeof(fdt32_t)
#define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */
#define FDT_TAGSIZE sizeof(fdt32_t)

#define FDT_BEGIN_NODE 0x1 /* Start node: full name */
#define FDT_END_NODE 0x2 /* End node */
#define FDT_PROP 0x3 /* Property: name off,
size, content */
#define FDT_NOP 0x4 /* nop */
#define FDT_END 0x9
#define FDT_BEGIN_NODE 0x1 /* Start node: full name */
#define FDT_END_NODE 0x2 /* End node */
#define FDT_PROP 0x3 /* Property: name off,
size, content */
#define FDT_NOP 0x4 /* nop */
#define FDT_END 0x9

#define FDT_V1_SIZE (7*sizeof(fdt32_t))
#define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t))
#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t))
#define FDT_V16_SIZE FDT_V3_SIZE
#define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t))
#define FDT_V1_SIZE (7*sizeof(fdt32_t))
#define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t))
#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t))
#define FDT_V16_SIZE FDT_V3_SIZE
#define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t))

#endif /* FDT_H */
Loading

0 comments on commit 0362ca5

Please sign in to comment.