refactor: switch from NASM to FASM

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-02-04 20:18:52 +01:00
parent 32f1956ca2
commit 3fddd705f8
61 changed files with 318 additions and 2516 deletions

View file

@ -11,7 +11,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install build-essential llvm lld nasm mtools
sudo apt-get install build-essential fasm mtools
- name: Build
run: |
make

1
.gitignore vendored
View file

@ -23,3 +23,4 @@ a.out
*.old
/bx_enh_dbg.ini
bochsrc.bxrc
/tmp

View file

@ -1,31 +1,32 @@
.DEFAULT_GOAL := all
TOPDIR := $(CURDIR)
export TOPDIR
TOPDIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
SYSROOTDIR := $(TOPDIR)/sysroot
TOOLSDIR := $(TOPDIR)/tools
SUBDIR := thirdparty lib bin kernel
RM = echo
CLEANFILES += stupid.iso stupid.tar.gz
SUBDIRS := kernel lib bin
.PHONY: docs
docs:
-mkdir -p docs/html
naturaldocs -p docs/config -img docs/img -xi tmp -i . -o HTML docs/html
cp docs/img/favicon.ico docs/html/
TARGET = stupid.iso stupid.tar.gz
.PHONY: all
all: $(TARGET)
GOAL:=install
clean: GOAL:=clean
.PHONY: $(SUBDIRS)
$(SUBDIRS):
@echo "📁 $@"
DESTDIR=$(SYSROOTDIR) $(MAKE) -C $@ $(GOAL)
.PHONY: stupid.iso
stupid.iso:
$(MAKE) all
DESTDIR=$(TOPDIR)/sysroot $(MAKE) install
stupid.iso: $(SUBDIRS)
$(TOPDIR)/tools/create-iso $@ sysroot
.PHONY: stupid.tar.gz
stupid.tar.gz:
$(MAKE) all
DESTDIR=$(TOPDIR)/sysroot $(MAKE) install
stupid.tar.gz: $(SUBDIRS)
tar -czvf $@ sysroot
run: stupid.iso
qemu-system-i386 -cdrom $< -serial stdio
include $(TOPDIR)/share/mk/stupid.subdir.mk
include $(TOPDIR)/share/mk/stupid.clean.mk
.PHONY: clean
clean: $(SUBDIRS)
$(RM) $(TARGET) $(SYSROOTDIR)

View file

@ -1,3 +1,11 @@
NOSUBDIR := 1
SUBDIRS = cmd
include $(TOPDIR)/share/mk/stupid.subdir.mk
TOPGOALS = all clean install
.PHONY: $(SUBDIRS)
$(SUBDIRS):
@echo "📁 bin/$@"
DESTDIR=$(DESTDIR)/bin $(MAKE) -C $@ $(MAKECMDGOALS)
.PHONY: $(TOPGOALS)
$(TOPGOALS): $(SUBDIRS)

5
bin/cmd/Makefile Normal file
View file

@ -0,0 +1,5 @@
all:
clean:
install:

6
bin/cmd/builtins.inc Normal file
View file

@ -0,0 +1,6 @@
builtins:
db 2, 'cd'
db 1, '.'
db 3, 'set'
db 5, 'unset'
db 4, 'exit'

8
bin/cmd/cmd.asm Normal file
View file

@ -0,0 +1,8 @@
format ELF
entry start
include 'builtins.inc'
start:
int 0x2A

View file

@ -9,10 +9,7 @@ Donate:
- <Liberapay at https://liberapay.com/d0p1/>
- <Github Sponsors at https://github.com/sponsors/d0p1s4m4>
- Monero: 85cm3SuAs98dcqXcdiyCNz6hkb5fKwHbtJYr8cyFdAGWKgj8rG3kPENNv1BXVp2HsiaC8otTzxxaEEuUVZQFxrSr7eBY2uw
- Zcash: zs1sqsdn4acrqygvupmhwl5vvzcdjk6fd4p6n3k4nzdey0huq7cwkl2ca7dru8alhhtan47wjes0x9
- Bitcoin: bc1qhpxa0hgj0mjstttkjgg6ees9dj5kadty04kgpp
- Oxen: LDrNKN6iXh98zUZbwa9iGmeuiWbrzU2WTKWwcwMYFSeCj2QACxfyFXNVQyN8QBe61bFgqtykTYpgcaWvf2C1K77KMQ82DaC
- Gridcoin: S8tw8EWXQ6p529kLEniCePceNAFTyc3GKM
About: License

View file

@ -1,17 +1,27 @@
AS = fasm
RM = rm -f
INSTALL = install
KERNEL = vmstupid
SRCS = kernel.asm \
const.inc \
boot/multiboot.inc \
boot/boot.inc \
mm/mm.inc
SRCS = boot/head.s \
boot/gdt.s \
boot/idt.s \
boot/isr.s \
boot/tss.s \
kernel.s \
lib/log.s dev/at/serial.s \
i18n/msg_en.s
INCS = sys/multiboot.inc \
sys/i386/cpuid.inc \
sys/i386/mmu.inc \
sys/i386/registers.inc
.PHONY: all
all: $(KERNEL)
include $(TOPDIR)/share/mk/stupid.kernel.mk
#include $(TOPDIR)/share/mk/stupid.inc.mk
$(KERNEL): $(SRCS)
$(AS) kernel.asm $@
.PHONY: clean
clean:
$(RM) $(KERNEL)
.PHONY: install
install: $(KERNEL)
@ mkdir -p $(DESTDIR)
install $< $(DESTDIR)
.PHONY: all clean

View file

@ -1,4 +0,0 @@
struc console
.init:
endstruc

35
kernel/boot/boot.inc Normal file
View file

@ -0,0 +1,35 @@
ORG 0x100000
ALIGN 4
USE32
INCLUDE 'boot/multiboot.inc'
INCLUDE 'const.inc'
mb_header MultibootHeader MB_FLAGS, mb_header, VIDEO_WIDTH, VIDEO_HEIGHT, VIDEO_DEPTH
_start:
cli
cmp eax, MULTIBOOT_MAGIC
jne hang
; iterate over memory
;
;
xor esi, esi
mov edi, kernel_page_table - KBASE
mov ecx, kernel_page_directory - KBASE
mov cr3, ecx
mov ecx, cr0
hang:
hlt
jmp $-1
; SEGMENT readable writable
boot_struct dd 0x0

View file

@ -1,94 +0,0 @@
;; File: gdt.s
;;
[BITS 32]
%include "sys/i386/mmu.inc"
section .text
; Function: gdt_setup
;
; in:
; none
;
; out:
; none
;
global gdt_setup
gdt_setup:
;; install tss
lea eax, gdt_entries.tss
push eax
extern tss_install
call tss_install
pop eax
;; setup gdt
lgdt [gdt_ptr]
mov eax, cr0
or al, 1
mov cr0, eax
jmp 0x08:.flush_cs
.flush_cs:
mov ax, 0x10 ; data segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
ret
section .data
gdt_ptr:
dw gdt_entries.end - gdt_entries - 1
dd gdt_entries
gdt_entries:
;; null descriptor
dd 0x0
dd 0x0
;; kernel mode code segment
istruc gdt_entry
at gdt_entry.limit_low, dw 0xFFFF
at gdt_entry.base_low, dw 0x0000
at gdt_entry.base_mid, db 0x00
at gdt_entry.access, db 0x9A
at gdt_entry.flags, db 0xCF
at gdt_entry.base_high, db 0x00
iend
;; kernel mode data segment
istruc gdt_entry
at gdt_entry.limit_low, dw 0xFFFF
at gdt_entry.base_low, dw 0x0000
at gdt_entry.base_mid, db 0x00
at gdt_entry.access, db 0x92
at gdt_entry.flags, db 0xCF
at gdt_entry.base_high, db 0x00
iend
;; user mode code segment
istruc gdt_entry
at gdt_entry.limit_low, dw 0xFFFF
at gdt_entry.base_low, dw 0x0000
at gdt_entry.base_mid, db 0x00
at gdt_entry.access, db 0xFA
at gdt_entry.flags, db 0xCF
at gdt_entry.base_high, db 0x00
iend
;; user mode data segment
istruc gdt_entry
at gdt_entry.limit_low, dw 0xFFFF
at gdt_entry.base_low, dw 0x0000
at gdt_entry.base_mid, db 0x00
at gdt_entry.access, db 0xF2
at gdt_entry.flags, db 0xCF
at gdt_entry.base_high, db 0x00
iend
.tss:
times gdt_entry_size db 0
.end:

View file

@ -1,125 +0,0 @@
;; File: head.s
;;
;; About: CPU compatibility
;; /!\ Only work on *486+* for now.
;; - `invlpg` which is not part of 386 ISA.
;;
[BITS 32]
%include "sys/multiboot.inc"
%include "sys/i386/registers.inc"
%include "sys/i386/mmu.inc"
;; Define: MB_HDR_FLAGS
MB_HDR_FLAGS equ MB_HDR_ALIGN | MB_HDR_MEMINFO | MB_HDR_VIDEO
section .multiboot.data
align 4
istruc mb_header
at mb_header.magic, dd MB_HDR_MAGIC
at mb_header.flags, dd MB_HDR_FLAGS
at mb_header.checksum, dd -(MB_HDR_MAGIC + MB_HDR_FLAGS)
; video mode info
at mb_header.mode_type, dd 0
at mb_header.width, dd 1024
at mb_header.height, dd 768
at mb_header.depth, dd 32
iend
section .multiboot.text
;; Function: entry
;; Setup boot page table, map kernel to higher half
;; then jump to <entry_high>
;;
;; in:
;; EAX - Multiboot magic
;; EBX - Multiboot structure
;;
;; out:
;; none
;;
global entry
entry:
;; disable interrupt
cli
;; save boot params
mov edi, eax
mov esi, ebx
;; setup 4MB paging
;; TODO: check if 4MB paging is available
mov eax, cr4
or eax, CR4_PSE
mov cr4, eax
cmp edi, MB_MAGIC
jne .skip_map_multiboot
;; check if multiboot struct is in first 4Mib
;; otherwith add entry in page dir
mov eax, 400000
cmp ebx, eax
jg .map_multiboot
jmp .skip_map_multiboot
.map_multiboot:
;; TODO: for now let's assume data are bellow 4Mib
jmp .end
.skip_map_multiboot:
add esi, KERNBASE
.end:
extern page_directory
mov eax, V2P(boot_page_dir)
mov cr3, eax
;; enable paging
mov eax, cr0
or eax, CR0_PG | CR0_PE | CR0_WP
mov cr0, eax
;; Jump to higher half
lea eax, entry_high
jmp eax ; near jump, indirect
section .text
;; Function: entry_high
;; Invalidate page[0], setup stack then call <kmain>
entry_high:
;; unmap first 4MiB, since it's not needed anymore
mov dword [boot_page_dir], 0
invlpg [0]
;; Setup stack
extern stack_top
mov esp, stack_top
xor ebp, ebp
;; Setup GDT: we "disable" segmentation
extern gdt_setup
call gdt_setup
extern tss_flush
call tss_flush
extern idt_setup
call idt_setup
push esi ; multiboot struct
push edi ; multiboot magic
extern kmain
call kmain
cli
hang:
hlt
jmp hang
section .data
align 0x1000
boot_page_dir:
dd 0 | PDE_P | PDE_W | PDE_PS
times (P2PDE(KERNBASE) - 1) dd 0
dd 0 | PDE_P | PDE_W | PDE_PS
times 0x400 - (boot_page_dir - $$) dd 0

View file

@ -1,57 +0,0 @@
;; File: idt.s
;;
[BITS 32]
%include "sys/i386/cpu.inc"
section .text
idt_set_table:
push ebp
mov ebp, esp
mov ecx, [ebp + 8]
extern isr_list
mov eax, [isr_list + (ecx * 4)]
; offset (low)
mov word [idt_entries + (ecx * 8)], ax
; segment selector (kernel code)
mov word [idt_entries + (ecx * 8) + idt_gate.selector], 0x08
; zero (skip)
; attr: 1 (Present) 00 (DPL) 0 1 (D: 32bits) 110
mov byte [idt_entries + (ecx * 8) + idt_gate.attributes], 0x8E
; offset (high)
shr eax, 16
mov word [idt_entries + (ecx * 8) + idt_gate.offset_high], ax
leave
ret
global idt_setup
idt_setup:
%assign i 0
%rep 32
push dword i
call idt_set_table
add esp, 4
%assign i i+1
%endrep
lidt [idt_ptr]
sti
ret
section .data
align 8
idt_ptr:
dw idt_entries.end-idt_entries-1
dd idt_entries
; variable: idt_entries
align 8
idt_entries:
times 256 dd 0x00000000, 0x00000000
.end:

View file

@ -1,124 +0,0 @@
[BITS 32]
%include "sys/i386/cpu.inc"
%include "base.inc"
%macro ISR_NO_ERR 1
isr%1:
push dword 0
push dword %1
jmp isr_common
%endmacro
%macro ISR_ERR 1
isr%1:
push dword %1
jmp isr_common
%endmacro
%macro ISR_ADDR 1
dd isr%1
%endmacro
section .text
ISR_NO_ERR 0
ISR_NO_ERR 1
ISR_NO_ERR 2
ISR_NO_ERR 3
ISR_NO_ERR 4
ISR_NO_ERR 5
ISR_NO_ERR 6
ISR_NO_ERR 7
ISR_ERR 8
ISR_NO_ERR 9
ISR_ERR 10
ISR_ERR 11
ISR_ERR 12
ISR_ERR 13
ISR_ERR 14
ISR_NO_ERR 15
ISR_NO_ERR 16
ISR_NO_ERR 17
ISR_NO_ERR 18
ISR_NO_ERR 19
ISR_NO_ERR 20
ISR_NO_ERR 21
ISR_NO_ERR 22
ISR_NO_ERR 23
ISR_NO_ERR 24
ISR_NO_ERR 25
ISR_NO_ERR 26
ISR_NO_ERR 27
ISR_NO_ERR 28
ISR_NO_ERR 29
ISR_NO_ERR 30
ISR_NO_ERR 31
%assign i 32
%rep 224
ISR_NO_ERR i
%assign i i+1
%endrep
panic:
LOG msg_interrupt
;htl
;jmp panic
ret
isr_handler:
push ebp
mov ebp, esp
.end:
leave
ret
isr_common:
xchg bx, bx
push ds
push es
push fs
push gs
pusha
mov ax, 0x10 ; data segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
LOG msg_interrupt
;call isr_handler
;extern pic_eoi
;call pic_eoi
popa
pop gs
pop fs
pop es
pop ds
add esp, 8 ; int no & error code
iret
section .data
global isr_list
isr_list:
%assign i 0
%rep 256
ISR_ADDR i
%assign i i+1
%endrep
section .rodata
msg_interrupt db "interrupt", 0xA
db "edi: %x esi: %x ebp: %x esp: %x", 0xA
db "ebx: %x edx: %x ecx: %x eax: %x", 0xA
db "gs: %x fs: %x es: %x ds: %x", 0xA
db "int: %x err: %x eip: %x cs: %x", 0xA
db "flg: %x usp: %x ss: %x", 0x0
file db __FILE__, 0

View file

@ -1,25 +0,0 @@
extern kernel_start
extern kernel_end
extern kernel_size
pmm_check_page_free:
push ebp
mov ebp, esp
leave
ret
pmm_setup_from_multiboot_mmap:
push ebp
mov ebp, esp
push edi
push esi
push ebx
mov eax, [esi + mb_info.mmap_addr]
pop ebx
pop esi
pop edi
leave
ret

106
kernel/boot/multiboot.inc Normal file
View file

@ -0,0 +1,106 @@
MULTIBOOT_HDR_MAGIC = 0x1BADB002
MULTIBOOT_MAGIC = 0x2BADB002
MULTIBOOT_HDR_ALIGN = 0x1
MULTIBOOT_HDR_MEMINFO = 0x2
MULTIBOOT_HDR_VIDEO = 0x4
struc MultibootHeader flags,addr,width,height,depth
{
.magic dd MULTIBOOT_HDR_MAGIC
.flags dd flags
.checksum dd -(MULTIBOOT_HDR_MAGIC + flags)
; address fields (we'll just skip them)
.header_addr dd addr
.load_addr dd 0x100000
.load_end_addr dd _edata - KBASE
.bss_end_addr dd _end - KBASE
.entry_addr dd _start
; Video mode
.mode_type dd 0x0
.width dd width
.height dd height
.depth dd depth
}
struc MultibootData
{
.flags dd ?
; if flags[0] is set
.mem_lower dd ?
.mem_upper dd ?
; if flags[1] is set
.boot_device dd ?
; if flags[2] is set
.cmdline dd ?
; if flags[3] is set
.mods_count dd ?
.mods_addr dd ?
; if flags[4] is set
.syms dd 4 dup ?
; if flags[6] is set
.mmap_length dd ?
.mmap_addr dd ?
; if flags[7] is set
.drives_length dd ?
.drives_addr dd ?
; if flags[8] is set
.config_table dd ?
; if flags[9] is set
.bootloader_name dd ?
; if flags[10] is set
.apm_table dd ?
; if flags[11] is set
.vbe_control_info dd ?
.vbe_mode_info dd ?
.vbe_mode dw ?
.vbe_if_seg dw ?
.vbe_if_off dw ?
.vbe_if_length dw ?
; if flags[12] is set
.fb_addr dq ?
.fb_pitch dd ?
.fb_width dd ?
.fb_height dd ?
.fb_bpp db ?
.fb_type db ?
.fb_misc dw 3 dup ?
}
MULTIBOOT_DATA_MEM = 0x0001
MULTIBOOT_DATA_BOOTDEV = 0x0002
MULTIBOOT_DATA_CMDLINE = 0x0004
MULTIBOOT_DATA_MODULES = 0x0008
MULTIBOOT_DATA_MMAP = 0x0040
MULTIBOOT_DATA_DRIVES = 0x0080
MULTIBOOT_DATA_BOOTLOADER_NAME = 0x0200
MULTIBOOT_DATA_VBE = 0x0800
MULTIBOOT_DATA_FB = 0x1000
struc MultibootMMap
{
.size dd ?
.addr dq ?
.length dq ?
.type dd ?
}
MULTIBOOT_MEMORY_AVAILABLE = 0x1
MULTIBOOT_MEMORY_RESERVED = 0x2
MULTIBOOT_MEMORY_ACPI = 0x3
MULTIBOOT_MEMORY_NVS = 0x4
MULTIBOOT_MEMORY_BADPARAM = 0x5

View file

@ -1,44 +0,0 @@
%include "sys/i386/mmu.inc"
%include "sys/i386/task.inc"
section .text
global tss_install
tss_install:
push ebp
mov ebp, esp
push esi
mov esi, [ebp + 8]
mov eax, tss_size
lea ebx, tss_entry
mov [esi + gdt_entry.limit_low], ax
mov [esi + gdt_entry.base_low], bx
shr eax, 16
mov [esi + gdt_entry.base_mid], al
mov al, 0x9 | (1 << 7)
mov [esi + gdt_entry.access], al
shr ebx, 16
and bl, 0xF
mov [esi + gdt_entry.flags], bl
mov [esi + gdt_entry.base_high], ah
mov dword [tss_entry + tss.ss0], 0x10
extern stack_top
mov dword [tss_entry + tss.esp0], stack_top
leave
ret
global tss_flush
tss_flush:
mov ax, (5 * 8) | 0
ltr ax
ret
section .data
tss_entry:
times tss_size db 0

53
kernel/const.inc Normal file
View file

@ -0,0 +1,53 @@
KBASE = 0xC0000000
PSIZE = 0x1000
; --------- VERSION -------------
VERSION_MAJOR = 1
VERSION_MINOR = 0
; --------- BOOT PARAMS ---------
MB_FLAGS = MULTIBOOT_HDR_ALIGN or MULTIBOOT_HDR_MEMINFO or MULTIBOOT_HDR_VIDEO
VIDEO_WIDTH = 1024
VIDEO_HEIGHT = 768
VIDEO_DEPTH = 32
; --------- Registers ------------
CR0_PE = 0x00000001
CR0_MP = 0x00000002
CR0_EM = 0x00000004
CR0_TS = 0x00000008
CR0_ET = 0x00000010
CR0_NE = 0x00000020
CR0_WP = 0x00010000
CR0_AM = 0x00040000
CR0_NW = 0x20000000
CR0_CD = 0x40000000
CR0_PG = 0x80000000
CR3_PWT = 0x08
CR3_PCD = 0x10
CR4_VME = 0x0000001
CR4_PVI = 0x0000002
CR4_TSD = 0x0000004
CR4_DE = 0x0000008
CR4_PSE = 0x0000010
CR4_PAE = 0x0000020
CR4_MCE = 0x0000040
CR4_PGE = 0x0000080
CR4_PCE = 0x0000100
CR4_OSDXSR = 0x0000200
CR4_OSXMMEXCPT = 0x0000400
CR4_UMIP = 0x0000800
CR4_VMXE = 0x0002000
CR4_SMXE = 0x0004000
CR4_FSGSBASE = 0x0010000
CR4_PCIDE = 0x0020000
CR4_OSXSAVE = 0x0040000
CR4_SMEP = 0x0100000
CR4_SMAP = 0x0200000
CR4_PKE = 0x0400000
CR4_CET = 0x0800000
CR4_PKS = 0x1000000

View file

@ -1,72 +0,0 @@
;; File: cmos.s
;; Real/Time Clock/CMOS RAM
;;
;; > +-------------+------------------------------+
;; > | 0x00 - 0x0D | *Real-time clock information |
;; > +-------------+------------------------------+
;; > | 0x0E | *Diagnostic status byte |
;; > +-------------+------------------------------+
;; > | 0x0F | *Shutdown status byte |
;; > +-------------+------------------------------+
;; > | 0x10 | Diskette drive type byte |
;; > +-------------+------------------------------+
;; > | 0x12 | Fixed disk type byte |
;; > +-------------+------------------------------+
;; > | 0x14 | Equipment byte |
;; > +-------------+------------------------------+
;; > | 0x15 | Low base memory byte |
;; > +-------------+------------------------------+
;; > | 0x16 | High base memory byte |
;; > +-------------+------------------------------+
;; > | 0x17 | Low expansion memory byte |
;; > +-------------+------------------------------+
;; > | 0x18 | High expansion memory byte |
;; > +-------------+------------------------------+
;; > | 0x19 | Disk C extended byte |
;; > +-------------+------------------------------+
;; > | 0x1A | Disk D extended byte |
;; > +-------------+------------------------------+
;; > | 0x2E - 0x2F | CMOS checksum |
;; > +-------------+------------------------------+
;; > | 0x30 | *Low expansion memory byte |
;; > +-------------+------------------------------+
;; > | 0x31 | *High expansion memory byte |
;; > +-------------+------------------------------+
;; > | 0x32 | *Date century byte |
;; > +-------------+------------------------------+
;; > | 0x33 | *Flags |
;; > +-------------+------------------------------+
CMOS_RTC equ 0x00
RTC_SECONDS equ 0x00
RTC_SECOND_ALRM equ 0x01
RTC_MINUTES equ 0x02
RTC_MINUTE_ALRM equ 0x03
RTC_HOURS equ 0x04
RTC_HOUR_ALRM equ 0x05
RTC_WEEKDAY equ 0x06
RTC_DATE_OF_MONTH equ 0x07
RTC_MONTH equ 0x08
RTC_YEAR equ 0x09
RTC_STATUS_REGA equ 0x0A
RTC_STATUS_REGB equ 0x0B
RTC_STATUS_REGC equ 0x0C
RTC_STATUS_REGD equ 0x0D
STATUS_REGA_UIP equ (1 << 7)
STATUS_REGB_PIE equ (1 << 6)
STATUS_REGB_AIE equ (1 << 5)
STATUS_REGB_UIE equ (1 << 4)
STATUS_REGB_SQWE equ (1 << 3)
STATUS_REGB_DM equ (1 << 2)
STATUS_REGB_24H equ (1 << 1)
STATUS_REGB_DSE equ (1 << 0)
CMOS_CENTURY equ 0x32

View file

@ -1,54 +0,0 @@
File: IBM PC/AT
About: I/O Address Map
> +---------------+-------------------------+
> | 0x000 - 0x01F | DMA controller 1 |
> +---------------+-------------------------+
> | 0x020 - 0x03F | 8259A, Primary |
> +---------------+-------------------------+
> | 0x040 - 0x05F | Timer |
> +---------------+-------------------------+
> | 0x060 - 0x06F | Keyboard |
> +---------------+-------------------------+
> | 0x070 - 0x07F | CMOS |
> +---------------+-------------------------+
> | 0x080 - 0x09F | DMA page register |
> +---------------+-------------------------+
> | 0x0A0 - 0x0BF | 8259A, Secondary |
> +---------------+-------------------------+
> | 0x0C0 - 0x0DF | DMA controller 2 |
> +---------------+-------------------------+
> | 0x0F0 | Clear Math Coprocessor |
> +---------------+-------------------------+
> | 0x0F1 | Reset Math Coprocessor |
> +---------------+-------------------------+
> | 0x0F8 - 0x0FF | Math Coprocessor |
> +---------------+-------------------------+
> | 0x1F0 - 0x1F8 | Fixed Disk |
> +---------------+-------------------------+
> | 0x200 - 0x207 | Game I/O |
> +---------------+-------------------------+
> | 0x278 - 0x27F | Parallel printer port 2 |
> +---------------+-------------------------+
> | 0x2F8 - 0x2FF | Serial port 2 |
> +---------------+-------------------------+
> | 0x300 - 0x31F | Prototype card |
> +---------------+-------------------------+
> | 0x360 - 0x363 | PC Network (low) |
> +---------------+-------------------------+
> | 0x368 - 0x36B | PC Network (high) |
> +---------------+-------------------------+
> | 0x378 - 0x37F | Parallel printer port 1 |
> +---------------+-------------------------+
> | 0x380 - 0x38F | SDLC, bisynchronous 2 |
> +---------------+-------------------------+
> | 0x3B0 - 0x3BF | Monochrome Display |
> +---------------+-------------------------+
> | 0x3D0 - 0x3DF | Color Monitor Adapter |
> +---------------+-------------------------+
> | 0x3F0 - 0x3F7 | Diskette controller |
> +---------------+-------------------------+
> | 0x3F8 - 0x3FF | Serial port 1 |
> +---------------+-------------------------+

View file

View file

@ -1,15 +0,0 @@
;; File: pit.s
;; Programmable Interval Timer (8253/8254)
PIT_CHAN_0 equ 0x40
PIT_CHAN_1 equ 0x41
PIT_CHAN_2 equ 0x42
PIT_CMD equ 0x43
CMD_CHANNEL_1 equ (0x1 << 6)
CMD_CHANNEL_2 equ (0x2 << 6)
CMD_READ_BACK equ (0x3 << 6)
CMD_ACCESS_LO equ (0x1 << 4)
CMD_ACCESS_HI equ (0x2 << 4)
CMD_ACCESS_LO_HI equ (0x3 << 4)

View file

@ -1,64 +0,0 @@
section .text
COM1 equ 0x3F8
COM2 equ 0x2F8
COM3 equ 0x3E8
COM4 equ 0x2E8
THR equ 0x0
RBR equ 0x0
IER equ 0x1
IIR equ 0x2
LCR equ 0x3
MCR equ 0x4
LSR equ 0x5
MSR equ 0x7
DLL equ 0x0
DLH equ 0x0
%macro COM_OUT 3
mov dx, %1+%2
mov al, %3
out dx, al
%endmacro
%macro COM_IN 2
mov dx, %1+%2
in al, dx
%endmacro
; Function: serial_init
;
; in:
; none
;
; out:
; none
;
global serial_init
serial_init:
COM_OUT COM1, IER, 0x00
COM_OUT COM1, LCR, 0x80
COM_OUT COM1, DLH, 0x00
COM_OUT COM1, DLL, 0x0C
COM_OUT COM1, LCR, 0x03
ret
; Function: serial_write
;
; in:
; none
;
; out:
; none
;
global serial_write
serial_write:
push ebp
mov ebp, esp
mov ecx, [ebp + 8]
COM_OUT COM1, THR, cl
leave
ret

View file

@ -1,14 +0,0 @@
struc superblock
.devid: resd 1
.size: resd 1
.ninode: resd 1
.fs_type: resd 1
endstruc
struc inode
.devid: resd 1
.size: resd 1
.inode: resd 1s
.access: resd 1
endstruc

View file

@ -1,3 +0,0 @@
%include "i18n/lang.inc"
extern msg_en

View file

@ -1,10 +0,0 @@
struc lang_entry
.code: resb 2
.data: resd 1
.next: resd 1
endstruc
struc msg_table
.hello_world: resd 1
.cpu_exceptions: resd 32
endstruc

View file

@ -1,102 +0,0 @@
; file: msg_en.s
; English strings
%include "i18n/lang.inc"
section .rodata
global lang_en
lang_en:
istruc lang_entry
at lang_entry.code, db "en"
at lang_entry.data, dd msg_en
at lang_entry.next, dd 0
iend
global msg_en
msg_en:
istruc msg_table
at msg_table.hello_world, dd msg_hello_world
at msg_table.cpu_exceptions,
dd msg_int_division_zero
dd msg_int_debug
dd msg_int_nmi
dd msg_int_breakpoint
dd msg_int_overflow
dd msg_int_range_exceeded
dd msg_int_invalid_opcode
dd msg_int_device_not_available
dd msg_int_double_fault
dd msg_int_coproc_segment_overrun
dd msg_int_invalid_tss
dd msg_int_seg_not_present
dd msg_int_stack_segfault
dd msg_int_gpf
dd msg_int_page_fault
dd msg_int_reserved
dd msg_int_fp_exception
dd msg_int_align_check
dd msg_int_machine_check
dd msg_int_simd_exception
dd msg_int_virt_exception
dd msg_int_reserved
dd msg_int_reserved
dd msg_int_reserved
dd msg_int_reserved
dd msg_int_reserved
dd msg_int_reserved
dd msg_int_reserved
dd msg_int_reserved
dd msg_int_reserved
dd msg_int_reserved
dd msg_int_reserved
iend
msg_hello_world:
db "StupidOS v", STUPID_VERSION, " (built with NASM v", __NASM_VER__, " on ", __DATE__, " ", __TIME__, ")", 0
msg_boot_info:
db "Bootloader: %s", 0
msg_pmm_initialized:
db "PMM initialized", 0
err_invalid_boot_magic:
db "[ERROR] Invalid boot magic (got: %x, expected: 0x2BADB002)", 0
err_cannot_map_memory:
db "[ERROR] Can't map memory", 0
warn_no_mmap:
db "[WARN] mmap flag not set", 0
msg_mmap_entry:
db "Memory Map Entry:", 0xA
db 0x9, "Address: (hi): %x (lo): %x", 0xA
db 0x9, "Length: (hi): %x (lo): %x", 0xA
db 0x9, "Type: %x", 0
msg_mem_block:
db "Free Memory:", 0xA
db 0x9, "Address: %x", 0xA
db 0x9, "Length: %x", 0
msg_max_mem:
db "Max memory: %x", 0
msg_bitmap_stored_at:
db "Bitmap stored at: %x", 0
msg_int_division_zero: db "Division by zero", 0x0
msg_int_debug: db "Debug", 0x0
msg_int_nmi: db "Non-maskable interrupt", 0x0
msg_int_breakpoint: db "Breakpoint", 0x0
msg_int_overflow: db "Overflow", 0x0
msg_int_range_exceeded: db "Bound range exceeded", 0x0
msg_int_invalid_opcode: db "Invalid Opcode", 0x0
msg_int_device_not_available: db "Device not available", 0x0
msg_int_double_fault: db "Double fault", 0x0
msg_int_coproc_segment_overrun: db "Coprocessor segment overrun", 0x0
msg_int_invalid_tss: db "Invalid TSS", 0x0
msg_int_seg_not_present: db "Segment not present", 0x0
msg_int_stack_segfault: db "Stack segment fault", 0x0
msg_int_gpf: db "General Protection Fault", 0x0
msg_int_page_fault: db "Page fault", 0x0
msg_int_reserved: db "Reserved", 0x0
msg_int_fp_exception: db "x87 Floating-Point Exception", 0x0
msg_int_align_check: db "Aligment check", 0x0
msg_int_machine_check: db "Machine check", 0x0
msg_int_simd_exception: db "SIMD Floating-Point exception", 0x0
msg_int_virt_exception: db "Virtualization exception", 0x0
msg_int_sec_exception: db "Security exception", 0x0

Binary file not shown.

15
kernel/kernel.asm Normal file
View file

@ -0,0 +1,15 @@
INCLUDE 'boot/boot.inc'
ORG $ + KBASE
INCLUDE 'mm/mm.inc'
kmain:
nop
_edata:
; BSS
rb 0x4000
_end:

View file

@ -1,38 +0,0 @@
; File: kernel.s
[BITS 32]
%include "base.inc"
section .bss
align 16
stack_bottom:
resb 16384
global stack_top
stack_top:
section .text
; Function: kmain
global kmain
kmain:
push ebp
mov ebp, esp
;; TODO: console init
extern serial_init
call serial_init
LOG msg_hello_world
LOG msg_print_boot, esi, edi
int3
;; setup cpu
;; initialize vm
leave
ret
section .rodata
msg_hello_world db "StupidOS v", STUPID_VERSION, " (built with ", __NASM_VER__, " on ", __DATE__, " ", __TIME__, ")", 0
msg_print_boot db "ESI: %x | EDI: %x", 0
file db __FILE__, 0

View file

@ -1,39 +0,0 @@
OUTPUT_ARCH(i386)
ENTRY(entry)
SECTIONS
{
. = 1M;
kernel_start = .;
.multiboot ALIGN(0x1000): {
KEEP(*(.multiboot.data))
KEEP(*(.multiboot.text))
}
. += 0xC0100000;
.text ALIGN(0x1000) : AT(ADDR(.text) - 0xC0000000) {
*(.text)
}
.rodata ALIGN(0x1000) : AT(ADDR(.rodata) - 0xC0000000) {
*(.rodata)
}
.data ALIGN(0x1000) : AT(ADDR(.data) - 0xC0000000) {
*(.data)
}
.bss ALIGN(0x1000) : AT(ADDR(.bss) - 0xC0000000) {
bss_start = .;
*(COMMON)
*(.bss)
bss_end = .;
}
kernel_end = .;
}
kernel_size = kernel_end - kernel_start;

11
kernel/mm/mm.inc Normal file
View file

@ -0,0 +1,11 @@
free_block_head dd 0x0
mm_init:
ret
kernel_page_directory:
dd 0x1000 dup 0x0
kernel_page_table:
dd 0x1000 dup 0x0

7
kernel/mm/stats.inc Normal file
View file

@ -0,0 +1,7 @@
struc VMStat
{
total_page dd 0
free_pages dd 0
used_pages dd 0
}

View file

@ -1,16 +0,0 @@
[BITS 32]
PE_PRESENT equ 1 << 0
PE_WRITABLE equ 1 << 1
PE_USERMODE equ 1 << 2
PE_ACCESSED equ 1 << 5
PE_DIRTY equ 1 << 6
section .bss
align 4096
global page_directory
page_directory:
resb 4096
global boot_page_table
boot_page_table:
resb 4096

View file

@ -1,114 +0,0 @@
; file: pic.s
; <Datasheet at https://pdos.csail.mit.edu/6.828/2005/readings/hardware/8259A.pdf>
[BITS 32]
PIC1_INT_START equ 0x20
PIC2_INT_START equ 0x28
PIC_INT_END equ PIC2_INT_START + 7
PIC1_CMD equ 0x20
PIC1_DATA equ 0x21
PIC2_CMD equ 0xA0
PIC2_DATA equ 0xA1
; Initialization Command Words (ICWs)
ICW1_INIT equ 1 << 4
ICW1_ICW4 equ 1 << 0
ICW1_SINGLE equ 1 << 1
ICW1_INTERVAL4 equ 1 << 2
ICW1_LVL_MODE equ 1 << 3
ICW4_8086_MODE equ 1 << 0
ICW4_AUTO_EOI equ 1 << 1
ICW4_BUF_SLAVE equ 1 << 3
ICW4_BUF_MASTER equ 1 << 3 | 1 << 2
ICW4_SFNM equ 1 << 4
; Operation Command Words (OWCs)
OCW2_EOI equ 1 << 5
section .text
; Function: setup_pic
;
; in:
; none
;
; out:
; none
;
global pic_setup
pic_setup:
push ebp
mov ebp, esp
sub esp, 2
in al, PIC1_DATA
mov [ebp - 2], al
in al, PIC2_DATA
mov [ebp - 1], al
mov al, ICW1_INIT | ICW1_ICW4
out PIC1_CMD, al
out PIC2_CMD, al
mov al, PIC1_INT_START
out PIC1_DATA, al
mov al, PIC2_INT_START
out PIC2_DATA, al
mov al, 4
out PIC1_DATA, al
mov al, 2
out PIC2_DATA, al
mov al, ICW4_8086_MODE
out PIC1_DATA, al
out PIC2_DATA, al
mov al, [ebp - 2]
out PIC1_DATA, al
mov al, [ebp - 1]
out PIC2_DATA, al
leave
ret
; Function: pic_eoi
;
; in:
; none
;
; out:
; none
;
global pic_eoi
pic_eoi:
push ebp
mov ebp, esp
mov al, OCW2_EOI
cmp byte [ebp + 8], PIC1_INT_START
jb .end
cmp byte [ebp + 8], PIC_INT_END
ja .end
cmp byte [ebp + 8], PIC2_INT_START
jb .pic1
out PIC2_CMD, al
jmp .end
.pic1:
out PIC1_CMD, al
.end:
leave
ret
; Function: pic_disable
global pic_disable
pic_disable:
mov al, 0xFF
out PIC1_DATA, al
out PIC2_DATA, al
ret

View file

@ -1,387 +0,0 @@
; File: pmm.s
[BITS 32]
;; XXX: align address to page
%include "base.inc"
%include "sys/multiboot.inc"
extern kernel_size
extern kernel_end
struc bitmap
.length: resd 1
.addr: resd 1
endstruc
section .text
bitmap_count_free_page:
push ebp
mov ebp, esp
push edi
push esi
push ebx
mov edi, [bitmap_info + bitmap.addr]
xor ebx, ebx
.loop:
inc edi
inc ebx
cmp ebx, [bitmap_info]
jb .loop
.end:
pop ebx
pop esi
pop edi
leave
ret
bitmap_mark:
push ebp
mov ebp, esp
push edi
push esi
mov edi, 1
mov eax, [ebp + 8]
and eax, 0x7 ; eax % 8
mov ecx, eax
shl edi, cl
mov eax, [ebp + 8]
shr eax, 0x3 ; eax / 8
mov esi, [bitmap_info + bitmap.addr]
add esi, eax
mov dl, byte [esi]
mov ecx, [ebp + 12]
test ecx, ecx
jz .clear
or edx, edi ; set bit
jmp .end
.clear:
not edi
and edx, edi ; clear bit
.end:
mov byte [esi], dl
pop esi
pop edi
leave
ret
init_bitmap:
push ebp
mov ebp, esp
push edi
mov ecx, [bitmap_info]
mov edi, [bitmap_info + bitmap.addr]
rep stosb
xchg bx, bx
pop edi
leave
ret
bitmap_mark_range_free:
push ebp
mov ebp, esp
push edi
push esi
push ebx
mov edi, [ebp + 8] ; start address
mov esi, [ebp + 12] ; length
xor ebx, ebx ; counter (I know I SHOUD use 'ecx' as counter
; but since the ABI state it's not preserved
; accross function call)
push dword 0 ; bitmap_mark(addr, 0) == clear
.loop:
cmp ebx, esi
jnb .end_loop
add edi, ebx
jc .end_loop ; exit on overflow
push edi
call bitmap_mark
add esp, 4
add ebx, 0x1000 ; add page size
jmp .loop
.end_loop:
add esp, 4
pop ebx
pop esi
pop edi
leave
ret
setup_pmm_mmap:
push ebp
mov ebp, esp
sub esp, 4
push edi
push esi
push ebx
mov edi, [ebp + 8] ; mb_mmap struct addr
mov esi, [ebp + 12] ; mmap length
xor ebx, ebx ; pass
mov [ebp - 4], ebx ; set max addr to 0
.loop:
;; TODO: PAE stuff
;; skip address > 32bit
mov eax, [edi + mb_mmap.addr + 4]
and eax, eax
jnz .next
mov eax, [edi + mb_mmap.length + 4]
and eax, eax
jnz .next
;; check if first pass
and ebx, ebx
jz .first_pass
mov eax, [edi + mb_mmap.type]
and eax, 0x1 ; check if free
jz .next
;;
mov eax, [bitmap_info]
mov ecx, [mb_mmap.length]
cmp eax, ecx
ja .next
cmp ebx, 0x1
jne .third_pass
mov eax, [edi + mb_mmap.addr]
mov [bitmap_info + bitmap.addr], eax
LOG msg_bitmap_stored_at, eax
call init_bitmap ; mark all memory as used
jmp .bitmap_size_already_set
;; TODO: mark as free in bitmap
.third_pass:
push dword [edi + mb_mmap.length]
push dword [edi + mb_mmap.addr]
call bitmap_mark_range_free
add esp, 8
jmp .next
;; first pass then calculate higher address
.first_pass:
LOG msg_mmap_entry, dword [edi + mb_mmap.addr + 4], \
dword [edi + mb_mmap.addr], \
dword [edi + mb_mmap.length + 4], \
dword [edi + mb_mmap.length], \
dword [edi + mb_mmap.type]
mov eax, [edi + mb_mmap.length]
add eax, [edi + mb_mmap.addr]
jnc .no_overflow
mov eax, -1 ; if overflow set eax to (uint32_t)-1
.no_overflow:
mov edx, [ebp - 4]
cmp edx, eax
ja .next
mov [ebp - 4], eax
.next:
mov eax, [edi + mb_mmap.size]
add eax, 0x4
add edi, eax ; jump to next entry
sub esi, eax
jnz .loop
and ebx, ebx
jnz .bitmap_size_already_set
LOG msg_max_mem, dword [ebp - 4]
mov eax, [ebp - 4]
shr eax, 15 ; eax / (4096*8)
mov [bitmap_info], eax
.bitmap_size_already_set:
mov edi, [ebp + 8] ; mb_mmap struct addr
mov esi, [ebp + 12] ; mmap length
inc ebx
cmp ebx, 2
jbe .loop
pop ebx
pop esi
pop edi
leave
ret
setup_pmm_legacy:
push ebp
mov ebp, esp
push edi
push esi
push ebx
xor eax, eax
mov ecx, [ebp + 8]
shl ecx, 0xA ; ecx * 1KiB
mov esi, ecx
LOG msg_mem_block, eax, ecx
mov eax, 0x100000
mov ecx, [ebp + 12]
shl ecx, 0xA ; ecx * 1KiB
mov ebx, ecx
mov edi, eax
add edi, ecx
LOG msg_mem_block, eax, ecx
LOG msg_max_mem, edi
shr edi, 15 ; (edi / (4046*8))
mov dword [bitmap_info], edi
cmp edi, esi
ja .try_high
mov dword [bitmap_info + bitmap.addr], 0
jmp .initialize_bitmap
.try_high:
mov eax, ebx
sub ebx, kernel_size
cmp edi, ebx
ja .err_no_mem
mov dword [bitmap_info + bitmap.addr], kernel_end
.initialize_bitmap:
call init_bitmap
push esi
push dword 0
call bitmap_mark_range_free
push ebx
push dword 0x100000
call bitmap_mark_range_free
xor eax, eax
jmp .end
.err_no_mem:
mov eax, 1
.end:
pop ebx
pop esi
pop edi
leave
ret
global setup_pmm
setup_pmm:
push ebp
mov ebp, esp
push edi
push esi
push ebx
mov edi, [ebp + 8]
mov eax, [edi]
and eax, 0x40 ; (1 << 6)
jz .no_mmap
push dword [edi + mb_info.mmap_length]
push dword [edi + mb_info.mmap_addr]
call setup_pmm_mmap
add esp, 8
jmp .end_mem_detection
.no_mmap:
LOG warn_no_mmap
mov eax, [edi]
and eax, 0x1
jz .err
push dword [edi + mb_info.mem_upper]
push dword [edi + mb_info.mem_lower]
call setup_pmm_legacy
add esp, 8
.end_mem_detection:
;; mark bitmap as used
xor ebx, ebx
mov edi, [bitmap_info + bitmap.addr]
mov esi, [bitmap_info]
push dword 1 ; bitmap_mark(addr, 1) == set
.loop:
cmp ebx, edi
jnb .end_loop
add edi, ebx
push edi
call bitmap_mark
add esp, 4
add ebx, 0x1000
jmp .loop
.end_loop:
add esp, 4 ; previous "push dword 0"
xor eax, eax
jmp .end
.err:
mov eax, 1
.end:
pop ebx
pop esi
pop ebx
leave
ret
global alloc_frames
alloc_frames:
push esp
mov ebp, esp
push edi
push esi
mov edi, [ebp + 8] ; count
pop esi
pop edi
leave
ret
global free_frames
free_frames:
push esp
mov ebp, esp
call bitmap_mark_range_free
leave
ret
section .data
bitmap_info:
istruc bitmap
at bitmap.length, dd 0
at bitmap.addr, dd 0
iend
section .rodata
warn_no_mmap db "[WARN] mmap flag not set", 0
msg_mmap_entry db "Memory Map Entry:", 0xA
db 0x9, "Address: (hi): %x (lo): %x", 0xA
db 0x9, "Length: (hi): %x (lo): %x", 0xA
db 0x9, "Type: %x", 0
msg_mem_block db "Free Memory:", 0xA
db 0x9, "Address: %x", 0xA
db 0x9, "Length: %x", 0
msg_max_mem db "Max memory: %x", 0
msg_dump_x db "dump: %x", 0
msg_bitmap_stored_at db "Bitmap stored at: %x", 0
file db __FILE__, 0

View file

@ -1,70 +0,0 @@
;; File: cpu.inc
;; Structure: idt_gate
;; .offset_low - TODO
;; .selector - TODO
;; .zero - TODO
;; .attributes - TODO
;; .offset_high - TODO
;;
struc idt_gate
.offset_low: resw 1
.selector: resw 1
.zero: resb 1
.attributes: resb 1
.offset_high: resw 1
endstruc
;; About: Gates
;; - Task Gate
;; > 31 23 15 7 0
;; > +----------------|----------------+-----------------|-----------------+
;; > | (NOT USED) | P DPL 0 0 1 0 1 (NOT USED) |
;; > +----------------|----------------+-----------------|-----------------+
;; > | SELECTOR | (NOT USED) |
;; > +----------------|----------------+-----------------|-----------------+
;;
;; - Interrupt Gate
;; > 31 23 15 7 0
;; > +----------------|----------------+-----------------|-----------------+
;; > | OFFSET 31..16 | P DPL 0 1 1 1 0 0 0 0 0 0 0 0 0 |
;; > +----------------|----------------+-----------------|-----------------+
;; > | SELECTOR | OFFSET 15..0 |
;; > +--------------- |----------------+-----------------|-----------------+
;;
;; - Trap Gate
;; > 31 23 15 7 0
;; > +----------------|----------------+-----------------|-----------------+
;; > | OFFSET 31..16 | P DPL 0 1 1 1 1 0 0 0 0 0 0 0 0 |
;; > +----------------|----------------+-----------------|-----------------+
;; > | SELECTOR | OFFSET 15..0 |
;; > +--------------- |----------------+-----------------|-----------------+
struc intframe
;; registers
.edi: resd 1
.esi: resd 1
.ebp: resd 1
.esp: resd 1
.ebx: resd 1
.edx: resd 1
.ecx: resd 1
.eax: resd 1
;;
.gs: resd 1
.fs: resd 1
.es: resd 1
.ds: resd 1
.intno: resd 1
;; by x86 hardware
.err: resd 1
.eip: resd 1
.cs: resd 1
.eflags: resd 1
;; crossring
.useresp: resd 1
.ss: resd 1
endstruc

View file

@ -1,13 +0,0 @@
;; File: cpuid.inc
CPUID_VENDORID equ 0x0
CPUID_GETFEATURES equ 0x1
CPUID_FEAT_EDX_FPU equ 1 << 0
CPUID_FEAT_EDX_VME equ 1 << 1
CPUID_FEAT_EDX_DE equ 1 << 2
CPUID_FEAT_EDX_PSE equ 1 << 3
CPUID_FEAT_EDX_TSC equ 1 << 4
CPUID_FEAT_EDX_MSR equ 1 << 5
CPUID_FEAT_EDX_PAE equ 1 << 6
CPUID_FEAT_EDX_MCE equ 1 << 7

View file

@ -1,91 +0,0 @@
;; File: mmu.inc
;;
;; About: Address Translation
;;
;; Since we don't use segmentation, this is how address translation works
;; > 31 21 11 0
;; > +--------+--------+--------+
;; > | DIR | PAGE | OFFSET |
;; > +--------+--------+--------+
;; > |
;; > v
;; > Page Translation
;; > |
;; > 31 v 0
;; > +--------------------------+
;; > | Pyshical address |
;; > +--------------------------+
;;
;; About: Page Translation
;;
;; > +--------+--------+--------+ +--------+
;; > | DIR | PAGE | OFFSET |-----+ | Phys |
;; > +--------+--------+--------+ +------>| addr |
;; > | | | |
;; > | +----+ +--------+
;; > | Page Dir | +---> Page Frame
;; > | +---------+ | +--------+ |
;; > | | | | | | |
;; > +->| PDE |-+ +->| PTE |-+
;; > | | | | |
;; > +---------+ | +--------+
;; > +----> Page Table
;; >
;;
;; Macro: V2P(addr)
;; Convert Kernel Address to Physical Address
%define V2P(addr) (addr - KERNBASE)
;; Macro: P2V(addr)
;; Convert Physical Address to Kernel Address
%define P2V(addr) (addr + KERNBASE)
%define P2PDE(addr) ((addr >> 22) & 0x3FF)
%define PDE2P(addr) (addr << 22)
%define P2PTE(addr) ((addr >> 12) & 0x3FF)
;; Defines: Page Directory Flags
;; PDE_P - Present
;; PDE_W - Writable
;; PDE_U - User
;; PDE_PWT - Write-Through
;; PDE_PS - 4MiB page
PDE_P equ 1 << 0
PDE_W equ 1 << 1
PDE_U equ 1 << 2
PDE_PWT equ 1 << 3
PDE_PCD equ 1 << 4
PDE_A equ 1 << 5
PDE_D equ 1 << 6
PDE_PS equ 1 << 7
PDE_G equ 1 << 8
;; Defines: Page Table Flags
;; PTE_P - Present
;; PTE_W - Writable
;; PTE_U - User
;; PTE_PWT - Write-Through
;; PTE_PCD - Cache Disable
;; PTE_A - Accessed
;; PTE_D - Dirty
;; PTE_PAT - TODO
;; PTE_G - TODO
PTE_P equ 1 << 0
PTE_W equ 1 << 1
PTE_U equ 1 << 2
PTE_PWT equ 1 << 3
PTE_PCD equ 1 << 4
PTE_A equ 1 << 5
PTE_D equ 1 << 6
PTE_PAT equ 1 << 7
PTE_G equ 1 << 8
struc gdt_entry
.limit_low: resw 1
.base_low: resw 1
.base_mid: resb 1
.access: resb 1
.flags: resb 1
.base_high: resb 1
endstruc

View file

@ -1,126 +0,0 @@
;; File: registers.inc
;; =========================================================================
;; Control Registers
;; =========================================================================
;; Defines: CR0
;; CR0_PE - Protected Mode Enable
;; CR0_MP - Monitor co-processor
;; CR0_EM - x87 FPU Emulation
;; CR0_TS - Task switched
;; CR0_ET - Extension type
;; CR0_NE - Numeric error
;; CR0_WP - Write protect
;; CR0_AM - Alignment mask
;; CR0_NW - Not-write through
;; CR0_CD - Cache disable
;; CR0_PG - Paging
CR0_PE equ 1 << 0
CR0_MP equ 1 << 1
CR0_EM equ 1 << 2
CR0_TS equ 1 << 3
CR0_ET equ 1 << 4
CR0_NE equ 1 << 5
CR0_WP equ 1 << 16
CR0_AM equ 1 << 18
CR0_NW equ 1 << 29
CR0_CD equ 1 << 30
CR0_PG equ 1 << 31
;; Defines: CR3
;; CR3_PWT - Page-level Write-Through
;; CR3_PCD - Page-level Cache Disable
CR3_PWT equ 1 << 3
CR3_PCD equ 1 << 4
;; Defines: CR4
;; CR4_VME - Virtual 8086 Mode Extensions
;; CR4_PVI - Protected-mode Virtual Interrupts
;; CR4_TSD - Time Stamp Disable
;; CR4_DE - Debugging Extensions
;; CR4_PSE - Page Size Extension
;; CR4_PAE - Physical Address Extension
;; CR4_MCE - Machine Check Exception
;; CR4_PGE - Page Global Enabled
;; CR4_PCE - Performance-Monitoring Counter enable
;; CR4_OSFXSR - Operating system support for FXSAVE and FXRSTOR
;; instructions
;; CR4_OSXMMEXCPT - Operating System Support for Unmasked SIMD
;; Floating-Point Excepions
;; CR4_UMIP - User-Mode Instruction Prevention
;; CR4_VMXE - Virtual Machine Extensions Enable
;; CR4_SMXE - Safer Mode Extensions Enable
;; CR4_FSGSBASE -
;; CR4_PCIDE - PCID Enable
;; CR4_OSXSSAVE - XSAVE and Processor Extended States Enable
;; CR4_SMEP - Supervisor Mode Execution Protection Enable
;; CR4_SMAP - Supervisor Mode Access Prevention Enable
;; CR4_PKE - Protection Key Enable
;; CR4_CET - Control-flow Enforcement Technology
;; CR4_PKS - Enable Protection Keys for Supervisor-Mode Pages
CR4_VME equ 1 << 0
CR4_PVI equ 1 << 1
CR4_TSD equ 1 << 2
CR4_DE equ 1 << 3
CR4_PSE equ 1 << 4
CR4_PAE equ 1 << 5
CR4_MCE equ 1 << 6
CR4_PGE equ 1 << 7
CR4_PCE equ 1 << 8
CR4_OSDXSR equ 1 << 9
CR4_OSXMMEXCPT equ 1 << 10
CR4_UMIP equ 1 << 11
CR4_VMXE equ 1 << 13
CR4_SMXE equ 1 << 14
CR4_FSGSBASE equ 1 << 16
CR4_PCIDE equ 1 << 17
CR4_OSXSAVE equ 1 << 18
CR4_SMEP equ 1 << 20
CR4_SMAP equ 1 << 21
CR4_PKE equ 1 << 22
CR4_CET equ 1 << 23
CR4_PKS equ 1 << 24
;; =========================================================================
;; eflags
;; =========================================================================
;; Defines: EFLAGS
;; EFLAGS_CF - Carry flag
;; EFLAGS_PF - Parity flag
;; EFLAGS_AF - Auxiliary flag
;; EFLAGS_ZF - Zero flag
;; EFLAGS_SF - Sign flag
;; EFLAGS_TF - Trap flag
;; EFLAGS_IF - Interrupt enable flag
;; EFLAGS_DF - Direction flag
;; EFLAGS_OF - Overflow flag
;; EFLAGS_IOPL1 - I/O privilege flag
;; EFLAGS_IOPL2 - I/O privilege flag
;; EFLAGS_NT - Nested task flag
;; EFLAGS_RF - Resume flag
;; EFLAGS_VM - Virtual 8086 mode flag
;; EFLAGS_AC - Alignment check
;; EFLAGS_VIF - Virtual Interrupt flag
;; EFLAGS_VIP - Virtual Interrupt pending
;; EFLAGS_ID - CPUID instruction available
EFLAGS_CF equ 1 << 0
EFLAGS_PF equ 1 << 2
EFLAGS_AF equ 1 << 4
EFLAGS_ZF equ 1 << 6
EFLAGS_SF equ 1 << 7
EFLAGS_TF equ 1 << 8
EFLAGS_IF equ 1 << 9
EFLAGS_DF equ 1 << 10
EFLAGS_OF equ 1 << 11
EFLAGS_IOPL1 equ 1 << 12
EFLAGS_IOPL2 equ 1 << 13
EFLAGS_NT equ 1 << 14
EFLAGS_RF equ 1 << 16
EFLAGS_VM equ 1 << 17
EFLAGS_AC equ 1 << 18
EFLAGS_VIF equ 1 << 19
EFLAGS_VIP equ 1 << 20
EFLAGS_ID equ 1 << 21

View file

@ -1,99 +0,0 @@
;; File: task.inc
;;
;; Structure: tss
;;
;; > 31 23 15 7 0
;; > +----------|----------+----------|----------+
;; > 0x64 | I/O map base | 00000000 0000000T |
;; > +----------|----------+----------|----------+
;; > 0x60 | 00000000 00000000 | LDT |
;; > +----------|----------+----------|----------+
;; > 0x5c | 00000000 00000000 | GS |
;; > +----------|----------+----------|----------+
;; > 0x58 | 00000000 00000000 | FS |
;; > +----------|----------+----------|----------+
;; > 0x54 | 00000000 00000000 | DS |
;; > +----------|----------+----------|----------+
;; > 0x50 | 00000000 00000000 | SS |
;; > +----------|----------+----------|----------+
;; > 0x4C | 00000000 00000000 | CS |
;; > +----------|----------+----------|----------+
;; > 0x48 | 00000000 00000000 | ES |
;; > +----------|----------+----------|----------+
;; > 0x44 | EDI |
;; > +----------|----------+----------|----------+
;; > 0x40 | ESI |
;; > +----------|----------+----------|----------+
;; > 0x3C | EBP |
;; > +----------|----------+----------|----------+
;; > 0x38 | ESP |
;; > +----------|----------+----------|----------+
;; > 0x34 | EBX |
;; > +----------|----------+----------|----------+
;; > 0x30 | EDX |
;; > +----------|----------+----------|----------+
;; > 0x2C | ECX |
;; > +----------|----------+----------|----------+
;; > 0x28 | EAX |
;; > +----------|----------+----------|----------+
;; > 0x24 | EFLAGS |
;; > +----------|----------+----------|----------+
;; > 0x20 | EIP |
;; > +----------|----------+----------|----------+
;; > 0x1C | CR3 |
;; > +----------|----------+----------|----------+
;; > 0x18 | 00000000 00000000 | SS2 |
;; > +----------|----------+----------|----------+
;; > 0x14 | ESP2 |
;; > +----------|----------+----------|----------+
;; > 0x10 | 00000000 00000000 | SS1 |
;; > +----------|----------+----------|----------+
;; > 0x0C | ESP1 |
;; > +----------|----------+----------|----------+
;; > 0x08 | 00000000 00000000 | SS0 |
;; > +----------|----------+----------|----------+
;; > 0x04 | ESP0 |
;; > +----------|----------+----------|----------+
;; > 0x00 | 00000000 00000000 | old TSS selector |
;; > +----------|----------+----------|----------+
struc tss
.link: resw 1
resw 1
.esp0: resd 1
.ss0: resw 1
resw 1
.esp1: resd 1
.ss1: resw 1
resw 1
.esp2: resd 1
.ss2: resw 1
resw 1
.cr3: resd 1
.eip: resd 1
.eflags: resd 1
.eax: resd 1
.ecx: resd 1
.edx: resd 1
.ebx: resd 1
.esp: resd 1
.ebp: resd 1
.esi: resd 1
.edi: resd 1
.es: resw 1
resw 1
.cs: resw 1
resw 1
.ss: resw 1
resw 1
.ds: resw 1
resw 1
.fs: resw 1
resw 1
.gs: resw 1
resw 1
.ldtr: resw 1
resw 1
.iopb: resw 1
resw 1
endstruc

View file

@ -1,140 +0,0 @@
; File: multiboot.inc
; Define: MB_HDR_MAGIC
; Multiboot Header Magic
MB_HDR_MAGIC equ 0x1BADB002
; Define: MB_MAGIC
; Multiboot Magic passed by the bootloader.
MB_MAGIC equ 0x2BADB002
; Structure: mb_header
;
; .magic - todo
; .flags - See <flags>
; .checksum - todo
; .aout_kludge - todo
; .mode_type - todo
; .width - todo
; .height - todo
; .depth - todo
struc mb_header
.magic: resd 1
.flags: resd 1
.checksum: resd 1
.aout_kludge: resd 5
.mode_type: resd 1
.width: resd 1
.height: resd 1
.depth: resd 1
endstruc
; Defines: flags
;
; MB_HDR_ALIGN - todo
; MB_HDR_MEMINFO - <mb_info.mem_lower>
; MB_HDR_VIDEO - todo
MB_HDR_ALIGN equ 1 << 0
MB_HDR_MEMINFO equ 1 << 1
MB_HDR_VIDEO equ 1 << 2
; Structure: mb_info
;
; Fields:
; .flags - See <flags>
; .mem_lower - todo
; .mem_upper - todo
; .boot_device - todo
; .
struc mb_info
;; flags
.flags: resd 1
;; flags[0] is set
.mem_lower: resd 1
.mem_upper: resd 1
;; flags[1] is set
.boot_device: resd 1
;; flags[2] is set
.cmdline: resd 1
;; flags[3] is set
.mods_count: resd 1
.mods_addr: resd 1
;; flags[4] || flags[4] is set
.syms: resd 4
;; flags[6] is set
.mmap_length: resd 1
; <mb_info.mmap_length>
; see <mb_mmap>
.mmap_addr: resd 1
;; flags[7] is set
.drives_length: resd 1
.drives_addr: resd 1
;; flags[8] is set
.config_table: resd 1
;; flags[9] is set
.bootloader_name: resd 1
;; flags[10] is set
.apm_table: resd 1
;;
.vbe_control_info: resd 1
.vbe_mode_info: resd 1
.vbe_mode: resw 1
.vbe_interface_seg: resw 1
.vbe_interface_off: resw 1
.vbe_interface_len: resw 1
.framebuffer_addr: resq 1
.framebuffer_pitch: resd 1
.framebuffer_width: resd 1
.framebuffer_height: resd 1
.framebuffer_bpp: resb 1
.framebuffer_type: resb 1
.framebuffer_misc: resw 3
endstruc
; Defines: flags
;
; MB_INFO_MEM - todo
; MB_INFO_BOOTDEV - todo
MB_INFO_MEM equ 1 << 0
MB_INFO_BOOTDEV equ 1 << 1
MB_INFO_CMDLINE equ 1 << 2
MB_INFO_MODULES equ 1 << 3
MB_INFO_MMAP equ 1 << 6
MB_INFO_DRIVES equ 1 << 7
MB_INFO_BOOTLOADER_NAME equ 1 << 9
MB_INFO_VBE equ 1 << 11
MB_INFO_FRAMEBUFFER equ 1 << 12
; Structure: mb_mmap
struc mb_mmap
.size: resd 1
.addr: resq 1
.length: resq 1
.type: resd 1
endstruc
; Defines: types
;
; MB_MEMORY_AVAILABLE - 1
; MB_MEMORY_RESERVED - 2
; MB_MEMORY_ACPI - 3
; MB_MEMORY_NVS - 4
; MB_MEMORY_BADRAM - 5
%define MB_MEMORY_AVAILABLE 1
%define MB_MEMORY_RESERVED 2
%define MB_MEMORY_ACPI 3
%define MB_MEMORY_NVS 4
%define MB_MEMORY_BADRAM 5

View file

@ -1,11 +0,0 @@
[BITS 32]
global syscall_table
syscall_table:
dd 0 ; sys_exit
dd 0 ; sys_fork
dd 0 ; sys_read
dd 0 ; sys_write
dd 0 ; sys_open
dd 0 ; sys_close
.end:

View file

@ -1,46 +0,0 @@
;; File: pmap.s
;; Physical Memory Map
;; Structure: pmap_block
;;
;; .next - pointer to next pmap_block struct
;; .phys_start - start physical address of memory range
;; .phys_end - stop address of memory range
;; .bitmap_size - bitmap size (max: 0xFF0)
;; .last_alloc - last allocated frame in bitmap
;; .bitmap - bitmap array
;;
;; > pmap_block
;; > 0x0000 +-------------+
;; > | next |-----> pmap_block
;; > 0x0004 +-------------+ +----------+
;; > | phys start | | next |----> NULL (0x0)
;; > 0x0008 +-------------+ +----------+
;; > | phys end | | ..... |
;; > 0x000C +-------------+ | ..... |
;; > | bitmap size | | ..... |
;; > 0x000e +-------------+ +----------+
;; > | last alloc |
;; > 0x0010 +-------------+
;; > | bitmap |
;; > 0x???? +-------------+ (bitmap size * 4)
;;
struct pmap_block
.next: resd 1
.phys_start: resd 1
.phys_end: resd 1
.bitmap_size: resw 1
.last_alloc: resw 1
.bitmap:
endstruc
section .text
;; Function: pmap_bootstrap
;;
;; (see pmap_bootstrap.png)
pmap_bootstrap:
push esp
mov esp, ebp
leave
ret

View file

@ -1,60 +0,0 @@
;; File: vm.inc
;; Stupid OS virtual Memory manager
;;
;; About: Memory Management
;;
;; Terminology:
;; VA - Virtual Address
;; PA - Physical Address
;; PDE - Page Directory Entry
;; PTE - Page Table Entry
;;
;; Memory Layout:
;;
;; Virtual Memory above `0xC0000000` is mapped as kernel only <PTE_U> flags
;;
;; > Virtual
;; > 0xFFFFFFFF +---------------+
;; > | |
;; > | Device Memory |
;; > | |
;; > +---------------+
;; > | |
;; > | Kernel Heap |
;; > | |
;; > KERN_END +---------------+
;; > | |
;; > | Stupid Kernel |
;; > | |
;; > 0xC0100000 +---------------+
;; > | I/O Space and |
;; > | phys memory |
;; > | Lower than 1M | kernel mode only
;; > 0xC0000000 +---------------+
;; > | | user mode
;; > | userspace |
;; > | |
;; > 0x00000000 +---------------+
;;
;; Page Frame Allocator
;;
%define K2P(addr) (addr - KERNBASE)
%define P2K(addr) (addr + KERNBASE)
struc vm_kmap
.virt: resd 1
.phys_start: resd 1
.phys_stop: resd 1
.access: resb 1
endstruc
struc vm_map
.pmap: resd 1
endstruc
struc
.directory: resd 1
.ref_count: resd 1
endstruc

View file

@ -1,3 +1,11 @@
SUBDIR = base crypto
SUBDIRS = crypto
include $(TOPDIR)/share/mk/stupid.subdir.mk
TOPGOALS = all clean install
.PHONY: $(SUBDIRS)
$(SUBDIRS):
@echo "📁 lib/$@"
DESTDIR=$(DESTDIR)/lib $(MAKE) -C $@ $(MAKECMDGOALS)
.PHONY: $(TOPGOALS)
$(TOPGOALS): $(SUBDIRS)

View file

@ -1,6 +0,0 @@
LIB = base
SRCS = log.s
INCS = base.inc
include $(TOPDIR)/share/mk/stupid.lib.mk
#include $(TOPDIR)/share/mk/stupid.inc.mk

View file

@ -1,26 +0,0 @@
; file: base.inc
extern log_impl
; macro: LOG
;
; example:
; (start code)
; LOG msg_boot_info, eax
; (end)
%macro LOG 1-*
%ifdef DEBUG
%rep %0
%rotate -1
push %1
%endrep
push file
call log_impl
add esp, 4
%rep %0
add esp, 4
%endrep
%endif
%endmacro

View file

@ -1,158 +0,0 @@
; file: log.s
[BITS 32]
%ifdef __KERNEL__
extern serial_write
%endif
section .text
; Function: putstr
;
putstr:
push ebp
mov ebp, esp
push edi
mov edi, [ebp + 8]
.loop:
mov eax, [edi]
cmp al, 0
je .end
push eax
%ifdef __KERNEL__
call serial_write
%else
%endif
add esp, 4
inc edi
jmp .loop
.end:
pop edi
leave
ret
; Function: puthex
;
puthex:
push ebp
mov ebp, esp
push edi
push esi
mov edi, [ebp + 8] ; number
mov eax, hexprefix
push hexprefix
call putstr
add esp, 4
mov edx, 0xF
mov ecx, 0x8
mov esi, buffer
.loop:
rol edi, 4
mov eax, edi
and eax, edx
mov al, [digits + eax]
mov [esi], al
inc esi
dec ecx
jnz .loop
mov eax, buffer
push eax
call putstr
add esp, 4
pop esi
pop edi
leave
ret
; Function: log_impl
;
global log_impl
log_impl:
push ebp
mov ebp, esp
push edi
push esi
push ebx
mov eax, [ebp + 8]
push eax
call putstr
add esp, 4
%ifdef __KERNEL__
mov eax, ':'
push eax
call serial_write
add esp, 4
%else
%endif
mov edi, [ebp + 12]
mov esi, 12
.loop:
mov eax, [edi]
cmp al, 0
je .end
cmp al, '%'
jne .putchar
inc edi
mov eax, [edi]
cmp al, '%'
je .next
cmp al, 'x'
jne .check_s
add esi, 4
mov ebx, ebp
add ebx, esi
mov eax, [ebx]
push eax
call puthex
add esp, 4
jmp .next
.check_s:
cmp al, 's'
jne .unknown_format
add esi, 4
mov ebx, ebp
add ebx, esi
mov eax, [ebx]
push eax
call putstr
add esp, 4
jmp .next
.unknown_format:
mov al, '?'
.putchar:
push eax
%ifdef __KERNEL__
call serial_write
%else
;; TODO
%endif
add esp, 4
.next:
inc edi
jmp .loop
.end:
;; print new line
%ifdef __KERNEL__
mov al, 0xA
push eax
call serial_write
add esp, 4
%else
%endif
pop ebx
pop esi
pop edi
leave
ret
digits db '0123456789ABCDEF'
hexprefix db '0x', 0
buffer db '00000000', 0

View file

@ -1,4 +1,5 @@
LIB = crypto
SRCS = hash/sha256.s
all:
include $(TOPDIR)/share/mk/stupid.lib.mk
clean:
install:

View file

@ -1,5 +0,0 @@
# File: stupid.clean.mk
#
clean:
$(RM) $(CLEANFILES)

View file

@ -1,9 +0,0 @@
include $(TOPDIR)/share/mk/stupid.own.mk
ifdef INCS
install::
$(INSTALL) -d $(DESTDIR)$(INCSDIR)
$(INSTALL) $^ $(DESTDIR)$(INCSDIR)
endif

View file

@ -1,45 +0,0 @@
# File: stupid.kernel.mk
#
include $(TOPDIR)/share/mk/stupid.own.mk
ifdef KERNEL
KERNBASE ?= 0xC0000000
ASFLAGS += -D__KERNEL__ -I$(TOPDIR)/kernel -DKERNBASE=$(KERNBASE) \
-I$(TOPDIR)/lib/base
OBJS = $(addsuffix .o, $(basename $(SRCS)))
OBJS-dbg = $(addsuffix .dbg.o, $(basename $(SRCS)))
CLEANFILES += $(KERNEL) $(KERNEL)-dbg $(OBJS) $(OBJS-dbg)
$(KERNEL): $(OBJS)
$(LD) -T $(TOPDIR)/kernel/linker.ld -nostdlib -o $@ $^
$(KERNEL)-dbg: $(OBJS-dbg)
$(LD) -T $(TOPDIR)/kernel/linker.ld -nostdlib -o $@ $^
%.o: %.s
$(AS) $(ASFLAGS) -o $@ $<
%.dbg.o: %.s
$(AS) $(ASFLAGS) $(ASDBGFLAGS) -o $@ $<
lib/%.o: ../lib/base/%.s
@$(MKCWD)
$(AS) $(ASFLAGS) -o $@ $<
lib/%.dbg.o: ../lib/base/%.s
@$(MKCWD)
$(AS) $(ASFLAGS) $(ASDBGFLAGS) -o $@ $<
all: $(KERNEL) $(KERNEL)-dbg
install:: $(KERNEL) $(KERNEL)-dbg
$(INSTALL) -d $(DESTDIR)/
$(INSTALL) $^ $(DESTDIR)/
endif
include $(TOPDIR)/share/mk/stupid.clean.mk

View file

@ -1,37 +0,0 @@
# File: stupid.lib.mk
# Support for building libraries
include $(TOPDIR)/share/mk/stupid.own.mk
ifdef LIB
CLEANFILES += lib$(LIB).a
ifdef SRCS
OBJS += $(addsuffix .o, $(basename $(SRCS)))
CLEANFILES += $(OBJS)
lib$(LIB).a: $(OBJS)
$(AR) rcs $@ $^
else
CLEANFILES += $(LIB).o
lib$(LIB).a: $(LIB).o
$(AR) rcs $@ $^
endif
all: lib$(LIB).a
install:: lib$(LIB).a
$(INSTALL) -d $(DESTDIR)$(LIBDIR)
$(INSTALL) $< $(DESTDIR)$(LIBDIR)
endif
include $(TOPDIR)/share/mk/stupid.clean.mk
include $(TOPDIR)/share/mk/stupid.sys.mk

View file

@ -1,33 +0,0 @@
# File: stupid.own.mk
# Define common variables
ifndef _STUPID_OWN_MK_
_STUPID_OWN_MK_=1
.DEFAULT_GOAL := all
BINDIR = /bin
LIBDIR = /lib
CC = clang -target i386-none-elf
CXX = clang++ -target i386-none-elf
AS = nasm
LD = ld.lld
PLSCC = plsc
OBJCOPY = llvm-objcopy
OBJDUMP = llvm-objdump
INSTALL = install
MKCWD = mkdir -p $(@D)
TARGETS = all clean install
.PHONY: $(TARGETS)
EXTRAFLAGS = -DSTUPID_VERSION="\"0.0\"" -D__STUPID__
CFLAGS += -Wall -Werror -Wextra $(EXTRAFLAGS)
CXXFLAGS += -Wall -Werror -Wextra $(EXTRAFLAGS)
ASFLAGS += -felf -I$(TOPDIR)/lib $(EXTRAFLAGS)
ASDBGFLAGS += -F dwarf -g -DDEBUG
endif

View file

@ -1,45 +0,0 @@
# File: stupid.prog.mk
# Building programs from source files
#
# targets:
# - all:
# build the program and its manual page.
# - clean:
# remove the program and any object files.
# - install:
# install the program and its manual page.
include $(TOPDIR)/share/mk/stupid.own.mk
ifdef PROG
CLEANFILES += $(PROG)
ifdef SRCS
OBJS += $(addsuffix .o, $(basename $(SRCS)))
CLEANFILES += $(OBJS)
$(PROG): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDADD)
else
CLEANFILES += $(PROG).o
$(PROG): $(PROG).o
$(CC) $(CFLAGS) -o $@ $< $(LDADD)
endif
all: $(PROG)
install:: $(PROG)
$(INSTALL) -d $(DESTDIR)$(LIBDIR)
$(INSTALL) $< $(DESTDIR)$(LIBDIR)
endif
include $(TOPDIR)/share/mk/stupid.clean.mk
include $(TOPDIR)/share/mk/stupid.sys.mk

View file

@ -1,20 +0,0 @@
# File: stupid.subdir.mk
# Targets for building subdirectories
.DEFAULT_GOAL := all
TOPGOALS = all clean install
ifndef NOSUBDIR
.PHONY: $(SUBDIR)
$(SUBDIR):
$(MAKE) -C $@ $(MAKECMDGOALS)
$(TOPGOALS): $(SUBDIR)
else
# ensure target exist
$(TOPGOALS):
endif

View file

@ -1,19 +0,0 @@
# File: stupid.sys.mk
%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS)
%.o: %.cc
$(CXX) -c -o $@ $< $(CXXFLAGS)
%.o: %.cpp
$(CXX) -c -o $@ $< $(CXXFLAGS)
%.o: %.cxx
$(CXX) -c -o $@ $< $(CXXFLAGS)
%.o: %.C
$(CXX) -c -o $@ $< $(CXXFLAGS)
%.o: %.s
$(AS) $(ASFLAGS) -o $@ $<

3
thirdparty/Makefile vendored
View file

@ -1,3 +0,0 @@
NOSUBDIR := 1
include $(TOPDIR)/share/mk/stupid.subdir.mk

View file

@ -12,12 +12,6 @@ menuentry "StupidOS" {
boot
}
menuentry "StupidOS (debug)" {
hashsum --hash sha256 --check /boot/hashfile --prefix /
multiboot /vmstupid-dbg "lang=en"
boot
}
EOF
)
@ -25,7 +19,6 @@ gen_iso_file() {
mkdir -p "$2/boot/grub"
echo "$grub_config" > "$2/boot/grub/grub.cfg"
sha256sum "$2/vmstupid" > "$2/boot/hashfile"
sha256sum "$2/vmstupid-dbg" >> "$2/boot/hashfile"
grub-mkrescue -o $1 $2
}