Skip to content

Commit

Permalink
feat(loader): logger print time
Browse files Browse the repository at this point in the history
  • Loading branch information
d0p1s4m4 committed Apr 28, 2024
1 parent fe5fc65 commit fb51cf6
Show file tree
Hide file tree
Showing 25 changed files with 796 additions and 14 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2020, d0p1
Copyright (c) 2024, d0p1
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 2 additions & 0 deletions boot/bootsect/floppy.asm
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ _start:
xor bx, bx
call fat_load_binary

mov dl, [drive_number]

jmp 0x0:LOADER_BASE

.error_not_found:
Expand Down
57 changes: 55 additions & 2 deletions boot/bootsect/mbr.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

include '../common/const.inc'
include '../common/macro.inc'
include '../common/bios.inc'
include '../common/mbr.inc'

org MBR_BASE
cli
Expand All @@ -19,9 +21,60 @@
rep movsw
jmp 0x0:start
start:
; TODO: read partition table and load bootable one.
; set LBA
mov ah, 0x41
mov bx, 0x55AA
mov dl, 0x80
int 0x13
jc .error_lba
lea ecx, [PT1]
.loop:
mov al, byte [ecx]
bt ax, 7
jc .found
lea eax, [PT4]
test eax, ecx
je .error_no_bootable
add cx, 0xF
jmp .loop
.found:
mov eax, dword [ecx + Partition.lba]
mov [disk_packet_lba], eax
mov si, disk_packet
mov ah, 0x42
mov dl, 0x80
int 13
jc .error_load
jmp 0x0:BOOTSECT_BASE
.error_lba:
mov si, msg_error_lba
jmp .error_print
.error_no_bootable:
mov si, msg_error_bootable
jmp .error_print
.error_load:
mov si, msg_error_load
.error_print:
call bios_print
.end:
hlt
jmp $

times 436-($-$$) db 0x90
disk_packet:
db 0x10
db 0
dw 1
dw BOOTSECT_BASE
dw 0x0
disk_packet_lba:
dd 0x0
dw 0x0

msg_error_lba db "We don't support CHS", CR, LF, 0
msg_error_bootable db "No bootable device found", CR, LF, 0
msg_error_load db "Can't load partition", CR, LF, 0

rb MBR_BASE+0x1a8-$
UID db 'STUPIDDISK'
; partition table
PT1 db 16 dup(0)
Expand Down
3 changes: 3 additions & 0 deletions boot/common/const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ DISK_BUFFER = 0x8000
KERNEL_PRELOAD = 0xF000
STACK_TOP = 0x7000

; ---------- Magic ------------
STPDBOOT_MAGIC = 0x53545044

; ---------- Video ------------
VIDEO_WIDTH = 1024
VIDEO_HEIGHT = 768
Expand Down
15 changes: 15 additions & 0 deletions boot/common/mbr.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
;; File: mbr.inc


struc Partition
{
.status db ?
.chs_start db 3 dup(?)
.type db ?
.chs_last db 3 dup(?)
.lba dd ?
.sectors dd ?
}
defn Partition


1 change: 1 addition & 0 deletions boot/intro.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ Section: UEFI (IA32)
> | BOOTIA32.EFI |----->| vmstupid.sys |
> +--------------+ +--------------+
>

3 changes: 3 additions & 0 deletions boot/loader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ TARGET = stpdldr.sys

LOADER_SRCS = loader.asm \
../common/const.inc \
video.inc \
memory.inc \
logger.inc \
a20.inc \
multiboot.inc

Expand Down
42 changes: 36 additions & 6 deletions boot/loader/loader.asm
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,41 @@ _start:
push cs
pop ds

mov [drive_number], dl

mov si, msg_stage2
call bios_print
call bios_log

; enable A20 line
call a20_enable
jc .error_a20

; check drive type
; dl <= 0x7F == floppy
; dl >= 0x80 == hard drive
; dl == 0xE0 ~= CD/DVD
; dl <= 0xFF == hard drive
mov dl, [drive_number]
cmp dl, 0x7F
; skip disk extension check
jle @f

; check disk extensions
mov ah, 0x41
mov bx, 0x55AA
int 0x13
jc @f
mov [drive_lba], 1
@@:
; detect filesystem (FAT12/16 or StpdFS)
; load kernel from filesystem

; fetch memory map from bios
call memory_get_map
jc .error_memory

; video information
call video_setup
xchg bx, bx

; load GDT and enter Protected-Mode
lgdt [gdt_ptr]
Expand All @@ -65,21 +86,26 @@ _start:
.error_a20:
mov si, msg_error_a20
.error:
call bios_print
call bios_log
@@:
hlt
jmp @b

include 'a20.inc'
include '../common/bios.inc'
include 'logger.inc'
include 'memory.inc'
include 'video.inc'
include 'gdt.inc'

msg_stage2 db "StupidOS Loader", CR, LF, 0
drive_number rb 1
drive_lba db 0

msg_stage2 db "StupidOS Loader", 0
kernel_fat12_file db "VMSTUPIDSYS", 0
msg_error_a20 db "ERROR: can't enable a20 line", CR, LF, 0
msg_error_memory db "ERROR: can't detect available memory", CR, LF, 0
config_fat12_file db "BOOT INI", 0
msg_error_a20 db "ERROR: can't enable a20 line", 0
msg_error_memory db "ERROR: can't detect available memory", 0

use32
; =========================================================================
Expand All @@ -101,6 +127,10 @@ common32:
; identity map first 1MB
; map kernel to 0xC0000000

push STPDBOOT_MAGIC

mov eax, 0xC0000000
jmp eax
hang:
hlt
jmp $
Expand Down
54 changes: 54 additions & 0 deletions boot/loader/logger.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
bios_log_time:
clc
mov ah, 0x02
int 0x1A

mov al, ch
aam
add ah, 0x30
add al, 0x30
mov [time + 1], ah
mov [time + 2], al

mov al, cl
aam
add ah, 0x30
add al, 0x30
mov [time + 4], ah
mov [time + 5], al

mov al, dh
aam
add ah, 0x30
add al, 0x30
mov [time + 7], ah
mov [time + 8], al

mov si, time
call bios_print

ret

bios_log_hex:
ret

;; Function: bios_log
;;
;; Parameters:
;; SI - string to print
;; [STACK] - variadic arguments
;;
bios_log:
push si
call bios_log_time
pop si

call bios_print


mov si, endline
call bios_print
ret

time db '[00:00.00] ', 0
endline db CR, LF, 0
4 changes: 4 additions & 0 deletions boot/loader/memory.inc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ memory_e820_get_map:
;; BX - Extended 2
;; CX - Configured 1
;; DX - Configured 2
memory_get_for_large_conf:
mov ax, 0xE801
int 0x15

;; Function: memory_get_extended_memory_size
;;
Expand All @@ -75,4 +78,5 @@ memory_e820_get_map:
;; CF - Non-Carry - indicates no error
;; AX - Number of contiguous KB above 1MB
memory_get_map:
clc
ret
3 changes: 3 additions & 0 deletions boot/loader/multiboot.inc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struc MultibootData
.fb_type db ?
.fb_misc dw 3 dup ?
}
defn MultibootData

MULTIBOOT_DATA_MEM = 0x0001
MULTIBOOT_DATA_BOOTDEV = 0x0002
Expand All @@ -100,6 +101,7 @@ struc MultibootMMap
.length dq ?
.type dd ?
}
defn MultibootMMap

MULTIBOOT_MEMORY_AVAILABLE = 0x1
MULTIBOOT_MEMORY_RESERVED = 0x2
Expand All @@ -114,3 +116,4 @@ struc MultibootModule
.cmdline dd ?
.pad dd ?
}
defn MultibootModule
26 changes: 26 additions & 0 deletions boot/loader/video.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struc VesaInfo
.Reserved db 222 dup(?)
.OEMData db 256 dup(?)
}
defn VesaInfo

struc VesaModeInfo
{
Expand Down Expand Up @@ -59,4 +60,29 @@ struc VesaModeInfo
defn VesaModeInfo

video_setup:
clc
mov di, [vesa_block_buffer]
mov ax, 0x4F00
int 0x10
cmp ax, 0x004F
jne .err

push word [vesa_block_buffer + VesaInfo.VideoModesSegment]
pop es
mov di, vesa_info_block_buffer
mov bx, [vesa_block_buffer + VesaInfo.VideoModesOffset]
mov cx, [bx]
cmp cx, 0xFFFF
je .err

mov ax, 0x4F01
int 0x10
cmp ax, 0x004F
jne .err
ret
.err:
stc
ret

vesa_block_buffer VesaInfo
vesa_info_block_buffer VesaModeInfo
File renamed without changes.
2 changes: 2 additions & 0 deletions include/fs/echfs.h → include/fs/fat16.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# define ECHFS_H 1

typedef struct {
uint8_t jmp[4];
uint8_t signature[8];

} EchFSIdentityTable;

Expand Down
8 changes: 8 additions & 0 deletions kernel/kernel.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@

include 'mm/mm.inc'

;; Function: kmain
;;
;; Parameters:
;;
;; EAX - Boot Magic
;; EBX - Boot structure address
;;
kmain:
; TODO: interupt, vmm
nop

_edata:
Expand Down
4 changes: 1 addition & 3 deletions kernel/mm/mm.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
free_block_head dd 0x0

mm_init:

ret
ret
2 changes: 1 addition & 1 deletion lib/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBDIRS = csu crypto lzp
SUBDIRS = csu crypto lzp c

TOPGOALS = all clean install

Expand Down
Loading

0 comments on commit fb51cf6

Please sign in to comment.