Loading from disk works, but jumping to the kernel does not
This commit is contained in:
19
Makefile
19
Makefile
@@ -1,16 +1,21 @@
|
|||||||
all: boot.img kernel.bin
|
all: boot.img kernel.bin
|
||||||
|
|
||||||
boot.bin: asm/bootloader.S asm/bootloader.S
|
|
||||||
nasm asm/bootloader.S -f bin -o $@
|
|
||||||
|
|
||||||
asm/%.o: asm/%.S
|
|
||||||
nasm $< -f as86 -o $@
|
|
||||||
|
|
||||||
src/%.o: src/%.c
|
src/%.o: src/%.c
|
||||||
bcc -ansi -3 -c -o $@ $<
|
bcc -ansi -3 -c -o $@ $<
|
||||||
|
|
||||||
kernel.bin: src/kernel.o
|
kernel.bin: src/kernel.o
|
||||||
ld86 -T0x1000 -o $@ $^
|
ld86 -T0x1000 -M -o $@ $^
|
||||||
|
|
||||||
|
asm/kernel_syms.S: kernel.bin
|
||||||
|
objdump86 kernel.bin | \
|
||||||
|
grep -E "^[0-9]+ T _.*" | \
|
||||||
|
python -c "import sys; print '\n'.join([\"_extern_c%s:\n jmp 0x1000:0x%04x\" % (x.split(' ')[2].strip('\n'), int(x.split(' ')[0].lstrip('0'), 16)-0x1000) for x in sys.stdin.readlines()])" > asm/kernel_syms.S
|
||||||
|
|
||||||
|
boot.bin: asm/kernel_syms.S asm/bootloader.S asm/bootloader.S
|
||||||
|
cd asm && nasm bootloader.S -f bin -o ../$@
|
||||||
|
|
||||||
|
asm/%.o: asm/%.S
|
||||||
|
nasm $< -f as86 -o $@
|
||||||
|
|
||||||
boot.img: boot.bin kernel.bin
|
boot.img: boot.bin kernel.bin
|
||||||
cat $^ > $@
|
cat $^ > $@
|
||||||
|
|||||||
@@ -13,44 +13,44 @@ start:
|
|||||||
mov dl, 0x0
|
mov dl, 0x0
|
||||||
call setCursorPosition
|
call setCursorPosition
|
||||||
|
|
||||||
mov al, 0x17 ; read the remaining 16 tracks
|
mov al, 0x1 ; read the remaining 16 tracks
|
||||||
mov ch, 0x1 ; .... on track 1 ....
|
mov ch, 0x0 ; .... on track 0 ....
|
||||||
mov cl, 0x1 ; .... starting at sector 1
|
mov cl, 0x2 ; .... starting at sector 2
|
||||||
mov bx, 0x1000 ; 0x1000 is a standard kernel start location
|
mov bx, 0x1000 ; 0x1000 is a standard kernel start location
|
||||||
mov es, bx
|
mov es, bx
|
||||||
xor bx, bx ; bx = 0, es:bs = 0x1000:0
|
mov bx, 0x0 ; bx = 0, es:bx = 0x1000:0
|
||||||
call loadFloppyDiskSectors
|
call loadFloppyDiskSectors
|
||||||
push ax
|
;; push ax
|
||||||
mov ax, bx
|
;; mov ax, bx
|
||||||
add ax, 0x2200 ; we just read 0x2200 bytes, move pointer in memory
|
;; add ax, 0x2200 ; we just read 0x2200 bytes, move pointer in memory
|
||||||
mov bx, ax
|
;; mov bx, ax
|
||||||
pop ax
|
;; pop ax
|
||||||
mov al, 0x17 ; read 18 sectors per track for all future tracks
|
;; mov al, 0x17 ; read 18 sectors per track for all future tracks
|
||||||
mov cl, 0x1 ; start at sector 1 for all future tracks
|
;; mov cl, 0x1 ; start at sector 1 for all future tracks
|
||||||
|
|
||||||
mov di, 0x2FF ; abuse di as a counter, while (di < 80)
|
;; mov di, 0x2FF ; abuse di as a counter, while (di < 80)
|
||||||
; di is technically a destination index for stream
|
;; ; di is technically a destination index for stream
|
||||||
; ops, but nothing is using it ATM, so gimme.
|
;; ; ops, but nothing is using it ATM, so gimme.
|
||||||
_next_floppy_track:
|
;; _next_floppy_track:
|
||||||
push ax
|
;; push ax
|
||||||
mov ax, 0x2e
|
;; mov ax, 0x2e
|
||||||
call printCharacter
|
;; call printCharacter
|
||||||
mov ax, cx
|
;; mov ax, cx
|
||||||
mov cx, di
|
;; mov cx, di
|
||||||
mov cl, al
|
;; mov cl, al
|
||||||
pop ax
|
;; pop ax
|
||||||
call loadFloppyDiskSectors
|
;; call loadFloppyDiskSectors
|
||||||
push ax
|
;; push ax
|
||||||
mov ax, bx
|
;; mov ax, bx
|
||||||
add ax, 0x2400 ; each floppy track is (512b*18s)=0x2400 bytes long
|
;; add ax, 0x2400 ; each floppy track is (512b*18s)=0x2400 bytes long
|
||||||
mov bx, ax
|
;; mov bx, ax
|
||||||
pop ax
|
;; pop ax
|
||||||
inc di
|
;; inc di
|
||||||
push cx
|
;; push cx
|
||||||
mov cx, 0x50
|
;; mov cx, 0x50
|
||||||
cmp di, cx ; di < 80 ?
|
;; cmp di, cx ; di < 80 ?
|
||||||
jg _end_floppy_read
|
;; jg _end_floppy_read
|
||||||
pop cx
|
;; pop cx
|
||||||
|
|
||||||
_end_floppy_read:
|
_end_floppy_read:
|
||||||
mov dh, 0x1
|
mov dh, 0x1
|
||||||
@@ -58,9 +58,10 @@ _end_floppy_read:
|
|||||||
call setCursorPosition
|
call setCursorPosition
|
||||||
mov si, _str_floppydone
|
mov si, _str_floppydone
|
||||||
call printString
|
call printString
|
||||||
jmp 0x1000
|
jmp _extern_c_main
|
||||||
|
|
||||||
%include "libinterrupt.S"
|
%include "libinterrupt.S"
|
||||||
|
%include "kernel_syms.S"
|
||||||
|
|
||||||
_str_hello db 'Piquant v0.1 Bootloader', 0xA, 0
|
_str_hello db 'Piquant v0.1 Bootloader', 0xA, 0
|
||||||
_str_loading db 'Loading', 0
|
_str_loading db 'Loading', 0
|
||||||
@@ -68,3 +69,4 @@ _end_floppy_read:
|
|||||||
|
|
||||||
times 510 - ($ - $$) db 0 ; fill up to 510 bytes with 0
|
times 510 - ($ - $$) db 0 ; fill up to 510 bytes with 0
|
||||||
dw 0xAA55 ; magic bootloader signature
|
dw 0xAA55 ; magic bootloader signature
|
||||||
|
|
||||||
|
|||||||
4
asm/kernel_syms.S
Normal file
4
asm/kernel_syms.S
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
_extern_c_main:
|
||||||
|
jmp 0x1000:0x0049
|
||||||
|
_extern_c_printCh:
|
||||||
|
jmp 0x1000:0x0000
|
||||||
@@ -1,14 +1,43 @@
|
|||||||
resetFloppy:
|
resetFloppy:
|
||||||
mov ax, 0 ; reset floppy disk (only need ah, reset
|
mov ah, 0 ; reset floppy disk
|
||||||
; al while we're here though)
|
|
||||||
mov dl, 0 ; use drive 0 (first floppy)
|
mov dl, 0 ; use drive 0 (first floppy)
|
||||||
int 0x13
|
int 0x13
|
||||||
jc resetFloppy
|
jc resetFloppy
|
||||||
ret
|
ret
|
||||||
|
|
||||||
loadDiskSector:
|
;; set al = how many sectors to read
|
||||||
|
;; set ch = what track to read from
|
||||||
|
;; set cl = what sector on the track to start reading
|
||||||
|
;; set es:bx = where to store the disk data
|
||||||
|
loadFloppyDiskSectors:
|
||||||
|
mov ah, 0x02 ; int 0x13 function 2 (read sectors from disk)
|
||||||
|
mov dh, 0 ; head 0 (assume simple small floppy)
|
||||||
|
mov dl, 0 ; drive 0 = floppy drive
|
||||||
|
int 0x13
|
||||||
|
jc loadFloppyDiskSectors ; retry on errors (not much else we can do)
|
||||||
|
|
||||||
|
blankScreen:
|
||||||
|
push cx
|
||||||
|
mov cx, 0x0
|
||||||
|
_blankScreen_next:
|
||||||
|
mov al, 0x20 ; blank space
|
||||||
|
call printCharacter
|
||||||
|
inc cx
|
||||||
|
cmp cx, 0x7d0 ; 80 * 25 screen = 0x7d0
|
||||||
|
jne _blankScreen_next
|
||||||
|
_blankScreen_exit:
|
||||||
|
pop cx
|
||||||
|
ret
|
||||||
|
|
||||||
|
;; set dh = row
|
||||||
|
;; set dl = column
|
||||||
|
setCursorPosition:
|
||||||
|
mov ah, 0x02
|
||||||
|
mov bh, 0
|
||||||
|
int 0x10
|
||||||
|
ret
|
||||||
|
|
||||||
|
;; set al = character to display
|
||||||
printCharacter: ; print a single character to the display
|
printCharacter: ; print a single character to the display
|
||||||
mov ah, 0x0e ; int 0x10 is the entire display control,
|
mov ah, 0x0e ; int 0x10 is the entire display control,
|
||||||
; 0x0e means teletype output
|
; 0x0e means teletype output
|
||||||
@@ -17,10 +46,14 @@ mov bl, 0x07 ; Color. 0x07 is grey on black.
|
|||||||
int 0x10
|
int 0x10
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
;; set si = string to display
|
||||||
printString: ; print the entire string pointed to by si
|
printString: ; print the entire string pointed to by si
|
||||||
|
_printString_next:
|
||||||
mov al, [si] ; [x] == *x, dereferencing source index
|
mov al, [si] ; [x] == *x, dereferencing source index
|
||||||
|
cmp al, 0x0 ; found the trailing NULL?
|
||||||
|
je _printString_exit
|
||||||
call printCharacter
|
call printCharacter
|
||||||
inc si
|
inc si
|
||||||
cmp al, 0x0 ; found the trailing NULL?
|
jmp _printString_next
|
||||||
jne printString
|
_printString_exit:
|
||||||
ret
|
ret
|
||||||
|
|||||||
52
bootloader.S
52
bootloader.S
@@ -1,52 +0,0 @@
|
|||||||
[bits 16] ; 16 bit real mode code
|
|
||||||
[org 0x7C00] ; Origin at 0x7C00 (upper end of memory)
|
|
||||||
|
|
||||||
start:
|
|
||||||
mov si, _str_hello ; si = source index
|
|
||||||
call printString
|
|
||||||
mov al, 0x97
|
|
||||||
call printCharacter
|
|
||||||
|
|
||||||
; mov al, 0x17 ; read the remaining 16 tracks
|
|
||||||
; mov ch, 0x1 ; .... on track 1 ....
|
|
||||||
; mov cl, 0x2 ; .... starting at sector 2
|
|
||||||
; mov bx, 0x1000 ; 0x1000 is a standard kernel start location
|
|
||||||
; mov es, bx
|
|
||||||
; xor bx ; bx = 0, es:bs = 0x1000:0
|
|
||||||
; call loadFloppyDiskSectors
|
|
||||||
; push ax
|
|
||||||
; mov ax, bx
|
|
||||||
; add ax, 0x2200 ; we just read 0x2200 bytes, move pointer in memory
|
|
||||||
; mov bx, ax
|
|
||||||
; pop ax
|
|
||||||
; mov al, 0x17 ; read 18 sectors per track for all future tracks
|
|
||||||
; mov cl, 0x1 ; start at sector 1 for all future tracks
|
|
||||||
|
|
||||||
; mov di, 0x2 ; abuse di as a counter, while (di < 80)
|
|
||||||
; ; di is technically a destination index for stream
|
|
||||||
; ; ops, but nothing is using it ATM, so gimme.
|
|
||||||
; _next_floppy_track:
|
|
||||||
; mov ch, di
|
|
||||||
; call loadFloppyDiskSectors
|
|
||||||
; push ax
|
|
||||||
; mov ax, bx
|
|
||||||
; add ax, 0x2400 ; each floppy track is (512b*18s)=0x2400 bytes long
|
|
||||||
; mov bx, ax
|
|
||||||
; pop ax
|
|
||||||
; inc di
|
|
||||||
; push cx
|
|
||||||
; mov cx, 0x50
|
|
||||||
; cmp di, cx ; di < 80 ?
|
|
||||||
; jlt _next_floppy_track
|
|
||||||
|
|
||||||
mov si, _str_floppydone
|
|
||||||
call printString
|
|
||||||
jmp $
|
|
||||||
|
|
||||||
%include "libinterrupt.S"
|
|
||||||
|
|
||||||
_str_hello db 'Piquant v0.1 Bootloader', 0xA, 0
|
|
||||||
_str_floppydone db 'Kernel loaded', 0xA, 0
|
|
||||||
|
|
||||||
times 510 - ($ - $$) db 0 ; fill up to 510 bytes with 0
|
|
||||||
dw 0xAA55 ; magic bootloader signature
|
|
||||||
@@ -19,9 +19,9 @@ void printChar(char c)
|
|||||||
|
|
||||||
void printString(char *ptr)
|
void printString(char *ptr)
|
||||||
{
|
{
|
||||||
while (*ptr != '\0') {
|
while ((char)*ptr != '\0') {
|
||||||
printChar(*ptr);
|
printChar((char)*ptr);
|
||||||
*ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -29,7 +29,6 @@ void printString(char *ptr)
|
|||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
char *kernelHello = "Welcome to Piquant, please wait while Kernel boots...\n";
|
//printString("Piquant Kernel v0.1\n");
|
||||||
printString(kernelHello);
|
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user