pritamzope / OS

Writing & Making Operating System and Kernel parts so simple like Hello World Programs, Starting from writing Bootloaders, Hello World Kernel, GDT, IDT, Terminal, Keyboard/Mouse, Memory Manager, HDD ATA R/W, VGA/VESA Graphics
http://createyourownos.blogspot.com
663 stars 103 forks source link

x86 Calculator error in Assembly and some disk errors #11

Closed AtieP closed 3 years ago

AtieP commented 4 years ago

This

;******************************************
; botloader code begin

[bits 16]           ; tell assembler that working in real mode(16 bit mode)
[org 0x7c00]        ; organize from 0x7C00 memory location where BIOS will load us

start:              ; start label from where our code starts

  xor ax,ax           ; set ax register to 0
  mov ds,ax           ; set data segment(ds) to 0
  mov es,ax           ; set extra segment(es) to 0

  ;******************************************
  ; jumping from rel mode to protected mode
  ; by using disk interrupt

  mov ah, 0x02        ; load second stage to memory
  mov al, 0x10        ; numbers of sectors to read into memory
  mov dl, 0x80        ; sector read from fixed/usb disk
  mov ch, 0           ; cylinder number
  mov dh, 0           ; head number
  mov cl, 2           ; sector number
  mov bx, _start      ; load into es:bx segment :offset of buffer
  int 0x13            ; disk I/O interrupt

  ; before jumping clearing all interrupts
  cli

  ; jump to protected mode
  jmp _start                 ; jump to second stage

  times (510 - ($ - $$)) db 0x00     ;set 512 bytes for boot sector which are necessary
  dw 0xAA55                          ; boot signature 0xAA & 0x55

; bootloader code end

;******************************************
; x86 code begin 

_start:

main : 

doesn't jump do protected mode. Theres no GDT in this code, an also, in protected mode you can't use bios interrupts.

Postdata: The disk reading code doesn't work on some emulators and computers, because CS isn't 0 ,you don't set the stack to 0x7c00, you musnt set dl to anything, you don't set bx to 0x7e00 and you don't jump to 0x7e00.

Hope this helps :sweat_smile: And to all frustrated people, here you are my bootloader that works anywhere: https://github.com/AtieP/AtieDOS/blob/master/bootloader.asm

pritamzope commented 3 years ago

Yes, it is an old code, GDT code has been added to https://github.com/pritamzope/OS/tree/master/Global_Descriptor_Table/asm so this code needs an update, you can combine this with above link code.