From 3d102dd9b8aaf0108b047e75e990d5915c3a5775 Mon Sep 17 00:00:00 2001 From: iDunnoDev Date: Mon, 7 Nov 2022 23:38:16 +0000 Subject: [PATCH] Added stage 3 Split the plot pixel part of the main function into its own function Changed the add to a arithmetic shift left Fixed comment error on the number of colors --- stage1/bootasm2.S | 4 +- stage1/bootasm2.o | Bin 3380 -> 3380 bytes stage1/bootblock2 | Bin 547 -> 547 bytes stage1/bootblock2.o | Bin 2736 -> 2736 bytes stage1/xv6.img | 2 +- stage2/bootasm2.S | 4 +- stage2/bootasm2.o | Bin 0 -> 2824 bytes stage2/bootblock2 | Bin 473 -> 473 bytes stage2/bootblock2.o | Bin 2452 -> 2452 bytes stage2/xv6.img | 2 +- stage3/.vscode/tasks.json | 13 ++ stage3/Makefile | 102 +++++++++++ stage3/bootasm.S | 101 +++++++++++ stage3/bootasm.d | 1 + stage3/bootasm.o | Bin 0 -> 2004 bytes stage3/bootasm2.S | 345 ++++++++++++++++++++++++++++++++++++++ stage3/bootasm2.d | 1 + stage3/bootasm2.o | Bin 0 -> 3076 bytes stage3/bootblock | Bin 0 -> 512 bytes stage3/bootblock.o | Bin 0 -> 1624 bytes stage3/bootblock2 | Bin 0 -> 545 bytes stage3/bootblock2.o | Bin 0 -> 2688 bytes stage3/sign.pl | 19 +++ stage3/xv6.img | 3 + 24 files changed, 591 insertions(+), 6 deletions(-) create mode 100644 stage2/bootasm2.o create mode 100644 stage3/.vscode/tasks.json create mode 100644 stage3/Makefile create mode 100644 stage3/bootasm.S create mode 100644 stage3/bootasm.d create mode 100644 stage3/bootasm.o create mode 100644 stage3/bootasm2.S create mode 100644 stage3/bootasm2.d create mode 100644 stage3/bootasm2.o create mode 100644 stage3/bootblock create mode 100644 stage3/bootblock.o create mode 100644 stage3/bootblock2 create mode 100644 stage3/bootblock2.o create mode 100644 stage3/sign.pl create mode 100644 stage3/xv6.img diff --git a/stage1/bootasm2.S b/stage1/bootasm2.S index d8f1323..736c92d 100644 --- a/stage1/bootasm2.S +++ b/stage1/bootasm2.S @@ -138,7 +138,7 @@ cons_line_loop_start: cons_line_loop_next_point: movw err, %ax # Load err into ax so that we can change it - add %ax, %ax # e2 is 2 * err, so we can just add err to itself + sal %ax # e2 is 2 * err, so we can arithmatic shift left cons_line_loop_move_y_point: movw deltay, %bx @@ -165,7 +165,7 @@ real_start: call cons_writeline draw_start: - # Set the Video mode to VGA 320 x 200 x 8 + # Set the Video mode to VGA 320 x 200 x 256 movb $0, %ah movb $0x13, %al int $0x10 diff --git a/stage1/bootasm2.o b/stage1/bootasm2.o index bca2c53f47410b1c081eb9dddf71df27a4940579..879d313ba61aa1462066bae47f3f5b3ad4463a09 100644 GIT binary patch delta 22 ecmdlYwMA-!B_q?t2b--K=P)w*ZN9-2!vz3h&Hsgae=e diff --git a/stage1/bootblock2.o b/stage1/bootblock2.o index 2dcd9fc7e60e2de9895c722222dee99f2b1209ef..27864b83088a3ebd50b97bf0841675ac0764cf99 100644 GIT binary patch delta 22 ecmdlWx$~D@CO+H diff --git a/stage1/xv6.img b/stage1/xv6.img index c8a3fc0..e1da1df 100644 --- a/stage1/xv6.img +++ b/stage1/xv6.img @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e53c6794d2c4777d4a5afbd56fe399b41542ac7164e7552408fac661793ba014 +oid sha256:78f098d34857cf65263e2fb5c83bc70d1a99ad0dd995f67f2d1c7d6b1eaf71ee size 5120000 diff --git a/stage2/bootasm2.S b/stage2/bootasm2.S index 15674ad..690d4e2 100644 --- a/stage2/bootasm2.S +++ b/stage2/bootasm2.S @@ -159,7 +159,7 @@ cons_line_loop_start: cons_line_loop_next_point: movw err(%bp), %ax # Load err into ax so that we can change it - add %ax, %ax # e2 is 2 * err, so we can just add err to itself + sal %ax # e2 is 2 * err, so we can do an arithmatic shift left cons_line_loop_move_y_point: movw deltay(%bp), %bx @@ -197,7 +197,7 @@ real_start: call cons_writeline draw_start: - # Set the Video mode to VGA 320 x 200 x 8 + # Set the Video mode to VGA 320 x 200 x 256 movb $0, %ah movb $0x13, %al int $0x10 diff --git a/stage2/bootasm2.o b/stage2/bootasm2.o new file mode 100644 index 0000000000000000000000000000000000000000..cd1591ed93eeaa460fbf7bd97bde1c0f6c395c36 GIT binary patch literal 2824 zcma)8Z){Ul6hCh*W0bWkG6IS~3z<=eeQQBrfwD2Af{+HCR6y;cTi@C~w|04bgUx_q z;De=vPewn=CqMX!m?cVLmdP|EBsEI>FajaO_@`z>OpNQCqxE-Q`?f0~k(1qfe!p|h zJ@?-8?!Dc+dk%yoNg_)mve5z~I@VD2Y&O-?w2a*J+X`vabO za9?s1+!Mv0D#d%1i8g;=)8^;5Y~9wrt84cQdqS7(H0t_l!k)W*=9i{(XE#v6{o@}K zV{cP#^2`jKYV?mI$8!aDZn8A#zkb<4rN2*KX?wpp4DZnIq2h(ggolL=<$gYMxA9>2 z%dbRUyBeA%%7+{B5l3s--WsXTh0D3fTs~~S8k&`8d${3beJMIyik9<{`m3QCm?91~ z&6J{Z`B1qvG?xoa`^Wt^M;kwE<)h zX`{oq~jg3jga(R?4EibtJ<65J(HF=S=fEFn3 zt!PV=ACh*|G!@$`nv3nGsn}Z4mS~RT7D;nxj^dgM@EDmCUC~+5oZyzRc)zSQaiD1{ z-YaX8mQKzRr`lh8i(Q^my;DA2Q+|n=E~BFQ%Nv5hhE+j-P!8^A(iUuku}${Nu*hEiv#l_^a)*~?{gEI`NAL)|oo3$w%6Tvn z1N@wcSqD@w7%)e9W$&(FC#-(hWVwU8;7*Q`(Sz(nC|l48cJ@~7P{EG6HQ1UwpvF@% zIoqdnk7N((nS>n6X4PzVKusHdIm=}VP!B2>%MJv5-6HgI1xT`U4b1v5xMAadDH@kZ zIxXSetXw8N)?{<7cD1;cFJd>#lW1o7Pr7qDNZei{V3_UEQ95Z__p_-9t6s za-L?@{9F<>f}86$M@Y01dVZmZehS=e`nZ#53;JaO4*~Ojsv^-LfDIN!d=z+-zz2XA zRw>aC_&&jZ7WlZpF90h7{|NY`z&`>0Sm0j(e$ntmLZ`Fe0^4bjG$_SbYfYxwyjNUMpQtZ||Ejo|o zY5wlg6V+Az#+et2${RUG4W7s0#VwF(XF4o@|zUY>cZtLy77a5irWC zi~dx)FN2|GY^x?fR3xkh@YqKcb1w+C&M^PKA-;pyzA3!-C1{-{BYFeZ zU=^?njbr!~<@&YMxb>bntB)+KRk8B5f^z)-#qoNqF`R+(%`&Ko<>TjGT%UpUd0^x9 z@eQ`t*9pvHs=uH_i?M+1;FhqD+p9Hg*}D+Od$WXNSPr6z^L~JNIXBPC`?Kaf25gN1 zqy+LcGpLE><1c4ncAZ9?he1s^CrcVlocC+Y>xPZz<)1%m-uHkxpS9nM$hQOB682e5 s{8YCP$3KuwP<%!>ALr*e*=5Ns6!#P-sEGyn?uc&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \ + then echo 'i386-jos-elf-'; \ + elif objdump -i 2>&1 | grep 'elf32-i386' >/dev/null 2>&1; \ + then echo ''; \ + else echo "***" 1>&2; \ + echo "*** Error: Couldn't find an i386-*-elf version of GCC/binutils." 1>&2; \ + echo "*** Is the directory with i386-jos-elf-gcc in your PATH?" 1>&2; \ + echo "*** If your i386-*-elf toolchain is installed with a command" 1>&2; \ + echo "*** prefix other than 'i386-jos-elf-', set your TOOLPREFIX" 1>&2; \ + echo "*** environment variable to that prefix and run 'make' again." 1>&2; \ + echo "*** To turn off this error, run 'gmake TOOLPREFIX= ...'." 1>&2; \ + echo "***" 1>&2; exit 1; fi) +endif + +# If the makefile can't find QEMU, specify its path here +# QEMU = qemu-system-i386 + +# Try to infer the correct QEMU +ifndef QEMU +QEMU = $(shell if which qemu > /dev/null; \ + then echo qemu; exit; \ + elif which qemu-system-i386 > /dev/null; \ + then echo qemu-system-i386; exit; \ + elif which qemu-system-x86_64 > /dev/null; \ + then echo qemu-system-x86_64; exit; \ + else \ + qemu=/Applications/Q.app/Contents/MacOS/i386-softmmu.app/Contents/MacOS/i386-softmmu; \ + if test -x $$qemu; then echo $$qemu; exit; fi; fi; \ + echo "***" 1>&2; \ + echo "*** Error: Couldn't find a working QEMU executable." 1>&2; \ + echo "*** Is the directory containing the qemu binary in your PATH" 1>&2; \ + echo "*** or have you tried setting the QEMU variable in Makefile?" 1>&2; \ + echo "***" 1>&2; exit 1) +endif + +CC = $(TOOLPREFIX)gcc +AS = $(TOOLPREFIX)gas +LD = $(TOOLPREFIX)ld +OBJCOPY = $(TOOLPREFIX)objcopy +OBJDUMP = $(TOOLPREFIX)objdump +CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer +CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) +ASFLAGS = -m32 -gdwarf-2 -Wa,-divide +# FreeBSD ld wants ``elf_i386_fbsd'' +LDFLAGS += -m $(shell $(LD) -V | grep elf_i386 2>/dev/null | head -n 1) + +# Disable PIE when possible (for Ubuntu 16.10 toolchain) +ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]no-pie'),) +CFLAGS += -fno-pie -no-pie +endif +ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]nopie'),) +CFLAGS += -fno-pie -nopie +endif + +xv6.img: bootblock bootblock2 + dd if=/dev/zero of=xv6.img count=10000 + dd if=bootblock of=xv6.img conv=notrunc + dd if=bootblock2 of=xv6.img seek=1 conv=notrunc + +bootblock: bootasm.S + $(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c bootasm.S + $(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o bootblock.o bootasm.o + $(OBJCOPY) -S -O binary -j .text bootblock.o bootblock + ./sign.pl bootblock + +bootblock2: bootasm2.S + $(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c bootasm2.S + $(LD) $(LDFLAGS) -N -e start -Ttext 0x9000 -o bootblock2.o bootasm2.o + $(OBJCOPY) -S -O binary -j .text bootblock2.o bootblock2 + + +.PRECIOUS: %.o + +clean: + rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \ + *.o *.d *.asm *.sym vectors.S bootblock bootblock2 entryother \ + initcode initcode.out kernel xv6.img fs.img kernelmemfs \ + xv6memfs.img mkfs \ + syscall.h syscalltable.h usys.S + +# run in emulators + +# try to generate a unique GDB port +GDBPORT = $(shell expr `id -u` % 5000 + 25000) +# QEMU's gdb stub command line changed in 0.11 +QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \ + then echo "-gdb tcp::$(GDBPORT)"; \ + else echo "-s -p $(GDBPORT)"; fi) +ifndef CPUS +CPUS := 1 +endif +QEMUOPTS = -drive file=xv6.img,index=0,media=disk,format=raw -smp $(CPUS) -m 512 $(QEMUEXTRA) + +qemu: xv6.img + $(QEMU) -vga std -serial mon:stdio $(QEMUOPTS) + +qemu-gdb: xv6.img + @echo "*** Now run 'gdb'." 1>&2 + $(QEMU) -vga std -serial mon:stdio $(QEMUOPTS) -S -gdb tcp::1234 + diff --git a/stage3/bootasm.S b/stage3/bootasm.S new file mode 100644 index 0000000..ebfa7da --- /dev/null +++ b/stage3/bootasm.S @@ -0,0 +1,101 @@ +# When the PC starts, the processor is essentially emulating an 8086 processor, i.e. +# a 16-bit processor. So our initial boot loader code is 16-bit code that will +# eventually switch the processor into 32-bit mode. + +# This code is linked to assume a starting address of 0x7C00 which is where the BIOS +# will load a boot segment. + +.code16 # Assemble for 16-bit mode +.globl start +start: + jmp real_start + +# Write to the console using BIOS. +# +# Input: SI contains the address of the null-terminated string to be displayed + +cons_write: + movb $0x0e, %ah # 0x0e is the INT 10h BIOS call to output the value contained in AL to screen + +cons_write_rpt: + movb (%si), %al # Load the byte at the location contained in the SI register into AL + inc %si # Add 1 to the value in SI + cmp $0, %al # Compare the value in AL with 0 + jz cons_write_done # If it is zero, then we are done + int $0x10 # Output the character in AL to the screen + jmp cons_write_rpt # and continue + +cons_write_done: # Something that is called will never return + ret # until a 'ret' instruction is encountered. Labels do + # not give a program any structure. They just give a + # memory location a name that we can use in our code. + +cons_write_crlf: + movb $0x0e, %ah # Output CR + movb $0x0d, %al + int $0x10 + movb $0x0a, %al # Output LF + int $0x10 + ret + +cons_writeline: + call cons_write + call cons_write_crlf + ret + +real_start: + cli # BIOS enabled interrupts; disable + + # Zero data segment registers DS, ES, and SS. + xorw %ax, %ax # Set %ax to zero + movw %ax, %ds # -> Data Segment + movw %ax, %es # -> Extra Segment + movw %ax, %ss # -> Stack Segment + movw $0, %sp # Set the stack to the top of the segment + + movb %dl, (boot_device) # Boot device number is passed in DL from BIOS. Save it hear since DL might get trashed + + movw $boot_message, %si # Display our boot message + call cons_writeline + + movb $2, %ah # BIOS function 13h, sub-function 2 is read sectors + movb $7, %al # Number of sectors to read = 7 + movw $0x9000, %bx # The 7 sectors will be loaded into memory at ES:BX (0000:9000h) + movb $0, %ch # Use cylinder 0 + movb $0, %dh # Use head 0 + movb (boot_device), %dl # Retrieve the ID of our boot device + movb $2, %cl # Start reading at sector 2 (i.e. one after the boot sector) + int $0x13 + cmpb $7, %al # AL returns the number of sectors read. If this is not 7, report an error + jne read_failed + + movb (0x9000), %al # Check that what we loaded is not empty + cmpb $0, %al + je read_failed + + movb (boot_device), %dl # Pass boot device ID to second stage + movw $0x9000, %ax # Jump to stage 2 + jmp *%ax + +read_failed: # Display error messages + movw $read_failed_msg, %si + call cons_writeline + + mov $cannot_continue, %si + call cons_writeline + +endless_loop: # Loop forever more + jmp endless_loop + +# Program data + +boot_device: + .byte 0 + +boot_message: + .string "Boot Loader V1.0" +read_failed_msg: + .string "Unable to read stage 2 of the boot process" +cannot_continue: + .string "Cannot continue boot process" + diff --git a/stage3/bootasm.d b/stage3/bootasm.d new file mode 100644 index 0000000..59e6ae8 --- /dev/null +++ b/stage3/bootasm.d @@ -0,0 +1 @@ +bootasm.o: bootasm.S diff --git a/stage3/bootasm.o b/stage3/bootasm.o new file mode 100644 index 0000000000000000000000000000000000000000..4f7fa1ef1cf180869b8278af4eed49b1e136e9ff GIT binary patch literal 2004 zcma)6PiP!v6o0du7#q!I+Y}2{$kZ4qT4u7Xib6L=rSZ@pg*MWIFqz$%-7N0TgqcaT zUZOV%5^@%V-h`ea#3Cr6m_ttik39-{SjfRsp;&PH`+YNC_EVAi;QQY1_uiZLz3x=b z^n+{(*WOGRR!rox5DG)#vMPmp(#L zcQx*XZhA9Cg>BbQQ&iatqpT*Z+fRGWRRf*ja$=2eK~)UFJ%z@BSdaC&g)2FA+&VE? zuAHvSR;Ka`djURGC^o3&o(9mv<^H>*_di&+-??g^cP_kXeEDz47sH}nJaSp`EO5R) zjh39kJgmf$m%%6LQew#)(A9!5ei8Vz!Iy!12KRv@gA;oO{|tD;;G4j=4gNLo#|A%w z0A+dFq~JX5p_Fkcrj%vOq==u8rwmJ#r-QfJ_3&1cOz<32?~|mHg$DGJHPhn-ar8HL zGwHUB@NNfgUZNL-H#*G%_wbz14O}enT7IV+1}64;X?v!3b4$z6a|>e#g|)1?Rb0 zmHaKJUUbr%z07ZjlV(Y-S2aq)u9JnIX5s{X=8Mxn$2&9zVPn1RsUtElPCqgIov0P# zQx)qs8cBG=^!kY(wL>J#1NiO#6}1-x>o>rEr`dZr7A1V&$1oNY!=BL~Jb!Fo^%MJr z=QmsMGBo8;u8wA%?^ReB|D-t9qrYJi=F12Q(LUB<*0+FyY}i;IJ3!aB0L*U~Pl-XC z9IBZbDGcUgey*wS3{X}< Xz9lGxc_{21Gwv1=e5E}3q~jg~f>af{ literal 0 HcmV?d00001 diff --git a/stage3/bootasm2.S b/stage3/bootasm2.S new file mode 100644 index 0000000..b435145 --- /dev/null +++ b/stage3/bootasm2.S @@ -0,0 +1,345 @@ +# Second stage of the boot loader + +.code16 # Assemble for 16-bit mode +.globl start +start: + jmp real_start + +# Write to the console using BIOS. +# +# Input: SI contains the address of the null-terminated string to be displayed + +cons_write: + movb $0x0e, %ah # 0x0e is the INT 10h BIOS call to output the value contained in AL to screen + +cons_write_rpt: + movb (%si), %al # Load the byte at the location contained in the SI register into AL + inc %si # Add 1 to the value in SI + cmp $0, %al # Compare the value in AL with 0 + jz cons_write_done # If it is zero, then we are done + int $0x10 # Output the character in AL to the screen + jmp cons_write_rpt # and continue + +cons_write_done: # Something that is called will never return + ret # until a 'ret' instruction is encountered. Labels do + # not give a program any structure. They just give a + # memory location a name that we can use in our code. + +cons_write_crlf: + movb $0x0e, %ah # Output CR + movb $0x0d, %al + int $0x10 + movb $0x0a, %al # Output LF + int $0x10 + ret + +cons_writeline: + call cons_write + call cons_write_crlf + ret + +# Added Write Hex and Int functions to help with debugging +HexChars: .ascii "0123456789ABCDEF" + +cons_write_hex: + movw $4, %cx + movb $0x0E, %ah + +hexloop: + rol $4, %bx + movw %bx, %si + and $0x000F, %si + movb HexChars(%si), %al + int $0x10 + loop hexloop + ret + +cons_write_int: + movw $IntBuffer + 4, %si + movw %bx, %ax + + cmpw $0, %ax + jge getdigit + + xor %ax, %ax # Added to handle signed numbers, it adds the minus and then neg's the number + movb $0x0E, %ah + movb $0x2D, %al + int $0x10 + + movw %bx, %ax + negw %ax + +getdigit: + xor %dx, %dx + movw $10, %cx + idiv %cx + addb $48, %dl + movb %dl, (%si) + dec %si + cmp $0, %ax + jne getdigit + inc %si + call cons_write + ret + +IntBuffer: .string " " + +# Draw Line function DrawLine(x0 (4), y0 (6), x1 (8), y1 (10), color (12)) +# Define parameter address positions in stack +#define color 12 +#define y1 10 +#define x1 8 +#define y0 6 +#define x0 4 + +# Define local variable positions in stack +#define deltax -2 +#define deltay -4 +#define sx -6 +#define sy -8 +#define err -10 +#define e2 -12 + +cons_draw_line: + pushw %bp + movw %sp, %bp + subw $12, %sp # Make room for our local variables in the stack + + # Store existing register values to the stack so we can restore later + pushw %ax + pushw %bx + pushw %cx + pushw %dx + pushw %si + pushw %di + + movw $0, err(%bp) # Make sure that err starts at 0 + movw x1(%bp), %cx # Load x1 and y1 into the registers + movw y1(%bp), %dx + sub x0(%bp), %cx # Remove x/y0 from x/y1 to get the delta values + sub y0(%bp), %dx + movw %cx, deltax(%bp) # Store the delta values + movw %dx, deltay(%bp) + +cons_line_check_x: + movw x0(%bp), %cx # Load x0 into register cx so we can manipulate this value to plot each pixel + movw $1, sx(%bp) # Preload the x slope with 1 + cmp x1(%bp), %cx # Check if x0 is less than x1 and we can move to y + jl cons_line_check_y + negw sx(%bp) # If x1 is greater than we need to flip the slope and the x delta values + negw deltax(%bp) # Flipping the deltax here saves us from having to have an abs function because if + # x0 was greater than x1 we know we have a negative delta value and we flip it to pos + +cons_line_check_y: + movw y0(%bp), %dx # Load y0 into register dx so we can manipulate this value to plot each pixel + movw $1, sy(%bp) # Preload the y slope with 1 + cmpw y1(%bp), %dx # Check if y0 is less than y1 and we can start our plotting + jl cons_line_prep_loop + negw sy(%bp) # if y1 is greater than we need to flip the slope y and delta y values + negw deltay(%bp) + +cons_line_prep_loop: + movw deltax(%bp), %ax # Calculate the err variable by subtracting delta y from delta x + sub deltay(%bp), %ax + movw %ax, err(%bp) + +cons_line_loop_start: + pushw color(%bp) + pushw %dx + pushw %cx + call cons_plot_pixel + + cmpw x1(%bp), %cx # Check if x0 and x1 are equal, if not then we are still plotting + jne cons_line_loop_next_point + cmpw y1(%bp), %dx # Check if y0 and y1 are equal, if not then we are still plotting + jne cons_line_loop_next_point + jmp cons_line_loop_end # if both x's and y's are equal then we can end the function + +cons_line_loop_next_point: + movw err(%bp), %ax # Load err into ax so that we can change it + sal %ax # e2 is 2 * err, so we can arithmatic shift left + +cons_line_loop_move_y_point: + movw deltay(%bp), %bx + negw %bx # We need negative deltay to compare + cmpw %bx, %ax # Check if we need to apply the slope value to y + jle cons_line_loop_move_x_point + negw %bx # Change deltay back to normal + subw %bx, err(%bp) # Remove the deltay from the err check + addw sx(%bp), %cx # Add the slope value to the current y value + +cons_line_loop_move_x_point: + movw deltax(%bp), %bx + cmpw %bx, %ax # Check if we need to apply the x slope value + jge cons_line_loop_start + addw %bx, err(%bp) # Add the deltax to the err value + addw sy(%bp), %dx # Add the slope value to the current x value + jmp cons_line_loop_start # Go back to the start of the loop + +cons_line_loop_end: + # Return all the original values to each register before we return back + popw %di + popw %si + popw %dx + popw %cx + popw %bx + popw %ax + movw %bp, %sp + popw %bp + ret $10 # Finish the loop and return to the call address + # we also tell it to free the 10 bytes in the stack for the paramters + # 5 x Word (2 bytes) + +# Function PlotPixel(pixelx, pixely, pixelColor) +#define pixelcolor 8 +#define pixely 6 +#define pixelx 4 + +# I split the pixel plotting off into its own function so that we can use it for any other function that plots pixels +# and any boundary checks will be applied with the same rules +cons_plot_pixel: + # Setup the stack + pushw %bp + movw %sp, %bp + + # Store existing register values to the stack so we can restore later + pushw %ax + pushw %bx + pushw %cx + pushw %dx + pushw %si + pushw %di + + xor %ax, %ax # Clear ax and bx for use with the draw function + xor %bx, %bx + movw pixelx(%bp), %cx # Move x and y into their registers + movw pixely(%bp), %dx + + cmpw (screen_width), %cx # Check if the x value has gone past the width of the screen + jg cons_plot_pixel_end # If so we ignore the pixel so that we dont draw into unrelated memory + cmpw $0, %cx # also check if x has gotten less than 0 + jl cons_plot_pixel_end + + cmpw (screen_height), %dx # Do the same checks for the y position, i chose to ignore the pixel rather than + jg cons_plot_pixel_end # end the entire draw because when we come to the circles and polygons we + cmpw $0, %dx # can still partially show the output that falls within the boundaries + jl cons_plot_pixel_end + + # Pixel point = 0xA0000 + (y * 320) + x + movw (screen_width), %ax # Set ax to 320 so that we can multiply this by y + mul %dx # does the (y * 320) part of our math + add %cx, %ax # Add the value of x to register ax + movw %ax, %si # Move the value of ax into the si counter + + movw $0xA000, %bx # Set the start of the video memory location + movw %bx, %es # Move that address into the "extra segment" es register + movw pixelcolor(%bp), %bx # Load the color into a register + movb %bl, %es:(%si) # Load the lower half of the color (since they should only be from 0 to 255) + # and place it at the given byte in the segment + +cons_plot_pixel_end: + # Return all the original values to each register before we return back + popw %di + popw %si + popw %dx + popw %cx + popw %bx + popw %ax + movw %bp, %sp + popw %bp + ret $6 # Finish the loop and return to the call address + +real_start: + movw $boot_message, %si # Display our boot message + call cons_writeline + +draw_start: + # Set the Video mode to VGA 320 x 200 x 256 + movb $0, %ah + movb $0x13, %al + int $0x10 + xor %ax, %ax + + # Plot a line, we add the parameters to the stack in reverse order + pushw $12 # Color + pushw $55 # y1 + pushw $160 # x1 + pushw $50 # y0 + pushw $50 # x0 + call cons_draw_line + + # Draw the rest of the lines + pushw $11 # Color + pushw $150 # y1 + pushw $90 # x1 + pushw $55 # y0 + pushw $160 # x0 + call cons_draw_line + + pushw $14 # Color + pushw $50 # y1 + pushw $50 # x1 + pushw $150 # y0 + pushw $90 # x0 + call cons_draw_line + + pushw $9 # Color + pushw $10 # y1 + pushw $310 # x1 + pushw $10 # y0 + pushw $10 # x0 + call cons_draw_line + + pushw $10 # Color + pushw $190 # y1 + pushw $310 # x1 + pushw $10 # y0 + pushw $310 # x0 + call cons_draw_line + + pushw $13 # Color + pushw $190 # y1 + pushw $10 # x1 + pushw $190 # y0 + pushw $310 # x0 + call cons_draw_line + + pushw $15 # Color + pushw $10 # y1 + pushw $10 # x1 + pushw $190 # y0 + pushw $10 # x0 + call cons_draw_line + + pushw $1 # Color + pushw $110 # y1 + pushw $250 # x1 + pushw $150 # y0 + pushw $75 # x0 + call cons_draw_line + + pushw $6 # Color + pushw $150 # y1 + pushw $300 # x1 + pushw $30 # y0 + pushw $210 # x0 + call cons_draw_line + + pushw $3 # Color + pushw $20 # y1 + pushw $170 # x1 + pushw $180 # y0 + pushw $180 # x0 + call cons_draw_line + +endless_loop: # Loop forever more + jmp endless_loop + +# Program data +boot_message: + .string "Boot Loader Stage 2 loaded" + +screen_width: + .word 320 +screen_height: + .Word 200 \ No newline at end of file diff --git a/stage3/bootasm2.d b/stage3/bootasm2.d new file mode 100644 index 0000000..74df401 --- /dev/null +++ b/stage3/bootasm2.d @@ -0,0 +1 @@ +bootasm2.o: bootasm2.S diff --git a/stage3/bootasm2.o b/stage3/bootasm2.o new file mode 100644 index 0000000000000000000000000000000000000000..b9342db5cc7ea23ac2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ITIMW-f;sY-MP!KG9qbB0XBk5fCf#raztMh)v03~LLN*Y22W>G{;iAVsNdW9R$k zT6(2p+gNGaHa2UY>$R`-%^%r~g%1lG3-4bMJ>Flbu6xzmr}~<{((;lPpV4!gM{rf& z?jCHJF_vf%ty($sf)?u^*XOFW=k@jFYHg*y^NTL}eq@gMjw=H5b~ZCWmFNiRtOOEFO3%(bXyqR4|dQP5KpKg|i_}qG&l`h|{PDFUr!@>*MByo93y^>2v?6`qPQGwoBrj zC$SWLtGB~Hid{EEqy2Dng?qs%g$KZ$3J-$~g>Qg+6t=+?g{Q!t!VkcJDiiG0Y!L*vO zUEljFT?on(N_n}2Gow=n zmqki$Q1Lk}P`8hrL}ZU^VCi#e77!&hY-H|s;`94iz91oeX0Bs(5-W3uaY-FROp2^y s+ql0PnacnZ!B$`znt~co<|e2V7w}F3EcapQf~s{V(co^JX*^`zZ!f?eo&W#< literal 0 HcmV?d00001 diff --git a/stage3/bootblock2 b/stage3/bootblock2 new file mode 100644 index 0000000000000000000000000000000000000000..01bc4ed003f4a4644fc6dda57aa1b22307954349 GIT binary patch literal 545 zcmYL@PiWIn9LImzLaedN0v17VF5n-KDlAnuOBHl#E=q74MmI4s*f2cAg0vo_b3!~U zi;U5OClB+gmmYGdLa7Vbc?jZ8m4e9d&yx=IvZf2=#g~fscszdJ&-?QIeSb_cjvQ;oByfcrO=h416QrD=4SlL z#MroYt){d9Y&B+Ud{SkT8fU4*(mJ-v)|7yOj2bI&z8?5Gu{Exyv?p#reHv0ENW!fug^`tXXeg!^)Ct z>#@TN`~C-UQ0Xb+SHywRZcmh}D2_&q6+kJJ!fc3k8BYOCbrIeoNQihB;qL_PM7%M~ zARh7fBcXEzx{^Nl9YK9m|AV+pP=93XGW?Pt2HiCRh@vjxX9RI{GLAB6zp)PZ2|>Lm oVY~pti7qaXCK=6UbJFGP^vvu%X(Bg$dsa$GcOp3hXPGtl1E|vMOaK4? literal 0 HcmV?d00001 diff --git a/stage3/bootblock2.o b/stage3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Zo{6pe57k9yXjv>10<*-`?BVDQl!l*5iq;L}|geCLIxJLAo>a#12L7cvZ|=C74J* z6Y0_99&vslszPMHW=}G$i#>^~oMa|aQA*B2CXE}LUzTR%RQ$nEce+m&`~O=`bJxxxmeg`5JE(sJl(WU7028rG9p8)>_gkA^h7J)JeQR~}@Vmr82LX_i@ zE)i0n>F?I1b{KWd8Wr2q;fs;_xZK{`B}$r<>XI`yCQ_Yg+n3tgHM!3wdihI}pb#5| zl{I?6|5vvRRB-YLzN_F_#P=9{f3Xd7Xntt6kDLXK51o>gUW=>;ksXBbJZxDx1qiOS*s+CU>2L;2O4J4Qx_rv~}y@5o-IW zwRJecQge0~bUp|ygvd&0_~i9MLx!d1Y@nQwpKx-?Y!`p)tS$-{>@`~iqpkY~M;Bnd literal 0 HcmV?d00001 diff --git a/stage3/sign.pl b/stage3/sign.pl new file mode 100644 index 0000000..d793035 --- /dev/null +++ b/stage3/sign.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl + +open(SIG, $ARGV[0]) || die "open $ARGV[0]: $!"; + +$n = sysread(SIG, $buf, 1000); + +if($n > 510){ + print STDERR "boot block too large: $n bytes (max 510)\n"; + exit 1; +} + +print STDERR "boot block is $n bytes (max 510)\n"; + +$buf .= "\0" x (510-$n); +$buf .= "\x55\xAA"; + +open(SIG, ">$ARGV[0]") || die "open >$ARGV[0]: $!"; +print SIG $buf; +close SIG; diff --git a/stage3/xv6.img b/stage3/xv6.img new file mode 100644 index 0000000..1c56e61 --- /dev/null +++ b/stage3/xv6.img @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9bedb7e2f1ba67990f6d1aaa49deb02e479cfdd6baa4669f2c23bca5b1034d0d +size 5120000