1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00

Merge pull request #27 from os-k-team/loader

Loader
This commit is contained in:
Adrien Bourmault 2019-03-06 20:12:53 +01:00 committed by GitHub
commit 7be54a602c
3 changed files with 331 additions and 0 deletions

46
boot/loader/cpu/cpu.inc Normal file
View File

@ -0,0 +1,46 @@
;=----------------------------------------------------------------------------=;
; GNU GPL OS/K ;
; ;
; Desc: Basic longmode CPU functions ;
; (x86_64 architecture only) ;
; ;
; ;
; Copyright © 2018-2019 The OS/K Team ;
; ;
; This file is part of OS/K. ;
; ;
; OS/K is free software: you can redistribute it and/or modify ;
; it under the terms of the GNU General Public License as published by ;
; the Free Software Foundation, either version 3 of the License, or ;
; (at your option) any later version. ;
; ;
; OS/K is distributed in the hope that it will be useful, ;
; but WITHOUT ANY WARRANTY; without even the implied warranty of ;
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;
; GNU General Public License for more details. ;
; ;
; You should have received a copy of the GNU General Public License ;
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
;=----------------------------------------------------------------------------=;
[BITS 64]
temporize:
push rcx
mov rcx, 2000
.looping:
nop
nop
nop
loop .looping
pop rcx
ret
bitemporize:
push rcx
mov rcx, 2000
.looping:
call temporize
loop .looping
pop rcx
ret

159
boot/loader/io/ata.inc Normal file
View File

@ -0,0 +1,159 @@
;=----------------------------------------------------------------------------=;
; GNU GPL OS/K ;
; ;
; Desc: Basic Read Only ATA Long mode Driver ;
; (x86_64 architecture only) ;
; ;
; ;
; Copyright © 2018-2019 The OS/K Team ;
; ;
; This file is part of OS/K. ;
; ;
; OS/K is free software: you can redistribute it and/or modify ;
; it under the terms of the GNU General Public License as published by ;
; the Free Software Foundation, either version 3 of the License, or ;
; (at your option) any later version. ;
; ;
; OS/K is distributed in the hope that it will be useful, ;
; but WITHOUT ANY WARRANTY; without even the implied warranty of ;
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;
; GNU General Public License for more details. ;
; ;
; You should have received a copy of the GNU General Public License ;
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
;=----------------------------------------------------------------------------=;
[BITS 64]
;; BPB
%define OEMName bp+0x03 ; Disk label
%define bytesPerSector bp+0x0b ; Bytes per sector
%define sectorsPerCluster bp+0x0d ; Sectors per cluster
%define reservedSectors bp+0x0e ; Reserved sectors
%define fats bp+0x10 ; Number of fats
%define rootDirEntries bp+0x11 ; Number of entries in root dir
%define sectors bp+0x13 ; Logical sectors
%define mediaType bp+0x15 ; Media descriptor byte
%define fatSectors bp+0x16 ; Sectors per FAT
%define sectorsPerTrack bp+0x18 ; Sectors per track
%define heads bp+0x1a ; Number of sides/heads
%define hiddenSectors bp+0x1c ; Hidden sectors
%define hugeSectors bp+0x20 ; LBA sectors
%define biosBootdrvNum bp+0x24 ; Bootdrv number
%define reserved bp+0x25 ; This is not used
%define bootSignature bp+0x26 ; Bootdrv signature
%define volumeId bp+0x27 ; Volume ID
%define volumeLabel bp+0x2b ; Volume Label
%define fatTypeLabel bp+0x36 ; File system type
;; GLOBAL DATA
Bootdrv db 0
ended db "[End of Sector]", 0x0A, 0x0A, 0x0D, 0x0
buffer: times 513 db "_"
;; TEXT
ata_read:
;-----------------------------------------------------------------------;
; x64/LM ATA Reading function ;
; bl : number of sectors to read XXX ;
; bh : the first sector to read ;
;-----------------------------------------------------------------------;
; Technical infos about the ports (Intel Doc):
;
; Port Access Mode Misc
;
; 1f0 r/w Data register, the bytes of the disk itself
; 1f1 r Error register that can be handled
; 1f2 r/w Sector count, how many sectors to read
; 1f3 r/w Sector number, the actual sector wanted
; 1f4 r/w Cylinder low, cylinders is 0-1024
; 1f5 r/w Cylinder high, this makes up the rest of the 1024
; 1f6 r/w Drive/head
; bit 7 = 1
; bit 6 = 0
; bit 5 = 1
; bit 4 = 0 drive 0 select
; = 1 drive 1 select
; bit 3-0 head select bits
; 1f7 r Status register
; bit 7 = 1 controller is executing a command
; bit 6 = 1 drive is ready
; bit 5 = 1 write fault
; bit 4 = 1 seek complete
; bit 3 = 1 sector buffer requires servicing
; bit 2 = 1 disk data read corrected
; bit 1 = 1 index - set to 1 each revolution
; bit 0 = 1 previous command ended in an error
; 1f7 w Command register
; commands:
; 50h format track
; 20h read sectors with retry
; 21h read sectors without retry
; 22h read long with retry
; 23h read long without retry
; 30h write sectors with retry
; 31h write sectors without retry
; 32h write long with retry
; 33h write long without retry
;
push rax
push rbx
push rcx
push rdx
push rdi
mov dx, 0x1f6 ; Drive and head port
mov al, 0x0a0 ; Drive 0, head 0
out dx,al
mov dx, 0x1f2 ; Sector count port
mov al, bl ; Read bl(s) sector
out dx, al
mov dx, 0x1f3 ; Sector number port
mov al, bh ; Read from sector n°bh
out dx, al
mov dx, 0x1f4 ; Cylinder low port
mov al, 0 ; Cylinder 0
out dx, al
mov dx, 0x1f5 ; Cylinder high port
mov al, 0 ; The rest of the cylinder 0
out dx, al
mov dx, 0x1f7 ; Command port
mov al, 0x20 ; Read with retry.
out dx, al
still_going:
in al, dx
test al, 8 ; This means the sector buffer requires
;servicing.
jz still_going ; Don't continue until the sector buffer
;is ready.
mov cx, 512/2 ; One sector /2 because it copies words
mov rdi, QWORD buffer
mov dx, 0x1f0 ; Data port - data comes in and out of here.
rep insw
pop rdi
%ifdef DEBUG
mov bl, 0x0F
mov esi, buffer
call dump
mov bl, 0x0A
mov esi, ended
call write
add qword [NextTRAM], 120 ; Cursor moving : 1120 = 80 * 2 * 7 lignes
%else
mov bl, 0x0A
mov esi, Pass
call write
%endif
pop rdx
pop rcx
pop rbx
pop rax
ret

126
boot/loader/io/terminal.inc Normal file
View File

@ -0,0 +1,126 @@
;=----------------------------------------------------------------------------=;
; GNU GPL OS/K ;
; ;
; Desc: Basic Colored VGA Terminal Long mode Driver ;
; (x86_64 architecture only) ;
; ;
; ;
; Copyright © 2018-2019 The OS/K Team ;
; ;
; This file is part of OS/K. ;
; ;
; OS/K is free software: you can redistribute it and/or modify ;
; it under the terms of the GNU General Public License as published by ;
; the Free Software Foundation, either version 3 of the License, or ;
; (at your option) any later version. ;
; ;
; OS/K is distributed in the hope that it will be useful, ;
; but WITHOUT ANY WARRANTY; without even the implied warranty of ;
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;
; GNU General Public License for more details. ;
; ;
; You should have received a copy of the GNU General Public License ;
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
;=----------------------------------------------------------------------------=;
;;VIDEO
%define TRAM 0x0B8000 ; [T]ext[RAM]
%define VRAM 0x0A0000 ; [V]ideo[RAM]
;; GLOBAL DATA
NextTRAM dq 0xB8000 ; Last position of cursor
VGA_HEIGHT64 dq 80
VGA_X dq 0
;; TEXT
[BITS 64]
clear:
;-----------------------------------------------------------------------;
; x64/LM Clear Text Screen Function ;
;-----------------------------------------------------------------------;
mov qword [NextTRAM], TRAM
mov edi, TRAM
push rsi
push rdi
push rcx
mov ah, 0
mov al, 0
mov rcx, 0x4000 ; traditionnal value
rep stosw ; fill screen with al while cx > 0
pop rcx
pop rsi
pop rdi
ret
write:
;-----------------------------------------------------------------------;
; x64/LM Text Printing Functions ;
; bl : color code ;
; esi : string address ;
;-----------------------------------------------------------------------;
mov edi, [NextTRAM] ; TRAM ADDRESS
push rsi
push rdi
.pLoop:
lodsb
cmp al, 0 ; while @al, i.e. while we're not hitting '\0'
je .pEnd
cmp al, 0x0A ; LF
je .lf
cmp al, 0x0D ; CR
je .cr
stosb ; text subpixel
mov al, bl
stosb ; color subpixel
add qword [NextTRAM], 0x2 ; Cursor moving
add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels
jmp .pLoop
.pEnd:
pop rdi
pop rsi
ret
.lf:
mov rax, [VGA_HEIGHT64]
add [NextTRAM], rax ; Cursor moving
add [NextTRAM], rax
add edi, eax ; Address moving
add edi, eax
jmp .pLoop
.cr:
push rax
mov rax, qword [VGA_X]
sub qword [NextTRAM], rax ; pos = X + Y * VGA_HEIGHT64. Donc pos - X = début de ligne
sub edi, edx
mov qword [VGA_X], 0
pop rax
jmp .pLoop
.scroll:
; XXX I don't think I'll implement this, but never know...;
jmp .pLoop
dump:
;-----------------------------------------------------------------------;
; x64/LM Dump 512 bytes of a buffer ;
; bl : color code ;
; esi : buffer address ;
;-----------------------------------------------------------------------;
mov edi, [NextTRAM] ; TRAM ADDRESS
push rsi
push rdi
push rcx
mov rcx, 512
.pLoop:
lodsb
stosb ; text subpixel
mov al, bl
stosb ; color subpixel
loop .pLoop
pop rcx
pop rdi
pop rsi
add qword [NextTRAM], 1000 ; Cursor moving : 1120 = 80 * 2 * 7 lignes
ret