summaryrefslogtreecommitdiff
path: root/meson.build
blob: ebd79a4c5fe49ffbc3df9e46fb97fc3654cdd1e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
project('nrvn', ['c', 'nasm'],
  version : '0.1',
  default_options : [
    'warning_level=3',
    'b_pie=false',
    'b_staticpic=false'
  ])

if not meson.is_cross_build()
  error('must be invoked with "meson setup --cross-file=toolchain.txt"')
endif

fs = import('fs')
linker_script = fs.copyfile('util/linker.ld')

drive = custom_target(output: 'drive',
  command: ['util/build_disk.sh',
    meson.current_source_dir() / 'disk',
    '@OUTPUT@',
    '@PRIVATE_DIR@'])

files = [
  'src/asm/boot.asm',
  'src/asm/long.asm',
  'src/nrvn.c',
  'src/acpi.c',
  'src/idt.c',
  'src/mem.c',
  'src/memory.c',
  'src/pci.c',
  'src/pic.c',
  'src/ps2.c',
  'src/ahci.c',
  'src/vga.c',
  'src/fs/gpt.c',
  linker_script,
  drive
]

ld_args = [
  '-ffreestanding',
  '-nostdlib',
  '-T',
  linker_script.full_path()
]

kernel = executable('nrvn', files,
  c_args: ['-ffreestanding'],
  nasm_args: ['-felf64'],
  link_args: ld_args,
  include_directories: 'include/')


iso = custom_target('iso',
  input: [fs.copyfile('util/grub.cfg'), kernel],
  output: 'nrvn.iso',
  command: ['util/build_iso.sh', '@PRIVATE_DIR@', '@INPUT@', '@OUTPUT@'])

qemu = find_program('qemu')
qemu_args = [
  '-m', get_option('ram'),
  '-boot', 'd',
  '-cdrom', iso,
  '-drive', 'id=disk,format=raw,file=@0@,if=none'.format(drive.full_path()),
  '-device', 'ahci,id=ahci',
  '-device', 'ide-hd,drive=disk,bus=ahci.0'
]

qemu_kvm = []
if get_option('kvm')
  qemu_kvm += '-enable-kvm'
endif

run_target('run', command: [qemu, qemu_args, qemu_kvm])
run_target('run-gdb', command: [qemu, qemu_args, '-s', '-S'])