OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 6:50 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Memory write chashes the OS
PostPosted: Fri Oct 04, 2019 2:59 am 
Offline

Joined: Fri Oct 04, 2019 2:19 am
Posts: 3
I am trying to write a simple OS and I am currently working on memory manager. In short - I have a problem with system crashing upon a write to a particular memory location.

system description:

During boot I set GDT with this setup:

Quote:
gdt_start:

gdt_null: ; the mandatory null descriptor
dd 0x0 ; 'dd' means define double word (i.e. 4 bytes)
dd 0x0

gdt_code: ; the code segment descriptor
; base = 0x0, limit=0xfffff,
; 1st flags: (present)1 (proviledge)00 (descriptor type)1 -> 1001b
; type flags: (code)1 (conforming)0 (readable)1 (accessed)0 -> 1010b
; 2nd flags: (granularity)1 (32-bit default)1 (64-bit seg)0 (AVL)0 -> 1100b
dw 0xffff ; Limit (bits 0-15)
dw 0x0 ; Base (bits 0-15)
db 0x0 ; Base (bits 16-23)
db 10011010b ; 1st flags, type flags
db 11001111b ; 2nd flags, limit (bits 16-19)
db 0x0 ; Base (bits 24-31)

gdt_data: ; the data segment descriptor
; Same as the code segment except for the type flags
; type flags: (code)0 (expend down)0 (writable)1 (accessed)0 -> 0010b
dw 0xffff ; Limit (bits 0-15)
dw 0x0 ; Base (bits 0-15)
db 0x0 ; Base (bits 16-23)
db 10010010b ; 1st flags, type flags
db 11001111b ; 2nd flags, limit (bits 16-19)
db 0x0 ; Base (bits 24-31)

gdt_end: ; The reason for putting a label at the end of the GDT is so we can have the assembler
; calculate the size of the GDT for the GDT descriptor (below)

; GDT descriptor
gdt_descriptor:
dw gdt_end - gdt_start - 1 ; Size of our GDT, always less one of the true Size
dd gdt_start ; Start address of our GDT


To my understanding, this is the simplistic model, where both code and data segment start at 0x0 and span the entire 4GB. No paging is attempted. After this I enter private mode. Here I switch from assembler to C where I have written some bare-bone drivers already (ps2, pic, com, vga text) which all work fine including interrupts. Now I face the memory manager. As a part of the initialization I set a pointer table. Here I encounter problem. I am testing everything in VirtualBox where I get "Guru meditation" :o

I narrowed it down to execution of writing a pointer into a specific memory location: 0x001084f4. Lacking the experiences I searched the twiki and brainstormed:

  • problem with segmentation - can not find anything wrong in code and the mem. write works for addresses before and after the problematic one. GDT table is compiled into my kernel, which gets loaded to 0x7e00, so I can not be altering the table by writing to addresses larger than 1MB.
  • ACPI - I have not covered this topic, but my understanding is that during the boot, some memory regions are populated with data concerning HW setup. In assembler I used https://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_0x15.2C_EAX_.3D_0xE820 to detect memory. To avoid problems I ignore memory intervals that are marked as ACPI recoverable, but that does not solve the problem.

I am sure that this is only a small subset of possible problems. Not having a lot of experiences I am asking for experienced eye to propose additional potential problems that I do not see.


Top
 Profile  
 
 Post subject: Re: Memory write chashes the OS
PostPosted: Fri Oct 04, 2019 3:22 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5103
bee wrote:
GDT table is compiled into my kernel, which gets loaded to 0x7e00, so I can not be altering the table by writing to addresses larger than 1MB.

...Unless you've forgotten to enable the A20 line.

You might want to consider using GRUB as your bootloader for now. You can always write your own bootloader later, if you find you need some functionality that GRUB doesn't provide.


Top
 Profile  
 
 Post subject: Re: Memory write chashes the OS
PostPosted: Fri Oct 04, 2019 5:20 am 
Offline

Joined: Fri Oct 04, 2019 2:19 am
Posts: 3
Experienced eye to the rescue! This actually did the trick and explained a lot - learned something new.

Thank you !


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot], SemrushBot [Bot] and 263 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group