Fixed memory lea issue in stage 4

Added Stage 5 polygon and array functions
This commit is contained in:
iDunnoDev
2022-11-22 00:38:22 +00:00
committed by iDunnoDev
parent d679b2b6bf
commit 1b040423c3
19 changed files with 1388 additions and 5 deletions

View File

@ -275,14 +275,14 @@ cons_filled_rect_check_x_dir:
cmpw $0, %ax
jge cons_filled_rect_check_y_dir
add %ax, rectx(%bp)
neg rectwidth(%bp)
negw rectwidth(%bp)
cons_filled_rect_check_y_dir:
movw rectheight(%bp), %ax # Check if the user has entered a negative height value and swap the direction to a pos
cmpw $0, %ax
jge cons_filled_rect_check_x_zero
add %ax, recty(%bp)
neg rectheight(%bp)
negw rectheight(%bp)
cons_filled_rect_check_x_zero:
movw rectx(%bp), %ax # Check if the x value is a negative value, set it to 0 and figure out the offset so we
@ -344,8 +344,7 @@ cons_filled_rect_setup:
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 # Load the memory address into the bx register
movw %ax, %bx # Load the memory offset address into the bx register
movw rectheight(%bp), %si # Set the counter to our height which should be the number of lines to draw to

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
stage4/xv6.img (Stored with Git LFS)

Binary file not shown.

19
stage5/.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,19 @@
{
// 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": []
},
{
"label": "Build and QEMU (debug)",
"type": "shell",
"command": "make qemu-gdb",
"problemMatcher": []
}
]
}

102
stage5/Makefile Normal file
View File

@ -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

101
stage5/bootasm.S Normal file
View File

@ -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"

1
stage5/bootasm.d Normal file
View File

@ -0,0 +1 @@
bootasm.o: bootasm.S

BIN
stage5/bootasm.o Normal file

Binary file not shown.

1138
stage5/bootasm2.S Normal file

File diff suppressed because it is too large Load Diff

1
stage5/bootasm2.d Normal file
View File

@ -0,0 +1 @@
bootasm2.o: bootasm2.S

BIN
stage5/bootasm2.o Normal file

Binary file not shown.

BIN
stage5/bootblock Normal file

Binary file not shown.

BIN
stage5/bootblock.o Normal file

Binary file not shown.

BIN
stage5/bootblock2 Normal file

Binary file not shown.

BIN
stage5/bootblock2.o Normal file

Binary file not shown.

19
stage5/sign.pl Normal file
View File

@ -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;

BIN
stage5/xv6.img (Stored with Git LFS) Normal file

Binary file not shown.