﻿1
00:00:00,060 --> 00:00:01,570
‫Hello and welcome back, guys.

2
00:00:01,590 --> 00:00:08,310
‫In the last lecture we implemented paging in this lecture, we're going to make it so we can change

3
00:00:08,310 --> 00:00:10,220
‫the pages and change where they point.

4
00:00:10,650 --> 00:00:12,300
‫So just go to page and see.

5
00:00:12,300 --> 00:00:18,210
‫And we're going to create a brand new function called paging get indexes and it'll return and encourage

6
00:00:18,210 --> 00:00:19,530
‫us to just go in it.

7
00:00:19,530 --> 00:00:23,730
‫Paging get indexes.

8
00:00:24,300 --> 00:00:29,520
‫And we're just going to want a virtual address passed into here.

9
00:00:29,770 --> 00:00:39,120
‫OK, we're also going to want a Unit 32 t pointer for the directory index, and this will be an index

10
00:00:39,120 --> 00:00:39,360
‫out.

11
00:00:39,360 --> 00:00:41,730
‫So we'll be setting whatever they pass to us here.

12
00:00:41,730 --> 00:00:42,060
‫Right.

13
00:00:42,390 --> 00:00:48,690
‫And we also want a table index out and we could just return the structure if we wanted.

14
00:00:49,050 --> 00:00:50,940
‫But I think it is unnecessary.

15
00:00:51,420 --> 00:00:56,770
‫So the first thing we need to do is ensure that the virtual address is aligned.

16
00:00:57,060 --> 00:00:59,880
‫Now, it doesn't look like we created a function for that yet.

17
00:00:59,880 --> 00:01:01,360
‫So we're going to create one.

18
00:01:01,380 --> 00:01:10,500
‫What we're going to do is we're going to say all paging is aligned and we're going to pass in a virtual

19
00:01:10,500 --> 00:01:11,240
‫address here.

20
00:01:11,940 --> 00:01:14,760
‫Oh, not even a virtual address, actually, just to address.

21
00:01:15,210 --> 00:01:17,910
‫And we're going to just return address.

22
00:01:21,160 --> 00:01:21,880
‫Paging.

23
00:01:23,710 --> 00:01:24,760
‫Page cise.

24
00:01:28,280 --> 00:01:32,430
‫And if this is equal to zero, then it's line, yeah.

25
00:01:32,900 --> 00:01:36,080
‫And we also need to scroll up and we need to include

26
00:01:38,630 --> 00:01:44,180
‫Sebold Page and we should put this in the header file, actually, because we're going to be putting

27
00:01:44,180 --> 00:01:45,770
‫the prototype in here eventually.

28
00:01:46,430 --> 00:01:47,870
‫So as we pull up the.

29
00:01:49,130 --> 00:01:50,890
‫Hey, back to paging Dr. C..

30
00:01:52,060 --> 00:01:56,580
‫And we can see it's complaining that's because it needs to be converted to a Unit 32 T.

31
00:01:56,710 --> 00:01:58,530
‫OK, so just cast it.

32
00:01:59,140 --> 00:01:59,620
‫There we are.

33
00:01:59,650 --> 00:02:10,120
‫So now we can say if the paging is not aligned for the virtual dress, then I will get Crane Response

34
00:02:10,120 --> 00:02:10,780
‫variable here.

35
00:02:11,330 --> 00:02:23,350
‫Uh, response equals minus INS and we're going to include status Hajj to give us access to that.

36
00:02:24,810 --> 00:02:27,000
‫OK, and we're going to go to out as well.

37
00:02:27,280 --> 00:02:28,880
‫We're crying out label down here.

38
00:02:29,520 --> 00:02:30,290
‫OK, nice.

39
00:02:30,300 --> 00:02:38,460
‫So the first thing this will do is it will ensure that the the virtual address provided here is paging

40
00:02:38,460 --> 00:02:46,410
‫aligned and basically is a valid paging address because remember, the pages are required to work on

41
00:02:46,410 --> 00:02:48,920
‫a four thousand eighty six byte boundary.

42
00:02:49,410 --> 00:02:51,030
‫That's just how the paging works.

43
00:02:51,030 --> 00:02:51,310
‫Right.

44
00:02:51,600 --> 00:02:53,220
‫Which is why we need to ensure alignment.

45
00:02:53,700 --> 00:03:01,050
‫Now, this function that we're creating will be responsible for taking a virtual address and calculating

46
00:03:01,290 --> 00:03:10,260
‫which directory index in the directory entry table and which in the page table are responsible for that

47
00:03:10,260 --> 00:03:11,150
‫virtual address.

48
00:03:11,530 --> 00:03:18,630
‫So, for example, if you put in zero zero zero, the directory index will be zero and the table entry

49
00:03:18,630 --> 00:03:20,140
‫will be zero as well.

50
00:03:20,880 --> 00:03:22,080
‫So that makes sense.

51
00:03:22,860 --> 00:03:28,800
‫So essentially this will resolve a virtual address to a directory entry and a table index.

52
00:03:29,710 --> 00:03:33,370
‫So this is directory entry, right?

53
00:03:33,390 --> 00:03:36,360
‫And this is our page table entry here.

54
00:03:36,550 --> 00:03:44,100
‫OK, so it will resolve which directory entry that we are using for that virtual address and which table

55
00:03:44,100 --> 00:03:46,230
‫entry we're using for that virtual address.

56
00:03:46,260 --> 00:03:52,020
‫OK, so we're going to write the equation for this now.

57
00:03:52,170 --> 00:03:59,130
‫OK, so to calculate the directory index to as follows so we go directory index out equals.

58
00:03:59,140 --> 00:04:01,500
‫So we're setting that directory index.

59
00:04:02,400 --> 00:04:04,970
‫Fairbrother the pass to us via pointer here.

60
00:04:04,980 --> 00:04:05,220
‫Right.

61
00:04:05,670 --> 00:04:09,920
‫So we're going to set that and we're going to cast to you and it's 32 t.

62
00:04:11,350 --> 00:04:12,820
‫The virtual address.

63
00:04:15,150 --> 00:04:21,630
‫And now we're going to divide it by total page in total anticipatable.

64
00:04:24,680 --> 00:04:29,180
‫Multiplied by paging page size.

65
00:04:30,500 --> 00:04:34,880
‫OK, so that's how we calculate the directory index.

66
00:04:36,030 --> 00:04:39,930
‫So it's the virtual address divided by.

67
00:04:41,930 --> 00:04:45,050
‫One thousand twenty four multiplied by four nine six.

68
00:04:45,680 --> 00:04:49,690
‫OK, that gives us the directory index that we are to be using.

69
00:04:50,450 --> 00:04:54,640
‫So we now need to implement the page table entry.

70
00:04:55,220 --> 00:04:57,130
‫We need to now calculate what that is.

71
00:04:57,410 --> 00:05:05,810
‫So to do that, we just go table index out equals Unit 32 T. And we could name these variables something

72
00:05:05,810 --> 00:05:07,610
‫a bit more appropriate, really.

73
00:05:07,610 --> 00:05:08,480
‫But never mind.

74
00:05:09,050 --> 00:05:10,400
‫You understand what I'm saying?

75
00:05:10,850 --> 00:05:19,960
‫So we're going to go a page in total entries per table multiplied by paging page size.

76
00:05:20,570 --> 00:05:24,200
‫And then here we're going to go divide by paging page size.

77
00:05:25,710 --> 00:05:31,940
‫OK, so I hope that makes sense and then in the out, we just return wrests.

78
00:05:32,790 --> 00:05:34,980
‫OK, so let's now explain the math here then.

79
00:05:34,980 --> 00:05:37,200
‫So I'm going to open Python so I can show you.

80
00:05:37,890 --> 00:05:43,110
‫So let's say we have a virtual address of zero X.

81
00:05:44,220 --> 00:05:51,780
‫Four hundred and five thousand, and let's just ensure that that goes into four, nine six, I'm pretty

82
00:05:51,780 --> 00:05:52,310
‫sure does.

83
00:05:52,320 --> 00:05:53,130
‫Yes, it does.

84
00:05:53,160 --> 00:05:53,700
‫Excellent.

85
00:05:54,210 --> 00:05:56,840
‫OK, so we've we've created a python variable here.

86
00:05:56,850 --> 00:05:58,230
‫You don't have to do this in Python.

87
00:05:58,230 --> 00:05:59,270
‫Just follow what I'm doing.

88
00:05:59,320 --> 00:06:02,790
‫Just follow the video so I can explain this math to you.

89
00:06:02,790 --> 00:06:03,050
‫Right.

90
00:06:03,630 --> 00:06:07,070
‫So we go virtual addresses for the directory index now, right.

91
00:06:07,410 --> 00:06:16,620
‫Directory index equals virtual address divided by one thousand twenty four entries per table, multiplied

92
00:06:16,620 --> 00:06:18,900
‫by the page size of four nine six.

93
00:06:19,650 --> 00:06:24,900
‫And if we now print the directory index, we get one.

94
00:06:30,480 --> 00:06:38,290
‫So by multiplying 1024 by four, nine six, that gives us the total number of bytes in a directory entry.

95
00:06:38,880 --> 00:06:41,190
‫So essentially is the entire.

96
00:06:42,290 --> 00:06:46,350
‫Page table that that directory entries pointing to, right?

97
00:06:46,490 --> 00:06:49,500
‫This is the total number of bytes we can store in there.

98
00:06:49,760 --> 00:06:57,230
‫So to calculate the directory index, we divide our virtual address by that value, by dividing it,

99
00:06:57,230 --> 00:06:58,280
‫by that value.

100
00:06:58,490 --> 00:07:05,660
‫It gives us the directory index that we care about because we know that each directory index points

101
00:07:05,660 --> 00:07:09,020
‫to a page table that can manage this many bytes.

102
00:07:09,320 --> 00:07:12,550
‫OK, so that is how we calculate the directory index.

103
00:07:12,560 --> 00:07:13,590
‫I hope that makes sense.

104
00:07:13,970 --> 00:07:17,470
‫So when are we going to calculate the page table index here?

105
00:07:19,460 --> 00:07:23,210
‫And that is virtual address.

106
00:07:24,470 --> 00:07:26,690
‫OK, remind us what is Modulus here.

107
00:07:27,690 --> 00:07:36,540
‫And we also do want those 24 Mogwai by four nine six in here, right, and then we divide it by four,

108
00:07:36,540 --> 00:07:43,650
‫nine, six, and we now print the page table index that gives us five.

109
00:07:44,070 --> 00:07:46,860
‫OK, let's just try that once more with a different address.

110
00:07:46,860 --> 00:07:51,660
‫So we're going to go VirTra dress equals zero x 400000, right?

111
00:07:52,020 --> 00:07:54,690
‫Oh, that was fourteen thousand four hundred thousand.

112
00:07:56,190 --> 00:07:59,970
‫And now we're now going to go print virtual address.

113
00:08:03,640 --> 00:08:07,120
‫Modulus four nine six multiplied by one or two for.

114
00:08:09,080 --> 00:08:15,630
‫OK, and that gives us zero, and now we divide that by four, nine, six, and we still get zero.

115
00:08:15,680 --> 00:08:17,900
‫OK, so that is how that's working, guys.

116
00:08:18,220 --> 00:08:26,210
‫We go virtual dress equals zero x 400000 and we change this to a one 400 1000.

117
00:08:26,210 --> 00:08:27,100
‫We print that again.

118
00:08:27,650 --> 00:08:28,750
‫Now we get one.

119
00:08:29,360 --> 00:08:36,020
‫So you can see this is the equation for calculating the table index and calculate the directory.

120
00:08:36,410 --> 00:08:42,450
‫The equation is print virtual address divided by four nine six multiplied by one or two four.

121
00:08:42,480 --> 00:08:47,750
‫OK, so we can see that four four one zero x 400 1000.

122
00:08:48,260 --> 00:08:51,860
‫We have a directory index of one and a page table index of one.

123
00:08:52,690 --> 00:08:59,860
‫So the this is the math basically, right, or what I should say is this is the directory index here,

124
00:08:59,860 --> 00:09:00,130
‫right?

125
00:09:00,340 --> 00:09:04,600
‫This one and this one here is the page table index.

126
00:09:04,610 --> 00:09:06,790
‫So I did that the wrong way round, but you know what I mean.

127
00:09:06,790 --> 00:09:07,000
‫Right?

128
00:09:07,030 --> 00:09:08,510
‫So that's how that's working.

129
00:09:08,860 --> 00:09:12,460
‫So this equation here calculates the page table entry.

130
00:09:12,940 --> 00:09:15,460
‫This equation here calculates the directory.

131
00:09:15,640 --> 00:09:17,110
‫I hope that makes sense.

132
00:09:17,470 --> 00:09:23,770
‫OK, so now that we've implemented page and get indexes, we are ready to implement the paging set function,

133
00:09:23,770 --> 00:09:26,340
‫which will basically set a page for us.

134
00:09:26,650 --> 00:09:31,570
‫So we're going to go into the paging set Unit 32 T.

135
00:09:34,490 --> 00:09:38,950
‫Directory, so expect a directory provided to us.

136
00:09:41,670 --> 00:09:48,010
‫And then we're going to say void virtual virt for virtual address unity to t Vall.

137
00:09:49,050 --> 00:09:57,200
‫OK, so this will set a page table entry, basically one of these to the value provided.

138
00:09:57,750 --> 00:10:02,850
‫So we're obviously expected to, you know, all the flags on and all this sort of stuff.

139
00:10:04,680 --> 00:10:10,140
‫So this value will obviously contain the physical address that we want this virtual address to point

140
00:10:10,140 --> 00:10:13,420
‫to, and it will also contain flags.

141
00:10:13,440 --> 00:10:16,290
‫OK, because it is essentially the page table entry.

142
00:10:16,290 --> 00:10:16,580
‫Right.

143
00:10:17,040 --> 00:10:19,800
‫OK, so what we're going to do then, we need to check alignment.

144
00:10:19,830 --> 00:10:20,790
‫Very first thing.

145
00:10:20,940 --> 00:10:24,720
‫Paging is aligned virtual address.

146
00:10:25,450 --> 00:10:29,050
‫Oh, and by the way, how you change this to that actually.

147
00:10:29,550 --> 00:10:36,660
‫So by the way, before we continue any further, when we implemented Ahepe, you'll notice I purposefully

148
00:10:36,660 --> 00:10:38,590
‫use the block size four nine six.

149
00:10:39,060 --> 00:10:44,340
‫This means that anything you allocate on the heat because it's four four nine six aligned, it can be

150
00:10:44,340 --> 00:10:46,400
‫used with paging is completely compatible.

151
00:10:46,800 --> 00:10:52,320
‫So make sure you don't change the block size of a heap because they are paging aligned.

152
00:10:52,350 --> 00:10:55,500
‫So if you've already done that, you should change that back four nine six.

153
00:10:55,500 --> 00:10:55,770
‫Right.

154
00:10:56,070 --> 00:11:00,280
‫Because when we came along, we can pass this straight into the paging.

155
00:11:00,300 --> 00:11:01,590
‫It works because it's aligned.

156
00:11:01,830 --> 00:11:04,590
‫If it's not aligned for 096, you'll have problems.

157
00:11:04,980 --> 00:11:08,830
‫OK, so we're now going to return minus E invalid argument.

158
00:11:08,940 --> 00:11:12,810
‫OK, so if then if the paging is an aligned invalid argument.

159
00:11:12,810 --> 00:11:13,100
‫Good.

160
00:11:13,650 --> 00:11:19,170
‫So we're now going to go unit three to T directory index equals zero.

161
00:11:19,350 --> 00:11:30,150
‫Unit thirty two T table index equals zero and we're going to address equals paging get indexes and it's

162
00:11:30,150 --> 00:11:32,430
‫going to ask for the virtual address.

163
00:11:32,880 --> 00:11:36,560
‫So we're going to pass invert, it's going to ask for the directory out.

164
00:11:37,200 --> 00:11:42,930
‫So we're going to pass in the directory index ampersand directory index for the address ampersand table

165
00:11:42,930 --> 00:11:45,580
‫index, OK, for the table out.

166
00:11:46,030 --> 00:11:52,010
‫And now if the rest is below zero, then there was an error and if there was an error, we just returned.

167
00:11:52,530 --> 00:11:58,230
‫OK, we don't need to be using go to here and stuff because we are not cleaning up any memory.

168
00:12:00,080 --> 00:12:06,770
‫OK, so we are now going to go unit 32 t entry equals directory directory index.

169
00:12:07,560 --> 00:12:12,430
‫So what this will do, this will get our page directory entry.

170
00:12:12,500 --> 00:12:15,340
‫OK, so that's what this does here.

171
00:12:15,360 --> 00:12:15,960
‫This entry.

172
00:12:15,960 --> 00:12:16,170
‫Right.

173
00:12:16,190 --> 00:12:19,170
‫So this, this entry contains the pointed to the page table.

174
00:12:19,170 --> 00:12:19,450
‫Right.

175
00:12:19,800 --> 00:12:25,510
‫So we're now going to go unit three to T table for the page table because unity to T and you know,

176
00:12:25,560 --> 00:12:30,560
‫this is a pointer pointer now and we're going to go entry ampersand.

177
00:12:30,730 --> 00:12:34,480
‫So we're going to do some bitwise logic now to extract only the address.

178
00:12:34,530 --> 00:12:41,160
‫OK, we don't want the flags, so we're going to go zero x f f f f f zero zero zero.

179
00:12:41,790 --> 00:12:43,360
‫OK, now that should be right.

180
00:12:43,890 --> 00:12:46,440
‫So each F here represents four bits.

181
00:12:46,890 --> 00:12:49,710
‫So four, eight, 12.

182
00:12:51,060 --> 00:12:51,870
‫16.

183
00:12:53,070 --> 00:13:01,740
‫Twenty, OK, so that is correct, that's 20 beds, and if we look here, it's 11 to 31, that's 20

184
00:13:01,740 --> 00:13:02,020
‫beds.

185
00:13:02,250 --> 00:13:03,560
‫We want to extract that.

186
00:13:04,140 --> 00:13:08,550
‫So you did if you did 31 minus 11, you get 20.

187
00:13:08,550 --> 00:13:08,810
‫Right.

188
00:13:09,180 --> 00:13:15,720
‫We've extracted the correct correct amount ignore in the last 12 beds here.

189
00:13:15,900 --> 00:13:18,810
‫OK, and remember, the bit number starts to zero.

190
00:13:18,810 --> 00:13:19,100
‫Right.

191
00:13:19,530 --> 00:13:21,420
‫Which is why you only see 11 here.

192
00:13:21,420 --> 00:13:23,760
‫So I just want to make that clear in case you're a bit confused.

193
00:13:23,760 --> 00:13:23,980
‫Right.

194
00:13:24,360 --> 00:13:31,830
‫OK, so that we've now extracted the page table address and we've assigned it to this point so we can

195
00:13:31,830 --> 00:13:33,160
‫access the table directly.

196
00:13:33,720 --> 00:13:35,460
‫So now the next page is very simple.

197
00:13:35,460 --> 00:13:41,910
‫We just go table, table index equals value and it's as simple as that.

198
00:13:42,420 --> 00:13:48,180
‫So now whenever we call page and set and we pass the value, we are expected.

199
00:13:48,540 --> 00:13:50,250
‫By the way, don't forget the semicolon here.

200
00:13:50,580 --> 00:13:56,190
‫We are expected to pass in the physical address along with the flags.

201
00:13:56,530 --> 00:13:59,760
‫So this will be our page, table entry, physical address.

202
00:13:59,760 --> 00:14:01,350
‫And there's the flags there, OK?

203
00:14:02,370 --> 00:14:04,110
‫And that's what gets set down here.

204
00:14:04,770 --> 00:14:11,010
‫And obviously here we extract only the address from the page directory entry.

205
00:14:11,370 --> 00:14:17,220
‫And then once we have that address, we can point to it, OK, and then set it like that.

206
00:14:17,670 --> 00:14:24,810
‫And the reason this works is because, remember, I said the the lower bits aren't used when we are

207
00:14:24,810 --> 00:14:26,580
‫applying to four, nine, six.

208
00:14:27,000 --> 00:14:33,780
‫And since every page is aligned to four nine six, we don't have a problem with this since every page

209
00:14:33,780 --> 00:14:35,940
‫table entries are lined up for nine six.

210
00:14:36,390 --> 00:14:38,420
‫OK, so there's our page and set complete.

211
00:14:38,730 --> 00:14:41,140
‫We can now actually try that, I think.

212
00:14:41,160 --> 00:14:47,340
‫So what we're going to do is we're going to copy and paste these these prototypes here into the file.

213
00:14:47,340 --> 00:14:47,670
‫Right.

214
00:14:48,270 --> 00:14:54,720
‫So Page set will go there into the header file and page is aligned.

215
00:14:54,720 --> 00:14:56,070
‫Also deserves to be there.

216
00:14:56,340 --> 00:14:59,040
‫Right, in case we use that elsewhere for whatever reason.

217
00:14:59,490 --> 00:15:04,190
‫So once we now that we've done that, we can actually start manipulating these addresses.

218
00:15:04,200 --> 00:15:05,640
‫So we're going to do that now.

219
00:15:05,800 --> 00:15:10,490
‫OK, so now go to Canada and see and we're going to actually map some memory now.

220
00:15:10,920 --> 00:15:16,940
‫So just above the neighbor page and we're going to go char PTA equals Kazal up four nine six.

221
00:15:16,950 --> 00:15:23,250
‫OK, so we've created a chunk of four thousand eighty six bytes of memory and we're going to map the

222
00:15:23,250 --> 00:15:29,740
‫virtual address you x 1000 to this address and it'll work fine because Casula will return a four thousand

223
00:15:29,740 --> 00:15:36,090
‫ninety six byte aligned address, assuming that you didn't change the chunk size when we are creating

224
00:15:36,090 --> 00:15:36,500
‫the heap.

225
00:15:36,870 --> 00:15:41,930
‫So we're now going to do is we're going to go paging set and we're just going to pass in the directory.

226
00:15:41,940 --> 00:15:53,010
‫So paging for paging four gigabyte chunk get directory, OK, and yeah, that could be a bit cleaner

227
00:15:53,010 --> 00:15:54,810
‫but it is Fynes for demonstration.

228
00:15:55,110 --> 00:15:59,670
‫So we're going to go XXXIV thousand here, but it expects a vote pointis so we're gonna have to cast

229
00:15:59,670 --> 00:16:01,230
‫that vote pointer as well.

230
00:16:01,230 --> 00:16:02,880
‫Guys, for the virtual dress.

231
00:16:03,120 --> 00:16:10,080
‫Another value will be a the pointer, but we need to cast it to you in a three to T right.

232
00:16:10,090 --> 00:16:20,250
‫So we go unity to t pointer Kasab and then we're going to go all paging axis from all or paging is present

233
00:16:20,430 --> 00:16:23,390
‫or paging is writable.

234
00:16:24,240 --> 00:16:31,410
‫OK, um so you can see here then we passed the address, the physical address now pointers, our physical

235
00:16:31,410 --> 00:16:37,500
‫address, we pass that and we basically all of these flags onto it now because it's four thousand eighty

236
00:16:37,500 --> 00:16:38,790
‫six aligned.

237
00:16:39,210 --> 00:16:43,010
‫We know that all of those lower bits for these flags are zero.

238
00:16:43,050 --> 00:16:45,150
‫So we so we know we can use them.

239
00:16:45,150 --> 00:16:47,670
‫Right, because it's four thousand eighty six bytes aligned.

240
00:16:47,670 --> 00:16:47,940
‫Right.

241
00:16:48,450 --> 00:16:52,830
‫So we passing paging axis from all paging is present and paging is writable.

242
00:16:53,010 --> 00:16:55,740
‫OK, so that is our physical address.

243
00:16:55,740 --> 00:16:59,190
‫So our virtual U.S. selects a thousand should now map to pointer.

244
00:16:59,670 --> 00:17:05,790
‫So whatever we do to address a thousand will affect physical address PTA.

245
00:17:06,030 --> 00:17:10,350
‫It will not affect physical address X a thousand.

246
00:17:10,500 --> 00:17:17,820
‫So just to demonstrate this then if we now did char PTA two equals char and we'll you know, we'll cast

247
00:17:17,820 --> 00:17:18,840
‫six a thousand here.

248
00:17:18,840 --> 00:17:20,820
‫Right, so we make a pointer to 6000.

249
00:17:21,370 --> 00:17:32,820
‫We now go pointed to zero equals a pointer to one equals B and we now pointed to and this will work

250
00:17:32,820 --> 00:17:34,680
‫because we kasar out.

251
00:17:34,680 --> 00:17:34,950
‫Right.

252
00:17:34,960 --> 00:17:40,770
‫So the second index indexed to would be null, terminated because we zero did.

253
00:17:42,300 --> 00:17:46,650
‫So we now did this and we pointed to you will seab.

254
00:17:46,680 --> 00:17:47,000
‫Right.

255
00:17:47,010 --> 00:17:52,530
‫So that's just demonstrate that, make clean build that S.H. City been.

256
00:17:53,260 --> 00:18:06,010
‫Kumu and you CAIB, OK, but now do Prince Peter and see what happens if we now run that again recompiling

257
00:18:06,010 --> 00:18:13,000
‫first guys, uh, we now run that again and we only see one a B..

258
00:18:13,090 --> 00:18:18,030
‫And the reason for this is because this code actually needs to be done after April Pageonce.

259
00:18:18,460 --> 00:18:23,080
‫So just paste that there and we're going to run that again.

260
00:18:23,080 --> 00:18:24,490
‫So back we go.

261
00:18:24,490 --> 00:18:30,530
‫Make clean, build that S.H. Cribben kumu and now you see a baby.

262
00:18:31,030 --> 00:18:32,350
‫So how is this possible?

263
00:18:33,280 --> 00:18:36,540
‫Well, I'll point to two points to virtual dress.

264
00:18:36,850 --> 00:18:37,750
‫A thousand, right.

265
00:18:38,290 --> 00:18:45,870
‫We then set Amba and we print pointer to which basically says print xox a thousand.

266
00:18:46,600 --> 00:18:52,930
‫However, our virtual address is map to the physical address, PTA, the Casula return.

267
00:18:52,940 --> 00:18:55,650
‫So it might be Xerox one million or something like that.

268
00:18:55,660 --> 00:18:55,900
‫Yeah.

269
00:18:56,440 --> 00:19:00,020
‫Uh, and we mapped 6000 to that address.

270
00:19:00,050 --> 00:19:08,230
‫OK, so then when we go print PTA, we're saying print zero x a million or whatever, but the page table

271
00:19:08,230 --> 00:19:14,340
‫Fazzio X but the page table entry for Xerox, a million points to Xerox, a million.

272
00:19:14,740 --> 00:19:15,520
‫It's LENNEAR.

273
00:19:15,850 --> 00:19:16,240
‫OK.

274
00:19:17,430 --> 00:19:26,580
‫Whereas the the address for pointed to is a thousand points to zero, Maximilien, you know, let's

275
00:19:26,580 --> 00:19:28,970
‫just assume that case over 26 million, right.

276
00:19:29,580 --> 00:19:36,210
‫So when we do print pointed to the memory management union, the CPU will see, which just selects 1000.

277
00:19:36,680 --> 00:19:37,570
‫It will resolve it.

278
00:19:37,590 --> 00:19:39,320
‫A physical address costs a million.

279
00:19:39,430 --> 00:19:46,770
‫OK, and when we go print Xerox a million, it will go into the virtual address and it will see that

280
00:19:46,770 --> 00:19:48,720
‫it maps to fiscal year six million.

281
00:19:49,230 --> 00:19:56,660
‫OK, so both point and point to two point to zero, Maximilien, that at the at the page table level.

282
00:19:57,060 --> 00:19:58,620
‫So that's how that's working guys.

283
00:19:58,860 --> 00:20:06,330
‫So even though point to two is Xerox a thousand and Peter is a million, they both point to the same

284
00:20:06,330 --> 00:20:10,380
‫data at the processor level in the page tables.

285
00:20:10,980 --> 00:20:16,850
‫So Page is incredibly useful, guys, and I hope now you have a taste of how that's working.

286
00:20:17,160 --> 00:20:18,720
‫So I hope that made sense.

287
00:20:18,720 --> 00:20:19,060
‫Right.

288
00:20:19,080 --> 00:20:23,100
‫I hope that made sense to you because these things can get confusing.

289
00:20:23,100 --> 00:20:23,370
‫Right.

290
00:20:23,670 --> 00:20:24,980
‫Let me just show you something else.

291
00:20:24,990 --> 00:20:30,510
‫And if I comment now, paging said, OK, and we run the exact same code as before.

292
00:20:31,770 --> 00:20:33,230
‫What you think you're going to see.

293
00:20:35,280 --> 00:20:39,230
‫And of course, my mistake that we need to put pointed to here.

294
00:20:39,690 --> 00:20:41,180
‫So I'm going to recompile that.

295
00:20:41,310 --> 00:20:42,540
‫What do you think we're going to see?

296
00:20:42,540 --> 00:20:42,890
‫Right.

297
00:20:44,700 --> 00:20:47,070
‫We only see one B and why?

298
00:20:47,880 --> 00:20:54,090
‫Because Xerox, a thousand virtual address is no longer mapped to physical address PTA, OK?

299
00:20:54,370 --> 00:21:00,600
‫And because of that reason, we are now writing to the physical address because a thousand not a physical

300
00:21:00,600 --> 00:21:07,680
‫address, six million or so pointer here, which is which return Xerox a million, eight points to six

301
00:21:07,680 --> 00:21:11,540
‫million, but the Xerox thousand point zero thousand.

302
00:21:11,790 --> 00:21:17,040
‫So the point represented by PR is never actually written to.

303
00:21:17,670 --> 00:21:22,980
‫OK, so if we put that back then, you know, obviously what you think you're going to see.

304
00:21:26,490 --> 00:21:31,100
‫A baby, so the benefits to paging are basically endless, right?

305
00:21:31,490 --> 00:21:33,630
‫Uh, you know how we print to the video memory?

306
00:21:33,630 --> 00:21:35,730
‫You know, that lecture we went to that address.

307
00:21:35,730 --> 00:21:36,020
‫Right.

308
00:21:36,810 --> 00:21:38,670
‫And then it outputs to the to the terminal.

309
00:21:38,670 --> 00:21:38,940
‫Right.

310
00:21:39,300 --> 00:21:43,440
‫We can use paging to map that address to some buffer in the process memory.

311
00:21:43,440 --> 00:21:43,720
‫Right.

312
00:21:44,280 --> 00:21:49,590
‫So then so then when one would task switching, when we're multitasking, it can still write to the

313
00:21:49,590 --> 00:21:50,730
‫video memory.

314
00:21:50,910 --> 00:21:54,570
‫Apart from us not writing the video memory, it's writing to a buffer.

315
00:21:54,570 --> 00:21:54,900
‫Right.

316
00:21:55,020 --> 00:22:01,740
‫And then when we switch back to the process, we can copy all of the all of all of that process, video

317
00:22:01,740 --> 00:22:09,810
‫memory buffer and copy it back into the physical real video memory buffer so the programs can just act

318
00:22:09,810 --> 00:22:12,240
‫as normal as if they're always right in the video memory.

319
00:22:12,450 --> 00:22:15,420
‫I don't have to worry about if they're the visible process.

320
00:22:15,930 --> 00:22:18,410
‫You know, we can abstract it all out with paging.

321
00:22:18,420 --> 00:22:19,890
‫That's just one of the benefits.

322
00:22:20,160 --> 00:22:27,660
‫Now, one thing I want you to know, we can map hardware addresses with paging because because the request

323
00:22:27,660 --> 00:22:29,010
‫has to go through the CPU.

324
00:22:29,730 --> 00:22:36,210
‫So when we have some machine code to ask for 6000, it goes to the CPU and it resolves to the page tables,

325
00:22:36,540 --> 00:22:38,520
‫whereas the physical hardware doesn't do that.

326
00:22:38,820 --> 00:22:46,210
‫So we can't map the video memory address somewhere else for the video card itself using paging.

327
00:22:46,230 --> 00:22:50,900
‫So in other words, the video card will always look at the physical address.

328
00:22:50,910 --> 00:22:54,360
‫We can't we can't map that with paging not not not this.

329
00:22:54,360 --> 00:22:54,570
‫What?

330
00:22:54,570 --> 00:22:55,890
‫Not like this at least.

331
00:22:57,660 --> 00:22:59,470
‫So I hope that makes sense.

332
00:22:59,880 --> 00:23:01,550
‫Any questions, please reach out.

