How To Build An Operating System: Segmentation- Part 04

What is Segmentation in OS?

  • Like Paging, Segmentation is another non-contiguous memory allocation technique.
  • In segmentation, the process is not divided blindly into fixed-size pages.
  • Rather, the process is divided into modules for better visualization.

Characteristics

  • Segmentation is a variable size partitioning scheme.
  • In segmentation, secondary memory and main memory are divided into partitions of unequal size.
  • The size of partitions depends on the length of the modules.
  • The partitions of secondary memory are called segments.
Translation of logical addresses to linear addresses

Accessing Memory

func:
mov eax, [esp+4]
mov ebx, [eax]
add ebx, 8
mov [eax], ebx
ret
func:
mov eax, [ss:esp+4]
mov ebx, [ds:eax]
add ebx, 8
mov [ds:eax], ebx
ret

Local Descriptor Table (LDT)

The Global Descriptor Table (GDT)

The segment descriptors needed

Loading the GDT

struct gdt {
unsigned int address;
unsigned short size;
} __attribute__((packed))
lgdt [eax]
Bit:     | 15                                3 | 2  | 1 0 |
Content: | offset (index) | ti | rpl |
The layout of segment selectors
mov ds, 0x10
mov ss, 0x10
mov es, 0x10
.
.
.
; code here uses the previous cs
jmp 0x08:flush_cs ; specify cs when jumping to flush_cs
flush_cs:
; now we've changed cs to 0x08

--

--

--

Software Engineering Undergraduate at University of Kelaniya

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Eth 2.0 Dev Update #54 — So Close to Official Multi-client Testnet!

coin master hack android 2021 | freespinsforcoinmaster.com/generator

How To Win The “Estimates” Game

Best practices for effective code reviews

Backup / Export Docker Image easily

Unleash Multiprocessing with Python and gRPC

Separate color lines illustrating separate processes in your program.

Balancer is live on Polygon!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pubudu Wickramathunge

Pubudu Wickramathunge

Software Engineering Undergraduate at University of Kelaniya

More from Medium

Why HTTP/3?

Elixir logging to (multiple) file(s) using metadata_filter

Scheduling Algorithms in OS

Practical tracing: a final recap