large restructure
This commit is contained in:
parent
ece330c1e9
commit
382bd0c5e9
3
.gitignore
vendored
3
.gitignore
vendored
@ -9,5 +9,4 @@ cpu/memory.h
|
||||
os.iso
|
||||
disk.img
|
||||
libc/libc.a
|
||||
iso/boot/initrd
|
||||
sysroot
|
||||
iso/boot/initrds
|
||||
|
61
Makefile
61
Makefile
@ -1,20 +1,12 @@
|
||||
PLAT=i386
|
||||
C_SOURCES = $(wildcard kernel/*.c drivers/$(PLAT)/*.c drivers/$(PLAT)/*/*.c kernel/cpu/$(PLAT)/*.c fs/*.c)
|
||||
ASM = $(wildcard kernel/cpu/$(PLAT)/*.asm)
|
||||
S_ASM = $(wildcard kernel/cpu/$(PLAT)/*.s)
|
||||
LIBC_SOURCES = $(wildcard libc/*.c libc/*/*.c)
|
||||
LIBC_HEADERS = $(wildcard libc/*.h libc/*/*.h)
|
||||
OBJ = $(C_SOURCES:.c=.o kernel/cpu/$(PLAT)/boot.o)
|
||||
ASM_OBJ = $(S_ASM:.s=.o)
|
||||
S_ASM_OBJ = $(ASM:.asm=.o)
|
||||
LIBC_OBJ = $(LIBC_SOURCES:.c=.o)
|
||||
CC = $(shell cat psinfo/$(PLAT)/cc.txt)
|
||||
AS = $(shell cat psinfo/$(PLAT)/as.txt)
|
||||
AR = $(shell cat psinfo/$(PLAT)/ar.txt)
|
||||
NASM = $(shell cat psinfo/$(PLAT)/nasm.txt)
|
||||
export PLAT=i386
|
||||
export CC = $(shell cat psinfo/$(PLAT)/cc.txt)
|
||||
export AS = $(shell cat psinfo/$(PLAT)/as.txt)
|
||||
export AR = $(shell cat psinfo/$(PLAT)/ar.txt)
|
||||
export NASM = $(shell cat psinfo/$(PLAT)/nasm.txt)
|
||||
EMU = $(shell cat psinfo/$(PLAT)/emu.txt)
|
||||
GDB = $(shell cat psinfo/$(PLAT)/gdb.txt)
|
||||
CFLAGS = -Isysroot/usr/include -Wextra -Wall -Wno-unused-parameter -g -ffreestanding
|
||||
LINK_OBJ = $(wildcard kernel/kernel.a libc/libc.a cpu/$(PLAT)/boot.o)
|
||||
export CFLAGS = -Wextra -Wall -Wno-unused-parameter -g -ffreestanding
|
||||
QFLAGS = -hda ext2.img -m 2G -boot d -cdrom os.iso -serial vc #-chardev socket,id=s1,port=3000,host=localhost -serial chardev:s1
|
||||
|
||||
.PHONY: sysroot
|
||||
@ -24,40 +16,27 @@ all: os.iso
|
||||
run: os.iso
|
||||
@$(EMU) $(QFLAGS) -monitor stdio
|
||||
|
||||
debug: os.iso kernel/kernel.elf
|
||||
debug: os.iso kernel.elf
|
||||
@$(EMU) -s $(QFLAGS) &
|
||||
@$(GDB) -ex "target remote localhost:1234" -ex "symbol-file kernel/kernel.elf"
|
||||
|
||||
os.iso: kernel/kernel.elf initrd/* initrd/init
|
||||
os.iso: kernel.elf initrd/* initrd/init
|
||||
@cp kernel/kernel.elf iso/boot
|
||||
@cd initrd; tar -f ../iso/boot/initrd.tar -c *
|
||||
@# ruby makeinitrd.rb initrd iso/boot/initrd
|
||||
@grub-mkrescue -o $@ iso
|
||||
@grub-mkrescue -o $@ iso > /dev/null 2>/dev/null
|
||||
|
||||
initrd/init: init/* kernel/start.o
|
||||
@cd init && make
|
||||
initrd/init: kernel/start.o
|
||||
@$(MAKE) -C init
|
||||
@cp init/init initrd/init
|
||||
|
||||
kernel/kernel.elf: $(OBJ) $(ASM_OBJ) $(S_ASM_OBJ) libc/libc.a
|
||||
@$(CC) -z max-page-size=4096 -Xlinker -n -T kernel/cpu/$(PLAT)/linker.ld -o $@ $(CFLAGS) -nostdlib $^ -lgcc
|
||||
.PHONY: kernel.elf
|
||||
|
||||
sysroot: $(LIBC_HEADERS)
|
||||
@mkdir -p sysroot/usr/include
|
||||
@cp -r libc/* sysroot/usr/include
|
||||
@rm -f sysroot/usr/include/libc.a sysroot/usr/include/*.o sysroot/usr/include/*/*.o sysroot/usr/include/*.c sysroot/usr/include/*/*.c
|
||||
|
||||
|
||||
libc/libc.a: $(LIBC_OBJ)
|
||||
@$(AR) rcs $@ $^
|
||||
|
||||
%.o: %.c sysroot
|
||||
@$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
%.o: %.asm
|
||||
@$(NASM) $< -o $@
|
||||
|
||||
%.o: %.s
|
||||
@$(AS) $< -o $@
|
||||
kernel.elf:
|
||||
@$(MAKE) -C kernel
|
||||
@$(MAKE) -C libc
|
||||
@$(CC) -z max-page-size=4096 -Xlinker -n -T kernel/cpu/$(PLAT)/linker.ld -o $@ $(CFLAGS) -nostdlib $(LINK_OBJ) -lgcc
|
||||
|
||||
clean:
|
||||
@rm -rf kernel/*.o drivers/*/*.o drivers/*/*/*.o cpu/*/*.o fs/*.o libc/libc.a kernel/cstart.o cpu/memory.h os.iso */*.elf iso/boot/initrd.tar
|
||||
@$(MAKE) clean -C kernel
|
||||
@$(MAKE) clean -C libc
|
||||
@$(MAKE) clean -C kernel/cpu
|
||||
|
22
kernel/Makefile
Normal file
22
kernel/Makefile
Normal file
@ -0,0 +1,22 @@
|
||||
C_SOURCES = $(wildcard *.c cpu/$(PLAT)/*.c)
|
||||
ASM = $(wildcard cpu/$(PLAT)/*.asm)
|
||||
S_ASM = $(wildcard cpu/$(PLAT)/*.s)
|
||||
OBJ = $(C_SOURCES:.c=.o)
|
||||
ASM_OBJ = $(S_ASM:.s=.o)
|
||||
S_ASM_OBJ = $(ASM:.asm=.o)
|
||||
|
||||
kernel.a: $(OBJ) $(ASM_OBJ) $(S_ASM_OBJ)
|
||||
@$(AR) rcs $@ $^
|
||||
|
||||
%.o: %.c
|
||||
@$(CC) -I../sysroot/usr/include $(CFLAGS) -c $< -o $@
|
||||
|
||||
%.o: %.asm
|
||||
@$(NASM) $< -o $@
|
||||
|
||||
%.o: %.s
|
||||
@$(AS) $< -o $@
|
||||
|
||||
|
||||
clean:
|
||||
@rm -rf *.o cpu/*/*.o
|
22
kernel/cpu/Makefile
Normal file
22
kernel/cpu/Makefile
Normal file
@ -0,0 +1,22 @@
|
||||
PLAT=i386
|
||||
C_SOURCES = $(wildcard $(PLAT)/*.c)
|
||||
ASM = $(wildcard $(PLAT)/*.asm)
|
||||
S_ASM = $(wildcard $(PLAT)/*.s)
|
||||
OBJ = $(C_SOURCES:.c=.o)
|
||||
ASM_OBJ = $(S_ASM:.s=.o)
|
||||
S_ASM_OBJ = $(ASM:.asm=.o)
|
||||
|
||||
cpu.a: $(OBJ) $(ASM_OBJ) $(S_ASM_OBJ)
|
||||
@$(AR) rcs $@ $^
|
||||
|
||||
%.o: %.c
|
||||
@$(CC) -I../../sysroot/usr/include $(CFLAGS) -c $< -o $@
|
||||
|
||||
%.o: %.asm
|
||||
@$(NASM) $< -o $@
|
||||
|
||||
%.o: %.s
|
||||
@$(AS) $< -o $@
|
||||
|
||||
clean:
|
||||
@rm -rf */*.o
|
BIN
kernel/cpu/cpu.a
Normal file
BIN
kernel/cpu/cpu.a
Normal file
Binary file not shown.
@ -1,3 +1,5 @@
|
||||
.extern kmain
|
||||
|
||||
# Declare a multiboot header that marks the program as a kernel.
|
||||
.section .multiboot
|
||||
header_start:
|
||||
|
@ -1,12 +0,0 @@
|
||||
#ifndef PORTS_H
|
||||
#define PORTS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t port_byte_in(uint16_t port);
|
||||
void port_byte_out(uint16_t port,uint8_t data);
|
||||
uint16_t port_word_in(uint16_t port);
|
||||
void port_word_out(uint16_t port,uint16_t data);
|
||||
uint32_t port_long_in(uint16_t port);
|
||||
void port_long_out(uint16_t port,uint32_t data);
|
||||
#endif
|
BIN
kernel/kernel.a
Normal file
BIN
kernel/kernel.a
Normal file
Binary file not shown.
@ -7,12 +7,12 @@
|
||||
#include <stdint.h>
|
||||
#include "cpu/cpu_init.h"
|
||||
#include "vga_err.h"
|
||||
#include "elf.h"
|
||||
#include <elf.h>
|
||||
|
||||
typedef struct {
|
||||
char filename[100];
|
||||
char mode[8];
|
||||
char uid[8];
|
||||
char uid[6];
|
||||
char gid[8];
|
||||
char size[12];
|
||||
char mtime[12];
|
||||
|
12
libc/Makefile
Normal file
12
libc/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
SOURCES = $(wildcard libc/*.c libc/*/*.c)
|
||||
HEADERS = $(wildcard libc/*.h libc/*/*.h)
|
||||
.PHONY: sysroot
|
||||
|
||||
libc.a: $(LIBC_OBJ)
|
||||
@$(AR) rcs $@ $^
|
||||
|
||||
%.o: %.c sysroot
|
||||
@$(CC) -I../sysroot/usr/include $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
@rm -rf *.o libc/libc.a
|
@ -9,4 +9,5 @@ uint16_t port_word_in(uint16_t port);
|
||||
void port_word_out(uint16_t port,uint16_t data);
|
||||
uint32_t port_long_in(uint16_t port);
|
||||
void port_long_out(uint16_t port,uint32_t data);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user