Page 1 of 1
Multitasking in flat memory model
Posted: Wed Oct 16, 2013 12:28 pm
by yee1
Hey,
I want to use flat memory model so there is 1 big segment where
CS=DS and memory size is 4 GB.
But... how about multitasking here ? While I was using tiny memory model (segments) i was preparing new TSS record for GDT table and load it with lgdt instruction. How about tiny memory model ? So far I have found out that I should use paging mechanism (CR3). But what about:
- privilege levels that before I had supported by TSS descriptor
- memory protection, example: TSS1 can not access TSS2 data
How to deal with it ? Please give me some explanations, thank you very much!
Re: Multitasking in flat memory model
Posted: Wed Oct 16, 2013 1:06 pm
by iansjack
Privelege levels - just use two: kernel and userland.
Memory protection - paging provides that. A task can only see memory that is mapped in its page table.
Re: Multitasking in flat memory model
Posted: Wed Oct 16, 2013 3:45 pm
by yee1
iansjack wrote:Privelege levels - just use two: kernel and userland.
Memory protection - paging provides that. A task can only see memory that is mapped in its page table.
Memory protection
ok
Privelege levels
why?
What if I want user application (example task TSS1) to access text video memory at 0xB8000 to write some message and others like access some sort of pc peripherials via task (userland), what then ? If TSS1 may only access some memory provided by paging mechanism then how to get access to 0xB8000 and others memory's area if needed ? How to provide that ?
1 more question. How to jump to new task when no TSS descriptors in GDTR ?
Re: Multitasking in flat memory model
Posted: Wed Oct 16, 2013 5:17 pm
by sortie
It's called system calls and abstractions. A kernel shouldn't allow programs raw access to the hardware, indeed that would be insane as they would have to provide all the kernel services themselves, poor. (Microkernel drivers are special) Instead, all programs would work through the kernel's designated services.
Paging is what allows memory protection. And yes, you can use paging to allow programs access to memory mapped IO buffers such as 0xB8000.
Repeat after me: Segmentation bad, paging awesome. Paging is doubleplusgood!
Also note that hardware task switching with the TSS is obsolete; it has been removed from 64-bit long mode on x86_64 CPUs. No modern operating system uses it - instead it does software context switching, which reportedly is much faster. It may also help you understand the process as software context switching means you do things yourself.
Re: Multitasking in flat memory model
Posted: Sun Oct 20, 2013 3:45 pm
by summersong
I think about that.
Code: Select all
org 0 ; <------ PROBLEM
mov esi,msg_text
int 90h ; syscall
mov esi,msg_text
mov edi,msg_buf
mov ecx,6
rep movsb
jmp $
msg_buf db 'task X',0
msg_text db 'task 1',0
You can do something like this:
Code: Select all
org 0
mov [reloc_offs],esi ; esi is setting by kernel and passed to task
mov esi,msg_text
add esi,[reloc_offs]
int 90h ; syscall
mov esi,msg_text
add esi,[reloc_offs]
mov edi,msg_buf
add edi,[reloc_offs]
mov ecx,6
rep movsb
jmp $
reloc_offs dd 0
msg_buf db 'task X',0
msg_text db 'task 1',0
All apps must be use reloc_offs. I think, that's isn't right.