commit 25405a7c11ddf5c34e39f962c41289078c7d77ab Author: xamidev <121681048+xamidev@users.noreply.github.com> Date: Sat May 18 22:06:31 2024 +0200 First commit: add folder structure, make process, kernel main function, base for framebuffer driver diff --git a/README.md b/README.md new file mode 100644 index 0000000..4a70cfc --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# blankos32 + +WIP (framebuffer driver) diff --git a/bochslog.txt b/bochslog.txt new file mode 100644 index 0000000..ee6056e --- /dev/null +++ b/bochslog.txt @@ -0,0 +1,275 @@ +00000000000i[ ] Bochs x86 Emulator 2.7 +00000000000i[ ] Built from SVN snapshot on August 1, 2021 +00000000000i[ ] Timestamp: Sun Aug 1 10:07:00 CEST 2021 +00000000000i[ ] System configuration +00000000000i[ ] processors: 1 (cores=1, HT threads=1) +00000000000i[ ] A20 line support: yes +00000000000i[ ] IPS is set to 1000000 +00000000000i[ ] CPU configuration +00000000000i[ ] SMP support: yes, quantum=16 +00000000000i[ ] level: 6 +00000000000i[ ] APIC support: xapic +00000000000i[ ] FPU support: yes +00000000000i[ ] MMX support: yes +00000000000i[ ] 3dnow! support: yes +00000000000i[ ] SEP support: yes +00000000000i[ ] SIMD support: sse2 +00000000000i[ ] XSAVE support: no +00000000000i[ ] AES support: no +00000000000i[ ] SHA support: no +00000000000i[ ] MOVBE support: no +00000000000i[ ] ADX support: no +00000000000i[ ] x86-64 support: yes +00000000000i[ ] 1G paging support: no +00000000000i[ ] MWAIT support: yes +00000000000i[ ] VMX support: 1 +00000000000i[ ] SVM support: no +00000000000i[ ] Optimization configuration +00000000000i[ ] RepeatSpeedups support: yes +00000000000i[ ] Fast function calls: yes +00000000000i[ ] Handlers Chaining speedups: no +00000000000i[ ] Devices configuration +00000000000i[ ] PCI support: i440FX i430FX i440BX +00000000000i[ ] Network devices support: NE2000 E1000 +00000000000i[ ] Sound support: SB16 ES1370 +00000000000i[ ] USB support: UHCI OHCI EHCI xHCI +00000000000i[ ] VGA extension support: vbe cirrus voodoo +00000000000i[IMG ] Disk image modules +00000000000i[IMG ] flat concat sparse dll growing undoable volatile vpc +00000000000i[IMG ] vmware3 vmware4 vbox vvfat +00000000000i[NETCTL] Networking modules +00000000000i[NETCTL] null vde vnet linux socket tuntap slirp +00000000000i[SNDCTL] Sound drivers +00000000000i[SNDCTL] dummy oss file alsa sdl +00000000000i[USBCTL] Pluggable USB devices +00000000000i[USBCTL] mouse tablet keypad keyboard floppy disk cdrom printer +00000000000i[USBCTL] hub +00000000000i[MEM0 ] allocated memory at 0x7f1f95ddd010. after alignment, vector=0x7f1f95dde000 +00000000000i[MEM0 ] 32.00MB +00000000000i[MEM0 ] mem block size = 0x00020000, blocks=256 +00000000000i[MEM0 ] rom at 0xffff0000/65536 ('/usr/share/bochs/BIOS-bochs-legacy') +00000000000i[CPU0 ] WARNING: 3DNow! is not implemented yet ! +00000000000i[DEV ] will paste characters every 100 iodev timer ticks +00000000000i[ ] lt_dlhandle is 0x55a4d7248350 +00000000000i[PLUGIN] loaded plugin libbx_soundalsa.so +00000000000i[WAVOUT] ALSA: opened default PCM output device +00000000000i[WAVOUT] changed sample rate to 44101 +00000000000i[ ] lt_dlhandle is 0x55a4d79fe0f0 +00000000000i[PLUGIN] loaded plugin libbx_pci.so +00000000000i[ ] lt_dlhandle is 0x55a4d7248430 +00000000000i[PLUGIN] loaded plugin libbx_pci2isa.so +00000000000i[ ] lt_dlhandle is 0x55a4d71c65f0 +00000000000i[PLUGIN] loaded plugin libbx_usb_uhci.so +00000000000i[ ] lt_dlhandle is 0x55a4d72628f0 +00000000000i[PLUGIN] loaded plugin libbx_acpi.so +00000000000i[ ] lt_dlhandle is 0x55a4d71c59f0 +00000000000i[PLUGIN] loaded plugin libbx_hpet.so +00000000000i[ ] lt_dlhandle is 0x55a4d7a088a0 +00000000000i[PLUGIN] loaded plugin libbx_cmos.so +00000000000i[ ] lt_dlhandle is 0x55a4d7a090b0 +00000000000i[PLUGIN] loaded plugin libbx_dma.so +00000000000i[ ] lt_dlhandle is 0x55a4d7a09a20 +00000000000i[PLUGIN] loaded plugin libbx_pic.so +00000000000i[ ] lt_dlhandle is 0x55a4d7a0a1e0 +00000000000i[PLUGIN] loaded plugin libbx_pit.so +00000000000i[ ] lt_dlhandle is 0x55a4d7a0ac00 +00000000000i[PLUGIN] loaded plugin libbx_vga.so +00000000000i[ ] lt_dlhandle is 0x55a4d7a2c240 +00000000000i[PLUGIN] loaded plugin libbx_floppy.so +00000000000i[ ] lt_dlhandle is 0x55a4d7a2ca80 +00000000000i[PLUGIN] loaded plugin libbx_ioapic.so +00000000000i[ ] lt_dlhandle is 0x55a4d7a2d290 +00000000000i[PLUGIN] loaded plugin libbx_keyboard.so +00000000000i[ ] lt_dlhandle is 0x55a4d7a2db90 +00000000000i[PLUGIN] loaded plugin libbx_harddrv.so +00000000000i[ ] lt_dlhandle is 0x55a4d7a2fc60 +00000000000i[PLUGIN] loaded plugin libbx_pci_ide.so +00000000000i[PLUGIN] init_dev of 'pci' plugin device by virtual method +00000000000i[DEV ] i440FX PMC present at device 0, function 0 +00000000000i[PLUGIN] init_dev of 'pci2isa' plugin device by virtual method +00000000000i[DEV ] PIIX3 PCI-to-ISA bridge present at device 1, function 0 +00000000000i[PLUGIN] init_dev of 'cmos' plugin device by virtual method +00000000000i[CMOS ] Using local time for initial clock +00000000000i[CMOS ] Setting initial clock to: Sat May 18 22:03:59 2024 (time0=1716062639) +00000000000i[PLUGIN] init_dev of 'dma' plugin device by virtual method +00000000000i[DMA ] channel 4 used by cascade +00000000000i[PLUGIN] init_dev of 'pic' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'pit' plugin device by virtual method +00000000000i[PIT ] PIT using realtime synchronisation method +00000000000i[PLUGIN] init_dev of 'vga' plugin device by virtual method +00000000000i[MEM0 ] Register memory access handlers: 0x0000000a0000 - 0x0000000bffff +00000000000i[VGA ] interval=200000, mode=realtime +00000000000i[VGA ] VSYNC using realtime mode +00000000000i[MEM0 ] Register memory access handlers: 0x0000e0000000 - 0x0000e0ffffff +00000000000i[BXVGA ] VBE Bochs Display Extension Enabled +00000000000i[MEM0 ] rom at 0xc0000/38400 ('/usr/share/bochs/VGABIOS-lgpl-latest') +00000000000i[PLUGIN] init_dev of 'floppy' plugin device by virtual method +00000000000i[DMA ] channel 2 used by Floppy Drive +00000000000i[FLOPPY] Using boot sequence cdrom, none, none +00000000000i[FLOPPY] Floppy boot signature check is enabled +00000000000i[PLUGIN] init_dev of 'acpi' plugin device by virtual method +00000000000i[DEV ] ACPI Controller present at device 1, function 3 +00000000000i[PLUGIN] init_dev of 'hpet' plugin device by virtual method +00000000000i[HPET ] initializing HPET +00000000000i[MEM0 ] Register memory access handlers: 0x0000fed00000 - 0x0000fed003ff +00000000000i[PLUGIN] init_dev of 'ioapic' plugin device by virtual method +00000000000i[IOAPIC] initializing I/O APIC +00000000000i[MEM0 ] Register memory access handlers: 0x0000fec00000 - 0x0000fec00fff +00000000000i[IOAPIC] IOAPIC enabled (base address = 0xfec00000) +00000000000i[PLUGIN] init_dev of 'keyboard' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'harddrv' plugin device by virtual method +00000000000i[HD ] CD on ata0-0: 'os.iso' +00000000000i[CD1 ] load cdrom with path='os.iso' +00000000000i[CD1 ] Opening image file as a cd. +00000000000i[HD ] Media present in CD-ROM drive +00000000000i[HD ] Capacity is 237 sectors (0.46 MB) +00000000000i[PLUGIN] init_dev of 'pci_ide' plugin device by virtual method +00000000000i[DEV ] PIIX3 PCI IDE controller present at device 1, function 1 +00000000000i[PLUGIN] init_dev of 'unmapped' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'speaker' plugin device by virtual method +00000000000i[PCSPK ] Using lowlevel sound support for output +00000000000i[PLUGIN] init_dev of 'iodebug' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'parallel' plugin device by virtual method +00000000000i[PAR ] parallel port 1 at 0x0378 irq 7 +00000000000i[PLUGIN] init_dev of 'biosdev' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'serial' plugin device by virtual method +00000000000i[SER ] com1 at 0x03f8 irq 4 (mode: null) +00000000000i[PLUGIN] init_dev of 'extfpuirq' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'gameport' plugin device by virtual method +00000000000i[PLUGIN] init_dev of 'usb_uhci' plugin device by virtual method +00000000000i[DEV ] USB UHCI present at device 1, function 2 +00000000000i[UHCI ] USB UHCI initialized +00000000000i[PLUGIN] register state of 'pci' plugin device by virtual method +00000000000i[PLUGIN] register state of 'pci2isa' plugin device by virtual method +00000000000i[PLUGIN] register state of 'cmos' plugin device by virtual method +00000000000i[PLUGIN] register state of 'dma' plugin device by virtual method +00000000000i[PLUGIN] register state of 'pic' plugin device by virtual method +00000000000i[PLUGIN] register state of 'pit' plugin device by virtual method +00000000000i[PLUGIN] register state of 'vga' plugin device by virtual method +00000000000i[PLUGIN] register state of 'floppy' plugin device by virtual method +00000000000i[PLUGIN] register state of 'unmapped' plugin device by virtual method +00000000000i[PLUGIN] register state of 'speaker' plugin device by virtual method +00000000000i[PLUGIN] register state of 'iodebug' plugin device by virtual method +00000000000i[PLUGIN] register state of 'parallel' plugin device by virtual method +00000000000i[PLUGIN] register state of 'biosdev' plugin device by virtual method +00000000000i[PLUGIN] register state of 'serial' plugin device by virtual method +00000000000i[PLUGIN] register state of 'extfpuirq' plugin device by virtual method +00000000000i[PLUGIN] register state of 'gameport' plugin device by virtual method +00000000000i[PLUGIN] register state of 'usb_uhci' plugin device by virtual method +00000000000i[PLUGIN] register state of 'acpi' plugin device by virtual method +00000000000i[PLUGIN] register state of 'hpet' plugin device by virtual method +00000000000i[PLUGIN] register state of 'ioapic' plugin device by virtual method +00000000000i[PLUGIN] register state of 'keyboard' plugin device by virtual method +00000000000i[PLUGIN] register state of 'harddrv' plugin device by virtual method +00000000000i[PLUGIN] register state of 'pci_ide' plugin device by virtual method +00000000000i[SYS ] bx_pc_system_c::Reset(HARDWARE) called +00000000000i[CPU0 ] cpu hardware reset +00000000000i[APIC0 ] allocate APIC id=0 (MMIO enabled) to 0x0000fee00000 +00000000000i[CPU0 ] CPU[0] is the bootstrap processor +00000000000i[CPU0 ] CPUID[0x00000000]: 00000005 68747541 444d4163 69746e65 +00000000000i[CPU0 ] CPUID[0x00000001]: 00000633 00010800 00002028 17cbfbff +00000000000i[CPU0 ] CPUID[0x00000002]: 00000000 00000000 00000000 00000000 +00000000000i[CPU0 ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000 +00000000000i[CPU0 ] CPUID[0x00000004]: 00000000 00000000 00000000 00000000 +00000000000i[CPU0 ] CPUID[0x00000005]: 00000040 00000040 00000003 00000020 +00000000000i[CPU0 ] CPUID[0x80000000]: 80000008 68747541 444d4163 69746e65 +00000000000i[CPU0 ] CPUID[0x80000001]: 00000633 00000000 00000101 ebd3f3ff +00000000000i[CPU0 ] CPUID[0x80000002]: 20444d41 6c687441 74286e6f 7020296d +00000000000i[CPU0 ] CPUID[0x80000003]: 65636f72 726f7373 00000000 00000000 +00000000000i[CPU0 ] CPUID[0x80000004]: 00000000 00000000 00000000 00000000 +00000000000i[CPU0 ] CPUID[0x80000005]: 01ff01ff 01ff01ff 40020140 40020140 +00000000000i[CPU0 ] CPUID[0x80000006]: 00000000 42004200 02008140 00000000 +00000000000i[CPU0 ] CPUID[0x80000007]: 00000000 00000000 00000000 00000000 +00000000000i[CPU0 ] CPUID[0x80000008]: 00003028 00000000 00000000 00000000 +00000000000i[CPU0 ] CPU Features supported: +00000000000i[CPU0 ] x87 +00000000000i[CPU0 ] 486ni +00000000000i[CPU0 ] pentium_ni +00000000000i[CPU0 ] p6ni +00000000000i[CPU0 ] mmx +00000000000i[CPU0 ] 3dnow! +00000000000i[CPU0 ] debugext +00000000000i[CPU0 ] vme +00000000000i[CPU0 ] pse +00000000000i[CPU0 ] pae +00000000000i[CPU0 ] pge +00000000000i[CPU0 ] pse36 +00000000000i[CPU0 ] mtrr +00000000000i[CPU0 ] pat +00000000000i[CPU0 ] sysenter_sysexit +00000000000i[CPU0 ] clflush +00000000000i[CPU0 ] sse +00000000000i[CPU0 ] sse2 +00000000000i[CPU0 ] mwait +00000000000i[CPU0 ] vmx +00000000000i[CPU0 ] longmode +00000000000i[CPU0 ] lm_lahf_sahf +00000000000i[CPU0 ] nx +00000000000i[CPU0 ] cmpxhg16b +00000000000i[CPU0 ] rdtscp +00000000000i[CPU0 ] ffxsr +00000000000i[CPU0 ] xapic +00000000000i[PLUGIN] reset of 'pci' plugin device by virtual method +00000000000i[PLUGIN] reset of 'pci2isa' plugin device by virtual method +00000000000i[PLUGIN] reset of 'cmos' plugin device by virtual method +00000000000i[PLUGIN] reset of 'dma' plugin device by virtual method +00000000000i[PLUGIN] reset of 'pic' plugin device by virtual method +00000000000i[PLUGIN] reset of 'pit' plugin device by virtual method +00000000000i[PLUGIN] reset of 'vga' plugin device by virtual method +00000000000i[PLUGIN] reset of 'floppy' plugin device by virtual method +00000000000i[PLUGIN] reset of 'acpi' plugin device by virtual method +00000000000i[PLUGIN] reset of 'hpet' plugin device by virtual method +00000000000i[PLUGIN] reset of 'ioapic' plugin device by virtual method +00000000000i[PLUGIN] reset of 'keyboard' plugin device by virtual method +00000000000i[PLUGIN] reset of 'harddrv' plugin device by virtual method +00000000000i[PLUGIN] reset of 'pci_ide' plugin device by virtual method +00000000000i[PLUGIN] reset of 'unmapped' plugin device by virtual method +00000000000i[PLUGIN] reset of 'speaker' plugin device by virtual method +00000000000i[PLUGIN] reset of 'iodebug' plugin device by virtual method +00000000000i[PLUGIN] reset of 'parallel' plugin device by virtual method +00000000000i[PLUGIN] reset of 'biosdev' plugin device by virtual method +00000000000i[PLUGIN] reset of 'serial' plugin device by virtual method +00000000000i[PLUGIN] reset of 'extfpuirq' plugin device by virtual method +00000000000i[PLUGIN] reset of 'gameport' plugin device by virtual method +00000000000i[PLUGIN] reset of 'usb_uhci' plugin device by virtual method +00000000000i[ ] set SIGINT handler to bx_debug_ctrlc_handler +00000004662i[BIOS ] $Revision: 14314 $ $Date: 2021-07-14 18:10:19 +0200 (Mi, 14. Jul 2021) $ +00000317288i[KBD ] reset-disable command received +00000318445i[PIDE ] BAR #4: i/o base address = 0xc000 +00000318672i[UHCI ] BAR #4: i/o base address = 0xc100 +00000324507i[P2ISA ] PCI IRQ routing: PIRQD# set to 0x0b +00000324523i[P2ISA ] write: ELCR2 = 0x08 +00000324543i[UHCI ] new IRQ line = 11 +00000324608i[P2ISA ] PCI IRQ routing: PIRQA# set to 0x0a +00000324624i[P2ISA ] write: ELCR2 = 0x0c +00000324644i[ACPI ] new IRQ line = 10 +00000442944i[VBIOS ] VGABios $Id: vgabios.c 288 2021-05-28 19:05:28Z vruppert $ +00000443015i[BXVGA ] VBE known Display Interface b0c0 +00000443047i[BXVGA ] VBE known Display Interface b0c5 +00000445690i[VBIOS ] VBE Bios $Id: vbe.c 292 2021-06-03 12:24:22Z vruppert $ +00004097860i[BIOS ] IDE time out +00808587967i[BIOS ] Booting from 07c0:0000 +00808683351i[BIOS ] int13_harddisk: function 41, unmapped device for ELDL=80 +00808687022i[BIOS ] int13_harddisk: function 08, unmapped device for ELDL=80 +00808690693i[BIOS ] *** int 15h function AX=00c0, BX=0000 not yet supported! +01119585462i[ ] Ctrl-C detected in signal handler. +01119585463i[ ] dbg: Quit +01119585463i[CPU0 ] CPU is in protected mode (active) +01119585463i[CPU0 ] CS.mode = 32 bit +01119585463i[CPU0 ] SS.mode = 32 bit +01119585463i[CPU0 ] EFER = 0x00000000 +01119585463i[CPU0 ] | EAX=0000002a EBX=0002cd80 ECX=00000008 EDX=00000028 +01119585463i[CPU0 ] | ESP=00067ecc EBP=00067ee0 ESI=0002ced8 EDI=0002ced9 +01119585463i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf af pf cf +01119585463i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D +01119585463i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1 +01119585463i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1 +01119585463i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1 +01119585463i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1 +01119585463i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1 +01119585463i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1 +01119585463i[CPU0 ] | EIP=00100147 (00100147) +01119585463i[CPU0 ] | CR0=0x60000011 CR2=0x00000000 +01119585463i[CPU0 ] | CR3=0x00000000 CR4=0x00000000 +01119585463i[CMOS ] Last time is 1716063758 (Sat May 18 22:22:38 2024) +01119585463i[SIM ] quit_sim called with exit code 0 diff --git a/bochsrc.txt b/bochsrc.txt new file mode 100644 index 0000000..362f256 --- /dev/null +++ b/bochsrc.txt @@ -0,0 +1,9 @@ +megs: 32 +display_library: sdl2 +romimage: file=/usr/share/bochs/BIOS-bochs-legacy +vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest +ata0-master: type=cdrom, path=os.iso, status=inserted +boot: cdrom +log: bochslog.txt +clock: sync=realtime, time0=local +cpu: count=1, ips=1000000 diff --git a/io.h b/io.h new file mode 100644 index 0000000..1ad2ff3 --- /dev/null +++ b/io.h @@ -0,0 +1,6 @@ +#ifndef INCLUDE_IO_H +#define INCLUDE_IO_H + +void outb(unsigned short port, unsigned char data); + +#endif diff --git a/io.o b/io.o new file mode 100644 index 0000000..e1fb404 Binary files /dev/null and b/io.o differ diff --git a/io.s b/io.s new file mode 100644 index 0000000..8ee142f --- /dev/null +++ b/io.s @@ -0,0 +1,7 @@ +global outb + +outb: + mov al, [esp + 8] + mov dx, [esp + 4] + out dx, al + ret diff --git a/iso/boot/grub/menu.lst b/iso/boot/grub/menu.lst new file mode 100644 index 0000000..9a5b08c --- /dev/null +++ b/iso/boot/grub/menu.lst @@ -0,0 +1,5 @@ +default=0 +timeout=0 + +title os +kernel /boot/kernel.elf diff --git a/iso/boot/grub/stage2_eltorito b/iso/boot/grub/stage2_eltorito new file mode 100644 index 0000000..9e1617c Binary files /dev/null and b/iso/boot/grub/stage2_eltorito differ diff --git a/iso/boot/kernel.elf b/iso/boot/kernel.elf new file mode 100755 index 0000000..770778f Binary files /dev/null and b/iso/boot/kernel.elf differ diff --git a/kernel.elf b/kernel.elf new file mode 100755 index 0000000..770778f Binary files /dev/null and b/kernel.elf differ diff --git a/kmain.c b/kmain.c new file mode 100644 index 0000000..8b2d3bc --- /dev/null +++ b/kmain.c @@ -0,0 +1,7 @@ +#include "stdio.h" + +int kmain(int retvalue) +{ + putchar(0, 'A', FB_GREEN, FB_DARK_GREY); + return retvalue; +} diff --git a/kmain.o b/kmain.o new file mode 100644 index 0000000..a7a54ac Binary files /dev/null and b/kmain.o differ diff --git a/link.ld b/link.ld new file mode 100644 index 0000000..177b029 --- /dev/null +++ b/link.ld @@ -0,0 +1,30 @@ +ENTRY(loader) + +SECTIONS { + /* Address to load at; 1MB */ + + . = 0x00100000; + + /* Align relevant sections at 4KB */ + + .text ALIGN (0x1000) : + { + *(.text) + } + + .rodata ALIGN (0x1000) : + { + *(.rodata*) + } + + .data ALIGN (0x1000) : + { + *(.data) + } + + .bss ALIGN (0x1000) : + { + *(COMMON) + *(.bss) + } +} diff --git a/loader.o b/loader.o new file mode 100644 index 0000000..b1872e5 Binary files /dev/null and b/loader.o differ diff --git a/loader.s b/loader.s new file mode 100644 index 0000000..0d3f9ce --- /dev/null +++ b/loader.s @@ -0,0 +1,28 @@ +global loader + +MAGIC_NUMBER equ 0x1BADB002 ; multiboot magic +FLAGS equ 0x0 +CHECKSUM equ -MAGIC_NUMBER +KERNEL_STACK_SIZE equ 4096 + +section .text: +align 4 + dd MAGIC_NUMBER + dd FLAGS + dd CHECKSUM + +extern kmain + +loader: + ; mov eax, 0xCAFEBABE + push dword 42 + call kmain + +.loop: + jmp .loop + +section .bss +align 4 +kernel_stack: + resb KERNEL_STACK_SIZE + mov esp, kernel_stack + KERNEL_STACK_SIZE diff --git a/makefile b/makefile new file mode 100644 index 0000000..5a84452 --- /dev/null +++ b/makefile @@ -0,0 +1,35 @@ +OBJECTS = loader.o kmain.o stdio.o io.o +CC = gcc +CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra -c +LDFLAGS = -T link.ld -melf_i386 +AS = nasm +ASFLAGS = -f elf + +all: kernel.elf + +kernel.elf: $(OBJECTS) + ld $(LDFLAGS) $(OBJECTS) -o kernel.elf + +os.iso: kernel.elf + cp kernel.elf iso/boot/kernel.elf + genisoimage -R \ + -b boot/grub/stage2_eltorito \ + -no-emul-boot \ + -boot-load-size 4 \ + -A os \ + -input-charset utf8 \ + -quiet \ + -boot-info-table \ + -o os.iso \ + iso + +run: os.iso + bochs -f bochsrc.txt -q + +%.o: %.c + $(CC) $(CFLAGS) $< -o $@ +%.o: %.s + $(AS) $(ASFLAGS) $< -o $@ + +clean: + rm -rf *.o kernel.elf os.iso diff --git a/os.iso b/os.iso new file mode 100644 index 0000000..d29c061 Binary files /dev/null and b/os.iso differ diff --git a/stage2_eltorito b/stage2_eltorito new file mode 100644 index 0000000..3748c94 Binary files /dev/null and b/stage2_eltorito differ diff --git a/stdio.c b/stdio.c new file mode 100644 index 0000000..d4f1680 --- /dev/null +++ b/stdio.c @@ -0,0 +1,23 @@ +#include "io.h" +#include "stdio.h" + +char* fb = (char *) 0x000B8000; + +void move_cursor(unsigned short pos) +{ + outb(FB_CMD_PORT, FB_HIGH_BYTE_CMD); + outb(FB_DATA_PORT, ((pos >> 8) & 0x00FF)); + outb(FB_CMD_PORT, FB_LOW_BYTE_CMD); + outb(FB_DATA_PORT, pos & 0x00FF); +} + +void putchar(unsigned int i, char c, unsigned char fg, unsigned char bg) +{ + fb[i] = c; + fb [i+1] = ((fg & 0x0F) << 4 | (bg & 0x0F)); +} + +int write(char *buf, unsigned int len) +{ + return 42; +} diff --git a/stdio.h b/stdio.h new file mode 100644 index 0000000..5991fa8 --- /dev/null +++ b/stdio.h @@ -0,0 +1,16 @@ +#ifndef INCLUDE_STDIO_H +#define INCLUDE_STDIO_H + +#define FB_GREEN 2 +#define FB_DARK_GREY 8 + +#define FB_CMD_PORT 0x3D4 +#define FB_DATA_PORT 0x3D5 +#define FB_HIGH_BYTE_CMD 14 +#define FB_LOW_BYTE_CMD 15 + +void move_cursor(unsigned short pos); +void putchar(unsigned int i, char c, unsigned char fg, unsigned char bg); +int write(char *buf, unsigned int len); + +#endif diff --git a/stdio.o b/stdio.o new file mode 100644 index 0000000..411d5fe Binary files /dev/null and b/stdio.o differ