Move kernel sources to platform specific subdirs
diff --git a/.build.yml b/.build.yml
index 2ab7807..00d4b3f 100644
--- a/.build.yml
+++ b/.build.yml
@@ -14,6 +14,7 @@
- lmodern
- texlive-xetex
- global
+ - tcl
tasks:
- build-latex: |
cd bluejay
@@ -23,6 +24,7 @@
- build-kernel: |
cd bluejay
./bin/jmk
+ ./bin/jmk2
cd src/kernel
make
- build-lisp: |
diff --git a/bin/jmk2 b/bin/jmk2
index a441ef9..c22e9cf 100755
--- a/bin/jmk2
+++ b/bin/jmk2
@@ -18,7 +18,7 @@
esac
done
-echo "$options"
+echo "Options: {$options }"
for file in $(find -name Jmk2); do
echo "$file" > /dev/stderr
@@ -30,5 +30,6 @@
set jmk_build_dir {$(pwd)}
cd {$outdir}
array set options {$options}
+source {$root/share/jmk/multiplat.jmk}
EOF
done
diff --git a/etc/platforms/platforms.jmk b/etc/platforms/platforms.jmk
new file mode 100644
index 0000000..f4bac15
--- /dev/null
+++ b/etc/platforms/platforms.jmk
@@ -0,0 +1,7 @@
+# -*- tcl -*-
+
+isa x86_32
+device pc-generic x86_32
+
+isa riscv32
+device esp32c3 riscv32
diff --git a/etc/platforms/x86_32/x86_32.jmk b/etc/platforms/x86_32/x86_32.jmk
new file mode 100644
index 0000000..e7cfbbb
--- /dev/null
+++ b/etc/platforms/x86_32/x86_32.jmk
@@ -0,0 +1,3 @@
+# -*- tcl -*-
+
+# nothing
\ No newline at end of file
diff --git a/share/jmk/jmk.tcl b/share/jmk/jmk.tcl
index b3b860c..64b9afd 100644
--- a/share/jmk/jmk.tcl
+++ b/share/jmk/jmk.tcl
@@ -7,6 +7,8 @@
variable jmk_lib_paths
variable jmk_lib_targets
+variable jmk_sourced
+
variable cflags {}
variable asmflags {}
variable ldflags {}
@@ -98,6 +100,15 @@
puts "\t@printf ' \\e\[1;34m%8s\\e\[m %s\\n' '$category' '$message' > /dev/stderr"
}
+proc jmk_log {message} {
+ puts stderr $message
+}
+
+proc jmk_error {message} {
+ puts stderr "\e[31mError\e[0m $message"
+ exit 1
+}
+
proc cc {command} {
puts "\t@$::cc $command $::cflags"
}
@@ -132,9 +143,9 @@
proc srcs {args} {
puts ""
- variable objs ""
foreach src $args {
+ set src [file join [pwd] $src]
variable obj [regsub -- {(.+)\.\w+} $src {\1.o}]
set ::objs "$::objs $obj"
}
@@ -233,3 +244,21 @@
set asm nasm
}
}
+
+proc jmk_source {path} {
+ variable dir [pwd]
+
+ if {![file exists $path]} {
+ jmk_error "jmk_source: $dir/$path doesn't exist"
+ }
+
+ lappend ::jmk_sourced "$dir/$path"
+
+ cd [file dirname $path]
+ uplevel 1 source [file tail $path]
+ cd $dir
+}
+
+proc jmk_finalize {} {
+ puts "Jmk2: $::jmk_sourced"
+}
diff --git a/share/jmk/multiplat.jmk b/share/jmk/multiplat.jmk
new file mode 100644
index 0000000..0638d8d
--- /dev/null
+++ b/share/jmk/multiplat.jmk
@@ -0,0 +1,53 @@
+# -*- tcl -*-
+
+variable isas
+variable devices
+
+variable isa_features
+
+proc isa {name} {
+ lappend ::isas $name
+}
+
+proc device {name isa} {
+ lappend ::devices($isa) $name
+}
+
+proc target_feature {feature} {
+ lappend ::isa_features $feature
+}
+
+proc target_features {args} {
+ lappend ::isa_features {*}$args
+}
+
+proc feature_supported {feature} {
+ return [expr {[lsearch -exact $::isa_features $feature] != -1}]
+}
+
+option ISA x86_32
+option DEVICE pc-generic
+
+proc source_if_exists {path} {
+ if {[file exists $path]} {
+ uplevel 1 jmk_source $path
+ }
+}
+
+proc enable_multiplat {} {
+ uplevel 1 source_if_exists "$::root/etc/platforms/platforms.jmk"
+
+ if {[lsearch -exact $::isas $::options(ISA)] == -1} {
+ jmk_error "Specified ISA $::options(ISA) is invalid, choose one of $::isas"
+ }
+
+ if {[lsearch -exact $::devices($::options(ISA)) $::options(DEVICE)] == -1} {
+ jmk_error "Specified DEVICE $::options(DEVICE) is invalid, choose one of $::devices($::options(ISA))"
+ }
+
+ uplevel 1 source_if_exists "$::root/etc/platforms/$::options(ISA)/$::options(DEVICE).jmk"
+ uplevel 1 source_if_exists "$::root/etc/platforms/$::options(ISA)/$::options(ISA).jmk"
+
+ uplevel 1 source_if_exists "$::options(ISA)/$::options(DEVICE).jmk"
+ uplevel 1 source_if_exists "$::options(ISA)/$::options(ISA).jmk"
+}
diff --git a/src/kernel/Jmk b/src/kernel/Jmk
deleted file mode 100644
index 25898cc..0000000
--- a/src/kernel/Jmk
+++ /dev/null
@@ -1,117 +0,0 @@
-# -*- mode:makefile -*-
-
-init(kernel, kernel.elf)
-
-preset(freestanding)
-# This makes debugging hard :(
-# preset(optimize)
-preset(debug)
-preset(32)
-preset(warn)
-preset(nasm)
-
-archetype(c)
-archetype(asm)
-
-depends(sys, $(ROOT)/src/libsys, libsys.a)
-depends(initrd, $(ROOT)/boot/initrd, initrd.img)
-depends(ata_pio, dri/ata_pio, ata_pio.a)
-depends(pci, dri/pci, pci.a)
-depends(ide, dri/ide, ide.a)
-depends(ext2, dri/fs/ext2, ext2.a)
-# AHCI not yet implemented
-# depends(ahci, dri/ahci, ahci.a)
-
-TEST ?=
-test_defines = $(TEST:%=-DTEST_%)
-
-FS ?= ext2
-
-CFLAGS += -I$(ROOT)/include/kernel $(test_defines) -O0 -Wno-ignored-qualifiers -Wno-sign-compare
-
-LDFLAGS += -Tlink.ld -melf_i386
-ASMFLAGS += -felf -Fdwarf
-QEMUFLAGS = -drive file=hd0_ext2.img,format=raw
-
-OBJECTS = boot.o \
- main.o \
- descriptor_tables.o \
- io.o \
- vga.o \
- gdt_flush.o \
- tss_flush.o \
- idt.o \
- log.o \
- irq.o \
- pic.o \
- timer.o \
- paging.o \
- switch_table.o \
- scan_codes.o \
- kheap.o \
- alloc.o \
- vfs.o \
- multiboot.o \
- vfs_initrd.o \
- syscall.o \
- task.o \
- task_api.o \
- faults.o \
- sync.o \
- lib(ext2) \
- lib(ide) \
- lib(ata_pio) \
- lib(pci) \
- lib(sys)
-
-type(custom_link)
-
-debug-wait: kernel.elf
- qemu-system-i386 -s -S $(QEMUFLAGS) -kernel kernel.elf
-
-debug: kernel.elf
- qemu-system-i386 -s -S $(QEMUFLAGS) -kernel kernel.elf &
- @echo run "target remote localhost:1234" to connect to qemu
- gdb $<
- @pkill qemu-system-i38
-
-hd0_%.img:
- status_log(MKFS, $@)
- @dd bs=4M count=8 if=/dev/zero of=$@
- @$(patsubst hd0_%.img,mkfs.%,$@) $@
-
-fs-info: hd0_$(FS).img
- tune2fs -l $< | grep -i inode
-
-reset-fs:
- @rm hd0_ext2.img
- @$(MAKE) hd0_ext2.img
- @sudo $(MAKE) mount
- @echo 'hi' | sudo tee $(ROOT)/mnt/hello.txt
- @sudo $(MAKE) umount
- @$(MAKE) qemu
-
-qemu: kernel.elf hd0_$(FS).img
- qemu-system-i386 $(QEMUFLAGS) -d cpu_reset -monitor stdio -kernel kernel.elf -no-reboot
-
-qemu-iso: install
- qemu-system-i386 $(QEMUFLAGS) -monitor stdio $(ROOT)/bin/bluejay.iso
-
-scan_codes.c: gen_scan_codes.py scan_codes.tsv
- python3 $< > $@
-
-mount: hd0_$(FS).img
- status_log(MOUNT, $^ $(ROOT)/mnt)
- @mkdir -p $(ROOT)/mnt
- @mount $^ $(ROOT)/mnt
-
-umount:
- status_log(UMOUNT, $(ROOT)/mnt)
- @umount $(ROOT)/mnt
-
-install: kernel.elf lib(initrd)
- cp kernel.elf $(ROOT)/boot/
- rm -f $(ROOT)/bin/bluejay.iso
- grub-mkrescue -o $(ROOT)/bin/bluejay.iso $(ROOT)
-
-finish
diff --git a/src/kernel/Jmk2 b/src/kernel/Jmk2
index 21b7ebe..38e44b9 100644
--- a/src/kernel/Jmk2
+++ b/src/kernel/Jmk2
@@ -4,69 +4,15 @@
presets freestanding debug 32 warn nasm
-cflags -I$root/include/kernel -I$root/include -O0 -Wno-ignored-qualifiers -Wno-sign-compare
+cflags -I$root/include/kernel -I$root/include -I[pwd] -O0 -Wno-ignored-qualifiers -Wno-unused-params -Wno-sign-compare
-ldflags -Tlink.ld -melf_i386
-asmflags -felf -Fdwarf
-set qemuflags "-drive file=hd0_ext2.img,format=raw"
+# Sources are mostly platform dependent (for now ;D )
+enable_multiplat
-depends sys $root/src/libsys libsys.a
-depends initrd $root/boot/initrd initrd.img
-depends ata_pio dri/ata_pio ata_pio.a
-depends pci dri/pci pci.a
-depends ide dri/ide ide.a
-depends ext2 dri/fs/ext2 ext2.a
-
-option FS ext2
-
-srcs boot.s \
- main.c \
- descriptor_tables.c \
- io.c \
- vga.c \
- gdt_flush.s \
- tss_flush.s \
- idt.s \
- log.c \
- irq.c \
- pic.c \
- timer.c \
- paging.c \
- switch_table.s \
- scan_codes.c \
- kheap.c \
- alloc.c \
- vfs.c \
- multiboot.c \
- vfs_initrd.c \
- syscall.c \
- task.c \
- task_api.s \
- faults.c \
- sync.c
-
-objs [lib ext2] \
- [lib ide] \
- [lib ata_pio] \
- [lib pci] \
- [lib sys]
-
-type custom_link
-
-rule debug-wait kernel.elf {
- shell "qemu-system-i386 -s -S $::qemuflags -kernel kernel.efl"
-}
-rule debug kernel.elf {
- shell "qemu-system-i386 -s -S $::qemuflags -kernel kernel.efl"
- shell "echo run target remote localhost:1234 to connect to qemu"
- shell "gdb $::first_src"
- shell "pkill qemu-system-i386"
-}
-
-rule qemu "kernel.elf hd0_$::options(FS).img" {
- shell "qemu-system-i386 $::qemuflags -d cpu_reset -monitor stdio -kernel kernel.elf -no-reboot"
-}
+srcs scan_codes.c
rule scan_codes.c "gen_scan_codes.py scan_codes.tsv" {
shell "python3 $::first_src > $::target"
}
+
+type custom_link
diff --git a/src/kernel/srcmap.txt b/src/kernel/srcmap.txt
deleted file mode 100644
index c9219a7..0000000
--- a/src/kernel/srcmap.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-+------------+
-| Source map |
-+------------+
-
-
-Source File Description
-----------------------------------------------------------------
-io.c low level memory management stuff, io utils
-log.c logging, panics, assert, etc
-vga.c vga drivers
-timer.c sets up interrupt timer
-descriptor_tables.c sets up IDT and GDT
-paging.c sets up paging
-pic.c IRQ handler
-interrupts.c ISR handler
-boot.s calls kmain
-main.c entry point
diff --git a/src/kernel/.gdbinit b/src/kernel/x86_32/.gdbinit
similarity index 100%
rename from src/kernel/.gdbinit
rename to src/kernel/x86_32/.gdbinit
diff --git a/src/kernel/alloc.c b/src/kernel/x86_32/alloc.c
similarity index 100%
rename from src/kernel/alloc.c
rename to src/kernel/x86_32/alloc.c
diff --git a/src/kernel/bf.c b/src/kernel/x86_32/bf.c
similarity index 100%
rename from src/kernel/bf.c
rename to src/kernel/x86_32/bf.c
diff --git a/src/kernel/boot.s b/src/kernel/x86_32/boot.s
similarity index 100%
rename from src/kernel/boot.s
rename to src/kernel/x86_32/boot.s
diff --git a/src/kernel/descriptor_tables.c b/src/kernel/x86_32/descriptor_tables.c
similarity index 100%
rename from src/kernel/descriptor_tables.c
rename to src/kernel/x86_32/descriptor_tables.c
diff --git a/src/kernel/descriptor_tables.h b/src/kernel/x86_32/descriptor_tables.h
similarity index 100%
rename from src/kernel/descriptor_tables.h
rename to src/kernel/x86_32/descriptor_tables.h
diff --git a/src/kernel/faults.c b/src/kernel/x86_32/faults.c
similarity index 100%
rename from src/kernel/faults.c
rename to src/kernel/x86_32/faults.c
diff --git a/src/kernel/faults.h b/src/kernel/x86_32/faults.h
similarity index 100%
rename from src/kernel/faults.h
rename to src/kernel/x86_32/faults.h
diff --git a/src/kernel/gdt_flush.s b/src/kernel/x86_32/gdt_flush.s
similarity index 100%
rename from src/kernel/gdt_flush.s
rename to src/kernel/x86_32/gdt_flush.s
diff --git a/src/kernel/idt.s b/src/kernel/x86_32/idt.s
similarity index 100%
rename from src/kernel/idt.s
rename to src/kernel/x86_32/idt.s
diff --git a/src/kernel/io.c b/src/kernel/x86_32/io.c
similarity index 100%
rename from src/kernel/io.c
rename to src/kernel/x86_32/io.c
diff --git a/src/kernel/irq.s b/src/kernel/x86_32/irq.s
similarity index 100%
rename from src/kernel/irq.s
rename to src/kernel/x86_32/irq.s
diff --git a/src/kernel/kheap.c b/src/kernel/x86_32/kheap.c
similarity index 100%
rename from src/kernel/kheap.c
rename to src/kernel/x86_32/kheap.c
diff --git a/src/kernel/kheap.h b/src/kernel/x86_32/kheap.h
similarity index 100%
rename from src/kernel/kheap.h
rename to src/kernel/x86_32/kheap.h
diff --git a/src/kernel/link.ld b/src/kernel/x86_32/link.ld
similarity index 100%
rename from src/kernel/link.ld
rename to src/kernel/x86_32/link.ld
diff --git a/src/kernel/log.c b/src/kernel/x86_32/log.c
similarity index 100%
rename from src/kernel/log.c
rename to src/kernel/x86_32/log.c
diff --git a/src/kernel/main.c b/src/kernel/x86_32/main.c
similarity index 100%
rename from src/kernel/main.c
rename to src/kernel/x86_32/main.c
diff --git a/src/kernel/multiboot.c b/src/kernel/x86_32/multiboot.c
similarity index 100%
rename from src/kernel/multiboot.c
rename to src/kernel/x86_32/multiboot.c
diff --git a/src/kernel/multiboot.h b/src/kernel/x86_32/multiboot.h
similarity index 100%
rename from src/kernel/multiboot.h
rename to src/kernel/x86_32/multiboot.h
diff --git a/src/kernel/paging.c b/src/kernel/x86_32/paging.c
similarity index 100%
rename from src/kernel/paging.c
rename to src/kernel/x86_32/paging.c
diff --git a/src/kernel/paging.h b/src/kernel/x86_32/paging.h
similarity index 100%
rename from src/kernel/paging.h
rename to src/kernel/x86_32/paging.h
diff --git a/src/kernel/pic.c b/src/kernel/x86_32/pic.c
similarity index 100%
rename from src/kernel/pic.c
rename to src/kernel/x86_32/pic.c
diff --git a/src/kernel/stdarg.h b/src/kernel/x86_32/stdarg.h
similarity index 100%
rename from src/kernel/stdarg.h
rename to src/kernel/x86_32/stdarg.h
diff --git a/src/kernel/switch_table.s b/src/kernel/x86_32/switch_table.s
similarity index 100%
rename from src/kernel/switch_table.s
rename to src/kernel/x86_32/switch_table.s
diff --git a/src/kernel/sync.c b/src/kernel/x86_32/sync.c
similarity index 100%
rename from src/kernel/sync.c
rename to src/kernel/x86_32/sync.c
diff --git a/src/kernel/syscall.c b/src/kernel/x86_32/syscall.c
similarity index 100%
rename from src/kernel/syscall.c
rename to src/kernel/x86_32/syscall.c
diff --git a/src/kernel/syscall.h b/src/kernel/x86_32/syscall.h
similarity index 100%
rename from src/kernel/syscall.h
rename to src/kernel/x86_32/syscall.h
diff --git a/src/kernel/task.c b/src/kernel/x86_32/task.c
similarity index 100%
rename from src/kernel/task.c
rename to src/kernel/x86_32/task.c
diff --git a/src/kernel/task_api.s b/src/kernel/x86_32/task_api.s
similarity index 100%
rename from src/kernel/task_api.s
rename to src/kernel/x86_32/task_api.s
diff --git a/src/kernel/timer.c b/src/kernel/x86_32/timer.c
similarity index 100%
rename from src/kernel/timer.c
rename to src/kernel/x86_32/timer.c
diff --git a/src/kernel/timer.h b/src/kernel/x86_32/timer.h
similarity index 100%
rename from src/kernel/timer.h
rename to src/kernel/x86_32/timer.h
diff --git a/src/kernel/tss_flush.s b/src/kernel/x86_32/tss_flush.s
similarity index 100%
rename from src/kernel/tss_flush.s
rename to src/kernel/x86_32/tss_flush.s
diff --git a/src/kernel/vfs.c b/src/kernel/x86_32/vfs.c
similarity index 100%
rename from src/kernel/vfs.c
rename to src/kernel/x86_32/vfs.c
diff --git a/src/kernel/vfs_initrd.c b/src/kernel/x86_32/vfs_initrd.c
similarity index 100%
rename from src/kernel/vfs_initrd.c
rename to src/kernel/x86_32/vfs_initrd.c
diff --git a/src/kernel/vfs_initrd.h b/src/kernel/x86_32/vfs_initrd.h
similarity index 100%
rename from src/kernel/vfs_initrd.h
rename to src/kernel/x86_32/vfs_initrd.h
diff --git a/src/kernel/vga.c b/src/kernel/x86_32/vga.c
similarity index 100%
rename from src/kernel/vga.c
rename to src/kernel/x86_32/vga.c
diff --git a/src/kernel/vga.h b/src/kernel/x86_32/vga.h
similarity index 100%
rename from src/kernel/vga.h
rename to src/kernel/x86_32/vga.h
diff --git a/src/kernel/x86_32/x86_32.jmk b/src/kernel/x86_32/x86_32.jmk
new file mode 100644
index 0000000..875331c
--- /dev/null
+++ b/src/kernel/x86_32/x86_32.jmk
@@ -0,0 +1,59 @@
+# -*- tcl -*-
+
+ldflags -T[pwd]/link.ld -melf_i386
+asmflags -felf -Fdwarf
+set qemuflags "-drive file=hd0_ext2.img,format=raw"
+
+depends sys $root/src/libsys libsys.a
+depends initrd $root/boot/initrd initrd.img
+depends ata_pio dri/ata_pio ata_pio.a
+depends pci dri/pci pci.a
+depends ide dri/ide ide.a
+depends ext2 dri/fs/ext2 ext2.a
+
+option FS ext2
+
+srcs boot.s \
+ main.c \
+ descriptor_tables.c \
+ io.c \
+ vga.c \
+ gdt_flush.s \
+ tss_flush.s \
+ idt.s \
+ log.c \
+ irq.c \
+ pic.c \
+ timer.c \
+ paging.c \
+ switch_table.s \
+ kheap.c \
+ alloc.c \
+ vfs.c \
+ multiboot.c \
+ vfs_initrd.c \
+ syscall.c \
+ task.c \
+ task_api.s \
+ faults.c \
+ sync.c
+
+objs [lib ext2] \
+ [lib ide] \
+ [lib ata_pio] \
+ [lib pci] \
+ [lib sys]
+
+rule debug-wait kernel.elf {
+ shell "qemu-system-i386 -s -S $::qemuflags -kernel kernel.efl"
+}
+rule debug kernel.elf {
+ shell "qemu-system-i386 -s -S $::qemuflags -kernel kernel.efl"
+ shell "echo run target remote localhost:1234 to connect to qemu"
+ shell "gdb $::first_src"
+ shell "pkill qemu-system-i386"
+}
+
+rule qemu "kernel.elf hd0_$::options(FS).img" {
+ shell "qemu-system-i386 $::qemuflags -d cpu_reset -monitor stdio -kernel kernel.elf -no-reboot"
+}