1

I made a simple Operating System and I have problem with running kernel, Actually Kernel Prints Nothing.

BootSector :

bits 16
org 0x7c00 ; 0x7c00 > Boot & 0x7c00 + 512 (0x7e00) > Kernel

%ifdef WITH_BPB
%include "BIOSParameterBlock.inc"
%endif

boot_continue:

    mov ax, 0x1000      
    mov ss, ax      ;SS:SP > 0x1000:0xfffe (0x1fffe)
    mov ax, 0xfffe
    mov sp, ax
    cld

    xor ax, ax
    mov ds, ax      ;DS:SI > 0x0000:0x0001 (0x00001)
    mov bx, ax
    mov ax, 0x0001  ;ES:BX > 0x07e0:0x0000 (0x07e00)
    mov si, ax
    mov ax, 0x07e0
    mov es,ax
    
    Kernel2Memory:
    mov al, 0x01    ; Load 1 sectors
    mov ah, 0x02    ; Load disk data to ES:BX
    mov cl, 0x01    ; Sector = 1
    mov ch, 0x00    ; Cylinder = 0
    mov dh, 0x00    ; Head = 0
    int 13h         ; Read
    jc Kernel2Memory

    jmp 0x07e0:0x0000

    TIMES 510-($-$$) db  0
    dw 0xaa55

    incbin "Kernel.bin"

    TIMES 1024*1440-($-$$) db 0x00

The BIOS Parameter Block which will add to the first of the boot sector (BIOSParameter.inc):

    global bpb_disk_info
    jmp short boot_continue
    nop

    bpb_disk_info:

    ; Dos 4.0 EBPB 1.44MB floppy
    OEMname:           db    "mkfs.fat"  ; mkfs.fat is what OEMname mkdosfs uses
    bytesPerSector:    dw    512
    sectPerCluster:    db    1
    reservedSectors:   dw    1
    numFAT:            db    2
    numRootDirEntries: dw    224
    numSectors:        dw    2880
    mediaType:         db    0xf0
    numFATsectors:     dw    9
    sectorsPerTrack:   dw    18
    numHeads:          dw    2
    numHiddenSectors:  dd    0
    numSectorsHuge:    dd    0
    driveNum:          db    0
    reserved:          db    0
    signature:         db    0x29
    volumeID:          dd    0x2d7e5a1a
    volumeLabel:       db    "NO NAME    "
    fileSysType:       db    "FAT12   "

And the kernel code let's say it print a simple 'A' character (Kernel.bin):

org 0x7e00
mov al,0x41
mov ah,0x0e
mov bl,0x07
mov bh,0x00
int 0x10
times 512-($-$$) db 0

it's prints nothing. I read lots of problems and solutions in StackOverflow and debugged it as much I could (I'm new to this field). I'll be thankful if someone helps me with the problem.

the command which I use:

nasm -fbin Kernel.asm -o Kernel.bin

nasm -DWITH_BPB -f bin Boot.asm -o OS.img

then run it as a floppy disk in VirtualBox

Thanks In Advance

  • Confusingly, sectors are numbered from 1. So you want to load sector #2. – Jester Nov 25 '20 at 20:34
  • @Jester change ```cx,0x01``` to ```cx,0x02```? checked... didn't work –  Nov 25 '20 at 20:43
  • You might also want to add something at the end, e.g. `jmp $` for an endless loop. Works in qemu, didn't test virtualbox. – Jester Nov 25 '20 at 20:48
  • 2
    You certainly want to load sector 2 (the second sector), not 1. Also, your `org 7E00h` clashes with `jmp 7E0h:0`. Either use `org 0` with that jump, or keep the `org 7E00h` but jump to `0:7E00h`. – ecm Nov 25 '20 at 21:06
  • @ecm Worked!!! your answers are always helpful. thank you so so much. you also help me with problem : https://stackoverflow.com/questions/64819255/load-sectors-to-ram-in-qemu –  Nov 25 '20 at 21:14
  • 1
    I changed the `org`, added `halt:` \ `sti` \ `hlt` \ `jmp halt` after the kernel code's end, changed to `mov cl, 2`, and put `mov sp` as the very next instruction after `mov ss`. It runs fine in dosemu2 and displays `A`. – ecm Nov 25 '20 at 21:16
  • @ecm I didn't change some of them, I'll change them too. thank a lot –  Nov 25 '20 at 21:28
  • @ecm Hey Mate. I ran my 16-bit kernel and worked well and it's a couple of hours I'm searching about how to make it a 64-bit kernel and didn't found something useful. Can you help me with this and tell me how I can do it? Thanks In Advance –  Nov 26 '20 at 14:04
  • That is beyond the scope of my activity here. There are resources out there if you search for them. Try "baremetal 64-bit kernel x86" or such. – ecm Nov 26 '20 at 16:10

0 Answers0