aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <David@FAMILY.(none)>2012-10-01 17:28:01 +1300
committerunknown <David@FAMILY.(none)>2012-10-01 17:28:01 +1300
commit52c86bd6941b210dfdaba1c7852e6eb49b7899b2 (patch)
treeb0fa2b82660caa836170f12ab98e5061a32beaac
downloadjaspos-52c86bd6941b210dfdaba1c7852e6eb49b7899b2.tar.xz
Initial commit
-rw-r--r--apm.asm49
-rw-r--r--diskio.asm21
-rw-r--r--jasposkernel.asm73
-rw-r--r--shell.asm8
-rw-r--r--strings.asm43
-rw-r--r--textvga.asm137
6 files changed, 331 insertions, 0 deletions
diff --git a/apm.asm b/apm.asm
new file mode 100644
index 0000000..1f06116
--- /dev/null
+++ b/apm.asm
@@ -0,0 +1,49 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Connect APM interface
+apm_ConnectInterface:
+ push ax ; Push some registers
+ push bx ;
+ mov si, apm_msgConnectingInterface ; Display a message saying that we're connecting the interface
+ call OutText ;
+ mov ax, 0x5301 ; 0x5301 - connect interface subfunction
+ xor bx, bx ; zero-out bx
+ int 0x15 ; Int 15.5301 - connect APM interface
+ jc .error ; Jump to .error if interrupt set cf on error
+.quit:
+ pop bx ; Pop our registers back off the stack
+ pop ax ;
+ ret
+.error:
+ mov si, msgFailedWithCode ; Display a message explaining that it failed
+ call OutText ;
+ xor dx, dx ; clear DX
+ mov dl, ah ; load DL with number to convert
+ call NumberToString ; Convert DL to string in NumberBuffer
+ mov si, NumberBuffer ; Load address on NumberBuffer for printing
+ call OutText ; Print NumberBuffer
+ jmp .quit ; Jump to .quit for some POPping and then return
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Power-off the computer using APM interface
+apm_PowerOff:
+ mov ax, 0x5307 ; 5307 - Set power state
+ mov bx, 0x0001 ; 0001 - Device: BIOS
+ mov cx, 0x0003 ; 0003 - power state: off
+ int 0x15 ; Int 15.5307 - set power state using APM interface
+ jc .error
+ ret
+.error:
+ mov si, msgFailedWithCode ; Print a message to tell the user a failiure happened
+ call OutText ;
+ xor dx, dx ; Zero-out DX
+ mov dl, ah ; Load DL with number to convert
+ call NumberToString ; Convert DL to string in NumberBuffer
+ mov si, NumberBuffer ; Load NumberBuffer address for printing
+ call OutText ; Print NumberBuffer
+ mov si, msgNewLine ;
+ call OutText ;
+ mov si, apm_msgPowerOffFailed ;
+ call OutText ;
+ ret
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; \ No newline at end of file
diff --git a/diskio.asm b/diskio.asm
new file mode 100644
index 0000000..fa1524c
--- /dev/null
+++ b/diskio.asm
@@ -0,0 +1,21 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Reset the disk system
+;; DL must be disk to reset
+diskio_ResetDiskSystem:
+ pop ax
+ pop dx
+ push ax
+ xor ah, ah
+ int 0x13
+ ret
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+diskio_DumpBootSector:
+ xor bx, bx
+ mov es, bx
+ mov bx, diskio_SectorBuffer ; ES:BX = address
+ mov dl, [Drive] ; DL = Drive number
+ mov ah, 2 ; AH = Read command
+ int 0x13 ; Read sector
+ push diskio_SectorBuffer
+ call OutText
+ ret
diff --git a/jasposkernel.asm b/jasposkernel.asm
new file mode 100644
index 0000000..ccc7dbc
--- /dev/null
+++ b/jasposkernel.asm
@@ -0,0 +1,73 @@
+Entry:
+ mov ax, cs
+ mov ds, ax
+ mov es, ax
+ mov ss, ax
+ ;mov esp, 0x7FFFF
+ mov sp, 0xFFFE
+ call ClearScreen ; Clear the screen
+ mov [Drive], dl ; Get the drive we booted from before we go and mess with dl
+
+ push msgJasposSplash ;
+ call OutText ;
+
+ call GetKey ;
+ call diskio_ResetDiskSystem
+ call diskio_ResetDiskSystem
+ call diskio_ResetDiskSystem
+ call diskio_DumpBootSector
+ call GetKey
+ call apm_ConnectInterface ;
+ call apm_PowerOff ;
+ jmp short Halt
+
+GetKey:
+ xor ax, ax ; Zero-out EAX
+ int 0x16 ; Int 16.00 - wait for keypress
+ ret ; Return
+
+Halt:
+ xor ax, ax ; Zero-out AX
+ int 0x16 ; Int 16.00 - wait for keypress
+ jmp Halt ; Loop
+
+ClearNumberBuffer:
+ push cx ; Push the registers we'll be messing with
+ push ax ;
+ push di ;
+ mov al, '0' ; AL = "0" - char to fill buffer with
+ mov cx, 5 ; write 0 six times
+ mov di, NumberBuffer ; Destination is NumberBuffer
+ rep stosb ; Store the byte AL CX times
+ pop di ; Pop our regisers back off the stack
+ pop ax ;
+ pop cx ;
+ ret
+
+ShowFiles:
+ pop ax
+ pop si
+ push ax
+ cld
+ mov di, diskio_SectorBuffer
+ mov cx, 16
+ rep movsb
+
+ push msgFile
+ call OutText
+ push diskio_SectorBuffer
+ call OutText
+
+ mov di, diskio_SectorBuffer
+ mov cx, 16
+ rep movsb
+ push msgAuthor
+ call OutText
+ push diskio_SectorBuffer
+ call OutText
+ ret
+
+%include "Kernel/textvga.asm"
+%include "Kernel/apm.asm"
+%include "Kernel/strings.asm"
+%include "Kernel/diskio.asm" \ No newline at end of file
diff --git a/shell.asm b/shell.asm
new file mode 100644
index 0000000..b73db67
--- /dev/null
+++ b/shell.asm
@@ -0,0 +1,8 @@
+Main:
+ call GetKey
+ mov ah, 0x0E
+
+GetKey:
+ xor ax, ax
+ int 0x16
+ ret
diff --git a/strings.asm b/strings.asm
new file mode 100644
index 0000000..b92cf6e
--- /dev/null
+++ b/strings.asm
@@ -0,0 +1,43 @@
+msgMmmBooting db "Mmm.. booting!",13,10,0
+msgFailedWithCode db 1,0x0C,"Failed",1,0x07," with error code: ",0
+msgWaitingKeypress db "Waiting for a keypress...",13,10,0
+msgNewLine db 13,10,0
+msgJasposSplash db 13,13,13,10,
+ db " ",1,0x07,"ллллллллллллллллллллллллллллллллллллллл",13,10,
+ db " ВВВВВлллллллллллллллллллллллллллллллллллллллВВВВВ",13,10,
+ db " БББББВВВВВлллллллллллллллллллллллллллллллллллллллВВВВВБББББ",13,10,
+ db " АААААБББББВВВВВлллллллллллллллллллллллллллллллллллллллВВВВВБББББААААА",13,10,
+ db " АААААБББББВВВВВлл",1,0x20," ",1,0x07,"лл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"лл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"лллВВВВВБББББААААА",13,10,
+ db " АААААБББББВВВВВлллл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"л",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"л",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"л",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"л",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"ллВВВВВБББББААААА",13,10,
+ db " АААААБББББВВВВВлллл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"лл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"лл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"лл",1,0x20," ",1,0x07,"ллллВВВВВБББББААААА",13,10,
+ db " АААААБББББВВВВВлллл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"лллл",1,0x20," ",1,0x07,"лл",1,0x20," ",1,0x07,"ллллл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"лллл",1,0x20," ",1,0x07,"лллВВВВВБББББААААА",13,10,
+ db " АААААБББББВВВВВлллл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"л",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"л",1,0x20," ",1,0x07,"ллллл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"л",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"ллВВВВВБББББААААА",13,10,
+ db " АААААБББББВВВВВлл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"лл",1,0x20," ",1,0x07,"лл",1,0x20," ",1,0x07,"лллллл",1,0x20," ",1,0x07,"ллл",1,0x20," ",1,0x07,"лллВВВВВБББББААААА",13,10,
+ db " АААААБББББВВВВВлллллллллллллллллллллллллллллллллллллллВВВВВБББББААААА",13,10,
+ db " АААААБББББВВВВВллл",1,0x70," Kernel Version : 1.0 ",1,0x07,"лллВВВВВБББББААААА",13,10,
+ db " АААААБББББВВВВВллл",1,0x70," Compilation Date: 2012-06-24 ",1,0x07,"лллВВВВВБББББААААА",13,10,
+ db " АААААБББББВВВВВллл",1,0x70," Author : David Phillips",1,0x07,"лллВВВВВБББББААААА",13,10,
+ db " АААААБББББВВВВВлллллллллллллллллллллллллллллллллллллллВВВВВБББББААААА",13,10,
+ db " БББББВВВВВлллллллллллллллллллллллллллллллллллллллВВВВВБББББ",13,10,
+ db " ВВВВВлллллллллллллллллллллллллллллллллллллллВВВВВ",13,10,
+ db " ллллллллллллллллллллллллллллллллллллллл",13,10,0
+
+;0000084D 07 pop es
+CharColour db 7d
+;0000084E 3030 xor [bx+si], dh
+NumberBuffer db "00000",0
+HexNumberBuffer db "00",0
+;00000850 3030 xor [bx+si], dh
+;00000852 3000 xor [bx+si], al
+;00000854 0000 add [bx+si], al
+VGAMemPointer dw 0
+apm_msgConnectingInterface db "Connecting APM interface...",13,10,0
+apm_msgPoweringOff db "Powering-off...",13,10,0
+apm_msgPowerOffFailed db "I requested that the system turns off but it hasn't done so.",13,10,
+ db "You may instead turn the power to your system off now. It's safe.",0
+msgPowerOff db "I'll turn the computer off now.",13,10
+Drive db 0xFF
+diskimage db "KERNEL ","JASPOS DEVELOPER",0," "
+msgFile db "File: ",0
+msgAuthor db "Author: ",0
+diskio_SectorBuffer times (512) db 0 \ No newline at end of file
diff --git a/textvga.asm b/textvga.asm
new file mode 100644
index 0000000..19f42e5
--- /dev/null
+++ b/textvga.asm
@@ -0,0 +1,137 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Print text onto the text screen
+OutText:
+ pop ax
+ pop si
+ push ax
+ mov ax, 0xB800 ; Load AX with the VGA segment
+ mov es, ax ; and then ES
+ mov di, [VGAMemPointer] ; Load DI with VGA memory pointer
+
+.loop:
+ lodsb ; Load a byte from the string into AL
+ or al, al ; Do a byte comarison on the char
+ jz .Quit ; Exit the function if it's a null
+ cmp al, 1 ; Check to see if it's a colour control char
+ jz .SetColour ; If so, jump to handle it
+ cmp al, 13d ; Is the byte a CR?
+ jz .cr ; if so, jump
+ cmp al, 10d ; Is the byte a LF?
+ jz .lf ; Jump if it is
+ stosb ; Store the byte in memory. This happens if it's not a control char
+ mov al, [CharColour] ; Load the current char colour
+ stosb ; Store the char colour in the byte after the character
+ jmp short .loop ; Loop
+
+.cr:
+ add di, 160d ; Add 160 to the byte pointer, thus moving the pointer down one line
+ jmp short .loop ; Jump back to top of the loop
+
+.lf:
+ mov ax, di ; Move our current position/pointer into AX
+ mov di, 160d ; Load DI with 160 (# of bytes per line)
+ div di ; AX = AX / DI and DX = remainder
+ mul di ; AX = AX * DI
+ mov di, ax ; So now AX has been divided and had the remainder chopped off in doing so
+ jmp short .loop ; and is now multiplied back, so the pointer is now at the start of current line
+
+.SetColour:
+ lodsb ; Load the byte
+ mov [CharColour], al ; Set the CharColour to that byte
+ jmp short .loop ; Go back to top of loop
+
+.Quit:
+ mov [VGAMemPointer], di ; Move the updated cursor position into VGAMemPointer
+ ret ; Return to where this function was called
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Clear the text screen
+ClearScreen:
+ push ax ; push our registers used
+ push cx
+ push di
+ push es
+ mov ax, 0xB800 ; Load AX with the VGA segment
+ mov es, ax ; And then load ES with AX
+ xor di, di ; Set our reading pointer to the base of the segment
+ mov cx, 0x7D0 ; We'll be looping 2000 times
+.loop:
+ mov al, 0x20 ; Load AL with character to clear address with
+ stosb ; Store our byte
+ mov al, [CharColour] ;
+ stosb ;
+ loop .loop ; Loop
+ xor ax, ax ; Zero-out AX
+ mov [VGAMemPointer], ax ; Load nulled-out AX into pointer
+ pop es
+ pop di
+ pop cx
+ pop ax ; pop registers we used back off stack
+ ret
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Set the cursor position
+SetCursorPosition:
+ push ax ; Push our registers
+ push bx ;
+ mov ah, 2 ; Subfunction 2 - set cursor pos.
+ xor bh, bh ; clear BH
+ int 0x10 ; Int 10.02 - set cursor position
+ pop bx ; Pop registers back off stack
+ pop ax ;
+ ret
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Convert decimal in dx to string in NumberBuffer
+NumberToString:
+ std
+ pop dx
+ mov cx, 0x5
+ lea di, [NumberBuffer + 4]
+.loop:
+ mov ax, dx
+ mov dx, 10d
+ div dl
+ mov dl, al
+ mov al, ah
+ add al, 0x30
+ stosb
+ loop .loop
+ cld
+ ret
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Convert he value in al to string in HexNumberBuffer
+HexToString:
+ mov di, HexNumberBuffer
+ xor ah, ah ; zero-out ah so shifiting doesn't cause bits of ah to come into al
+ push ax ; save AL
+ shr al, 4 ; Shift AL along 4 bits
+ add al, 48d ; add 48 onto it
+ cmp al, 57d ; see if it's > 9
+ jg .letter
+.return:
+ stosb
+ pop ax
+ shl al, 4
+ shr al, 4
+ add al, 48d
+ cmp al, 57d
+ jg .letter_last_digit
+ stosb
+.quit:
+ ret
+
+.letter:
+ add ax, 7d
+ jmp .return
+
+.letter_last_digit:
+ add ax, 7d
+ stosb
+ jmp .quit
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; \ No newline at end of file