• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tispe

OS and application interaction questions

3 posts in this topic

Let me bring you down to the very core of a CPU, we have the ALU, CU, Registers, CLK, and PC. Outside of the CPU we have memory and in between the memory controller. For the sake of simplicity lets not dwell on cache and "unimportant" CPU sub-systems like pipelining.

On start-up the operating system loads the application binary (EXE file) to memory and it sets the Program Counter (PC) to the Address of the first instruction of the binary block. After execution of the first instruction the PC is incremented and the next instruction is fetched, decoded and executed. This goes on until some interrupt happens or the application has ended.

Before the application was started by the OS, the "context" (registers) was saved on stacks, and after the application finished the context is retrieved.


Now to the point; multitasking. The Scheduler(software) is supposed to allow multiple applications to share the same core by using different schemes.

But how does the Scheduler actually interrupt the application when it has full control?
Is there a timer that interrupts the CPU every 10ms unless it is reset, triggering some Scheduler code?
Is it this we call a preemptive scheduler?
Does the OS before launching a new thread set the CPU to operate in "user mode" limiting some instructions?
What is the difference in processes and services from this perspective?
How does the application allocate memory without hazard, through the memory controller?
How can the OS restrict the application to its own address space, user mode, can't the application disable "user mode" itself?


Also, where can I find the x86 ISA standard? I am interested in assembly language for x86, any compendium / video lessons out there?
0

Share this post


Link to post
Share on other sites
[quote]
But how does the Scheduler actually interrupt the application when it has full control?
Is there a timer that interrupts the CPU every 10ms unless it is reset, triggering some Scheduler code?
[/quote]

On x86, you can set up a timer interrupt to trigger every so often.

[quote]
Does the OS before launching a new thread set the CPU to operate in "user mode" limiting some instructions?
[/quote]

On x86, most os's will set the 'ring level' to 3, limiting some cpu commands (like loading the page table, 'hlt' ing the cpu, etc., making some io ports unavailable)


[quote]
How does the application allocate memory without hazard, through the memory controller?
[/quote]

Generally, it sends a 'syscall' irq, where when the os recieves it, it maps some memory for the application, possibly adding a page table entry.

[quote]
How can the OS restrict the application to its own address space, user mode, can't the application disable "user mode" itself?
[/quote]

On x86, the 'kernel' sets the process to ring level 3, limiting many commands. Restricting the address space is basically done by the kernel setting up a unique page table for the process itself before handing over control to the process.

www.osdev.net may have documentation that will help you out.
1

Share this post


Link to post
Share on other sites
http://wiki.osdev.org/Main_Page

Note that all of what follows depends on the OS you're running, but in a general high level overview, this is how it works.

Basically, the OS keeps a copy of the CPU's registers for every thread. Every so often it interrupts a thread and saves all of it's CPU state. It then loads the CPU state from the next scheduled thread, and continues that thread (part of the loaded/saved state is the PC). If the thread is in a different task, the scheduler will probably load the new task's memory context.

Each process has it's own page directory (memory context), dividing up the physical RAM and placing it around the process's address space. The only way one process can see memory from another process is if the OS puts the page of RAM (typically 4KB) into both address spaces. The OS then protects the page directory and tables by saying only ring 0 can write to it.

x86/x64 has 4 'rings' of protection, though most only use ring 0 (OS) and ring 3 (userspace). Switches between the rings are tightly controled by the OS. Ring switches are almost always either interrupts (hardware notifying the CPU it needs attention now) or system calls (the app requesting a service, like memory allocation or talking to another process)

The typical x86/x64 platform has several timers that can be set to interrupt the CPU at any frequency requested (among other hardware that will also interrupt the CPU when requested, like disk IO finishing or PS/2 data waiting). The OS tells the CPU what to do for which interrupts in a table of basically function pointers. The OS then protects the interrupt tables by saying only ring 0 can write to it. Whenever the CPU recieves a timer interrupt, it jumps to the piece of code that the OS tells it to, which usually executes the sceduler.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0