Skip to content

Commit

Permalink
Added memory total system call and command - &mem. System vars now mo…
Browse files Browse the repository at this point in the history
…ved into correct position in memory according to map. Added a 'wait' system call using the PIT. Started RTC code. Moved vesa.inc into drivers folder. Added start of PCI device dump system call, showing device and vendor id's of connected PCI interfaces ref #1. Removed 16-bit macros file and replaced with functions_16.inc which now includes routines from e820 fixing #4. Removed initial memory count as was inaccurate / wrong.
  • Loading branch information
triforce committed Feb 27, 2015
1 parent 2438b05 commit 609c20e
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 349 deletions.
Binary file modified imgs/build.img
Binary file not shown.
28 changes: 0 additions & 28 deletions src/constants.inc

This file was deleted.

64 changes: 51 additions & 13 deletions src/drivers/pci.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ PCI_CONFIG_ADDRESS equ 0xCF8

PCI_CONFIG_DATA equ 0xCFC

; ================================================
; ========================================================
; drv_pci_read
; -------------
; ------------
; IN - EAX = 00000000 00000000 00000000 00000000
; (Unused) Bus Num Dev/Fun Num Reg Num
; OUT - EAX = contains pci register information
; ================================================
; ========================================================

drv_pci_read:
push rax rbx rdx rcx
and eax, 0x00ffffff ; Set bits 24-31 to zero
Expand All @@ -37,7 +38,14 @@ drv_pci_read:
drv_done_pci_read:
pop rax rbx rdx rcx
ret

; ==============================================
; drv_pci_init
; ------------
; IN - None
; OUT - [k_pci_enabled] = Set to 1 if successful
; ==============================================

drv_pci_init:
push rdx rcx rbx rax
mov eax, 0x80000000
Expand All @@ -48,6 +56,7 @@ drv_pci_init:
xor edx, edx
cmp eax, ebx
je drv_set_pci_init
mov dl, 0
jmp drv_done_pci_init
drv_set_pci_init:
Expand All @@ -57,25 +66,54 @@ drv_pci_init:
mov byte [k_pci_enabled], dl
pop rdx rcx rbx rax
ret
drv_pci_scan:
push rdx rcx rbx rax

xor rcx, rcx
xor rax, rax
mov ecx, 0x8000000 ; Set bit 31
; ===========================================================
; drv_pci_scan
; ------------
; Scan for PCI devices and output hex format of device/vendor
; IN / OUT - None
; ===========================================================

drv_pci_scan:
push rdx rcx rbx rax

xor rcx, rcx
xor rax, rax
mov ecx, 0x8000000 ; Set bit 31
mov [k_pci_devices], 0
mov [k_pci_device], 0

drv_pci_scan_next:
mov eax, ecx
mov dx, PCI_CONFIG_ADDRESS
out dx, eax
mov dx, PCI_CONFIG_DATA
in eax, dx
; If all bits are set in eax then no device exists, if not eax will contain the device/vendor id
; If all bits are set in eax then no device exists, if not eax will contain the device/vendor
cmp eax, 0xffffffff
je drv_pci_scan_not_present
; Print eax
; Keep a count of devices
inc [k_pci_devices]
; TODO store list of devices
; mov [k_pci_list], eax

; Output device / vendor
push rcx
mov [k_pci_device], eax
mov al, byte [k_pci_device+3]
call sys_hex_print
mov al, byte [k_pci_device+2]
call sys_hex_print
mov al, byte [k_pci_device+1]
call sys_hex_print
mov al, byte [k_pci_device+0]
call sys_hex_print
mov esi, '-'
mov ecx, 1
call sys_character_print
pop rcx

drv_pci_scan_not_present:
add ecx, 0x800
cmp ecx, 0x81000000
Expand Down
File renamed without changes.
10 changes: 7 additions & 3 deletions src/drivers/vga.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
; =========================================================

ScreenYPos dd 0
ScreenWidth dd 0
ScreenLines dd 2 ; Memory total requires two lines currently
ScreenWidth dd 0
ScreenLines dd 0 ; Memory total requires two lines currently
ScreenBuf1 dd 0
ScreenBuf2 dd 0
CursorPosition dd 0
CursorPosition dd 0

; 80 x 25
MinX equ 80
MinY equ 25

; VGA Settings
; AX
Expand Down
171 changes: 51 additions & 120 deletions src/inc/e820.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,88 +14,88 @@ ram_88h_msg db 'Memory Available Above 1MB (kb): ', 0
detect_memory:

do_e820:
pusha
pusha

mov [total_mem], dword 0
mov [total_mem], dword 0

mov di, e820_buffer
xor ebx, ebx
mov edx, 0534D4150h
mov ecx, e820_bufferLength
mov eax, 0E820h
int 15h
jc .nsupported
mov di, e820_buffer
xor ebx, ebx
mov edx, 0534D4150h
mov ecx, e820_bufferLength
mov eax, 0E820h
int 15h
jc .nsupported

.e820_check_1:
cmp eax, 0534D4150h
stc
jne .e820_check_4
cmp eax, 0534D4150h
stc
jne .e820_check_4

push ebx
push ecx

mov eax, dword [di + 16]
cmp eax, 1
jg .not_os
mov eax, [di + 8]
add eax, [total_mem]
mov [total_mem], eax ; Save total mem
jmp .print_values
mov eax, dword [di + 16]
cmp eax, 1
jg .not_os
mov eax, [di + 8]
add eax, [total_mem]
mov [total_mem], eax ; Save total mem
jmp .print_values

.not_os:
cmp eax,2
jg .not_reserved
jmp .print_values
cmp eax,2
jg .not_reserved
jmp .print_values

.not_reserved:
cmp eax, 3
jg .not_reclaimed
jmp .print_values
cmp eax, 3
jg .not_reclaimed
jmp .print_values

.not_reclaimed:
cmp eax, 4
jg .handle_acpinvs
jmp .print_values
cmp eax, 4
jg .handle_acpinvs
jmp .print_values

.handle_acpinvs:
cmp eax, 5
jg .print_values
cmp eax, 5
jg .print_values

.print_values:
; TODO

.e820_check_2:
pop ecx
cmp ecx, 24
jne .end_record
test dword [di + 20], 1
je .ignore
jmp .non_volatile
pop ecx
cmp ecx, 24
jne .end_record
test dword [di + 20], 1
je .ignore
jmp .non_volatile

.ignore:
; TODO

.non_volatile:
test dword [di + 20], 1 shl 1
jne .end_record
test dword [di + 20], 1 shl 1
jne .end_record

.end_record:
pop ebx
or ebx, ebx
je .e820_check_3
pop ebx
or ebx, ebx
je .e820_check_3

mov edx, 0534D4150h
mov ecx, e820_bufferLength
mov eax, 0E820h
int 15h
mov edx, 0534D4150h
mov ecx, e820_bufferLength
mov eax, 0E820h
int 15h

jnc .e820_check_1
jnc .e820_check_1

.e820_check_3:
clc
clc

.e820_check_4:
jmp .finish_e820
jmp .finish_e820

.nsupported:
mov [mem_check], 0
Expand All @@ -104,26 +104,8 @@ do_e820:
int 10h

.finish_e820:
popa
mov si, ram_e820h_msg
call print_string

mov ax, total_mem
call print_register

mov si, line
call print_string

mov si, ram_88h_msg
call print_string
call do_e88h

mov si, line
call print_string

xor eax, eax
mov eax, total_mem
;jmp $
popa
call do_e88h
ret

do_e88h:
Expand All @@ -132,7 +114,6 @@ do_e88h:
int 15h
jc .nsupported_88
mov [user_mem], ax
call print_register
pop ax
ret

Expand All @@ -141,54 +122,4 @@ do_e88h:
mov al, 'n'
mov ah, 0eh
int 10h
ret

; TODO move into library
print_string:
; Pushes contents of ax to top of stack
push ax
; Decrements the stack pointer and then stores AX on the top of the stack

@@:
; Loads byte from ds:si into AL
lodsb
; Check if AL is 0
or al, al
jz .ret
mov ah, 0eh

; Teletext output, AL = character to write
int 10h
jmp @b

.ret:
; Loads the value from the top of the stack to AX, increment pointer
pop ax

ret

; TODO move into library
print_register:
pusha
push 0
mov bx, 10
@@:
xor dx, dx
div bx
add dx, '0'
push dx
or al, al
jz @f
jmp @b

@@:
pop ax
or al, al
jz @f
mov ah, 0Eh
int 10h
jmp @b

@@:
popa
ret
ret
Loading

0 comments on commit 609c20e

Please sign in to comment.