alright I am trying to develop an operating system with assembly. I have written the boot loader and the beginnings of a kernel-however I am having a problem printing characters to the screen.

Here is my bootloader

use16      ; We need 16-bit intructions for Real mode

ORG 0x7C00    ; The BIOS loads the boot sector into memory location 0x7C00
      mov ah, 0
      int 13h
      or ah, ah
      jnz reset_drive
mov ax,0
mov es,ax
mov bx,0x1000
mov ah,02h
mov al,02h
mov ch,0
mov cl,02h
mov dh,0
int 13h
or ah,ah
jnz reset_drive
        cli                     ; Disable interrupts, we want to be alone
        xor ax, ax
        mov ds, ax              ; Set DS-register to 0 - used by lgdt

        lgdt [gdt_desc]         ; Load the GDT descriptor

        mov eax, cr0            ; Copy the contents of CR0 into EAX
        or eax, 1               ; Set bit 0
        mov cr0, eax            ; Copy the contents of EAX into CR0

       jmp 08h:clear_pipe      ; Jump to code segment, offset clear_pipe

use32                       ; We now need 32-bit instructions
        mov ax, 10h             ; Save data segment identifyer
        mov ds, ax              ; Move a valid data segment into the data segment register
        mov ss, ax              ; Move a valid data segment into the stack segment register
        mov esp, 090000h        ; Move the stack pointer to 090000h
	mov esi,words
	xor edx,edx
	loop0:    ;put message to screen
	  mov word cx,[esi]
	  mov word [ds:0B8000h+1920d+edx],cx    ; M
	  inc edx
	  inc esi
	  cmp byte [esi],0
	  jnz loop0
	;mov byte [ds:0B8001h], 1Bh      ; Assign a color code
jmp 01000h

gdt:                    ; Address for the GDT

gdt_null:               ; Null Segment
        dd 0
        dd 0

gdt_code:               ; Code segment, read/execute, nonconforming
        dw 0FFFFh
        dw 0
        db 0
        db 10011010b
        db 11001111b
        db 0

gdt_data:               ; Data segment, read/write, expand down
        dw 0FFFFh
        dw 0
        db 0
        db 10010010b
        db 11001111b
        db 0

gdt_end:                ; Used to calculate the size of the GDT

gdt_desc:                       ; The GDT descriptor
        dw gdt_end - gdt - 1    ; Limit (size)
        dd gdt                  ; Address of the GDT
words db 't h i s   i s   a   f u n c t i o n a l   b o o t l o a d e r   ',0000

times 510-($-$$) db 0           ; Fill up the file with zeros

        dw 0AA55h                ; Boot sector identifyer
;credit for tutorial which helped me make this goes to Greg Brunmar and his "The Booting Process"

now when this loads it has no problem putting the text "This is a functional bootloader" to the screen with background color green. However, when it loads the kernel(at 01000h) it will not print sample text to the screen

org 0x1000
mov eax,0B8000h				
  mov dword [eax],'PPPP'		;print 'PP' with background dark purple
  jmp hang

when i debug the output it shows that it is correctly loading and running, but PP is not printed to the screen. Also, eax gets set to FFFFFFFFh, not the video memory offset. Is this because this being loaded into protected mode disallows access to the bios video memory? Then why doesn't the bootloader code have the same restriction because it is loaded into the same code segment? Also, in the bootloader, changing jmp 08h:clear_pipe to just jmp clear_pipe allows the kernel code to write to the screen, but not the bootloader code(it shows PP but not 'this is a functional bootloader')

Edited by maf5693: n/a

6 Years
Discussion Span
Last Post by maf5693

nevermind i fixed it...needed 'use32' command at top so it knew to be 32bit code-also needed to specify the location as the data segment [ds:0b8000h]

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.