Problem printing to screen in protected mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Ziddia
Member
Member
Posts: 38
Joined: Sat Nov 05, 2011 6:28 pm

Problem printing to screen in protected mode

Post by Ziddia »

Hello,

I've recently all but completed my bootloader. I successfully managed to enable the A20 line, load the GDT (excluding interrupts, which I'll be working on as soon as I resolve this), and enabled PMode. However, I don't think that my data segment is set properly, and I can't find the cause.

I draw this from the fact that a method I use for printing to the screen in PMode (which worked when my bootloader was only single-stage) is no longer working, and it depends on the DS register.

I need to resolve this before I add in my kernel, to prevent all sorts of problems from appearing, but I can't find the cause (or, what I'm doing wrong, perhaps). For reference, I use the ISO9660 Filesystem, compile ASM in NASM, use a 2-stage bootloader, create my ISOs in MagicISO, and virtualize in VirtualBox.

This applies specifically to NASM in PMode, of course.

And here's the code:

Stage One:

Code: Select all

BITS 16 ; 16-bit mode
ORG 0x7C00 ; Bootloader loads at 0x7C00 in memory

%include "iso9660fs.inc" ; Filesystem data

JMP start ; Jumps to main method

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Bootloader entry point.                                      ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
start:
   MOV SI, msg_booting
   CALL print
   CLI ; CLears Interrupts
   XOR AX, AX ; Reset AX
   MOV DS, AX ; Set DS to 0Ah (AX default?)
   MOV SP, AX ; Same with SP
   MOV AX, 9000h ; Set AX to 9000h
   MOV SS, AX ; Setting our stack
   MOV AX, 1000h ; Set AX to 1000h
   MOV ES, AX ; Setting a different segment
   STI ; STarts Interrupts
   MOV BYTE[bootdrv], DL ; Our bootdrive
   CALL load_vol_desc ; Loads the volume data
   TEST AX, AX ; Test AX
   JZ .err_read ; Jumps to error code if AX == 0
   CALL load_root_dir ; Loads root directory of CD
   TEST AX, AX ; Test AX
   JZ .err_read ; Jumps to error code if AX == 0
   CALL load_loader ; Loads the loader image
   TEST AX, AX ; Test AX
   JZ .err_no_loader ; Jumps to error code if AX == 0
   MOV DL, BYTE[bootdrv] ; Restores our bootdrive
   MOV SI, msg_jumping ; Sets jumping msg to print
   CALL print ; Prints message.
   JMP 1000h:0000h ; Jumps to the loaded boot image

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Called if the image file couldn't be found.                  ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.err_no_loader:
   MOV SI, msg_no_loader ; Set up to print error
   CALL print ; Prints the error
   JMP hang ; Hangs the system

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Called if an error occured while reading the disc.           ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.err_read:
   MOV SI, msg_read ; Set up to print error
   CALL print ; Prints the error
   JMP hang ; Hangs the system

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Loads the volume's data, in preparation for image loading.   ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
load_vol_desc:

.loop:
   MOV SI, dap ; Loads disc data from dap function
   MOV AH, 42h ; Size of the currently looped file
   MOV DL, [bootdrv] ; Bootdrive loaded
   INT 13h ; Interrupt for LBA

   JC .end_err ; Error if carry flag is set by INT 13h

   CMP BYTE[ES:0],1 ; Primary descriptor?
   JE .end ; If yes, end the search
   CMP BYTE[ES:0], 0ffh ; Last descriptor?
   JE .end_err ; If yes, call an error.

   INC DWORD[dap.lba] ; Grabs the next LBA to check.
   JMP .loop ; Try again!


.end:
   MOV AX, 1 ; Ensures that AX checks will fail
   RET ; Return

.end_err:
   XOR AX, AX ; Resets AX (checks will succeed)
   RET ; Return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Loads the root dir. Uses the data in iso9660fs.inc for this. ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
load_root_dir:
   MOV SI, iso9660vol_desc.root_dir_rec ; Loads root data
   MOV EAX, DWORD[ES:SI+iso9660dir_desc.loc_data]
   MOV ECX, DWORD[ES:SI+iso9660dir_desc.data_len] ; Loads root dir length
   SHR ECX, 11 ; Length of root dir / 2048 to get block # (right bit shift) TODO
   ADD CX, 1 ; Not entirely sure what's happening here. TODO
   CALL load_lba ; Gets the LBA for the root block

.end:
   RET ; Return on ending (hopefully with AX == 1)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Loads the LBA for the root dir.                              ;
; Note: EAX is the LBA we are on.                              ;
; CX is the number of LBAs to load for the root directory.     ;
; Defined in load_root_dir.                                    ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
load_lba:
   PUSHA ; Save AH register
   MOV [dap.blocks], CX ; Saves the number of blocks to load.
   MOV [dap.lba], EAX ; Saves the LBA we will load.
   MOV SI, dap ; Loads the data
   MOV AH, 42h ; Size of the currently looped block/lba
   MOV DL, [bootdrv] ; Creates boot drive data
   INT 13h ; Interrupt, we now have the LBA.
   JC .end_err ; Error if carry flag is set

.end:
   POPA ; Restores AH register
   MOV AX, 1 ; FUQ DA ERRORS
   RET ; Return

.end_err:
   POPA ; Restores AH register
   XOR AX, AX ; CONFOUND THESE BUGS
   RET ; Return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Loads the image file.                                        ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
load_loader:
   XOR SI, SI ; Restore SI
   SHL ECX, 11 ; Gets size of root dir

.loop_search:
   CMP BYTE[ES:SI], 0 ; Checks if is root dir entry
   JE .end_err ; If not, error.
   CMP SI, CX ; Checks if SI == root dir size
   JE .end_err ; If yes, error.
   MOV DI, SI ; Saves DI
   ADD DI, iso9660dir_desc.file_ident ; Points DI to file name/address
   PUSH CX ; Save CX
   PUSH SI ; Save SI
   MOVZX CX, BYTE[ES:SI+iso9660dir_desc.len_file_ident] ; Size of file ID
   MOV SI, os_img ; Load our image name
   REP CMPSB ; Compares string bytes until CX == 0
   MOV AL, [SI] ; If strings equal, AL == 0
   POP SI ; Restore SI
   POP CX ; Restore CX
   TEST AL, AL ; Tests if AL is 0
   JZ .load ; If so, load the file
   MOVZX AX, BYTE[ES:SI+iso9660dir_desc.len_dir_rec] ; Size of directory
   ADD SI, AX ; Make SI point to next entry
   JMP .loop_search ; Search again

.load:
   MOV EAX, DWORD[ES:SI+iso9660dir_desc.loc_data] ; LBA of file
   MOV ECX, DWORD[ES:SI+iso9660dir_desc.data_len] ; Length of file
   SHR ECX, 11 ; Switch back to 16-bit
   INC CX ; Increment in case we miss a block
   CALL load_lba ; Reload all LBAs

.end:
   RET ; File loaded into memory - return

.end_err:
   XOR AX, AX ; Null AX
   RET ; Return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DAP stuff.                                                   ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 4 ; 4 bits

dap:
   .size DB 10h ; Disc size I believe
   .reserved DB 0 ; Reserved sectors/blocks
   .blocks DW 1 ; Number of blocks
   .offset DW 0 ; Offset at beginning of search
   .segment DW 1000h ; Segments in disc
   .lba DD 10h, 0 ; Number of LBAs

bootdrv DB 0 ; Our drive number

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Stage1 subroutines.                                          ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;                                      

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Prints a string to the screen.                               ;
; Takes the value of SI to do this.                            ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
print:         ; Routine: output string in SI to screen
   PUSHA ; Saves value of AH
   MOV AH, 0Eh      ; int 10h 'print char' function

.repeat:
   LODSB         ; Get character from string
   CMP AL, 0
   JE .done      ; If char is zero, end of string
   INT 10h         ; Otherwise, print it
   JMP .repeat

.done:
   POPA ; Loads AH back into memory
   RET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Hangs the system.                                            ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
hang:
CLI
HLT

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Stage1 declarations.                                         ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
msg_booting DB 'ZidOS is booting...',13,10,0
msg_jumping DB 'Preparing to jump to Stage2.',13,10,0
msg_no_loader DB 'Could not find the Stage2 image.',13,10,0
msg_read DB 'Could not read the disc.',13,10,0
os_img DB 'BOOTTWO.BIN',0

TIMES 510-($-$$) DB 0
DW 0AA55h
Stage Two:

Code: Select all

[BITS 16] ; Working in 16-bit mode

PUSH CS
POP DS ; Reloads DS register because it seems to have been messed up in Stage1
MOV SI, boot_msg ; Sets up to print the boot message
CALL print ; Prints the contents of SI
CALL enable_a20 ; Enables A20 for OVER 4GB of RAM!
MOV SI, pmode_msg ; Sets up to print the Entering PMode message
CALL print ; Prints the contents of SI
CLI ; Clears those pesky interrupts for GDT!
XOR AX, AX ; Logical OR (basically resets, I think?)
MOV DS, AX ; Loads DS register
lgdt[gdt_desc] ; Loads the GDT.
MOV EAX, CR0 ; Setting up PMode, dumps CR0 into EAX
OR EAX, 1 ; Sets bit 0 on CR0
MOV CR0, EAX ; Dumps EAX into CR0, with bits set
JMP 08h:clear_pipe ; Jumps to clear 16-bit instructions

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; STAGE2 SUBROUTINES                                           ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; GDT section.                                                 ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
gdt:                    ; Address for the GDT

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Null segment, reserved by Intel.                             ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
gdt_null:               ; Null Segment
        dd 0
        dd 0

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

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Calculates the GDT size.                                     ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
gdt_end:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; GDT descriptor.                                              ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
gdt_desc:
 dw gdt_end - gdt - 1    ; Limit (size)
 dd gdt                  ; Address of the GDT

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Prints a string to the screen.                               ;
; Takes the value of SI to do this.                            ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
print:			; Routine: output string in SI to screen
	mov ah, 0Eh		; int 10h 'print char' function

.repeat:
	lodsb			; Get character from string
	cmp al, 0
	je .done		; If char is zero, end of string
	int 10h			; Otherwise, print it
	jmp .repeat

.done:
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Sets up the A20 line for up to 4GB of memory.                ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
enable_a20:
	cli                ;Disables interrupts
	push	ax         ;Saves AX
	mov	al, 0xdd  ;Look at the command list 
	out	0x64, al   ;Command Register 
	pop	ax          ;Restore's AX
	sti                ;Enables interrupts
	mov si, a20_msg
	call print
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 16-bit Declarations.                                         ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
boot_msg DB 'Stage Two Loaded.',13,10,0 ; Boot message
pmode_msg DB 'Now entering Protected Mode...',13,10,0 ; PMode message
a20_msg DB 'Address line active.',13,10,0 ; A20 active


[BITS 32] ; Enter 32-bit mode.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Clears previous 16-bit instructions in PMode.                ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
clear_pipe:
 MOV AX, 10h ; Sets AX for segments
 MOV DS, AX ; Sets data segment
 MOV SS, AX ; Sets stack segment
 MOV ESP, 090000h ; Sets our stack
 MOV BYTE [DS:0B8000h], 'P'
 MOV BYTE [DS:0B8001h], 1Bh
 JMP hang

hang:
 JMP hang
Thankyou to anyone who can help!
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Problem printing to screen in protected mode

Post by VolTeK »

Try your debugger, step through and see what results you get, or if its even executing your code ;)
Ziddia
Member
Member
Posts: 38
Joined: Sat Nov 05, 2011 6:28 pm

Re: Problem printing to screen in protected mode

Post by Ziddia »

VolTeK wrote:Try your debugger, step through and see what results you get, or if its even executing your code ;)
I was debugging earlier with some string printing - I haven't set up any way to dump the contents of the registers yet, and I don't think VB can do that, so I'll look into that. I know that it at least gets through the LGDT before it all goes to hell :P
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Problem printing to screen in protected mode

Post by VolTeK »

What virtual machine are you using, id recommend bochs for its debugger.
Ziddia
Member
Member
Posts: 38
Joined: Sat Nov 05, 2011 6:28 pm

Re: Problem printing to screen in protected mode

Post by Ziddia »

VolTeK wrote:What virtual machine are you using, id recommend bochs for its debugger.
I was having trouble with bochsrc configurations, but I'll try it again soon.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Problem printing to screen in protected mode

Post by DavidCooper »

Nothing obviously wrong. I can only see a couple of things which might be worth checking. When you do lgdt, could the structure that points at the GDT be defective because the last two bytes of that 8-byte structure contain mov ah,0Eh? (I don't know if they ever matter, but making them both 0 would at least rule that out as a possible problem.) Might your A20 setting code be upsetting the emulator in some way - I haven't seen this way of enabling the A20 before and it looks to me as if may only be doing half the job, and getting that wrong too. (A quick way to check that would be to bypass that bit of code and not open the A20 - it isn't actually needed for anything at the moment as you aren't touching memory beyond the one megabyte point.)

[Another thought, though I expect you've looked at it already: when you do lgdt, I haven't tried to trace the content of ds at that point, but I hope you've checked that it's actually managing to find the structure that points at the GDT by generating the right address to go with whatever ds contains.]
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
Ziddia
Member
Member
Posts: 38
Joined: Sat Nov 05, 2011 6:28 pm

Re: Problem printing to screen in protected mode

Post by Ziddia »

Thanks for the help - I'm 99% certain that lgdt is generating the right address for DS, but I'll take a look. I'll also take out the part about the a20 and see if that fixes it.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Problem printing to screen in protected mode

Post by VolTeK »

A good question is, what are you expecting DS to be? ;)
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: Problem printing to screen in protected mode

Post by turdus »

Ziddia wrote:I don't think VB can do that, so I'll look into that.
If by any chance VB means VirtualBox, it has a really nice built-in debugger afaik:
http://www.virtualbox.org/manual/ch12.html#idp6387504
Ziddia
Member
Member
Posts: 38
Joined: Sat Nov 05, 2011 6:28 pm

Re: Problem printing to screen in protected mode

Post by Ziddia »

turdus wrote:
Ziddia wrote:I don't think VB can do that, so I'll look into that.
If by any chance VB means VirtualBox, it has a really nice built-in debugger afaik:
http://www.virtualbox.org/manual/ch12.html#idp6387504
Never saw that. Thanks!
Ziddia
Member
Member
Posts: 38
Joined: Sat Nov 05, 2011 6:28 pm

Re: Problem printing to screen in protected mode

Post by Ziddia »

Seems that DS isn't right. I dumped the contents of the registers just after the MOV BYTE[DS:0B8000h], 'P' part, and here's what I ended up with:

Image

Also, I don't know whether it's a compiler thing or if I wrote something weirdly, but this section here in clear_pipe:

Code: Select all

MOV AX, 10h ; Sets AX for segments
MOV DS, AX ; Sets data segment
MOV SS, AX ; Sets stack segment
MOV ESP, 090000h ; Sets our stack
looks like this in the Bochs debugger:

Code: Select all

MOV AX, 10h ; Sets AX for segments
MOV RSP, AX
XOR AX, AX
MOV DS, AX ; Sets data segment
MOV SS, AX ; Sets stack segment
MOV ESP, 090000h ; Sets our stack
Which would mean that both DS and SS are being set to zero, rather than 10h, I assume? Not sure if that's a problem at all.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Problem printing to screen in protected mode

Post by DavidCooper »

Not being an assembler user, I'm wondering how the assembler knows where the 2nd stage sits in memory without an ORG statement in order to be able to generate correct addresses for it.

Have you got a version of your code that also shows all the hex that it gets turned into?
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problem printing to screen in protected mode

Post by Combuster »

Image
It amazes me that it neither shows DS, nor CRx, nor any of your code being actually executed (CS:IP points into the bios). How did you draw your conclusions?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Ziddia
Member
Member
Posts: 38
Joined: Sat Nov 05, 2011 6:28 pm

Re: Problem printing to screen in protected mode

Post by Ziddia »

Combuster wrote:
Image
It amazes me that it neither shows DS, nor CRx, nor any of your code being actually executed (CS:IP points into the bios). How did you draw your conclusions?
This is only a small portion of the output I received - I thought that this part was the relevant section of it. I don't think it showed the content of all the registers, though.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Problem printing to screen in protected mode

Post by VolTeK »

sreg shows the content of the Segment registers. If you thought that was relevant there is a missing portion of education in either assembler, or how to use the debugger you need to gain.

0xFE0AF refers to bios memory. Do a cli hlt and get the address halted at, then replace the cli hlt with two nop instructions, run through again and perform a break at the address where the nop's are, and single step through there.


Also look up how to fully use bochs debugger (or its manual), and how to debug while you at it.
Post Reply