Initial work on the bootloader
This commit is contained in:
parent
6fdc308faa
commit
86c0c87425
|
@ -65,3 +65,7 @@ compile_commands.json
|
||||||
CTestTestfile.cmake
|
CTestTestfile.cmake
|
||||||
_deps
|
_deps
|
||||||
|
|
||||||
|
# TSOS stuff
|
||||||
|
|
||||||
|
*.bin
|
||||||
|
dist/
|
|
@ -1,3 +1,10 @@
|
||||||
# TSOS
|
# TSOS
|
||||||
|
|
||||||
The Simple Operating System
|
A toy project to implement:
|
||||||
|
- A BIOS-compatible bootloader written in x86 Assembly
|
||||||
|
- A 32-bit kernel and associated operating system written in C
|
||||||
|
- Drivers (keyboard, VGA, etc.)
|
||||||
|
- Dynamic memory management
|
||||||
|
- A shell
|
||||||
|
- Multitasking
|
||||||
|
- More?
|
|
@ -0,0 +1,41 @@
|
||||||
|
; Definition of the MBR (Master Boot Record). This is basically our bootloader and
|
||||||
|
; is located in the first 512 bytes of the drive we're booting from. From here, we
|
||||||
|
; do some basic setup and then call into the kernel
|
||||||
|
|
||||||
|
[org 0x7c00] ; Address where the code expects to be loaded in. The BIOS always loads us here
|
||||||
|
[bits 16] ; All x86 CPUs start in 16 bit (aka "real") mode, so we tell nasm to emit 16-bit code
|
||||||
|
|
||||||
|
; We print a simple startup message using the ISRs
|
||||||
|
; from the BIOS
|
||||||
|
mov si, startup_msg
|
||||||
|
call print
|
||||||
|
|
||||||
|
|
||||||
|
; Now we setup the stack by setting the
|
||||||
|
; base pointer to address 0x8000. The
|
||||||
|
; address itself doesn't matter as long
|
||||||
|
; as it's far enough away from memory already
|
||||||
|
; in use by the BIOS
|
||||||
|
mov bp, 0x8000
|
||||||
|
mov sp, bp ; The stack starts out empty, so sp == bp
|
||||||
|
|
||||||
|
|
||||||
|
jmp $ ; Keeps jumping at the current address (loops forever)
|
||||||
|
|
||||||
|
; These two lines never execute (for now), but they might once
|
||||||
|
; we jump into the kernel, so we disable interrupts and halt the
|
||||||
|
; CPU, just in case
|
||||||
|
cli
|
||||||
|
hlt
|
||||||
|
|
||||||
|
; Now we include our "function definitions" (after the halting, so
|
||||||
|
; they're never executed unless explicitly called)
|
||||||
|
%include "src/bootloader/util/tty.s"
|
||||||
|
|
||||||
|
; Here we define our variables: They need to be defined after the
|
||||||
|
; halting because otherwise they will be executed as code!
|
||||||
|
startup_msg: db "TSOS - Bootloader: Starting up", 0xA, 0xD, 0x0
|
||||||
|
|
||||||
|
; padding and magic number
|
||||||
|
times 510 - ($-$$) db 0
|
||||||
|
dw 0xaa55
|
|
@ -0,0 +1,44 @@
|
||||||
|
; Some utilities to deal with the TTY using the BIOS
|
||||||
|
; during real mode
|
||||||
|
|
||||||
|
next_line:
|
||||||
|
; Points the TTY cursor to the next
|
||||||
|
; line
|
||||||
|
pusha
|
||||||
|
; Source: http://www.techhelpmanual.com/118-int_10h_03h__query_cursor_position_and_size.html
|
||||||
|
mov ah, 0x3 ; Get cursor position
|
||||||
|
mov bh, 0x0 ; Page 0
|
||||||
|
int 0x10
|
||||||
|
; Go to the next row
|
||||||
|
; Source: http://www.techhelpmanual.com/117-int_10h_02h__set_cursor_position.html
|
||||||
|
mov ah, 0x2 ; Set cursor position
|
||||||
|
mov bh, 0x0 ; Page 0
|
||||||
|
xor dl, dl ; Goes to column 0 (i.e. start of the line)
|
||||||
|
inc dh ; Goes to the next row
|
||||||
|
int 0x10
|
||||||
|
popa
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
print:
|
||||||
|
; Prints a null-terminated string whose address
|
||||||
|
; is located in the si register
|
||||||
|
pusha
|
||||||
|
mov ah, 0xe ; Set the screen in TTY mode
|
||||||
|
print_loop:
|
||||||
|
mov al, [si]
|
||||||
|
int 0x10 ; Writes the content of al to the screen
|
||||||
|
inc si
|
||||||
|
cmp byte [si], 0x0 ; If we got to the null byte, we're done
|
||||||
|
jne print_loop ; Otherwise, we run this again
|
||||||
|
popa
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
println:
|
||||||
|
; Prints a null-terminated string whose address
|
||||||
|
; is located in the si register and sets the TTY
|
||||||
|
; cursor to the next line
|
||||||
|
call print
|
||||||
|
call next_line
|
||||||
|
ret
|
Loading…
Reference in New Issue