Makefile 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370
  1. # Bootloader: 512-byte boot sector + contiguous kernel at sector 1. Builds image.bin for QEMU.
  2. CC = gcc
  3. AS = as
  4. LD = ld
  5. OBJCOPY = objcopy
  6. # -march=i586: first-gen Pentium (P5); avoids CMOV etc. (P6+)
  7. CFLAGS = -ffreestanding -fno-pie -m32 -march=i586 -nostdlib -fno-stack-protector \
  8. -fno-asynchronous-unwind-tables -mno-sse -mno-sse2 -mno-mmx \
  9. -Wall -Wextra -O2 -c
  10. # Ring-3 objects are compiled with function sections so the browser link can
  11. # drop code it never reaches; the legacy rootfs pack is close to its cap.
  12. SECTION_CFLAGS = -ffunction-sections -fdata-sections
  13. # Ring-3 libc: a static archive linked only into commands that use it. The
  14. # archive means apps that never reference malloc/string keep paying nothing,
  15. # and --gc-sections drops unused functions from the members that are pulled.
  16. LIBC_CFLAGS = $(CFLAGS) -Os $(SECTION_CFLAGS) -fno-builtin \
  17. -I. -Ilibc/include
  18. LIBC_HEADERS = libc/include/stddef.h libc/include/stdint.h \
  19. libc/include/stdarg.h libc/include/stdlib.h \
  20. libc/include/string.h libc/include/ctype.h \
  21. libc/include/assert.h libc/include/ucmd_heap.h \
  22. libc/include/setjmp.h libc/include/errno.h \
  23. libc/include/stdio.h libc/include/math.h \
  24. libc/include/time.h libc/include/sys/time.h \
  25. libc/include/sys/types.h libc/include/float.h \
  26. libc/include/limits.h libc/include/inttypes.h \
  27. libc/include/alloca.h libc/dtoa.h
  28. LIBC_OBJS = libc/malloc.o libc/string.o libc/strdup.o \
  29. libc/stdlib.o libc/ucmd_mem.o libc/setjmp.o \
  30. libc/errno.o libc/div64.o libc/dtoa.o libc/stdio.o \
  31. libc/stdio_file.o libc/math.o libc/time.o
  32. # QuickJS (third_party/quickjs, see its VENDOR file) is the browser's
  33. # JavaScript engine. -nostdinc keeps host headers from leaking into the
  34. # freestanding build; __nebos__ selects the local patches.
  35. QJS_DIR = third_party/quickjs
  36. QJS_CFLAGS = $(CFLAGS) -O1 $(SECTION_CFLAGS) -nostdinc -Ilibc/include \
  37. -I$(QJS_DIR) -fno-builtin -w -D__nebos__ -U__linux__ \
  38. -U__gnu_linux__ -U__unix__ -U__GLIBC__ -DNDEBUG \
  39. -DCONFIG_VERSION='"2026-06-04"'
  40. QJS_OBJS = $(QJS_DIR)/quickjs.o $(QJS_DIR)/cutils.o $(QJS_DIR)/dtoa.o \
  41. $(QJS_DIR)/libregexp.o $(QJS_DIR)/libunicode.o
  42. # Fixed-point TrueType text engine, linked only into GUI commands.
  43. UFONT_OBJS = ufont.o ufont_ttf.o ufont_draw.o ufont_file.o
  44. ASFLAGS = --32 -I.
  45. BOOT_LDFLAGS = -T linker.ld -nostdlib -m elf_i386
  46. KERNEL_LDFLAGS = -T kernel.ld -nostdlib -m elf_i386
  47. # NOWM=1 builds a diagnostic kernel that boots to the console without the
  48. # window manager (make nowm).
  49. NOWM ?= 0
  50. ifeq ($(NOWM),1)
  51. CFLAGS += -DNOWM
  52. endif
  53. # UEFI loader: a PE32+ x86-64 EFI application built with the mingw toolchain.
  54. # The kernel itself stays 32-bit; the loader leaves long mode before jumping.
  55. EFI_CC ?= x86_64-w64-mingw32-gcc
  56. EFI_AS ?= x86_64-w64-mingw32-as
  57. EFI_CFLAGS = -ffreestanding -fno-stack-protector -mno-red-zone -fno-builtin \
  58. -fno-asynchronous-unwind-tables -fno-unwind-tables -O2 \
  59. -Wall -Wextra -I. -Iefi
  60. EFI_LDFLAGS = -nostdlib -Wl,--subsystem,10 -Wl,-e,efi_main \
  61. -Wl,--image-base,0x0 -Wl,--dynamicbase \
  62. -Wl,--enable-reloc-section -Wl,--no-insert-timestamp
  63. .PHONY: all clean run run-smp run-floppy run-usb run-uhci run-ehci run-ehci-asix run-xhci run-xhci-asix run-net run-rndis run-e1000 run-ahci test-usb test-install run-serial floppy usb uefi run-uefi test-uefi flash dev net-dev net-install cmds-dev net-cmds browser-dev gallery-dev compat-serve netmon monitor test-crypto test-wpa test-ccmp test-images test-images-asan test-libc test-font test-font-asan test-svg test-touchpad test-chat test-chat-e2e fonts kernel-dev kernel-net-dev rootfs
  64. all: floppy.img usb.img final.bin root.img image.bin
  65. boot.o: boot.S
  66. $(AS) $(ASFLAGS) -o $@ $<
  67. kernel.o: kernel.c acpi.h cpu.h cros_ec.h idle.h io.h lapic.h mouse.h panic.h phys.h process.h sched.h smp.h terminal.h timer.h serial.h tss.h usbhid.h version.h vga.h wifi_cfg.h
  68. $(CC) $(CFLAGS) -o $@ $<
  69. screen.o: screen.c screen.h
  70. $(CC) $(CFLAGS) -o $@ $<
  71. io.o: io.c io.h fbtext.h process.h screen.h tty.h
  72. $(CC) $(CFLAGS) -o $@ $<
  73. tty.o: tty.c tty.h mm.h netlog.h process.h
  74. $(CC) $(CFLAGS) -o $@ $<
  75. font_8x8.o: font_8x8.c font_8x8.h
  76. $(CC) $(CFLAGS) -o $@ $<
  77. font_8x16.o: font_8x16.c font_8x16.h
  78. $(CC) $(CFLAGS) $(SECTION_CFLAGS) -o $@ $<
  79. fbtext.o: fbtext.c fbtext.h font_8x8.h vga.h
  80. $(CC) $(CFLAGS) -o $@ $<
  81. terminal.o: terminal.c terminal.h screen.h vfs.h fat.h blkdev.h io.h dbg.h kexec.h process.h timer.h
  82. $(CC) $(CFLAGS) -Os -o $@ $<
  83. wm.o: wm.c wm.h wm_abi.h terminal.h screen.h fbtext.h idle.h io.h mouse.h process.h paging.h rtc.h timer.h version.h vga.h vfs.h
  84. $(CC) $(CFLAGS) -o $@ $<
  85. sys_wm.o: sys_wm.c sys_wm.h wm_abi.h wm.h paging.h process.h
  86. $(CC) $(CFLAGS) -o $@ $<
  87. hello.o: hello.c
  88. $(CC) $(CFLAGS) -o $@ $<
  89. reboot.o: reboot.c
  90. $(CC) $(CFLAGS) -o $@ $<
  91. poweroff.o: poweroff.c
  92. $(CC) $(CFLAGS) -o $@ $<
  93. disk.o: disk.c disk.h io.h timer.h
  94. $(CC) $(CFLAGS) -Os -o $@ $<
  95. fat.o: fat.c fat.h blkdev.h io.h
  96. $(CC) $(CFLAGS) -Os -o $@ $<
  97. rtc.o: rtc.c rtc.h acpi.h
  98. $(CC) $(CFLAGS) -o $@ $<
  99. serial.o: serial.c serial.h serial_ring_buf.h pci.h idle.h sched.h timer.h
  100. $(CC) $(CFLAGS) -o $@ $<
  101. serial_ring_buf.o: serial_ring_buf.c serial_ring_buf.h
  102. $(CC) $(CFLAGS) -o $@ $<
  103. serial_loop.o: serial_loop.c serial.h io.h timer.h
  104. $(CC) $(CFLAGS) -o $@ $<
  105. vga.o: vga.c vga.h bootinfo.h blit.h pci.h gpu.h ati.h process.h
  106. $(CC) $(CFLAGS) -o $@ $<
  107. blit.o: blit.c blit.h vga.h gfx.h cpu.h
  108. $(CC) $(CFLAGS) -o $@ $<
  109. cpu.o: cpu.c cpu.h
  110. $(CC) $(CFLAGS) -o $@ $<
  111. thermal.o: thermal.c thermal.h cpu.h sched.h serial.h
  112. $(CC) $(CFLAGS) -o $@ $<
  113. power.o: power.c power.h cpu.h idle.h io.h sched.h serial.h
  114. $(CC) $(CFLAGS) -o $@ $<
  115. tpec.o: tpec.c tpec.h power_src.h ec.h paging.h serial.h
  116. $(CC) $(CFLAGS) -o $@ $<
  117. ec.o: ec.c ec.h pci.h
  118. $(CC) $(CFLAGS) -o $@ $<
  119. cros_ec.o: cros_ec.c cros_ec.h power_src.h ec.h tpec.h serial.h
  120. $(CC) $(CFLAGS) -o $@ $<
  121. power_src.o: power_src.c power_src.h tpec.h cros_ec.h
  122. $(CC) $(CFLAGS) -o $@ $<
  123. it87.o: it87.c it87.h pci.h
  124. $(CC) $(CFLAGS) -o $@ $<
  125. gfxbench.o: gfxbench.c blit.h cpu.h fbtext.h gfx.h io.h mm.h timer.h vga.h
  126. $(CC) $(CFLAGS) -o $@ $<
  127. vga_copy.o: vga_copy.S
  128. $(AS) $(ASFLAGS) -o $@ $<
  129. gpu.o: gpu.c gpu.h pci.h ati.h cirrus.h intel.h nvidia.h
  130. $(CC) $(CFLAGS) -o $@ $<
  131. intel.o: intel.c intel.h cursor_shape.h mm.h paging.h pci.h serial.h timer.h vga.h
  132. $(CC) $(CFLAGS) -o $@ $<
  133. ati.o: ati.c ati.h pci.h radeon.h
  134. $(CC) $(CFLAGS) -o $@ $<
  135. cirrus.o: cirrus.c cirrus.h cursor_shape.h pci.h vga.h
  136. $(CC) $(CFLAGS) -o $@ $<
  137. nvidia.o: nvidia.c nvidia.h nv50.h pci.h process.h serial.h
  138. $(CC) $(CFLAGS) -Os -o $@ $<
  139. nv50.o: nv50.c nv50.h nvidia.h serial.h
  140. $(CC) $(CFLAGS) -Os -o $@ $<
  141. radeon.o: radeon.c radeon.h cursor_shape.h pci.h paging.h serial.h vga.h
  142. $(CC) $(CFLAGS) -o $@ $<
  143. mtrr.o: mtrr.c mtrr.h serial.h
  144. $(CC) $(CFLAGS) -o $@ $<
  145. gfx.o: gfx.c gfx.h mm.h vga.h
  146. $(CC) $(CFLAGS) -o $@ $<
  147. display.o: display.c io.h vga.h gpu.h ati.h nvidia.h radeon.h mouse.h fbtext.h
  148. $(CC) $(CFLAGS) -o $@ $<
  149. uhci.o: uhci.c uhci.h usb_hcd.h pci.h serial.h timer.h
  150. $(CC) $(CFLAGS) -Os -o $@ $<
  151. ohci.o: ohci.c ohci.h usb_hcd.h pci.h paging.h mm.h serial.h timer.h
  152. $(CC) $(CFLAGS) -Os -o $@ $<
  153. ehci.o: ehci.c ehci.h usb_hcd.h pci.h paging.h mm.h serial.h timer.h
  154. $(CC) $(CFLAGS) -Os -o $@ $<
  155. xhci.o: xhci.c xhci.h usb_hcd.h pci.h paging.h mm.h serial.h timer.h spinlock.h
  156. $(CC) $(CFLAGS) -Os -o $@ $<
  157. asix.o: asix.c asix.h netdev.h usb.h io.h serial.h timer.h
  158. $(CC) $(CFLAGS) -Os -o $@ $<
  159. rndis.o: rndis.c rndis.h netdev.h usb.h io.h serial.h timer.h
  160. $(CC) $(CFLAGS) -Os -o $@ $<
  161. # Intel WiFi: PCIe transport, the MVM (7265D/3165) and DVM (6200/6300)
  162. # firmware layers, their dispatch, and the 802.11 station.
  163. iwl_trans.o: iwl_trans.c iwl_trans.h mm.h paging.h pci.h process.h ramfs.h serial.h
  164. $(CC) $(CFLAGS) -Os -o $@ $<
  165. iwl_mvm.o: iwl_mvm.c iwl_mvm.h iwl_trans.h mm.h serial.h
  166. $(CC) $(CFLAGS) -Os -o $@ $<
  167. iwl_dvm.o: iwl_dvm.c iwl_dvm.h iwl_mvm.h iwl_trans.h mm.h serial.h
  168. $(CC) $(CFLAGS) -Os -o $@ $<
  169. iwl_fw.o: iwl_fw.c iwl_fw.h iwl_dvm.h iwl_mvm.h iwl_trans.h
  170. $(CC) $(CFLAGS) -Os -o $@ $<
  171. wifi.o: wifi.c wifi.h iwl_fw.h iwl_mvm.h iwl_trans.h netdev.h io.h mm.h net.h paging.h process.h serial.h syscall.h
  172. $(CC) $(CFLAGS) -Os -o $@ $<
  173. ccmp.o: ccmp.c ccmp.h
  174. $(CC) $(CFLAGS) -Os -o $@ $<
  175. usb.o: usb.c usb.h usb_hcd.h io.h serial.h timer.h
  176. $(CC) $(CFLAGS) -Os -o $@ $<
  177. usbhid.o: usbhid.c usbhid.h io.h usb.h usb_hcd.h serial.h timer.h
  178. $(CC) $(CFLAGS) -o $@ $<
  179. lsusb.o: lsusb.c io.h usb.h
  180. $(CC) $(CFLAGS) -Os -o $@ $<
  181. panic.o: panic.c panic.h bootinfo.h font_8x8.h phys.h process.h serial.h timer.h vga.h
  182. $(CC) $(CFLAGS) -o $@ $<
  183. bootcon.o: bootcon.c bootcon.h bootinfo.h font_8x8.h vga.h
  184. $(CC) $(CFLAGS) -o $@ $<
  185. lspci.o: lspci.c io.h pci.h
  186. $(CC) $(CFLAGS) -Os -o $@ $<
  187. peek.o: peek.c io.h
  188. $(CC) $(CFLAGS) -Os -o $@ $<
  189. ne2000.o: ne2000.c ne2000.h pci.h timer.h io.h
  190. $(CC) $(CFLAGS) -Os -o $@ $<
  191. r8168.o: r8168.c r8168.h netdev.h io.h mm.h paging.h pci.h process.h serial.h timer.h
  192. $(CC) $(CFLAGS) -Os -o $@ $<
  193. e1000e.o: e1000e.c e1000e.h io.h mm.h netdev.h paging.h pci.h process.h serial.h timer.h
  194. $(CC) $(CFLAGS) -Oz -o $@ $<
  195. netkexec.o: netkexec.c netkexec.h install.h io.h kexec.h net.h netcore.h netdev.h rootfs.h tcp.h timer.h
  196. $(CC) $(CFLAGS) -o $@ $<
  197. netlog.o: netlog.c netlog.h net.h netcore.h netdev.h tcp.h timer.h
  198. $(CC) $(CFLAGS) -o $@ $<
  199. dhcp.o: dhcp.c dhcp.h io.h net.h netdev.h timer.h
  200. $(CC) $(CFLAGS) -o $@ $<
  201. dns.o: dns.c dns.h io.h timer.h netcore.h netdev.h net.h process.h
  202. $(CC) $(CFLAGS) -o $@ $<
  203. ntp.o: ntp.c ntp.h dns.h net.h netdev.h timer.h syscall.h
  204. $(CC) $(CFLAGS) -o $@ $<
  205. tcp.o: tcp.c tcp.h io.h timer.h mm.h netcore.h netdev.h net.h process.h
  206. $(CC) $(CFLAGS) -o $@ $<
  207. netdev.o: netdev.c netdev.h ne2000.h r8168.h e1000e.h tcp.h
  208. $(CC) $(CFLAGS) -o $@ $<
  209. net.o: net.c net.h io.h netcore.h netdev.h process.h timer.h
  210. $(CC) $(CFLAGS) -o $@ $<
  211. netcore.o: netcore.c netcore.h dns.h net.h netdev.h netkexec.h spinlock.h tcp.h
  212. $(CC) $(CFLAGS) -o $@ $<
  213. blkdev.o: blkdev.c blkdev.h ata.h ahci.h disk.h sdhci.h
  214. $(CC) $(CFLAGS) -Os -o $@ $<
  215. sdhci.o: sdhci.c sdhci.h paging.h pci.h process.h serial.h timer.h
  216. $(CC) $(CFLAGS) -o $@ $<
  217. ata.o: ata.c ata.h pci.h serial.h timer.h
  218. $(CC) $(CFLAGS) -o $@ $<
  219. ahci.o: ahci.c ahci.h ata.h mm.h paging.h pci.h process.h serial.h timer.h
  220. $(CC) $(CFLAGS) -o $@ $<
  221. fatdetect.o: fatdetect.c fatdetect.h fat.h blkdev.h
  222. $(CC) $(CFLAGS) -Os -o $@ $<
  223. fatformat.o: fatformat.c fatformat.h blkdev.h io.h mm.h sched.h
  224. $(CC) $(CFLAGS) -Os -o $@ $<
  225. format.o: format.c blkdev.h disk.h fatformat.h io.h process.h sched.h vga.h vfs.h
  226. $(CC) $(CFLAGS) -Os -o $@ $<
  227. install.o: install.c install.h blkdev.h fatdetect.h fatformat.h io.h mm.h process.h ramfs.h rootfs.h sched.h serial.h vga.h vfs.h
  228. $(CC) $(CFLAGS) -Os -o $@ $<
  229. usbmsc.o: usbmsc.c usbmsc.h blkdev.h io.h serial.h timer.h usb.h
  230. $(CC) $(CFLAGS) -Os -o $@ $<
  231. mouse.o: mouse.c mouse.h bootinfo.h cirrus.h cursor_shape.h radeon.h timer.h touchpad.h usbhid.h vga.h
  232. $(CC) $(CFLAGS) -o $@ $<
  233. i2c.o: i2c.c i2c.h timer.h
  234. $(CC) $(CFLAGS) -o $@ $<
  235. touchpad.o: touchpad.c touchpad.h touchpad_gesture.h i2c.h io.h paging.h timer.h
  236. $(CC) $(CFLAGS) -o $@ $<
  237. touchpad_gesture.o: touchpad_gesture.c touchpad_gesture.h
  238. $(CC) $(CFLAGS) -o $@ $<
  239. idle.o: idle.c idle.h power.h
  240. $(CC) $(CFLAGS) -o $@ $<
  241. kexec.o: kexec.c kexec.h io.h serial.h smp.h
  242. $(CC) $(CFLAGS) -o $@ $<
  243. kexec_tramp.o: kexec_tramp.S
  244. $(AS) $(ASFLAGS) -o $@ $<
  245. dbg.o: dbg.c dbg.h serial.h
  246. $(CC) $(CFLAGS) -Os -o $@ $<
  247. vfs.o: vfs.c vfs.h fat.h fatdetect.h blkdev.h io.h
  248. $(CC) $(CFLAGS) -Os -o $@ $<
  249. boot.elf: boot.o
  250. $(LD) $(BOOT_LDFLAGS) -o $@ $<
  251. vesa_stage.o: vesa_stage.S
  252. $(AS) $(ASFLAGS) -o $@ $<
  253. timer.o: timer.S irqret.inc
  254. $(AS) $(ASFLAGS) -o $@ $<
  255. switch.o: switch.S irqret.inc
  256. $(AS) $(ASFLAGS) -o $@ $<
  257. entry.o: entry.S
  258. $(AS) $(ASFLAGS) -o $@ $<
  259. sched.o: sched.c sched.h process.h paging.h smp.h spinlock.h sys_fs.h thermal.h power.h timer.h tss.h vga.h
  260. $(CC) $(CFLAGS) -o $@ $<
  261. acpi.o: acpi.c acpi.h bootinfo.h paging.h serial.h
  262. $(CC) $(CFLAGS) -o $@ $<
  263. lapic.o: lapic.c lapic.h timer.h
  264. $(CC) $(CFLAGS) -o $@ $<
  265. smp.o: smp.c smp.h acpi.h idle.h lapic.h paging.h process.h sched.h serial.h timer.h tss.h
  266. $(CC) $(CFLAGS) -o $@ $<
  267. ap_tramp.o: ap_tramp.S
  268. $(AS) $(ASFLAGS) -o $@ $<
  269. ap_tramp.elf: ap_tramp.o ap_tramp.ld
  270. $(LD) -T ap_tramp.ld -nostdlib -m elf_i386 -o $@ $<
  271. ap_tramp.bin: ap_tramp.elf
  272. $(OBJCOPY) -O binary $< $@
  273. ap_tramp_embed.o: ap_tramp.bin
  274. $(LD) -m elf_i386 -r -b binary -o ap_tramp_embed.o ap_tramp.bin
  275. process.o: process.c process.h sched.h io.h kmalloc.h mm.h serial.h smp.h idle.h timer.h wm_abi.h
  276. $(CC) $(CFLAGS) -o $@ $<
  277. mm.o: mm.c mm.h phys.h
  278. $(CC) $(CFLAGS) -o $@ $<
  279. kmalloc.o: kmalloc.c kmalloc.h mm.h
  280. $(CC) $(CFLAGS) -o $@ $<
  281. paging.o: paging.c paging.h mm.h phys.h mtrr.h vga.h serial.h
  282. $(CC) $(CFLAGS) -o $@ $<
  283. elf.o: elf.c elf.h mm.h paging.h
  284. $(CC) $(CFLAGS) -o $@ $<
  285. tss.o: tss.c tss.h sched.h
  286. $(CC) $(CFLAGS) -o $@ $<
  287. syscall.o: syscall.c syscall.h io.h process.h timer.h sys_wm.h wm_abi.h
  288. $(CC) $(CFLAGS) -o $@ $<
  289. sys_fs.o: sys_fs.c sys_fs.h syscall.h fat.h vfs.h
  290. $(CC) $(CFLAGS) -o $@ $<
  291. sys_mem.o: sys_mem.c sys_mem.h mm.h paging.h process.h
  292. $(CC) $(CFLAGS) -o $@ $<
  293. inflate.o: inflate.c inflate.h
  294. $(CC) $(CFLAGS) $(SECTION_CFLAGS) -o $@ $<
  295. sys_info.o: sys_info.c sys_info.h syscall.h ahci.h blkdev.h cros_ec.h it87.h mm.h mouse.h power_src.h thermal.h tpec.h usbhid.h vfs.h
  296. $(CC) $(CFLAGS) -o $@ $<
  297. sys_net.o: sys_net.c sys_net.h syscall.h dhcp.h dns.h net.h netcore.h netdev.h netlog.h ntp.h process.h sched.h tcp.h timer.h
  298. $(CC) $(CFLAGS) -o $@ $<
  299. syscall_stub.o: syscall_stub.S irqret.inc
  300. $(AS) $(ASFLAGS) -o $@ $<
  301. kernel.elf: kernel.ld vesa_stage.o entry.o kernel.o timer.o switch.o sched.o process.o mm.o kmalloc.o paging.o elf.o tss.o syscall.o sys_wm.o syscall_stub.o screen.o io.o tty.o rtc.o terminal.o wm.o reboot.o poweroff.o disk.o fat.o serial.o serial_ring_buf.o serial_loop.o vga.o blit.o cpu.o thermal.o it87.o tpec.o ec.o cros_ec.o power_src.o power.o vga_copy.o gfxbench.o gpu.o ati.o cirrus.o intel.o nvidia.o nv50.o radeon.o mtrr.o font_8x8.o fbtext.o gfx.o display.o mouse.o i2c.o touchpad.o touchpad_gesture.o uhci.o ohci.o ehci.o xhci.o asix.o rndis.o iwl_trans.o iwl_mvm.o iwl_dvm.o iwl_fw.o wifi.o ccmp.o usb.o usbmsc.o usbhid.o lsusb.o panic.o bootcon.o blkdev.o sdhci.o ata.o ahci.o fatdetect.o fatformat.o format.o install.o vfs.o sys_fs.o sys_info.o sys_mem.o sys_net.o idle.o kexec.o kexec_tramp.o dbg.o lspci.o peek.o ne2000.o r8168.o e1000e.o netdev.o net.o netcore.o netkexec.o netlog.o dhcp.o dns.o ntp.o tcp.o acpi.o lapic.o smp.o ap_tramp_embed.o inflate.o ramfs.o share.o payload.o
  302. $(LD) $(KERNEL_LDFLAGS) -o $@ $(filter-out kernel.ld,$^)
  303. MBR_LDFLAGS = -T mbr.ld -nostdlib -m elf_i386
  304. mbr.o: mbr.S
  305. $(AS) $(ASFLAGS) -o $@ $<
  306. mbr.elf: mbr.o
  307. $(LD) $(MBR_LDFLAGS) -o $@ $<
  308. mbr.bin: mbr.elf
  309. $(OBJCOPY) -O binary $< $@
  310. boot.bin: boot.elf
  311. $(OBJCOPY) -O binary --only-section=.boot $< $@.tmp
  312. dd if=$@.tmp of=$@ bs=1 count=510 2>/dev/null
  313. printf '\x55\xaa' >> $@
  314. rm -f $@.tmp
  315. kernel.bin: kernel.elf
  316. $(OBJCOPY) -O binary $< $@
  317. # Byte offsets inside boot.bin (see boot.S). Keep decimal: dd's seek= does not
  318. # parse 0x… literals (it silently treats them as 0) and the error is hidden by
  319. # the 2>/dev/null below.
  320. # 62 = kernel_sectors field (0x3E)
  321. # 64 = kernel_lba field (0x40, word; LBA 64 fits in the low byte)
  322. # 66 = pack_lba field (0x42, dword; rootfs image LBA)
  323. KERNEL_SECTORS_OFFSET = 62
  324. BOOT_SECTOR_START_OFFSET = 64
  325. PACK_LBA_OFFSET = 66
  326. # USB rootfs partition (type 0x7F) and UEFI ESP (type 0xEF). Partition 1
  327. # has room for a 512 KB kernel; the rootfs starts after it at LBA 1088.
  328. # The header and the 242 KB gzip pack are still inside the first 1.44 MB.
  329. ROOTFS_LBA = 1088
  330. ROOTFS_SECTORS = 16384
  331. ESP_LBA = 18432
  332. # Patch a little-endian 16/32-bit value into a boot-sector copy. Usage:
  333. # $(call patch16,file,offset,value)
  334. # (shell snippets are inlined below because make functions cannot easily
  335. # expand `$$(...)` arithmetic; the helpers keep the rules readable.)
  336. patch32 = printf "$$(printf '\\x%02x\\x%02x\\x%02x\\x%02x' \
  337. $$(( ( ($(2)) >> 0) & 0xFF )) $$(( ( ($(2)) >> 8) & 0xFF )) \
  338. $$(( ( ($(2)) >> 16) & 0xFF )) $$(( ( ($(2)) >> 24) & 0xFF )))" | \
  339. dd of=$(1) bs=1 seek=$(3) conv=notrunc 2>/dev/null
  340. patch16 = printf "$$(printf '\\x%02x\\x%02x' \
  341. $$(( ( ($(2)) >> 0) & 0xFF )) $$(( ( ($(2)) >> 8) & 0xFF )))" | \
  342. dd of=$(1) bs=1 seek=$(3) conv=notrunc 2>/dev/null
  343. floppy.img: boot.bin kernel.bin rootfs.bin
  344. SECTORS=$$(( ($$(stat -c%s kernel.bin) + 511) / 512 )); \
  345. cp boot.bin $@.boot.tmp; \
  346. $(call patch16,$@.boot.tmp,$$SECTORS,$(KERNEL_SECTORS_OFFSET)); \
  347. $(call patch32,$@.boot.tmp,1 + SECTORS,$(PACK_LBA_OFFSET)); \
  348. cat $@.boot.tmp kernel.bin > $@; \
  349. PAD=$$(( SECTORS * 512 - $$(stat -c%s kernel.bin) )); \
  350. dd if=/dev/zero bs=1 count=$$PAD 2>/dev/null >> $@; \
  351. cat rootfs.bin >> $@; \
  352. SIZE=$$(stat -c%s $@); \
  353. if [ $$SIZE -gt 1474560 ]; then \
  354. echo "error: floppy.img is $$SIZE bytes; max is 1474560"; \
  355. rm -f $@; exit 1; \
  356. fi; \
  357. truncate -s 1474560 $@; \
  358. rm -f $@.boot.tmp
  359. usb.img: mbr.bin boot.bin kernel.bin cmds.img
  360. SECTORS=$$(( ($$(stat -c%s kernel.bin) + 511) / 512 )); \
  361. cp boot.bin $@.boot.tmp; \
  362. $(call patch16,$@.boot.tmp,$$SECTORS,$(KERNEL_SECTORS_OFFSET)); \
  363. printf '\x40' | dd of=$@.boot.tmp bs=1 seek=$(BOOT_SECTOR_START_OFFSET) conv=notrunc 2>/dev/null; \
  364. $(call patch32,$@.boot.tmp,$(ROOTFS_LBA),$(PACK_LBA_OFFSET)); \
  365. cat mbr.bin > $@; \
  366. dd if=/dev/zero bs=512 count=62 2>/dev/null >> $@; \
  367. cat $@.boot.tmp kernel.bin >> $@; \
  368. truncate -s 9M $@; \
  369. dd if=cmds.img of=$@ bs=512 seek=$(ROOTFS_LBA) conv=notrunc 2>/dev/null; \
  370. printf '\x00\x11\x12\x00\x7f\x16\x15\x01\x40\x04\x00\x00\x00\x40\x00\x00' | \
  371. dd of=$@ bs=1 seek=462 conv=notrunc 2>/dev/null; \
  372. rm -f $@.boot.tmp
  373. image.bin: floppy.img
  374. cp floppy.img image.bin
  375. final.bin: boot.bin kernel.bin rootfs.bin
  376. SECTORS=$$(( ($$(stat -c%s kernel.bin) + 511) / 512 )); \
  377. cp boot.bin $@.boot.tmp; \
  378. $(call patch16,$@.boot.tmp,$$SECTORS,$(KERNEL_SECTORS_OFFSET)); \
  379. $(call patch32,$@.boot.tmp,1 + SECTORS,$(PACK_LBA_OFFSET)); \
  380. cat $@.boot.tmp kernel.bin > $@; \
  381. PAD=$$(( SECTORS * 512 - $$(stat -c%s kernel.bin) )); \
  382. dd if=/dev/zero bs=1 count=$$PAD 2>/dev/null >> $@; \
  383. cat rootfs.bin >> $@; \
  384. rm -f $@.boot.tmp
  385. # ---- UEFI loader and dual-boot USB image -------------------------------
  386. #
  387. # The legacy image (usb.img) is left byte-for-byte alone. usb-efi.img copies
  388. # it, adds a third MBR partition (type 0xEF, starting at the old 64 MB end)
  389. # and writes a small FAT16 ESP there. BIOS booting still uses the active
  390. # partition 1 at LBA 63; UEFI finds BOOTX64.EFI in the ESP.
  391. efi/efi_entry.h: kernel.elf
  392. @mkdir -p efi
  393. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  394. if [ -z "$$entry" ]; then echo "efi: kernel_entry not found" >&2; exit 1; fi; \
  395. printf '#define KERNEL_ENTRY 0x%s\n' "$$entry" > $@
  396. efi/main.o: efi/main.c efi/efi.h bootinfo.h phys.h vga.h efi/efi_entry.h
  397. $(EFI_CC) $(EFI_CFLAGS) -c -o $@ $<
  398. efi/payload.o: efi/payload.S kernel.bin cmds_pack_gz.bin efi/tramp.bin
  399. $(EFI_AS) --64 -o $@ $<
  400. efi/tramp.o: efi/tramp.S
  401. $(AS) --64 -o $@ $<
  402. efi/tramp.elf: efi/tramp.o efi/tramp.ld
  403. $(LD) -T efi/tramp.ld -nostdlib -m elf_x86_64 -o $@ $<
  404. efi/tramp.bin: efi/tramp.elf
  405. $(OBJCOPY) -O binary $< $@
  406. BOOTX64.EFI: efi/main.o efi/payload.o
  407. $(EFI_CC) $(EFI_LDFLAGS) -o $@ efi/main.o efi/payload.o
  408. ESP_SECTORS = 16384
  409. esp.img: BOOTX64.EFI
  410. truncate -s $$(( $(ESP_SECTORS) * 512 )) $@
  411. mkfs.fat -F 16 -s 2 -n NEBOSESP $@
  412. mmd -i $@ ::/EFI
  413. mmd -i $@ ::/EFI/BOOT
  414. mcopy -i $@ BOOTX64.EFI ::/EFI/BOOT/BOOTX64.EFI
  415. usb-efi.img: usb.img esp.img
  416. cp usb.img $@
  417. # The legacy partition is a raw kernel blob with a deliberately empty
  418. # BPB (boot.S), so neither UEFI firmware nor VFS mistakes it for FAT.
  419. # Partition 3: ESP at LBA 18432, type 0xEF, 8 MB (partition 2 is the
  420. # rootfs at LBA 1088 written by usb.img).
  421. printf '\x00\xfe\xff\xff\xef\xfe\xff\xff\x00\x48\x00\x00\x00\x40\x00\x00' | \
  422. dd of=$@ bs=1 seek=478 conv=notrunc 2>/dev/null
  423. dd if=esp.img of=$@ bs=512 seek=$(ESP_LBA) conv=notrunc 2>/dev/null
  424. truncate -s $$(( ($(ESP_LBA) + $(ESP_SECTORS)) * 512 )) $@
  425. uefi: usb-efi.img
  426. OVMF ?= $(firstword $(wildcard /usr/share/ovmf/x64/OVMF.4m.fd /usr/share/OVMF/OVMF.4m.fd))
  427. # Guest RAM for the QEMU targets. The kernel ceiling is 512 MB (phys.h);
  428. # override with `make run QEMU_MEM=1G` for larger guests.
  429. QEMU_MEM ?= 512M
  430. # root.img is deliberately not attached: a running QEMU may hold its write
  431. # lock, and the UEFI boot test does not need a second filesystem.
  432. run-uefi: usb-efi.img
  433. @test -n "$(OVMF)" || { echo "OVMF not found; set OVMF=/path/to/OVMF.4m.fd" >&2; exit 1; }
  434. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -smp 4 -bios $(OVMF) -snapshot \
  435. -drive file=usb-efi.img,format=raw,if=ide \
  436. -device pci-ohci -device usb-mouse \
  437. -device ne2k_pci,netdev=n0 -netdev user,id=n0 \
  438. -serial file:/tmp/opencode/nebos-uefi-serial.log
  439. test-uefi: usb-efi.img
  440. @test -n "$(OVMF)" || { echo "OVMF not found; set OVMF=/path/to/OVMF.4m.fd" >&2; exit 1; }
  441. @rm -f /tmp/opencode/nebos-uefi-serial.log
  442. timeout 40 qemu-system-x86_64 -M pc -m $(QEMU_MEM) -smp 4 -bios $(OVMF) -snapshot \
  443. -drive file=usb-efi.img,format=raw,if=ide \
  444. -device pci-ohci -device usb-mouse \
  445. -device ne2k_pci,netdev=n0 -netdev user,id=n0 \
  446. -display none -serial file:/tmp/opencode/nebos-uefi-serial.log \
  447. -no-reboot >/dev/null 2>&1 || true
  448. @grep -q "booted" /tmp/opencode/nebos-uefi-serial.log && \
  449. echo "UEFI boot: OK (/tmp/opencode/nebos-uefi-serial.log)" || \
  450. { echo "UEFI boot: FAILED"; tail -c 4000 /tmp/opencode/nebos-uefi-serial.log; exit 1; }
  451. # Ring-3 commands: freestanding ELFs at USER_BASE, packed into cmds.pack and
  452. # mounted at /ramfs/bin (the shell's PATH default). New command: add
  453. # ucmd_<name>.c to UCMDS; the pack is rebuilt automatically.
  454. UCMDS = ucmd_cpuinfo ucmd_ls ucmd_cat ucmd_save ucmd_rm ucmd_mkdir ucmd_rmdir \
  455. ucmd_meminfo ucmd_mouseinfo ucmd_storage ucmd_top \
  456. ucmd_clock ucmd_colors ucmd_edit ucmd_wm ucmd_term ucmd_spin \
  457. ucmd_netinfo ucmd_netip ucmd_netdns ucmd_host ucmd_dhcp \
  458. ucmd_netsend ucmd_netrecv ucmd_ping ucmd_pong ucmd_netlog \
  459. ucmd_netconsole ucmd_netregs ucmd_netloop ucmd_netreset ucmd_net100 ucmd_netmac ucmd_curl \
  460. ucmd_files ucmd_view ucmd_sensors ucmd_powerinfo ucmd_mines ucmd_solitaire \
  461. ucmd_settime ucmd_date ucmd_gallery ucmd_websrv ucmd_browser ucmd_chat \
  462. ucmd_wifi ucmd_netmenu
  463. # Keep the linked ELFs around (make would treat them as disposable
  464. # intermediates between the pattern rules).
  465. .PRECIOUS: $(addsuffix .elf,$(UCMDS))
  466. # Ring-3 libc objects and archive.
  467. libc/%.o: libc/%.c $(LIBC_HEADERS) ucmd_lib.h syscall.h
  468. $(CC) $(LIBC_CFLAGS) -o $@ $<
  469. libc/setjmp.o: libc/setjmp.S
  470. $(AS) $(ASFLAGS) -o $@ $<
  471. libc.a: $(LIBC_OBJS)
  472. rm -f $@
  473. ar rcs $@ $^
  474. ufont.o: ufont.c ufont.h ufont_internal.h $(LIBC_HEADERS)
  475. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -Ilibc/include -o $@ $<
  476. ufont_ttf.o: ufont_ttf.c ufont_internal.h $(LIBC_HEADERS)
  477. $(CC) $(CFLAGS) -O2 $(SECTION_CFLAGS) -Ilibc/include -o $@ $<
  478. ufont_draw.o: ufont_draw.c ufont.h $(LIBC_HEADERS)
  479. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -Ilibc/include -o $@ $<
  480. ufont_file.o: ufont_file.c ufont.h ucmd_lib.h syscall.h $(LIBC_HEADERS)
  481. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -Ilibc/include -o $@ $<
  482. UFONT_TEST_SRCS = ufont_test.c ufont.c ufont_ttf.c ufont_draw.c
  483. ufont_test: $(UFONT_TEST_SRCS) ufont.h ufont_internal.h fonts/emoji.ttf
  484. gcc -O2 -Wall -Wextra -I. -o $@ $(UFONT_TEST_SRCS)
  485. test-font: ufont_test
  486. ./ufont_test
  487. svg_test: svg_test.c svg_raster.c svg_raster.h
  488. gcc -O1 -g -Wall -Wextra -fsanitize=address,undefined -I. -o $@ svg_test.c svg_raster.c -lm
  489. test-svg: svg_test
  490. ./svg_test
  491. test-touchpad: touchpad_gesture_test
  492. ./touchpad_gesture_test
  493. touchpad_gesture_test: touchpad_gesture_test.c touchpad_gesture.c touchpad_gesture.h
  494. gcc -O2 -Wall -Wextra -I. -o $@ touchpad_gesture_test.c touchpad_gesture.c
  495. test-font-asan: $(UFONT_TEST_SRCS) ufont.h ufont_internal.h fonts/emoji.ttf
  496. gcc -O1 -g -fsanitize=address,undefined -I. -o ufont_test_asan $(UFONT_TEST_SRCS)
  497. ./ufont_test_asan
  498. fonts:
  499. tools/subset_fonts.sh
  500. ucmd_%.o: ucmd_%.c ucmd_lib.h syscall.h $(LIBC_HEADERS)
  501. $(CC) $(CFLAGS) -Ilibc/include -o $@ $<
  502. ucmd_%.elf: ucmd_%.o ucmd.ld
  503. $(LD) -T ucmd.ld -z max-page-size=0x100 -nostdlib -m elf_i386 -o $@ $<
  504. $(OBJCOPY) --strip-all $@ $@
  505. # websrv buffers its whole PUT/GET body on the libc heap.
  506. ucmd_websrv.elf: ucmd_websrv.o ucmd.ld libc.a
  507. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  508. $(OBJCOPY) --strip-all $@ $@
  509. # edit draws text itself, so it links the kernel's 8x8 font into its ELF.
  510. ucmd_edit.o: ucmd_edit.c ucmd_lib.h syscall.h font_8x16.h
  511. $(CC) $(CFLAGS) -o $@ $<
  512. ucmd_edit.elf: ucmd_edit.o font_8x16.o ucmd.ld
  513. $(LD) -T ucmd.ld -z max-page-size=0x100 -nostdlib -m elf_i386 -o $@ $(filter %.o,$^)
  514. $(OBJCOPY) --strip-all $@ $@
  515. # The ring-3 WM draws its own chrome and terminal cells.
  516. ucmd_wm.o: ucmd_wm.c ucmd_lib.h syscall.h wm_abi.h uwm_lib.h version.h
  517. $(CC) $(CFLAGS) -o $@ $<
  518. uwm_lib.o: uwm_lib.c uwm_lib.h font_8x16.h ufont.h
  519. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -Ilibc/include -o $@ $<
  520. ucmd_wm.elf: ucmd_wm.o uwm_lib.o font_8x16.o $(UFONT_OBJS) ucmd.ld libc.a
  521. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  522. $(OBJCOPY) --strip-all $@ $@
  523. ucmd_term.o: ucmd_term.c ucmd_lib.h syscall.h wm_abi.h uwm_lib.h io.h vfs.h $(LIBC_HEADERS)
  524. $(CC) $(CFLAGS) -Ilibc/include -o $@ $<
  525. ucmd_term.elf: ucmd_term.o uwm_lib.o font_8x16.o $(UFONT_OBJS) ucmd.ld libc.a
  526. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  527. $(OBJCOPY) --strip-all $@ $@
  528. # ngui: the userland immediate-mode GUI toolkit and its apps.
  529. # -Os: every GUI app links the whole toolkit, and the rootfs pack has a
  530. # 512 KB cap; -Os saves ~10 KB compressed across the pack.
  531. ngui.o: ngui.c ngui.h ucmd_lib.h syscall.h wm_abi.h font_8x16.h ufont.h
  532. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -Ilibc/include -o $@ $<
  533. ucmd_files.o: ucmd_files.c ucmd_lib.h syscall.h wm_abi.h ngui.h img.h
  534. $(CC) $(CFLAGS) -o $@ $<
  535. ucmd_files.elf: ucmd_files.o ngui.o font_8x16.o $(UFONT_OBJS) ucmd.ld libc.a
  536. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  537. $(OBJCOPY) --strip-all $@ $@
  538. # mines is a second ngui canvas app; it links the same toolkit.
  539. ucmd_mines.o: ucmd_mines.c ucmd_lib.h syscall.h wm_abi.h ngui.h
  540. $(CC) $(CFLAGS) -o $@ $<
  541. ucmd_mines.elf: ucmd_mines.o ngui.o font_8x16.o $(UFONT_OBJS) ucmd.ld libc.a
  542. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  543. $(OBJCOPY) --strip-all $@ $@
  544. # settime: Date & Time editor (RTC read/write) on the same canvas toolkit.
  545. ucmd_settime.o: ucmd_settime.c ucmd_lib.h syscall.h wm_abi.h ngui.h
  546. $(CC) $(CFLAGS) -Os -o $@ $<
  547. ucmd_settime.elf: ucmd_settime.o ngui.o font_8x16.o $(UFONT_OBJS) ucmd.ld libc.a
  548. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  549. $(OBJCOPY) --strip-all $@ $@
  550. # solitaire: a Windows 95 style Klondike game on the same canvas toolkit.
  551. ucmd_solitaire.o: ucmd_solitaire.c ucmd_lib.h syscall.h wm_abi.h ngui.h
  552. $(CC) $(CFLAGS) -Os -o $@ $<
  553. ucmd_solitaire.elf: ucmd_solitaire.o ngui.o font_8x16.o $(UFONT_OBJS) ucmd.ld libc.a
  554. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  555. $(OBJCOPY) --strip-all $@ $@
  556. # gallery: a live showcase of every ngui widget and primitive. The real ELF
  557. # ships in the rootfs pack as bin/gallery.app; ucmd_gallery.c (in UCMDS) is
  558. # the tiny PATH launcher (which also accepts /share/GALLERY).
  559. gallery.o: gallery.c ucmd_lib.h syscall.h wm_abi.h ngui.h
  560. $(CC) $(CFLAGS) -o $@ $<
  561. gallery.elf: gallery.o ngui.o font_8x16.o $(UFONT_OBJS) ucmd.ld libc.a
  562. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  563. $(OBJCOPY) --strip-all $@ $@
  564. # Image library: pure freestanding decoders + RGB565 compositing. Only the
  565. # viewer links them today; a browser can link the same objects later.
  566. IMGLIB_OBJS = img.o img_mem.o img_blit.o img_png.o img_bmp.o img_gif.o \
  567. img_jpeg.o img_tga.o img_pnm.o img_ico.o img_pam.o img_gif_anim.o img_file.o
  568. $(IMGLIB_OBJS): %.o: %.c img.h img_internal.h inflate.h ucmd_lib.h syscall.h
  569. $(CC) $(CFLAGS) $(SECTION_CFLAGS) -o $@ $<
  570. # The integer IDCT deliberately relies on 32-bit wrap-around.
  571. img_jpeg.o: CFLAGS += -fwrapv
  572. ucmd_view.o: ucmd_view.c ucmd_lib.h syscall.h wm_abi.h ngui.h img.h img_file.h $(LIBC_HEADERS)
  573. $(CC) $(CFLAGS) -Ilibc/include -o $@ $<
  574. ucmd_view.elf: ucmd_view.o $(IMGLIB_OBJS) inflate.o ngui.o font_8x16.o $(UFONT_OBJS) ucmd.ld libc.a
  575. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  576. $(OBJCOPY) --strip-all $@ $@
  577. # TLS 1.3 client library (ring-3, linked into ucmd_curl; see tls.h). The
  578. # crypto files are pure freestanding C, so tls_test can exercise them on
  579. # the host (make test-crypto).
  580. TLSLIB_OBJS = tls_sha256.o tls_chacha20.o tls_x25519.o tls_rng.o tls.o
  581. # Shared ring-3 HTTP/TLS client (curl, the browser and chat). The cookie
  582. # jar and the JSON parser are pure C with host tests (make test-chat).
  583. uhttp.o: uhttp.c uhttp.h uhttp_cookie.h ucmd_lib.h tls.h
  584. $(CC) $(CFLAGS) $(SECTION_CFLAGS) -o $@ $<
  585. uhttp_cookie.o: uhttp_cookie.c uhttp_cookie.h
  586. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -o $@ $<
  587. ujson.o: ujson.c ujson.h
  588. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -o $@ $<
  589. # curl embeds struct uhttp, so it rebuilds when the header changes.
  590. ucmd_curl.o: uhttp.h uhttp_cookie.h
  591. ucmd_curl.elf: ucmd_curl.o uhttp.o uhttp_cookie.o $(TLSLIB_OBJS) ucmd.ld libc.a
  592. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  593. $(OBJCOPY) --strip-all $@ $@
  594. # chat: native Cloudron Chat client (ngui + uhttp/TLS + cookie jar + JSON +
  595. # the native OIDC login driver).
  596. chat_login.o: chat_login.c chat_login.h ujson.h uhttp.h uhttp_cookie.h ucmd_lib.h
  597. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -o $@ $<
  598. ucmd_chat.o: ucmd_chat.c ucmd_lib.h syscall.h wm_abi.h ngui.h uhttp.h uhttp_cookie.h ujson.h chat_login.h $(LIBC_HEADERS)
  599. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -Ilibc/include -o $@ $<
  600. ucmd_chat.elf: ucmd_chat.o chat_login.o ujson.o uhttp.o uhttp_cookie.o ngui.o font_8x16.o $(UFONT_OBJS) $(TLSLIB_OBJS) ucmd.ld libc.a
  601. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  602. $(OBJCOPY) --strip-all $@ $@
  603. # Host tests for the chat client's pure modules: JSON, cookie jar and the
  604. # login page/reply/config parsers.
  605. CHAT_TEST_CFLAGS = -O1 -g -Wall -Wextra -fsanitize=address,undefined -I.
  606. ujson_test: ujson_test.c ujson.c ujson.h
  607. gcc $(CHAT_TEST_CFLAGS) -o $@ ujson_test.c ujson.c
  608. uhttp_cookie_test: uhttp_cookie_test.c uhttp_cookie.c uhttp_cookie.h
  609. gcc $(CHAT_TEST_CFLAGS) -o $@ uhttp_cookie_test.c uhttp_cookie.c
  610. chat_login_test: chat_login_test.c chat_login.c chat_login.h ujson.c ujson.h
  611. gcc $(CHAT_TEST_CFLAGS) -DCHAT_LOGIN_PURE -o $@ chat_login_test.c chat_login.c ujson.c
  612. test-chat: ujson_test uhttp_cookie_test chat_login_test
  613. ./ujson_test
  614. ./uhttp_cookie_test
  615. ./chat_login_test
  616. # QEMU end-to-end chat test against tools/mock_chat.py (ports 18080/18081 on
  617. # the host, 10.0.2.2 in the guest). CHAT_E2E=--totp|--consent|--passkey|
  618. # --wrong selects a login variant; screenshots land in chat-test-out/.
  619. CHAT_E2E ?=
  620. test-chat-e2e: floppy.img root.img
  621. python3 tools/qmp_chat_test.py $(CHAT_E2E)
  622. # browser: the real app is a disk image (BROWSER) because it links ngui, the
  623. # image library, TLS and uhttp. ucmd_browser.c is the tiny PATH launcher.
  624. # Compile this graph with function sections and link it with --gc-sections:
  625. # unreachable image, TLS and UI paths are dropped, leaving room under the
  626. # 512 KB rootfs pack cap.
  627. browser_html.o: browser_html.c browser_html.h
  628. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -o $@ $<
  629. svg_raster.o: svg_raster.c svg_raster.h $(LIBC_HEADERS)
  630. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -Ilibc/include -o $@ $<
  631. $(QJS_DIR)/%.o: $(QJS_DIR)/%.c $(wildcard $(QJS_DIR)/*.h) $(LIBC_HEADERS)
  632. $(CC) $(QJS_CFLAGS) -o $@ $<
  633. js_mu.o: js_mu.c js_mu.h ucmd_lib.h syscall.h $(QJS_DIR)/quickjs.h $(LIBC_HEADERS)
  634. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -Wno-unused-parameter -Ilibc/include -I$(QJS_DIR) -o $@ $<
  635. js_browser.o: js_browser.c js_browser.h js_mu.h browser_html.h ucmd_lib.h \
  636. syscall.h $(LIBC_HEADERS)
  637. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -Ilibc/include -o $@ $<
  638. browser.o: browser.c ucmd_lib.h syscall.h wm_abi.h ngui.h browser_html.h svg_raster.h js_browser.h uhttp.h img.h inflate.h $(LIBC_HEADERS)
  639. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -Ilibc/include -o $@ $<
  640. browser.elf: browser.o browser_html.o svg_raster.o js_browser.o uhttp.o uhttp_cookie.o ngui.o font_8x16.o $(UFONT_OBJS) $(IMGLIB_OBJS) inflate.o $(TLSLIB_OBJS) js_mu.o $(QJS_OBJS) ucmd.ld libc.a
  641. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  642. $(OBJCOPY) --strip-all $@ $@
  643. tls_sha256.o: tls_sha256.c tls_sha256.h
  644. $(CC) $(CFLAGS) $(SECTION_CFLAGS) -o $@ $<
  645. tls_chacha20.o: tls_chacha20.c tls_chacha20.h
  646. $(CC) $(CFLAGS) $(SECTION_CFLAGS) -o $@ $<
  647. tls_x25519.o: tls_x25519.c tls_x25519.h
  648. $(CC) $(CFLAGS) $(SECTION_CFLAGS) -o $@ $<
  649. tls_rng.o: tls_rng.c tls_rng.h tls_sha256.h ucmd_lib.h syscall.h
  650. $(CC) $(CFLAGS) $(SECTION_CFLAGS) -o $@ $<
  651. tls.o: tls.c tls.h tls_sha256.h tls_chacha20.h tls_x25519.h tls_rng.h \
  652. ucmd_lib.h syscall.h
  653. $(CC) $(CFLAGS) $(SECTION_CFLAGS) -o $@ $<
  654. tls_test: tls_test.c tls_sha256.c tls_chacha20.c tls_x25519.c \
  655. tls_sha256.h tls_chacha20.h tls_x25519.h
  656. gcc -O2 -I. -o $@ tls_test.c tls_sha256.c tls_chacha20.c tls_x25519.c
  657. test-crypto: tls_test
  658. ./tls_test
  659. # WPA2-PSK supplicant for the ring-3 `wifi` command (wifi.c is the kernel
  660. # side). Pure freestanding C with host vectors (make test-wpa).
  661. WPA_OBJS = wpa.o wpa_crypto.o
  662. wpa.o: wpa.c wpa.h wpa_crypto.h
  663. $(CC) $(CFLAGS) -Os $(SECTION_CFLAGS) -o $@ $<
  664. wpa_crypto.o: wpa_crypto.c wpa_crypto.h
  665. $(CC) $(CFLAGS) -O2 $(SECTION_CFLAGS) -o $@ $<
  666. ucmd_wifi.o: ucmd_wifi.c ucmd_lib.h syscall.h wpa.h tls_rng.h wifi_cfg.h
  667. ucmd_wifi.elf: ucmd_wifi.o $(WPA_OBJS) tls_rng.o tls_sha256.o ucmd.ld libc.a
  668. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  669. $(OBJCOPY) --strip-all $@ $@
  670. # Top-bar network menu: NIC list, WiFi scan and the WPA2 passphrase prompt.
  671. ucmd_netmenu.o: ucmd_netmenu.c ucmd_lib.h syscall.h ngui.h wifi_cfg.h
  672. $(CC) $(CFLAGS) -Ilibc/include -o $@ $<
  673. ucmd_netmenu.elf: ucmd_netmenu.o ngui.o font_8x16.o $(UFONT_OBJS) ucmd.ld libc.a
  674. $(LD) -T ucmd.ld -z max-page-size=0x100 --gc-sections -nostdlib -m elf_i386 -o $@ $(filter-out ucmd.ld,$^)
  675. $(OBJCOPY) --strip-all $@ $@
  676. wpa_test: wpa_test.c wpa.c wpa_crypto.c wpa.h wpa_crypto.h
  677. gcc -O2 -Wall -Wextra -I. -o $@ wpa_test.c wpa.c wpa_crypto.c
  678. test-wpa: wpa_test
  679. ./wpa_test
  680. ccmp_test: ccmp_test.c ccmp.c ccmp.h
  681. gcc -O2 -Wall -Wextra -I. -o $@ ccmp_test.c
  682. test-ccmp: ccmp_test
  683. ./ccmp_test
  684. # Host image-library tests (no kernel needed). The corpus and expected hashes
  685. # are committed; tools/gen_img_tests.py regenerates them.
  686. IMGTEST_SRCS = img_test.c img.c img_mem.c img_blit.c img_png.c img_bmp.c \
  687. img_gif.c img_gif_anim.c img_jpeg.c img_tga.c img_pnm.c img_ico.c img_pam.c inflate.c
  688. IMGTEST_DEPS = img.h img_internal.h inflate.h testdata/images/expected.h
  689. img_test: $(IMGTEST_SRCS) $(IMGTEST_DEPS)
  690. gcc -O2 -fwrapv -Wall -Wextra -I. -o $@ $(IMGTEST_SRCS)
  691. test-images: img_test
  692. ./img_test
  693. test-images-asan: $(IMGTEST_SRCS) $(IMGTEST_DEPS)
  694. # -fwrapv: the integer IDCT deliberately relies on 32-bit wrap-around.
  695. gcc -O1 -g -fwrapv -fsanitize=address,undefined -I. -o img_test_asan $(IMGTEST_SRCS)
  696. ./img_test_asan
  697. # Host test for the ring-3 allocator. The malloc/free names are renamed so
  698. # the host libc (printf, rand, write) keeps working normally.
  699. HOST_MALLOC_DEFS = -Dmalloc=libc_malloc -Dfree=libc_free \
  700. -Dcalloc=libc_calloc -Drealloc=libc_realloc \
  701. -Dheap_reset=libc_heap_reset
  702. libc/malloc_host.o: libc/malloc.c $(LIBC_HEADERS)
  703. gcc -O2 -Wall -Wextra -Ilibc/include -fno-builtin \
  704. $(HOST_MALLOC_DEFS) -c -o $@ $<
  705. libc/test_host_mem.o: libc/test_host_mem.c
  706. gcc -O2 -Wall -Wextra -c -o $@ $<
  707. malloc_test: libc/test_malloc.c libc/malloc_host.o libc/test_host_mem.o
  708. gcc -O2 -Wall -Wextra -o $@ libc/test_malloc.c \
  709. libc/malloc_host.o libc/test_host_mem.o
  710. libc/stdio_host.o: libc/stdio.c libc/dtoa.h $(LIBC_HEADERS)
  711. gcc -O2 -Wall -Wextra -Ilibc/include -fno-builtin -c -o $@ $<
  712. libc/dtoa_host.o: libc/dtoa.c libc/dtoa.h
  713. gcc -O2 -Wall -Wextra -Ilibc/include -fno-builtin -c -o $@ $<
  714. libc/math_host.o: libc/math.c $(LIBC_HEADERS)
  715. gcc -O2 -Wall -Wextra -Ilibc/include -fno-builtin -c -o $@ $<
  716. libc/div64_host.o: libc/div64.c
  717. gcc -O2 -Wall -Wextra -c -o $@ $<
  718. format_test: libc/test_format.c libc/stdio_host.o libc/dtoa_host.o
  719. gcc -O2 -Wall -Wextra -Wno-format-truncation -Ilibc/include -o $@ \
  720. libc/test_format.c libc/stdio_host.o libc/dtoa_host.o
  721. math_test: libc/test_math.c libc/math_host.o
  722. gcc -O2 -Wall -Wextra -o $@ libc/test_math.c libc/math_host.o -lm
  723. div64_test: libc/test_div64.c libc/div64_host.o
  724. gcc -O2 -Wall -Wextra -o $@ libc/test_div64.c libc/div64_host.o
  725. setjmp_test: libc/test_setjmp.c libc/setjmp.o
  726. gcc -m32 -O2 -Wall -Wextra -Ilibc/include -o $@ \
  727. libc/test_setjmp.c libc/setjmp.o
  728. test-libc: malloc_test format_test math_test div64_test setjmp_test
  729. ./malloc_test
  730. ./format_test
  731. ./math_test
  732. ./div64_test
  733. ./setjmp_test
  734. QJS_HOST_SRCS = $(addprefix $(QJS_DIR)/,quickjs.c cutils.c dtoa.c libregexp.c libunicode.c)
  735. js_test: js_test.c js_mu.c js_mu.h $(QJS_HOST_SRCS) $(wildcard $(QJS_DIR)/*.h)
  736. gcc -O1 -g -w -fsanitize=address,undefined -fno-sanitize=shift -I. -I$(QJS_DIR) -D__nebos__ -DJS_MU_HOST \
  737. -DCONFIG_VERSION='"2026-06-04"' -o $@ js_test.c js_mu.c $(QJS_HOST_SRCS) -lm
  738. test-js: js_test
  739. ./js_test
  740. mkpack: mkpack.c
  741. gcc -O2 -o $@ $<
  742. # Command pack (the system rootfs): the ring-3 command ELFs plus hello and the
  743. # browser/gallery apps, packed into bin/<name>. See mkpack.c, rootfs.h and
  744. # ramfs.h.
  745. FONT_FILES = fonts/sans.ttf fonts/sans-b.ttf fonts/sans-i.ttf \
  746. fonts/sans-bi.ttf fonts/mono.ttf fonts/emoji.ttf
  747. PACK_FILES = $(foreach f,$(UCMDS),bin/$(patsubst ucmd_%,%,$(f))=$(f).elf) \
  748. bin/hello=hello.elf \
  749. bin/browser.app=browser.elf \
  750. bin/gallery.app=gallery.elf \
  751. $(foreach f,$(FONT_FILES),$(f)=$(f))
  752. # `install self` reads the flat kernel from the full pack. The lite/floppy
  753. # pack deliberately omits it (no room on a 1.44 MB disk).
  754. PACK_INSTALL_FILES = install/kernel.bin=kernel.bin
  755. # WiFi firmware (iwl_trans.c): the Intel 7265D/3165 (Chromebook, MVM) and
  756. # the 6200/6300 (ThinkPad X201, DVM). Taken from the host's linux-firmware
  757. # (`.zst` or plain); WIFI_FW_7265D / WIFI_FW_6000 override the search. A
  758. # machine without one still builds: the pack then has no firmware/ entry for
  759. # that card and `wifi` reports it missing.
  760. fw_search = $(firstword $(wildcard \
  761. /usr/lib/firmware/intel/iwlwifi/$(1).zst /usr/lib/firmware/$(1).zst \
  762. /usr/lib/firmware/intel/iwlwifi/$(1) /usr/lib/firmware/$(1) \
  763. /lib/firmware/$(1)))
  764. WIFI_FW_7265D ?= $(call fw_search,iwlwifi-7265D-29.ucode)
  765. WIFI_FW_6000 ?= $(call fw_search,iwlwifi-6000-4.ucode)
  766. WIFI_FW_FILE =
  767. PACK_FW_FILES =
  768. # $(1) = file name in the pack, $(2) = host source.
  769. define wifi_fw_rule
  770. ifneq ($(2),)
  771. WIFI_FW_FILE += firmware/$(1)
  772. PACK_FW_FILES += firmware/$(1)=firmware/$(1)
  773. firmware/$(1): $(2)
  774. @mkdir -p firmware
  775. case "$$<" in *.zst) zstd -q -d -c "$$<" > $$@ ;; *) cp "$$<" $$@ ;; esac
  776. else
  777. $$(info note: $(1) not found; building the pack without it)
  778. endif
  779. endef
  780. $(eval $(call wifi_fw_rule,iwlwifi-7265D-29.ucode,$(WIFI_FW_7265D)))
  781. $(eval $(call wifi_fw_rule,iwlwifi-6000-4.ucode,$(WIFI_FW_6000)))
  782. cmds.pack: $(addsuffix .elf,$(UCMDS)) hello.elf browser.elf gallery.elf \
  783. $(FONT_FILES) $(WIFI_FW_FILE) kernel.bin mkpack
  784. ./mkpack $@ $(PACK_FILES) $(PACK_INSTALL_FILES) $(PACK_FW_FILES)
  785. # The floppy images cannot hold the ~1 MB firmware: they get the same pack
  786. # without firmware/*.
  787. cmds-lite.pack: $(addsuffix .elf,$(UCMDS)) hello.elf browser.elf gallery.elf \
  788. $(FONT_FILES) mkpack
  789. ./mkpack $@ $(PACK_FILES)
  790. # The boot-time rootfs is gzip-compressed; the raw cmds.pack is still what
  791. # cmds-dev/net-cmds send for a runtime replacement. Prefer libdeflate's
  792. # level 12 when it is installed: it saves about 8 KB over gzip -9 on the
  793. # current pack. The high-memory rootfs loader supports up to 2 MB; the
  794. # floppy images use the firmware-less lite pack (rootfs.bin).
  795. CMDS_GZ = $(shell command -v libdeflate-gzip >/dev/null 2>&1 && \
  796. echo "libdeflate-gzip -12 -c" || echo "gzip -9 -n -c")
  797. CMDS_GZ_MAX = 2097152
  798. cmds_lite_gz.bin: cmds-lite.pack
  799. $(CMDS_GZ) $< > $@
  800. cmds_pack_gz.bin: cmds.pack
  801. $(CMDS_GZ) $< > $@
  802. @sz=$$(stat -c%s $@); \
  803. if [ $$sz -gt $(CMDS_GZ_MAX) ]; then \
  804. echo "error: cmds_pack_gz.bin is $$sz bytes; the legacy rootfs cap is $(CMDS_GZ_MAX)"; \
  805. rm -f $@; exit 1; \
  806. fi
  807. mkrootfs: mkrootfs.c rootfs.h
  808. gcc -O2 -o $@ $<
  809. # Rootfs image: one NBROOT1 header sector + the gzip pack (rootfs.h).
  810. # rootfs.bin (the lite pack, no firmware) is appended to the floppy images;
  811. # cmds.img is the 8 MB image flashed into the USB rootfs partition.
  812. rootfs.bin: cmds_lite_gz.bin mkrootfs
  813. ./mkrootfs $@ cmds_lite_gz.bin
  814. # Full NBROOT1 image (header + gzip pack, no partition padding) for the
  815. # network install path. `install self` uses the retained boot image instead.
  816. rootfs-full.bin: cmds_pack_gz.bin mkrootfs
  817. ./mkrootfs $@ cmds_pack_gz.bin
  818. rootfs: cmds.img
  819. # Diagnostic: no WM, boot console stays visible. Rebuild normally with
  820. # `make -B ...` afterwards (the objects carry -DNOWM).
  821. nowm:
  822. $(MAKE) NOWM=1 -B kernel.elf kernel.bin floppy.img usb.img usb-efi.img final.bin
  823. @echo "nowm: WM disabled; flash usb.img or usb-efi.img."
  824. cmds.img: cmds_pack_gz.bin mkrootfs
  825. ./mkrootfs $@ cmds_pack_gz.bin $$(( $(ROOTFS_SECTORS) * 512 ))
  826. payload.o: payload.c payload.h io.h mm.h ramfs.h serial.h vfs.h
  827. $(CC) $(CFLAGS) -o $@ $<
  828. ramfs.o: ramfs.c ramfs.h serial.h inflate.h mm.h
  829. $(CC) $(CFLAGS) -o $@ $<
  830. hello.elf: hello.o
  831. $(LD) -T hello.ld -nostdlib -m elf_i386 -o $@ $<
  832. $(OBJCOPY) --strip-all $@ $@
  833. root.img: browser.elf gallery.elf testdata/browser/demo.html testdata/browser/js.html testdata/browser/jsext.js testdata/images/rgb.bmp
  834. dd if=/dev/zero of=$@ bs=512 count=2880 2>/dev/null
  835. mkfs.fat -F 12 -n "ROOTDISK" $@
  836. echo "Hello from the second floppy!" | mcopy -i $@ - ::HELLO.TXT
  837. echo "This is a test file on drive 1." | mcopy -i $@ - ::TEST.TXT
  838. mcopy -i $@ browser.elf ::BROWSER
  839. mcopy -i $@ gallery.elf ::GALLERY
  840. mcopy -i $@ testdata/browser/demo.html ::DEMO.HTM
  841. mcopy -i $@ testdata/browser/js.html ::JS.HTM
  842. mcopy -i $@ testdata/browser/jsext.js ::JSEXT.JS
  843. mcopy -i $@ testdata/images/rgb.bmp ::PIC.BMP
  844. run: image.bin root.img
  845. $(MAKE) run-floppy
  846. # Four logical CPUs (the Atom 330 topology). UP is still the default so a
  847. # machine without ACPI/MADT boots exactly as before.
  848. run-smp: floppy.img root.img
  849. qemu-system-i386 -M pc -m $(QEMU_MEM) -smp 4 -device pci-ohci -device usb-mouse -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  850. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -smp 4 -device pci-ohci -device usb-mouse -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  851. floppy: floppy.img
  852. usb: usb.img
  853. # Write the dual-boot USB image (legacy BIOS + UEFI) to a stick; prompts
  854. # before destroying anything.
  855. # make flash USB=/dev/sdX FORCE=1 skips the removable-device check.
  856. # make flash FLASH_IMG=usb.img legacy-only image
  857. # The UEFI half needs the mingw toolchain (EFI_CC); the legacy half does not.
  858. FLASH_IMG ?= usb-efi.img
  859. flash: $(FLASH_IMG)
  860. @./flash.sh "$(USB)" "$(FORCE)" "$(FLASH_IMG)"
  861. run-floppy: floppy.img root.img
  862. qemu-system-i386 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  863. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  864. run-usb: usb.img root.img
  865. qemu-system-i386 -M pc -m $(QEMU_MEM) -boot c -device pci-ohci -device usb-mouse -drive file=usb.img,format=raw,if=ide -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  866. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -boot c -device pci-ohci -device usb-mouse -drive file=usb.img,format=raw,if=ide -drive file=root.img,format=raw,if=floppy
  867. # UHCI variant (machines with an Intel/VIA-style controller, and the
  868. # regression test for the UHCI backend of the USB core).
  869. run-uhci: floppy.img root.img
  870. qemu-system-i386 -M pc -m $(QEMU_MEM) -device piix3-usb-uhci -device usb-mouse -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  871. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -device piix3-usb-uhci -device usb-mouse -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  872. # xHCI variant (Braswell/Intel PCH and other USB 3.0-only machines).
  873. run-xhci: floppy.img root.img
  874. qemu-system-i386 -M pc -m $(QEMU_MEM) -device qemu-xhci -device usb-mouse -device usb-kbd -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  875. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -device qemu-xhci -device usb-mouse -device usb-kbd -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  876. # RNDIS variant: QEMU's usb-net is a full-speed RNDIS function. It sits on
  877. # xHCI (QEMU's USB2 root ports), and `-nic none` keeps the PCI e1000 out of
  878. # the way so the phone/tethering link is the active NIC.
  879. run-rndis: floppy.img root.img
  880. qemu-system-i386 -M pc -m $(QEMU_MEM) -nic none -device qemu-xhci -device usb-mouse -device usb-kbd -device usb-net,netdev=n1 -netdev user,id=n1 -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  881. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -nic none -device qemu-xhci -device usb-mouse -device usb-kbd -device usb-net,netdev=n1 -netdev user,id=n1 -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  882. # EHCI variant (USB 2.0 high-speed root ports). usb-storage is high-speed
  883. # and lands on EHCI; the mouse/keyboard are full-speed and use the UHCI
  884. # companion, exercising the multi-controller USB core.
  885. run-ehci: floppy.img root.img
  886. qemu-system-i386 -M pc -m $(QEMU_MEM) -boot a -device usb-ehci,id=ehci0 -device piix3-usb-uhci,id=uhci0 \
  887. -device usb-storage,bus=ehci0.0,drive=usbstick \
  888. -drive if=none,id=usbstick,file=root.img,format=raw \
  889. -device usb-mouse,bus=uhci0.0 -device usb-kbd,bus=uhci0.0 \
  890. -drive file=floppy.img,format=raw,if=floppy 2>/dev/null || \
  891. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -boot a -device usb-ehci,id=ehci0 -device piix3-usb-uhci,id=uhci0 \
  892. -device usb-storage,bus=ehci0.0,drive=usbstick \
  893. -drive if=none,id=usbstick,file=root.img,format=raw \
  894. -device usb-mouse,bus=uhci0.0 -device usb-kbd,bus=uhci0.0 \
  895. -drive file=floppy.img,format=raw,if=floppy
  896. # Passthrough of the real ASIX AX88772 dongle (requires the host's asix
  897. # driver to be unbound and permission on /dev/bus/usb/...; typically run with
  898. # sudo). `-nic none` keeps the QEMU e1000 out of the way so the USB NIC is
  899. # the only netdev.
  900. ASIX_HOST ?= vendorid=0x0b95,productid=0x7720
  901. run-ehci-asix: floppy.img root.img
  902. qemu-system-i386 -M pc -m $(QEMU_MEM) -nic none -device usb-ehci -device usb-host,$(ASIX_HOST) -serial file:/tmp/opencode/serial-asix.log -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  903. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -nic none -device usb-ehci -device usb-host,$(ASIX_HOST) -serial file:/tmp/opencode/serial-asix.log -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  904. run-xhci-asix: floppy.img root.img
  905. qemu-system-i386 -M pc -m $(QEMU_MEM) -nic none -device qemu-xhci -device usb-host,$(ASIX_HOST) -serial file:/tmp/opencode/serial-asix.log -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  906. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -nic none -device qemu-xhci -device usb-host,$(ASIX_HOST) -serial file:/tmp/opencode/serial-asix.log -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  907. # Network variant: a PCI NE2000 (RTL8029, the driver's QEMU match) on QEMU's
  908. # user-mode network (slirp). DHCP/DNS come from slirp, the host is 10.0.2.2
  909. # (e.g. `python3 -m http.server` + `curl http://10.0.2.2:8000/` in a window).
  910. run-net: floppy.img root.img
  911. qemu-system-i386 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -device ne2k_pci,netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080 -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  912. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -device ne2k_pci,netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080 -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  913. # Intel e1000 variant: QEMU's 82540EM exercises the e1000e driver's MAC/DMA
  914. # path. (The X201's 82577LM uses the same registers; only its PCH PHY is
  915. # different.) usb-kbd is there for headless QMP `send-key` typing.
  916. run-e1000: floppy.img root.img
  917. qemu-system-i386 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -device usb-kbd \
  918. -device e1000,netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080 \
  919. -drive file=floppy.img,format=raw,if=floppy \
  920. -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  921. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -device usb-kbd \
  922. -device e1000,netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080 \
  923. -drive file=floppy.img,format=raw,if=floppy \
  924. -drive file=root.img,format=raw,if=floppy
  925. # SATA/AHCI variant: an ICH9 AHCI controller with a test disk on port 0.
  926. # The disk image lives outside the repo and is created on first use; boot
  927. # stays on the floppy (order=a), the SATA disk shows up as sata0.
  928. SATA_IMG ?= /tmp/opencode/nebos-sata.img
  929. run-ahci: floppy.img root.img
  930. @test -f $(SATA_IMG) || truncate -s 512M $(SATA_IMG)
  931. qemu-system-i386 -M pc -m $(QEMU_MEM) -boot order=a -device pci-ohci -device usb-mouse \
  932. -drive file=floppy.img,format=raw,if=floppy \
  933. -drive file=root.img,format=raw,if=floppy \
  934. -device ich9-ahci,id=sata \
  935. -drive file=$(SATA_IMG),format=raw,if=none,id=satadisk \
  936. -device ide-hd,drive=satadisk,bus=sata.0 2>/dev/null || \
  937. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -boot order=a -device pci-ohci -device usb-mouse \
  938. -drive file=floppy.img,format=raw,if=floppy \
  939. -drive file=root.img,format=raw,if=floppy \
  940. -device ich9-ahci,id=sata \
  941. -drive file=$(SATA_IMG),format=raw,if=none,id=satadisk \
  942. -device ide-hd,drive=satadisk,bus=sata.0
  943. # Headless USB HID regression tests (QEMU + python3): cursor movement via
  944. # injected USB mouse reports and keyboard input via injected key events,
  945. # including hotplug. See tools/*.py.
  946. test-usb: floppy.img root.img
  947. python3 tools/qmp_cursor_test.py
  948. python3 tools/qmp_cursor_test.py --uhci
  949. python3 tools/qmp_cursor_test.py --uhci72
  950. python3 tools/qmp_cursor_test.py --hotplug
  951. python3 tools/qmp_cursor_test.py --xhci
  952. python3 tools/qmp_cursor_test.py --ehci
  953. python3 tools/qmp_keyboard_test.py
  954. python3 tools/qmp_keyboard_test.py --hotplug
  955. python3 tools/qmp_keyboard_test.py --xhci
  956. python3 tools/qmp_keyboard_test.py --ehci
  957. # End-to-end installer test: boot the dual-boot USB image as an IDE disk,
  958. # attach the same image as a USB mass-storage source, type `install ide1`
  959. # on the terminal and verify + boot the cloned target.
  960. test-install: usb-efi.img
  961. python3 tools/qmp_install_test.py
  962. scp-final: final.bin
  963. scp final.bin root@192.168.0.136:
  964. ssh root@192.168.0.136 dd if=final.bin of=/dev/fd0 bs=512
  965. scp-root: root.img
  966. scp root.img root@192.168.0.136:
  967. ssh root@192.168.0.136 dd if=root.img of=/dev/fd0 bs=512
  968. SERIAL_DEV ?= /dev/ttyUSB0
  969. SERIAL_BAUD ?= 115200
  970. run-serial:
  971. @echo "Starting serial monitor on $(SERIAL_DEV) at $(SERIAL_BAUD) baud..."
  972. @echo "Type 'serial test' in the nebos terminal."
  973. @echo "Press Ctrl-A Ctrl-X to exit picocom."
  974. picocom $(SERIAL_DEV) --baud $(SERIAL_BAUD)
  975. monitor:
  976. @echo "Watching $(SERIAL_DEV) @ $(SERIAL_BAUD) baud (Ctrl-A Ctrl-X to exit)."
  977. @echo "Each 'make dev' reload prints: NebOS v<version> booted"
  978. picocom $(SERIAL_DEV) --baud $(SERIAL_BAUD)
  979. kexec_send: kexec_send.c
  980. gcc -O2 -o $@ $<
  981. netkexec_send: netkexec_send.c
  982. gcc -O2 -o $@ $<
  983. netmonitor: netmonitor.c
  984. gcc -O2 -o $@ $<
  985. dev: kernel.bin cmds_pack_gz.bin kexec_send
  986. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  987. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  988. echo "Sending kernel.bin + cmds_pack_gz.bin (entry 0x$$entry) via $(SERIAL_DEV) @ $(SERIAL_BAUD)..."; \
  989. ./kexec_send $(SERIAL_DEV) $(SERIAL_BAUD) $$entry kernel.bin cmds_pack_gz.bin
  990. # Kernel-only fast path: the board keeps its running rootfs.
  991. kernel-dev: kernel.bin kexec_send
  992. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  993. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  994. echo "Sending kernel.bin only (entry 0x$$entry) via $(SERIAL_DEV) @ $(SERIAL_BAUD)..."; \
  995. ./kexec_send $(SERIAL_DEV) $(SERIAL_BAUD) $$entry kernel.bin
  996. # Push just the command pack (cmds.pack) to a running board: no kernel
  997. # reload, the /ramfs contents are replaced in place. The board must be idle
  998. # at a prompt (the WM loop auto-detects the transfer).
  999. cmds-dev: cmds.pack kexec_send
  1000. @echo "Sending cmds.pack via $(SERIAL_DEV) @ $(SERIAL_BAUD)..."
  1001. ./kexec_send --payload $(SERIAL_DEV) $(SERIAL_BAUD) cmds.pack
  1002. net-cmds: cmds.pack netkexec_send
  1003. @echo "Sending cmds.pack to $(BOARD_IP):$(NETKEXEC_PORT)..."
  1004. ./netkexec_send --payload $(BOARD_IP) $(NETKEXEC_PORT) cmds.pack
  1005. # Development override: upload the real browser to the board's writable
  1006. # /share; the bin/browser launcher prefers it over the pack copy. The board
  1007. # must be running `websrv`; stop it before browsing HTTP, since the WebDAV
  1008. # server owns the NIC.
  1009. browser-dev: browser.elf
  1010. @echo "Uploading browser.elf to http://$(BOARD_IP):8080/share/BROWSER..."
  1011. curl -f -T browser.elf http://$(BOARD_IP):8080/share/BROWSER
  1012. # gallery follows the same development-override model.
  1013. gallery-dev: gallery.elf
  1014. @echo "Uploading gallery.elf to http://$(BOARD_IP):8080/share/GALLERY..."
  1015. curl -f -T gallery.elf http://$(BOARD_IP):8080/share/GALLERY
  1016. # Browser compatibility ladder: serve testdata/browser/compat so the board
  1017. # or a QEMU guest can open http://<host>:$(COMPAT_PORT)/.
  1018. COMPAT_PORT ?= 8000
  1019. compat-serve:
  1020. @echo "Serving the browser compatibility ladder on port $(COMPAT_PORT)"
  1021. python3 -m http.server -d testdata/browser/compat $(COMPAT_PORT)
  1022. # Show the board's netlog stream (kernel debug + terminal text) like `make
  1023. # monitor` does over serial.
  1024. netmon: netmonitor
  1025. @echo "Listening for netlog on UDP $(NETLOG_PORT) (Ctrl-C to exit)."
  1026. ./netmonitor $(NETLOG_PORT)
  1027. # Push a fresh kernel over Ethernet (the board auto-detects it from its idle
  1028. # loop; no serial and no USB stick involved).
  1029. BOARD_IP ?= 192.168.178.240
  1030. NETLOG_PORT ?= 19290
  1031. NETKEXEC_PORT ?= 19288
  1032. net-dev: kernel.bin cmds_pack_gz.bin netkexec_send
  1033. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  1034. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  1035. echo "Sending kernel.bin + cmds_pack_gz.bin (entry 0x$$entry) to $(BOARD_IP):$(NETKEXEC_PORT)..."; \
  1036. ./netkexec_send $(BOARD_IP) $(NETKEXEC_PORT) 0x$$entry kernel.bin cmds_pack_gz.bin
  1037. # Kernel-only fast path: the board keeps its running rootfs.
  1038. kernel-net-dev: kernel.bin netkexec_send
  1039. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  1040. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  1041. echo "Sending kernel.bin only (entry 0x$$entry) to $(BOARD_IP):$(NETKEXEC_PORT)..."; \
  1042. ./netkexec_send $(BOARD_IP) $(NETKEXEC_PORT) 0x$$entry kernel.bin
  1043. # Persistent update: write P1/P2 on the target disk (P4/data is untouched),
  1044. # then jump into the new kernel. TARGET=auto picks the only non-USB NebOS
  1045. # disk; use NETINSTALL_TARGET=mmc0/sata0/... to override.
  1046. NETINSTALL_TARGET ?= auto
  1047. net-install: kernel.bin rootfs-full.bin netkexec_send
  1048. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  1049. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  1050. echo "Persisting kernel.bin + rootfs-full.bin to $(NETINSTALL_TARGET) on $(BOARD_IP):$(NETKEXEC_PORT)..."; \
  1051. ./netkexec_send --install $(NETINSTALL_TARGET) $(BOARD_IP) $(NETKEXEC_PORT) 0x$$entry kernel.bin rootfs-full.bin
  1052. clean:
  1053. rm -f boot.o vesa_stage.o entry.o kernel.o timer.o switch.o sched.o process.o mm.o kmalloc.o paging.o elf.o tss.o syscall.o sys_wm.o syscall_stub.o screen.o io.o tty.o rtc.o terminal.o wm.o hello.o reboot.o poweroff.o fat.o disk.o serial.o serial_ring_buf.o serial_loop.o vga.o blit.o cpu.o thermal.o it87.o tpec.o ec.o cros_ec.o power_src.o power.o vga_copy.o gfxbench.o gpu.o ati.o cirrus.o intel.o nvidia.o nv50.o radeon.o mtrr.o font_8x8.o font_8x16.o fbtext.o gfx.o display.o mouse.o i2c.o touchpad.o touchpad_gesture.o uhci.o ohci.o ehci.o xhci.o asix.o rndis.o usb.o usbmsc.o usbhid.o lsusb.o panic.o bootcon.o blkdev.o sdhci.o ata.o ahci.o fatdetect.o fatformat.o format.o install.o vfs.o sys_fs.o sys_info.o sys_mem.o inflate.o idle.o kexec.o kexec_tramp.o dbg.o lspci.o peek.o ne2000.o r8168.o e1000e.o netdev.o net.o netcore.o netkexec.o netlog.o dhcp.o dns.o ntp.o tcp.o acpi.o lapic.o smp.o ap_tramp.o ap_tramp.elf ap_tramp.bin ap_tramp_embed.o mbr.o boot.elf kernel.elf mbr.elf boot.bin mbr.bin kernel.bin boot.bin.tmp boot.bin.patched image.bin floppy.img usb.img final.bin root.img hello.elf cmds.pack cmds_pack_gz.bin cmds-lite.pack cmds_lite_gz.bin firmware/*.ucode cmds_pack.o rootfs.bin rootfs-full.bin cmds.img mkrootfs ramfs.o share.o payload.o mkpack uwm_lib.o ngui.o img.o img_mem.o img_blit.o img_png.o img_bmp.o img_gif.o img_jpeg.o img_tga.o img_pnm.o img_ico.o img_pam.o img_gif_anim.o img_file.o browser.o browser_html.o svg_raster.o svg_test uhttp.o browser.elf img_test img_test_asan *.boot.tmp $(addsuffix .o,$(UCMDS)) $(addsuffix .elf,$(UCMDS)) gallery.o gallery.elf $(TLSLIB_OBJS) tls_test kexec_send netkexec_send netmonitor BOOTX64.EFI esp.img usb-efi.img efi/main.o efi/payload.o efi/tramp.o efi/tramp.elf efi/tramp.bin efi/efi_entry.h libc.a libc/*.o malloc_test format_test math_test div64_test setjmp_test js_test js_browser.o js_mu.o $(QJS_OBJS) ufont.o ufont_ttf.o ufont_draw.o ufont_file.o ufont_test ufont_test_asan touchpad_gesture_test ujson_test uhttp_cookie_test chat_login_test chat_login.o ujson.o uhttp_cookie.o iwl_trans.o iwl_mvm.o iwl_dvm.o iwl_fw.o wifi.o ccmp.o ccmp_test wpa.o wpa_crypto.o wpa_test