From e55a90e358b070c0871c0f08560cabc5885930c7 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 12 Jan 2021 18:11:02 +0100 Subject: [PATCH 1/9] Fix --- src/bootloader.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index 02fb35b..6a8b7e8 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -34,8 +34,8 @@ loop: ; newline mov al, ASCII_CARRIAGE_RETURN int BIOS_INT - mov al, ASCII_LINEBREAK - int BIOS_INT + mov al, ASCII_LINEBREAK + int BIOS_INT ; Prepair for next iteration pop ax ; restore From bd7bf3ee859c46c561b24022be8b0fa602656d0f Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 12 Jan 2021 19:05:46 +0100 Subject: [PATCH 2/9] Removed unneeded stuff --- src/bootloader.asm | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index 6a8b7e8..7ec8b10 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -23,25 +23,25 @@ mov al, ASCII_LINEBREAK ; linebreak int BIOS_INT ; ALPHABET PRINT -mov al, 64 ; one less than A since we are printing in a loop and it increments before sys interupt -loop: - ; Print the alphabetic char - inc al ; move to next char - int BIOS_INT ; bios interupt to print it - - push ax ; push ax onto stack - - ; newline - mov al, ASCII_CARRIAGE_RETURN - int BIOS_INT - mov al, ASCII_LINEBREAK - int BIOS_INT - - ; Prepair for next iteration - pop ax ; restore - - cmp al, 90 ; 26 letters in english alphabet (64 + 26) - jl loop ; if al < 64+26: jmp loop +;; mov al, 64 ; one less than A since we are printing in a loop and it increments before sys interupt +;; loop: +;; ; Print the alphabetic char +;; inc al ; move to next char +;; int BIOS_INT ; bios interupt to print it + +;; push ax ; push ax onto stack + +;; ; newline +;; mov al, ASCII_CARRIAGE_RETURN +;; int BIOS_INT +;; mov al, ASCII_LINEBREAK +;; int BIOS_INT + +;; ; Prepair for next iteration +;; pop ax ; restore + +;; cmp al, 90 ; 26 letters in english alphabet (64 + 26) +;; jl loop ; if al < 64+26: jmp loop jmp $ From 56b0ac41f0b9480d9986a3e5c2c5385d7dd029ca Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 12 Jan 2021 19:23:25 +0100 Subject: [PATCH 3/9] Removed bad comments --- src/bootloader.asm | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index 7ec8b10..f374456 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -22,26 +22,15 @@ int BIOS_INT mov al, ASCII_LINEBREAK ; linebreak int BIOS_INT -; ALPHABET PRINT -;; mov al, 64 ; one less than A since we are printing in a loop and it increments before sys interupt -;; loop: -;; ; Print the alphabetic char -;; inc al ; move to next char -;; int BIOS_INT ; bios interupt to print it - -;; push ax ; push ax onto stack - -;; ; newline -;; mov al, ASCII_CARRIAGE_RETURN -;; int BIOS_INT -;; mov al, ASCII_LINEBREAK -;; int BIOS_INT - -;; ; Prepair for next iteration -;; pop ax ; restore - -;; cmp al, 90 ; 26 letters in english alphabet (64 + 26) -;; jl loop ; if al < 64+26: jmp loop +; ALPHABET PRINT TEST +mov al, 64 ; one less than A since we are printing in a loop and it increments before sys interupt +loop: + ; Print the alphabetic char + inc al ; move to next char + int BIOS_INT ; bios interupt to print it + + cmp al, 90 ; 26 letters in english alphabet (64 + 26) + jl loop ; if al < 64+26: jmp loop jmp $ From 064fc9f2c7aa01de92cac4cf3681e634f4a42bf1 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 12 Jan 2021 20:28:06 +0100 Subject: [PATCH 4/9] Print sr --- src/bootloader.asm | 17 +++++------------ src/elib/io.asm | 27 ++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index f374456..2ee71fb 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -1,26 +1,19 @@ %include "equ/BIOS.asm" %include "equ/ASCII.asm" +; eLIB +%include "elib/io.asm" + mov ah, BIOS_MODE_TELETYPE ; enter teletype mode (BIOS) mov al, ASCII_LINEBREAK ; linebreak int BIOS_INT -; Print "eOS" -mov al, "e" -int BIOS_INT +test db "eOS", ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK -mov al, "O" -int BIOS_INT - -mov al, "S" -int BIOS_INT -mov al, ASCII_CARRIAGE_RETURN -int BIOS_INT +; Print "eOS" -mov al, ASCII_LINEBREAK ; linebreak -int BIOS_INT ; ALPHABET PRINT TEST mov al, 64 ; one less than A since we are printing in a loop and it increments before sys interupt diff --git a/src/elib/io.asm b/src/elib/io.asm index 49b94f2..5607c03 100644 --- a/src/elib/io.asm +++ b/src/elib/io.asm @@ -1,2 +1,27 @@ ; eLibrary -; Input/Output sr +; Input/Output subroutines + +; String structure +; ASCII Offset = 8 bits +; Array of the char bytes, ending with 0 (ASCII_END) + +eLIB_STR_OFFSET equ 8 ; 8 bits + +print: ; Subroutine to print strings (from stack) + ; Input: RCX, takes pointer to string from stack + pop rcx + + ; rcx now holds the starting point (address) + + printLoop: + ; Print the char + mov al, [rcx] ; dereference address to get value + cmp al, ASCII_END ; check if ASCII end + je printExit ; if reached the end then return + + int BIOS_INT ; system interupt (print string) + add rcx, eLIB_STR_OFFSET ; increase with offset + jmp printLoop ; loop for next char + + printExit: + ret From dac804d3bf9852e0a32de7084e0756aa5943ed5d Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 12 Jan 2021 20:56:13 +0100 Subject: [PATCH 5/9] Print sr & stuff --- src/bootloader.asm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index 2ee71fb..53ff58a 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -2,18 +2,18 @@ %include "equ/ASCII.asm" ; eLIB -%include "elib/io.asm" +;; %include "elib/io.asm" mov ah, BIOS_MODE_TELETYPE ; enter teletype mode (BIOS) mov al, ASCII_LINEBREAK ; linebreak int BIOS_INT -test db "eOS", ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK - +;; test db "Welcome to eOS", ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK ; Print "eOS" - +;; mov rcx, test +;; call print ; ALPHABET PRINT TEST mov al, 64 ; one less than A since we are printing in a loop and it increments before sys interupt From a2eddaeba89be357d74c6758f370374eb75a3247 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 13 Jan 2021 11:59:13 +0100 Subject: [PATCH 6/9] Updated print sr to work --- src/bootloader.asm | 35 +++++++++++------------------------ src/elib/io.asm | 43 +++++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index 53ff58a..226de1b 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -1,32 +1,19 @@ +[org 0x7c00] ; bootsector + +jmp $ ; inf loop + +;; includes +; EQU %include "equ/BIOS.asm" %include "equ/ASCII.asm" ; eLIB -;; %include "elib/io.asm" - -mov ah, BIOS_MODE_TELETYPE ; enter teletype mode (BIOS) - -mov al, ASCII_LINEBREAK ; linebreak -int BIOS_INT - -;; test db "Welcome to eOS", ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK - -; Print "eOS" -;; mov rcx, test -;; call print - -; ALPHABET PRINT TEST -mov al, 64 ; one less than A since we are printing in a loop and it increments before sys interupt -loop: - ; Print the alphabetic char - inc al ; move to next char - int BIOS_INT ; bios interupt to print it - - cmp al, 90 ; 26 letters in english alphabet (64 + 26) - jl loop ; if al < 64+26: jmp loop - +;%include "elib/io.asm" -jmp $ +;; Data +welcomeString: + db "Welcome to eOS", ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK +; Magic BIOS number times 510-($-$$) db 0 db 0x55, 0xaa diff --git a/src/elib/io.asm b/src/elib/io.asm index 5607c03..fa9eb6d 100644 --- a/src/elib/io.asm +++ b/src/elib/io.asm @@ -1,27 +1,34 @@ ; eLibrary ; Input/Output subroutines -; String structure -; ASCII Offset = 8 bits -; Array of the char bytes, ending with 0 (ASCII_END) +; Subroutine to print a string +print: + pusha ; save current state of registers -eLIB_STR_OFFSET equ 8 ; 8 bits + printLoop: + ; Char check + mov al, [bx] ; load the char + cmp al, ASCII_END ; check if end of string + je return ; if al == ASCII_END then return end | lua is good psuedo-code -print: ; Subroutine to print strings (from stack) - ; Input: RCX, takes pointer to string from stack - pop rcx - ; rcx now holds the starting point (address) + ; BIOS Printing + mov ah, BIOS_MODE_TELETYPE ; enter tty mode + int BIOS_INT ; interupt and print the char (from line 10) - printLoop: - ; Print the char - mov al, [rcx] ; dereference address to get value - cmp al, ASCII_END ; check if ASCII end - je printExit ; if reached the end then return + ; Preperation for next iteration + inc bx ; increment the pointer to get next char + jmp printLoop ; repeat + + return: + popa ; restore all registers + ret ; return to previous location - int BIOS_INT ; system interupt (print string) - add rcx, eLIB_STR_OFFSET ; increase with offset - jmp printLoop ; loop for next char +; Subroutine to print a string on a new line +newline: + db ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK - printExit: - ret +println: + ; Print the newline + mov bx, newline + call print From 8c21f378418d982b7d1a2610f53f82853dc57286 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 13 Jan 2021 12:07:56 +0100 Subject: [PATCH 7/9] Println bug fix --- src/bootloader.asm | 7 +++++-- src/elib/io.asm | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index 226de1b..b685912 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -1,5 +1,8 @@ [org 0x7c00] ; bootsector +mov bx, welcomeString ; Print the welcome string +call println + jmp $ ; inf loop ;; includes @@ -8,11 +11,11 @@ jmp $ ; inf loop %include "equ/ASCII.asm" ; eLIB -;%include "elib/io.asm" +%include "elib/io.asm" ;; Data welcomeString: - db "Welcome to eOS", ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK + db "Welcome to eOS", ASCII_END ; Magic BIOS number times 510-($-$$) db 0 diff --git a/src/elib/io.asm b/src/elib/io.asm index fa9eb6d..939ec03 100644 --- a/src/elib/io.asm +++ b/src/elib/io.asm @@ -26,9 +26,17 @@ print: ; Subroutine to print a string on a new line newline: - db ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK + db ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK, ASCII_END println: + pusha + + ; Print the input string + call print ; this will print whatever is in [bx], so clear it if you dont want to print anything + ; Print the newline mov bx, newline call print + + popa + ret From df2db14bbabbf7316bcb86c8036103823429c310 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 13 Jan 2021 12:09:36 +0100 Subject: [PATCH 8/9] Refactor --- src/bootloader.asm | 3 +-- src/elib/io.asm | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index b685912..f07345c 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -14,8 +14,7 @@ jmp $ ; inf loop %include "elib/io.asm" ;; Data -welcomeString: - db "Welcome to eOS", ASCII_END +welcomeString: db "Welcome to eOS", ASCII_END ; Magic BIOS number times 510-($-$$) db 0 diff --git a/src/elib/io.asm b/src/elib/io.asm index 939ec03..10ed003 100644 --- a/src/elib/io.asm +++ b/src/elib/io.asm @@ -24,10 +24,10 @@ print: popa ; restore all registers ret ; return to previous location -; Subroutine to print a string on a new line -newline: - db ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK, ASCII_END +newline: db ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK, ASCII_END ; used for printing newlines + +; Subroutine to print a string on a new line println: pusha From feaafc7e0b7621c8e3fdf3ee3725195a8b91b446 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 13 Jan 2021 12:09:56 +0100 Subject: [PATCH 9/9] BIOS is not 64bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e2f4ef..1a73256 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # eOS -A simple x86_64 operating system (BIOS) +A simple x86 operating system (BIOS) This operating system is in no way original nor do I recommend even taking a look at it. I am only making this as a learning exercise. ## Books