OK, now I am stuck. It does not look like any data is being saved into the RAM even though it looks as though it is being read... Here is the complete (censored) code.
Code: Select all
;
%define os_version '###'
%define v_name '###'
%define v_code '0.0.2'
%define v_mod 'Dev'
;Set info for NASM
BITS 16 ;Code bitness
ORG 0x00 ;Start location of instructions in file
;(Optional, the default is zero but this is included for clarity)
%define segment_address 0x07C0
%define stage1_address 0x5000
%define stage1_segment 0x0500
;
;Debugging switches, 0 = NO_DEBUG & 1 = DEBUG
%assign DEBUG_CLEAR_LOOP_PRINT_ADDRESS 0 ;Print the address that the ram clearing loop is at
%assign DEBUG_DISK_DONE_RESET 0 ;Reset boot device after read was successful
%assign DEBUG_JERRY_RIG_JUMP 0 ;Force use of far return to accomplish jump into os loader
%assign DEBUG_DISABLE_JUMP 0 ;Disable jump into os loader
%assign DEBUG_HALT_JUMP 0 ;If jump is disabled and jerry rig jump is disabled then this will act as if it is on
%assign DEBUG_ENABLE_HANG_OVER_HALT 0 ;If hang is jumped to and this is enabled, then halt will be jumped to
%assign DEBUG_HALT_STRING 0 ;Print a string if halt is jumped to
%assign DEBUG_HANG_STRING 0 ;Print a string if hang is jumped to
;
;Boot Stage 0
main:
jmp 0x07C0:.start ;Set CS to correct location
.start:
;Dissable interupts for stack operations
cli
;Setup stacks for kernel
mov ax, segment_address ;Start address of stacks
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
;Setup ss and sp registers and stacks
mov ax, 0x0600 ;0x6000
mov ss, ax
xor ax, ax
mov sp, ax
;Enable interupts, stack operations done
sti
pusha ;Store registers while we prep the RAM and print messages
;Setup video mode
xor bx, bx
xor cx, cx
xor dx, dx
mov ah, 0x00 ;Int 10h set video mode
mov al, 0x12 ;640x480, 16 colors, VGA
int 10h
;Print some intro text while booting
mov bl, 0x09 ;Light blue bios color
mov si, os_s
call print_string
mov si, v_s
call print_string
mov bl, 0x03 ;Cyan bios color
mov si, by_s
call print_string
mov bl, 0x01 ;Blue bios color
mov si, lcs_s
call print_string
;move cursor under text
mov ah, 0x02 ;Cursor move function
mov dx, 0x0400 ;Y axis + ;X axis
int 10h
;draw border
mov ax, 0x09F0 ;Repeat print function, ;Three horizontal lines
mov cx, 0x50 ;Number of times to print
int 10h
popa ;Restore registers, RAM is preped to store the data
.boot_id_store0:
;Store boot device ID in RAM at 0x1002, device ID in DL
mov ax, 0x0100
mov es, ax
mov byte [es:0x0002], dl
mov ax, segment_address
mov es, ax
;Continue onto read_disk
read_disk:
.prep:
;Print string
mov si, starting_stage1_s
call update_status
mov byte [errors_b], 0x07 ;Counter for errors, 7 trys
.values:
;Reset the disk and load it with disk geom' ... dl has disk BIOS ID already loaded above
xor ax, ax ;Int 13 disk reset
int 13h ;Reset disk
;
xor bx, bx ;0x0000, Location to write sectors at in relation to es
mov ax, 0x0207 ;Int 13h read sector function, al; Number of sectors to read,
;fills RAM allocated for Boot Stage 1 (3,584 bytes, 7 sectors)
mov cx, 0x0002 ;Set cylinder + Set sector to start reading at... NOTE: Cylinders start at 0, Sectors start at 1
mov dh, 0x00 ;Set head
;
push bx
mov bl, 0x02 ;Bios color green
call print_dx ;#########################DEBUGGING OUTPUT
pop bx
;
;Setup es for data transfer, segment for writing os loader
mov ax, stage1_segment
mov es, ax
.loop:
;Read code
int 13h ;Perform read
jnc .done ;If read worked
cmp byte [ds:errors_b], 0x00
je .error ;Check if counter is zero
;If not...
dec byte [ds:errors_b]
;Print errors
pusha
mov bl, 0x02 ;Bios color green
mov dh, byte [ds:errors_b]
call print_dx
popa
jmp .values ;Try to read again
.error:
;Restore es to es address
mov ax, segment_address
mov es, ax
xor ax,ax ;Int 13 disk reset
int 13h ;Reset disk
mov si, disk_error_s
mov bl, 0x04 ;Bios color red
call update_status
mov dx, ax
call print_dx
jmp hang ;Stall system, cannot boot
.done:
;Restore es to ds address
mov ax, segment_address
mov es, ax
;Calculate and store number of read failures
mov cl, byte [ds:errors_b]
mov ax, 0x0007 ;Store value to operate against
sub ax, cx ;Get fails
mov cx, 0x0100
mov es, cx
mov byte [es:0x0003], al ;Store number of read failures in 0x1003
mov cx, segment_address
mov es, cx
mov dx, ax
mov bl, 0x07
call print_dx
;
;Continue onto start_boot
start_boot:
%if ((!DEBUG_HALT_JUMP) || (DEBUG_DISABLE_JUMP && !DEBUG_JERRY_RIG_JUMP))
%if !DEBUG_DISABLE_JUMP && !DEBUG_JERRY_RIG_JUMP
;Jump to 0x0500:0x0000 which sets: CS=0x0500 IP=0x0000
;Test first byte to check if it is there
mov ax, 0x0500
mov es, ax
mov bl, 0x09
mov dx, word [es:0x0000]
call print_dx
mov ax, segment_address
mov es, ax
;JUMP!!!!!
jmp stage1_segment:0x0000
%endif
%if DEBUG_JERRY_RIG_JUMP
;A work around that far returns (jumps) to correct address
push word 0x0000
push word stage1_address ;0x5000
retf
%endif
%else
;Halt processor
jmp hang
%endif
;A hang method used in debugging, this hangs the system forever!
hang:
%if DEBUG_HANG_STRING
mov si, hang_s
mov bl, 0x04 ;Bios color red
call update_status
%endif
%if DEBUG_ENABLE_HANG_OVER_HALT
.hang:
jmp .hang ;Jump to hang infinitly
%else
jmp halt ;Uses halt over hang because it is more useful at this point
%endif
;Same as in os_loader, uses bl as color and si for string
update_status:
pusha
mov bl, 0x02 ;Bios color green
;move cursor to bottom
mov ah, 0x02 ;Cursor move function
mov dh, 0x1A ;Y axis
mov dl, 0x00 ;X axis
int 10h
;bottom border
mov ah, 0x09 ;Repeat print function
mov al, 0xDC ;Lower Half Block
mov cx, 0x50 ;Number of times to print
int 10h
;move cursor to top
mov ah, 0x02 ;Cursor move function
mov dh, 0x18 ;Y axis
mov dl, 0x00 ;X axis
int 10h
;top border
mov ah, 0x09 ;Repeat print function
mov al, 0xDF ;Upper Half Block
mov cx, 0x50 ;Number of times to print
int 10h
;move cursor to string
mov ah, 0x02 ;Cursor move function
mov dh, 0x19 ;Y axis
mov dl, 0x00 ;X axis
int 10h
;clear
mov ah, 0x09 ;Repeat print function
mov al, ' ' ;Space
mov cx, 0x50 ;Number of times to print
int 10h
;move cursor to bottom
mov ah, 0x02 ;Cursor move function
mov dh, 25 ;Y axis
mov dl, 0x00 ;X axis
int 10h
popa
call print_string
ret
;From print_string_color in io.asm
;Print string to screen
;Uses si register for string, and bl for bios color
print_string:
.prep:
pusha
mov ah, 0x0E ;Int 10h teletype mode
cmp bx, 0x0000 ;Check if message will be unreadable
jne .print
mov bl, 0x01 ;Set to white on black if it is-^
.print:
lodsb ;Load next char from ds into al using si
or al, al ;Check for 0 to indicate end of string
jz .done ;Break from loop if al is 0
int 10h ;Int 10h for print
jmp .print ;Loop
.done:
popa
ret ;Return from print_string
;Prints a ASCI string that represents the number in dx
;Uses dx for number to print, bl for bios color
print_dx:
.prep:
;Save registers
pusha
;
mov cl, 0x04 ;Set counter to 4
.calc:
rol dx, 0x0004 ;Rotate dx over 4 bits
mov al, dl ;Store dl in al
and al, 0x0F ;Lop off the last 12 bits to leave us the first 4 bits
cmp al, 0x09 ;Check if number needs A-F
jbe .add48 ;If number needs A-F
.add55: ;Number is A-F
add al, 0x07 ;Convert number to asci A-F
.add48: ;Number is 0-9
add al, 0x30 ;Convert number to asci 0-9
.print:
dec cl ;Decrement counter
push cx ;Save counter
mov ah, 0x0E ; Int 10 teletype mode
int 10h ;Print char
pop cx ;Restore counter
cmp cl, 0 ;Check if counter is 0
jne .calc ;If counter is not 0, continue loop
.done:
;Restore registers
popa
ret
;A halt method used in debugging, this halts the system forever!
halt:
%if DEBUG_HALT_STRING
mov si, halt_s
mov bl, 0x04 ;Bios color red
call update_status
%endif
hlt ;Halt Processor
;Strings
os_s db '### OS ', 0
by_s db 'By: Trevor ###', 13, 10, 0
lcs_s db '###', 13, 10, 10, 0
v_s db os_version, 10, 0
new_line_s db 13, 10, 0
;hang_s db 'Hang!', 0
;halt_s db 'Halt!', 0
disk_error_s db 'Boot disk error: ', 0
starting_stage1_s db 'Reading Boot Disk', 0
errors_b db 0x00
;End of file
times 510-($-$$) db 0x00
;End bytes
db 0x55
db 0xAA