Discussion:
16-bit absolute addresses
(too old to reply)
muta...@gmail.com
2022-12-10 15:20:41 UTC
Permalink
If you want to point to video memory, you
can hardcode an address by going:

char *x = (char *)0xb8000000;

even though you only want 0xb8000.

And you can encapsulate that in a macro

char *x = MK_FP(0xb800, 0x0).

But with huge memory model you should instead
be able to code:

char *x = NULL;

x += 0xb8000UL;

ie you have a nice address, finally.

I'm wondering whether syntax like that should
always be used, so even in PM32, instead of
doing:

char *x = (char *)0xb8000;

you instead go:

char *x = NULL;
x += 0xb8000UL;

and have code that is portable regardless of which x86
processor you are using.

Or put the above into a macro.

I'm not sure you can even doing arithmetic on a NULL
pointer officially.

Any suggestions?

I guess addresses should be obtained from a syscall
in the first place instead of hardcode though.

But the case I really want to do it in is the bootloader,
and I need a start address of 0x10600. I'm planning
on switching my bootloader to huge memory model
(currently it is tiny).

I'm also thinking of writing an exe2flat that takes an
arbitrary executable and "loads" it to a particular
address instead of being dependent on the linker to
support such a facility.

And I'll also initialize BSS in that process, as I think
the location of BSS can be determined by getting
the "minsize" from the executable header and subtracting
the stack length.

Any thoughts on that too?

Thanks. Paul.
Alexei A. Frounze
2022-12-10 17:25:26 UTC
Permalink
Post by ***@gmail.com
If you want to point to video memory, you
...
Post by ***@gmail.com
char *x = MK_FP(0xb800, 0x0).
This just works in a test program I'm compiling with:
- Borland/Turbo C/C++, large model
- Open Watcom, large model
- Smaller C, huge, unreal and DPMI models

The definition for Smaller C is:
#define MK_FP(s,o) ((void*)(((unsigned long)(s) << 4) + (unsigned)(o)))

Alex
Joe Monk
2022-12-11 23:25:30 UTC
Permalink
You forgot the volatile keyword.

Since the video memory can be altered by events outside your code, you have to use the volatile keyword, otherwise you will get unpredictable results when C compilers apply optimizations.

Joe
Joe Monk
2022-12-12 00:42:24 UTC
Permalink
Post by ***@gmail.com
char *x = NULL;
char *x = NULL;
I'm not sure you can even doing arithmetic on a NULL
pointer officially.
You shouldnt be using NULL at all.

"Hoare’s friend, Edsger Dijkstra, pointed out that a null pointer reference could be a bad idea. Comparing a null pointer reference to a promiscuous adulterer he noted that the null assignment for every bachelor represented in an object structure “will seem to be married polyamorously to the same person Null”.

https://www.bbc.com/news/health-63859184

Joe
muta...@gmail.com
2022-12-12 02:12:19 UTC
Permalink
Post by Joe Monk
Post by ***@gmail.com
char *x = NULL;
char *x = NULL;
I'm not sure you can even doing arithmetic on a NULL
pointer officially.
You shouldnt be using NULL at all.
"Hoare’s friend, Edsger Dijkstra, pointed out that a null pointer reference could be a bad idea. Comparing a null pointer reference to a promiscuous adulterer he noted that the null assignment for every bachelor represented in an object structure “will seem to be married polyamorously to the same person Null”.
https://www.bbc.com/news/health-63859184
I thought that was a very amusing thing for the BBC
to say, so was smiling before I even clicked the (fake)
link. :-)

BFN. Paul.
Joe Monk
2022-12-12 02:38:47 UTC
Permalink
Post by ***@gmail.com
I thought that was a very amusing thing for the BBC
to say, so was smiling before I even clicked the (fake)
link. :-)
Oh sorry. Honest Mistake. That was a link for my daughter, who works in the DNA lab at the hospital doing that kind of work. She has two degrees in genetics and molecular genetics. If you read the article, it was about base amino acid editing used to make a custom therapy for a girl suffering from leukemia.

This was the link I meant to post:

https://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare/

https://www.theregister.com/2022/12/09/google_dart_null_safety/

Joe
muta...@gmail.com
2022-12-12 11:23:45 UTC
Permalink
Post by Joe Monk
Post by ***@gmail.com
I thought that was a very amusing thing for the BBC
to say, so was smiling before I even clicked the (fake)
link. :-)
Oh sorry. Honest Mistake. That was a link for my daughter, who
works in the DNA lab at the hospital doing that kind of work. She
has two degrees in genetics and molecular genetics. If you read
the article, it was about base amino acid editing used to make a
custom therapy for a girl suffering from leukemia.
Reminds me of when someone accidentally cross-linked
the C programming echo with some sex one, so we
suddenly started receiving some pretty unusual messages.

Someone remarked "if there's any justice in the world, they
will have been hit with a whole lot of C programming messages"
and someone from the sex group confirmed that it was really
bad getting C programming messages.

Man, I love humanity sometimes.
Post by Joe Monk
https://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare/
https://www.theregister.com/2022/12/09/google_dart_null_safety/
Ok, I read the articles.

BFN. Paul.

Loading...