root@C202511211157657:~# python3 segmentation.py -a 128 -p 512 -b 0 -l 20 -B 512 -L 20 -s 0
ARG seed 0
ARG address space size 128
ARG phys mem size 512
Segment register information:
Segment 0 base (grows positive) : 0x00000000 (decimal 0)
Segment 0 limit : 20
Segment 1 base (grows negative) : 0x00000200 (decimal 512)
Segment 1 limit : 20
Virtual Address Trace
VA 0: 0x0000006c (decimal: 108) --> PA or segmentation violation?
VA 1: 0x00000061 (decimal: 97) --> PA or segmentation violation?
VA 2: 0x00000035 (decimal: 53) --> PA or segmentation violation?
VA 3: 0x00000021 (decimal: 33) --> PA or segmentation violation?
VA 4: 0x00000041 (decimal: 65) --> PA or segmentation violation?
For each virtual address, either write down the physical address it translates to
OR write down that it is an out-of-bounds address (a segmentation violation). For
this problem, you should assume a simple address space with two segments: the top
bit of the virtual address can thus be used to check whether the virtual address
is in segment 0 (topbit=0) or segment 1 (topbit=1). Note that the base/limit pairs
given to you grow in different directions, depending on the segment, i.e., segment 0
grows in the positive direction, whereas segment 1 in the negative.
Seg 0: [0, 19] – difference of VA and PA: 0
Seg 1:[108, 127] – difference of VA and PA: 384
Since the address space size is 128, we should check the least 7th bit (or, if the VA is less than 0x40 – 64, then it belongs to Seg0)
No matter which seg a VA belongs to, we can always use the difference of both base (of VA and PA, physical address) to plus VA to get its corresponding PA.
VA 0: 0x0000006c (decimal: 108) –> seg1, Physical Address 0x1EC (decimal 492)
VA 1: 0x00000061 (decimal: 97) –> seg1, segmentation violation
VA 2: 0x00000035 (decimal: 53) –> seg0, segmentation violation
VA 3: 0x00000021 (decimal: 33) –> seg0, segmentation violation
VA 4: 0x00000041 (decimal: 65) –> seg1, segmentation violation
However, I found a problem that it says “ARG phys mem size 512”, while the base of Segment 1 is 512… Isn’t it wrong?
Later, I found it’s not wrong because the valid interval of seg1 is actually [base – limit + 1 .. base – 1].
root@C202511211157657:~# python3 segmentation.py -a 128 -p 512 -b 0 -l 20 -B 512 -L 20 -s 1
ARG seed 1
ARG address space size 128
ARG phys mem size 512
Segment register information:
Segment 0 base (grows positive) : 0x00000000 (decimal 0)
Segment 0 limit : 20
Segment 1 base (grows negative) : 0x00000200 (decimal 512)
Segment 1 limit : 20
Virtual Address Trace
VA 0: 0x00000011 (decimal: 17) --> PA or segmentation violation?
VA 1: 0x0000006c (decimal: 108) --> PA or segmentation violation?
VA 2: 0x00000061 (decimal: 97) --> PA or segmentation violation?
VA 3: 0x00000020 (decimal: 32) --> PA or segmentation violation?
VA 4: 0x0000003f (decimal: 63) --> PA or segmentation violation?
For each virtual address, either write down the physical address it translates to
OR write down that it is an out-of-bounds address (a segmentation violation). For
this problem, you should assume a simple address space with two segments: the top
bit of the virtual address can thus be used to check whether the virtual address
is in segment 0 (topbit=0) or segment 1 (topbit=1). Note that the base/limit pairs
given to you grow in different directions, depending on the segment, i.e., segment 0
grows in the positive direction, whereas segment 1 in the negative.
Seg 0: [0, 19] – difference of VA and PA: 0
Seg 1:[108, 127] – difference of VA and PA: 384
VA 0: 0x00000011 (decimal: 17) –> seg0, Physical Address 0x011 (decimal 17)
VA 1: 0x0000006c (decimal: 108) –> seg1, Physical Address 0x1EC (decimal 492)
VA 2: 0x00000061 (decimal: 97) –> seg1, segmentation violation
VA 3: 0x00000020 (decimal: 32) –> seg0, segmentation violation
VA 4: 0x0000003f (decimal: 63) –> seg1, segmentation violation
root@C202511211157657:~# python3 segmentation.py -a 128 -p 512 -b 0 -l 20 -B 512 -L 20 -s 2
ARG seed 2
ARG address space size 128
ARG phys mem size 512
Segment register information:
Segment 0 base (grows positive) : 0x00000000 (decimal 0)
Segment 0 limit : 20
Segment 1 base (grows negative) : 0x00000200 (decimal 512)
Segment 1 limit : 20
Virtual Address Trace
VA 0: 0x0000007a (decimal: 122) --> PA or segmentation violation?
VA 1: 0x00000079 (decimal: 121) --> PA or segmentation violation?
VA 2: 0x00000007 (decimal: 7) --> PA or segmentation violation?
VA 3: 0x0000000a (decimal: 10) --> PA or segmentation violation?
VA 4: 0x0000006a (decimal: 106) --> PA or segmentation violation?
For each virtual address, either write down the physical address it translates to
OR write down that it is an out-of-bounds address (a segmentation violation). For
this problem, you should assume a simple address space with two segments: the top
bit of the virtual address can thus be used to check whether the virtual address
is in segment 0 (topbit=0) or segment 1 (topbit=1). Note that the base/limit pairs
given to you grow in different directions, depending on the segment, i.e., segment 0
grows in the positive direction, whereas segment 1 in the negative.
Seg 0: [0, 19] – difference of VA and PA: 0
Seg 1:[108, 127] – difference of VA and PA: 384
VA 0: 0x0000007a (decimal: 122) –> seg1, Physical Address 0x1FA (decimal 506)
VA 1: 0x00000079 (decimal: 121) –> seg1, Physical Address 0x1F9 (decimal 505)
VA 2: 0x00000007 (decimal: 7) –> seg0, Physical Address 0x007 (decimal 7)
VA 3: 0x0000000a (decimal: 10) –> seg0, Physical Address 0x00A (decimal 10)
VA 4: 0x0000006a (decimal: 106) –> seg1, Physical Address 0x1EA (decimal 490)
The highest legal virtual address in segment 0: 0x13(decimal 19)
The lowest legal virtual address in segment 1: 0x6C(decimal 108)
The lowest and highest illegal addresses in this entire address space: 0x14, 0x6B
Verification using -A:
root@C202511211157657:~# python3 segmentation.py -a 128 -p 512 -b 0 -l 20 -B 512 -L 20 -A 19,108,20,107 -c
ARG seed 0
ARG address space size 128
ARG phys mem size 512
Segment register information:
Segment 0 base (grows positive) : 0x00000000 (decimal 0)
Segment 0 limit : 20
Segment 1 base (grows negative) : 0x00000200 (decimal 512)
Segment 1 limit : 20
Virtual Address Trace
VA 0: 0x00000013 (decimal: 19) --> VALID in SEG0: 0x00000013 (decimal: 19)
VA 1: 0x0000006c (decimal: 108) --> VALID in SEG1: 0x000001ec (decimal: 492)
VA 2: 0x00000014 (decimal: 20) --> SEGMENTATION VIOLATION (SEG0)
VA 3: 0x0000006b (decimal: 107) --> SEGMENTATION VIOLATION (SEG1)
I can set them like this below:
root@C202511211157657:~# python3 segmentation.py -a 16 -p 128 -A 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 --b0 0 --l0 2 --b1 128 --l1 2 -c
ARG seed 0
ARG address space size 16
ARG phys mem size 128
Segment register information:
Segment 0 base (grows positive) : 0x00000000 (decimal 0)
Segment 0 limit : 2
Segment 1 base (grows negative) : 0x00000080 (decimal 128)
Segment 1 limit : 2
Virtual Address Trace
VA 0: 0x00000000 (decimal: 0) --> VALID in SEG0: 0x00000000 (decimal: 0)
VA 1: 0x00000001 (decimal: 1) --> VALID in SEG0: 0x00000001 (decimal: 1)
VA 2: 0x00000002 (decimal: 2) --> SEGMENTATION VIOLATION (SEG0)
VA 3: 0x00000003 (decimal: 3) --> SEGMENTATION VIOLATION (SEG0)
VA 4: 0x00000004 (decimal: 4) --> SEGMENTATION VIOLATION (SEG0)
VA 5: 0x00000005 (decimal: 5) --> SEGMENTATION VIOLATION (SEG0)
VA 6: 0x00000006 (decimal: 6) --> SEGMENTATION VIOLATION (SEG0)
VA 7: 0x00000007 (decimal: 7) --> SEGMENTATION VIOLATION (SEG0)
VA 8: 0x00000008 (decimal: 8) --> SEGMENTATION VIOLATION (SEG1)
VA 9: 0x00000009 (decimal: 9) --> SEGMENTATION VIOLATION (SEG1)
VA 10: 0x0000000a (decimal: 10) --> SEGMENTATION VIOLATION (SEG1)
VA 11: 0x0000000b (decimal: 11) --> SEGMENTATION VIOLATION (SEG1)
VA 12: 0x0000000c (decimal: 12) --> SEGMENTATION VIOLATION (SEG1)
VA 13: 0x0000000d (decimal: 13) --> SEGMENTATION VIOLATION (SEG1)
VA 14: 0x0000000e (decimal: 14) --> VALID in SEG1: 0x0000007e (decimal: 126)
VA 15: 0x0000000f (decimal: 15) --> VALID in SEG1: 0x0000007f (decimal: 127)
But it would be okay if –l0 and –l1 is 2 and if both segs doen’t overlap.
Prerequisite: both segs doesn’t overlap.
Answer: When the sum of two ‘-l’s is greater than 90% of address space. So -a, –l0 and –l1 is important.
Setting –l0 and –l1 to zero.