From: Christoffer Bubach Date: Fri, 9 Jan 2015 03:53:14 +0000 (+0100) Subject: made it assemble under os x, moved loading position of kernel + install script for osx X-Git-Url: https://git.wirehaze.ovh/BOS.git/commitdiff_plain/2c5764025542375cf66d6eb178fd9468b9022726 made it assemble under os x, moved loading position of kernel + install script for osx --- diff --git a/boot/BOS_boot.asm b/boot/BOS_boot.asm index c77b7e3..a7a5c12 100755 --- a/boot/BOS_boot.asm +++ b/boot/BOS_boot.asm @@ -24,30 +24,33 @@ ; 0x0000:0x6c00 -> 0x0000:0x7400 IDT, 256 descriptors ; 0x0000:0x7400 -> 0x0000:0x7c00 GDT, 256 descriptors ; 0x0000:0x7c00 -> 0x0000:0x7e00 bootsector -; 0x0000:0x7e00 <- 0x0000:0xffff ~32,5kb stack for boot -; 0x1000:0x0000 -> 0x9000:0xffff 576kb kernel/free space -; 0xa000:0x0000 -> ............. VGA mem etc. +; 0x0000:0x7e00 <- 0x0000:0x8000 512b stack for boot +; 0x0000:0x8000 -> 0x9000:0xffff 608kb kernel/free space +;;;; 0x0000:0x7e00 <- 0x0000:0xffff ~32,5kb stack for boot +;;;; 0x1000:0x0000 -> 0x9000:0xffff 576kb kernel/free space +; 0xA000:0x0000 -> ............. VGA mem etc. use16 org 0x7C00 -boot: jmp near start +boot: + jmp short start nop ;------------------------------------------; ; Standard BIOS Parameter Block, "BPB". ; ;------------------------------------------; - bpbOEM db 'BOS 0.04' + bpbOEM db 'BOS 0.04' bpbSectSize dw 512 bpbClustSize db 1 bpbReservedSec dw 1 - bpbFats db 2 + bpbFats db 2 bpbRootSize dw 224 bpbTotalSect dw 2880 - bpbMedia db 240 + bpbMedia db 240 bpbFatSize dw 9 bpbTrackSect dw 18 - bpbHeads dw 2 + bpbHeads dw 2 bpbHiddenSect dd 0 bpbLargeSect dd 0 ;---------------------------------; @@ -56,7 +59,7 @@ boot: jmp near start bpbDriveNo db 0 bpbReserved db 0 bpbSignature db 41 ; 0 = nothing more. 41 = three more (below).. - bpbID dd 1 + bpbID dd 1 bpbVolumeLabel db 'BOOT FLOPPY' bpbFileSystem db 'FAT12 ' @@ -71,7 +74,7 @@ start: mov ds, ax ; registers. mov es, ax mov ss, ax - mov sp, 0xFFFF ; Stack.. + mov sp, 0x8000 ; Stack.. mov [bpbDriveNo], dl @@ -227,7 +230,7 @@ start: ;-----------------------------------; found: mov bp, [bx+26] ; bp=cluster number from directory entry - mov di, 0x1000 ; 1000 (segment) + mov di, 0x800 ; 1000 (segment) .next_block: xor cx, cx @@ -272,7 +275,7 @@ found: ; the file is loaded ; ;-----------------------; quit: - jmp 0x1000:0x0000 ; jump to loaded file (64kb in mem) + jmp 0x0000:0x8000 ; jump to loaded file (64kb in mem) ;-------------------------------------; diff --git a/boot/BOS_boot.bin b/boot/BOS_boot.bin index b196cc4..48d8b83 100755 Binary files a/boot/BOS_boot.bin and b/boot/BOS_boot.bin differ diff --git a/doc/bochsrc-osx.txt b/doc/bochsrc-osx.txt new file mode 100644 index 0000000..9fbb925 --- /dev/null +++ b/doc/bochsrc-osx.txt @@ -0,0 +1,24 @@ +####################################### +# # +# BOCHS config file for BOS # +# # +####################################### + +#display_library: term +romimage: file=/usr/local/Cellar/bochs/2.6.2/share/bochs/BIOS-bochs-latest +megs: 32 +vgaromimage: file=/usr/local/Cellar/bochs/2.6.2/share/bochs/VGABIOS-elpin-2.40 +floppya: 1_44=/Volumes/BOS, status=inserted +boot: a +floppy_bootsig_check: disabled=0 +log: bochsout.txt +panic: action=ask +error: action=report +info: action=report +debug: action=ignore +debugger_log: debugger.out +keyboard_serial_delay: 250 +keyboard_paste_delay: 100000 +mouse: enabled=0 +keyboard_mapping: enabled=0, map= +user_shortcut: keys=ctrlaltdel \ No newline at end of file diff --git a/kernel/kernel.asm b/kernel/kernel.asm old mode 100755 new mode 100644 index 40c2225..df6d48f --- a/kernel/kernel.asm +++ b/kernel/kernel.asm @@ -1,24 +1,24 @@ ;-------------------------------------------------------; -; BOS kernel ; +; BOS kernel ; ;-------------------------------------------------------; -; BOS 32-bit kernel, expects to be loaded at 64kb ; -; in mem. Small amount of 16-bit code included. ; -; ; -; For any comments on this code, mail me. ; -; http://bos.asmhackers.net/ asmhacker@gmail.com ; -; ; -; by: Christoffer Bubach, 2003-2005 ; +; BOS 32-bit kernel, expects to be loaded at 64kb ; +; in mem. Small amount of 16-bit code included. ; +; ; +; For any comments on this code, mail me. ; +; http://bos.asmhackers.net/ asmhacker@gmail.com ; +; ; +; by: Christoffer Bubach, 2003-2005 ; ;-------------------------------------------------------; use16 -org 0x10000 +org 0x8000 ;---------------------------; ; jump to starting point ; ;---------------------------; - jmp start + jmp start ;----------------------------------------; -; 16-bit include files ; +; 16-bit include files ; ;----------------------------------------; include 'realmode/a20.inc' ; Function to set the a20-gate. include 'realmode/gdt.inc' ; Global Description Table. @@ -30,7 +30,7 @@ org 0x10000 ;--------------------------; -; 16-bit entry point ; +; 16-bit entry point ; ;--------------------------; start: cli @@ -48,10 +48,10 @@ start: cli mov ax, cs ; save cs - mov [realmode_cs - 0x10000], ax ; in variables.inc + mov [realmode_cs], ax ; in variables.inc - lgdt [gdtr - 0x10000] ; Load the GDT descriptor - lidt [idtr - 0x10000] ; Load the IDT descriptor + lgdt [gdtr] ; Load the GDT descriptor + lidt [idtr] ; Load the IDT descriptor mov eax, cr0 or al, 1 @@ -62,7 +62,7 @@ start: ;--------------------------; -; 32-bit entry point ; +; 32-bit entry point ; ;--------------------------; use32 flush: @@ -84,7 +84,7 @@ flush: call init_cmd jmp shell - ;int 0x32 + ;int 0x32 .hang: cli @@ -93,7 +93,7 @@ flush: ;----------------------------------------; -; 32-bit include files ; +; 32-bit include files ; ;----------------------------------------; include 'krl_incs/idt.inc' ; The Interrupt Description Table. include 'krl_incs/text.inc' ; The default textmode functions. @@ -112,7 +112,7 @@ flush: include 'krl_incs/time_date.inc' ; Print time and date. include 'krl_incs/timer.inc' ; Timer IRQ. include 'krl_incs/vga.inc' ; VGA functions. - ; include 'krl_incs/font8x16.inc' ; Standard font. + ; include 'krl_incs/font8x16.inc' ; Standard font. include 'krl_incs/dma.inc' ; DMA code. include 'krl_incs/fdc.inc' ; Floppy code. include 'krl_incs/mario.inc' ; Mario sprite. diff --git a/kernel/kernel.sys b/kernel/kernel.sys index d553f80..b0c3de3 100755 Binary files a/kernel/kernel.sys and b/kernel/kernel.sys differ diff --git a/kernel/krl_incs/idt.inc b/kernel/krl_incs/idt.inc old mode 100755 new mode 100644 index a899cbc..cafbc63 --- a/kernel/krl_incs/idt.inc +++ b/kernel/krl_incs/idt.inc @@ -1,15 +1,15 @@ ;----------------------------------------------------------; -; BOS kernel Christoffer Bubach, 2003-2005. ; +; BOS kernel Christoffer Bubach, 2003-2005. ; ;----------------------------------------------------------; -; ; -; set/modify IDT entries ; -; ; +; ; +; set/modify IDT entries ; +; ; ;----------------------------------------------------------; ;--------------------------------------------------; -; set up IDT ; +; set up IDT ; ; in: edi = pointer to "unhandled int"-function. ; ;--------------------------------------------------; init_idt: @@ -40,9 +40,9 @@ init_idt: ;--------------------------------------; -; modify IDT, set any int ; -; in: cl = int number ; -; edi = int function pointer ; +; modify IDT, set any int ; +; in: cl = int number ; +; edi = int function pointer ; ;--------------------------------------; set_int: push eax @@ -51,7 +51,8 @@ set_int: mov al, 8 ; 8 bytes for each int mul cl ; cl * al = ax movzx ecx, ax ; ecx = offset in IDT (1/2 for dword list) - mov [(idt_list+ecx/2)], edi ; add new int to idt entry list + ;;mov [(idt_list+ecx/2)], edi ; add new int to idt entry list + mov dword [(idt_list+ecx)], edi ; add new int to idt entry list mov eax, edi mov [(0x6c00+ecx)], ax @@ -71,9 +72,9 @@ set_int: ;------------------------------------------------; -; get int address ; -; in: cl = int number ; -; out: esi = address or 0 if none present ; +; get int address ; +; in: cl = int number ; +; out: esi = address or 0 if none present ; ;------------------------------------------------; get_int: push eax @@ -90,8 +91,8 @@ get_int: ;----------------------------------------; -; sets ints from list ; -; in: esi = pointer to int list ; +; sets ints from list ; +; in: esi = pointer to int list ; ;----------------------------------------; set_idt_list: push eax @@ -117,7 +118,7 @@ set_idt_list: ;------------------------------; ; list of idt entries. ; -; 0 = not handled ; +; 0 = not handled ; ;------------------------------; idt_list: dd isr00 dd isr01 diff --git a/kernel/krl_incs/rmode_int.inc b/kernel/krl_incs/rmode_int.inc index bd2dbe2..ed5716d 100755 --- a/kernel/krl_incs/rmode_int.inc +++ b/kernel/krl_incs/rmode_int.inc @@ -24,7 +24,7 @@ rmode_int: mov word [realmode_cx], cx mov word [realmode_dx], dx call disable_irqs - jmp pword 0x18:do_16pmode-0x10000 ; must substract 0x10000 from + jmp pword 0x18:do_16pmode ; must substract 0x10000 from ; data addresses becasue of ; fasm strict "org" behavior use16 @@ -41,7 +41,7 @@ do_16pmode: and al, 0xFE mov cr0, eax - jmp 0x1000:(do_realm-0x10000) + jmp 0x1000:(do_realm) do_realm: mov ax, cs @@ -53,34 +53,34 @@ do_realm: mov gs, ax mov ss, ax - lidt [ridtr - 0x10000] ; realmode/variables.inc + lidt [ridtr] ; realmode/variables.inc sti - mov ax, word [realmode_ax - 0x10000] - mov bx, word [realmode_bx - 0x10000] - mov cx, word [realmode_cx - 0x10000] - mov dx, word [realmode_dx - 0x10000] + mov ax, word [realmode_ax] + mov bx, word [realmode_bx] + mov cx, word [realmode_cx] + mov dx, word [realmode_dx] push ax ; this is some cool shit.. ;) - mov al, [int_number - 0x10000] ; interrupt to preform - mov [$+5 - 0x10000], al ; move it to right pos. + mov al, [int_number] ; interrupt to preform + mov [$+5], al ; move it to right pos. pop ax db 0xCD ; opcode for int. db 0x00 ; move int_number here jnc .no_error - mov byte [realmode_error - 0x10000], 1 + mov byte [realmode_error], 1 .no_error: - mov word [realmode_ax - 0x10000], ax - mov word [realmode_bx - 0x10000], bx - mov word [realmode_cx - 0x10000], cx - mov word [realmode_dx - 0x10000], dx + mov word [realmode_ax], ax + mov word [realmode_bx], bx + mov word [realmode_cx], cx + mov word [realmode_dx], dx cli - lgdt [gdtr - 0x10000] - lidt [idtr - 0x10000] + lgdt [gdtr] + lidt [idtr] mov eax, cr0 or al, 1 mov cr0, eax diff --git a/kernel/realmode/a20.inc b/kernel/realmode/a20.inc old mode 100755 new mode 100644 index f0ab1c8..f9a561c --- a/kernel/realmode/a20.inc +++ b/kernel/realmode/a20.inc @@ -1,9 +1,9 @@ ;----------------------------------------------------------; -; BOS 0.04 Christoffer Bubach, 2005. ; +; BOS 0.04 Christoffer Bubach, 2005. ; ;----------------------------------------------------------; -; ; -; Realmode functions to set a20-gate. ; -; ; +; ; +; Realmode functions to set a20-gate. ; +; ; ;----------------------------------------------------------; ;----------------------; @@ -39,7 +39,7 @@ enable_a20: ret ;------------------------; -; test if A20 is set ; +; test if A20 is set ; ;------------------------; a20_test: mov al, byte [fs:0] diff --git a/kernel/realmode/do_all_16bit.inc b/kernel/realmode/do_all_16bit.inc index f0fb4c3..86f7799 100755 --- a/kernel/realmode/do_all_16bit.inc +++ b/kernel/realmode/do_all_16bit.inc @@ -11,7 +11,7 @@ ;---------------------; do_all_16bit: call getmem ; realmode/mem.inc - mov [ram_amount - 0x10000], eax + mov [ram_amount], eax xor eax, eax ; clear mem for IDT and GDT mov edi, 0x6c00 ; IDT address @@ -20,15 +20,15 @@ do_all_16bit: mov eax, cs shl eax, 4 - mov [gdt.BOS_16code - 0x10000 + 2], ax ; Prepare GDT by - mov [gdt.BOS_16data - 0x10000 + 2], ax ; setting 16-bit base. + mov [gdt.BOS_16code + 2], ax ; Prepare GDT by + mov [gdt.BOS_16data + 2], ax ; setting 16-bit base. shr eax, 16 - mov [gdt.BOS_16code - 0x10000 + 4], al - mov [gdt.BOS_16data - 0x10000 + 4], al - mov [gdt.BOS_16code - 0x10000 + 7], ah - mov [gdt.BOS_16data - 0x10000 + 7], ah + mov [gdt.BOS_16code + 4], al + mov [gdt.BOS_16data + 4], al + mov [gdt.BOS_16code + 7], ah + mov [gdt.BOS_16data + 7], ah - lea esi, [gdt - 0x10000] + lea esi, [gdt] mov edi, 0x7400 ; GDT address mov ecx, (gdt_end - gdt)/4 rep movsd ; Move it to final pos. diff --git a/mac-install.sh b/mac-install.sh new file mode 100755 index 0000000..18b1cc6 --- /dev/null +++ b/mac-install.sh @@ -0,0 +1,70 @@ +#! /bin/sh + +# BOS MacOS X Installer version 0.2 +# You must be root to run this script because of the floppy/loopback device + +echo +echo " BOS - MacOS X installer" +echo "-------------------------" +echo "Requires: Homebrew mtools" +echo + +if [ `id -u` != "0" ]; then + echo "You must be root to use this installer!" + echo +fi + +if [ -z "$1" ]; then + echo "Usage is:" + echo "$0 image - Creates a floppy image called bos.img" + echo "$0 floppy - Install BOS into a floppy ( must be inserted )" + echo + echo "Note: this installer will create a bootable image/floppy." + echo "Floppy creation is not tested ( I don't have a floppy reader ) and it should be already formatted" + exit +fi + +echo "Compiling BOS..." +./utils/osxfasm kernel/kernel.asm kernel/kernel.sys +./utils/osxfasm boot/BOS_boot.asm boot/BOS_boot.bin + +if [ "$1" = "floppy" ]; then + echo "Starting floppy installation..." + + #Install BOS_boot.bin as bootsector into bos.img + dd if=boot/BOS_boot.bin of=/dev/fd0 bs=1 count=512 + mount /mnt/floppy + + #Insert kernel.sys into image + cp kernel/kernel.sys /mnt/floppy + + #Umount & cleanup + umount /mnt/floppy + + echo "BOS installed." + +else + echo "Starting image creation..." + + #Create image + rm -rf ./bos.img + mformat -C -f 1440 -v BOS -i bos.img :: + + #Erhm, it isn't pretty.... + DISKNAME=`hdiutil attach -nomount bos.img` + diskutil mount $DISKNAME + MOUNTNAME=`diskutil info $DISKNAME | grep 'Mount Point' | cut -d : -f 2 | sed 's/^ *//g' | sed 's/ *$//g';` + + #Mounted, copy kernel.sys + cp kernel/kernel.sys $MOUNTNAME + + #Install BOS_boot.bin as bootsector into bos.img + umount $DISKNAME + dd if=boot/BOS_boot.bin of=$DISKNAME bs=1 count=512 + + #Detach + hdiutil detach $DISKNAME + chmod 0777 bos.img + + echo "BOS image created!" +fi \ No newline at end of file diff --git a/utils/osxfasm b/utils/osxfasm new file mode 100755 index 0000000..408cf0e Binary files /dev/null and b/utils/osxfasm differ