From c3113bc245028c880049fd66f5c6968c665028b5 Mon Sep 17 00:00:00 2001 From: iDunnoDev Date: Sun, 13 Nov 2022 00:53:24 +0000 Subject: [PATCH] Added the filled rectangle function Added comments for the new functions Finished the circle function --- stage4/.vscode/tasks.json | 13 + stage4/Makefile | 102 ++++++ stage4/bootasm.S | 101 ++++++ stage4/bootasm.d | 1 + stage4/bootasm.o | Bin 0 -> 2004 bytes stage4/bootasm2.S | 637 ++++++++++++++++++++++++++++++++++++++ stage4/bootasm2.d | 1 + stage4/bootasm2.o | Bin 0 -> 4184 bytes stage4/bootblock | Bin 0 -> 512 bytes stage4/bootblock.o | Bin 0 -> 1624 bytes stage4/bootblock2 | Bin 0 -> 984 bytes stage4/bootblock2.o | Bin 0 -> 3776 bytes stage4/sign.pl | 19 ++ stage4/xv6.img | 3 + 14 files changed, 877 insertions(+) create mode 100644 stage4/.vscode/tasks.json create mode 100644 stage4/Makefile create mode 100644 stage4/bootasm.S create mode 100644 stage4/bootasm.d create mode 100644 stage4/bootasm.o create mode 100644 stage4/bootasm2.S create mode 100644 stage4/bootasm2.d create mode 100644 stage4/bootasm2.o create mode 100644 stage4/bootblock create mode 100644 stage4/bootblock.o create mode 100644 stage4/bootblock2 create mode 100644 stage4/bootblock2.o create mode 100644 stage4/sign.pl create mode 100644 stage4/xv6.img diff --git a/stage4/.vscode/tasks.json b/stage4/.vscode/tasks.json new file mode 100644 index 0000000..51722d9 --- /dev/null +++ b/stage4/.vscode/tasks.json @@ -0,0 +1,13 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Build and QEMU", + "type": "shell", + "command": "make qemu", + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/stage4/Makefile b/stage4/Makefile new file mode 100644 index 0000000..e409242 --- /dev/null +++ b/stage4/Makefile @@ -0,0 +1,102 @@ +# Try to infer the correct TOOLPREFIX if not set +ifndef TOOLPREFIX +TOOLPREFIX := $(shell if i386-jos-elf-objdump -i 2>&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/stage4/bootasm.S b/stage4/bootasm.S new file mode 100644 index 0000000..ebfa7da --- /dev/null +++ b/stage4/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/stage4/bootasm.d b/stage4/bootasm.d new file mode 100644 index 0000000..59e6ae8 --- /dev/null +++ b/stage4/bootasm.d @@ -0,0 +1 @@ +bootasm.o: bootasm.S diff --git a/stage4/bootasm.o b/stage4/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/stage4/bootasm2.S b/stage4/bootasm2.S new file mode 100644 index 0000000..1d187b0 --- /dev/null +++ b/stage4/bootasm2.S @@ -0,0 +1,637 @@ +# 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 (4), pixely (6), pixelColor (8)) +#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 + +# Draw Line function DrawFilledRect(rectx (4), recty (6), rectWidth (8), rectHeight (10), rectColor (12)) +# Define parameter address positions in stack +#define rectcolor 12 +#define rectheight 10 +#define rectwidth 8 +#define recty 6 +#define rectx 4 + +#define rectendx -2 +#define rectendy -4 + +cons_draw_filled_rect: + pushw %bp + movw %sp, %bp + subw $4, %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 + +cons_filled_rect_setup: + movw rectwidth(%bp), %ax + add rectx(%bp), %ax + movw %ax, rectendx(%bp) + + movw rectheight(%bp), %bx + add recty(%bp), %bx + movw %bx, rectendy(%bp) + + movw $0xA000, %bx # Set the start of the video memory location + movw %bx, %es # Move that address into the "extra segment" es register + + movw recty(%bp), %dx + 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 rectx(%bp), %ax # Add the value of x to register ax + movw %ax, %si + lea %es:(%si), %bx # Move the value of ax into the si counter + + movw rectheight(%bp), %si + +cons_filled_rect_loop_start: + movw rectcolor(%bp), %ax + movw %bx, %di + movw rectwidth(%bp), %cx + cld + rep stosb + + movw (screen_width), %cx + add %cx, %bx + + dec %si + jnz cons_filled_rect_loop_start + + +cons_filled_rect_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) + +# Draw Line function DrawCircle(circlex (4), circley (6), circleRadius (8), circleColor (10)) +# This follows the bresenham circle drawing algorithm so that we can stick to integer values +# Define parameter address positions in stack +#define circlecolor 10 +#define circleradius 8 +#define circley 6 +#define circlex 4 + +# Define local variable positions in stack +#define circled -4 # Decision variable +#define circlexcax -6 +#define circlexcsx -8 +#define circleycay -10 +#define circleycsy -12 +#define circlexcay -14 +#define circlexcsy -16 +#define circleycax -18 +#define circleycsx -20 + +cons_draw_circle: + pushw %bp + movw %sp, %bp + subw $20, %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 + +cons_draw_circle_setup: + movw $0, %cx # x starts at 0 + movw circleradius(%bp), %dx # y starts as the radius + movw circleradius(%bp), %bx # d = 3 - (2 * r), we load the radius into a register + sal %bx # and multiply it by 2 + movw $3, %ax # load a 3 into a register to subtract the above from + sub %bx, %ax + movw %ax, circled(%bp) # Move the d variable into the stack + +cons_circle_loop_start: + # We need to plot all 8 points for this step + xor %ax, %ax # Clear a and b registers for use below + xor %bx, %bx + + movw circlex(%bp), %ax # Points xc + x, yc + y + add %cx, %ax + movw circley(%bp), %bx + add %dx, %bx + movw %ax, circlexcax(%bp) + movw %bx, circleycay(%bp) + + movw circlex(%bp), %ax # Points xc - x, yc - y + sub %cx, %ax + movw circley(%bp), %bx + sub %dx, %bx + movw %ax, circlexcsx(%bp) + movw %bx, circleycsy(%bp) + + movw circlex(%bp), %ax # Points xc + y, yc + x + add %dx, %ax + movw circley(%bp), %bx + add %cx, %bx + movw %ax, circlexcay(%bp) + movw %bx, circleycax(%bp) + + movw circlex(%bp), %ax # Points xc - y, yc - x + sub %dx, %ax + movw circley(%bp), %bx + sub %cx, %bx + movw %ax, circlexcsy(%bp) + movw %bx, circleycsx(%bp) + + # Plot the 8 pixels for this turn of the circle + pushw circlecolor(%bp) + pushw circleycay(%bp) + pushw circlexcax(%bp) + call cons_plot_pixel + + pushw circlecolor(%bp) + pushw circleycay(%bp) + pushw circlexcsx(%bp) + call cons_plot_pixel + + pushw circlecolor(%bp) + pushw circleycsy(%bp) + pushw circlexcax(%bp) + call cons_plot_pixel + + pushw circlecolor(%bp) + pushw circleycsy(%bp) + pushw circlexcsx(%bp) + call cons_plot_pixel + + pushw circlecolor(%bp) + pushw circleycax(%bp) + pushw circlexcay(%bp) + call cons_plot_pixel + + pushw circlecolor(%bp) + pushw circleycax(%bp) + pushw circlexcsy(%bp) + call cons_plot_pixel + + pushw circlecolor(%bp) + pushw circleycsx(%bp) + pushw circlexcay(%bp) + call cons_plot_pixel + + pushw circlecolor(%bp) + pushw circleycsx(%bp) + pushw circlexcsy(%bp) + call cons_plot_pixel + + inc %cx # Inc the x value + cmpw $0, circled(%bp) # check if the decision variable is less than 0 + jle cons_circle_skip_y + + dec %dx # If not we decrement the Y value and calculate the new decision value + movw %cx, %ax # Move the x value into ax for mul + movw %dx, %bx # Move the y value into bx since mul destroys the value in dx + movw $4, %si # Move 4 into si because we are out of registers + sub %bx, %ax # d = d + 4 * (x - y) + 10 + imul %si + add $10, %ax + add %ax, circled(%bp) # Add the result to the current D value + movw %bx, %dx # Move y back into the dx register + jmp cons_circle_check_end # jump over the next section to the end check + +cons_circle_skip_y: + movw %cx, %ax # If the decision var was greater than 0 we use another formula for d + movw %dx, %bx # Store y in bx because we are using mul again + movw $4, %si # d = d + 4 * x + 6 + imul %si + add $6, %ax + add %ax, circled(%bp) + movw %bx, %dx # Restore y to the dx register + +cons_circle_check_end: + cmpw %cx, %dx # Check if y is greater than or equal to x + jge cons_circle_loop_start # If so we carry on the loop until it is no longer + +cons_circle_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 $8 # Finish the loop and return to the call address + # we also tell it to free the 10 bytes in the stack for the paramters + # 4 x Word (2 bytes) + +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 + + # Setup the registers to loop through the flag stripes + movw $150, %ax # x Offset + movw $15, %bx # y Offset + movw $6, %cx # Sets of stripes (12 red/white) for the loop to decrement + +draw_flag_loop: + # Draw our filled rectangles for the flag stripes + add $5, %bx # add the height of stripe to the y offset + + pushw $12 # Color + pushw $5 # height + pushw $120 # width + pushw %bx # y + pushw %ax # x + call cons_draw_filled_rect + + add $5, %bx # add the height of stripe to the y offset + pushw $15 # Color + pushw $5 # height + pushw $120 # width + pushw %bx # y + pushw %ax # x + call cons_draw_filled_rect + loop draw_flag_loop + +draw_flag_loop_end: + # Draw the 13th stripe + add $5, %bx + pushw $12 # Color + pushw $5 # height + pushw $120 # width + pushw %bx # y + pushw %ax # x + call cons_draw_filled_rect + + # Draw the blue box that would hold the stars + pushw $1 # Color + pushw $35 # height + pushw $45 # width + pushw $20 # y + pushw $150 # x + call cons_draw_filled_rect + + pushw $6 # Color + pushw $180 # height + pushw $5 # width + pushw $20 # y + pushw $145 # x + call cons_draw_filled_rect + + # Draw some circles to show off that function + pushw $14 # Color + pushw $3 # radius + pushw $17 # y + pushw $147 # x + call cons_draw_circle + + pushw $2 # Color + pushw $25 # radius + pushw $80 # y + pushw $90 # x + call cons_draw_circle + + pushw $15 # Color + pushw $5 # radius + pushw $75 # y + pushw $80 # x + call cons_draw_circle + + pushw $15 # Color + pushw $5 # radius + pushw $75 # y + pushw $100 # x + call cons_draw_circle + + # Plot a line, we add the parameters to the stack in reverse order + pushw $15 # Color + pushw $90 # y1 + pushw $75 # x1 + pushw $95 # y0 + pushw $90 # x0 + call cons_draw_line + + pushw $15 # Color + pushw $90 # y1 + pushw $105 # x1 + pushw $95 # y0 + pushw $90 # x0 + call cons_draw_line + + # Draw the rest of the lines + pushw $2 # Color + pushw $200 # y1 + pushw $90 # x1 + pushw $105 # y0 + pushw $90 # x0 + call cons_draw_line + + pushw $2 # Color + pushw $100 # y1 + pushw $145 # x1 + pushw $120 # y0 + pushw $90 # x0 + call cons_draw_line + + # Line borders + 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 + +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/stage4/bootasm2.d b/stage4/bootasm2.d new file mode 100644 index 0000000..74df401 --- /dev/null +++ b/stage4/bootasm2.d @@ -0,0 +1 @@ +bootasm2.o: bootasm2.S diff --git a/stage4/bootasm2.o b/stage4/bootasm2.o new file mode 100644 index 0000000000000000000000000000000000000000..a7f25f373204afdd01ea59219b3dc319171a066b GIT binary patch literal 4184 zcma)9eQaCR6~8Zb++Y$XrP&IisBudw(y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PIgZhf%qxSM>zd4;4zM$0G2uaBJdH8p9FrHe*h*Qw*5KaUvm6o;FBE3+sDUNRfzrgV}@L!|a{`Uc&T-5c#_Na82A*Y|2gn`9DfP;pB(=q@SnNyc4X=utcs`L?%R0zB%1cd4J+9=SPgTP z7@bp0G^K>&GA?f_!v>Oxw0tNP%P1U_QzN`ajwBPes0UKgQkG%_P34@8xLr{r4B7@B;-S}NG57JDQ6&)W6L0_#D=2${0C$4xDt_5%77*11aex*j9Sadi*KLof9Xmy zF_w5BmKum#o5~4z@1}{dsQfBg;`CFo5!u=SOJwd-DGooLg!D|v!+1RKXfPwDc?1nO z7!MDb`*$lf)(NBI7-#Ak+k^95k7N9()jt4Cyw&OhR-d){m#uyh_l)c|VVtm?v2R$t z-|E|_hn{Ynu#Ms7pobBC%Sle(eW97Ld#!$>)zkeF@FR%c0ORLRbNcXbCfv`O)0vdn zM{Sf+;>{VHHr5;oXTq$xKb>aHB#bEiqgVmDN*u<*r+9rVF_^UV;r{-VGRAAesc>RQ zfkV?7js2>{mUZw3AT#=p0izENoIcc69}jIm>Q90_|+$%bBQTE9k%+n=@S@-q&N zX-hqp*|7hAc9f5u1C1kpS2%$U>1PF>-#O&h02$>+UrIZ_PGA~C_EbKDa+e8>mUL8~ zw0c8`W-Atm=4KbNq0)oO$NdCx$v4HN^|0gq2-qG2$R2~gdIDClb+mIfCRG%64Fs%W zzX}O(K5jh@Z5?D3mwsm1aeoR-{_Oc4hriw6b|IZzaZO6)9PH@FPc1qTmHd%^ifQi| bAUg*^`OPcmPIrg5yC3=ej0RYRVp91JFGbR{ literal 0 HcmV?d00001 diff --git a/stage4/bootblock b/stage4/bootblock new file mode 100644 index 0000000000000000000000000000000000000000..95937cb7cd534fc98e8774a40d52622b32d8a199 GIT binary patch literal 512 zcmaE@u!XOS#m$DHgypQj>#v8m@NM8dE3kpwgSR`S~RZKKY3$sYME5hI$4Jp?Qf(IjIUI`3gm;i75)jC5h>&3PuX~ sX$mD7sR~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/stage4/bootblock2 b/stage4/bootblock2 new file mode 100644 index 0000000000000000000000000000000000000000..98b529f342ae8e5c5a10eb3f2bb31bba1e3d8eb8 GIT binary patch literal 984 zcmYk2Z%7ki9LJw?*R_tdtr|sOG$?~5g0r&3itNwxqGG6{tBjryl-5Hbg$@bL;CkWX zp%{Z+M$x-o`C^4b5Obs>S!G6ygbJ;AV#7phH^+I`b36ZZFOKi$`}^JZ_q*S(7e!HL z4-b!mRzB%Y|BXkT1DliX0Ws;0)9(iTZN$s{6$cI;syuw8s^;XW(`R6e2T|v%I8VOF zKV3Z!_Vg#+GxPD`yZt03=Rl{!Kf*G~l5UbxQ~nPz5vWV|N6WiC0ak6BgS5|xd(8)2 zAV1`cqc&JqFI^mmSpbxPU6I7n0ADHzB%l*XQv&=r%yXbRVDAuAlvk0iNWwVGF-sCn zE2kn&fqE&_2+SH`M|~YVX12F&WDRXa=@JEIC%-93Q>Uv^_w4Gl4`pqEyn^(qROdU6 zfs{*+UqcO-uUsOTtD~a1mbH_A#6QgzU<0e2A0u6R~+gKStCU zE~hXg6#Xci`Rn$>;HHwOM!M9?bday? z658T(g^lGV0&SV~)WUjl#$%<%*v%w6n>;x?Xal~~GtDS04S6o1Ac31AFi%icfxORT zALATBe;9M`&H4m^3k1!Xb(4LJ=LyOfVbKV)W9I3CzN&Ndr=|ax{^vEFqi-!eXM`8% z=$f9VFD=c|7U=UeJx?F&HS%%I0QYvBB?&S$%(KPSIeA3n1kE6y(_2?u(-SPO>W!xH;;xR$oB$|ictlnwYC zzQ$ViFBjlO0d_6pqEG^`;tf`EF~UtO9=9{%mhmPmhAKHMVv#OtOb>$svKO7z@MgxV sCY{n)ENd)y^tG1OPqwtQde65sHZ|Yz23s4iH+w6*H%)8;C%6Ro2i@+_I{*Lx literal 0 HcmV?d00001 diff --git a/stage4/bootblock2.o b/stage4/bootblock2.o new file mode 100644 index 0000000000000000000000000000000000000000..4c928c91b9d82e57ce76a379a5a8b9d555ad1e58 GIT binary patch literal 3776 zcma)ryXn6IzQTS41%nb40r7|-<uM5lq$jU7tXb%n(tbM1ZK z_wJIn*(UMI@B2QV=lQbIf?>|1~w{Ia4>|J>#D7PU(NC>i?)t`2(%n zcYNuAFYnydxp&|G2c-!I8T0&h%Ax(a@L~P4-`#v_#yfX?YVzBswAsQEd8#&W7CE-g zc(vKmY~YU*Zc_U6#5w;njUhybuSxpJ>Qoag<+n(IZKh{QlwH0JI_l?aE0B}wN#3fi&ABaRMw=$>PYQl z2lOD753hq@*f!r>lol_3P>hsIS9Z-l?J8Yqi7eVf%f(1#*X&al1VDIc{=6JHeCX?6 z(-yvY&P|tPtSN9da0Ls%gu6YLM~{E8@F_XAY4;uPjvl|OuuP6M{`m4}X-=5d-h7?> z=;Tx};=1>ljjM^A#`QUjTt&%cmmHc@DMsA(h*OJ{jX_~2%R*ys-uv9f;)uH_)oSl! zC(0kcTEw)%TcP2F)vRoJg@r~V>jd^J?83|!ua4VE%j{3eRkmo!Axsw|PT`U!Eo+g* zqU30y+yY+GBA-w(@8`*B?uddkF^&eC^3vJ~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@@ -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/stage4/xv6.img b/stage4/xv6.img new file mode 100644 index 0000000..6f9ef93 --- /dev/null +++ b/stage4/xv6.img @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e72ff56ad3e3b45619ce85e77f8a521e4ab77e93fc1b0154d51ccc93efc416a +size 5120000