Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x86 Calculator error in Assembly and some disk errors #11

Closed
AtieP opened this issue Mar 15, 2020 · 1 comment
Closed

x86 Calculator error in Assembly and some disk errors #11

AtieP opened this issue Mar 15, 2020 · 1 comment

Comments

@AtieP
Copy link

AtieP commented Mar 15, 2020

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 😅
And to all frustrated people, here you are my bootloader that works anywhere: https://github.com/AtieP/AtieDOS/blob/master/bootloader.asm

@pritamzope
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants