diff --git a/fdpp/cdata.S b/fdpp/kernel/cdata.S similarity index 96% rename from fdpp/cdata.S rename to fdpp/kernel/cdata.S index 15df49fd..cfea82b3 100644 --- a/fdpp/cdata.S +++ b/fdpp/kernel/cdata.S @@ -17,7 +17,7 @@ */ %include "segs.inc" -#include "../hdr/version.h" +#include "version.h" segment CONST2 diff --git a/fdpp/kernel/makefile b/fdpp/kernel/makefile index 0e5c0a63..e5985785 100644 --- a/fdpp/kernel/makefile +++ b/fdpp/kernel/makefile @@ -13,6 +13,8 @@ PPINC = $(TOP)/include/fdpp AVER = $(shell echo FDPP_API_VER | cpp -include $(PPINC)/thunks.h - | tail -n 1) BVER = $(shell echo BPRM_VER | cpp -include $(PPINC)/bprm.h - | tail -n 1) TARGET=fdppkrnl.$(AVER).$(BVER) +VERSION = 1.7 +CPPFLAGS += -I$(TOP)/fdpp NASMFLAGS += -i$(SRC) -i$(HDR) -f elf32 @@ -94,15 +96,15 @@ $(PPOBJS): %.o: %.asm makefile plt.o: plt.asm plt.inc $(SRC)/segs.inc -plt.asm: $(srcdir)/$(T)/plt.S $(SRC)/glob_asm.h $(TOP)/include/fdpp/bprm.h \ +plt.asm: $(srcdir)/plt.S $(SRC)/glob_asm.h $(TOP)/include/fdpp/bprm.h \ $(srcdir)/$(T)/thunks_priv.h $(srcdir)/makefile - $(CPP) -iquote $(PPINC) -P $< >$@ || ($(RM) $@ ; false) + $(CPP) $(CPPFLAGS) -iquote $(PPINC) -P $< >$@ || ($(RM) $@ ; false) GIT_DESCRIBE := $(shell git describe) -cdata.asm: $(srcdir)/$(T)/cdata.S $(HDR)/version.h $(GIT_REV) $(srcdir)/makefile - $(CPP) $(CPPFLAGS) -DKERNEL_VERSION="$(VERSION) [GIT: $(GIT_DESCRIBE)]" \ - -P $< | sed 's/" "/","/g' >$@ +cdata.asm: $(srcdir)/cdata.S $(HDR)/version.h $(GIT_REV) $(srcdir)/makefile + $(CPP) -iquote $(HDR) -DKERNEL_VERSION="$(VERSION) [GIT: $(GIT_DESCRIBE)]" \ + -DCMA=, -P $< >$@ thunk_calls.tmp: $(SRC)/proto.h srcdir=$(srcdir)/$(T)/parsers CPP="$(CPP)" \ diff --git a/fdpp/kernel/meson.build b/fdpp/kernel/meson.build new file mode 100644 index 00000000..6d739e6c --- /dev/null +++ b/fdpp/kernel/meson.build @@ -0,0 +1,85 @@ +project('kernel', ['nasm', 'c'], version: '1.7') +TOP = '../..' +PD = TOP / 'fdpp/parsers/parse_decls.sh' +SRC = TOP / 'kernel' +DSRC = SRC / 'drivers' +kernel_ld = TOP / 'kernel.ld' +rel_inc = TOP / 'include/fdpp' +abs_inc = meson.current_source_dir() / rel_inc +incdir = include_directories(rel_inc) +cpp = meson.get_compiler('c') +AVER = cpp.get_define('FDPP_API_VER', + include_directories: incdir, + prefix: '#include "thunks.h"') +BVER = cpp.get_define('BPRM_VER', + include_directories: incdir, + prefix: '#include "bprm.h"') +FVER = AVER + '.' + BVER +TARGET = 'fdppkrnl.' + FVER +GIT_DESCRIBE = run_command('git', 'describe', check: true).stdout().strip() +hdr = [TOP / 'kernel', TOP / 'hdr', TOP / 'fdpp', rel_inc] +incdir2 = include_directories(hdr) +sfiles = cpp.preprocess(['cdata.S', 'plt.S'], + output : '@BASENAME@.asm', + include_directories: incdir2, + compile_args : [ + '-D__ASSEMBLER__', + '-DKERNEL_VERSION=' + meson.project_version() + + ' [GIT: ' + GIT_DESCRIBE + ']', + '-DCMA=,', '-P']) +env = environment() +env.set('CPP', 'cpp') +env.set('srcdir', meson.current_source_dir() / '../parsers') +tct = custom_target('thunk_calls.tmp', + output: 'thunk_calls.tmp', + input: SRC / 'proto.h', + env: env, + command: [PD, '1', '@INPUT@'], + capture: true) +plt_inc = custom_target('plt.inc', + output: 'plt.inc', + input: tct, + command: [PD, '3', '@INPUT@'], + capture: true) + +SRCS = [ + SRC/'console.asm', + SRC/'cpu.asm', + SRC/'dosidle.asm', + SRC/'entry.asm', + SRC/'execrh.asm', + SRC/'int2f.asm', + SRC/'intr.asm', + SRC/'io.asm', + SRC/'irqstack.asm', + SRC/'kernel.asm', + SRC/'nls_hc.asm', + SRC/'nlssupt.asm', + SRC/'printer.asm', + SRC/'procsupt.asm', + SRC/'serial.asm', + + DSRC/'floppy.asm', + DSRC/'rdpcclk.asm', + DSRC/'wrpcclk.asm', + DSRC/'wratclk.asm', +] + +nargs = ['-DXCPU=186', '-DWITHFAT32', '-DFDPP'] + +lib = static_library('dummy', + [SRCS, sfiles, plt_inc], + include_directories: incdir2, + nasm_args: nargs, + build_by_default: false) +nasm_ld = find_program(['i686-linux-gnu-ld', 'i386-elf-ld', 'x86_64-linux-gnu-ld', 'ld']) +custom_target(TARGET + '.elf', + output: [TARGET + '.elf', TARGET + '.map'], + input: lib.extract_all_objects(recursive: true), + command: [nasm_ld, '-melf_i386', '-static', + '-Map=@OUTPUT1@', '-o', '@OUTPUT0@', + '--emit-relocs', '-T' + kernel_ld, '@INPUT@'], + install: true, + install_dir: get_option('datadir') / 'fdpp', + install_mode: 'rw-r--r--', + build_by_default: true) diff --git a/fdpp/plt.S b/fdpp/kernel/plt.S similarity index 100% rename from fdpp/plt.S rename to fdpp/kernel/plt.S diff --git a/fdpp/kernel/toolchain.ini b/fdpp/kernel/toolchain.ini new file mode 100644 index 00000000..0ba25d6a --- /dev/null +++ b/fdpp/kernel/toolchain.ini @@ -0,0 +1,13 @@ +[binaries] +nasm = 'nasm-segelf' +c = 'gcc' +strip = 'llvm-strip' + +[constants] +arch = 'i386-linux-gnu' + +[host_machine] +system = 'linux' +cpu_family = 'x86' +cpu = 'i386' +endian = 'little' diff --git a/fdpp/loader/meson.build b/fdpp/loader/meson.build new file mode 100644 index 00000000..5e7846b2 --- /dev/null +++ b/fdpp/loader/meson.build @@ -0,0 +1,25 @@ +project('loader', 'c', version: '0.1') +TOP = '../..' +rel_inc = TOP / 'include/fdpp' +abs_inc = meson.current_source_dir() / rel_inc +lelf = dependency('libelf') +incdir = include_directories(rel_inc) +cpp = meson.get_compiler('c') +AVER = cpp.get_define('FDPP_API_VER', + include_directories: incdir, + prefix: '#include "thunks.h"') +BVER = cpp.get_define('BPRM_VER', + include_directories: incdir, + prefix: '#include "bprm.h"') +FVER = AVER + '.' + BVER +TARGET = 'fdppkrnl.' + FVER +shared_library('fdldr', 'elf.c', 'loader.c', + dependencies: lelf, include_directories: incdir, + version: FVER, + c_args: [ + '-DFDPPKRNLDIR=' + get_option('prefix') / get_option('datadir') / 'fdpp', + '-DKRNL_ELFNAME=' + TARGET + '.elf', + '-DKRNL_MAP_NAME=' + TARGET + '.map' + ], + install: true, + install_dir: get_option('libdir') / 'fdpp') diff --git a/fdpp/meson.build b/fdpp/meson.build new file mode 100644 index 00000000..09d22971 --- /dev/null +++ b/fdpp/meson.build @@ -0,0 +1,151 @@ +project('libfdpp', ['c', 'cpp'], version: '0.1') +TOP = '..' +MF = meson.current_source_dir() / 'parsers/mkfar.sh' +MA = meson.current_source_dir() / 'parsers/mkasmdefs.sh' +PD = meson.current_source_dir() / 'parsers/parse_decls.sh' +M4 = meson.current_source_dir() / 'parsers/thunks.m4' +TG = './thunk_gen/build/thunk_gen' +TFLAGS = ['-a', '2', '-p', '2'] +SRC = TOP / 'kernel' +rel_inc = TOP / 'include/fdpp' +abs_inc = meson.current_source_dir() / rel_inc +incdir = include_directories(rel_inc) +cpp = meson.get_compiler('c') +AVER = cpp.get_define('FDPP_API_VER', + include_directories: incdir, + prefix: '#include "thunks.h"') +BVER = cpp.get_define('BPRM_VER', + include_directories: incdir, + prefix: '#include "bprm.h"') +FVER = AVER + '.' + BVER +TARGET = 'fdppkrnl.' + FVER + +CFILES = [ + SRC / 'blockio.c', + SRC / 'break.c', + SRC / 'chario.c', + SRC / 'dosfns.c', + SRC / 'dsk.c', + SRC / 'error.c', + SRC / 'fatdir.c', + SRC / 'fatfs.c', + SRC / 'fattab.c', + SRC / 'fcbfns.c', + SRC / 'hmamgr.c', + SRC / 'inthndlr.c', + SRC / 'ioctl.c', + SRC / 'memmgr.c', + SRC / 'misc.c', + SRC / 'newstuff.c', + SRC / 'network.c', + SRC / 'nls.c', + SRC / 'strings.c', + SRC / 'sysclk.c', + SRC / 'systime.c', + SRC / 'task.c', + SRC / 'config.c', + SRC / 'initoem.c', + SRC / 'main.c', + SRC / 'inithma.c', + SRC / 'dyninit.c', + SRC / 'initdisk.c', + SRC / 'initclk.c', + SRC / 'prf.c', + SRC / 'share.c'] + +ccgen = generator(find_program(MF), + output: '@BASENAME@.cc', + arguments: '@INPUT@', + capture: true) +ccfiles = ccgen.process(CFILES) + +gad = custom_target('glob_asmdefs.h', + output: 'glob_asmdefs.h', + input: SRC / 'glob_asm.h', + command: [MA, '@INPUT@'], + capture: true) + +GEN_TMP = { '1':'thunk_calls.tmp', '2':'thunk_asms.tmp' } +GEN_H = { 'plt_asmc.h':'4', 'plt_asmp.h':'5' } + +env = environment() +env.set('CPP', 'cpp') +env.set('srcdir', meson.current_source_dir() / 'parsers') +pd = find_program(PD) +gtgen = generator(pd, + arguments: ['@EXTRA_ARGS@', '@INPUT@'], + output: '@BASENAME@.tmp', + capture: true) +gt = [] +foreach n: GEN_TMP.keys() + gt += gtgen.process(SRC / 'proto.h', + extra_args: n, + env: ['CPP=cpp', 'srcdir=' + meson.current_source_dir() / 'parsers']) +endforeach +GEN = { GEN_TMP['1']:gt[0], GEN_TMP['2']:gt[1] } +pac = custom_target('plt_asmc.h', + output: 'plt_asmc.h', + input: GEN['thunk_asms.tmp'], + command: [PD, GEN_H['plt_asmc.h'], '@INPUT@'], + env: env, + capture: true) +pap = custom_target('plt_asmp.h', + output: 'plt_asmp.h', + input: GEN['thunk_asms.tmp'], + command: [PD, GEN_H['plt_asmp.h'], '@INPUT@'], + env: env, + capture: true) + +tc = custom_target('thunk_calls.h', + output: 'thunk_calls.h', + input: GEN['thunk_calls.tmp'], + command: [TG, TFLAGS], + feed: true, + capture: true) + +ta1 = custom_target('thunk_asms1.h', + output: 'thunk_asms1.h', + input: GEN['thunk_asms.tmp'], + command: [TG, TFLAGS, '1'], + feed: true, + capture: true) + +ta2 = custom_target('thunk_asms2.h', + output: 'thunk_asms2.h', + input: GEN['thunk_asms.tmp'], + command: [TG, TFLAGS, '2'], + feed: true, + capture: true) + +find_program('autom4te') +ta = custom_target('thunk_asms.h', + output: 'thunk_asms.h', + input: [ta1, ta2], + command: ['sh', '-c', 'cat @INPUT0@ | sort | uniq | autom4te -l m4sugar ' + + M4 + ' - | cat - @INPUT1@'], + capture: true) + +FDPP_CFILES = ['smalloc.c', 'farhlp_sta.c'] +ccgen = generator(find_program('echo'), + arguments: ['#include', '"@INPUT@"'], + output: '@BASENAME@.cc', + capture: true) +ppccf = ccgen.process(FDPP_CFILES) + +FDPP_CCFILES = ['thunks.cc', 'thunks_c.cc', 'thunks_a.cc', 'thunks_p.cc', + 'dosobj.cc'] +CPPFILES = ['objhlp.cpp', 'ctors.cpp', 'farhlp.cpp', 'objtrace.cpp'] +hdr = [TOP / 'kernel', TOP / 'hdr', TOP / 'fdpp', rel_inc] +incdir2 = include_directories(hdr) +shared_library('fdpp', [ccfiles, ppccf, FDPP_CCFILES, CPPFILES], + include_directories: incdir2, + version: FVER, + sources: [gad, pac, pap, tc, ta], + cpp_args: ['-DFDPP', '-DDEBUG', '-DWITHFAT32', + '-fno-threadsafe-statics', + '-Werror=packed-non-pod', '-Wno-unknown-warning-option', + '-Wno-format-invalid-specifier', '-Wno-c99-designator' + ], + link_args: ['-Wl,-Bsymbolic'], + install: true, + install_dir: get_option('libdir') / 'fdpp') diff --git a/fdpp/parsers/mkasmdefs.sh b/fdpp/parsers/mkasmdefs.sh index 053ebeee..11c163e2 100755 --- a/fdpp/parsers/mkasmdefs.sh +++ b/fdpp/parsers/mkasmdefs.sh @@ -1,3 +1,5 @@ +#!/bin/sh + grep "__ASM(" $1 | grep -v '^/' | grep -v '#define' | \ sed -E 's/.+, (.+)\).*/#define \1 __ASYM\(__\1\)/' grep "__ASM_ARR(" $1 | grep -v '^/' | grep -v '#define' | \ diff --git a/fdpp/parsers/mkfar.sh b/fdpp/parsers/mkfar.sh index 18d53ccf..0b9da078 100755 --- a/fdpp/parsers/mkfar.sh +++ b/fdpp/parsers/mkfar.sh @@ -1,3 +1,5 @@ +#!/bin/sh + mkfar() { sed -E \ -e ':loop' \ diff --git a/fdpp/thunk_gen/meson.build b/fdpp/thunk_gen/meson.build new file mode 100644 index 00000000..dbaf0c71 --- /dev/null +++ b/fdpp/thunk_gen/meson.build @@ -0,0 +1,16 @@ +project('thunk_gen', 'c', version: '0.1') + +flex = find_program('flex', required: true) +bison = find_program('bison', required: true) + +lgen = generator(flex, + output : '@PLAINNAME@.yy.c', + arguments : ['-o', '@OUTPUT@', '@INPUT@']) +lfiles = lgen.process('thunk_gen.l') + +pgen = generator(bison, + output : ['@BASENAME@.tab.c', '@BASENAME@.tab.h'], + arguments : ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@']) +pfiles = pgen.process('thunk_gen.y') + +executable('thunk_gen', lfiles, pfiles) diff --git a/fdpp/toolchain.ini b/fdpp/toolchain.ini new file mode 100644 index 00000000..48ec5042 --- /dev/null +++ b/fdpp/toolchain.ini @@ -0,0 +1,2 @@ +[binaries] +cpp = 'clang++' diff --git a/hdr/version.h b/hdr/version.h index dc3bdc78..3ac23e74 100644 --- a/hdr/version.h +++ b/hdr/version.h @@ -45,6 +45,9 @@ #endif /* actual version string */ -#define KVS(v) "FDPP kernel " #v " (compiled " __DATE__ ")" +#ifndef CMA +#define CMA +#endif +#define KVS(v) "FDPP kernel " CMA #v CMA " (compiled " CMA __DATE__ CMA ")" #define xKVS(v) KVS(v) #define KERNEL_VERSION_STRING xKVS(KERNEL_VERSION)